Example #1
0
 @Test
 public void imports() throws Exception {
   ECKey key1 = new ECKey();
   int numKeys = group.numKeys();
   assertFalse(group.removeImportedKey(key1));
   assertEquals(1, group.importKeys(ImmutableList.of(key1)));
   assertEquals(
       numKeys + 1, group.numKeys()); // Lookahead is triggered by requesting a key, so none yet.
   group.removeImportedKey(key1);
   assertEquals(numKeys, group.numKeys());
 }
Example #2
0
  @Test
  public void freshCurrentKeys() throws Exception {
    int numKeys =
        ((group.getLookaheadSize() + group.getLookaheadThreshold())
                * 2) // * 2 because of internal/external
            + 1 // keys issued
            + 3 /* account key + int/ext parent keys */;
    assertEquals(numKeys, group.numKeys());
    assertEquals(2 * numKeys, group.getBloomFilterElementCount());
    ECKey r1 = group.currentKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
    assertEquals(numKeys, group.numKeys());
    assertEquals(2 * numKeys, group.getBloomFilterElementCount());

    ECKey i1 = new ECKey();
    group.importKeys(i1);
    numKeys++;
    assertEquals(numKeys, group.numKeys());
    assertEquals(2 * numKeys, group.getBloomFilterElementCount());

    ECKey r2 = group.currentKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
    assertEquals(r1, r2);
    ECKey c1 = group.currentKey(KeyChain.KeyPurpose.CHANGE);
    assertNotEquals(r1, c1);
    ECKey r3 = group.freshKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
    assertNotEquals(r1, r3);
    ECKey c2 = group.freshKey(KeyChain.KeyPurpose.CHANGE);
    assertNotEquals(r3, c2);
    // Current key has not moved and will not under marked as used.
    ECKey r4 = group.currentKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
    assertEquals(r2, r4);
    ECKey c3 = group.currentKey(KeyChain.KeyPurpose.CHANGE);
    assertEquals(c1, c3);
    // Mark as used. Current key is now different.
    group.markPubKeyAsUsed(r4.getPubKey());
    ECKey r5 = group.currentKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
    assertNotEquals(r4, r5);
  }
Example #3
0
  @Test
  public void freshAddress() throws Exception {
    group = createMarriedKeyChainGroup();
    Address a1 = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
    Address a2 = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
    assertTrue(a1.isP2SHAddress());
    assertNotEquals(a1, a2);
    group.getBloomFilterElementCount();
    assertEquals(
        ((group.getLookaheadSize() + group.getLookaheadThreshold())
                * 2) // * 2 because of internal/external
            + (2 - group.getLookaheadThreshold()) // keys issued
            + 4 /* master, account, int, ext */,
        group.numKeys());

    Address a3 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
    assertEquals(a2, a3);
  }