3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-12 10:15:52 +00:00

Wallet: set lookahead size to 5 when using unit test params instead of scattering calls all over the test code.

This commit is contained in:
Mike Hearn 2014-04-22 17:41:51 +02:00
parent fc83deb8fd
commit 1e4f930b70
6 changed files with 2 additions and 10 deletions

View File

@ -222,6 +222,8 @@ public class Wallet extends BaseTaggableObject implements Serializable, BlockCha
public Wallet(NetworkParameters params, KeyChainGroup keyChainGroup) { public Wallet(NetworkParameters params, KeyChainGroup keyChainGroup) {
this.params = checkNotNull(params); this.params = checkNotNull(params);
this.keychain = checkNotNull(keyChainGroup); this.keychain = checkNotNull(keyChainGroup);
if (params == UnitTestParams.get())
this.keychain.setLookaheadSize(5); // Cut down excess computation for unit tests.
watchedScripts = Sets.newHashSet(); watchedScripts = Sets.newHashSet();
unspent = new HashMap<Sha256Hash, Transaction>(); unspent = new HashMap<Sha256Hash, Transaction>();
spent = new HashMap<Sha256Hash, Transaction>(); spent = new HashMap<Sha256Hash, Transaction>();

View File

@ -85,7 +85,6 @@ public class TestWithNetworkConnections {
Wallet.SendRequest.DEFAULT_FEE_PER_KB = BigInteger.ZERO; Wallet.SendRequest.DEFAULT_FEE_PER_KB = BigInteger.ZERO;
this.blockStore = blockStore; this.blockStore = blockStore;
wallet = new Wallet(unitTestParams); wallet = new Wallet(unitTestParams);
wallet.setKeychainLookaheadSize(5); // Make tests faster by reducing the number of keys derived ahead of time.
key = wallet.freshReceiveKey(); key = wallet.freshReceiveKey();
address = key.toAddress(unitTestParams); address = key.toAddress(unitTestParams);
blockChain = new BlockChain(unitTestParams, wallet, blockStore); blockChain = new BlockChain(unitTestParams, wallet, blockStore);

View File

@ -20,7 +20,6 @@ import com.google.bitcoin.core.*;
import com.google.bitcoin.params.UnitTestParams; 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.testing.FakeTxBuilder;
import com.google.bitcoin.utils.BriefLogFormatter; import com.google.bitcoin.utils.BriefLogFormatter;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -52,7 +51,6 @@ public class TestWithWallet {
BriefLogFormatter.init(); BriefLogFormatter.init();
Wallet.SendRequest.DEFAULT_FEE_PER_KB = BigInteger.ZERO; Wallet.SendRequest.DEFAULT_FEE_PER_KB = BigInteger.ZERO;
wallet = new Wallet(params); wallet = new Wallet(params);
wallet.setKeychainLookaheadSize(5);
myKey = wallet.currentReceiveKey(); myKey = wallet.currentReceiveKey();
myAddress = myKey.toAddress(params); myAddress = myKey.toAddress(params);
blockStore = new MemoryBlockStore(params); blockStore = new MemoryBlockStore(params);

View File

@ -56,7 +56,6 @@ public class ChainSplitTest {
Wallet.SendRequest.DEFAULT_FEE_PER_KB = BigInteger.ZERO; Wallet.SendRequest.DEFAULT_FEE_PER_KB = BigInteger.ZERO;
unitTestParams = UnitTestParams.get(); unitTestParams = UnitTestParams.get();
wallet = new Wallet(unitTestParams); wallet = new Wallet(unitTestParams);
wallet.setKeychainLookaheadSize(5); // Make tests faster.
ECKey key1 = wallet.freshReceiveKey(); ECKey key1 = wallet.freshReceiveKey();
ECKey key2 = wallet.freshReceiveKey(); ECKey key2 = wallet.freshReceiveKey();
blockStore = new MemoryBlockStore(unitTestParams); blockStore = new MemoryBlockStore(unitTestParams);

View File

@ -81,7 +81,6 @@ public class WalletTest extends TestWithWallet {
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
encryptedWallet = new Wallet(params); encryptedWallet = new Wallet(params);
encryptedWallet.setKeychainLookaheadSize(5); // For speed.
myEncryptedAddress = encryptedWallet.freshReceiveKey().toAddress(params); myEncryptedAddress = encryptedWallet.freshReceiveKey().toAddress(params);
encryptedWallet.encrypt(PASSWORD1); encryptedWallet.encrypt(PASSWORD1);
keyCrypter = encryptedWallet.getKeyCrypter(); keyCrypter = encryptedWallet.getKeyCrypter();
@ -990,7 +989,6 @@ public class WalletTest extends TestWithWallet {
@Test @Test
public void keyCreationTime() throws Exception { public void keyCreationTime() throws Exception {
wallet = new Wallet(params); wallet = new Wallet(params);
wallet.setKeychainLookaheadSize(5); // For speed.
Utils.setMockClock(); Utils.setMockClock();
long now = Utils.currentTimeSeconds(); long now = Utils.currentTimeSeconds();
// No keys returns current time. // No keys returns current time.
@ -1006,7 +1004,6 @@ public class WalletTest extends TestWithWallet {
@Test @Test
public void scriptCreationTime() throws Exception { public void scriptCreationTime() throws Exception {
wallet = new Wallet(params); wallet = new Wallet(params);
wallet.setKeychainLookaheadSize(5); // For speed.
Utils.setMockClock(); Utils.setMockClock();
long now = Utils.currentTimeSeconds(); long now = Utils.currentTimeSeconds();
// No keys returns current time. // No keys returns current time.
@ -2373,7 +2370,6 @@ public class WalletTest extends TestWithWallet {
keys.addAll(k); keys.addAll(k);
} }
}, Threading.SAME_THREAD); }, Threading.SAME_THREAD);
wallet.setKeychainLookaheadSize(5);
wallet.freshReceiveKey(); wallet.freshReceiveKey();
assertEquals(6, keys.size()); assertEquals(6, keys.size());
} }

View File

@ -69,7 +69,6 @@ public class ChannelConnectionTest extends TestWithWallet {
sendMoneyToWallet(Utils.COIN, AbstractBlockChain.NewBlockType.BEST_CHAIN); sendMoneyToWallet(Utils.COIN, AbstractBlockChain.NewBlockType.BEST_CHAIN);
wallet.addExtension(new StoredPaymentChannelClientStates(wallet, failBroadcaster)); wallet.addExtension(new StoredPaymentChannelClientStates(wallet, failBroadcaster));
serverWallet = new Wallet(params); serverWallet = new Wallet(params);
serverWallet.setKeychainLookaheadSize(5);
serverWallet.addExtension(new StoredPaymentChannelServerStates(serverWallet, failBroadcaster)); serverWallet.addExtension(new StoredPaymentChannelServerStates(serverWallet, failBroadcaster));
serverWallet.freshReceiveKey(); serverWallet.freshReceiveKey();
serverChain = new BlockChain(params, serverWallet, blockStore); serverChain = new BlockChain(params, serverWallet, blockStore);
@ -544,7 +543,6 @@ public class ChannelConnectionTest extends TestWithWallet {
@Test @Test
public void testEmptyWallet() throws Exception { public void testEmptyWallet() throws Exception {
Wallet emptyWallet = new Wallet(params); Wallet emptyWallet = new Wallet(params);
emptyWallet.setKeychainLookaheadSize(5);
emptyWallet.freshReceiveKey(); emptyWallet.freshReceiveKey();
ChannelTestUtils.RecordingPair pair = ChannelTestUtils.makeRecorders(serverWallet, mockBroadcaster); ChannelTestUtils.RecordingPair pair = ChannelTestUtils.makeRecorders(serverWallet, mockBroadcaster);
PaymentChannelServer server = pair.server; PaymentChannelServer server = pair.server;