graphql: test case

Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
jsvisa 2023-10-27 14:47:34 +08:00
parent eee6dfc9f1
commit ba409e2e49
3 changed files with 3 additions and 2 deletions

View file

@ -25,6 +25,7 @@ var (
errOnlyNumberOrHash = invalidParamsError("only one of number or hash must be specified") errOnlyNumberOrHash = invalidParamsError("only one of number or hash must be specified")
errBlockInvariant = invalidParamsError("block objects must be instantiated with at least one of num or hash") errBlockInvariant = invalidParamsError("block objects must be instantiated with at least one of num or hash")
errInvalidBlockRange = invalidParamsError("invalid from and to block combination: from > to") errInvalidBlockRange = invalidParamsError("invalid from and to block combination: from > to")
errFromBlockRequired = invalidParamsError("from block number must be specified")
) )
const ( const (

View file

@ -1320,7 +1320,7 @@ func (r *Resolver) Blocks(ctx context.Context, args struct {
To *Long To *Long
}) ([]*Block, error) { }) ([]*Block, error) {
if args.From == nil { if args.From == nil {
return nil, errors.New("from block number must be specified") return nil, errFromBlockRequired
} }
from := rpc.BlockNumber(*args.From) from := rpc.BlockNumber(*args.From)

View file

@ -150,7 +150,7 @@ func TestGraphQLBlockSerialization(t *testing.T) {
}, },
{ {
body: `{"query": "{blocks {number}}"}`, body: `{"query": "{blocks {number}}"}`,
want: `{"errors":[{"message":"from block number must be specified","path":["blocks"]}],"data":null}`, want: `{"errors":[{"message":"error [-32602]: from block number must be specified","path":["blocks"],"extensions":{"errorCode":-32602,"errorMessage":"from block number must be specified"}}],"data":null}`,
code: 400, code: 400,
}, },
// invalid block range // invalid block range