LCOV - code coverage report
Current view: top level - src/wallet/test - scriptpubkeyman_tests.cpp (source / functions) Coverage Total Hit
Test: total_coverage.info Lines: 100.0 % 22 22
Test Date: 2026-06-07 07:49:58 Functions: 100.0 % 4 4
Branches: 49.1 % 232 114

             Branch data     Line data    Source code
       1                 :             : // Copyright (c) 2020-present The Bitcoin Core developers
       2                 :             : // Distributed under the MIT software license, see the accompanying
       3                 :             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       4                 :             : 
       5                 :             : #include <key.h>
       6                 :             : #include <key_io.h>
       7                 :             : #include <test/util/common.h>
       8                 :             : #include <test/util/setup_common.h>
       9                 :             : #include <script/solver.h>
      10                 :             : #include <wallet/scriptpubkeyman.h>
      11                 :             : #include <wallet/wallet.h>
      12                 :             : #include <wallet/test/util.h>
      13                 :             : 
      14                 :             : #include <boost/test/unit_test.hpp>
      15                 :             : 
      16                 :             : namespace wallet {
      17                 :             : BOOST_FIXTURE_TEST_SUITE(scriptpubkeyman_tests, BasicTestingSetup)
      18                 :             : 
      19   [ +  -  +  -  :           7 : BOOST_AUTO_TEST_CASE(DescriptorScriptPubKeyManTests)
          +  -  +  -  -  
          +  +  -  +  -  
          +  -  +  -  +  
          -  +  -  -  +  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  -  +  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  -  +  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  -  +  +  
                      - ]
      20                 :             : {
      21                 :           1 :     std::unique_ptr<interfaces::Chain>& chain = m_node.chain;
      22                 :             : 
      23   [ +  -  +  - ]:           2 :     CWallet keystore(chain.get(), "", CreateMockableWalletDatabase());
      24                 :           1 :     auto key_scriptpath = GenerateRandomKey();
      25                 :             : 
      26                 :             :     // Verify that a SigningProvider for a pubkey is only returned if its corresponding private key is available
      27                 :           1 :     auto key_internal = GenerateRandomKey();
      28   [ +  -  +  -  :           3 :     std::string desc_str = "tr(" + EncodeSecret(key_internal) + ",pk(" + HexStr(key_scriptpath.GetPubKey()) + "))";
          +  -  +  -  +  
                      - ]
      29         [ +  - ]:           1 :     auto spk_man1 = CreateDescriptor(keystore, desc_str, true);
      30   [ +  -  +  -  :           2 :     BOOST_CHECK(spk_man1 != nullptr);
                   +  - ]
      31   [ +  -  +  - ]:           1 :     auto signprov_keypath_spendable = spk_man1->GetSigningProvider(key_internal.GetPubKey());
      32   [ +  -  +  -  :           2 :     BOOST_CHECK(signprov_keypath_spendable != nullptr);
                   +  - ]
      33                 :             : 
      34   [ +  -  +  -  :           3 :     desc_str = "tr(" + HexStr(XOnlyPubKey::NUMS_H) + ",pk(" + HexStr(key_scriptpath.GetPubKey()) + "))";
             +  -  +  - ]
      35         [ +  - ]:           1 :     auto spk_man2 = CreateDescriptor(keystore, desc_str, true);
      36   [ +  -  +  -  :           2 :     BOOST_CHECK(spk_man2 != nullptr);
                   +  - ]
      37   [ +  -  +  - ]:           1 :     auto signprov_keypath_nums_h = spk_man2->GetSigningProvider(XOnlyPubKey::NUMS_H.GetEvenCorrespondingCPubKey());
      38   [ +  -  +  -  :           2 :     BOOST_CHECK(signprov_keypath_nums_h == nullptr);
                   -  + ]
      39         [ +  - ]:           2 : }
      40                 :             : 
      41   [ +  -  +  -  :           7 : BOOST_AUTO_TEST_CASE(desc_spkm_topup_fail)
          +  -  +  -  -  
          +  +  -  +  -  
          +  -  +  -  +  
          -  +  -  -  +  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  -  +  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  -  +  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  -  +  +  
                      - ]
      42                 :             : {
      43                 :             :     // Attempting to construct a DescriptorSPKM that cannot be topped up (hardened derivation without private keys)
      44                 :             :     // should throw even though it is valid and can be parsed
      45         [ +  - ]:           1 :     CExtKey extkey;
      46         [ +  - ]:           1 :     extkey.SetSeed(std::array<std::byte, 32>{});
      47   [ +  -  +  -  :           2 :     CWallet keystore(m_node.chain.get(), "", CreateMockableWalletDatabase());
                   +  - ]
      48   [ +  -  +  -  :           6 :     BOOST_CHECK_EXCEPTION(
          +  -  +  -  -  
          +  -  -  -  -  
          -  +  +  -  +  
                -  +  - ]
      49                 :             :         CreateDescriptor(keystore, "wpkh(" + EncodeExtPubKey(extkey.Neuter()) + "/*h)", /*success=*/true),
      50                 :             :         std::runtime_error, HasReason("Could not top up scriptPubKeys"));
      51                 :           1 : }
      52                 :             : 
      53                 :             : BOOST_AUTO_TEST_SUITE_END()
      54                 :             : } // namespace wallet
        

Generated by: LCOV version 2.0-1