Search in sources :

Example 16 with ValidationResult

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

the class GossipHandlerTest method apply_duplicate.

@Test
@SuppressWarnings("FutureReturnValueIgnored")
public void apply_duplicate() {
    final Bytes data = Bytes.fromHexString("0x01");
    final MockMessageApi message = new MockMessageApi(data, topic);
    gossipHandler.apply(message);
    final SafeFuture<ValidationResult> result = gossipHandler.apply(message);
    assertThat(result).isCompletedWithValue(ValidationResult.Ignore);
    verify(topicHandler).handleMessage(any());
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) MockMessageApi(tech.pegasys.teku.network.p2p.jvmlibp2p.MockMessageApi) ValidationResult(io.libp2p.core.pubsub.ValidationResult) Test(org.junit.jupiter.api.Test)

Example 17 with ValidationResult

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

the class GossipHandlerTest method apply_afterDuplicateGossip.

@Test
@SuppressWarnings("FutureReturnValueIgnored")
public void apply_afterDuplicateGossip() {
    final Bytes data = Bytes.fromHexString("0x01");
    final MockMessageApi message = new MockMessageApi(data, topic);
    gossipHandler.gossip(data);
    gossipHandler.apply(message);
    final SafeFuture<ValidationResult> result = gossipHandler.apply(message);
    assertThat(result).isCompletedWithValue(ValidationResult.Ignore);
    verify(topicHandler, never()).handleMessage(any());
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) MockMessageApi(tech.pegasys.teku.network.p2p.jvmlibp2p.MockMessageApi) ValidationResult(io.libp2p.core.pubsub.ValidationResult) Test(org.junit.jupiter.api.Test)

Example 18 with ValidationResult

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

the class GossipHandlerTest method apply_exceedsMaxSize.

@Test
public void apply_exceedsMaxSize() {
    final Bytes data = Bytes.wrap(new byte[GOSSIP_MAX_SIZE + 1]);
    final MockMessageApi message = new MockMessageApi(data, topic);
    final SafeFuture<ValidationResult> result = gossipHandler.apply(message);
    assertThat(result).isCompletedWithValue(ValidationResult.Invalid);
    verify(topicHandler, never()).handleMessage(any());
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) MockMessageApi(tech.pegasys.teku.network.p2p.jvmlibp2p.MockMessageApi) ValidationResult(io.libp2p.core.pubsub.ValidationResult) Test(org.junit.jupiter.api.Test)

Example 19 with ValidationResult

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

the class GossipHandlerTest method apply_invalid.

@Test
public void apply_invalid() {
    final Bytes data = Bytes.fromHexString("0x01");
    final MockMessageApi message = new MockMessageApi(data, topic);
    when(topicHandler.handleMessage(any())).thenReturn(SafeFuture.completedFuture(ValidationResult.Invalid));
    final SafeFuture<ValidationResult> result = gossipHandler.apply(message);
    assertThat(result).isCompletedWithValue(ValidationResult.Invalid);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) MockMessageApi(tech.pegasys.teku.network.p2p.jvmlibp2p.MockMessageApi) ValidationResult(io.libp2p.core.pubsub.ValidationResult) Test(org.junit.jupiter.api.Test)

Example 20 with ValidationResult

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

the class GossipHandlerTest method apply_valid.

@Test
public void apply_valid() {
    final Bytes data = Bytes.fromHexString("0x01");
    final MockMessageApi message = new MockMessageApi(data, topic);
    final SafeFuture<ValidationResult> result = gossipHandler.apply(message);
    assertThat(result).isCompletedWithValue(ValidationResult.Valid);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) MockMessageApi(tech.pegasys.teku.network.p2p.jvmlibp2p.MockMessageApi) ValidationResult(io.libp2p.core.pubsub.ValidationResult) 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