mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 14:38:29 +01:00
tests: Use Descriptor wallets for generic wallet tests
For the generic wallet tests, make DescriptorScriptPubKeyMans. There are still some wallet tests that test legacy wallet things. Those remain unchanged.
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include <chain.h>
|
#include <chain.h>
|
||||||
#include <key.h>
|
#include <key.h>
|
||||||
|
#include <key_io.h>
|
||||||
#include <test/util/setup_common.h>
|
#include <test/util/setup_common.h>
|
||||||
#include <wallet/wallet.h>
|
#include <wallet/wallet.h>
|
||||||
#include <wallet/walletdb.h>
|
#include <wallet/walletdb.h>
|
||||||
@@ -23,9 +24,16 @@ std::unique_ptr<CWallet> CreateSyncedWallet(interfaces::Chain& chain, CChain& cc
|
|||||||
}
|
}
|
||||||
wallet->LoadWallet();
|
wallet->LoadWallet();
|
||||||
{
|
{
|
||||||
auto spk_man = wallet->GetOrCreateLegacyScriptPubKeyMan();
|
LOCK(wallet->cs_wallet);
|
||||||
LOCK2(wallet->cs_wallet, spk_man->cs_KeyStore);
|
wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
|
||||||
spk_man->AddKeyPubKey(key, key.GetPubKey());
|
wallet->SetupDescriptorScriptPubKeyMans();
|
||||||
|
|
||||||
|
FlatSigningProvider provider;
|
||||||
|
std::string error;
|
||||||
|
std::unique_ptr<Descriptor> desc = Parse("combo(" + EncodeSecret(key) + ")", provider, error, /* require_checksum=*/ false);
|
||||||
|
assert(desc);
|
||||||
|
WalletDescriptor w_desc(std::move(desc), 0, 0, 1, 1);
|
||||||
|
if (!wallet->AddWalletDescriptor(w_desc, provider, "", false)) assert(false);
|
||||||
}
|
}
|
||||||
WalletRescanReserver reserver(*wallet);
|
WalletRescanReserver reserver(*wallet);
|
||||||
reserver.reserve();
|
reserver.reserve();
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <interfaces/chain.h>
|
#include <interfaces/chain.h>
|
||||||
|
#include <key_io.h>
|
||||||
#include <node/blockstorage.h>
|
#include <node/blockstorage.h>
|
||||||
#include <node/context.h>
|
#include <node/context.h>
|
||||||
#include <policy/policy.h>
|
#include <policy/policy.h>
|
||||||
@@ -43,6 +44,7 @@ BOOST_FIXTURE_TEST_SUITE(wallet_tests, WalletTestingSetup)
|
|||||||
static std::shared_ptr<CWallet> TestLoadWallet(WalletContext& context)
|
static std::shared_ptr<CWallet> TestLoadWallet(WalletContext& context)
|
||||||
{
|
{
|
||||||
DatabaseOptions options;
|
DatabaseOptions options;
|
||||||
|
options.create_flags = WALLET_FLAG_DESCRIPTORS;
|
||||||
DatabaseStatus status;
|
DatabaseStatus status;
|
||||||
bilingual_str error;
|
bilingual_str error;
|
||||||
std::vector<bilingual_str> warnings;
|
std::vector<bilingual_str> warnings;
|
||||||
@@ -77,9 +79,13 @@ static CMutableTransaction TestSimpleSpend(const CTransaction& from, uint32_t in
|
|||||||
|
|
||||||
static void AddKey(CWallet& wallet, const CKey& key)
|
static void AddKey(CWallet& wallet, const CKey& key)
|
||||||
{
|
{
|
||||||
auto spk_man = wallet.GetOrCreateLegacyScriptPubKeyMan();
|
LOCK(wallet.cs_wallet);
|
||||||
LOCK2(wallet.cs_wallet, spk_man->cs_KeyStore);
|
FlatSigningProvider provider;
|
||||||
spk_man->AddKeyPubKey(key, key.GetPubKey());
|
std::string error;
|
||||||
|
std::unique_ptr<Descriptor> desc = Parse("combo(" + EncodeSecret(key) + ")", provider, error, /* require_checksum=*/ false);
|
||||||
|
assert(desc);
|
||||||
|
WalletDescriptor w_desc(std::move(desc), 0, 0, 1, 1);
|
||||||
|
if (!wallet.AddWalletDescriptor(w_desc, provider, "", false)) assert(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
|
BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
|
||||||
@@ -95,6 +101,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
|
|||||||
CWallet wallet(m_node.chain.get(), "", CreateDummyWalletDatabase());
|
CWallet wallet(m_node.chain.get(), "", CreateDummyWalletDatabase());
|
||||||
{
|
{
|
||||||
LOCK(wallet.cs_wallet);
|
LOCK(wallet.cs_wallet);
|
||||||
|
wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
|
||||||
wallet.SetLastBlockProcessed(m_node.chainman->ActiveChain().Height(), m_node.chainman->ActiveChain().Tip()->GetBlockHash());
|
wallet.SetLastBlockProcessed(m_node.chainman->ActiveChain().Height(), m_node.chainman->ActiveChain().Tip()->GetBlockHash());
|
||||||
}
|
}
|
||||||
AddKey(wallet, coinbaseKey);
|
AddKey(wallet, coinbaseKey);
|
||||||
@@ -114,6 +121,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
|
|||||||
CWallet wallet(m_node.chain.get(), "", CreateDummyWalletDatabase());
|
CWallet wallet(m_node.chain.get(), "", CreateDummyWalletDatabase());
|
||||||
{
|
{
|
||||||
LOCK(wallet.cs_wallet);
|
LOCK(wallet.cs_wallet);
|
||||||
|
wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
|
||||||
wallet.SetLastBlockProcessed(m_node.chainman->ActiveChain().Height(), m_node.chainman->ActiveChain().Tip()->GetBlockHash());
|
wallet.SetLastBlockProcessed(m_node.chainman->ActiveChain().Height(), m_node.chainman->ActiveChain().Tip()->GetBlockHash());
|
||||||
}
|
}
|
||||||
AddKey(wallet, coinbaseKey);
|
AddKey(wallet, coinbaseKey);
|
||||||
@@ -140,6 +148,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
|
|||||||
CWallet wallet(m_node.chain.get(), "", CreateDummyWalletDatabase());
|
CWallet wallet(m_node.chain.get(), "", CreateDummyWalletDatabase());
|
||||||
{
|
{
|
||||||
LOCK(wallet.cs_wallet);
|
LOCK(wallet.cs_wallet);
|
||||||
|
wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
|
||||||
wallet.SetLastBlockProcessed(m_node.chainman->ActiveChain().Height(), m_node.chainman->ActiveChain().Tip()->GetBlockHash());
|
wallet.SetLastBlockProcessed(m_node.chainman->ActiveChain().Height(), m_node.chainman->ActiveChain().Tip()->GetBlockHash());
|
||||||
}
|
}
|
||||||
AddKey(wallet, coinbaseKey);
|
AddKey(wallet, coinbaseKey);
|
||||||
@@ -165,6 +174,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
|
|||||||
CWallet wallet(m_node.chain.get(), "", CreateDummyWalletDatabase());
|
CWallet wallet(m_node.chain.get(), "", CreateDummyWalletDatabase());
|
||||||
{
|
{
|
||||||
LOCK(wallet.cs_wallet);
|
LOCK(wallet.cs_wallet);
|
||||||
|
wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
|
||||||
wallet.SetLastBlockProcessed(m_node.chainman->ActiveChain().Height(), m_node.chainman->ActiveChain().Tip()->GetBlockHash());
|
wallet.SetLastBlockProcessed(m_node.chainman->ActiveChain().Height(), m_node.chainman->ActiveChain().Tip()->GetBlockHash());
|
||||||
}
|
}
|
||||||
AddKey(wallet, coinbaseKey);
|
AddKey(wallet, coinbaseKey);
|
||||||
@@ -320,10 +330,12 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup)
|
|||||||
BOOST_FIXTURE_TEST_CASE(coin_mark_dirty_immature_credit, TestChain100Setup)
|
BOOST_FIXTURE_TEST_CASE(coin_mark_dirty_immature_credit, TestChain100Setup)
|
||||||
{
|
{
|
||||||
CWallet wallet(m_node.chain.get(), "", CreateDummyWalletDatabase());
|
CWallet wallet(m_node.chain.get(), "", CreateDummyWalletDatabase());
|
||||||
auto spk_man = wallet.GetOrCreateLegacyScriptPubKeyMan();
|
|
||||||
CWalletTx wtx(m_coinbase_txns.back());
|
CWalletTx wtx(m_coinbase_txns.back());
|
||||||
|
|
||||||
LOCK2(wallet.cs_wallet, spk_man->cs_KeyStore);
|
LOCK(wallet.cs_wallet);
|
||||||
|
wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
|
||||||
|
wallet.SetupDescriptorScriptPubKeyMans();
|
||||||
|
|
||||||
wallet.SetLastBlockProcessed(m_node.chainman->ActiveChain().Height(), m_node.chainman->ActiveChain().Tip()->GetBlockHash());
|
wallet.SetLastBlockProcessed(m_node.chainman->ActiveChain().Height(), m_node.chainman->ActiveChain().Tip()->GetBlockHash());
|
||||||
|
|
||||||
CWalletTx::Confirmation confirm(CWalletTx::Status::CONFIRMED, m_node.chainman->ActiveChain().Height(), m_node.chainman->ActiveChain().Tip()->GetBlockHash(), 0);
|
CWalletTx::Confirmation confirm(CWalletTx::Status::CONFIRMED, m_node.chainman->ActiveChain().Height(), m_node.chainman->ActiveChain().Tip()->GetBlockHash(), 0);
|
||||||
@@ -336,7 +348,7 @@ BOOST_FIXTURE_TEST_CASE(coin_mark_dirty_immature_credit, TestChain100Setup)
|
|||||||
// Invalidate the cached value, add the key, and make sure a new immature
|
// Invalidate the cached value, add the key, and make sure a new immature
|
||||||
// credit amount is calculated.
|
// credit amount is calculated.
|
||||||
wtx.MarkDirty();
|
wtx.MarkDirty();
|
||||||
BOOST_CHECK(spk_man->AddKeyPubKey(coinbaseKey, coinbaseKey.GetPubKey()));
|
AddKey(wallet, coinbaseKey);
|
||||||
BOOST_CHECK_EQUAL(CachedTxGetImmatureCredit(wallet, wtx), 50*COIN);
|
BOOST_CHECK_EQUAL(CachedTxGetImmatureCredit(wallet, wtx), 50*COIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -593,14 +605,26 @@ BOOST_FIXTURE_TEST_CASE(ListCoinsTest, ListCoinsTestingSetup)
|
|||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(wallet_disableprivkeys, TestChain100Setup)
|
BOOST_FIXTURE_TEST_CASE(wallet_disableprivkeys, TestChain100Setup)
|
||||||
{
|
{
|
||||||
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(m_node.chain.get(), "", CreateDummyWalletDatabase());
|
{
|
||||||
wallet->SetupLegacyScriptPubKeyMan();
|
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(m_node.chain.get(), "", CreateDummyWalletDatabase());
|
||||||
wallet->SetMinVersion(FEATURE_LATEST);
|
wallet->SetupLegacyScriptPubKeyMan();
|
||||||
wallet->SetWalletFlag(WALLET_FLAG_DISABLE_PRIVATE_KEYS);
|
wallet->SetMinVersion(FEATURE_LATEST);
|
||||||
BOOST_CHECK(!wallet->TopUpKeyPool(1000));
|
wallet->SetWalletFlag(WALLET_FLAG_DISABLE_PRIVATE_KEYS);
|
||||||
CTxDestination dest;
|
BOOST_CHECK(!wallet->TopUpKeyPool(1000));
|
||||||
bilingual_str error;
|
CTxDestination dest;
|
||||||
BOOST_CHECK(!wallet->GetNewDestination(OutputType::BECH32, "", dest, error));
|
bilingual_str error;
|
||||||
|
BOOST_CHECK(!wallet->GetNewDestination(OutputType::BECH32, "", dest, error));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(m_node.chain.get(), "", CreateDummyWalletDatabase());
|
||||||
|
LOCK(wallet->cs_wallet);
|
||||||
|
wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
|
||||||
|
wallet->SetMinVersion(FEATURE_LATEST);
|
||||||
|
wallet->SetWalletFlag(WALLET_FLAG_DISABLE_PRIVATE_KEYS);
|
||||||
|
CTxDestination dest;
|
||||||
|
bilingual_str error;
|
||||||
|
BOOST_CHECK(!wallet->GetNewDestination(OutputType::BECH32, "", dest, error));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Explicit calculation which is used to test the wallet constant
|
// Explicit calculation which is used to test the wallet constant
|
||||||
|
|||||||
Reference in New Issue
Block a user