mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-11-02 05:27:17 +00:00
KeyChainGroup: Fix currentKey() and currentAddress() still vends old key/address after new chain was activated.
This commit is contained in:
@@ -272,6 +272,8 @@ public class KeyChainGroup implements KeyBag {
|
|||||||
if (lookaheadThreshold >= 0)
|
if (lookaheadThreshold >= 0)
|
||||||
chain.setLookaheadThreshold(lookaheadThreshold);
|
chain.setLookaheadThreshold(lookaheadThreshold);
|
||||||
chains.add(chain);
|
chains.add(chain);
|
||||||
|
currentKeys.clear();
|
||||||
|
currentAddresses.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -518,6 +518,27 @@ public class KeyChainGroupTest {
|
|||||||
assertEquals(key1, key2);
|
assertEquals(key1, key2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void addAndActivateHDChain_freshCurrentAddress() {
|
||||||
|
DeterministicSeed seed = new DeterministicSeed(ENTROPY, "", 0);
|
||||||
|
DeterministicKeyChain chain1 = DeterministicKeyChain.builder().seed(seed)
|
||||||
|
.accountPath(DeterministicKeyChain.ACCOUNT_ZERO_PATH).outputScriptType(Script.ScriptType.P2PKH).build();
|
||||||
|
group = KeyChainGroup.builder(MAINNET).addChain(chain1).build();
|
||||||
|
assertEquals("1M5T5k9yKtGWRtWYMjQtGx3K2sshrABzCT", group.currentAddress(KeyPurpose.RECEIVE_FUNDS).toString());
|
||||||
|
|
||||||
|
final DeterministicKeyChain chain2 = DeterministicKeyChain.builder().seed(seed)
|
||||||
|
.accountPath(DeterministicKeyChain.ACCOUNT_ONE_PATH).outputScriptType(Script.ScriptType.P2PKH).build();
|
||||||
|
group.addAndActivateHDChain(chain2);
|
||||||
|
assertEquals("1JLnjJEXcyByAaW6sqSxNvGiiSEWRhdvPb", group.currentAddress(KeyPurpose.RECEIVE_FUNDS).toString());
|
||||||
|
|
||||||
|
final DeterministicKeyChain chain3 = DeterministicKeyChain.builder().seed(seed)
|
||||||
|
.accountPath(DeterministicKeyChain.BIP44_ACCOUNT_ZERO_PATH).outputScriptType(Script.ScriptType.P2WPKH)
|
||||||
|
.build();
|
||||||
|
group.addAndActivateHDChain(chain3);
|
||||||
|
assertEquals("bc1q5fa84aghxd6uzk5g2ywkppmzlut5d77vg8cd20",
|
||||||
|
group.currentAddress(KeyPurpose.RECEIVE_FUNDS).toString());
|
||||||
|
}
|
||||||
|
|
||||||
@Test(expected = DeterministicUpgradeRequiredException.class)
|
@Test(expected = DeterministicUpgradeRequiredException.class)
|
||||||
public void deterministicUpgradeRequired() throws Exception {
|
public void deterministicUpgradeRequired() throws Exception {
|
||||||
// Check that if we try to use HD features in a KCG that only has random keys, we get an exception.
|
// Check that if we try to use HD features in a KCG that only has random keys, we get an exception.
|
||||||
|
|||||||
Reference in New Issue
Block a user