Skip to content

Commit

Permalink
Modify test related files
Browse files Browse the repository at this point in the history
  • Loading branch information
cc7768 committed Nov 19, 2021
1 parent 35c00f1 commit e981622
Show file tree
Hide file tree
Showing 4 changed files with 306 additions and 258 deletions.
2 changes: 2 additions & 0 deletions tests/core/contracts/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,7 @@ class LogFunctions:
LogTripleWithIndex = 10
LogQuadrupleWithIndex = 11
LogBytes = 12
LogStructArgs = 13


@pytest.fixture()
Expand Down Expand Up @@ -975,6 +976,7 @@ class LogTopics:
LogListArgs = _encode_to_topic("LogListArgs(bytes2[],bytes2[])")
LogAddressIndexed = _encode_to_topic("LogAddressIndexed(address,address)")
LogAddressNotIndexed = _encode_to_topic("LogAddressNotIndexed(address,address)")
LogStructArgs = _encode_to_topic("LogStructArgs(uint256,tuple)")


@pytest.fixture()
Expand Down
25 changes: 19 additions & 6 deletions tests/core/contracts/contract_sources/Emitter.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.21;
pragma solidity ^0.8.7;


contract Emitter {
Expand All @@ -23,6 +23,13 @@ contract Emitter {
event LogAddressIndexed(address indexed arg0, address arg1);
event LogAddressNotIndexed(address arg0, address arg1);

// Nested type functionality
struct TestTuple {
uint a;
uint b;
}
event LogStructArgs(uint arg0, TestTuple arg1);

enum WhichEvent {
LogAnonymous,
LogNoArguments,
Expand All @@ -41,7 +48,8 @@ contract Emitter {
LogDynamicArgs,
LogListArgs,
LogAddressIndexed,
LogAddressNotIndexed
LogAddressNotIndexed,
LogStructArgs
}

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

function logDynamicArgs(string arg0, string arg1) public {
function logDynamicArgs(string memory arg0, string memory arg1) public {
emit LogDynamicArgs(arg0, arg1);
}

function logListArgs(bytes2[] arg0, bytes2[] arg1) public {
function logListArgs(bytes2[] memory arg0, bytes2[] memory arg1) public {
emit LogListArgs(arg0, arg1);
}

Expand All @@ -92,11 +100,16 @@ contract Emitter {
emit LogAddressNotIndexed(arg0, arg1);
}

function logBytes(bytes v) public {
function logBytes(bytes memory v) public {
emit LogBytes(v);
}

function logString(string v) public {
function logString(string memory v) public {
emit LogString(v);
}

function logStruct(uint arg0, TestTuple memory arg1) public {
emit LogStructArgs(arg0, arg1);
}
}

24 changes: 24 additions & 0 deletions tests/core/contracts/test_extracting_event_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ def dup_txn_receipt(
[12345, 54321, 98765, 56789],
{'arg0': 12345, 'arg1': 54321, 'arg2': 98765, 'arg3': 56789},
),
(
'logStruct',
'LogStructArgs',
[12345, {'a': 0, 'b': 1}],
{'arg0': 12345, 'arg1': {'a': 0, 'b': 1}},
)
)
)
def test_event_data_extraction(web3,
Expand All @@ -159,6 +165,8 @@ def test_event_data_extraction(web3,
event_name,
call_args,
expected_args):
print(call_args)
print(expected_args)
emitter_fn = emitter.functions[contract_fn]
event_id = getattr(emitter_event_ids, event_name)
txn_hash = emitter_fn(event_id, *call_args).transact()
Expand Down Expand Up @@ -558,6 +566,22 @@ def test_argument_extraction_strict_bytes_types(w3_strict_abi,
'The event signature did not match the provided ABI',
False,
),
(
'logStruct',
'logStructArgs',
[12345, {'a': 0, 'b': 1}],
{'arg0': 12345, 'arg1': {'a': 0, 'b': 1}},
'The event signature did not match the provided ABI',
True,
),
(
'logStruct',
'logStructArgs',
[12345, {'a': 0, 'b': 1}],
{'arg0': 12345, 'arg1': {'a': 0, 'b': 1}},
'The event signature did not match the provided ABI',
False,
),
)
)
def test_event_rich_log(
Expand Down
Loading

0 comments on commit e981622

Please sign in to comment.