Skip to content

Commit b47e2a5

Browse files
cc7768fselmo
authored andcommitted
Implement fix proposed in #1484
1 parent 6a90a26 commit b47e2a5

File tree

5 files changed

+306
-259
lines changed

5 files changed

+306
-259
lines changed

tests/core/contracts/conftest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,7 @@ class LogFunctions:
943943
LogTripleWithIndex = 10
944944
LogQuadrupleWithIndex = 11
945945
LogBytes = 12
946+
LogStructArgs = 13
946947

947948

948949
@pytest.fixture()
@@ -975,6 +976,7 @@ class LogTopics:
975976
LogListArgs = _encode_to_topic("LogListArgs(bytes2[],bytes2[])")
976977
LogAddressIndexed = _encode_to_topic("LogAddressIndexed(address,address)")
977978
LogAddressNotIndexed = _encode_to_topic("LogAddressNotIndexed(address,address)")
979+
LogStructArgs = _encode_to_topic("LogStructArgs(uint256,tuple)")
978980

979981

980982
@pytest.fixture()

tests/core/contracts/contract_sources/Emitter.sol

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pragma solidity ^0.4.21;
1+
pragma solidity ^0.8.7;
22

33

44
contract Emitter {
@@ -23,6 +23,13 @@ contract Emitter {
2323
event LogAddressIndexed(address indexed arg0, address arg1);
2424
event LogAddressNotIndexed(address arg0, address arg1);
2525

26+
// Nested type functionality
27+
struct TestTuple {
28+
uint a;
29+
uint b;
30+
}
31+
event LogStructArgs(uint arg0, TestTuple arg1);
32+
2633
enum WhichEvent {
2734
LogAnonymous,
2835
LogNoArguments,
@@ -41,7 +48,8 @@ contract Emitter {
4148
LogDynamicArgs,
4249
LogListArgs,
4350
LogAddressIndexed,
44-
LogAddressNotIndexed
51+
LogAddressNotIndexed,
52+
LogStructArgs
4553
}
4654

4755
function logNoArgs(WhichEvent which) public {
@@ -76,11 +84,11 @@ contract Emitter {
7684
else revert("Didn't match any allowable event index");
7785
}
7886

79-
function logDynamicArgs(string arg0, string arg1) public {
87+
function logDynamicArgs(string memory arg0, string memory arg1) public {
8088
emit LogDynamicArgs(arg0, arg1);
8189
}
8290

83-
function logListArgs(bytes2[] arg0, bytes2[] arg1) public {
91+
function logListArgs(bytes2[] memory arg0, bytes2[] memory arg1) public {
8492
emit LogListArgs(arg0, arg1);
8593
}
8694

@@ -92,11 +100,16 @@ contract Emitter {
92100
emit LogAddressNotIndexed(arg0, arg1);
93101
}
94102

95-
function logBytes(bytes v) public {
103+
function logBytes(bytes memory v) public {
96104
emit LogBytes(v);
97105
}
98106

99-
function logString(string v) public {
107+
function logString(string memory v) public {
100108
emit LogString(v);
101109
}
110+
111+
function logStruct(uint arg0, TestTuple memory arg1) public {
112+
emit LogStructArgs(arg0, arg1);
113+
}
102114
}
115+

tests/core/contracts/test_extracting_event_data.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ def dup_txn_receipt(
148148
[12345, 54321, 98765, 56789],
149149
{'arg0': 12345, 'arg1': 54321, 'arg2': 98765, 'arg3': 56789},
150150
),
151+
(
152+
'logStruct',
153+
'LogStructArgs',
154+
[12345, {'a': 0, 'b': 1}],
155+
{'arg0': 12345, 'arg1': {'a': 0, 'b': 1}},
156+
)
151157
)
152158
)
153159
def test_event_data_extraction(web3,
@@ -558,6 +564,22 @@ def test_argument_extraction_strict_bytes_types(w3_strict_abi,
558564
'The event signature did not match the provided ABI',
559565
False,
560566
),
567+
(
568+
'logStruct',
569+
'logStructArgs',
570+
[12345, {'a': 0, 'b': 1}],
571+
{'arg0': 12345, 'arg1': {'a': 0, 'b': 1}},
572+
'The event signature did not match the provided ABI',
573+
True,
574+
),
575+
(
576+
'logStruct',
577+
'logStructArgs',
578+
[12345, {'a': 0, 'b': 1}],
579+
{'arg0': 12345, 'arg1': {'a': 0, 'b': 1}},
580+
'The event signature did not match the provided ABI',
581+
False,
582+
),
561583
)
562584
)
563585
def test_event_rich_log(

web3/_utils/events.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
to_hex,
4040
to_tuple,
4141
)
42+
from eth_utils.abi import collapse_if_tuple
4243
from eth_utils.curried import (
4344
apply_formatter_if,
4445
)
@@ -193,7 +194,7 @@ def get_event_abi_types_for_decoding(event_inputs: Sequence[ABIEventParams]) ->
193194
if input_abi['indexed'] and is_dynamic_sized_type(input_abi['type']):
194195
yield 'bytes32'
195196
else:
196-
yield input_abi['type']
197+
yield collapse_if_tuple(input_abi)
197198

198199

199200
@curry

0 commit comments

Comments
 (0)