use of tech.pegasys.teku.validator.api.SendSignedBlockResult in project teku by ConsenSys.
the class ValidatorDataProviderTest method submitSignedBlock_shouldReturn202ForInvalidBlock.
@TestTemplate
public void submitSignedBlock_shouldReturn202ForInvalidBlock() {
final SignedBeaconBlock internalSignedBeaconBlock = dataStructureUtil.randomSignedBeaconBlock(1);
final tech.pegasys.teku.api.schema.SignedBeaconBlock signedBeaconBlock = tech.pegasys.teku.api.schema.SignedBeaconBlock.create(internalSignedBeaconBlock);
final AtomicInteger failReasonCount = new AtomicInteger();
Stream.of(FailureReason.values()).filter(failureReason -> !failureReason.equals(FailureReason.INTERNAL_ERROR)).forEach(failureReason -> {
failReasonCount.getAndIncrement();
final SafeFuture<SendSignedBlockResult> failImportResult = completedFuture(SendSignedBlockResult.notImported(failureReason.name()));
when(validatorApiChannel.sendSignedBlock(any())).thenReturn(failImportResult);
final SafeFuture<ValidatorBlockResult> validatorBlockResultSafeFuture = provider.submitSignedBlock(signedBeaconBlock);
try {
assertThat(validatorBlockResultSafeFuture.get().getResponseCode()).isEqualTo(202);
} catch (final Exception e) {
fail("Exception while executing test.");
}
});
// Assert that the check has run over each FailureReason except the 500.
assertThat(failReasonCount.get()).isEqualTo(FailureReason.values().length - 1);
}
use of tech.pegasys.teku.validator.api.SendSignedBlockResult in project teku by ConsenSys.
the class ValidatorDataProviderTest method submitSignedBlock_shouldReturn500ForInternalError.
@TestTemplate
public void submitSignedBlock_shouldReturn500ForInternalError() throws ExecutionException, InterruptedException {
final SignedBeaconBlock internalSignedBeaconBlock = dataStructureUtil.randomSignedBeaconBlock(1);
final tech.pegasys.teku.api.schema.SignedBeaconBlock signedBeaconBlock = tech.pegasys.teku.api.schema.SignedBeaconBlock.create(internalSignedBeaconBlock);
final SafeFuture<SendSignedBlockResult> failImportResult = completedFuture(SendSignedBlockResult.rejected(FailureReason.INTERNAL_ERROR.name()));
when(validatorApiChannel.sendSignedBlock(any())).thenReturn(failImportResult);
final SafeFuture<ValidatorBlockResult> validatorBlockResultSafeFuture = provider.submitSignedBlock(signedBeaconBlock);
assertThat(validatorBlockResultSafeFuture.get().getResponseCode()).isEqualTo(500);
}
use of tech.pegasys.teku.validator.api.SendSignedBlockResult in project teku by ConsenSys.
the class ValidatorDataProviderTest method submitSignedBlock_shouldReturn200ForSuccess.
@TestTemplate
public void submitSignedBlock_shouldReturn200ForSuccess() throws ExecutionException, InterruptedException {
final SignedBeaconBlock internalSignedBeaconBlock = dataStructureUtil.randomSignedBeaconBlock(1);
final tech.pegasys.teku.api.schema.SignedBeaconBlock signedBeaconBlock = tech.pegasys.teku.api.schema.SignedBeaconBlock.create(internalSignedBeaconBlock);
final SafeFuture<SendSignedBlockResult> successImportResult = completedFuture(SendSignedBlockResult.success(internalSignedBeaconBlock.getRoot()));
when(validatorApiChannel.sendSignedBlock(any())).thenReturn(successImportResult);
final SafeFuture<ValidatorBlockResult> validatorBlockResultSafeFuture = provider.submitSignedBlock(signedBeaconBlock);
assertThat(validatorBlockResultSafeFuture.get().getResponseCode()).isEqualTo(200);
}
use of tech.pegasys.teku.validator.api.SendSignedBlockResult in project teku by ConsenSys.
the class ValidatorApiHandlerTest method sendSignedBlock_shouldConvertKnownBlockResult.
@Test
public void sendSignedBlock_shouldConvertKnownBlockResult() {
final SignedBeaconBlock block = dataStructureUtil.randomSignedBeaconBlock(5);
when(blockImportChannel.importBlock(block)).thenReturn(SafeFuture.completedFuture(BlockImportResult.knownBlock(block)));
final SafeFuture<SendSignedBlockResult> result = validatorApiHandler.sendSignedBlock(block);
verify(blockGossipChannel).publishBlock(block);
verify(blockImportChannel).importBlock(block);
assertThat(result).isCompletedWithValue(SendSignedBlockResult.success(block.getRoot()));
}
use of tech.pegasys.teku.validator.api.SendSignedBlockResult in project teku by ConsenSys.
the class ValidatorApiHandlerTest method sendSignedBlock_shouldConvertSuccessfulResult.
@Test
public void sendSignedBlock_shouldConvertSuccessfulResult() {
final SignedBeaconBlock block = dataStructureUtil.randomSignedBeaconBlock(5);
when(blockImportChannel.importBlock(block)).thenReturn(SafeFuture.completedFuture(BlockImportResult.successful(block)));
final SafeFuture<SendSignedBlockResult> result = validatorApiHandler.sendSignedBlock(block);
verify(blockGossipChannel).publishBlock(block);
verify(blockImportChannel).importBlock(block);
assertThat(result).isCompletedWithValue(SendSignedBlockResult.success(block.getRoot()));
}
Aggregations