mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-05-14 12:10:42 +02:00
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.
This commit is contained in:
parent
cc5a5e8121
commit
ee7a984f85
@ -199,8 +199,6 @@ FUZZ_WALLET_SRC += \
|
|||||||
endif # USE_SQLITE
|
endif # USE_SQLITE
|
||||||
|
|
||||||
BITCOIN_TEST_SUITE += \
|
BITCOIN_TEST_SUITE += \
|
||||||
wallet/test/util.cpp \
|
|
||||||
wallet/test/util.h \
|
|
||||||
wallet/test/wallet_test_fixture.cpp \
|
wallet/test/wallet_test_fixture.cpp \
|
||||||
wallet/test/wallet_test_fixture.h \
|
wallet/test/wallet_test_fixture.h \
|
||||||
wallet/test/init_test_fixture.cpp \
|
wallet/test/init_test_fixture.cpp \
|
||||||
|
@ -18,8 +18,11 @@ TEST_UTIL_H = \
|
|||||||
test/util/str.h \
|
test/util/str.h \
|
||||||
test/util/transaction_utils.h \
|
test/util/transaction_utils.h \
|
||||||
test/util/txmempool.h \
|
test/util/txmempool.h \
|
||||||
test/util/validation.h \
|
test/util/validation.h
|
||||||
test/util/wallet.h
|
|
||||||
|
if ENABLE_WALLET
|
||||||
|
TEST_UTIL_H += wallet/test/util.h
|
||||||
|
endif # ENABLE_WALLET
|
||||||
|
|
||||||
libtest_util_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(BOOST_CPPFLAGS)
|
libtest_util_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(BOOST_CPPFLAGS)
|
||||||
libtest_util_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
libtest_util_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||||
@ -33,6 +36,10 @@ libtest_util_a_SOURCES = \
|
|||||||
test/util/str.cpp \
|
test/util/str.cpp \
|
||||||
test/util/transaction_utils.cpp \
|
test/util/transaction_utils.cpp \
|
||||||
test/util/txmempool.cpp \
|
test/util/txmempool.cpp \
|
||||||
test/util/validation.cpp \
|
test/util/validation.cpp
|
||||||
test/util/wallet.cpp \
|
|
||||||
$(TEST_UTIL_H)
|
if ENABLE_WALLET
|
||||||
|
libtest_util_a_SOURCES += wallet/test/util.cpp
|
||||||
|
endif # ENABLE_WALLET
|
||||||
|
|
||||||
|
libtest_util_a_SOURCES += $(TEST_UTIL_H)
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
#include <test/util/mining.h>
|
#include <test/util/mining.h>
|
||||||
#include <test/util/script.h>
|
#include <test/util/script.h>
|
||||||
#include <test/util/setup_common.h>
|
#include <test/util/setup_common.h>
|
||||||
#include <test/util/wallet.h>
|
|
||||||
#include <txmempool.h>
|
#include <txmempool.h>
|
||||||
#include <validation.h>
|
#include <validation.h>
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
#include <node/context.h>
|
#include <node/context.h>
|
||||||
#include <test/util/mining.h>
|
#include <test/util/mining.h>
|
||||||
#include <test/util/setup_common.h>
|
#include <test/util/setup_common.h>
|
||||||
#include <test/util/wallet.h>
|
#include <wallet/test/util.h>
|
||||||
#include <validationinterface.h>
|
#include <validationinterface.h>
|
||||||
#include <wallet/receive.h>
|
#include <wallet/receive.h>
|
||||||
#include <wallet/wallet.h>
|
#include <wallet/wallet.h>
|
||||||
@ -20,6 +20,8 @@ using wallet::DBErrors;
|
|||||||
using wallet::GetBalance;
|
using wallet::GetBalance;
|
||||||
using wallet::WALLET_FLAG_DESCRIPTORS;
|
using wallet::WALLET_FLAG_DESCRIPTORS;
|
||||||
|
|
||||||
|
const std::string ADDRESS_BCRT1_UNSPENDABLE = "bcrt1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq3xueyj";
|
||||||
|
|
||||||
static void WalletBalance(benchmark::Bench& bench, const bool set_dirty, const bool add_mine)
|
static void WalletBalance(benchmark::Bench& bench, const bool set_dirty, const bool add_mine)
|
||||||
{
|
{
|
||||||
const auto test_setup = MakeNoLogFileContext<const TestingSetup>();
|
const auto test_setup = MakeNoLogFileContext<const TestingSetup>();
|
||||||
|
@ -9,9 +9,9 @@
|
|||||||
#include <kernel/chain.h>
|
#include <kernel/chain.h>
|
||||||
#include <node/context.h>
|
#include <node/context.h>
|
||||||
#include <test/util/setup_common.h>
|
#include <test/util/setup_common.h>
|
||||||
#include <test/util/wallet.h>
|
|
||||||
#include <validation.h>
|
#include <validation.h>
|
||||||
#include <wallet/spend.h>
|
#include <wallet/spend.h>
|
||||||
|
#include <wallet/test/util.h>
|
||||||
#include <wallet/wallet.h>
|
#include <wallet/wallet.h>
|
||||||
|
|
||||||
using wallet::CWallet;
|
using wallet::CWallet;
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
#include <node/context.h>
|
#include <node/context.h>
|
||||||
#include <test/util/mining.h>
|
#include <test/util/mining.h>
|
||||||
#include <test/util/setup_common.h>
|
#include <test/util/setup_common.h>
|
||||||
#include <test/util/wallet.h>
|
#include <wallet/test/util.h>
|
||||||
#include <util/translation.h>
|
#include <util/translation.h>
|
||||||
#include <validationinterface.h>
|
#include <validationinterface.h>
|
||||||
#include <wallet/context.h>
|
#include <wallet/context.h>
|
||||||
|
@ -1,32 +0,0 @@
|
|||||||
// Copyright (c) 2019-2021 The Bitcoin Core developers
|
|
||||||
// Distributed under the MIT software license, see the accompanying
|
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
||||||
|
|
||||||
#include <test/util/wallet.h>
|
|
||||||
|
|
||||||
#include <key_io.h>
|
|
||||||
#include <outputtype.h>
|
|
||||||
#include <script/standard.h>
|
|
||||||
#ifdef ENABLE_WALLET
|
|
||||||
#include <util/check.h>
|
|
||||||
#include <util/translation.h>
|
|
||||||
#include <wallet/wallet.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
using wallet::CWallet;
|
|
||||||
|
|
||||||
const std::string ADDRESS_BCRT1_UNSPENDABLE = "bcrt1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq3xueyj";
|
|
||||||
|
|
||||||
#ifdef ENABLE_WALLET
|
|
||||||
std::string getnewaddress(CWallet& w)
|
|
||||||
{
|
|
||||||
constexpr auto output_type = OutputType::BECH32;
|
|
||||||
return EncodeDestination(getNewDestination(w, output_type));
|
|
||||||
}
|
|
||||||
|
|
||||||
CTxDestination getNewDestination(CWallet& w, OutputType output_type)
|
|
||||||
{
|
|
||||||
return *Assert(w.GetNewDestination(output_type, ""));
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // ENABLE_WALLET
|
|
@ -1,29 +0,0 @@
|
|||||||
// Copyright (c) 2019 The Bitcoin Core developers
|
|
||||||
// Distributed under the MIT software license, see the accompanying
|
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
||||||
|
|
||||||
#ifndef BITCOIN_TEST_UTIL_WALLET_H
|
|
||||||
#define BITCOIN_TEST_UTIL_WALLET_H
|
|
||||||
|
|
||||||
#include <outputtype.h>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace wallet {
|
|
||||||
class CWallet;
|
|
||||||
} // namespace wallet
|
|
||||||
|
|
||||||
// Constants //
|
|
||||||
|
|
||||||
extern const std::string ADDRESS_BCRT1_UNSPENDABLE;
|
|
||||||
|
|
||||||
// RPC-like //
|
|
||||||
|
|
||||||
/** Import the address to the wallet */
|
|
||||||
void importaddress(wallet::CWallet& wallet, const std::string& address);
|
|
||||||
/** Returns a new encoded destination from the wallet (hardcoded to BECH32) */
|
|
||||||
std::string getnewaddress(wallet::CWallet& w);
|
|
||||||
/** Returns a new destination, of an specific type, from the wallet */
|
|
||||||
CTxDestination getNewDestination(wallet::CWallet& w, OutputType output_type);
|
|
||||||
|
|
||||||
|
|
||||||
#endif // BITCOIN_TEST_UTIL_WALLET_H
|
|
@ -11,8 +11,6 @@
|
|||||||
#include <wallet/wallet.h>
|
#include <wallet/wallet.h>
|
||||||
#include <wallet/walletdb.h>
|
#include <wallet/walletdb.h>
|
||||||
|
|
||||||
#include <boost/test/unit_test.hpp>
|
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace wallet {
|
namespace wallet {
|
||||||
@ -39,10 +37,22 @@ std::unique_ptr<CWallet> CreateSyncedWallet(interfaces::Chain& chain, CChain& cc
|
|||||||
WalletRescanReserver reserver(*wallet);
|
WalletRescanReserver reserver(*wallet);
|
||||||
reserver.reserve();
|
reserver.reserve();
|
||||||
CWallet::ScanResult result = wallet->ScanForWalletTransactions(cchain.Genesis()->GetBlockHash(), /*start_height=*/0, /*max_height=*/{}, reserver, /*fUpdate=*/false, /*save_progress=*/false);
|
CWallet::ScanResult result = wallet->ScanForWalletTransactions(cchain.Genesis()->GetBlockHash(), /*start_height=*/0, /*max_height=*/{}, reserver, /*fUpdate=*/false, /*save_progress=*/false);
|
||||||
BOOST_CHECK_EQUAL(result.status, CWallet::ScanResult::SUCCESS);
|
assert(result.status == CWallet::ScanResult::SUCCESS);
|
||||||
BOOST_CHECK_EQUAL(result.last_scanned_block, cchain.Tip()->GetBlockHash());
|
assert(result.last_scanned_block == cchain.Tip()->GetBlockHash());
|
||||||
BOOST_CHECK_EQUAL(*result.last_scanned_height, cchain.Height());
|
assert(*result.last_scanned_height == cchain.Height());
|
||||||
BOOST_CHECK(result.last_failed_block.IsNull());
|
assert(result.last_failed_block.IsNull());
|
||||||
return wallet;
|
return wallet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string getnewaddress(CWallet& w)
|
||||||
|
{
|
||||||
|
constexpr auto output_type = OutputType::BECH32;
|
||||||
|
return EncodeDestination(getNewDestination(w, output_type));
|
||||||
|
}
|
||||||
|
|
||||||
|
CTxDestination getNewDestination(CWallet& w, OutputType output_type)
|
||||||
|
{
|
||||||
|
return *Assert(w.GetNewDestination(output_type, ""));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace wallet
|
} // namespace wallet
|
||||||
|
@ -5,11 +5,13 @@
|
|||||||
#ifndef BITCOIN_WALLET_TEST_UTIL_H
|
#ifndef BITCOIN_WALLET_TEST_UTIL_H
|
||||||
#define BITCOIN_WALLET_TEST_UTIL_H
|
#define BITCOIN_WALLET_TEST_UTIL_H
|
||||||
|
|
||||||
|
#include <script/standard.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
class ArgsManager;
|
class ArgsManager;
|
||||||
class CChain;
|
class CChain;
|
||||||
class CKey;
|
class CKey;
|
||||||
|
enum class OutputType;
|
||||||
namespace interfaces {
|
namespace interfaces {
|
||||||
class Chain;
|
class Chain;
|
||||||
} // namespace interfaces
|
} // namespace interfaces
|
||||||
@ -18,6 +20,12 @@ namespace wallet {
|
|||||||
class CWallet;
|
class CWallet;
|
||||||
|
|
||||||
std::unique_ptr<CWallet> CreateSyncedWallet(interfaces::Chain& chain, CChain& cchain, ArgsManager& args, const CKey& key);
|
std::unique_ptr<CWallet> CreateSyncedWallet(interfaces::Chain& chain, CChain& cchain, ArgsManager& args, const CKey& key);
|
||||||
|
|
||||||
|
/** Returns a new encoded destination from the wallet (hardcoded to BECH32) */
|
||||||
|
std::string getnewaddress(CWallet& w);
|
||||||
|
/** Returns a new destination, of an specific type, from the wallet */
|
||||||
|
CTxDestination getNewDestination(CWallet& w, OutputType output_type);
|
||||||
|
|
||||||
} // namespace wallet
|
} // namespace wallet
|
||||||
|
|
||||||
#endif // BITCOIN_WALLET_TEST_UTIL_H
|
#endif // BITCOIN_WALLET_TEST_UTIL_H
|
||||||
|
Loading…
Reference in New Issue
Block a user