Skip to content

Commit ff9494a

Browse files
fselmocarver
authored andcommitted
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 fddce69 commit ff9494a

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

eth/tools/_utils/normalization.py

Lines changed: 2 additions & 0 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,11 @@ def assert_imported_genesis_header_unchanged(genesis_fields, genesis_header):
371371
)
372372

373373

374+
EXPECTED_BAD_BLOCK_EXCEPTIONS = (
375+
TypeError, rlp.DecodingError, rlp.DeserializationError, ValidationError, AssertionError,
376+
)
377+
378+
374379
def test_blockchain_fixtures(fixture_data, fixture):
375380
try:
376381
chain = new_chain_from_fixture(fixture)
@@ -403,7 +408,7 @@ def test_blockchain_fixtures(fixture_data, fixture):
403408
# 4 - check that all previous blocks were valid
404409

405410
for block_fixture in fixture['blocks']:
406-
should_be_good_block = 'blockHeader' in block_fixture
411+
should_be_good_block = 'expectException' not in block_fixture
407412

408413
if 'rlp_error' in block_fixture:
409414
assert not should_be_good_block
@@ -420,7 +425,7 @@ def test_blockchain_fixtures(fixture_data, fixture):
420425
else:
421426
try:
422427
apply_fixture_block_to_chain(block_fixture, chain)
423-
except (TypeError, rlp.DecodingError, rlp.DeserializationError, ValidationError):
428+
except EXPECTED_BAD_BLOCK_EXCEPTIONS:
424429
# failure is expected on this bad block
425430
pass
426431
else:

0 commit comments

Comments
 (0)