use of tech.pegasys.teku.core.ChainBuilder in project teku by ConsenSys.
the class RecentChainDataTest method getAncestorsOnFork_unknownRoot.
@Test
public void getAncestorsOnFork_unknownRoot() {
initPreGenesis();
final ChainBuilder chainBuilder = ChainBuilder.create(BLSKeyGenerator.generateKeyPairs(16));
final SignedBlockAndState genesis = chainBuilder.generateGenesis();
recentChainData.initializeFromGenesis(genesis.getState(), UInt64.ZERO);
assertThat(recentChainData.getAncestorsOnFork(UInt64.valueOf(1), Bytes32.ZERO)).isEmpty();
}
use of tech.pegasys.teku.core.ChainBuilder in project teku by ConsenSys.
the class RecentChainDataTest method initializeFromAnchorPoint_withTimeLessThanAnchorBlockTime.
@Test
public void initializeFromAnchorPoint_withTimeLessThanAnchorBlockTime() {
initPreGenesis();
final ChainBuilder chainBuilder = ChainBuilder.create(spec);
final UInt64 genesisTime = UInt64.valueOf(5000);
chainBuilder.generateGenesis(genesisTime, true);
// Build a small chain
chainBuilder.generateBlocksUpToSlot(10);
final SignedBlockAndState anchor = chainBuilder.generateNextBlock();
final AnchorPoint anchorPoint = AnchorPoint.fromInitialState(spec, anchor.getState());
final UInt64 anchorBlockTime = anchorPoint.getBlockSlot().times(genesisSpecConfig.getSecondsPerSlot()).plus(genesisTime);
final UInt64 time = genesisTime.plus(1);
assertThat(time).isLessThan(anchorBlockTime);
recentChainData.initializeFromAnchorPoint(anchorPoint, time);
assertThat(recentChainData.getStore().getTime()).isEqualTo(anchorBlockTime);
}
use of tech.pegasys.teku.core.ChainBuilder in project teku by ConsenSys.
the class ForkChoiceStrategyTest method getBlockRootsAtSlot_shouldReturnAllRoots.
@Test
void getBlockRootsAtSlot_shouldReturnAllRoots() {
final StorageSystem storageSystem = initStorageSystem();
storageSystem.chainUpdater().addNewBestBlock();
ChainBuilder fork = storageSystem.chainBuilder().fork();
final SignedBlockAndState bestBlock = storageSystem.chainUpdater().addNewBestBlock();
final SignedBlockAndState forkBlock = fork.generateBlockAtSlot(bestBlock.getSlot(), ChainBuilder.BlockOptions.create().setEth1Data(new Eth1Data(Bytes32.ZERO, UInt64.valueOf(6), Bytes32.ZERO)));
final ForkChoiceStrategy strategy = getProtoArray(storageSystem);
strategy.applyUpdate(List.of(BlockAndCheckpointEpochs.fromBlockAndState(bestBlock), BlockAndCheckpointEpochs.fromBlockAndState(forkBlock)), emptySet(), storageSystem.recentChainData().getFinalizedCheckpoint().orElseThrow());
assertThat(strategy.getBlockRootsAtSlot(bestBlock.getSlot())).containsExactlyInAnyOrder(bestBlock.getRoot(), forkBlock.getRoot());
}
Aggregations