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 <shaleva.ann@nspcc.ru>
This commit is contained in:
Anna Shaleva 2023-11-13 20:27:37 +03:00
parent dbd647e3a6
commit 963a22e280
4 changed files with 9 additions and 9 deletions

View file

@ -282,13 +282,13 @@ func NewError(code int64, message string, data string) *Error {
// NewParseError creates a new error with code // NewParseError creates a new error with code
// -32700. // -32700.
func NewParseError(data string) *Error { func NewParseError(data string) *Error {
return NewError(BadRequestCode, "Parse Error", data) return NewError(BadRequestCode, "Parse error", data)
} }
// NewInvalidRequestError creates a new error with // NewInvalidRequestError creates a new error with
// code -32600. // code -32600.
func NewInvalidRequestError(data string) *Error { func NewInvalidRequestError(data string) *Error {
return NewError(InvalidRequestCode, "Invalid Request", data) return NewError(InvalidRequestCode, "Invalid request", data)
} }
// NewMethodNotFoundError creates a new error with // NewMethodNotFoundError creates a new error with
@ -300,7 +300,7 @@ func NewMethodNotFoundError(data string) *Error {
// NewInvalidParamsError creates a new error with // NewInvalidParamsError creates a new error with
// code -32602. // code -32602.
func NewInvalidParamsError(data string) *Error { func NewInvalidParamsError(data string) *Error {
return NewError(InvalidParamsCode, "Invalid Params", data) return NewError(InvalidParamsCode, "Invalid params", data)
} }
// NewInternalServerError creates a new error with // NewInternalServerError creates a new error with

View file

@ -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", name: "getapplicationlog_invalid_params_error",
invoke: func(c *Client) (any, error) { invoke: func(c *Client) (any, error) {

View file

@ -83,7 +83,7 @@ func TestWSClientSubscription(t *testing.T) {
t.Run("bad", func(t *testing.T) { t.Run("bad", func(t *testing.T) {
for name, f := range cases { for name, f := range cases {
t.Run(name, func(t *testing.T) { 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{}) wsc, err := NewWS(context.TODO(), httpURLtoWS(srv.URL), WSOptions{})
require.NoError(t, err) require.NoError(t, err)
wsc.getNextRequestID = getTestRequestID wsc.getNextRequestID = getTestRequestID
@ -118,7 +118,7 @@ func TestWSClientUnsubscription(t *testing.T) {
err := wsc.Unsubscribe("0") err := wsc.Unsubscribe("0")
require.Error(t, err) 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. // We can't really subscribe using this stub server, so set up wsc internals.
wsc.subscriptions["0"] = &blockReceiver{} wsc.subscriptions["0"] = &blockReceiver{}
err := wsc.Unsubscribe("0") err := wsc.Unsubscribe("0")

View file

@ -3148,15 +3148,15 @@ func testRPCProtocol(t *testing.T, doRPCCall func(string, string, *testing.T) []
t.Run("calculatenetworkfee", func(t *testing.T) { t.Run("calculatenetworkfee", func(t *testing.T) {
t.Run("no parameters", 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) 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) { t.Run("non-base64 parameter", func(t *testing.T) {
body := doRPCCall(`{"jsonrpc": "2.0", "id": 1, "method": "calculatenetworkfee", "params": ["noatbase64"]}"`, httpSrv.URL, 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) { t.Run("non-transaction parameter", func(t *testing.T) {
body := doRPCCall(`{"jsonrpc": "2.0", "id": 1, "method": "calculatenetworkfee", "params": ["bm90IGEgdHJhbnNhY3Rpb24K"]}"`, httpSrv.URL, 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 { 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())) rpc := fmt.Sprintf(`{"jsonrpc": "2.0", "id": 1, "method": "calculatenetworkfee", "params": ["%s"]}"`, base64.StdEncoding.EncodeToString(tx.Bytes()))