예제 #1
0
  @Test
  public void invDownloadTxMultiPeer() throws Exception {
    // Check co-ordination of which peer to download via the memory pool.
    VersionMessage ver = new VersionMessage(unitTestParams, 100);
    InetSocketAddress address = new InetSocketAddress("127.0.0.1", 4242);
    Peer peer2 = new Peer(unitTestParams, ver, new PeerAddress(address), blockChain, memoryPool);
    peer2.addWallet(wallet);
    VersionMessage peerVersion = new VersionMessage(unitTestParams, OTHER_PEER_CHAIN_HEIGHT);
    peerVersion.clientVersion = 70001;
    peerVersion.localServices = VersionMessage.NODE_NETWORK;

    connect();
    InboundMessageQueuer writeTarget2 = connect(peer2, peerVersion);

    // Make a tx and advertise it to one of the peers.
    BigInteger value = Utils.toNanoCoins(1, 0);
    Transaction tx = createFakeTx(unitTestParams, value, this.address);
    InventoryMessage inv = new InventoryMessage(unitTestParams);
    InventoryItem item = new InventoryItem(InventoryItem.Type.Transaction, tx.getHash());
    inv.addItem(item);

    inbound(writeTarget, inv);

    // We got a getdata message.
    GetDataMessage message = (GetDataMessage) outbound(writeTarget);
    assertEquals(1, message.getItems().size());
    assertEquals(tx.getHash(), message.getItems().get(0).hash);
    assertTrue(memoryPool.maybeWasSeen(tx.getHash()));

    // Advertising to peer2 results in no getdata message.
    inbound(writeTarget2, inv);
    pingAndWait(writeTarget2);
    assertNull(outbound(writeTarget2));
  }
예제 #2
0
 private void connectWithVersion(int version) throws Exception {
   VersionMessage peerVersion = new VersionMessage(unitTestParams, OTHER_PEER_CHAIN_HEIGHT);
   peerVersion.clientVersion = version;
   peerVersion.localServices = VersionMessage.NODE_NETWORK;
   writeTarget = connect(peer, peerVersion);
 }