|
| 1 | +import copy |
1 | 2 | import pytest
|
2 | 3 | import re
|
3 | 4 |
|
| 5 | +from eth_abi.exceptions import ( |
| 6 | + InsufficientDataBytes, |
| 7 | +) |
4 | 8 | from eth_utils import (
|
5 | 9 | is_same_address,
|
6 | 10 | )
|
@@ -1233,3 +1237,29 @@ def test_get_all_entries_with_nested_tuple_event_non_strict(
|
1233 | 1237 | assert log_entry.blockNumber == txn_receipt["blockNumber"]
|
1234 | 1238 | assert log_entry.transactionIndex == txn_receipt["transactionIndex"]
|
1235 | 1239 | assert is_same_address(log_entry.address, non_strict_emitter.address)
|
| 1240 | + |
| 1241 | + |
| 1242 | +def test_receipt_processing_catches_insufficientdatabytes_error_by_default( |
| 1243 | + w3, emitter, wait_for_transaction |
| 1244 | +): |
| 1245 | + txn_hash = emitter.functions.logListArgs([b"13"], [b"54"]).transact() |
| 1246 | + txn_receipt = wait_for_transaction(w3, txn_hash) |
| 1247 | + event_instance = emitter.events.LogListArgs() |
| 1248 | + |
| 1249 | + # web3 doesn't generate logs with non-standard lengths, so we have to do it manually |
| 1250 | + txn_receipt_dict = copy.deepcopy(txn_receipt) |
| 1251 | + txn_receipt_dict["logs"][0] = dict(txn_receipt_dict["logs"][0]) |
| 1252 | + txn_receipt_dict["logs"][0]["data"] = txn_receipt_dict["logs"][0]["data"][:-8] |
| 1253 | + |
| 1254 | + # WARN is default |
| 1255 | + assert len(event_instance.process_receipt(txn_receipt_dict)) == 0 |
| 1256 | + assert len(event_instance.process_receipt(txn_receipt_dict, errors=WARN)) == 0 |
| 1257 | + assert len(event_instance.process_receipt(txn_receipt_dict, errors=DISCARD)) == 0 |
| 1258 | + |
| 1259 | + # IGNORE includes the InsufficientDataBytes error in the log |
| 1260 | + assert len(event_instance.process_receipt(txn_receipt_dict, errors=IGNORE)) == 1 |
| 1261 | + |
| 1262 | + # STRICT raises an error to be caught |
| 1263 | + with pytest.raises(InsufficientDataBytes): |
| 1264 | + returned_log = event_instance.process_receipt(txn_receipt_dict, errors=STRICT) |
| 1265 | + assert len(returned_log) == 0 |
0 commit comments