Skip to content

Commit ee7a984

Browse files
committed
refactor: unify test/util/wallet.h with wallet/test/util.h
files share the same purpose, and we shouldn't have wallet code inside the test directory. This later is needed to use wallet util functions in the bench and test binaries without be forced to duplicate them.
1 parent cc5a5e8 commit ee7a984

File tree

10 files changed

+41
-78
lines changed

10 files changed

+41
-78
lines changed

src/Makefile.test.include

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,6 @@ FUZZ_WALLET_SRC += \
199199
endif # USE_SQLITE
200200

201201
BITCOIN_TEST_SUITE += \
202-
wallet/test/util.cpp \
203-
wallet/test/util.h \
204202
wallet/test/wallet_test_fixture.cpp \
205203
wallet/test/wallet_test_fixture.h \
206204
wallet/test/init_test_fixture.cpp \

src/Makefile.test_util.include

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ TEST_UTIL_H = \
1818
test/util/str.h \
1919
test/util/transaction_utils.h \
2020
test/util/txmempool.h \
21-
test/util/validation.h \
22-
test/util/wallet.h
21+
test/util/validation.h
22+
23+
if ENABLE_WALLET
24+
TEST_UTIL_H += wallet/test/util.h
25+
endif # ENABLE_WALLET
2326

2427
libtest_util_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(BOOST_CPPFLAGS)
2528
libtest_util_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
@@ -33,6 +36,10 @@ libtest_util_a_SOURCES = \
3336
test/util/str.cpp \
3437
test/util/transaction_utils.cpp \
3538
test/util/txmempool.cpp \
36-
test/util/validation.cpp \
37-
test/util/wallet.cpp \
38-
$(TEST_UTIL_H)
39+
test/util/validation.cpp
40+
41+
if ENABLE_WALLET
42+
libtest_util_a_SOURCES += wallet/test/util.cpp
43+
endif # ENABLE_WALLET
44+
45+
libtest_util_a_SOURCES += $(TEST_UTIL_H)

src/bench/block_assemble.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <test/util/mining.h>
99
#include <test/util/script.h>
1010
#include <test/util/setup_common.h>
11-
#include <test/util/wallet.h>
1211
#include <txmempool.h>
1312
#include <validation.h>
1413

src/bench/wallet_balance.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <node/context.h>
88
#include <test/util/mining.h>
99
#include <test/util/setup_common.h>
10-
#include <test/util/wallet.h>
10+
#include <wallet/test/util.h>
1111
#include <validationinterface.h>
1212
#include <wallet/receive.h>
1313
#include <wallet/wallet.h>
@@ -20,6 +20,8 @@ using wallet::DBErrors;
2020
using wallet::GetBalance;
2121
using wallet::WALLET_FLAG_DESCRIPTORS;
2222

23+
const std::string ADDRESS_BCRT1_UNSPENDABLE = "bcrt1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq3xueyj";
24+
2325
static void WalletBalance(benchmark::Bench& bench, const bool set_dirty, const bool add_mine)
2426
{
2527
const auto test_setup = MakeNoLogFileContext<const TestingSetup>();

src/bench/wallet_create_tx.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
#include <kernel/chain.h>
1010
#include <node/context.h>
1111
#include <test/util/setup_common.h>
12-
#include <test/util/wallet.h>
1312
#include <validation.h>
1413
#include <wallet/spend.h>
14+
#include <wallet/test/util.h>
1515
#include <wallet/wallet.h>
1616

1717
using wallet::CWallet;

src/bench/wallet_loading.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <node/context.h>
88
#include <test/util/mining.h>
99
#include <test/util/setup_common.h>
10-
#include <test/util/wallet.h>
10+
#include <wallet/test/util.h>
1111
#include <util/translation.h>
1212
#include <validationinterface.h>
1313
#include <wallet/context.h>

src/test/util/wallet.cpp

Lines changed: 0 additions & 32 deletions
This file was deleted.

src/test/util/wallet.h

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/wallet/test/util.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
#include <wallet/wallet.h>
1212
#include <wallet/walletdb.h>
1313

14-
#include <boost/test/unit_test.hpp>
15-
1614
#include <memory>
1715

1816
namespace wallet {
@@ -39,10 +37,22 @@ std::unique_ptr<CWallet> CreateSyncedWallet(interfaces::Chain& chain, CChain& cc
3937
WalletRescanReserver reserver(*wallet);
4038
reserver.reserve();
4139
CWallet::ScanResult result = wallet->ScanForWalletTransactions(cchain.Genesis()->GetBlockHash(), /*start_height=*/0, /*max_height=*/{}, reserver, /*fUpdate=*/false, /*save_progress=*/false);
42-
BOOST_CHECK_EQUAL(result.status, CWallet::ScanResult::SUCCESS);
43-
BOOST_CHECK_EQUAL(result.last_scanned_block, cchain.Tip()->GetBlockHash());
44-
BOOST_CHECK_EQUAL(*result.last_scanned_height, cchain.Height());
45-
BOOST_CHECK(result.last_failed_block.IsNull());
40+
assert(result.status == CWallet::ScanResult::SUCCESS);
41+
assert(result.last_scanned_block == cchain.Tip()->GetBlockHash());
42+
assert(*result.last_scanned_height == cchain.Height());
43+
assert(result.last_failed_block.IsNull());
4644
return wallet;
4745
}
46+
47+
std::string getnewaddress(CWallet& w)
48+
{
49+
constexpr auto output_type = OutputType::BECH32;
50+
return EncodeDestination(getNewDestination(w, output_type));
51+
}
52+
53+
CTxDestination getNewDestination(CWallet& w, OutputType output_type)
54+
{
55+
return *Assert(w.GetNewDestination(output_type, ""));
56+
}
57+
4858
} // namespace wallet

src/wallet/test/util.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
#ifndef BITCOIN_WALLET_TEST_UTIL_H
66
#define BITCOIN_WALLET_TEST_UTIL_H
77

8+
#include <script/standard.h>
89
#include <memory>
910

1011
class ArgsManager;
1112
class CChain;
1213
class CKey;
14+
enum class OutputType;
1315
namespace interfaces {
1416
class Chain;
1517
} // namespace interfaces
@@ -18,6 +20,12 @@ namespace wallet {
1820
class CWallet;
1921

2022
std::unique_ptr<CWallet> CreateSyncedWallet(interfaces::Chain& chain, CChain& cchain, ArgsManager& args, const CKey& key);
23+
24+
/** Returns a new encoded destination from the wallet (hardcoded to BECH32) */
25+
std::string getnewaddress(CWallet& w);
26+
/** Returns a new destination, of an specific type, from the wallet */
27+
CTxDestination getNewDestination(CWallet& w, OutputType output_type);
28+
2129
} // namespace wallet
2230

2331
#endif // BITCOIN_WALLET_TEST_UTIL_H

0 commit comments

Comments
 (0)