Esempio n. 1
0
  // Instantiate from constructor
  @Test
  public void test2() {

    // Init
    byte version = 2;
    String clientStr = "Ethereum(++)/v0.7.9/Release/Linux/g++";
    List<Capability> capabilities =
        Arrays.asList(
            new Capability(Capability.ETH, EthVersion.UPPER),
            new Capability(Capability.SHH, ShhHandler.VERSION),
            new Capability(Capability.P2P, P2pHandler.VERSION));
    int listenPort = 992;
    String peerId = "1fbf1e41f08078918c9f7b6734594ee56d7f538614f602c71194db0a1af5a";

    HelloMessage helloMessage =
        new HelloMessage(version, clientStr, capabilities, listenPort, peerId);
    logger.info(helloMessage.toString());

    assertEquals(P2pMessageCodes.HELLO, helloMessage.getCommand());
    assertEquals(version, helloMessage.getP2PVersion());
    assertEquals(clientStr, helloMessage.getClientId());
    assertEquals(3, helloMessage.getCapabilities().size());
    assertEquals(listenPort, helloMessage.getListenPort());
    assertEquals(peerId, helloMessage.getPeerId());
  }
Esempio n. 2
0
  // Parsing from raw bytes
  @Test
  public void test1() {
    String helloMessageRaw =
        "f87902a5457468657265756d282b2b292f76302e372e392f52656c656173652f4c696e75782f672b2bccc58365746827c583736868018203e0b8401fbf1e41f08078918c9f7b6734594ee56d7f538614f602c71194db0a1af5a77f9b86eb14669fe7a8a46a2dd1b7d070b94e463f4ecd5b337c8b4d31bbf8dd5646";

    byte[] payload = Hex.decode(helloMessageRaw);
    HelloMessage helloMessage = new HelloMessage(payload);
    logger.info(helloMessage.toString());

    assertEquals(P2pMessageCodes.HELLO, helloMessage.getCommand());
    assertEquals(2, helloMessage.getP2PVersion());
    assertEquals("Ethereum(++)/v0.7.9/Release/Linux/g++", helloMessage.getClientId());
    assertEquals(2, helloMessage.getCapabilities().size());
    assertEquals(992, helloMessage.getListenPort());
    assertEquals(
        "1fbf1e41f08078918c9f7b6734594ee56d7f538614f602c71194db0a1af5a77f9b86eb14669fe7a8a46a2dd1b7d070b94e463f4ecd5b337c8b4d31bbf8dd5646",
        helloMessage.getPeerId());
  }
Esempio n. 3
0
  // Fail test
  @Test
  public void test3() {
    // Init
    byte version = -1; // invalid version
    String clientStr = ""; // null id
    List<Capability> capabilities =
        Arrays.asList(
            new Capability(null, (byte) 0),
            new Capability(null, (byte) 0),
            null, // null here causes NullPointerException when using toString
            new Capability(null, (byte) 0)); // encoding null capabilities
    int listenPort = 99999; // invalid port
    String peerId = ""; // null id

    HelloMessage helloMessage =
        new HelloMessage(version, clientStr, capabilities, listenPort, peerId);

    assertEquals(P2pMessageCodes.HELLO, helloMessage.getCommand());
    assertEquals(version, helloMessage.getP2PVersion());
    assertEquals(clientStr, helloMessage.getClientId());
    assertEquals(4, helloMessage.getCapabilities().size());
    assertEquals(listenPort, helloMessage.getListenPort());
    assertEquals(peerId, helloMessage.getPeerId());
  }