Skip to content

Commit b3bb17d

Browse files
committed
tests: Update DuplicateMockDatabase for MockableDatabase
1 parent f0eecf5 commit b3bb17d

File tree

4 files changed

+6
-26
lines changed

4 files changed

+6
-26
lines changed

src/bench/wallet_loading.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ static void WalletLoading(benchmark::Bench& bench, bool legacy_wallet)
7979
AddTx(*wallet);
8080
}
8181

82-
database = DuplicateMockDatabase(wallet->GetDatabase(), options);
82+
database = DuplicateMockDatabase(wallet->GetDatabase());
8383

8484
// reload the wallet for the actual benchmark
8585
BenchUnloadWallet(std::move(wallet));
@@ -88,7 +88,7 @@ static void WalletLoading(benchmark::Bench& bench, bool legacy_wallet)
8888
wallet = BenchLoadWallet(std::move(database), context, options);
8989

9090
// Cleanup
91-
database = DuplicateMockDatabase(wallet->GetDatabase(), options);
91+
database = DuplicateMockDatabase(wallet->GetDatabase());
9292
BenchUnloadWallet(std::move(wallet));
9393
});
9494
}

src/wallet/test/util.cpp

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,28 +45,9 @@ std::unique_ptr<CWallet> CreateSyncedWallet(interfaces::Chain& chain, CChain& cc
4545
return wallet;
4646
}
4747

48-
std::unique_ptr<WalletDatabase> DuplicateMockDatabase(WalletDatabase& database, DatabaseOptions& options)
48+
std::unique_ptr<WalletDatabase> DuplicateMockDatabase(WalletDatabase& database)
4949
{
50-
auto new_database = CreateMockableWalletDatabase();
51-
52-
// Get a cursor to the original database
53-
auto batch = database.MakeBatch();
54-
std::unique_ptr<wallet::DatabaseCursor> cursor = batch->GetNewCursor();
55-
56-
// Get a batch for the new database
57-
auto new_batch = new_database->MakeBatch();
58-
59-
// Read all records from the original database and write them to the new one
60-
while (true) {
61-
DataStream key{};
62-
DataStream value{};
63-
DatabaseCursor::Status status = cursor->Next(key, value);
64-
assert(status != DatabaseCursor::Status::FAIL);
65-
if (status == DatabaseCursor::Status::DONE) break;
66-
new_batch->Write(key, value);
67-
}
68-
69-
return new_database;
50+
return std::make_unique<MockableDatabase>(dynamic_cast<MockableDatabase&>(database).m_records);
7051
}
7152

7253
std::string getnewaddress(CWallet& w)

src/wallet/test/util.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@ class Chain;
2020

2121
namespace wallet {
2222
class CWallet;
23-
struct DatabaseOptions;
2423
class WalletDatabase;
2524

2625
std::unique_ptr<CWallet> CreateSyncedWallet(interfaces::Chain& chain, CChain& cchain, const CKey& key);
2726

2827
// Creates a copy of the provided database
29-
std::unique_ptr<WalletDatabase> DuplicateMockDatabase(WalletDatabase& database, DatabaseOptions& options);
28+
std::unique_ptr<WalletDatabase> DuplicateMockDatabase(WalletDatabase& database);
3029

3130
/** Returns a new encoded destination from the wallet (hardcoded to BECH32) */
3231
std::string getnewaddress(CWallet& w);

src/wallet/test/walletload_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ BOOST_FIXTURE_TEST_CASE(wallet_load_verif_crypted_key_checksum, TestingSetup)
100100

101101
DatabaseOptions options;
102102
for (int i=0; i < NUMBER_OF_TESTS; i++) {
103-
dbs.emplace_back(DuplicateMockDatabase(wallet->GetDatabase(), options));
103+
dbs.emplace_back(DuplicateMockDatabase(wallet->GetDatabase()));
104104
}
105105
}
106106

0 commit comments

Comments
 (0)