Beispiel #1
0
 @Test
 public void findRedeemScriptFromPubHash() throws Exception {
   group = createMarriedKeyChainGroup();
   Address address = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
   assertTrue(group.findRedeemDataFromScriptHash(address.getHash160()) != null);
   group.getBloomFilterElementCount();
   KeyChainGroup group2 = createMarriedKeyChainGroup();
   group2.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
   group2.getBloomFilterElementCount(); // Force lookahead.
   // test address from lookahead zone and lookahead threshold zone
   for (int i = 0; i < group.getLookaheadSize() + group.getLookaheadThreshold(); i++) {
     address = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
     assertTrue(group2.findRedeemDataFromScriptHash(address.getHash160()) != null);
   }
   assertFalse(
       group2.findRedeemDataFromScriptHash(
               group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS).getHash160())
           != null);
 }
Beispiel #2
0
  @Test
  public void bloomFilterForMarriedChains() throws Exception {
    group = createMarriedKeyChainGroup();
    int bufferSize = group.getLookaheadSize() + group.getLookaheadThreshold();
    int expected = bufferSize * 2 /* chains */ * 2 /* elements */;
    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));
    assertTrue(filter.contains(address1.getHash160()));

    Address address2 = group.freshAddress(KeyChain.KeyPurpose.CHANGE);
    assertTrue(filter.contains(address2.getHash160()));

    // Check that the filter contains the lookahead buffer.
    for (int i = 0; i < bufferSize - 1 /* issued address */; i++) {
      Address address = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
      assertTrue("key " + i, filter.contains(address.getHash160()));
    }
    // We ran ahead of the lookahead buffer.
    assertFalse(
        filter.contains(group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS).getHash160()));
  }
Beispiel #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);
  }
Beispiel #4
0
 @Test(expected = IllegalStateException.class)
 public void addFollowingAccountsForUsedKeychainShouldFail() {
   group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
   group.addFollowingAccountKeys(ImmutableList.of(watchingAccountKey));
 }