Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
test: refactor: move CreateDescriptor helper to wallet test util mo…
…dule

Can be reviewed via `--color-moved=dimmed-zebra`.
  • Loading branch information
theStack authored and achow101 committed Jan 3, 2025
commit 62a95f5af9b998e241eb72c16ba581e77c480126
20 changes: 0 additions & 20 deletions src/wallet/test/ismine_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,6 @@ using namespace util::hex_literals;
namespace wallet {
BOOST_FIXTURE_TEST_SUITE(ismine_tests, BasicTestingSetup)

wallet::ScriptPubKeyMan* CreateDescriptor(CWallet& keystore, const std::string& desc_str, const bool success)
{
keystore.SetWalletFlag(WALLET_FLAG_DESCRIPTORS);

FlatSigningProvider keys;
std::string error;
auto parsed_descs = Parse(desc_str, keys, error, false);
BOOST_CHECK(success == (!parsed_descs.empty()));
if (!success) return nullptr;
auto& desc = parsed_descs.at(0);

const int64_t range_start = 0, range_end = 1, next_index = 0, timestamp = 1;

WalletDescriptor w_desc(std::move(desc), timestamp, range_start, range_end, next_index);

LOCK(keystore.cs_wallet);

return Assert(keystore.AddWalletDescriptor(w_desc, keys,/*label=*/"", /*internal=*/false));
};

BOOST_AUTO_TEST_CASE(ismine_standard)
{
CKey keys[2];
Expand Down
20 changes: 20 additions & 0 deletions src/wallet/test/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,24 @@ MockableDatabase& GetMockableDatabase(CWallet& wallet)
{
return dynamic_cast<MockableDatabase&>(wallet.GetDatabase());
}

wallet::ScriptPubKeyMan* CreateDescriptor(CWallet& keystore, const std::string& desc_str, const bool success)
{
keystore.SetWalletFlag(WALLET_FLAG_DESCRIPTORS);

FlatSigningProvider keys;
std::string error;
auto parsed_descs = Parse(desc_str, keys, error, false);
Assert(success == (!parsed_descs.empty()));
if (!success) return nullptr;
auto& desc = parsed_descs.at(0);

const int64_t range_start = 0, range_end = 1, next_index = 0, timestamp = 1;

WalletDescriptor w_desc(std::move(desc), timestamp, range_start, range_end, next_index);

LOCK(keystore.cs_wallet);

return Assert(keystore.AddWalletDescriptor(w_desc, keys,/*label=*/"", /*internal=*/false));
};
} // namespace wallet
4 changes: 3 additions & 1 deletion src/wallet/test/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <addresstype.h>
#include <wallet/db.h>
#include <wallet/scriptpubkeyman.h>

#include <memory>

Expand Down Expand Up @@ -127,8 +128,9 @@ class MockableDatabase : public WalletDatabase
};

std::unique_ptr<WalletDatabase> CreateMockableWalletDatabase(MockableData records = {});

MockableDatabase& GetMockableDatabase(CWallet& wallet);

ScriptPubKeyMan* CreateDescriptor(CWallet& keystore, const std::string& desc_str, const bool success);
} // namespace wallet

#endif // BITCOIN_WALLET_TEST_UTIL_H