Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wallet: coverage for unknown descriptor load
Previously, this was crashing the wallet. Note: added the test in a separate file intentionally. Will continue adding further coverage for the wallet load process in follow-up commits.
- Loading branch information
Showing
2 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) 2022 The Bitcoin Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or https://www.opensource.org/licenses/mit-license.php. | ||
|
||
#include <wallet/wallet.h> | ||
#include <test/util/setup_common.h> | ||
|
||
#include <boost/test/unit_test.hpp> | ||
|
||
namespace wallet { | ||
|
||
BOOST_AUTO_TEST_SUITE(walletload_tests) | ||
|
||
class UnknownDescriptor final : public Descriptor { | ||
|
||
public: | ||
explicit UnknownDescriptor() {}; | ||
~UnknownDescriptor() = default; | ||
|
||
std::string ToString() const override { return "trx(not_a_random_key)"; } | ||
std::optional<OutputType> GetOutputType() const override { return OutputType::UNKNOWN; } | ||
|
||
bool IsRange() const override { return false; } | ||
bool IsSolvable() const override { return false; } | ||
bool IsSingleType() const override { return true; } | ||
bool ToPrivateString(const SigningProvider& provider, std::string& out) const override { return false; } | ||
bool ToNormalizedString(const SigningProvider& provider, std::string& out, const DescriptorCache* cache = nullptr) const override { return false; } | ||
bool Expand(int pos, const SigningProvider& provider, std::vector<CScript>& output_scripts, FlatSigningProvider& out, DescriptorCache* write_cache = nullptr) const override { return false; }; | ||
bool ExpandFromCache(int pos, const DescriptorCache& read_cache, std::vector<CScript>& output_scripts, FlatSigningProvider& out) const override { return false; } | ||
void ExpandPrivate(int pos, const SigningProvider& provider, FlatSigningProvider& out) const override {} | ||
}; | ||
|
||
BOOST_FIXTURE_TEST_CASE(wallet_load_unknown_descriptor, TestingSetup) | ||
{ | ||
std::unique_ptr<WalletDatabase> database = CreateMockWalletDatabase(); | ||
{ | ||
// Write unknown descriptor | ||
WalletBatch batch(*database, false); | ||
WalletDescriptor wallet_descriptor(std::make_shared<UnknownDescriptor>(), 0, 0, 0, 0); | ||
BOOST_CHECK(batch.WriteDescriptor(uint256(), wallet_descriptor)); | ||
} | ||
|
||
{ | ||
// Now try to load the wallet and verify the error. | ||
const std::shared_ptr<CWallet> wallet(new CWallet(m_node.chain.get(), "", m_args, std::move(database))); | ||
BOOST_CHECK_EQUAL(wallet->LoadWallet(), DBErrors::UNKNOWN_DESCRIPTOR); | ||
} | ||
} | ||
|
||
BOOST_AUTO_TEST_SUITE_END() | ||
} // namespace wallet |