diff options
Diffstat (limited to 'src/selftest.cpp')
| -rw-r--r-- | src/selftest.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/selftest.cpp b/src/selftest.cpp index 67f96f8..df55bcd 100644 --- a/src/selftest.cpp +++ b/src/selftest.cpp | |||
| @@ -336,6 +336,7 @@ static int RunWalletHDSelfTest() | |||
| 336 | 336 | ||
| 337 | // The address the wallet was showing before any of this. It has to | 337 | // The address the wallet was showing before any of this. It has to |
| 338 | // survive under a name that says it is not covered by the phrase. | 338 | // survive under a name that says it is not covered by the phrase. |
| 339 | std::vector<unsigned char> vchPreSeedKey = keyUser.GetPubKey(); | ||
| 339 | std::string strPreSeedAddr = PubKeyToAddress(keyUser.GetPubKey()); | 340 | std::string strPreSeedAddr = PubKeyToAddress(keyUser.GetPubKey()); |
| 340 | 341 | ||
| 341 | nFail += Check(SetHDSeedFromMnemonic(strPhraseA, strError), | 342 | nFail += Check(SetHDSeedFromMnemonic(strPhraseA, strError), |
| @@ -449,6 +450,41 @@ static int RunWalletHDSelfTest() | |||
| 449 | } | 450 | } |
| 450 | nFail += Check(fStored, "every derived pooled key is stored in wallet.dat") ? 0 : 1; | 451 | nFail += Check(fStored, "every derived pooled key is stored in wallet.dat") ? 0 : 1; |
| 451 | nFail += Check(fFromSeed, "every pooled key came from the seed, not from chance") ? 0 : 1; | 452 | nFail += Check(fFromSeed, "every pooled key came from the seed, not from chance") ? 0 : 1; |
| 453 | |||
| 454 | // A recovery phrase is only useful if the wallet can tell the user | ||
| 455 | // what today's spendable balance would actually come back from it. | ||
| 456 | CKey keyAuditDerived; | ||
| 457 | if (!DeriveHDKey(0, keyAuditDerived, strError)) | ||
| 458 | throw std::runtime_error("audit derivation failed: " + strError); | ||
| 459 | |||
| 460 | CWalletTx wtxLegacy; | ||
| 461 | wtxLegacy.vout.push_back(CTxOut(5 * COIN, CScript() << vchPreSeedKey << OP_CHECKSIG)); | ||
| 462 | CWalletTx wtxDerived; | ||
| 463 | wtxDerived.vout.push_back(CTxOut(7 * COIN, CScript() << keyAuditDerived.GetPubKey() << OP_CHECKSIG)); | ||
| 464 | CWalletTx wtxImmatureLegacy; | ||
| 465 | wtxImmatureLegacy.vin.push_back(CTxIn()); | ||
| 466 | wtxImmatureLegacy.vout.push_back(CTxOut(11 * COIN, CScript() << vchPreSeedKey << OP_CHECKSIG)); | ||
| 467 | |||
| 468 | CRITICAL_BLOCK(cs_mapWallet) | ||
| 469 | { | ||
| 470 | mapWallet.clear(); | ||
| 471 | mapWallet[wtxLegacy.GetHash()] = wtxLegacy; | ||
| 472 | mapWallet[wtxDerived.GetHash()] = wtxDerived; | ||
| 473 | mapWallet[wtxImmatureLegacy.GetHash()] = wtxImmatureLegacy; | ||
| 474 | } | ||
| 475 | |||
| 476 | WalletRecoveryAudit audit = GetWalletRecoveryAudit(); | ||
| 477 | nFail += Check(audit.fHaveSeed, "the recovery audit reports the phrase") ? 0 : 1; | ||
| 478 | nFail += Check(audit.nLegacyCredit == 5 * COIN, | ||
| 479 | "the recovery audit finds wallet.dat-only balance") ? 0 : 1; | ||
| 480 | nFail += Check(audit.nRecoverableCredit == 7 * COIN, | ||
| 481 | "the recovery audit finds phrase-backed balance") ? 0 : 1; | ||
| 482 | nFail += Check(audit.nLegacyTx == 1 && audit.nRecoverableTx == 1, | ||
| 483 | "the recovery audit counts legacy and phrase-backed transactions") ? 0 : 1; | ||
| 484 | nFail += Check(audit.nLegacyImmatureCredit == 11 * COIN, | ||
| 485 | "the recovery audit finds wallet.dat-only immature mining rewards") ? 0 : 1; | ||
| 486 | nFail += Check(audit.nLegacyImmatureTx == 1, | ||
| 487 | "the recovery audit counts wallet.dat-only immature mining rewards") ? 0 : 1; | ||
| 452 | } | 488 | } |
| 453 | catch (const std::exception& e) | 489 | catch (const std::exception& e) |
| 454 | { | 490 | { |