Bitcoin Core  24.1.0
P2P Digital Currency
walletload_tests.cpp
Go to the documentation of this file.
1 // Copyright (c) 2022 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or https://www.opensource.org/licenses/mit-license.php.
4 
5 #include <wallet/wallet.h>
7 
8 #include <boost/test/unit_test.hpp>
9 
10 namespace wallet {
11 
12 BOOST_AUTO_TEST_SUITE(walletload_tests)
13 
14 class DummyDescriptor final : public Descriptor {
15 private:
16  std::string desc;
17 public:
18  explicit DummyDescriptor(const std::string& descriptor) : desc(descriptor) {};
19  ~DummyDescriptor() = default;
20 
21  std::string ToString() const override { return desc; }
22  std::optional<OutputType> GetOutputType() const override { return OutputType::UNKNOWN; }
23 
24  bool IsRange() const override { return false; }
25  bool IsSolvable() const override { return false; }
26  bool IsSingleType() const override { return true; }
27  bool ToPrivateString(const SigningProvider& provider, std::string& out) const override { return false; }
28  bool ToNormalizedString(const SigningProvider& provider, std::string& out, const DescriptorCache* cache = nullptr) const override { return false; }
29  bool Expand(int pos, const SigningProvider& provider, std::vector<CScript>& output_scripts, FlatSigningProvider& out, DescriptorCache* write_cache = nullptr) const override { return false; };
30  bool ExpandFromCache(int pos, const DescriptorCache& read_cache, std::vector<CScript>& output_scripts, FlatSigningProvider& out) const override { return false; }
31  void ExpandPrivate(int pos, const SigningProvider& provider, FlatSigningProvider& out) const override {}
32 };
33 
34 BOOST_FIXTURE_TEST_CASE(wallet_load_unknown_descriptor, TestingSetup)
35 {
36  std::unique_ptr<WalletDatabase> database = CreateMockWalletDatabase();
37  {
38  // Write unknown active descriptor
39  WalletBatch batch(*database, false);
40  std::string unknown_desc = "trx(tpubD6NzVbkrYhZ4Y4S7m6Y5s9GD8FqEMBy56AGphZXuagajudVZEnYyBahZMgHNCTJc2at82YX6s8JiL1Lohu5A3v1Ur76qguNH4QVQ7qYrBQx/86'/1'/0'/0/*)#8pn8tzdt";
41  WalletDescriptor wallet_descriptor(std::make_shared<DummyDescriptor>(unknown_desc), 0, 0, 0, 0);
42  BOOST_CHECK(batch.WriteDescriptor(uint256(), wallet_descriptor));
43  BOOST_CHECK(batch.WriteActiveScriptPubKeyMan(static_cast<uint8_t>(OutputType::UNKNOWN), uint256(), false));
44  }
45 
46  {
47  // Now try to load the wallet and verify the error.
48  const std::shared_ptr<CWallet> wallet(new CWallet(m_node.chain.get(), "", m_args, std::move(database)));
50  }
51 }
52 
54 } // namespace wallet
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::unique_ptr< interfaces::Chain > chain
Definition: context.h:57
bool ToNormalizedString(const SigningProvider &provider, std::string &out, const DescriptorCache *cache=nullptr) const override
Convert the descriptor to a normalized string.
bool IsSolvable() const override
Whether this descriptor has all information about signing ignoring lack of private keys...
std::string ToString() const override
Convert the descriptor back to a string, undoing parsing.
node::NodeContext m_node
Definition: bitcoin-gui.cpp:37
Access to the wallet database.
Definition: walletdb.h:187
bool WriteDescriptor(const uint256 &desc_id, const WalletDescriptor &descriptor)
Definition: walletdb.cpp:242
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 WriteActiveScriptPubKeyMan(uint8_t type, const uint256 &id, bool internal)
Definition: walletdb.cpp:210
std::unique_ptr< WalletDatabase > CreateMockWalletDatabase(DatabaseOptions &options)
Return object for accessing temporary in-memory database.
Definition: walletdb.cpp:1242
BOOST_FIXTURE_TEST_CASE(BasicOutputTypesTest, AvailableCoinsTestingSetup)
BOOST_AUTO_TEST_SUITE_END()
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
Definition: wallet.h:235
Definition: node.h:39
bool IsSingleType() const override
Whether this descriptor will return one scriptPubKey or multiple (aka is or is not combo) ...
Descriptor with some wallet metadata.
Definition: walletutil.h:76
256-bit opaque blob.
Definition: uint256.h:119
An interface to be implemented by keystores that support signing.
#define BOOST_CHECK_EQUAL(v1, v2)
Definition: object.cpp:17
Cache for single descriptor&#39;s derived extended pubkeys.
Definition: descriptor.h:19
DummyDescriptor(const std::string &descriptor)
bool IsRange() const override
Whether the expansion of this descriptor depends on the position.
bool ToPrivateString(const SigningProvider &provider, std::string &out) const override
Convert the descriptor to a private string.
std::optional< OutputType > GetOutputType() const override
BOOST_AUTO_TEST_SUITE(cuckoocache_tests)
Test Suite for CuckooCache.
std::shared_ptr< CWallet > wallet
void ExpandPrivate(int pos, const SigningProvider &provider, FlatSigningProvider &out) const override
Expand the private key for a descriptor at a specified position, if possible.
Testing setup that configures a complete environment.
Definition: setup_common.h:109
Interface for parsed descriptor objects.
Definition: descriptor.h:98
#define BOOST_CHECK(expr)
Definition: object.cpp:16