From 1e6372e6d91f4b23b423346a0ac11c0a3fe42a6e Mon Sep 17 00:00:00 2001 From: Tatiana Nesterenko Date: Fri, 11 Aug 2023 22:56:15 +0100 Subject: [PATCH] rpcsrv: return error on unknown storage item from `getstorage` Follow the reference implementation, the behaviour was changed in https://github.com/neo-project/neo-modules/commit/237ef7d057265723571efde74e54001f68ce969d. Signed-off-by: Tatiana Nesterenko --- pkg/services/rpcsrv/server.go | 5 +---- pkg/services/rpcsrv/server_test.go | 10 ++++------ 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/pkg/services/rpcsrv/server.go b/pkg/services/rpcsrv/server.go index 145b2cb6d..cfc5df532 100644 --- a/pkg/services/rpcsrv/server.go +++ b/pkg/services/rpcsrv/server.go @@ -1722,9 +1722,6 @@ func (s *Server) getStateRoot(ps params.Params) (any, *neorpc.Error) { func (s *Server) getStorage(ps params.Params) (any, *neorpc.Error) { id, rErr := s.contractIDFromParam(ps.Value(0)) - if rErr == neorpc.ErrUnknownContract { - return nil, nil - } if rErr != nil { return nil, rErr } @@ -1736,7 +1733,7 @@ func (s *Server) getStorage(ps params.Params) (any, *neorpc.Error) { item := s.chain.GetStorageItem(id, key) if item == nil { - return "", nil + return "", neorpc.ErrUnknownStorageItem } return []byte(item), nil diff --git a/pkg/services/rpcsrv/server_test.go b/pkg/services/rpcsrv/server_test.go index 35e58dbd9..bc098e3ca 100644 --- a/pkg/services/rpcsrv/server_test.go +++ b/pkg/services/rpcsrv/server_test.go @@ -621,12 +621,10 @@ var rpcTestCases = map[string][]rpcTestCase{ }, }, { - name: "missing key", - params: fmt.Sprintf(`["%s", "dGU="]`, testContractHash), - result: func(e *executor) any { - v := "" - return &v - }, + name: "missing key", + params: fmt.Sprintf(`["%s", "dGU="]`, testContractHash), + fail: true, + errCode: neorpc.ErrUnknownStorageItemCode, }, { name: "no params",