Skip to content

Commit 861f1f6

Browse files
committed
verify intermidiate block state in blockchain test
1 parent 54f0b43 commit 861f1f6

File tree

4 files changed

+68
-4
lines changed

4 files changed

+68
-4
lines changed

src/ethereum_test_specs/blockchain.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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
"""
@@ -491,10 +495,13 @@ def network_info(self, fork: Fork, eips: Optional[List[int]] = None):
491495
else fork.blockchain_test_network_name()
492496
)
493497

494-
def verify_post_state(self, t8n, alloc: Alloc):
498+
def verify_post_state(self, t8n, t8n_state: Alloc, expected_state: Alloc | None = None):
495499
"""Verify post alloc after all block/s or payload/s are generated."""
496500
try:
497-
self.post.verify_post_alloc(alloc)
501+
if expected_state:
502+
expected_state.verify_post_alloc(t8n_state)
503+
else:
504+
self.post.verify_post_alloc(t8n_state)
498505
except Exception as e:
499506
print_traces(t8n.get_traces())
500507
raise e
@@ -570,7 +577,12 @@ def make_fixture(
570577
),
571578
)
572579

573-
self.verify_post_state(t8n, alloc)
580+
if block.expected_post_state:
581+
self.verify_post_state(
582+
t8n, t8n_state=alloc, expected_state=block.expected_post_state
583+
)
584+
585+
self.verify_post_state(t8n, t8n_state=alloc)
574586
return Fixture(
575587
fork=self.network_info(fork, eips),
576588
genesis=genesis.header,
@@ -628,7 +640,7 @@ def make_hive_fixture(
628640
), "A hive fixture was requested but no forkchoice update is defined. The framework should"
629641
" never try to execute this test case."
630642

631-
self.verify_post_state(t8n, alloc)
643+
self.verify_post_state(t8n, t8n_state=alloc)
632644

633645
sync_payload: Optional[FixtureEngineNewPayload] = None
634646
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)