コード例 #1
0
ファイル: PeerTest.java プロジェクト: Bushstar/bitcoinj
  // Check that an inv to a peer that is not set to download missing blocks does nothing.
  @Test
  public void invNoDownload() throws Exception {
    // Don't download missing blocks.
    peer.setDownloadData(false);

    connect();

    // Make a missing block that we receive.
    Block b1 = createFakeBlock(blockStore).block;
    blockChain.add(b1);
    Block b2 = makeSolvedTestBlock(b1);

    // Receive an inv.
    InventoryMessage inv = new InventoryMessage(unitTestParams);
    InventoryItem item = new InventoryItem(InventoryItem.Type.Block, b2.getHash());
    inv.addItem(item);
    inbound(writeTarget, inv);

    // Peer does nothing with it.
    assertNull(outbound(writeTarget));
  }
コード例 #2
0
ファイル: PeerTest.java プロジェクト: Bushstar/bitcoinj
  @Test
  public void invDownloadTx() throws Exception {
    connect();

    peer.setDownloadData(true);
    // Make a transaction and tell the peer we have it.
    BigInteger value = Utils.toNanoCoins(1, 0);
    Transaction tx = createFakeTx(unitTestParams, value, address);
    InventoryMessage inv = new InventoryMessage(unitTestParams);
    InventoryItem item = new InventoryItem(InventoryItem.Type.Transaction, tx.getHash());
    inv.addItem(item);
    inbound(writeTarget, inv);
    // Peer hasn't seen it before, so will ask for it.
    GetDataMessage getdata = (GetDataMessage) outbound(writeTarget);
    assertEquals(1, getdata.getItems().size());
    assertEquals(tx.getHash(), getdata.getItems().get(0).hash);
    inbound(writeTarget, tx);
    // Ask for the dependency, it's not in the mempool (in chain).
    getdata = (GetDataMessage) outbound(writeTarget);
    inbound(writeTarget, new NotFoundMessage(unitTestParams, getdata.getItems()));
    pingAndWait(writeTarget);
    assertEquals(value, wallet.getBalance(Wallet.BalanceType.ESTIMATED));
  }