From 01e776fa05162909790f0dc0cdee41e6da450ec5 Mon Sep 17 00:00:00 2001 From: Mario Vega Date: Tue, 4 Jun 2024 02:22:28 +0000 Subject: [PATCH] fix(filler): Auto-fill pre --- src/ethereum_test_tools/spec/eof/eof_test.py | 16 ++++++++-------- src/pytest_plugins/test_filler/test_filler.py | 2 ++ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/ethereum_test_tools/spec/eof/eof_test.py b/src/ethereum_test_tools/spec/eof/eof_test.py index 8cb9b69eb5..ff7ab29de7 100644 --- a/src/ethereum_test_tools/spec/eof/eof_test.py +++ b/src/ethereum_test_tools/spec/eof/eof_test.py @@ -15,9 +15,8 @@ from ethereum_test_forks import Fork from evm_transition_tool import FixtureFormats, TransitionTool -from ...common import Account, Address, Alloc, Environment, Transaction +from ...common import Account, Alloc, Environment, Transaction from ...common.base_types import Bytes -from ...common.constants import TestAddress from ...eof.v1 import Container from ...exceptions import EOFException, EvmoneExceptionMapper from ..base.base_test import BaseFixture, BaseTest @@ -267,8 +266,10 @@ class EOFStateTest(EOFTest): tx_gas_limit: int = 10_000_000 tx_data: Bytes = Bytes(b"") + tx_sender_funding_amount: int = 1_000_000_000_000_000_000_000 env: Environment = Field(default_factory=Environment) container_post: Account = Field(default_factory=Account) + pre: Alloc | None = None supported_fixture_formats: ClassVar[List[FixtureFormats]] = [ FixtureFormats.EOF_TEST, @@ -288,22 +289,21 @@ def generate_state_test(self) -> StateTest: """ Generate the StateTest filler. """ - pre = Alloc() - container_address = Address(0x100) - pre[container_address] = Account(code=self.data, nonce=1) - pre[TestAddress] = Account(balance=1_000_000_000_000_000_000_000, nonce=0) + assert self.pre is not None, "pre must be set to generate a StateTest." + container_address = self.pre.deploy_contract(code=self.data) + sender = self.pre.fund_sender(amount=self.tx_sender_funding_amount) tx = Transaction( - nonce=0, to=container_address, gas_limit=self.tx_gas_limit, gas_price=10, protected=False, data=self.tx_data, + sender=sender, ) post = Alloc() post[container_address] = self.container_post return StateTest( - pre=pre, + pre=self.pre, tx=tx, env=self.env, post=post, diff --git a/src/pytest_plugins/test_filler/test_filler.py b/src/pytest_plugins/test_filler/test_filler.py index 7f4e4c34b1..dfdb4aac32 100644 --- a/src/pytest_plugins/test_filler/test_filler.py +++ b/src/pytest_plugins/test_filler/test_filler.py @@ -650,6 +650,8 @@ def base_test_parametrizer_func( class BaseTestWrapper(cls): def __init__(self, *args, **kwargs): kwargs["t8n_dump_dir"] = dump_dir_parameter_level + if "pre" not in kwargs: + kwargs["pre"] = request.getfixturevalue("pre") super(BaseTestWrapper, self).__init__(*args, **kwargs) fixture = self.generate( t8n=t8n,