本文整理汇总了Java中com.google.bitcoin.utils.TestUtils.makeSolvedTestBlock方法的典型用法代码示例。如果您正苦于以下问题:Java TestUtils.makeSolvedTestBlock方法的具体用法?Java TestUtils.makeSolvedTestBlock怎么用?Java TestUtils.makeSolvedTestBlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.bitcoin.utils.TestUtils
的用法示例。
在下文中一共展示了TestUtils.makeSolvedTestBlock方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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());
}
示例2: 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);
}
示例3: 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();
}
示例4: singleDownloadPeer1
import com.google.bitcoin.utils.TestUtils; //导入方法依赖的package包/类
@Test
public void singleDownloadPeer1() throws Exception {
// Check that we don't attempt to retrieve blocks on multiple peers.
peerGroup.startAndWait();
// Create a couple of peers.
FakeChannel p1 = connectPeer(1);
FakeChannel p2 = connectPeer(2);
assertEquals(2, peerGroup.numConnectedPeers());
// Set up a little block chain. We heard about b1 but not b2 (it is pending download). b3 is solved whilst we
// are downloading the chain.
Block b1 = TestUtils.createFakeBlock(blockStore).block;
blockChain.add(b1);
Block b2 = TestUtils.makeSolvedTestBlock(b1);
Block b3 = TestUtils.makeSolvedTestBlock(b2);
// Peer 1 and 2 receives an inv advertising a newly solved block.
InventoryMessage inv = new InventoryMessage(params);
inv.addBlock(b3);
// Only peer 1 tries to download it.
inbound(p1, inv);
assertTrue(outbound(p1) instanceof GetDataMessage);
assertNull(outbound(p2));
// Peer 1 goes away, peer 2 becomes the download peer and thus queries the remote mempool.
closePeer(peerOf(p1));
// Peer 2 fetches it next time it hears an inv (should it fetch immediately?).
inbound(p2, inv);
assertTrue(outbound(p2) instanceof GetDataMessage);
peerGroup.stop();
}
示例5: 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.
FakeChannel 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.
FakeChannel p2 = connectPeer(2);
Message message = (Message)outbound(p2);
assertNull(message == null ? "" : message.toString(), message);
peerGroup.stop();
}
示例6: singleDownloadPeer1
import com.google.bitcoin.utils.TestUtils; //导入方法依赖的package包/类
@Test
public void singleDownloadPeer1() throws Exception {
// Check that we don't attempt to retrieve blocks on multiple peers.
peerGroup.startAndWait();
// Create a couple of peers.
InboundMessageQueuer p1 = connectPeer(1);
InboundMessageQueuer p2 = connectPeer(2);
assertEquals(2, peerGroup.numConnectedPeers());
// Set up a little block chain. We heard about b1 but not b2 (it is pending download). b3 is solved whilst we
// are downloading the chain.
Block b1 = TestUtils.createFakeBlock(blockStore).block;
blockChain.add(b1);
Block b2 = TestUtils.makeSolvedTestBlock(b1);
Block b3 = TestUtils.makeSolvedTestBlock(b2);
// Peer 1 and 2 receives an inv advertising a newly solved block.
InventoryMessage inv = new InventoryMessage(params);
inv.addBlock(b3);
// Only peer 1 tries to download it.
inbound(p1, inv);
pingAndWait(p1);
assertTrue(outbound(p1) instanceof GetDataMessage);
assertNull(outbound(p2));
// Peer 1 goes away, peer 2 becomes the download peer and thus queries the remote mempool.
final SettableFuture<Void> p1CloseFuture = SettableFuture.create();
peerOf(p1).addEventListener(new AbstractPeerEventListener() {
@Override
public void onPeerDisconnected(Peer peer, int peerCount) {
p1CloseFuture.set(null);
}
});
closePeer(peerOf(p1));
p1CloseFuture.get();
// Peer 2 fetches it next time it hears an inv (should it fetch immediately?).
inbound(p2, inv);
assertTrue(outbound(p2) instanceof GetDataMessage);
peerGroup.stop();
}