Skip to content

Commit

Permalink
Disallow merging topic lists
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanjw committed Jul 30, 2018
1 parent f69f30e commit 28b1a2d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 33 deletions.
27 changes: 8 additions & 19 deletions tests/core/filtering/test_contract_createFilter_topic_merging.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import pytest


def test_merged_topic_list_event(
web3,
emitter,
Expand All @@ -9,22 +12,8 @@ def test_merged_topic_list_event(
'0x0000000000000000000000000000000000000000000000000000000000000457', # 1111
'0x0000000000000000000000000000000000000000000000000000000000000457', # 1111
]
log_filter = emitter.events.LogTripleWithIndex().createFilter(
fromBlock="latest",
topics=manual_topics,
argument_filters={'arg0': 2222, 'arg1': 2222, 'arg2': 2222})
event_id = getattr(emitter_event_ids, 'LogTripleWithIndex')
txn_hashes = [
emitter.functions.logTriple(event_id, 1111, 1111, 1111).transact(),
emitter.functions.logTriple(event_id, 1111, 1111, 2222).transact(),
emitter.functions.logTriple(event_id, 1111, 2222, 1111).transact(),
emitter.functions.logTriple(event_id, 2222, 1111, 1111).transact(),
emitter.functions.logTriple(event_id, 2222, 1111, 2222).transact(),
emitter.functions.logTriple(event_id, 1111, 2222, 2222).transact(),
emitter.functions.logTriple(event_id, 2222, 2222, 1111).transact(),
emitter.functions.logTriple(event_id, 2222, 2222, 2222).transact()
]
while True:
if all(wait_for_transaction(web3, txn_hash) for txn_hash in txn_hashes):
break
assert len(log_filter.get_all_entries()) == 2
with pytest.raises(TypeError):
emitter.events.LogTripleWithIndex().createFilter(
fromBlock="latest",
topics=manual_topics,
argument_filters={'arg0': 2222, 'arg1': 2222, 'arg2': 2222})
5 changes: 2 additions & 3 deletions tests/core/utilities/test_construct_event_filter_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@
(EVENT_1_ABI, {}, {
"topics": ['0xb470a829ed7792f06947f0ca3730a570cb378329ddcf09f2b4efabd6326f51f6'],
}),
(EVENT_1_ABI, {'topics': ['should-be-preserved']}, {
(EVENT_1_ABI, {'topics': ['should-overwrite-topics']}, {
"topics": [
['should-be-preserved'],
['0xb470a829ed7792f06947f0ca3730a570cb378329ddcf09f2b4efabd6326f51f6'],
'should-overwrite-topics'
]
}),
(EVENT_1_ABI, {'contract_address': '0xd3CdA913deB6f67967B99D67aCDFa1712C293601'}, {
Expand Down
11 changes: 5 additions & 6 deletions web3/utils/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
from web3.utils.normalizers import (
BASE_RETURN_NORMALIZERS,
)
from web3.utils.toolz import (
curry,
compose,
)

from .abi import (
exclude_indexed_event_inputs,
Expand Down Expand Up @@ -71,12 +75,7 @@ def construct_event_topic_set(event_abi, arguments=None):
for arg, arg_options in zipped_abi_and_args
]

topics = [
[event_topic] + list(permutation)
if any(value is not None for value in permutation)
else [event_topic]
for permutation in itertools.product(*encoded_args)
]
topics = list(normalize_topic_list([event_topic] + encoded_args))
return topics


Expand Down
13 changes: 8 additions & 5 deletions web3/utils/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ def construct_event_filter_params(event_abi,
toBlock=None,
address=None):
filter_params = {}

if topics is None:
topic_set = construct_event_topic_set(event_abi, argument_filters)
else:
topic_set = [topics] + construct_event_topic_set(event_abi, argument_filters)
topic_set = construct_event_topic_set(event_abi, argument_filters)

if topics is not None:
if len(topic_set) > 1:
raise TypeError(
"Merging the topics argument with topics generated "
"from argument_filters is not supported.")
topic_set = topics

if len(topic_set) == 1 and is_list_like(topic_set[0]):
filter_params['topics'] = topic_set[0]
Expand Down

0 comments on commit 28b1a2d

Please sign in to comment.