Skip to content

Commit 879accf

Browse files
kclowesfselmo
authored andcommitted
feat(spec-specs, tests): 8037 more 2d edge cases (ethereum#2735)
* feat(spec-specs, tests): 8037 2d edge cases * refactor(tests): Combine almost duplicated tests * refactor(test): DRY - merge boundary tests together and parametrize --------- Co-authored-by: fselmo <fselmo2@gmail.com>
1 parent 9a03237 commit 879accf

2 files changed

Lines changed: 38 additions & 22 deletions

File tree

tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_block_2d_gas_accounting.py

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -483,14 +483,28 @@ def test_multi_block_dimension_flip(
483483
)
484484

485485

486-
@pytest.mark.exception_test
486+
@pytest.mark.parametrize(
487+
"delta",
488+
[
489+
pytest.param(0, id="exactly_fits"),
490+
pytest.param(1, id="exceeds", marks=pytest.mark.exception_test),
491+
],
492+
)
487493
@pytest.mark.valid_from("EIP8037")
488-
def test_tx_rejected_when_regular_gas_exceeds_block_limit_small(
494+
def test_tx_inclusion_at_regular_gas_block_limit_small(
489495
blockchain_test: BlockchainTestFiller,
490496
pre: Alloc,
491497
fork: Fork,
498+
delta: int,
492499
) -> None:
493-
"""Reject a small-gas tx whose regular gas overflows the block."""
500+
"""
501+
Probe the regular-gas inclusion boundary with a small-gas tx.
502+
503+
The second tx's ``gas_limit`` is the remaining regular budget
504+
plus ``delta``. The inclusion check uses strict ``>``, so
505+
``delta=0`` must pass and ``delta=1`` must reject with
506+
``GAS_ALLOWANCE_EXCEEDED``. Catches an off-by-one ``>=`` bug.
507+
"""
494508
gas_limit_cap = fork.transaction_gas_limit_cap()
495509
assert gas_limit_cap is not None
496510
intrinsic_gas = fork.transaction_intrinsic_cost_calculator()()
@@ -504,24 +518,25 @@ def test_tx_rejected_when_regular_gas_exceeds_block_limit_small(
504518
sender=pre.fund_eoa(),
505519
)
506520

507-
rejected_gas_limit = intrinsic_gas + 1
508-
assert rejected_gas_limit < gas_limit_cap
509-
rejected = pre.deploy_contract(code=Op.STOP)
510-
rejected_tx = Transaction(
511-
to=rejected,
512-
gas_limit=rejected_gas_limit,
521+
second_gas_limit = intrinsic_gas + delta
522+
assert second_gas_limit < gas_limit_cap
523+
error = TransactionException.GAS_ALLOWANCE_EXCEEDED if delta else None
524+
second = pre.deploy_contract(code=Op.STOP)
525+
second_tx = Transaction(
526+
to=second,
527+
gas_limit=second_gas_limit,
513528
sender=pre.fund_eoa(),
514-
error=TransactionException.GAS_ALLOWANCE_EXCEEDED,
529+
error=error,
515530
)
516531

517532
blockchain_test(
518533
genesis_environment=Environment(gas_limit=block_gas_limit),
519534
pre=pre,
520535
blocks=[
521536
Block(
522-
txs=[filler_tx, rejected_tx],
537+
txs=[filler_tx, second_tx],
523538
gas_limit=block_gas_limit,
524-
exception=TransactionException.GAS_ALLOWANCE_EXCEEDED,
539+
exception=error,
525540
)
526541
],
527542
post={},

tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,15 +1845,16 @@ def test_create_code_deposit_oog_refunds_state_gas(
18451845
)
18461846
@pytest.mark.valid_from("EIP8037")
18471847
def test_failed_create_tx_refunds_intrinsic_new_account(
1848-
blockchain_test: BlockchainTestFiller,
1848+
state_test: StateTestFiller,
18491849
pre: Alloc,
18501850
fork: Fork,
18511851
init_code: Bytecode,
18521852
) -> None:
18531853
"""
18541854
Verify the NEW_ACCOUNT × CPSB portion of intrinsic_state_gas is
1855-
refunded on creation-tx revert/halt, so block state-gas excludes
1856-
it and header gas_used reflects only the regular component.
1855+
refunded on creation-tx revert/halt. Block state-gas excludes it
1856+
so header gas_used reflects only the regular component, and the
1857+
sender's receipt reflects the same refund via cumulative_gas_used.
18571858
"""
18581859
intrinsic_calc = fork.transaction_intrinsic_cost_calculator()
18591860
create_state_gas = fork.create_state_gas(code_size=0)
@@ -1870,23 +1871,23 @@ def test_failed_create_tx_refunds_intrinsic_new_account(
18701871
regular_consumed = init_code.regular_cost(fork)
18711872

18721873
expected_gas_used = intrinsic_regular + regular_consumed
1874+
expected_cumulative = intrinsic_total + regular_consumed - create_state_gas
18731875

18741876
tx = Transaction(
18751877
to=None,
18761878
data=init_code,
18771879
gas_limit=gas_limit,
18781880
sender=pre.fund_eoa(),
1881+
expected_receipt=TransactionReceipt(
1882+
cumulative_gas_used=expected_cumulative,
1883+
),
18791884
)
18801885

1881-
blockchain_test(
1886+
state_test(
18821887
pre=pre,
1883-
blocks=[
1884-
Block(
1885-
txs=[tx],
1886-
header_verify=Header(gas_used=expected_gas_used),
1887-
),
1888-
],
18891888
post={},
1889+
tx=tx,
1890+
blockchain_test_header_verify=Header(gas_used=expected_gas_used),
18901891
)
18911892

18921893

0 commit comments

Comments
 (0)