Skip to content

Commit 0106994

Browse files
jsvisacolinlyguo
authored andcommitted
graphql: fix an issue of nil pointer panic (ethereum#28416)
Signed-off-by: jsvisa <[email protected]>
1 parent 55e20e9 commit 0106994

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

graphql/graphql.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,6 +1335,9 @@ func (r *Resolver) Blocks(ctx context.Context, args struct {
13351335
From *Long
13361336
To *Long
13371337
}) ([]*Block, error) {
1338+
if args.From == nil {
1339+
return nil, errors.New("from block number must be specified")
1340+
}
13381341
from := rpc.BlockNumber(*args.From)
13391342

13401343
var to rpc.BlockNumber

graphql/graphql_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ func TestGraphQLBlockSerialization(t *testing.T) {
148148
want: `{"data":{"block":{"number":"0xa","call":{"data":"0x","status":"0x1"}}}}`,
149149
code: 200,
150150
},
151+
{
152+
body: `{"query": "{blocks {number}}"}`,
153+
want: `{"errors":[{"message":"from block number must be specified","path":["blocks"]}],"data":null}`,
154+
code: 400,
155+
},
151156
} {
152157
resp, err := http.Post(fmt.Sprintf("%s/graphql", stack.HTTPEndpoint()), "application/json", strings.NewReader(tt.body))
153158
if err != nil {

0 commit comments

Comments
 (0)