mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-10 10:52:31 -05:00
test,gui: decouple chain and wallet initialization from test case
Prepare ground for legacy watch-only test.
This commit is contained in:
parent
cd98b71739
commit
2f76ac0383
1 changed files with 50 additions and 37 deletions
|
@ -173,6 +173,39 @@ void VerifyUseAvailableBalance(SendCoinsDialog& sendCoinsDialog, const WalletMod
|
||||||
QVERIFY(send_entry->getValue().amount == sum_selected_coins);
|
QVERIFY(send_entry->getValue().amount == sum_selected_coins);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SyncUpWallet(const std::shared_ptr<CWallet>& wallet, interfaces::Node& node)
|
||||||
|
{
|
||||||
|
WalletRescanReserver reserver(*wallet);
|
||||||
|
reserver.reserve();
|
||||||
|
CWallet::ScanResult result = wallet->ScanForWalletTransactions(Params().GetConsensus().hashGenesisBlock, /*start_height=*/0, /*max_height=*/{}, reserver, /*fUpdate=*/true, /*save_progress=*/false);
|
||||||
|
QCOMPARE(result.status, CWallet::ScanResult::SUCCESS);
|
||||||
|
QCOMPARE(result.last_scanned_block, WITH_LOCK(node.context()->chainman->GetMutex(), return node.context()->chainman->ActiveChain().Tip()->GetBlockHash()));
|
||||||
|
QVERIFY(result.last_failed_block.IsNull());
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<CWallet> SetupDescriptorsWallet(interfaces::Node& node, TestChain100Setup& test)
|
||||||
|
{
|
||||||
|
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(node.context()->chain.get(), "", CreateMockWalletDatabase());
|
||||||
|
wallet->LoadWallet();
|
||||||
|
LOCK(wallet->cs_wallet);
|
||||||
|
wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
|
||||||
|
wallet->SetupDescriptorScriptPubKeyMans();
|
||||||
|
|
||||||
|
// Add the coinbase key
|
||||||
|
FlatSigningProvider provider;
|
||||||
|
std::string error;
|
||||||
|
std::unique_ptr<Descriptor> desc = Parse("combo(" + EncodeSecret(test.coinbaseKey) + ")", 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);
|
||||||
|
CTxDestination dest = GetDestinationForKey(test.coinbaseKey.GetPubKey(), wallet->m_default_address_type);
|
||||||
|
wallet->SetAddressBook(dest, "", "receive");
|
||||||
|
wallet->SetLastBlockProcessed(105, WITH_LOCK(node.context()->chainman->GetMutex(), return node.context()->chainman->ActiveChain().Tip()->GetBlockHash()));
|
||||||
|
SyncUpWallet(wallet, node);
|
||||||
|
wallet->SetBroadcastTransactions(true);
|
||||||
|
return wallet;
|
||||||
|
}
|
||||||
|
|
||||||
//! Simple qt wallet tests.
|
//! Simple qt wallet tests.
|
||||||
//
|
//
|
||||||
// Test widgets can be debugged interactively calling show() on them and
|
// Test widgets can be debugged interactively calling show() on them and
|
||||||
|
@ -186,44 +219,8 @@ void VerifyUseAvailableBalance(SendCoinsDialog& sendCoinsDialog, const WalletMod
|
||||||
// QT_QPA_PLATFORM=xcb src/qt/test/test_bitcoin-qt # Linux
|
// QT_QPA_PLATFORM=xcb src/qt/test/test_bitcoin-qt # Linux
|
||||||
// QT_QPA_PLATFORM=windows src/qt/test/test_bitcoin-qt # Windows
|
// QT_QPA_PLATFORM=windows src/qt/test/test_bitcoin-qt # Windows
|
||||||
// QT_QPA_PLATFORM=cocoa src/qt/test/test_bitcoin-qt # macOS
|
// QT_QPA_PLATFORM=cocoa src/qt/test/test_bitcoin-qt # macOS
|
||||||
void TestGUI(interfaces::Node& node)
|
void TestGUI(interfaces::Node& node, const std::shared_ptr<CWallet>& wallet)
|
||||||
{
|
{
|
||||||
// Set up wallet and chain with 105 blocks (5 mature blocks for spending).
|
|
||||||
TestChain100Setup test;
|
|
||||||
for (int i = 0; i < 5; ++i) {
|
|
||||||
test.CreateAndProcessBlock({}, GetScriptForRawPubKey(test.coinbaseKey.GetPubKey()));
|
|
||||||
}
|
|
||||||
auto wallet_loader = interfaces::MakeWalletLoader(*test.m_node.chain, *Assert(test.m_node.args));
|
|
||||||
test.m_node.wallet_loader = wallet_loader.get();
|
|
||||||
node.setContext(&test.m_node);
|
|
||||||
const std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(node.context()->chain.get(), "", CreateMockWalletDatabase());
|
|
||||||
wallet->LoadWallet();
|
|
||||||
wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
|
|
||||||
{
|
|
||||||
LOCK(wallet->cs_wallet);
|
|
||||||
wallet->SetupDescriptorScriptPubKeyMans();
|
|
||||||
|
|
||||||
// Add the coinbase key
|
|
||||||
FlatSigningProvider provider;
|
|
||||||
std::string error;
|
|
||||||
std::unique_ptr<Descriptor> desc = Parse("combo(" + EncodeSecret(test.coinbaseKey) + ")", 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);
|
|
||||||
CTxDestination dest = GetDestinationForKey(test.coinbaseKey.GetPubKey(), wallet->m_default_address_type);
|
|
||||||
wallet->SetAddressBook(dest, "", "receive");
|
|
||||||
wallet->SetLastBlockProcessed(105, WITH_LOCK(node.context()->chainman->GetMutex(), return node.context()->chainman->ActiveChain().Tip()->GetBlockHash()));
|
|
||||||
}
|
|
||||||
{
|
|
||||||
WalletRescanReserver reserver(*wallet);
|
|
||||||
reserver.reserve();
|
|
||||||
CWallet::ScanResult result = wallet->ScanForWalletTransactions(Params().GetConsensus().hashGenesisBlock, /*start_height=*/0, /*max_height=*/{}, reserver, /*fUpdate=*/true, /*save_progress=*/false);
|
|
||||||
QCOMPARE(result.status, CWallet::ScanResult::SUCCESS);
|
|
||||||
QCOMPARE(result.last_scanned_block, WITH_LOCK(node.context()->chainman->GetMutex(), return node.context()->chainman->ActiveChain().Tip()->GetBlockHash()));
|
|
||||||
QVERIFY(result.last_failed_block.IsNull());
|
|
||||||
}
|
|
||||||
wallet->SetBroadcastTransactions(true);
|
|
||||||
|
|
||||||
// Create widgets for sending coins and listing transactions.
|
// Create widgets for sending coins and listing transactions.
|
||||||
std::unique_ptr<const PlatformStyle> platformStyle(PlatformStyle::instantiate("other"));
|
std::unique_ptr<const PlatformStyle> platformStyle(PlatformStyle::instantiate("other"));
|
||||||
SendCoinsDialog sendCoinsDialog(platformStyle.get());
|
SendCoinsDialog sendCoinsDialog(platformStyle.get());
|
||||||
|
@ -353,6 +350,22 @@ void TestGUI(interfaces::Node& node)
|
||||||
QCOMPARE(walletModel.wallet().getAddressReceiveRequests().size(), size_t{0});
|
QCOMPARE(walletModel.wallet().getAddressReceiveRequests().size(), size_t{0});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestGUI(interfaces::Node& node)
|
||||||
|
{
|
||||||
|
// Set up wallet and chain with 105 blocks (5 mature blocks for spending).
|
||||||
|
TestChain100Setup test;
|
||||||
|
for (int i = 0; i < 5; ++i) {
|
||||||
|
test.CreateAndProcessBlock({}, GetScriptForRawPubKey(test.coinbaseKey.GetPubKey()));
|
||||||
|
}
|
||||||
|
auto wallet_loader = interfaces::MakeWalletLoader(*test.m_node.chain, *Assert(test.m_node.args));
|
||||||
|
test.m_node.wallet_loader = wallet_loader.get();
|
||||||
|
node.setContext(&test.m_node);
|
||||||
|
|
||||||
|
// "Full" GUI tests, use descriptor wallet
|
||||||
|
const std::shared_ptr<CWallet>& desc_wallet = SetupDescriptorsWallet(node, test);
|
||||||
|
TestGUI(node, desc_wallet);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void WalletTests::walletTests()
|
void WalletTests::walletTests()
|
||||||
|
|
Loading…
Add table
Reference in a new issue