Skip to content

test_beacon_root_contract_calls()

Documentation for tests/cancun/eip4788_beacon_root/test_beacon_root_contract.py::test_beacon_root_contract_calls@20373115.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/cancun/eip4788_beacon_root/test_beacon_root_contract.py::test_beacon_root_contract_calls --fork Amsterdam

Test calling the beacon root contract in various call contexts.

These call contexts are tested: - CALL - DELEGATECALL - CALLCODE - STATICCALL for different call gas amounts: - exact gas (valid call) - extra gas (valid call) - insufficient gas (invalid call).

The expected result is that the contract call will be executed if the gas amount is met and return the correctparent_beacon_block_root. Otherwise the call will be invalid, and not be executed. This is highlighted within storage by storing the return value of each call context.

Source code in tests/cancun/eip4788_beacon_root/test_beacon_root_contract.py
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
@pytest.mark.parametrize(
    "call_gas, valid_call",
    [
        pytest.param(Spec.BEACON_ROOTS_CALL_GAS, True),
        pytest.param(int(Spec.BEACON_ROOTS_CALL_GAS / 100), False),
    ],
)
@pytest.mark.parametrize(
    "call_type,call_value,valid_input",
    [
        (Op.CALL, 1, True),
        (Op.CALL, 0, True),
        (Op.CALLCODE, 0, False),
        (Op.DELEGATECALL, 0, False),
        (Op.STATICCALL, 0, True),
    ],
)
@pytest.mark.valid_from("Cancun")
def test_beacon_root_contract_calls(
    blockchain_test: BlockchainTestFiller,
    beacon_root: bytes,
    timestamp: int,
    pre: Alloc,
    tx: Transaction,
    post: Dict,
) -> None:
    """
    Test calling the beacon root contract in various call contexts.

    These call contexts are tested:
    - `CALL`
    - `DELEGATECALL`
    - `CALLCODE`
    - `STATICCALL`
    for different call gas amounts:
    - exact gas (valid call)
    - extra gas (valid call)
    - insufficient gas (invalid call).

    The expected result is that the contract call will be executed if the gas
    amount is met and return the correct`parent_beacon_block_root`. Otherwise
    the call will be invalid, and not be executed. This is highlighted within
    storage by storing the return value of each call context.
    """
    blockchain_test(
        pre=pre,
        blocks=[
            Block(
                txs=[tx],
                parent_beacon_block_root=beacon_root,
                timestamp=timestamp,
            )
        ],
        post=post,
    )

Parametrized Test Cases

This test generates 10 parametrized test cases across 4 forks.