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

Generate fixtures for these test cases for Bogota with:

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

Test the PUSH0 operation in various contract call contexts.

Test PUSH0 in the following contract call contexts:

  • CALL,
  • CALLCODE,
  • DELEGATECALL,
  • STATICCALL.
Source code in tests/shanghai/eip3855_push0/test_push0.py
class TestPush0CallContext:
    """
    Test the PUSH0 operation in various contract call contexts.

    Test PUSH0 in the following contract call contexts:

    - 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 the contract that calls the callee PUSH0 contract into `pre`.

        This fixture returns 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.bigmem
    @pytest.mark.xdist_group(name="bigmem")
    @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,
    ) -> None:
        """Test PUSH0 during various call contexts."""
        tx = Transaction(to=push0_contract_caller, 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
@pytest.mark.bigmem
@pytest.mark.xdist_group(name="bigmem")
@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,
) -> None:
    """Test PUSH0 during various call contexts."""
    tx = Transaction(to=push0_contract_caller, 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

This test generates 4 parametrized test cases across 6 forks.