Skip to content

test_receipt_cumulative_differs_from_header_gas_used()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_block_2d_gas_accounting.py::test_receipt_cumulative_differs_from_header_gas_used@c74f1a67.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_block_2d_gas_accounting.py::test_receipt_cumulative_differs_from_header_gas_used --fork Amsterdam

Verify receipt cumulative_gas_used can diverge from header gas_used under 2D accounting when state gas dominates.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_block_2d_gas_accounting.py
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
@pytest.mark.valid_from("EIP8037")
def test_receipt_cumulative_differs_from_header_gas_used(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Verify receipt cumulative_gas_used can diverge from header
    gas_used under 2D accounting when state gas dominates.
    """
    tx_regular, tx_state = sstore_tx_gas(fork)
    num_txs = 3

    sstore_state_gas = Op.SSTORE(new_value=1).state_cost(fork)
    per_tx_gas_used = tx_regular + tx_state

    txs: list[Transaction] = []
    post: dict = {}
    for i in range(num_txs):
        storage = Storage()
        contract = pre.deploy_contract(
            code=Op.SSTORE(storage.store_next(1), 1) + Op.STOP,
        )
        txs.append(
            Transaction(
                to=contract,
                state_gas_reservoir=sstore_state_gas,
                sender=pre.fund_eoa(),
                expected_receipt=TransactionReceipt(
                    cumulative_gas_used=(i + 1) * per_tx_gas_used,
                ),
            )
        )
        post[contract] = Account(storage=storage)

    block_regular = num_txs * tx_regular
    block_state = num_txs * tx_state
    header_gas_used = max(block_regular, block_state)

    assert block_state > block_regular
    assert header_gas_used < num_txs * per_tx_gas_used

    blockchain_test(
        pre=pre,
        blocks=[
            Block(
                txs=txs,
                header_verify=Header(gas_used=header_gas_used),
            ),
        ],
        post=post,
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.