-
Notifications
You must be signed in to change notification settings - Fork 153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix topic_list parameter implementation (matching and validation) to align with JSON-RPC spec #118
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,8 +15,9 @@ | |
check_if_log_matches, | ||
is_topic, | ||
is_flat_topic_array, | ||
is_nested_topic_array, | ||
is_valid_with_nested_topic_array, | ||
is_topic_array, | ||
extrapolate_flat_topic_from_topic_list, | ||
) | ||
|
||
|
||
|
@@ -101,7 +102,7 @@ def test_is_topic(value, expected): | |
(TOPICS_MANY_WITH_NULL, True), | ||
) | ||
) | ||
def test_is_flat_topic_array(value, expected): | ||
def test_is_valid_topic_array_with_flat_topic_arrays(value, expected): | ||
actual = is_flat_topic_array(value) | ||
assert actual is expected | ||
|
||
|
@@ -110,6 +111,7 @@ def test_is_flat_topic_array(value, expected): | |
NESTED_TOPICS_B = (TOPICS_EMPTY, TOPICS_SINGLE_NULL) | ||
NESTED_TOPICS_C = (TOPICS_SINGLE_NULL, TOPICS_MANY) | ||
NESTED_TOPICS_D = (TOPICS_MANY_WITH_NULL, TOPICS_MANY, TOPICS_EMPTY) | ||
NESTED_TOPICS_E = (TOPIC_A, TOPICS_MANY, TOPICS_EMPTY) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
|
@@ -130,25 +132,26 @@ def test_is_flat_topic_array(value, expected): | |
([b'a', None, b'b'], False), | ||
(list(), False), | ||
([None], False), | ||
(TOPIC_A, False), | ||
(TOPICS_EMPTY, False), | ||
(TOPICS_SINGLE_NULL, False), | ||
(TOPICS_MANY, False), | ||
(TOPICS_MANY_WITH_NULL, False), | ||
(([],), False), | ||
(([tuple()],), False), | ||
([tuple()], False), | ||
((tuple(), []), False), | ||
((TOPICS_EMPTY, (b'arst',)), False), | ||
(TOPIC_A, False), | ||
(TOPICS_EMPTY, False), | ||
# good values | ||
(TOPICS_SINGLE_NULL, True), | ||
(TOPICS_MANY, True), | ||
(TOPICS_MANY_WITH_NULL, True), | ||
(NESTED_TOPICS_A, True), | ||
(NESTED_TOPICS_B, True), | ||
(NESTED_TOPICS_C, True), | ||
(NESTED_TOPICS_D, True), | ||
(NESTED_TOPICS_E, True), | ||
) | ||
) | ||
def test_is_nested_topic_array(value, expected): | ||
actual = is_nested_topic_array(value) | ||
def test_is_valid_with_nested_topic_array(value, expected): | ||
actual = is_valid_with_nested_topic_array(value) | ||
assert actual is expected | ||
|
||
|
||
|
@@ -272,12 +275,12 @@ def test_check_if_to_block_match(block_number, _type, to_block, expected): | |
|
||
|
||
FILTER_MATCH_ALL = tuple() | ||
FILTER_MATCH_ANY_ONE = (None,) | ||
FILTER_MATCH_ANY_TWO = (None, None) | ||
FILTER_MATCH_ANY_THREE = (None, None, None) | ||
FILTER_MATCH_ONLY_A = (TOPIC_A,) | ||
FILTER_MATCH_ONLY_B = (TOPIC_B,) | ||
FILTER_MATCH_ONLY_C = (TOPIC_C,) | ||
FILTER_MATCH_ONE_OR_MORE = (None,) | ||
FILTER_MATCH_TWO_OR_MORE = (None, None) | ||
FILTER_MATCH_THREE_OR_MORE = (None, None, None) | ||
FILTER_MATCH_A = (TOPIC_A,) | ||
FILTER_MATCH_B = (TOPIC_B,) | ||
FILTER_MATCH_C = (TOPIC_C,) | ||
FILTER_MATCH_A_ANY = (TOPIC_A, None) | ||
FILTER_MATCH_B_ANY = (TOPIC_B, None) | ||
FILTER_MATCH_C_ANY = (TOPIC_C, None) | ||
|
@@ -308,38 +311,38 @@ def test_check_if_to_block_match(block_number, _type, to_block, expected): | |
(TOPICS_B_A_C, FILTER_MATCH_ALL, True), | ||
(TOPICS_B_C_A, FILTER_MATCH_ALL, True), | ||
# length 1 matches | ||
(TOPICS_EMPTY, FILTER_MATCH_ANY_ONE, False), | ||
(TOPICS_ONLY_A, FILTER_MATCH_ANY_ONE, True), | ||
(TOPICS_ONLY_B, FILTER_MATCH_ANY_ONE, True), | ||
(TOPICS_ONLY_C, FILTER_MATCH_ANY_ONE, True), | ||
(TOPICS_EMPTY, FILTER_MATCH_ONLY_A, False), | ||
(TOPICS_EMPTY, FILTER_MATCH_ONLY_B, False), | ||
(TOPICS_EMPTY, FILTER_MATCH_ONLY_C, False), | ||
(TOPICS_ONLY_A, FILTER_MATCH_ONLY_A, True), | ||
(TOPICS_ONLY_B, FILTER_MATCH_ONLY_B, True), | ||
(TOPICS_ONLY_C, FILTER_MATCH_ONLY_C, True), | ||
(TOPICS_ONLY_B, FILTER_MATCH_ONLY_A, False), | ||
(TOPICS_ONLY_C, FILTER_MATCH_ONLY_A, False), | ||
(TOPICS_ONLY_A, FILTER_MATCH_ONLY_B, False), | ||
(TOPICS_ONLY_C, FILTER_MATCH_ONLY_B, False), | ||
(TOPICS_ONLY_A, FILTER_MATCH_ONLY_C, False), | ||
(TOPICS_ONLY_B, FILTER_MATCH_ONLY_C, False), | ||
(TOPICS_A_A, FILTER_MATCH_ONLY_A, True), | ||
(TOPICS_A_B, FILTER_MATCH_ONLY_A, True), | ||
(TOPICS_A_C, FILTER_MATCH_ONLY_A, True), | ||
(TOPICS_A_B_C, FILTER_MATCH_ONLY_A, True), | ||
(TOPICS_A_C_B, FILTER_MATCH_ONLY_A, True), | ||
(TOPICS_B_A, FILTER_MATCH_ONLY_A, False), | ||
(TOPICS_B_C, FILTER_MATCH_ONLY_A, False), | ||
(TOPICS_B_A_C, FILTER_MATCH_ONLY_A, False), | ||
(TOPICS_B_C_A, FILTER_MATCH_ONLY_A, False), | ||
(TOPICS_EMPTY, FILTER_MATCH_ONE_OR_MORE, False), | ||
(TOPICS_ONLY_A, FILTER_MATCH_ONE_OR_MORE, True), | ||
(TOPICS_ONLY_B, FILTER_MATCH_ONE_OR_MORE, True), | ||
(TOPICS_ONLY_C, FILTER_MATCH_ONE_OR_MORE, True), | ||
(TOPICS_EMPTY, FILTER_MATCH_A, False), | ||
(TOPICS_EMPTY, FILTER_MATCH_B, False), | ||
(TOPICS_EMPTY, FILTER_MATCH_C, False), | ||
(TOPICS_ONLY_A, FILTER_MATCH_A, True), | ||
(TOPICS_ONLY_B, FILTER_MATCH_B, True), | ||
(TOPICS_ONLY_C, FILTER_MATCH_C, True), | ||
(TOPICS_ONLY_B, FILTER_MATCH_A, False), | ||
(TOPICS_ONLY_C, FILTER_MATCH_A, False), | ||
(TOPICS_ONLY_A, FILTER_MATCH_B, False), | ||
(TOPICS_ONLY_C, FILTER_MATCH_B, False), | ||
(TOPICS_ONLY_A, FILTER_MATCH_C, False), | ||
(TOPICS_ONLY_B, FILTER_MATCH_C, False), | ||
(TOPICS_A_A, FILTER_MATCH_A, True), | ||
(TOPICS_A_B, FILTER_MATCH_A, True), | ||
(TOPICS_A_C, FILTER_MATCH_A, True), | ||
(TOPICS_A_B_C, FILTER_MATCH_A, True), | ||
(TOPICS_A_C_B, FILTER_MATCH_A, True), | ||
(TOPICS_B_A, FILTER_MATCH_A, False), | ||
(TOPICS_B_C, FILTER_MATCH_A, False), | ||
(TOPICS_B_A_C, FILTER_MATCH_A, False), | ||
(TOPICS_B_C_A, FILTER_MATCH_A, False), | ||
# length 2 matches | ||
(TOPICS_EMPTY, FILTER_MATCH_ANY_TWO, False), | ||
(TOPICS_A_A, FILTER_MATCH_ANY_TWO, True), | ||
(TOPICS_A_B, FILTER_MATCH_ANY_TWO, True), | ||
(TOPICS_ONLY_A, FILTER_MATCH_ANY_TWO, False), | ||
(TOPICS_ONLY_B, FILTER_MATCH_ANY_TWO, False), | ||
(TOPICS_ONLY_C, FILTER_MATCH_ANY_TWO, False), | ||
(TOPICS_EMPTY, FILTER_MATCH_TWO_OR_MORE, False), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same assumption here. That a None value matches any topic that exists at that position, but not an absent topic. |
||
(TOPICS_A_A, FILTER_MATCH_TWO_OR_MORE, True), | ||
(TOPICS_A_B, FILTER_MATCH_TWO_OR_MORE, True), | ||
(TOPICS_ONLY_A, FILTER_MATCH_TWO_OR_MORE, False), | ||
(TOPICS_ONLY_B, FILTER_MATCH_TWO_OR_MORE, False), | ||
(TOPICS_ONLY_C, FILTER_MATCH_TWO_OR_MORE, False), | ||
(TOPICS_A_A, FILTER_MATCH_A_B, False), | ||
(TOPICS_A_B, FILTER_MATCH_A_B, True), | ||
(TOPICS_A_B_C, FILTER_MATCH_A_B, True), | ||
|
@@ -368,26 +371,29 @@ def test_check_if_to_block_match(block_number, _type, to_block, expected): | |
(TOPICS_A_B, FILTER_MATCH_ANY_C, False), | ||
(TOPICS_A_B_C, FILTER_MATCH_ANY_C, False), | ||
# length 3 matches | ||
(TOPICS_EMPTY, FILTER_MATCH_ANY_THREE, False), | ||
(TOPICS_A_B_C, FILTER_MATCH_ANY_THREE, True), | ||
(TOPICS_A_C_B, FILTER_MATCH_ANY_THREE, True), | ||
(TOPICS_B_A_C, FILTER_MATCH_ANY_THREE, True), | ||
(TOPICS_B_C_A, FILTER_MATCH_ANY_THREE, True), | ||
(TOPICS_A_A, FILTER_MATCH_ANY_THREE, False), | ||
(TOPICS_EMPTY, FILTER_MATCH_THREE_OR_MORE, False), | ||
(TOPICS_A_B_C, FILTER_MATCH_THREE_OR_MORE, True), | ||
(TOPICS_A_C_B, FILTER_MATCH_THREE_OR_MORE, True), | ||
(TOPICS_B_A_C, FILTER_MATCH_THREE_OR_MORE, True), | ||
(TOPICS_B_C_A, FILTER_MATCH_THREE_OR_MORE, True), | ||
(TOPICS_A_A, FILTER_MATCH_THREE_OR_MORE, False), | ||
(TOPICS_A_B_C, FILTER_MATCH_A_B_C, True), | ||
(TOPICS_A_C_B, FILTER_MATCH_A_B_C, False), | ||
(TOPICS_A_C_B, FILTER_MATCH_A_C_B, True), | ||
(TOPICS_A_B_C, FILTER_MATCH_A_C_B, False), | ||
# nested matches | ||
(TOPICS_EMPTY, (FILTER_MATCH_ONLY_A, FILTER_MATCH_ONLY_B, FILTER_MATCH_ONLY_C), False), | ||
(TOPICS_ONLY_A, (FILTER_MATCH_ONLY_A, FILTER_MATCH_ONLY_B, FILTER_MATCH_ONLY_C), True), | ||
(TOPICS_ONLY_B, (FILTER_MATCH_ONLY_A, FILTER_MATCH_ONLY_B, FILTER_MATCH_ONLY_C), True), | ||
(TOPICS_ONLY_C, (FILTER_MATCH_ONLY_A, FILTER_MATCH_ONLY_B, FILTER_MATCH_ONLY_C), True), | ||
(TOPICS_A_B, (FILTER_MATCH_ONLY_B, FILTER_MATCH_ONLY_C), False), | ||
(TOPICS_A_B, (FILTER_MATCH_ONLY_B, FILTER_MATCH_ONLY_C, FILTER_MATCH_ONLY_A), True), | ||
# positional topic options matches | ||
(TOPICS_EMPTY, (FILTER_MATCH_A, FILTER_MATCH_B, FILTER_MATCH_C), False), | ||
(TOPICS_ONLY_A, (FILTER_MATCH_A, FILTER_MATCH_B, FILTER_MATCH_C), False), | ||
(TOPICS_ONLY_B, (FILTER_MATCH_A, FILTER_MATCH_B, FILTER_MATCH_C), False), | ||
(TOPICS_ONLY_C, (FILTER_MATCH_A, FILTER_MATCH_B, FILTER_MATCH_C), False), | ||
(TOPICS_A_B, (FILTER_MATCH_B, FILTER_MATCH_C), False), | ||
(TOPICS_A_B, (FILTER_MATCH_B, FILTER_MATCH_C, FILTER_MATCH_A), False), | ||
(TOPICS_A_C, (FILTER_MATCH_A_ANY, FILTER_MATCH_ANY_A), True), | ||
(TOPICS_B_A, (FILTER_MATCH_A_ANY, FILTER_MATCH_ANY_A), True), | ||
(TOPICS_B_C, (FILTER_MATCH_A_ANY, FILTER_MATCH_ANY_A), False), | ||
(TOPICS_B_C, (FILTER_MATCH_A_ANY, FILTER_MATCH_ANY_A), True), | ||
(TOPICS_A_B_C, (FILTER_MATCH_A, FILTER_MATCH_A_B_C, FILTER_MATCH_C), True), | ||
(TOPICS_A_B_C, (FILTER_MATCH_A, FILTER_MATCH_A_C_B, FILTER_MATCH_C), True), | ||
(TOPICS_A_B_C, (FILTER_MATCH_A, FILTER_MATCH_A_C_B, TOPIC_C), True), | ||
), | ||
ids=topic_id, | ||
) | ||
|
@@ -464,8 +470,8 @@ def _make_filter(from_block=None, to_block=None, topics=None, addresses=None): | |
# topics | ||
(_make_log(topics=(TOPIC_A,)), _make_filter(topics=FILTER_MATCH_ALL), True), | ||
(_make_log(topics=(TOPIC_A, TOPIC_B)), _make_filter(topics=FILTER_MATCH_ALL), True), | ||
(_make_log(topics=(TOPIC_A,)), _make_filter(topics=FILTER_MATCH_ONLY_A), True), | ||
(_make_log(topics=(TOPIC_B,)), _make_filter(topics=FILTER_MATCH_ONLY_A), False), | ||
(_make_log(topics=(TOPIC_A,)), _make_filter(topics=FILTER_MATCH_A), True), | ||
(_make_log(topics=(TOPIC_B,)), _make_filter(topics=FILTER_MATCH_A), False), | ||
(_make_log(topics=(TOPIC_A, TOPIC_A)), _make_filter(topics=FILTER_MATCH_A_ANY), True), | ||
(_make_log(topics=(TOPIC_A, TOPIC_B)), _make_filter(topics=FILTER_MATCH_A_ANY), True), | ||
(_make_log(topics=(TOPIC_B, TOPIC_A)), _make_filter(topics=FILTER_MATCH_A_ANY), False), | ||
|
@@ -491,3 +497,31 @@ def _make_filter(from_block=None, to_block=None, topics=None, addresses=None): | |
def test_check_if_log_matches(log_entry, filter_params, expected): | ||
actual = check_if_log_matches(log_entry, **filter_params) | ||
assert actual == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'topic_list_input,expected_flat_topics', | ||
( | ||
( | ||
('A', ('A','B'), 'A'), | ||
( | ||
('A', 'A', 'A'), | ||
('A', 'B', 'A') | ||
), | ||
), | ||
( | ||
('A', ('A','B', 'C'), ('A', 'B')), | ||
( | ||
('A', 'A', 'A'), | ||
('A', 'A', 'B'), | ||
('A', 'B', 'A'), | ||
('A', 'B', 'B'), | ||
('A', 'C', 'A'), | ||
('A', 'C', 'B') | ||
), | ||
) | ||
) | ||
) | ||
def test_extrapolate_flat_topic_from_topic_list(topic_list_input, expected_flat_topics): | ||
assert tuple(extrapolate_flat_topic_from_topic_list(topic_list_input)) == expected_flat_topics | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one im not sure on. Intuitively I would think
(None,)
should match all non-anonymous events excluding anonymous ones, but that is assuming.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests results from ethereum/web3.py#985 show that clients diverge in how they treat None values. go-ethereum interprets None as matching any thing, and parity will match anything even the absence of a value.
I think it is up to us to decide what makes the most sense.
What should happen in these cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parity version makes more sense to me. You can already get the geth like functionally by removing the None.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parity doesn't allow things like matching any one, or any two, like go-ethereum does. go-ethereum essentially treats None as a place specific wildcard. On the other hand None feels like a bad choice for a wildcard symbol, and is more intuitive that it provide no actual matching function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, right, I got them switched up. The geth one makes more sense to me, too. 👍