Merge pull request #3199 from nspcc-dev/fix-err

neorpc: adjust common error messages
This commit is contained in:
Roman Khimov 2023-11-13 22:17:07 +03:00 committed by GitHub
commit 5e220754d7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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()))