Skip to content

Commit

Permalink
KeyChainGroupTest: reduce false positive rate for the bloom filters
Browse files Browse the repository at this point in the history
This will hopefully reduce spurious test failures.

This is a backport of b585f9f.
  • Loading branch information
schildbach committed Jun 24, 2024
1 parent 9b8660f commit 4059c95
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions core/src/test/java/org/bitcoinj/wallet/KeyChainGroupTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class KeyChainGroupTest {
private static final byte[] ENTROPY = Sha256Hash.hash("don't use a string seed like this in real life".getBytes());
private static final KeyCrypterScrypt KEY_CRYPTER = new KeyCrypterScrypt(2);
private static final KeyParameter AES_KEY = KEY_CRYPTER.deriveKey("password");
private static final double LOW_FALSE_POSITIVE_RATE = 0.00001;
private KeyChainGroup group;
private DeterministicKey watchingAccountKey;

Expand Down Expand Up @@ -334,7 +335,7 @@ public void encryptionWhilstEmpty() throws Exception {
public void bloom() throws Exception {
ECKey key1 = group.freshKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
ECKey key2 = new ECKey();
BloomFilter filter = group.getBloomFilter(group.getBloomFilterElementCount(), 0.001, (long)(Math.random() * Long.MAX_VALUE));
BloomFilter filter = group.getBloomFilter(group.getBloomFilterElementCount(), LOW_FALSE_POSITIVE_RATE, (long)(Math.random() * Long.MAX_VALUE));
assertTrue(filter.contains(key1.getPubKeyHash()));
assertTrue(filter.contains(key1.getPubKey()));
assertFalse(filter.contains(key2.getPubKey()));
Expand All @@ -346,7 +347,7 @@ public void bloom() throws Exception {
// We ran ahead of the lookahead buffer.
assertFalse(filter.contains(group.freshKey(KeyChain.KeyPurpose.RECEIVE_FUNDS).getPubKey()));
group.importKeys(key2);
filter = group.getBloomFilter(group.getBloomFilterElementCount(), 0.001, (long) (Math.random() * Long.MAX_VALUE));
filter = group.getBloomFilter(group.getBloomFilterElementCount(), LOW_FALSE_POSITIVE_RATE, (long) (Math.random() * Long.MAX_VALUE));
assertTrue(filter.contains(key1.getPubKeyHash()));
assertTrue(filter.contains(key1.getPubKey()));
assertTrue(filter.contains(key2.getPubKey()));
Expand Down Expand Up @@ -377,7 +378,7 @@ public void bloomFilterForMarriedChains() throws Exception {
assertEquals(expected, group.getBloomFilterElementCount());
Address address1 = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
assertEquals(expected, group.getBloomFilterElementCount());
BloomFilter filter = group.getBloomFilter(expected + 2, 0.001, (long)(Math.random() * Long.MAX_VALUE));
BloomFilter filter = group.getBloomFilter(expected + 2, LOW_FALSE_POSITIVE_RATE, (long)(Math.random() * Long.MAX_VALUE));
assertTrue(filter.contains(address1.getHash()));

Address address2 = group.freshAddress(KeyChain.KeyPurpose.CHANGE);
Expand Down

0 comments on commit 4059c95

Please sign in to comment.