Skip to content

Commit 2c244c2

Browse files
MarcoFalkePastaPastaPasta
authored andcommitted
Merge bitcoin#11365: [Tests] Add Qt GUI tests to Overview and ReceiveCoin Page
634e38c [Tests] Add Qt GUI tests to Overview and ReceiveCoin Page (Anditto Heristyo) Pull request description: I've added some Qt wallet tests based on bitcoin#9974, namely the input & buttons on ReceiveCoin. Tree-SHA512: f4223827145e35c2abee83a6ca777498bebcff3825fece10fbb1dbfd1f6bb017d3f2c0521662854b4407cdeee9c6a527269ab9cc28e0dc85c11b668155fcd195
1 parent b26a3b8 commit 2c244c2

File tree

1 file changed

+71
-2
lines changed

1 file changed

+71
-2
lines changed

src/qt/test/wallettests.cpp

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,18 @@
1212
#include "test/test_dash.h"
1313
#include "validation.h"
1414
#include "wallet/wallet.h"
15+
#include "qt/overviewpage.h"
16+
#include "qt/receivecoinsdialog.h"
17+
#include "qt/recentrequeststablemodel.h"
18+
#include "qt/receiverequestdialog.h"
1519

1620
#include <QAbstractButton>
1721
#include <QApplication>
1822
#include <QTimer>
1923
#include <QVBoxLayout>
24+
#include <QTextEdit>
25+
#include <QListView>
26+
#include <QDialogButtonBox>
2027

2128
namespace
2229
{
@@ -79,7 +86,7 @@ QModelIndex FindTx(const QAbstractItemModel& model, const uint256& txid)
7986
// src/qt/test/test_bitcoin-qt -platform xcb # Linux
8087
// src/qt/test/test_bitcoin-qt -platform windows # Windows
8188
// src/qt/test/test_bitcoin-qt -platform cocoa # macOS
82-
void TestSendCoins()
89+
void TestGUI()
8390
{
8491
// Set up wallet and chain with 101 blocks (1 mature block for spending).
8592
TestChain100Setup test;
@@ -116,6 +123,68 @@ void TestSendCoins()
116123
QVERIFY(FindTx(*transactionTableModel, txid1).isValid());
117124
QVERIFY(FindTx(*transactionTableModel, txid2).isValid());
118125

126+
// Check current balance on OverviewPage
127+
OverviewPage overviewPage(platformStyle.get());
128+
overviewPage.setWalletModel(&walletModel);
129+
QLabel* balanceLabel = overviewPage.findChild<QLabel*>("labelBalance");
130+
QString balanceText = balanceLabel->text();
131+
int unit = walletModel.getOptionsModel()->getDisplayUnit();
132+
CAmount balance = walletModel.getBalance();
133+
QString balanceComparison = BitcoinUnits::formatWithUnit(unit, balance, false, BitcoinUnits::separatorAlways);
134+
QCOMPARE(balanceText, balanceComparison);
135+
136+
// Check Request Payment button
137+
ReceiveCoinsDialog receiveCoinsDialog(platformStyle.get());
138+
receiveCoinsDialog.setModel(&walletModel);
139+
RecentRequestsTableModel* requestTableModel = walletModel.getRecentRequestsTableModel();
140+
141+
// Label input
142+
QLineEdit* labelInput = receiveCoinsDialog.findChild<QLineEdit*>("reqLabel");
143+
labelInput->setText("TEST_LABEL_1");
144+
145+
// Amount input
146+
BitcoinAmountField* amountInput = receiveCoinsDialog.findChild<BitcoinAmountField*>("reqAmount");
147+
amountInput->setValue(1);
148+
149+
// Message input
150+
QLineEdit* messageInput = receiveCoinsDialog.findChild<QLineEdit*>("reqMessage");
151+
messageInput->setText("TEST_MESSAGE_1");
152+
int initialRowCount = requestTableModel->rowCount({});
153+
QPushButton* requestPaymentButton = receiveCoinsDialog.findChild<QPushButton*>("receiveButton");
154+
requestPaymentButton->click();
155+
for (QWidget* widget : QApplication::topLevelWidgets()) {
156+
if (widget->inherits("ReceiveRequestDialog")) {
157+
ReceiveRequestDialog* receiveRequestDialog = qobject_cast<ReceiveRequestDialog*>(widget);
158+
QTextEdit* rlist = receiveRequestDialog->QObject::findChild<QTextEdit*>("outUri");
159+
QString paymentText = rlist->toPlainText();
160+
QStringList paymentTextList = paymentText.split('\n');
161+
QCOMPARE(paymentTextList.at(0), QString("Payment information"));
162+
QVERIFY(paymentTextList.at(1).indexOf(QString("URI: bitcoin:")) != -1);
163+
QVERIFY(paymentTextList.at(2).indexOf(QString("Address:")) != -1);
164+
QCOMPARE(paymentTextList.at(3), QString("Amount: 0.00000001 ") + QString::fromStdString(CURRENCY_UNIT));
165+
QCOMPARE(paymentTextList.at(4), QString("Label: TEST_LABEL_1"));
166+
QCOMPARE(paymentTextList.at(5), QString("Message: TEST_MESSAGE_1"));
167+
}
168+
}
169+
170+
// Clear button
171+
QPushButton* clearButton = receiveCoinsDialog.findChild<QPushButton*>("clearButton");
172+
clearButton->click();
173+
QCOMPARE(labelInput->text(), QString(""));
174+
QCOMPARE(amountInput->value(), CAmount(0));
175+
QCOMPARE(messageInput->text(), QString(""));
176+
177+
// Check addition to history
178+
int currentRowCount = requestTableModel->rowCount({});
179+
QCOMPARE(currentRowCount, initialRowCount+1);
180+
181+
// Check Remove button
182+
QTableView* table = receiveCoinsDialog.findChild<QTableView*>("recentRequestsView");
183+
table->selectRow(currentRowCount-1);
184+
QPushButton* removeRequestButton = receiveCoinsDialog.findChild<QPushButton*>("removeRequestButton");
185+
removeRequestButton->click();
186+
QCOMPARE(requestTableModel->rowCount({}), currentRowCount-1);
187+
119188
bitdb.Flush(true);
120189
bitdb.Reset();
121190
}
@@ -124,5 +193,5 @@ void TestSendCoins()
124193

125194
void WalletTests::walletTests()
126195
{
127-
TestSendCoins();
196+
TestGUI();
128197
}

0 commit comments

Comments
 (0)