|
| 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 | ) |
@@ -1025,6 +1029,39 @@ def test_receipt_processing_with_no_flag(indexed_event_contract, dup_txn_receipt |
1025 | 1029 | with pytest.warns(UserWarning, match="Expected 1 log topics. Got 0"): |
1026 | 1030 | returned_log = event_instance.process_receipt(dup_txn_receipt) |
1027 | 1031 | assert len(returned_log) == 0 |
| 1032 | + |
| 1033 | + |
| 1034 | +def test_receipt_processing_catches_insufficientdatabytes_error( |
| 1035 | + w3, emitter, emitter_contract_event_ids, wait_for_transaction |
| 1036 | +): |
| 1037 | + txn_hash = emitter.functions.logListArgs([b"13"], [b"54"]).transact() |
| 1038 | + txn_receipt = wait_for_transaction(w3, txn_hash) |
| 1039 | + event_instance = emitter.events.LogListArgs() |
| 1040 | + |
| 1041 | + # web3 doesn't generate logs with non-standard lengths, so we have to do it manually |
| 1042 | + txn_receipt_dict = copy.deepcopy(txn_receipt) |
| 1043 | + txn_receipt_dict["logs"][0] = dict(txn_receipt_dict["logs"][0]) |
| 1044 | + txn_receipt_dict["logs"][0]["data"] = txn_receipt_dict["logs"][0]["data"][:-8] |
| 1045 | + |
| 1046 | + |
| 1047 | + assert len(event_instance.process_receipt(txn_receipt_dict)) == 0 |
| 1048 | + |
| 1049 | + with pytest.raises(InsufficientDataBytes): |
| 1050 | + returned_log = event_instance.process_receipt(txn_receipt_dict, errors=STRICT) |
| 1051 | + assert len(returned_log) == 0 |
| 1052 | + |
| 1053 | + assert len(event_instance.process_receipt(txn_receipt_dict, errors=WARN)) == 0 |
| 1054 | + assert len(event_instance.process_receipt(txn_receipt_dict, errors=WARN, abi_decode_strict=False)) == 0 |
| 1055 | + |
| 1056 | + # processed_logs = event_instance.process_receipt(txn_receipt) |
| 1057 | + # assert len(processed_logs) == 1 |
| 1058 | + # rich_log = processed_logs[0] |
| 1059 | + |
| 1060 | + # event_instance = indexed_event_contract.events.LogSingleWithIndex() |
| 1061 | + # breakpoint() |
| 1062 | + |
| 1063 | + |
| 1064 | +# def test_receipt_processing_with_abi_strict_decode_flag(indexed_event_contract, dup_txn_receipt): |
1028 | 1065 |
|
1029 | 1066 |
|
1030 | 1067 | def test_single_log_processing_with_errors(indexed_event_contract, dup_txn_receipt): |
|
0 commit comments