From 06cd05e05aeb8b64e14c22c19c6b98280528f8c2 Mon Sep 17 00:00:00 2001 From: Uxio Fuentefria Date: Wed, 16 Feb 2022 14:09:14 +0100 Subject: [PATCH] Fix decoding ERC20/721 Transfer events - If a not standard event was used, like `Transfer(address indexed, address, uint256 indexed)`, decoding was broken --- gnosis/eth/ethereum_client.py | 30 +- gnosis/eth/tests/mocks/mock_log_receipts.py | 306 ++++++++++++++++++++ gnosis/eth/tests/test_ethereum_client.py | 286 +----------------- 3 files changed, 339 insertions(+), 283 deletions(-) create mode 100644 gnosis/eth/tests/mocks/mock_log_receipts.py diff --git a/gnosis/eth/ethereum_client.py b/gnosis/eth/ethereum_client.py index 55a164517..723f582ae 100644 --- a/gnosis/eth/ethereum_client.py +++ b/gnosis/eth/ethereum_client.py @@ -388,7 +388,7 @@ class Erc20Manager(EthereumClientManager): # ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef TRANSFER_TOPIC = HexBytes(ERC20_721_TRANSFER_TOPIC) - def decode_logs(self, logs: List[Dict[str, Any]]): + def decode_logs(self, logs: List[LogReceipt]): decoded_logs = [] for log in logs: decoded = self._decode_transfer_log(log["data"], log["topics"]) @@ -413,13 +413,29 @@ def _decode_transfer_log( elif topics_len == 3: # ERC20 Transfer(address indexed from, address indexed to, uint256 value) # 3 topics (transfer topic + from + to) - value = eth_abi.decode_single("uint256", HexBytes(data)) - _from, to = [ - Web3.toChecksumAddress(address) - for address in eth_abi.decode_abi( - ["address", "address"], b"".join(topics[1:]) + try: + value_data = HexBytes(data) + value = eth_abi.decode_single("uint256", value_data) + except DecodingError: + logger.warning( + "Cannot decode Transfer event `uint256 value` from data=%s", + value_data.hex(), ) - ] + return None + try: + from_to_data = b"".join(topics[1:]) + _from, to = ( + Web3.toChecksumAddress(address) + for address in eth_abi.decode_abi( + ["address", "address"], from_to_data + ) + ) + except DecodingError: + logger.warning( + "Cannot decode Transfer event `address from, address to` from topics=%s", + HexBytes(from_to_data).hex(), + ) + return None return {"from": _from, "to": to, "value": value} elif topics_len == 4: # ERC712 Transfer(address indexed from, address indexed to, uint256 indexed tokenId) diff --git a/gnosis/eth/tests/mocks/mock_log_receipts.py b/gnosis/eth/tests/mocks/mock_log_receipts.py new file mode 100644 index 000000000..f1d3d7d4c --- /dev/null +++ b/gnosis/eth/tests/mocks/mock_log_receipts.py @@ -0,0 +1,306 @@ +from hexbytes import HexBytes +from web3.datastructures import AttributeDict + +log_receipts = [ + AttributeDict( + { + "address": "0x39C4BFa00b6edecCDd00fA9589E1BE76DE63e862", + "topics": [ + HexBytes( + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef" + ), + HexBytes( + "0x00000000000000000000000094e01661ebaef430fe862f958c03200b0f483f27" + ), + HexBytes( + "0x00000000000000000000000094e01661ebaef430fe862f958c03200b0f483f27" + ), + ], + "data": "0x000000000000000000000000000000000000000000000003aa2371d700680000", + "blockNumber": 4357126, + "transactionHash": HexBytes( + "0x21381484d8f69dcd782560d1fd3cd818e743c79767985d01aec7e61c2a7f1de9" + ), + "transactionIndex": 14, + "blockHash": HexBytes( + "0x677ada1a306fc50751001bca6eeaa3f5a87a0bf2c9f6fa27899bfbaf999cca4f" + ), + "logIndex": 13, + "removed": False, + } + ), + AttributeDict( + { + "address": "0x39C4BFa00b6edecCDd00fA9589E1BE76DE63e862", + "topics": [ + HexBytes( + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef" + ), + HexBytes( + "0x00000000000000000000000094e01661ebaef430fe862f958c03200b0f483f27" + ), + HexBytes( + "0x00000000000000000000000064da772dd84965f0ee58174941d78a9dfbccca2e" + ), + ], + "data": "0x000000000000000000000000000000000000000000000001a055690d9db80000", + "blockNumber": 4357126, + "transactionHash": HexBytes( + "0x21381484d8f69dcd782560d1fd3cd818e743c79767985d01aec7e61c2a7f1de9" + ), + "transactionIndex": 14, + "blockHash": HexBytes( + "0x677ada1a306fc50751001bca6eeaa3f5a87a0bf2c9f6fa27899bfbaf999cca4f" + ), + "logIndex": 14, + "removed": False, + } + ), + AttributeDict( + { + "address": "0x39C4BFa00b6edecCDd00fA9589E1BE76DE63e862", + "topics": [ + HexBytes( + "0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925" + ), + HexBytes( + "0x00000000000000000000000064da772dd84965f0ee58174941d78a9dfbccca2e" + ), + HexBytes( + "0x00000000000000000000000080cdad25de6b439e866805b2dc6808d23ff57b5d" + ), + ], + "data": "0x000000000000000000000000000000000000000000000001a055690d9db80000", + "blockNumber": 4357126, + "transactionHash": HexBytes( + "0x21381484d8f69dcd782560d1fd3cd818e743c79767985d01aec7e61c2a7f1de9" + ), + "transactionIndex": 14, + "blockHash": HexBytes( + "0x677ada1a306fc50751001bca6eeaa3f5a87a0bf2c9f6fa27899bfbaf999cca4f" + ), + "logIndex": 15, + "removed": False, + } + ), + AttributeDict( + { + "address": "0x39C4BFa00b6edecCDd00fA9589E1BE76DE63e862", + "topics": [ + HexBytes( + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef" + ), + HexBytes( + "0x00000000000000000000000064da772dd84965f0ee58174941d78a9dfbccca2e" + ), + HexBytes( + "0x00000000000000000000000080cdad25de6b439e866805b2dc6808d23ff57b5d" + ), + ], + "data": "0x000000000000000000000000000000000000000000000001a055690d9db80000", + "blockNumber": 4357126, + "transactionHash": HexBytes( + "0x21381484d8f69dcd782560d1fd3cd818e743c79767985d01aec7e61c2a7f1de9" + ), + "transactionIndex": 14, + "blockHash": HexBytes( + "0x677ada1a306fc50751001bca6eeaa3f5a87a0bf2c9f6fa27899bfbaf999cca4f" + ), + "logIndex": 16, + "removed": False, + } + ), + AttributeDict( + { + "address": "0x99b9F9BA62002a9b43aF6e540428277D5E52EF47", + "topics": [ + HexBytes( + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef" + ), + HexBytes( + "0x00000000000000000000000099b9f9ba62002a9b43af6e540428277d5e52ef47" + ), + HexBytes( + "0x00000000000000000000000094e01661ebaef430fe862f958c03200b0f483f27" + ), + HexBytes( + "0xcc292d3dab2c0fbbf616670ac57ec51162959c2d9cbe938819b6e8bc1c757335" + ), + ], + "data": "0x", + "blockNumber": 4357126, + "transactionHash": HexBytes( + "0x21381484d8f69dcd782560d1fd3cd818e743c79767985d01aec7e61c2a7f1de9" + ), + "transactionIndex": 14, + "blockHash": HexBytes( + "0x677ada1a306fc50751001bca6eeaa3f5a87a0bf2c9f6fa27899bfbaf999cca4f" + ), + "logIndex": 17, + "removed": False, + } + ), + AttributeDict( + { + "address": "0x99b9F9BA62002a9b43aF6e540428277D5E52EF47", + "topics": [ + HexBytes( + "0x2114851a3e2a54429989f46c1ab0743e37ded205d9bbdfd85635aed5bd595a06" + ), + HexBytes( + "0x00000000000000000000000099b9f9ba62002a9b43af6e540428277d5e52ef47" + ), + HexBytes( + "0x00000000000000000000000094e01661ebaef430fe862f958c03200b0f483f27" + ), + HexBytes( + "0xcc292d3dab2c0fbbf616670ac57ec51162959c2d9cbe938819b6e8bc1c757335" + ), + ], + "data": "0x0000000000000000000000000000000000000000000000000000000000000001", + "blockNumber": 4357126, + "transactionHash": HexBytes( + "0x21381484d8f69dcd782560d1fd3cd818e743c79767985d01aec7e61c2a7f1de9" + ), + "transactionIndex": 14, + "blockHash": HexBytes( + "0x677ada1a306fc50751001bca6eeaa3f5a87a0bf2c9f6fa27899bfbaf999cca4f" + ), + "logIndex": 18, + "removed": False, + } + ), + AttributeDict( + { + "address": "0x99b9F9BA62002a9b43aF6e540428277D5E52EF47", + "topics": [ + HexBytes( + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef" + ), + HexBytes( + "0x00000000000000000000000099b9f9ba62002a9b43af6e540428277d5e52ef47" + ), + HexBytes( + "0x00000000000000000000000094e01661ebaef430fe862f958c03200b0f483f27" + ), + HexBytes( + "0xe37edda38a308a6fae15178579aab28bc7f9e46e52fde30c3a46b82b7461aa08" + ), + ], + "data": "0x", + "blockNumber": 4357126, + "transactionHash": HexBytes( + "0x21381484d8f69dcd782560d1fd3cd818e743c79767985d01aec7e61c2a7f1de9" + ), + "transactionIndex": 14, + "blockHash": HexBytes( + "0x677ada1a306fc50751001bca6eeaa3f5a87a0bf2c9f6fa27899bfbaf999cca4f" + ), + "logIndex": 19, + "removed": False, + } + ), + AttributeDict( + { + "address": "0x99b9F9BA62002a9b43aF6e540428277D5E52EF47", + "topics": [ + HexBytes( + "0x2114851a3e2a54429989f46c1ab0743e37ded205d9bbdfd85635aed5bd595a06" + ), + HexBytes( + "0x00000000000000000000000099b9f9ba62002a9b43af6e540428277d5e52ef47" + ), + HexBytes( + "0x00000000000000000000000094e01661ebaef430fe862f958c03200b0f483f27" + ), + HexBytes( + "0xe37edda38a308a6fae15178579aab28bc7f9e46e52fde30c3a46b82b7461aa08" + ), + ], + "data": "0x0000000000000000000000000000000000000000000000000000000000000001", + "blockNumber": 4357126, + "transactionHash": HexBytes( + "0x21381484d8f69dcd782560d1fd3cd818e743c79767985d01aec7e61c2a7f1de9" + ), + "transactionIndex": 14, + "blockHash": HexBytes( + "0x677ada1a306fc50751001bca6eeaa3f5a87a0bf2c9f6fa27899bfbaf999cca4f" + ), + "logIndex": 20, + "removed": False, + } + ), + AttributeDict( + { + "address": "0x64DA772DD84965f0Ee58174941d78a9DfBccca2e", + "topics": [ + HexBytes( + "0x3c8fbbba495ddb1296f967c80627bcca81b77be0b349ed8ae5f604365c22e9c7" + ) + ], + "data": "0x6e4f8d9f6517dfa28f202b2e2582943d1bd567dfb0c4a774989715c29e4aed180000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000039c4bfa00b6edeccdd00fa9589e1be76de63e862000000000000000000000000000000000000000000000003aa2371d7006800000000000000000000000000000000000000000000000000000000000000000001", + "blockNumber": 4357126, + "transactionHash": HexBytes( + "0x21381484d8f69dcd782560d1fd3cd818e743c79767985d01aec7e61c2a7f1de9" + ), + "transactionIndex": 14, + "blockHash": HexBytes( + "0x677ada1a306fc50751001bca6eeaa3f5a87a0bf2c9f6fa27899bfbaf999cca4f" + ), + "logIndex": 21, + "removed": False, + } + ), + AttributeDict( + { + "address": "0xe35F3B71CA90eE2606F64b645D8F4f8DCaA914Bf", + "topics": [ + HexBytes( + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef" + ) + ], + "data": "0x0000000000000000000000008683f9c4e856be65f8a38a3a768e8fd6de94d30a000000000000000000000000fd1017c3284a12ac33bc65df12d71721c85931e00000000000000000000000000000000000000000000000000000000000000001", + "blockNumber": 7240557, + "transactionHash": HexBytes( + "0x1962e296457b16d5221d33623f2db5f617cb54221deb7cfd73611f761ac526a3" + ), + "transactionIndex": 6, + "blockHash": HexBytes( + "0xdf3c33d034f1b342820afdfb2612d0794d4a1c15518184d71a047ef1eb151d10" + ), + "logIndex": 5, + "removed": False, + } + ), +] + +# Real transfer log of a `Transfer(address indexed, address, uint256 indexed)` found on Rinkeby +invalid_log_receipt = AttributeDict( + { + "address": "0x1607a02df130c472159fAEb2BC706175B84055Fa", + "blockHash": HexBytes( + "0xe386d2275b6db3b1e02d5fae3f663312ecbf4f5f58fdf20c47da5fb6769dc578" + ), + "blockNumber": 10172601, + "data": "0x0000000000000000000000000000000000000000000000000000000000000000", + "logIndex": 11, + "removed": False, + "topics": [ + HexBytes( + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef" + ), + HexBytes( + "0x00000000000000000000000073c9cc436c1249394d1ea28bf1d9f2217da006f4" + ), + HexBytes( + "0x4567000000000000000000000000000000000000000000000000000000000000" + ), + ], + "transactionHash": HexBytes( + "0xcbb6f53e05b3bfde1fde259f9b44d48fde73f4f633604cbe6bd4375dddbefa0f" + ), + "transactionIndex": 5, + "transactionLogIndex": "0x0", + "type": "mined", + } +) diff --git a/gnosis/eth/tests/test_ethereum_client.py b/gnosis/eth/tests/test_ethereum_client.py index 05a789fae..f4a2d66fd 100644 --- a/gnosis/eth/tests/test_ethereum_client.py +++ b/gnosis/eth/tests/test_ethereum_client.py @@ -6,7 +6,6 @@ from eth_account import Account from hexbytes import HexBytes -from web3.datastructures import AttributeDict from web3.eth import Eth from web3.types import TxParams @@ -26,6 +25,7 @@ from ..utils import get_eth_address_with_key from .ethereum_test_case import EthereumTestCaseMixin from .mocks.mock_internal_txs import creation_internal_txs, internal_txs_errored +from .mocks.mock_log_receipts import invalid_log_receipt, log_receipts from .mocks.mock_trace_block import trace_block_2191709_mock, trace_block_13191781_mock from .mocks.mock_trace_filter import trace_filter_mock_1 from .mocks.mock_trace_transaction import trace_transaction_mocks @@ -34,281 +34,9 @@ class TestERC20Module(EthereumTestCaseMixin, TestCase): def test_decode_transfer_log(self): - logs = [ - AttributeDict( - { - "address": "0x39C4BFa00b6edecCDd00fA9589E1BE76DE63e862", - "topics": [ - HexBytes( - "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef" - ), - HexBytes( - "0x00000000000000000000000094e01661ebaef430fe862f958c03200b0f483f27" - ), - HexBytes( - "0x00000000000000000000000094e01661ebaef430fe862f958c03200b0f483f27" - ), - ], - "data": "0x000000000000000000000000000000000000000000000003aa2371d700680000", - "blockNumber": 4357126, - "transactionHash": HexBytes( - "0x21381484d8f69dcd782560d1fd3cd818e743c79767985d01aec7e61c2a7f1de9" - ), - "transactionIndex": 14, - "blockHash": HexBytes( - "0x677ada1a306fc50751001bca6eeaa3f5a87a0bf2c9f6fa27899bfbaf999cca4f" - ), - "logIndex": 13, - "removed": False, - } - ), - AttributeDict( - { - "address": "0x39C4BFa00b6edecCDd00fA9589E1BE76DE63e862", - "topics": [ - HexBytes( - "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef" - ), - HexBytes( - "0x00000000000000000000000094e01661ebaef430fe862f958c03200b0f483f27" - ), - HexBytes( - "0x00000000000000000000000064da772dd84965f0ee58174941d78a9dfbccca2e" - ), - ], - "data": "0x000000000000000000000000000000000000000000000001a055690d9db80000", - "blockNumber": 4357126, - "transactionHash": HexBytes( - "0x21381484d8f69dcd782560d1fd3cd818e743c79767985d01aec7e61c2a7f1de9" - ), - "transactionIndex": 14, - "blockHash": HexBytes( - "0x677ada1a306fc50751001bca6eeaa3f5a87a0bf2c9f6fa27899bfbaf999cca4f" - ), - "logIndex": 14, - "removed": False, - } - ), - AttributeDict( - { - "address": "0x39C4BFa00b6edecCDd00fA9589E1BE76DE63e862", - "topics": [ - HexBytes( - "0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925" - ), - HexBytes( - "0x00000000000000000000000064da772dd84965f0ee58174941d78a9dfbccca2e" - ), - HexBytes( - "0x00000000000000000000000080cdad25de6b439e866805b2dc6808d23ff57b5d" - ), - ], - "data": "0x000000000000000000000000000000000000000000000001a055690d9db80000", - "blockNumber": 4357126, - "transactionHash": HexBytes( - "0x21381484d8f69dcd782560d1fd3cd818e743c79767985d01aec7e61c2a7f1de9" - ), - "transactionIndex": 14, - "blockHash": HexBytes( - "0x677ada1a306fc50751001bca6eeaa3f5a87a0bf2c9f6fa27899bfbaf999cca4f" - ), - "logIndex": 15, - "removed": False, - } - ), - AttributeDict( - { - "address": "0x39C4BFa00b6edecCDd00fA9589E1BE76DE63e862", - "topics": [ - HexBytes( - "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef" - ), - HexBytes( - "0x00000000000000000000000064da772dd84965f0ee58174941d78a9dfbccca2e" - ), - HexBytes( - "0x00000000000000000000000080cdad25de6b439e866805b2dc6808d23ff57b5d" - ), - ], - "data": "0x000000000000000000000000000000000000000000000001a055690d9db80000", - "blockNumber": 4357126, - "transactionHash": HexBytes( - "0x21381484d8f69dcd782560d1fd3cd818e743c79767985d01aec7e61c2a7f1de9" - ), - "transactionIndex": 14, - "blockHash": HexBytes( - "0x677ada1a306fc50751001bca6eeaa3f5a87a0bf2c9f6fa27899bfbaf999cca4f" - ), - "logIndex": 16, - "removed": False, - } - ), - AttributeDict( - { - "address": "0x99b9F9BA62002a9b43aF6e540428277D5E52EF47", - "topics": [ - HexBytes( - "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef" - ), - HexBytes( - "0x00000000000000000000000099b9f9ba62002a9b43af6e540428277d5e52ef47" - ), - HexBytes( - "0x00000000000000000000000094e01661ebaef430fe862f958c03200b0f483f27" - ), - HexBytes( - "0xcc292d3dab2c0fbbf616670ac57ec51162959c2d9cbe938819b6e8bc1c757335" - ), - ], - "data": "0x", - "blockNumber": 4357126, - "transactionHash": HexBytes( - "0x21381484d8f69dcd782560d1fd3cd818e743c79767985d01aec7e61c2a7f1de9" - ), - "transactionIndex": 14, - "blockHash": HexBytes( - "0x677ada1a306fc50751001bca6eeaa3f5a87a0bf2c9f6fa27899bfbaf999cca4f" - ), - "logIndex": 17, - "removed": False, - } - ), - AttributeDict( - { - "address": "0x99b9F9BA62002a9b43aF6e540428277D5E52EF47", - "topics": [ - HexBytes( - "0x2114851a3e2a54429989f46c1ab0743e37ded205d9bbdfd85635aed5bd595a06" - ), - HexBytes( - "0x00000000000000000000000099b9f9ba62002a9b43af6e540428277d5e52ef47" - ), - HexBytes( - "0x00000000000000000000000094e01661ebaef430fe862f958c03200b0f483f27" - ), - HexBytes( - "0xcc292d3dab2c0fbbf616670ac57ec51162959c2d9cbe938819b6e8bc1c757335" - ), - ], - "data": "0x0000000000000000000000000000000000000000000000000000000000000001", - "blockNumber": 4357126, - "transactionHash": HexBytes( - "0x21381484d8f69dcd782560d1fd3cd818e743c79767985d01aec7e61c2a7f1de9" - ), - "transactionIndex": 14, - "blockHash": HexBytes( - "0x677ada1a306fc50751001bca6eeaa3f5a87a0bf2c9f6fa27899bfbaf999cca4f" - ), - "logIndex": 18, - "removed": False, - } - ), - AttributeDict( - { - "address": "0x99b9F9BA62002a9b43aF6e540428277D5E52EF47", - "topics": [ - HexBytes( - "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef" - ), - HexBytes( - "0x00000000000000000000000099b9f9ba62002a9b43af6e540428277d5e52ef47" - ), - HexBytes( - "0x00000000000000000000000094e01661ebaef430fe862f958c03200b0f483f27" - ), - HexBytes( - "0xe37edda38a308a6fae15178579aab28bc7f9e46e52fde30c3a46b82b7461aa08" - ), - ], - "data": "0x", - "blockNumber": 4357126, - "transactionHash": HexBytes( - "0x21381484d8f69dcd782560d1fd3cd818e743c79767985d01aec7e61c2a7f1de9" - ), - "transactionIndex": 14, - "blockHash": HexBytes( - "0x677ada1a306fc50751001bca6eeaa3f5a87a0bf2c9f6fa27899bfbaf999cca4f" - ), - "logIndex": 19, - "removed": False, - } - ), - AttributeDict( - { - "address": "0x99b9F9BA62002a9b43aF6e540428277D5E52EF47", - "topics": [ - HexBytes( - "0x2114851a3e2a54429989f46c1ab0743e37ded205d9bbdfd85635aed5bd595a06" - ), - HexBytes( - "0x00000000000000000000000099b9f9ba62002a9b43af6e540428277d5e52ef47" - ), - HexBytes( - "0x00000000000000000000000094e01661ebaef430fe862f958c03200b0f483f27" - ), - HexBytes( - "0xe37edda38a308a6fae15178579aab28bc7f9e46e52fde30c3a46b82b7461aa08" - ), - ], - "data": "0x0000000000000000000000000000000000000000000000000000000000000001", - "blockNumber": 4357126, - "transactionHash": HexBytes( - "0x21381484d8f69dcd782560d1fd3cd818e743c79767985d01aec7e61c2a7f1de9" - ), - "transactionIndex": 14, - "blockHash": HexBytes( - "0x677ada1a306fc50751001bca6eeaa3f5a87a0bf2c9f6fa27899bfbaf999cca4f" - ), - "logIndex": 20, - "removed": False, - } - ), - AttributeDict( - { - "address": "0x64DA772DD84965f0Ee58174941d78a9DfBccca2e", - "topics": [ - HexBytes( - "0x3c8fbbba495ddb1296f967c80627bcca81b77be0b349ed8ae5f604365c22e9c7" - ) - ], - "data": "0x6e4f8d9f6517dfa28f202b2e2582943d1bd567dfb0c4a774989715c29e4aed180000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000039c4bfa00b6edeccdd00fa9589e1be76de63e862000000000000000000000000000000000000000000000003aa2371d7006800000000000000000000000000000000000000000000000000000000000000000001", - "blockNumber": 4357126, - "transactionHash": HexBytes( - "0x21381484d8f69dcd782560d1fd3cd818e743c79767985d01aec7e61c2a7f1de9" - ), - "transactionIndex": 14, - "blockHash": HexBytes( - "0x677ada1a306fc50751001bca6eeaa3f5a87a0bf2c9f6fa27899bfbaf999cca4f" - ), - "logIndex": 21, - "removed": False, - } - ), - AttributeDict( - { - "address": "0xe35F3B71CA90eE2606F64b645D8F4f8DCaA914Bf", - "topics": [ - HexBytes( - "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef" - ) - ], - "data": "0x0000000000000000000000008683f9c4e856be65f8a38a3a768e8fd6de94d30a000000000000000000000000fd1017c3284a12ac33bc65df12d71721c85931e00000000000000000000000000000000000000000000000000000000000000001", - "blockNumber": 7240557, - "transactionHash": HexBytes( - "0x1962e296457b16d5221d33623f2db5f617cb54221deb7cfd73611f761ac526a3" - ), - "transactionIndex": 6, - "blockHash": HexBytes( - "0xdf3c33d034f1b342820afdfb2612d0794d4a1c15518184d71a047ef1eb151d10" - ), - "logIndex": 5, - "removed": False, - } - ), - ] - - # TODO Test with ganache - decoded_logs = self.ethereum_client.erc20.decode_logs(logs) + decoded_logs = self.ethereum_client.erc20.decode_logs( + log_receipts + [invalid_log_receipt] + ) self.assertEqual(len(decoded_logs), 6) self.assertEqual( len([event for event in decoded_logs if "tokenId" in event["args"]]), 2 @@ -413,6 +141,12 @@ def test_decode_transfer_log(self): self.assertEqual(decoded_logs[3], expected_log_3) self.assertEqual(decoded_logs[5], expected_log_5) + def test_decode_invalid_transfer_log(self): + invalid_transfer_logs = [invalid_log_receipt] + self.assertEqual( + self.ethereum_client.erc20.decode_logs(invalid_transfer_logs), [] + ) + def test_get_name_symbol_balance(self): amount = 1000 address = Account.create().address