Search in sources :

Example 6 with ValidationResult

use of io.libp2p.core.pubsub.ValidationResult in project teku by ConsenSys.

the class AggregateTopicHandlerTest method handleMessage_ignoredAggregate.

@Test
public void handleMessage_ignoredAggregate() {
    final ValidateableAttestation aggregate = ValidateableAttestation.aggregateFromValidator(spec, dataStructureUtil.randomSignedAggregateAndProof());
    when(processor.process(aggregate)).thenReturn(SafeFuture.completedFuture(InternalValidationResult.IGNORE));
    final SafeFuture<ValidationResult> result = topicHandler.handleMessage(topicHandler.prepareMessage(gossipEncoding.encode(aggregate.getSignedAggregateAndProof())));
    asyncRunner.executeQueuedActions();
    assertThat(result).isCompletedWithValue(ValidationResult.Ignore);
}
Also used : ValidateableAttestation(tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation) ValidationResult(io.libp2p.core.pubsub.ValidationResult) InternalValidationResult(tech.pegasys.teku.statetransition.validation.InternalValidationResult) Test(org.junit.jupiter.api.Test)

Example 7 with ValidationResult

use of io.libp2p.core.pubsub.ValidationResult in project teku by ConsenSys.

the class BlockTopicHandlerTest method handleMessage_invalidBlock_invalidSSZ.

@Test
public void handleMessage_invalidBlock_invalidSSZ() {
    Bytes serialized = Bytes.fromHexString("0x1234");
    final SafeFuture<ValidationResult> result = topicHandler.handleMessage(topicHandler.prepareMessage(serialized));
    asyncRunner.executeQueuedActions();
    assertThat(result).isCompletedWithValue(ValidationResult.Invalid);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) ValidationResult(io.libp2p.core.pubsub.ValidationResult) InternalValidationResult(tech.pegasys.teku.statetransition.validation.InternalValidationResult) Test(org.junit.jupiter.api.Test)

Example 8 with ValidationResult

use of io.libp2p.core.pubsub.ValidationResult in project teku by ConsenSys.

the class BlockTopicHandlerTest method handleMessage_invalidBlock_wrongProposer.

@Test
public void handleMessage_invalidBlock_wrongProposer() throws Exception {
    final UInt64 nextSlot = recentChainData.getHeadSlot().plus(UInt64.ONE);
    final SignedBeaconBlock block = beaconChainUtil.createBlockAtSlotFromInvalidProposer(nextSlot);
    Bytes serialized = gossipEncoding.encode(block);
    beaconChainUtil.setSlot(nextSlot);
    final SafeFuture<ValidationResult> result = topicHandler.handleMessage(topicHandler.prepareMessage(serialized));
    asyncRunner.executeQueuedActions();
    assertThat(result).isCompletedWithValue(ValidationResult.Invalid);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) ValidationResult(io.libp2p.core.pubsub.ValidationResult) InternalValidationResult(tech.pegasys.teku.statetransition.validation.InternalValidationResult) Test(org.junit.jupiter.api.Test)

Example 9 with ValidationResult

use of io.libp2p.core.pubsub.ValidationResult in project teku by ConsenSys.

the class BlockTopicHandlerTest method handleMessage_invalidBlock_unknownPreState.

@Test
public void handleMessage_invalidBlock_unknownPreState() {
    SignedBeaconBlock block = dataStructureUtil.randomSignedBeaconBlock(1);
    Bytes serialized = gossipEncoding.encode(block);
    when(processor.process(block)).thenReturn(SafeFuture.completedFuture(InternalValidationResult.SAVE_FOR_FUTURE));
    final SafeFuture<ValidationResult> result = topicHandler.handleMessage(topicHandler.prepareMessage(serialized));
    asyncRunner.executeQueuedActions();
    assertThat(result).isCompletedWithValue(ValidationResult.Ignore);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) ValidationResult(io.libp2p.core.pubsub.ValidationResult) InternalValidationResult(tech.pegasys.teku.statetransition.validation.InternalValidationResult) Test(org.junit.jupiter.api.Test)

Example 10 with ValidationResult

use of io.libp2p.core.pubsub.ValidationResult in project teku by ConsenSys.

the class BlockTopicHandlerTest method handleMessage_validBlock.

@Test
public void handleMessage_validBlock() throws Exception {
    final UInt64 nextSlot = recentChainData.getHeadSlot().plus(UInt64.ONE);
    final SignedBeaconBlock block = beaconChainUtil.createBlockAtSlot(nextSlot);
    Bytes serialized = gossipEncoding.encode(block);
    when(processor.process(block)).thenReturn(SafeFuture.completedFuture(InternalValidationResult.ACCEPT));
    final SafeFuture<ValidationResult> result = topicHandler.handleMessage(topicHandler.prepareMessage(serialized));
    asyncRunner.executeQueuedActions();
    assertThat(result).isCompletedWithValue(ValidationResult.Valid);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) ValidationResult(io.libp2p.core.pubsub.ValidationResult) InternalValidationResult(tech.pegasys.teku.statetransition.validation.InternalValidationResult) Test(org.junit.jupiter.api.Test)

Aggregations

ValidationResult (io.libp2p.core.pubsub.ValidationResult)36 Test (org.junit.jupiter.api.Test)34 InternalValidationResult (tech.pegasys.teku.statetransition.validation.InternalValidationResult)29 Bytes (org.apache.tuweni.bytes.Bytes)28 ValidateableAttestation (tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation)8 MockMessageApi (tech.pegasys.teku.network.p2p.jvmlibp2p.MockMessageApi)6 AttestationGenerator (tech.pegasys.teku.core.AttestationGenerator)4 SignedBeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock)4 StateAndBlockSummary (tech.pegasys.teku.spec.datastructures.blocks.StateAndBlockSummary)4 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)3 CompletionException (java.util.concurrent.CompletionException)2 DecodingException (tech.pegasys.teku.networking.eth2.gossip.encoding.DecodingException)2 AttesterSlashing (tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing)2 ProposerSlashing (tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing)2 SignedVoluntaryExit (tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit)2 Preconditions (com.google.common.base.Preconditions)1 PubsubApi (io.libp2p.core.pubsub.PubsubApi)1 PubsubApiKt (io.libp2p.core.pubsub.PubsubApiKt)1 PubsubPublisherApi (io.libp2p.core.pubsub.PubsubPublisherApi)1 FastIdSeenCache (io.libp2p.pubsub.FastIdSeenCache)1