Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Makefile.test.include
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ BITCOIN_TESTS += \
wallet/test/ismine_tests.cpp \
wallet/test/rpc_util_tests.cpp \
wallet/test/scriptpubkeyman_tests.cpp \
wallet/test/walletload_tests.cpp
wallet/test/walletload_tests.cpp \
wallet/test/group_outputs_tests.cpp

FUZZ_SUITE_LD_COMMON +=\
$(SQLITE_LIBS) \
Expand All @@ -256,6 +257,7 @@ endif
FUZZ_WALLET_SRC = \
wallet/test/fuzz/coincontrol.cpp \
wallet/test/fuzz/coinselection.cpp \
wallet/test/fuzz/fees.cpp \
wallet/test/fuzz/parse_iso8601.cpp

if USE_SQLITE
Expand Down
10 changes: 6 additions & 4 deletions src/bench/coin_selection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <wallet/coinselection.h>
#include <wallet/spend.h>
#include <wallet/wallet.h>
#include <wallet/test/util.h>

#include <set>

Expand All @@ -17,7 +18,7 @@ using wallet::CHANGE_LOWER;
using wallet::CoinEligibilityFilter;
using wallet::CoinSelectionParams;
using wallet::COutput;
using wallet::CreateDummyWalletDatabase;
using wallet::CreateMockableWalletDatabase;
using wallet::CWallet;
using wallet::CWalletTx;
using wallet::OutputGroup;
Expand All @@ -44,7 +45,7 @@ static void CoinSelection(benchmark::Bench& bench)
{
NodeContext node;
auto chain = interfaces::MakeChain(node);
CWallet wallet(chain.get(), "", CreateDummyWalletDatabase());
CWallet wallet(chain.get(), "", CreateMockableWalletDatabase());
std::vector<std::unique_ptr<CWalletTx>> wtxs;
LOCK(wallet.cs_wallet);

Expand Down Expand Up @@ -73,8 +74,9 @@ static void CoinSelection(benchmark::Bench& bench)
/*tx_noinputs_size=*/ 0,
/*avoid_partial=*/ false,
};
auto group = wallet::GroupOutputs(wallet, available_coins, coin_selection_params, {{filter_standard}})[filter_standard];
bench.run([&] {
auto result = AttemptSelection(wallet, 1003 * COIN, filter_standard, available_coins, coin_selection_params, /*allow_mixed_output_types=*/true);
auto result = AttemptSelection(wallet, 1003 * COIN, group, coin_selection_params, /*allow_mixed_output_types=*/true);
assert(result);
assert(result->GetSelectedValue() == 1003 * COIN);
assert(result->GetInputSet().size() == 2);
Expand All @@ -89,7 +91,7 @@ static void add_coin(const CAmount& nValue, int nInput, std::vector<OutputGroup>
tx.vout[nInput].nValue = nValue;
COutput output(COutPoint(tx.GetHash(), nInput), tx.vout.at(nInput), /*depth=*/ 0, /*input_bytes=*/ -1, /*spendable=*/ true, /*solvable=*/ true, /*safe=*/ true, /*time=*/ 0, /*from_me=*/ true, /*fees=*/ 0);
set.emplace_back();
set.back().Insert(output, /*ancestors=*/ 0, /*descendants=*/ 0, /*positive_only=*/ false);
set.back().Insert(std::make_shared<COutput>(output), /*ancestors=*/ 0, /*descendants=*/ 0);
}
// Copied from src/wallet/test/coinselector_tests.cpp
static CAmount make_hard_case(int utxos, std::vector<OutputGroup>& utxo_pool)
Expand Down
12 changes: 3 additions & 9 deletions src/bench/wallet_balance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,7 @@

#include <optional>

using wallet::CreateMockWalletDatabase;
using wallet::CWallet;
using wallet::DBErrors;
using wallet::WALLET_FLAG_DESCRIPTORS;

const std::string ADDRESS_B58T_UNSPENDABLE = "yXXXXXXXXXXXXXXXXXXXXXXXXXXXVd2rXU";

namespace wallet {
static void WalletBalance(benchmark::Bench& bench, const bool set_dirty, const bool add_mine, const uint32_t epoch_iters)
{
const auto test_setup = MakeNoLogFileContext<const TestingSetup>();
Expand All @@ -31,12 +25,11 @@ static void WalletBalance(benchmark::Bench& bench, const bool set_dirty, const b
// Set clock to genesis block, so the descriptors/keys creation time don't interfere with the blocks scanning process.
// The reason is 'generatetoaddress', which creates a chain with deterministic timestamps in the past.
SetMockTime(test_setup->m_node.chainman->GetParams().GenesisBlock().nTime);
CWallet wallet{test_setup->m_node.chain.get(), "", CreateMockWalletDatabase()};
CWallet wallet{test_setup->m_node.chain.get(), "", CreateMockableWalletDatabase()};
{
LOCK(wallet.cs_wallet);
wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
wallet.SetupDescriptorScriptPubKeyMans("", "");
if (wallet.LoadWallet() != DBErrors::LOAD_OK) assert(false);
}
auto handler = test_setup->m_node.chain->handleNotifications({&wallet, [](CWallet*) {}});

Expand Down Expand Up @@ -66,3 +59,4 @@ BENCHMARK(WalletBalanceDirty, benchmark::PriorityLevel::HIGH);
BENCHMARK(WalletBalanceClean, benchmark::PriorityLevel::HIGH);
BENCHMARK(WalletBalanceMine, benchmark::PriorityLevel::HIGH);
BENCHMARK(WalletBalanceWatch, benchmark::PriorityLevel::HIGH);
} // namespace wallet
6 changes: 3 additions & 3 deletions src/bench/wallet_create_tx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <wallet/wallet.h>

using wallet::CWallet;
using wallet::CreateMockWalletDatabase;
using wallet::CreateMockableWalletDatabase;
using wallet::DBErrors;
using wallet::WALLET_FLAG_DESCRIPTORS;

Expand Down Expand Up @@ -84,7 +84,7 @@ static void WalletCreateTx(benchmark::Bench& bench, const OutputType output_type
{
const auto test_setup = MakeNoLogFileContext<const TestingSetup>();

CWallet wallet{test_setup->m_node.chain.get(), "", CreateMockWalletDatabase()};
CWallet wallet{test_setup->m_node.chain.get(), "", CreateMockableWalletDatabase()};
{
LOCK(wallet.cs_wallet);
wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
Expand Down Expand Up @@ -137,7 +137,7 @@ static void WalletCreateTx(benchmark::Bench& bench, const OutputType output_type
static void AvailableCoins(benchmark::Bench& bench, const std::vector<OutputType>& output_type)
{
const auto test_setup = MakeNoLogFileContext<const TestingSetup>();
CWallet wallet{test_setup->m_node.chain.get(), "", CreateMockWalletDatabase()};
CWallet wallet{test_setup->m_node.chain.get(), "", CreateMockableWalletDatabase()};
{
LOCK(wallet.cs_wallet);
wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
Expand Down
53 changes: 12 additions & 41 deletions src/bench/wallet_loading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,7 @@

#include <optional>

using wallet::CWallet;
using wallet::DatabaseFormat;
using wallet::DatabaseOptions;
using wallet::TxStateInactive;
using wallet::WALLET_FLAG_DESCRIPTORS;
using wallet::WalletContext;
using wallet::WalletDatabase;

static std::shared_ptr<CWallet> BenchLoadWallet(std::unique_ptr<WalletDatabase> database, WalletContext& context, DatabaseOptions& options)
{
bilingual_str error;
std::vector<bilingual_str> warnings;
auto wallet = CWallet::Create(context, "", std::move(database), options.create_flags, error, warnings);
NotifyWalletLoaded(context, wallet);
if (context.chain) {
wallet->postInitProcess();
}
return wallet;
}

static void BenchUnloadWallet(std::shared_ptr<CWallet>&& wallet)
{
SyncWithValidationInterfaceQueue();
wallet->m_chain_notifications_handler.reset();
UnloadWallet(std::move(wallet));
}

namespace wallet{
static void AddTx(CWallet& wallet)
{
CMutableTransaction mtx;
Expand All @@ -59,40 +33,36 @@ static void AddTx(CWallet& wallet)
static void WalletLoading(benchmark::Bench& bench, bool legacy_wallet)
{
const auto test_setup = MakeNoLogFileContext<TestingSetup>();
test_setup->m_args.ForceSetArg("-unsafesqlitesync", "1");

WalletContext context;
context.args = &test_setup->m_args;
context.chain = test_setup->m_node.chain.get();

// Setup the wallet
// Loading the wallet will also create it
DatabaseOptions options;
if (legacy_wallet) {
options.require_format = DatabaseFormat::BERKELEY;
} else {
options.create_flags = WALLET_FLAG_DESCRIPTORS;
options.require_format = DatabaseFormat::SQLITE;
uint64_t create_flags = 0;
if (!legacy_wallet) {
create_flags = WALLET_FLAG_DESCRIPTORS;
}
auto database = CreateMockWalletDatabase(options);
auto wallet = BenchLoadWallet(std::move(database), context, options);
auto database = CreateMockableWalletDatabase();
auto wallet = TestLoadWallet(std::move(database), context, create_flags);

// Generate a bunch of transactions and addresses to put into the wallet
for (int i = 0; i < 1000; ++i) {
AddTx(*wallet);
}

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

// reload the wallet for the actual benchmark
BenchUnloadWallet(std::move(wallet));
TestUnloadWallet(std::move(wallet));

bench.epochs(5).run([&] {
wallet = BenchLoadWallet(std::move(database), context, options);
wallet = TestLoadWallet(std::move(database), context, create_flags);

// Cleanup
database = DuplicateMockDatabase(wallet->GetDatabase(), options);
BenchUnloadWallet(std::move(wallet));
database = DuplicateMockDatabase(wallet->GetDatabase());
TestUnloadWallet(std::move(wallet));
});
}

Expand All @@ -105,3 +75,4 @@ BENCHMARK(WalletLoadingLegacy, benchmark::PriorityLevel::HIGH);
static void WalletLoadingDescriptors(benchmark::Bench& bench) { WalletLoading(bench, /*legacy_wallet=*/false); }
BENCHMARK(WalletLoadingDescriptors, benchmark::PriorityLevel::HIGH);
#endif
} // namespace wallet
5 changes: 3 additions & 2 deletions src/qt/test/addressbooktests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <key.h>
#include <key_io.h>
#include <wallet/wallet.h>
#include <wallet/test/util.h>
#include <walletinitinterface.h>

#include <chrono>
Expand All @@ -29,7 +30,7 @@
#include <QTimer>

using wallet::AddWallet;
using wallet::CreateMockWalletDatabase;
using wallet::CreateMockableWalletDatabase;
using wallet::CWallet;
using wallet::RemoveWallet;
using wallet::WALLET_FLAG_DESCRIPTORS;
Expand Down Expand Up @@ -72,7 +73,7 @@ void TestAddAddressesToSendBook(interfaces::Node& node)
{
TestChain100Setup test;
node.setContext(&test.m_node);
const std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(node.context()->chain.get(), "", CreateMockWalletDatabase());
const std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(node.context()->chain.get(), "", CreateMockableWalletDatabase());
wallet->LoadWallet();
wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
{
Expand Down
5 changes: 3 additions & 2 deletions src/qt/test/masternodetestutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <util/system.h>
#include <validation.h>
#include <wallet/context.h>
#include <wallet/test/util.h>
#include <wallet/wallet.h>

#include <univalue.h>
Expand All @@ -29,7 +30,7 @@

using wallet::AddWallet;
using wallet::CWallet;
using wallet::CreateMockWalletDatabase;
using wallet::CreateMockableWalletDatabase;
using wallet::RemoveWallet;
using wallet::WALLET_FLAG_DESCRIPTORS;
using wallet::WalletContext;
Expand Down Expand Up @@ -74,7 +75,7 @@ struct WalletOptions {
std::shared_ptr<CWallet> MakeWallet(interfaces::Node& node, WalletContext& context, const std::string& name,
const WalletOptions& options)
{
auto wallet{std::make_shared<CWallet>(node.context()->chain.get(), name, CreateMockWalletDatabase())};
auto wallet{std::make_shared<CWallet>(node.context()->chain.get(), name, CreateMockableWalletDatabase())};
wallet->LoadWallet();
wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
const CBlockIndex* const tip{options.setup == nullptr
Expand Down
23 changes: 12 additions & 11 deletions src/qt/test/masternodewidgettests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <util/system.h>
#include <util/translation.h>
#include <validation.h>
#include <wallet/test/util.h>
#include <wallet/wallet.h>

#include <QAbstractButton>
Expand Down Expand Up @@ -67,7 +68,7 @@
#include <utility>
#include <vector>

using wallet::CreateMockWalletDatabase;
using wallet::CreateMockableWalletDatabase;
using wallet::CWallet;
using wallet::WalletContext;

Expand Down Expand Up @@ -407,7 +408,7 @@ void MasternodeWidgetTests::operationRunnerThreading()
TestChain100Setup test;
m_node.setContext(&test.m_node);
WalletContext& context{*m_node.walletLoader().context()};
const auto wallet{std::make_shared<CWallet>(m_node.context()->chain.get(), "", CreateMockWalletDatabase())};
const auto wallet{std::make_shared<CWallet>(m_node.context()->chain.get(), "", CreateMockableWalletDatabase())};
wallet->LoadWallet();
auto wallet_interface{interfaces::MakeWallet(context, wallet)};
QVERIFY(wallet_interface != nullptr);
Expand Down Expand Up @@ -455,7 +456,7 @@ void MasternodeWidgetTests::operationRunnerExceptions()
TestChain100Setup test;
m_node.setContext(&test.m_node);
WalletContext& context{*m_node.walletLoader().context()};
const auto wallet{std::make_shared<CWallet>(m_node.context()->chain.get(), "", CreateMockWalletDatabase())};
const auto wallet{std::make_shared<CWallet>(m_node.context()->chain.get(), "", CreateMockableWalletDatabase())};
wallet->LoadWallet();
auto wallet_interface{interfaces::MakeWallet(context, wallet)};
QVERIFY(wallet_interface != nullptr);
Expand Down Expand Up @@ -492,7 +493,7 @@ void MasternodeWidgetTests::operationRunnerShutdownDelivery()
TestChain100Setup test;
m_node.setContext(&test.m_node);
WalletContext& context{*m_node.walletLoader().context()};
const auto wallet{std::make_shared<CWallet>(m_node.context()->chain.get(), "", CreateMockWalletDatabase())};
const auto wallet{std::make_shared<CWallet>(m_node.context()->chain.get(), "", CreateMockableWalletDatabase())};
wallet->LoadWallet();
auto wallet_interface{interfaces::MakeWallet(context, wallet)};
QVERIFY(wallet_interface != nullptr);
Expand Down Expand Up @@ -548,7 +549,7 @@ void MasternodeWidgetTests::feeSourcePickerEligibility()
TestChain100Setup test;
m_node.setContext(&test.m_node);
WalletContext& context{*m_node.walletLoader().context()};
const auto wallet{std::make_shared<CWallet>(m_node.context()->chain.get(), "", CreateMockWalletDatabase())};
const auto wallet{std::make_shared<CWallet>(m_node.context()->chain.get(), "", CreateMockableWalletDatabase())};
wallet->LoadWallet();
wallet->SetWalletFlag(wallet::WALLET_FLAG_DESCRIPTORS);

Expand Down Expand Up @@ -613,7 +614,7 @@ void MasternodeWidgetTests::registeredCollateralExclusion()
TestChain100Setup test;
m_node.setContext(&test.m_node);
WalletContext& context{*m_node.walletLoader().context()};
const auto wallet{std::make_shared<CWallet>(m_node.context()->chain.get(), "", CreateMockWalletDatabase())};
const auto wallet{std::make_shared<CWallet>(m_node.context()->chain.get(), "", CreateMockableWalletDatabase())};
wallet->LoadWallet();
wallet->SetWalletFlag(wallet::WALLET_FLAG_DESCRIPTORS);

Expand Down Expand Up @@ -916,7 +917,7 @@ void MasternodeWidgetTests::masternodeListRegistrationAvailability()
TestChain100Setup test;
m_node.setContext(&test.m_node);
WalletContext& context{*m_node.walletLoader().context()};
const auto wallet{std::make_shared<CWallet>(m_node.context()->chain.get(), "", CreateMockWalletDatabase())};
const auto wallet{std::make_shared<CWallet>(m_node.context()->chain.get(), "", CreateMockableWalletDatabase())};
wallet->LoadWallet();
MasternodeTestUtil::GuiModels models{m_node};
QVERIFY2(models.ok, qPrintable(QString::fromStdString(models.error.translated)));
Expand Down Expand Up @@ -999,7 +1000,7 @@ void MasternodeWidgetTests::sharedMasternodeOwnedFilter()
TestChain100Setup test;
m_node.setContext(&test.m_node);
WalletContext& context{*m_node.walletLoader().context()};
const auto wallet{std::make_shared<CWallet>(m_node.context()->chain.get(), "", CreateMockWalletDatabase())};
const auto wallet{std::make_shared<CWallet>(m_node.context()->chain.get(), "", CreateMockableWalletDatabase())};
wallet->LoadWallet();
wallet->SetWalletFlag(wallet::WALLET_FLAG_DESCRIPTORS);

Expand Down Expand Up @@ -1036,7 +1037,7 @@ void MasternodeWidgetTests::sharedMasternodeContextMenu()
TestChain100Setup test;
m_node.setContext(&test.m_node);
WalletContext& context{*m_node.walletLoader().context()};
const auto wallet{std::make_shared<CWallet>(m_node.context()->chain.get(), "", CreateMockWalletDatabase())};
const auto wallet{std::make_shared<CWallet>(m_node.context()->chain.get(), "", CreateMockableWalletDatabase())};
wallet->LoadWallet();
wallet->SetWalletFlag(wallet::WALLET_FLAG_DESCRIPTORS);

Expand Down Expand Up @@ -1220,7 +1221,7 @@ void MasternodeWidgetTests::wizardInteractionLifecycle()
TestChain100Setup test;
m_node.setContext(&test.m_node);
WalletContext& context{*m_node.walletLoader().context()};
const auto wallet{std::make_shared<CWallet>(m_node.context()->chain.get(), "", CreateMockWalletDatabase())};
const auto wallet{std::make_shared<CWallet>(m_node.context()->chain.get(), "", CreateMockableWalletDatabase())};
wallet->LoadWallet();
MasternodeTestUtil::GuiModels models{m_node};
QVERIFY2(models.ok, qPrintable(QString::fromStdString(models.error.translated)));
Expand Down Expand Up @@ -1303,7 +1304,7 @@ void MasternodeWidgetTests::registrationResultStates()
TestChain100Setup test;
m_node.setContext(&test.m_node);
WalletContext& context{*m_node.walletLoader().context()};
const auto wallet{std::make_shared<CWallet>(m_node.context()->chain.get(), "", CreateMockWalletDatabase())};
const auto wallet{std::make_shared<CWallet>(m_node.context()->chain.get(), "", CreateMockableWalletDatabase())};
wallet->LoadWallet();
MasternodeTestUtil::GuiModels models{m_node};
QVERIFY2(models.ok, qPrintable(QString::fromStdString(models.error.translated)));
Expand Down
Loading
Loading