Skip to content

test_sstore_nonzero_to_nonzero()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_sstore.py::test_sstore_nonzero_to_nonzero@622620d8.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_sstore.py::test_sstore_nonzero_to_nonzero --fork Amsterdam

Test SSTORE nonzero-to-nonzero charges no state gas.

Updating a slot that already holds a nonzero value to a different nonzero value does not create new state, so no state gas is charged and the header reports the execution dimension alone.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_sstore.py
 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
@pytest.mark.valid_from("EIP8037")
def test_sstore_nonzero_to_nonzero(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Test SSTORE nonzero-to-nonzero charges no state gas.

    Updating a slot that already holds a nonzero value to a different
    nonzero value does not create new state, so no state gas is charged
    and the header reports the execution dimension alone.
    """
    storage = Storage()
    code = Op.SSTORE(
        storage.store_next(2),
        2,
        original_value=1,
        current_value=1,
        new_value=2,
    )
    assert code.state_cost(fork) == 0, "no state growth, no state gas"
    tx_execution = (
        fork.transaction_intrinsic_cost_calculator()()
        + code.execution_cost(fork)
    )

    contract = pre.deploy_contract(code=code, storage={0: 1})

    tx = Transaction(
        to=contract,
        state_gas_reservoir=0,
        sender=pre.fund_eoa(),
        expected_receipt=TransactionReceipt(cumulative_gas_used=tx_execution),
    )

    state_test(
        pre=pre,
        post={contract: Account(storage=storage)},
        tx=tx,
        blockchain_test_header_verify=Header(gas_used=tx_execution),
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.