|
12 | 12 | from ethereum_test_tools import Block |
13 | 13 | from ethereum_test_types import Alloc, Environment, Storage, Transaction, TransactionReceipt |
14 | 14 |
|
15 | | -from ..blockchain import BlockchainTest |
| 15 | +from ..blockchain import BlockchainEngineFixture, BlockchainTest |
16 | 16 | from ..helpers import ( |
17 | 17 | TransactionExceptionMismatchError, |
18 | 18 | TransactionReceiptMismatchError, |
@@ -353,51 +353,97 @@ def test_transaction_expectation( |
353 | 353 | state_test.generate(request=None, t8n=t8n, fork=fork, fixture_format=fixture_format) |
354 | 354 |
|
355 | 355 |
|
| 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 | +) |
356 | 385 | @pytest.mark.parametrize( |
357 | 386 | "fixture_format", |
358 | 387 | [ |
359 | 388 | BlockchainFixture, |
| 389 | + BlockchainEngineFixture, |
360 | 390 | ], |
361 | 391 | ) |
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 | +): |
363 | 395 | """Validate the state when building blockchain.""" |
364 | 396 | env = Environment() |
365 | | - # pre = Alloc() |
366 | | - sender = pre.fund_eoa() |
367 | 397 |
|
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) |
370 | 401 |
|
371 | 402 | block_1 = Block( |
372 | 403 | txs=[tx], |
373 | 404 | expected_post_state={ |
374 | | - sender: Account( |
375 | | - nonce=1, |
376 | | - ), |
| 405 | + TestAddress: Account(nonce=1), |
| 406 | + to: Account(balance=1), |
377 | 407 | }, |
378 | 408 | ) |
379 | 409 |
|
380 | | - block_2 = Block(txs=[]) |
| 410 | + block_2 = Block(txs=[], expected_post_state=intermediate_state) |
381 | 411 |
|
382 | 412 | block_3 = Block( |
383 | 413 | txs=[tx_2], |
384 | 414 | expected_post_state={ |
385 | | - sender: Account( |
386 | | - nonce=2, |
387 | | - ), |
| 415 | + TestAddress: Account(nonce=2), |
| 416 | + to: Account(balance=2), |
388 | 417 | }, |
389 | 418 | ) |
390 | 419 |
|
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