diff --git a/core/src/main/java/com/google/bitcoin/testing/TestWithWallet.java b/core/src/main/java/com/google/bitcoin/testing/TestWithWallet.java index 66e3be53..0da93cb0 100644 --- a/core/src/main/java/com/google/bitcoin/testing/TestWithWallet.java +++ b/core/src/main/java/com/google/bitcoin/testing/TestWithWallet.java @@ -51,11 +51,10 @@ public class TestWithWallet { public void setUp() throws Exception { BriefLogFormatter.init(); Wallet.SendRequest.DEFAULT_FEE_PER_KB = BigInteger.ZERO; - myKey = new ECKey(); - myAddress = myKey.toAddress(params); wallet = new Wallet(params); wallet.setKeychainLookaheadSize(5); - wallet.importKey(myKey); + myKey = wallet.currentReceiveKey(); + myAddress = myKey.toAddress(params); blockStore = new MemoryBlockStore(params); chain = new BlockChain(params, wallet, blockStore); } diff --git a/core/src/test/java/com/google/bitcoin/core/WalletTest.java b/core/src/test/java/com/google/bitcoin/core/WalletTest.java index 2cf55b1f..b98ca448 100644 --- a/core/src/test/java/com/google/bitcoin/core/WalletTest.java +++ b/core/src/test/java/com/google/bitcoin/core/WalletTest.java @@ -1097,15 +1097,14 @@ public class WalletTest extends TestWithWallet { @Test(expected = ECKey.MissingPrivateKeyException.class) public void watchingWallet() throws Exception { - DeterministicKey key = wallet.freshReceiveKey(); DeterministicKey watchKey = wallet.getWatchingKey(); String serialized = watchKey.serializePubB58(); watchKey = DeterministicKey.deserializeB58(null, serialized); Wallet watchingWallet = Wallet.fromWatchingKey(params, watchKey); DeterministicKey key2 = watchingWallet.freshReceiveKey(); - assertEquals(key, key2); + assertEquals(myKey, key2); - key = wallet.freshKey(KeyChain.KeyPurpose.CHANGE); + ECKey key = wallet.freshKey(KeyChain.KeyPurpose.CHANGE); key2 = watchingWallet.freshKey(KeyChain.KeyPurpose.CHANGE); assertEquals(key, key2); key.sign(Sha256Hash.ZERO_HASH); @@ -1141,13 +1140,13 @@ public class WalletTest extends TestWithWallet { @Test public void watchingScriptsSentFrom() throws Exception { - assertEquals(2, wallet.getBloomFilterElementCount()); + int baseElements = wallet.getBloomFilterElementCount(); ECKey key = new ECKey(); ECKey notMyAddr = new ECKey(); Address watchedAddress = key.toAddress(params); wallet.addWatchedAddress(watchedAddress); - assertEquals(3, wallet.getBloomFilterElementCount()); + assertEquals(baseElements + 1, wallet.getBloomFilterElementCount()); Transaction t1 = createFakeTx(params, CENT, watchedAddress); Transaction t2 = createFakeTx(params, COIN, notMyAddr); @@ -1158,9 +1157,9 @@ public class WalletTest extends TestWithWallet { st2.addInput(t1.getOutput(0)); st2.addInput(t2.getOutput(0)); wallet.receiveFromBlock(t1, b1, BlockChain.NewBlockType.BEST_CHAIN, 0); - assertEquals(4, wallet.getBloomFilterElementCount()); + assertEquals(baseElements + 2, wallet.getBloomFilterElementCount()); wallet.receiveFromBlock(st2, b1, BlockChain.NewBlockType.BEST_CHAIN, 0); - assertEquals(4, wallet.getBloomFilterElementCount()); + assertEquals(baseElements + 2, wallet.getBloomFilterElementCount()); assertEquals(CENT, st2.getValueSentFromMe(wallet)); }