-
-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
82 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import pytest | ||
from ethpm_types import HexBytes | ||
from ethpm_types.abi import EventABI, EventABIType | ||
|
||
from ape.utils.abi import LogInputABICollection | ||
|
||
|
||
@pytest.fixture | ||
def event_abi(): | ||
return EventABI( | ||
type="event", | ||
name="NodeOperatorAdded", | ||
inputs=[ | ||
EventABIType( | ||
name="nodeOperatorId", | ||
type="uint256", | ||
components=None, | ||
internalType=None, | ||
indexed=False, | ||
), | ||
EventABIType( | ||
name="name", type="string", components=None, internalType=None, indexed=False | ||
), | ||
EventABIType( | ||
name="rewardAddress", | ||
type="address", | ||
components=None, | ||
internalType=None, | ||
indexed=False, | ||
), | ||
EventABIType( | ||
name="stakingLimit", | ||
type="uint64", | ||
components=None, | ||
internalType=None, | ||
indexed=False, | ||
), | ||
], | ||
anonymous=False, | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def collection(event_abi): | ||
return LogInputABICollection(event_abi) | ||
|
||
|
||
@pytest.fixture | ||
def topics(): | ||
return ["0xc52ec0ad7872dae440d886040390c13677df7bf3cca136d8d81e5e5e7dd62ff1"] | ||
|
||
|
||
@pytest.fixture | ||
def log_data_missing_trailing_zeroes(): | ||
return HexBytes( | ||
"0x000000000000000000000000000000000000000000000000000000000000001e" | ||
"000000000000000000000000000000000000000000000000000000000000008000" | ||
"00000000000000000000005a8b929edbf3ce44526465dd2087ec7efb59a5610000" | ||
"000000000000000000000000000000000000000000000000000000000000000000" | ||
"000000000000000000000000000000000000000000000000000000000b4c61756e" | ||
"63686e6f646573" | ||
) | ||
|
||
|
||
def test_decoding_with_strict(collection, topics, log_data_missing_trailing_zeroes, caplog): | ||
""" | ||
This test is for a time where Alchemy gave us log data when it was missing trailing zeroes. | ||
When using strict=False, it was able to properly decode. In this case, in Ape, we warn | ||
the user and still proceed to decode the log. | ||
""" | ||
actual = collection.decode(topics, log_data_missing_trailing_zeroes) | ||
expected = { | ||
"name": "Launchnodes", | ||
"nodeOperatorId": 30, | ||
"rewardAddress": "0x5a8b929edbf3ce44526465dd2087ec7efb59a561", | ||
"stakingLimit": 0, | ||
} | ||
assert actual == expected | ||
assert ( | ||
"However, we are able to get a value using decode(strict=False)" | ||
in caplog.records[-1].message | ||
) |