10#include <boost/test/unit_test.hpp>
14BOOST_AUTO_TEST_SUITE(walletload_tests)
23 std::string
ToString(
bool compat_format)
const override {
return desc; }
26 bool IsRange()
const override {
return false; }
34 std::optional<int64_t>
ScriptSize()
const override {
return {}; }
37 void GetPubKeys(std::set<CPubKey>& pubkeys, std::set<CExtPubKey>& ext_pubs)
const override {}
46 std::string unknown_desc =
"trx(tpubD6NzVbkrYhZ4Y4S7m6Y5s9GD8FqEMBy56AGphZXuagajudVZEnYyBahZMgHNCTJc2at82YX6s8JiL1Lohu5A3v1Ur76qguNH4QVQ7qYrBQx/86'/1'/0'/0/*)#8pn8tzdt";
47 WalletDescriptor wallet_descriptor(std::make_shared<DummyDescriptor>(unknown_desc), 0, 0, 0, 0);
65 DebugLogHelper logHelper(
"The descriptor ID calculated by the wallet differs from the one in DB", [&](
const std::string*
s) {
73 std::string desc =
"wpkh([d34db33f/84h/0h/0h]xpub6DJ2dNUysrn5Vt36jH2KLBT2i1auw1tTSSomg8PhqNiUtx8QX2SvC9nrHu81fT41fvDUnhMjEzQgXnQjKEu3oaqMSzhSrHMxyyoEAmUHQbY/0/*)#cjjspncu";
74 WalletDescriptor wallet_descriptor(std::make_shared<DummyDescriptor>(desc), 0, 0, 0, 0);
88 std::unique_ptr<DatabaseBatch> batch = db.
MakeBatch(
false);
90 std::unique_ptr<DatabaseCursor> cursor = batch->GetNewCursor();
100 if (type == key)
return true;
105template<
typename... Args>
110 return {
s.begin(),
s.end()};
125 auto legacy_spkm =
wallet->GetOrCreateLegacyScriptPubKeyMan();
132 BOOST_CHECK(legacy_spkm->GetKey(key_id, first_key));
143 ckey_record_value = records.at(ckey_record_key);
171 records[ckey_record_key].resize(ckey_record_value.size() - 32);
192 records[ckey_record_key].resize(ckey_record_value.size() - 32);
194 records[ckey_record_key].resize(ckey_record_value.size());
206 records[key] = ckey_record_value;
std::variant< CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, PayToAnchor, WitnessUnknown > CTxDestination
A txout script categorized into standard templates.
#define Assert(val)
Identity function.
An encapsulated private key.
CPubKey GetPubKey() const
Compute the public key from a private key.
A reference to a CKey: the Hash160 of its serialized public key.
An encapsulated public key.
Double ended buffer combining vector and stream-like interfaces.
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 ToNormalizedString(const SigningProvider &provider, std::string &out, const DescriptorCache *cache=nullptr) const override
Convert the descriptor to a normalized string.
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::optional< int64_t > MaxSatisfactionWeight(bool) const override
Get the maximum size of a satisfaction for this descriptor, in weight units.
~DummyDescriptor()=default
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 one scriptPubKey or multiple (aka is or is not combo)
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)
An instance of this class represents one database.
virtual std::unique_ptr< DatabaseBatch > MakeBatch(bool flush_on_close=true)=0
Make a DatabaseBatch connected to this database.
Descriptor with some wallet metadata.
BOOST_AUTO_TEST_SUITE_END()
const std::string CRYPTED_KEY
BOOST_FIXTURE_TEST_CASE(wallet_coinsresult_test, BasicTestingSetup)
bool HasAnyRecordOfType(WalletDatabase &db, const std::string &key)
MockableDatabase & GetMockableDatabase(CWallet &wallet)
std::unique_ptr< WalletDatabase > CreateMockableWalletDatabase(MockableData records)
std::map< SerializeData, SerializeData, std::less<> > MockableData
SerializeData MakeSerializeData(const Args &... args)
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
void SerializeMany(Stream &s, const Args &... args)
Support for (un)serializing many things at once.
CKeyID GetKeyForDestination(const SigningProvider &store, const CTxDestination &dest)
Return the CKeyID of the key involved in a script (if there is a unique one).
Interface for parsed descriptor objects.
Testing setup that configures a complete environment.
std::unique_ptr< interfaces::Chain > chain
std::vector< std::byte, zero_after_free_allocator< std::byte > > SerializeData
Byte-vector that clears its contents before deletion.