@Test 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)); assertTrue(filter.contains(key1.getPubKeyHash())); assertTrue(filter.contains(key1.getPubKey())); assertFalse(filter.contains(key2.getPubKey())); // Check that the filter contains the lookahead buffer and threshold zone. for (int i = 0; i < LOOKAHEAD_SIZE + group.getLookaheadThreshold(); i++) { ECKey k = group.freshKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); assertTrue(filter.contains(k.getPubKeyHash())); } // 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)); assertTrue(filter.contains(key1.getPubKeyHash())); assertTrue(filter.contains(key1.getPubKey())); assertTrue(filter.contains(key2.getPubKey())); }
@Test public void findKey() throws Exception { ECKey a = group.freshKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); ECKey b = group.freshKey(KeyChain.KeyPurpose.CHANGE); ECKey c = new ECKey(); ECKey d = new ECKey(); // Not imported. group.importKeys(c); assertTrue(group.hasKey(a)); assertTrue(group.hasKey(b)); assertTrue(group.hasKey(c)); assertFalse(group.hasKey(d)); ECKey result = group.findKeyFromPubKey(a.getPubKey()); assertEquals(a, result); result = group.findKeyFromPubKey(b.getPubKey()); assertEquals(b, result); result = group.findKeyFromPubHash(a.getPubKeyHash()); assertEquals(a, result); result = group.findKeyFromPubHash(b.getPubKeyHash()); assertEquals(b, result); result = group.findKeyFromPubKey(c.getPubKey()); assertEquals(c, result); result = group.findKeyFromPubHash(c.getPubKeyHash()); assertEquals(c, result); assertNull(group.findKeyFromPubKey(d.getPubKey())); assertNull(group.findKeyFromPubHash(d.getPubKeyHash())); }