Clean up coin constants and make more use of it.

This commit is contained in:
Andreas Schildbach 2014-04-26 20:09:41 +02:00 committed by Mike Hearn
parent 938dec7a73
commit 51c48bb69f
27 changed files with 305 additions and 295 deletions

View file

@ -35,7 +35,7 @@ import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import static com.google.bitcoin.core.Coin.valueOf;
import static com.google.bitcoin.core.Coin.FIFTY_COINS;
import static com.google.bitcoin.core.Utils.doubleDigest;
import static com.google.bitcoin.core.Utils.doubleDigestTwoBuffers;
@ -168,7 +168,7 @@ public class Block extends Message {
* </p>
*/
public Coin getBlockInflation(int height) {
return valueOf(50, 0).shiftRight(height / params.getSubsidyDecreaseBlockCount());
return FIFTY_COINS.shiftRight(height / params.getSubsidyDecreaseBlockCount());
}
private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
@ -982,7 +982,7 @@ public class Block extends Message {
*/
@VisibleForTesting
public Block createNextBlock(Address to, long time) {
return createNextBlock(to, null, time, pubkeyForTesting, valueOf(50, 0));
return createNextBlock(to, null, time, pubkeyForTesting, FIFTY_COINS);
}
/**
@ -998,7 +998,7 @@ public class Block extends Message {
if (to != null) {
// Add a transaction paying 50 coins to the "to" address.
Transaction t = new Transaction(params);
t.addOutput(new TransactionOutput(params, t, valueOf(50, 0), to));
t.addOutput(new TransactionOutput(params, t, FIFTY_COINS, to));
// The input does not really need to be a valid signature, as long as it has the right general form.
TransactionInput input;
if (prevOut == null) {
@ -1033,7 +1033,7 @@ public class Block extends Message {
@VisibleForTesting
public Block createNextBlock(@Nullable Address to, TransactionOutPoint prevOut) {
return createNextBlock(to, prevOut, Utils.currentTimeSeconds(), pubkeyForTesting, valueOf(50, 0));
return createNextBlock(to, prevOut, Utils.currentTimeSeconds(), pubkeyForTesting, FIFTY_COINS);
}
@VisibleForTesting
@ -1043,7 +1043,7 @@ public class Block extends Message {
@VisibleForTesting
public Block createNextBlock(@Nullable Address to) {
return createNextBlock(to, valueOf(50, 0));
return createNextBlock(to, FIFTY_COINS);
}
@VisibleForTesting
@ -1057,7 +1057,7 @@ public class Block extends Message {
*/
@VisibleForTesting
Block createNextBlockWithCoinbase(byte[] pubKey) {
return createNextBlock(null, null, Utils.currentTimeSeconds(), pubKey, valueOf(50, 0));
return createNextBlock(null, null, Utils.currentTimeSeconds(), pubKey, FIFTY_COINS);
}
@VisibleForTesting

View file

@ -29,28 +29,38 @@ import com.google.common.math.LongMath;
*/
public final class Coin implements Comparable<Coin>, Serializable {
/**
* Zero Bitcoins.
*/
public static final Coin ZERO = Coin.valueOf(0);
public static final Coin ONE = Coin.valueOf(1);
public static final Coin TEN = Coin.valueOf(10);
public static final Coin NEGATIVE_ONE = Coin.valueOf(-1);
/**
* How many "nanocoins" there are in a Bitcoin.
* <p/>
* A nanocoin is the smallest unit that can be transferred using Bitcoin.
* The term nanocoin is very misleading, though, because there are only 100 million
* of them in a coin (whereas one would expect 1 billion.
* One Bitcoin.
*/
public static final Coin COIN = Coin.valueOf(100000000);
/**
* How many "nanocoins" there are in 0.01 BitCoins.
* <p/>
* A nanocoin is the smallest unit that can be transferred using Bitcoin.
* The term nanocoin is very misleading, though, because there are only 100 million
* of them in a coin (whereas one would expect 1 billion).
* 0.01 Bitcoins. This unit is not really used much.
*/
public static final Coin CENT = Coin.valueOf(1000000);
public static final Coin CENT = COIN.divide(100);
/**
* 0.001 Bitcoins, also known as 1 mBTC.
*/
public static final Coin MILLICOIN = COIN.divide(1000);
/**
* 0.000001 Bitcoins, also known as 1 µBTC or 1 uBTC.
*/
public static final Coin NANOCOIN = MILLICOIN.divide(1000);
/**
* A satoshi is the smallest unit that can be transferred. 100 million of them fit into a Bitcoin.
*/
public static final Coin SATOSHI = Coin.valueOf(1);
public static final Coin FIFTY_COINS = COIN.multiply(50);
public static final Coin NEGATIVE_ONE = Coin.valueOf(-1);
private final long value;

View file

@ -110,7 +110,7 @@ public abstract class NetworkParameters implements Serializable {
Script.writeBytes(scriptPubKeyBytes, Hex.decode
("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f"));
scriptPubKeyBytes.write(ScriptOpCodes.OP_CHECKSIG);
t.addOutput(new TransactionOutput(n, t, valueOf(50, 0), scriptPubKeyBytes.toByteArray()));
t.addOutput(new TransactionOutput(n, t, FIFTY_COINS, scriptPubKeyBytes.toByteArray()));
} catch (Exception e) {
// Cannot happen.
throw new RuntimeException(e);

View file

@ -206,7 +206,7 @@ public class TransactionOutput extends ChildMessage implements Serializable {
// size of data needed to satisfy all different script types, or just hard code 33 below.
final long size = this.bitcoinSerialize().length + 148;
Coin[] nonDustAndRemainder = feePerKbRequired.multiply(size).divideAndRemainder(1000);
return nonDustAndRemainder[1].equals(Coin.ZERO) ? nonDustAndRemainder[0] : nonDustAndRemainder[0].add(Coin.ONE);
return nonDustAndRemainder[1].equals(Coin.ZERO) ? nonDustAndRemainder[0] : nonDustAndRemainder[0].add(Coin.SATOSHI);
}
/**

View file

@ -3625,7 +3625,7 @@ public class Wallet extends BaseTaggableObject implements Serializable, BlockCha
// This solution definitely fits in category 3
isCategory3 = true;
additionalValueForNextCategory = Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.add(
Transaction.MIN_NONDUST_OUTPUT.add(Coin.ONE));
Transaction.MIN_NONDUST_OUTPUT.add(Coin.SATOSHI));
} else {
size += changeOutput.bitcoinSerialize().length + VarInt.sizeOf(req.tx.getOutputs().size()) - VarInt.sizeOf(req.tx.getOutputs().size() - 1);
// This solution is either category 1 or 2
@ -3636,7 +3636,7 @@ public class Wallet extends BaseTaggableObject implements Serializable, BlockCha
if (eitherCategory2Or3) {
// This solution definitely fits in category 3 (we threw away change because it was smaller than MIN_TX_FEE)
isCategory3 = true;
additionalValueForNextCategory = Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.add(Coin.ONE);
additionalValueForNextCategory = Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.add(Coin.SATOSHI);
}
}

View file

@ -24,7 +24,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import static com.google.bitcoin.core.Coin.valueOf;
import static com.google.bitcoin.core.Coin.*;
public class FakeTxBuilder {
/**
@ -132,7 +132,7 @@ public class FakeTxBuilder {
*/
public static DoubleSpends createFakeDoubleSpendTxns(NetworkParameters params, Address to) {
DoubleSpends doubleSpends = new DoubleSpends();
Coin value = valueOf(1, 0);
Coin value = COIN;
Address someBadGuy = new ECKey().toAddress(params);
doubleSpends.t1 = new Transaction(params);

View file

@ -33,7 +33,7 @@ import java.io.File;
import java.lang.ref.WeakReference;
import java.util.Arrays;
import static com.google.bitcoin.core.Coin.valueOf;
import static com.google.bitcoin.core.Coin.FIFTY_COINS;
import static org.junit.Assert.*;
/**
@ -132,7 +132,7 @@ public abstract class AbstractFullPrunedBlockChainTest
rollingBlock = rollingBlock.createNextBlock(null);
Transaction t = new Transaction(params);
t.addOutput(new TransactionOutput(params, t, valueOf(50, 0), new byte[] {}));
t.addOutput(new TransactionOutput(params, t, FIFTY_COINS, new byte[] {}));
TransactionInput input = t.addInput(spendableOutput);
// Invalid script.
input.setScriptBytes(new byte[]{});
@ -174,7 +174,7 @@ public abstract class AbstractFullPrunedBlockChainTest
Transaction t = new Transaction(params);
// Entirely invalid scriptPubKey
t.addOutput(new TransactionOutput(params, t, valueOf(50, 0), new byte[] {}));
t.addOutput(new TransactionOutput(params, t, FIFTY_COINS, new byte[] {}));
t.addSignedInput(spendableOutput, new Script(spendableOutputScriptPubKey), outKey);
rollingBlock.addTransaction(t);
rollingBlock.solve();

View file

@ -33,7 +33,7 @@ import java.math.BigInteger;
import java.text.SimpleDateFormat;
import java.util.Date;
import static com.google.bitcoin.core.Coin.valueOf;
import static com.google.bitcoin.core.Coin.*;
import static com.google.bitcoin.testing.FakeTxBuilder.createFakeBlock;
import static com.google.bitcoin.testing.FakeTxBuilder.createFakeTx;
import static org.junit.Assert.*;
@ -124,7 +124,7 @@ public class BlockChainTest {
public void receiveCoins() throws Exception {
// Quick check that we can actually receive coins.
Transaction tx1 = createFakeTx(unitTestParams,
valueOf(1, 0),
COIN,
wallet.currentReceiveKey().toAddress(unitTestParams));
Block b1 = createFakeBlock(blockStore, tx1).block;
chain.add(b1);
@ -136,7 +136,7 @@ public class BlockChainTest {
// Test that merkle root verification takes place when a relevant transaction is present and doesn't when
// there isn't any such tx present (as an optimization).
Transaction tx1 = createFakeTx(unitTestParams,
valueOf(1, 0),
COIN,
wallet.currentReceiveKey().toAddress(unitTestParams));
Block b1 = createFakeBlock(blockStore, tx1).block;
chain.add(b1);
@ -151,7 +151,7 @@ public class BlockChainTest {
b1.setMerkleRoot(hash);
}
// Now add a second block with no relevant transactions and then break it.
Transaction tx2 = createFakeTx(unitTestParams, valueOf(1, 0),
Transaction tx2 = createFakeTx(unitTestParams, COIN,
new ECKey().toAddress(unitTestParams));
Block b2 = createFakeBlock(blockStore, tx2).block;
b2.getMerkleRoot();
@ -271,7 +271,7 @@ public class BlockChainTest {
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, valueOf(1, 0), addr);
Transaction t1 = FakeTxBuilder.createFakeTx(unitTestParams, COIN, addr);
Transaction t2 = new Transaction(unitTestParams);
t2.addInput(t1.getOutputs().get(0));
t2.addOutput(valueOf(2, 0), somebodyElse);
@ -302,7 +302,7 @@ public class BlockChainTest {
// The coinbase tx is not yet available to spend.
assertEquals(Coin.ZERO, wallet.getBalance());
assertEquals(wallet.getBalance(BalanceType.ESTIMATED), valueOf(50, 0));
assertEquals(wallet.getBalance(BalanceType.ESTIMATED), FIFTY_COINS);
assertTrue(!coinbaseTransaction.isMature());
// Attempt to spend the coinbase - this should fail as the coinbase is not mature yet.
@ -315,7 +315,7 @@ public class BlockChainTest {
// Check that the coinbase is unavailable to spend for the next spendableCoinbaseDepth - 2 blocks.
for (int i = 0; i < unitTestParams.getSpendableCoinbaseDepth() - 2; i++) {
// Non relevant tx - just for fake block creation.
Transaction tx2 = createFakeTx(unitTestParams, valueOf(1, 0),
Transaction tx2 = createFakeTx(unitTestParams, COIN,
new ECKey().toAddress(unitTestParams));
Block b2 = createFakeBlock(blockStore, tx2).block;
@ -323,7 +323,7 @@ public class BlockChainTest {
// Wallet still does not have the coinbase transaction available for spend.
assertEquals(Coin.ZERO, wallet.getBalance());
assertEquals(wallet.getBalance(BalanceType.ESTIMATED), valueOf(50, 0));
assertEquals(wallet.getBalance(BalanceType.ESTIMATED), FIFTY_COINS);
// The coinbase transaction is still not mature.
assertTrue(!coinbaseTransaction.isMature());
@ -337,13 +337,13 @@ public class BlockChainTest {
}
// Give it one more block - should now be able to spend coinbase transaction. Non relevant tx.
Transaction tx3 = createFakeTx(unitTestParams, valueOf(1, 0), new ECKey().toAddress(unitTestParams));
Transaction tx3 = createFakeTx(unitTestParams, COIN, new ECKey().toAddress(unitTestParams));
Block b3 = createFakeBlock(blockStore, tx3).block;
chain.add(b3);
// Wallet now has the coinbase transaction available for spend.
assertEquals(wallet.getBalance(), valueOf(50, 0));
assertEquals(wallet.getBalance(BalanceType.ESTIMATED), valueOf(50, 0));
assertEquals(wallet.getBalance(), FIFTY_COINS);
assertEquals(wallet.getBalance(BalanceType.ESTIMATED), FIFTY_COINS);
assertTrue(coinbaseTransaction.isMature());
// Create a spend with the coinbase BTC to the address in the second wallet - this should now succeed.
@ -352,14 +352,14 @@ public class BlockChainTest {
// Commit the coinbaseSpend to the first wallet and check the balances decrement.
wallet.commitTx(coinbaseSend2);
assertEquals(wallet.getBalance(BalanceType.ESTIMATED), valueOf(1, 0));
assertEquals(wallet.getBalance(BalanceType.ESTIMATED), COIN);
// Available balance is zero as change has not been received from a block yet.
assertEquals(wallet.getBalance(BalanceType.AVAILABLE), valueOf(0, 0));
assertEquals(wallet.getBalance(BalanceType.AVAILABLE), ZERO);
// Give it one more block - change from coinbaseSpend should now be available in the first wallet.
Block b4 = createFakeBlock(blockStore, coinbaseSend2).block;
chain.add(b4);
assertEquals(wallet.getBalance(BalanceType.AVAILABLE), valueOf(1, 0));
assertEquals(wallet.getBalance(BalanceType.AVAILABLE), COIN);
// Check the balances in the second wallet.
assertEquals(wallet2.getBalance(BalanceType.ESTIMATED), valueOf(49, 0));

View file

@ -164,7 +164,7 @@ public class BlockTest {
//assertTrue(tx.length == tx.bitcoinSerialize().length && tx.length == 8);
byte[] outputScript = new byte[10];
Arrays.fill(outputScript, (byte) ScriptOpCodes.OP_FALSE);
tx.addOutput(new TransactionOutput(params, null, Coin.valueOf(1), outputScript));
tx.addOutput(new TransactionOutput(params, null, Coin.SATOSHI, outputScript));
tx.addInput(new TransactionInput(params, null, new byte[] {(byte) ScriptOpCodes.OP_FALSE},
new TransactionOutPoint(params, 0, Sha256Hash.create(new byte[] {1}))));
int origTxLength = 8 + 2 + 8 + 1 + 10 + 40 + 1 + 1;

View file

@ -140,7 +140,7 @@ public class ChainSplitTest {
// \-> b3 -> b4
// We lost some coins! b2 is no longer a part of the best chain so our available balance should drop to 50.
// It's now pending reconfirmation.
assertEquals("50.00", wallet.getBalance().toFriendlyString());
assertEquals(FIFTY_COINS, wallet.getBalance());
// ... and back to the first chain.
Block b5 = b2.createNextBlock(coinsTo);
Block b6 = b5.createNextBlock(coinsTo);
@ -172,7 +172,7 @@ public class ChainSplitTest {
assertTrue(chain.add(b3));
assertEquals(Coin.ZERO, wallet.getBalance());
assertTrue(chain.add(b4));
assertEquals("50.00", wallet.getBalance().toFriendlyString());
assertEquals(FIFTY_COINS, wallet.getBalance());
}
@Test
@ -180,7 +180,7 @@ public class ChainSplitTest {
// Check that we can handle our own spends being rolled back by a fork.
Block b1 = unitTestParams.getGenesisBlock().createNextBlock(coinsTo);
chain.add(b1);
assertEquals("50.00", wallet.getBalance().toFriendlyString());
assertEquals(FIFTY_COINS, wallet.getBalance());
Address dest = new ECKey().toAddress(unitTestParams);
Transaction spend = wallet.createSend(dest, valueOf(10, 0));
wallet.commitTx(spend);
@ -214,9 +214,9 @@ public class ChainSplitTest {
// keys are being shared between wallets.
Block b1 = unitTestParams.getGenesisBlock().createNextBlock(coinsTo);
chain.add(b1);
assertEquals("50.00", wallet.getBalance().toFriendlyString());
assertEquals(FIFTY_COINS, wallet.getBalance());
Address dest = new ECKey().toAddress(unitTestParams);
Transaction spend = wallet.createSend(dest, valueOf(50, 0));
Transaction spend = wallet.createSend(dest, FIFTY_COINS);
// We do NOT confirm the spend here. That means it's not considered to be pending because createSend is
// stateless. For our purposes it is as if some other program with our keys created the tx.
//
@ -229,13 +229,13 @@ public class ChainSplitTest {
b3.solve();
chain.add(roundtrip(b3));
// The external spend is now pending.
assertEquals(valueOf(0, 0), wallet.getBalance());
assertEquals(ZERO, wallet.getBalance());
Transaction tx = wallet.getTransaction(spend.getHash());
assertEquals(ConfidenceType.PENDING, tx.getConfidence().getConfidenceType());
Block b4 = b3.createNextBlock(someOtherGuy);
chain.add(b4);
// The external spend is now active.
assertEquals(valueOf(0, 0), wallet.getBalance());
assertEquals(ZERO, wallet.getBalance());
assertEquals(ConfidenceType.BUILDING, tx.getConfidence().getConfidenceType());
}
@ -245,7 +245,7 @@ public class ChainSplitTest {
Block b1 = unitTestParams.getGenesisBlock().createNextBlock(coinsTo);
chain.add(b1);
final Transaction t = b1.transactions.get(1);
assertEquals("50.00", wallet.getBalance().toFriendlyString());
assertEquals(FIFTY_COINS, wallet.getBalance());
// genesis -> b1
// -> b2
Block b2 = unitTestParams.getGenesisBlock().createNextBlock(coinsTo);
@ -255,13 +255,13 @@ public class ChainSplitTest {
b2.addTransaction(t);
b2.solve();
chain.add(roundtrip(b2));
assertEquals("50.00", wallet.getBalance().toFriendlyString());
assertEquals(FIFTY_COINS, wallet.getBalance());
assertTrue(wallet.isConsistent());
assertEquals(2, wallet.getTransaction(t.getHash()).getAppearsInHashes().size());
// -> b2 -> b3
Block b3 = b2.createNextBlock(someOtherGuy);
chain.add(b3);
assertEquals("50.00", wallet.getBalance().toFriendlyString());
assertEquals(FIFTY_COINS, wallet.getBalance());
}
@ -285,7 +285,7 @@ public class ChainSplitTest {
b3.addTransaction(b2.transactions.get(1));
b3.solve();
chain.add(roundtrip(b3));
assertEquals("50.00", wallet.getBalance().toFriendlyString());
assertEquals(FIFTY_COINS, wallet.getBalance());
}
@Test
@ -358,7 +358,7 @@ public class ChainSplitTest {
// t1 is still pending ...
Block b2 = b1.createNextBlock(new ECKey().toAddress(unitTestParams));
chain.add(b2);
assertEquals(valueOf(0, 0), wallet.getBalance());
assertEquals(ZERO, wallet.getBalance());
assertEquals(valueOf(40, 0), wallet.getBalance(Wallet.BalanceType.ESTIMATED));
// Now we make a double spend become active after a re-org.
@ -385,7 +385,7 @@ public class ChainSplitTest {
chain.add(b6);
// genesis -> b1 -> b2 -> b5 -> b6 [t1 still dead]
// \-> b3 [t2 resurrected and now pending] -> b4
assertEquals(valueOf(0, 0), wallet.getBalance());
assertEquals(ZERO, wallet.getBalance());
// t2 is pending - resurrected double spends take precedence over our dead transactions (which are in nobodies
// mempool by this point).
t1 = checkNotNull(wallet.getTransaction(t1.getHash()));
@ -618,7 +618,7 @@ public class ChainSplitTest {
chain.add(firstTip);
}
// ... and spend.
Transaction fodder = wallet.createSend(new ECKey().toAddress(unitTestParams), valueOf(50, 0));
Transaction fodder = wallet.createSend(new ECKey().toAddress(unitTestParams), FIFTY_COINS);
wallet.commitTx(fodder);
final AtomicBoolean fodderIsDead = new AtomicBoolean(false);
fodder.getConfidence().addEventListener(new TransactionConfidence.Listener() {

View file

@ -56,7 +56,7 @@ public class CoinTest {
@Test
public void testToFriendlyString() {
assertEquals("1.00", valueOf(1, 0).toFriendlyString());
assertEquals("1.00", COIN.toFriendlyString());
assertEquals("1.23", valueOf(1, 23).toFriendlyString());
assertEquals("0.001", Coin.valueOf(COIN.longValue() / 1000).toFriendlyString());
assertEquals("-1.23", valueOf(1, 23).negate().toFriendlyString());

View file

@ -12,7 +12,7 @@ import java.io.IOException;
import java.math.BigInteger;
import java.util.*;
import static com.google.bitcoin.core.Coin.valueOf;
import static com.google.bitcoin.core.Coin.*;
import static com.google.bitcoin.script.ScriptOpCodes.*;
/**
@ -134,14 +134,14 @@ public class FullBlockTestGenerator {
blocks.add(new BlockAndValidity(blockToHeightMap, chainHead, true, false, chainHead.getHash(), 1, "Initial Block"));
spendableOutputs.offer(new TransactionOutPointWithValue(
new TransactionOutPoint(params, 0, chainHead.getTransactions().get(0).getHash()),
valueOf(50, 0), chainHead.getTransactions().get(0).getOutputs().get(0).getScriptPubKey()));
FIFTY_COINS, chainHead.getTransactions().get(0).getOutputs().get(0).getScriptPubKey()));
for (int i = 1; i < params.getSpendableCoinbaseDepth(); i++) {
chainHead = chainHead.createNextBlockWithCoinbase(coinbaseOutKeyPubKey);
chainHeadHeight++;
blocks.add(new BlockAndValidity(blockToHeightMap, chainHead, true, false, chainHead.getHash(), i+1, "Initial Block chain output generation"));
spendableOutputs.offer(new TransactionOutPointWithValue(
new TransactionOutPoint(params, 0, chainHead.getTransactions().get(0).getHash()),
valueOf(50, 0), chainHead.getTransactions().get(0).getOutputs().get(0).getScriptPubKey()));
FIFTY_COINS, chainHead.getTransactions().get(0).getOutputs().get(0).getScriptPubKey()));
}
// Start by building a couple of blocks on top of the genesis block.
@ -218,7 +218,7 @@ public class FullBlockTestGenerator {
// \-> b9 (4)
// \-> b3 (1) -> b4 (2)
//
Block b9 = createNextBlock(b6, chainHeadHeight + 5, out4, Coin.valueOf(1));
Block b9 = createNextBlock(b6, chainHeadHeight + 5, out4, SATOSHI);
blocks.add(new BlockAndValidity(blockToHeightMap, b9, false, true, b6.getHash(), chainHeadHeight + 4, "b9"));
// Create a fork that ends in a block with too much fee (the one that causes the reorg)
@ -229,7 +229,7 @@ public class FullBlockTestGenerator {
Block b10 = createNextBlock(b5, chainHeadHeight + 4, out3, null);
blocks.add(new BlockAndValidity(blockToHeightMap, b10, true, false, b6.getHash(), chainHeadHeight + 4, "b10"));
Block b11 = createNextBlock(b10, chainHeadHeight + 5, out4, Coin.valueOf(1));
Block b11 = createNextBlock(b10, chainHeadHeight + 5, out4, SATOSHI);
blocks.add(new BlockAndValidity(blockToHeightMap, b11, false, true, b6.getHash(), chainHeadHeight + 4, "b11"));
// Try again, but with a valid fork first
@ -255,7 +255,7 @@ public class FullBlockTestGenerator {
TransactionOutPointWithValue out5 = spendableOutputs.poll();
Block b14 = createNextBlock(b13, chainHeadHeight + 6, out5, Coin.valueOf(1));
Block b14 = createNextBlock(b13, chainHeadHeight + 6, out5, SATOSHI);
// This will be "validly" added, though its actually invalid, it will just be marked orphan
// and will be discarded when an attempt is made to reorg to it.
// TODO: Use a WeakReference to check that it is freed properly after the reorg
@ -279,10 +279,10 @@ public class FullBlockTestGenerator {
Transaction tx = new Transaction(params);
byte[] outputScript = new byte[Block.MAX_BLOCK_SIGOPS - sigOps];
Arrays.fill(outputScript, (byte) OP_CHECKSIG);
tx.addOutput(new TransactionOutput(params, tx, Coin.valueOf(1), outputScript));
tx.addOutput(new TransactionOutput(params, tx, SATOSHI, outputScript));
addOnlyInputToTransaction(tx, new TransactionOutPointWithValue(
new TransactionOutPoint(params, 1, b15.getTransactions().get(1).getHash()),
Coin.valueOf(1), b15.getTransactions().get(1).getOutputs().get(1).getScriptPubKey()));
SATOSHI, b15.getTransactions().get(1).getOutputs().get(1).getScriptPubKey()));
b15.addTransaction(tx);
}
b15.solve();
@ -304,10 +304,10 @@ public class FullBlockTestGenerator {
Transaction tx = new Transaction(params);
byte[] outputScript = new byte[Block.MAX_BLOCK_SIGOPS - sigOps + 1];
Arrays.fill(outputScript, (byte) OP_CHECKSIG);
tx.addOutput(new TransactionOutput(params, tx, Coin.valueOf(1), outputScript));
tx.addOutput(new TransactionOutput(params, tx, SATOSHI, outputScript));
addOnlyInputToTransaction(tx, new TransactionOutPointWithValue(
new TransactionOutPoint(params, 1, b16.getTransactions().get(1).getHash()),
Coin.valueOf(1), b16.getTransactions().get(1).getOutputs().get(1).getScriptPubKey()));
SATOSHI, b16.getTransactions().get(1).getOutputs().get(1).getScriptPubKey()));
b16.addTransaction(tx);
}
b16.solve();
@ -322,10 +322,10 @@ public class FullBlockTestGenerator {
Block b17 = createNextBlock(b15, chainHeadHeight + 7, out6, null);
{
Transaction tx = new Transaction(params);
tx.addOutput(new TransactionOutput(params, tx, Coin.valueOf(1), new byte[] {}));
tx.addOutput(new TransactionOutput(params, tx, SATOSHI, new byte[] {}));
addOnlyInputToTransaction(tx, new TransactionOutPointWithValue(
new TransactionOutPoint(params, 1, b3.getTransactions().get(1).getHash()),
Coin.valueOf(1), b3.getTransactions().get(1).getOutputs().get(1).getScriptPubKey()));
SATOSHI, b3.getTransactions().get(1).getOutputs().get(1).getScriptPubKey()));
b17.addTransaction(tx);
}
b17.solve();
@ -340,10 +340,10 @@ public class FullBlockTestGenerator {
Block b18 = createNextBlock(b13, chainHeadHeight + 6, out5, null);
{
Transaction tx = new Transaction(params);
tx.addOutput(new TransactionOutput(params, tx, Coin.valueOf(1), new byte[] {}));
tx.addOutput(new TransactionOutput(params, tx, SATOSHI, new byte[] {}));
addOnlyInputToTransaction(tx, new TransactionOutPointWithValue(
new TransactionOutPoint(params, 1, b3.getTransactions().get(1).getHash()),
Coin.valueOf(1), b3.getTransactions().get(1).getOutputs().get(1).getScriptPubKey()));
SATOSHI, b3.getTransactions().get(1).getOutputs().get(1).getScriptPubKey()));
b18.addTransaction(tx);
}
b18.solve();
@ -385,10 +385,10 @@ public class FullBlockTestGenerator {
// Signature size is non-deterministic, so it may take several runs before finding any off-by-one errors
byte[] outputScript = new byte[Block.MAX_BLOCK_SIZE - b23.getMessageSize() - 138];
Arrays.fill(outputScript, (byte) OP_FALSE);
tx.addOutput(new TransactionOutput(params, tx, Coin.valueOf(1), outputScript));
tx.addOutput(new TransactionOutput(params, tx, SATOSHI, outputScript));
addOnlyInputToTransaction(tx, new TransactionOutPointWithValue(
new TransactionOutPoint(params, 1, b23.getTransactions().get(1).getHash()),
Coin.valueOf(1), b23.getTransactions().get(1).getOutputs().get(1).getScriptPubKey()));
SATOSHI, b23.getTransactions().get(1).getOutputs().get(1).getScriptPubKey()));
b23.addTransaction(tx);
}
b23.solve();
@ -404,10 +404,10 @@ public class FullBlockTestGenerator {
// Signature size is non-deterministic, so it may take several runs before finding any off-by-one errors
byte[] outputScript = new byte[Block.MAX_BLOCK_SIZE - b24.getMessageSize() - 135];
Arrays.fill(outputScript, (byte) OP_FALSE);
tx.addOutput(new TransactionOutput(params, tx, Coin.valueOf(1), outputScript));
tx.addOutput(new TransactionOutput(params, tx, SATOSHI, outputScript));
addOnlyInputToTransaction(tx, new TransactionOutPointWithValue(
new TransactionOutPoint(params, 1, b24.getTransactions().get(1).getHash()),
Coin.valueOf(1), b24.getTransactions().get(1).getOutputs().get(1).getScriptPubKey()));
SATOSHI, b24.getTransactions().get(1).getOutputs().get(1).getScriptPubKey()));
b24.addTransaction(tx);
}
b24.solve();
@ -480,10 +480,10 @@ public class FullBlockTestGenerator {
Transaction tx = new Transaction(params);
byte[] outputScript = new byte[(Block.MAX_BLOCK_SIGOPS - sigOps)/20];
Arrays.fill(outputScript, (byte) OP_CHECKMULTISIG);
tx.addOutput(new TransactionOutput(params, tx, Coin.valueOf(1), outputScript));
tx.addOutput(new TransactionOutput(params, tx, SATOSHI, outputScript));
addOnlyInputToTransaction(tx, new TransactionOutPointWithValue(
new TransactionOutPoint(params, 1, b31.getTransactions().get(1).getHash()),
Coin.valueOf(1), b31.getTransactions().get(1).getOutputs().get(1).getScriptPubKey()));
SATOSHI, b31.getTransactions().get(1).getOutputs().get(1).getScriptPubKey()));
b31.addTransaction(tx);
}
b31.solve();
@ -507,10 +507,10 @@ public class FullBlockTestGenerator {
Arrays.fill(outputScript, (byte) OP_CHECKMULTISIG);
for (int i = 0; i < (Block.MAX_BLOCK_SIGOPS - sigOps)%20; i++)
outputScript[i] = (byte) OP_CHECKSIG;
tx.addOutput(new TransactionOutput(params, tx, Coin.valueOf(1), outputScript));
tx.addOutput(new TransactionOutput(params, tx, SATOSHI, outputScript));
addOnlyInputToTransaction(tx, new TransactionOutPointWithValue(
new TransactionOutPoint(params, 1, b32.getTransactions().get(1).getHash()),
Coin.valueOf(1), b32.getTransactions().get(1).getOutputs().get(1).getScriptPubKey()));
SATOSHI, b32.getTransactions().get(1).getOutputs().get(1).getScriptPubKey()));
b32.addTransaction(tx);
}
b32.solve();
@ -527,10 +527,10 @@ public class FullBlockTestGenerator {
Transaction tx = new Transaction(params);
byte[] outputScript = new byte[(Block.MAX_BLOCK_SIGOPS - sigOps)/20];
Arrays.fill(outputScript, (byte) OP_CHECKMULTISIGVERIFY);
tx.addOutput(new TransactionOutput(params, tx, Coin.valueOf(1), outputScript));
tx.addOutput(new TransactionOutput(params, tx, SATOSHI, outputScript));
addOnlyInputToTransaction(tx, new TransactionOutPointWithValue(
new TransactionOutPoint(params, 1, b33.getTransactions().get(1).getHash()),
Coin.valueOf(1), b33.getTransactions().get(1).getOutputs().get(1).getScriptPubKey()));
SATOSHI, b33.getTransactions().get(1).getOutputs().get(1).getScriptPubKey()));
b33.addTransaction(tx);
}
b33.solve();
@ -554,10 +554,10 @@ public class FullBlockTestGenerator {
Arrays.fill(outputScript, (byte) OP_CHECKMULTISIGVERIFY);
for (int i = 0; i < (Block.MAX_BLOCK_SIGOPS - sigOps)%20; i++)
outputScript[i] = (byte) OP_CHECKSIG;
tx.addOutput(new TransactionOutput(params, tx, Coin.valueOf(1), outputScript));
tx.addOutput(new TransactionOutput(params, tx, SATOSHI, outputScript));
addOnlyInputToTransaction(tx, new TransactionOutPointWithValue(
new TransactionOutPoint(params, 1, b34.getTransactions().get(1).getHash()),
Coin.valueOf(1), b34.getTransactions().get(1).getOutputs().get(1).getScriptPubKey()));
SATOSHI, b34.getTransactions().get(1).getOutputs().get(1).getScriptPubKey()));
b34.addTransaction(tx);
}
b34.solve();
@ -574,10 +574,10 @@ public class FullBlockTestGenerator {
Transaction tx = new Transaction(params);
byte[] outputScript = new byte[Block.MAX_BLOCK_SIGOPS - sigOps];
Arrays.fill(outputScript, (byte) OP_CHECKSIGVERIFY);
tx.addOutput(new TransactionOutput(params, tx, Coin.valueOf(1), outputScript));
tx.addOutput(new TransactionOutput(params, tx, SATOSHI, outputScript));
addOnlyInputToTransaction(tx, new TransactionOutPointWithValue(
new TransactionOutPoint(params, 1, b35.getTransactions().get(1).getHash()),
Coin.valueOf(1), b35.getTransactions().get(1).getOutputs().get(1).getScriptPubKey()));
SATOSHI, b35.getTransactions().get(1).getOutputs().get(1).getScriptPubKey()));
b35.addTransaction(tx);
}
b35.solve();
@ -599,10 +599,10 @@ public class FullBlockTestGenerator {
Transaction tx = new Transaction(params);
byte[] outputScript = new byte[Block.MAX_BLOCK_SIGOPS - sigOps + 1];
Arrays.fill(outputScript, (byte) OP_CHECKSIGVERIFY);
tx.addOutput(new TransactionOutput(params, tx, Coin.valueOf(1), outputScript));
tx.addOutput(new TransactionOutput(params, tx, SATOSHI, outputScript));
addOnlyInputToTransaction(tx, new TransactionOutPointWithValue(
new TransactionOutPoint(params, 1, b36.getTransactions().get(1).getHash()),
Coin.valueOf(1), b36.getTransactions().get(1).getOutputs().get(1).getScriptPubKey()));
SATOSHI, b36.getTransactions().get(1).getOutputs().get(1).getScriptPubKey()));
b36.addTransaction(tx);
}
b36.solve();
@ -619,7 +619,7 @@ public class FullBlockTestGenerator {
Block b37 = createNextBlock(b35, chainHeadHeight + 12, out11, null);
{
Transaction tx = new Transaction(params);
tx.addOutput(new TransactionOutput(params, tx, Coin.valueOf(1), new byte[] {}));
tx.addOutput(new TransactionOutput(params, tx, SATOSHI, new byte[] {}));
addOnlyInputToTransaction(tx, out11); // double spend out11
b37.addTransaction(tx);
}
@ -629,11 +629,11 @@ public class FullBlockTestGenerator {
Block b38 = createNextBlock(b35, chainHeadHeight + 12, out11, null);
{
Transaction tx = new Transaction(params);
tx.addOutput(new TransactionOutput(params, tx, Coin.valueOf(1), new byte[] {}));
tx.addOutput(new TransactionOutput(params, tx, SATOSHI, new byte[] {}));
// Attempt to spend b37's first non-coinbase tx, at which point b37 was still considered valid
addOnlyInputToTransaction(tx, new TransactionOutPointWithValue(
new TransactionOutPoint(params, 1, b37.getTransactions().get(1).getHash()),
Coin.valueOf(1), b37.getTransactions().get(1).getOutputs().get(1).getScriptPubKey()));
SATOSHI, b37.getTransactions().get(1).getOutputs().get(1).getScriptPubKey()));
b38.addTransaction(tx);
}
b38.solve();
@ -677,11 +677,11 @@ public class FullBlockTestGenerator {
}
scriptPubKey.write(OP_EQUAL);
Coin lastOutputValue = out11.value.subtract(Coin.valueOf(1));
Coin lastOutputValue = out11.value.subtract(SATOSHI);
TransactionOutPoint lastOutPoint;
{
Transaction tx = new Transaction(params);
tx.addOutput(new TransactionOutput(params, tx, Coin.valueOf(1), scriptPubKey.toByteArray()));
tx.addOutput(new TransactionOutput(params, tx, SATOSHI, scriptPubKey.toByteArray()));
tx.addOutput(new TransactionOutput(params, tx, lastOutputValue, new byte[]{OP_1}));
addOnlyInputToTransaction(tx, out11);
lastOutPoint = new TransactionOutPoint(params, 1, tx.getHash());
@ -693,8 +693,8 @@ public class FullBlockTestGenerator {
{
Transaction tx = new Transaction(params);
lastOutputValue = lastOutputValue.subtract(Coin.valueOf(1));
tx.addOutput(new TransactionOutput(params, tx, Coin.valueOf(1), scriptPubKey.toByteArray()));
lastOutputValue = lastOutputValue.subtract(SATOSHI);
tx.addOutput(new TransactionOutput(params, tx, SATOSHI, scriptPubKey.toByteArray()));
tx.addOutput(new TransactionOutput(params, tx, lastOutputValue, new byte[]{OP_1}));
tx.addInput(new TransactionInput(params, tx, new byte[]{OP_1}, lastOutPoint));
lastOutPoint = new TransactionOutPoint(params, 1, tx.getHash());
@ -730,7 +730,7 @@ public class FullBlockTestGenerator {
byte[] scriptSig = null;
for (int i = 1; i <= numTxes; i++) {
Transaction tx = new Transaction(params);
tx.addOutput(new TransactionOutput(params, tx, Coin.valueOf(1), new byte[] {OP_1}));
tx.addOutput(new TransactionOutput(params, tx, SATOSHI, new byte[] {OP_1}));
tx.addInput(new TransactionInput(params, tx, new byte[]{OP_1}, lastOutPoint));
TransactionInput input = new TransactionInput(params, tx, new byte[]{},
@ -771,7 +771,7 @@ public class FullBlockTestGenerator {
tx.addInput(new TransactionInput(params, tx, new byte[]{OP_1}, lastOutPoint));
byte[] scriptPubKey = new byte[Block.MAX_BLOCK_SIGOPS - sigOps + 1];
Arrays.fill(scriptPubKey, (byte) OP_CHECKSIG);
tx.addOutput(new TransactionOutput(params, tx, Coin.ZERO, scriptPubKey));
tx.addOutput(new TransactionOutput(params, tx, ZERO, scriptPubKey));
b40.addTransaction(tx);
}
b40.solve();
@ -797,7 +797,7 @@ public class FullBlockTestGenerator {
for (int i = 1; i <= numTxes; i++) {
Transaction tx = new Transaction(params);
tx.addOutput(new TransactionOutput(params, tx, Coin
.valueOf(1), new byte[] {OP_1}));
.SATOSHI, new byte[] {OP_1}));
tx.addInput(new TransactionInput(params, tx,
new byte[] {OP_1}, lastOutPoint));
@ -848,7 +848,7 @@ public class FullBlockTestGenerator {
new byte[] {OP_1}, lastOutPoint));
byte[] scriptPubKey = new byte[Block.MAX_BLOCK_SIGOPS - sigOps];
Arrays.fill(scriptPubKey, (byte) OP_CHECKSIG);
tx.addOutput(new TransactionOutput(params, tx, Coin.ZERO, scriptPubKey));
tx.addOutput(new TransactionOutput(params, tx, ZERO, scriptPubKey));
b41.addTransaction(tx);
}
b41.solve();
@ -886,14 +886,14 @@ public class FullBlockTestGenerator {
byte[] outScriptBytes = ScriptBuilder.createOutputScript(ECKey.fromPublicOnly(coinbaseOutKeyPubKey)).getProgram();
{
b44.setDifficultyTarget(b43.getDifficultyTarget());
b44.addCoinbaseTransaction(coinbaseOutKeyPubKey, Coin.ZERO);
b44.addCoinbaseTransaction(coinbaseOutKeyPubKey, ZERO);
Transaction t = new Transaction(params);
// Entirely invalid scriptPubKey to ensure we aren't pre-verifying too much
t.addOutput(new TransactionOutput(params, t, Coin.valueOf(0), new byte[] {OP_PUSHDATA1 - 1 }));
t.addOutput(new TransactionOutput(params, t, Coin.valueOf(1), outScriptBytes));
t.addOutput(new TransactionOutput(params, t, ZERO, new byte[] {OP_PUSHDATA1 - 1 }));
t.addOutput(new TransactionOutput(params, t, SATOSHI, outScriptBytes));
// Spendable output
t.addOutput(new TransactionOutput(params, t, Coin.ZERO, new byte[] {OP_1}));
t.addOutput(new TransactionOutput(params, t, ZERO, new byte[] {OP_1}));
addOnlyInputToTransaction(t, out14);
b44.addTransaction(t);
@ -913,10 +913,10 @@ public class FullBlockTestGenerator {
Transaction t = new Transaction(params);
// Entirely invalid scriptPubKey to ensure we aren't pre-verifying too much
t.addOutput(new TransactionOutput(params, t, Coin.valueOf(0), new byte[] {OP_PUSHDATA1 - 1 }));
t.addOutput(new TransactionOutput(params, t, Coin.valueOf(1), outScriptBytes));
t.addOutput(new TransactionOutput(params, t, ZERO, new byte[] {OP_PUSHDATA1 - 1 }));
t.addOutput(new TransactionOutput(params, t, SATOSHI, outScriptBytes));
// Spendable output
t.addOutput(new TransactionOutput(params, t, Coin.ZERO, new byte[] {OP_1}));
t.addOutput(new TransactionOutput(params, t, ZERO, new byte[] {OP_1}));
addOnlyInputToTransaction(t, out15);
try {
b45.addTransaction(t);
@ -990,7 +990,7 @@ public class FullBlockTestGenerator {
{
Transaction coinbase = new Transaction(params);
coinbase.addInput(new TransactionInput(params, coinbase, new byte[]{(byte) 0xff, 110, 1}));
coinbase.addOutput(new TransactionOutput(params, coinbase, Coin.ONE, outScriptBytes));
coinbase.addOutput(new TransactionOutput(params, coinbase, SATOSHI, outScriptBytes));
b51.addTransaction(coinbase, false);
}
b51.solve();
@ -1000,10 +1000,10 @@ public class FullBlockTestGenerator {
Block b52 = createNextBlock(b44, chainHeadHeight + 16, out15, null);
{
Transaction tx = new Transaction(params);
tx.addOutput(new TransactionOutput(params, tx, Coin.valueOf(1), new byte[] {}));
tx.addOutput(new TransactionOutput(params, tx, SATOSHI, new byte[] {}));
addOnlyInputToTransaction(tx, new TransactionOutPointWithValue(
new TransactionOutPoint(params, 1, b52.getTransactions().get(1).getHash()),
Coin.valueOf(1), b52.getTransactions().get(1).getOutputs().get(1).getScriptPubKey()));
SATOSHI, b52.getTransactions().get(1).getOutputs().get(1).getScriptPubKey()));
b52.addTransaction(tx);
b52.addTransaction(tx);
}
@ -1048,10 +1048,10 @@ public class FullBlockTestGenerator {
Transaction b56txToDuplicate;
{
b56txToDuplicate = new Transaction(params);
b56txToDuplicate.addOutput(new TransactionOutput(params, b56txToDuplicate, Coin.valueOf(1), new byte[] {}));
b56txToDuplicate.addOutput(new TransactionOutput(params, b56txToDuplicate, SATOSHI, new byte[] {}));
addOnlyInputToTransaction(b56txToDuplicate, new TransactionOutPointWithValue(
new TransactionOutPoint(params, 1, b57.getTransactions().get(1).getHash()),
Coin.valueOf(1), b57.getTransactions().get(1).getOutputs().get(1).getScriptPubKey()));
SATOSHI, b57.getTransactions().get(1).getOutputs().get(1).getScriptPubKey()));
b57.addTransaction(b56txToDuplicate);
}
b57.solve();
@ -1082,7 +1082,7 @@ public class FullBlockTestGenerator {
Block b58 = createNextBlock(b57, chainHeadHeight + 18, out17, null);
{
Transaction tx = new Transaction(params);
tx.addOutput(new TransactionOutput(params, tx, Coin.ZERO, new byte[] {}));
tx.addOutput(new TransactionOutput(params, tx, ZERO, new byte[] {}));
tx.addInput(new TransactionInput(params, tx, new byte[] {OP_1},
new TransactionOutPoint(params, 3, b58.getTransactions().get(1).getHash())));
b58.addTransaction(tx);
@ -1095,7 +1095,7 @@ public class FullBlockTestGenerator {
{
Transaction tx = new Transaction(params);
tx.addOutput(new TransactionOutput(params, tx,
b59.getTransactions().get(1).getOutputs().get(2).getValue().add(Coin.ONE), new byte[] {}));
b59.getTransactions().get(1).getOutputs().get(2).getValue().add(SATOSHI), new byte[] {}));
tx.addInput(new TransactionInput(params, tx, new byte[] {OP_1},
new TransactionOutPoint(params, 2, b59.getTransactions().get(1).getHash())));
b59.addTransaction(tx);
@ -1133,7 +1133,7 @@ public class FullBlockTestGenerator {
{
Transaction tx = new Transaction(params);
tx.setLockTime(0xffffffffL);
tx.addOutput(new TransactionOutput(params, tx, Coin.ZERO, new byte[] {OP_TRUE}));
tx.addOutput(new TransactionOutput(params, tx, ZERO, new byte[] {OP_TRUE}));
addOnlyInputToTransaction(tx, out18, 0);
b62.addTransaction(tx);
Preconditions.checkState(!tx.isFinal(chainHeadHeight + 17, b62.getTimeSeconds()));
@ -1165,10 +1165,10 @@ public class FullBlockTestGenerator {
// Signature size is non-deterministic, so it may take several runs before finding any off-by-one errors
byte[] outputScript = new byte[Block.MAX_BLOCK_SIZE - b64Created.getMessageSize() - 138];
Arrays.fill(outputScript, (byte) OP_FALSE);
tx.addOutput(new TransactionOutput(params, tx, Coin.valueOf(1), outputScript));
tx.addOutput(new TransactionOutput(params, tx, SATOSHI, outputScript));
addOnlyInputToTransaction(tx, new TransactionOutPointWithValue(
new TransactionOutPoint(params, 1, b64Created.getTransactions().get(1).getHash()),
Coin.valueOf(1), b64Created.getTransactions().get(1).getOutputs().get(1).getScriptPubKey()));
SATOSHI, b64Created.getTransactions().get(1).getOutputs().get(1).getScriptPubKey()));
b64Created.addTransaction(tx);
b64Created.solve();
@ -1211,7 +1211,7 @@ public class FullBlockTestGenerator {
addOnlyInputToTransaction(tx1, out19, 0);
b65.addTransaction(tx1);
Transaction tx2 = new Transaction(params);
tx2.addOutput(new TransactionOutput(params, tx2, Coin.ZERO, new byte[]{OP_TRUE}));
tx2.addOutput(new TransactionOutput(params, tx2, ZERO, new byte[]{OP_TRUE}));
tx2.addInput(new TransactionInput(params, tx2, new byte[]{OP_TRUE},
new TransactionOutPoint(params, 0, tx1.getHash())));
b65.addTransaction(tx2);
@ -1235,7 +1235,7 @@ public class FullBlockTestGenerator {
tx1.addOutput(new TransactionOutput(params, tx1, out20.value, new byte[]{OP_TRUE}));
addOnlyInputToTransaction(tx1, out20, 0);
Transaction tx2 = new Transaction(params);
tx2.addOutput(new TransactionOutput(params, tx2, Coin.ZERO, new byte[]{OP_TRUE}));
tx2.addOutput(new TransactionOutput(params, tx2, ZERO, new byte[]{OP_TRUE}));
tx2.addInput(new TransactionInput(params, tx2, new byte[]{OP_TRUE},
new TransactionOutPoint(params, 0, tx1.getHash())));
b66.addTransaction(tx2);
@ -1255,7 +1255,7 @@ public class FullBlockTestGenerator {
addOnlyInputToTransaction(tx1, out20, 0);
b67.addTransaction(tx1);
Transaction tx2 = new Transaction(params);
tx2.addOutput(new TransactionOutput(params, tx2, Coin.ZERO, new byte[]{OP_TRUE}));
tx2.addOutput(new TransactionOutput(params, tx2, ZERO, new byte[]{OP_TRUE}));
tx2.addInput(new TransactionInput(params, tx2, new byte[]{OP_TRUE},
new TransactionOutPoint(params, 0, tx1.getHash())));
b67.addTransaction(tx2);
@ -1272,20 +1272,20 @@ public class FullBlockTestGenerator {
// -> b43 (13) -> b53 (14) -> b55 (15) -> b57 (16) -> b60 (17) -> b64 (18) -> b65 (19) -> b69 (20)
// \-> b68 (20)
//
Block b68 = createNextBlock(b65, chainHeadHeight + 21, null, Coin.TEN);
Block b68 = createNextBlock(b65, chainHeadHeight + 21, null, SATOSHI.multiply(10));
{
Transaction tx = new Transaction(params);
tx.addOutput(new TransactionOutput(params, tx, out20.value.subtract(Coin.valueOf(9)), new byte[]{OP_TRUE}));
tx.addOutput(new TransactionOutput(params, tx, out20.value.subtract(valueOf(9)), new byte[]{OP_TRUE}));
addOnlyInputToTransaction(tx, out20, 0);
b68.addTransaction(tx);
}
b68.solve();
blocks.add(new BlockAndValidity(blockToHeightMap, b68, false, true, b65.getHash(), chainHeadHeight + 20, "b68"));
Block b69 = createNextBlock(b65, chainHeadHeight + 21, null, Coin.TEN);
Block b69 = createNextBlock(b65, chainHeadHeight + 21, null, SATOSHI.multiply(10));
{
Transaction tx = new Transaction(params);
tx.addOutput(new TransactionOutput(params, tx, out20.value.subtract(Coin.TEN), new byte[]{OP_TRUE}));
tx.addOutput(new TransactionOutput(params, tx, out20.value.subtract(SATOSHI.multiply(10)), new byte[]{OP_TRUE}));
addOnlyInputToTransaction(tx, out20, 0);
b69.addTransaction(tx);
}
@ -1305,7 +1305,7 @@ public class FullBlockTestGenerator {
Block b70 = createNextBlock(b69, chainHeadHeight + 22, out21, null);
{
Transaction tx = new Transaction(params);
tx.addOutput(new TransactionOutput(params, tx, Coin.ZERO, new byte[]{OP_TRUE}));
tx.addOutput(new TransactionOutput(params, tx, ZERO, new byte[]{OP_TRUE}));
tx.addInput(new TransactionInput(params, tx, new byte[]{OP_TRUE},
new TransactionOutPoint(params, 0, new Sha256Hash("23c70ed7c0506e9178fc1a987f40a33946d4ad4c962b5ae3a52546da53af0c5c"))));
b70.addTransaction(tx);
@ -1320,10 +1320,10 @@ public class FullBlockTestGenerator {
Block b72 = createNextBlock(b69, chainHeadHeight + 22, out21, null);
{
Transaction tx = new Transaction(params);
tx.addOutput(new TransactionOutput(params, tx, Coin.ZERO, new byte[]{OP_TRUE}));
tx.addOutput(new TransactionOutput(params, tx, ZERO, new byte[]{OP_TRUE}));
addOnlyInputToTransaction(tx, new TransactionOutPointWithValue(
new TransactionOutPoint(params, 1, b72.getTransactions().get(1).getHash()),
Coin.valueOf(1), b72.getTransactions().get(1).getOutputs().get(1).getScriptPubKey()));
SATOSHI, b72.getTransactions().get(1).getOutputs().get(1).getScriptPubKey()));
b72.addTransaction(tx);
}
b72.solve();
@ -1357,10 +1357,10 @@ public class FullBlockTestGenerator {
// If we push an element that is too large, the CHECKSIGs after that push are still counted
outputScript[Block.MAX_BLOCK_SIGOPS - sigOps] = OP_PUSHDATA4;
Utils.uint32ToByteArrayLE(Script.MAX_SCRIPT_ELEMENT_SIZE + 1, outputScript, Block.MAX_BLOCK_SIGOPS - sigOps + 1);
tx.addOutput(new TransactionOutput(params, tx, Coin.valueOf(1), outputScript));
tx.addOutput(new TransactionOutput(params, tx, SATOSHI, outputScript));
addOnlyInputToTransaction(tx, new TransactionOutPointWithValue(
new TransactionOutPoint(params, 1, b73.getTransactions().get(1).getHash()),
Coin.valueOf(1), b73.getTransactions().get(1).getOutputs().get(1).getScriptPubKey()));
SATOSHI, b73.getTransactions().get(1).getOutputs().get(1).getScriptPubKey()));
b73.addTransaction(tx);
}
b73.solve();
@ -1381,10 +1381,10 @@ public class FullBlockTestGenerator {
outputScript[Block.MAX_BLOCK_SIGOPS - sigOps + 3] = (byte)0xff;
outputScript[Block.MAX_BLOCK_SIGOPS - sigOps + 4] = (byte)0xff;
outputScript[Block.MAX_BLOCK_SIGOPS - sigOps + 5] = (byte)0xff;
tx.addOutput(new TransactionOutput(params, tx, Coin.valueOf(1), outputScript));
tx.addOutput(new TransactionOutput(params, tx, SATOSHI, outputScript));
addOnlyInputToTransaction(tx, new TransactionOutPointWithValue(
new TransactionOutPoint(params, 1, b74.getTransactions().get(1).getHash()),
Coin.valueOf(1), b74.getTransactions().get(1).getOutputs().get(1).getScriptPubKey()));
SATOSHI, b74.getTransactions().get(1).getOutputs().get(1).getScriptPubKey()));
b74.addTransaction(tx);
}
b74.solve();
@ -1405,10 +1405,10 @@ public class FullBlockTestGenerator {
outputScript[Block.MAX_BLOCK_SIGOPS - sigOps + 2] = (byte)0xff;
outputScript[Block.MAX_BLOCK_SIGOPS - sigOps + 3] = (byte)0xff;
outputScript[Block.MAX_BLOCK_SIGOPS - sigOps + 4] = (byte)0xff;
tx.addOutput(new TransactionOutput(params, tx, Coin.valueOf(1), outputScript));
tx.addOutput(new TransactionOutput(params, tx, SATOSHI, outputScript));
addOnlyInputToTransaction(tx, new TransactionOutPointWithValue(
new TransactionOutPoint(params, 1, b75.getTransactions().get(1).getHash()),
Coin.valueOf(1), b75.getTransactions().get(1).getOutputs().get(1).getScriptPubKey()));
SATOSHI, b75.getTransactions().get(1).getOutputs().get(1).getScriptPubKey()));
b75.addTransaction(tx);
}
b75.solve();
@ -1432,10 +1432,10 @@ public class FullBlockTestGenerator {
// If we push an element that is filled with CHECKSIGs, they (obviously) arent counted
outputScript[Block.MAX_BLOCK_SIGOPS - sigOps] = OP_PUSHDATA4;
Utils.uint32ToByteArrayLE(Block.MAX_BLOCK_SIGOPS, outputScript, Block.MAX_BLOCK_SIGOPS - sigOps + 1);
tx.addOutput(new TransactionOutput(params, tx, Coin.valueOf(1), outputScript));
tx.addOutput(new TransactionOutput(params, tx, SATOSHI, outputScript));
addOnlyInputToTransaction(tx, new TransactionOutPointWithValue(
new TransactionOutPoint(params, 1, b76.getTransactions().get(1).getHash()),
Coin.valueOf(1), b76.getTransactions().get(1).getOutputs().get(1).getScriptPubKey()));
SATOSHI, b76.getTransactions().get(1).getOutputs().get(1).getScriptPubKey()));
b76.addTransaction(tx);
}
b76.solve();
@ -1461,10 +1461,10 @@ public class FullBlockTestGenerator {
Block b78 = createNextBlock(b77, chainHeadHeight + 26, out25, null);
Transaction b78tx = new Transaction(params);
{
b78tx.addOutput(new TransactionOutput(params, b78tx, Coin.ZERO, new byte[]{OP_TRUE}));
b78tx.addOutput(new TransactionOutput(params, b78tx, ZERO, new byte[]{OP_TRUE}));
addOnlyInputToTransaction(b78tx, new TransactionOutPointWithValue(
new TransactionOutPoint(params, 1, b77.getTransactions().get(1).getHash()),
Coin.valueOf(1), b77.getTransactions().get(1).getOutputs().get(1).getScriptPubKey()));
SATOSHI, b77.getTransactions().get(1).getOutputs().get(1).getScriptPubKey()));
b78.addTransaction(b78tx);
}
b78.solve();
@ -1473,7 +1473,7 @@ public class FullBlockTestGenerator {
Block b79 = createNextBlock(b78, chainHeadHeight + 27, out26, null);
Transaction b79tx = new Transaction(params);
{
b79tx.addOutput(new TransactionOutput(params, b79tx, Coin.ZERO, new byte[]{OP_TRUE}));
b79tx.addOutput(new TransactionOutput(params, b79tx, ZERO, new byte[]{OP_TRUE}));
b79tx.addInput(new TransactionInput(params, b79tx, new byte[]{OP_TRUE}, new TransactionOutPoint(params, 0, b78tx.getHash())));
b79.addTransaction(b79tx);
}
@ -1542,8 +1542,8 @@ public class FullBlockTestGenerator {
while (block.getMessageSize() < Block.MAX_BLOCK_SIZE - 500) {
Transaction tx = new Transaction(params);
tx.addInput(new TransactionInput(params, tx, new byte[] { OP_TRUE }, lastOutput));
tx.addOutput(new TransactionOutput(params, tx, Coin.ZERO, new byte[] { OP_TRUE }));
tx.addOutput(new TransactionOutput(params, tx, Coin.ZERO, new byte[] { OP_TRUE }));
tx.addOutput(new TransactionOutput(params, tx, ZERO, new byte[] { OP_TRUE }));
tx.addOutput(new TransactionOutput(params, tx, ZERO, new byte[] { OP_TRUE }));
lastOutput = new TransactionOutPoint(params, 1, tx.getHash());
hashesToSpend.add(tx.getHash());
block.addTransaction(tx);
@ -1561,7 +1561,7 @@ public class FullBlockTestGenerator {
Transaction tx = new Transaction(params);
tx.addInput(new TransactionInput(params, tx, new byte[] { OP_TRUE },
new TransactionOutPoint(params, 0, hashes.next())));
tx.addOutput(new TransactionOutput(params, tx, Coin.ZERO, new byte[] { OP_TRUE }));
tx.addOutput(new TransactionOutput(params, tx, ZERO, new byte[] { OP_TRUE }));
block.addTransaction(tx);
}
block.solve();
@ -1587,7 +1587,7 @@ public class FullBlockTestGenerator {
Transaction tx = new Transaction(params);
tx.addInput(new TransactionInput(params, tx, new byte[] {OP_TRUE},
new TransactionOutPoint(params, 0, hashesToSpend.get(0))));
tx.addOutput(new TransactionOutput(params, tx, Coin.ZERO, new byte[] { OP_TRUE }));
tx.addOutput(new TransactionOutput(params, tx, ZERO, new byte[] { OP_TRUE }));
b1002.addTransaction(tx);
}
b1002.solve();
@ -1603,7 +1603,7 @@ public class FullBlockTestGenerator {
Transaction tx = new Transaction(params);
tx.addInput(new TransactionInput(params, tx, new byte[] {OP_TRUE},
new TransactionOutPoint(params, 0, hashesToSpend.get(0))));
tx.addOutput(new TransactionOutput(params, tx, Coin.ZERO, new byte[] { OP_TRUE }));
tx.addOutput(new TransactionOutput(params, tx, ZERO, new byte[] { OP_TRUE }));
b1004.addTransaction(tx);
}
b1004.solve();
@ -1625,18 +1625,18 @@ public class FullBlockTestGenerator {
Integer height = blockToHeightMap.get(baseBlock.getHash());
if (height != null)
Preconditions.checkState(height == nextBlockHeight - 1);
Coin coinbaseValue = valueOf(50, 0).shiftRight(nextBlockHeight / params.getSubsidyDecreaseBlockCount())
.add((prevOut != null ? prevOut.value.subtract(Coin.ONE) : Coin.ZERO))
.add(additionalCoinbaseValue == null ? Coin.ZERO : additionalCoinbaseValue);
Coin coinbaseValue = FIFTY_COINS.shiftRight(nextBlockHeight / params.getSubsidyDecreaseBlockCount())
.add((prevOut != null ? prevOut.value.subtract(SATOSHI) : ZERO))
.add(additionalCoinbaseValue == null ? ZERO : additionalCoinbaseValue);
Block block = baseBlock.createNextBlockWithCoinbase(coinbaseOutKeyPubKey, coinbaseValue);
if (prevOut != null) {
Transaction t = new Transaction(params);
// Entirely invalid scriptPubKey to ensure we aren't pre-verifying too much
t.addOutput(new TransactionOutput(params, t, Coin.valueOf(0), new byte[] {OP_PUSHDATA1 - 1 }));
t.addOutput(new TransactionOutput(params, t, Coin.valueOf(1),
t.addOutput(new TransactionOutput(params, t, ZERO, new byte[] {OP_PUSHDATA1 - 1 }));
t.addOutput(new TransactionOutput(params, t, SATOSHI,
ScriptBuilder.createOutputScript(ECKey.fromPublicOnly(coinbaseOutKeyPubKey)).getProgram()));
// Spendable output
t.addOutput(new TransactionOutput(params, t, Coin.ZERO, new byte[] {OP_1, uniquenessCounter++}));
t.addOutput(new TransactionOutput(params, t, ZERO, new byte[] {OP_1, uniquenessCounter++}));
addOnlyInputToTransaction(t, prevOut);
block.addTransaction(t);
block.solve();

View file

@ -28,7 +28,7 @@ import java.io.ByteArrayOutputStream;
import java.nio.ByteBuffer;
import java.util.Arrays;
import static com.google.bitcoin.core.Coin.valueOf;
import static com.google.bitcoin.core.Coin.*;
import static com.google.bitcoin.testing.FakeTxBuilder.createFakeBlock;
import static com.google.bitcoin.testing.FakeTxBuilder.createFakeTx;
import static org.junit.Assert.*;
@ -92,12 +92,12 @@ public class LazyParseByteCacheTest {
//add a second input so can test granularity of byte cache.
Transaction prevTx = new Transaction(unitTestParams);
TransactionOutput prevOut = new TransactionOutput(unitTestParams, prevTx, valueOf(1, 0), wallet.currentReceiveKey().toAddress(unitTestParams));
TransactionOutput prevOut = new TransactionOutput(unitTestParams, prevTx, COIN, wallet.currentReceiveKey().toAddress(unitTestParams));
prevTx.addOutput(prevOut);
// Connect it.
tx1.addInput(prevOut);
Transaction tx2 = createFakeTx(unitTestParams, valueOf(1, 0),
Transaction tx2 = createFakeTx(unitTestParams, COIN,
new ECKey().toAddress(unitTestParams));
Block b1 = createFakeBlock(blockStore, tx1, tx2).block;

View file

@ -24,7 +24,7 @@ import org.junit.Test;
import java.net.InetAddress;
import static com.google.bitcoin.core.Coin.valueOf;
import static com.google.bitcoin.core.Coin.COIN;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@ -36,7 +36,7 @@ public class MemoryPoolTest {
@Before
public void setup() throws Exception {
BriefLogFormatter.init();
tx1 = FakeTxBuilder.createFakeTx(params, valueOf(1, 0), new ECKey().toAddress(params));
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 }));

View file

@ -179,7 +179,7 @@ public class PeerGroupTest extends TestWithPeerGroup {
expectedPeers.add(peerOf(p2));
assertEquals(tmp, expectedPeers);
Coin value = valueOf(1, 0);
Coin value = COIN;
Transaction t1 = FakeTxBuilder.createFakeTx(unitTestParams, value, address);
InventoryMessage inv = new InventoryMessage(unitTestParams);
inv.addTransaction(t1);

View file

@ -47,7 +47,7 @@ import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import static com.google.bitcoin.core.Coin.valueOf;
import static com.google.bitcoin.core.Coin.*;
import static com.google.bitcoin.testing.FakeTxBuilder.*;
import static org.junit.Assert.*;
@ -245,7 +245,7 @@ public class PeerTest extends TestWithNetworkConnections {
peer.setDownloadData(true);
// Make a transaction and tell the peer we have it.
Coin value = valueOf(1, 0);
Coin value = COIN;
Transaction tx = createFakeTx(unitTestParams, value, address);
InventoryMessage inv = new InventoryMessage(unitTestParams);
InventoryItem item = new InventoryItem(InventoryItem.Type.Transaction, tx.getHash());
@ -278,7 +278,7 @@ public class PeerTest extends TestWithNetworkConnections {
InboundMessageQueuer writeTarget2 = connect(peer2, peerVersion);
// Make a tx and advertise it to one of the peers.
Coin value = valueOf(1, 0);
Coin value = COIN;
Transaction tx = createFakeTx(unitTestParams, value, this.address);
InventoryMessage inv = new InventoryMessage(unitTestParams);
InventoryItem item = new InventoryItem(InventoryItem.Type.Transaction, tx.getHash());
@ -543,14 +543,14 @@ public class PeerTest extends TestWithNetworkConnections {
// -> [t7]
// -> [t8]
// The ones in brackets are assumed to be in the chain and are represented only by hashes.
Transaction t2 = FakeTxBuilder.createFakeTx(unitTestParams, valueOf(1, 0), to);
Transaction t2 = FakeTxBuilder.createFakeTx(unitTestParams, COIN, to);
Sha256Hash t5 = t2.getInput(0).getOutpoint().getHash();
Transaction t4 = FakeTxBuilder.createFakeTx(unitTestParams, valueOf(1, 0), new ECKey());
Transaction t4 = FakeTxBuilder.createFakeTx(unitTestParams, COIN, new ECKey());
Sha256Hash t6 = t4.getInput(0).getOutpoint().getHash();
t4.addOutput(valueOf(1, 0), new ECKey());
t4.addOutput(COIN, new ECKey());
Transaction t3 = new Transaction(unitTestParams);
t3.addInput(t4.getOutput(0));
t3.addOutput(valueOf(1, 0), new ECKey());
t3.addOutput(COIN, new ECKey());
Transaction t1 = new Transaction(unitTestParams);
t1.addInput(t2.getOutput(0));
t1.addInput(t3.getOutput(0));
@ -558,7 +558,7 @@ public class PeerTest extends TestWithNetworkConnections {
t1.addInput(new TransactionInput(unitTestParams, t1, new byte[]{}, new TransactionOutPoint(unitTestParams, 0, someHash)));
Sha256Hash anotherHash = new Sha256Hash("3b801dd82f01d17bbde881687bf72bc62e2faa8ab8133d36fcb8c3abe7459da6");
t1.addInput(new TransactionInput(unitTestParams, t1, new byte[]{}, new TransactionOutPoint(unitTestParams, 1, anotherHash)));
t1.addOutput(valueOf(1, 0), to);
t1.addOutput(COIN, to);
t1 = FakeTxBuilder.roundTripTransaction(unitTestParams, t1);
t2 = FakeTxBuilder.roundTripTransaction(unitTestParams, t2);
t3 = FakeTxBuilder.roundTripTransaction(unitTestParams, t3);
@ -664,7 +664,7 @@ public class PeerTest extends TestWithNetworkConnections {
}
});
// Send a normal relevant transaction, it's received correctly.
Transaction t1 = FakeTxBuilder.createFakeTx(unitTestParams, valueOf(1, 0), key);
Transaction t1 = FakeTxBuilder.createFakeTx(unitTestParams, COIN, key);
inbound(writeTarget, t1);
GetDataMessage getdata = (GetDataMessage) outbound(writeTarget);
if (useNotFound) {
@ -743,10 +743,10 @@ public class PeerTest extends TestWithNetworkConnections {
Sha256Hash t3 = Sha256Hash.create("abc".getBytes(Charset.forName("UTF-8")));
t2.addInput(new TransactionInput(unitTestParams, t2, new byte[]{}, new TransactionOutPoint(unitTestParams, 0, t3)));
t2.getInput(0).setSequenceNumber(0xDEADBEEF);
t2.addOutput(valueOf(1, 0), new ECKey());
t2.addOutput(COIN, new ECKey());
Transaction t1 = new Transaction(unitTestParams);
t1.addInput(t2.getOutput(0));
t1.addOutput(valueOf(1, 0), key); // Make it relevant.
t1.addOutput(COIN, key); // Make it relevant.
// Announce t1.
InventoryMessage inv = new InventoryMessage(unitTestParams);
inv.addTransaction(t1);
@ -840,10 +840,10 @@ public class PeerTest extends TestWithNetworkConnections {
connect();
Transaction t1 = new Transaction(unitTestParams);
t1.addInput(new TransactionInput(unitTestParams, t1, new byte[]{}));
t1.addOutput(valueOf(1, 0), new ECKey().toAddress(unitTestParams));
t1.addOutput(COIN, new ECKey().toAddress(unitTestParams));
Transaction t2 = new Transaction(unitTestParams);
t2.addInput(t1.getOutput(0));
t2.addOutput(valueOf(1, 0), wallet.getChangeAddress());
t2.addOutput(COIN, wallet.getChangeAddress());
inbound(writeTarget, t2);
final InventoryItem inventoryItem = new InventoryItem(InventoryItem.Type.Transaction, t2.getInput(0).getOutpoint().getHash());
final NotFoundMessage nfm = new NotFoundMessage(unitTestParams, Lists.newArrayList(inventoryItem));

View file

@ -33,7 +33,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Random;
import static com.google.bitcoin.core.Coin.valueOf;
import static com.google.bitcoin.core.Coin.*;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.junit.Assert.*;
@ -108,11 +108,11 @@ public class TransactionBroadcastTest extends TestWithPeerGroup {
Block b1 = FakeTxBuilder.makeSolvedTestBlock(blockStore, address);
inbound(p1, b1);
assertNull(outbound(p1));
assertEquals(valueOf(50, 0), wallet.getBalance());
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, valueOf(1, 0));
Wallet.SendResult sendResult = wallet.sendCoins(peerGroup, dest, COIN);
assertFalse(sendResult.broadcastComplete.isDone());
Transaction t1;
{
@ -148,7 +148,7 @@ public class TransactionBroadcastTest extends TestWithPeerGroup {
inbound(p1, b1);
pingAndWait(p1);
assertNull(outbound(p1));
assertEquals(valueOf(50, 0), wallet.getBalance());
assertEquals(FIFTY_COINS, wallet.getBalance());
// Check that the wallet informs us of changes in confidence as the transaction ripples across the network.
final Transaction[] transactions = new Transaction[1];
@ -161,7 +161,7 @@ public class TransactionBroadcastTest extends TestWithPeerGroup {
// Now create a spend, and expect the announcement on p1.
Address dest = new ECKey().toAddress(params);
Wallet.SendResult sendResult = wallet.sendCoins(peerGroup, dest, valueOf(1, 0));
Wallet.SendResult sendResult = wallet.sendCoins(peerGroup, dest, COIN);
assertNotNull(sendResult.tx);
Threading.waitForUserCode();
assertFalse(sendResult.broadcastComplete.isDone());

View file

@ -31,6 +31,7 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.protobuf.ByteString;
import org.bitcoinj.wallet.Protos;
import org.bitcoinj.wallet.Protos.Wallet.EncryptionType;
import org.junit.After;
@ -154,7 +155,7 @@ public class WalletTest extends TestWithWallet {
Coin v2 = valueOf(0, 50);
SendRequest req = SendRequest.to(destination, v2);
req.fee = valueOf(0, 1);
req.fee = CENT;
wallet.completeTx(req);
Transaction t2 = req.tx;
@ -205,7 +206,7 @@ public class WalletTest extends TestWithWallet {
// Force selection of the incoming coin so that we can spend it
req.coinSelector = new TestCoinSelector();
req.fee = valueOf(0, 1);
req.fee = CENT;
wallet.completeTx(req);
wallet.commitTx(req.tx);
@ -223,7 +224,7 @@ public class WalletTest extends TestWithWallet {
assertEquals("Wrong number of PENDING.5", 3, wallet.getPoolSize(WalletTransaction.Pool.PENDING));
assertEquals("Wrong number of UNSPENT.5", 0, wallet.getPoolSize(WalletTransaction.Pool.UNSPENT));
assertEquals("Wrong number of ALL.5", 4, wallet.getTransactions(true).size());
assertEquals(valueOf(0, 0), wallet.getBalance(Wallet.BalanceType.ESTIMATED));
assertEquals(ZERO, wallet.getBalance(Wallet.BalanceType.ESTIMATED));
}
private void basicSpendingCommon(Wallet wallet, Address toAddress, Address destination, boolean testEncryption) throws Exception {
@ -247,7 +248,7 @@ public class WalletTest extends TestWithWallet {
// Prepare to send.
Coin v2 = valueOf(0, 50);
req = Wallet.SendRequest.to(destination, v2);
req.fee = valueOf(0, 1);
req.fee = CENT;
if (testEncryption) {
// Try to create a send with a fee but no password (this should fail).
@ -263,7 +264,7 @@ public class WalletTest extends TestWithWallet {
// Try to create a send with a fee but the wrong password (this should fail).
req = Wallet.SendRequest.to(destination, v2);
req.aesKey = wrongAesKey;
req.fee = valueOf(0, 1);
req.fee = CENT;
req.ensureMinRequiredFee = false;
try {
@ -279,7 +280,7 @@ public class WalletTest extends TestWithWallet {
// Create a send with a fee with the correct password (this should succeed).
req = Wallet.SendRequest.to(destination, v2);
req.aesKey = aesKey;
req.fee = valueOf(0, 1);
req.fee = CENT;
req.ensureMinRequiredFee = false;
}
@ -306,7 +307,7 @@ public class WalletTest extends TestWithWallet {
}
private void receiveATransaction(Wallet wallet, Address toAddress) throws Exception {
Coin v1 = valueOf(1, 0);
Coin v1 = COIN;
final ListenableFuture<Coin> availFuture = wallet.getBalanceFuture(v1, Wallet.BalanceType.AVAILABLE);
final ListenableFuture<Coin> estimatedFuture = wallet.getBalanceFuture(v1, Wallet.BalanceType.ESTIMATED);
assertFalse(availFuture.isDone());
@ -431,7 +432,7 @@ public class WalletTest extends TestWithWallet {
public void sideChain() throws Exception {
// The wallet receives a coin on the main chain, then on a side chain. Balance is equal to both added together
// as we assume the side chain tx is pending and will be included shortly.
Coin v1 = valueOf(1, 0);
Coin v1 = COIN;
sendMoneyToWallet(v1, AbstractBlockChain.NewBlockType.BEST_CHAIN);
assertEquals(v1, wallet.getBalance());
assertEquals(1, wallet.getPoolSize(WalletTransaction.Pool.UNSPENT));
@ -458,7 +459,7 @@ public class WalletTest extends TestWithWallet {
assertEquals(expected, wallet.getBalance());
// Now spend one coin.
Coin v3 = valueOf(1, 0);
Coin v3 = COIN;
Transaction spend = wallet.createSend(new ECKey().toAddress(params), v3);
wallet.commitTx(spend);
assertEquals(1, wallet.getPoolSize(WalletTransaction.Pool.PENDING));
@ -514,7 +515,7 @@ public class WalletTest extends TestWithWallet {
});
// Receive some money.
Coin oneCoin = valueOf(1, 0);
Coin oneCoin = COIN;
Transaction tx1 = sendMoneyToWallet(oneCoin, AbstractBlockChain.NewBlockType.BEST_CHAIN);
Threading.waitForUserCode();
assertEquals(null, txn[1]); // onCoinsSent not called.
@ -555,7 +556,7 @@ public class WalletTest extends TestWithWallet {
@Test
public void balances() throws Exception {
Coin nanos = valueOf(1, 0);
Coin nanos = COIN;
Transaction tx1 = sendMoneyToWallet(nanos, AbstractBlockChain.NewBlockType.BEST_CHAIN);
assertEquals(nanos, tx1.getValueSentToMe(wallet, true));
// Send 0.10 to somebody else.
@ -570,7 +571,7 @@ public class WalletTest extends TestWithWallet {
public void isConsistent_duplicates() throws Exception {
// This test ensures that isConsistent catches duplicate transactions, eg, because we submitted the same block
// twice (this is not allowed).
Transaction tx = createFakeTx(params, valueOf(1, 0), myAddress);
Transaction tx = createFakeTx(params, COIN, myAddress);
Address someOtherGuy = new ECKey().toAddress(params);
TransactionOutput output = new TransactionOutput(params, tx, valueOf(0, 5), someOtherGuy);
tx.addOutput(output);
@ -590,7 +591,7 @@ public class WalletTest extends TestWithWallet {
@Test
public void isConsistent_pools() throws Exception {
// This test ensures that isConsistent catches transactions that are in incompatible pools.
Transaction tx = createFakeTx(params, valueOf(1, 0), myAddress);
Transaction tx = createFakeTx(params, COIN, myAddress);
Address someOtherGuy = new ECKey().toAddress(params);
TransactionOutput output = new TransactionOutput(params, tx, valueOf(0, 5), someOtherGuy);
tx.addOutput(output);
@ -606,7 +607,7 @@ public class WalletTest extends TestWithWallet {
public void isConsistent_spent() throws Exception {
// This test ensures that isConsistent catches transactions that are marked spent when
// they aren't.
Transaction tx = createFakeTx(params, valueOf(1, 0), myAddress);
Transaction tx = createFakeTx(params, COIN, myAddress);
Address someOtherGuy = new ECKey().toAddress(params);
TransactionOutput output = new TransactionOutput(params, tx, valueOf(0, 5), someOtherGuy);
tx.addOutput(output);
@ -619,7 +620,7 @@ public class WalletTest extends TestWithWallet {
@Test
public void transactions() throws Exception {
// This test covers a bug in which Transaction.getValueSentFromMe was calculating incorrectly.
Transaction tx = createFakeTx(params, valueOf(1, 0), myAddress);
Transaction tx = createFakeTx(params, COIN, myAddress);
// Now add another output (ie, change) that goes to some other address.
Address someOtherGuy = new ECKey().toAddress(params);
TransactionOutput output = new TransactionOutput(params, tx, valueOf(0, 5), someOtherGuy);
@ -633,14 +634,14 @@ public class WalletTest extends TestWithWallet {
tx2.addInput(output);
tx2.addOutput(new TransactionOutput(params, tx2, valueOf(0, 5), myAddress));
// tx2 doesn't send any coins from us, even though the output is in the wallet.
assertEquals(valueOf(0, 0), tx2.getValueSentFromMe(wallet));
assertEquals(ZERO, tx2.getValueSentFromMe(wallet));
}
@Test
public void bounce() throws Exception {
// This test covers bug 64 (False double spends). Check that if we create a spend and it's immediately sent
// back to us, this isn't considered as a double spend.
Coin coin1 = valueOf(1, 0);
Coin coin1 = COIN;
sendMoneyToWallet(coin1, AbstractBlockChain.NewBlockType.BEST_CHAIN);
// Send half to some other guy. Sending only half then waiting for a confirm is important to ensure the tx is
// in the unspent pool, not pending or spent.
@ -666,12 +667,12 @@ public class WalletTest extends TestWithWallet {
// frees up the other outputs and makes them spendable again.
// Receive 1 coin and then 2 coins in separate transactions.
sendMoneyToWallet(valueOf(1, 0), AbstractBlockChain.NewBlockType.BEST_CHAIN);
sendMoneyToWallet(COIN, AbstractBlockChain.NewBlockType.BEST_CHAIN);
sendMoneyToWallet(valueOf(2, 0), AbstractBlockChain.NewBlockType.BEST_CHAIN);
// Create a send to a merchant of all our coins.
Transaction send1 = wallet.createSend(new ECKey().toAddress(params), valueOf(2, 90));
// Create a double spend of just the first one.
Transaction send2 = wallet.createSend(new ECKey().toAddress(params), valueOf(1, 0));
Transaction send2 = wallet.createSend(new ECKey().toAddress(params), COIN);
send2 = new Transaction(params, send2.bitcoinSerialize());
// Broadcast send1, it's now pending.
wallet.commitTx(send1);
@ -691,7 +692,7 @@ public class WalletTest extends TestWithWallet {
// This can (and has!) happened when a wallet is cloned between devices, and both devices decide to make the
// same spend simultaneously - for example due a re-keying operation. It can also happen if there are malicious
// nodes in the P2P network that are mutating transactions on the fly as occurred during Feb 2014.
final Coin value = valueOf(1, 0);
final Coin value = COIN;
final Coin value2 = valueOf(2, 0);
// Give us three coins and make sure we have some change.
sendMoneyToWallet(value.add(value2), AbstractBlockChain.NewBlockType.BEST_CHAIN);
@ -758,7 +759,7 @@ public class WalletTest extends TestWithWallet {
});
// Receive 1 BTC.
Coin nanos = valueOf(1, 0);
Coin nanos = COIN;
sendMoneyToWallet(nanos, AbstractBlockChain.NewBlockType.BEST_CHAIN);
Transaction received = wallet.getTransactions(false).iterator().next();
// Create a send to a merchant.
@ -794,7 +795,7 @@ public class WalletTest extends TestWithWallet {
@Test
public void pending1() throws Exception {
// Check that if we receive a pending transaction that is then confirmed, we are notified as appropriate.
final Coin nanos = valueOf(1, 0);
final Coin nanos = COIN;
final Transaction t1 = createFakeTx(params, nanos, myAddress);
// First one is "called" second is "pending".
@ -877,7 +878,7 @@ public class WalletTest extends TestWithWallet {
}
});
// Receive some coins.
Coin nanos = valueOf(1, 0);
Coin nanos = COIN;
sendMoneyToWallet(nanos, AbstractBlockChain.NewBlockType.BEST_CHAIN);
// Create a spend with them, but don't commit it (ie it's from somewhere else but using our keys). This TX
// will have change as we don't spend our entire balance.
@ -900,7 +901,7 @@ public class WalletTest extends TestWithWallet {
// Check that if we receive a pending tx, and it's overridden by a double spend from the main chain, we
// are notified that it's dead. This should work even if the pending tx inputs are NOT ours, ie, they don't
// connect to anything.
Coin nanos = valueOf(1, 0);
Coin nanos = COIN;
// Create two transactions that share the same input tx.
Address badGuy = new ECKey().toAddress(params);
@ -952,7 +953,7 @@ public class WalletTest extends TestWithWallet {
public void transactionsList() throws Exception {
// Check the wallet can give us an ordered list of all received transactions.
Utils.setMockClock();
Transaction tx1 = sendMoneyToWallet(valueOf(1, 0), AbstractBlockChain.NewBlockType.BEST_CHAIN);
Transaction tx1 = sendMoneyToWallet(COIN, AbstractBlockChain.NewBlockType.BEST_CHAIN);
Utils.rollMockClock(60 * 10);
Transaction tx2 = sendMoneyToWallet(valueOf(0, 5), AbstractBlockChain.NewBlockType.BEST_CHAIN);
// Check we got them back in order.
@ -1021,7 +1022,7 @@ public class WalletTest extends TestWithWallet {
// Test that a spend to the same wallet is dealt with correctly.
// It should appear in the wallet and confirm.
// This is a bit of a silly thing to do in the real world as all it does is burn a fee but it is perfectly valid.
Coin coin1 = valueOf(1, 0);
Coin coin1 = COIN;
Coin coinHalf = valueOf(0, 50);
// Start by giving us 1 coin.
sendMoneyToWallet(coin1, AbstractBlockChain.NewBlockType.BEST_CHAIN);
@ -1273,7 +1274,7 @@ public class WalletTest extends TestWithWallet {
@Test
public void spendOutputFromPendingTransaction() throws Exception {
// We'll set up a wallet that receives a coin, then sends a coin of lesser value and keeps the change.
Coin v1 = valueOf(1, 0);
Coin v1 = COIN;
sendMoneyToWallet(v1, AbstractBlockChain.NewBlockType.BEST_CHAIN);
// First create our current transaction
ECKey k2 = wallet.freshReceiveKey();
@ -1314,13 +1315,13 @@ public class WalletTest extends TestWithWallet {
// Check that if a pending transaction spends outputs of chain-included transactions, we mark them as spent.
// See bug 345. This can happen if there is a pending transaction floating around and then you replay the
// chain without emptying the memory pool (or refilling it from a peer).
Coin value = valueOf(1, 0);
Coin value = COIN;
Transaction tx1 = createFakeTx(params, value, myAddress);
Transaction tx2 = new Transaction(params);
tx2.addInput(tx1.getOutput(0));
tx2.addOutput(valueOf(0, 9), new ECKey());
// Add a change address to ensure this tx is relevant.
tx2.addOutput(valueOf(0, 1), wallet.getChangeAddress());
tx2.addOutput(CENT, wallet.getChangeAddress());
wallet.receivePending(tx2, null);
BlockPair bp = createFakeBlock(blockStore, tx1);
wallet.receiveFromBlock(tx1, bp.storedBlock, AbstractBlockChain.NewBlockType.BEST_CHAIN, 0);
@ -1443,11 +1444,11 @@ public class WalletTest extends TestWithWallet {
final int ITERATIONS = 10;
Transaction[] txns = new Transaction[ITERATIONS];
for (int i = 0; i < ITERATIONS; i++) {
txns[i] = sendMoneyToWallet(valueOf(1, 0), AbstractBlockChain.NewBlockType.BEST_CHAIN);
txns[i] = sendMoneyToWallet(COIN, AbstractBlockChain.NewBlockType.BEST_CHAIN);
}
// Check that we spend transactions in order of reception.
for (int i = 0; i < ITERATIONS; i++) {
Transaction spend = wallet.createSend(new ECKey().toAddress(params), valueOf(1, 0));
Transaction spend = wallet.createSend(new ECKey().toAddress(params), COIN);
assertEquals(spend.getInputs().size(), 1);
assertEquals("Failed on iteration " + i, spend.getInput(0).getOutpoint().getHash(), txns[i].getHash());
wallet.commitTx(spend);
@ -1461,7 +1462,7 @@ public class WalletTest extends TestWithWallet {
Transaction tx = new Transaction(params);
byte[] bits = new byte[20];
new Random().nextBytes(bits);
Coin v = valueOf(0, 1);
Coin v = CENT;
// 3100 outputs to a random address.
for (int i = 0; i < 3100; i++) {
tx.addOutput(v, new Address(params, bits));
@ -1481,23 +1482,23 @@ public class WalletTest extends TestWithWallet {
// Generate a few outputs to us that are far too small to spend reasonably
StoredBlock block = new StoredBlock(makeSolvedTestBlock(blockStore, notMyAddr), BigInteger.ONE, 1);
Transaction tx1 = createFakeTx(params, ONE, myAddress);
Transaction tx1 = createFakeTx(params, SATOSHI, myAddress);
wallet.receiveFromBlock(tx1, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, 0);
Transaction tx2 = createFakeTx(params, ONE, myAddress);
Transaction tx2 = createFakeTx(params, SATOSHI, myAddress);
assertTrue(!tx1.getHash().equals(tx2.getHash()));
wallet.receiveFromBlock(tx2, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, 1);
Transaction tx3 = createFakeTx(params, Coin.TEN, myAddress);
Transaction tx3 = createFakeTx(params, SATOSHI.multiply(10), myAddress);
wallet.receiveFromBlock(tx3, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, 2);
// Not allowed to send dust.
try {
wallet.createSend(notMyAddr, ONE);
wallet.createSend(notMyAddr, SATOSHI);
fail();
} catch (Wallet.DustySendRequested e) {
// Expected.
}
// Spend it all without fee enforcement
SendRequest req = SendRequest.to(notMyAddr, Coin.TEN.add(ONE.add(ONE)));
SendRequest req = SendRequest.to(notMyAddr, SATOSHI.multiply(12));
req.ensureMinRequiredFee = false;
assertNotNull(wallet.sendCoinsOffline(req));
assertEquals(ZERO, wallet.getBalance());
@ -1508,7 +1509,7 @@ public class WalletTest extends TestWithWallet {
wallet.receiveFromBlock(tx4, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, 0);
// Simple test to make sure if we have an ouput < 0.01 we get a fee
Transaction spend1 = wallet.createSend(notMyAddr, CENT.subtract(ONE));
Transaction spend1 = wallet.createSend(notMyAddr, CENT.subtract(SATOSHI));
assertEquals(2, spend1.getOutputs().size());
// We optimize for priority, so the output selected should be the largest one.
// We should have paid the default minfee.
@ -1522,19 +1523,19 @@ public class WalletTest extends TestWithWallet {
assertEquals(Coin.COIN, spend2.getOutput(0).getValue().add(spend2.getOutput(1).getValue()));
// ...but not more fee than what we request
SendRequest request3 = SendRequest.to(notMyAddr, CENT.subtract(ONE));
request3.fee = Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.add(ONE);
SendRequest request3 = SendRequest.to(notMyAddr, CENT.subtract(SATOSHI));
request3.fee = Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.add(SATOSHI);
wallet.completeTx(request3);
assertEquals(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.add(ONE), request3.fee);
assertEquals(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.add(SATOSHI), request3.fee);
Transaction spend3 = request3.tx;
assertEquals(2, spend3.getOutputs().size());
// We optimize for priority, so the output selected should be the largest one.
assertEquals(spend3.getOutput(0).getValue().add(spend3.getOutput(1).getValue()),
Coin.COIN.subtract(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.add(ONE)));
Coin.COIN.subtract(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.add(SATOSHI)));
// ...unless we need it
SendRequest request4 = SendRequest.to(notMyAddr, CENT.subtract(ONE));
request4.fee = Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.subtract(ONE);
SendRequest request4 = SendRequest.to(notMyAddr, CENT.subtract(SATOSHI));
request4.fee = Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.subtract(SATOSHI);
wallet.completeTx(request4);
assertEquals(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE, request4.fee);
Transaction spend4 = request4.tx;
@ -1543,7 +1544,7 @@ public class WalletTest extends TestWithWallet {
assertEquals(spend4.getOutput(0).getValue().add(spend4.getOutput(1).getValue()),
Coin.COIN.subtract(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE));
SendRequest request5 = SendRequest.to(notMyAddr, Coin.COIN.subtract(CENT.subtract(ONE)));
SendRequest request5 = SendRequest.to(notMyAddr, Coin.COIN.subtract(CENT.subtract(SATOSHI)));
wallet.completeTx(request5);
assertEquals(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE, request5.fee);
Transaction spend5 = request5.tx;
@ -1562,8 +1563,8 @@ public class WalletTest extends TestWithWallet {
// We optimize for priority, so the output selected should be the largest one
assertEquals(Coin.COIN, spend6.getOutput(0).getValue().add(spend6.getOutput(1).getValue()));
SendRequest request7 = SendRequest.to(notMyAddr, Coin.COIN.subtract(CENT.subtract(Coin.valueOf(2)).multiply(2)));
request7.tx.addOutput(CENT.subtract(ONE), notMyAddr);
SendRequest request7 = SendRequest.to(notMyAddr, Coin.COIN.subtract(CENT.subtract(SATOSHI.multiply(2)).multiply(2)));
request7.tx.addOutput(CENT.subtract(SATOSHI), notMyAddr);
wallet.completeTx(request7);
assertEquals(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE, request7.fee);
Transaction spend7 = request7.tx;
@ -1594,7 +1595,7 @@ public class WalletTest extends TestWithWallet {
COIN.subtract(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.add(Transaction.MIN_NONDUST_OUTPUT)));
SendRequest request10 = SendRequest.to(notMyAddr, COIN.subtract(
Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.add(Transaction.MIN_NONDUST_OUTPUT).add(ONE)));
Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.add(Transaction.MIN_NONDUST_OUTPUT).add(SATOSHI)));
wallet.completeTx(request10);
assertEquals(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE, request10.fee);
Transaction spend10 = request10.tx;
@ -1605,16 +1606,16 @@ public class WalletTest extends TestWithWallet {
COIN.subtract(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE));
SendRequest request11 = SendRequest.to(notMyAddr, COIN.subtract(
Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.add(Transaction.MIN_NONDUST_OUTPUT).add(Coin.valueOf(2))));
request11.fee = Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.add(ONE);
Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.add(Transaction.MIN_NONDUST_OUTPUT).add(SATOSHI.multiply(2))));
request11.fee = Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.add(SATOSHI);
wallet.completeTx(request11);
assertEquals(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.add(ONE), request11.fee);
assertEquals(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.add(SATOSHI), request11.fee);
Transaction spend11 = request11.tx;
// ...of course fee should be min(request.fee, MIN_TX_FEE) so we should get MIN_TX_FEE.add(ONE) here
// ...of course fee should be min(request.fee, MIN_TX_FEE) so we should get MIN_TX_FEE.add(SATOSHI) here
assertEquals(2, spend11.getOutputs().size());
// We optimize for priority, so the output selected should be the largest one.
assertEquals(spend11.getOutput(0).getValue().add(spend11.getOutput(1).getValue()),
COIN.subtract(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.add(ONE)));
COIN.subtract(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.add(SATOSHI)));
// Remove the coin from our wallet
wallet.commitTx(spend11);
@ -1658,9 +1659,9 @@ public class WalletTest extends TestWithWallet {
for (int i = 0; i < 29; i++)
request15.tx.addOutput(CENT, notMyAddr);
assertTrue(request15.tx.bitcoinSerialize().length > 1000);
request15.feePerKb = ONE;
request15.feePerKb = SATOSHI;
wallet.completeTx(request15);
assertEquals(Coin.valueOf(2), request15.fee);
assertEquals(SATOSHI.multiply(2), request15.fee);
Transaction spend15 = request15.tx;
// If a transaction is over 1kb, 2 satoshis should be added.
assertEquals(31, spend15.getOutputs().size());
@ -1668,7 +1669,7 @@ public class WalletTest extends TestWithWallet {
Coin outValue15 = ZERO;
for (TransactionOutput out : spend15.getOutputs())
outValue15 = outValue15.add(out.getValue());
assertEquals(COIN.subtract(Coin.valueOf(2)), outValue15);
assertEquals(COIN.subtract(SATOSHI.multiply(2)), outValue15);
SendRequest request16 = SendRequest.to(notMyAddr, CENT);
request16.feePerKb = ZERO;
@ -1691,9 +1692,9 @@ public class WalletTest extends TestWithWallet {
for (int i = 0; i < 22; i++)
request17.tx.addOutput(CENT, notMyAddr);
request17.tx.addOutput(new TransactionOutput(params, request17.tx, CENT, new byte[15]));
request17.feePerKb = ONE;
request17.feePerKb = SATOSHI;
wallet.completeTx(request17);
assertEquals(ONE, request17.fee);
assertEquals(SATOSHI, request17.fee);
assertEquals(1, request17.tx.getInputs().size());
// Calculate its max length to make sure it is indeed 999
int theoreticalMaxLength17 = request17.tx.bitcoinSerialize().length + myKey.getPubKey().length + 75;
@ -1712,16 +1713,16 @@ public class WalletTest extends TestWithWallet {
Coin outValue17 = ZERO;
for (TransactionOutput out : spend17.getOutputs())
outValue17 = outValue17.add(out.getValue());
assertEquals(COIN.subtract(ONE), outValue17);
assertEquals(COIN.subtract(SATOSHI), outValue17);
// Create a transaction who's max size could be up to 1001 (if signatures were maximum size)
SendRequest request18 = SendRequest.to(notMyAddr, CENT);
for (int i = 0; i < 22; i++)
request18.tx.addOutput(CENT, notMyAddr);
request18.tx.addOutput(new TransactionOutput(params, request18.tx, CENT, new byte[17]));
request18.feePerKb = ONE;
request18.feePerKb = SATOSHI;
wallet.completeTx(request18);
assertEquals(Coin.valueOf(2), request18.fee);
assertEquals(SATOSHI.multiply(2), request18.fee);
assertEquals(1, request18.tx.getInputs().size());
// Calculate its max length to make sure it is indeed 1001
Transaction spend18 = request18.tx;
@ -1738,7 +1739,7 @@ public class WalletTest extends TestWithWallet {
Coin outValue18 = ZERO;
for (TransactionOutput out : spend18.getOutputs())
outValue18 = outValue18.add(out.getValue());
assertEquals(outValue18, COIN.subtract(Coin.valueOf(2)));
assertEquals(outValue18, COIN.subtract(SATOSHI.multiply(2)));
// Now create a transaction that will spend COIN + fee, which makes it require both inputs
assertEquals(wallet.getBalance(), CENT.add(COIN));
@ -1754,7 +1755,7 @@ public class WalletTest extends TestWithWallet {
// Now reset request19 and give it a fee per kb
request19.tx.clearInputs();
request19 = SendRequest.forTx(request19.tx);
request19.feePerKb = ONE;
request19.feePerKb = SATOSHI;
request19.shuffleOutputs = false;
wallet.completeTx(request19);
assertEquals(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE, request19.fee);
@ -1824,15 +1825,15 @@ public class WalletTest extends TestWithWallet {
request25.ensureMinRequiredFee = false;
request25.shuffleOutputs = false;
wallet.completeTx(request25);
assertEquals(CENT.subtract(ONE), request25.fee);
assertEquals(CENT.subtract(SATOSHI), request25.fee);
assertEquals(2, request25.tx.getInputs().size());
Coin outValue25 = ZERO;
for (TransactionOutput out : request25.tx.getOutputs())
outValue25 = outValue25.add(out.getValue());
// Our change output should be one satoshi
assertEquals(ONE, request25.tx.getOutput(request25.tx.getOutputs().size() - 1).getValue());
assertEquals(SATOSHI, request25.tx.getOutput(request25.tx.getOutputs().size() - 1).getValue());
// and our fee should be CENT-1 satoshi
assertEquals(outValue25, COIN.add(ONE));
assertEquals(outValue25, COIN.add(SATOSHI));
// Spend our CENT output.
Transaction spendTx5 = new Transaction(params);
@ -1849,7 +1850,7 @@ public class WalletTest extends TestWithWallet {
request26.tx.addOutput(CENT.subtract(
Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.add(Transaction.MIN_NONDUST_OUTPUT)), notMyAddr);
assertTrue(request26.tx.bitcoinSerialize().length > 1000);
request26.feePerKb = ONE;
request26.feePerKb = SATOSHI;
wallet.completeTx(request26);
assertEquals(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.add(Transaction.MIN_NONDUST_OUTPUT), request26.fee);
Transaction spend26 = request26.tx;
@ -1882,9 +1883,9 @@ public class WalletTest extends TestWithWallet {
}
// Create a spend that will throw away change (category 3 type 2 in which the change causes fee which is worth more than change)
SendRequest request1 = SendRequest.to(notMyAddr, CENT.add(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE).subtract(ONE));
SendRequest request1 = SendRequest.to(notMyAddr, CENT.add(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE).subtract(SATOSHI));
wallet.completeTx(request1);
assertEquals(ONE, request1.fee);
assertEquals(SATOSHI, request1.fee);
assertEquals(request1.tx.getInputs().size(), i); // We should have spent all inputs
// Give us one more input...
@ -1893,9 +1894,9 @@ public class WalletTest extends TestWithWallet {
wallet.receiveFromBlock(tx1, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, i);
// ... and create a spend that will throw away change (category 3 type 1 in which the change causes dust output)
SendRequest request2 = SendRequest.to(notMyAddr, CENT.add(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE).subtract(ONE));
SendRequest request2 = SendRequest.to(notMyAddr, CENT.add(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE).subtract(SATOSHI));
wallet.completeTx(request2);
assertEquals(ONE, request2.fee);
assertEquals(SATOSHI, request2.fee);
assertEquals(request2.tx.getInputs().size(), i - 1); // We should have spent all inputs - 1
// Give us one more input...
@ -1905,16 +1906,16 @@ public class WalletTest extends TestWithWallet {
// ... and create a spend that will throw away change (category 3 type 1 in which the change causes dust output)
// but that also could have been category 2 if it wanted
SendRequest request3 = SendRequest.to(notMyAddr, CENT.add(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE).subtract(ONE));
SendRequest request3 = SendRequest.to(notMyAddr, CENT.add(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE).subtract(SATOSHI));
wallet.completeTx(request3);
assertEquals(ONE, request3.fee);
assertEquals(SATOSHI, request3.fee);
assertEquals(request3.tx.getInputs().size(), i - 2); // We should have spent all inputs - 2
//
SendRequest request4 = SendRequest.to(notMyAddr, CENT.add(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE).subtract(ONE));
SendRequest request4 = SendRequest.to(notMyAddr, CENT.add(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE).subtract(SATOSHI));
request4.feePerKb = Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.divide(request3.tx.bitcoinSerialize().length);
wallet.completeTx(request4);
assertEquals(ONE, request4.fee);
assertEquals(SATOSHI, request4.fee);
assertEquals(request4.tx.getInputs().size(), i - 2); // We should have spent all inputs - 2
// Give us a few more inputs...
@ -1925,9 +1926,9 @@ public class WalletTest extends TestWithWallet {
}
// ...that is just slightly less than is needed for category 1
SendRequest request5 = SendRequest.to(notMyAddr, CENT.add(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE).subtract(ONE));
SendRequest request5 = SendRequest.to(notMyAddr, CENT.add(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE).subtract(SATOSHI));
wallet.completeTx(request5);
assertEquals(ONE, request5.fee);
assertEquals(SATOSHI, request5.fee);
assertEquals(1, request5.tx.getOutputs().size()); // We should have no change output
// Give us one more input...
@ -1936,7 +1937,7 @@ public class WalletTest extends TestWithWallet {
wallet.receiveFromBlock(tx4, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, i);
// ... that puts us in category 1 (no fee!)
SendRequest request6 = SendRequest.to(notMyAddr, CENT.add(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE).subtract(ONE));
SendRequest request6 = SendRequest.to(notMyAddr, CENT.add(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE).subtract(SATOSHI));
wallet.completeTx(request6);
assertEquals(ZERO, request6.fee);
assertEquals(2, request6.tx.getOutputs().size()); // We should have a change output
@ -1963,7 +1964,7 @@ public class WalletTest extends TestWithWallet {
}
// The selector will choose 2 with MIN_TX_FEE fee
SendRequest request1 = SendRequest.to(notMyAddr, CENT.add(ONE));
SendRequest request1 = SendRequest.to(notMyAddr, CENT.add(SATOSHI));
wallet.completeTx(request1);
assertEquals(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE, request1.fee);
assertEquals(request1.tx.getInputs().size(), i); // We should have spent all inputs
@ -2002,7 +2003,7 @@ public class WalletTest extends TestWithWallet {
wallet.receiveFromBlock(tx, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, 0);
Transaction tx2 = createFakeTx(params, CENT, myAddress);
wallet.receiveFromBlock(tx2, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, 1);
Transaction tx3 = createFakeTx(params, ONE, myAddress);
Transaction tx3 = createFakeTx(params, SATOSHI, myAddress);
wallet.receiveFromBlock(tx3, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, 2);
// Create a transaction who's max size could be up to 1000 (if signatures were maximum size)
@ -2010,8 +2011,8 @@ public class WalletTest extends TestWithWallet {
for (int i = 0; i < 16; i++)
request1.tx.addOutput(CENT, notMyAddr);
request1.tx.addOutput(new TransactionOutput(params, request1.tx, CENT, new byte[16]));
request1.fee = ONE;
request1.feePerKb = ONE;
request1.fee = SATOSHI;
request1.feePerKb = SATOSHI;
// We get a category 2 using COIN+CENT
// It spends COIN + 1(fee) and because its output is thus < CENT, we have to pay MIN_TX_FEE
// When it tries category 1, its too large and requires COIN + 2 (fee)
@ -2021,7 +2022,7 @@ public class WalletTest extends TestWithWallet {
assertEquals(2, request1.tx.getInputs().size());
// We then add one more satoshi output to the wallet
Transaction tx4 = createFakeTx(params, ONE, myAddress);
Transaction tx4 = createFakeTx(params, SATOSHI, myAddress);
wallet.receiveFromBlock(tx4, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, 3);
// Create a transaction who's max size could be up to 1000 (if signatures were maximum size)
@ -2029,10 +2030,10 @@ public class WalletTest extends TestWithWallet {
for (int i = 0; i < 16; i++)
request2.tx.addOutput(CENT, notMyAddr);
request2.tx.addOutput(new TransactionOutput(params, request2.tx, CENT, new byte[16]));
request2.feePerKb = ONE;
request2.feePerKb = SATOSHI;
// The process is the same as above, but now we can complete category 1 with one more input, and pay a fee of 2
wallet.completeTx(request2);
assertEquals(Coin.valueOf(2), request2.fee);
assertEquals(SATOSHI.multiply(2), request2.fee);
assertEquals(4, request2.tx.getInputs().size());
}
@ -2121,7 +2122,7 @@ public class WalletTest extends TestWithWallet {
}
});
sendMoneyToWallet(valueOf(1, 0), AbstractBlockChain.NewBlockType.BEST_CHAIN);
sendMoneyToWallet(COIN, AbstractBlockChain.NewBlockType.BEST_CHAIN);
log.info("Wait for user thread");
Threading.waitForUserCode();
log.info("... and test flag.");
@ -2171,17 +2172,17 @@ public class WalletTest extends TestWithWallet {
// Add just under 0.01
StoredBlock block2 = new StoredBlock(block.getHeader().createNextBlock(outputKey), BigInteger.ONE, 2);
tx = createFakeTx(params, CENT.subtract(ONE), myAddress);
tx = createFakeTx(params, CENT.subtract(SATOSHI), myAddress);
wallet.receiveFromBlock(tx, block2, AbstractBlockChain.NewBlockType.BEST_CHAIN, 0);
request = SendRequest.emptyWallet(outputKey);
wallet.completeTx(request);
wallet.commitTx(request.tx);
assertEquals(ZERO, wallet.getBalance());
assertEquals(CENT.subtract(ONE).subtract(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE), request.tx.getOutput(0).getValue());
assertEquals(CENT.subtract(SATOSHI).subtract(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE), request.tx.getOutput(0).getValue());
// Add an unsendable value
StoredBlock block3 = new StoredBlock(block2.getHeader().createNextBlock(outputKey), BigInteger.ONE, 3);
Coin outputValue = Transaction.MIN_NONDUST_OUTPUT.add(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE).subtract(ONE);
Coin outputValue = Transaction.MIN_NONDUST_OUTPUT.add(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE).subtract(SATOSHI);
tx = createFakeTx(params, outputValue, myAddress);
wallet.receiveFromBlock(tx, block3, AbstractBlockChain.NewBlockType.BEST_CHAIN, 0);
request = SendRequest.emptyWallet(outputKey);

View file

@ -463,7 +463,7 @@ public class ChannelConnectionTest extends TestWithWallet {
assertEquals(CloseReason.NO_ACCEPTABLE_VERSION, pair.clientRecorder.q.take());
// Double-check that we cant do anything that requires an open channel
try {
client.incrementPayment(Coin.ONE);
client.incrementPayment(Coin.SATOSHI);
fail();
} catch (IllegalStateException e) { }
}
@ -489,7 +489,7 @@ public class ChannelConnectionTest extends TestWithWallet {
assertEquals(CloseReason.TIME_WINDOW_TOO_LARGE, pair.clientRecorder.q.take());
// Double-check that we cant do anything that requires an open channel
try {
client.incrementPayment(Coin.ONE);
client.incrementPayment(Coin.SATOSHI);
fail();
} catch (IllegalStateException e) { }
}
@ -505,7 +505,7 @@ public class ChannelConnectionTest extends TestWithWallet {
client.receiveMessage(pair.serverRecorder.checkNextMsg(MessageType.SERVER_VERSION));
client.receiveMessage(Protos.TwoWayChannelMessage.newBuilder()
.setInitiate(Protos.Initiate.newBuilder().setExpireTimeSecs(Utils.currentTimeSeconds())
.setMinAcceptedChannelSize(COIN.add(ONE).longValue())
.setMinAcceptedChannelSize(COIN.add(SATOSHI).longValue())
.setMultisigKey(ByteString.copyFrom(new ECKey().getPubKey()))
.setMinPayment(Transaction.MIN_NONDUST_OUTPUT.longValue()))
.setType(MessageType.INITIATE).build());
@ -513,7 +513,7 @@ public class ChannelConnectionTest extends TestWithWallet {
assertEquals(CloseReason.SERVER_REQUESTED_TOO_MUCH_VALUE, pair.clientRecorder.q.take());
// Double-check that we cant do anything that requires an open channel
try {
client.incrementPayment(Coin.ONE);
client.incrementPayment(Coin.SATOSHI);
fail();
} catch (IllegalStateException e) { }
@ -531,7 +531,7 @@ public class ChannelConnectionTest extends TestWithWallet {
client.receiveMessage(pair.serverRecorder.checkNextMsg(MessageType.SERVER_VERSION));
client.receiveMessage(Protos.TwoWayChannelMessage.newBuilder()
.setInitiate(Protos.Initiate.newBuilder().setExpireTimeSecs(Utils.currentTimeSeconds())
.setMinAcceptedChannelSize(COIN.add(ONE).longValue())
.setMinAcceptedChannelSize(COIN.add(SATOSHI).longValue())
.setMultisigKey(ByteString.copyFrom(new ECKey().getPubKey()))
.setMinPayment(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.longValue()))
.setType(MessageType.INITIATE).build());

View file

@ -409,7 +409,7 @@ public class PaymentChannelStateTest extends TestWithWallet {
clientState.fakeSave();
assertEquals(PaymentChannelClientState.State.PROVIDE_MULTISIG_CONTRACT_TO_SERVER, clientState.getState());
try { clientState.incrementPaymentBy(Coin.ONE); fail(); } catch (IllegalStateException e) {}
try { clientState.incrementPaymentBy(Coin.SATOSHI); fail(); } catch (IllegalStateException e) {}
byte[] multisigContractSerialized = clientState.getMultisigContract().bitcoinSerialize();
@ -511,12 +511,12 @@ public class PaymentChannelStateTest extends TestWithWallet {
assertEquals(serverState.getBestValueToMe(), totalPayment);
try {
clientState.incrementPaymentBy(Coin.ONE.negate());
clientState.incrementPaymentBy(Coin.SATOSHI.negate());
fail();
} catch (ValueOutOfRangeException e) {}
try {
clientState.incrementPaymentBy(halfCoin.subtract(size).add(Coin.ONE));
clientState.incrementPaymentBy(halfCoin.subtract(size).add(Coin.SATOSHI));
fail();
} catch (ValueOutOfRangeException e) {}
}
@ -538,8 +538,8 @@ public class PaymentChannelStateTest extends TestWithWallet {
serverState = new PaymentChannelServerState(mockBroadcaster, serverWallet, serverKey, EXPIRE_TIME);
assertEquals(PaymentChannelServerState.State.WAITING_FOR_REFUND_TRANSACTION, serverState.getState());
// Clearly ONE is far too small to be useful
clientState = new PaymentChannelClientState(wallet, myKey, ECKey.fromPublicOnly(serverKey.getPubKey()), Coin.ONE, EXPIRE_TIME);
// Clearly SATOSHI is far too small to be useful
clientState = new PaymentChannelClientState(wallet, myKey, ECKey.fromPublicOnly(serverKey.getPubKey()), Coin.SATOSHI, EXPIRE_TIME);
assertEquals(PaymentChannelClientState.State.NEW, clientState.getState());
try {
clientState.initiate();
@ -547,7 +547,7 @@ public class PaymentChannelStateTest extends TestWithWallet {
} catch (ValueOutOfRangeException e) {}
clientState = new PaymentChannelClientState(wallet, myKey, ECKey.fromPublicOnly(serverKey.getPubKey()),
Transaction.MIN_NONDUST_OUTPUT.subtract(Coin.ONE).add(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE),
Transaction.MIN_NONDUST_OUTPUT.subtract(Coin.SATOSHI).add(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE),
EXPIRE_TIME);
assertEquals(PaymentChannelClientState.State.NEW, clientState.getState());
try {
@ -596,13 +596,13 @@ public class PaymentChannelStateTest extends TestWithWallet {
Coin totalPayment = Coin.ZERO;
// We can send as little as we want - its up to the server to get the fees right
byte[] signature = clientState.incrementPaymentBy(Coin.ONE).signature.encodeToBitcoin();
totalPayment = totalPayment.add(Coin.ONE);
byte[] signature = clientState.incrementPaymentBy(Coin.SATOSHI).signature.encodeToBitcoin();
totalPayment = totalPayment.add(Coin.SATOSHI);
serverState.incrementPayment(CENT.subtract(totalPayment), signature);
// We can't refund more than the contract is worth...
try {
serverState.incrementPayment(CENT.add(ONE), signature);
serverState.incrementPayment(CENT.add(SATOSHI), signature);
fail();
} catch (ValueOutOfRangeException e) {}
@ -610,12 +610,12 @@ public class PaymentChannelStateTest extends TestWithWallet {
// will correct it for us to be larger than the requested amount, to make the change output zero.
PaymentChannelClientState.IncrementedPayment payment =
clientState.incrementPaymentBy(CENT.subtract(Transaction.MIN_NONDUST_OUTPUT));
assertEquals(CENT.subtract(ONE), payment.amount);
assertEquals(CENT.subtract(SATOSHI), payment.amount);
totalPayment = totalPayment.add(payment.amount);
// The server also won't accept it if we do that.
try {
serverState.incrementPayment(Transaction.MIN_NONDUST_OUTPUT.subtract(Coin.ONE), signature);
serverState.incrementPayment(Transaction.MIN_NONDUST_OUTPUT.subtract(Coin.SATOSHI), signature);
fail();
} catch (ValueOutOfRangeException e) {}
@ -679,9 +679,9 @@ public class PaymentChannelStateTest extends TestWithWallet {
assertEquals(PaymentChannelServerState.State.READY, serverState.getState());
// Both client and server are now in the ready state, split the channel in half
byte[] signature = clientState.incrementPaymentBy(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.subtract(Coin.ONE))
byte[] signature = clientState.incrementPaymentBy(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.subtract(Coin.SATOSHI))
.signature.encodeToBitcoin();
Coin totalRefund = CENT.subtract(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.subtract(ONE));
Coin totalRefund = CENT.subtract(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.subtract(SATOSHI));
serverState.incrementPayment(totalRefund, signature);
// We need to pay MIN_TX_FEE, but we only have MIN_NONDUST_OUTPUT
@ -704,8 +704,8 @@ public class PaymentChannelStateTest extends TestWithWallet {
assertTrue(e.getMessage().contains("more in fees"));
}
signature = clientState.incrementPaymentBy(Coin.valueOf(2)).signature.encodeToBitcoin();
totalRefund = totalRefund.subtract(Coin.valueOf(2));
signature = clientState.incrementPaymentBy(SATOSHI.multiply(2)).signature.encodeToBitcoin();
totalRefund = totalRefund.subtract(SATOSHI.multiply(2));
serverState.incrementPayment(totalRefund, signature);
// And settle the channel.

View file

@ -50,7 +50,7 @@ public class PaymentProtocolTest {
// static test data
private static final NetworkParameters NETWORK_PARAMS = UnitTestParams.get();
private static final Coin AMOUNT = Coin.ONE;
private static final Coin AMOUNT = Coin.SATOSHI;
private static final Address TO_ADDRESS = new ECKey().toAddress(NETWORK_PARAMS);
private static final String MEMO = "memo";
private static final String PAYMENT_URL = "https://example.com";
@ -128,7 +128,7 @@ public class PaymentProtocolTest {
// Create
List<Transaction> transactions = new LinkedList<Transaction>();
transactions.add(FakeTxBuilder.createFakeTx(NETWORK_PARAMS, AMOUNT, TO_ADDRESS));
Coin refundAmount = Coin.ONE;
Coin refundAmount = Coin.SATOSHI;
Address refundAddress = new ECKey().toAddress(NETWORK_PARAMS);
Payment payment = PaymentProtocol.createPaymentMessage(transactions, refundAmount, refundAddress, MEMO,
MERCHANT_DATA);

View file

@ -32,7 +32,7 @@ import java.net.URL;
import java.util.ArrayList;
import java.util.Date;
import static com.google.bitcoin.core.Coin.valueOf;
import static com.google.bitcoin.core.Coin.COIN;
import static org.junit.Assert.*;
public class PaymentSessionTest {
@ -45,7 +45,7 @@ public class PaymentSessionTest {
private ECKey serverKey;
private Transaction tx;
private TransactionOutput outputToMe;
private Coin nanoCoins = valueOf(1, 0);
private Coin nanoCoins = COIN;
@Before
public void setUp() throws Exception {

View file

@ -40,7 +40,7 @@ import java.util.Date;
import java.util.Iterator;
import java.util.Set;
import static com.google.bitcoin.core.Coin.valueOf;
import static com.google.bitcoin.core.Coin.*;
import static com.google.bitcoin.testing.FakeTxBuilder.createFakeTx;
import static org.junit.Assert.*;
@ -93,7 +93,7 @@ public class WalletProtobufSerializerTest {
@Test
public void oneTx() throws Exception {
// Check basic tx serialization.
Coin v1 = valueOf(1, 0);
Coin v1 = COIN;
Transaction t1 = createFakeTx(params, v1, myAddress);
t1.getConfidence().markBroadcastBy(new PeerAddress(InetAddress.getByName("1.2.3.4")));
t1.getConfidence().markBroadcastBy(new PeerAddress(InetAddress.getByName("5.6.7.8")));
@ -288,7 +288,7 @@ public class WalletProtobufSerializerTest {
@Test
public void coinbaseTxns() throws Exception {
// Covers issue 420 where the outpoint index of a coinbase tx input was being mis-serialized.
Block b = params.getGenesisBlock().createNextBlockWithCoinbase(myKey.getPubKey(), valueOf(50, 0));
Block b = params.getGenesisBlock().createNextBlockWithCoinbase(myKey.getPubKey(), FIFTY_COINS);
Transaction coinbase = b.getTransactions().get(0);
assertTrue(coinbase.isCoinBase());
BlockChain chain = new BlockChain(params, myWallet, new MemoryBlockStore(params));

View file

@ -362,7 +362,7 @@ public class BitcoinURITest {
String str = "bitcoin://1KzTSfqjF2iKCduwz59nv2uqh1W2JsTxZH?amount=0.01000000";
BitcoinURI uri = new BitcoinURI(str);
assertEquals("1KzTSfqjF2iKCduwz59nv2uqh1W2JsTxZH", uri.getAddress().toString());
assertEquals(valueOf(0, 1), uri.getAmount());
assertEquals(CENT, uri.getAmount());
}
@Test(expected = BitcoinURIParseException.class)

View file

@ -135,7 +135,7 @@ public class DefaultRiskAnalysisTest {
Transaction dustTx = new Transaction(params);
dustTx.addInput(params.getGenesisBlock().getTransactions().get(0).getOutput(0));
dustTx.addOutput(Coin.ONE, key1); // 1 Satoshi
dustTx.addOutput(Coin.SATOSHI, key1); // 1 Satoshi
assertEquals(RiskAnalysis.Result.NON_STANDARD, DefaultRiskAnalysis.FACTORY.create(wallet, dustTx, NO_DEPS).analyze());
Transaction edgeCaseTx = new Transaction(params);

View file

@ -29,7 +29,7 @@ public class DoubleSpend {
kit.wallet().getBalanceFuture(COIN, Wallet.BalanceType.AVAILABLE).get();
Transaction tx1 = kit.wallet().createSend(new Address(params, "muYPFNCv7KQEG2ZLM7Z3y96kJnNyXJ53wm"), CENT);
Transaction tx2 = kit.wallet().createSend(new Address(params, "muYPFNCv7KQEG2ZLM7Z3y96kJnNyXJ53wm"), CENT.add(TEN));
Transaction tx2 = kit.wallet().createSend(new Address(params, "muYPFNCv7KQEG2ZLM7Z3y96kJnNyXJ53wm"), CENT.add(SATOSHI.multiply(10)));
final Peer peer = kit.peerGroup().getConnectedPeers().get(0);
peer.addEventListener(new AbstractPeerEventListener() {
@Override

View file

@ -71,8 +71,7 @@ public class ExamplePaymentChannelServer implements PaymentChannelServerListener
// We provide a peer group, a wallet, a timeout in seconds, the amount we require to start a channel and
// an implementation of HandlerFactory, which we just implement ourselves.
final int MILLI = 100000;
new PaymentChannelServerListener(appKit.peerGroup(), appKit.wallet(), 15, Coin.valueOf(MILLI), this).bindAndStart(4242);
new PaymentChannelServerListener(appKit.peerGroup(), appKit.wallet(), 15, Coin.valueOf(100000), this).bindAndStart(4242);
}
@Override