• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java FakeTxBuilder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: testPaymentMessage

import org.bitcoinj.testing.FakeTxBuilder; //导入依赖的package包/类
@Test
public void testPaymentMessage() throws Exception {
    // Create
    List<Transaction> transactions = new LinkedList<Transaction>();
    transactions.add(FakeTxBuilder.createFakeTx(NETWORK_PARAMS, AMOUNT, TO_ADDRESS));
    Coin refundAmount = Coin.SATOSHI;
    Address refundAddress = new ECKey().toAddress(NETWORK_PARAMS);
    Payment payment = PaymentProtocol.createPaymentMessage(transactions, refundAmount, refundAddress, MEMO,
            MERCHANT_DATA);
    byte[] paymentBytes = payment.toByteArray();

    // Parse
    Payment parsedPayment = Payment.parseFrom(paymentBytes);
    List<Transaction> parsedTransactions = PaymentProtocol.parseTransactionsFromPaymentMessage(NETWORK_PARAMS,
            parsedPayment);
    assertEquals(transactions, parsedTransactions);
    assertEquals(1, parsedPayment.getRefundToCount());
    assertEquals(MEMO, parsedPayment.getMemo());
    assertArrayEquals(MERCHANT_DATA, parsedPayment.getMerchantData().toByteArray());
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:21,代码来源:PaymentProtocolTest.java


示例2: testInitialize

import org.bitcoinj.testing.FakeTxBuilder; //导入依赖的package包/类
@Test
public void testInitialize() throws BlockStoreException {
    final BlockStore blockStore = new MemoryBlockStore(PARAMS);
    final BlockChain chain = new BlockChain(PARAMS, blockStore);

    // Build a historical chain of version 2 blocks
    long timeSeconds = 1231006505;
    StoredBlock chainHead = null;
    for (int height = 0; height < PARAMS.getMajorityWindow(); height++) {
        chainHead = FakeTxBuilder.createFakeBlock(blockStore, 2, timeSeconds, height).storedBlock;
        assertEquals(2, chainHead.getHeader().getVersion());
        timeSeconds += 60;
    }

    VersionTally instance = new VersionTally(PARAMS);
    instance.initialize(blockStore, chainHead);
    assertEquals(PARAMS.getMajorityWindow(), instance.getCountAtOrAbove(2).intValue());
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:19,代码来源:VersionTallyTest.java


示例3: intraBlockDependencies

import org.bitcoinj.testing.FakeTxBuilder; //导入依赖的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(PARAMS);
    Block b1 = PARAMS.getGenesisBlock().createNextBlock(somebodyElse);
    ECKey key = wallet.freshReceiveKey();
    Address addr = key.toAddress(PARAMS);
    // Create a tx that gives us some coins, and another that spends it to someone else in the same block.
    Transaction t1 = FakeTxBuilder.createFakeTx(PARAMS, COIN, addr);
    Transaction t2 = new Transaction(PARAMS);
    t2.addInput(t1.getOutputs().get(0));
    t2.addOutput(valueOf(2, 0), somebodyElse);
    b1.addTransaction(t1);
    b1.addTransaction(t2);
    b1.solve();
    chain.add(b1);
    assertEquals(Coin.ZERO, wallet.getBalance());
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:20,代码来源:BlockChainTest.java


示例4: testStandardWalletDisconnect

import org.bitcoinj.testing.FakeTxBuilder; //导入依赖的package包/类
@Test
public void testStandardWalletDisconnect() throws Exception {
    NetworkParameters params = UnitTestParams.get();
    Wallet w = new Wallet(new Context(params));
    w.setCoinSelector(new AllowUnconfirmedCoinSelector());
    Address a = w.currentReceiveAddress();
    Transaction tx1 = FakeTxBuilder.createFakeTxWithoutChangeAddress(params, Coin.COIN, a);
    w.receivePending(tx1, null);
    Transaction tx2 = new Transaction(params);
    tx2.addOutput(Coin.valueOf(99000000), new ECKey());
    w.completeTx(SendRequest.forTx(tx2));

    TransactionInput txInToDisconnect = tx2.getInput(0);

    assertEquals(tx1, txInToDisconnect.getOutpoint().fromTx);
    assertNull(txInToDisconnect.getOutpoint().connectedOutput);

    txInToDisconnect.disconnect();

    assertNull(txInToDisconnect.getOutpoint().fromTx);
    assertNull(txInToDisconnect.getOutpoint().connectedOutput);
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:23,代码来源:TransactionInputTest.java


示例5: markKeysAsUsedDisorder

import org.bitcoinj.testing.FakeTxBuilder; //导入依赖的package包/类
@Test
public void markKeysAsUsedDisorder() throws Exception {
    control.replay();
    DeterministicKey key1 = wallet.currentReceiveKey();
    String a1 = "mfsh3sGu8SzxRZXDRPMbwdCykDfdiXLTVQ";
    String a2 = "mpkchvF3Twgpd5AEmrRZM3TENT8V7Ygi8T";

    Transaction tx1 = FakeTxBuilder.createFakeTx(params, Coin.CENT, new Address(params, a2));
    multiWallet.addPendingDownload(tx1.getHash());
    multiWallet.receive(tx1, 0);
    DeterministicKey key2 = wallet.currentReceiveKey();
    assertEquals(wallet.currentReceiveKey(), key1);

    Transaction tx2 = FakeTxBuilder.createFakeTx(params, Coin.CENT, new Address(params, a1));
    multiWallet.addPendingDownload(tx2.getHash());
    multiWallet.receive(tx2, 0);
    assertNotEquals(wallet.currentReceiveKey(), key2);
    assertNotEquals(wallet.currentReceiveKey().toAddress(params), a1);
    assertNotEquals(wallet.currentReceiveKey().toAddress(params), a2);
    control.verify();
}
 
开发者ID:devrandom,项目名称:java-stratum,代码行数:22,代码来源:ElectrumMultiWalletTest.java


示例6: coinAgeOrdering

import org.bitcoinj.testing.FakeTxBuilder; //导入依赖的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(COIN, AbstractBlockChain.NewBlockType.BEST_CHAIN));
    // Padding block.
    wallet.notifyNewBestBlock(FakeTxBuilder.createFakeBlock(blockStore).storedBlock);
    final Coin TWO_COINS = COIN.multiply(2);
    Transaction t2 = checkNotNull(sendMoneyToWallet(TWO_COINS, AbstractBlockChain.NewBlockType.BEST_CHAIN));
    Transaction t3 = checkNotNull(sendMoneyToWallet(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,项目名称:namecoinj,代码行数:22,代码来源:DefaultCoinSelectorTest.java


示例7: intraBlockDependencies

import org.bitcoinj.testing.FakeTxBuilder; //导入依赖的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 = wallet.freshReceiveKey();
    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 = FakeTxBuilder.createFakeTx(unitTestParams, COIN, addr);
    Transaction t2 = new Transaction(unitTestParams);
    t2.addInput(t1.getOutputs().get(0));
    t2.addOutput(valueOf(2, 0), somebodyElse);
    b1.addTransaction(t1);
    b1.addTransaction(t2);
    b1.solve();
    chain.add(b1);
    assertEquals(Coin.ZERO, wallet.getBalance());
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:20,代码来源:BlockChainTest.java


示例8: createFilteredBlock

import org.bitcoinj.testing.FakeTxBuilder; //导入依赖的package包/类
@Test
public void createFilteredBlock() throws Exception {
    ECKey key1 = new ECKey();
    ECKey key2 = new ECKey();
    Transaction tx1 = FakeTxBuilder.createFakeTx(params, Coin.COIN,  key1);
    Transaction tx2 = FakeTxBuilder.createFakeTx(params, Coin.FIFTY_COINS, key2.toAddress(params));
    Block block = FakeTxBuilder.makeSolvedTestBlock(params.getGenesisBlock(), new Address(params, "msg2t2V2sWNd85LccoddtWysBTR8oPnkzW"), tx1, tx2);
    BloomFilter filter = new BloomFilter(4, 0.1, 1);
    filter.insert(key1);
    filter.insert(key2);
    FilteredBlock filteredBlock = filter.applyAndUpdate(block);
    assertEquals(4, filteredBlock.getTransactionCount());
    // This call triggers verification of the just created data.
    List<Sha256Hash> txns = filteredBlock.getTransactionHashes();
    assertTrue(txns.contains(tx1.getHash()));
    assertTrue(txns.contains(tx2.getHash()));
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:18,代码来源:FilteredBlockAndPartialMerkleTreeTests.java


示例9: testPaymentMessage

import org.bitcoinj.testing.FakeTxBuilder; //导入依赖的package包/类
@Test
public void testPaymentMessage() throws Exception {
    // Create
    List<Transaction> transactions = new LinkedList<>();
    transactions.add(FakeTxBuilder.createFakeTx(NETWORK_PARAMS, AMOUNT, TO_ADDRESS));
    Coin refundAmount = Coin.SATOSHI;
    Address refundAddress = new ECKey().toAddress(NETWORK_PARAMS);
    Payment payment = PaymentProtocol.createPaymentMessage(transactions, refundAmount, refundAddress, MEMO,
            MERCHANT_DATA);
    byte[] paymentBytes = payment.toByteArray();

    // Parse
    Payment parsedPayment = Payment.parseFrom(paymentBytes);
    List<Transaction> parsedTransactions = PaymentProtocol.parseTransactionsFromPaymentMessage(NETWORK_PARAMS,
            parsedPayment);
    assertEquals(transactions, parsedTransactions);
    assertEquals(1, parsedPayment.getRefundToCount());
    assertEquals(MEMO, parsedPayment.getMemo());
    assertArrayEquals(MERCHANT_DATA, parsedPayment.getMerchantData().toByteArray());
}
 
开发者ID:bitcoinj,项目名称:bitcoinj,代码行数:21,代码来源:PaymentProtocolTest.java


示例10: transactionVersions

import org.bitcoinj.testing.FakeTxBuilder; //导入依赖的package包/类
@Test
public void transactionVersions() throws Exception {
    Transaction tx = FakeTxBuilder.createFakeTx(PARAMS);
    tx.setVersion(1);
    DefaultRiskAnalysis analysis = DefaultRiskAnalysis.FACTORY.create(wallet, tx, NO_DEPS);
    assertEquals(RiskAnalysis.Result.OK, analysis.analyze());

    tx.setVersion(2);
    analysis = DefaultRiskAnalysis.FACTORY.create(wallet, tx, NO_DEPS);
    assertEquals(RiskAnalysis.Result.OK, analysis.analyze());

    tx.setVersion(3);
    analysis = DefaultRiskAnalysis.FACTORY.create(wallet, tx, NO_DEPS);
    assertEquals(RiskAnalysis.Result.NON_STANDARD, analysis.analyze());
    assertEquals(tx, analysis.getNonStandard());
}
 
开发者ID:bitcoinj,项目名称:bitcoinj,代码行数:17,代码来源:DefaultRiskAnalysisTest.java


示例11: optInFullRBF

import org.bitcoinj.testing.FakeTxBuilder; //导入依赖的package包/类
@Test
public void optInFullRBF() throws Exception {
    Transaction tx = FakeTxBuilder.createFakeTx(PARAMS);
    tx.getInput(0).setSequenceNumber(TransactionInput.NO_SEQUENCE - 2);
    DefaultRiskAnalysis analysis = DefaultRiskAnalysis.FACTORY.create(wallet, tx, NO_DEPS);
    assertEquals(RiskAnalysis.Result.NON_FINAL, analysis.analyze());
    assertEquals(tx, analysis.getNonFinal());
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:9,代码来源:DefaultRiskAnalysisTest.java


示例12: orderingInsideBlock

import org.bitcoinj.testing.FakeTxBuilder; //导入依赖的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 = FakeTxBuilder.createFakeTx(PARAMS, COIN, coinsTo);
    final Block b1 = FakeTxBuilder.makeSolvedTestBlock(PARAMS.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(PARAMS), CENT));
    wallet.commitTx(t2);
    Transaction t3 = checkNotNull(wallet.createSend(new ECKey().toAddress(PARAMS), CENT));
    wallet.commitTx(t3);
    chain.add(FakeTxBuilder.makeSolvedTestBlock(b1, t2, t3));

    final Coin coins0point98 = COIN.subtract(CENT).subtract(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 = FakeTxBuilder.makeSolvedTestBlock(b1, t2, t3);
    final Block b3 = FakeTxBuilder.makeSolvedTestBlock(b2);
    chain.add(b2);
    chain.add(b3);

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


示例13: testDeprecatedBlockVersion

import org.bitcoinj.testing.FakeTxBuilder; //导入依赖的package包/类
private void testDeprecatedBlockVersion(final long deprecatedVersion, final long newVersion)
        throws Exception {
    final BlockStore versionBlockStore = new MemoryBlockStore(PARAMS);
    final BlockChain versionChain = new BlockChain(PARAMS, versionBlockStore);

    // Build a historical chain of version 3 blocks
    long timeSeconds = 1231006505;
    int height = 0;
    FakeTxBuilder.BlockPair chainHead = null;

    // Put in just enough v2 blocks to be a minority
    for (height = 0; height < (PARAMS.getMajorityWindow() - PARAMS.getMajorityRejectBlockOutdated()); height++) {
        chainHead = FakeTxBuilder.createFakeBlock(versionBlockStore, deprecatedVersion, timeSeconds, height);
        versionChain.add(chainHead.block);
        timeSeconds += 60;
    }
    // Fill the rest of the window with v3 blocks
    for (; height < PARAMS.getMajorityWindow(); height++) {
        chainHead = FakeTxBuilder.createFakeBlock(versionBlockStore, newVersion, timeSeconds, height);
        versionChain.add(chainHead.block);
        timeSeconds += 60;
    }

    chainHead = FakeTxBuilder.createFakeBlock(versionBlockStore, deprecatedVersion, timeSeconds, height);
    // Trying to add a new v2 block should result in rejection
    thrown.expect(VerificationException.BlockVersionOutOfDate.class);
    try {
        versionChain.add(chainHead.block);
    } catch(final VerificationException ex) {
        throw (Exception) ex.getCause();
    }
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:33,代码来源:BlockChainTest.java


示例14: markKeysAsUsed

import org.bitcoinj.testing.FakeTxBuilder; //导入依赖的package包/类
@Test
public void markKeysAsUsed() throws Exception {
    control.replay();
    DeterministicKey key1 = wallet.currentReceiveKey();
    Transaction tx1 = FakeTxBuilder.createFakeTx(params, Coin.CENT, key1.toAddress(params));
    multiWallet.addPendingDownload(tx1.getHash());
    multiWallet.receive(tx1, 0);
    DeterministicKey key2 = wallet.currentReceiveKey();
    assertNotEquals(wallet.currentReceiveKey(), key1);
    Transaction tx2 = FakeTxBuilder.createFakeTx(params, Coin.CENT, key2.toAddress(params));
    multiWallet.addPendingDownload(tx2.getHash());
    multiWallet.receive(tx2, 0);
    assertNotEquals(wallet.currentReceiveKey(), key2);
    control.verify();
}
 
开发者ID:devrandom,项目名称:java-stratum,代码行数:16,代码来源:ElectrumMultiWalletTest.java


示例15: setUp

import org.bitcoinj.testing.FakeTxBuilder; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    dummy = FakeTxBuilder.createFakeTx(PARAMS, Coin.COIN, ADDRESS);
    tx = new Transaction(PARAMS);
    tx.addOutput(Coin.COIN, ADDRESS);
    tx.addInput(dummy.getOutput(0));
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:8,代码来源:TransactionTest.java


示例16: orderingInsideBlock

import org.bitcoinj.testing.FakeTxBuilder; //导入依赖的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 = FakeTxBuilder.createFakeTx(unitTestParams, COIN, coinsTo);
    final Block b1 = FakeTxBuilder.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), CENT));
    wallet.commitTx(t2);
    Transaction t3 = checkNotNull(wallet.createSend(new ECKey().toAddress(unitTestParams), CENT));
    wallet.commitTx(t3);
    chain.add(FakeTxBuilder.makeSolvedTestBlock(b1, t2, t3));

    final Coin coins0point98 = COIN.subtract(CENT).subtract(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 = FakeTxBuilder.makeSolvedTestBlock(b1, t2, t3);
    final Block b3 = FakeTxBuilder.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,项目名称:namecoinj,代码行数:35,代码来源:ChainSplitTest.java


示例17: retryFailedBroadcast

import org.bitcoinj.testing.FakeTxBuilder; //导入依赖的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 = FakeTxBuilder.makeSolvedTestBlock(blockStore, address);
    inbound(p1, b1);
    assertNull(outbound(p1));
    assertEquals(FIFTY_COINS, 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, COIN);
    assertFalse(sendResult.broadcastComplete.isDone());
    Transaction t1;
    {
        Message m;
        while (!((m = outbound(p1)) instanceof Transaction));
        t1 = (Transaction) m;
    }
    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,项目名称:namecoinj,代码行数:36,代码来源:TransactionBroadcastTest.java


示例18: setup

import org.bitcoinj.testing.FakeTxBuilder; //导入依赖的package包/类
@Before
public void setup() throws Exception {
    BriefLogFormatter.init();
    tx1 = FakeTxBuilder.createFakeTx(params, COIN, 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,项目名称:namecoinj,代码行数:11,代码来源:MemoryPoolTest.java


示例19: receiveTxBroadcast

import org.bitcoinj.testing.FakeTxBuilder; //导入依赖的package包/类
@Test
public void receiveTxBroadcast() throws Exception {
    // Check that when we receive transactions on all our peers, we do the right thing.
    peerGroup.startAsync();
    peerGroup.awaitRunning();

    // 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);

    Coin value = COIN;
    Transaction t1 = FakeTxBuilder.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.stopAsync();
    peerGroup.awaitTerminated();
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:41,代码来源:PeerGroupTest.java


示例20: receiveTxBroadcastOnAddedWallet

import org.bitcoinj.testing.FakeTxBuilder; //导入依赖的package包/类
@Test
public void receiveTxBroadcastOnAddedWallet() throws Exception {
    // Check that when we receive transactions on all our peers, we do the right thing.
    peerGroup.startAsync();
    peerGroup.awaitRunning();

    // Create a peer.
    InboundMessageQueuer p1 = connectPeer(1);
    
    Wallet wallet2 = new Wallet(unitTestParams);
    ECKey key2 = wallet2.freshReceiveKey();
    Address address2 = key2.toAddress(unitTestParams);
    
    peerGroup.addWallet(wallet2);
    blockChain.addWallet(wallet2);

    assertTrue(outbound(p1) instanceof BloomFilter);
    assertTrue(outbound(p1) instanceof MemoryPoolMessage);

    Coin value = COIN;
    Transaction t1 = FakeTxBuilder.createFakeTx(unitTestParams, value, address2);
    InventoryMessage inv = new InventoryMessage(unitTestParams);
    inv.addTransaction(t1);

    inbound(p1, inv);
    assertTrue(outbound(p1) instanceof GetDataMessage);
    inbound(p1, t1);
    // Asks for dependency.
    GetDataMessage getdata = (GetDataMessage) outbound(p1);
    assertNotNull(getdata);
    inbound(p1, new NotFoundMessage(unitTestParams, getdata.getItems()));
    pingAndWait(p1);
    assertEquals(value, wallet2.getBalance(Wallet.BalanceType.ESTIMATED));
    peerGroup.stopAsync();
    peerGroup.awaitTerminated();
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:37,代码来源:PeerGroupTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java EPlugin类代码示例发布时间:2022-05-22
下一篇:
Java EntitySnowball类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap