Skip to content

test_create_with_reservoir()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py::test_create_with_reservoir@c74f1a67.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py::test_create_with_reservoir --fork Amsterdam

Test CREATE/CREATE2 with state gas funded from the reservoir.

Provide gas above TX_MAX_GAS_LIMIT so the new account state gas is drawn from the reservoir rather than gas_left.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py
 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
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
@pytest.mark.parametrize(
    "opcode",
    [
        pytest.param(Op.CREATE, id="create"),
        pytest.param(Op.CREATE2, id="create2"),
    ],
)
@pytest.mark.valid_from("EIP8037")
def test_create_with_reservoir(
    state_test: StateTestFiller,
    pre: Alloc,
    opcode: Op,
    fork: Fork,
) -> None:
    """
    Test CREATE/CREATE2 with state gas funded from the reservoir.

    Provide gas above TX_MAX_GAS_LIMIT so the new account state gas
    is drawn from the reservoir rather than gas_left.
    """
    gas_costs = fork.gas_costs()
    create_state_gas = gas_costs.NEW_ACCOUNT

    storage = Storage()
    init_code = Op.STOP

    if opcode == Op.CREATE:
        create_call = Op.CREATE(0, 0, len(init_code))
    else:
        create_call = Op.CREATE2(0, 0, len(init_code), 0)

    contract = pre.deploy_contract(
        code=(
            Op.MSTORE(
                0,
                int.from_bytes(bytes(init_code), "big")
                << (256 - 8 * len(init_code)),
            )
            + Op.SSTORE(
                storage.store_next(True),
                Op.GT(create_call, 0),
            )
        ),
    )

    tx = Transaction(
        to=contract,
        state_gas_reservoir=create_state_gas,
        sender=pre.fund_eoa(),
    )

    post = {contract: Account(storage=storage)}
    state_test(pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.