Skip to content

Commit 2d2edc1

Browse files
committed
tests: Use Descriptor wallets for generic wallet tests
For the generic wallet tests, make DescriptorScriptPubKeyMans. There are still some wallet tests that test legacy wallet things. Those remain unchanged.
1 parent 9951628 commit 2d2edc1

File tree

2 files changed

+49
-17
lines changed

2 files changed

+49
-17
lines changed

src/wallet/test/util.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <chain.h>
88
#include <key.h>
9+
#include <key_io.h>
910
#include <test/util/setup_common.h>
1011
#include <wallet/wallet.h>
1112
#include <wallet/walletdb.h>
@@ -23,9 +24,16 @@ std::unique_ptr<CWallet> CreateSyncedWallet(interfaces::Chain& chain, CChain& cc
2324
}
2425
wallet->LoadWallet();
2526
{
26-
auto spk_man = wallet->GetOrCreateLegacyScriptPubKeyMan();
27-
LOCK2(wallet->cs_wallet, spk_man->cs_KeyStore);
28-
spk_man->AddKeyPubKey(key, key.GetPubKey());
27+
LOCK(wallet->cs_wallet);
28+
wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
29+
wallet->SetupDescriptorScriptPubKeyMans();
30+
31+
FlatSigningProvider provider;
32+
std::string error;
33+
std::unique_ptr<Descriptor> desc = Parse("combo(" + EncodeSecret(key) + ")", provider, error, /* require_checksum=*/ false);
34+
assert(desc);
35+
WalletDescriptor w_desc(std::move(desc), 0, 0, 1, 1);
36+
if (!wallet->AddWalletDescriptor(w_desc, provider, "", false)) assert(false);
2937
}
3038
WalletRescanReserver reserver(*wallet);
3139
reserver.reserve();

src/wallet/test/wallet_tests.cpp

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <vector>
1212

