Skip to content

Commit cc385d3

Browse files
committed
verify intermidiate block state in blockchain test
1 parent 83d89db commit cc385d3

File tree

4 files changed

+69
-5
lines changed

4 files changed

+69
-5
lines changed

src/ethereum_test_specs/blockchain.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Ethereum blockchain test spec definition and filler."""
22

33
from pprint import pprint
4-
from typing import Any, Callable, ClassVar, Dict, Generator, List, Optional, Tuple, Type
4+
from typing import Any, Callable, ClassVar, Dict, Generator, List, Optional, Tuple, Type, Union
55

66
import pytest
77
from pydantic import ConfigDict, Field, field_validator
@@ -224,6 +224,10 @@ class Block(Header):
224224
"""
225225
Custom list of requests to embed in this block.
226226
"""
227+
expected_post_state: Alloc | None = None
228+
"""
229+
Post state for verification after block execution in BlockchainTest
230+
"""
227231

228232
def set_environment(self, env: Environment) -> Environment:
229233
"""
@@ -489,10 +493,13 @@ def network_info(self, fork: Fork, eips: Optional[List[int]] = None):
489493
else fork.blockchain_test_network_name()
490494
)
491495

492-
def verify_post_state(self, t8n, alloc: Alloc):
496+
def verify_post_state(self, t8n, t8n_state: Alloc, expected_state: Alloc | None = None):
493497
"""Verify post alloc after all block/s or payload/s are generated."""
494498
try:
495-
self.post.verify_post_alloc(alloc)
499+
if expected_state:
500+
expected_state.verify_post_alloc(t8n_state)
501+
else:
502+
self.post.verify_post_alloc(t8n_state)
496503
except Exception as e:
497504
print_traces(t8n.get_traces())
498505
raise e
@@ -568,7 +575,12 @@ def make_fixture(
568575
),
569576
)
570577

571-
self.verify_post_state(t8n, alloc)
578+
if block.expected_post_state:
579+
self.verify_post_state(
580+
t8n, t8n_state=alloc, expected_state=block.expected_post_state
581+
)
582+
583+
self.verify_post_state(t8n, t8n_state=alloc)
572584
return Fixture(
573585
fork=self.network_info(fork, eips),
574586
genesis=genesis.header,
@@ -626,7 +638,7 @@ def make_hive_fixture(
626638
), "A hive fixture was requested but no forkchoice update is defined. The framework should"
627639
" never try to execute this test case."
628640

629-
self.verify_post_state(t8n, alloc)
641+
self.verify_post_state(t8n, t8n_state=alloc)
630642

631643
sync_payload: Optional[FixtureEngineNewPayload] = None
632644
if self.verify_sync:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Test examples, patterns, templates to use in .py tests."""
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
"""Test the SELFDESTRUCT opcode."""
2+
3+
import pytest
4+
5+
from ethereum_test_tools import (
6+
Account,
7+
Alloc,
8+
Block,
9+
BlockchainTestFiller,
10+
Environment,
11+
Transaction,
12+
)
13+
14+
15+
@pytest.mark.valid_from("Frontier")
16+
@pytest.mark.valid_until("Homestead")
17+
def test_block_intermidiate_state(blockchain_test: BlockchainTestFiller, pre: Alloc):
18+
"""Verify intermidiate block states."""
19+
env = Environment()
20+
sender = pre.fund_eoa()
21+
22+
tx = Transaction(gas_limit=100_000, to=None, data=b"", sender=sender)
23+
tx_2 = Transaction(gas_limit=100_000, to=None, data=b"", sender=sender)
24+
25+
block_1 = Block(
26+
txs=[tx],
27+
expected_post_state={
28+
sender: Account(
29+
nonce=1,
30+
),
31+
},
32+
)
33+
34+
block_2 = Block(txs=[])
35+
36+
block_3 = Block(
37+
txs=[tx_2],
38+
expected_post_state={
39+
sender: Account(
40+
nonce=2,
41+
),
42+
},
43+
)
44+
45+
blockchain_test(
46+
genesis_environment=env,
47+
pre=pre,
48+
post=block_3.expected_post_state,
49+
blocks=[block_1, block_2, block_3],
50+
)

whitelist.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ isort
253253
isort's
254254
ispkg
255255
itemName
256+
intermidiate
256257
javascripts
257258
jimporter
258259
joinpath

0 commit comments

Comments
 (0)