@@ -173,6 +173,39 @@ void VerifyUseAvailableBalance(SendCoinsDialog& sendCoinsDialog, const WalletMod
173
173
QVERIFY (send_entry->getValue ().amount == sum_selected_coins);
174
174
}
175
175
176
+ void SyncUpWallet (const std::shared_ptr<CWallet>& wallet, interfaces::Node& node)
177
+ {
178
+ WalletRescanReserver reserver (*wallet);
179
+ reserver.reserve ();
180
+ CWallet::ScanResult result = wallet->ScanForWalletTransactions (Params ().GetConsensus ().hashGenesisBlock , /* start_height=*/ 0 , /* max_height=*/ {}, reserver, /* fUpdate=*/ true , /* save_progress=*/ false );
181
+ QCOMPARE (result.status , CWallet::ScanResult::SUCCESS);
182
+ QCOMPARE (result.last_scanned_block , WITH_LOCK (node.context ()->chainman ->GetMutex (), return node.context ()->chainman ->ActiveChain ().Tip ()->GetBlockHash ()));
183
+ QVERIFY (result.last_failed_block .IsNull ());
184
+ }
185
+
186
+ std::shared_ptr<CWallet> SetupDescriptorsWallet (interfaces::Node& node, TestChain100Setup& test)
187
+ {
188
+ std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(node.context ()->chain .get (), " " , CreateMockWalletDatabase ());
189
+ wallet->LoadWallet ();
190
+ LOCK (wallet->cs_wallet );
191
+ wallet->SetWalletFlag (WALLET_FLAG_DESCRIPTORS);
192
+ wallet->SetupDescriptorScriptPubKeyMans ();
193
+
194
+ // Add the coinbase key
195
+ FlatSigningProvider provider;
196
+ std::string error;
197
+ std::unique_ptr<Descriptor> desc = Parse (" combo(" + EncodeSecret (test.coinbaseKey ) + " )" , provider, error, /* require_checksum=*/ false );
198
+ assert (desc);
199
+ WalletDescriptor w_desc (std::move (desc), 0 , 0 , 1 , 1 );
200
+ if (!wallet->AddWalletDescriptor (w_desc, provider, " " , false )) assert (false );
201
+ CTxDestination dest = GetDestinationForKey (test.coinbaseKey .GetPubKey (), wallet->m_default_address_type );
202
+ wallet->SetAddressBook (dest, " " , " receive" );
203
+ wallet->SetLastBlockProcessed (105 , WITH_LOCK (node.context ()->chainman ->GetMutex (), return node.context ()->chainman ->ActiveChain ().Tip ()->GetBlockHash ()));
204
+ SyncUpWallet (wallet, node);
205
+ wallet->SetBroadcastTransactions (true );
206
+ return wallet;
207
+ }
208
+
176
209
// ! Simple qt wallet tests.
177
210
//
178
211
// Test widgets can be debugged interactively calling show() on them and
@@ -186,44 +219,8 @@ void VerifyUseAvailableBalance(SendCoinsDialog& sendCoinsDialog, const WalletMod
186
219
// QT_QPA_PLATFORM=xcb src/qt/test/test_bitcoin-qt # Linux
187
220
// QT_QPA_PLATFORM=windows src/qt/test/test_bitcoin-qt # Windows
188
221
// QT_QPA_PLATFORM=cocoa src/qt/test/test_bitcoin-qt # macOS
189
- void TestGUI (interfaces::Node& node)
222
+ void TestGUI (interfaces::Node& node, const std::shared_ptr<CWallet>& wallet )
190
223
{
191
- // Set up wallet and chain with 105 blocks (5 mature blocks for spending).
192
- TestChain100Setup test;
193
- for (int i = 0 ; i < 5 ; ++i) {
194
- test.CreateAndProcessBlock ({}, GetScriptForRawPubKey (test.coinbaseKey .GetPubKey ()));
195
- }
196
- auto wallet_loader = interfaces::MakeWalletLoader (*test.m_node .chain , *Assert (test.m_node .args ));
197
- test.m_node .wallet_loader = wallet_loader.get ();
198
- node.setContext (&test.m_node );
199
- const std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(node.context ()->chain .get (), " " , CreateMockWalletDatabase ());
200
- wallet->LoadWallet ();
201
- wallet->SetWalletFlag (WALLET_FLAG_DESCRIPTORS);
202
- {
203
- LOCK (wallet->cs_wallet );
204
- wallet->SetupDescriptorScriptPubKeyMans ();
205
-
206
- // Add the coinbase key
207
- FlatSigningProvider provider;
208
- std::string error;
209
- std::unique_ptr<Descriptor> desc = Parse (" combo(" + EncodeSecret (test.coinbaseKey ) + " )" , provider, error, /* require_checksum=*/ false );
210
- assert (desc);
211
- WalletDescriptor w_desc (std::move (desc), 0 , 0 , 1 , 1 );
212
- if (!wallet->AddWalletDescriptor (w_desc, provider, " " , false )) assert (false );
213
- CTxDestination dest = GetDestinationForKey (test.coinbaseKey .GetPubKey (), wallet->m_default_address_type );
214
- wallet->SetAddressBook (dest, " " , " receive" );
215
- wallet->SetLastBlockProcessed (105 , WITH_LOCK (node.context ()->chainman ->GetMutex (), return node.context ()->chainman ->ActiveChain ().Tip ()->GetBlockHash ()));
216
- }
217
- {
218
- WalletRescanReserver reserver (*wallet);
219
- reserver.reserve ();
220
- CWallet::ScanResult result = wallet->ScanForWalletTransactions (Params ().GetConsensus ().hashGenesisBlock , /* start_height=*/ 0 , /* max_height=*/ {}, reserver, /* fUpdate=*/ true , /* save_progress=*/ false );
221
- QCOMPARE (result.status , CWallet::ScanResult::SUCCESS);
222
- QCOMPARE (result.last_scanned_block , WITH_LOCK (node.context ()->chainman ->GetMutex (), return node.context ()->chainman ->ActiveChain ().Tip ()->GetBlockHash ()));
223
- QVERIFY (result.last_failed_block .IsNull ());
224
- }
225
- wallet->SetBroadcastTransactions (true );
226
-
227
224
// Create widgets for sending coins and listing transactions.
228
225
std::unique_ptr<const PlatformStyle> platformStyle (PlatformStyle::instantiate (" other" ));
229
226
SendCoinsDialog sendCoinsDialog (platformStyle.get ());
@@ -353,6 +350,22 @@ void TestGUI(interfaces::Node& node)
353
350
QCOMPARE (walletModel.wallet ().getAddressReceiveRequests ().size (), size_t {0 });
354
351
}
355
352
353
+ void TestGUI (interfaces::Node& node)
354
+ {
355
+ // Set up wallet and chain with 105 blocks (5 mature blocks for spending).
356
+ TestChain100Setup test;
357
+ for (int i = 0 ; i < 5 ; ++i) {
358
+ test.CreateAndProcessBlock ({}, GetScriptForRawPubKey (test.coinbaseKey .GetPubKey ()));
359
+ }
360
+ auto wallet_loader = interfaces::MakeWalletLoader (*test.m_node .chain , *Assert (test.m_node .args ));
361
+ test.m_node .wallet_loader = wallet_loader.get ();
362
+ node.setContext (&test.m_node );
363
+
364
+ // "Full" GUI tests, use descriptor wallet
365
+ const std::shared_ptr<CWallet>& desc_wallet = SetupDescriptorsWallet (node, test);
366
+ TestGUI (node, desc_wallet);
367
+ }
368
+
356
369
} // namespace
357
370
358
371
void WalletTests::walletTests ()
0 commit comments