Skip to content

test_create_selfdestruct_code_deposit_no_refund_header_check()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_selfdestruct.py::test_create_selfdestruct_code_deposit_no_refund_header_check@87aba1a3.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_selfdestruct.py::test_create_selfdestruct_code_deposit_no_refund_header_check --fork Amsterdam

Verify block header gas reflects the full account plus code-deposit state-gas charge on a same-tx CREATE+SELFDESTRUCT.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_selfdestruct.py
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
@pytest.mark.valid_from("EIP8037")
def test_create_selfdestruct_code_deposit_no_refund_header_check(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Verify block header gas reflects the full account plus code-deposit
    state-gas charge on a same-tx CREATE+SELFDESTRUCT.
    """
    gas_costs = fork.gas_costs()
    new_account_state_gas = gas_costs.NEW_ACCOUNT

    selfdestruct = Op.SELFDESTRUCT(Op.ADDRESS)
    sd_len = len(bytes(selfdestruct))
    code_size = 256
    assert code_size >= sd_len
    deployed = bytes(selfdestruct) + b"\x00" * (code_size - sd_len)
    initcode = Initcode(deploy_code=deployed)
    initcode_len = len(initcode)
    code_deposit_state_gas = fork.code_deposit_state_gas(code_size=code_size)

    factory_code = Op.CALLDATACOPY(
        0,
        0,
        Op.CALLDATASIZE,
        data_size=initcode_len,
        new_memory_size=initcode_len,
    ) + Op.POP(
        Op.CALL(
            gas=Op.GAS,
            address=Op.CREATE(
                value=0,
                offset=0,
                size=Op.CALLDATASIZE,
                init_code_size=initcode_len,
            ),
        )
    )
    factory = pre.deploy_contract(code=factory_code)
    created_address = compute_create_address(address=factory, nonce=1)

    total_state_gas = new_account_state_gas + code_deposit_state_gas
    tx = Transaction(
        to=factory,
        data=bytes(initcode),
        state_gas_reservoir=total_state_gas,
        sender=pre.fund_eoa(),
    )

    baseline_block_regular = 0x94C8
    expected_gas_used = max(baseline_block_regular, total_state_gas)

    blockchain_test(
        pre=pre,
        blocks=[
            Block(
                txs=[tx],
                header_verify=Header(gas_used=expected_gas_used),
            ),
        ],
        post={created_address: Account.NONEXISTENT},
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.