Skip to content

test_contract_creation_gas()

Documentation for tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_eip_mainnet.py::test_contract_creation_gas@26332146.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_eip_mainnet.py::test_contract_creation_gas --fork Amsterdam

Gas for a contract-creation transaction, per value.

Source code in tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_eip_mainnet.py
 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
@EIPChecklist.GasCostChanges.Test.GasUpdatesMeasurement()
@pytest.mark.parametrize(
    "value",
    [
        pytest.param(0, id="zero_value"),
        pytest.param(1, id="non-zero_value"),
    ],
)
def test_contract_creation_gas(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    value: int,
) -> None:
    """Gas for a contract-creation transaction, per value."""
    sender = pre.fund_eoa()
    deploy_code = Op.STOP
    init_code = Initcode(deploy_code=deploy_code)

    intrinsic_gas = fork.transaction_intrinsic_cost_calculator()(
        calldata=init_code,
        contract_creation=True,
        sends_value=bool(value),
        return_cost_deducted_prior_execution=True,
    )
    new_account_state_gas = fork.transaction_top_frame_state_gas(
        contract_creation=True,
    )
    gas_used = intrinsic_gas + new_account_state_gas + init_code.gas_cost(fork)

    tx = Transaction(
        to=None,
        value=value,
        data=init_code,
        gas_limit=gas_used,
        sender=sender,
        expected_receipt=TransactionReceipt(cumulative_gas_used=gas_used),
    )

    created = compute_create_address(address=sender, nonce=0)
    post = {created: Account(balance=value, code=deploy_code)}
    state_test(pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.