mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-26 03:03:22 -03:00
refactor: Use util::Result class in wallet/test
This commit is contained in:
parent
3d657ccd02
commit
ab0476db30
6 changed files with 18 additions and 34 deletions
|
@ -41,19 +41,14 @@ static void WalletCreate(benchmark::Bench& bench, bool encrypted)
|
|||
options.create_passphrase = random.rand256().ToString();
|
||||
}
|
||||
|
||||
DatabaseStatus status;
|
||||
bilingual_str error_string;
|
||||
std::vector<bilingual_str> warnings;
|
||||
|
||||
auto wallet_path = fs::PathToString(test_setup->m_path_root / "test_wallet");
|
||||
bench.run([&] {
|
||||
auto wallet{ResultExtract(CreateWallet(context, wallet_path, /*load_on_start=*/std::nullopt, options), &status, &error_string, &warnings)};
|
||||
assert(status == DatabaseStatus::SUCCESS);
|
||||
assert(wallet != nullptr);
|
||||
auto wallet{CreateWallet(context, wallet_path, /*load_on_start=*/std::nullopt, options)};
|
||||
assert(wallet);
|
||||
|
||||
// Release wallet
|
||||
RemoveWallet(context, wallet, /*load_on_start=*/ std::nullopt);
|
||||
WaitForDeleteWallet(std::move(wallet));
|
||||
RemoveWallet(context, wallet.value(), /*load_on_start=*/ std::nullopt);
|
||||
WaitForDeleteWallet(std::move(wallet.value()));
|
||||
fs::remove_all(wallet_path);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -345,7 +345,7 @@ BOOST_AUTO_TEST_CASE(concurrent_txn_dont_interfere)
|
|||
std::string value2 = "value_2";
|
||||
|
||||
DatabaseOptions options;
|
||||
auto database = MakeSQLiteDatabase(m_path_root / "sqlite", options);
|
||||
const auto& database = MakeSQLiteDatabase(m_path_root / "sqlite", options);
|
||||
|
||||
std::unique_ptr<DatabaseBatch> handler = Assert(database)->MakeBatch();
|
||||
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
#endif
|
||||
|
||||
using wallet::DatabaseOptions;
|
||||
using wallet::DatabaseStatus;
|
||||
|
||||
namespace {
|
||||
TestingSetup* g_setup;
|
||||
|
@ -48,9 +47,6 @@ FUZZ_TARGET(wallet_bdb_parser, .init = initialize_wallet_bdb_parser)
|
|||
}
|
||||
|
||||
const DatabaseOptions options{};
|
||||
DatabaseStatus status;
|
||||
bilingual_str error;
|
||||
|
||||
fs::path bdb_ro_dumpfile{g_setup->m_args.GetDataDirNet() / "fuzzed_dumpfile_bdb_ro.dump"};
|
||||
if (fs::exists(bdb_ro_dumpfile)) { // Writing into an existing dump file will throw an exception
|
||||
remove(bdb_ro_dumpfile);
|
||||
|
@ -61,13 +57,14 @@ FUZZ_TARGET(wallet_bdb_parser, .init = initialize_wallet_bdb_parser)
|
|||
bool bdb_ro_err = false;
|
||||
bool bdb_ro_strict_err = false;
|
||||
#endif
|
||||
auto db{ResultExtract(MakeBerkeleyRODatabase(wallet_path, options), &status, &error)};
|
||||
auto db{MakeBerkeleyRODatabase(wallet_path, options)};
|
||||
if (db) {
|
||||
assert(DumpWallet(g_setup->m_args, *db));
|
||||
} else {
|
||||
#ifdef USE_BDB_NON_MSVC
|
||||
bdb_ro_err = true;
|
||||
#endif
|
||||
bilingual_str error{util::ErrorString(db)};
|
||||
if (error.original.starts_with("AutoFile::ignore: end of file") ||
|
||||
error.original.starts_with("AutoFile::read: end of file") ||
|
||||
error.original.starts_with("AutoFile::seek: ") ||
|
||||
|
@ -114,7 +111,7 @@ FUZZ_TARGET(wallet_bdb_parser, .init = initialize_wallet_bdb_parser)
|
|||
g_setup->m_args.ForceSetArg("-dumpfile", fs::PathToString(bdb_dumpfile));
|
||||
|
||||
try {
|
||||
auto db{ResultExtract(MakeBerkeleyDatabase(wallet_path, options), &status, &error)};
|
||||
auto db{MakeBerkeleyDatabase(wallet_path, options)};
|
||||
if (bdb_ro_err && !db) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -49,25 +49,21 @@ std::unique_ptr<CWallet> CreateSyncedWallet(interfaces::Chain& chain, CChain& cc
|
|||
|
||||
std::shared_ptr<CWallet> TestLoadWallet(std::unique_ptr<WalletDatabase> database, WalletContext& context, uint64_t create_flags)
|
||||
{
|
||||
bilingual_str error;
|
||||
std::vector<bilingual_str> warnings;
|
||||
auto wallet{ResultExtract(CWallet::Create(context, "", std::move(database), create_flags), nullptr, &error, &warnings)};
|
||||
NotifyWalletLoaded(context, wallet);
|
||||
auto wallet{CWallet::Create(context, "", std::move(database), create_flags)};
|
||||
NotifyWalletLoaded(context, wallet.value());
|
||||
if (context.chain) {
|
||||
wallet->postInitProcess();
|
||||
}
|
||||
return wallet;
|
||||
return wallet.value();
|
||||
}
|
||||
|
||||
std::shared_ptr<CWallet> TestLoadWallet(WalletContext& context)
|
||||
{
|
||||
DatabaseOptions options;
|
||||
options.create_flags = WALLET_FLAG_DESCRIPTORS;
|
||||
DatabaseStatus status;
|
||||
bilingual_str error;
|
||||
std::vector<bilingual_str> warnings;
|
||||
auto database{ResultExtract(MakeWalletDatabase("", options), &status, &error)};
|
||||
return TestLoadWallet(std::move(database), context, options.create_flags);
|
||||
auto database{MakeWalletDatabase("", options)};
|
||||
return TestLoadWallet(std::move(database.value()), context, options.create_flags);
|
||||
}
|
||||
|
||||
void TestUnloadWallet(std::shared_ptr<CWallet>&& wallet)
|
||||
|
|
|
@ -449,11 +449,8 @@ void TestLoadWallet(const std::string& name, DatabaseFormat format, std::functio
|
|||
auto chain{interfaces::MakeChain(node)};
|
||||
DatabaseOptions options;
|
||||
options.require_format = format;
|
||||
DatabaseStatus status;
|
||||
bilingual_str error;
|
||||
std::vector<bilingual_str> warnings;
|
||||
auto database{ResultExtract(MakeWalletDatabase(name, options), &status, &error)};
|
||||
auto wallet{std::make_shared<CWallet>(chain.get(), "", std::move(database))};
|
||||
auto database{MakeWalletDatabase(name, options)};
|
||||
auto wallet{std::make_shared<CWallet>(chain.get(), "", std::move(database.value()))};
|
||||
BOOST_CHECK_EQUAL(wallet->LoadWallet(), DBErrors::LOAD_OK);
|
||||
WITH_LOCK(wallet->cs_wallet, f(wallet));
|
||||
}
|
||||
|
|
|
@ -36,12 +36,11 @@ BOOST_AUTO_TEST_CASE(walletdb_read_write_deadlock)
|
|||
// Context setup
|
||||
DatabaseOptions options;
|
||||
options.require_format = db_format;
|
||||
DatabaseStatus status;
|
||||
bilingual_str error_string;
|
||||
std::unique_ptr<WalletDatabase> db = ResultExtract(MakeDatabase(m_path_root / strprintf("wallet_%d_.dat", db_format).c_str(), options), &status, &error_string);
|
||||
BOOST_CHECK_EQUAL(status, DatabaseStatus::SUCCESS);
|
||||
auto db = MakeDatabase(m_path_root / strprintf("wallet_%d_.dat", db_format).c_str(), options);
|
||||
BOOST_CHECK(db);
|
||||
|
||||
std::shared_ptr<CWallet> wallet(new CWallet(m_node.chain.get(), "", std::move(db)));
|
||||
std::shared_ptr<CWallet> wallet(new CWallet(m_node.chain.get(), "", std::move(db.value())));
|
||||
wallet->m_keypool_size = 4;
|
||||
|
||||
// Create legacy spkm
|
||||
|
|
Loading…
Add table
Reference in a new issue