Skip to content

Commit 3ec99ef

Browse files
authored
fix(tests): Restrict extra args being passed to BaseTest; fix valid BAL tests (ethereum#2102)
* - fix(fw): Restrict extra fields for ``BaseTest`` types - refactor(tests): Remove benign extra args to blockchain tests After restricting extra args, some tests were failing because they passed extra args that do not exist on the `BlockchainTest` class. This does not affect the test itself but now will cause failure. Thankfully, mypy caught all of these so it was easier to identify. * fix(tests,bal): Fix unreleased BAL tests from old design - BAL tests were wrongly passing the expected BAL to the ``blockchain_test`` itself. This was updated to live on the ``Block`` itself, but the tests were not updated. With the recent changes to restrict extra fields on the ``BlockchainTest`` (``BaseTest`` classess), this now correctly raises an error and allows us to have a sanity check.
1 parent 1909874 commit 3ec99ef

File tree

4 files changed

+58
-50
lines changed

4 files changed

+58
-50
lines changed

amsterdam/eip7928_block_level_access_lists/test_block_access_lists.py

Lines changed: 57 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,16 @@ def test_bal_nonce_changes(
4343
value=100,
4444
)
4545

46-
block = Block(txs=[tx])
46+
block = Block(
47+
txs=[tx],
48+
expected_block_access_list=BlockAccessListExpectation(
49+
account_expectations={
50+
alice: BalAccountExpectation(
51+
nonce_changes=[BalNonceChange(tx_index=1, post_nonce=1)],
52+
),
53+
}
54+
),
55+
)
4756

4857
blockchain_test(
4958
pre=pre,
@@ -52,13 +61,6 @@ def test_bal_nonce_changes(
5261
alice: Account(nonce=1),
5362
bob: Account(balance=100),
5463
},
55-
expected_block_access_list=BlockAccessListExpectation(
56-
account_expectations={
57-
alice: BalAccountExpectation(
58-
nonce_changes=[BalNonceChange(tx_index=1, post_nonce=1)],
59-
),
60-
}
61-
),
6264
)
6365

6466

@@ -88,21 +90,15 @@ def test_bal_balance_changes(
8890
gas_price=1_000_000_000,
8991
)
9092

91-
block = Block(txs=[tx])
9293
alice_account = pre[alice]
9394
assert alice_account is not None, "Alice account should exist"
9495
alice_initial_balance = alice_account.balance
9596

9697
# Account for both the value sent and gas cost (gas_price * gas_used)
9798
alice_final_balance = alice_initial_balance - 100 - (intrinsic_gas_cost * 1_000_000_000)
9899

99-
blockchain_test(
100-
pre=pre,
101-
blocks=[block],
102-
post={
103-
alice: Account(nonce=1, balance=alice_final_balance),
104-
bob: Account(balance=100),
105-
},
100+
block = Block(
101+
txs=[tx],
106102
expected_block_access_list=BlockAccessListExpectation(
107103
account_expectations={
108104
alice: BalAccountExpectation(
@@ -118,6 +114,15 @@ def test_bal_balance_changes(
118114
),
119115
)
120116

117+
blockchain_test(
118+
pre=pre,
119+
blocks=[block],
120+
post={
121+
alice: Account(nonce=1, balance=alice_final_balance),
122+
bob: Account(balance=100),
123+
},
124+
)
125+
121126

122127
@pytest.mark.valid_from("Amsterdam")
123128
def test_bal_storage_writes(
@@ -139,15 +144,8 @@ def test_bal_storage_writes(
139144
gas_limit=100000,
140145
)
141146

142-
block = Block(txs=[tx])
143-
144-
blockchain_test(
145-
pre=pre,
146-
blocks=[block],
147-
post={
148-
alice: Account(nonce=1),
149-
storage_contract: Account(storage={0x01: 0x42}),
150-
},
147+
block = Block(
148+
txs=[tx],
151149
expected_block_access_list=BlockAccessListExpectation(
152150
account_expectations={
153151
storage_contract: BalAccountExpectation(
@@ -162,6 +160,15 @@ def test_bal_storage_writes(
162160
),
163161
)
164162

163+
blockchain_test(
164+
pre=pre,
165+
blocks=[block],
166+
post={
167+
alice: Account(nonce=1),
168+
storage_contract: Account(storage={0x01: 0x42}),
169+
},
170+
)
171+
165172

166173
@pytest.mark.valid_from("Amsterdam")
167174
def test_bal_storage_reads(
@@ -181,7 +188,16 @@ def test_bal_storage_reads(
181188
gas_limit=100000,
182189
)
183190

184-
block = Block(txs=[tx])
191+
block = Block(
192+
txs=[tx],
193+
expected_block_access_list=BlockAccessListExpectation(
194+
account_expectations={
195+
storage_contract: BalAccountExpectation(
196+
storage_reads=[0x01],
197+
),
198+
}
199+
),
200+
)
185201

186202
blockchain_test(
187203
pre=pre,
@@ -190,13 +206,6 @@ def test_bal_storage_reads(
190206
alice: Account(nonce=1),
191207
storage_contract: Account(storage={0x01: 0x42}),
192208
},
193-
expected_block_access_list=BlockAccessListExpectation(
194-
account_expectations={
195-
storage_contract: BalAccountExpectation(
196-
storage_reads=[0x01],
197-
),
198-
}
199-
),
200209
)
201210

202211

@@ -244,21 +253,10 @@ def test_bal_code_changes(
244253
gas_limit=500000,
245254
)
246255

247-
block = Block(txs=[tx])
248-
249256
created_contract = compute_create_address(address=factory_contract, nonce=1)
250257

251-
blockchain_test(
252-
pre=pre,
253-
blocks=[block],
254-
post={
255-
alice: Account(nonce=1),
256-
factory_contract: Account(nonce=2), # incremented by CREATE to 2
257-
created_contract: Account(
258-
code=runtime_code_bytes,
259-
storage={},
260-
),
261-
},
258+
block = Block(
259+
txs=[tx],
262260
expected_block_access_list=BlockAccessListExpectation(
263261
account_expectations={
264262
alice: BalAccountExpectation(
@@ -273,3 +271,16 @@ def test_bal_code_changes(
273271
}
274272
),
275273
)
274+
275+
blockchain_test(
276+
pre=pre,
277+
blocks=[block],
278+
post={
279+
alice: Account(nonce=1),
280+
factory_contract: Account(nonce=2), # incremented by CREATE to 2
281+
created_contract: Account(
282+
code=runtime_code_bytes,
283+
storage={},
284+
),
285+
},
286+
)

osaka/eip7825_transaction_gas_limit_cap/test_tx_gas_limit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def test_tx_gas_larger_than_block_gas_limit(
198198
exception=TransactionException.GAS_ALLOWANCE_EXCEEDED if exceed_block_gas_limit else None,
199199
)
200200

201-
blockchain_test(env=env, pre=pre, post={}, blocks=[block])
201+
blockchain_test(pre=pre, post={}, blocks=[block])
202202

203203

204204
@pytest.fixture

prague/eip2935_historical_block_hashes_from_state/test_block_hashes.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,6 @@ def test_invalid_history_contract_calls(
430430
pre=pre,
431431
blocks=blocks,
432432
post=post,
433-
reverts=reverts,
434433
)
435434

436435

@@ -490,5 +489,4 @@ def test_invalid_history_contract_calls_input_size(
490489
pre=pre,
491490
blocks=blocks,
492491
post=post,
493-
reverts=reverts,
494492
)

unscheduled/eip7692_eof_v1/eip6206_jumpf/test_jumpf_execution.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,6 @@ def test_jumpf_with_inputs_stack_overflow(
628628
def test_jumpf_infinite_loop(eof_state_test: EOFStateTestFiller, container: Container):
629629
"""Tests JUMPF causing an infinite loop."""
630630
eof_state_test(
631-
tx_gas=100_000,
632631
container=container,
633632
container_post=Account(storage={slot_code_worked: 0}),
634633
)

0 commit comments

Comments
 (0)