当前位置: 首页>>代码示例>>Java>>正文


Java TestUtils类代码示例

本文整理汇总了Java中com.google.bitcoin.utils.TestUtils的典型用法代码示例。如果您正苦于以下问题:Java TestUtils类的具体用法?Java TestUtils怎么用?Java TestUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TestUtils类属于com.google.bitcoin.utils包,在下文中一共展示了TestUtils类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: coinAgeOrdering

import com.google.bitcoin.utils.TestUtils; //导入依赖的package包/类
@Test
public void coinAgeOrdering() throws Exception {
    // Send three transactions in four blocks on top of each other. Coin age of t1 is 1*4=4, coin age of t2 = 2*2=4
    // and t3=0.01.
    Transaction t1 = checkNotNull(sendMoneyToWallet(Utils.COIN, AbstractBlockChain.NewBlockType.BEST_CHAIN));
    // Padding block.
    wallet.notifyNewBestBlock(TestUtils.createFakeBlock(blockStore).storedBlock);
    final BigInteger TWO_COINS = Utils.COIN.multiply(BigInteger.valueOf(2));
    Transaction t2 = checkNotNull(sendMoneyToWallet(TWO_COINS, AbstractBlockChain.NewBlockType.BEST_CHAIN));
    Transaction t3 = checkNotNull(sendMoneyToWallet(Utils.CENT, AbstractBlockChain.NewBlockType.BEST_CHAIN));

    // Should be ordered t2, t1, t3.
    ArrayList<TransactionOutput> candidates = new ArrayList<TransactionOutput>();
    candidates.add(t3.getOutput(0));
    candidates.add(t2.getOutput(0));
    candidates.add(t1.getOutput(0));
    DefaultCoinSelector.sortOutputs(candidates);
    assertEquals(t2.getOutput(0), candidates.get(0));
    assertEquals(t1.getOutput(0), candidates.get(1));
    assertEquals(t3.getOutput(0), candidates.get(2));
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:22,代码来源:DefaultCoinSelectorTest.java

示例2: intraBlockDependencies

import com.google.bitcoin.utils.TestUtils; //导入依赖的package包/类
@Test
public void intraBlockDependencies() throws Exception {
    // Covers issue 166 in which transactions that depend on each other inside a block were not always being
    // considered relevant.
    Address somebodyElse = new ECKey().toAddress(unitTestParams);
    Block b1 = unitTestParams.getGenesisBlock().createNextBlock(somebodyElse);
    ECKey key = new ECKey();
    wallet.addKey(key);
    Address addr = key.toAddress(unitTestParams);
    // Create a tx that gives us some coins, and another that spends it to someone else in the same block.
    Transaction t1 = TestUtils.createFakeTx(unitTestParams, Utils.toNanoCoins(1, 0), addr);
    Transaction t2 = new Transaction(unitTestParams);
    t2.addInput(t1.getOutputs().get(0));
    t2.addOutput(Utils.toNanoCoins(2, 0), somebodyElse);
    b1.addTransaction(t1);
    b1.addTransaction(t2);
    b1.solve();
    chain.add(b1);
    assertEquals(BigInteger.ZERO, wallet.getBalance());
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:21,代码来源:BlockChainTest.java

示例3: orderingInsideBlock

import com.google.bitcoin.utils.TestUtils; //导入依赖的package包/类
@Test
public void orderingInsideBlock() throws Exception {
    // Test that transactions received in the same block have their ordering preserved when reorganising.
    // This covers issue 468.

    // Receive some money to the wallet.
    Transaction t1 = TestUtils.createFakeTx(unitTestParams, Utils.COIN, coinsTo);
    final Block b1 = TestUtils.makeSolvedTestBlock(unitTestParams.genesisBlock, t1);
    chain.add(b1);

    // Send a couple of payments one after the other (so the second depends on the change output of the first).
    wallet.allowSpendingUnconfirmedTransactions();
    Transaction t2 = checkNotNull(wallet.createSend(new ECKey().toAddress(unitTestParams), Utils.CENT));
    wallet.commitTx(t2);
    Transaction t3 = checkNotNull(wallet.createSend(new ECKey().toAddress(unitTestParams), Utils.CENT));
    wallet.commitTx(t3);
    chain.add(TestUtils.makeSolvedTestBlock(b1, t2, t3));

    final BigInteger coins0point98 = Utils.COIN.subtract(Utils.CENT).subtract(Utils.CENT);
    assertEquals(coins0point98, wallet.getBalance());

    // Now round trip the wallet and force a re-org.
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    wallet.saveToFileStream(bos);
    wallet = Wallet.loadFromFileStream(new ByteArrayInputStream(bos.toByteArray()));
    final Block b2 = TestUtils.makeSolvedTestBlock(b1, t2, t3);
    final Block b3 = TestUtils.makeSolvedTestBlock(b2);
    chain.add(b2);
    chain.add(b3);

    // And verify that the balance is as expected. Because signatures are currently non-deterministic if the order
    // isn't being stored correctly this should fail 50% of the time.
    assertEquals(coins0point98, wallet.getBalance());
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:35,代码来源:ChainSplitTest.java

示例4: retryFailedBroadcast

import com.google.bitcoin.utils.TestUtils; //导入依赖的package包/类
@Test
public void retryFailedBroadcast() throws Exception {
    // If we create a spend, it's sent to a peer that swallows it, and the peergroup is removed/re-added then
    // the tx should be broadcast again.
    InboundMessageQueuer p1 = connectPeer(1);
    connectPeer(2);

    // Send ourselves a bit of money.
    Block b1 = TestUtils.makeSolvedTestBlock(blockStore, address);
    inbound(p1, b1);
    assertNull(outbound(p1));
    assertEquals(Utils.toNanoCoins(50, 0), wallet.getBalance());

    // Now create a spend, and expect the announcement on p1.
    Address dest = new ECKey().toAddress(params);
    Wallet.SendResult sendResult = wallet.sendCoins(peerGroup, dest, Utils.toNanoCoins(1, 0));
    assertFalse(sendResult.broadcastComplete.isDone());
    Transaction t1 = (Transaction) outbound(p1);
    assertFalse(sendResult.broadcastComplete.isDone());

    // p1 eats it :( A bit later the PeerGroup is taken down.
    peerGroup.removeWallet(wallet);
    peerGroup.addWallet(wallet);

    // We want to hear about it again. Now, because we've disabled the randomness for the unit tests it will
    // re-appear on p1 again. Of course in the real world it would end up with a different set of peers and
    // select randomly so we get a second chance.
    Transaction t2 = (Transaction) outbound(p1);
    assertEquals(t1, t2);
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:31,代码来源:TransactionBroadcastTest.java

示例5: setup

import com.google.bitcoin.utils.TestUtils; //导入依赖的package包/类
@Before
public void setup() throws Exception {
    BriefLogFormatter.init();
    tx1 = TestUtils.createFakeTx(params, Utils.toNanoCoins(1, 0), new ECKey().toAddress(params));
    tx2 = new Transaction(params, tx1.bitcoinSerialize());

    address1 = new PeerAddress(InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 }));
    address2 = new PeerAddress(InetAddress.getByAddress(new byte[] { 127, 0, 0, 2 }));
    address3 = new PeerAddress(InetAddress.getByAddress(new byte[] { 127, 0, 0, 3 }));
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:11,代码来源:MemoryPoolTest.java

示例6: receiveTxBroadcast

import com.google.bitcoin.utils.TestUtils; //导入依赖的package包/类
@Test
public void receiveTxBroadcast() throws Exception {
    // Check that when we receive transactions on all our peers, we do the right thing.
    peerGroup.startAndWait();

    // Create a couple of peers.
    InboundMessageQueuer p1 = connectPeer(1);
    InboundMessageQueuer p2 = connectPeer(2);
    
    // Check the peer accessors.
    assertEquals(2, peerGroup.numConnectedPeers());
    Set<Peer> tmp = new HashSet<Peer>(peerGroup.getConnectedPeers());
    Set<Peer> expectedPeers = new HashSet<Peer>();
    expectedPeers.add(peerOf(p1));
    expectedPeers.add(peerOf(p2));
    assertEquals(tmp, expectedPeers);

    BigInteger value = Utils.toNanoCoins(1, 0);
    Transaction t1 = TestUtils.createFakeTx(unitTestParams, value, address);
    InventoryMessage inv = new InventoryMessage(unitTestParams);
    inv.addTransaction(t1);

    // Note: we start with p2 here to verify that transactions are downloaded from whichever peer announces first
    // which does not have to be the same as the download peer (which is really the "block download peer").
    inbound(p2, inv);
    assertTrue(outbound(p2) instanceof GetDataMessage);
    inbound(p1, inv);
    assertNull(outbound(p1));  // Only one peer is used to download.
    inbound(p2, t1);
    assertNull(outbound(p1));
    // Asks for dependency.
    GetDataMessage getdata = (GetDataMessage) outbound(p2);
    assertNotNull(getdata);
    inbound(p2, new NotFoundMessage(unitTestParams, getdata.getItems()));
    pingAndWait(p2);
    assertEquals(value, wallet.getBalance(Wallet.BalanceType.ESTIMATED));
    peerGroup.stopAndWait();
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:39,代码来源:PeerGroupTest.java

示例7: singleDownloadPeer2

import com.google.bitcoin.utils.TestUtils; //导入依赖的package包/类
@Test
public void singleDownloadPeer2() throws Exception {
    // Check that we don't attempt multiple simultaneous block chain downloads, when adding a new peer in the
    // middle of an existing chain download.
    // Create a couple of peers.
    peerGroup.startAndWait();

    // Create a couple of peers.
    InboundMessageQueuer p1 = connectPeer(1);

    // Set up a little block chain.
    Block b1 = TestUtils.createFakeBlock(blockStore).block;
    Block b2 = TestUtils.makeSolvedTestBlock(b1);
    Block b3 = TestUtils.makeSolvedTestBlock(b2);

    // Expect a zero hash getblocks on p1. This is how the process starts.
    peerGroup.startBlockChainDownload(new AbstractPeerEventListener() {
    });
    GetBlocksMessage getblocks = (GetBlocksMessage) outbound(p1);
    assertEquals(Sha256Hash.ZERO_HASH, getblocks.getStopHash());
    // We give back an inv with some blocks in it.
    InventoryMessage inv = new InventoryMessage(params);
    inv.addBlock(b1);
    inv.addBlock(b2);
    inv.addBlock(b3);
    
    inbound(p1, inv);
    assertTrue(outbound(p1) instanceof GetDataMessage);
    // We hand back the first block.
    inbound(p1, b1);
    // Now we successfully connect to another peer. There should be no messages sent.
    InboundMessageQueuer p2 = connectPeer(2);
    Message message = (Message)outbound(p2);
    assertNull(message == null ? "" : message.toString(), message);
    peerGroup.stop();
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:37,代码来源:PeerGroupTest.java

示例8: testBloomOnP2Pubkey

import com.google.bitcoin.utils.TestUtils; //导入依赖的package包/类
@Test
public void testBloomOnP2Pubkey() throws Exception {
    // Cover bug 513. When a relevant transaction with a p2pubkey output is found, the Bloom filter should be
    // recalculated to include that transaction hash but not re-broadcast as the remote nodes should have followed
    // the same procedure. However a new node that's connected should get the fresh filter.
    peerGroup.startAndWait();
    final ECKey key = wallet.getKeys().get(0);
    // Create a couple of peers.
    InboundMessageQueuer p1 = connectPeer(1);
    InboundMessageQueuer p2 = connectPeer(2);
    // Create a pay to pubkey tx.
    Transaction tx = TestUtils.createFakeTx(params, Utils.COIN, key);
    Transaction tx2 = new Transaction(params);
    tx2.addInput(tx.getOutput(0));
    TransactionOutPoint outpoint = tx2.getInput(0).getOutpoint();
    assertTrue(p1.lastReceivedFilter.contains(key.getPubKey()));
    assertFalse(p1.lastReceivedFilter.contains(tx.getHash().getBytes()));
    inbound(p1, tx);
    // p1 requests dep resolution, p2 is quiet.
    assertTrue(outbound(p1) instanceof GetDataMessage);
    final Sha256Hash dephash = tx.getInput(0).getOutpoint().getHash();
    final InventoryItem inv = new InventoryItem(InventoryItem.Type.Transaction, dephash);
    inbound(p1, new NotFoundMessage(params, ImmutableList.of(inv)));
    assertNull(outbound(p1));
    assertNull(outbound(p2));
    peerGroup.waitForJobQueue();
    // Now we connect p3 and there is a new bloom filter sent, that DOES match the relevant outpoint.
    InboundMessageQueuer p3 = connectPeer(3);
    assertTrue(p3.lastReceivedFilter.contains(key.getPubKey()));
    assertTrue(p3.lastReceivedFilter.contains(outpoint.bitcoinSerialize()));
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:32,代码来源:PeerGroupTest.java


注:本文中的com.google.bitcoin.utils.TestUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。