Skip to content

test_bal_fork_transition_transfers_and_storage()

Documentation for tests/amsterdam/eip7928_block_level_access_lists/test_fork_transition.py::test_bal_fork_transition_transfers_and_storage@26332146.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip7928_block_level_access_lists/test_fork_transition.py::test_bal_fork_transition_transfers_and_storage --fork Amsterdam

Verify the BAL of an activation block with ordinary transfers, storage writes and Transfer logs.

The first Amsterdam block mixes a plain EOA transfer with a contract call that writes storage and forwards value: the BAL must carry the balance and storage changes while the receipts carry the EIP-7708 Transfer logs.

Source code in tests/amsterdam/eip7928_block_level_access_lists/test_fork_transition.py
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
@pytest.mark.valid_at_transition_to("Amsterdam")
def test_bal_fork_transition_transfers_and_storage(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
) -> None:
    """
    Verify the BAL of an activation block with ordinary transfers,
    storage writes and Transfer logs.

    The first Amsterdam block mixes a plain EOA transfer with a contract
    call that writes storage and forwards value: the BAL must carry the
    balance and storage changes while the receipts carry the EIP-7708
    Transfer logs.
    """
    transfer_value = 100
    forward_value = 500

    alice = pre.fund_eoa()
    bob = pre.fund_eoa(amount=0)
    carol = pre.fund_eoa()
    dave = pre.fund_eoa(amount=0)
    relay = pre.deploy_contract(
        code=Op.SSTORE(0, 1)
        + Op.POP(Op.CALL(Op.GAS, dave, forward_value, 0, 0, 0, 0)),
        balance=forward_value,
    )

    pre_fork_tx = Transaction(
        sender=alice, to=bob, value=transfer_value, gas_price=10
    )
    tx_transfer = Transaction(
        sender=alice,
        to=bob,
        value=transfer_value,
        expected_receipt=TransactionReceipt(
            logs=[transfer_log(alice, bob, transfer_value)]
        ),
    )
    tx_relay = Transaction(
        sender=carol,
        to=relay,
        expected_receipt=TransactionReceipt(
            logs=[transfer_log(relay, dave, forward_value)]
        ),
    )

    blocks = [
        Block(
            timestamp=FORK_TIMESTAMP - 1,
            txs=[pre_fork_tx],
            header_verify=Header(
                block_access_list_hash=Header.EMPTY_FIELD,
            ),
        ),
        Block(
            timestamp=FORK_TIMESTAMP,
            txs=[tx_transfer, tx_relay],
            expected_block_access_list=BlockAccessListExpectation(
                account_expectations={
                    alice: BalAccountExpectation(
                        nonce_changes=[
                            BalNonceChange(block_access_index=1, post_nonce=2)
                        ],
                    ),
                    bob: BalAccountExpectation(
                        balance_changes=[
                            BalBalanceChange(
                                block_access_index=1,
                                post_balance=transfer_value * 2,
                            )
                        ],
                    ),
                    carol: BalAccountExpectation(
                        nonce_changes=[
                            BalNonceChange(block_access_index=2, post_nonce=1)
                        ],
                    ),
                    relay: BalAccountExpectation(
                        balance_changes=[
                            BalBalanceChange(
                                block_access_index=2, post_balance=0
                            )
                        ],
                        storage_changes=[
                            BalStorageSlot(
                                slot=0,
                                slot_changes=[
                                    BalStorageChange(
                                        block_access_index=2, post_value=1
                                    )
                                ],
                            )
                        ],
                    ),
                    dave: BalAccountExpectation(
                        balance_changes=[
                            BalBalanceChange(
                                block_access_index=2,
                                post_balance=forward_value,
                            )
                        ],
                    ),
                }
            ),
        ),
    ]

    blockchain_test(
        pre=pre,
        blocks=blocks,
        post={
            bob: Account(balance=transfer_value * 2),
            dave: Account(balance=forward_value),
            relay: Account(balance=0, storage={0: 1}),
        },
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.