diff options
author | Andrew Chow <github@achow101.com> | 2022-12-12 16:57:54 -0500 |
---|---|---|
committer | Andrew Chow <github@achow101.com> | 2023-05-03 10:45:10 -0400 |
commit | b3bb17d5d07f51ac2e501e4a7a3bbcd17144070f (patch) | |
tree | b4c8622e0d38ea2e9d61c0f7359fdd0a3cd15339 /src/wallet/test | |
parent | f0eecf5e408238c64b77b0a4974ba2b9edb17487 (diff) |
tests: Update DuplicateMockDatabase for MockableDatabase
Diffstat (limited to 'src/wallet/test')
-rw-r--r-- | src/wallet/test/util.cpp | 23 | ||||
-rw-r--r-- | src/wallet/test/util.h | 3 | ||||
-rw-r--r-- | src/wallet/test/walletload_tests.cpp | 2 |
3 files changed, 4 insertions, 24 deletions
diff --git a/src/wallet/test/util.cpp b/src/wallet/test/util.cpp index 7b0b3fe033..09e7979c02 100644 --- a/src/wallet/test/util.cpp +++ b/src/wallet/test/util.cpp @@ -45,28 +45,9 @@ std::unique_ptr<CWallet> CreateSyncedWallet(interfaces::Chain& chain, CChain& cc return wallet; } -std::unique_ptr<WalletDatabase> DuplicateMockDatabase(WalletDatabase& database, DatabaseOptions& options) +std::unique_ptr<WalletDatabase> DuplicateMockDatabase(WalletDatabase& database) { - auto new_database = CreateMockableWalletDatabase(); - - // Get a cursor to the original database - auto batch = database.MakeBatch(); - std::unique_ptr<wallet::DatabaseCursor> cursor = batch->GetNewCursor(); - - // Get a batch for the new database - auto new_batch = new_database->MakeBatch(); - - // Read all records from the original database and write them to the new one - while (true) { - DataStream key{}; - DataStream value{}; - DatabaseCursor::Status status = cursor->Next(key, value); - assert(status != DatabaseCursor::Status::FAIL); - if (status == DatabaseCursor::Status::DONE) break; - new_batch->Write(key, value); - } - - return new_database; + return std::make_unique<MockableDatabase>(dynamic_cast<MockableDatabase&>(database).m_records); } std::string getnewaddress(CWallet& w) diff --git a/src/wallet/test/util.h b/src/wallet/test/util.h index 92405107cf..01c2458a6c 100644 --- a/src/wallet/test/util.h +++ b/src/wallet/test/util.h @@ -20,13 +20,12 @@ class Chain; namespace wallet { class CWallet; -struct DatabaseOptions; class WalletDatabase; std::unique_ptr<CWallet> CreateSyncedWallet(interfaces::Chain& chain, CChain& cchain, const CKey& key); // Creates a copy of the provided database -std::unique_ptr<WalletDatabase> DuplicateMockDatabase(WalletDatabase& database, DatabaseOptions& options); +std::unique_ptr<WalletDatabase> DuplicateMockDatabase(WalletDatabase& database); /** Returns a new encoded destination from the wallet (hardcoded to BECH32) */ std::string getnewaddress(CWallet& w); diff --git a/src/wallet/test/walletload_tests.cpp b/src/wallet/test/walletload_tests.cpp index 23934b11dd..082416d035 100644 --- a/src/wallet/test/walletload_tests.cpp +++ b/src/wallet/test/walletload_tests.cpp @@ -100,7 +100,7 @@ BOOST_FIXTURE_TEST_CASE(wallet_load_verif_crypted_key_checksum, TestingSetup) DatabaseOptions options; for (int i=0; i < NUMBER_OF_TESTS; i++) { - dbs.emplace_back(DuplicateMockDatabase(wallet->GetDatabase(), options)); + dbs.emplace_back(DuplicateMockDatabase(wallet->GetDatabase())); } } |