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@83970623.

Generate fixtures for these test cases for Prague with:

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

Tests the beacon root contract call using various call contexts: - 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
46
47
48
49
50
51
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
@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,
):
    """
    Tests the beacon root contract call using various call contexts:
    - `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

The interactive table below is also available as a standalone page.

Test ID (Abbreviated) call_type call_value valid_input call_gas valid_call
...fork_Cancun-blockchain_test-call_type_CALL-call_value_1-valid_input_True-call_gas_100000-valid_call_True CALL 1 True 100000 True
...fork_Cancun-blockchain_test-call_type_CALL-call_value_1-valid_input_True-call_gas_1000-valid_call_False CALL 1 True 1000 False
...fork_Cancun-blockchain_test-call_type_CALL-call_value_0-valid_input_True-call_gas_100000-valid_call_True CALL 0 True 100000 True
...fork_Cancun-blockchain_test-call_type_CALL-call_value_0-valid_input_True-call_gas_1000-valid_call_False CALL 0 True 1000 False
...fork_Cancun-blockchain_test-call_type_CALLCODE-call_value_0-valid_input_False-call_gas_100000-valid_call_True CALLCODE 0 False 100000 True
...fork_Cancun-blockchain_test-call_type_CALLCODE-call_value_0-valid_input_False-call_gas_1000-valid_call_False CALLCODE 0 False 1000 False
...fork_Cancun-blockchain_test-call_type_DELEGATECALL-call_value_0-valid_input_False-call_gas_100000-valid_call_True DELEGATECALL 0 False 100000 True
...fork_Cancun-blockchain_test-call_type_DELEGATECALL-call_value_0-valid_input_False-call_gas_1000-valid_call_False DELEGATECALL 0 False 1000 False
...fork_Cancun-blockchain_test-call_type_STATICCALL-call_value_0-valid_input_True-call_gas_100000-valid_call_True STATICCALL 0 True 100000 True
...fork_Cancun-blockchain_test-call_type_STATICCALL-call_value_0-valid_input_True-call_gas_1000-valid_call_False STATICCALL 0 True 1000 False
...fork_Prague-blockchain_test-call_type_CALL-call_value_1-valid_input_True-call_gas_100000-valid_call_True CALL 1 True 100000 True
...fork_Prague-blockchain_test-call_type_CALL-call_value_1-valid_input_True-call_gas_1000-valid_call_False CALL 1 True 1000 False
...fork_Prague-blockchain_test-call_type_CALL-call_value_0-valid_input_True-call_gas_100000-valid_call_True CALL 0 True 100000 True
...fork_Prague-blockchain_test-call_type_CALL-call_value_0-valid_input_True-call_gas_1000-valid_call_False CALL 0 True 1000 False
...fork_Prague-blockchain_test-call_type_CALLCODE-call_value_0-valid_input_False-call_gas_100000-valid_call_True CALLCODE 0 False 100000 True
...fork_Prague-blockchain_test-call_type_CALLCODE-call_value_0-valid_input_False-call_gas_1000-valid_call_False CALLCODE 0 False 1000 False
...fork_Prague-blockchain_test-call_type_DELEGATECALL-call_value_0-valid_input_False-call_gas_100000-valid_call_True DELEGATECALL 0 False 100000 True
...fork_Prague-blockchain_test-call_type_DELEGATECALL-call_value_0-valid_input_False-call_gas_1000-valid_call_False DELEGATECALL 0 False 1000 False
...fork_Prague-blockchain_test-call_type_STATICCALL-call_value_0-valid_input_True-call_gas_100000-valid_call_True STATICCALL 0 True 100000 True
...fork_Prague-blockchain_test-call_type_STATICCALL-call_value_0-valid_input_True-call_gas_1000-valid_call_False STATICCALL 0 True 1000 False
...fork_Osaka-blockchain_test-call_type_CALL-call_value_1-valid_input_True-call_gas_100000-valid_call_True CALL 1 True 100000 True
...fork_Osaka-blockchain_test-call_type_CALL-call_value_1-valid_input_True-call_gas_1000-valid_call_False CALL 1 True 1000 False
...fork_Osaka-blockchain_test-call_type_CALL-call_value_0-valid_input_True-call_gas_100000-valid_call_True CALL 0 True 100000 True
...fork_Osaka-blockchain_test-call_type_CALL-call_value_0-valid_input_True-call_gas_1000-valid_call_False CALL 0 True 1000 False
...fork_Osaka-blockchain_test-call_type_CALLCODE-call_value_0-valid_input_False-call_gas_100000-valid_call_True CALLCODE 0 False 100000 True
...fork_Osaka-blockchain_test-call_type_CALLCODE-call_value_0-valid_input_False-call_gas_1000-valid_call_False CALLCODE 0 False 1000 False
...fork_Osaka-blockchain_test-call_type_DELEGATECALL-call_value_0-valid_input_False-call_gas_100000-valid_call_True DELEGATECALL 0 False 100000 True
...fork_Osaka-blockchain_test-call_type_DELEGATECALL-call_value_0-valid_input_False-call_gas_1000-valid_call_False DELEGATECALL 0 False 1000 False
...fork_Osaka-blockchain_test-call_type_STATICCALL-call_value_0-valid_input_True-call_gas_100000-valid_call_True STATICCALL 0 True 100000 True
...fork_Osaka-blockchain_test-call_type_STATICCALL-call_value_0-valid_input_True-call_gas_1000-valid_call_False STATICCALL 0 True 1000 False