コード例 #1
0
 @Test
 public void removeKey() {
   ECKey key = new ECKey();
   chain.importKeys(key);
   assertEquals(1, chain.numKeys());
   assertTrue(chain.removeKey(key));
   assertEquals(0, chain.numKeys());
   assertFalse(chain.removeKey(key));
 }
コード例 #2
0
 @Test
 public void watching() throws UnreadableWalletException {
   ECKey key1 = new ECKey();
   ECKey pub = ECKey.fromPublicOnly(key1.getPubKeyPoint());
   chain.importKeys(pub);
   assertEquals(1, chain.numKeys());
   List<Protos.Key> keys = chain.serializeToProtobuf();
   assertEquals(1, keys.size());
   assertTrue(keys.get(0).hasPublicKey());
   assertFalse(keys.get(0).hasSecretBytes());
   chain = BasicKeyChain.fromProtobufUnencrypted(keys);
   assertEquals(1, chain.numKeys());
   assertFalse(chain.findKeyFromPubKey(pub.getPubKey()).hasPrivKey());
 }
コード例 #3
0
  @Test
  public void importKeys() {
    long now = Utils.currentTimeSeconds();
    Utils.setMockClock(now);
    final ECKey key1 = new ECKey();
    Utils.rollMockClock(86400);
    final ECKey key2 = new ECKey();
    final ArrayList<ECKey> keys = Lists.newArrayList(key1, key2);

    // Import two keys, check the event is correct.
    assertEquals(2, chain.importKeys(keys));
    assertEquals(2, chain.numKeys());
    assertTrue(onKeysAddedRan.getAndSet(false));
    assertArrayEquals(keys.toArray(), onKeysAdded.get().toArray());
    assertEquals(now, chain.getEarliestKeyCreationTime());
    // Check we ignore duplicates.
    final ECKey newKey = new ECKey();
    keys.add(newKey);
    assertEquals(1, chain.importKeys(keys));
    assertTrue(onKeysAddedRan.getAndSet(false));
    assertEquals(newKey, onKeysAdded.getAndSet(null).get(0));
    assertEquals(0, chain.importKeys(keys));
    assertFalse(onKeysAddedRan.getAndSet(false));
    assertNull(onKeysAdded.get());

    assertTrue(chain.hasKey(key1));
    assertTrue(chain.hasKey(key2));
    assertEquals(key1, chain.findKeyFromPubHash(key1.getPubKeyHash()));
    assertEquals(key2, chain.findKeyFromPubKey(key2.getPubKey()));
    assertNull(chain.findKeyFromPubKey(key2.getPubKeyHash()));
  }
コード例 #4
0
 @Test
 public void bloom() throws Exception {
   ECKey key1 = new ECKey();
   ECKey key2 = new ECKey();
   chain.importKeys(key1, key2);
   assertEquals(2, chain.numKeys());
   assertEquals(4, chain.numBloomFilterEntries());
   BloomFilter filter = chain.getFilter(4, 0.001, 100);
   assertTrue(filter.contains(key1.getPubKey()));
   assertTrue(filter.contains(key1.getPubKeyHash()));
   assertTrue(filter.contains(key2.getPubKey()));
   assertTrue(filter.contains(key2.getPubKeyHash()));
   ECKey key3 = new ECKey();
   assertFalse(filter.contains(key3.getPubKey()));
 }