From a78c2298080f173d0266e708267458a72eb2f600 Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Fri, 22 Oct 2021 16:26:18 -0400 Subject: [PATCH 1/2] tests: Place into mapWallet in coinselector_tests Instead of using AddToWallet so that making a COutput will work, directly add the transaction into wallet.mapWallet. This bypasses many checks that AddToWallet will do which are pointless and just slow down this test. --- src/wallet/test/coinselector_tests.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/wallet/test/coinselector_tests.cpp b/src/wallet/test/coinselector_tests.cpp index e880e138458..8606924bb30 100644 --- a/src/wallet/test/coinselector_tests.cpp +++ b/src/wallet/test/coinselector_tests.cpp @@ -71,13 +71,18 @@ static void add_coin(std::vector& coins, CWallet& wallet, const CAmount // so stop vin being empty, and cache a non-zero Debit to fake out IsFromMe() tx.vin.resize(1); } - CWalletTx* wtx = wallet.AddToWallet(MakeTransactionRef(std::move(tx)), /* confirm= */ {}); + uint256 txid = tx.GetHash(); + + LOCK(wallet.cs_wallet); + auto ret = wallet.mapWallet.emplace(std::piecewise_construct, std::forward_as_tuple(txid), std::forward_as_tuple(MakeTransactionRef(std::move(tx)))); + assert(ret.second); + CWalletTx& wtx = (*ret.first).second; if (fIsFromMe) { - wtx->m_amounts[CWalletTx::DEBIT].Set(ISMINE_SPENDABLE, 1); - wtx->m_is_cache_empty = false; + wtx.m_amounts[CWalletTx::DEBIT].Set(ISMINE_SPENDABLE, 1); + wtx.m_is_cache_empty = false; } - COutput output(wallet, *wtx, nInput, nAge, true /* spendable */, true /* solvable */, true /* safe */); + COutput output(wallet, wtx, nInput, nAge, true /* spendable */, true /* solvable */, true /* safe */); coins.push_back(output); } From a52f1d13409e4ef46277596ec13fa8b421fa1329 Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Fri, 22 Oct 2021 17:33:24 -0400 Subject: [PATCH 2/2] walletdb: Use SQLiteDatabase for mock wallet databases Default to SQLiteDatabase instead of BerkeleyDatabase for CreateDummyWalletDatabase. Most tests already use descriptor wallets and the mock db doesn't really matter for tests. The tests where it does matter will make the db directly. --- src/wallet/walletdb.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index a6839f1f784..c920d4af51e 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -1188,9 +1188,9 @@ std::unique_ptr CreateDummyWalletDatabase() /** Return object for accessing temporary in-memory database. */ std::unique_ptr CreateMockWalletDatabase() { -#ifdef USE_BDB - return std::make_unique(std::make_shared(), ""); -#elif USE_SQLITE +#ifdef USE_SQLITE return std::make_unique("", "", true); +#elif USE_BDB + return std::make_unique(std::make_shared(), ""); #endif }