mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-04 17:52:25 +01:00
test: add check for getting SigningProvider for a CPubKey
Verify that the DescriptorSPKM method `GetSigningProvider` should only return a signing provider for the passed public key if its corresponding private key of the passed public key is available.
This commit is contained in:
committed by
Ava Chow
parent
62a95f5af9
commit
f6a6d91205
@@ -3,6 +3,7 @@
|
||||
// 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>
|
||||
@@ -40,5 +41,27 @@ BOOST_AUTO_TEST_CASE(CanProvide)
|
||||
BOOST_CHECK(keyman.CanProvide(p2sh_script, data));
|
||||
}
|
||||
|
||||
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 = dynamic_cast<DescriptorScriptPubKeyMan*>(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 = dynamic_cast<DescriptorScriptPubKeyMan*>(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
|
||||
|
||||
Reference in New Issue
Block a user