Search in sources :

Example 1 with MockMessageApi

use of tech.pegasys.teku.network.p2p.jvmlibp2p.MockMessageApi 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 2 with MockMessageApi

use of tech.pegasys.teku.network.p2p.jvmlibp2p.MockMessageApi 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 3 with MockMessageApi

use of tech.pegasys.teku.network.p2p.jvmlibp2p.MockMessageApi 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 4 with MockMessageApi

use of tech.pegasys.teku.network.p2p.jvmlibp2p.MockMessageApi in project teku by ConsenSys.

the class GossipHandlerTest method gossip_afterDuplicateApply.

@Test
@SuppressWarnings("FutureReturnValueIgnored")
public void gossip_afterDuplicateApply() {
    final Bytes data = Bytes.fromHexString("0x01");
    final MockMessageApi message = new MockMessageApi(data, topic);
    gossipHandler.apply(message);
    gossipHandler.gossip(data);
    verify(publisher, never()).publish(any(), any());
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) MockMessageApi(tech.pegasys.teku.network.p2p.jvmlibp2p.MockMessageApi) Test(org.junit.jupiter.api.Test)

Example 5 with MockMessageApi

use of tech.pegasys.teku.network.p2p.jvmlibp2p.MockMessageApi 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)

Aggregations

Test (org.junit.jupiter.api.Test)7 MockMessageApi (tech.pegasys.teku.network.p2p.jvmlibp2p.MockMessageApi)7 ValidationResult (io.libp2p.core.pubsub.ValidationResult)6 Bytes (org.apache.tuweni.bytes.Bytes)6 ByteBuf (io.netty.buffer.ByteBuf)1