4
4
5
5
#include < wallet/test/util.h>
6
6
#include < wallet/wallet.h>
7
+ #include < test/util/logging.h>
7
8
#include < test/util/setup_common.h>
8
9
9
10
#include < boost/test/unit_test.hpp>
@@ -32,7 +33,7 @@ class DummyDescriptor final : public Descriptor {
32
33
void ExpandPrivate (int pos, const SigningProvider& provider, FlatSigningProvider& out) const override {}
33
34
};
34
35
35
- BOOST_FIXTURE_TEST_CASE (wallet_load_unknown_descriptor , TestingSetup)
36
+ BOOST_FIXTURE_TEST_CASE (wallet_load_descriptors , TestingSetup)
36
37
{
37
38
std::unique_ptr<WalletDatabase> database = CreateMockableWalletDatabase ();
38
39
{
@@ -49,6 +50,33 @@ BOOST_FIXTURE_TEST_CASE(wallet_load_unknown_descriptor, TestingSetup)
49
50
const std::shared_ptr<CWallet> wallet (new CWallet (m_node.chain .get (), " " , std::move (database)));
50
51
BOOST_CHECK_EQUAL (wallet->LoadWallet (), DBErrors::UNKNOWN_DESCRIPTOR);
51
52
}
53
+
54
+ // Test 2
55
+ // Now write a valid descriptor with an invalid ID.
56
+ // As the software produces another ID for the descriptor, the loading process must be aborted.
57
+ database = CreateMockableWalletDatabase ();
58
+
59
+ // Verify the error
60
+ bool found = false ;
61
+ DebugLogHelper logHelper (" The descriptor ID calculated by the wallet differs from the one in DB" , [&](const std::string* s) {
62
+ found = true ;
63
+ return false ;
64
+ });
65
+
66
+ {
67
+ // Write valid descriptor with invalid ID
68
+ WalletBatch batch (*database, false );
69
+ std::string desc = " wpkh([d34db33f/84h/0h/0h]xpub6DJ2dNUysrn5Vt36jH2KLBT2i1auw1tTSSomg8PhqNiUtx8QX2SvC9nrHu81fT41fvDUnhMjEzQgXnQjKEu3oaqMSzhSrHMxyyoEAmUHQbY/0/*)#cjjspncu" ;
70
+ WalletDescriptor wallet_descriptor (std::make_shared<DummyDescriptor>(desc), 0 , 0 , 0 , 0 );
71
+ BOOST_CHECK (batch.WriteDescriptor (uint256::ONE, wallet_descriptor));
72
+ }
73
+
74
+ {
75
+ // Now try to load the wallet and verify the error.
76
+ const std::shared_ptr<CWallet> wallet (new CWallet (m_node.chain .get (), " " , std::move (database)));
77
+ BOOST_CHECK_EQUAL (wallet->LoadWallet (), DBErrors::CORRUPT);
78
+ BOOST_CHECK (found); // The error must be logged
79
+ }
52
80
}
53
81
54
82
bool HasAnyRecordOfType (WalletDatabase& db, const std::string& key)
0 commit comments