def create_mock_genesis( num_validators: int, config: BeaconConfig, keymap: Dict[BLSPubkey, int], genesis_block_class: Type[BaseBeaconBlock], genesis_time: Timestamp = 0) -> Tuple[BeaconState, BaseBeaconBlock]: latest_eth1_data = Eth1Data.create_empty_data() assert num_validators <= len(keymap) pubkeys = list(keymap)[:num_validators] initial_validator_deposits = create_mock_initial_validator_deposits( num_validators=num_validators, config=config, pubkeys=pubkeys, keymap=keymap, ) state = get_initial_beacon_state( initial_validator_deposits=initial_validator_deposits, genesis_time=genesis_time, latest_eth1_data=latest_eth1_data, genesis_slot=config.GENESIS_SLOT, genesis_epoch=config.GENESIS_EPOCH, genesis_fork_version=config.GENESIS_FORK_VERSION, genesis_start_shard=config.GENESIS_START_SHARD, shard_count=config.SHARD_COUNT, seed_lookahead=config.SEED_LOOKAHEAD, latest_block_roots_length=config.LATEST_BLOCK_ROOTS_LENGTH, latest_index_roots_length=config.LATEST_INDEX_ROOTS_LENGTH, epoch_length=config.EPOCH_LENGTH, max_deposit_amount=config.MAX_DEPOSIT_AMOUNT, latest_penalized_exit_length=config.LATEST_PENALIZED_EXIT_LENGTH, latest_randao_mixes_length=config.LATEST_RANDAO_MIXES_LENGTH, entry_exit_delay=config.ENTRY_EXIT_DELAY, ) block = get_genesis_block( startup_state_root=state.root, genesis_slot=config.GENESIS_SLOT, block_class=genesis_block_class, ) assert len(state.validator_registry) == num_validators return state, block
def test_get_initial_beacon_state( privkeys, pubkeys, num_validators, genesis_epoch, genesis_slot, genesis_fork_version, genesis_start_shard, shard_count, seed_lookahead, latest_block_roots_length, latest_index_roots_length, epoch_length, max_deposit_amount, latest_penalized_exit_length, latest_randao_mixes_length, entry_exit_delay, sample_eth1_data_params): withdrawal_credentials = b'\x22' * 32 randao_commitment = b'\x33' * 32 custody_commitment = b'\x44' * 32 fork = Fork( previous_version=genesis_fork_version, current_version=genesis_fork_version, epoch=genesis_epoch, ) validator_count = 5 initial_validator_deposits = (Deposit( branch=(b'\x11' * 32 for j in range(10)), index=i, deposit_data=DepositData( deposit_input=DepositInput( pubkey=pubkeys[i], withdrawal_credentials=withdrawal_credentials, randao_commitment=randao_commitment, custody_commitment=custody_commitment, proof_of_possession=sign_proof_of_possession( deposit_input=DepositInput( pubkey=pubkeys[i], withdrawal_credentials=withdrawal_credentials, randao_commitment=randao_commitment, custody_commitment=custody_commitment, ), privkey=privkeys[i], fork=fork, slot=genesis_slot, epoch_length=epoch_length, ), ), amount=max_deposit_amount, timestamp=0, ), ) for i in range(validator_count)) genesis_time = 10 latest_eth1_data = Eth1Data(**sample_eth1_data_params) state = get_initial_beacon_state( initial_validator_deposits=initial_validator_deposits, genesis_time=genesis_time, latest_eth1_data=latest_eth1_data, genesis_epoch=genesis_epoch, genesis_slot=genesis_slot, genesis_fork_version=genesis_fork_version, genesis_start_shard=genesis_start_shard, shard_count=shard_count, seed_lookahead=seed_lookahead, latest_block_roots_length=latest_block_roots_length, latest_index_roots_length=latest_index_roots_length, epoch_length=epoch_length, max_deposit_amount=max_deposit_amount, latest_penalized_exit_length=latest_penalized_exit_length, latest_randao_mixes_length=latest_randao_mixes_length, entry_exit_delay=entry_exit_delay, ) # Misc assert state.slot == genesis_slot assert state.genesis_time == genesis_time assert state.fork.previous_version == genesis_fork_version assert state.fork.current_version == genesis_fork_version assert state.fork.epoch == genesis_epoch # Validator registry assert len(state.validator_registry) == validator_count assert len(state.validator_balances) == validator_count assert state.validator_registry_update_epoch == genesis_epoch assert state.validator_registry_exit_count == 0 # Randomness and committees assert len(state.latest_randao_mixes) == latest_randao_mixes_length assert len( state.latest_vdf_outputs) == latest_randao_mixes_length // epoch_length # TODO: `persistent_committees`, `persistent_committee_reassignments` will be removed assert len(state.persistent_committees) == 0 assert len(state.persistent_committee_reassignments) == 0 assert state.previous_epoch_start_shard == genesis_start_shard assert state.current_epoch_start_shard == genesis_start_shard assert state.previous_calculation_epoch == genesis_epoch assert state.current_calculation_epoch == genesis_epoch assert state.previous_epoch_seed == ZERO_HASH32 # Custody challenges assert len(state.custody_challenges) == 0 # Finality assert state.previous_justified_epoch == genesis_epoch assert state.justified_epoch == genesis_epoch assert state.justification_bitfield == 0 assert state.finalized_epoch == genesis_epoch # Recent state assert len(state.latest_crosslinks) == shard_count assert state.latest_crosslinks[0] == CrosslinkRecord( epoch=genesis_epoch, shard_block_root=ZERO_HASH32, ) assert len(state.latest_block_roots) == latest_block_roots_length assert state.latest_block_roots[0] == ZERO_HASH32 assert len(state.latest_penalized_balances) == latest_penalized_exit_length assert state.latest_penalized_balances[0] == Gwei(0) assert len(state.latest_attestations) == 0 assert len(state.batched_block_roots) == 0 # Ethereum 1.0 chain data assert state.latest_eth1_data == latest_eth1_data assert len(state.eth1_data_votes) == 0 assert state.validator_registry[0].is_active(genesis_epoch)