From da24699ed59855cb891fb734069bb540ce1418c0 Mon Sep 17 00:00:00 2001 From: Faiz Khan Date: Mon, 29 Dec 2014 04:01:28 -0600 Subject: [PATCH] Peer test --- .../test/java/test/ethereum/net/PeerTest.java | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 ethereumj-core/src/test/java/test/ethereum/net/PeerTest.java diff --git a/ethereumj-core/src/test/java/test/ethereum/net/PeerTest.java b/ethereumj-core/src/test/java/test/ethereum/net/PeerTest.java new file mode 100644 index 00000000..532119e1 --- /dev/null +++ b/ethereumj-core/src/test/java/test/ethereum/net/PeerTest.java @@ -0,0 +1,57 @@ +package test.ethereum.net; + +import static org.junit.Assert.assertEquals; + +import org.ethereum.net.client.Capability; +import org.ethereum.net.p2p.Peer; + +import org.spongycastle.util.encoders.Hex; +import java.net.InetAddress; +import java.util.List; +import java.util.ArrayList; +import org.junit.Test; + +public class PeerTest { + + /* PEER */ + + @Test + public void testPeer() { + + //Init + InetAddress address = InetAddress.getLoopbackAddress(); + List 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(-1, peer.hashCode()); + } +} +