13#include <boost/test/unit_test.hpp>
17BOOST_AUTO_TEST_SUITE(walletload_tests)
26 std::string
ToString(
bool compat_format)
const override {
return desc; }
30 bool IsRange()
const override {
return true; }
39 std::optional<int64_t>
ScriptSize()
const override {
return {}; }
42 void GetPubKeys(std::set<CPubKey>& pubkeys, std::set<CExtPubKey>& ext_pubs)
const override {}
44 std::vector<std::string>
Warnings()
const override {
return {}; }
53 std::vector<bilingual_str> _warnings;
58 std::string unknown_desc =
"trx(tpubD6NzVbkrYhZ4Y4S7m6Y5s9GD8FqEMBy56AGphZXuagajudVZEnYyBahZMgHNCTJc2at82YX6s8JiL1Lohu5A3v1Ur76qguNH4QVQ7qYrBQx/86'/1'/0'/0/*)#8pn8tzdt";
59 WalletDescriptor wallet_descriptor(std::make_shared<DummyDescriptor>(unknown_desc), 0, 0, 0, 0);
77 std::string desc =
"wpkh([d34db33f/84h/0h/0h]xpub6DJ2dNUysrn5Vt36jH2KLBT2i1auw1tTSSomg8PhqNiUtx8QX2SvC9nrHu81fT41fvDUnhMjEzQgXnQjKEu3oaqMSzhSrHMxyyoEAmUHQbY/0/*)#cjjspncu";
78 WalletDescriptor wallet_descriptor(std::make_shared<DummyDescriptor>(desc), 0, 0, 0, 0);
94 std::vector<bilingual_str> warnings;
96 const std::string desc_str =
"wpkh([d34db33f/84h/0h/0h]xpub6DJ2dNUysrn5Vt36jH2KLBT2i1auw1tTSSomg8PhqNiUtx8QX2SvC9nrHu81fT41fvDUnhMjEzQgXnQjKEu3oaqMSzhSrHMxyyoEAmUHQbY/0/*)#cjjspncu";
98 std::string parse_error;
99 std::vector<std::unique_ptr<Descriptor>> descs =
Parse(desc_str,
keys, parse_error,
true);
100 BOOST_REQUIRE_MESSAGE(descs.size() == 1, parse_error);
101 std::shared_ptr<Descriptor> descriptor = std::move(descs.at(0));
104 auto make_db_with_short_cache_xpub = [&](
const std::string& cache_type) {
112 std::unique_ptr<DatabaseBatch> raw = database->MakeBatch();
113 BOOST_CHECK(raw->Write(std::make_pair(std::make_pair(cache_type, desc_id), uint32_t{0}), short_xpub));
118 std::unique_ptr<WalletDatabase> database = make_db_with_short_cache_xpub(
"walletdescriptorcache");
125 std::unique_ptr<WalletDatabase> database = make_db_with_short_cache_xpub(
"walletdescriptorlhcache");
Cache for single descriptor's derived extended pubkeys.
An interface to be implemented by keystores that support signing.
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
bool IsSolvable() const override
Whether this descriptor has all information about signing ignoring lack of private keys.
std::string ToString(bool compat_format) const override
Convert the descriptor back to a string, undoing parsing.
void GetPubKeys(std::set< CPubKey > &pubkeys, std::set< CExtPubKey > &ext_pubs) const override
Return all (extended) public keys for this descriptor, including any from subdescriptors.
bool HavePrivateKeys(const SigningProvider &) const override
Whether the given provider has all private keys required by this descriptor.
bool ToNormalizedString(const SigningProvider &provider, std::string &out, const DescriptorCache *cache=nullptr) const override
Convert the descriptor to a normalized string.
bool CanSelfExpand() const final
Whether the descriptor can be used to produce its address(es) without needing a cache or private keys...
void ExpandPrivate(int pos, const SigningProvider &provider, FlatSigningProvider &out) const override
Expand the private key for a descriptor at a specified position, if possible.
bool ToPrivateString(const SigningProvider &provider, std::string &out) const override
Convert the descriptor to a private string.
bool Expand(int pos, const SigningProvider &provider, std::vector< CScript > &output_scripts, FlatSigningProvider &out, DescriptorCache *write_cache=nullptr) const override
Expand a descriptor at a specified position.
std::string ToCanonicalString() const override
Convert the descriptor to the canonical string.
uint32_t GetMaxKeyExpr() const override
Get the maximum key expression index.
std::optional< int64_t > MaxSatisfactionWeight(bool) const override
Get the maximum size of a satisfaction for this descriptor, in weight units.
~DummyDescriptor()=default
size_t GetKeyCount() const override
Get the number of key expressions in this descriptor.
bool ExpandFromCache(int pos, const DescriptorCache &read_cache, std::vector< CScript > &output_scripts, FlatSigningProvider &out) const override
Expand a descriptor at a specified position using cached expansion data.
bool IsRange() const override
Whether the expansion of this descriptor depends on the position.
std::optional< OutputType > GetOutputType() const override
bool IsSingleType() const override
Whether this descriptor will return at most one scriptPubKey or multiple (aka is or is not combo)
bool HasScripts() const override
Whether this descriptor produces any scripts with the Expand functions.
std::vector< std::string > Warnings() const override
Semantic/safety warnings (includes subdescriptors).
std::optional< int64_t > MaxSatisfactionElems() const override
Get the maximum size number of stack elements for satisfying this descriptor.
std::optional< int64_t > ScriptSize() const override
Get the size of the scriptPubKey for this descriptor.
DummyDescriptor(const std::string &descriptor)
Access to the wallet database.
bool WriteDescriptor(const uint256 &desc_id, const WalletDescriptor &descriptor)
bool WriteActiveScriptPubKeyMan(uint8_t type, const uint256 &id, bool internal)
Descriptor with some wallet metadata.
static UniValue Parse(std::string_view raw, ParamFormat format=ParamFormat::JSON)
Parse string to UniValue or throw runtime_error if string contains invalid JSON.
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL(headers.FindFirst("key"), "value")
std::unique_ptr< WalletDatabase > CreateMockableWalletDatabase()
BOOST_FIXTURE_TEST_CASE(wallet_coinsresult_test, BasicTestingSetup)
#define BOOST_CHECK(expr)
constexpr unsigned int BIP32_EXTKEY_SIZE
uint256 CompatDescriptorHash(const Descriptor &desc)
Hash of the COMPAT string representation of the descriptor that is not supposed to change over time.
Interface for parsed descriptor objects.
Testing setup that configures a complete environment.
std::unique_ptr< interfaces::Chain > chain
std::vector< uint16_t > keys
FuzzedDataProvider provider
#define ASSERT_DEBUG_LOG(message)
std::shared_ptr< CWallet > wallet