Bitcoin ABC  0.26.3
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/rpcdump.h>
17 #include <wallet/wallet.h>
18 
19 #include <test/util/logging.h>
20 #include <test/util/setup_common.h>
22 
23 #include <boost/test/unit_test.hpp>
24 
25 #include <univalue.h>
26 
27 #include <any>
28 #include <cstdint>
29 #include <future>
30 #include <memory>
31 #include <vector>
32 
34 
36 
37 static std::shared_ptr<CWallet> TestLoadWallet(interfaces::Chain &chain) {
38  DatabaseOptions options;
39  DatabaseStatus status;
41  std::vector<bilingual_str> warnings;
42  auto database = MakeWalletDatabase("", options, status, error);
43  auto wallet = CWallet::Create(chain, "", std::move(database),
44  options.create_flags, error, warnings);
45  wallet->postInitProcess();
46  return wallet;
47 }
48 
49 static void TestUnloadWallet(std::shared_ptr<CWallet> &&wallet) {
51  wallet->m_chain_notifications_handler.reset();
52  UnloadWallet(std::move(wallet));
53 }
54 
56  uint32_t index, const CKey &key,
57  const CScript &pubkey) {
59  mtx.vout.push_back(
60  {from.vout[index].nValue - DEFAULT_TRANSACTION_MAXFEE, pubkey});
61  mtx.vin.push_back({CTxIn{from.GetId(), index}});
62  FillableSigningProvider keystore;
63  keystore.AddKey(key);
64  std::map<COutPoint, Coin> coins;
65  coins[mtx.vin[0].prevout].GetTxOut() = from.vout[index];
66  std::map<int, std::string> input_errors;
67  BOOST_CHECK(SignTransaction(mtx, &keystore, coins,
68  SigHashType().withForkId(), input_errors));
69  return mtx;
70 }
71 
72 static void AddKey(CWallet &wallet, const CKey &key) {
73  auto spk_man = wallet.GetOrCreateLegacyScriptPubKeyMan();
74  LOCK2(wallet.cs_wallet, spk_man->cs_KeyStore);
75  spk_man->AddKeyPubKey(key, key.GetPubKey());
76 }
77 
78 BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup) {
79  // Cap last block file size, and mine new block in a new block file.
80  CBlockIndex *oldTip = m_node.chainman->ActiveTip();
81  WITH_LOCK(::cs_main, m_node.chainman->m_blockman
82  .GetBlockFileInfo(oldTip->GetBlockPos().nFile)
83  ->nSize = MAX_BLOCKFILE_SIZE);
84  CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey()));
85  CBlockIndex *newTip = m_node.chainman->ActiveTip();
86 
87  // Verify ScanForWalletTransactions fails to read an unknown start block.
88  {
89  CWallet wallet(m_node.chain.get(), "", CreateDummyWalletDatabase());
90  {
91  LOCK(wallet.cs_wallet);
92  wallet.SetLastBlockProcessed(
93  m_node.chainman->ActiveHeight(),
94  m_node.chainman->ActiveTip()->GetBlockHash());
95  }
96  AddKey(wallet, coinbaseKey);
97  WalletRescanReserver reserver(wallet);
98  reserver.reserve();
100  BlockHash() /* start_block */, 0 /* start_height */,
101  {} /* max_height */, reserver, false /* update */);
107  }
108 
109  // Verify ScanForWalletTransactions picks up transactions in both the old
110  // and new block files.
111  {
112  CWallet wallet(m_node.chain.get(), "", CreateDummyWalletDatabase());
113  {
114  LOCK(wallet.cs_wallet);
115  wallet.SetLastBlockProcessed(
116  m_node.chainman->ActiveHeight(),
117  m_node.chainman->ActiveTip()->GetBlockHash());
118  }
119  AddKey(wallet, coinbaseKey);
120  WalletRescanReserver reserver(wallet);
121  reserver.reserve();
123  oldTip->GetBlockHash(), oldTip->nHeight, {} /* max_height */,
124  reserver, false /* update */);
127  BOOST_CHECK_EQUAL(result.last_scanned_block, newTip->GetBlockHash());
128  BOOST_CHECK_EQUAL(*result.last_scanned_height, newTip->nHeight);
130  }
131 
132  // Prune the older block file.
133  {
134  LOCK(cs_main);
136  ->m_blockman.PruneOneBlockFile(oldTip->GetBlockPos().nFile);
137  }
138  UnlinkPrunedFiles({oldTip->GetBlockPos().nFile});
139 
140  // Verify ScanForWalletTransactions only picks transactions in the new block
141  // file.
142  {
143  CWallet wallet(m_node.chain.get(), "", CreateDummyWalletDatabase());
144  {
145  LOCK(wallet.cs_wallet);
146  wallet.SetLastBlockProcessed(
147  m_node.chainman->ActiveHeight(),
148  m_node.chainman->ActiveTip()->GetBlockHash());
149  }
150  AddKey(wallet, coinbaseKey);
151  WalletRescanReserver reserver(wallet);
152  reserver.reserve();
154  oldTip->GetBlockHash(), oldTip->nHeight, {} /* max_height */,
155  reserver, false /* update */);
158  BOOST_CHECK_EQUAL(result.last_scanned_block, newTip->GetBlockHash());
159  BOOST_CHECK_EQUAL(*result.last_scanned_height, newTip->nHeight);
161  }
162 
163  // Prune the remaining block file.
164  {
165  LOCK(cs_main);
167  ->m_blockman.PruneOneBlockFile(newTip->GetBlockPos().nFile);
168  }
169  UnlinkPrunedFiles({newTip->GetBlockPos().nFile});
170 
171  // Verify ScanForWalletTransactions scans no blocks.
172  {
173  CWallet wallet(m_node.chain.get(), "", CreateDummyWalletDatabase());
174  {
175  LOCK(wallet.cs_wallet);
176  wallet.SetLastBlockProcessed(
177  m_node.chainman->ActiveHeight(),
178  m_node.chainman->ActiveTip()->GetBlockHash());
179  }
180  AddKey(wallet, coinbaseKey);
181  WalletRescanReserver reserver(wallet);
182  reserver.reserve();
184  oldTip->GetBlockHash(), oldTip->nHeight, {} /* max_height */,
185  reserver, false /* update */);
187  BOOST_CHECK_EQUAL(result.last_failed_block, newTip->GetBlockHash());
191  }
192 }
193 
194 BOOST_FIXTURE_TEST_CASE(importmulti_rescan, TestChain100Setup) {
195  // Cap last block file size, and mine new block in a new block file.
196  CBlockIndex *oldTip = m_node.chainman->ActiveTip();
197  WITH_LOCK(::cs_main, m_node.chainman->m_blockman
198  .GetBlockFileInfo(oldTip->GetBlockPos().nFile)
199  ->nSize = MAX_BLOCKFILE_SIZE);
200  CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey()));
201  CBlockIndex *newTip = m_node.chainman->ActiveTip();
202 
203  // Prune the older block file.
204  {
205  LOCK(cs_main);
207  ->m_blockman.PruneOneBlockFile(oldTip->GetBlockPos().nFile);
208  }
209  UnlinkPrunedFiles({oldTip->GetBlockPos().nFile});
210 
211  // Verify importmulti RPC returns failure for a key whose creation time is
212  // before the missing block, and success for a key whose creation time is
213  // after.
214  {
215  std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(
216  m_node.chain.get(), "", CreateDummyWalletDatabase());
217  wallet->SetupLegacyScriptPubKeyMan();
218  WITH_LOCK(wallet->cs_wallet,
219  wallet->SetLastBlockProcessed(newTip->nHeight,
220  newTip->GetBlockHash()));
221  AddWallet(wallet);
222  UniValue keys;
223  keys.setArray();
224  UniValue key;
225  key.setObject();
226  key.pushKV("scriptPubKey",
227  HexStr(GetScriptForRawPubKey(coinbaseKey.GetPubKey())));
228  key.pushKV("timestamp", 0);
229  key.pushKV("internal", UniValue(true));
230  keys.push_back(key);
231  key.clear();
232  key.setObject();
233  CKey futureKey;
234  futureKey.MakeNewKey(true);
235  key.pushKV("scriptPubKey",
236  HexStr(GetScriptForRawPubKey(futureKey.GetPubKey())));
237  key.pushKV("timestamp",
238  newTip->GetBlockTimeMax() + TIMESTAMP_WINDOW + 1);
239  key.pushKV("internal", UniValue(true));
240  keys.push_back(key);
241  JSONRPCRequest request;
242  request.params.setArray();
243  request.params.push_back(keys);
244 
247  response.write(),
248  strprintf("[{\"success\":false,\"error\":{\"code\":-1,\"message\":"
249  "\"Rescan failed for key with creation timestamp %d. "
250  "There was an error reading a block from time %d, which "
251  "is after or within %d seconds of key creation, and "
252  "could contain transactions pertaining to the key. As a "
253  "result, transactions and coins using this key may not "
254  "appear in the wallet. This error could be caused by "
255  "pruning or data corruption (see bitcoind log for "
256  "details) and could be dealt with by downloading and "
257  "rescanning the relevant blocks (see -reindex and "
258  "-rescan options).\"}},{\"success\":true}]",
259  0, oldTip->GetBlockTimeMax(), TIMESTAMP_WINDOW));
260  RemoveWallet(wallet, std::nullopt);
261  }
262 }
263 
264 // Verify importwallet RPC starts rescan at earliest block with timestamp
265 // greater or equal than key birthday. Previously there was a bug where
266 // importwallet RPC would start the scan at the latest block with timestamp less
267 // than or equal to key birthday.
268 BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup) {
269  // Create two blocks with same timestamp to verify that importwallet rescan
270  // will pick up both blocks, not just the first.
271  const int64_t BLOCK_TIME =
272  m_node.chainman->ActiveTip()->GetBlockTimeMax() + 5;
273  SetMockTime(BLOCK_TIME);
274  m_coinbase_txns.emplace_back(
275  CreateAndProcessBlock({},
276  GetScriptForRawPubKey(coinbaseKey.GetPubKey()))
277  .vtx[0]);
278  m_coinbase_txns.emplace_back(
279  CreateAndProcessBlock({},
280  GetScriptForRawPubKey(coinbaseKey.GetPubKey()))
281  .vtx[0]);
282 
283  // Set key birthday to block time increased by the timestamp window, so
284  // rescan will start at the block time.
285  const int64_t KEY_TIME = BLOCK_TIME + TIMESTAMP_WINDOW;
286  SetMockTime(KEY_TIME);
287  m_coinbase_txns.emplace_back(
288  CreateAndProcessBlock({},
289  GetScriptForRawPubKey(coinbaseKey.GetPubKey()))
290  .vtx[0]);
291 
292  std::string backup_file =
293  fs::PathToString(gArgs.GetDataDirNet() / "wallet.backup");
294 
295  // Import key into wallet and call dumpwallet to create backup file.
296  {
297  std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(
298  m_node.chain.get(), "", CreateDummyWalletDatabase());
299  {
300  auto spk_man = wallet->GetOrCreateLegacyScriptPubKeyMan();
301  LOCK2(wallet->cs_wallet, spk_man->cs_KeyStore);
302  spk_man->mapKeyMetadata[coinbaseKey.GetPubKey().GetID()]
303  .nCreateTime = KEY_TIME;
304  spk_man->AddKeyPubKey(coinbaseKey, coinbaseKey.GetPubKey());
305 
306  AddWallet(wallet);
307  wallet->SetLastBlockProcessed(
308  m_node.chainman->ActiveHeight(),
309  m_node.chainman->ActiveTip()->GetBlockHash());
310  }
311  JSONRPCRequest request;
312  request.params.setArray();
313  request.params.push_back(backup_file);
314  ::dumpwallet().HandleRequest(GetConfig(), request);
315  RemoveWallet(wallet, std::nullopt);
316  }
317 
318  // Call importwallet RPC and verify all blocks with timestamps >= BLOCK_TIME
319  // were scanned, and no prior blocks were scanned.
320  {
321  std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(
322  m_node.chain.get(), "", CreateDummyWalletDatabase());
323  LOCK(wallet->cs_wallet);
324  wallet->SetupLegacyScriptPubKeyMan();
325 
326  JSONRPCRequest request;
327  request.params.setArray();
328  request.params.push_back(backup_file);
329  AddWallet(wallet);
330  wallet->SetLastBlockProcessed(
331  m_node.chainman->ActiveHeight(),
332  m_node.chainman->ActiveTip()->GetBlockHash());
333  ::importwallet().HandleRequest(GetConfig(), request);
334  RemoveWallet(wallet, std::nullopt);
335 
336  BOOST_CHECK_EQUAL(wallet->mapWallet.size(), 3U);
337  BOOST_CHECK_EQUAL(m_coinbase_txns.size(), 103U);
338  for (size_t i = 0; i < m_coinbase_txns.size(); ++i) {
339  bool found = wallet->GetWalletTx(m_coinbase_txns[i]->GetId());
340  bool expected = i >= 100;
341  BOOST_CHECK_EQUAL(found, expected);
342  }
343  }
344 }
345 
346 // Check that GetImmatureCredit() returns a newly calculated value instead of
347 // the cached value after a MarkDirty() call.
348 //
349 // This is a regression test written to verify a bugfix for the immature credit
350 // function. Similar tests probably should be written for the other credit and
351 // debit functions.
352 BOOST_FIXTURE_TEST_CASE(coin_mark_dirty_immature_credit, TestChain100Setup) {
353  CWallet wallet(m_node.chain.get(), "", CreateDummyWalletDatabase());
354  auto spk_man = wallet.GetOrCreateLegacyScriptPubKeyMan();
355  CWalletTx wtx(&wallet, m_coinbase_txns.back());
356 
357  LOCK2(wallet.cs_wallet, spk_man->cs_KeyStore);
358  wallet.SetLastBlockProcessed(m_node.chainman->ActiveHeight(),
359  m_node.chainman->ActiveTip()->GetBlockHash());
360 
361  CWalletTx::Confirmation confirm(
362  CWalletTx::Status::CONFIRMED, m_node.chainman->ActiveHeight(),
363  m_node.chainman->ActiveTip()->GetBlockHash(), 0);
364  wtx.m_confirm = confirm;
365 
366  // Call GetImmatureCredit() once before adding the key to the wallet to
367  // cache the current immature credit amount, which is 0.
369 
370  // Invalidate the cached value, add the key, and make sure a new immature
371  // credit amount is calculated.
372  wtx.MarkDirty();
373  BOOST_CHECK(spk_man->AddKeyPubKey(coinbaseKey, coinbaseKey.GetPubKey()));
375 }
376 
377 static int64_t AddTx(ChainstateManager &chainman, CWallet &wallet,
378  uint32_t lockTime, int64_t mockTime, int64_t blockTime) {
380  CWalletTx::Confirmation confirm;
381  tx.nLockTime = lockTime;
382  SetMockTime(mockTime);
383  CBlockIndex *block = nullptr;
384  if (blockTime > 0) {
385  LOCK(cs_main);
386  auto inserted = chainman.BlockIndex().emplace(BlockHash(GetRandHash()),
387  new CBlockIndex);
388  assert(inserted.second);
389  const BlockHash &hash = inserted.first->first;
390  block = inserted.first->second;
391  block->nTime = blockTime;
392  block->phashBlock = &hash;
393  confirm = {CWalletTx::Status::CONFIRMED, block->nHeight, hash, 0};
394  }
395 
396  // If transaction is already in map, to avoid inconsistencies,
397  // unconfirmation is needed before confirm again with different block.
398  return wallet
399  .AddToWallet(MakeTransactionRef(tx), confirm,
400  [&](CWalletTx &wtx, bool /* new_tx */) {
401  wtx.setUnconfirmed();
402  return true;
403  })
404  ->nTimeSmart;
405 }
406 
407 // Simple test to verify assignment of CWalletTx::nSmartTime value. Could be
408 // expanded to cover more corner cases of smart time logic.
409 BOOST_AUTO_TEST_CASE(ComputeTimeSmart) {
410  // New transaction should use clock time if lower than block time.
411  BOOST_CHECK_EQUAL(AddTx(*m_node.chainman, m_wallet, 1, 100, 120), 100);
412 
413  // Test that updating existing transaction does not change smart time.
414  BOOST_CHECK_EQUAL(AddTx(*m_node.chainman, m_wallet, 1, 200, 220), 100);
415 
416  // New transaction should use clock time if there's no block time.
417  BOOST_CHECK_EQUAL(AddTx(*m_node.chainman, m_wallet, 2, 300, 0), 300);
418 
419  // New transaction should use block time if lower than clock time.
420  BOOST_CHECK_EQUAL(AddTx(*m_node.chainman, m_wallet, 3, 420, 400), 400);
421 
422  // New transaction should use latest entry time if higher than
423  // min(block time, clock time).
424  BOOST_CHECK_EQUAL(AddTx(*m_node.chainman, m_wallet, 4, 500, 390), 400);
425 
426  // If there are future entries, new transaction should use time of the
427  // newest entry that is no more than 300 seconds ahead of the clock time.
428  BOOST_CHECK_EQUAL(AddTx(*m_node.chainman, m_wallet, 5, 50, 600), 300);
429 
430  // Reset mock time for other tests.
431  SetMockTime(0);
432 }
433 
434 BOOST_AUTO_TEST_CASE(LoadReceiveRequests) {
435  CTxDestination dest = PKHash();
436  LOCK(m_wallet.cs_wallet);
437  WalletBatch batch{m_wallet.GetDatabase()};
438  m_wallet.AddDestData(batch, dest, "misc", "val_misc");
439  m_wallet.AddDestData(batch, dest, "rr0", "val_rr0");
440  m_wallet.AddDestData(batch, dest, "rr1", "val_rr1");
441 
442  auto values = m_wallet.GetDestValues("rr");
443  BOOST_CHECK_EQUAL(values.size(), 2U);
444  BOOST_CHECK_EQUAL(values[0], "val_rr0");
445  BOOST_CHECK_EQUAL(values[1], "val_rr1");
446 }
447 
448 // Test some watch-only LegacyScriptPubKeyMan methods by the procedure of
449 // loading (LoadWatchOnly), checking (HaveWatchOnly), getting (GetWatchPubKey)
450 // and removing (RemoveWatchOnly) a given PubKey, resp. its corresponding P2PK
451 // Script. Results of the the impact on the address -> PubKey map is dependent
452 // on whether the PubKey is a point on the curve
454  const CPubKey &add_pubkey) {
455  CScript p2pk = GetScriptForRawPubKey(add_pubkey);
456  CKeyID add_address = add_pubkey.GetID();
457  CPubKey found_pubkey;
458  LOCK(spk_man->cs_KeyStore);
459 
460  // all Scripts (i.e. also all PubKeys) are added to the general watch-only
461  // set
462  BOOST_CHECK(!spk_man->HaveWatchOnly(p2pk));
463  spk_man->LoadWatchOnly(p2pk);
464  BOOST_CHECK(spk_man->HaveWatchOnly(p2pk));
465 
466  // only PubKeys on the curve shall be added to the watch-only address ->
467  // PubKey map
468  bool is_pubkey_fully_valid = add_pubkey.IsFullyValid();
469  if (is_pubkey_fully_valid) {
470  BOOST_CHECK(spk_man->GetWatchPubKey(add_address, found_pubkey));
471  BOOST_CHECK(found_pubkey == add_pubkey);
472  } else {
473  BOOST_CHECK(!spk_man->GetWatchPubKey(add_address, found_pubkey));
474  // passed key is unchanged
475  BOOST_CHECK(found_pubkey == CPubKey());
476  }
477 
478  spk_man->RemoveWatchOnly(p2pk);
479  BOOST_CHECK(!spk_man->HaveWatchOnly(p2pk));
480 
481  if (is_pubkey_fully_valid) {
482  BOOST_CHECK(!spk_man->GetWatchPubKey(add_address, found_pubkey));
483  // passed key is unchanged
484  BOOST_CHECK(found_pubkey == add_pubkey);
485  }
486 }
487 
488 // Cryptographically invalidate a PubKey whilst keeping length and first byte
489 static void PollutePubKey(CPubKey &pubkey) {
490  std::vector<uint8_t> pubkey_raw(pubkey.begin(), pubkey.end());
491  std::fill(pubkey_raw.begin() + 1, pubkey_raw.end(), 0);
492  pubkey = CPubKey(pubkey_raw);
493  assert(!pubkey.IsFullyValid());
494  assert(pubkey.IsValid());
495 }
496 
497 // Test watch-only logic for PubKeys
498 BOOST_AUTO_TEST_CASE(WatchOnlyPubKeys) {
499  CKey key;
500  CPubKey pubkey;
501  LegacyScriptPubKeyMan *spk_man =
502  m_wallet.GetOrCreateLegacyScriptPubKeyMan();
503 
504  BOOST_CHECK(!spk_man->HaveWatchOnly());
505 
506  // uncompressed valid PubKey
507  key.MakeNewKey(false);
508  pubkey = key.GetPubKey();
509  assert(!pubkey.IsCompressed());
510  TestWatchOnlyPubKey(spk_man, pubkey);
511 
512  // uncompressed cryptographically invalid PubKey
513  PollutePubKey(pubkey);
514  TestWatchOnlyPubKey(spk_man, pubkey);
515 
516  // compressed valid PubKey
517  key.MakeNewKey(true);
518  pubkey = key.GetPubKey();
519  assert(pubkey.IsCompressed());
520  TestWatchOnlyPubKey(spk_man, pubkey);
521 
522  // compressed cryptographically invalid PubKey
523  PollutePubKey(pubkey);
524  TestWatchOnlyPubKey(spk_man, pubkey);
525 
526  // invalid empty PubKey
527  pubkey = CPubKey();
528  TestWatchOnlyPubKey(spk_man, pubkey);
529 }
530 
531 class ListCoinsTestingSetup : public TestChain100Setup {
532 public:
534  CreateAndProcessBlock({},
535  GetScriptForRawPubKey(coinbaseKey.GetPubKey()));
536  wallet = std::make_unique<CWallet>(m_node.chain.get(), "",
538  {
539  LOCK2(wallet->cs_wallet, ::cs_main);
540  wallet->SetLastBlockProcessed(
541  m_node.chainman->ActiveHeight(),
542  m_node.chainman->ActiveTip()->GetBlockHash());
543  }
544  bool firstRun;
545  wallet->LoadWallet(firstRun);
546  AddKey(*wallet, coinbaseKey);
547  WalletRescanReserver reserver(*wallet);
548  reserver.reserve();
549  CWallet::ScanResult result = wallet->ScanForWalletTransactions(
550  m_node.chainman->ActiveChain().Genesis()->GetBlockHash(),
551  0 /* start_height */, {} /* max_height */, reserver,
552  false /* update */);
555  m_node.chainman->ActiveTip()->GetBlockHash());
557  m_node.chainman->ActiveHeight());
559  }
560 
562 
563  CWalletTx &AddTx(CRecipient recipient) {
564  CTransactionRef tx;
565  Amount fee;
566  int changePos = -1;
568  CCoinControl dummy;
569  {
570  BOOST_CHECK(wallet->CreateTransaction({recipient}, tx, fee,
571  changePos, error, dummy));
572  }
573  wallet->CommitTransaction(tx, {}, {});
574  CMutableTransaction blocktx;
575  {
576  LOCK(wallet->cs_wallet);
577  blocktx =
578  CMutableTransaction(*wallet->mapWallet.at(tx->GetId()).tx);
579  }
580  CreateAndProcessBlock({CMutableTransaction(blocktx)},
581  GetScriptForRawPubKey(coinbaseKey.GetPubKey()));
582 
583  LOCK(wallet->cs_wallet);
584  wallet->SetLastBlockProcessed(
585  wallet->GetLastBlockHeight() + 1,
586  m_node.chainman->ActiveTip()->GetBlockHash());
587  auto it = wallet->mapWallet.find(tx->GetId());
588  BOOST_CHECK(it != wallet->mapWallet.end());
589  CWalletTx::Confirmation confirm(
590  CWalletTx::Status::CONFIRMED, m_node.chainman->ActiveHeight(),
591  m_node.chainman->ActiveTip()->GetBlockHash(), 1);
592  it->second.m_confirm = confirm;
593  return it->second;
594  }
595 
596  std::unique_ptr<CWallet> wallet;
597 };
598 
600  std::string coinbaseAddress = coinbaseKey.GetPubKey().GetID().ToString();
601 
602  // Confirm ListCoins initially returns 1 coin grouped under coinbaseKey
603  // address.
604  std::map<CTxDestination, std::vector<COutput>> list;
605  {
606  LOCK(wallet->cs_wallet);
607  list = wallet->ListCoins();
608  }
609  BOOST_CHECK_EQUAL(list.size(), 1U);
610  BOOST_CHECK_EQUAL(boost::get<PKHash>(list.begin()->first).ToString(),
611  coinbaseAddress);
612  BOOST_CHECK_EQUAL(list.begin()->second.size(), 1U);
613 
614  // Check initial balance from one mature coinbase transaction.
615  BOOST_CHECK_EQUAL(50 * COIN, wallet->GetAvailableBalance());
616 
617  // Add a transaction creating a change address, and confirm ListCoins still
618  // returns the coin associated with the change address underneath the
619  // coinbaseKey pubkey, even though the change address has a different
620  // pubkey.
622  false /* subtract fee */});
623  {
624  LOCK(wallet->cs_wallet);
625  list = wallet->ListCoins();
626  }
627  BOOST_CHECK_EQUAL(list.size(), 1U);
628  BOOST_CHECK_EQUAL(boost::get<PKHash>(list.begin()->first).ToString(),
629  coinbaseAddress);
630  BOOST_CHECK_EQUAL(list.begin()->second.size(), 2U);
631 
632  // Lock both coins. Confirm number of available coins drops to 0.
633  {
634  LOCK(wallet->cs_wallet);
635  std::vector<COutput> available;
636  wallet->AvailableCoins(available);
637  BOOST_CHECK_EQUAL(available.size(), 2U);
638  }
639  for (const auto &group : list) {
640  for (const auto &coin : group.second) {
641  LOCK(wallet->cs_wallet);
642  wallet->LockCoin(COutPoint(coin.tx->GetId(), coin.i));
643  }
644  }
645  {
646  LOCK(wallet->cs_wallet);
647  std::vector<COutput> available;
648  wallet->AvailableCoins(available);
649  BOOST_CHECK_EQUAL(available.size(), 0U);
650  }
651  // Confirm ListCoins still returns same result as before, despite coins
652  // being locked.
653  {
654  LOCK(wallet->cs_wallet);
655  list = wallet->ListCoins();
656  }
657  BOOST_CHECK_EQUAL(list.size(), 1U);
658  BOOST_CHECK_EQUAL(boost::get<PKHash>(list.begin()->first).ToString(),
659  coinbaseAddress);
660  BOOST_CHECK_EQUAL(list.begin()->second.size(), 2U);
661 }
662 
663 BOOST_FIXTURE_TEST_CASE(wallet_disableprivkeys, TestChain100Setup) {
664  std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(
665  m_node.chain.get(), "", CreateDummyWalletDatabase());
666  wallet->SetupLegacyScriptPubKeyMan();
667  wallet->SetMinVersion(FEATURE_LATEST);
668  wallet->SetWalletFlag(WALLET_FLAG_DISABLE_PRIVATE_KEYS);
669  BOOST_CHECK(!wallet->TopUpKeyPool(1000));
670  CTxDestination dest;
671  std::string error;
672  BOOST_CHECK(
673  !wallet->GetNewDestination(OutputType::LEGACY, "", dest, error));
674 }
675 
676 // Explicit calculation which is used to test the wallet constant
677 static size_t CalculateP2PKHInputSize(bool use_max_sig) {
678  // Generate ephemeral valid pubkey
679  CKey key;
680  key.MakeNewKey(true);
681  CPubKey pubkey = key.GetPubKey();
682 
683  // Generate pubkey hash
684  PKHash key_hash(pubkey);
685 
686  // Create script to enter into keystore. Key hash can't be 0...
687  CScript script = GetScriptForDestination(key_hash);
688 
689  // Add script to key store and key to watchonly
690  FillableSigningProvider keystore;
691  keystore.AddKeyPubKey(key, pubkey);
692 
693  // Fill in dummy signatures for fee calculation.
694  SignatureData sig_data;
695  if (!ProduceSignature(keystore,
696  use_max_sig ? DUMMY_MAXIMUM_SIGNATURE_CREATOR
698  script, sig_data)) {
699  // We're hand-feeding it correct arguments; shouldn't happen
700  assert(false);
701  }
702 
703  CTxIn tx_in;
704  UpdateInput(tx_in, sig_data);
705  return (size_t)GetVirtualTransactionInputSize(tx_in);
706 }
707 
708 BOOST_FIXTURE_TEST_CASE(dummy_input_size_test, TestChain100Setup) {
711 }
712 
713 bool malformed_descriptor(std::ios_base::failure e) {
714  std::string s(e.what());
715  return s.find("Missing checksum") != std::string::npos;
716 }
717 
718 BOOST_FIXTURE_TEST_CASE(wallet_descriptor_test, BasicTestingSetup) {
719  std::vector<uint8_t> malformed_record;
720  CVectorWriter vw(0, 0, malformed_record, 0);
721  vw << std::string("notadescriptor");
722  vw << (uint64_t)0;
723  vw << (int32_t)0;
724  vw << (int32_t)0;
725  vw << (int32_t)1;
726 
727  VectorReader vr(0, 0, malformed_record, 0);
728  WalletDescriptor w_desc;
729  BOOST_CHECK_EXCEPTION(vr >> w_desc, std::ios_base::failure,
731 }
732 
752  // Create new wallet with known key and unload it.
753  auto wallet = TestLoadWallet(*m_node.chain);
754  CKey key;
755  key.MakeNewKey(true);
756  AddKey(*wallet, key);
757  TestUnloadWallet(std::move(wallet));
758 
759  // Add log hook to detect AddToWallet events from rescans, blockConnected,
760  // and transactionAddedToMempool notifications
761  int addtx_count = 0;
762  DebugLogHelper addtx_counter("[default wallet] AddToWallet",
763  [&](const std::string *s) {
764  if (s) {
765  ++addtx_count;
766  }
767  return false;
768  });
769 
770  bool rescan_completed = false;
771  DebugLogHelper rescan_check("[default wallet] Rescan completed",
772  [&](const std::string *s) {
773  if (s) {
774  rescan_completed = true;
775  }
776  return false;
777  });
778 
779  // Block the queue to prevent the wallet receiving blockConnected and
780  // transactionAddedToMempool notifications, and create block and mempool
781  // transactions paying to the wallet
782  std::promise<void> promise;
784  [&promise] { promise.get_future().wait(); });
785  std::string error;
786  m_coinbase_txns.push_back(
787  CreateAndProcessBlock({},
788  GetScriptForRawPubKey(coinbaseKey.GetPubKey()))
789  .vtx[0]);
790  auto block_tx = TestSimpleSpend(*m_coinbase_txns[0], 0, coinbaseKey,
792  m_coinbase_txns.push_back(
793  CreateAndProcessBlock({block_tx},
794  GetScriptForRawPubKey(coinbaseKey.GetPubKey()))
795  .vtx[0]);
796  auto mempool_tx = TestSimpleSpend(*m_coinbase_txns[1], 0, coinbaseKey,
798  BOOST_CHECK(m_node.chain->broadcastTransaction(
800  false, error));
801 
802  // Reload wallet and make sure new transactions are detected despite events
803  // being blocked
804  wallet = TestLoadWallet(*m_node.chain);
805  BOOST_CHECK(rescan_completed);
806  BOOST_CHECK_EQUAL(addtx_count, 2);
807  {
808  LOCK(wallet->cs_wallet);
809  BOOST_CHECK_EQUAL(wallet->mapWallet.count(block_tx.GetId()), 1U);
810  BOOST_CHECK_EQUAL(wallet->mapWallet.count(mempool_tx.GetId()), 1U);
811  }
812 
813  // Unblock notification queue and make sure stale blockConnected and
814  // transactionAddedToMempool events are processed
815  promise.set_value();
817  BOOST_CHECK_EQUAL(addtx_count, 4);
818 
819  TestUnloadWallet(std::move(wallet));
820 
821  // Load wallet again, this time creating new block and mempool transactions
822  // paying to the wallet as the wallet finishes loading and syncing the
823  // queue so the events have to be handled immediately. Releasing the wallet
824  // lock during the sync is a little artificial but is needed to avoid a
825  // deadlock during the sync and simulates a new block notification happening
826  // as soon as possible.
827  addtx_count = 0;
828  auto handler = HandleLoadWallet(
829  [&](std::unique_ptr<interfaces::Wallet> wallet_param)
830  EXCLUSIVE_LOCKS_REQUIRED(wallet_param->wallet()->cs_wallet,
831  cs_wallets) {
832  BOOST_CHECK(rescan_completed);
833  m_coinbase_txns.push_back(
834  CreateAndProcessBlock(
835  {}, GetScriptForRawPubKey(coinbaseKey.GetPubKey()))
836  .vtx[0]);
837  block_tx =
838  TestSimpleSpend(*m_coinbase_txns[2], 0, coinbaseKey,
840  m_coinbase_txns.push_back(
841  CreateAndProcessBlock(
842  {block_tx},
843  GetScriptForRawPubKey(coinbaseKey.GetPubKey()))
844  .vtx[0]);
845  mempool_tx =
846  TestSimpleSpend(*m_coinbase_txns[3], 0, coinbaseKey,
848  BOOST_CHECK(m_node.chain->broadcastTransaction(
849  GetConfig(), MakeTransactionRef(mempool_tx),
852  LEAVE_CRITICAL_SECTION(wallet_param->wallet()->cs_wallet);
854  ENTER_CRITICAL_SECTION(wallet_param->wallet()->cs_wallet);
856  });
857  wallet = TestLoadWallet(*m_node.chain);
858  BOOST_CHECK_EQUAL(addtx_count, 4);
859  {
860  LOCK(wallet->cs_wallet);
861  BOOST_CHECK_EQUAL(wallet->mapWallet.count(block_tx.GetId()), 1U);
862  BOOST_CHECK_EQUAL(wallet->mapWallet.count(mempool_tx.GetId()), 1U);
863  }
864 
865  TestUnloadWallet(std::move(wallet));
866 }
867 
868 BOOST_FIXTURE_TEST_CASE(ZapSelectTx, TestChain100Setup) {
869  auto wallet = TestLoadWallet(*m_node.chain);
870  CKey key;
871  key.MakeNewKey(true);
872  AddKey(*wallet, key);
873 
874  std::string error;
875  m_coinbase_txns.push_back(
876  CreateAndProcessBlock({},
877  GetScriptForRawPubKey(coinbaseKey.GetPubKey()))
878  .vtx[0]);
879  auto block_tx = TestSimpleSpend(*m_coinbase_txns[0], 0, coinbaseKey,
881  CreateAndProcessBlock({block_tx},
882  GetScriptForRawPubKey(coinbaseKey.GetPubKey()));
883 
885 
886  {
887  auto block_id = block_tx.GetId();
888  auto prev_id = m_coinbase_txns[0]->GetId();
889 
890  LOCK(wallet->cs_wallet);
891  BOOST_CHECK(wallet->HasWalletSpend(prev_id));
892  BOOST_CHECK_EQUAL(wallet->mapWallet.count(block_id), 1u);
893 
894  std::vector<TxId> vIdIn{block_id}, vIdOut;
895  BOOST_CHECK_EQUAL(wallet->ZapSelectTx(vIdIn, vIdOut),
897 
898  BOOST_CHECK(!wallet->HasWalletSpend(prev_id));
899  BOOST_CHECK_EQUAL(wallet->mapWallet.count(block_id), 0u);
900  }
901 
902  TestUnloadWallet(std::move(wallet));
903 }
904 
static constexpr Amount COIN
Definition: amount.h:154
void UnlinkPrunedFiles(const std::set< int > &setFilesToPrune)
Actually unlink the specified files.
static const unsigned int MAX_BLOCKFILE_SIZE
The maximum size of a blk?????.dat file (since 0.8)
Definition: blockstorage.h:40
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
RecursiveMutex cs_main
Global state.
Definition: validation.cpp:94
#define Assert(val)
Identity function.
Definition: check.h:56
const fs::path & GetDataDirNet() const
Get data directory path with appended network identifier.
Definition: system.h:257
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: blockindex.h:23
const BlockHash * phashBlock
pointer to the hash of the block, if any.
Definition: blockindex.h:27
FlatFilePos GetBlockPos() const
Definition: blockindex.h:111
uint32_t nTime
Definition: blockindex.h:90
int64_t GetBlockTimeMax() const
Definition: blockindex.h:171
BlockHash GetBlockHash() const
Definition: blockindex.h:142
int nHeight
height of the entry in the chain. The genesis block has height 0
Definition: blockindex.h:36
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:278
std::vector< CTxOut > vout
Definition: transaction.h:281
std::vector< CTxIn > vin
Definition: transaction.h:280
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:22
An encapsulated public key.
Definition: pubkey.h:31
const uint8_t * begin() const
Definition: pubkey.h:100
bool IsCompressed() const
Check whether this is a compressed public key.
Definition: pubkey.h:159
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
Definition: pubkey.h:140
bool IsValid() const
Definition: pubkey.h:152
const uint8_t * end() const
Definition: pubkey.h:101
bool IsFullyValid() const
fully validate whether this is a valid public key (more expensive than IsValid())
Definition: pubkey.cpp:257
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:431
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:194
const std::vector< CTxOut > vout
Definition: transaction.h:211
const TxId GetId() const
Definition: transaction.h:244
An input of a transaction.
Definition: transaction.h:61
Minimal stream for overwriting and/or appending to an existing byte vector.
Definition: streams.h:63
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
Definition: wallet.h:679
RecursiveMutex cs_wallet
Definition: wallet.h:819
LegacyScriptPubKeyMan * GetOrCreateLegacyScriptPubKeyMan()
Definition: wallet.cpp:4895
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:4263
void SetLastBlockProcessed(int block_height, BlockHash block_hash) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Set last block processed height, currently only use in unit test.
Definition: wallet.h:1530
A transaction with a bunch of additional info that only the owner cares about.
Definition: wallet.h:280
Confirmation m_confirm
Definition: wallet.h:413
void setUnconfirmed()
Definition: wallet.h:581
void MarkDirty()
make sure balances are recalculated
Definition: wallet.h:485
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
Definition: validation.h:1075
BlockMap & BlockIndex() EXCLUSIVE_LOCKS_REQUIRED(
Definition: validation.h:1214
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:495
Signature hash type wrapper class.
Definition: sighashtype.h:37
bool setArray()
Definition: univalue.cpp:94
bool setObject()
Definition: univalue.cpp:101
void clear()
Definition: univalue.cpp:15
bool push_back(const UniValue &val)
Definition: univalue.cpp:108
bool pushKV(const std::string &key, const UniValue &val)
Definition: univalue.cpp:133
Minimal stream for reading from an existing vector by reference.
Definition: streams.h:129
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:1586
bool IsNull() const
Definition: uint256.h:30
const Config & GetConfig()
Definition: config.cpp:34
Balance GetBalance(int min_depth=0, bool avoid_reuse=true) const
Definition: wallet.cpp:2414
CWalletTx * AddToWallet(CTransactionRef tx, const CWalletTx::Confirmation &confirm, const UpdateWalletTxFn &update_wtx=nullptr, bool fFlushOnClose=true)
Definition: wallet.cpp:955
Amount GetImmatureCredit(bool fUseCache=true) const
Definition: wallet.cpp:2191
ScanResult ScanForWalletTransactions(const BlockHash &start_block, int start_height, std::optional< int > max_height, const WalletRescanReserver &reserver, bool fUpdate)
Scan the block chain (starting in start_block) for transactions from or to us.
Definition: wallet.cpp:1924
NodeContext & m_node
Definition: chain.cpp:483
std::shared_ptr< CWallet > m_wallet
Definition: wallet.cpp:462
static std::string PathToString(const path &path)
Convert path object to byte string.
Definition: fs.h:134
#define BOOST_AUTO_TEST_SUITE_END()
Definition: object.cpp:16
#define BOOST_FIXTURE_TEST_SUITE(a, b)
Definition: object.cpp:14
#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 nSigOpCount, unsigned int bytes_per_sigop)
Definition: policy.cpp:173
static CTransactionRef MakeTransactionRef()
Definition: transaction.h:320
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:319
Response response
Definition: processor.cpp:452
uint256 GetRandHash() noexcept
Definition: random.cpp:658
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.
bool(* handler)(Config &config, const std::any &context, HTTPRequest *req, const std::string &strReq)
Definition: rest.cpp:819
RPCHelpMan importmulti()
Definition: rpcdump.cpp:1664
RPCHelpMan importwallet()
Definition: rpcdump.cpp:631
RPCHelpMan dumpwallet()
Definition: rpcdump.cpp:898
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
CScript GetScriptForRawPubKey(const CPubKey &pubKey)
Generate a P2PK script for the given pubkey.
Definition: standard.cpp:247
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
Definition: standard.cpp:243
boost::variant< CNoDestination, PKHash, ScriptHash > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:93
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
Definition: amount.h:19
static constexpr Amount zero()
Definition: amount.h:42
A BlockHash is a unqiue identifier for a block.
Definition: blockhash.h:13
Amount m_mine_immature
Immature coinbases in the main chain.
Definition: wallet.h:1101
std::optional< int > last_scanned_height
Definition: wallet.h:1077
BlockHash last_scanned_block
Hash and height of most recent block that was successfully scanned.
Definition: wallet.h:1076
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:1083
Confirmation includes tx status and a triplet of {block height/block hash/tx index in block} at which...
Definition: wallet.h:403
uint64_t create_flags
Definition: db.h:224
int nFile
Definition: flatfile.h:15
std::unique_ptr< ChainstateManager > chainman
Definition: context.h:42
std::unique_ptr< interfaces::Chain > chain
Definition: context.h:46
Testing setup and teardown for wallet.
Bilingual messages:
Definition: translation.h:17
#define ENTER_CRITICAL_SECTION(cs)
Definition: sync.h:254
#define LEAVE_CRITICAL_SECTION(cs)
Definition: sync.h:260
#define LOCK2(cs1, cs2)
Definition: sync.h:246
#define LOCK(cs)
Definition: sync.h:243
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
Definition: sync.h:276
ArgsManager gArgs
Definition: system.cpp:77
bool error(const char *fmt, const Args &...args)
Definition: system.h:46
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:56
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
Definition: time.cpp:94
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1201
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::unique_ptr< interfaces::Handler > HandleLoadWallet(LoadWalletFn load_wallet)
Definition: wallet.cpp:165
bool RemoveWallet(const std::shared_ptr< CWallet > &wallet, std::optional< bool > load_on_start, std::vector< bilingual_str > &warnings)
Definition: wallet.cpp:119
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:283
void UnloadWallet(std::shared_ptr< CWallet > &&wallet)
Explicitly unload and delete the wallet.
Definition: wallet.cpp:200
std::unique_ptr< WalletDatabase > MakeWalletDatabase(const std::string &name, const DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error_string)
Definition: wallet.cpp:4233
bool AddWallet(const std::shared_ptr< CWallet > &wallet)
Definition: wallet.cpp:105
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
static void PollutePubKey(CPubKey &pubkey)
static size_t CalculateP2PKHInputSize(bool use_max_sig)
static std::shared_ptr< CWallet > TestLoadWallet(interfaces::Chain &chain)
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:49
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 > CreateMockWalletDatabase()
Return object for accessing temporary in-memory database.
Definition: walletdb.cpp:1169
std::unique_ptr< WalletDatabase > CreateDummyWalletDatabase()
Return object for accessing dummy database with no read/write capabilities.
Definition: walletdb.cpp:1164
@ WALLET_FLAG_DISABLE_PRIVATE_KEYS
Definition: walletutil.h:55
@ FEATURE_LATEST
Definition: walletutil.h:36