Skip to content

Commit 2bc7c79

Browse files
feat(tests): improve robustness for EIP-7981 (#2696)
Co-authored-by: spencer-tb <spencer.taylor-brown@ethereum.org>
1 parent 8bd536b commit 2bc7c79

1 file changed

Lines changed: 33 additions & 3 deletions

File tree

tests/ported_static/stEIP2930/test_transaction_costs.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
StateTestFiller,
1919
Transaction,
2020
)
21-
from execution_testing.forks import Fork
21+
from execution_testing.forks import Amsterdam, Fork
2222
from execution_testing.specs.static_state.expect_section import (
2323
resolve_expect_post,
2424
)
@@ -143,7 +143,16 @@ def test_transaction_costs(
143143
)
144144
pre[sender] = Account(balance=0x5FA9C18)
145145

146-
expect_entries_: list[dict] = [
146+
expect_entries: list[dict] = [
147+
# EIP-7981 changes access list costs in Amsterdam+. Balance is a
148+
# placeholder; the expected value is computed dynamically below.
149+
# Ordered first so Amsterdam+ forks match here instead of the
150+
# entries below.
151+
{
152+
"indexes": {"data": -1, "gas": -1, "value": -1},
153+
"network": [">=Amsterdam"],
154+
"result": {sender: Account(balance=0)},
155+
},
147156
{
148157
"indexes": {"data": [0, 1], "gas": -1, "value": -1},
149158
"network": ["Cancun"],
@@ -181,7 +190,7 @@ def test_transaction_costs(
181190
},
182191
]
183192

184-
post, _exc = resolve_expect_post(expect_entries_, d, g, v, fork)
193+
post, _exc = resolve_expect_post(expect_entries, d, g, v, fork)
185194

186195
tx_data = [
187196
Bytes("00"),
@@ -455,4 +464,25 @@ def test_transaction_costs(
455464
error=_exc,
456465
)
457466

467+
# EIP-7981 (access list repricing) activates in Amsterdam. Compute the
468+
# expected balance dynamically from the fork's intrinsic cost calculator
469+
# rather than hardcoding values that change as EIP-7981 evolves. Past
470+
# forks keep their original hardcoded values above.
471+
if _exc is None and fork >= Amsterdam:
472+
sender_pre = pre[sender]
473+
assert sender_pre is not None
474+
gas_price = int(tx.gas_price or tx.max_fee_per_gas or 0)
475+
intrinsic_gas = fork.transaction_intrinsic_cost_calculator()(
476+
calldata=tx.data,
477+
contract_creation=tx.to is None,
478+
access_list=tx.access_list,
479+
)
480+
post[sender] = Account(
481+
balance=(
482+
int(sender_pre.balance)
483+
- int(tx.value)
484+
- intrinsic_gas * gas_price
485+
),
486+
)
487+
458488
state_test(env=env, pre=pre, post=post, tx=tx)

0 commit comments

Comments
 (0)