LCOV - code coverage report
Current view: top level - src/wallet/test - wallet_interfaces_tests.cpp (source / functions) Coverage Total Hit
Test: total_coverage.info Lines: 100.0 % 46 46
Test Date: 2026-10-11 08:27:57 Functions: 100.0 % 8 8
Branches: 50.0 % 402 201

             Branch data     Line data    Source code
       1                 :             : // Copyright (c) 2026-present 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 <interfaces/wallet.h>
       6                 :             : #include <key_io.h>
       7                 :             : #include <test/util/setup_common.h>
       8                 :             : #include <wallet/context.h>
       9                 :             : #include <wallet/test/util.h>
      10                 :             : #include <wallet/wallet.h>
      11                 :             : 
      12                 :             : #include <boost/test/unit_test.hpp>
      13                 :             : #include <optional>
      14                 :             : 
      15                 :             : namespace wallet {
      16                 :             : 
      17                 :             : BOOST_FIXTURE_TEST_SUITE(wallet_interfaces_tests, BasicTestingSetup)
      18                 :             : 
      19   [ +  -  +  -  :           7 : BOOST_AUTO_TEST_CASE(addhdkey)
          +  -  +  -  -  
          +  +  -  +  -  
          +  -  +  -  +  
          -  +  -  -  +  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  -  +  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  -  +  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  -  +  +  
                      - ]
      20                 :             : {
      21                 :           1 :     WalletContext context;
      22                 :           1 :     context.args = &m_args;
      23         [ +  - ]:           1 :     auto wallet = TestCreateWallet(context);
      24         [ +  - ]:           1 :     auto interface = interfaces::MakeWallet(context, wallet);
      25                 :             : 
      26         [ +  - ]:           1 :     auto result = interface->addHDKey(std::nullopt);
      27   [ +  -  +  -  :           2 :     BOOST_REQUIRE(result);
                   +  - ]
      28   [ +  -  +  - ]:           2 :     BOOST_CHECK(result->pubkey.IsValid());
      29         [ +  - ]:           2 : }
      30                 :             : 
      31   [ +  -  +  -  :           7 : BOOST_AUTO_TEST_CASE(addhdkey_with_key)
          +  -  +  -  -  
          +  +  -  +  -  
          +  -  +  -  +  
          -  +  -  -  +  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  -  +  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  -  +  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  -  +  +  
                      - ]
      32                 :             : {
      33                 :           1 :     WalletContext context;
      34                 :           1 :     context.args = &m_args;
      35         [ +  - ]:           1 :     auto wallet = TestCreateWallet(context);
      36         [ +  - ]:           1 :     auto interface = interfaces::MakeWallet(context, wallet);
      37                 :             : 
      38                 :           1 :     CKey seed_key = GenerateRandomKey();
      39         [ +  - ]:           1 :     CExtKey key;
      40   [ +  -  +  - ]:           2 :     key.SetSeed(seed_key);
      41                 :             : 
      42   [ +  -  +  - ]:           1 :     auto result = interface->addHDKey(key);
      43   [ +  -  +  -  :           2 :     BOOST_REQUIRE(result);
                   +  - ]
      44   [ +  -  +  -  :           2 :     BOOST_CHECK(result->pubkey.IsValid());
                   +  - ]
      45   [ +  -  +  -  :           2 :     BOOST_CHECK_EQUAL(EncodeExtPubKey(*result), EncodeExtPubKey(key.Neuter()));
          +  -  +  -  +  
                      - ]
      46         [ +  - ]:           2 : }
      47                 :             : 
      48   [ +  -  +  -  :           7 : BOOST_AUTO_TEST_CASE(addhdkey_with_malformed_key)
          +  -  +  -  -  
          +  +  -  +  -  
          +  -  +  -  +  
          -  +  -  -  +  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  -  +  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  -  +  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  -  +  +  
                      - ]
      49                 :             : {
      50                 :           1 :     WalletContext context;
      51                 :           1 :     context.args = &m_args;
      52         [ +  - ]:           1 :     auto wallet = TestCreateWallet(context);
      53         [ +  - ]:           1 :     auto interface = interfaces::MakeWallet(context, wallet);
      54                 :             : 
      55                 :           1 :     CExtKey key;
      56   [ +  -  +  - ]:           2 :     key.SetSeed(GenerateRandomKey());
      57                 :           1 :     key.nChild = 1;
      58                 :             : 
      59   [ +  -  +  - ]:           1 :     auto result = interface->addHDKey(key);
      60   [ +  -  +  -  :           2 :     BOOST_REQUIRE(!result);
                   +  - ]
      61   [ +  -  +  -  :           2 :     BOOST_CHECK(result.error().code == WalletErrorCode::GenericError);
                   +  - ]
      62   [ +  -  +  - ]:           1 :     BOOST_CHECK_EQUAL(result.error().message.original, "Invalid HD key");
      63         [ +  - ]:           2 : }
      64                 :             : 
      65   [ +  -  +  -  :           7 : BOOST_AUTO_TEST_CASE(addhdkey_wallet_locked)
          +  -  +  -  -  
          +  +  -  +  -  
          +  -  +  -  +  
          -  +  -  -  +  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  -  +  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  -  +  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  -  +  +  
                      - ]
      66                 :             : {
      67                 :           1 :     WalletContext context;
      68                 :           1 :     context.args = &m_args;
      69         [ +  - ]:           1 :     auto wallet = TestCreateWallet(context);
      70   [ +  -  +  -  :           2 :     BOOST_REQUIRE(wallet->EncryptWallet("hunter2"));
          +  -  +  -  +  
                      - ]
      71   [ +  -  +  -  :           2 :     BOOST_REQUIRE(wallet->Lock());
             +  -  +  - ]
      72                 :             : 
      73         [ +  - ]:           1 :     auto interface = interfaces::MakeWallet(context, wallet);
      74         [ +  - ]:           1 :     auto result = interface->addHDKey(std::nullopt);
      75   [ +  -  +  -  :           2 :     BOOST_REQUIRE(!result);
                   +  - ]
      76   [ +  -  +  - ]:           2 :     BOOST_CHECK(result.error().code == WalletErrorCode::UnlockNeeded);
      77         [ +  - ]:           2 : }
      78                 :             : 
      79                 :             : BOOST_AUTO_TEST_SUITE_END()
      80                 :             : 
      81                 :             : } // namespace wallet
        

Generated by: LCOV version 2.0-1