Skip to content

Commit 795a08e

Browse files
committed
Failing blockchain tests now emit a state diff
- Blockchain tests embed the GeneralStateTest's. They were previously being skipped but the former enable nice state diffs and the latter don't. This commit turns them on again. Future work: Remove state_tests.py, as of this commit the state tests are being run twice. - The tests were inefficient, they first checked that the state hash matched and then checked that the states matched. It's unlikely the states will ever not match! - Some validations needed to be deferred until after state-tree comparison, or else they would fail the test early with an unhelpful message.
1 parent f616298 commit 795a08e

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

eth/tools/fixtures/helpers.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
BaseVM,
4141
)
4242
from eth.vm.forks import (
43+
ConstantinopleVM,
4344
ByzantiumVM,
4445
TangerineWhistleVM,
4546
FrontierVM,
@@ -123,6 +124,10 @@ def chain_vm_configuration(fixture: Dict[str, Any]) -> Iterable[Tuple[int, Type[
123124
return (
124125
(0, ByzantiumVM),
125126
)
127+
elif network == 'Constantinople':
128+
return (
129+
(0, ConstantinopleVM),
130+
)
126131
elif network == 'FrontierToHomesteadAt5':
127132
HomesteadVM = BaseHomesteadVM.configure(support_dao_fork=False)
128133
return (
@@ -209,7 +214,7 @@ def apply_fixture_block_to_chain(block_fixture: Dict[str, Any],
209214

210215
block = rlp.decode(block_fixture['rlp'], sedes=block_class)
211216

212-
mined_block, _, _ = chain.import_block(block)
217+
mined_block, _, _ = chain.import_block(block, perform_validation=False)
213218

214219
rlp_encoded_mined_block = rlp.encode(mined_block, sedes=block_class)
215220

tests/json-fixtures/test_blockchain.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,13 @@ def blockchain_fixture_mark_fn(fixture_path, fixture_name):
5757
return pytest.mark.xfail(reason="Listed in INCORRECT_UPSTREAM_TESTS.")
5858

5959

60-
def blockchain_fixture_ignore_fn(fixture_path, fixture_name):
61-
if fixture_path.startswith('GeneralStateTests'):
62-
# General state tests are also exported as blockchain tests. We
63-
# skip them here so we don't run them twice
64-
return True
65-
66-
6760
def pytest_generate_tests(metafunc):
6861
generate_fixture_tests(
6962
metafunc=metafunc,
7063
base_fixture_path=BASE_FIXTURE_PATH,
7164
filter_fn=filter_fixtures(
7265
fixtures_base_dir=BASE_FIXTURE_PATH,
7366
mark_fn=blockchain_fixture_mark_fn,
74-
ignore_fn=blockchain_fixture_ignore_fn,
7567
),
7668
)
7769

@@ -111,8 +103,10 @@ def test_blockchain_fixtures(fixture_data, fixture):
111103
# 2 - loop over blocks:
112104
# - apply transactions
113105
# - mine block
114-
# 4 - profit!!
106+
# 3 - diff resulting state with expected state
107+
# 4 - check that all previous blocks were valid
115108

109+
mined_blocks = list()
116110
for block_fixture in fixture['blocks']:
117111
should_be_good_block = 'blockHeader' in block_fixture
118112

@@ -122,7 +116,7 @@ def test_blockchain_fixtures(fixture_data, fixture):
122116

123117
if should_be_good_block:
124118
(block, mined_block, block_rlp) = apply_fixture_block_to_chain(block_fixture, chain)
125-
assert_mined_block_unchanged(block, mined_block)
119+
mined_blocks.append((block, mined_block))
126120
else:
127121
try:
128122
apply_fixture_block_to_chain(block_fixture, chain)
@@ -133,6 +127,10 @@ def test_blockchain_fixtures(fixture_data, fixture):
133127
raise AssertionError("Block should have caused a validation error")
134128

135129
latest_block_hash = chain.get_canonical_block_by_number(chain.get_block().number - 1).hash
136-
assert latest_block_hash == fixture['lastblockhash']
130+
if latest_block_hash != fixture['lastblockhash']:
131+
verify_account_db(fixture['postState'], chain.get_vm().state.account_db)
132+
assert False, 'the state must be different if the hashes are'
137133

138-
verify_account_db(fixture['postState'], chain.get_vm().state.account_db)
134+
for block, mined_block in mined_blocks:
135+
assert_mined_block_unchanged(block, mined_block)
136+
chain.validate_block(block)

0 commit comments

Comments
 (0)