Skip to content

Commit 1b0780a

Browse files
committed
feat(spec-specs, tests): 8037 2d edge cases
1 parent f5da8ef commit 1b0780a

2 files changed

Lines changed: 98 additions & 0 deletions

File tree

tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_block_2d_gas_accounting.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,52 @@ def test_tx_rejected_when_regular_gas_exceeds_block_limit_small(
515515
)
516516

517517

518+
@pytest.mark.valid_from("EIP8037")
519+
def test_tx_accepted_when_regular_gas_exactly_fits_block_limit_small(
520+
blockchain_test: BlockchainTestFiller,
521+
pre: Alloc,
522+
fork: Fork,
523+
) -> None:
524+
"""
525+
Accept a small-gas tx whose regular gas exactly fits the block.
526+
527+
Boundary counterpart to
528+
``test_tx_rejected_when_regular_gas_exceeds_block_limit_small``.
529+
The second tx's gas_limit equals the remaining regular budget
530+
exactly. The inclusion check uses strict ``>``, so equal must
531+
pass. Catches an off-by-one ``>=`` bug.
532+
"""
533+
intrinsic_gas = fork.transaction_intrinsic_cost_calculator()()
534+
535+
block_gas_limit = intrinsic_gas * 2
536+
537+
filler = pre.deploy_contract(code=Op.STOP)
538+
filler_tx = Transaction(
539+
to=filler,
540+
gas_limit=intrinsic_gas,
541+
sender=pre.fund_eoa(),
542+
)
543+
544+
accepted = pre.deploy_contract(code=Op.STOP)
545+
accepted_tx = Transaction(
546+
to=accepted,
547+
gas_limit=intrinsic_gas,
548+
sender=pre.fund_eoa(),
549+
)
550+
551+
blockchain_test(
552+
genesis_environment=Environment(gas_limit=block_gas_limit),
553+
pre=pre,
554+
blocks=[
555+
Block(
556+
txs=[filler_tx, accepted_tx],
557+
gas_limit=block_gas_limit,
558+
)
559+
],
560+
post={},
561+
)
562+
563+
518564
@pytest.mark.parametrize(
519565
"tx2_gas_limit_equals_block_gas_limit",
520566
[

tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
Storage,
2828
Transaction,
2929
TransactionException,
30+
TransactionReceipt,
3031
compute_create_address,
3132
)
3233
from execution_testing.checklists import EIPChecklist
@@ -1585,6 +1586,57 @@ def test_failed_create_tx_state_gas_dominates(
15851586
)
15861587

15871588

1589+
@pytest.mark.parametrize(
1590+
"failure_mode",
1591+
[
1592+
pytest.param("revert", id="revert"),
1593+
pytest.param("halt", id="halt"),
1594+
],
1595+
)
1596+
@pytest.mark.valid_from("EIP8037")
1597+
def test_failed_create_tx_sender_billing(
1598+
state_test: StateTestFiller,
1599+
pre: Alloc,
1600+
fork: Fork,
1601+
failure_mode: str,
1602+
) -> None:
1603+
"""
1604+
Verify sender billing for a failed creation tx with tight gas.
1605+
1606+
Complements ``test_failed_create_tx_state_gas_dominates`` which
1607+
checks the header. This pins ``cumulative_gas_used`` to verify
1608+
the execution state gas refund reaches the sender.
1609+
"""
1610+
intrinsic_calc = fork.transaction_intrinsic_cost_calculator()
1611+
1612+
if failure_mode == "revert":
1613+
init_code = Op.REVERT(0, 0)
1614+
else:
1615+
init_code = Op.INVALID
1616+
1617+
intrinsic_total = intrinsic_calc(
1618+
calldata=bytes(init_code), contract_creation=True
1619+
)
1620+
gas_limit = intrinsic_total + 1000
1621+
1622+
if failure_mode == "revert":
1623+
expected_cumulative = intrinsic_total + init_code.gas_cost(fork)
1624+
else:
1625+
expected_cumulative = gas_limit
1626+
1627+
tx = Transaction(
1628+
to=None,
1629+
data=init_code,
1630+
gas_limit=gas_limit,
1631+
sender=pre.fund_eoa(),
1632+
expected_receipt=TransactionReceipt(
1633+
cumulative_gas_used=expected_cumulative,
1634+
),
1635+
)
1636+
1637+
state_test(pre=pre, post={}, tx=tx)
1638+
1639+
15881640
@pytest.mark.parametrize(
15891641
"initcode_size_delta",
15901642
[

0 commit comments

Comments
 (0)