Ejemplo n.º 1
0
def test_get_genesis_block():
    genesis_state_root = b'\x10' * 32
    genesis_slot = 10
    genesis_block = get_genesis_block(genesis_state_root, genesis_slot,
                                      BeaconBlock)
    assert genesis_block.slot == genesis_slot
    assert genesis_block.previous_block_root == ZERO_HASH32
    assert genesis_block.state_root == genesis_state_root
    assert genesis_block.signature == EMPTY_SIGNATURE
    assert genesis_block.body.is_empty
Ejemplo n.º 2
0
def test_get_genesis_block():
    genesis_state_root = b'\x10' * 32
    genesis_slot = 10
    genesis_block = get_genesis_block(genesis_state_root, genesis_slot,
                                      BeaconBlock)
    assert genesis_block.slot == genesis_slot
    assert genesis_block.parent_root == ZERO_HASH32
    assert genesis_block.state_root == genesis_state_root
    assert genesis_block.randao_reveal == EMPTY_SIGNATURE
    assert genesis_block.eth1_data == Eth1Data.create_empty_data()
    assert genesis_block.signature == EMPTY_SIGNATURE
    assert genesis_block.body.is_empty
Ejemplo n.º 3
0
def create_mock_genesis(
        num_validators: int,
        config: Eth2Config,
        keymap: Dict[BLSPubkey, int],
        genesis_block_class: Type[BaseBeaconBlock],
        genesis_time: Timestamp=ZERO_TIMESTAMP) -> Tuple[BeaconState, BaseBeaconBlock]:
    assert num_validators <= len(keymap)

    pubkeys = list(keymap)[:num_validators]

    genesis_validator_deposits, deposit_root = create_mock_genesis_validator_deposits_and_root(
        num_validators=num_validators,
        config=config,
        pubkeys=pubkeys,
        keymap=keymap,
    )

    genesis_eth1_data = Eth1Data(
        deposit_root=deposit_root,
        block_hash=ZERO_HASH32,
    )

    state = get_genesis_beacon_state(
        genesis_validator_deposits=genesis_validator_deposits,
        genesis_time=genesis_time,
        genesis_eth1_data=genesis_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,
        min_seed_lookahead=config.MIN_SEED_LOOKAHEAD,
        slots_per_historical_root=config.SLOTS_PER_HISTORICAL_ROOT,
        latest_active_index_roots_length=config.LATEST_ACTIVE_INDEX_ROOTS_LENGTH,
        slots_per_epoch=config.SLOTS_PER_EPOCH,
        max_deposit_amount=config.MAX_DEPOSIT_AMOUNT,
        latest_slashed_exit_length=config.LATEST_SLASHED_EXIT_LENGTH,
        latest_randao_mixes_length=config.LATEST_RANDAO_MIXES_LENGTH,
        activation_exit_delay=config.ACTIVATION_EXIT_DELAY,
        deposit_contract_tree_depth=config.DEPOSIT_CONTRACT_TREE_DEPTH,
        block_class=genesis_block_class,
    )

    block = get_genesis_block(
        genesis_state_root=state.root,
        genesis_slot=config.GENESIS_SLOT,
        block_class=genesis_block_class,
    )
    assert len(state.validator_registry) == num_validators

    return state, block
Ejemplo n.º 4
0
def genesis_block(genesis_state, genesis_slot):
    return get_genesis_block(
        genesis_state.root,
        genesis_slot,
        SerenityBeaconBlock,
    )