Skip to content

Commit 94a00e7

Browse files
committed
Implement tests.helpers.consensus.consensus_on_block, fix lint errors
1 parent 23f5c39 commit 94a00e7

File tree

4 files changed

+15
-13
lines changed

4 files changed

+15
-13
lines changed

src/dvspec/spec.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def serve_attestation_duty(slashing_db: SlashingDB, attestation_duty: Attestatio
115115
attestation_data = consensus_on_attestation(slashing_db, attestation_duty)
116116
# Release lock on consensus_on_attestation here.
117117
# Add attestation to slashing DB
118-
update_attestation_slashing_db(slashing_db, attestation_data, attestation_duty)
118+
update_attestation_slashing_db(slashing_db, attestation_data, attestation_duty.pubkey)
119119
# Cache decided attestation data value to provide to VC
120120
cache_attestation_data_for_vc(attestation_data, attestation_duty)
121121

@@ -137,7 +137,7 @@ def serve_proposer_duty(slashing_db: SlashingDB, proposer_duty: ProposerDuty) ->
137137
block = consensus_on_block(slashing_db, proposer_duty)
138138
# Release lock on consensus_on_block here.
139139
# Add block to slashing DB
140-
update_block_slashing_db(slashing_db, block, proposer_duty)
140+
update_block_slashing_db(slashing_db, block, proposer_duty.pubkey)
141141
# Cache decided block value to provide to VC
142142
cache_block_for_vc(block, proposer_duty)
143143

tests/helpers/consensus.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,20 @@
33
BeaconBlock,
44
)
55
from dvspec.utils.types import (
6+
BLSSignature,
7+
Bytes32,
68
AttestationDuty,
79
ProposerDuty,
810
SlashingDB,
911
)
10-
from dvspec.utils.helpers import (
11-
is_slashable_attestation_data,
12-
is_slashable_block,
13-
)
1412
from dvspec.consensus import (
1513
consensus_is_valid_attestation_data,
1614
consensus_is_valid_block,
1715
)
1816

1917
from tests.helpers.eth_node_interface import (
2018
bn_produce_attestation_data,
19+
bn_produce_block,
2120
)
2221

2322

@@ -35,16 +34,18 @@ def consensus_on_attestation(slashing_db: SlashingDB, attestation_duty: Attestat
3534
"""
3635
# TODO: Use this method in tests instead of dvspec.consensus.consensus_on_attestation
3736
attestation_data = bn_produce_attestation_data(attestation_duty.slot, attestation_duty.committee_index)
38-
assert consensus_is_valid_attestation_data(slashing_db, attestation_data)
37+
assert consensus_is_valid_attestation_data(slashing_db, attestation_data, attestation_duty)
3938
return attestation_data
4039

4140

42-
def consensus_on_block(slashing_db: SlashingDB, proposer_duty: ProposerDuty) -> AttestationData:
41+
def consensus_on_block(slashing_db: SlashingDB, proposer_duty: ProposerDuty) -> BeaconBlock:
4342
"""Consensus protocol between distributed validator nodes for block values.
4443
Returns the decided value.
4544
If this DV is the leader, it must use `bn_produce_block` for the proposed value.
4645
The consensus protocol must use `consensus_is_valid_block` to determine
4746
validity of the proposed block value.
4847
"""
49-
# TODO: Implement & use this method in tests instead of dvspec.consensus.consensus_on_block
50-
pass
48+
# TODO: Use this method in tests instead of dvspec.consensus.consensus_on_block
49+
block = bn_produce_block(proposer_duty.slot, BLSSignature(0x00), Bytes32(0x00))
50+
assert consensus_is_valid_block(slashing_db, block, proposer_duty)
51+
return block

tests/helpers/state.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"""
1919

2020

21-
def build_distributed_validator(validator_identity: ValidatorIdentity, num_covalidators=4) -> DistributedValidator:
21+
def build_distributed_validator(validator_identity: ValidatorIdentity,
22+
num_covalidators: int = 4) -> DistributedValidator:
2223
co_validators = []
2324
for i in range(1, num_covalidators):
2425
co_validators.append(CoValidator(validator_identity=validator_identity, pubkey=BLSPubkey(0x00), index=i))
@@ -31,7 +32,7 @@ def build_distributed_validator(validator_identity: ValidatorIdentity, num_coval
3132
return distributed_validator
3233

3334

34-
def build_state(num_distributed_validators) -> State:
35+
def build_state(num_distributed_validators: int) -> State:
3536
distributed_validators = []
3637
for i in range(num_distributed_validators):
3738
validator_identity = ValidatorIdentity(pubkey=BLSPubkey(i), index=i)

tests/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
)
1818

1919

20-
def test_basic_attestation():
20+
def test_basic_attestation() -> None:
2121
state = build_state(5)
2222
time = get_current_time()
2323

0 commit comments

Comments
 (0)