Skip to content

Commit 3077967

Browse files
committed
Add test_validate_parent_block_proposer and test_validate_state_roots
1 parent 075c093 commit 3077967

File tree

3 files changed

+94
-5
lines changed

3 files changed

+94
-5
lines changed

eth/beacon/state_machines/validation.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ def validate_parent_block_proposer(crystallized_state: 'CrystallizedState',
8686
#
8787
# Attestation validation
8888
#
89-
9089
def validate_attestation(
9190
block: BaseBeaconBlock,
9291
parent_block: BaseBeaconBlock,

tests/beacon/state_machines/test_block_validation.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
validate_attestation,
1919
validate_bitfield,
2020
validate_justified,
21+
validate_parent_block_proposer,
2122
validate_slot,
23+
validate_state_roots,
2224
)
2325

2426

@@ -103,6 +105,62 @@ def attestation_validation_fixture(fixture_sm_class,
103105
)
104106

105107

108+
@pytest.mark.parametrize(
109+
(
110+
'num_validators,cycle_length,'
111+
'min_committee_size,shard_count'
112+
),
113+
[
114+
(100, 50, 10, 10)
115+
],
116+
)
117+
def test_validate_parent_block_proposer(attestation_validation_fixture,
118+
cycle_length):
119+
(
120+
crystallized_state,
121+
_,
122+
attestation,
123+
block,
124+
parent_block,
125+
_,
126+
) = attestation_validation_fixture
127+
128+
validate_parent_block_proposer(
129+
crystallized_state,
130+
block,
131+
parent_block,
132+
cycle_length,
133+
)
134+
135+
# Case 1: No attestations
136+
block = block.copy(
137+
attestations=()
138+
)
139+
with pytest.raises(ValidationError):
140+
validate_parent_block_proposer(
141+
crystallized_state,
142+
block,
143+
parent_block,
144+
cycle_length,
145+
)
146+
147+
# Case 2: Proposer didn't attest
148+
block = block.copy(
149+
attestations=[
150+
attestation.copy(
151+
attester_bitfield=get_empty_bitfield(10),
152+
)
153+
]
154+
)
155+
with pytest.raises(ValidationError):
156+
validate_parent_block_proposer(
157+
crystallized_state,
158+
block,
159+
parent_block,
160+
cycle_length,
161+
)
162+
163+
106164
@pytest.mark.parametrize(
107165
(
108166
'num_validators,cycle_length,'
@@ -306,3 +364,31 @@ def test_validate_attestation_aggregate_sig(attestation_validation_fixture, cycl
306364
attestation_indices,
307365
parent_hashes,
308366
)
367+
368+
369+
def test_validate_state_roots(genesis_crystallized_state, genesis_active_state, genesis_block):
370+
371+
validate_state_roots(
372+
crystallized_state_root=genesis_crystallized_state.hash,
373+
active_state_root=genesis_active_state.hash,
374+
block=genesis_block,
375+
)
376+
377+
# Case 1: Wrong crystallized state root
378+
with pytest.raises(ValidationError):
379+
validate_state_roots(
380+
crystallized_state_root=genesis_active_state,
381+
active_state_root=genesis_active_state.hash,
382+
block=genesis_block.copy(
383+
active_state_root=ZERO_HASH32,
384+
),
385+
)
386+
387+
with pytest.raises(ValidationError):
388+
validate_state_roots(
389+
crystallized_state_root=genesis_active_state,
390+
active_state_root=genesis_active_state.hash,
391+
block=genesis_block.copy(
392+
crystallized_state_root=ZERO_HASH32,
393+
),
394+
)

tests/beacon/state_machines/test_proposer.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
(1000, 20, 10, 100),
2727
]
2828
)
29-
def test_propose_block_and_validate_attestation(fixture_sm_class,
30-
initial_chaindb,
31-
genesis_block,
32-
privkeys):
29+
def test_propose_block(fixture_sm_class,
30+
initial_chaindb,
31+
genesis_block,
32+
privkeys):
3333
chaindb = initial_chaindb
3434

3535
# Propose a block
@@ -39,7 +39,9 @@ def test_propose_block_and_validate_attestation(fixture_sm_class,
3939
)
4040
sm = fixture_sm_class(chaindb, block_1_shell)
4141

42+
#
4243
# The proposer of block_1
44+
#
4345
block_committees_info = (
4446
get_block_committees_info(
4547
block_1_shell,
@@ -94,7 +96,9 @@ def test_propose_block_and_validate_attestation(fixture_sm_class,
9496
block_committees_info.proposer_index_in_committee
9597
)
9698

99+
#
97100
# The proposer of block_2
101+
#
98102
block_committees_info = (
99103
get_block_committees_info(
100104
block_2_shell,

0 commit comments

Comments
 (0)