mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 07:09:15 +01:00
32023 changed AddWalletDescriptor to return util::Error, but did not change all of the failure cases to do so. This may result in some callers continuing when there was actually an error. Unify all of the failure cases to use util::Error so that all callers handle AddWalletDescriptor errors in the same way. The encapsulated return type is changed from ScriptPubKeyMan* to std::reference_wrapper<DescriptorScriptPubKeyMan>. This avoids having a value that can be interpreted as a bool, and also removes the need to constantly dynamic_cast the returned value. The only kind of ScriptPubKeyMan that can come out of AddWalletDescriptor is a DescriptorScriptPubKeyMan anyways.
42 lines
1.7 KiB
C++
42 lines
1.7 KiB
C++
// Copyright (c) 2020-2021 The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#include <key.h>
|
|
#include <key_io.h>
|
|
#include <test/util/setup_common.h>
|
|
#include <script/solver.h>
|
|
#include <wallet/scriptpubkeyman.h>
|
|
#include <wallet/wallet.h>
|
|
#include <wallet/test/util.h>
|
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
namespace wallet {
|
|
BOOST_FIXTURE_TEST_SUITE(scriptpubkeyman_tests, BasicTestingSetup)
|
|
|
|
BOOST_AUTO_TEST_CASE(DescriptorScriptPubKeyManTests)
|
|
{
|
|
std::unique_ptr<interfaces::Chain>& chain = m_node.chain;
|
|
|
|
CWallet keystore(chain.get(), "", CreateMockableWalletDatabase());
|
|
auto key_scriptpath = GenerateRandomKey();
|
|
|
|
// Verify that a SigningProvider for a pubkey is only returned if its corresponding private key is available
|
|
auto key_internal = GenerateRandomKey();
|
|
std::string desc_str = "tr(" + EncodeSecret(key_internal) + ",pk(" + HexStr(key_scriptpath.GetPubKey()) + "))";
|
|
auto spk_man1 = CreateDescriptor(keystore, desc_str, true);
|
|
BOOST_CHECK(spk_man1 != nullptr);
|
|
auto signprov_keypath_spendable = spk_man1->GetSigningProvider(key_internal.GetPubKey());
|
|
BOOST_CHECK(signprov_keypath_spendable != nullptr);
|
|
|
|
desc_str = "tr(" + HexStr(XOnlyPubKey::NUMS_H) + ",pk(" + HexStr(key_scriptpath.GetPubKey()) + "))";
|
|
auto spk_man2 = CreateDescriptor(keystore, desc_str, true);
|
|
BOOST_CHECK(spk_man2 != nullptr);
|
|
auto signprov_keypath_nums_h = spk_man2->GetSigningProvider(XOnlyPubKey::NUMS_H.GetEvenCorrespondingCPubKey());
|
|
BOOST_CHECK(signprov_keypath_nums_h == nullptr);
|
|
}
|
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|
|
} // namespace wallet
|