From 1bb4e286b1a2b2ec8d6bd3c6d0722b522d261e3c Mon Sep 17 00:00:00 2001 From: Mirella de Medeiros Date: Fri, 1 Mar 2024 14:15:19 -0300 Subject: [PATCH 1/2] fix type error when find state not found --- neo3/api/noderpc.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/neo3/api/noderpc.py b/neo3/api/noderpc.py index 7a2eafc..848c01b 100644 --- a/neo3/api/noderpc.py +++ b/neo3/api/noderpc.py @@ -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"]: + 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"] From d73374b4214736aed66fd065f355a299adc722c6 Mon Sep 17 00:00:00 2001 From: Erik van den Brink Date: Wed, 20 Mar 2024 16:47:32 +0100 Subject: [PATCH 2/2] add test --- neo3/api/noderpc.py | 2 +- tests/api/test_noderpc.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/neo3/api/noderpc.py b/neo3/api/noderpc.py index 848c01b..8b85bcf 100644 --- a/neo3/api/noderpc.py +++ b/neo3/api/noderpc.py @@ -930,7 +930,7 @@ async def find_states( response = await self._do_post( "findstorage", [contract_hash, _prefix, start] ) - if response["results"]: + if response["results"] is not None: for pair in response["results"]: key = base64.b64decode(pair["key"]) value = base64.b64decode(pair["value"]) diff --git a/tests/api/test_noderpc.py b/tests/api/test_noderpc.py index dfc6b84..d97173b 100644 --- a/tests/api/test_noderpc.py +++ b/tests/api/test_noderpc.py @@ -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