graphql: add testcase for errorCode

Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
jsvisa 2023-10-26 08:17:56 +08:00
parent 31705c5d74
commit eee6dfc9f1

View file

@ -153,6 +153,18 @@ func TestGraphQLBlockSerialization(t *testing.T) {
want: `{"errors":[{"message":"from block number must be specified","path":["blocks"]}],"data":null}`, want: `{"errors":[{"message":"from block number must be specified","path":["blocks"]}],"data":null}`,
code: 400, code: 400,
}, },
// invalid block range
{
body: `{"query": "{blocks(from: 5 to: 1 ){number}}"}`,
want: `{"errors":[{"message":"error [-32602]: invalid from and to block combination: from \u003e to","path":["blocks"],"extensions":{"errorCode":-32602,"errorMessage":"invalid from and to block combination: from \u003e to"}}],"data":null}`,
code: 400,
},
// both hash and number
{
body: `{"query": "{block(number: 1 hash: \"0xd864c9d7d37fade6b70164740540c06dd58bb9c3f6b46101908d6339db6a6a7b\"){number}}"}`,
want: `{"errors":[{"message":"error [-32602]: only one of number or hash must be specified","path":["block"],"extensions":{"errorCode":-32602,"errorMessage":"only one of number or hash must be specified"}}],"data":{"block":null}}`,
code: 400,
},
} { } {
resp, err := http.Post(fmt.Sprintf("%s/graphql", stack.HTTPEndpoint()), "application/json", strings.NewReader(tt.body)) resp, err := http.Post(fmt.Sprintf("%s/graphql", stack.HTTPEndpoint()), "application/json", strings.NewReader(tt.body))
if err != nil { if err != nil {