Search in sources :

Example 1 with TestStoreFactory

use of tech.pegasys.teku.spec.datastructures.forkchoice.TestStoreFactory in project teku by ConsenSys.

the class ForkChoiceStrategyTest method findHead_worksForChainInitializedFromNonGenesisAnchor.

@Test
public void findHead_worksForChainInitializedFromNonGenesisAnchor() {
    // Set up store with an anchor point that has justified and finalized checkpoints prior to its
    // epoch
    final UInt64 initialEpoch = UInt64.valueOf(100);
    final BeaconState anchorState = dataStructureUtil.stateBuilderPhase0().setJustifiedCheckpointsToEpoch(initialEpoch.minus(2)).setFinalizedCheckpointToEpoch(initialEpoch.minus(3)).setSlotToStartOfEpoch(initialEpoch).build();
    AnchorPoint anchor = dataStructureUtil.createAnchorFromState(anchorState);
    final ProtoArray protoArray = ProtoArray.builder().initialCheckpoint(Optional.of(anchor.getCheckpoint())).justifiedCheckpoint(anchorState.getCurrent_justified_checkpoint()).finalizedCheckpoint(anchorState.getFinalized_checkpoint()).build();
    protoArray.onBlock(anchor.getBlockSlot(), anchor.getRoot(), anchor.getParentRoot(), anchor.getStateRoot(), anchor.getEpoch(), anchor.getEpoch(), Bytes32.ZERO, false);
    final ForkChoiceStrategy forkChoiceStrategy = ForkChoiceStrategy.initialize(spec, protoArray);
    TestStoreImpl store = new TestStoreFactory().createAnchorStore(anchor);
    assertThat(forkChoiceStrategy.getTotalTrackedNodeCount()).isEqualTo(1);
    final List<UInt64> effectiveBalances = dataStructureUtil.getSpec().getBeaconStateUtil(anchor.getState().getSlot()).getEffectiveBalances(anchor.getState());
    final Bytes32 head = forkChoiceStrategy.applyPendingVotes(store, Optional.empty(), anchor.getCheckpoint(), anchor.getCheckpoint(), effectiveBalances, ZERO);
    assertThat(head).isEqualTo(anchor.getRoot());
}
Also used : TestStoreImpl(tech.pegasys.teku.spec.datastructures.forkchoice.TestStoreImpl) AnchorPoint(tech.pegasys.teku.spec.datastructures.state.AnchorPoint) ReadOnlyForkChoiceStrategy(tech.pegasys.teku.spec.datastructures.forkchoice.ReadOnlyForkChoiceStrategy) TestStoreFactory(tech.pegasys.teku.spec.datastructures.forkchoice.TestStoreFactory) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Bytes32(org.apache.tuweni.bytes.Bytes32) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) Test(org.junit.jupiter.api.Test)

Aggregations

Bytes32 (org.apache.tuweni.bytes.Bytes32)1 Test (org.junit.jupiter.api.Test)1 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)1 ReadOnlyForkChoiceStrategy (tech.pegasys.teku.spec.datastructures.forkchoice.ReadOnlyForkChoiceStrategy)1 TestStoreFactory (tech.pegasys.teku.spec.datastructures.forkchoice.TestStoreFactory)1 TestStoreImpl (tech.pegasys.teku.spec.datastructures.forkchoice.TestStoreImpl)1 AnchorPoint (tech.pegasys.teku.spec.datastructures.state.AnchorPoint)1 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)1