1313
#include <interfaces/chain.h>
14+
#include <key_io.h>
1415
#include <node/blockstorage.h>
1516
#include <node/context.h>
1617
#include <policy/policy.h>
@@ -43,6 +44,7 @@ BOOST_FIXTURE_TEST_SUITE(wallet_tests, WalletTestingSetup)
4344
static std::shared_ptr<CWallet> TestLoadWallet(WalletContext& context)
4445
{
4546
DatabaseOptions options;
47+
options.create_flags = WALLET_FLAG_DESCRIPTORS;
4648
DatabaseStatus status;
4749
bilingual_str error;
4850
std::vector<bilingual_str> warnings;
@@ -77,9 +79,13 @@ static CMutableTransaction TestSimpleSpend(const CTransaction& from, uint32_t in
7779

7880
static void AddKey(CWallet& wallet, const CKey& key)
7981
{
80-
auto spk_man = wallet.GetOrCreateLegacyScriptPubKeyMan();
81-
LOCK2(wallet.cs_wallet, spk_man->cs_KeyStore);
82-
spk_man->AddKeyPubKey(key, key.GetPubKey());
82+
LOCK(wallet.cs_wallet);
83+
FlatSigningProvider provider;
84+
std::string error;
85+
std::unique_ptr<Descriptor> desc = Parse("combo(" + EncodeSecret(key) + ")", provider, error, /* require_checksum=*/ false);
86+
assert(desc);
87+
WalletDescriptor w_desc(std::move(desc), 0, 0, 1, 1);
88+
if (!wallet.AddWalletDescriptor(w_desc, provider, "", false)) assert(false);
8389
}
8490

8591
BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
@@ -95,6 +101,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
95101
CWallet wallet(m_node.chain.get(), "", CreateDummyWalletDatabase());
96102
{
97103
LOCK(wallet.cs_wallet);
104+
wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
98105
wallet.SetLastBlockProcessed(m_node.chainman->ActiveChain().Height(), m_node.chainman->ActiveChain().Tip()->GetBlockHash());
99106
}
100107
AddKey(wallet, coinbaseKey);
@@ -114,6 +121,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
114121
CWallet wallet(m_node.chain.get(), "", CreateDummyWalletDatabase());
115122
{
116123
LOCK(wallet.cs_wallet);
124+
wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
117125
wallet.SetLastBlockProcessed(m_node.chainman->ActiveChain().Height(), m_node.chainman->ActiveChain().Tip()->GetBlockHash());
118126
}
119127
AddKey(wallet, coinbaseKey);
@@ -140,6 +148,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
140148
CWallet wallet(m_node.chain.get(), "", CreateDummyWalletDatabase());
141149
{
142150
LOCK(wallet.cs_wallet);
151+
wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
143152
wallet.SetLastBlockProcessed(m_node.chainman->ActiveChain().Height(), m_node.chainman->ActiveChain().Tip()->GetBlockHash());
144153
}
145154
AddKey(wallet, coinbaseKey);
@@ -165,6 +174,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
165174
CWallet wallet(m_node.chain.get(), "", CreateDummyWalletDatabase());
166175
{
167176
LOCK(wallet.cs_wallet);
177+
wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
168178
wallet.SetLastBlockProcessed(m_node.chainman->ActiveChain().Height(), m_node.chainman->ActiveChain().Tip()->GetBlockHash());
169179
}
170180
AddKey(wallet, coinbaseKey);
@@ -320,10 +330,12 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup)
320330
BOOST_FIXTURE_TEST_CASE(coin_mark_dirty_immature_credit, TestChain100Setup)
321331
{
322332
CWallet wallet(m_node.chain.get(), "", CreateDummyWalletDatabase());
323-
auto spk_man = wallet.GetOrCreateLegacyScriptPubKeyMan();
324333
CWalletTx wtx(m_coinbase_txns.back());
325334

326-
LOCK2(wallet.cs_wallet, spk_man->cs_KeyStore);
335+
LOCK(wallet.cs_wallet);
336+
wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
337+
wallet.SetupDescriptorScriptPubKeyMans();
338+
327339
wallet.SetLastBlockProcessed(m_node.chainman->ActiveChain().Height(), m_node.chainman->ActiveChain().Tip()->GetBlockHash());
328340

329341
CWalletTx::Confirmation confirm(CWalletTx::Status::CONFIRMED, m_node.chainman->ActiveChain().Height(), m_node.chainman->ActiveChain().Tip()->GetBlockHash(), 0);
@@ -336,7 +348,7 @@ BOOST_FIXTURE_TEST_CASE(coin_mark_dirty_immature_credit, TestChain100Setup)
336348
// Invalidate the cached value, add the key, and make sure a new immature
337349
// credit amount is calculated.
338350
wtx.MarkDirty();
339-
BOOST_CHECK(spk_man->AddKeyPubKey(coinbaseKey, coinbaseKey.GetPubKey()));
351+
AddKey(wallet, coinbaseKey);
340352
BOOST_CHECK_EQUAL(CachedTxGetImmatureCredit(wallet, wtx), 50*COIN);
341353
}
342354

@@ -593,14 +605,26 @@ BOOST_FIXTURE_TEST_CASE(ListCoinsTest, ListCoinsTestingSetup)
593605

594606
BOOST_FIXTURE_TEST_CASE(wallet_disableprivkeys, TestChain100Setup)
595607
{
596-
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(m_node.chain.get(), "", CreateDummyWalletDatabase());
597-
wallet->SetupLegacyScriptPubKeyMan();
598-
wallet->SetMinVersion(FEATURE_LATEST);
599-
wallet->SetWalletFlag(WALLET_FLAG_DISABLE_PRIVATE_KEYS);
600-
BOOST_CHECK(!wallet->TopUpKeyPool(1000));
601-
CTxDestination dest;
602-
bilingual_str error;
603-
BOOST_CHECK(!wallet->GetNewDestination(OutputType::BECH32, "", dest, error));
608+
{
609+
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(m_node.chain.get(), "", CreateDummyWalletDatabase());
610+
wallet->SetupLegacyScriptPubKeyMan();
611+
wallet->SetMinVersion(FEATURE_LATEST);
612+
wallet->SetWalletFlag(WALLET_FLAG_DISABLE_PRIVATE_KEYS);
613+
BOOST_CHECK(!wallet->TopUpKeyPool(1000));
614+
CTxDestination dest;
615+
bilingual_str error;
616+
BOOST_CHECK(!wallet->GetNewDestination(OutputType::BECH32, "", dest, error));
617+
}
618+
{
619+
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(m_node.chain.get(), "", CreateDummyWalletDatabase());
620+
LOCK(wallet->cs_wallet);
621+
wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
622+
wallet->SetMinVersion(FEATURE_LATEST);
623+
wallet->SetWalletFlag(WALLET_FLAG_DISABLE_PRIVATE_KEYS);
624+
CTxDestination dest;
625+
bilingual_str error;
626+
BOOST_CHECK(!wallet->GetNewDestination(OutputType::BECH32, "", dest, error));
627+
}
604628
}
605629

606630
// Explicit calculation which is used to test the wallet constant

0 commit comments

Comments
 (0)