use of tech.pegasys.teku.storage.client.ChainUpdater in project teku by ConsenSys.
the class BlockValidatorTest method shouldReturnInvalidForBlockThatDoesNotDescendFromFinalizedCheckpoint.
@TestTemplate
void shouldReturnInvalidForBlockThatDoesNotDescendFromFinalizedCheckpoint() {
List<BLSKeyPair> VALIDATOR_KEYS = BLSKeyGenerator.generateKeyPairs(4);
StorageSystem storageSystem = InMemoryStorageSystemBuilder.buildDefault();
ChainBuilder chainBuilder = ChainBuilder.create(VALIDATOR_KEYS);
ChainUpdater chainUpdater = new ChainUpdater(storageSystem.recentChainData(), chainBuilder);
BlockValidator blockValidator = new BlockValidator(spec, storageSystem.recentChainData());
chainUpdater.initializeGenesis();
chainUpdater.updateBestBlock(chainUpdater.advanceChainUntil(1));
ChainBuilder chainBuilderFork = chainBuilder.fork();
ChainUpdater chainUpdaterFork = new ChainUpdater(storageSystem.recentChainData(), chainBuilderFork);
UInt64 startSlotOfFinalizedEpoch = spec.computeStartSlotAtEpoch(UInt64.valueOf(4));
chainUpdaterFork.advanceChain(20);
chainUpdater.finalizeEpoch(4);
SignedBlockAndState blockAndState = chainBuilderFork.generateBlockAtSlot(startSlotOfFinalizedEpoch.increment());
chainUpdater.saveBlockTime(blockAndState);
final SafeFuture<InternalValidationResult> result = blockValidator.validate(blockAndState.getBlock());
assertThat(result).isCompletedWithValueMatching(InternalValidationResult::isReject);
}
Aggregations