11
11
#include < vector>
12
12
13
13
#include < interfaces/chain.h>
14
+ #include < key_io.h>
14
15
#include < node/blockstorage.h>
15
16
#include < node/context.h>
16
17
#include < policy/policy.h>
@@ -43,6 +44,7 @@ BOOST_FIXTURE_TEST_SUITE(wallet_tests, WalletTestingSetup)
43
44
static std::shared_ptr<CWallet> TestLoadWallet(WalletContext& context)
44
45
{
45
46
DatabaseOptions options;
47
+ options.create_flags = WALLET_FLAG_DESCRIPTORS;
46
48
DatabaseStatus status;
47
49
bilingual_str error;
48
50
std::vector<bilingual_str> warnings;
@@ -77,9 +79,13 @@ static CMutableTransaction TestSimpleSpend(const CTransaction& from, uint32_t in
77
79
78
80
static void AddKey (CWallet& wallet, const CKey& key)
79
81
{
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 );
83
89
}
84
90
85
91
BOOST_FIXTURE_TEST_CASE (scan_for_wallet_transactions, TestChain100Setup)
@@ -95,6 +101,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
95
101
CWallet wallet (m_node.chain .get (), " " , CreateDummyWalletDatabase ());
96
102
{
97
103
LOCK (wallet.cs_wallet );
104
+ wallet.SetWalletFlag (WALLET_FLAG_DESCRIPTORS);
98
105
wallet.SetLastBlockProcessed (m_node.chainman ->ActiveChain ().Height (), m_node.chainman ->ActiveChain ().Tip ()->GetBlockHash ());
99
106
}
100
107
AddKey (wallet, coinbaseKey);
@@ -114,6 +121,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
114
121
CWallet wallet (m_node.chain .get (), " " , CreateDummyWalletDatabase ());
115
122
{
116
123
LOCK (wallet.cs_wallet );
124
+ wallet.SetWalletFlag (WALLET_FLAG_DESCRIPTORS);
117
125
wallet.SetLastBlockProcessed (m_node.chainman ->ActiveChain ().Height (), m_node.chainman ->ActiveChain ().Tip ()->GetBlockHash ());
118
126
}
119
127
AddKey (wallet, coinbaseKey);
@@ -140,6 +148,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
140
148
CWallet wallet (m_node.chain .get (), " " , CreateDummyWalletDatabase ());
141
149
{
142
150
LOCK (wallet.cs_wallet );
151
+ wallet.SetWalletFlag (WALLET_FLAG_DESCRIPTORS);
143
152
wallet.SetLastBlockProcessed (m_node.chainman ->ActiveChain ().Height (), m_node.chainman ->ActiveChain ().Tip ()->GetBlockHash ());
144
153
}
145
154
AddKey (wallet, coinbaseKey);
@@ -165,6 +174,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
165
174
CWallet wallet (m_node.chain .get (), " " , CreateDummyWalletDatabase ());
166
175
{
167
176
LOCK (wallet.cs_wallet );
177
+ wallet.SetWalletFlag (WALLET_FLAG_DESCRIPTORS);
168
178
wallet.SetLastBlockProcessed (m_node.chainman ->ActiveChain ().Height (), m_node.chainman ->ActiveChain ().Tip ()->GetBlockHash ());
169
179
}
170
180
AddKey (wallet, coinbaseKey);
@@ -320,10 +330,12 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup)
320
330
BOOST_FIXTURE_TEST_CASE (coin_mark_dirty_immature_credit, TestChain100Setup)
321
331
{
322
332
CWallet wallet (m_node.chain .get (), " " , CreateDummyWalletDatabase ());
323
- auto spk_man = wallet.GetOrCreateLegacyScriptPubKeyMan ();
324
333
CWalletTx wtx (m_coinbase_txns.back ());
325
334
326
- LOCK2 (wallet.cs_wallet , spk_man->cs_KeyStore );
335
+ LOCK (wallet.cs_wallet );
336
+ wallet.SetWalletFlag (WALLET_FLAG_DESCRIPTORS);
337
+ wallet.SetupDescriptorScriptPubKeyMans ();
338
+
327
339
wallet.SetLastBlockProcessed (m_node.chainman ->ActiveChain ().Height (), m_node.chainman ->ActiveChain ().Tip ()->GetBlockHash ());
328
340
329
341
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)
336
348
// Invalidate the cached value, add the key, and make sure a new immature
337
349
// credit amount is calculated.
338
350
wtx.MarkDirty ();
339
- BOOST_CHECK (spk_man-> AddKeyPubKey (coinbaseKey , coinbaseKey. GetPubKey ()) );
351
+ AddKey (wallet , coinbaseKey);
340
352
BOOST_CHECK_EQUAL (CachedTxGetImmatureCredit (wallet, wtx), 50 *COIN);
341
353
}
342
354
@@ -593,14 +605,26 @@ BOOST_FIXTURE_TEST_CASE(ListCoinsTest, ListCoinsTestingSetup)
593
605
594
606
BOOST_FIXTURE_TEST_CASE (wallet_disableprivkeys, TestChain100Setup)
595
607
{
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
+ }
604
628
}
605
629
606
630
// Explicit calculation which is used to test the wallet constant
0 commit comments