Skip to content

Commit 5aa1f22

Browse files
committed
PR review updates
1 parent d605888 commit 5aa1f22

File tree

6 files changed

+48
-50
lines changed

6 files changed

+48
-50
lines changed

docs/contracts.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -741,11 +741,11 @@ For example:
741741
- ``DISCARD`` - silently discards any logs that have errors, and returns processed logs that don't have errors.
742742
- ``WARN`` - logs a warning to the console for the log that has an error, and discards the log. Returns any logs that are able to be processed.
743743

744-
An ``EventLogErrorFlag`` needs to be imported from web3/event_log_error_flags.py.
744+
An event log error flag needs to be imported from web3/log.py.
745745

746746
.. code-block:: python
747747
748-
>>> from web3.event_log_error_flags import STRICT, IGNORE, DISCARD, WARN
748+
>>> from web3.logs import STRICT, IGNORE, DISCARD, WARN
749749
750750
>>> tx_hash = contract.functions.myFunction(12345).transact({'to':contract_address})
751751
>>> tx_receipt = w3.eth.getTransactionReceipt(tx_hash)

tests/core/contracts/test_extracting_event_data.py

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,22 @@
44
from eth_utils import (
55
is_same_address,
66
)
7+
from eth_utils.toolz import (
8+
dissoc,
9+
)
710

811
from web3._utils.events import (
912
get_event_data,
1013
)
11-
from web3.event_log_error_flags import (
14+
from web3.exceptions import (
15+
LogTopicError,
16+
)
17+
from web3.logs import (
1218
DISCARD,
1319
IGNORE,
1420
STRICT,
1521
WARN,
1622
)
17-
from web3.exceptions import (
18-
LogTopicError,
19-
)
2023

2124

2225
@pytest.fixture()
@@ -340,29 +343,22 @@ def test_event_processing_with_ignore_flag(
340343
returned_logs = event_instance.processReceipt(dup_txn_receipt, errors=IGNORE)
341344
assert len(returned_logs) == 2
342345

343-
first_log = dict(returned_logs[0])
344-
345346
# Check that the correct error is appended to the log
346-
expected_error = re.compile("Expected 1 log topics. Got 0")
347-
assert expected_error.search(str(first_log['errors'])) is not None
348-
349-
# Check that the returned log is the same as what got sent in,
350-
# except the added errors field
351-
del first_log['errors']
352-
assert first_log == dup_txn_receipt['logs'][0]
353-
assert is_same_address(first_log['address'], event_contract.address)
347+
first_log = returned_logs[0]
348+
log_error = re.compile("Expected 1 log topics. Got 0")
349+
assert log_error.search(str(first_log.errors)) is not None
354350

355351
# Then, do the same with the other log:
356-
second_log = dict(returned_logs[1])
357-
352+
second_log = returned_logs[1]
358353
abi_error = re.compile("The event signature did not match the provided ABI")
359-
assert abi_error.search(str(second_log['errors'])) is not None
360-
361-
# Check that the returned log is the same as what got sent in,
362-
# except the added errors field
363-
del second_log['errors']
364-
assert second_log == dup_txn_receipt['logs'][1]
365-
assert is_same_address(second_log['address'], event_contract.address)
354+
assert abi_error.search(str(second_log.errors)) is not None
355+
356+
for log in returned_logs:
357+
# Check that the returned log is the same as what got sent in,
358+
# except for the added errors field
359+
orig_log = dissoc(dict(log), 'errors')
360+
assert orig_log in dup_txn_receipt['logs']
361+
assert is_same_address(log['address'], event_contract.address)
366362

367363

368364
def test_event_processing_with_warn_flag(

web3/_utils/events.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
ABC,
33
abstractmethod,
44
)
5+
from enum import Enum
56
import itertools
67

78
from eth_abi import (
@@ -448,3 +449,14 @@ def _encode(self, value):
448449
return to_hex(keccak(encode_single_packed(self.arg_type, value)))
449450
else:
450451
return to_hex(encode_single(self.arg_type, value))
452+
453+
454+
class EventLogErrorFlags(Enum):
455+
Discard = 'discard'
456+
Ignore = 'ignore'
457+
Strict = 'strict'
458+
Warn = 'warn'
459+
460+
@classmethod
461+
def flag_options(self):
462+
return [key.upper() for key in self.__members__.keys()]

web3/contract.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,6 @@
8686
AttributeDict,
8787
MutableAttributeDict,
8888
)
89-
from web3.event_log_error_flags import (
90-
DISCARD,
91-
IGNORE,
92-
STRICT,
93-
WARN,
94-
EventLogErrorFlags,
95-
)
9689
from web3.exceptions import (
9790
BadFunctionCallOutput,
9891
BlockNumberOutofRange,
@@ -105,6 +98,13 @@
10598
NoABIFunctionsFound,
10699
ValidationError,
107100
)
101+
from web3.logs import (
102+
DISCARD,
103+
IGNORE,
104+
STRICT,
105+
WARN,
106+
EventLogErrorFlags,
107+
)
108108

109109
ACCEPTABLE_EMPTY_STRINGS = ["0x", b"0x", "", b""]
110110

web3/event_log_error_flags.py

Lines changed: 0 additions & 18 deletions
This file was deleted.

web3/logs.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from web3._utils.events import (
2+
EventLogErrorFlags,
3+
)
4+
5+
DISCARD = EventLogErrorFlags.Discard
6+
IGNORE = EventLogErrorFlags.Ignore
7+
STRICT = EventLogErrorFlags.Strict
8+
WARN = EventLogErrorFlags.Warn

0 commit comments

Comments
 (0)