mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 14:59:39 -04:00
tests, gui: Use descriptors watchonly wallet for watchonly test
This commit is contained in:
parent
9a4c92eb9a
commit
d9ac9dbd8e
1 changed files with 15 additions and 23 deletions
|
@ -189,36 +189,28 @@ void SyncUpWallet(const std::shared_ptr<CWallet>& wallet, interfaces::Node& node
|
||||||
QVERIFY(result.last_failed_block.IsNull());
|
QVERIFY(result.last_failed_block.IsNull());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<CWallet> SetupLegacyWatchOnlyWallet(interfaces::Node& node, TestChain100Setup& test)
|
std::shared_ptr<CWallet> SetupDescriptorsWallet(interfaces::Node& node, TestChain100Setup& test, bool watch_only = false)
|
||||||
{
|
|
||||||
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(node.context()->chain.get(), "", CreateMockableWalletDatabase());
|
|
||||||
wallet->LoadWallet();
|
|
||||||
{
|
|
||||||
LOCK(wallet->cs_wallet);
|
|
||||||
wallet->SetWalletFlag(WALLET_FLAG_DISABLE_PRIVATE_KEYS);
|
|
||||||
wallet->SetupLegacyScriptPubKeyMan();
|
|
||||||
// Add watched key
|
|
||||||
CPubKey pubKey = test.coinbaseKey.GetPubKey();
|
|
||||||
bool import_keys = wallet->ImportPubKeys({{pubKey.GetID(), false}}, {{pubKey.GetID(), pubKey}} , /*key_origins=*/{}, /*add_keypool=*/false, /*timestamp=*/1);
|
|
||||||
assert(import_keys);
|
|
||||||
wallet->SetLastBlockProcessed(105, WITH_LOCK(node.context()->chainman->GetMutex(), return node.context()->chainman->ActiveChain().Tip()->GetBlockHash()));
|
|
||||||
}
|
|
||||||
SyncUpWallet(wallet, node);
|
|
||||||
return wallet;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<CWallet> SetupDescriptorsWallet(interfaces::Node& node, TestChain100Setup& test)
|
|
||||||
{
|
{
|
||||||
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(node.context()->chain.get(), "", CreateMockableWalletDatabase());
|
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(node.context()->chain.get(), "", CreateMockableWalletDatabase());
|
||||||
wallet->LoadWallet();
|
wallet->LoadWallet();
|
||||||
LOCK(wallet->cs_wallet);
|
LOCK(wallet->cs_wallet);
|
||||||
wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
|
wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
|
||||||
wallet->SetupDescriptorScriptPubKeyMans();
|
if (watch_only) {
|
||||||
|
wallet->SetWalletFlag(WALLET_FLAG_DISABLE_PRIVATE_KEYS);
|
||||||
|
} else {
|
||||||
|
wallet->SetupDescriptorScriptPubKeyMans();
|
||||||
|
}
|
||||||
|
|
||||||
// Add the coinbase key
|
// Add the coinbase key
|
||||||
FlatSigningProvider provider;
|
FlatSigningProvider provider;
|
||||||
std::string error;
|
std::string error;
|
||||||
auto descs = Parse("combo(" + EncodeSecret(test.coinbaseKey) + ")", provider, error, /* require_checksum=*/ false);
|
std::string key_str;
|
||||||
|
if (watch_only) {
|
||||||
|
key_str = HexStr(test.coinbaseKey.GetPubKey());
|
||||||
|
} else {
|
||||||
|
key_str = EncodeSecret(test.coinbaseKey);
|
||||||
|
}
|
||||||
|
auto descs = Parse("combo(" + key_str + ")", provider, error, /* require_checksum=*/ false);
|
||||||
assert(!descs.empty());
|
assert(!descs.empty());
|
||||||
assert(descs.size() == 1);
|
assert(descs.size() == 1);
|
||||||
auto& desc = descs.at(0);
|
auto& desc = descs.at(0);
|
||||||
|
@ -397,7 +389,7 @@ void TestGUI(interfaces::Node& node, const std::shared_ptr<CWallet>& wallet)
|
||||||
|
|
||||||
void TestGUIWatchOnly(interfaces::Node& node, TestChain100Setup& test)
|
void TestGUIWatchOnly(interfaces::Node& node, TestChain100Setup& test)
|
||||||
{
|
{
|
||||||
const std::shared_ptr<CWallet>& wallet = SetupLegacyWatchOnlyWallet(node, test);
|
const std::shared_ptr<CWallet>& wallet = SetupDescriptorsWallet(node, test, /*watch_only=*/true);
|
||||||
|
|
||||||
// Create widgets and init models
|
// Create widgets and init models
|
||||||
std::unique_ptr<const PlatformStyle> platformStyle(PlatformStyle::instantiate("other"));
|
std::unique_ptr<const PlatformStyle> platformStyle(PlatformStyle::instantiate("other"));
|
||||||
|
@ -409,7 +401,7 @@ void TestGUIWatchOnly(interfaces::Node& node, TestChain100Setup& test)
|
||||||
// Update walletModel cached balance which will trigger an update for the 'labelBalance' QLabel.
|
// Update walletModel cached balance which will trigger an update for the 'labelBalance' QLabel.
|
||||||
walletModel.pollBalanceChanged();
|
walletModel.pollBalanceChanged();
|
||||||
// Check balance in send dialog
|
// Check balance in send dialog
|
||||||
CompareBalance(walletModel, walletModel.wallet().getBalances().watch_only_balance,
|
CompareBalance(walletModel, walletModel.wallet().getBalances().balance,
|
||||||
sendCoinsDialog.findChild<QLabel*>("labelBalance"));
|
sendCoinsDialog.findChild<QLabel*>("labelBalance"));
|
||||||
|
|
||||||
// Set change address
|
// Set change address
|
||||||
|
|
Loading…
Add table
Reference in a new issue