Skip to content

Commit 2115d30

Browse files
marioevzwinsvega
authored andcommitted
fix(specs): Unit test
1 parent a8b1434 commit 2115d30

File tree

1 file changed

+72
-26
lines changed

1 file changed

+72
-26
lines changed

src/ethereum_test_specs/tests/test_expect.py

Lines changed: 72 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from ethereum_test_tools import Block
1313
from ethereum_test_types import Alloc, Environment, Storage, Transaction, TransactionReceipt
1414

15-
from ..blockchain import BlockchainTest
15+
from ..blockchain import BlockchainEngineFixture, BlockchainTest
1616
from ..helpers import (
1717
TransactionExceptionMismatchError,
1818
TransactionReceiptMismatchError,
@@ -353,51 +353,97 @@ def test_transaction_expectation(
353353
state_test.generate(request=None, t8n=t8n, fork=fork, fixture_format=fixture_format)
354354

355355

356+
@pytest.mark.parametrize(
357+
"intermediate_state,expected_exception",
358+
[
359+
pytest.param(
360+
{
361+
TestAddress: Account(nonce=1),
362+
Address(0x01): Account(balance=1),
363+
},
364+
None,
365+
id="NoException",
366+
),
367+
pytest.param(
368+
{
369+
TestAddress: Account(nonce=2),
370+
Address(0x01): Account(balance=1),
371+
},
372+
Account.NonceMismatchError,
373+
id="NonceMismatchError",
374+
),
375+
pytest.param(
376+
{
377+
TestAddress: Account(nonce=1),
378+
Address(0x01): Account(balance=2),
379+
},
380+
Account.BalanceMismatchError,
381+
id="BalanceMismatchError",
382+
),
383+
],
384+
)
356385
@pytest.mark.parametrize(
357386
"fixture_format",
358387
[
359388
BlockchainFixture,
389+
BlockchainEngineFixture,
360390
],
361391
)
362-
def test_block_intermediate_state(pre, t8n, fork, fixture_format: FixtureFormat):
392+
def test_block_intermediate_state(
393+
pre, t8n, fork, fixture_format: FixtureFormat, intermediate_state, expected_exception
394+
):
363395
"""Validate the state when building blockchain."""
364396
env = Environment()
365-
# pre = Alloc()
366-
sender = pre.fund_eoa()
367397

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)
398+
to = Address(0x01)
399+
tx = Transaction(gas_limit=100_000, to=to, value=1, nonce=0, secret_key=TestPrivateKey)
400+
tx_2 = Transaction(gas_limit=100_000, to=to, value=1, nonce=1, secret_key=TestPrivateKey)
370401

371402
block_1 = Block(
372403
txs=[tx],
373404
expected_post_state={
374-
sender: Account(
375-
nonce=1,
376-
),
405+
TestAddress: Account(nonce=1),
406+
to: Account(balance=1),
377407
},
378408
)
379409

380-
block_2 = Block(txs=[])
410+
block_2 = Block(txs=[], expected_post_state=intermediate_state)
381411

382412
block_3 = Block(
383413
txs=[tx_2],
384414
expected_post_state={
385-
sender: Account(
386-
nonce=2,
387-
),
415+
TestAddress: Account(nonce=2),
416+
to: Account(balance=2),
388417
},
389418
)
390419

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-
)
420+
if expected_exception:
421+
with pytest.raises(expected_exception) as _:
422+
BlockchainTest(
423+
genesis_environment=env,
424+
fork=fork,
425+
t8n=t8n,
426+
pre=pre,
427+
post=block_3.expected_post_state,
428+
blocks=[block_1, block_2, block_3],
429+
).generate(
430+
request=None, # type: ignore
431+
t8n=t8n,
432+
fork=fork,
433+
fixture_format=fixture_format,
434+
)
435+
return
436+
else:
437+
BlockchainTest(
438+
genesis_environment=env,
439+
fork=fork,
440+
t8n=t8n,
441+
pre=pre,
442+
post=block_3.expected_post_state,
443+
blocks=[block_1, block_2, block_3],
444+
).generate(
445+
request=None, # type: ignore
446+
t8n=t8n,
447+
fork=fork,
448+
fixture_format=fixture_format,
449+
)

0 commit comments

Comments
 (0)