mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-09 10:43:19 -05:00
tests: Update DuplicateMockDatabase for MockableDatabase
This commit is contained in:
parent
f0eecf5e40
commit
b3bb17d5d0
4 changed files with 6 additions and 26 deletions
|
@ -79,7 +79,7 @@ static void WalletLoading(benchmark::Bench& bench, bool legacy_wallet)
|
||||||
AddTx(*wallet);
|
AddTx(*wallet);
|
||||||
}
|
}
|
||||||
|
|
||||||
database = DuplicateMockDatabase(wallet->GetDatabase(), options);
|
database = DuplicateMockDatabase(wallet->GetDatabase());
|
||||||
|
|
||||||
// reload the wallet for the actual benchmark
|
// reload the wallet for the actual benchmark
|
||||||
BenchUnloadWallet(std::move(wallet));
|
BenchUnloadWallet(std::move(wallet));
|
||||||
|
@ -88,7 +88,7 @@ static void WalletLoading(benchmark::Bench& bench, bool legacy_wallet)
|
||||||
wallet = BenchLoadWallet(std::move(database), context, options);
|
wallet = BenchLoadWallet(std::move(database), context, options);
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
database = DuplicateMockDatabase(wallet->GetDatabase(), options);
|
database = DuplicateMockDatabase(wallet->GetDatabase());
|
||||||
BenchUnloadWallet(std::move(wallet));
|
BenchUnloadWallet(std::move(wallet));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,28 +45,9 @@ std::unique_ptr<CWallet> CreateSyncedWallet(interfaces::Chain& chain, CChain& cc
|
||||||
return wallet;
|
return wallet;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<WalletDatabase> DuplicateMockDatabase(WalletDatabase& database, DatabaseOptions& options)
|
std::unique_ptr<WalletDatabase> DuplicateMockDatabase(WalletDatabase& database)
|
||||||
{
|
{
|
||||||
auto new_database = CreateMockableWalletDatabase();
|
return std::make_unique<MockableDatabase>(dynamic_cast<MockableDatabase&>(database).m_records);
|
||||||
|
|
||||||
// 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string getnewaddress(CWallet& w)
|
std::string getnewaddress(CWallet& w)
|
||||||
|
|
|
@ -20,13 +20,12 @@ class Chain;
|
||||||
|
|
||||||
namespace wallet {
|
namespace wallet {
|
||||||
class CWallet;
|
class CWallet;
|
||||||
struct DatabaseOptions;
|
|
||||||
class WalletDatabase;
|
class WalletDatabase;
|
||||||
|
|
||||||
std::unique_ptr<CWallet> CreateSyncedWallet(interfaces::Chain& chain, CChain& cchain, const CKey& key);
|
std::unique_ptr<CWallet> CreateSyncedWallet(interfaces::Chain& chain, CChain& cchain, const CKey& key);
|
||||||
|
|
||||||
// Creates a copy of the provided database
|
// 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) */
|
/** Returns a new encoded destination from the wallet (hardcoded to BECH32) */
|
||||||
std::string getnewaddress(CWallet& w);
|
std::string getnewaddress(CWallet& w);
|
||||||
|
|
|
@ -100,7 +100,7 @@ BOOST_FIXTURE_TEST_CASE(wallet_load_verif_crypted_key_checksum, TestingSetup)
|
||||||
|
|
||||||
DatabaseOptions options;
|
DatabaseOptions options;
|
||||||
for (int i=0; i < NUMBER_OF_TESTS; i++) {
|
for (int i=0; i < NUMBER_OF_TESTS; i++) {
|
||||||
dbs.emplace_back(DuplicateMockDatabase(wallet->GetDatabase(), options));
|
dbs.emplace_back(DuplicateMockDatabase(wallet->GetDatabase()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue