use of io.libp2p.core.security.SecureChannel.Session in project teku by ConsenSys.
the class PeerManagerTest method shouldReportSuccessfulConnectionsToReputationManager.
@Test
public void shouldReportSuccessfulConnectionsToReputationManager() {
final Connection connection = mock(Connection.class);
final Session secureSession = new Session(PeerId.random(), PeerId.random(), EcdsaKt.generateEcdsaKeyPair().component2());
when(connection.secureSession()).thenReturn(secureSession);
when(connection.closeFuture()).thenReturn(new SafeFuture<>());
final Multiaddr multiaddr = Multiaddr.fromString("/ip4/127.0.0.1/tcp/9000");
final MultiaddrPeerAddress peerAddress = new MultiaddrPeerAddress(new MockNodeId(1), multiaddr);
final SafeFuture<Connection> connectionFuture = new SafeFuture<>();
when(network.connect(multiaddr)).thenReturn(connectionFuture);
final SafeFuture<Peer> result = peerManager.connect(peerAddress, network);
peerManager.handleConnection(connection);
connectionFuture.complete(connection);
assertThat(result).isCompleted();
verify(reputationManager).reportInitiatedConnectionSuccessful(peerAddress);
verify(reputationManager, never()).reportInitiatedConnectionFailed(peerAddress);
}
Aggregations