Merge pull request #2866 from nspcc-dev/findstates-ret-nothing

Fix findstates response difference
This commit is contained in:
Roman Khimov 2023-01-11 20:41:10 +07:00 committed by GitHub
commit 4e23695441
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 7 deletions

View file

@ -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 {

View file

@ -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)