Bitcoin ABC 0.30.12
P2P Digital Currency
wallet_tests.cpp
Go to the documentation of this file.
1// Copyright (c) 2012-2019 The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#include <chain.h>
6#include <chainparams.h>
7#include <config.h>
8#include <interfaces/chain.h>
9#include <node/blockstorage.h>
10#include <node/context.h>
11#include <policy/policy.h>
12#include <rpc/server.h>
13#include <util/translation.h>
14#include <validation.h>
15#include <wallet/coincontrol.h>
16#include <wallet/receive.h>
17#include <wallet/rpc/backup.h>
18#include <wallet/spend.h>
19#include <wallet/wallet.h>
20
21#include <test/util/logging.h>
22#include <test/util/setup_common.h>
24
25#include <boost/test/unit_test.hpp>
26
27#include <univalue.h>
28
29#include <any>
30#include <cstdint>
31#include <future>
32#include <memory>
33#include <variant>
34#include <vector>
35
37
39
40BOOST_FIXTURE_TEST_SUITE(wallet_tests, WalletTestingSetup)
41
42static std::shared_ptr<CWallet> TestLoadWallet(interfaces::Chain *chain) {
43 DatabaseOptions options;
44 DatabaseStatus status;
46 std::vector<bilingual_str> warnings;
47 auto database = MakeWalletDatabase("", options, status, error);
48 auto wallet = CWallet::Create(chain, "", std::move(database),
49 options.create_flags, error, warnings);
50 if (chain) {
51 wallet->postInitProcess();
52 }
53 return wallet;
54}
55
56static void TestUnloadWallet(std::shared_ptr<CWallet> &&wallet) {
58 wallet->m_chain_notifications_handler.reset();
59 UnloadWallet(std::move(wallet));
60}
61
62static CMutableTransaction TestSimpleSpend(const CTransaction &from,
63 uint32_t index, const CKey &key,
64 const CScript &pubkey) {
66 mtx.vout.push_back(
67 {from.vout[index].nValue - DEFAULT_TRANSACTION_MAXFEE, pubkey});
68 mtx.vin.push_back({CTxIn{from.GetId(), index}});
70 keystore.AddKey(key);
71 std::map<COutPoint, Coin> coins;
72 coins[mtx.vin[0].prevout].GetTxOut() = from.vout[index];
73 std::map<int, std::string> input_errors;
74 BOOST_CHECK(SignTransaction(mtx, &keystore, coins,
75 SigHashType().withForkId(), input_errors));
76 return mtx;
77}
78
79static void AddKey(CWallet &wallet, const CKey &key) {
80 auto spk_man = wallet.GetOrCreateLegacyScriptPubKeyMan();
81 LOCK2(wallet.cs_wallet, spk_man->cs_KeyStore);
82 spk_man->AddKeyPubKey(key, key.GetPubKey());
83}
84
85BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup) {
86 ChainstateManager &chainman = *Assert(m_node.chainman);
87 // Cap last block file size, and mine new block in a new block file.
88 CBlockIndex *oldTip = WITH_LOCK(
89 chainman.GetMutex(), return m_node.chainman->ActiveChain().Tip());
90 WITH_LOCK(::cs_main, m_node.chainman->m_blockman
91 .GetBlockFileInfo(oldTip->GetBlockPos().nFile)
92 ->nSize = MAX_BLOCKFILE_SIZE);
93 CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey()));
94 CBlockIndex *newTip = WITH_LOCK(
95 chainman.GetMutex(), return m_node.chainman->ActiveChain().Tip());
96
97 // Verify ScanForWalletTransactions fails to read an unknown start block.
98 {
100 {
101 LOCK(wallet.cs_wallet);
102 LOCK(chainman.GetMutex());
103 wallet.SetLastBlockProcessed(
104 m_node.chainman->ActiveHeight(),
105 m_node.chainman->ActiveTip()->GetBlockHash());
106 }
107 AddKey(wallet, coinbaseKey);
109 reserver.reserve();
110 CWallet::ScanResult result = wallet.ScanForWalletTransactions(
111 BlockHash() /* start_block */, 0 /* start_height */,
112 {} /* max_height */, reserver, false /* update */);
117 BOOST_CHECK_EQUAL(GetBalance(wallet).m_mine_immature, Amount::zero());
118 }
119
120 // Verify ScanForWalletTransactions picks up transactions in both the old
121 // and new block files.
122 {
124 {
125 LOCK(wallet.cs_wallet);
126 LOCK(chainman.GetMutex());
127 wallet.SetLastBlockProcessed(
128 m_node.chainman->ActiveHeight(),
129 m_node.chainman->ActiveTip()->GetBlockHash());
130 }
131 AddKey(wallet, coinbaseKey);
133 reserver.reserve();
134 CWallet::ScanResult result = wallet.ScanForWalletTransactions(
135 oldTip->GetBlockHash(), oldTip->nHeight, {} /* max_height */,
136 reserver, false /* update */);
139 BOOST_CHECK_EQUAL(result.last_scanned_block, newTip->GetBlockHash());
140 BOOST_CHECK_EQUAL(*result.last_scanned_height, newTip->nHeight);
141 BOOST_CHECK_EQUAL(GetBalance(wallet).m_mine_immature, 100 * COIN);
142 }
143
144 // Prune the older block file.
145 int file_number;
146 {
147 LOCK(cs_main);
148 file_number = oldTip->GetBlockPos().nFile;
149 Assert(m_node.chainman)->m_blockman.PruneOneBlockFile(file_number);
150 }
151 m_node.chainman->m_blockman.UnlinkPrunedFiles({file_number});
152
153 // Verify ScanForWalletTransactions only picks transactions in the new block
154 // file.
155 {
157 {
158 LOCK(wallet.cs_wallet);
159 LOCK(chainman.GetMutex());
160 wallet.SetLastBlockProcessed(
161 m_node.chainman->ActiveHeight(),
162 m_node.chainman->ActiveTip()->GetBlockHash());
163 }
164 AddKey(wallet, coinbaseKey);
166 reserver.reserve();
167 CWallet::ScanResult result = wallet.ScanForWalletTransactions(
168 oldTip->GetBlockHash(), oldTip->nHeight, {} /* max_height */,
169 reserver, false /* update */);
172 BOOST_CHECK_EQUAL(result.last_scanned_block, newTip->GetBlockHash());
173 BOOST_CHECK_EQUAL(*result.last_scanned_height, newTip->nHeight);
174 BOOST_CHECK_EQUAL(GetBalance(wallet).m_mine_immature, 50 * COIN);
175 }
176
177 // Prune the remaining block file.
178 {
179 LOCK(cs_main);
180 file_number = newTip->GetBlockPos().nFile;
181 Assert(m_node.chainman)->m_blockman.PruneOneBlockFile(file_number);
182 }
183 m_node.chainman->m_blockman.UnlinkPrunedFiles({file_number});
184
185 // Verify ScanForWalletTransactions scans no blocks.
186 {
188 {
189 LOCK(wallet.cs_wallet);
190 LOCK(chainman.GetMutex());
191 wallet.SetLastBlockProcessed(
192 m_node.chainman->ActiveHeight(),
193 m_node.chainman->ActiveTip()->GetBlockHash());
194 }
195 AddKey(wallet, coinbaseKey);
197 reserver.reserve();
198 CWallet::ScanResult result = wallet.ScanForWalletTransactions(
199 oldTip->GetBlockHash(), oldTip->nHeight, {} /* max_height */,
200 reserver, false /* update */);
202 BOOST_CHECK_EQUAL(result.last_failed_block, newTip->GetBlockHash());
205 BOOST_CHECK_EQUAL(GetBalance(wallet).m_mine_immature, Amount::zero());
206 }
207}
208
209BOOST_FIXTURE_TEST_CASE(importmulti_rescan, TestChain100Setup) {
210 ChainstateManager &chainman = *Assert(m_node.chainman);
211 // Cap last block file size, and mine new block in a new block file.
212 CBlockIndex *oldTip = WITH_LOCK(
213 chainman.GetMutex(), return m_node.chainman->ActiveChain().Tip());
214 WITH_LOCK(::cs_main, m_node.chainman->m_blockman
215 .GetBlockFileInfo(oldTip->GetBlockPos().nFile)
216 ->nSize = MAX_BLOCKFILE_SIZE);
217 CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey()));
218 CBlockIndex *newTip = WITH_LOCK(
219 chainman.GetMutex(), return m_node.chainman->ActiveChain().Tip());
220
221 // Prune the older block file.
222 int file_number;
223 {
224 LOCK(cs_main);
225 file_number = oldTip->GetBlockPos().nFile;
226 chainman.m_blockman.PruneOneBlockFile(file_number);
227 }
228 m_node.chainman->m_blockman.UnlinkPrunedFiles({file_number});
229
230 // Verify importmulti RPC returns failure for a key whose creation time is
231 // before the missing block, and success for a key whose creation time is
232 // after.
233 {
234 std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(
235 m_node.chain.get(), "", CreateDummyWalletDatabase());
236 wallet->SetupLegacyScriptPubKeyMan();
237 WITH_LOCK(wallet->cs_wallet,
238 wallet->SetLastBlockProcessed(newTip->nHeight,
239 newTip->GetBlockHash()));
241 UniValue keys;
242 keys.setArray();
243 UniValue key;
244 key.setObject();
245 key.pushKV("scriptPubKey",
246 HexStr(GetScriptForRawPubKey(coinbaseKey.GetPubKey())));
247 key.pushKV("timestamp", 0);
248 key.pushKV("internal", UniValue(true));
249 keys.push_back(key);
250 key.clear();
251 key.setObject();
252 CKey futureKey;
253 futureKey.MakeNewKey(true);
254 key.pushKV("scriptPubKey",
256 key.pushKV("timestamp",
257 newTip->GetBlockTimeMax() + TIMESTAMP_WINDOW + 1);
258 key.pushKV("internal", UniValue(true));
259 keys.push_back(key);
260 JSONRPCRequest request;
261 request.params.setArray();
262 request.params.push_back(keys);
263
266 response.write(),
267 strprintf("[{\"success\":false,\"error\":{\"code\":-1,\"message\":"
268 "\"Rescan failed for key with creation timestamp %d. "
269 "There was an error reading a block from time %d, which "
270 "is after or within %d seconds of key creation, and "
271 "could contain transactions pertaining to the key. As a "
272 "result, transactions and coins using this key may not "
273 "appear in the wallet. This error could be caused by "
274 "pruning or data corruption (see bitcoind log for "
275 "details) and could be dealt with by downloading and "
276 "rescanning the relevant blocks (see -reindex and "
277 "-rescan options).\"}},{\"success\":true}]",
278 0, oldTip->GetBlockTimeMax(), TIMESTAMP_WINDOW));
279 RemoveWallet(wallet, std::nullopt);
280 }
281}
282
283// Verify importwallet RPC starts rescan at earliest block with timestamp
284// greater or equal than key birthday. Previously there was a bug where
285// importwallet RPC would start the scan at the latest block with timestamp less
286// than or equal to key birthday.
287BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup) {
288 ChainstateManager &chainman = *Assert(m_node.chainman);
289 // Create two blocks with same timestamp to verify that importwallet rescan
290 // will pick up both blocks, not just the first.
291 const int64_t BLOCK_TIME =
292 WITH_LOCK(chainman.GetMutex(),
293 return chainman.ActiveTip()->GetBlockTimeMax() + 5);
294 SetMockTime(BLOCK_TIME);
295 m_coinbase_txns.emplace_back(
296 CreateAndProcessBlock({},
297 GetScriptForRawPubKey(coinbaseKey.GetPubKey()))
298 .vtx[0]);
299 m_coinbase_txns.emplace_back(
300 CreateAndProcessBlock({},
301 GetScriptForRawPubKey(coinbaseKey.GetPubKey()))
302 .vtx[0]);
303
304 // Set key birthday to block time increased by the timestamp window, so
305 // rescan will start at the block time.
306 const int64_t KEY_TIME = BLOCK_TIME + TIMESTAMP_WINDOW;
307 SetMockTime(KEY_TIME);
308 m_coinbase_txns.emplace_back(
309 CreateAndProcessBlock({},
310 GetScriptForRawPubKey(coinbaseKey.GetPubKey()))
311 .vtx[0]);
312
313 std::string backup_file =
314 fs::PathToString(gArgs.GetDataDirNet() / "wallet.backup");
315
316 // Import key into wallet and call dumpwallet to create backup file.
317 {
318 std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(
319 m_node.chain.get(), "", CreateDummyWalletDatabase());
320 {
321 auto spk_man = wallet->GetOrCreateLegacyScriptPubKeyMan();
322 LOCK2(wallet->cs_wallet, spk_man->cs_KeyStore);
323 spk_man->mapKeyMetadata[coinbaseKey.GetPubKey().GetID()]
324 .nCreateTime = KEY_TIME;
325 spk_man->AddKeyPubKey(coinbaseKey, coinbaseKey.GetPubKey());
326
328 LOCK(chainman.GetMutex());
329 wallet->SetLastBlockProcessed(chainman.ActiveHeight(),
330 chainman.ActiveTip()->GetBlockHash());
331 }
332 JSONRPCRequest request;
333 request.params.setArray();
334 request.params.push_back(backup_file);
336 RemoveWallet(wallet, std::nullopt);
337 }
338
339 // Call importwallet RPC and verify all blocks with timestamps >= BLOCK_TIME
340 // were scanned, and no prior blocks were scanned.
341 {
342 std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(
343 m_node.chain.get(), "", CreateDummyWalletDatabase());
344 LOCK(wallet->cs_wallet);
345 wallet->SetupLegacyScriptPubKeyMan();
346
347 JSONRPCRequest request;
348 request.params.setArray();
349 request.params.push_back(backup_file);
351 {
352 LOCK(chainman.GetMutex());
353 wallet->SetLastBlockProcessed(chainman.ActiveHeight(),
354 chainman.ActiveTip()->GetBlockHash());
355 }
357 RemoveWallet(wallet, std::nullopt);
358
359 BOOST_CHECK_EQUAL(wallet->mapWallet.size(), 3U);
360 BOOST_CHECK_EQUAL(m_coinbase_txns.size(), 103U);
361 for (size_t i = 0; i < m_coinbase_txns.size(); ++i) {
362 bool found = wallet->GetWalletTx(m_coinbase_txns[i]->GetId());
363 bool expected = i >= 100;
364 BOOST_CHECK_EQUAL(found, expected);
365 }
366 }
367}
368
369// Check that GetImmatureCredit() returns a newly calculated value instead of
370// the cached value after a MarkDirty() call.
371//
372// This is a regression test written to verify a bugfix for the immature credit
373// function. Similar tests probably should be written for the other credit and
374// debit functions.
375BOOST_FIXTURE_TEST_CASE(coin_mark_dirty_immature_credit, TestChain100Setup) {
376 ChainstateManager &chainman = *Assert(m_node.chainman);
378 auto spk_man = wallet.GetOrCreateLegacyScriptPubKeyMan();
379 CWalletTx wtx(m_coinbase_txns.back());
380
381 LOCK2(wallet.cs_wallet, spk_man->cs_KeyStore);
382 LOCK(chainman.GetMutex());
383 wallet.SetLastBlockProcessed(chainman.ActiveHeight(),
384 chainman.ActiveTip()->GetBlockHash());
385
386 CWalletTx::Confirmation confirm(CWalletTx::Status::CONFIRMED,
387 chainman.ActiveHeight(),
388 chainman.ActiveTip()->GetBlockHash(), 0);
389 wtx.m_confirm = confirm;
390
391 // Call GetImmatureCredit() once before adding the key to the wallet to
392 // cache the current immature credit amount, which is 0.
394
395 // Invalidate the cached value, add the key, and make sure a new immature
396 // credit amount is calculated.
397 wtx.MarkDirty();
398 BOOST_CHECK(spk_man->AddKeyPubKey(coinbaseKey, coinbaseKey.GetPubKey()));
400}
401
402static int64_t AddTx(ChainstateManager &chainman, CWallet &wallet,
403 uint32_t lockTime, int64_t mockTime, int64_t blockTime) {
406 tx.nLockTime = lockTime;
407 SetMockTime(mockTime);
408 CBlockIndex *block = nullptr;
409 if (blockTime > 0) {
410 LOCK(cs_main);
411 auto inserted = chainman.BlockIndex().emplace(
412 std::piecewise_construct, std::make_tuple(GetRandHash()),
413 std::make_tuple());
414 assert(inserted.second);
415 const BlockHash &hash = inserted.first->first;
416 block = &inserted.first->second;
417 block->nTime = blockTime;
418 block->phashBlock = &hash;
419 confirm = {CWalletTx::Status::CONFIRMED, block->nHeight, hash, 0};
420 }
421
422 // If transaction is already in map, to avoid inconsistencies,
423 // unconfirmation is needed before confirm again with different block.
424 return wallet
425 .AddToWallet(MakeTransactionRef(tx), confirm,
426 [&](CWalletTx &wtx, bool /* new_tx */) {
427 wtx.setUnconfirmed();
428 return true;
429 })
430 ->nTimeSmart;
431}
432
433// Simple test to verify assignment of CWalletTx::nSmartTime value. Could be
434// expanded to cover more corner cases of smart time logic.
435BOOST_AUTO_TEST_CASE(ComputeTimeSmart) {
436 // New transaction should use clock time if lower than block time.
437 BOOST_CHECK_EQUAL(AddTx(*m_node.chainman, m_wallet, 1, 100, 120), 100);
438
439 // Test that updating existing transaction does not change smart time.
440 BOOST_CHECK_EQUAL(AddTx(*m_node.chainman, m_wallet, 1, 200, 220), 100);
441
442 // New transaction should use clock time if there's no block time.
443 BOOST_CHECK_EQUAL(AddTx(*m_node.chainman, m_wallet, 2, 300, 0), 300);
444
445 // New transaction should use block time if lower than clock time.
446 BOOST_CHECK_EQUAL(AddTx(*m_node.chainman, m_wallet, 3, 420, 400), 400);
447
448 // New transaction should use latest entry time if higher than
449 // min(block time, clock time).
450 BOOST_CHECK_EQUAL(AddTx(*m_node.chainman, m_wallet, 4, 500, 390), 400);
451
452 // If there are future entries, new transaction should use time of the
453 // newest entry that is no more than 300 seconds ahead of the clock time.
454 BOOST_CHECK_EQUAL(AddTx(*m_node.chainman, m_wallet, 5, 50, 600), 300);
455
456 // Reset mock time for other tests.
457 SetMockTime(0);
458}
459
460BOOST_AUTO_TEST_CASE(LoadReceiveRequests) {
461 CTxDestination dest = PKHash();
462 LOCK(m_wallet.cs_wallet);
463 WalletBatch batch{m_wallet.GetDatabase()};
464 m_wallet.AddDestData(batch, dest, "misc", "val_misc");
465 m_wallet.AddDestData(batch, dest, "rr0", "val_rr0");
466 m_wallet.AddDestData(batch, dest, "rr1", "val_rr1");
467
468 auto values = m_wallet.GetDestValues("rr");
469 BOOST_CHECK_EQUAL(values.size(), 2U);
470 BOOST_CHECK_EQUAL(values[0], "val_rr0");
471 BOOST_CHECK_EQUAL(values[1], "val_rr1");
472}
473
474// Test some watch-only LegacyScriptPubKeyMan methods by the procedure of
475// loading (LoadWatchOnly), checking (HaveWatchOnly), getting (GetWatchPubKey)
476// and removing (RemoveWatchOnly) a given PubKey, resp. its corresponding P2PK
477// Script. Results of the the impact on the address -> PubKey map is dependent
478// on whether the PubKey is a point on the curve
480 const CPubKey &add_pubkey) {
481 CScript p2pk = GetScriptForRawPubKey(add_pubkey);
482 CKeyID add_address = add_pubkey.GetID();
483 CPubKey found_pubkey;
484 LOCK(spk_man->cs_KeyStore);
485
486 // all Scripts (i.e. also all PubKeys) are added to the general watch-only
487 // set
488 BOOST_CHECK(!spk_man->HaveWatchOnly(p2pk));
489 spk_man->LoadWatchOnly(p2pk);
490 BOOST_CHECK(spk_man->HaveWatchOnly(p2pk));
491
492 // only PubKeys on the curve shall be added to the watch-only address ->
493 // PubKey map
494 bool is_pubkey_fully_valid = add_pubkey.IsFullyValid();
495 if (is_pubkey_fully_valid) {
496 BOOST_CHECK(spk_man->GetWatchPubKey(add_address, found_pubkey));
497 BOOST_CHECK(found_pubkey == add_pubkey);
498 } else {
499 BOOST_CHECK(!spk_man->GetWatchPubKey(add_address, found_pubkey));
500 // passed key is unchanged
501 BOOST_CHECK(found_pubkey == CPubKey());
502 }
503
504 spk_man->RemoveWatchOnly(p2pk);
505 BOOST_CHECK(!spk_man->HaveWatchOnly(p2pk));
506
507 if (is_pubkey_fully_valid) {
508 BOOST_CHECK(!spk_man->GetWatchPubKey(add_address, found_pubkey));
509 // passed key is unchanged
510 BOOST_CHECK(found_pubkey == add_pubkey);
511 }
512}
513
514// Cryptographically invalidate a PubKey whilst keeping length and first byte
515static void PollutePubKey(CPubKey &pubkey) {
516 assert(pubkey.size() > 0);
517 std::vector<uint8_t> pubkey_raw(pubkey.begin(), pubkey.end());
518 std::fill(pubkey_raw.begin() + 1, pubkey_raw.end(), 0);
519 pubkey = CPubKey(pubkey_raw);
520 assert(!pubkey.IsFullyValid());
521 assert(pubkey.IsValid());
522}
523
524// Test watch-only logic for PubKeys
525BOOST_AUTO_TEST_CASE(WatchOnlyPubKeys) {
526 CKey key;
527 CPubKey pubkey;
528 LegacyScriptPubKeyMan *spk_man =
529 m_wallet.GetOrCreateLegacyScriptPubKeyMan();
530
531 BOOST_CHECK(!spk_man->HaveWatchOnly());
532
533 // uncompressed valid PubKey
534 key.MakeNewKey(false);
535 pubkey = key.GetPubKey();
536 assert(!pubkey.IsCompressed());
537 TestWatchOnlyPubKey(spk_man, pubkey);
538
539 // uncompressed cryptographically invalid PubKey
540 PollutePubKey(pubkey);
541 TestWatchOnlyPubKey(spk_man, pubkey);
542
543 // compressed valid PubKey
544 key.MakeNewKey(true);
545 pubkey = key.GetPubKey();
546 assert(pubkey.IsCompressed());
547 TestWatchOnlyPubKey(spk_man, pubkey);
548
549 // compressed cryptographically invalid PubKey
550 PollutePubKey(pubkey);
551 TestWatchOnlyPubKey(spk_man, pubkey);
552
553 // invalid empty PubKey
554 pubkey = CPubKey();
555 TestWatchOnlyPubKey(spk_man, pubkey);
556}
557
558class ListCoinsTestingSetup : public TestChain100Setup {
559public:
561 ChainstateManager &chainman = *Assert(m_node.chainman);
562 CreateAndProcessBlock({},
563 GetScriptForRawPubKey(coinbaseKey.GetPubKey()));
564 wallet = std::make_unique<CWallet>(m_node.chain.get(), "",
566 {
567 LOCK2(wallet->cs_wallet, ::cs_main);
568 wallet->SetLastBlockProcessed(chainman.ActiveHeight(),
569 chainman.ActiveTip()->GetBlockHash());
570 }
571 wallet->LoadWallet();
572 AddKey(*wallet, coinbaseKey);
573 WalletRescanReserver reserver(*wallet);
574 reserver.reserve();
575 CWallet::ScanResult result = wallet->ScanForWalletTransactions(
576 m_node.chainman->ActiveChain().Genesis()->GetBlockHash(),
577 0 /* start_height */, {} /* max_height */, reserver,
578 false /* update */);
580 LOCK(chainman.GetMutex());
582 chainman.ActiveTip()->GetBlockHash());
585 }
586
588
590 ChainstateManager &chainman = *Assert(m_node.chainman);
592 Amount fee;
593 int changePos = -1;
595 CCoinControl dummy;
596 {
597 BOOST_CHECK(CreateTransaction(*wallet, {recipient}, tx, fee,
598 changePos, error, dummy));
599 }
600 BOOST_CHECK_EQUAL(tx->nLockTime, 0);
601
602 wallet->CommitTransaction(tx, {}, {});
603 CMutableTransaction blocktx;
604 {
605 LOCK(wallet->cs_wallet);
606 blocktx =
607 CMutableTransaction(*wallet->mapWallet.at(tx->GetId()).tx);
608 }
609 CreateAndProcessBlock({CMutableTransaction(blocktx)},
610 GetScriptForRawPubKey(coinbaseKey.GetPubKey()));
611
612 LOCK(wallet->cs_wallet);
613 LOCK(chainman.GetMutex());
614 wallet->SetLastBlockProcessed(wallet->GetLastBlockHeight() + 1,
615 chainman.ActiveTip()->GetBlockHash());
616 auto it = wallet->mapWallet.find(tx->GetId());
617 BOOST_CHECK(it != wallet->mapWallet.end());
619 CWalletTx::Status::CONFIRMED, chainman.ActiveHeight(),
620 chainman.ActiveTip()->GetBlockHash(), 1);
621 it->second.m_confirm = confirm;
622 return it->second;
623 }
624
625 std::unique_ptr<CWallet> wallet;
626};
627
629 std::string coinbaseAddress = coinbaseKey.GetPubKey().GetID().ToString();
630
631 // Confirm ListCoins initially returns 1 coin grouped under coinbaseKey
632 // address.
633 std::map<CTxDestination, std::vector<COutput>> list;
634 {
635 LOCK(wallet->cs_wallet);
636 list = ListCoins(*wallet);
637 }
638 BOOST_CHECK_EQUAL(list.size(), 1U);
639 BOOST_CHECK_EQUAL(std::get<PKHash>(list.begin()->first).ToString(),
640 coinbaseAddress);
641 BOOST_CHECK_EQUAL(list.begin()->second.size(), 1U);
642
643 // Check initial balance from one mature coinbase transaction.
645
646 // Add a transaction creating a change address, and confirm ListCoins still
647 // returns the coin associated with the change address underneath the
648 // coinbaseKey pubkey, even though the change address has a different
649 // pubkey.
651 false /* subtract fee */});
652 {
653 LOCK(wallet->cs_wallet);
654 list = ListCoins(*wallet);
655 }
656 BOOST_CHECK_EQUAL(list.size(), 1U);
657 BOOST_CHECK_EQUAL(std::get<PKHash>(list.begin()->first).ToString(),
658 coinbaseAddress);
659 BOOST_CHECK_EQUAL(list.begin()->second.size(), 2U);
660
661 // Lock both coins. Confirm number of available coins drops to 0.
662 {
663 LOCK(wallet->cs_wallet);
664 std::vector<COutput> available;
665 AvailableCoins(*wallet, available);
666 BOOST_CHECK_EQUAL(available.size(), 2U);
667 }
668 for (const auto &group : list) {
669 for (const auto &coin : group.second) {
670 LOCK(wallet->cs_wallet);
671 wallet->LockCoin(COutPoint(coin.tx->GetId(), coin.i));
672 }
673 }
674 {
675 LOCK(wallet->cs_wallet);
676 std::vector<COutput> available;
677 AvailableCoins(*wallet, available);
678 BOOST_CHECK_EQUAL(available.size(), 0U);
679 }
680 // Confirm ListCoins still returns same result as before, despite coins
681 // being locked.
682 {
683 LOCK(wallet->cs_wallet);
684 list = ListCoins(*wallet);
685 }
686 BOOST_CHECK_EQUAL(list.size(), 1U);
687 BOOST_CHECK_EQUAL(std::get<PKHash>(list.begin()->first).ToString(),
688 coinbaseAddress);
689 BOOST_CHECK_EQUAL(list.begin()->second.size(), 2U);
690}
691
692BOOST_FIXTURE_TEST_CASE(wallet_disableprivkeys, TestChain100Setup) {
693 std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(
694 m_node.chain.get(), "", CreateDummyWalletDatabase());
695 wallet->SetupLegacyScriptPubKeyMan();
696 wallet->SetMinVersion(FEATURE_LATEST);
698 BOOST_CHECK(!wallet->TopUpKeyPool(1000));
699 CTxDestination dest;
700 std::string error;
702 !wallet->GetNewDestination(OutputType::LEGACY, "", dest, error));
703}
704
705// Explicit calculation which is used to test the wallet constant
706static size_t CalculateP2PKHInputSize(bool use_max_sig) {
707 // Generate ephemeral valid pubkey
708 CKey key;
709 key.MakeNewKey(true);
710 CPubKey pubkey = key.GetPubKey();
711
712 // Generate pubkey hash
713 PKHash key_hash(pubkey);
714
715 // Create script to enter into keystore. Key hash can't be 0...
716 CScript script = GetScriptForDestination(key_hash);
717
718 // Add script to key store and key to watchonly
720 keystore.AddKeyPubKey(key, pubkey);
721
722 // Fill in dummy signatures for fee calculation.
723 SignatureData sig_data;
724 if (!ProduceSignature(keystore,
727 script, sig_data)) {
728 // We're hand-feeding it correct arguments; shouldn't happen
729 assert(false);
730 }
731
732 CTxIn tx_in;
733 UpdateInput(tx_in, sig_data);
734 return (size_t)GetVirtualTransactionInputSize(tx_in);
735}
736
737BOOST_FIXTURE_TEST_CASE(dummy_input_size_test, TestChain100Setup) {
740}
741
742bool malformed_descriptor(std::ios_base::failure e) {
743 std::string s(e.what());
744 return s.find("Missing checksum") != std::string::npos;
745}
746
747BOOST_FIXTURE_TEST_CASE(wallet_descriptor_test, BasicTestingSetup) {
748 std::vector<uint8_t> malformed_record;
749 CVectorWriter vw(0, 0, malformed_record, 0);
750 vw << std::string("notadescriptor");
751 vw << (uint64_t)0;
752 vw << (int32_t)0;
753 vw << (int32_t)0;
754 vw << (int32_t)1;
755
756 SpanReader vr{0, 0, malformed_record};
757 WalletDescriptor w_desc;
758 BOOST_CHECK_EXCEPTION(vr >> w_desc, std::ios_base::failure,
760}
761
781 // Create new wallet with known key and unload it.
782 auto wallet = TestLoadWallet(m_node.chain.get());
783 CKey key;
784 key.MakeNewKey(true);
785 AddKey(*wallet, key);
786 TestUnloadWallet(std::move(wallet));
787
788 // Add log hook to detect AddToWallet events from rescans, blockConnected,
789 // and transactionAddedToMempool notifications
790 int addtx_count = 0;
791 DebugLogHelper addtx_counter("[default wallet] AddToWallet",
792 [&](const std::string *s) {
793 if (s) {
794 ++addtx_count;
795 }
796 return false;
797 });
798
799 bool rescan_completed = false;
800 DebugLogHelper rescan_check("[default wallet] Rescan completed",
801 [&](const std::string *s) {
802 if (s) {
803 rescan_completed = true;
804 }
805 return false;
806 });
807
808 // Block the queue to prevent the wallet receiving blockConnected and
809 // transactionAddedToMempool notifications, and create block and mempool
810 // transactions paying to the wallet
811 std::promise<void> promise;
813 [&promise] { promise.get_future().wait(); });
814 std::string error;
815 m_coinbase_txns.push_back(
816 CreateAndProcessBlock({},
817 GetScriptForRawPubKey(coinbaseKey.GetPubKey()))
818 .vtx[0]);
819 auto block_tx = TestSimpleSpend(*m_coinbase_txns[0], 0, coinbaseKey,
821 m_coinbase_txns.push_back(
822 CreateAndProcessBlock({block_tx},
823 GetScriptForRawPubKey(coinbaseKey.GetPubKey()))
824 .vtx[0]);
825 auto mempool_tx = TestSimpleSpend(*m_coinbase_txns[1], 0, coinbaseKey,
827 BOOST_CHECK(m_node.chain->broadcastTransaction(
829 false, error));
830
831 // Reload wallet and make sure new transactions are detected despite events
832 // being blocked
833 wallet = TestLoadWallet(m_node.chain.get());
834 BOOST_CHECK(rescan_completed);
835 BOOST_CHECK_EQUAL(addtx_count, 2);
836 {
837 LOCK(wallet->cs_wallet);
838 BOOST_CHECK_EQUAL(wallet->mapWallet.count(block_tx.GetId()), 1U);
839 BOOST_CHECK_EQUAL(wallet->mapWallet.count(mempool_tx.GetId()), 1U);
840 }
841
842 // Unblock notification queue and make sure stale blockConnected and
843 // transactionAddedToMempool events are processed
844 promise.set_value();
846 BOOST_CHECK_EQUAL(addtx_count, 4);
847
848 TestUnloadWallet(std::move(wallet));
849
850 // Load wallet again, this time creating new block and mempool transactions
851 // paying to the wallet as the wallet finishes loading and syncing the
852 // queue so the events have to be handled immediately. Releasing the wallet
853 // lock during the sync is a little artificial but is needed to avoid a
854 // deadlock during the sync and simulates a new block notification happening
855 // as soon as possible.
856 addtx_count = 0;
858 [&](std::unique_ptr<interfaces::Wallet> wallet_param)
859 EXCLUSIVE_LOCKS_REQUIRED(wallet_param->wallet()->cs_wallet,
860 cs_wallets) {
861 BOOST_CHECK(rescan_completed);
862 m_coinbase_txns.push_back(
863 CreateAndProcessBlock(
864 {}, GetScriptForRawPubKey(coinbaseKey.GetPubKey()))
865 .vtx[0]);
866 block_tx =
867 TestSimpleSpend(*m_coinbase_txns[2], 0, coinbaseKey,
869 m_coinbase_txns.push_back(
870 CreateAndProcessBlock(
871 {block_tx},
872 GetScriptForRawPubKey(coinbaseKey.GetPubKey()))
873 .vtx[0]);
874 mempool_tx =
875 TestSimpleSpend(*m_coinbase_txns[3], 0, coinbaseKey,
877 BOOST_CHECK(m_node.chain->broadcastTransaction(
878 GetConfig(), MakeTransactionRef(mempool_tx),
881 LEAVE_CRITICAL_SECTION(wallet_param->wallet()->cs_wallet);
883 ENTER_CRITICAL_SECTION(wallet_param->wallet()->cs_wallet);
885 });
886 wallet = TestLoadWallet(m_node.chain.get());
887 BOOST_CHECK_EQUAL(addtx_count, 4);
888 {
889 LOCK(wallet->cs_wallet);
890 BOOST_CHECK_EQUAL(wallet->mapWallet.count(block_tx.GetId()), 1U);
891 BOOST_CHECK_EQUAL(wallet->mapWallet.count(mempool_tx.GetId()), 1U);
892 }
893
894 TestUnloadWallet(std::move(wallet));
895}
896
897BOOST_FIXTURE_TEST_CASE(CreateWalletWithoutChain, BasicTestingSetup) {
898 auto wallet = TestLoadWallet(nullptr);
900 UnloadWallet(std::move(wallet));
901}
902
903BOOST_FIXTURE_TEST_CASE(ZapSelectTx, TestChain100Setup) {
904 auto wallet = TestLoadWallet(m_node.chain.get());
905 CKey key;
906 key.MakeNewKey(true);
907 AddKey(*wallet, key);
908
909 std::string error;
910 m_coinbase_txns.push_back(
911 CreateAndProcessBlock({},
912 GetScriptForRawPubKey(coinbaseKey.GetPubKey()))
913 .vtx[0]);
914 auto block_tx = TestSimpleSpend(*m_coinbase_txns[0], 0, coinbaseKey,
916 CreateAndProcessBlock({block_tx},
917 GetScriptForRawPubKey(coinbaseKey.GetPubKey()));
918
920
921 {
922 auto block_id = block_tx.GetId();
923 auto prev_id = m_coinbase_txns[0]->GetId();
924
925 LOCK(wallet->cs_wallet);
926 BOOST_CHECK(wallet->HasWalletSpend(prev_id));
927 BOOST_CHECK_EQUAL(wallet->mapWallet.count(block_id), 1u);
928
929 std::vector<TxId> vIdIn{block_id}, vIdOut;
930 BOOST_CHECK_EQUAL(wallet->ZapSelectTx(vIdIn, vIdOut),
932
933 BOOST_CHECK(!wallet->HasWalletSpend(prev_id));
934 BOOST_CHECK_EQUAL(wallet->mapWallet.count(block_id), 0u);
935 }
936
937 TestUnloadWallet(std::move(wallet));
938}
939
940BOOST_AUTO_TEST_SUITE_END()
static constexpr Amount COIN
Definition: amount.h:144
ArgsManager gArgs
Definition: args.cpp:38
RPCHelpMan importmulti()
Definition: backup.cpp:1682
RPCHelpMan importwallet()
Definition: backup.cpp:647
RPCHelpMan dumpwallet()
Definition: backup.cpp:915
static constexpr int64_t TIMESTAMP_WINDOW
Timestamp window used as a grace period by code that compares external timestamps (such as timestamps...
Definition: chain.h:36
#define Assert(val)
Identity function.
Definition: check.h:84
fs::path GetDataDirNet() const
Get data directory path with appended network identifier.
Definition: args.h:215
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: blockindex.h:25
const BlockHash * phashBlock
pointer to the hash of the block, if any.
Definition: blockindex.h:29
uint32_t nTime
Definition: blockindex.h:92
int64_t GetBlockTimeMax() const
Definition: blockindex.h:182
BlockHash GetBlockHash() const
Definition: blockindex.h:146
int nHeight
height of the entry in the chain. The genesis block has height 0
Definition: blockindex.h:38
FlatFilePos GetBlockPos() const EXCLUSIVE_LOCKS_REQUIRED(
Definition: blockindex.h:113
Coin Control Features.
Definition: coincontrol.h:21
An encapsulated secp256k1 private key.
Definition: key.h:28
void MakeNewKey(bool fCompressed)
Generate a new private key using a cryptographic PRNG.
Definition: key.cpp:183
CPubKey GetPubKey() const
Compute the public key from a private key.
Definition: key.cpp:210
A reference to a CKey: the Hash160 of its serialized public key.
Definition: pubkey.h:22
A mutable version of CTransaction.
Definition: transaction.h:274
std::vector< CTxOut > vout
Definition: transaction.h:277
std::vector< CTxIn > vin
Definition: transaction.h:276
An encapsulated public key.
Definition: pubkey.h:31
bool IsCompressed() const
Check whether this is a compressed public key.
Definition: pubkey.h:154
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
Definition: pubkey.h:137
const uint8_t * end() const
Definition: pubkey.h:101
bool IsValid() const
Definition: pubkey.h:147
bool IsFullyValid() const
fully validate whether this is a valid public key (more expensive than IsValid())
Definition: pubkey.cpp:256
unsigned int size() const
Simple read-only vector-like interface to the pubkey data.
Definition: pubkey.h:98
const uint8_t * begin() const
Definition: pubkey.h:100
Minimal stream for overwriting and/or appending to an existing byte vector.
Definition: streams.h:65
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
Definition: wallet.h:254
static std::shared_ptr< CWallet > Create(interfaces::Chain *chain, const std::string &name, std::unique_ptr< WalletDatabase > database, uint64_t wallet_creation_flags, bilingual_str &error, std::vector< bilingual_str > &warnings)
Initializes the wallet, returns a new CWallet instance or a null pointer in case of an error.
Definition: wallet.cpp:2703
A transaction with a bunch of additional info that only the owner cares about.
Definition: transaction.h:65
Confirmation m_confirm
Definition: transaction.h:191
void setUnconfirmed()
Definition: transaction.h:295
void MarkDirty()
make sure balances are recalculated
Definition: transaction.h:263
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
Definition: validation.h:1140
node::BlockMap & BlockIndex() EXCLUSIVE_LOCKS_REQUIRED(
Definition: validation.h:1407
RecursiveMutex & GetMutex() const LOCK_RETURNED(
Alias for cs_main.
Definition: validation.h:1265
CBlockIndex * ActiveTip() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
Definition: validation.h:1390
int ActiveHeight() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
Definition: validation.h:1387
node::BlockManager m_blockman
A single BlockManager instance is shared across each constructed chainstate to avoid duplicating bloc...
Definition: validation.h:1273
Fillable signing provider that keeps keys in an address->secret map.
virtual bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey)
virtual bool AddKey(const CKey &key)
RecursiveMutex cs_KeyStore
UniValue params
Definition: request.h:34
bool LoadWatchOnly(const CScript &dest)
Adds a watch-only address to the store, without saving it to disk (used by LoadWallet)
bool RemoveWatchOnly(const CScript &dest)
Remove a watch only script from the keystore.
bool GetWatchPubKey(const CKeyID &address, CPubKey &pubkey_out) const
Fetches a pubkey from mapWatchKeys if it exists there.
bool HaveWatchOnly(const CScript &dest) const
Returns whether the watch-only script is in the wallet.
std::unique_ptr< CWallet > wallet
CWalletTx & AddTx(CRecipient recipient)
UniValue HandleRequest(const Config &config, const JSONRPCRequest &request) const
Definition: util.cpp:587
Signature hash type wrapper class.
Definition: sighashtype.h:37
Minimal stream for reading from an existing byte array by Span.
Definition: streams.h:129
void push_back(UniValue val)
Definition: univalue.cpp:96
void setArray()
Definition: univalue.cpp:86
void clear()
Definition: univalue.cpp:18
void setObject()
Definition: univalue.cpp:91
void pushKV(std::string key, UniValue val)
Definition: univalue.cpp:115
Access to the wallet database.
Definition: walletdb.h:175
Descriptor with some wallet metadata.
Definition: walletutil.h:80
RAII object to check and reserve a wallet rescan.
Definition: wallet.h:1110
bool IsNull() const
Definition: uint256.h:32
void PruneOneBlockFile(const int fileNumber) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Mark one block file as pruned (modify associated database entries)
const Config & GetConfig()
Definition: config.cpp:40
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition: cs_main.cpp:7
bool error(const char *fmt, const Args &...args)
Definition: logging.h:263
static std::string PathToString(const path &path)
Convert path object to byte string.
Definition: fs.h:142
static const unsigned int MAX_BLOCKFILE_SIZE
The maximum size of a blk?????.dat file (since 0.8)
Definition: blockstorage.h:47
Implement std::hash so RCUPtr can be used as a key for maps or sets.
Definition: rcu.h:259
NodeContext & m_node
Definition: interfaces.cpp:788
#define BOOST_CHECK_EQUAL(v1, v2)
Definition: object.cpp:18
#define BOOST_CHECK(expr)
Definition: object.cpp:17
int64_t GetVirtualTransactionInputSize(const CTxIn &txin, int64_t nSigChecks, unsigned int bytes_per_sigCheck)
Definition: policy.cpp:176
static CTransactionRef MakeTransactionRef()
Definition: transaction.h:316
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:315
Response response
Definition: processor.cpp:506
uint256 GetRandHash() noexcept
Definition: random.cpp:659
void SignTransaction(CMutableTransaction &mtx, const SigningProvider *keystore, const std::map< COutPoint, Coin > &coins, const UniValue &hashType, UniValue &result)
Sign a transaction with the given keystore and previous transactions.
Amount CachedTxGetImmatureCredit(const CWallet &wallet, const CWalletTx &wtx, bool fUseCache)
Definition: receive.cpp:192
Balance GetBalance(const CWallet &wallet, const int min_depth, bool avoid_reuse)
Definition: receive.cpp:384
bool(* handler)(Config &config, const std::any &context, HTTPRequest *req, const std::string &strReq)
Definition: rest.cpp:818
bool ProduceSignature(const SigningProvider &provider, const BaseSignatureCreator &creator, const CScript &fromPubKey, SignatureData &sigdata)
Produce a script signature using a generic signature creator.
Definition: sign.cpp:198
void UpdateInput(CTxIn &input, const SignatureData &data)
Definition: sign.cpp:331
const BaseSignatureCreator & DUMMY_MAXIMUM_SIGNATURE_CREATOR
A signature creator that just produces 72-byte empty signatures.
Definition: sign.cpp:421
const BaseSignatureCreator & DUMMY_SIGNATURE_CREATOR
A signature creator that just produces 71-byte empty signatures.
Definition: sign.cpp:419
std::map< CTxDestination, std::vector< COutput > > ListCoins(const CWallet &wallet)
Return list of available coins and locked coins grouped by non-change output address.
Definition: spend.cpp:252
bool CreateTransaction(CWallet &wallet, const std::vector< CRecipient > &vecSend, CTransactionRef &tx, Amount &nFeeRet, int &nChangePosInOut, bilingual_str &error, const CCoinControl &coin_control, bool sign)
Create a new transaction paying the recipients with a set of coins selected by SelectCoins(); Also cr...
Definition: spend.cpp:993
void AvailableCoins(const CWallet &wallet, std::vector< COutput > &vCoins, const CCoinControl *coinControl, const Amount nMinimumAmount, const Amount nMaximumAmount, const Amount nMinimumSumAmount, const uint64_t nMaximumCount)
populate vCoins with vector of available COutputs.
Definition: spend.cpp:73
Amount GetAvailableBalance(const CWallet &wallet, const CCoinControl *coinControl)
Definition: spend.cpp:217
CScript GetScriptForRawPubKey(const CPubKey &pubKey)
Generate a P2PK script for the given pubkey.
Definition: standard.cpp:244
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
Definition: standard.cpp:240
std::variant< CNoDestination, PKHash, ScriptHash > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:85
Definition: amount.h:19
static constexpr Amount zero() noexcept
Definition: amount.h:32
A BlockHash is a unqiue identifier for a block.
Definition: blockhash.h:13
std::optional< int > last_scanned_height
Definition: wallet.h:627
BlockHash last_scanned_block
Hash and height of most recent block that was successfully scanned.
Definition: wallet.h:626
enum CWallet::ScanResult::@20 status
BlockHash last_failed_block
Hash of the most recent block that could not be scanned due to read errors or pruning.
Definition: wallet.h:633
Confirmation includes tx status and a triplet of {block height/block hash/tx index in block} at which...
Definition: transaction.h:181
uint64_t create_flags
Definition: db.h:224
int nFile
Definition: flatfile.h:15
Testing setup and teardown for wallet.
Bilingual messages:
Definition: translation.h:17
#define ENTER_CRITICAL_SECTION(cs)
Definition: sync.h:320
#define LEAVE_CRITICAL_SECTION(cs)
Definition: sync.h:326
#define LOCK2(cs1, cs2)
Definition: sync.h:309
#define LOCK(cs)
Definition: sync.h:306
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
Definition: sync.h:357
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:56
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
Definition: time.cpp:89
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1202
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
assert(!tx.IsCoinBase())
void CallFunctionInValidationInterfaceQueue(std::function< void()> func)
Pushes a function to callback onto the notification queue, guaranteeing any callbacks generated prior...
void SyncWithValidationInterfaceQueue()
This is a synonym for the following, which asserts certain locks are not held: std::promise<void> pro...
DatabaseStatus
Definition: db.h:229
std::shared_ptr< CWallet > m_wallet
Definition: interfaces.cpp:475
static constexpr size_t DUMMY_P2PKH_INPUT_SIZE
Pre-calculated constants for input size estimation.
Definition: wallet.h:115
constexpr Amount DEFAULT_TRANSACTION_MAXFEE
-maxtxfee default
Definition: wallet.h:108
std::unique_ptr< interfaces::Handler > HandleLoadWallet(LoadWalletFn load_wallet)
Definition: wallet.cpp:167
bool RemoveWallet(const std::shared_ptr< CWallet > &wallet, std::optional< bool > load_on_start, std::vector< bilingual_str > &warnings)
Definition: wallet.cpp:121
std::unique_ptr< WalletDatabase > MakeWalletDatabase(const std::string &name, const DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error_string)
Definition: wallet.cpp:2671
void UnloadWallet(std::shared_ptr< CWallet > &&wallet)
Explicitly unload and delete the wallet.
Definition: wallet.cpp:202
bool AddWallet(const std::shared_ptr< CWallet > &wallet)
Definition: wallet.cpp:107
std::shared_ptr< CWallet > CreateWallet(interfaces::Chain &chain, const std::string &name, std::optional< bool > load_on_start, const DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error, std::vector< bilingual_str > &warnings)
Definition: wallet.cpp:284
static void PollutePubKey(CPubKey &pubkey)
static std::shared_ptr< CWallet > TestLoadWallet(interfaces::Chain *chain)
static size_t CalculateP2PKHInputSize(bool use_max_sig)
static void TestUnloadWallet(std::shared_ptr< CWallet > &&wallet)
static CMutableTransaction TestSimpleSpend(const CTransaction &from, uint32_t index, const CKey &key, const CScript &pubkey)
BOOST_AUTO_TEST_CASE(ComputeTimeSmart)
static int64_t AddTx(ChainstateManager &chainman, CWallet &wallet, uint32_t lockTime, int64_t mockTime, int64_t blockTime)
RecursiveMutex cs_wallets
Definition: wallet.cpp:51
BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
static void AddKey(CWallet &wallet, const CKey &key)
static void TestWatchOnlyPubKey(LegacyScriptPubKeyMan *spk_man, const CPubKey &add_pubkey)
bool malformed_descriptor(std::ios_base::failure e)
std::unique_ptr< WalletDatabase > CreateDummyWalletDatabase()
Return object for accessing dummy database with no read/write capabilities.
Definition: walletdb.cpp:1170
std::unique_ptr< WalletDatabase > CreateMockWalletDatabase()
Return object for accessing temporary in-memory database.
Definition: walletdb.cpp:1175
@ WALLET_FLAG_DISABLE_PRIVATE_KEYS
Definition: walletutil.h:55
@ FEATURE_LATEST
Definition: walletutil.h:36