Skip to content

Commit c288bcd

Browse files
committed
feat(test): configure block gas used with header_verify
1 parent 3178c2a commit c288bcd

2 files changed

Lines changed: 52 additions & 2 deletions

File tree

tests/ported_static/stCreateTest/test_transaction_collision_to_empty_but_code.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
Address,
1313
Alloc,
1414
Environment,
15+
Header,
1516
StateTestFiller,
1617
Transaction,
1718
)
@@ -136,4 +137,28 @@ def test_transaction_collision_to_empty_but_code(
136137
error=_exc,
137138
)
138139

139-
state_test(env=env, pre=pre, post=post, tx=tx)
140+
# On collision, all execution gas is reclassified to regular and the
141+
# tx-time state reservoir is restored. Under EIP-8037 2D gas this
142+
# gives header.gas_used = max(intrinsic_regular + execution_gas,
143+
# intrinsic_state); pre-EIP-8037 the state component is zero, so the
144+
# same expression collapses to tx.gas.
145+
intrinsic_total = fork.transaction_intrinsic_cost_calculator()(
146+
calldata=bytes(tx_data[d]),
147+
contract_creation=True,
148+
)
149+
intrinsic_state = fork.create_state_gas()
150+
intrinsic_regular = intrinsic_total - intrinsic_state
151+
execution_gas = tx_gas[g] - intrinsic_total
152+
expected_header_gas_used = max(
153+
intrinsic_regular + execution_gas, intrinsic_state
154+
)
155+
156+
state_test(
157+
env=env,
158+
pre=pre,
159+
post=post,
160+
tx=tx,
161+
blockchain_test_header_verify=Header(
162+
gas_used=expected_header_gas_used,
163+
),
164+
)

tests/ported_static/stEIP3607/test_init_colliding_with_non_empty_account.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
Address,
1313
Alloc,
1414
Environment,
15+
Header,
1516
StateTestFiller,
1617
Transaction,
1718
compute_create_address,
@@ -163,4 +164,28 @@ def test_init_colliding_with_non_empty_account(
163164
sender: Account(nonce=1),
164165
}
165166

166-
state_test(env=env, pre=pre, post=post, tx=tx)
167+
# On collision, all execution gas is reclassified to regular and the
168+
# tx-time state reservoir is restored. Under EIP-8037 2D gas this
169+
# gives header.gas_used = max(intrinsic_regular + execution_gas,
170+
# intrinsic_state); pre-EIP-8037 the state component is zero, so the
171+
# same expression collapses to tx.gas.
172+
intrinsic_total = fork.transaction_intrinsic_cost_calculator()(
173+
calldata=bytes(tx_data[d]),
174+
contract_creation=True,
175+
)
176+
intrinsic_state = fork.create_state_gas()
177+
intrinsic_regular = intrinsic_total - intrinsic_state
178+
execution_gas = tx_gas[g] - intrinsic_total
179+
expected_header_gas_used = max(
180+
intrinsic_regular + execution_gas, intrinsic_state
181+
)
182+
183+
state_test(
184+
env=env,
185+
pre=pre,
186+
post=post,
187+
tx=tx,
188+
blockchain_test_header_verify=Header(
189+
gas_used=expected_header_gas_used,
190+
),
191+
)

0 commit comments

Comments
 (0)