Skip to content

Commit 00b4fb3

Browse files
authored
refactor(plugins): Move pre-alloc logic to a separate filler plugin, rename test_filler (#692)
* refactor(plugins): Move pre-alloc logic to a separate filler pytest-plugin * fixup: docs navigation * refactor(plugins): rename `test_filler` -> `filler`
1 parent 1902472 commit 00b4fb3

File tree

21 files changed

+421
-243
lines changed

21 files changed

+421
-243
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Filler Plugin
2+
3+
::: pytest_plugins.filler
4+
5+
::: pytest_plugins.filler.filler
6+
7+
::: pytest_plugins.filler.pre_alloc
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!-- markdownlint-disable MD041 (MD0041=first-line-heading) -->
22
* [Overview](index.md)
33
* [Forks](forks.md)
4-
* [Test Filler](test_filler.md)
4+
* [Test Filler](filler.md)
55
* [Spec Version Checker](spec_version_checker.md)

docs/library/pytest_plugins/test_filler.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

docs/navigation.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,4 @@
4444
* [Ethereum Test VM Package](library/ethereum_test_vm.md)
4545
* [EVM Transition Tool Package](library/evm_transition_tool.md)
4646
* [Pytest Plugins](library/pytest_plugins/index.md)
47+
* [Filler Plugin](library/pytest_plugins/filler.md)

pytest-consume.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ addopts =
66
-rxXs
77
--tb short
88
-p pytest_plugins.consume.consume
9-
-p pytest_plugins.test_help.test_help
9+
-p pytest_plugins.help.help

pytest-framework.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ testpaths =
77
src
88
addopts =
99
-p pytester
10-
--ignore=src/pytest_plugins/test_filler/test_filler.py
1110
--ignore=src/pytest_plugins/consume/direct/test_direct.py
1211
--ignore=src/pytest_plugins/consume/hive_simulators/engine/test_via_engine.py
1312
--ignore=src/pytest_plugins/consume/hive_simulators/rlp/test_via_rlp.py

pytest.ini

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ testpaths = tests/
66
markers =
77
slow
88
addopts =
9-
-p pytest_plugins.test_filler.test_filler
9+
-p pytest_plugins.filler.pre_alloc
10+
-p pytest_plugins.filler.filler
1011
-p pytest_plugins.forks.forks
1112
-p pytest_plugins.spec_version_checker.spec_version_checker
12-
-p pytest_plugins.test_help.test_help
13+
-p pytest_plugins.help.help
1314
-m "not eip_version_check"
1415
--tb short
1516
--dist loadscope

src/cli/tests/test_pytest_commands.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import pytest
1010
from click.testing import CliRunner
1111

12-
import pytest_plugins.test_filler.test_filler
12+
import pytest_plugins.filler.filler
1313

1414
from ..pytest_commands import fill
1515

@@ -82,7 +82,7 @@ def default_html_report_filename(self):
8282
"""
8383
The default filename for fill's pytest html report.
8484
"""
85-
return pytest_plugins.test_filler.test_filler.default_html_report_filename()
85+
return pytest_plugins.filler.filler.default_html_report_filename()
8686

8787
@pytest.fixture(scope="function")
8888
def temp_dir(self) -> Generator[Path, None, None]: # noqa: D102
@@ -103,7 +103,7 @@ def mock_default_output_directory():
103103
return temp_dir
104104

105105
monkeypatch.setattr(
106-
pytest_plugins.test_filler.test_filler,
106+
pytest_plugins.filler.filler,
107107
"default_output_directory",
108108
mock_default_output_directory,
109109
)

src/ethereum_test_specs/tests/test_fixtures.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from click.testing import CliRunner
1111

1212
import cli.check_fixtures
13-
from ethereum_test_base_types import Account, Hash
13+
from ethereum_test_base_types import Account, Address, Hash
1414
from ethereum_test_exceptions import TransactionException
1515
from ethereum_test_fixtures import BlockchainFixture, FixtureFormats
1616
from ethereum_test_fixtures.blockchain import FixtureCommon
@@ -38,9 +38,9 @@ def hash(request: pytest.FixtureRequest):
3838
Set the hash based on the fork and solc version.
3939
"""
4040
if request.node.funcargs["fork"] == Berlin:
41-
return bytes.fromhex("0408c6a5c6")
41+
return bytes.fromhex("e57ad774ca")
4242
elif request.node.funcargs["fork"] == London:
43-
return bytes.fromhex("a1babd536a")
43+
return bytes.fromhex("3714102a4c")
4444

4545

4646
def test_check_helper_fixtures():
@@ -73,12 +73,16 @@ def test_check_helper_fixtures():
7373
def test_make_genesis(fork: Fork, hash: bytes): # noqa: D103
7474
env = Environment()
7575

76-
pre = Alloc()
77-
pre.deploy_contract(
78-
(Op.SSTORE(0, Op.ADD(1, 2)) + Op.RETURN(0, 32)),
79-
balance=0x0BA1A9CE0BA1A9CE,
76+
pre = Alloc(
77+
{
78+
Address(0x0BA1A9CE0BA1A9CE): Account(balance=0x0BA1A9CE0BA1A9CE),
79+
Address(0xC0DE): Account(
80+
code=Op.SSTORE(0, Op.ADD(1, 2)) + Op.RETURN(0, 32),
81+
balance=0x0BA1A9CE0BA1A9CE,
82+
nonce=1,
83+
),
84+
}
8085
)
81-
pre.fund_eoa(0x0BA1A9CE0BA1A9CE)
8286

8387
t8n = GethTransitionTool()
8488
fixture = BlockchainTest(

src/ethereum_test_tools/tests/test_code.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import pytest
99
from semver import Version
1010

11-
from ethereum_test_base_types import Account, Bytes, Hash
11+
from ethereum_test_base_types import Account, Address, Bytes, Hash, TestAddress, TestPrivateKey
1212
from ethereum_test_fixtures import FixtureFormats
1313
from ethereum_test_forks import (
1414
Cancun,
@@ -619,11 +619,15 @@ def test_switch(tx_data: bytes, switch_bytecode: bytes, expected_storage: Mappin
619619
"""
620620
Test that the switch opcode macro gets executed as using the t8n tool.
621621
"""
622-
pre = Alloc()
623-
code_address = pre.deploy_contract(switch_bytecode)
624-
sender = pre.fund_eoa(10_000_000)
625-
tx = Transaction(to=code_address, data=tx_data, gas_limit=1_000_000, sender=sender)
626-
post = {sender: Account(nonce=1), code_address: Account(storage=expected_storage)}
622+
code_address = Address(0x1000)
623+
pre = Alloc(
624+
{
625+
code_address: Account(code=switch_bytecode),
626+
TestAddress: Account(balance=10_000_000),
627+
}
628+
)
629+
tx = Transaction(to=code_address, data=tx_data, gas_limit=1_000_000, secret_key=TestPrivateKey)
630+
post = {TestAddress: Account(nonce=1), code_address: Account(storage=expected_storage)}
627631
state_test = StateTest(
628632
env=Environment(),
629633
pre=pre,

0 commit comments

Comments
 (0)