Search in sources :

Example 6 with ChainUpdater

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);
}
Also used : ChainBuilder(tech.pegasys.teku.core.ChainBuilder) ChainUpdater(tech.pegasys.teku.storage.client.ChainUpdater) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) StorageSystem(tech.pegasys.teku.storage.storageSystem.StorageSystem) TestTemplate(org.junit.jupiter.api.TestTemplate)

Aggregations

ChainUpdater (tech.pegasys.teku.storage.client.ChainUpdater)6 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)5 SignedBlockAndState (tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState)4 Test (org.junit.jupiter.api.Test)3 ChainBuilder (tech.pegasys.teku.core.ChainBuilder)3 Attestation (tech.pegasys.teku.spec.datastructures.operations.Attestation)2 TestTemplate (org.junit.jupiter.api.TestTemplate)1 BLSKeyPair (tech.pegasys.teku.bls.BLSKeyPair)1 AttestationGenerator (tech.pegasys.teku.core.AttestationGenerator)1 InlineEventThread (tech.pegasys.teku.infrastructure.async.eventthread.InlineEventThread)1 ForkChoice (tech.pegasys.teku.statetransition.forkchoice.ForkChoice)1 MergeTransitionBlockValidator (tech.pegasys.teku.statetransition.forkchoice.MergeTransitionBlockValidator)1 StubForkChoiceNotifier (tech.pegasys.teku.statetransition.forkchoice.StubForkChoiceNotifier)1 ActiveValidatorCache (tech.pegasys.teku.statetransition.validatorcache.ActiveValidatorCache)1 StorageSystem (tech.pegasys.teku.storage.storageSystem.StorageSystem)1