3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-07 23:03:04 +00:00

Further global replace of NetworkParameters.* -> *.get()

This commit is contained in:
Matt Corallo 2013-05-22 23:50:50 +02:00 committed by Mike Hearn
parent f4c3b6a49d
commit 5993f2dc6c
16 changed files with 40 additions and 23 deletions

View File

@ -19,6 +19,7 @@ package com.google.bitcoin.core;
import com.google.bitcoin.core.Wallet.BalanceType; import com.google.bitcoin.core.Wallet.BalanceType;
import com.google.bitcoin.params.MainNetParams; import com.google.bitcoin.params.MainNetParams;
import com.google.bitcoin.params.TestNet2Params; import com.google.bitcoin.params.TestNet2Params;
import com.google.bitcoin.params.UnitTestParams;
import com.google.bitcoin.store.BlockStore; import com.google.bitcoin.store.BlockStore;
import com.google.bitcoin.store.MemoryBlockStore; import com.google.bitcoin.store.MemoryBlockStore;
import com.google.bitcoin.utils.BriefLogFormatter; import com.google.bitcoin.utils.BriefLogFormatter;
@ -63,7 +64,7 @@ public class BlockChainTest {
BriefLogFormatter.initVerbose(); BriefLogFormatter.initVerbose();
testNetChain = new BlockChain(testNet, new Wallet(testNet), new MemoryBlockStore(testNet)); testNetChain = new BlockChain(testNet, new Wallet(testNet), new MemoryBlockStore(testNet));
unitTestParams = NetworkParameters.unitTests(); unitTestParams = UnitTestParams.get();
wallet = new Wallet(unitTestParams) { wallet = new Wallet(unitTestParams) {
@Override @Override
public void receiveFromBlock(Transaction tx, StoredBlock block, BlockChain.NewBlockType blockType) throws VerificationException { public void receiveFromBlock(Transaction tx, StoredBlock block, BlockChain.NewBlockType blockType) throws VerificationException {

View File

@ -16,6 +16,8 @@
package com.google.bitcoin.core; package com.google.bitcoin.core;
import com.google.bitcoin.params.TestNet2Params;
import com.google.bitcoin.params.UnitTestParams;
import com.google.bitcoin.script.ScriptOpCodes; import com.google.bitcoin.script.ScriptOpCodes;
import org.junit.Test; import org.junit.Test;
import org.spongycastle.util.encoders.Hex; import org.spongycastle.util.encoders.Hex;
@ -30,7 +32,7 @@ import java.util.Arrays;
import static org.junit.Assert.*; import static org.junit.Assert.*;
public class BlockTest { public class BlockTest {
static final NetworkParameters params = NetworkParameters.testNet2(); static final NetworkParameters params = TestNet2Params.get();
public static final byte[] blockBytes; public static final byte[] blockBytes;
@ -66,7 +68,7 @@ public class BlockTest {
@Test @Test
public void testProofOfWork() throws Exception { public void testProofOfWork() throws Exception {
// This params accepts any difficulty target. // This params accepts any difficulty target.
NetworkParameters params = NetworkParameters.unitTests(); NetworkParameters params = UnitTestParams.get();
Block block = new Block(params, blockBytes); Block block = new Block(params, blockBytes);
block.setNonce(12346); block.setNonce(12346);
try { try {
@ -153,7 +155,7 @@ public class BlockTest {
@Test @Test
public void testUpdateLength() { public void testUpdateLength() {
NetworkParameters params = NetworkParameters.unitTests(); NetworkParameters params = UnitTestParams.get();
Block block = params.getGenesisBlock().createNextBlockWithCoinbase(new ECKey().getPubKey()); Block block = params.getGenesisBlock().createNextBlockWithCoinbase(new ECKey().getPubKey());
assertEquals(block.bitcoinSerialize().length, block.length); assertEquals(block.bitcoinSerialize().length, block.length);
final int origBlockLen = block.length; final int origBlockLen = block.length;

View File

@ -17,6 +17,7 @@
package com.google.bitcoin.core; package com.google.bitcoin.core;
import com.google.bitcoin.core.TransactionConfidence.ConfidenceType; import com.google.bitcoin.core.TransactionConfidence.ConfidenceType;
import com.google.bitcoin.params.UnitTestParams;
import com.google.bitcoin.store.MemoryBlockStore; import com.google.bitcoin.store.MemoryBlockStore;
import com.google.bitcoin.utils.BriefLogFormatter; import com.google.bitcoin.utils.BriefLogFormatter;
import org.junit.Before; import org.junit.Before;
@ -43,7 +44,7 @@ public class ChainSplitTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
BriefLogFormatter.init(); BriefLogFormatter.init();
unitTestParams = NetworkParameters.unitTests(); unitTestParams = UnitTestParams.get();
wallet = new Wallet(unitTestParams); wallet = new Wallet(unitTestParams);
wallet.addKey(new ECKey()); wallet.addKey(new ECKey());
wallet.addKey(new ECKey()); wallet.addKey(new ECKey());

View File

@ -21,6 +21,7 @@ import com.google.bitcoin.crypto.KeyCrypter;
import com.google.bitcoin.crypto.KeyCrypterScrypt; import com.google.bitcoin.crypto.KeyCrypterScrypt;
import com.google.bitcoin.params.MainNetParams; import com.google.bitcoin.params.MainNetParams;
import com.google.bitcoin.params.TestNet3Params; import com.google.bitcoin.params.TestNet3Params;
import com.google.bitcoin.params.UnitTestParams;
import com.google.bitcoin.utils.BriefLogFormatter; import com.google.bitcoin.utils.BriefLogFormatter;
import com.google.protobuf.ByteString; import com.google.protobuf.ByteString;
import org.bitcoinj.wallet.Protos; import org.bitcoinj.wallet.Protos;
@ -355,7 +356,7 @@ public class ECKeyTest {
public void roundTripDumpedPrivKey() throws Exception { public void roundTripDumpedPrivKey() throws Exception {
ECKey key = new ECKey(); ECKey key = new ECKey();
assertTrue(key.isCompressed()); assertTrue(key.isCompressed());
NetworkParameters params = NetworkParameters.unitTests(); NetworkParameters params = UnitTestParams.get();
String base58 = key.getPrivateKeyEncoded(params).toString(); String base58 = key.getPrivateKeyEncoded(params).toString();
ECKey key2 = new DumpedPrivateKey(params, base58).getKey(); ECKey key2 = new DumpedPrivateKey(params, base58).getKey();
assertTrue(key2.isCompressed()); assertTrue(key2.isCompressed());

View File

@ -1,6 +1,7 @@
package com.google.bitcoin.core; package com.google.bitcoin.core;
import com.google.bitcoin.core.TransactionConfidence.ConfidenceType; import com.google.bitcoin.core.TransactionConfidence.ConfidenceType;
import com.google.bitcoin.params.UnitTestParams;
import com.google.bitcoin.store.MemoryBlockStore; import com.google.bitcoin.store.MemoryBlockStore;
import org.junit.Test; import org.junit.Test;
import org.spongycastle.util.encoders.Hex; import org.spongycastle.util.encoders.Hex;
@ -16,7 +17,7 @@ public class FilteredBlockAndPartialMerkleTreeTests extends TestWithPeerGroup {
@Test @Test
// Simple deserialization sanity check // Simple deserialization sanity check
public void deserializeFilteredBlock() throws Exception { public void deserializeFilteredBlock() throws Exception {
NetworkParameters params = NetworkParameters.unitTests(); NetworkParameters params = UnitTestParams.get();
// Random real block (000000000000dab0130bbcc991d3d7ae6b81aa6f50a798888dfe62337458dc45) // Random real block (000000000000dab0130bbcc991d3d7ae6b81aa6f50a798888dfe62337458dc45)
// With one tx // With one tx
@ -33,7 +34,7 @@ public class FilteredBlockAndPartialMerkleTreeTests extends TestWithPeerGroup {
@Test @Test
public void serializeDownloadBlockWithWallet() throws Exception { public void serializeDownloadBlockWithWallet() throws Exception {
unitTestParams = NetworkParameters.unitTests(); unitTestParams = UnitTestParams.get();
// First we create all the neccessary objects, including lots of serialization and double-checks // First we create all the neccessary objects, including lots of serialization and double-checks
// Note that all serialized forms here are generated by the reference client/pulled from block explorer // Note that all serialized forms here are generated by the reference client/pulled from block explorer
@ -76,7 +77,7 @@ public class FilteredBlockAndPartialMerkleTreeTests extends TestWithPeerGroup {
assertTrue(Arrays.equals(filter.bitcoinSerialize(), Hex.decode("0e1b091ca195e45a9164889b6bc46a09000000efbeadde02"))); assertTrue(Arrays.equals(filter.bitcoinSerialize(), Hex.decode("0e1b091ca195e45a9164889b6bc46a09000000efbeadde02")));
// Cheat and place the previous block (block 100000) at the head of the block store without supporting blocks // Cheat and place the previous block (block 100000) at the head of the block store without supporting blocks
blockStore = new MemoryBlockStore(NetworkParameters.unitTests()); blockStore = new MemoryBlockStore(UnitTestParams.get());
blockStore.put(new StoredBlock(new Block(unitTestParams, Hex.decode("0100000050120119172a610421a6c3011dd330d9df07b63616c2cc1f1cd00200000000006657a9252aacd5c0b2940996ecff952228c3067cc38d4885efb5a4ac4247e9f337221b4d4c86041b0f2b5710")), blockStore.put(new StoredBlock(new Block(unitTestParams, Hex.decode("0100000050120119172a610421a6c3011dd330d9df07b63616c2cc1f1cd00200000000006657a9252aacd5c0b2940996ecff952228c3067cc38d4885efb5a4ac4247e9f337221b4d4c86041b0f2b5710")),
BigInteger.valueOf(1), 100000)); BigInteger.valueOf(1), 100000));
blockStore.setChainHead(blockStore.get(new Sha256Hash("000000000003ba27aa200b1cecaad478d2b00432346c3f1f3986da1afd33e506"))); blockStore.setChainHead(blockStore.get(new Sha256Hash("000000000003ba27aa200b1cecaad478d2b00432346c3f1f3986da1afd33e506")));

View File

@ -18,6 +18,7 @@
package com.google.bitcoin.core; package com.google.bitcoin.core;
import com.google.bitcoin.core.Transaction.SigHash; import com.google.bitcoin.core.Transaction.SigHash;
import com.google.bitcoin.params.MainNetParams;
import com.google.bitcoin.params.UnitTestParams; import com.google.bitcoin.params.UnitTestParams;
import com.google.bitcoin.script.Script; import com.google.bitcoin.script.Script;
import com.google.bitcoin.store.BlockStoreException; import com.google.bitcoin.store.BlockStoreException;
@ -176,7 +177,7 @@ public class FullPrunedBlockChainTest {
@Test @Test
public void testFirst100KBlocks() throws BlockStoreException, VerificationException, PrunedException { public void testFirst100KBlocks() throws BlockStoreException, VerificationException, PrunedException {
NetworkParameters params = NetworkParameters.prodNet(); NetworkParameters params = MainNetParams.get();
File blockFile = new File(getClass().getResource("first-100k-blocks.dat").getFile()); File blockFile = new File(getClass().getResource("first-100k-blocks.dat").getFile());
BlockFileLoader loader = new BlockFileLoader(params, Arrays.asList(new File[] {blockFile})); BlockFileLoader loader = new BlockFileLoader(params, Arrays.asList(new File[] {blockFile}));

View File

@ -17,6 +17,7 @@
package com.google.bitcoin.core; package com.google.bitcoin.core;
import com.google.bitcoin.params.MainNetParams; import com.google.bitcoin.params.MainNetParams;
import com.google.bitcoin.params.UnitTestParams;
import com.google.bitcoin.store.BlockStore; import com.google.bitcoin.store.BlockStore;
import com.google.bitcoin.store.MemoryBlockStore; import com.google.bitcoin.store.MemoryBlockStore;
import org.junit.Before; import org.junit.Before;
@ -78,7 +79,7 @@ public class LazyParseByteCacheTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
unitTestParams = NetworkParameters.unitTests(); unitTestParams = UnitTestParams.get();
wallet = new Wallet(unitTestParams); wallet = new Wallet(unitTestParams);
wallet.addKey(new ECKey()); wallet.addKey(new ECKey());

View File

@ -16,6 +16,7 @@
package com.google.bitcoin.core; package com.google.bitcoin.core;
import com.google.bitcoin.params.UnitTestParams;
import com.google.bitcoin.utils.BriefLogFormatter; import com.google.bitcoin.utils.BriefLogFormatter;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -26,7 +27,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
public class MemoryPoolTest { public class MemoryPoolTest {
private NetworkParameters params = NetworkParameters.unitTests(); private NetworkParameters params = UnitTestParams.get();
private Transaction tx1, tx2; private Transaction tx1, tx2;
private PeerAddress address1, address2, address3; private PeerAddress address1, address2, address3;

View File

@ -18,6 +18,7 @@ package com.google.bitcoin.core;
import com.google.bitcoin.discovery.PeerDiscovery; import com.google.bitcoin.discovery.PeerDiscovery;
import com.google.bitcoin.discovery.PeerDiscoveryException; import com.google.bitcoin.discovery.PeerDiscoveryException;
import com.google.bitcoin.params.UnitTestParams;
import com.google.bitcoin.store.MemoryBlockStore; import com.google.bitcoin.store.MemoryBlockStore;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
@ -34,12 +35,12 @@ import java.util.concurrent.TimeUnit;
import static org.junit.Assert.*; import static org.junit.Assert.*;
public class PeerGroupTest extends TestWithPeerGroup { public class PeerGroupTest extends TestWithPeerGroup {
static final NetworkParameters params = NetworkParameters.unitTests(); static final NetworkParameters params = UnitTestParams.get();
@Override @Override
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(new MemoryBlockStore(NetworkParameters.unitTests())); super.setUp(new MemoryBlockStore(UnitTestParams.get()));
peerGroup.addWallet(wallet); peerGroup.addWallet(wallet);
} }

View File

@ -16,6 +16,7 @@
package com.google.bitcoin.core; package com.google.bitcoin.core;
import com.google.bitcoin.params.UnitTestParams;
import com.google.bitcoin.store.BlockStore; import com.google.bitcoin.store.BlockStore;
import com.google.bitcoin.store.MemoryBlockStore; import com.google.bitcoin.store.MemoryBlockStore;
import com.google.bitcoin.utils.BriefLogFormatter; import com.google.bitcoin.utils.BriefLogFormatter;
@ -49,7 +50,7 @@ public class TestWithNetworkConnections {
protected ChannelPipeline pipeline; protected ChannelPipeline pipeline;
public void setUp() throws Exception { public void setUp() throws Exception {
setUp(new MemoryBlockStore(NetworkParameters.unitTests())); setUp(new MemoryBlockStore(UnitTestParams.get()));
} }
public void setUp(BlockStore blockStore) throws Exception { public void setUp(BlockStore blockStore) throws Exception {
@ -58,7 +59,7 @@ public class TestWithNetworkConnections {
control = createStrictControl(); control = createStrictControl();
control.checkOrder(false); control.checkOrder(false);
unitTestParams = NetworkParameters.unitTests(); unitTestParams = UnitTestParams.get();
this.blockStore = blockStore; this.blockStore = blockStore;
wallet = new Wallet(unitTestParams); wallet = new Wallet(unitTestParams);
key = new ECKey(); key = new ECKey();

View File

@ -16,6 +16,7 @@
package com.google.bitcoin.core; package com.google.bitcoin.core;
import com.google.bitcoin.params.UnitTestParams;
import com.google.bitcoin.store.BlockStore; import com.google.bitcoin.store.BlockStore;
import com.google.bitcoin.store.MemoryBlockStore; import com.google.bitcoin.store.MemoryBlockStore;
import com.google.bitcoin.utils.BriefLogFormatter; import com.google.bitcoin.utils.BriefLogFormatter;
@ -29,7 +30,7 @@ import static com.google.bitcoin.core.TestUtils.createFakeBlock;
import static com.google.bitcoin.core.TestUtils.createFakeTx; import static com.google.bitcoin.core.TestUtils.createFakeTx;
public class TestWithWallet { public class TestWithWallet {
protected static final NetworkParameters params = NetworkParameters.unitTests(); protected static final NetworkParameters params = UnitTestParams.get();
protected ECKey myKey; protected ECKey myKey;
protected Address myAddress; protected Address myAddress;
protected Wallet wallet; protected Wallet wallet;

View File

@ -1,5 +1,6 @@
package com.google.bitcoin.core; package com.google.bitcoin.core;
import com.google.bitcoin.params.UnitTestParams;
import org.junit.Test; import org.junit.Test;
import org.spongycastle.util.encoders.Hex; import org.spongycastle.util.encoders.Hex;
@ -9,7 +10,7 @@ public class VersionMessageTest {
@Test @Test
// Test that we can decode version messages which miss data which some old nodes may not include // Test that we can decode version messages which miss data which some old nodes may not include
public void testDecode() throws Exception { public void testDecode() throws Exception {
NetworkParameters params = NetworkParameters.unitTests(); NetworkParameters params = UnitTestParams.get();
VersionMessage ver = new VersionMessage(params, Hex.decode("71110100000000000000000048e5e95000000000000000000000000000000000000000000000ffff7f000001479d000000000000000000000000000000000000ffff7f000001479d0000000000000000172f426974436f696e4a3a302e372d534e415053484f542f0004000000")); VersionMessage ver = new VersionMessage(params, Hex.decode("71110100000000000000000048e5e95000000000000000000000000000000000000000000000ffff7f000001479d000000000000000000000000000000000000ffff7f000001479d0000000000000000172f426974436f696e4a3a302e372d534e415053484f542f0004000000"));
assertTrue(!ver.relayTxesBeforeFilter); assertTrue(!ver.relayTxesBeforeFilter);

View File

@ -19,6 +19,7 @@ import com.google.bitcoin.core.Address;
import com.google.bitcoin.core.ECKey; import com.google.bitcoin.core.ECKey;
import com.google.bitcoin.core.NetworkParameters; import com.google.bitcoin.core.NetworkParameters;
import com.google.bitcoin.core.StoredBlock; import com.google.bitcoin.core.StoredBlock;
import com.google.bitcoin.params.UnitTestParams;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TemporaryFolder; import org.junit.rules.TemporaryFolder;
@ -38,7 +39,7 @@ public class BoundedOverheadBlockStoreTest {
File temp = folder.newFile("bitcoinj-test"); File temp = folder.newFile("bitcoinj-test");
System.out.println(temp.getAbsolutePath()); System.out.println(temp.getAbsolutePath());
NetworkParameters params = NetworkParameters.unitTests(); NetworkParameters params = UnitTestParams.get();
Address to = new ECKey().toAddress(params); Address to = new ECKey().toAddress(params);
BoundedOverheadBlockStore store = new BoundedOverheadBlockStore(params, temp); BoundedOverheadBlockStore store = new BoundedOverheadBlockStore(params, temp);
// Check the first block in a new store is the genesis block. // Check the first block in a new store is the genesis block.
@ -64,7 +65,7 @@ public class BoundedOverheadBlockStoreTest {
File temp = folder.newFile("bitcoinj-test"); File temp = folder.newFile("bitcoinj-test");
System.out.println(temp.getAbsolutePath()); System.out.println(temp.getAbsolutePath());
NetworkParameters params = NetworkParameters.unitTests(); NetworkParameters params = UnitTestParams.get();
BoundedOverheadBlockStore store = new BoundedOverheadBlockStore(params, temp); BoundedOverheadBlockStore store = new BoundedOverheadBlockStore(params, temp);
try { try {
BoundedOverheadBlockStore store1 = new BoundedOverheadBlockStore(params, temp); BoundedOverheadBlockStore store1 = new BoundedOverheadBlockStore(params, temp);

View File

@ -20,6 +20,7 @@ import com.google.bitcoin.core.ECKey;
import com.google.bitcoin.core.NetworkParameters; import com.google.bitcoin.core.NetworkParameters;
import com.google.bitcoin.core.StoredBlock; import com.google.bitcoin.core.StoredBlock;
import com.google.bitcoin.params.UnitTestParams;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
@ -43,7 +44,7 @@ public class DiskBlockStoreTest {
temp = folder.newFile("bitcoinj-test"); temp = folder.newFile("bitcoinj-test");
System.out.println(temp.getAbsolutePath()); System.out.println(temp.getAbsolutePath());
params = NetworkParameters.unitTests(); params = UnitTestParams.get();
to = new ECKey().toAddress(params); to = new ECKey().toAddress(params);
} }

View File

@ -20,6 +20,7 @@ import com.google.bitcoin.core.Address;
import com.google.bitcoin.core.ECKey; import com.google.bitcoin.core.ECKey;
import com.google.bitcoin.core.NetworkParameters; import com.google.bitcoin.core.NetworkParameters;
import com.google.bitcoin.core.StoredBlock; import com.google.bitcoin.core.StoredBlock;
import com.google.bitcoin.params.UnitTestParams;
import org.junit.Test; import org.junit.Test;
import java.io.File; import java.io.File;
@ -30,7 +31,7 @@ public class SPVBlockStoreTest {
@Test @Test
public void basics() throws Exception { public void basics() throws Exception {
NetworkParameters params = NetworkParameters.unitTests(); NetworkParameters params = UnitTestParams.get();
File f = File.createTempFile("spvblockstore", null); File f = File.createTempFile("spvblockstore", null);
f.delete(); f.delete();
f.deleteOnExit(); f.deleteOnExit();

View File

@ -4,6 +4,7 @@ package com.google.bitcoin.store;
import com.google.bitcoin.core.*; import com.google.bitcoin.core.*;
import com.google.bitcoin.core.TransactionConfidence.ConfidenceType; import com.google.bitcoin.core.TransactionConfidence.ConfidenceType;
import com.google.bitcoin.params.MainNetParams; import com.google.bitcoin.params.MainNetParams;
import com.google.bitcoin.params.UnitTestParams;
import com.google.bitcoin.utils.BriefLogFormatter; import com.google.bitcoin.utils.BriefLogFormatter;
import com.google.protobuf.ByteString; import com.google.protobuf.ByteString;
import org.bitcoinj.wallet.Protos; import org.bitcoinj.wallet.Protos;
@ -22,7 +23,7 @@ import static com.google.bitcoin.core.TestUtils.createFakeTx;
import static org.junit.Assert.*; import static org.junit.Assert.*;
public class WalletProtobufSerializerTest { public class WalletProtobufSerializerTest {
static final NetworkParameters params = NetworkParameters.unitTests(); static final NetworkParameters params = UnitTestParams.get();
private ECKey myKey; private ECKey myKey;
private Address myAddress; private Address myAddress;
private Wallet myWallet; private Wallet myWallet;