rpcsrv: fix findstorage if a contract state is not found

Previously findstorage returns null for the results key if a contract
state is not found. C# returns an empty list.

Close #3370

Signed-off-by: Ekaterina Pavlova <ekt@morphbits.io>
This commit is contained in:
Ekaterina Pavlova 2024-04-01 15:14:13 +03:00
parent e7a0ded65e
commit fff25bd85c
3 changed files with 18 additions and 5 deletions

View file

@ -2321,7 +2321,11 @@ func TestClient_FindStorage(t *testing.T) {
// Missing item.
actual, err = c.FindStorageByHash(h, []byte("unknown prefix"), nil)
require.NoError(t, err)
require.Equal(t, result.FindStorage{}, actual)
require.Equal(t, result.FindStorage{
Results: []result.KeyValue{},
Next: 0,
Truncated: false,
}, actual)
}
func TestClient_FindStorageHistoric(t *testing.T) {
@ -2386,7 +2390,11 @@ func TestClient_FindStorageHistoric(t *testing.T) {
require.NoError(t, err)
actual, err = c.FindStorageByHashHistoric(earlyRoot.Root, h, prefix, nil)
require.NoError(t, err)
require.Equal(t, result.FindStorage{}, actual)
require.Equal(t, result.FindStorage{
Results: []result.KeyValue{},
Next: 0,
Truncated: false,
}, actual)
}
func TestClient_GetStorageHistoric(t *testing.T) {

View file

@ -1750,7 +1750,8 @@ func (s *Server) findStorageInternal(id int32, prefix []byte, start, take int, s
var (
i int
end = start + take
res = new(result.FindStorage)
// Result is an empty list if a contract state is not found as it is in C# implementation.
res = &result.FindStorage{Results: make([]result.KeyValue, 0)}
)
seeker.SeekStorage(id, prefix, func(k, v []byte) bool {
if i < start {

View file

@ -817,7 +817,7 @@ var rpcTestCases = map[string][]rpcTestCase{
require.True(t, ok)
expected := &result.FindStorage{
Results: nil,
Results: []result.KeyValue{},
Next: 0,
Truncated: false,
}
@ -956,7 +956,11 @@ var rpcTestCases = map[string][]rpcTestCase{
actual, ok := res.(*result.FindStorage)
require.True(t, ok)
expected := &result.FindStorage{}
expected := &result.FindStorage{
Results: []result.KeyValue{},
Next: 0,
Truncated: false,
}
require.Equal(t, expected, actual)
},
},