コード例 #1
0
ファイル: test_validator.py プロジェクト: AndreMiras/trinity
async def get_validator(
    event_loop,
    event_bus,
    monkeypatch,
    indices,
    num_validators=None,
) -> Validator:
    if num_validators is not None:
        chain = BeaconChainFactory(num_validators=num_validators)
    else:
        chain = BeaconChainFactory()

    validator_privkeys = {
        index: mk_key_pair_from_seed_index(index)[1]
        for index in indices
    }

    # Mock attestation pool
    unaggregated_attestation_pool = set()
    aggregated_attestation_pool = set()

    def get_ready_attestations_fn(slot, is_aggregated):
        return tuple(unaggregated_attestation_pool)

    def get_aggregatable_attestations_fn(slot, committee_index):
        return tuple(unaggregated_attestation_pool)

    def import_attestation_fn(attestation, is_aggregated):
        if is_aggregated:
            aggregated_attestation_pool.add(attestation)
        else:
            unaggregated_attestation_pool.add(attestation)

    v = Validator(
        chain=chain,
        p2p_node=FakeNode(),
        validator_privkeys=validator_privkeys,
        get_ready_attestations_fn=get_ready_attestations_fn,
        get_aggregatable_attestations_fn=get_aggregatable_attestations_fn,
        import_attestation_fn=import_attestation_fn,
        event_bus=event_bus,
    )

    # Make requesting eth1 vote and deposit a stub
    async def _get_eth1_vote(slot, state, state_machine):
        return None

    monkeypatch.setattr(v, '_get_eth1_vote', _get_eth1_vote)

    async def _get_deposit_data(state, state_machine, eth1_vote):
        return None

    monkeypatch.setattr(v, '_get_deposit_data', _get_deposit_data)

    asyncio.ensure_future(v.run(), loop=event_loop)
    await v.events.started.wait()
    # yield to `validator._run`
    await asyncio.sleep(0)
    return v
コード例 #2
0
ファイル: test_validator.py プロジェクト: wschwab/trinity
async def get_validator(event_loop, event_bus, indices) -> Validator:
    chain = BeaconChainFactory()
    validator_privkeys = {
        index: keymap[index_to_pubkey[index]]
        for index in indices
    }

    def get_ready_attestations_fn():
        return ()

    v = Validator(
        chain=chain,
        p2p_node=FakeNode(),
        validator_privkeys=validator_privkeys,
        get_ready_attestations_fn=get_ready_attestations_fn,
        event_bus=event_bus,
    )
    asyncio.ensure_future(v.run(), loop=event_loop)
    await v.events.started.wait()
    # yield to `validator._run`
    await asyncio.sleep(0)
    return v