use of tech.pegasys.teku.spec.executionengine.ForkChoiceUpdatedResult in project teku by ConsenSys.
the class ForkChoiceTest method setForkChoiceNotifierForkChoiceUpdatedResult.
private void setForkChoiceNotifierForkChoiceUpdatedResult(final Optional<PayloadStatus> status) {
ForkChoiceUpdatedResult result = status.map(payloadStatus -> new ForkChoiceUpdatedResult(payloadStatus, Optional.empty())).orElse(null);
when(forkChoiceNotifier.onForkChoiceUpdated(any())).thenReturn(SafeFuture.completedFuture(Optional.ofNullable(result)));
}
use of tech.pegasys.teku.spec.executionengine.ForkChoiceUpdatedResult in project teku by ConsenSys.
the class ForkChoiceNotifierTest method getPayloadId_shouldReturnExceptionallyLatestPayloadIdOnWrongRoot.
@Test
void getPayloadId_shouldReturnExceptionallyLatestPayloadIdOnWrongRoot() {
final Bytes8 payloadId = dataStructureUtil.randomBytes8();
final ForkChoiceState forkChoiceState = getCurrentForkChoiceState();
final BeaconState headState = getHeadState();
final UInt64 blockSlot = headState.getSlot().plus(1);
final Bytes32 wrongBlockRoot = dataStructureUtil.randomBytes32();
final PayloadAttributes payloadAttributes = withProposerForSlot(headState, blockSlot);
final SafeFuture<ForkChoiceUpdatedResult> responseFuture = new SafeFuture<>();
when(executionEngineChannel.forkChoiceUpdated(forkChoiceState, Optional.of(payloadAttributes))).thenReturn(responseFuture);
assertThat(notifier.onForkChoiceUpdated(forkChoiceState)).isCompleted();
responseFuture.complete(createForkChoiceUpdatedResult(ExecutionPayloadStatus.VALID, Optional.of(payloadId)));
assertThatSafeFuture(notifier.getPayloadId(wrongBlockRoot, blockSlot)).isCompletedExceptionally();
}
use of tech.pegasys.teku.spec.executionengine.ForkChoiceUpdatedResult in project teku by ConsenSys.
the class ForkChoiceNotifierTest method getPayloadId_shouldReturnExceptionallyBeforeTheFirstForkChoiceState.
@Test
void getPayloadId_shouldReturnExceptionallyBeforeTheFirstForkChoiceState() {
final BeaconState headState = getHeadState();
// proposing slot 3
final UInt64 blockSlot = headState.getSlot().plus(2);
final Bytes32 blockRoot = recentChainData.getBestBlockRoot().orElseThrow();
final SafeFuture<ForkChoiceUpdatedResult> responseFuture = new SafeFuture<>();
final ForkChoiceState forkChoiceState = getCurrentForkChoiceState();
final PayloadAttributes payloadAttributes = withProposerForSlot(headState, blockSlot);
when(executionEngineChannel.forkChoiceUpdated(forkChoiceState, Optional.of(payloadAttributes))).thenReturn(responseFuture);
storageSystem.chainUpdater().setCurrentSlot(blockSlot);
// we are post-merge, we must have a payloadId
assertThatSafeFuture(notifier.getPayloadId(blockRoot, blockSlot)).isCompletedExceptionally();
}
use of tech.pegasys.teku.spec.executionengine.ForkChoiceUpdatedResult in project teku by ConsenSys.
the class ForkChoiceNotifierTest method getPayloadId_preMergeShouldReturnEmptyBeforeTheFirstForkChoiceState.
@Test
void getPayloadId_preMergeShouldReturnEmptyBeforeTheFirstForkChoiceState() {
reInitializePreMerge();
final BeaconState headState = getHeadState();
// proposing slot 3
final UInt64 blockSlot = headState.getSlot().plus(2);
final Bytes32 blockRoot = recentChainData.getBestBlockRoot().orElseThrow();
final SafeFuture<ForkChoiceUpdatedResult> responseFuture = new SafeFuture<>();
final ForkChoiceState forkChoiceState = getCurrentForkChoiceState();
final PayloadAttributes payloadAttributes = withProposerForSlot(headState, blockSlot);
when(executionEngineChannel.forkChoiceUpdated(forkChoiceState, Optional.of(payloadAttributes))).thenReturn(responseFuture);
storageSystem.chainUpdater().setCurrentSlot(blockSlot);
// we are pre-merge, we can continue producing blocks with no execution payload
assertThatSafeFuture(notifier.getPayloadId(blockRoot, blockSlot)).isCompletedWithEmptyOptional();
}
use of tech.pegasys.teku.spec.executionengine.ForkChoiceUpdatedResult in project teku by ConsenSys.
the class ForkChoiceNotifierTest method getPayloadId_shouldReturnLatestPayloadId.
@Test
void getPayloadId_shouldReturnLatestPayloadId() {
final Bytes8 payloadId = dataStructureUtil.randomBytes8();
final ForkChoiceState forkChoiceState = getCurrentForkChoiceState();
final BeaconState headState = getHeadState();
final Bytes32 blockRoot = recentChainData.getBestBlockRoot().orElseThrow();
final UInt64 blockSlot = headState.getSlot().plus(1);
final PayloadAttributes payloadAttributes = withProposerForSlot(headState, blockSlot);
final SafeFuture<ForkChoiceUpdatedResult> responseFuture = new SafeFuture<>();
when(executionEngineChannel.forkChoiceUpdated(forkChoiceState, Optional.of(payloadAttributes))).thenReturn(responseFuture);
assertThat(notifier.onForkChoiceUpdated(forkChoiceState)).isCompleted();
// Initially has no payload ID.
assertThatSafeFuture(notifier.getPayloadId(blockRoot, blockSlot)).isNotCompleted();
// But becomes available once we receive the response
responseFuture.complete(createForkChoiceUpdatedResult(ExecutionPayloadStatus.VALID, Optional.of(payloadId)));
assertThatSafeFuture(notifier.getPayloadId(blockRoot, blockSlot)).isCompletedWithOptionalContaining(payloadId);
}
Aggregations