File tree Expand file tree Collapse file tree 4 files changed +76
-0
lines changed Expand file tree Collapse file tree 4 files changed +76
-0
lines changed Original file line number Diff line number Diff line change
1
+ from eth_typing import (
2
+ Hash32 ,
3
+ )
4
+ import rlp
5
+
6
+ from eth .beacon .utils .hash import (
7
+ hash_eth2 ,
8
+ )
9
+ from eth .rlp .sedes import (
10
+ hash32 ,
11
+ uint24 ,
12
+ uint64 ,
13
+ uint384 ,
14
+ )
15
+
16
+
17
+ class ValidatorRegistryDeltaBlock (rlp .Serializable ):
18
+ """
19
+ Note: using RLP until we have standardized serialization format.
20
+ """
21
+ fields = [
22
+ ('latest_registry_delta_root' , hash32 ),
23
+ ('validator_index' , uint24 ),
24
+ ('pubkey' , uint384 ),
25
+ ('flag' , uint64 )
26
+ ]
27
+
28
+ def __init__ (self ,
29
+ latest_registry_delta_root : Hash32 ,
30
+ validator_index : int ,
31
+ pubkey : int ,
32
+ flag : int ) -> None :
33
+ super ().__init__ (
34
+ latest_registry_delta_root = latest_registry_delta_root ,
35
+ validator_index = validator_index ,
36
+ pubkey = pubkey ,
37
+ flag = flag ,
38
+ )
39
+
40
+ _hash = None
41
+
42
+ @property
43
+ def hash (self ) -> Hash32 :
44
+ if self ._hash is None :
45
+ self ._hash = hash_eth2 (rlp .encode (self ))
46
+ return self ._hash
47
+
48
+ @property
49
+ def root (self ) -> Hash32 :
50
+ # Alias of `hash`.
51
+ # Using flat hash, might change to SSZ tree hash.
52
+ return self .hash
Original file line number Diff line number Diff line change 15
15
uint32 = BigEndianInt (32 )
16
16
uint64 = BigEndianInt (64 )
17
17
uint256 = BigEndianInt (256 )
18
+ uint384 = BigEndianInt (384 )
18
19
trie_root = Binary .fixed_length (32 , allow_empty = True )
Original file line number Diff line number Diff line change @@ -294,6 +294,16 @@ def sample_validator_record_params():
294
294
}
295
295
296
296
297
+ @pytest .fixture
298
+ def sample_validator_registry_delta_block_params ():
299
+ return {
300
+ 'latest_registry_delta_root' : b'\x01 ' * 32 ,
301
+ 'validator_index' : 1 ,
302
+ 'pubkey' : 123 ,
303
+ 'flag' : 1 ,
304
+ }
305
+
306
+
297
307
#
298
308
# Temporary default values
299
309
#
Original file line number Diff line number Diff line change
1
+ from eth .beacon .types .validator_registry_delta_block import (
2
+ ValidatorRegistryDeltaBlock ,
3
+ )
4
+
5
+
6
+ def test_defaults (sample_validator_registry_delta_block_params ):
7
+ validator_registry_delta_block = ValidatorRegistryDeltaBlock (
8
+ ** sample_validator_registry_delta_block_params
9
+ )
10
+ assert validator_registry_delta_block .latest_registry_delta_root == sample_validator_registry_delta_block_params ['latest_registry_delta_root' ] # noqa: E501
11
+ assert validator_registry_delta_block .validator_index == sample_validator_registry_delta_block_params ['validator_index' ] # noqa: E501
12
+ assert validator_registry_delta_block .pubkey == sample_validator_registry_delta_block_params ['pubkey' ] # noqa: E501
13
+ assert validator_registry_delta_block .flag == sample_validator_registry_delta_block_params ['flag' ] # noqa: E501
You can’t perform that action at this time.
0 commit comments