Skip to content

Commit 7cfe4bb

Browse files
committed
tweak blockchain test validation and fix gas_limit check
- We have an 'expectException' flag we can reference for validating should_be_good_block for blockchain tests. These changes tweak blockchain test validation to use this flag since some block fixtures for tests have both good and bad blocks in them now. - If the gas limit is AT 1/1024th of the parent gas limit, this is also unacceptable. These changes add equal-to signs when comparing the gas limit to the parent. This passes currently-failing ethereum tests >= London.
1 parent 29d255d commit 7cfe4bb

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

eth/tools/_utils/normalization.py

+2
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,8 @@ def normalize_block(block: Dict[str, Any]) -> Dict[str, Any]:
567567
for transaction
568568
in block['transactions']
569569
]
570+
if 'expectException' in block:
571+
normalized_block['expectException'] = block['expectException']
570572
return normalized_block
571573

572574

eth/validation.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,11 @@ def validate_vm_configuration(vm_configuration: Tuple[Tuple[int, Type[VirtualMac
230230

231231
def validate_gas_limit(gas_limit: int, parent_gas_limit: int) -> None:
232232
low_bound, high_bound = compute_gas_limit_bounds(parent_gas_limit)
233-
if gas_limit < low_bound:
233+
if gas_limit <= low_bound:
234234
raise ValidationError(
235235
f"The gas limit {gas_limit} is too low. It must be at least {low_bound}"
236236
)
237-
elif gas_limit > high_bound:
237+
elif gas_limit >= high_bound:
238238
raise ValidationError(
239239
f"The gas limit {gas_limit} is too high. It must be at most {high_bound}"
240240
)

tests/json-fixtures/blockchain/test_blockchain.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,11 @@ def assert_imported_genesis_header_unchanged(genesis_fields, genesis_header):
369369
)
370370

371371

372+
EXPECTED_BAD_BLOCK_EXCEPTIONS = (
373+
TypeError, rlp.DecodingError, rlp.DeserializationError, ValidationError, AssertionError
374+
)
375+
376+
372377
def test_blockchain_fixtures(fixture_data, fixture):
373378
try:
374379
chain = new_chain_from_fixture(fixture)
@@ -401,7 +406,7 @@ def test_blockchain_fixtures(fixture_data, fixture):
401406
# 4 - check that all previous blocks were valid
402407

403408
for block_fixture in fixture['blocks']:
404-
should_be_good_block = 'blockHeader' in block_fixture
409+
should_be_good_block = 'expectException' not in block_fixture
405410

406411
if 'rlp_error' in block_fixture:
407412
assert not should_be_good_block
@@ -418,7 +423,7 @@ def test_blockchain_fixtures(fixture_data, fixture):
418423
else:
419424
try:
420425
apply_fixture_block_to_chain(block_fixture, chain)
421-
except (TypeError, rlp.DecodingError, rlp.DeserializationError, ValidationError):
426+
except EXPECTED_BAD_BLOCK_EXCEPTIONS:
422427
# failure is expected on this bad block
423428
pass
424429
else:

0 commit comments

Comments
 (0)