use of tech.pegasys.teku.networking.p2p.mock.MockNodeId in project teku by ConsenSys.
the class SubnetScorerTest method shouldScoreCandidatePeersOnSubnetsWithFewPeersMoreHighly.
@Test
void shouldScoreCandidatePeersOnSubnetsWithFewPeersMoreHighly() {
final MockNodeId node1 = new MockNodeId(0);
final MockNodeId node2 = new MockNodeId(1);
final MockNodeId node3 = new MockNodeId(2);
final SubnetScorer scorer = SubnetScorer.create(PeerSubnetSubscriptions.builder(() -> schemaDefinitions).attestationSubnetSubscriptions(b -> b.addRelevantSubnet(1).addRelevantSubnet(2).addRelevantSubnet(3).addRelevantSubnet(5).addSubscriber(1, node2).addSubscriber(3, node3)).syncCommitteeSubnetSubscriptions(b -> b.addRelevantSubnet(1).addRelevantSubnet(2).addSubscriber(1, node1).addSubscriber(1, node2).addSubscriber(1, node3)).build());
assertCandidatePeerScores(scorer, entry(candidateWithSubnets(List.of(1, 3), List.of(1)), 562), entry(candidateWithSubnets(List.of(1), List.of(1)), 312), entry(candidateWithSubnets(List.of(2), List.of(1)), 1062), entry(candidateWithSubnets(List.of(3), List.of(1)), 312), entry(candidateWithSubnets(emptyList(), emptyList()), 0), entry(candidateWithSubnets(List.of(5), emptyList()), 1000), entry(candidateWithSubnets(List.of(4), emptyList()), 0), entry(candidateWithSubnets(emptyList(), List.of(2)), 1000), entry(candidateWithSubnets(emptyList(), List.of(3)), 0));
}
use of tech.pegasys.teku.networking.p2p.mock.MockNodeId in project teku by ConsenSys.
the class PeerManagerTest method subscribeConnect_shouldRejectConnectionThatAlreadyExists.
@Test
public void subscribeConnect_shouldRejectConnectionThatAlreadyExists() {
final List<Peer> connectedPeers = new ArrayList<>();
peerManager.subscribeConnect(connectedPeers::add);
final Peer peer = mock(Peer.class);
when(peer.getId()).thenReturn(new MockNodeId(1));
peerManager.onConnectedPeer(peer);
assertThat(connectedPeers).containsExactly(peer);
Assertions.assertThrows(PeerAlreadyConnectedException.class, () -> peerManager.onConnectedPeer(peer));
assertThat(connectedPeers).containsExactly(peer);
}
use of tech.pegasys.teku.networking.p2p.mock.MockNodeId in project teku by ConsenSys.
the class PeerManagerTest method shouldReportFailedConnectionsToReputationManager.
@Test
public void shouldReportFailedConnectionsToReputationManager() {
final Multiaddr multiaddr = Multiaddr.fromString("/ip4/127.0.0.1/tcp/9000");
final MultiaddrPeerAddress peerAddress = new MultiaddrPeerAddress(new MockNodeId(1), multiaddr);
when(network.connect(multiaddr)).thenReturn(CompletableFuture.failedFuture(new RuntimeException("Nope")));
final SafeFuture<Peer> result = peerManager.connect(peerAddress, network);
assertThat(result).isCompletedExceptionally();
verify(reputationManager).reportInitiatedConnectionFailed(peerAddress);
verify(reputationManager, never()).reportInitiatedConnectionSuccessful(peerAddress);
}
use of tech.pegasys.teku.networking.p2p.mock.MockNodeId in project teku by ConsenSys.
the class PeerPoolsTest method shouldReturnToDefaultPoolWhenPeerForgotten.
@Test
void shouldReturnToDefaultPoolWhenPeerForgotten() {
final MockNodeId nodeId = new MockNodeId(1);
pools.addPeerToPool(nodeId, PeerPool.RANDOMLY_SELECTED);
pools.forgetPeer(nodeId);
assertThat(pools.getPool(nodeId)).isEqualTo(PeerPool.SCORE_BASED);
}
use of tech.pegasys.teku.networking.p2p.mock.MockNodeId in project teku by ConsenSys.
the class ConnectionManagerTest method shouldConnectPeersThatPassPeerFilter.
@Test
public void shouldConnectPeersThatPassPeerFilter() {
final ConnectionManager manager = createManager();
final StubPeer peer1 = new StubPeer(new MockNodeId(1));
final StubPeer peer2 = new StubPeer(new MockNodeId(2));
when(network.connect(PEER1)).thenReturn(SafeFuture.completedFuture(peer1));
when(network.connect(PEER2)).thenReturn(SafeFuture.completedFuture(peer2));
when(discoveryService.streamKnownPeers()).thenReturn(Stream.of(DISCOVERY_PEER1, DISCOVERY_PEER2));
manager.start().join();
verify(network).connect(PEER1);
verify(network).connect(PEER2);
}
Aggregations