Skip to content

test_failed_create_header_gas_used()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py::test_failed_create_header_gas_used@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_failed_create_header_gas_used --fork Amsterdam

Verify block header gas_used for failed CREATE/CREATE2 via opcode.

A factory contract calls CREATE/CREATE2 which fails (revert or halt). Verify the block is accepted with correct gas accounting. Parametrized across failure modes and create opcodes.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
@pytest.mark.parametrize(
    "failure_mode",
    [
        pytest.param("revert", id="revert"),
        pytest.param("halt", id="halt"),
    ],
)
@pytest.mark.with_all_create_opcodes()
@pytest.mark.valid_from("EIP8037")
def test_failed_create_header_gas_used(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    fork: Fork,
    create_opcode: Op,
    failure_mode: str,
) -> None:
    """
    Verify block header gas_used for failed CREATE/CREATE2 via opcode.

    A factory contract calls CREATE/CREATE2 which fails (revert or
    halt). Verify the block is accepted with correct gas accounting.
    Parametrized across failure modes and create opcodes.
    """
    create_state_gas = fork.create_state_gas(code_size=0)

    if failure_mode == "revert":
        init_code = Op.REVERT(0, 0)
    else:
        init_code = Op.INVALID

    create_call = (
        create_opcode(value=0, offset=0, size=len(init_code), salt=0)
        if create_opcode == Op.CREATE2
        else create_opcode(value=0, offset=0, size=len(init_code))
    )

    storage = Storage()
    factory_code = Op.MSTORE(
        0,
        int.from_bytes(bytes(init_code), "big") << (256 - 8 * len(init_code)),
    ) + Op.SSTORE(
        storage.store_next(0, "create_fails"),
        create_call,
    )

    factory = pre.deploy_contract(factory_code)

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

    blockchain_test(
        pre=pre,
        blocks=[
            Block(txs=[tx]),
        ],
        post={factory: Account(storage=storage)},
    )

Parametrized Test Cases

This test generates 4 parametrized test cases across 1 fork.