Skip to content

Commit 6ac8e40

Browse files
committed
feat(spec-specs, tests): 8037 2d edge cases
1 parent 5416cbb commit 6ac8e40

2 files changed

Lines changed: 97 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
@@ -528,6 +528,52 @@ def test_tx_rejected_when_regular_gas_exceeds_block_limit_small(
528528
)
529529

530530

531+
@pytest.mark.valid_from("EIP8037")
532+
def test_tx_accepted_when_regular_gas_exactly_fits_block_limit_small(
533+
blockchain_test: BlockchainTestFiller,
534+
pre: Alloc,
535+
fork: Fork,
536+
) -> None:
537+
"""
538+
Accept a small-gas tx whose regular gas exactly fits the block.
539+
540+
Boundary counterpart to
541+
``test_tx_rejected_when_regular_gas_exceeds_block_limit_small``.
542+
The second tx's gas_limit equals the remaining regular budget
543+
exactly. The inclusion check uses strict ``>``, so equal must
544+
pass. Catches an off-by-one ``>=`` bug.
545+
"""
546+
intrinsic_gas = fork.transaction_intrinsic_cost_calculator()()
547+
548+
block_gas_limit = intrinsic_gas * 2
549+
550+
filler = pre.deploy_contract(code=Op.STOP)
551+
filler_tx = Transaction(
552+
to=filler,
553+
gas_limit=intrinsic_gas,
554+
sender=pre.fund_eoa(),
555+
)
556+
557+
accepted = pre.deploy_contract(code=Op.STOP)
558+
accepted_tx = Transaction(
559+
to=accepted,
560+
gas_limit=intrinsic_gas,
561+
sender=pre.fund_eoa(),
562+
)
563+
564+
blockchain_test(
565+
genesis_environment=Environment(gas_limit=block_gas_limit),
566+
pre=pre,
567+
blocks=[
568+
Block(
569+
txs=[filler_tx, accepted_tx],
570+
gas_limit=block_gas_limit,
571+
)
572+
],
573+
post={},
574+
)
575+
576+
531577
@pytest.mark.parametrize(
532578
"tx2_gas_limit_equals_block_gas_limit",
533579
[

tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_create.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1886,6 +1886,57 @@ def test_failed_create_tx_state_gas_dominates(
18861886
)
18871887

18881888

1889+
@pytest.mark.parametrize(
1890+
"failure_mode",
1891+
[
1892+
pytest.param("revert", id="revert"),
1893+
pytest.param("halt", id="halt"),
1894+
],
1895+
)
1896+
@pytest.mark.valid_from("EIP8037")
1897+
def test_failed_create_tx_sender_billing(
1898+
state_test: StateTestFiller,
1899+
pre: Alloc,
1900+
fork: Fork,
1901+
failure_mode: str,
1902+
) -> None:
1903+
"""
1904+
Verify sender billing for a failed creation tx with tight gas.
1905+
1906+
Complements ``test_failed_create_tx_state_gas_dominates`` which
1907+
checks the header. This pins ``cumulative_gas_used`` to verify
1908+
the execution state gas refund reaches the sender.
1909+
"""
1910+
intrinsic_calc = fork.transaction_intrinsic_cost_calculator()
1911+
1912+
if failure_mode == "revert":
1913+
init_code = Op.REVERT(0, 0)
1914+
else:
1915+
init_code = Op.INVALID
1916+
1917+
intrinsic_total = intrinsic_calc(
1918+
calldata=bytes(init_code), contract_creation=True
1919+
)
1920+
gas_limit = intrinsic_total + 1000
1921+
1922+
if failure_mode == "revert":
1923+
expected_cumulative = intrinsic_total + init_code.gas_cost(fork)
1924+
else:
1925+
expected_cumulative = gas_limit
1926+
1927+
tx = Transaction(
1928+
to=None,
1929+
data=init_code,
1930+
gas_limit=gas_limit,
1931+
sender=pre.fund_eoa(),
1932+
expected_receipt=TransactionReceipt(
1933+
cumulative_gas_used=expected_cumulative,
1934+
),
1935+
)
1936+
1937+
state_test(pre=pre, post={}, tx=tx)
1938+
1939+
18891940
@pytest.mark.parametrize(
18901941
"initcode_size_delta",
18911942
[

0 commit comments

Comments
 (0)