diff --git a/pkg/services/rpcsrv/server.go b/pkg/services/rpcsrv/server.go index 6258b8ef5..97ef82e73 100644 --- a/pkg/services/rpcsrv/server.go +++ b/pkg/services/rpcsrv/server.go @@ -1538,8 +1538,8 @@ func (s *Server) findStates(ps params.Params) (interface{}, *neorpc.Error) { } pKey := makeStorageKey(cs.ID, prefix) kvs, err := s.chain.GetStateModule().FindStates(root, pKey, key, count+1) // +1 to define result truncation - if err != nil { - return nil, neorpc.NewInternalServerError(fmt.Sprintf("failed to find historical items: %s", err)) + if err != nil && !errors.Is(err, mpt.ErrNotFound) { + return nil, neorpc.NewInternalServerError(fmt.Sprintf("failed to find state items: %s", err)) } res := result.FindStates{} if len(kvs) == count+1 { diff --git a/pkg/services/rpcsrv/server_test.go b/pkg/services/rpcsrv/server_test.go index a6851a841..08d636d07 100644 --- a/pkg/services/rpcsrv/server_test.go +++ b/pkg/services/rpcsrv/server_test.go @@ -472,22 +472,22 @@ var rpcTestCases = map[string][]rpcTestCase{ }, { name: "invalid contract", - params: `["0000000000000000000000000000000000000000000000000000000000000000", "0xabcdef"]`, + params: `["` + block20StateRootLE + `", "0xabcdef"]`, fail: true, }, { name: "invalid prefix", - params: `["0000000000000000000000000000000000000000000000000000000000000000", "` + testContractHash + `", "notabase64%"]`, + params: `["` + block20StateRootLE + `", "` + testContractHash + `", "notabase64%"]`, fail: true, }, { name: "invalid key", - params: `["0000000000000000000000000000000000000000000000000000000000000000", "` + testContractHash + `", "QQ==", "notabase64%"]`, + params: `["` + block20StateRootLE + `", "` + testContractHash + `", "QQ==", "notabase64%"]`, fail: true, }, { name: "unknown contract/large count", - params: `["0000000000000000000000000000000000000000000000000000000000000000", "0000000000000000000000000000000000000000", "QQ==", "QQ==", 101]`, + params: `["` + block20StateRootLE + `", "0000000000000000000000000000000000000000", "QQ==", "QQ==", 101]`, fail: true, }, }, @@ -2123,7 +2123,9 @@ func testRPCProtocol(t *testing.T, doRPCCall func(string, string, *testing.T) [] require.NoError(t, json.Unmarshal(rawRes, vp)) require.Equal(t, value, vp.Value) } - checkProof(t, actual.FirstProof, actual.Results[0].Value) + if len(actual.Results) > 0 { + checkProof(t, actual.FirstProof, actual.Results[0].Value) + } if len(actual.Results) > 1 { checkProof(t, actual.LastProof, actual.Results[len(actual.Results)-1].Value) } @@ -2157,6 +2159,17 @@ func testRPCProtocol(t *testing.T, doRPCCall func(string, string, *testing.T) [] Truncated: false, }) }) + t.Run("good: empty prefix, no limit, no data", func(t *testing.T) { + // empty prefix should be considered as no prefix specified. + root, err := e.chain.GetStateModule().GetStateRoot(20) + require.NoError(t, err) + stdHash, _ := e.chain.GetNativeContractScriptHash(nativenames.StdLib) // It has no data. + params := fmt.Sprintf(`"%s", "%s", ""`, root.Root.StringLE(), stdHash.StringLE()) + testFindStates(t, params, root.Root, result.FindStates{ + Results: []result.KeyValue{}, + Truncated: false, + }) + }) t.Run("good: with prefix, no limit", func(t *testing.T) { // pairs for this test where put to the contract storage at block #16 root, err := e.chain.GetStateModule().GetStateRoot(16)