Skip to content

Commit

Permalink
Add some JavaDocs to FakeTxBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
mikehearn committed May 20, 2014
1 parent 2548076 commit 1fe0e7f
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions core/src/main/java/com/google/bitcoin/testing/FakeTxBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,15 @@
import java.math.BigInteger;
import java.nio.ByteBuffer;

/**
* Utility methods for building fake/invalid transactions, often useful for unit testing.
*/
public class FakeTxBuilder {
/**
* Create a fake TX of sufficient realism to exercise the unit tests. Two outputs, one to us, one to somewhere
* else to simulate change. There is one random input.
*/
public static Transaction createFakeTxWithChangeAddress(NetworkParameters params, BigInteger nanocoins, Address to, Address changeOutput) {
// Create a fake TX of sufficient realism to exercise the unit tests. Two outputs, one to us, one to somewhere
// else to simulate change.
Transaction t = new Transaction(params);
TransactionOutput outputToMe = new TransactionOutput(params, t, nanocoins, to);
t.addOutput(outputToMe);
Expand All @@ -45,13 +50,19 @@ public static Transaction createFakeTxWithChangeAddress(NetworkParameters params
return roundTripTransaction(params, t);
}

/**
* Create a fake TX of sufficient realism to exercise the unit tests. Two outputs, one to us, one to somewhere
* else to simulate change. There is one random input.
*/
public static Transaction createFakeTx(NetworkParameters params, BigInteger nanocoins, Address to) {
return createFakeTxWithChangeAddress(params, nanocoins, to, new ECKey().toAddress(params));
}

/**
* Create a fake TX of sufficient realism to exercise the unit tests. Two outputs, one to us, one to somewhere
* else to simulate change. There is one random input.
*/
public static Transaction createFakeTx(NetworkParameters params, BigInteger nanocoins, ECKey to) {
// Create a fake TX of sufficient realism to exercise the unit tests. Two outputs, one to us, one to somewhere
// else to simulate change.
Transaction t = new Transaction(params);
TransactionOutput outputToMe = new TransactionOutput(params, t, nanocoins, to);
t.addOutput(outputToMe);
Expand All @@ -69,7 +80,7 @@ public static Transaction createFakeTx(NetworkParameters params, BigInteger nano
}

/**
* @return Transaction[] Transaction[0] is a feeder transaction, supplying BTC to Transaction[1]
* Transaction[0] is a feeder transaction, supplying BTC to Transaction[1]
*/
public static Transaction[] createFakeTx(NetworkParameters params, BigInteger nanocoins,
Address to, Address from) {
Expand Down Expand Up @@ -154,7 +165,7 @@ public static class BlockPair {
public Block block;
}

// Emulates receiving a valid block that builds on top of the chain.
/** Emulates receiving a valid block that builds on top of the chain. */
public static BlockPair createFakeBlock(BlockStore blockStore, long timeSeconds, Transaction... transactions) {
try {
Block chainHead = blockStore.getChainHead().getHeader();
Expand Down

0 comments on commit 1fe0e7f

Please sign in to comment.