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());
}
Aggregations