Merge pull request #3385 from nspcc-dev/findstorage

rpcsrv: fix findstorage if a contract state is not found
This commit is contained in:
Anna Shaleva 2024-04-03 11:00:55 +03:00 committed by GitHub
commit c5ba53986f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
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)
},
},