mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-03-13 11:36:15 +01:00
TestWithWallet hierarchy: use TestNet3Params, rather than UnitTestParams
This commit is contained in:
parent
b0442721c8
commit
6584fbcef3
4 changed files with 234 additions and 238 deletions
|
@ -57,7 +57,7 @@ public class TransactionOutputTest extends TestWithWallet {
|
|||
ECKey otherKey = new ECKey();
|
||||
|
||||
// Create multi-sig transaction
|
||||
Transaction multiSigTransaction = new Transaction(UNITTEST);
|
||||
Transaction multiSigTransaction = new Transaction(TESTNET);
|
||||
List<ECKey> keys = Arrays.asList(myKey, otherKey);
|
||||
|
||||
Script scriptPubKey = ScriptBuilder.createMultiSigOutputScript(2, keys);
|
||||
|
@ -91,11 +91,11 @@ public class TransactionOutputTest extends TestWithWallet {
|
|||
|
||||
@Test
|
||||
public void getMinNonDustValue() {
|
||||
TransactionOutput p2pk = new TransactionOutput(UNITTEST, null, Coin.COIN, myKey);
|
||||
TransactionOutput p2pk = new TransactionOutput(TESTNET, null, Coin.COIN, myKey);
|
||||
assertEquals(Coin.valueOf(576), p2pk.getMinNonDustValue());
|
||||
TransactionOutput p2pkh = new TransactionOutput(UNITTEST, null, Coin.COIN, LegacyAddress.fromKey(UNITTEST, myKey));
|
||||
TransactionOutput p2pkh = new TransactionOutput(TESTNET, null, Coin.COIN, LegacyAddress.fromKey(TESTNET, myKey));
|
||||
assertEquals(Coin.valueOf(546), p2pkh.getMinNonDustValue());
|
||||
TransactionOutput p2wpkh = new TransactionOutput(UNITTEST, null, Coin.COIN, SegwitAddress.fromKey(UNITTEST, myKey));
|
||||
TransactionOutput p2wpkh = new TransactionOutput(TESTNET, null, Coin.COIN, SegwitAddress.fromKey(TESTNET, myKey));
|
||||
assertEquals(Coin.valueOf(294), p2wpkh.getMinNonDustValue());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ import org.bitcoinj.core.Transaction;
|
|||
import org.bitcoinj.core.Utils;
|
||||
import org.bitcoinj.core.VerificationException;
|
||||
import org.bitcoinj.params.MainNetParams;
|
||||
import org.bitcoinj.params.UnitTestParams;
|
||||
import org.bitcoinj.params.TestNet3Params;
|
||||
import org.bitcoinj.store.BlockStore;
|
||||
import org.bitcoinj.store.MemoryBlockStore;
|
||||
import org.bitcoinj.utils.BriefLogFormatter;
|
||||
|
@ -51,8 +51,8 @@ import static org.bitcoinj.testing.FakeTxBuilder.createFakeTx;
|
|||
* fee per kilobyte to zero in setUp.
|
||||
*/
|
||||
public class TestWithWallet {
|
||||
protected static NetworkParameters UNITTEST;
|
||||
protected static NetworkParameters MAINNET;
|
||||
protected static final NetworkParameters TESTNET = TestNet3Params.get();
|
||||
protected static final NetworkParameters MAINNET = MainNetParams.get();
|
||||
|
||||
protected ECKey myKey;
|
||||
protected Address myAddress;
|
||||
|
@ -63,18 +63,16 @@ public class TestWithWallet {
|
|||
@BeforeClass
|
||||
public static void setUpClass() throws Exception {
|
||||
Utils.resetMocking();
|
||||
UNITTEST = UnitTestParams.get();
|
||||
MAINNET = MainNetParams.get();
|
||||
}
|
||||
|
||||
public void setUp() throws Exception {
|
||||
BriefLogFormatter.init();
|
||||
Context.propagate(new Context(100, Coin.ZERO, false, false));
|
||||
wallet = Wallet.createDeterministic(UNITTEST, ScriptType.P2PKH, KeyChainGroupStructure.BIP32);
|
||||
Context.propagate(new Context(100, Coin.ZERO, false, true));
|
||||
wallet = Wallet.createDeterministic(TESTNET, ScriptType.P2PKH, KeyChainGroupStructure.BIP32);
|
||||
myKey = wallet.freshReceiveKey();
|
||||
myAddress = wallet.freshReceiveAddress(ScriptType.P2PKH);
|
||||
blockStore = new MemoryBlockStore(UNITTEST);
|
||||
chain = new BlockChain(UNITTEST, wallet, blockStore);
|
||||
blockStore = new MemoryBlockStore(TESTNET);
|
||||
chain = new BlockChain(TESTNET, wallet, blockStore);
|
||||
}
|
||||
|
||||
public void tearDown() throws Exception {
|
||||
|
@ -103,12 +101,12 @@ public class TestWithWallet {
|
|||
|
||||
@Nullable
|
||||
protected Transaction sendMoneyToWallet(Wallet wallet, AbstractBlockChain.NewBlockType type, Coin value, Address toAddress) throws VerificationException {
|
||||
return sendMoneyToWallet(wallet, type, createFakeTx(UNITTEST, value, toAddress));
|
||||
return sendMoneyToWallet(wallet, type, createFakeTx(TESTNET, value, toAddress));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected Transaction sendMoneyToWallet(Wallet wallet, AbstractBlockChain.NewBlockType type, Coin value, ECKey toPubKey) throws VerificationException {
|
||||
return sendMoneyToWallet(wallet, type, createFakeTx(UNITTEST, value, toPubKey));
|
||||
return sendMoneyToWallet(wallet, type, createFakeTx(TESTNET, value, toPubKey));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
|
|
@ -26,7 +26,6 @@ import org.bitcoinj.core.TransactionConfidence;
|
|||
import org.bitcoinj.core.TransactionOutput;
|
||||
import org.bitcoinj.core.Utils;
|
||||
import org.bitcoinj.params.RegTestParams;
|
||||
import org.bitcoinj.params.UnitTestParams;
|
||||
import org.bitcoinj.testing.FakeTxBuilder;
|
||||
import org.bitcoinj.testing.TestWithWallet;
|
||||
import org.junit.After;
|
||||
|
@ -46,7 +45,6 @@ import static org.junit.Assert.assertFalse;
|
|||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class DefaultCoinSelectorTest extends TestWithWallet {
|
||||
private static final NetworkParameters UNITTEST = UnitTestParams.get();
|
||||
private static final NetworkParameters REGTEST = RegTestParams.get();
|
||||
|
||||
@Before
|
||||
|
@ -65,16 +63,16 @@ public class DefaultCoinSelectorTest extends TestWithWallet {
|
|||
@Test
|
||||
public void selectable() throws Exception {
|
||||
Transaction t;
|
||||
t = new Transaction(UNITTEST);
|
||||
t = new Transaction(TESTNET);
|
||||
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(UNITTEST, InetAddress.getByName("1.2.3.4")));
|
||||
t.getConfidence().markBroadcastBy(new PeerAddress(TESTNET, InetAddress.getByName("1.2.3.4")));
|
||||
assertTrue(DefaultCoinSelector.isSelectable(t));
|
||||
t.getConfidence().markBroadcastBy(new PeerAddress(UNITTEST, InetAddress.getByName("5.6.7.8")));
|
||||
t.getConfidence().markBroadcastBy(new PeerAddress(TESTNET, InetAddress.getByName("5.6.7.8")));
|
||||
assertTrue(DefaultCoinSelector.isSelectable(t));
|
||||
t = new Transaction(UNITTEST);
|
||||
t = new Transaction(TESTNET);
|
||||
t.getConfidence().setConfidenceType(TransactionConfidence.ConfidenceType.BUILDING);
|
||||
assertTrue(DefaultCoinSelector.isSelectable(t));
|
||||
t = new Transaction(REGTEST);
|
||||
|
@ -129,12 +127,12 @@ public class DefaultCoinSelectorTest extends TestWithWallet {
|
|||
@Test
|
||||
public void identicalInputs() {
|
||||
// Add four outputs to a transaction with same value and destination. Select them all.
|
||||
Transaction t = new Transaction(UNITTEST);
|
||||
Transaction t = new Transaction(TESTNET);
|
||||
List<TransactionOutput> outputs = Arrays.asList(
|
||||
new TransactionOutput(UNITTEST, t, Coin.valueOf(30302787), myAddress),
|
||||
new TransactionOutput(UNITTEST, t, Coin.valueOf(30302787), myAddress),
|
||||
new TransactionOutput(UNITTEST, t, Coin.valueOf(30302787), myAddress),
|
||||
new TransactionOutput(UNITTEST, t, Coin.valueOf(30302787), myAddress)
|
||||
new TransactionOutput(TESTNET, t, Coin.valueOf(30302787), myAddress),
|
||||
new TransactionOutput(TESTNET, t, Coin.valueOf(30302787), myAddress),
|
||||
new TransactionOutput(TESTNET, t, Coin.valueOf(30302787), myAddress),
|
||||
new TransactionOutput(TESTNET, t, Coin.valueOf(30302787), myAddress)
|
||||
);
|
||||
t.getConfidence().setConfidenceType(TransactionConfidence.ConfidenceType.BUILDING);
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue