Skip to content

Test Tstorage Selfdestruct

Documentation for tests/cancun/eip1153_tstore/test_tstorage_selfdestruct.py.

Generate fixtures for these test cases with:

fill -v tests/cancun/eip1153_tstore/test_tstorage_selfdestruct.py
Tests for EIP-1153: Transient Storage

Test cases for TSTORE and TLOAD opcode calls in reentrancy after self-destruct, taking into account the changes in EIP-6780.

test_reentrant_selfdestructing_call(state_test, pre_existing_contract, caller_bytecode, callee_bytecode, expected_storage)

Test transient storage in different reentrancy contexts after selfdestructing.

Source code in tests/cancun/eip1153_tstore/test_tstorage_selfdestruct.py
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
@SelfDestructCases.parametrize()
def test_reentrant_selfdestructing_call(
    state_test: StateTestFiller,
    pre_existing_contract,
    caller_bytecode,
    callee_bytecode,
    expected_storage,
):
    """
    Test transient storage in different reentrancy contexts after selfdestructing.
    """
    env = Environment()

    pre = {
        TestAddress: Account(balance=10**40),
        caller_address: Account(code=caller_bytecode, nonce=1),
        copy_from_initcode_address: Account(code=Initcode(deploy_code=callee_bytecode)),
    }

    if pre_existing_contract:
        pre[callee_address] = Account(code=callee_bytecode)

    tx = Transaction(
        to=caller_address,
        gas_limit=1_000_000,
    )

    post: Dict = {caller_address: Account(storage=expected_storage)}

    if pre_existing_contract:
        post[callee_address] = Account(code=callee_bytecode)
    else:
        post[callee_address] = Account.NONEXISTENT

    state_test(env=env, pre=pre, post=post, tx=tx)