diff options
author | furszy <matiasfurszyfer@protonmail.com> | 2023-05-02 12:19:33 -0300 |
---|---|---|
committer | furszy <matiasfurszyfer@protonmail.com> | 2023-05-15 12:29:38 -0300 |
commit | 69d43905b7f1d4849dfaea1b5744ee473ccc8744 (patch) | |
tree | 18ad5a1400c1527737ec438f8317a32db3eeee9b /src/wallet/test/walletdb_tests.cpp | |
parent | 12daf6fcdcbf5c7f03038338d843df3877714b24 (diff) | |
download | bitcoin-69d43905b7f1d4849dfaea1b5744ee473ccc8744.tar.xz |
test: add coverage for wallet read write db deadlock
Diffstat (limited to 'src/wallet/test/walletdb_tests.cpp')
-rw-r--r-- | src/wallet/test/walletdb_tests.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/wallet/test/walletdb_tests.cpp b/src/wallet/test/walletdb_tests.cpp index 21842fe780..00b2f47e14 100644 --- a/src/wallet/test/walletdb_tests.cpp +++ b/src/wallet/test/walletdb_tests.cpp @@ -6,6 +6,8 @@ #include <clientversion.h> #include <streams.h> #include <uint256.h> +#include <wallet/test/util.h> +#include <wallet/wallet.h> #include <boost/test/unit_test.hpp> @@ -27,5 +29,31 @@ BOOST_AUTO_TEST_CASE(walletdb_readkeyvalue) BOOST_CHECK_THROW(ssValue >> dummy, std::ios_base::failure); } +BOOST_AUTO_TEST_CASE(walletdb_read_write_deadlock) +{ + // Exercises a db read write operation that shouldn't deadlock. + for (const DatabaseFormat& db_format : DATABASE_FORMATS) { + // Context setup + DatabaseOptions options; + options.require_format = db_format; + DatabaseStatus status; + bilingual_str error_string; + std::unique_ptr<WalletDatabase> db = MakeDatabase(m_path_root / strprintf("wallet_%d_.dat", db_format).c_str(), options, status, error_string); + BOOST_ASSERT(status == DatabaseStatus::SUCCESS); + + std::shared_ptr<CWallet> wallet(new CWallet(m_node.chain.get(), "", std::move(db))); + wallet->m_keypool_size = 4; + + // Create legacy spkm + LOCK(wallet->cs_wallet); + auto legacy_spkm = wallet->GetOrCreateLegacyScriptPubKeyMan(); + BOOST_CHECK(legacy_spkm->SetupGeneration(true)); + wallet->Flush(); + + // Now delete all records, which performs a read write operation. + BOOST_CHECK(wallet->GetLegacyScriptPubKeyMan()->DeleteRecords()); + } +} + BOOST_AUTO_TEST_SUITE_END() } // namespace wallet |