From e8b649c281477fa8aed6537498412a7e86ac416a Mon Sep 17 00:00:00 2001 From: Bogdan Opanchuk Date: Fri, 24 May 2024 23:15:10 -0700 Subject: [PATCH] Restore the complicated contract test --- docs/changelog.rst | 2 ++ pons/_local_provider.py | 14 +++++++++++--- tests/TestContractFunctionality.sol | 27 ++++++++++++--------------- tests/conftest.py | 3 ++- tests/test_contract_functionality.py | 17 +++++++++++------ 5 files changed, 38 insertions(+), 25 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 0ba8be2..ec3863f 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -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 @@ -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) diff --git a/pons/_local_provider.py b/pons/_local_provider.py index 8e7a0cd..eb35543 100644 --- a/pons/_local_provider.py +++ b/pons/_local_provider.py @@ -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 @@ -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 diff --git a/tests/TestContractFunctionality.sol b/tests/TestContractFunctionality.sol index 4d37208..7baf92e 100644 --- a/tests/TestContractFunctionality.sol +++ b/tests/TestContractFunctionality.sol @@ -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); diff --git a/tests/conftest.py b/tests/conftest.py index a0e575b..9051354 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,5 @@ import pytest +from alysis import EVMVersion from ethereum_rpc import Amount from pons import AccountSigner, Client, LocalProvider @@ -6,7 +7,7 @@ @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 diff --git a/tests/test_contract_functionality.py b/tests/test_contract_functionality.py index b00491d..b6b9955 100644 --- a/tests/test_contract_functionality.py +++ b/tests/test_contract_functionality.py @@ -7,6 +7,7 @@ Constructor, ContractABI, DeployedContract, + EVMVersion, Method, Mutability, abi, @@ -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): @@ -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