Skip to content

test_push0_contract_during_call_contexts()

Documentation for tests/shanghai/eip3855_push0/test_push0.py::TestPush0CallContext::test_push0_contract_during_call_contexts@21fb11c8.

Generate fixtures for these test cases for Prague with:

fill -v tests/shanghai/eip3855_push0/test_push0.py::TestPush0CallContext::test_push0_contract_during_call_contexts --fork Prague

Tests the PUSH0 operation during various call contexts including: - CALL - CALLCODE - DELEGATECALL - STATICCALL.

Source code in tests/shanghai/eip3855_push0/test_push0.py
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
class TestPush0CallContext:
    """
    Tests the PUSH0 operation during various call contexts including:
    - CALL
    - CALLCODE
    - DELEGATECALL
    - STATICCALL.
    """

    @pytest.fixture
    def push0_contract_callee(self, pre: Alloc) -> Address:
        """Deploys a PUSH0 contract callee to the pre alloc returning its address."""
        push0_contract = pre.deploy_contract(Op.MSTORE8(Op.PUSH0, 0xFF) + Op.RETURN(Op.PUSH0, 1))
        return push0_contract

    @pytest.fixture
    def push0_contract_caller(
        self, pre: Alloc, call_opcode: Op, push0_contract_callee: Address
    ) -> Address:
        """
        Deploy contract responsible for calling the callee PUSH0 contract
        returning its address.
        """
        call_code = (
            Op.SSTORE(0, call_opcode(gas=100_000, address=push0_contract_callee))
            + Op.SSTORE(0, 1)
            + Op.RETURNDATACOPY(0x1F, 0, 1)
            + Op.SSTORE(1, Op.MLOAD(0))
        )
        return pre.deploy_contract(call_code)

    @pytest.mark.parametrize(
        "call_opcode",
        [
            Op.CALL,
            Op.CALLCODE,
            Op.DELEGATECALL,
            Op.STATICCALL,
        ],
        ids=["call", "callcode", "delegatecall", "staticcall"],
    )
    def test_push0_contract_during_call_contexts(
        self,
        state_test: StateTestFiller,
        env: Environment,
        pre: Alloc,
        post: Alloc,
        sender: EOA,
        push0_contract_caller: Address,
    ):
        """Test PUSH0 during various call contexts."""
        tx = Transaction(to=push0_contract_caller, gas_limit=100_000, sender=sender)
        post[push0_contract_caller] = Account(storage={0x00: 0x01, 0x01: 0xFF})
        state_test(env=env, pre=pre, post=post, tx=tx)

test_push0_contract_during_call_contexts(state_test, env, pre, post, sender, push0_contract_caller)

Test PUSH0 during various call contexts.

Source code in tests/shanghai/eip3855_push0/test_push0.py
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
@pytest.mark.parametrize(
    "call_opcode",
    [
        Op.CALL,
        Op.CALLCODE,
        Op.DELEGATECALL,
        Op.STATICCALL,
    ],
    ids=["call", "callcode", "delegatecall", "staticcall"],
)
def test_push0_contract_during_call_contexts(
    self,
    state_test: StateTestFiller,
    env: Environment,
    pre: Alloc,
    post: Alloc,
    sender: EOA,
    push0_contract_caller: Address,
):
    """Test PUSH0 during various call contexts."""
    tx = Transaction(to=push0_contract_caller, gas_limit=100_000, sender=sender)
    post[push0_contract_caller] = Account(storage={0x00: 0x01, 0x01: 0xFF})
    state_test(env=env, pre=pre, post=post, tx=tx)

Parametrized Test Cases

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

Test ID (Abbreviated) call_opcode
...fork_Shanghai-state_test-call CALL
...fork_Shanghai-state_test-callcode CALLCODE
...fork_Shanghai-state_test-delegatecall DELEGATECALL
...fork_Shanghai-state_test-staticcall STATICCALL
...fork_Shanghai-blockchain_test_from_state_test-call CALL
...fork_Shanghai-blockchain_test_from_state_test-callcode CALLCODE
...fork_Shanghai-blockchain_test_from_state_test-delegatecall DELEGATECALL
...fork_Shanghai-blockchain_test_from_state_test-staticcall STATICCALL
...fork_Cancun-state_test-call CALL
...fork_Cancun-state_test-callcode CALLCODE
...fork_Cancun-state_test-delegatecall DELEGATECALL
...fork_Cancun-state_test-staticcall STATICCALL
...fork_Cancun-blockchain_test_from_state_test-call CALL
...fork_Cancun-blockchain_test_from_state_test-callcode CALLCODE
...fork_Cancun-blockchain_test_from_state_test-delegatecall DELEGATECALL
...fork_Cancun-blockchain_test_from_state_test-staticcall STATICCALL
...fork_Prague-state_test-call CALL
...fork_Prague-state_test-callcode CALLCODE
...fork_Prague-state_test-delegatecall DELEGATECALL
...fork_Prague-state_test-staticcall STATICCALL
...fork_Prague-blockchain_test_from_state_test-call CALL
...fork_Prague-blockchain_test_from_state_test-callcode CALLCODE
...fork_Prague-blockchain_test_from_state_test-delegatecall DELEGATECALL
...fork_Prague-blockchain_test_from_state_test-staticcall STATICCALL
...fork_Osaka-state_test-call CALL
...fork_Osaka-state_test-callcode CALLCODE
...fork_Osaka-state_test-delegatecall DELEGATECALL
...fork_Osaka-state_test-staticcall STATICCALL
...fork_Osaka-blockchain_test_from_state_test-call CALL
...fork_Osaka-blockchain_test_from_state_test-callcode CALLCODE
...fork_Osaka-blockchain_test_from_state_test-delegatecall DELEGATECALL
...fork_Osaka-blockchain_test_from_state_test-staticcall STATICCALL