From 963a22e280a7599fe915b521670636f7b356398f Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Mon, 13 Nov 2023 20:27:37 +0300 Subject: [PATCH] neorpc: adjust common error messages According to the initial proposal and https://github.com/neo-project/proposals/pull/156/files#diff-2b5f7c12a23f7dbe4cb46bbf4be6936882f8e0f0b3a4db9d8c58eb294b02e6ed. Signed-off-by: Anna Shaleva --- pkg/neorpc/errors.go | 6 +++--- pkg/rpcclient/rpc_test.go | 2 +- pkg/rpcclient/wsclient_test.go | 4 ++-- pkg/services/rpcsrv/server_test.go | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pkg/neorpc/errors.go b/pkg/neorpc/errors.go index d6488283a..b38d0b695 100644 --- a/pkg/neorpc/errors.go +++ b/pkg/neorpc/errors.go @@ -282,13 +282,13 @@ func NewError(code int64, message string, data string) *Error { // NewParseError creates a new error with code // -32700. func NewParseError(data string) *Error { - return NewError(BadRequestCode, "Parse Error", data) + return NewError(BadRequestCode, "Parse error", data) } // NewInvalidRequestError creates a new error with // code -32600. func NewInvalidRequestError(data string) *Error { - return NewError(InvalidRequestCode, "Invalid Request", data) + return NewError(InvalidRequestCode, "Invalid request", data) } // NewMethodNotFoundError creates a new error with @@ -300,7 +300,7 @@ func NewMethodNotFoundError(data string) *Error { // NewInvalidParamsError creates a new error with // code -32602. func NewInvalidParamsError(data string) *Error { - return NewError(InvalidParamsCode, "Invalid Params", data) + return NewError(InvalidParamsCode, "Invalid params", data) } // NewInternalServerError creates a new error with diff --git a/pkg/rpcclient/rpc_test.go b/pkg/rpcclient/rpc_test.go index d36d6804c..32d8d9ca8 100644 --- a/pkg/rpcclient/rpc_test.go +++ b/pkg/rpcclient/rpc_test.go @@ -1456,7 +1456,7 @@ var rpcClientErrorCases = map[string][]rpcClientErrorCase{ }, }, }, - `{"id":1,"jsonrpc":"2.0","error":{"code":-32602,"message":"Invalid Params"}}`: { + `{"id":1,"jsonrpc":"2.0","error":{"code":-32602,"message":"Invalid params"}}`: { { name: "getapplicationlog_invalid_params_error", invoke: func(c *Client) (any, error) { diff --git a/pkg/rpcclient/wsclient_test.go b/pkg/rpcclient/wsclient_test.go index af2b65d1b..e004659f3 100644 --- a/pkg/rpcclient/wsclient_test.go +++ b/pkg/rpcclient/wsclient_test.go @@ -83,7 +83,7 @@ func TestWSClientSubscription(t *testing.T) { t.Run("bad", func(t *testing.T) { for name, f := range cases { t.Run(name, func(t *testing.T) { - srv := initTestServer(t, `{"jsonrpc": "2.0", "id": 1, "error":{"code":-32602,"message":"Invalid Params"}}`) + srv := initTestServer(t, `{"jsonrpc": "2.0", "id": 1, "error":{"code":-32602,"message":"Invalid params"}}`) wsc, err := NewWS(context.TODO(), httpURLtoWS(srv.URL), WSOptions{}) require.NoError(t, err) wsc.getNextRequestID = getTestRequestID @@ -118,7 +118,7 @@ func TestWSClientUnsubscription(t *testing.T) { err := wsc.Unsubscribe("0") require.Error(t, err) }}, - "error returned": {`{"jsonrpc": "2.0", "id": 1, "error":{"code":-32602,"message":"Invalid Params"}}`, func(t *testing.T, wsc *WSClient) { + "error returned": {`{"jsonrpc": "2.0", "id": 1, "error":{"code":-32602,"message":"Invalid params"}}`, func(t *testing.T, wsc *WSClient) { // We can't really subscribe using this stub server, so set up wsc internals. wsc.subscriptions["0"] = &blockReceiver{} err := wsc.Unsubscribe("0") diff --git a/pkg/services/rpcsrv/server_test.go b/pkg/services/rpcsrv/server_test.go index 66393c11c..441abcf1f 100644 --- a/pkg/services/rpcsrv/server_test.go +++ b/pkg/services/rpcsrv/server_test.go @@ -3148,15 +3148,15 @@ func testRPCProtocol(t *testing.T, doRPCCall func(string, string, *testing.T) [] t.Run("calculatenetworkfee", func(t *testing.T) { t.Run("no parameters", func(t *testing.T) { body := doRPCCall(`{"jsonrpc": "2.0", "id": 1, "method": "calculatenetworkfee", "params": []}"`, httpSrv.URL, t) - _ = checkErrGetResult(t, body, true, neorpc.InvalidParamsCode, "Invalid Params") + _ = checkErrGetResult(t, body, true, neorpc.InvalidParamsCode, "Invalid params") }) t.Run("non-base64 parameter", func(t *testing.T) { body := doRPCCall(`{"jsonrpc": "2.0", "id": 1, "method": "calculatenetworkfee", "params": ["noatbase64"]}"`, httpSrv.URL, t) - _ = checkErrGetResult(t, body, true, neorpc.InvalidParamsCode, "Invalid Params") + _ = checkErrGetResult(t, body, true, neorpc.InvalidParamsCode, "Invalid params") }) t.Run("non-transaction parameter", func(t *testing.T) { body := doRPCCall(`{"jsonrpc": "2.0", "id": 1, "method": "calculatenetworkfee", "params": ["bm90IGEgdHJhbnNhY3Rpb24K"]}"`, httpSrv.URL, t) - _ = checkErrGetResult(t, body, true, neorpc.InvalidParamsCode, "Invalid Params") + _ = checkErrGetResult(t, body, true, neorpc.InvalidParamsCode, "Invalid params") }) calcReq := func(t *testing.T, tx *transaction.Transaction) []byte { rpc := fmt.Sprintf(`{"jsonrpc": "2.0", "id": 1, "method": "calculatenetworkfee", "params": ["%s"]}"`, base64.StdEncoding.EncodeToString(tx.Bytes()))