Consistently uppercase constant PARAMS in unit tests.

This commit is contained in:
Andreas Schildbach
2016-02-29 22:32:36 +01:00
parent c4ea9c95e5
commit 315863d4e8
20 changed files with 626 additions and 627 deletions

View File

@@ -53,7 +53,11 @@ public abstract class AbstractFullPrunedBlockChainTest {
private static final Logger log = LoggerFactory.getLogger(AbstractFullPrunedBlockChainTest.class);
protected NetworkParameters params;
protected static final NetworkParameters PARAMS = new UnitTestParams() {
@Override public int getInterval() {
return 10000;
}
};
protected FullPrunedBlockChain chain;
protected FullPrunedBlockStore store;
protected Context context;
@@ -61,12 +65,7 @@ public abstract class AbstractFullPrunedBlockChainTest {
@Before
public void setUp() throws Exception {
BriefLogFormatter.init();
params = new UnitTestParams() {
@Override public int getInterval() {
return 10000;
}
};
context = new Context(params);
context = new Context(PARAMS);
}
public abstract FullPrunedBlockStore createStore(NetworkParameters params, int blockCount)
@@ -77,11 +76,11 @@ public abstract class AbstractFullPrunedBlockChainTest {
@Test
public void testGeneratedChain() throws Exception {
// Tests various test cases from FullBlockTestGenerator
FullBlockTestGenerator generator = new FullBlockTestGenerator(params);
FullBlockTestGenerator generator = new FullBlockTestGenerator(PARAMS);
RuleList blockList = generator.getBlocksToTest(false, false, null);
store = createStore(params, blockList.maximumReorgBlockCount);
chain = new FullPrunedBlockChain(params, store);
store = createStore(PARAMS, blockList.maximumReorgBlockCount);
chain = new FullPrunedBlockChain(PARAMS, store);
for (Rule rule : blockList.list) {
if (!(rule instanceof FullBlockTestGenerator.BlockAndValidity))
@@ -125,8 +124,8 @@ public abstract class AbstractFullPrunedBlockChainTest {
@Test
public void skipScripts() throws Exception {
store = createStore(params, 10);
chain = new FullPrunedBlockChain(params, store);
store = createStore(PARAMS, 10);
chain = new FullPrunedBlockChain(PARAMS, store);
// Check that we aren't accidentally leaving any references
// to the full StoredUndoableBlock's lying around (ie memory leaks)
@@ -135,17 +134,17 @@ public abstract class AbstractFullPrunedBlockChainTest {
int height = 1;
// Build some blocks on genesis block to create a spendable output
Block rollingBlock = params.getGenesisBlock().createNextBlockWithCoinbase(Block.BLOCK_VERSION_GENESIS, outKey.getPubKey(), height++);
Block rollingBlock = PARAMS.getGenesisBlock().createNextBlockWithCoinbase(Block.BLOCK_VERSION_GENESIS, outKey.getPubKey(), height++);
chain.add(rollingBlock);
TransactionOutput spendableOutput = rollingBlock.getTransactions().get(0).getOutput(0);
for (int i = 1; i < params.getSpendableCoinbaseDepth(); i++) {
for (int i = 1; i < PARAMS.getSpendableCoinbaseDepth(); i++) {
rollingBlock = rollingBlock.createNextBlockWithCoinbase(Block.BLOCK_VERSION_GENESIS, outKey.getPubKey(), height++);
chain.add(rollingBlock);
}
rollingBlock = rollingBlock.createNextBlock(null);
Transaction t = new Transaction(params);
t.addOutput(new TransactionOutput(params, t, FIFTY_COINS, new byte[] {}));
Transaction t = new Transaction(PARAMS);
t.addOutput(new TransactionOutput(PARAMS, t, FIFTY_COINS, new byte[] {}));
TransactionInput input = t.addInput(spendableOutput);
// Invalid script.
input.clearScriptBytes();
@@ -165,8 +164,8 @@ public abstract class AbstractFullPrunedBlockChainTest {
@Test
public void testFinalizedBlocks() throws Exception {
final int UNDOABLE_BLOCKS_STORED = 10;
store = createStore(params, UNDOABLE_BLOCKS_STORED);
chain = new FullPrunedBlockChain(params, store);
store = createStore(PARAMS, UNDOABLE_BLOCKS_STORED);
chain = new FullPrunedBlockChain(PARAMS, store);
// Check that we aren't accidentally leaving any references
// to the full StoredUndoableBlock's lying around (ie memory leaks)
@@ -175,11 +174,11 @@ public abstract class AbstractFullPrunedBlockChainTest {
int height = 1;
// Build some blocks on genesis block to create a spendable output
Block rollingBlock = params.getGenesisBlock().createNextBlockWithCoinbase(Block.BLOCK_VERSION_GENESIS, outKey.getPubKey(), height++);
Block rollingBlock = PARAMS.getGenesisBlock().createNextBlockWithCoinbase(Block.BLOCK_VERSION_GENESIS, outKey.getPubKey(), height++);
chain.add(rollingBlock);
TransactionOutPoint spendableOutput = new TransactionOutPoint(params, 0, rollingBlock.getTransactions().get(0).getHash());
TransactionOutPoint spendableOutput = new TransactionOutPoint(PARAMS, 0, rollingBlock.getTransactions().get(0).getHash());
byte[] spendableOutputScriptPubKey = rollingBlock.getTransactions().get(0).getOutputs().get(0).getScriptBytes();
for (int i = 1; i < params.getSpendableCoinbaseDepth(); i++) {
for (int i = 1; i < PARAMS.getSpendableCoinbaseDepth(); i++) {
rollingBlock = rollingBlock.createNextBlockWithCoinbase(Block.BLOCK_VERSION_GENESIS, outKey.getPubKey(), height++);
chain.add(rollingBlock);
}
@@ -188,9 +187,9 @@ public abstract class AbstractFullPrunedBlockChainTest {
(store.getTransactionOutput(spendableOutput.getHash(), spendableOutput.getIndex()));
rollingBlock = rollingBlock.createNextBlock(null);
Transaction t = new Transaction(params);
Transaction t = new Transaction(PARAMS);
// Entirely invalid scriptPubKey
t.addOutput(new TransactionOutput(params, t, FIFTY_COINS, new byte[]{}));
t.addOutput(new TransactionOutput(PARAMS, t, FIFTY_COINS, new byte[]{}));
t.addSignedInput(spendableOutput, new Script(spendableOutputScriptPubKey), outKey);
rollingBlock.addTransaction(t);
rollingBlock.solve();
@@ -240,8 +239,8 @@ public abstract class AbstractFullPrunedBlockChainTest {
@Test
public void testGetOpenTransactionOutputs() throws Exception {
final int UNDOABLE_BLOCKS_STORED = 10;
store = createStore(params, UNDOABLE_BLOCKS_STORED);
chain = new FullPrunedBlockChain(params, store);
store = createStore(PARAMS, UNDOABLE_BLOCKS_STORED);
chain = new FullPrunedBlockChain(PARAMS, store);
// Check that we aren't accidentally leaving any references
// to the full StoredUndoableBlock's lying around (ie memory leaks)
@@ -249,12 +248,12 @@ public abstract class AbstractFullPrunedBlockChainTest {
int height = 1;
// Build some blocks on genesis block to create a spendable output
Block rollingBlock = params.getGenesisBlock().createNextBlockWithCoinbase(Block.BLOCK_VERSION_GENESIS, outKey.getPubKey(), height++);
Block rollingBlock = PARAMS.getGenesisBlock().createNextBlockWithCoinbase(Block.BLOCK_VERSION_GENESIS, outKey.getPubKey(), height++);
chain.add(rollingBlock);
Transaction transaction = rollingBlock.getTransactions().get(0);
TransactionOutPoint spendableOutput = new TransactionOutPoint(params, 0, transaction.getHash());
TransactionOutPoint spendableOutput = new TransactionOutPoint(PARAMS, 0, transaction.getHash());
byte[] spendableOutputScriptPubKey = transaction.getOutputs().get(0).getScriptBytes();
for (int i = 1; i < params.getSpendableCoinbaseDepth(); i++) {
for (int i = 1; i < PARAMS.getSpendableCoinbaseDepth(); i++) {
rollingBlock = rollingBlock.createNextBlockWithCoinbase(Block.BLOCK_VERSION_GENESIS, outKey.getPubKey(), height++);
chain.add(rollingBlock);
}
@@ -263,11 +262,11 @@ public abstract class AbstractFullPrunedBlockChainTest {
// Create bitcoin spend of 1 BTC.
ECKey toKey = new ECKey();
Coin amount = Coin.valueOf(100000000);
Address address = new Address(params, toKey.getPubKeyHash());
Address address = new Address(PARAMS, toKey.getPubKeyHash());
Coin totalAmount = Coin.ZERO;
Transaction t = new Transaction(params);
t.addOutput(new TransactionOutput(params, t, amount, toKey));
Transaction t = new Transaction(PARAMS);
t.addOutput(new TransactionOutput(PARAMS, t, amount, toKey));
t.addSignedInput(spendableOutput, new Script(spendableOutputScriptPubKey), outKey);
rollingBlock.addTransaction(t);
rollingBlock.solve();
@@ -291,8 +290,8 @@ public abstract class AbstractFullPrunedBlockChainTest {
@Test
public void testUTXOProviderWithWallet() throws Exception {
final int UNDOABLE_BLOCKS_STORED = 10;
store = createStore(params, UNDOABLE_BLOCKS_STORED);
chain = new FullPrunedBlockChain(params, store);
store = createStore(PARAMS, UNDOABLE_BLOCKS_STORED);
chain = new FullPrunedBlockChain(PARAMS, store);
// Check that we aren't accidentally leaving any references
// to the full StoredUndoableBlock's lying around (ie memory leaks)
@@ -300,19 +299,19 @@ public abstract class AbstractFullPrunedBlockChainTest {
int height = 1;
// Build some blocks on genesis block to create a spendable output.
Block rollingBlock = params.getGenesisBlock().createNextBlockWithCoinbase(Block.BLOCK_VERSION_GENESIS, outKey.getPubKey(), height++);
Block rollingBlock = PARAMS.getGenesisBlock().createNextBlockWithCoinbase(Block.BLOCK_VERSION_GENESIS, outKey.getPubKey(), height++);
chain.add(rollingBlock);
Transaction transaction = rollingBlock.getTransactions().get(0);
TransactionOutPoint spendableOutput = new TransactionOutPoint(params, 0, transaction.getHash());
TransactionOutPoint spendableOutput = new TransactionOutPoint(PARAMS, 0, transaction.getHash());
byte[] spendableOutputScriptPubKey = transaction.getOutputs().get(0).getScriptBytes();
for (int i = 1; i < params.getSpendableCoinbaseDepth(); i++) {
for (int i = 1; i < PARAMS.getSpendableCoinbaseDepth(); i++) {
rollingBlock = rollingBlock.createNextBlockWithCoinbase(Block.BLOCK_VERSION_GENESIS, outKey.getPubKey(), height++);
chain.add(rollingBlock);
}
rollingBlock = rollingBlock.createNextBlock(null);
// Create 1 BTC spend to a key in this wallet (to ourselves).
Wallet wallet = new Wallet(params);
Wallet wallet = new Wallet(PARAMS);
assertEquals("Available balance is incorrect", Coin.ZERO, wallet.getBalance(Wallet.BalanceType.AVAILABLE));
assertEquals("Estimated balance is incorrect", Coin.ZERO, wallet.getBalance(Wallet.BalanceType.ESTIMATED));
@@ -320,8 +319,8 @@ public abstract class AbstractFullPrunedBlockChainTest {
ECKey toKey = wallet.freshReceiveKey();
Coin amount = Coin.valueOf(100000000);
Transaction t = new Transaction(params);
t.addOutput(new TransactionOutput(params, t, amount, toKey));
Transaction t = new Transaction(PARAMS);
t.addOutput(new TransactionOutput(PARAMS, t, amount, toKey));
t.addSignedInput(spendableOutput, new Script(spendableOutputScriptPubKey), outKey);
rollingBlock.addTransaction(t);
rollingBlock.solve();
@@ -330,7 +329,7 @@ public abstract class AbstractFullPrunedBlockChainTest {
// Create another spend of 1/2 the value of BTC we have available using the wallet (store coin selector).
ECKey toKey2 = new ECKey();
Coin amount2 = amount.divide(2);
Address address2 = new Address(params, toKey2.getPubKeyHash());
Address address2 = new Address(PARAMS, toKey2.getPubKeyHash());
Wallet.SendRequest req = Wallet.SendRequest.to(address2, amount2);
wallet.completeTx(req);
wallet.commitTx(req.tx);
@@ -358,25 +357,25 @@ public abstract class AbstractFullPrunedBlockChainTest {
*/
@Test
public void missingHeightFromCoinbase() throws Exception {
final int UNDOABLE_BLOCKS_STORED = params.getMajorityEnforceBlockUpgrade() + 1;
store = createStore(params, UNDOABLE_BLOCKS_STORED);
final int UNDOABLE_BLOCKS_STORED = PARAMS.getMajorityEnforceBlockUpgrade() + 1;
store = createStore(PARAMS, UNDOABLE_BLOCKS_STORED);
try {
chain = new FullPrunedBlockChain(params, store);
chain = new FullPrunedBlockChain(PARAMS, store);
ECKey outKey = new ECKey();
int height = 1;
Block chainHead = params.getGenesisBlock();
Block chainHead = PARAMS.getGenesisBlock();
// Build some blocks on genesis block to create a spendable output.
// Put in just enough v1 blocks to stop the v2 blocks from forming a majority
for (height = 1; height <= (params.getMajorityWindow() - params.getMajorityEnforceBlockUpgrade()); height++) {
for (height = 1; height <= (PARAMS.getMajorityWindow() - PARAMS.getMajorityEnforceBlockUpgrade()); height++) {
chainHead = chainHead.createNextBlockWithCoinbase(Block.BLOCK_VERSION_GENESIS,
outKey.getPubKey(), height);
chain.add(chainHead);
}
// Fill the rest of the window in with v2 blocks
for (; height < params.getMajorityWindow(); height++) {
for (; height < PARAMS.getMajorityWindow(); height++) {
chainHead = chainHead.createNextBlockWithCoinbase(Block.BLOCK_VERSION_BIP34,
outKey.getPubKey(), height);
chain.add(chainHead);

View File

@@ -38,7 +38,7 @@ import static org.bitcoinj.core.Utils.HEX;
import static org.junit.Assert.*;
public class BlockTest {
static final NetworkParameters params = TestNet2Params.get();
private static final NetworkParameters PARAMS = TestNet2Params.get();
public static final byte[] blockBytes;
@@ -50,12 +50,12 @@ public class BlockTest {
@Before
public void setUp() throws Exception {
Context context = new Context(params);
Context context = new Context(PARAMS);
}
@Test
public void testWork() throws Exception {
BigInteger work = params.getGenesisBlock().getWork();
BigInteger work = PARAMS.getGenesisBlock().getWork();
// This number is printed by Bitcoin Core at startup as the calculated value of chainWork on testnet:
//
// SetBestChain: new best=00000007199508e34a9f height=0 work=536879104
@@ -64,7 +64,7 @@ public class BlockTest {
@Test
public void testBlockVerification() throws Exception {
Block block = params.getDefaultSerializer().makeBlock(blockBytes);
Block block = PARAMS.getDefaultSerializer().makeBlock(blockBytes);
block.verify(Block.BLOCK_HEIGHT_GENESIS, EnumSet.noneOf(Block.VerifyFlag.class));
assertEquals("00000000a6e5eb79dcec11897af55e90cd571a4335383a3ccfbc12ec81085935", block.getHashAsString());
}
@@ -72,7 +72,7 @@ public class BlockTest {
@SuppressWarnings("deprecation")
@Test
public void testDate() throws Exception {
Block block = params.getDefaultSerializer().makeBlock(blockBytes);
Block block = PARAMS.getDefaultSerializer().makeBlock(blockBytes);
assertEquals("4 Nov 2010 16:06:04 GMT", block.getTime().toGMTString());
}
@@ -109,7 +109,7 @@ public class BlockTest {
@Test
public void testBadTransactions() throws Exception {
Block block = params.getDefaultSerializer().makeBlock(blockBytes);
Block block = PARAMS.getDefaultSerializer().makeBlock(blockBytes);
// Re-arrange so the coinbase transaction is not first.
Transaction tx1 = block.transactions.get(0);
Transaction tx2 = block.transactions.get(1);
@@ -125,9 +125,9 @@ public class BlockTest {
@Test
public void testHeaderParse() throws Exception {
Block block = params.getDefaultSerializer().makeBlock(blockBytes);
Block block = PARAMS.getDefaultSerializer().makeBlock(blockBytes);
Block header = block.cloneAsHeader();
Block reparsed = params.getDefaultSerializer().makeBlock(header.bitcoinSerialize());
Block reparsed = PARAMS.getDefaultSerializer().makeBlock(header.bitcoinSerialize());
assertEquals(reparsed, header);
}
@@ -137,7 +137,7 @@ public class BlockTest {
// proves that transaction serialization works, along with all its subobjects like scripts and in/outpoints.
//
// NB: This tests the bitcoin serialization protocol.
Block block = params.getDefaultSerializer().makeBlock(blockBytes);
Block block = PARAMS.getDefaultSerializer().makeBlock(blockBytes);
assertTrue(Arrays.equals(blockBytes, block.bitcoinSerialize()));
}

File diff suppressed because one or more lines are too long

View File

@@ -213,8 +213,8 @@ public class PeerGroupTest extends TestWithPeerGroup {
assertEquals(tmp, expectedPeers);
Coin value = COIN;
Transaction t1 = FakeTxBuilder.createFakeTx(params, value, address);
InventoryMessage inv = new InventoryMessage(params);
Transaction t1 = FakeTxBuilder.createFakeTx(PARAMS, value, address);
InventoryMessage inv = new InventoryMessage(PARAMS);
inv.addTransaction(t1);
// Note: we start with p2 here to verify that transactions are downloaded from whichever peer announces first
@@ -228,7 +228,7 @@ public class PeerGroupTest extends TestWithPeerGroup {
// Asks for dependency.
GetDataMessage getdata = (GetDataMessage) outbound(p2);
assertNotNull(getdata);
inbound(p2, new NotFoundMessage(params, getdata.getItems()));
inbound(p2, new NotFoundMessage(PARAMS, getdata.getItems()));
pingAndWait(p2);
assertEquals(value, wallet.getBalance(Wallet.BalanceType.ESTIMATED));
}
@@ -242,9 +242,9 @@ public class PeerGroupTest extends TestWithPeerGroup {
// Create a peer.
InboundMessageQueuer p1 = connectPeer(1);
Wallet wallet2 = new Wallet(params);
Wallet wallet2 = new Wallet(PARAMS);
ECKey key2 = wallet2.freshReceiveKey();
Address address2 = key2.toAddress(params);
Address address2 = key2.toAddress(PARAMS);
peerGroup.addWallet(wallet2);
blockChain.addWallet(wallet2);
@@ -253,8 +253,8 @@ public class PeerGroupTest extends TestWithPeerGroup {
assertEquals(MemoryPoolMessage.class, waitForOutbound(p1).getClass());
Coin value = COIN;
Transaction t1 = FakeTxBuilder.createFakeTx(params, value, address2);
InventoryMessage inv = new InventoryMessage(params);
Transaction t1 = FakeTxBuilder.createFakeTx(PARAMS, value, address2);
InventoryMessage inv = new InventoryMessage(PARAMS);
inv.addTransaction(t1);
inbound(p1, inv);
@@ -263,7 +263,7 @@ public class PeerGroupTest extends TestWithPeerGroup {
// Asks for dependency.
GetDataMessage getdata = (GetDataMessage) outbound(p1);
assertNotNull(getdata);
inbound(p1, new NotFoundMessage(params, getdata.getItems()));
inbound(p1, new NotFoundMessage(PARAMS, getdata.getItems()));
pingAndWait(p1);
assertEquals(value, wallet2.getBalance(Wallet.BalanceType.ESTIMATED));
}
@@ -286,7 +286,7 @@ public class PeerGroupTest extends TestWithPeerGroup {
Block b3 = FakeTxBuilder.makeSolvedTestBlock(b2);
// Peer 1 and 2 receives an inv advertising a newly solved block.
InventoryMessage inv = new InventoryMessage(params);
InventoryMessage inv = new InventoryMessage(PARAMS);
inv.addBlock(b3);
// Only peer 1 tries to download it.
inbound(p1, inv);
@@ -330,7 +330,7 @@ public class PeerGroupTest extends TestWithPeerGroup {
GetBlocksMessage getblocks = (GetBlocksMessage) outbound(p1);
assertEquals(Sha256Hash.ZERO_HASH, getblocks.getStopHash());
// We give back an inv with some blocks in it.
InventoryMessage inv = new InventoryMessage(params);
InventoryMessage inv = new InventoryMessage(PARAMS);
inv.addBlock(b1);
inv.addBlock(b2);
inv.addBlock(b3);
@@ -364,8 +364,8 @@ public class PeerGroupTest extends TestWithPeerGroup {
InboundMessageQueuer p2 = connectPeer(2);
InboundMessageQueuer p3 = connectPeer(3);
Transaction tx = FakeTxBuilder.createFakeTx(params, valueOf(20, 0), address);
InventoryMessage inv = new InventoryMessage(params);
Transaction tx = FakeTxBuilder.createFakeTx(PARAMS, valueOf(20, 0), address);
InventoryMessage inv = new InventoryMessage(PARAMS);
inv.addTransaction(tx);
assertEquals(0, tx.getConfidence().numBroadcastPeers());
@@ -418,7 +418,7 @@ public class PeerGroupTest extends TestWithPeerGroup {
final long now = Utils.currentTimeSeconds();
peerGroup.start();
assertTrue(peerGroup.getFastCatchupTimeSecs() > now - WEEK - 10000);
Wallet w2 = new Wallet(params);
Wallet w2 = new Wallet(PARAMS);
ECKey key1 = new ECKey();
key1.setCreationTimeSeconds(now - 86400); // One day ago.
w2.importKey(key1);
@@ -438,7 +438,7 @@ public class PeerGroupTest extends TestWithPeerGroup {
public void noPings() throws Exception {
peerGroup.start();
peerGroup.setPingIntervalMsec(0);
VersionMessage versionMessage = new VersionMessage(params, 2);
VersionMessage versionMessage = new VersionMessage(PARAMS, 2);
versionMessage.clientVersion = NetworkParameters.ProtocolVersion.BLOOM_FILTER.getBitcoinProtocolVersion();
versionMessage.localServices = VersionMessage.NODE_NETWORK;
connectPeer(1, versionMessage);
@@ -450,7 +450,7 @@ public class PeerGroupTest extends TestWithPeerGroup {
public void pings() throws Exception {
peerGroup.start();
peerGroup.setPingIntervalMsec(100);
VersionMessage versionMessage = new VersionMessage(params, 2);
VersionMessage versionMessage = new VersionMessage(PARAMS, 2);
versionMessage.clientVersion = NetworkParameters.ProtocolVersion.BLOOM_FILTER.getBitcoinProtocolVersion();
versionMessage.localServices = VersionMessage.NODE_NETWORK;
InboundMessageQueuer p1 = connectPeer(1, versionMessage);
@@ -467,10 +467,10 @@ public class PeerGroupTest extends TestWithPeerGroup {
@Test
public void downloadPeerSelection() throws Exception {
peerGroup.start();
VersionMessage versionMessage2 = new VersionMessage(params, 2);
VersionMessage versionMessage2 = new VersionMessage(PARAMS, 2);
versionMessage2.clientVersion = NetworkParameters.ProtocolVersion.BLOOM_FILTER.getBitcoinProtocolVersion();
versionMessage2.localServices = VersionMessage.NODE_NETWORK;
VersionMessage versionMessage3 = new VersionMessage(params, 3);
VersionMessage versionMessage3 = new VersionMessage(PARAMS, 3);
versionMessage3.clientVersion = NetworkParameters.ProtocolVersion.BLOOM_FILTER.getBitcoinProtocolVersion();
versionMessage3.localServices = VersionMessage.NODE_NETWORK;
assertNull(peerGroup.getDownloadPeer());
@@ -490,7 +490,7 @@ public class PeerGroupTest extends TestWithPeerGroup {
// New peer with a higher protocol version but same chain height.
// TODO: When PeerGroup.selectDownloadPeer.PREFERRED_VERSION is not equal to vMinRequiredProtocolVersion,
// reenable this test
/*VersionMessage versionMessage4 = new VersionMessage(params, 3);
/*VersionMessage versionMessage4 = new VersionMessage(PARAMS, 3);
versionMessage4.clientVersion = 100000;
versionMessage4.localServices = VersionMessage.NODE_NETWORK;
InboundMessageQueuer d = connectPeer(5, versionMessage4);
@@ -616,8 +616,8 @@ public class PeerGroupTest extends TestWithPeerGroup {
InboundMessageQueuer p1 = connectPeer(1);
InboundMessageQueuer p2 = connectPeer(2);
// Create a pay to pubkey tx.
Transaction tx = FakeTxBuilder.createFakeTx(params, COIN, key);
Transaction tx2 = new Transaction(params);
Transaction tx = FakeTxBuilder.createFakeTx(PARAMS, COIN, key);
Transaction tx2 = new Transaction(PARAMS);
tx2.addInput(tx.getOutput(0));
TransactionOutPoint outpoint = tx2.getInput(0).getOutpoint();
assertTrue(p1.lastReceivedFilter.contains(key.getPubKey()));
@@ -627,7 +627,7 @@ public class PeerGroupTest extends TestWithPeerGroup {
assertTrue(outbound(p1) instanceof GetDataMessage);
final Sha256Hash dephash = tx.getInput(0).getOutpoint().getHash();
final InventoryItem inv = new InventoryItem(InventoryItem.Type.Transaction, dephash);
inbound(p1, new NotFoundMessage(params, ImmutableList.of(inv)));
inbound(p1, new NotFoundMessage(PARAMS, ImmutableList.of(inv)));
assertNull(outbound(p1));
assertNull(outbound(p2));
peerGroup.waitForJobQueue();
@@ -693,10 +693,10 @@ public class PeerGroupTest extends TestWithPeerGroup {
ListenableFuture<List<Peer>> future = peerGroup.waitForPeersOfVersion(2, newVer);
VersionMessage ver1 = new VersionMessage(params, 10);
VersionMessage ver1 = new VersionMessage(PARAMS, 10);
ver1.clientVersion = baseVer;
ver1.localServices = VersionMessage.NODE_NETWORK;
VersionMessage ver2 = new VersionMessage(params, 10);
VersionMessage ver2 = new VersionMessage(PARAMS, 10);
ver2.clientVersion = newVer;
ver2.localServices = VersionMessage.NODE_NETWORK;
peerGroup.start();
@@ -715,10 +715,10 @@ public class PeerGroupTest extends TestWithPeerGroup {
public void waitForPeersWithServiceFlags() throws Exception {
ListenableFuture<List<Peer>> future = peerGroup.waitForPeersWithServiceMask(2, 3);
VersionMessage ver1 = new VersionMessage(params, 10);
VersionMessage ver1 = new VersionMessage(PARAMS, 10);
ver1.clientVersion = 70000;
ver1.localServices = VersionMessage.NODE_NETWORK;
VersionMessage ver2 = new VersionMessage(params, 10);
VersionMessage ver2 = new VersionMessage(PARAMS, 10);
ver2.clientVersion = 70000;
ver2.localServices = VersionMessage.NODE_NETWORK | 2;
peerGroup.start();
@@ -743,12 +743,12 @@ public class PeerGroupTest extends TestWithPeerGroup {
// 1. Test are executed on the same machine that is running a full node
// 2. Test are executed without any full node running locally
// We have to avoid to connecting to real and external services in unit tests
// So we skip this test in case we have already something running on port params.getPort()
// So we skip this test in case we have already something running on port PARAMS.getPort()
// Check that if we have a localhost port 8333 or 18333 then it's used instead of the p2p network.
ServerSocket local = null;
try {
local = new ServerSocket(params.getPort(), 100, InetAddresses.forString("127.0.0.1"));
local = new ServerSocket(PARAMS.getPort(), 100, InetAddresses.forString("127.0.0.1"));
}
catch(BindException e) { // Port already in use, skipping this test.
return;
@@ -761,7 +761,7 @@ public class PeerGroupTest extends TestWithPeerGroup {
local.accept(); // Real connect
// If we get here it used the local peer. Check no others are in use.
assertEquals(1, peerGroup.getMaxConnections());
assertEquals(PeerAddress.localhost(params), peerGroup.getPendingPeers().get(0).getAddress());
assertEquals(PeerAddress.localhost(PARAMS), peerGroup.getPendingPeers().get(0).getAddress());
} finally {
local.close();
}
@@ -803,8 +803,8 @@ public class PeerGroupTest extends TestWithPeerGroup {
Coin expectedBalance = Coin.ZERO;
Block prev = blockStore.getChainHead().getHeader();
for (ECKey key1 : keys) {
Address addr = key1.toAddress(params);
Block next = FakeTxBuilder.makeSolvedTestBlock(prev, FakeTxBuilder.createFakeTx(params, Coin.FIFTY_COINS, addr));
Address addr = key1.toAddress(PARAMS);
Block next = FakeTxBuilder.makeSolvedTestBlock(prev, FakeTxBuilder.createFakeTx(PARAMS, Coin.FIFTY_COINS, addr));
expectedBalance = expectedBalance.add(next.getTransactions().get(2).getOutput(0).getValue());
blocks.add(next);
prev = next;
@@ -813,7 +813,7 @@ public class PeerGroupTest extends TestWithPeerGroup {
// Send the chain that doesn't have all the transactions in it. The blocks after the exhaustion point should all
// be ignored.
int epoch = wallet.getKeyChainGroupCombinedKeyLookaheadEpochs();
BloomFilter filter = new BloomFilter(params, p1.lastReceivedFilter.bitcoinSerialize());
BloomFilter filter = new BloomFilter(PARAMS, p1.lastReceivedFilter.bitcoinSerialize());
filterAndSend(p1, blocks, filter);
Block exhaustionPoint = blocks.get(3);
pingAndWait(p1);

View File

@@ -77,9 +77,9 @@ public class PeerTest extends TestWithNetworkConnections {
@Before
public void setUp() throws Exception {
super.setUp();
VersionMessage ver = new VersionMessage(params, 100);
VersionMessage ver = new VersionMessage(PARAMS, 100);
InetSocketAddress address = new InetSocketAddress("127.0.0.1", 4000);
peer = new Peer(params, ver, new PeerAddress(params, address), blockChain);
peer = new Peer(PARAMS, ver, new PeerAddress(PARAMS, address), blockChain);
peer.addWallet(wallet);
}
@@ -95,7 +95,7 @@ public class PeerTest extends TestWithNetworkConnections {
}
private void connectWithVersion(int version, int flags) throws Exception {
VersionMessage peerVersion = new VersionMessage(params, OTHER_PEER_CHAIN_HEIGHT);
VersionMessage peerVersion = new VersionMessage(PARAMS, OTHER_PEER_CHAIN_HEIGHT);
peerVersion.clientVersion = version;
peerVersion.localServices = flags;
writeTarget = connect(peer, peerVersion);
@@ -147,7 +147,7 @@ public class PeerTest extends TestWithNetworkConnections {
assertEquals(blockStore.getChainHead().getHeader().getHash(), getblocks.getLocator().get(0));
assertEquals(Sha256Hash.ZERO_HASH, getblocks.getStopHash());
// Remote peer sends us an inv with some blocks.
InventoryMessage inv = new InventoryMessage(params);
InventoryMessage inv = new InventoryMessage(PARAMS);
inv.addBlock(b2);
inv.addBlock(b3);
// We do a getdata on them.
@@ -161,7 +161,7 @@ public class PeerTest extends TestWithNetworkConnections {
inbound(writeTarget, b2);
inbound(writeTarget, b3);
inv = new InventoryMessage(params);
inv = new InventoryMessage(PARAMS);
inv.addBlock(b5);
// We request the head block.
inbound(writeTarget, inv);
@@ -180,7 +180,7 @@ public class PeerTest extends TestWithNetworkConnections {
// because we walk backwards down the orphan chain and then discover we already asked for those blocks, so
// nothing is done.
Block b6 = makeSolvedTestBlock(b5);
inv = new InventoryMessage(params);
inv = new InventoryMessage(PARAMS);
inv.addBlock(b6);
inbound(writeTarget, inv);
getdata = (GetDataMessage)outbound(writeTarget);
@@ -189,7 +189,7 @@ public class PeerTest extends TestWithNetworkConnections {
inbound(writeTarget, b6);
assertNull(outbound(writeTarget)); // Nothing is sent at this point.
// We're still waiting for the response to the getblocks (b3,b5) sent above.
inv = new InventoryMessage(params);
inv = new InventoryMessage(PARAMS);
inv.addBlock(b4);
inv.addBlock(b5);
inbound(writeTarget, inv);
@@ -215,7 +215,7 @@ public class PeerTest extends TestWithNetworkConnections {
Block b2 = makeSolvedTestBlock(b1);
Block b3 = makeSolvedTestBlock(b2);
inbound(writeTarget, b3);
InventoryMessage inv = new InventoryMessage(params);
InventoryMessage inv = new InventoryMessage(PARAMS);
InventoryItem item = new InventoryItem(InventoryItem.Type.Block, b3.getHash());
inv.addItem(item);
inbound(writeTarget, inv);
@@ -223,7 +223,7 @@ public class PeerTest extends TestWithNetworkConnections {
GetBlocksMessage getblocks = (GetBlocksMessage)outbound(writeTarget);
List<Sha256Hash> expectedLocator = new ArrayList<Sha256Hash>();
expectedLocator.add(b1.getHash());
expectedLocator.add(params.getGenesisBlock().getHash());
expectedLocator.add(PARAMS.getGenesisBlock().getHash());
assertEquals(getblocks.getLocator(), expectedLocator);
assertEquals(getblocks.getStopHash(), b3.getHash());
@@ -244,7 +244,7 @@ public class PeerTest extends TestWithNetworkConnections {
Block b2 = makeSolvedTestBlock(b1);
// Receive an inv.
InventoryMessage inv = new InventoryMessage(params);
InventoryMessage inv = new InventoryMessage(PARAMS);
InventoryItem item = new InventoryItem(InventoryItem.Type.Block, b2.getHash());
inv.addItem(item);
inbound(writeTarget, inv);
@@ -260,8 +260,8 @@ public class PeerTest extends TestWithNetworkConnections {
peer.setDownloadData(true);
// Make a transaction and tell the peer we have it.
Coin value = COIN;
Transaction tx = createFakeTx(params, value, address);
InventoryMessage inv = new InventoryMessage(params);
Transaction tx = createFakeTx(PARAMS, value, address);
InventoryMessage inv = new InventoryMessage(PARAMS);
InventoryItem item = new InventoryItem(InventoryItem.Type.Transaction, tx.getHash());
inv.addItem(item);
inbound(writeTarget, inv);
@@ -272,7 +272,7 @@ public class PeerTest extends TestWithNetworkConnections {
inbound(writeTarget, tx);
// Ask for the dependency, it's not in the mempool (in chain).
getdata = (GetDataMessage) outbound(writeTarget);
inbound(writeTarget, new NotFoundMessage(params, getdata.getItems()));
inbound(writeTarget, new NotFoundMessage(PARAMS, getdata.getItems()));
pingAndWait(writeTarget);
assertEquals(value, wallet.getBalance(Wallet.BalanceType.ESTIMATED));
}
@@ -280,11 +280,11 @@ public class PeerTest extends TestWithNetworkConnections {
@Test
public void invDownloadTxMultiPeer() throws Exception {
// Check co-ordination of which peer to download via the memory pool.
VersionMessage ver = new VersionMessage(params, 100);
VersionMessage ver = new VersionMessage(PARAMS, 100);
InetSocketAddress address = new InetSocketAddress("127.0.0.1", 4242);
Peer peer2 = new Peer(params, ver, new PeerAddress(params, address), blockChain);
Peer peer2 = new Peer(PARAMS, ver, new PeerAddress(PARAMS, address), blockChain);
peer2.addWallet(wallet);
VersionMessage peerVersion = new VersionMessage(params, OTHER_PEER_CHAIN_HEIGHT);
VersionMessage peerVersion = new VersionMessage(PARAMS, OTHER_PEER_CHAIN_HEIGHT);
peerVersion.clientVersion = 70001;
peerVersion.localServices = VersionMessage.NODE_NETWORK;
@@ -293,8 +293,8 @@ public class PeerTest extends TestWithNetworkConnections {
// Make a tx and advertise it to one of the peers.
Coin value = COIN;
Transaction tx = createFakeTx(params, value, this.address);
InventoryMessage inv = new InventoryMessage(params);
Transaction tx = createFakeTx(PARAMS, value, this.address);
InventoryMessage inv = new InventoryMessage(PARAMS);
InventoryItem item = new InventoryItem(InventoryItem.Type.Transaction, tx.getHash());
inv.addItem(item);
@@ -319,7 +319,7 @@ public class PeerTest extends TestWithNetworkConnections {
blockChain.add(b1);
final Block b2 = makeSolvedTestBlock(b1);
// Receive notification of a new block.
final InventoryMessage inv = new InventoryMessage(params);
final InventoryMessage inv = new InventoryMessage(PARAMS);
InventoryItem item = new InventoryItem(InventoryItem.Type.Block, b2.getHash());
inv.addItem(item);
@@ -395,7 +395,7 @@ public class PeerTest extends TestWithNetworkConnections {
List<Sha256Hash> expectedLocator = new ArrayList<Sha256Hash>();
expectedLocator.add(b2.getHash());
expectedLocator.add(b1.getHash());
expectedLocator.add(params.getGenesisBlock().getHash());
expectedLocator.add(PARAMS.getGenesisBlock().getHash());
GetBlocksMessage message = (GetBlocksMessage) outbound(writeTarget);
assertEquals(message.getLocator(), expectedLocator);
@@ -431,9 +431,9 @@ public class PeerTest extends TestWithNetworkConnections {
Block b1 = createFakeBlock(blockStore, Block.BLOCK_HEIGHT_GENESIS).block;
blockChain.add(b1);
Block b2 = makeSolvedTestBlock(b1);
Transaction t = new Transaction(params);
Transaction t = new Transaction(PARAMS);
t.addInput(b1.getTransactions().get(0).getOutput(0));
t.addOutput(new TransactionOutput(params, t, Coin.ZERO, new byte[Block.MAX_BLOCK_SIZE - 1000]));
t.addOutput(new TransactionOutput(PARAMS, t, Coin.ZERO, new byte[Block.MAX_BLOCK_SIZE - 1000]));
b2.addTransaction(t);
// Request the block.
@@ -476,23 +476,23 @@ public class PeerTest extends TestWithNetworkConnections {
GetHeadersMessage getheaders = (GetHeadersMessage) outbound(writeTarget);
List<Sha256Hash> expectedLocator = new ArrayList<Sha256Hash>();
expectedLocator.add(b1.getHash());
expectedLocator.add(params.getGenesisBlock().getHash());
expectedLocator.add(PARAMS.getGenesisBlock().getHash());
assertEquals(getheaders.getLocator(), expectedLocator);
assertEquals(getheaders.getStopHash(), Sha256Hash.ZERO_HASH);
// Now send all the headers.
HeadersMessage headers = new HeadersMessage(params, b2.cloneAsHeader(),
HeadersMessage headers = new HeadersMessage(PARAMS, b2.cloneAsHeader(),
b3.cloneAsHeader(), b4.cloneAsHeader());
// We expect to be asked for b3 and b4 again, but this time, with a body.
expectedLocator.clear();
expectedLocator.add(b2.getHash());
expectedLocator.add(b1.getHash());
expectedLocator.add(params.getGenesisBlock().getHash());
expectedLocator.add(PARAMS.getGenesisBlock().getHash());
inbound(writeTarget, headers);
GetBlocksMessage getblocks = (GetBlocksMessage) outbound(writeTarget);
assertEquals(expectedLocator, getblocks.getLocator());
assertEquals(Sha256Hash.ZERO_HASH, getblocks.getStopHash());
// We're supposed to get an inv here.
InventoryMessage inv = new InventoryMessage(params);
InventoryMessage inv = new InventoryMessage(PARAMS);
inv.addItem(new InventoryItem(InventoryItem.Type.Block, b3.getHash()));
inbound(writeTarget, inv);
GetDataMessage getdata = (GetDataMessage) outbound(writeTarget);
@@ -539,7 +539,7 @@ public class PeerTest extends TestWithNetworkConnections {
peer.setDownloadTxDependencies(false);
connect();
// Check that if we request dependency download to be disabled and receive a relevant tx, things work correctly.
Transaction tx = FakeTxBuilder.createFakeTx(params, COIN, address);
Transaction tx = FakeTxBuilder.createFakeTx(PARAMS, COIN, address);
final Transaction[] result = new Transaction[1];
wallet.addCoinsReceivedEventListener(new WalletCoinsReceivedEventListener() {
@Override
@@ -572,29 +572,29 @@ 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(params, COIN, to);
Transaction t2 = FakeTxBuilder.createFakeTx(PARAMS, COIN, to);
Sha256Hash t5hash = t2.getInput(0).getOutpoint().getHash();
Transaction t4 = FakeTxBuilder.createFakeTx(params, COIN, new ECKey());
Transaction t4 = FakeTxBuilder.createFakeTx(PARAMS, COIN, new ECKey());
Sha256Hash t6hash = t4.getInput(0).getOutpoint().getHash();
t4.addOutput(COIN, new ECKey());
Transaction t3 = new Transaction(params);
Transaction t3 = new Transaction(PARAMS);
t3.addInput(t4.getOutput(0));
t3.addOutput(COIN, new ECKey());
Transaction t1 = new Transaction(params);
Transaction t1 = new Transaction(PARAMS);
t1.addInput(t2.getOutput(0));
t1.addInput(t3.getOutput(0));
Sha256Hash t7hash = Sha256Hash.wrap("2b801dd82f01d17bbde881687bf72bc62e2faa8ab8133d36fcb8c3abe7459da6");
t1.addInput(new TransactionInput(params, t1, new byte[]{}, new TransactionOutPoint(params, 0, t7hash)));
t1.addInput(new TransactionInput(PARAMS, t1, new byte[]{}, new TransactionOutPoint(PARAMS, 0, t7hash)));
Sha256Hash t8hash = Sha256Hash.wrap("3b801dd82f01d17bbde881687bf72bc62e2faa8ab8133d36fcb8c3abe7459da6");
t1.addInput(new TransactionInput(params, t1, new byte[]{}, new TransactionOutPoint(params, 1, t8hash)));
t1.addInput(new TransactionInput(PARAMS, t1, new byte[]{}, new TransactionOutPoint(PARAMS, 1, t8hash)));
t1.addOutput(COIN, to);
t1 = FakeTxBuilder.roundTripTransaction(params, t1);
t2 = FakeTxBuilder.roundTripTransaction(params, t2);
t3 = FakeTxBuilder.roundTripTransaction(params, t3);
t4 = FakeTxBuilder.roundTripTransaction(params, t4);
t1 = FakeTxBuilder.roundTripTransaction(PARAMS, t1);
t2 = FakeTxBuilder.roundTripTransaction(PARAMS, t2);
t3 = FakeTxBuilder.roundTripTransaction(PARAMS, t3);
t4 = FakeTxBuilder.roundTripTransaction(PARAMS, t4);
// Announce the first one. Wait for it to be downloaded.
InventoryMessage inv = new InventoryMessage(params);
InventoryMessage inv = new InventoryMessage(PARAMS);
inv.addTransaction(t1);
inbound(writeTarget, inv);
GetDataMessage getdata = (GetDataMessage) outbound(writeTarget);
@@ -616,7 +616,7 @@ public class PeerTest extends TestWithNetworkConnections {
// Deliver the requested transactions.
inbound(writeTarget, t2);
inbound(writeTarget, t3);
NotFoundMessage notFound = new NotFoundMessage(params);
NotFoundMessage notFound = new NotFoundMessage(PARAMS);
notFound.addItem(new InventoryItem(InventoryItem.Type.Transaction, t7hash));
notFound.addItem(new InventoryItem(InventoryItem.Type.Transaction, t8hash));
inbound(writeTarget, notFound);
@@ -625,7 +625,7 @@ public class PeerTest extends TestWithNetworkConnections {
getdata = (GetDataMessage) outbound(writeTarget);
assertEquals(getdata.getItems().get(0).hash, t2.getInput(0).getOutpoint().getHash());
// t5 isn't found and t4 is.
notFound = new NotFoundMessage(params);
notFound = new NotFoundMessage(PARAMS);
notFound.addItem(new InventoryItem(InventoryItem.Type.Transaction, t5hash));
inbound(writeTarget, notFound);
assertFalse(futures.isDone());
@@ -636,7 +636,7 @@ public class PeerTest extends TestWithNetworkConnections {
// Continue to explore the t4 branch and ask for t6, which is in the chain.
getdata = (GetDataMessage) outbound(writeTarget);
assertEquals(t6hash, getdata.getItems().get(0).hash);
notFound = new NotFoundMessage(params);
notFound = new NotFoundMessage(PARAMS);
notFound.addItem(new InventoryItem(InventoryItem.Type.Transaction, t6hash));
inbound(writeTarget, notFound);
pingAndWait(writeTarget);
@@ -658,21 +658,21 @@ public class PeerTest extends TestWithNetworkConnections {
// t1 -> t2 -> t3 -> [t4]
// The ones in brackets are assumed to be in the chain and are represented only by hashes.
Sha256Hash t4hash = Sha256Hash.wrap("2b801dd82f01d17bbde881687bf72bc62e2faa8ab8133d36fcb8c3abe7459da6");
Transaction t3 = new Transaction(params);
t3.addInput(new TransactionInput(params, t3, new byte[]{}, new TransactionOutPoint(params, 0, t4hash)));
Transaction t3 = new Transaction(PARAMS);
t3.addInput(new TransactionInput(PARAMS, t3, new byte[]{}, new TransactionOutPoint(PARAMS, 0, t4hash)));
t3.addOutput(COIN, new ECKey());
t3 = FakeTxBuilder.roundTripTransaction(params, t3);
Transaction t2 = new Transaction(params);
t3 = FakeTxBuilder.roundTripTransaction(PARAMS, t3);
Transaction t2 = new Transaction(PARAMS);
t2.addInput(t3.getOutput(0));
t2.addOutput(COIN, new ECKey());
t2 = FakeTxBuilder.roundTripTransaction(params, t2);
Transaction t1 = new Transaction(params);
t2 = FakeTxBuilder.roundTripTransaction(PARAMS, t2);
Transaction t1 = new Transaction(PARAMS);
t1.addInput(t2.getOutput(0));
t1.addOutput(COIN, new ECKey());
t1 = FakeTxBuilder.roundTripTransaction(params, t1);
t1 = FakeTxBuilder.roundTripTransaction(PARAMS, t1);
// Announce the first one. Wait for it to be downloaded.
InventoryMessage inv = new InventoryMessage(params);
InventoryMessage inv = new InventoryMessage(PARAMS);
inv.addTransaction(t1);
inbound(writeTarget, inv);
GetDataMessage getdata = (GetDataMessage) outbound(writeTarget);
@@ -705,7 +705,7 @@ public class PeerTest extends TestWithNetworkConnections {
connectWithVersion(70001, VersionMessage.NODE_NETWORK);
// Test that if we receive a relevant transaction that has a lock time, it doesn't result in a notification
// until we explicitly opt in to seeing those.
Wallet wallet = new Wallet(params);
Wallet wallet = new Wallet(PARAMS);
ECKey key = wallet.freshReceiveKey();
peer.addWallet(wallet);
final Transaction[] vtx = new Transaction[1];
@@ -716,16 +716,16 @@ public class PeerTest extends TestWithNetworkConnections {
}
});
// Send a normal relevant transaction, it's received correctly.
Transaction t1 = FakeTxBuilder.createFakeTx(params, COIN, key);
Transaction t1 = FakeTxBuilder.createFakeTx(PARAMS, COIN, key);
inbound(writeTarget, t1);
GetDataMessage getdata = (GetDataMessage) outbound(writeTarget);
inbound(writeTarget, new NotFoundMessage(params, getdata.getItems()));
inbound(writeTarget, new NotFoundMessage(PARAMS, getdata.getItems()));
pingAndWait(writeTarget);
Threading.waitForUserCode();
assertNotNull(vtx[0]);
vtx[0] = null;
// Send a timelocked transaction, nothing happens.
Transaction t2 = FakeTxBuilder.createFakeTx(params, valueOf(2, 0), key);
Transaction t2 = FakeTxBuilder.createFakeTx(PARAMS, valueOf(2, 0), key);
t2.setLockTime(999999);
inbound(writeTarget, t2);
Threading.waitForUserCode();
@@ -734,7 +734,7 @@ public class PeerTest extends TestWithNetworkConnections {
wallet.setAcceptRiskyTransactions(true);
inbound(writeTarget, t2);
getdata = (GetDataMessage) outbound(writeTarget);
inbound(writeTarget, new NotFoundMessage(params, getdata.getItems()));
inbound(writeTarget, new NotFoundMessage(PARAMS, getdata.getItems()));
pingAndWait(writeTarget);
Threading.waitForUserCode();
assertEquals(t2, vtx[0]);
@@ -756,7 +756,7 @@ public class PeerTest extends TestWithNetworkConnections {
private void checkTimeLockedDependency(boolean shouldAccept) throws Exception {
// Initial setup.
connectWithVersion(70001, VersionMessage.NODE_NETWORK);
Wallet wallet = new Wallet(params);
Wallet wallet = new Wallet(PARAMS);
ECKey key = wallet.freshReceiveKey();
wallet.setAcceptRiskyTransactions(shouldAccept);
peer.addWallet(wallet);
@@ -768,18 +768,18 @@ public class PeerTest extends TestWithNetworkConnections {
}
});
// t1 -> t2 [locked] -> t3 (not available)
Transaction t2 = new Transaction(params);
Transaction t2 = new Transaction(PARAMS);
t2.setLockTime(999999);
// Add a fake input to t3 that goes nowhere.
Sha256Hash t3 = Sha256Hash.of("abc".getBytes(Charset.forName("UTF-8")));
t2.addInput(new TransactionInput(params, t2, new byte[]{}, new TransactionOutPoint(params, 0, t3)));
t2.addInput(new TransactionInput(PARAMS, t2, new byte[]{}, new TransactionOutPoint(PARAMS, 0, t3)));
t2.getInput(0).setSequenceNumber(0xDEADBEEF);
t2.addOutput(COIN, new ECKey());
Transaction t1 = new Transaction(params);
Transaction t1 = new Transaction(PARAMS);
t1.addInput(t2.getOutput(0));
t1.addOutput(COIN, key); // Make it relevant.
// Announce t1.
InventoryMessage inv = new InventoryMessage(params);
InventoryMessage inv = new InventoryMessage(PARAMS);
inv.addTransaction(t1);
inbound(writeTarget, inv);
// Send it.
@@ -796,7 +796,7 @@ public class PeerTest extends TestWithNetworkConnections {
getdata = (GetDataMessage) outbound(writeTarget);
assertEquals(t3, getdata.getItems().get(0).hash);
// Can't find it: bottom of tree.
NotFoundMessage notFound = new NotFoundMessage(params);
NotFoundMessage notFound = new NotFoundMessage(PARAMS);
notFound.addItem(new InventoryItem(InventoryItem.Type.Transaction, t3));
inbound(writeTarget, notFound);
pingAndWait(writeTarget);
@@ -865,15 +865,15 @@ public class PeerTest extends TestWithNetworkConnections {
}
});
connect();
Transaction t1 = new Transaction(params);
t1.addInput(new TransactionInput(params, t1, new byte[]{}));
t1.addOutput(COIN, new ECKey().toAddress(params));
Transaction t2 = new Transaction(params);
Transaction t1 = new Transaction(PARAMS);
t1.addInput(new TransactionInput(PARAMS, t1, new byte[]{}));
t1.addOutput(COIN, new ECKey().toAddress(PARAMS));
Transaction t2 = new Transaction(PARAMS);
t2.addInput(t1.getOutput(0));
t2.addOutput(COIN, wallet.currentChangeAddress());
inbound(writeTarget, t2);
final InventoryItem inventoryItem = new InventoryItem(InventoryItem.Type.Transaction, t2.getInput(0).getOutpoint().getHash());
final NotFoundMessage nfm = new NotFoundMessage(params, Lists.newArrayList(inventoryItem));
final NotFoundMessage nfm = new NotFoundMessage(PARAMS, Lists.newArrayList(inventoryItem));
inbound(writeTarget, nfm);
pingAndWait(writeTarget);
Threading.waitForUserCode();
@@ -886,8 +886,8 @@ public class PeerTest extends TestWithNetworkConnections {
// Basic test of support for BIP 64: getutxos support. The Lighthouse unit tests exercise this stuff more
// thoroughly.
connectWithVersion(GetUTXOsMessage.MIN_PROTOCOL_VERSION, VersionMessage.NODE_NETWORK | VersionMessage.NODE_GETUTXOS);
TransactionOutPoint op1 = new TransactionOutPoint(params, 1, Sha256Hash.of("foo".getBytes()));
TransactionOutPoint op2 = new TransactionOutPoint(params, 2, Sha256Hash.of("bar".getBytes()));
TransactionOutPoint op1 = new TransactionOutPoint(PARAMS, 1, Sha256Hash.of("foo".getBytes()));
TransactionOutPoint op2 = new TransactionOutPoint(PARAMS, 2, Sha256Hash.of("bar".getBytes()));
ListenableFuture<UTXOsMessage> future1 = peer.getUTXOs(ImmutableList.of(op1));
ListenableFuture<UTXOsMessage> future2 = peer.getUTXOs(ImmutableList.of(op2));
@@ -902,13 +902,13 @@ public class PeerTest extends TestWithNetworkConnections {
assertFalse(future1.isDone());
ECKey key = new ECKey();
TransactionOutput out1 = new TransactionOutput(params, null, Coin.CENT, key);
UTXOsMessage response1 = new UTXOsMessage(params, ImmutableList.of(out1), new long[]{UTXOsMessage.MEMPOOL_HEIGHT}, Sha256Hash.ZERO_HASH, 1234);
TransactionOutput out1 = new TransactionOutput(PARAMS, null, Coin.CENT, key);
UTXOsMessage response1 = new UTXOsMessage(PARAMS, ImmutableList.of(out1), new long[]{UTXOsMessage.MEMPOOL_HEIGHT}, Sha256Hash.ZERO_HASH, 1234);
inbound(writeTarget, response1);
assertEquals(future1.get(), response1);
TransactionOutput out2 = new TransactionOutput(params, null, Coin.FIFTY_COINS, key);
UTXOsMessage response2 = new UTXOsMessage(params, ImmutableList.of(out2), new long[]{1000}, Sha256Hash.ZERO_HASH, 1234);
TransactionOutput out2 = new TransactionOutput(PARAMS, null, Coin.FIFTY_COINS, key);
UTXOsMessage response2 = new UTXOsMessage(PARAMS, ImmutableList.of(out2), new long[]{1000}, Sha256Hash.ZERO_HASH, 1234);
inbound(writeTarget, response2);
assertEquals(future2.get(), response2);
}
@@ -935,7 +935,7 @@ public class PeerTest extends TestWithNetworkConnections {
MessageSerializer serializer = params.getDefaultSerializer();
// Now write some bogus truncated message.
ByteArrayOutputStream out = new ByteArrayOutputStream();
serializer.serialize("inv", new InventoryMessage(params) {
serializer.serialize("inv", new InventoryMessage(PARAMS) {
@Override
public void bitcoinSerializeToStream(OutputStream stream) throws IOException {
// Add some hashes.

View File

@@ -64,7 +64,7 @@ public class TransactionBroadcastTest extends TestWithPeerGroup {
@Test
public void fourPeers() throws Exception {
InboundMessageQueuer[] channels = { connectPeer(1), connectPeer(2), connectPeer(3), connectPeer(4) };
Transaction tx = new Transaction(params);
Transaction tx = new Transaction(PARAMS);
tx.getConfidence().setSource(TransactionConfidence.Source.SELF);
TransactionBroadcast broadcast = new TransactionBroadcast(peerGroup, tx);
final AtomicDouble lastProgress = new AtomicDouble();
@@ -107,7 +107,7 @@ public class TransactionBroadcastTest extends TestWithPeerGroup {
// immediately with the latest state. This avoids API users writing accidentally racy code when they use
// a convenience method like peerGroup.broadcastTransaction.
InboundMessageQueuer[] channels = { connectPeer(1), connectPeer(2), connectPeer(3), connectPeer(4) };
Transaction tx = FakeTxBuilder.createFakeTx(params, CENT, address);
Transaction tx = FakeTxBuilder.createFakeTx(PARAMS, CENT, address);
tx.getConfidence().setSource(TransactionConfidence.Source.SELF);
TransactionBroadcast broadcast = peerGroup.broadcastTransaction(tx);
inbound(channels[1], InventoryMessage.with(tx));
@@ -125,14 +125,14 @@ public class TransactionBroadcastTest extends TestWithPeerGroup {
@Test
public void rejectHandling() throws Exception {
InboundMessageQueuer[] channels = { connectPeer(0), connectPeer(1), connectPeer(2), connectPeer(3), connectPeer(4) };
Transaction tx = new Transaction(params);
Transaction tx = new Transaction(PARAMS);
TransactionBroadcast broadcast = new TransactionBroadcast(peerGroup, tx);
ListenableFuture<Transaction> future = broadcast.broadcast();
// 0 and 3 are randomly selected to receive the broadcast.
assertEquals(tx, outbound(channels[1]));
assertEquals(tx, outbound(channels[2]));
assertEquals(tx, outbound(channels[4]));
RejectMessage reject = new RejectMessage(params, RejectMessage.RejectCode.DUST, tx.getHash(), "tx", "dust");
RejectMessage reject = new RejectMessage(PARAMS, RejectMessage.RejectCode.DUST, tx.getHash(), "tx", "dust");
inbound(channels[1], reject);
inbound(channels[4], reject);
try {
@@ -157,7 +157,7 @@ public class TransactionBroadcastTest extends TestWithPeerGroup {
assertEquals(FIFTY_COINS, wallet.getBalance());
// Now create a spend, and expect the announcement on p1.
Address dest = new ECKey().toAddress(params);
Address dest = new ECKey().toAddress(PARAMS);
Wallet.SendResult sendResult = wallet.sendCoins(peerGroup, dest, COIN);
assertFalse(sendResult.broadcastComplete.isDone());
Transaction t1;
@@ -184,7 +184,7 @@ public class TransactionBroadcastTest extends TestWithPeerGroup {
// Make sure we can create spends, and that they are announced. Then do the same with offline mode.
// Set up connections and block chain.
VersionMessage ver = new VersionMessage(params, 2);
VersionMessage ver = new VersionMessage(PARAMS, 2);
ver.localServices = VersionMessage.NODE_NETWORK;
InboundMessageQueuer p1 = connectPeer(1, ver);
InboundMessageQueuer p2 = connectPeer(2);
@@ -206,7 +206,7 @@ public class TransactionBroadcastTest extends TestWithPeerGroup {
});
// Now create a spend, and expect the announcement on p1.
Address dest = new ECKey().toAddress(params);
Address dest = new ECKey().toAddress(PARAMS);
Wallet.SendResult sendResult = wallet.sendCoins(peerGroup, dest, COIN);
assertNotNull(sendResult.tx);
Threading.waitForUserCode();
@@ -227,7 +227,7 @@ public class TransactionBroadcastTest extends TestWithPeerGroup {
// 49 BTC in change.
assertEquals(valueOf(49, 0), t1.getValueSentToMe(wallet));
// The future won't complete until it's heard back from the network on p2.
InventoryMessage inv = new InventoryMessage(params);
InventoryMessage inv = new InventoryMessage(PARAMS);
inv.addTransaction(t1);
inbound(p2, inv);
pingAndWait(p2);

View File

@@ -35,7 +35,7 @@ public class TransactionOutputTest extends TestWithWallet {
ECKey otherKey = new ECKey();
// Create multi-sig transaction
Transaction multiSigTransaction = new Transaction(params);
Transaction multiSigTransaction = new Transaction(PARAMS);
ImmutableList<ECKey> keys = ImmutableList.of(myKey, otherKey);
Script scriptPubKey = ScriptBuilder.createMultiSigOutputScript(2, keys);
@@ -63,7 +63,7 @@ public class TransactionOutputTest extends TestWithWallet {
Transaction tx = new Transaction(MainNetParams.get());
Script script = new ScriptBuilder().op(ScriptOpCodes.OP_RETURN).data("hello world!".getBytes()).build();
tx.addOutput(Coin.CENT, script);
assertNull(tx.getOutput(0).getAddressFromP2SH(params));
assertNull(tx.getOutput(0).getAddressFromP2PKHScript(params));
assertNull(tx.getOutput(0).getAddressFromP2SH(PARAMS));
assertNull(tx.getOutput(0).getAddressFromP2PKHScript(PARAMS));
}
}

View File

@@ -27,7 +27,7 @@ import static org.bitcoinj.core.Coin.*;
import static org.junit.Assert.*;
public class TxConfidenceTableTest {
private NetworkParameters params = UnitTestParams.get();
private static final NetworkParameters PARAMS = UnitTestParams.get();
private Transaction tx1, tx2;
private PeerAddress address1, address2, address3;
private TxConfidenceTable table;
@@ -35,24 +35,24 @@ public class TxConfidenceTableTest {
@Before
public void setup() throws Exception {
BriefLogFormatter.init();
Context context = new Context(params);
Context context = new Context(PARAMS);
table = context.getConfidenceTable();
Address to = new ECKey().toAddress(params);
Address change = new ECKey().toAddress(params);
Address to = new ECKey().toAddress(PARAMS);
Address change = new ECKey().toAddress(PARAMS);
tx1 = FakeTxBuilder.createFakeTxWithChangeAddress(params, COIN, to, change);
tx2 = FakeTxBuilder.createFakeTxWithChangeAddress(params, COIN, to, change);
tx1 = FakeTxBuilder.createFakeTxWithChangeAddress(PARAMS, COIN, to, change);
tx2 = FakeTxBuilder.createFakeTxWithChangeAddress(PARAMS, COIN, to, change);
assertEquals(tx1.getHash(), tx2.getHash());
address1 = new PeerAddress(params, InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 }));
address2 = new PeerAddress(params, InetAddress.getByAddress(new byte[] { 127, 0, 0, 2 }));
address3 = new PeerAddress(params, InetAddress.getByAddress(new byte[] { 127, 0, 0, 3 }));
address1 = new PeerAddress(PARAMS, InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 }));
address2 = new PeerAddress(PARAMS, InetAddress.getByAddress(new byte[] { 127, 0, 0, 2 }));
address3 = new PeerAddress(PARAMS, InetAddress.getByAddress(new byte[] { 127, 0, 0, 3 }));
}
@Test
public void pinHandlers() throws Exception {
Transaction tx = params.getDefaultSerializer().makeTransaction(tx1.bitcoinSerialize());
Transaction tx = PARAMS.getDefaultSerializer().makeTransaction(tx1.bitcoinSerialize());
Sha256Hash hash = tx.getHash();
table.seen(hash, address1);
assertEquals(1, tx.getConfidence().numBroadcastPeers());

File diff suppressed because it is too large Load Diff

View File

@@ -105,7 +105,7 @@ public class ChannelConnectionTest extends TestWithWallet {
sendMoneyToWallet(COIN, AbstractBlockChain.NewBlockType.BEST_CHAIN);
sendMoneyToWallet(COIN, AbstractBlockChain.NewBlockType.BEST_CHAIN);
wallet.addExtension(new StoredPaymentChannelClientStates(wallet, failBroadcaster));
Context context = new Context(params, 3); // Shorter event horizon for unit tests.
Context context = new Context(PARAMS, 3); // Shorter event horizon for unit tests.
serverWallet = new Wallet(context);
serverWallet.addExtension(new StoredPaymentChannelServerStates(serverWallet, failBroadcaster));
serverWallet.freshReceiveKey();
@@ -667,7 +667,7 @@ public class ChannelConnectionTest extends TestWithWallet {
.setType(MessageType.INITIATE).build());
if (useRefunds()) {
final Protos.TwoWayChannelMessage provideRefund = pair.clientRecorder.checkNextMsg(MessageType.PROVIDE_REFUND);
Transaction refund = new Transaction(params, provideRefund.getProvideRefund().getTx().toByteArray());
Transaction refund = new Transaction(PARAMS, provideRefund.getProvideRefund().getTx().toByteArray());
assertEquals(myValue, refund.getOutput(0).getValue());
} else {
assertEquals(2, client.state().getMajorVersion());
@@ -678,7 +678,7 @@ public class ChannelConnectionTest extends TestWithWallet {
@Test
public void testEmptyWallet() throws Exception {
Wallet emptyWallet = new Wallet(params);
Wallet emptyWallet = new Wallet(PARAMS);
emptyWallet.freshReceiveKey();
ChannelTestUtils.RecordingPair pair = ChannelTestUtils.makeRecorders(serverWallet, mockBroadcaster);
PaymentChannelServer server = pair.server;
@@ -846,7 +846,7 @@ public class ChannelConnectionTest extends TestWithWallet {
Transaction settlement1 = broadcasts.take();
// Server sends back the settle TX it just broadcast.
final Protos.TwoWayChannelMessage closeMsg = pair.serverRecorder.checkNextMsg(MessageType.CLOSE);
final Transaction settlement2 = new Transaction(params, closeMsg.getSettlement().getTx().toByteArray());
final Transaction settlement2 = new Transaction(PARAMS, closeMsg.getSettlement().getTx().toByteArray());
assertEquals(settlement1, settlement2);
client.receiveMessage(closeMsg);
assertNotNull(wallet.getTransaction(settlement2.getHash())); // Close TX entered the wallet.

View File

@@ -96,8 +96,8 @@ public class PaymentChannelStateTest extends TestWithWallet {
}
}));
sendMoneyToWallet(COIN, AbstractBlockChain.NewBlockType.BEST_CHAIN);
chain = new BlockChain(params, wallet, blockStore); // Recreate chain as sendMoneyToWallet will confuse it
serverWallet = new Wallet(params);
chain = new BlockChain(PARAMS, wallet, blockStore); // Recreate chain as sendMoneyToWallet will confuse it
serverWallet = new Wallet(PARAMS);
serverKey = serverWallet.freshReceiveKey();
chain.addWallet(serverWallet);
halfCoin = valueOf(0, 50);
@@ -234,7 +234,7 @@ public class PaymentChannelStateTest extends TestWithWallet {
// Send the refund tx from client to server and get back the signature.
Transaction refund;
if (useRefunds()) {
refund = new Transaction(params, clientV1State().getIncompleteRefundTransaction().bitcoinSerialize());
refund = new Transaction(PARAMS, clientV1State().getIncompleteRefundTransaction().bitcoinSerialize());
byte[] refundSig = serverV1State().provideRefundTransaction(refund, myKey.getPubKey());
assertEquals(PaymentChannelServerState.State.WAITING_FOR_MULTISIG_CONTRACT, serverState.getState());
// This verifies that the refund can spend the multi-sig output when run.
@@ -247,7 +247,7 @@ public class PaymentChannelStateTest extends TestWithWallet {
assertEquals(PaymentChannelClientState.State.PROVIDE_MULTISIG_CONTRACT_TO_SERVER, clientState.getState());
// Validate the multisig contract looks right.
Transaction multisigContract = new Transaction(params, clientState.getContract().bitcoinSerialize());
Transaction multisigContract = new Transaction(PARAMS, clientState.getContract().bitcoinSerialize());
assertEquals(PaymentChannelClientState.State.READY, clientState.getState());
assertEquals(2, multisigContract.getOutputs().size()); // One multi-sig, one change.
Script script = multisigContract.getOutput(0).getScriptPubKey();
@@ -305,7 +305,7 @@ public class PaymentChannelStateTest extends TestWithWallet {
final TxFuturePair pair2 = broadcasts.take();
Transaction closeTx = pair2.tx;
pair2.future.set(closeTx);
final Transaction reserializedCloseTx = new Transaction(params, closeTx.bitcoinSerialize());
final Transaction reserializedCloseTx = new Transaction(PARAMS, closeTx.bitcoinSerialize());
assertEquals(PaymentChannelServerState.State.CLOSED, serverState.getState());
// ... and on the client side.
wallet.receivePending(reserializedCloseTx, null);
@@ -337,9 +337,9 @@ public class PaymentChannelStateTest extends TestWithWallet {
// we can broadcast the refund and get our balance back.
// Spend the client wallet's one coin
Transaction spendCoinTx = wallet.sendCoinsOffline(Wallet.SendRequest.to(new ECKey().toAddress(params), COIN));
Transaction spendCoinTx = wallet.sendCoinsOffline(Wallet.SendRequest.to(new ECKey().toAddress(PARAMS), COIN));
assertEquals(Coin.ZERO, wallet.getBalance());
chain.add(makeSolvedTestBlock(blockStore.getChainHead().getHeader(), spendCoinTx, createFakeTx(params, CENT, myAddress)));
chain.add(makeSolvedTestBlock(blockStore.getChainHead().getHeader(), spendCoinTx, createFakeTx(PARAMS, CENT, myAddress)));
assertEquals(CENT, wallet.getBalance());
// Set the wallet's stored states to use our real test PeerGroup
@@ -363,7 +363,7 @@ public class PaymentChannelStateTest extends TestWithWallet {
if (useRefunds()) {
// Send the refund tx from client to server and get back the signature.
Transaction refund = new Transaction(params, clientV1State().getIncompleteRefundTransaction().bitcoinSerialize());
Transaction refund = new Transaction(PARAMS, clientV1State().getIncompleteRefundTransaction().bitcoinSerialize());
byte[] refundSig = serverV1State().provideRefundTransaction(refund, myKey.getPubKey());
assertEquals(PaymentChannelServerState.State.WAITING_FOR_MULTISIG_CONTRACT, serverState.getState());
// This verifies that the refund can spend the multi-sig output when run.
@@ -374,7 +374,7 @@ public class PaymentChannelStateTest extends TestWithWallet {
assertEquals(PaymentChannelClientState.State.PROVIDE_MULTISIG_CONTRACT_TO_SERVER, clientState.getState());
// Validate the multisig contract looks right.
Transaction multisigContract = new Transaction(params, clientState.getContract().bitcoinSerialize());
Transaction multisigContract = new Transaction(PARAMS, clientState.getContract().bitcoinSerialize());
assertEquals(PaymentChannelClientState.State.READY, clientState.getState());
assertEquals(2, multisigContract.getOutputs().size()); // One multi-sig, one change.
Script script = multisigContract.getOutput(0).getScriptPubKey();
@@ -470,23 +470,23 @@ public class PaymentChannelStateTest extends TestWithWallet {
if (useRefunds()) {
// Test refund transaction with any number of issues
byte[] refundTxBytes = clientV1State().getIncompleteRefundTransaction().bitcoinSerialize();
Transaction refund = new Transaction(params, refundTxBytes);
refund.addOutput(Coin.ZERO, new ECKey().toAddress(params));
Transaction refund = new Transaction(PARAMS, refundTxBytes);
refund.addOutput(Coin.ZERO, new ECKey().toAddress(PARAMS));
try {
serverV1State().provideRefundTransaction(refund, myKey.getPubKey());
fail();
} catch (VerificationException e) {
}
refund = new Transaction(params, refundTxBytes);
refund.addInput(new TransactionInput(params, refund, new byte[]{}, new TransactionOutPoint(params, 42, refund.getHash())));
refund = new Transaction(PARAMS, refundTxBytes);
refund.addInput(new TransactionInput(PARAMS, refund, new byte[]{}, new TransactionOutPoint(PARAMS, 42, refund.getHash())));
try {
serverV1State().provideRefundTransaction(refund, myKey.getPubKey());
fail();
} catch (VerificationException e) {
}
refund = new Transaction(params, refundTxBytes);
refund = new Transaction(PARAMS, refundTxBytes);
refund.setLockTime(0);
try {
serverV1State().provideRefundTransaction(refund, myKey.getPubKey());
@@ -494,7 +494,7 @@ public class PaymentChannelStateTest extends TestWithWallet {
} catch (VerificationException e) {
}
refund = new Transaction(params, refundTxBytes);
refund = new Transaction(PARAMS, refundTxBytes);
refund.getInput(0).setSequenceNumber(TransactionInput.NO_SEQUENCE);
try {
serverV1State().provideRefundTransaction(refund, myKey.getPubKey());
@@ -502,7 +502,7 @@ public class PaymentChannelStateTest extends TestWithWallet {
} catch (VerificationException e) {
}
refund = new Transaction(params, refundTxBytes);
refund = new Transaction(PARAMS, refundTxBytes);
byte[] refundSig = serverV1State().provideRefundTransaction(refund, myKey.getPubKey());
try {
serverV1State().provideRefundTransaction(refund, myKey.getPubKey());
@@ -563,7 +563,7 @@ public class PaymentChannelStateTest extends TestWithWallet {
byte[] multisigContractSerialized = clientState.getContract().bitcoinSerialize();
Transaction multisigContract = new Transaction(params, multisigContractSerialized);
Transaction multisigContract = new Transaction(PARAMS, multisigContractSerialized);
multisigContract.clearOutputs();
// Swap order of client and server keys to check correct failure
if (versionSelector == PaymentChannelClient.VersionSelector.VERSION_1) {
@@ -580,7 +580,7 @@ public class PaymentChannelStateTest extends TestWithWallet {
assertTrue(e.getMessage().contains("client and server in that order"));
}
multisigContract = new Transaction(params, multisigContractSerialized);
multisigContract = new Transaction(PARAMS, multisigContractSerialized);
multisigContract.clearOutputs();
if (versionSelector == PaymentChannelClient.VersionSelector.VERSION_1) {
multisigContract.addOutput(Coin.ZERO, ScriptBuilder.createMultiSigOutputScript(2, Lists.newArrayList(myKey, serverKey)));
@@ -596,15 +596,15 @@ public class PaymentChannelStateTest extends TestWithWallet {
assertTrue(e.getMessage().contains("zero value"));
}
multisigContract = new Transaction(params, multisigContractSerialized);
multisigContract = new Transaction(PARAMS, multisigContractSerialized);
multisigContract.clearOutputs();
multisigContract.addOutput(new TransactionOutput(params, multisigContract, halfCoin, new byte[] {0x01}));
multisigContract.addOutput(new TransactionOutput(PARAMS, multisigContract, halfCoin, new byte[] {0x01}));
try {
serverState.provideContract(multisigContract);
fail();
} catch (VerificationException e) {}
multisigContract = new Transaction(params, multisigContractSerialized);
multisigContract = new Transaction(PARAMS, multisigContractSerialized);
ListenableFuture<PaymentChannelServerState> multisigStateFuture = serverState.provideContract(multisigContract);
try { serverState.provideContract(multisigContract); fail(); } catch (IllegalStateException e) {}
assertEquals(PaymentChannelServerState.State.WAITING_FOR_MULTISIG_ACCEPTANCE, serverState.getState());
@@ -689,10 +689,10 @@ public class PaymentChannelStateTest extends TestWithWallet {
// Test that transactions are getting the necessary fees
// Spend the client wallet's one coin
wallet.sendCoinsOffline(Wallet.SendRequest.to(new ECKey().toAddress(params), COIN));
wallet.sendCoinsOffline(Wallet.SendRequest.to(new ECKey().toAddress(PARAMS), COIN));
assertEquals(Coin.ZERO, wallet.getBalance());
chain.add(makeSolvedTestBlock(blockStore.getChainHead().getHeader(), createFakeTx(params, CENT, myAddress)));
chain.add(makeSolvedTestBlock(blockStore.getChainHead().getHeader(), createFakeTx(PARAMS, CENT, myAddress)));
assertEquals(CENT, wallet.getBalance());
Utils.setMockClock(); // Use mock clock
@@ -736,7 +736,7 @@ public class PaymentChannelStateTest extends TestWithWallet {
if (useRefunds()) {
// Send the refund tx from client to server and get back the signature.
Transaction refund = new Transaction(params, clientV1State().getIncompleteRefundTransaction().bitcoinSerialize());
Transaction refund = new Transaction(PARAMS, clientV1State().getIncompleteRefundTransaction().bitcoinSerialize());
byte[] refundSig = serverV1State().provideRefundTransaction(refund, myKey.getPubKey());
assertEquals(PaymentChannelServerState.State.WAITING_FOR_MULTISIG_CONTRACT, serverState.getState());
// This verifies that the refund can spend the multi-sig output when run.
@@ -747,7 +747,7 @@ public class PaymentChannelStateTest extends TestWithWallet {
assertEquals(PaymentChannelClientState.State.PROVIDE_MULTISIG_CONTRACT_TO_SERVER, clientState.getState());
// Get the multisig contract
Transaction multisigContract = new Transaction(params, clientState.getContract().bitcoinSerialize());
Transaction multisigContract = new Transaction(PARAMS, clientState.getContract().bitcoinSerialize());
assertEquals(PaymentChannelClientState.State.READY, clientState.getState());
// Provide the server with the multisig contract and simulate successful propagation/acceptance.
@@ -834,7 +834,7 @@ public class PaymentChannelStateTest extends TestWithWallet {
if (useRefunds()) {
// Send the refund tx from client to server and get back the signature.
Transaction refund = new Transaction(params, clientV1State().getIncompleteRefundTransaction().bitcoinSerialize());
Transaction refund = new Transaction(PARAMS, clientV1State().getIncompleteRefundTransaction().bitcoinSerialize());
byte[] refundSig = serverV1State().provideRefundTransaction(refund, myKey.getPubKey());
assertEquals(PaymentChannelServerState.State.WAITING_FOR_MULTISIG_CONTRACT, serverState.getState());
// This verifies that the refund can spend the multi-sig output when run.
@@ -845,7 +845,7 @@ public class PaymentChannelStateTest extends TestWithWallet {
assertEquals(PaymentChannelClientState.State.PROVIDE_MULTISIG_CONTRACT_TO_SERVER, clientState.getState());
// Validate the multisig contract looks right.
Transaction multisigContract = new Transaction(params, clientState.getContract().bitcoinSerialize());
Transaction multisigContract = new Transaction(PARAMS, clientState.getContract().bitcoinSerialize());
assertEquals(PaymentChannelV1ClientState.State.READY, clientState.getState());
assertEquals(2, multisigContract.getOutputs().size()); // One multi-sig, one change.
Script script = multisigContract.getOutput(0).getScriptPubKey();
@@ -882,8 +882,8 @@ public class PaymentChannelStateTest extends TestWithWallet {
}
// Now give the server enough coins to pay the fee
StoredBlock block = new StoredBlock(makeSolvedTestBlock(blockStore, new ECKey().toAddress(params)), BigInteger.ONE, 1);
Transaction tx1 = createFakeTx(params, COIN, serverKey.toAddress(params));
StoredBlock block = new StoredBlock(makeSolvedTestBlock(blockStore, new ECKey().toAddress(PARAMS)), BigInteger.ONE, 1);
Transaction tx1 = createFakeTx(PARAMS, COIN, serverKey.toAddress(PARAMS));
serverWallet.receiveFromBlock(tx1, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, 0);
// The contract is still not worth redeeming - its worth less than we pay in fee
@@ -924,7 +924,7 @@ public class PaymentChannelStateTest extends TestWithWallet {
Transaction refund;
if (useRefunds()) {
refund = new Transaction(params, clientV1State().getIncompleteRefundTransaction().bitcoinSerialize());
refund = new Transaction(PARAMS, clientV1State().getIncompleteRefundTransaction().bitcoinSerialize());
// Send the refund tx from client to server and get back the signature.
byte[] refundSig = serverV1State().provideRefundTransaction(refund, myKey.getPubKey());
assertEquals(PaymentChannelV1ServerState.State.WAITING_FOR_MULTISIG_CONTRACT, serverState.getState());
@@ -938,7 +938,7 @@ public class PaymentChannelStateTest extends TestWithWallet {
assertEquals(PaymentChannelClientState.State.PROVIDE_MULTISIG_CONTRACT_TO_SERVER, clientState.getState());
// Validate the multisig contract looks right.
Transaction multisigContract = new Transaction(params, clientState.getContract().bitcoinSerialize());
Transaction multisigContract = new Transaction(PARAMS, clientState.getContract().bitcoinSerialize());
assertEquals(PaymentChannelClientState.State.READY, clientState.getState());
assertEquals(2, multisigContract.getOutputs().size()); // One multi-sig, one change.
Script script = multisigContract.getOutput(0).getScriptPubKey();
@@ -984,13 +984,13 @@ public class PaymentChannelStateTest extends TestWithWallet {
}
// Now create a double-spend and send it to the server
Transaction doubleSpendContract = new Transaction(params);
doubleSpendContract.addInput(new TransactionInput(params, doubleSpendContract, new byte[0],
Transaction doubleSpendContract = new Transaction(PARAMS);
doubleSpendContract.addInput(new TransactionInput(PARAMS, doubleSpendContract, new byte[0],
multisigContract.getInput(0).getOutpoint()));
doubleSpendContract.addOutput(halfCoin, myKey);
doubleSpendContract = new Transaction(params, doubleSpendContract.bitcoinSerialize());
doubleSpendContract = new Transaction(PARAMS, doubleSpendContract.bitcoinSerialize());
StoredBlock block = new StoredBlock(params.getGenesisBlock().createNextBlock(myKey.toAddress(params)), BigInteger.TEN, 1);
StoredBlock block = new StoredBlock(PARAMS.getGenesisBlock().createNextBlock(myKey.toAddress(PARAMS)), BigInteger.TEN, 1);
serverWallet.receiveFromBlock(doubleSpendContract, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, 0);
// Now if we try to spend again the server will reject it since it saw a double-spend

View File

@@ -36,7 +36,7 @@ import static org.bitcoinj.core.Coin.COIN;
import static org.junit.Assert.*;
public class PaymentSessionTest {
private static final NetworkParameters params = TestNet3Params.get();
private static final NetworkParameters PARAMS = TestNet3Params.get();
private static final String simplePaymentUrl = "http://a.simple.url.com/";
private static final String paymentRequestMemo = "send coinz noa plz kthx";
private static final String paymentMemo = "take ze coinz";
@@ -50,8 +50,8 @@ public class PaymentSessionTest {
@Before
public void setUp() throws Exception {
serverKey = new ECKey();
tx = new Transaction(params);
outputToMe = new TransactionOutput(params, tx, coin, serverKey);
tx = new Transaction(PARAMS);
outputToMe = new TransactionOutput(PARAMS, tx, coin, serverKey);
tx.addOutput(outputToMe);
}
@@ -68,10 +68,10 @@ public class PaymentSessionTest {
// Send the payment and verify that the correct information is sent.
// Add a dummy input to tx so it is considered valid.
tx.addInput(new TransactionInput(params, tx, outputToMe.getScriptBytes()));
tx.addInput(new TransactionInput(PARAMS, tx, outputToMe.getScriptBytes()));
ArrayList<Transaction> txns = new ArrayList<Transaction>();
txns.add(tx);
Address refundAddr = new Address(params, serverKey.getPubKeyHash());
Address refundAddr = new Address(PARAMS, serverKey.getPubKeyHash());
paymentSession.sendPayment(txns, refundAddr, paymentMemo);
assertEquals(1, paymentSession.getPaymentLog().size());
assertEquals(simplePaymentUrl, paymentSession.getPaymentLog().get(0).getUrl().toString());
@@ -80,7 +80,7 @@ public class PaymentSessionTest {
assertEquals(merchantData, payment.getMerchantData());
assertEquals(1, payment.getRefundToCount());
assertEquals(coin.value, payment.getRefundTo(0).getAmount());
TransactionOutput refundOutput = new TransactionOutput(params, null, coin, refundAddr);
TransactionOutput refundOutput = new TransactionOutput(PARAMS, null, coin, refundAddr);
ByteString refundScript = ByteString.copyFrom(refundOutput.getScriptBytes());
assertTrue(refundScript.equals(payment.getRefundTo(0).getScript()));
}
@@ -108,7 +108,7 @@ public class PaymentSessionTest {
assertTrue(paymentSession.isExpired());
// Send the payment and verify that an exception is thrown.
// Add a dummy input to tx so it is considered valid.
tx.addInput(new TransactionInput(params, tx, outputToMe.getScriptBytes()));
tx.addInput(new TransactionInput(PARAMS, tx, outputToMe.getScriptBytes()));
ArrayList<Transaction> txns = new ArrayList<Transaction>();
txns.add(tx);
try {
@@ -139,10 +139,10 @@ public class PaymentSessionTest {
// Send the payment and verify that the correct information is sent.
// Add a dummy input to tx so it is considered valid.
tx.addInput(new TransactionInput(params, tx, outputToMe.getScriptBytes()));
tx.addInput(new TransactionInput(PARAMS, tx, outputToMe.getScriptBytes()));
ArrayList<Transaction> txns = new ArrayList<Transaction>();
txns.add(tx);
Address refundAddr = new Address(params, serverKey.getPubKeyHash());
Address refundAddr = new Address(PARAMS, serverKey.getPubKeyHash());
paymentSession.sendPayment(txns, refundAddr, paymentMemo);
assertEquals(1, paymentSession.getPaymentLog().size());
}

View File

@@ -55,13 +55,13 @@ public class ScriptTest {
static final String pubkeyProg = "76a91433e81a941e64cda12c6a299ed322ddbdd03f8d0e88ac";
static final NetworkParameters params = TestNet3Params.get();
private static final NetworkParameters PARAMS = TestNet3Params.get();
private static final Logger log = LoggerFactory.getLogger(ScriptTest.class);
@Before
public void setUp() throws Exception {
Context context = new Context(params);
Context context = new Context(PARAMS);
}
@Test
@@ -70,7 +70,7 @@ public class ScriptTest {
Script script = new Script(sigProgBytes);
// Test we can extract the from address.
byte[] hash160 = Utils.sha256hash160(script.getPubKey());
Address a = new Address(params, hash160);
Address a = new Address(PARAMS, hash160);
assertEquals("mkFQohBpy2HDXrCwyMrYL5RtfrmeiuuPY2", a.toString());
}
@@ -80,7 +80,7 @@ public class ScriptTest {
byte[] pubkeyBytes = HEX.decode(pubkeyProg);
Script pubkey = new Script(pubkeyBytes);
assertEquals("DUP HASH160 PUSHDATA(20)[33e81a941e64cda12c6a299ed322ddbdd03f8d0e] EQUALVERIFY CHECKSIG", pubkey.toString());
Address toAddr = new Address(params, pubkey.getPubKeyHash());
Address toAddr = new Address(PARAMS, pubkey.getPubKeyHash());
assertEquals("mkFQohBpy2HDXrCwyMrYL5RtfrmeiuuPY2", toAddr.toString());
}
@@ -126,15 +126,15 @@ public class ScriptTest {
@Test
public void testCreateMultiSigInputScript() {
// Setup transaction and signatures
ECKey key1 = DumpedPrivateKey.fromBase58(params, "cVLwRLTvz3BxDAWkvS3yzT9pUcTCup7kQnfT2smRjvmmm1wAP6QT").getKey();
ECKey key2 = DumpedPrivateKey.fromBase58(params, "cTine92s8GLpVqvebi8rYce3FrUYq78ZGQffBYCS1HmDPJdSTxUo").getKey();
ECKey key3 = DumpedPrivateKey.fromBase58(params, "cVHwXSPRZmL9adctwBwmn4oTZdZMbaCsR5XF6VznqMgcvt1FDDxg").getKey();
ECKey key1 = DumpedPrivateKey.fromBase58(PARAMS, "cVLwRLTvz3BxDAWkvS3yzT9pUcTCup7kQnfT2smRjvmmm1wAP6QT").getKey();
ECKey key2 = DumpedPrivateKey.fromBase58(PARAMS, "cTine92s8GLpVqvebi8rYce3FrUYq78ZGQffBYCS1HmDPJdSTxUo").getKey();
ECKey key3 = DumpedPrivateKey.fromBase58(PARAMS, "cVHwXSPRZmL9adctwBwmn4oTZdZMbaCsR5XF6VznqMgcvt1FDDxg").getKey();
Script multisigScript = ScriptBuilder.createMultiSigOutputScript(2, Arrays.asList(key1, key2, key3));
byte[] bytes = HEX.decode("01000000013df681ff83b43b6585fa32dd0e12b0b502e6481e04ee52ff0fdaf55a16a4ef61000000006b483045022100a84acca7906c13c5895a1314c165d33621cdcf8696145080895cbf301119b7cf0220730ff511106aa0e0a8570ff00ee57d7a6f24e30f592a10cae1deffac9e13b990012102b8d567bcd6328fd48a429f9cf4b315b859a58fd28c5088ef3cb1d98125fc4e8dffffffff02364f1c00000000001976a91439a02793b418de8ec748dd75382656453dc99bcb88ac40420f000000000017a9145780b80be32e117f675d6e0ada13ba799bf248e98700000000");
Transaction transaction = params.getDefaultSerializer().makeTransaction(bytes);
Transaction transaction = PARAMS.getDefaultSerializer().makeTransaction(bytes);
TransactionOutput output = transaction.getOutput(1);
Transaction spendTx = new Transaction(params);
Address address = Address.fromBase58(params, "n3CFiCmBXVt5d3HXKQ15EFZyhPz4yj5F3H");
Transaction spendTx = new Transaction(PARAMS);
Address address = Address.fromBase58(PARAMS, "n3CFiCmBXVt5d3HXKQ15EFZyhPz4yj5F3H");
Script outputScript = ScriptBuilder.createOutputScript(address);
spendTx.addOutput(output.getValue(), outputScript);
spendTx.addInput(output);
@@ -224,8 +224,8 @@ public class ScriptTest {
@Test
public void testOp0() {
// Check that OP_0 doesn't NPE and pushes an empty stack frame.
Transaction tx = new Transaction(params);
tx.addInput(new TransactionInput(params, tx, new byte[] {}));
Transaction tx = new Transaction(PARAMS);
tx.addInput(new TransactionInput(PARAMS, tx, new byte[] {}));
Script script = new ScriptBuilder().smallNum(0).build();
LinkedList<byte[]> stack = new LinkedList<byte[]>();
@@ -292,7 +292,7 @@ public class ScriptTest {
Script scriptPubKey = parseScriptString(test.get(1).asText());
Set<VerifyFlag> verifyFlags = parseVerifyFlags(test.get(2).asText());
try {
scriptSig.correctlySpends(new Transaction(params), 0, scriptPubKey, verifyFlags);
scriptSig.correctlySpends(new Transaction(PARAMS), 0, scriptPubKey, verifyFlags);
} catch (ScriptException e) {
System.err.println(test);
System.err.flush();
@@ -310,7 +310,7 @@ public class ScriptTest {
Script scriptSig = parseScriptString(test.get(0).asText());
Script scriptPubKey = parseScriptString(test.get(1).asText());
Set<VerifyFlag> verifyFlags = parseVerifyFlags(test.get(2).asText());
scriptSig.correctlySpends(new Transaction(params), 0, scriptPubKey, verifyFlags);
scriptSig.correctlySpends(new Transaction(PARAMS), 0, scriptPubKey, verifyFlags);
System.err.println(test);
System.err.flush();
fail();
@@ -327,7 +327,7 @@ public class ScriptTest {
int index = input.get(1).asInt();
String script = input.get(2).asText();
Sha256Hash sha256Hash = Sha256Hash.wrap(HEX.decode(hash));
scriptPubKeys.put(new TransactionOutPoint(params, index, sha256Hash), parseScriptString(script));
scriptPubKeys.put(new TransactionOutPoint(PARAMS, index, sha256Hash), parseScriptString(script));
}
return scriptPubKeys;
}
@@ -342,7 +342,7 @@ public class ScriptTest {
Transaction transaction = null;
try {
Map<TransactionOutPoint, Script> scriptPubKeys = parseScriptPubKeys(test.get(0));
transaction = params.getDefaultSerializer().makeTransaction(HEX.decode(test.get(1).asText().toLowerCase()));
transaction = PARAMS.getDefaultSerializer().makeTransaction(HEX.decode(test.get(1).asText().toLowerCase()));
transaction.verify();
Set<VerifyFlag> verifyFlags = parseVerifyFlags(test.get(2).asText());
@@ -371,7 +371,7 @@ public class ScriptTest {
if (test.isArray() && test.size() == 1 && test.get(0).isTextual())
continue; // This is a comment.
Map<TransactionOutPoint, Script> scriptPubKeys = parseScriptPubKeys(test.get(0));
Transaction transaction = params.getDefaultSerializer().makeTransaction(HEX.decode(test.get(1).asText().toLowerCase()));
Transaction transaction = PARAMS.getDefaultSerializer().makeTransaction(HEX.decode(test.get(1).asText().toLowerCase()));
Set<VerifyFlag> verifyFlags = parseVerifyFlags(test.get(2).asText());
boolean valid = true;
@@ -416,19 +416,19 @@ public class ScriptTest {
public void getToAddress() throws Exception {
// pay to pubkey
ECKey toKey = new ECKey();
Address toAddress = toKey.toAddress(params);
assertEquals(toAddress, ScriptBuilder.createOutputScript(toKey).getToAddress(params, true));
Address toAddress = toKey.toAddress(PARAMS);
assertEquals(toAddress, ScriptBuilder.createOutputScript(toKey).getToAddress(PARAMS, true));
// pay to pubkey hash
assertEquals(toAddress, ScriptBuilder.createOutputScript(toAddress).getToAddress(params, true));
assertEquals(toAddress, ScriptBuilder.createOutputScript(toAddress).getToAddress(PARAMS, true));
// pay to script hash
Script p2shScript = ScriptBuilder.createP2SHOutputScript(new byte[20]);
Address scriptAddress = Address.fromP2SHScript(params, p2shScript);
assertEquals(scriptAddress, p2shScript.getToAddress(params, true));
Address scriptAddress = Address.fromP2SHScript(PARAMS, p2shScript);
assertEquals(scriptAddress, p2shScript.getToAddress(PARAMS, true));
}
@Test(expected = ScriptException.class)
public void getToAddressNoPubKey() throws Exception {
ScriptBuilder.createOutputScript(new ECKey()).getToAddress(params, false);
ScriptBuilder.createOutputScript(new ECKey()).getToAddress(PARAMS, false);
}
/** Test encoding of zero, which should result in an opcode */

View File

@@ -53,7 +53,7 @@ import static org.bitcoinj.testing.FakeTxBuilder.createFakeTx;
import static org.junit.Assert.*;
public class WalletProtobufSerializerTest {
static final NetworkParameters params = UnitTestParams.get();
private static final NetworkParameters PARAMS = UnitTestParams.get();
private ECKey myKey;
private ECKey myWatchedKey;
private Address myAddress;
@@ -65,17 +65,17 @@ public class WalletProtobufSerializerTest {
@Before
public void setUp() throws Exception {
BriefLogFormatter.initVerbose();
Context ctx = new Context(params);
Context ctx = new Context(PARAMS);
myWatchedKey = new ECKey();
myWallet = new Wallet(params);
myWallet = new Wallet(PARAMS);
myKey = new ECKey();
myKey.setCreationTimeSeconds(123456789L);
myWallet.importKey(myKey);
myAddress = myKey.toAddress(params);
myWallet = new Wallet(params);
myAddress = myKey.toAddress(PARAMS);
myWallet = new Wallet(PARAMS);
myWallet.importKey(myKey);
mScriptCreationTime = new Date().getTime() / 1000 - 1234;
myWallet.addWatchedAddress(myWatchedKey.toAddress(params), mScriptCreationTime);
myWallet.addWatchedAddress(myWatchedKey.toAddress(PARAMS), mScriptCreationTime);
myWallet.setDescription(WALLET_DESCRIPTION);
}
@@ -94,7 +94,7 @@ public class WalletProtobufSerializerTest {
assertEquals(mScriptCreationTime,
wallet1.getWatchedScripts().get(0).getCreationTimeSeconds());
assertEquals(1, wallet1.getWatchedScripts().size());
assertEquals(ScriptBuilder.createOutputScript(myWatchedKey.toAddress(params)),
assertEquals(ScriptBuilder.createOutputScript(myWatchedKey.toAddress(PARAMS)),
wallet1.getWatchedScripts().get(0));
assertEquals(WALLET_DESCRIPTION, wallet1.getDescription());
}
@@ -103,9 +103,9 @@ public class WalletProtobufSerializerTest {
public void oneTx() throws Exception {
// Check basic tx serialization.
Coin v1 = COIN;
Transaction t1 = createFakeTx(params, v1, myAddress);
t1.getConfidence().markBroadcastBy(new PeerAddress(params, InetAddress.getByName("1.2.3.4")));
t1.getConfidence().markBroadcastBy(new PeerAddress(params, InetAddress.getByName("5.6.7.8")));
Transaction t1 = createFakeTx(PARAMS, v1, myAddress);
t1.getConfidence().markBroadcastBy(new PeerAddress(PARAMS, InetAddress.getByName("1.2.3.4")));
t1.getConfidence().markBroadcastBy(new PeerAddress(PARAMS, InetAddress.getByName("5.6.7.8")));
t1.getConfidence().setSource(TransactionConfidence.Source.NETWORK);
myWallet.receivePending(t1, null);
Wallet wallet1 = roundTrip(myWallet);
@@ -139,7 +139,7 @@ public class WalletProtobufSerializerTest {
public void raiseFeeTx() throws Exception {
// Check basic tx serialization.
Coin v1 = COIN;
Transaction t1 = createFakeTx(params, v1, myAddress);
Transaction t1 = createFakeTx(PARAMS, v1, myAddress);
t1.setPurpose(Purpose.RAISE_FEE);
myWallet.receivePending(t1, null);
Wallet wallet1 = roundTrip(myWallet);
@@ -150,7 +150,7 @@ public class WalletProtobufSerializerTest {
@Test
public void doubleSpend() throws Exception {
// Check that we can serialize double spends correctly, as this is a slightly tricky case.
FakeTxBuilder.DoubleSpends doubleSpends = FakeTxBuilder.createFakeDoubleSpendTxns(params, myAddress);
FakeTxBuilder.DoubleSpends doubleSpends = FakeTxBuilder.createFakeDoubleSpendTxns(PARAMS, myAddress);
// t1 spends to our wallet.
myWallet.receivePending(doubleSpends.t1, null);
// t2 rolls back t1 and spends somewhere else.
@@ -169,8 +169,8 @@ public class WalletProtobufSerializerTest {
public void testKeys() throws Exception {
for (int i = 0 ; i < 20 ; i++) {
myKey = new ECKey();
myAddress = myKey.toAddress(params);
myWallet = new Wallet(params);
myAddress = myKey.toAddress(PARAMS);
myWallet = new Wallet(PARAMS);
myWallet.importKey(myKey);
Wallet wallet1 = roundTrip(myWallet);
assertArrayEquals(myKey.getPubKey(), wallet1.findKeyFromPubHash(myKey.getPubKeyHash()).getPubKey());
@@ -183,13 +183,13 @@ public class WalletProtobufSerializerTest {
// Test the lastBlockSeenHash field works.
// LastBlockSeenHash should be empty if never set.
Wallet wallet = new Wallet(params);
Wallet wallet = new Wallet(PARAMS);
Protos.Wallet walletProto = new WalletProtobufSerializer().walletToProto(wallet);
ByteString lastSeenBlockHash = walletProto.getLastSeenBlockHash();
assertTrue(lastSeenBlockHash.isEmpty());
// Create a block.
Block block = params.getDefaultSerializer().makeBlock(BlockTest.blockBytes);
Block block = PARAMS.getDefaultSerializer().makeBlock(BlockTest.blockBytes);
Sha256Hash blockHash = block.getHash();
wallet.setLastBlockSeenHash(blockHash);
wallet.setLastBlockSeenHeight(1);
@@ -210,7 +210,7 @@ public class WalletProtobufSerializerTest {
public void testAppearedAtChainHeightDepthAndWorkDone() throws Exception {
// Test the TransactionConfidence appearedAtChainHeight, depth and workDone field are stored.
BlockChain chain = new BlockChain(params, myWallet, new MemoryBlockStore(params));
BlockChain chain = new BlockChain(PARAMS, myWallet, new MemoryBlockStore(PARAMS));
final ArrayList<Transaction> txns = new ArrayList<Transaction>(2);
myWallet.addCoinsReceivedEventListener(new WalletCoinsReceivedEventListener() {
@@ -221,7 +221,7 @@ public class WalletProtobufSerializerTest {
});
// Start by building two blocks on top of the genesis block.
Block b1 = params.getGenesisBlock().createNextBlock(myAddress);
Block b1 = PARAMS.getGenesisBlock().createNextBlock(myAddress);
BigInteger work1 = b1.getWork();
assertTrue(work1.signum() > 0);
@@ -303,9 +303,9 @@ public class WalletProtobufSerializerTest {
@Test
public void testRoundTripMarriedWallet() throws Exception {
// create 2-of-2 married wallet
myWallet = new Wallet(params);
myWallet = new Wallet(PARAMS);
final DeterministicKeyChain partnerChain = new DeterministicKeyChain(new SecureRandom());
DeterministicKey partnerKey = DeterministicKey.deserializeB58(null, partnerChain.getWatchingKey().serializePubB58(params), params);
DeterministicKey partnerKey = DeterministicKey.deserializeB58(null, partnerChain.getWatchingKey().serializePubB58(PARAMS), PARAMS);
MarriedKeyChain chain = MarriedKeyChain.builder()
.random(new SecureRandom())
.followingKeys(partnerKey)
@@ -324,10 +324,10 @@ 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(Block.BLOCK_VERSION_GENESIS, myKey.getPubKey(), FIFTY_COINS, Block.BLOCK_HEIGHT_GENESIS);
Block b = PARAMS.getGenesisBlock().createNextBlockWithCoinbase(Block.BLOCK_VERSION_GENESIS, myKey.getPubKey(), FIFTY_COINS, Block.BLOCK_HEIGHT_GENESIS);
Transaction coinbase = b.getTransactions().get(0);
assertTrue(coinbase.isCoinBase());
BlockChain chain = new BlockChain(params, myWallet, new MemoryBlockStore(params));
BlockChain chain = new BlockChain(PARAMS, myWallet, new MemoryBlockStore(PARAMS));
assertTrue(chain.add(b));
// Wallet now has a coinbase tx in it.
assertEquals(1, myWallet.getTransactions(true).size());
@@ -351,21 +351,21 @@ public class WalletProtobufSerializerTest {
Protos.Wallet proto = new WalletProtobufSerializer().walletToProto(myWallet);
// Initial extension is mandatory: try to read it back into a wallet that doesn't know about it.
try {
new WalletProtobufSerializer().readWallet(params, null, proto);
new WalletProtobufSerializer().readWallet(PARAMS, null, proto);
fail();
} catch (UnreadableWalletException e) {
assertTrue(e.getMessage().contains("mandatory"));
}
Wallet wallet = new WalletProtobufSerializer().readWallet(params,
Wallet wallet = new WalletProtobufSerializer().readWallet(PARAMS,
new WalletExtension[]{ new FooWalletExtension("com.whatever.required", true) },
proto);
assertTrue(wallet.getExtensions().containsKey("com.whatever.required"));
// Non-mandatory extensions are ignored if the wallet doesn't know how to read them.
Wallet wallet2 = new Wallet(params);
Wallet wallet2 = new Wallet(PARAMS);
wallet2.addExtension(new FooWalletExtension("com.whatever.optional", false));
Protos.Wallet proto2 = new WalletProtobufSerializer().walletToProto(wallet2);
Wallet wallet5 = new WalletProtobufSerializer().readWallet(params, null, proto2);
Wallet wallet5 = new WalletProtobufSerializer().readWallet(PARAMS, null, proto2);
assertEquals(0, wallet5.getExtensions().size());
}
@@ -394,7 +394,7 @@ public class WalletProtobufSerializerTest {
};
myWallet.addExtension(extension);
Protos.Wallet proto = new WalletProtobufSerializer().walletToProto(myWallet);
Wallet wallet = new WalletProtobufSerializer().readWallet(params, new WalletExtension[]{extension}, proto);
Wallet wallet = new WalletProtobufSerializer().readWallet(PARAMS, new WalletExtension[]{extension}, proto);
assertEquals(0, wallet.getExtensions().size());
}
@@ -402,6 +402,6 @@ public class WalletProtobufSerializerTest {
public void versions() throws Exception {
Protos.Wallet.Builder proto = Protos.Wallet.newBuilder(new WalletProtobufSerializer().walletToProto(myWallet));
proto.setVersion(2);
new WalletProtobufSerializer().readWallet(params, null, proto.build());
new WalletProtobufSerializer().readWallet(PARAMS, null, proto.build());
}
}

View File

@@ -46,7 +46,7 @@ import static com.google.common.base.Preconditions.checkState;
*/
public class TestWithNetworkConnections {
public static final int PEER_SERVERS = 5;
protected final NetworkParameters params = UnitTestParams.get();
protected static final NetworkParameters PARAMS = UnitTestParams.get();
protected Context context;
protected BlockStore blockStore;
protected BlockChain blockChain;
@@ -83,16 +83,16 @@ public class TestWithNetworkConnections {
public void setUp(BlockStore blockStore) throws Exception {
BriefLogFormatter.init();
context = new Context(params);
context = new Context(PARAMS);
Wallet.SendRequest.DEFAULT_FEE_PER_KB = Coin.ZERO;
this.blockStore = blockStore;
// Allow subclasses to override the wallet object with their own.
if (wallet == null) {
wallet = new Wallet(params);
wallet = new Wallet(PARAMS);
key = wallet.freshReceiveKey();
address = key.toAddress(params);
address = key.toAddress(PARAMS);
}
blockChain = new BlockChain(params, wallet, blockStore);
blockChain = new BlockChain(PARAMS, wallet, blockStore);
startPeerServers();
if (clientType == ClientType.NIO_CLIENT_MANAGER || clientType == ClientType.BLOCKING_CLIENT_MANAGER) {
@@ -114,7 +114,7 @@ public class TestWithNetworkConnections {
@Nullable
@Override
public StreamConnection getNewConnection(InetAddress inetAddress, int port) {
return new InboundMessageQueuer(params) {
return new InboundMessageQueuer(PARAMS) {
@Override
public void connectionClosed() {
}

View File

@@ -48,14 +48,14 @@ public class TestWithPeerGroup extends TestWithNetworkConnections {
@Override
public void setUp() throws Exception {
setUp(new MemoryBlockStore(params));
setUp(new MemoryBlockStore(PARAMS));
}
@Override
public void setUp(BlockStore blockStore) throws Exception {
super.setUp(blockStore);
remoteVersionMessage = new VersionMessage(params, 1);
remoteVersionMessage = new VersionMessage(PARAMS, 1);
remoteVersionMessage.localServices = VersionMessage.NODE_NETWORK;
remoteVersionMessage.clientVersion = NotFoundMessage.MIN_PROTOCOL_VERSION;
blockJobs = false;
@@ -89,7 +89,7 @@ public class TestWithPeerGroup extends TestWithNetworkConnections {
protected final Semaphore jobBlocks = new Semaphore(0);
private PeerGroup createPeerGroup(final ClientConnectionManager manager) {
return new PeerGroup(params, blockChain, manager) {
return new PeerGroup(PARAMS, blockChain, manager) {
@Override
protected ListeningScheduledExecutorService createPrivateExecutor() {
return MoreExecutors.listeningDecorator(new ScheduledThreadPoolExecutor(1, new ContextPropagatingThreadFactory("PeerGroup test thread")) {

View File

@@ -38,7 +38,7 @@ import static org.bitcoinj.testing.FakeTxBuilder.createFakeTx;
* {@link Transaction#REFERENCE_DEFAULT_MIN_TX_FEE} before doing so.
*/
public class TestWithWallet {
protected static final NetworkParameters params = UnitTestParams.get();
protected static final NetworkParameters PARAMS = UnitTestParams.get();
protected ECKey myKey;
protected Address myAddress;
protected Wallet wallet;
@@ -48,12 +48,12 @@ public class TestWithWallet {
public void setUp() throws Exception {
BriefLogFormatter.init();
Wallet.SendRequest.DEFAULT_FEE_PER_KB = Coin.ZERO;
Context ctx = new Context(params);
wallet = new Wallet(params);
Context ctx = new Context(PARAMS);
wallet = new Wallet(PARAMS);
myKey = wallet.currentReceiveKey();
myAddress = myKey.toAddress(params);
blockStore = new MemoryBlockStore(params);
chain = new BlockChain(params, wallet, blockStore);
myAddress = myKey.toAddress(PARAMS);
blockStore = new MemoryBlockStore(PARAMS);
chain = new BlockChain(PARAMS, wallet, blockStore);
}
public void tearDown() throws Exception {
@@ -83,16 +83,16 @@ public class TestWithWallet {
@Nullable
protected Transaction sendMoneyToWallet(Wallet wallet, Coin value, Address toAddress, AbstractBlockChain.NewBlockType type) throws VerificationException {
return sendMoneyToWallet(wallet, createFakeTx(params, value, toAddress), type);
return sendMoneyToWallet(wallet, createFakeTx(PARAMS, value, toAddress), type);
}
@Nullable
protected Transaction sendMoneyToWallet(Wallet wallet, Coin value, ECKey toPubKey, AbstractBlockChain.NewBlockType type) throws VerificationException {
return sendMoneyToWallet(wallet, createFakeTx(params, value, toPubKey), type);
return sendMoneyToWallet(wallet, createFakeTx(PARAMS, value, toPubKey), type);
}
@Nullable
protected Transaction sendMoneyToWallet(Coin value, AbstractBlockChain.NewBlockType type) throws VerificationException {
return sendMoneyToWallet(this.wallet, createFakeTx(params, value, myAddress), type);
return sendMoneyToWallet(this.wallet, createFakeTx(PARAMS, value, myAddress), type);
}
}

View File

@@ -29,7 +29,7 @@ import static org.bitcoinj.core.Coin.*;
import static org.junit.Assert.*;
public class DefaultCoinSelectorTest extends TestWithWallet {
private static final NetworkParameters params = UnitTestParams.get();
private static final NetworkParameters PARAMS = UnitTestParams.get();
@Before
@Override
@@ -47,16 +47,16 @@ public class DefaultCoinSelectorTest extends TestWithWallet {
@Test
public void selectable() throws Exception {
Transaction t;
t = new Transaction(params);
t = new Transaction(PARAMS);
t.getConfidence().setConfidenceType(TransactionConfidence.ConfidenceType.PENDING);
assertFalse(DefaultCoinSelector.isSelectable(t));
t.getConfidence().setSource(TransactionConfidence.Source.SELF);
assertFalse(DefaultCoinSelector.isSelectable(t));
t.getConfidence().markBroadcastBy(new PeerAddress(params, InetAddress.getByName("1.2.3.4")));
t.getConfidence().markBroadcastBy(new PeerAddress(PARAMS, InetAddress.getByName("1.2.3.4")));
assertFalse(DefaultCoinSelector.isSelectable(t));
t.getConfidence().markBroadcastBy(new PeerAddress(params, InetAddress.getByName("5.6.7.8")));
t.getConfidence().markBroadcastBy(new PeerAddress(PARAMS, InetAddress.getByName("5.6.7.8")));
assertTrue(DefaultCoinSelector.isSelectable(t));
t = new Transaction(params);
t = new Transaction(PARAMS);
t.getConfidence().setConfidenceType(TransactionConfidence.ConfidenceType.BUILDING);
assertTrue(DefaultCoinSelector.isSelectable(t));
t = new Transaction(RegTestParams.get());
@@ -111,12 +111,12 @@ public class DefaultCoinSelectorTest extends TestWithWallet {
@Test
public void identicalInputs() throws Exception {
// Add four outputs to a transaction with same value and destination. Select them all.
Transaction t = new Transaction(params);
Transaction t = new Transaction(PARAMS);
java.util.List<TransactionOutput> outputs = Arrays.asList(
new TransactionOutput(params, t, Coin.valueOf(30302787), myAddress),
new TransactionOutput(params, t, Coin.valueOf(30302787), myAddress),
new TransactionOutput(params, t, Coin.valueOf(30302787), myAddress),
new TransactionOutput(params, t, Coin.valueOf(30302787), myAddress)
new TransactionOutput(PARAMS, t, Coin.valueOf(30302787), myAddress),
new TransactionOutput(PARAMS, t, Coin.valueOf(30302787), myAddress),
new TransactionOutput(PARAMS, t, Coin.valueOf(30302787), myAddress),
new TransactionOutput(PARAMS, t, Coin.valueOf(30302787), myAddress)
);
t.getConfidence().setConfidenceType(TransactionConfidence.ConfidenceType.BUILDING);

View File

@@ -34,7 +34,7 @@ import static org.junit.Assert.*;
public class DefaultRiskAnalysisTest {
// Uses mainnet because isStandard checks are disabled on testnet.
private static final NetworkParameters params = MainNetParams.get();
private static final NetworkParameters PARAMS = MainNetParams.get();
private Wallet wallet;
private final int TIMESTAMP = 1384190189;
private static final ECKey key1 = new ECKey();
@@ -42,7 +42,7 @@ public class DefaultRiskAnalysisTest {
@Before
public void setup() {
wallet = new Wallet(new Context(params)) {
wallet = new Wallet(new Context(PARAMS)) {
@Override
public int getLastBlockSeenHeight() {
return 1000;
@@ -57,7 +57,7 @@ public class DefaultRiskAnalysisTest {
@Test(expected = IllegalStateException.class)
public void analysisCantBeUsedTwice() {
Transaction tx = new Transaction(params);
Transaction tx = new Transaction(PARAMS);
DefaultRiskAnalysis analysis = DefaultRiskAnalysis.FACTORY.create(wallet, tx, NO_DEPS);
assertEquals(RiskAnalysis.Result.OK, analysis.analyze());
assertNull(analysis.getNonFinal());
@@ -68,8 +68,8 @@ public class DefaultRiskAnalysisTest {
@Test
public void nonFinal() throws Exception {
// Verify that just having a lock time in the future is not enough to be considered risky (it's still final).
Transaction tx = new Transaction(params);
TransactionInput input = tx.addInput(params.getGenesisBlock().getTransactions().get(0).getOutput(0));
Transaction tx = new Transaction(PARAMS);
TransactionInput input = tx.addInput(PARAMS.getGenesisBlock().getTransactions().get(0).getOutput(0));
tx.addOutput(COIN, key1);
tx.setLockTime(TIMESTAMP + 86400);
DefaultRiskAnalysis analysis = DefaultRiskAnalysis.FACTORY.create(wallet, tx, NO_DEPS);
@@ -90,8 +90,8 @@ public class DefaultRiskAnalysisTest {
@Test
public void selfCreatedAreNotRisky() {
Transaction tx = new Transaction(params);
tx.addInput(params.getGenesisBlock().getTransactions().get(0).getOutput(0)).setSequenceNumber(1);
Transaction tx = new Transaction(PARAMS);
tx.addInput(PARAMS.getGenesisBlock().getTransactions().get(0).getOutput(0)).setSequenceNumber(1);
tx.addOutput(COIN, key1);
tx.setLockTime(TIMESTAMP + 86400);
@@ -111,11 +111,11 @@ public class DefaultRiskAnalysisTest {
@Test
public void nonFinalDependency() {
// Final tx has a dependency that is non-final.
Transaction tx1 = new Transaction(params);
tx1.addInput(params.getGenesisBlock().getTransactions().get(0).getOutput(0)).setSequenceNumber(1);
Transaction tx1 = new Transaction(PARAMS);
tx1.addInput(PARAMS.getGenesisBlock().getTransactions().get(0).getOutput(0)).setSequenceNumber(1);
TransactionOutput output = tx1.addOutput(COIN, key1);
tx1.setLockTime(TIMESTAMP + 86400);
Transaction tx2 = new Transaction(params);
Transaction tx2 = new Transaction(PARAMS);
tx2.addInput(output);
tx2.addOutput(COIN, new ECKey());
@@ -126,18 +126,18 @@ public class DefaultRiskAnalysisTest {
@Test
public void nonStandardDust() {
Transaction standardTx = new Transaction(params);
standardTx.addInput(params.getGenesisBlock().getTransactions().get(0).getOutput(0));
Transaction standardTx = new Transaction(PARAMS);
standardTx.addInput(PARAMS.getGenesisBlock().getTransactions().get(0).getOutput(0));
standardTx.addOutput(COIN, key1);
assertEquals(RiskAnalysis.Result.OK, DefaultRiskAnalysis.FACTORY.create(wallet, standardTx, NO_DEPS).analyze());
Transaction dustTx = new Transaction(params);
dustTx.addInput(params.getGenesisBlock().getTransactions().get(0).getOutput(0));
Transaction dustTx = new Transaction(PARAMS);
dustTx.addInput(PARAMS.getGenesisBlock().getTransactions().get(0).getOutput(0));
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);
edgeCaseTx.addInput(params.getGenesisBlock().getTransactions().get(0).getOutput(0));
Transaction edgeCaseTx = new Transaction(PARAMS);
edgeCaseTx.addInput(PARAMS.getGenesisBlock().getTransactions().get(0).getOutput(0));
edgeCaseTx.addOutput(DefaultRiskAnalysis.MIN_ANALYSIS_NONDUST_OUTPUT, key1); // Dust threshold
assertEquals(RiskAnalysis.Result.OK, DefaultRiskAnalysis.FACTORY.create(wallet, edgeCaseTx, NO_DEPS).analyze());
}
@@ -147,14 +147,14 @@ public class DefaultRiskAnalysisTest {
ScriptChunk nonStandardChunk = new ScriptChunk(OP_PUSHDATA1, new byte[75]);
byte[] nonStandardScript = new ScriptBuilder().addChunk(nonStandardChunk).build().getProgram();
// Test non-standard script as an input.
Transaction tx = new Transaction(params);
Transaction tx = new Transaction(PARAMS);
assertEquals(DefaultRiskAnalysis.RuleViolation.NONE, DefaultRiskAnalysis.isStandard(tx));
tx.addInput(new TransactionInput(params, null, nonStandardScript));
tx.addInput(new TransactionInput(PARAMS, null, nonStandardScript));
assertEquals(DefaultRiskAnalysis.RuleViolation.SHORTEST_POSSIBLE_PUSHDATA, DefaultRiskAnalysis.isStandard(tx));
// Test non-standard script as an output.
tx.clearInputs();
assertEquals(DefaultRiskAnalysis.RuleViolation.NONE, DefaultRiskAnalysis.isStandard(tx));
tx.addOutput(new TransactionOutput(params, null, COIN, nonStandardScript));
tx.addOutput(new TransactionOutput(PARAMS, null, COIN, nonStandardScript));
assertEquals(DefaultRiskAnalysis.RuleViolation.SHORTEST_POSSIBLE_PUSHDATA, DefaultRiskAnalysis.isStandard(tx));
}
@@ -163,14 +163,14 @@ public class DefaultRiskAnalysisTest {
TransactionSignature sig = TransactionSignature.dummy();
Script scriptOk = ScriptBuilder.createInputScript(sig);
assertEquals(RuleViolation.NONE,
DefaultRiskAnalysis.isInputStandard(new TransactionInput(params, null, scriptOk.getProgram())));
DefaultRiskAnalysis.isInputStandard(new TransactionInput(PARAMS, null, scriptOk.getProgram())));
byte[] sigBytes = sig.encodeToBitcoin();
// Appending a zero byte makes the signature uncanonical without violating DER encoding.
Script scriptUncanonicalEncoding = new ScriptBuilder().data(Arrays.copyOf(sigBytes, sigBytes.length + 1))
.build();
assertEquals(RuleViolation.SIGNATURE_CANONICAL_ENCODING,
DefaultRiskAnalysis.isInputStandard(new TransactionInput(params, null, scriptUncanonicalEncoding
DefaultRiskAnalysis.isInputStandard(new TransactionInput(PARAMS, null, scriptUncanonicalEncoding
.getProgram())));
}
@@ -181,10 +181,10 @@ public class DefaultRiskAnalysisTest {
Script scriptHighS = ScriptBuilder
.createInputScript(new TransactionSignature(sig.r, ECKey.CURVE.getN().subtract(sig.s)));
assertEquals(RuleViolation.SIGNATURE_CANONICAL_ENCODING,
DefaultRiskAnalysis.isInputStandard(new TransactionInput(params, null, scriptHighS.getProgram())));
DefaultRiskAnalysis.isInputStandard(new TransactionInput(PARAMS, null, scriptHighS.getProgram())));
// This is a real transaction. Its signatures S component is "low".
Transaction tx1 = new Transaction(params, Utils.HEX.decode(
Transaction tx1 = new Transaction(PARAMS, Utils.HEX.decode(
"010000000200a2be4376b7f47250ad9ad3a83b6aa5eb6a6d139a1f50771704d77aeb8ce76c010000006a4730440220055723d363cd2d4fe4e887270ebdf5c4b99eaf233a5c09f9404f888ec8b839350220763c3794d310b384ce86decfb05787e5bfa5d31983db612a2dde5ffec7f396ae012102ef47e27e0c4bdd6dc83915f185d972d5eb8515c34d17bad584a9312e59f4e0bcffffffff52239451d37757eeacb86d32864ec1ee6b6e131d1e3fee6f1cff512703b71014030000006b483045022100ea266ac4f893d98a623a6fc0e6a961cd5a3f32696721e87e7570a68851917e75022056d75c3b767419f6f6cb8189a0ad78d45971523908dc4892f7594b75fd43a8d00121038bb455ca101ebbb0ecf7f5c01fa1dcb7d14fbf6b7d7ea52ee56f0148e72a736cffffffff0630b15a00000000001976a9146ae477b690cf85f21c2c01e2c8639a5c18dc884e88ac4f260d00000000001976a91498d08c02ab92a671590adb726dddb719695ee12e88ac65753b00000000001976a9140b2eb4ba6d364c82092f25775f56bc10cd92c8f188ac65753b00000000001976a914d1cb414e22081c6ba3a935635c0f1d837d3c5d9188ac65753b00000000001976a914df9d137a0d279471a2796291874c29759071340b88ac3d753b00000000001976a91459f5aa4815e3aa8e1720e8b82f4ac8e6e904e47d88ac00000000"));
assertEquals("2a1c8569b2b01ebac647fb94444d1118d4d00e327456a3c518e40d47d72cd5fe", tx1.getHashAsString());
@@ -192,7 +192,7 @@ public class DefaultRiskAnalysisTest {
// This tx is the same as the above, except for a "high" S component on the signature of input 1.
// It was part of the Oct 2015 malleability attack.
Transaction tx2 = new Transaction(params, Utils.HEX.decode(
Transaction tx2 = new Transaction(PARAMS, Utils.HEX.decode(
"010000000200a2be4376b7f47250ad9ad3a83b6aa5eb6a6d139a1f50771704d77aeb8ce76c010000006a4730440220055723d363cd2d4fe4e887270ebdf5c4b99eaf233a5c09f9404f888ec8b839350220763c3794d310b384ce86decfb05787e5bfa5d31983db612a2dde5ffec7f396ae012102ef47e27e0c4bdd6dc83915f185d972d5eb8515c34d17bad584a9312e59f4e0bcffffffff52239451d37757eeacb86d32864ec1ee6b6e131d1e3fee6f1cff512703b71014030000006c493046022100ea266ac4f893d98a623a6fc0e6a961cd5a3f32696721e87e7570a68851917e75022100a928a3c4898be60909347e765f52872a613d8aada66c57a8c8791316d2f298710121038bb455ca101ebbb0ecf7f5c01fa1dcb7d14fbf6b7d7ea52ee56f0148e72a736cffffffff0630b15a00000000001976a9146ae477b690cf85f21c2c01e2c8639a5c18dc884e88ac4f260d00000000001976a91498d08c02ab92a671590adb726dddb719695ee12e88ac65753b00000000001976a9140b2eb4ba6d364c82092f25775f56bc10cd92c8f188ac65753b00000000001976a914d1cb414e22081c6ba3a935635c0f1d837d3c5d9188ac65753b00000000001976a914df9d137a0d279471a2796291874c29759071340b88ac3d753b00000000001976a91459f5aa4815e3aa8e1720e8b82f4ac8e6e904e47d88ac00000000"));
assertEquals("dbe4147cf89b89fd9fa6c8ce6a3e2adecb234db094ec88301ae09073ca17d61d", tx2.getHashAsString());
assertFalse(ECKey.ECDSASignature
@@ -204,10 +204,10 @@ public class DefaultRiskAnalysisTest {
@Test
public void standardOutputs() throws Exception {
Transaction tx = new Transaction(params);
tx.addInput(params.getGenesisBlock().getTransactions().get(0).getOutput(0));
Transaction tx = new Transaction(PARAMS);
tx.addInput(PARAMS.getGenesisBlock().getTransactions().get(0).getOutput(0));
// A pay to address output
tx.addOutput(Coin.CENT, ScriptBuilder.createOutputScript(key1.toAddress(params)));
tx.addOutput(Coin.CENT, ScriptBuilder.createOutputScript(key1.toAddress(PARAMS)));
// A pay to pubkey output
tx.addOutput(Coin.CENT, ScriptBuilder.createOutputScript(key1));
tx.addOutput(Coin.CENT, ScriptBuilder.createOutputScript(key1));
@@ -225,7 +225,7 @@ public class DefaultRiskAnalysisTest {
@Test
public void optInFullRBF() throws Exception {
Transaction tx = FakeTxBuilder.createFakeTx(params);
Transaction tx = FakeTxBuilder.createFakeTx(PARAMS);
tx.getInput(0).setSequenceNumber(TransactionInput.NO_SEQUENCE - 2);
DefaultRiskAnalysis analysis = DefaultRiskAnalysis.FACTORY.create(wallet, tx, NO_DEPS);
assertEquals(RiskAnalysis.Result.NON_FINAL, analysis.analyze());

View File

@@ -38,7 +38,7 @@ public class KeyChainGroupTest {
// Number of initial keys in this tests HD wallet, including interior keys.
private static final int INITIAL_KEYS = 4;
private static final int LOOKAHEAD_SIZE = 5;
private static final NetworkParameters params = MainNetParams.get();
private static final NetworkParameters PARAMS = MainNetParams.get();
private static final String XPUB = "xpub68KFnj3bqUx1s7mHejLDBPywCAKdJEu1b49uniEEn2WSbHmZ7xbLqFTjJbtx1LUcAt1DwhoqWHmo2s5WMJp6wi38CiF2hYD49qVViKVvAoi";
private KeyChainGroup group;
private DeterministicKey watchingAccountKey;
@@ -47,15 +47,15 @@ public class KeyChainGroupTest {
public void setup() {
BriefLogFormatter.init();
Utils.setMockClock();
group = new KeyChainGroup(params);
group = new KeyChainGroup(PARAMS);
group.setLookaheadSize(LOOKAHEAD_SIZE); // Don't want slow tests.
group.getActiveKeyChain(); // Force create a chain.
watchingAccountKey = DeterministicKey.deserializeB58(null, XPUB, params);
watchingAccountKey = DeterministicKey.deserializeB58(null, XPUB, PARAMS);
}
private KeyChainGroup createMarriedKeyChainGroup() {
KeyChainGroup group = new KeyChainGroup(params);
KeyChainGroup group = new KeyChainGroup(PARAMS);
DeterministicKeyChain chain = createMarriedKeyChain();
group.addAndActivateHDChain(chain);
group.setLookaheadSize(LOOKAHEAD_SIZE);
@@ -293,7 +293,7 @@ public class KeyChainGroupTest {
@Test
public void encryptionWhilstEmpty() throws Exception {
group = new KeyChainGroup(params);
group = new KeyChainGroup(PARAMS);
group.setLookaheadSize(5);
KeyCrypterScrypt scrypt = new KeyCrypterScrypt(2);
final KeyParameter aesKey = scrypt.deriveKey("password");
@@ -410,7 +410,7 @@ public class KeyChainGroupTest {
public void serialization() throws Exception {
int initialKeys = INITIAL_KEYS + group.getActiveKeyChain().getAccountPath().size() - 1;
assertEquals(initialKeys + 1 /* for the seed */, group.serializeToProtobuf().size());
group = KeyChainGroup.fromProtobufUnencrypted(params, group.serializeToProtobuf());
group = KeyChainGroup.fromProtobufUnencrypted(PARAMS, group.serializeToProtobuf());
group.freshKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
DeterministicKey key1 = group.freshKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
DeterministicKey key2 = group.freshKey(KeyChain.KeyPurpose.CHANGE);
@@ -421,13 +421,13 @@ public class KeyChainGroupTest {
List<Protos.Key> protoKeys2 = group.serializeToProtobuf();
assertEquals(initialKeys + ((LOOKAHEAD_SIZE + 1) * 2) + 1 /* for the seed */ + 2, protoKeys2.size());
group = KeyChainGroup.fromProtobufUnencrypted(params, protoKeys1);
group = KeyChainGroup.fromProtobufUnencrypted(PARAMS, protoKeys1);
assertEquals(initialKeys + ((LOOKAHEAD_SIZE + 1) * 2) + 1 /* for the seed */ + 1, protoKeys1.size());
assertTrue(group.hasKey(key1));
assertTrue(group.hasKey(key2));
assertEquals(key2, group.currentKey(KeyChain.KeyPurpose.CHANGE));
assertEquals(key1, group.currentKey(KeyChain.KeyPurpose.RECEIVE_FUNDS));
group = KeyChainGroup.fromProtobufUnencrypted(params, protoKeys2);
group = KeyChainGroup.fromProtobufUnencrypted(PARAMS, protoKeys2);
assertEquals(initialKeys + ((LOOKAHEAD_SIZE + 1) * 2) + 1 /* for the seed */ + 2, protoKeys2.size());
assertTrue(group.hasKey(key1));
assertTrue(group.hasKey(key2));
@@ -436,7 +436,7 @@ public class KeyChainGroupTest {
final KeyParameter aesKey = scrypt.deriveKey("password");
group.encrypt(scrypt, aesKey);
List<Protos.Key> protoKeys3 = group.serializeToProtobuf();
group = KeyChainGroup.fromProtobufEncrypted(params, protoKeys3, scrypt);
group = KeyChainGroup.fromProtobufEncrypted(PARAMS, protoKeys3, scrypt);
assertTrue(group.isEncrypted());
assertTrue(group.checkPassword("password"));
group.decrypt(aesKey);
@@ -446,14 +446,14 @@ public class KeyChainGroupTest {
@Test
public void serializeWatching() throws Exception {
group = new KeyChainGroup(params, watchingAccountKey);
group = new KeyChainGroup(PARAMS, watchingAccountKey);
group.setLookaheadSize(LOOKAHEAD_SIZE);
group.freshKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
group.freshKey(KeyChain.KeyPurpose.CHANGE);
group.getBloomFilterElementCount(); // Force lookahead.
List<Protos.Key> protoKeys1 = group.serializeToProtobuf();
assertEquals(3 + (group.getLookaheadSize() + group.getLookaheadThreshold() + 1) * 2, protoKeys1.size());
group = KeyChainGroup.fromProtobufUnencrypted(params, protoKeys1);
group = KeyChainGroup.fromProtobufUnencrypted(PARAMS, protoKeys1);
assertEquals(3 + (group.getLookaheadSize() + group.getLookaheadThreshold() + 1) * 2, group.serializeToProtobuf().size());
}
@@ -465,7 +465,7 @@ public class KeyChainGroupTest {
assertEquals(2, group.getActiveKeyChain().getSigsRequiredToSpend());
List<Protos.Key> protoKeys = group.serializeToProtobuf();
KeyChainGroup group2 = KeyChainGroup.fromProtobufUnencrypted(params, protoKeys);
KeyChainGroup group2 = KeyChainGroup.fromProtobufUnencrypted(PARAMS, protoKeys);
assertTrue(group2.isMarried());
assertEquals(2, group.getActiveKeyChain().getSigsRequiredToSpend());
Address address2 = group2.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
@@ -483,7 +483,7 @@ public class KeyChainGroupTest {
public void constructFromSeed() throws Exception {
ECKey key1 = group.freshKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
final DeterministicSeed seed = checkNotNull(group.getActiveKeyChain().getSeed());
KeyChainGroup group2 = new KeyChainGroup(params, seed);
KeyChainGroup group2 = new KeyChainGroup(PARAMS, seed);
group2.setLookaheadSize(5);
ECKey key2 = group2.freshKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
assertEquals(key1, key2);
@@ -492,7 +492,7 @@ public class KeyChainGroupTest {
@Test(expected = DeterministicUpgradeRequiredException.class)
public void deterministicUpgradeRequired() throws Exception {
// Check that if we try to use HD features in a KCG that only has random keys, we get an exception.
group = new KeyChainGroup(params);
group = new KeyChainGroup(PARAMS);
group.importKeys(new ECKey(), new ECKey());
assertTrue(group.isDeterministicUpgradeRequired());
group.freshKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); // throws
@@ -502,7 +502,7 @@ public class KeyChainGroupTest {
public void deterministicUpgradeUnencrypted() throws Exception {
// Check that a group that contains only random keys has its HD chain created using the private key bytes of
// the oldest random key, so upgrading the same wallet twice gives the same outcome.
group = new KeyChainGroup(params);
group = new KeyChainGroup(PARAMS);
group.setLookaheadSize(LOOKAHEAD_SIZE); // Don't want slow tests.
ECKey key1 = new ECKey();
Utils.rollMockClock(86400);
@@ -516,7 +516,7 @@ public class KeyChainGroupTest {
DeterministicSeed seed1 = group.getActiveKeyChain().getSeed();
assertNotNull(seed1);
group = KeyChainGroup.fromProtobufUnencrypted(params, protobufs);
group = KeyChainGroup.fromProtobufUnencrypted(PARAMS, protobufs);
group.upgradeToDeterministic(0, null); // Should give same result as last time.
DeterministicKey dkey2 = group.freshKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
DeterministicSeed seed2 = group.getActiveKeyChain().getSeed();
@@ -530,7 +530,7 @@ public class KeyChainGroupTest {
@Test
public void deterministicUpgradeRotating() throws Exception {
group = new KeyChainGroup(params);
group = new KeyChainGroup(PARAMS);
group.setLookaheadSize(LOOKAHEAD_SIZE); // Don't want slow tests.
long now = Utils.currentTimeSeconds();
ECKey key1 = new ECKey();
@@ -549,7 +549,7 @@ public class KeyChainGroupTest {
@Test
public void deterministicUpgradeEncrypted() throws Exception {
group = new KeyChainGroup(params);
group = new KeyChainGroup(PARAMS);
final ECKey key = new ECKey();
group.importKeys(key);
final KeyCrypterScrypt crypter = new KeyCrypterScrypt();
@@ -586,7 +586,7 @@ public class KeyChainGroupTest {
@Test
public void isNotWatching() {
group = new KeyChainGroup(params);
group = new KeyChainGroup(PARAMS);
final ECKey key = ECKey.fromPrivate(BigInteger.TEN);
group.importKeys(key);
assertFalse(group.isWatching());
@@ -595,11 +595,11 @@ public class KeyChainGroupTest {
@Test
public void isWatching() {
group = new KeyChainGroup(
params,
PARAMS,
DeterministicKey
.deserializeB58(
"xpub69bjfJ91ikC5ghsqsVDHNq2dRGaV2HHVx7Y9LXi27LN9BWWAXPTQr4u8U3wAtap8bLdHdkqPpAcZmhMS5SnrMQC4ccaoBccFhh315P4UYzo",
params));
PARAMS));
final ECKey watchingKey = ECKey.fromPublicOnly(new ECKey().getPubKeyPoint());
group.importKeys(watchingKey);
assertTrue(group.isWatching());
@@ -607,18 +607,18 @@ public class KeyChainGroupTest {
@Test(expected = IllegalStateException.class)
public void isWatchingNoKeys() {
group = new KeyChainGroup(params);
group = new KeyChainGroup(PARAMS);
group.isWatching();
}
@Test(expected = IllegalStateException.class)
public void isWatchingMixedKeys() {
group = new KeyChainGroup(
params,
PARAMS,
DeterministicKey
.deserializeB58(
"xpub69bjfJ91ikC5ghsqsVDHNq2dRGaV2HHVx7Y9LXi27LN9BWWAXPTQr4u8U3wAtap8bLdHdkqPpAcZmhMS5SnrMQC4ccaoBccFhh315P4UYzo",
params));
PARAMS));
final ECKey key = ECKey.fromPrivate(BigInteger.TEN);
group.importKeys(key);
group.isWatching();