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 c7807f7 commit de098c7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 23 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})
9 changes: 5 additions & 4 deletions web3/utils/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ def construct_event_filter_params(event_abi,
toBlock=None,
address=None):
filter_params = {}
topic_set = construct_event_topic_set(event_abi, argument_filters)

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)
if topics is not None and len(topic_set) != 0:
raise TypeError(
"Merging the topics argument with topics generated "
"from argument_filters is not supported.")

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

0 comments on commit de098c7

Please sign in to comment.