Skip to content

Commit 62a95f5

Browse files
theStackachow101
authored andcommitted
test: refactor: move CreateDescriptor helper to wallet test util module
Can be reviewed via `--color-moved=dimmed-zebra`.
1 parent 4936567 commit 62a95f5

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

src/wallet/test/ismine_tests.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,6 @@ using namespace util::hex_literals;
2020
namespace wallet {
2121
BOOST_FIXTURE_TEST_SUITE(ismine_tests, BasicTestingSetup)
2222

23-
wallet::ScriptPubKeyMan* CreateDescriptor(CWallet& keystore, const std::string& desc_str, const bool success)
24-
{
25-
keystore.SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
26-
27-
FlatSigningProvider keys;
28-
std::string error;
29-
auto parsed_descs = Parse(desc_str, keys, error, false);
30-
BOOST_CHECK(success == (!parsed_descs.empty()));
31-
if (!success) return nullptr;
32-
auto& desc = parsed_descs.at(0);
33-
34-
const int64_t range_start = 0, range_end = 1, next_index = 0, timestamp = 1;
35-
36-
WalletDescriptor w_desc(std::move(desc), timestamp, range_start, range_end, next_index);
37-
38-
LOCK(keystore.cs_wallet);
39-
40-
return Assert(keystore.AddWalletDescriptor(w_desc, keys,/*label=*/"", /*internal=*/false));
41-
};
42-
4323
BOOST_AUTO_TEST_CASE(ismine_standard)
4424
{
4525
CKey keys[2];

src/wallet/test/util.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,24 @@ MockableDatabase& GetMockableDatabase(CWallet& wallet)
192192
{
193193
return dynamic_cast<MockableDatabase&>(wallet.GetDatabase());
194194
}
195+
196+
wallet::ScriptPubKeyMan* CreateDescriptor(CWallet& keystore, const std::string& desc_str, const bool success)
197+
{
198+
keystore.SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
199+
200+
FlatSigningProvider keys;
201+
std::string error;
202+
auto parsed_descs = Parse(desc_str, keys, error, false);
203+
Assert(success == (!parsed_descs.empty()));
204+
if (!success) return nullptr;
205+
auto& desc = parsed_descs.at(0);
206+
207+
const int64_t range_start = 0, range_end = 1, next_index = 0, timestamp = 1;
208+
209+
WalletDescriptor w_desc(std::move(desc), timestamp, range_start, range_end, next_index);
210+
211+
LOCK(keystore.cs_wallet);
212+
213+
return Assert(keystore.AddWalletDescriptor(w_desc, keys,/*label=*/"", /*internal=*/false));
214+
};
195215
} // namespace wallet

src/wallet/test/util.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <addresstype.h>
1111
#include <wallet/db.h>
12+
#include <wallet/scriptpubkeyman.h>
1213

1314
#include <memory>
1415

@@ -127,8 +128,9 @@ class MockableDatabase : public WalletDatabase
127128
};
128129

129130
std::unique_ptr<WalletDatabase> CreateMockableWalletDatabase(MockableData records = {});
130-
131131
MockableDatabase& GetMockableDatabase(CWallet& wallet);
132+
133+
ScriptPubKeyMan* CreateDescriptor(CWallet& keystore, const std::string& desc_str, const bool success);
132134
} // namespace wallet
133135

134136
#endif // BITCOIN_WALLET_TEST_UTIL_H

0 commit comments

Comments
 (0)