Skip to content

test_block_gas_used_with_state_ops()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_reservoir.py::test_block_gas_used_with_state_ops@87aba1a3.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_reservoir.py::test_block_gas_used_with_state_ops --fork Amsterdam

Test block gas_used includes state gas contribution.

A transaction performing SSTORE zero-to-nonzero contributes to both block_gas_used and block_state_gas_used. The block header gas_used is max(block_gas_used, block_state_gas_used).

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_reservoir.py
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
@pytest.mark.valid_from("EIP8037")
def test_block_gas_used_with_state_ops(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Test block gas_used includes state gas contribution.

    A transaction performing SSTORE zero-to-nonzero contributes to both
    block_gas_used and block_state_gas_used. The block header gas_used
    is max(block_gas_used, block_state_gas_used).
    """
    storage = Storage()
    code = Op.SSTORE(storage.store_next(1), 1)
    contract = pre.deploy_contract(code=code)

    tx = Transaction(
        to=contract,
        state_gas_reservoir=0,
        sender=pre.fund_eoa(),
    )

    intrinsic_cost = fork.transaction_intrinsic_cost_calculator()
    block_regular_gas = intrinsic_cost() + code.regular_cost(fork)
    block_state_gas = code.state_cost(fork)
    assert block_state_gas > block_regular_gas

    blockchain_test(
        pre=pre,
        blocks=[
            Block(
                txs=[tx],
                header_verify=Header(
                    gas_used=block_state_gas,
                ),
            ),
        ],
        post={contract: Account(storage=storage)},
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.