mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-01-25 15:14:48 +00:00
rpcsrv: return empty set from findstates when there is no data
Fix #2863.
This commit is contained in:
parent
5ad1fcd321
commit
9718602ce3
2 changed files with 16 additions and 3 deletions
|
@ -1541,8 +1541,8 @@ func (s *Server) findStates(ps params.Params) (interface{}, *neorpc.Error) {
|
||||||
}
|
}
|
||||||
pKey := makeStorageKey(cs.ID, prefix)
|
pKey := makeStorageKey(cs.ID, prefix)
|
||||||
kvs, err := s.chain.GetStateModule().FindStates(root, pKey, key, count+1) // +1 to define result truncation
|
kvs, err := s.chain.GetStateModule().FindStates(root, pKey, key, count+1) // +1 to define result truncation
|
||||||
if err != nil {
|
if err != nil && !errors.Is(err, mpt.ErrNotFound) {
|
||||||
return nil, neorpc.NewInternalServerError(fmt.Sprintf("failed to find historical items: %s", err))
|
return nil, neorpc.NewInternalServerError(fmt.Sprintf("failed to find state items: %s", err))
|
||||||
}
|
}
|
||||||
res := result.FindStates{}
|
res := result.FindStates{}
|
||||||
if len(kvs) == count+1 {
|
if len(kvs) == count+1 {
|
||||||
|
|
|
@ -2123,7 +2123,9 @@ func testRPCProtocol(t *testing.T, doRPCCall func(string, string, *testing.T) []
|
||||||
require.NoError(t, json.Unmarshal(rawRes, vp))
|
require.NoError(t, json.Unmarshal(rawRes, vp))
|
||||||
require.Equal(t, value, vp.Value)
|
require.Equal(t, value, vp.Value)
|
||||||
}
|
}
|
||||||
|
if len(actual.Results) > 0 {
|
||||||
checkProof(t, actual.FirstProof, actual.Results[0].Value)
|
checkProof(t, actual.FirstProof, actual.Results[0].Value)
|
||||||
|
}
|
||||||
if len(actual.Results) > 1 {
|
if len(actual.Results) > 1 {
|
||||||
checkProof(t, actual.LastProof, actual.Results[len(actual.Results)-1].Value)
|
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,
|
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) {
|
t.Run("good: with prefix, no limit", func(t *testing.T) {
|
||||||
// pairs for this test where put to the contract storage at block #16
|
// pairs for this test where put to the contract storage at block #16
|
||||||
root, err := e.chain.GetStateModule().GetStateRoot(16)
|
root, err := e.chain.GetStateModule().GetStateRoot(16)
|
||||||
|
|
Loading…
Reference in a new issue