Skip to content

Commit a8b1434

Browse files
committed
unit test
1 parent 861f1f6 commit a8b1434

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

src/ethereum_test_specs/blockchain.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,12 @@ def make_hive_fixture(
634634
alloc = new_alloc
635635
env = apply_new_parent(env, header)
636636
head_hash = header.block_hash
637+
638+
if block.expected_post_state:
639+
self.verify_post_state(
640+
t8n, t8n_state=alloc, expected_state=block.expected_post_state
641+
)
642+
637643
fcu_version = fork.engine_forkchoice_updated_version(header.number, header.timestamp)
638644
assert (
639645
fcu_version is not None

src/ethereum_test_specs/tests/test_expect.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
from ethereum_test_exceptions import TransactionException
1010
from ethereum_test_fixtures import BlockchainFixture, FixtureFormat, StateFixture
1111
from ethereum_test_forks import Fork, get_deployed_forks
12+
from ethereum_test_tools import Block
1213
from ethereum_test_types import Alloc, Environment, Storage, Transaction, TransactionReceipt
1314

15+
from ..blockchain import BlockchainTest
1416
from ..helpers import (
1517
TransactionExceptionMismatchError,
1618
TransactionReceiptMismatchError,
@@ -349,3 +351,53 @@ def test_transaction_expectation(
349351
else:
350352
with pytest.raises(exception_type) as _:
351353
state_test.generate(request=None, t8n=t8n, fork=fork, fixture_format=fixture_format)
354+
355+
356+
@pytest.mark.parametrize(
357+
"fixture_format",
358+
[
359+
BlockchainFixture,
360+
],
361+
)
362+
def test_block_intermediate_state(pre, t8n, fork, fixture_format: FixtureFormat):
363+
"""Validate the state when building blockchain."""
364+
env = Environment()
365+
# pre = Alloc()
366+
sender = pre.fund_eoa()
367+
368+
tx = Transaction(gas_limit=100_000, to=None, data=b"", sender=sender)
369+
tx_2 = Transaction(gas_limit=100_000, to=None, data=b"", sender=sender)
370+
371+
block_1 = Block(
372+
txs=[tx],
373+
expected_post_state={
374+
sender: Account(
375+
nonce=1,
376+
),
377+
},
378+
)
379+
380+
block_2 = Block(txs=[])
381+
382+
block_3 = Block(
383+
txs=[tx_2],
384+
expected_post_state={
385+
sender: Account(
386+
nonce=2,
387+
),
388+
},
389+
)
390+
391+
BlockchainTest(
392+
genesis_environment=env,
393+
fork=fork,
394+
t8n=t8n,
395+
pre=pre,
396+
post=block_3.expected_post_state,
397+
blocks=[block_1, block_2, block_3],
398+
).generate(
399+
request=None, # type: ignore
400+
t8n=t8n,
401+
fork=fork,
402+
fixture_format=fixture_format,
403+
)

0 commit comments

Comments
 (0)