Skip to content

Commit

Permalink
Merge pull request #78 from fjarri-eth/restore-complicated-test
Browse files Browse the repository at this point in the history
Restore the complicated contract test
  • Loading branch information
fjarri authored May 29, 2024
2 parents 53e648b + e8b649c commit 39d44a2
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 25 deletions.
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Added
- Support for the ``logs`` field in ``TxReceipt``. (PR_68_)
- ``ClientSession.eth_get_logs()`` and ``eth_get_filter_logs()``. (PR_68_)
- Support for a custom block number in gas estimation methods. (PR_70_)
- ``LocalProvider`` accepts an ``evm_version`` parameter. (PR_78_)


Fixed
Expand Down Expand Up @@ -71,6 +72,7 @@ Fixed
.. _PR_75: https://github.com/fjarri-eth/pons/pull/75
.. _PR_76: https://github.com/fjarri-eth/pons/pull/76
.. _PR_77: https://github.com/fjarri-eth/pons/pull/77
.. _PR_78: https://github.com/fjarri-eth/pons/pull/78


0.7.0 (09-07-2023)
Expand Down
14 changes: 11 additions & 3 deletions pons/_local_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from copy import deepcopy
from typing import Any

from alysis import Node, RPCNode
from alysis import EVMVersion, Node, RPCNode
from eth_account import Account
from ethereum_rpc import Amount

Expand All @@ -27,8 +27,16 @@ class LocalProvider(Provider):
root: Signer
"""The signer for the pre-created account."""

def __init__(self, *, root_balance: Amount, chain_id: int = 1):
self._local_node = Node(root_balance_wei=root_balance.as_wei(), chain_id=chain_id)
def __init__(
self,
*,
root_balance: Amount,
chain_id: int = 1,
evm_version: EVMVersion = EVMVersion.CANCUN,
):
self._local_node = Node(
root_balance_wei=root_balance.as_wei(), chain_id=chain_id, evm_version=evm_version
)
self._rpc_node = RPCNode(self._local_node)
self.root = AccountSigner(Account.from_key(self._local_node.root_private_key))
self._default_address = self.root.address
Expand Down
27 changes: 12 additions & 15 deletions tests/TestContractFunctionality.sol
Original file line number Diff line number Diff line change
Expand Up @@ -68,38 +68,35 @@ contract Test {

struct ByteInner {
bytes4 inner1;
bytes10 inner2;
bytes inner2;
}

struct Foo {
bytes4 foo1;
bytes2[2] foo2;
bytes6 foo3;
bytes foo3;
string foo4;
ByteInner inner;
}

event Complicated(
bytes4 indexed x,
bytes8 indexed y,
bytes indexed y,
Foo indexed u,
ByteInner[2] indexed v
) anonymous;

function emitComplicated() public {
bytes memory bytestring33len1 = "012345678901234567890123456789012";
bytes memory bytestring33len2 = "-12345678901234567890123456789012";
ByteInner memory inner1 = ByteInner("0123", bytestring33len1);
ByteInner memory inner2 = ByteInner("-123", bytestring33len2);
bytes2 x = "aa";
bytes2 y = "bb";
emit Complicated(
"aaaa",
"55555555",
Foo(
"4567", [x, y],
"444444",
ByteInner("0123", "3333333333")
),
[
ByteInner("0123", "1111111111"),
ByteInner("-123", "2222222222")
]);
bytes2[2] memory foo2 = [x, y];
Foo memory foo = Foo("4567", foo2, bytestring33len1, "\u1234\u1212", inner1);
ByteInner[2] memory inner_arr = [inner1, inner2];
emit Complicated("aaaa", bytestring33len2, foo, inner_arr);
}

error MyError(address sender);
Expand Down
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import pytest
from alysis import EVMVersion
from ethereum_rpc import Amount

from pons import AccountSigner, Client, LocalProvider


@pytest.fixture
def local_provider():
return LocalProvider(root_balance=Amount.ether(100))
return LocalProvider(root_balance=Amount.ether(100), evm_version=EVMVersion.CANCUN)


@pytest.fixture
Expand Down
17 changes: 11 additions & 6 deletions tests/test_contract_functionality.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Constructor,
ContractABI,
DeployedContract,
EVMVersion,
Method,
Mutability,
abi,
Expand All @@ -17,7 +18,7 @@
@pytest.fixture
def compiled_contracts():
path = Path(__file__).resolve().parent / "TestContractFunctionality.sol"
return compile_contract_file(path)
return compile_contract_file(path, evm_version=EVMVersion.CANCUN)


async def test_empty_constructor(session, root_signer, compiled_contracts):
Expand Down Expand Up @@ -161,12 +162,16 @@ async def test_complicated_event(session, root_signer, compiled_contracts):

basic_contract = compiled_contracts["Test"]

inner1 = [b"0123", b"1111111111"]
inner2 = [b"-123", b"2222222222"]
foo = [b"4567", [b"aa", b"bb"], b"444444", [b"0123", b"3333333333"]]
event_filter = basic_contract.abi.event.Complicated(b"aaaa", b"55555555", foo, [inner1, inner2])
bytestring33len1 = b"012345678901234567890123456789012"
bytestring33len2 = b"-12345678901234567890123456789012"
inner1 = [b"0123", bytestring33len1]
inner2 = [b"-123", bytestring33len2]
foo = [b"4567", [b"aa", b"bb"], bytestring33len1, "\u1234\u1212", inner1]
event_filter = basic_contract.abi.event.Complicated(
b"aaaa", bytestring33len2, foo, [inner1, inner2]
)

contract = await session.deploy(root_signer, basic_contract.constructor(123, 456))
contract = await session.deploy(root_signer, basic_contract.constructor(12345, 56789))

log_filter1 = await session.eth_new_filter(event_filter=event_filter) # filter by topics
log_filter2 = await session.eth_new_filter() # collect everything
Expand Down

0 comments on commit 39d44a2

Please sign in to comment.