示例#1
0
 @Test
 public void markAsUsed() throws Exception {
   Address addr1 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
   Address addr2 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
   assertEquals(addr1, addr2);
   group.markPubKeyHashAsUsed(addr1.getHash160());
   Address addr3 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
   assertNotEquals(addr2, addr3);
 }
示例#2
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);
 }
示例#3
0
  @Test
  public void findRedeemData() throws Exception {
    group = createMarriedKeyChainGroup();

    // test script hash that we don't have
    assertNull(group.findRedeemDataFromScriptHash(new ECKey().getPubKey()));

    // test our script hash
    Address address = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
    RedeemData redeemData = group.findRedeemDataFromScriptHash(address.getHash160());
    assertNotNull(redeemData);
    assertNotNull(redeemData.redeemScript);
    assertEquals(2, redeemData.keys.size());
  }
示例#4
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()));
  }