Skip to content

Commit

Permalink
api: make find_state resilient against node implementation differences (
Browse files Browse the repository at this point in the history
#303)

Co-authored-by: Mirella de Medeiros <[email protected]>
Co-authored-by: Erik van den Brink <[email protected]>
  • Loading branch information
3 people authored Mar 20, 2024
1 parent e16f79c commit 1823903
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 5 additions & 4 deletions neo3/api/noderpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -930,10 +930,11 @@ async def find_states(
response = await self._do_post(
"findstorage", [contract_hash, _prefix, start]
)
for pair in response["results"]:
key = base64.b64decode(pair["key"])
value = base64.b64decode(pair["value"])
yield key, value
if response["results"] is not None:
for pair in response["results"]:
key = base64.b64decode(pair["key"])
value = base64.b64decode(pair["value"])
yield key, value
if not response["truncated"]:
break
start = response["next"]
Expand Down
8 changes: 8 additions & 0 deletions tests/api/test_noderpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,14 @@ async def test_exception(self):
self.assertIn("bogus_message", str(context.exception))
self.assertIn("bogus_data", str(context.exception))

async def test_findstorage_issue_neogo(self):
# test workaround for https://github.com/nspcc-dev/neo-go/issues/3370
captured = {"results": None, "next": 0, "truncated": False}
self.mock_response(captured)

x = [(k, v) async for k, v in self.client.find_states(types.UInt160.zero())]
self.assertEqual(0, len(x))


class TestStackItem(unittest.TestCase):
@classmethod
Expand Down

0 comments on commit 1823903

Please sign in to comment.