Changeset View
Changeset View
Standalone View
Standalone View
src/qt/test/wallettests.cpp
Show All 23 Lines | |||||
#include <QDialogButtonBox> | #include <QDialogButtonBox> | ||||
#include <QListView> | #include <QListView> | ||||
#include <QPushButton> | #include <QPushButton> | ||||
#include <QTextEdit> | #include <QTextEdit> | ||||
#include <QTimer> | #include <QTimer> | ||||
#include <QVBoxLayout> | #include <QVBoxLayout> | ||||
namespace { | namespace { | ||||
//! Press "Yes" button in modal send confirmation dialog. | //! Press "Yes" or "Cancel" buttons in modal send confirmation dialog. | ||||
void ConfirmSend() { | void ConfirmSend(QString *text = nullptr, bool cancel = false) { | ||||
QTimer::singleShot(0, Qt::PreciseTimer, []() { | QTimer::singleShot(0, Qt::PreciseTimer, [text, cancel]() { | ||||
for (QWidget *widget : QApplication::topLevelWidgets()) { | for (QWidget *widget : QApplication::topLevelWidgets()) { | ||||
if (widget->inherits("SendConfirmationDialog")) { | if (widget->inherits("SendConfirmationDialog")) { | ||||
SendConfirmationDialog *dialog = | SendConfirmationDialog *dialog = | ||||
qobject_cast<SendConfirmationDialog *>(widget); | qobject_cast<SendConfirmationDialog *>(widget); | ||||
QAbstractButton *button = dialog->button(QMessageBox::Yes); | if (text) { | ||||
*text = dialog->text(); | |||||
} | |||||
QAbstractButton *button = dialog->button( | |||||
cancel ? QMessageBox::Cancel : QMessageBox::Yes); | |||||
button->setEnabled(true); | button->setEnabled(true); | ||||
button->click(); | button->click(); | ||||
} | } | ||||
} | } | ||||
}); | }); | ||||
} | } | ||||
//! Send coins to address and return txid. | //! Send coins to address and return txid. | ||||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | if (QApplication::platformName() == "minimal") { | ||||
QWARN("Skipping WalletTests on mac build with 'minimal' platform set " | QWARN("Skipping WalletTests on mac build with 'minimal' platform set " | ||||
"due to Qt bugs. To run AppTests, invoke " | "due to Qt bugs. To run AppTests, invoke " | ||||
"with 'test_bitcoin-qt -platform cocoa' on mac, or else use a " | "with 'test_bitcoin-qt -platform cocoa' on mac, or else use a " | ||||
"linux or windows build."); | "linux or windows build."); | ||||
return; | return; | ||||
} | } | ||||
#endif | #endif | ||||
// Set up wallet and chain with 101 blocks (1 mature block for spending). | // Set up wallet and chain with 105 blocks (5 mature blocks for spending). | ||||
TestChain100Setup test; | TestChain100Setup test; | ||||
for (int i = 0; i < 5; ++i) { | |||||
test.CreateAndProcessBlock( | test.CreateAndProcessBlock( | ||||
{}, GetScriptForRawPubKey(test.coinbaseKey.GetPubKey())); | {}, GetScriptForRawPubKey(test.coinbaseKey.GetPubKey())); | ||||
} | |||||
bitdb.MakeMock(); | bitdb.MakeMock(); | ||||
std::unique_ptr<CWalletDBWrapper> dbw( | std::unique_ptr<CWalletDBWrapper> dbw( | ||||
new CWalletDBWrapper(&bitdb, "wallet_test.dat")); | new CWalletDBWrapper(&bitdb, "wallet_test.dat")); | ||||
CWallet wallet(Params(), std::move(dbw)); | CWallet wallet(Params(), std::move(dbw)); | ||||
bool firstRun; | bool firstRun; | ||||
wallet.LoadWallet(firstRun); | wallet.LoadWallet(firstRun); | ||||
{ | { | ||||
LOCK(wallet.cs_wallet); | LOCK(wallet.cs_wallet); | ||||
Show All 13 Lines | #endif | ||||
SendCoinsDialog sendCoinsDialog(platformStyle.get()); | SendCoinsDialog sendCoinsDialog(platformStyle.get()); | ||||
OptionsModel optionsModel; | OptionsModel optionsModel; | ||||
WalletModel walletModel(platformStyle.get(), &wallet, &optionsModel); | WalletModel walletModel(platformStyle.get(), &wallet, &optionsModel); | ||||
sendCoinsDialog.setModel(&walletModel); | sendCoinsDialog.setModel(&walletModel); | ||||
// Send two transactions, and verify they are added to transaction list. | // Send two transactions, and verify they are added to transaction list. | ||||
TransactionTableModel *transactionTableModel = | TransactionTableModel *transactionTableModel = | ||||
walletModel.getTransactionTableModel(); | walletModel.getTransactionTableModel(); | ||||
QCOMPARE(transactionTableModel->rowCount({}), 101); | QCOMPARE(transactionTableModel->rowCount({}), 105); | ||||
uint256 txid1 = | uint256 txid1 = | ||||
SendCoins(wallet, sendCoinsDialog, CTxDestination(CKeyID()), 5 * COIN); | SendCoins(wallet, sendCoinsDialog, CTxDestination(CKeyID()), 5 * COIN); | ||||
uint256 txid2 = | uint256 txid2 = | ||||
SendCoins(wallet, sendCoinsDialog, CTxDestination(CKeyID()), 10 * COIN); | SendCoins(wallet, sendCoinsDialog, CTxDestination(CKeyID()), 10 * COIN); | ||||
QCOMPARE(transactionTableModel->rowCount({}), 103); | QCOMPARE(transactionTableModel->rowCount({}), 107); | ||||
QVERIFY(FindTx(*transactionTableModel, txid1).isValid()); | QVERIFY(FindTx(*transactionTableModel, txid1).isValid()); | ||||
QVERIFY(FindTx(*transactionTableModel, txid2).isValid()); | QVERIFY(FindTx(*transactionTableModel, txid2).isValid()); | ||||
// Check current balance on OverviewPage | // Check current balance on OverviewPage | ||||
OverviewPage overviewPage(platformStyle.get()); | OverviewPage overviewPage(platformStyle.get()); | ||||
overviewPage.setWalletModel(&walletModel); | overviewPage.setWalletModel(&walletModel); | ||||
QLabel *balanceLabel = overviewPage.findChild<QLabel *>("labelBalance"); | QLabel *balanceLabel = overviewPage.findChild<QLabel *>("labelBalance"); | ||||
QString balanceText = balanceLabel->text(); | QString balanceText = balanceLabel->text(); | ||||
▲ Show 20 Lines • Show All 81 Lines • Show Last 20 Lines |