Search in sources :

Example 1 with Peer

use of org.ethereum.net.p2p.Peer in project rskj by rsksmart.

the class PeerTest method testPeer.

/* PEER */
@Test
public void testPeer() {
    // Init
    InetAddress address = InetAddress.getLoopbackAddress();
    List<Capability> capabilities = new ArrayList<>();
    int port = 1010;
    String peerId = "1010";
    Peer peerCopy = new Peer(address, port, peerId);
    // Peer
    Peer peer = new Peer(address, port, peerId);
    // getAddress
    assertEquals("127.0.0.1", peer.getAddress().getHostAddress());
    // getPort
    assertEquals(port, peer.getPort());
    // getPeerId
    assertEquals(peerId, peer.getPeerId());
    // getCapabilities
    assertEquals(capabilities, peer.getCapabilities());
    // getEncoded
    assertEquals("CC847F0000018203F2821010C0", Hex.toHexString(peer.getEncoded()).toUpperCase());
    // toString
    assertEquals("[ip=" + address.getHostAddress() + " port=" + Integer.toString(port) + " peerId=" + peerId + "]", peer.toString());
    // equals
    assertEquals(true, peer.equals(peerCopy));
    assertEquals(false, peer.equals(null));
    // hashCode
    assertEquals(-1218913009, peer.hashCode());
}
Also used : Capability(org.ethereum.net.client.Capability) Peer(org.ethereum.net.p2p.Peer) ArrayList(java.util.ArrayList) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Aggregations

InetAddress (java.net.InetAddress)1 ArrayList (java.util.ArrayList)1 Capability (org.ethereum.net.client.Capability)1 Peer (org.ethereum.net.p2p.Peer)1 Test (org.junit.Test)1