Skip to content

test_no_beacon_root_contract_at_transition()

Documentation for tests/cancun/eip4788_beacon_root/test_beacon_root_contract.py::test_no_beacon_root_contract_at_transition@892e6d1e.

Generate fixtures for these test cases for Cancun with:

fill -v tests/cancun/eip4788_beacon_root/test_beacon_root_contract.py::test_no_beacon_root_contract_at_transition --fork Cancun

Tests the fork transition to cancun in the case where the beacon root pre-deploy was not deployed in time for the fork.

Source code in tests/cancun/eip4788_beacon_root/test_beacon_root_contract.py
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
@pytest.mark.parametrize("timestamp", [15_000])
@pytest.mark.valid_at_transition_to("Cancun")
@pytest.mark.pre_alloc_mutable()
def test_no_beacon_root_contract_at_transition(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    beacon_roots: Iterator[bytes],
    tx: Transaction,
    timestamp: int,
    caller_address: Address,
    fork: TransitionFork,
) -> None:
    """
    Tests the fork transition to cancun in the case where the beacon root
    pre-deploy was not deployed in time for the fork.
    """
    assert fork.fork_at(
        block_number=1, timestamp=timestamp
    ).header_beacon_root_required()
    blocks: List[Block] = [
        Block(
            txs=[tx],
            parent_beacon_block_root=next(beacon_roots),
            timestamp=timestamp,
            withdrawals=[
                # Also withdraw to the beacon root contract and the system
                # address
                Withdrawal(
                    address=Spec.BEACON_ROOTS_ADDRESS,
                    amount=1,
                    index=0,
                    validator_index=0,
                ),
                Withdrawal(
                    address=Spec.SYSTEM_ADDRESS,
                    amount=1,
                    index=1,
                    validator_index=1,
                ),
            ],
        )
    ]
    pre[Spec.BEACON_ROOTS_ADDRESS] = Account(
        code=b"",  # Remove the code that is automatically allocated on Cancun
        # fork
        nonce=0,
        balance=0,
    )
    post = {
        Spec.BEACON_ROOTS_ADDRESS: Account(
            storage={
                timestamp % Spec.HISTORY_BUFFER_LENGTH: 0,
                (timestamp % Spec.HISTORY_BUFFER_LENGTH)
                + Spec.HISTORY_BUFFER_LENGTH: 0,
            },
            code=b"",
            nonce=0,
            balance=int(1e9),
        ),
        caller_address: Account(
            storage={
                0: 1
            },  # Successful call because the contract is not there, but
            # nothing else is stored
        ),
    }
    blockchain_test(
        pre=pre,
        blocks=blocks,
        post=post,
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.