Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -483,14 +483,28 @@ def test_multi_block_dimension_flip(
)


@pytest.mark.exception_test
@pytest.mark.parametrize(
"delta",
[
pytest.param(0, id="exactly_fits"),
pytest.param(1, id="exceeds", marks=pytest.mark.exception_test),
],
)
@pytest.mark.valid_from("EIP8037")
def test_tx_rejected_when_regular_gas_exceeds_block_limit_small(
def test_tx_inclusion_at_regular_gas_block_limit_small(
blockchain_test: BlockchainTestFiller,
pre: Alloc,
fork: Fork,
delta: int,
) -> None:
"""Reject a small-gas tx whose regular gas overflows the block."""
"""
Probe the regular-gas inclusion boundary with a small-gas tx.

The second tx's ``gas_limit`` is the remaining regular budget
plus ``delta``. The inclusion check uses strict ``>``, so
``delta=0`` must pass and ``delta=1`` must reject with
``GAS_ALLOWANCE_EXCEEDED``. Catches an off-by-one ``>=`` bug.
"""
gas_limit_cap = fork.transaction_gas_limit_cap()
assert gas_limit_cap is not None
intrinsic_gas = fork.transaction_intrinsic_cost_calculator()()
Expand All @@ -504,24 +518,25 @@ def test_tx_rejected_when_regular_gas_exceeds_block_limit_small(
sender=pre.fund_eoa(),
)

rejected_gas_limit = intrinsic_gas + 1
assert rejected_gas_limit < gas_limit_cap
rejected = pre.deploy_contract(code=Op.STOP)
rejected_tx = Transaction(
to=rejected,
gas_limit=rejected_gas_limit,
second_gas_limit = intrinsic_gas + delta
assert second_gas_limit < gas_limit_cap
error = TransactionException.GAS_ALLOWANCE_EXCEEDED if delta else None
second = pre.deploy_contract(code=Op.STOP)
second_tx = Transaction(
to=second,
gas_limit=second_gas_limit,
sender=pre.fund_eoa(),
error=TransactionException.GAS_ALLOWANCE_EXCEEDED,
error=error,
)

blockchain_test(
genesis_environment=Environment(gas_limit=block_gas_limit),
pre=pre,
blocks=[
Block(
txs=[filler_tx, rejected_tx],
txs=[filler_tx, second_tx],
gas_limit=block_gas_limit,
exception=TransactionException.GAS_ALLOWANCE_EXCEEDED,
exception=error,
)
],
post={},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1845,15 +1845,16 @@ def test_create_code_deposit_oog_refunds_state_gas(
)
@pytest.mark.valid_from("EIP8037")
def test_failed_create_tx_refunds_intrinsic_new_account(
blockchain_test: BlockchainTestFiller,
state_test: StateTestFiller,
pre: Alloc,
fork: Fork,
init_code: Bytecode,
) -> None:
"""
Verify the NEW_ACCOUNT × CPSB portion of intrinsic_state_gas is
refunded on creation-tx revert/halt, so block state-gas excludes
it and header gas_used reflects only the regular component.
refunded on creation-tx revert/halt. Block state-gas excludes it
so header gas_used reflects only the regular component, and the
sender's receipt reflects the same refund via cumulative_gas_used.
"""
intrinsic_calc = fork.transaction_intrinsic_cost_calculator()
create_state_gas = fork.create_state_gas(code_size=0)
Expand All @@ -1870,23 +1871,23 @@ def test_failed_create_tx_refunds_intrinsic_new_account(
regular_consumed = init_code.regular_cost(fork)

expected_gas_used = intrinsic_regular + regular_consumed
expected_cumulative = intrinsic_total + regular_consumed - create_state_gas

tx = Transaction(
to=None,
data=init_code,
gas_limit=gas_limit,
sender=pre.fund_eoa(),
expected_receipt=TransactionReceipt(
cumulative_gas_used=expected_cumulative,
),
)

blockchain_test(
state_test(
pre=pre,
blocks=[
Block(
txs=[tx],
header_verify=Header(gas_used=expected_gas_used),
),
],
post={},
tx=tx,
blockchain_test_header_verify=Header(gas_used=expected_gas_used),
)


Expand Down
Loading