Skip to content

Commit 213f0e8

Browse files
feat(test-benchmark): validate post-state for stateful filler (#3148)
* feat: add post-state verification to stateful filler * fix(test-plugins): Fix types, simplify --------- Co-authored-by: Mario Vega <marioevz@gmail.com>
1 parent c5043ec commit 213f0e8

8 files changed

Lines changed: 36 additions & 19 deletions

File tree

packages/testing/src/execution_testing/cli/pytest_commands/plugins/execute/execute.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
from pytest_metadata.plugin import metadata_key
1111

1212
from execution_testing.base_types import Account
13-
from execution_testing.base_types import Alloc as BaseAlloc
1413
from execution_testing.base_types.base_types import HexNumber
1514
from execution_testing.execution import BaseExecute
1615
from execution_testing.forks import Fork, TransitionFork
1716
from execution_testing.logging import get_logger
1817
from execution_testing.rpc import EngineRPC, EthRPC
1918
from execution_testing.specs import BaseTest
19+
from execution_testing.test_types import Alloc as BaseAlloc
2020
from execution_testing.test_types import (
2121
Environment,
2222
EnvironmentDefaults,

packages/testing/src/execution_testing/cli/pytest_commands/plugins/execute/pre_alloc.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
Storage,
2121
StorageRootType,
2222
)
23-
from execution_testing.base_types import (
24-
Alloc as BaseAlloc,
25-
)
2623
from execution_testing.base_types.conversions import (
2724
BytesConvertible,
2825
NumberConvertible,
@@ -42,6 +39,7 @@
4239
TransactionTestMetadata,
4340
compute_deterministic_create2_address,
4441
)
42+
from execution_testing.test_types import Alloc as BaseAlloc
4543
from execution_testing.tools import Initcode
4644
from execution_testing.vm import Bytecode, Op
4745

packages/testing/src/execution_testing/cli/pytest_commands/plugins/shared/execute_fill.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@
99
from pytest import StashKey
1010

1111
from execution_testing.base_types import Account, Number
12-
from execution_testing.base_types import Alloc as BaseAlloc
13-
from execution_testing.execution import (
14-
BaseExecute,
15-
LabeledExecuteFormat,
16-
)
12+
from execution_testing.execution import BaseExecute, LabeledExecuteFormat
1713
from execution_testing.fixtures import BaseFixture, LabeledFixtureFormat
1814
from execution_testing.logging import get_logger
1915
from execution_testing.rpc import EthRPC
@@ -65,7 +61,7 @@ def _validate_and_cache_address_stubs(
6561
eth_rpc = EthRPC(rpc_endpoint)
6662
labels = list(address_stubs.root.keys())
6763
addresses = [address_stubs.root[k].addr for k in labels]
68-
query = BaseAlloc(root={addr: Account() for addr in addresses})
64+
query = Alloc(root={addr: Account() for addr in addresses})
6965
alloc = eth_rpc.get_alloc(query)
7066
empty: list[str] = []
7167
accounts: Dict[str, Account] = {}

packages/testing/src/execution_testing/client_clis/client_backend.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from execution_testing.forks import Fork, TransitionFork
2121
from execution_testing.logging import get_logger
2222
from execution_testing.rpc import (
23+
BlockNumberType,
2324
DebugRPC,
2425
EngineRPC,
2526
EthRPC,
@@ -33,7 +34,12 @@
3334
PayloadAttributes,
3435
PayloadStatusEnum,
3536
)
36-
from execution_testing.test_types import Requests, Transaction, Withdrawal
37+
from execution_testing.test_types import (
38+
Alloc,
39+
Requests,
40+
Transaction,
41+
Withdrawal,
42+
)
3743
from execution_testing.test_types.block_access_list import BlockAccessList
3844
from execution_testing.test_types.receipt_types import TransactionReceipt
3945

@@ -306,6 +312,12 @@ def evaluate(
306312
),
307313
)
308314

315+
def get_post_state_alloc(
316+
self, expected: Alloc, *, block_number: BlockNumberType = "latest"
317+
) -> Alloc:
318+
"""Fetch the post-state that ``expected`` constrains from client."""
319+
return self.eth_rpc.get_alloc(expected, block_number=block_number)
320+
309321
def extract_block_opcode_count(
310322
self, block_hash: Hash
311323
) -> OpcodeCount | None:

packages/testing/src/execution_testing/execution/transaction_post.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import pytest
66
from pytest import FixtureRequest
77

8-
from execution_testing.base_types import Address, Alloc, Hash
8+
from execution_testing.base_types import Address, Hash
99
from execution_testing.forks import Fork
1010
from execution_testing.logging import get_logger
1111
from execution_testing.rpc import (
@@ -14,6 +14,7 @@
1414
SendTransactionExceptionError,
1515
)
1616
from execution_testing.test_types import (
17+
Alloc,
1718
Environment,
1819
NetworkWrappedTransaction,
1920
TestPhase,

packages/testing/src/execution_testing/rpc/rpc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@
3737
from execution_testing.base_types import (
3838
Account,
3939
Address,
40-
Alloc,
4140
Bytes,
4241
Hash,
4342
to_json,
4443
)
4544
from execution_testing.logging import (
4645
get_logger,
4746
)
47+
from execution_testing.test_types import Alloc
4848

4949
from .rpc_types import (
5050
EthConfigResponse,

packages/testing/src/execution_testing/specs/blockchain.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1384,7 +1384,8 @@ def make_stateful_fixture(
13841384
- Payloads are partitioned by ``FixtureEngineNewPayload.phase``
13851385
into ``setup_payloads`` (setup-phase txs) and ``payloads``
13861386
(execution-phase txs).
1387-
- ``verify_post_state`` is skipped: the client is the oracle.
1387+
- ``post`` is verified against the live client (the oracle) via
1388+
``get_post_state_alloc``; there is no t8n post alloc to diff.
13881389
"""
13891390
if not isinstance(t8n, ClientBackend):
13901391
raise RuntimeError(
@@ -1557,6 +1558,10 @@ def make_stateful_fixture(
15571558
)
15581559
head_hash = client_hash
15591560

1561+
if self.post.root:
1562+
got_alloc = t8n.get_post_state_alloc(self.post)
1563+
self.post.verify_post_alloc(got_alloc)
1564+
15601565
fixture = BlockchainEngineStatefulFixture(
15611566
fork=self.fork,
15621567
last_block_hash=head_hash,

packages/testing/src/execution_testing/test_types/account_types.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,13 @@ def __contains__(
324324
address = Address(address)
325325
return address in self.root
326326

327+
def get(self, address: Address) -> Account | None:
328+
"""Get an account if it's present in the allocation, otherwise None."""
329+
account = self.root.get(address)
330+
if not account:
331+
return None
332+
return account
333+
327334
def empty_accounts(self) -> List[Address]:
328335
"""Return list of addresses of empty accounts."""
329336
return [
@@ -372,12 +379,10 @@ def verify_post_alloc(self, got_alloc: "Alloc") -> None:
372379
for address, account in self.root.items():
373380
if account is None:
374381
# Account must not exist
375-
if (
376-
address in got_alloc.root
377-
and got_alloc.root[address] is not None
378-
):
382+
got_account = got_alloc.get(address)
383+
if got_account:
379384
raise Alloc.UnexpectedAccountError(
380-
address=address, account=got_alloc.root[address]
385+
address=address, account=got_account
381386
)
382387
else:
383388
if address in got_alloc.root:

0 commit comments

Comments
 (0)