This repository has been archived by the owner on Jan 6, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from hwwhww/len_of_list
Use `num` properties instead of `len()` functions
- Loading branch information
Showing
15 changed files
with
197 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from beacon_chain.state.config import ( | ||
DEFAULT_CONFIG, | ||
) | ||
from beacon_chain.state.crystallized_state import ( | ||
CrystallizedState, | ||
) | ||
from beacon_chain.state.validator_record import ( | ||
ValidatorRecord, | ||
) | ||
from beacon_chain.state.state_transition import ( | ||
get_shuffling, | ||
) | ||
|
||
|
||
def mock_crystallized_state( | ||
genesis_crystallized_state, | ||
init_shuffling_seed, | ||
next_shard, | ||
active_validators=None, | ||
config=DEFAULT_CONFIG): | ||
|
||
crystallized_state = CrystallizedState() | ||
crystallized_state.next_shard = next_shard | ||
if active_validators is not None: | ||
crystallized_state.active_validators = active_validators | ||
crystallized_state.current_shuffling = get_shuffling( | ||
init_shuffling_seed, | ||
len(active_validators), | ||
config=config, | ||
) | ||
return crystallized_state | ||
|
||
|
||
def mock_validator_record(pubkey, config): | ||
return ValidatorRecord( | ||
pubkey=pubkey, | ||
withdrawal_shard=0, | ||
withdrawal_address=pubkey.to_bytes(32, 'big')[-20:], | ||
randao_commitment=b'\x55'*32, | ||
balance=config['default_balance'], | ||
switch_dynasty=config['default_switch_dynasty'] | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from beacon_chain.state.aggregate_vote import ( | ||
AggregateVote, | ||
) | ||
|
||
|
||
def test_num_properties(): | ||
aggregate_vote = AggregateVote( | ||
aggregate_sig=list(range(3)) | ||
) | ||
|
||
assert aggregate_vote.num_aggregate_sig == 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from beacon_chain.state.crystallized_state import ( | ||
CrystallizedState, | ||
) | ||
from beacon_chain.state.crosslink_record import ( | ||
CrosslinkRecord, | ||
) | ||
|
||
from tests.state.helpers import ( | ||
mock_validator_record, | ||
) | ||
|
||
|
||
def test_num_properties(config): | ||
active_validators = [ | ||
mock_validator_record(pubkey, config) | ||
for pubkey in range(2) | ||
] | ||
queued_validators = [ | ||
mock_validator_record(pubkey, config) | ||
for pubkey in range(3) | ||
] | ||
exited_validators = [ | ||
mock_validator_record(pubkey, config) | ||
for pubkey in range(4) | ||
] | ||
crosslink_records = [ | ||
CrosslinkRecord(hash=b'\x00'*32, epoch=0) for i in range(5) | ||
] | ||
|
||
crystallized_state = CrystallizedState( | ||
active_validators=active_validators, | ||
queued_validators=queued_validators, | ||
exited_validators=exited_validators, | ||
current_shuffling=active_validators, | ||
crosslink_records=crosslink_records, | ||
) | ||
|
||
assert crystallized_state.num_active_validators == 2 | ||
assert crystallized_state.num_queued_validators == 3 | ||
assert crystallized_state.num_exited_validators == 4 | ||
assert crystallized_state.num_crosslink_records == 5 |
Oops, something went wrong.