9
9
)
10
10
11
11
from eth .beacon .types .blocks import BaseBeaconBlock
12
+ from eth .beacon .types .proposal_signed_data import (
13
+ ProposalSignedData ,
14
+ )
12
15
from eth .beacon .types .states import BeaconState
13
16
17
+ from eth ._utils import bls
18
+
14
19
from tests .beacon .helpers import mock_validator_record
15
20
from tests .beacon .test_helpers import (
16
21
get_sample_shard_committees_at_slots ,
17
22
)
18
23
19
24
25
+ @pytest .mark .parametrize (
26
+ 'proposer_privkey, proposer_pubkey, is_valid_signature' ,
27
+ (
28
+ (0 , bls .privtopub (0 ), True ),
29
+ (0 , bls .privtopub (0 ) + 1 , False ),
30
+ (0 , 123 , False ),
31
+
32
+ (123 , bls .privtopub (123 ), True ),
33
+ (123 , bls .privtopub (123 ) + 1 , False ),
34
+ (123 , 123 , False ),
35
+ )
36
+ )
20
37
def test_validate_proposer_signature (
21
- beacon_chain_shard_number ,
22
- epoch_length ,
38
+ proposer_privkey ,
39
+ proposer_pubkey ,
40
+ is_valid_signature ,
23
41
sample_beacon_block_params ,
24
42
sample_beacon_state_params ,
25
- sample_shard_committee_params ):
26
- block = BaseBeaconBlock (** sample_beacon_block_params )
43
+ sample_shard_committee_params ,
44
+ beacon_chain_shard_number ,
45
+ epoch_length ):
46
+
27
47
state = BeaconState (** sample_beacon_state_params ).copy (
28
48
validator_registry = [
29
49
mock_validator_record (
30
- pubkey = 0 ,
50
+ pubkey = proposer_pubkey ,
31
51
max_deposit = 0 ,
32
52
)
33
53
for _ in range (10 )
@@ -39,40 +59,35 @@ def test_validate_proposer_signature(
39
59
),
40
60
)
41
61
42
- validate_proposer_signature (
43
- state ,
44
- block ,
45
- beacon_chain_shard_number ,
46
- epoch_length ,
47
- )
48
-
62
+ default_block = BaseBeaconBlock (** sample_beacon_block_params )
63
+ empty_signature_block_root = BaseBeaconBlock .get_block_without_signature_root (default_block )
49
64
50
- def test_validate_proposer_bad_signature (
65
+ proposal_root = ProposalSignedData (
66
+ state .slot ,
51
67
beacon_chain_shard_number ,
52
- epoch_length ,
53
- sample_beacon_block_params ,
54
- sample_beacon_state_params ,
55
- sample_shard_committee_params ):
56
- block = BaseBeaconBlock (** sample_beacon_block_params )
57
- state = BeaconState (** sample_beacon_state_params ).copy (
58
- validator_registry = [
59
- mock_validator_record (
60
- pubkey = 123 ,
61
- max_deposit = 0 ,
62
- )
63
- for _ in range (10 )
64
- ],
65
- shard_committees_at_slots = get_sample_shard_committees_at_slots (
66
- num_slot = 128 ,
67
- num_shard_committee_per_slot = 10 ,
68
- sample_shard_committee_params = sample_shard_committee_params ,
68
+ empty_signature_block_root ,
69
+ ).root
70
+
71
+ proposed_block = BaseBeaconBlock (** sample_beacon_block_params ).copy (
72
+ signature = bls .sign (
73
+ message = proposal_root ,
74
+ privkey = proposer_privkey ,
75
+ domain = 2 ,
69
76
),
70
77
)
71
78
72
- with pytest . raises ( ValidationError ) :
79
+ if is_valid_signature :
73
80
validate_proposer_signature (
74
81
state ,
75
- block ,
82
+ proposed_block ,
76
83
beacon_chain_shard_number ,
77
84
epoch_length ,
78
85
)
86
+ else :
87
+ with pytest .raises (ValidationError ):
88
+ validate_proposer_signature (
89
+ state ,
90
+ proposed_block ,
91
+ beacon_chain_shard_number ,
92
+ epoch_length ,
93
+ )
0 commit comments