Skip to content

Commit 7345a04

Browse files
committed
test: GUI WalletTests, trigger walletModel balance changed manually.
So the model updates its internal state and can be used by the widgets. Plus unify balance check code in the test.
1 parent 6076a95 commit 7345a04

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

src/qt/test/wallettests.cpp

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,13 @@ void BumpFee(TransactionView& view, const uint256& txid, bool expectDisabled, st
129129
QVERIFY(text.indexOf(QString::fromStdString(expectError)) != -1);
130130
}
131131

132+
void CompareBalance(WalletModel& walletModel, CAmount expected_balance, QLabel* balance_label_to_check)
133+
{
134+
BitcoinUnit unit = walletModel.getOptionsModel()->getDisplayUnit();
135+
QString balanceComparison = BitcoinUnits::formatWithUnit(unit, expected_balance, false, BitcoinUnits::SeparatorStyle::ALWAYS);
136+
QCOMPARE(balance_label_to_check->text().trimmed(), balanceComparison);
137+
}
138+
132139
//! Simple qt wallet tests.
133140
//
134141
// Test widgets can be debugged interactively calling show() on them and
@@ -193,15 +200,10 @@ void TestGUI(interfaces::Node& node)
193200
sendCoinsDialog.setModel(&walletModel);
194201
transactionView.setModel(&walletModel);
195202

196-
{
197-
// Check balance in send dialog
198-
QLabel* balanceLabel = sendCoinsDialog.findChild<QLabel*>("labelBalance");
199-
QString balanceText = balanceLabel->text();
200-
BitcoinUnit unit = walletModel.getOptionsModel()->getDisplayUnit();
201-
CAmount balance = walletModel.wallet().getBalance();
202-
QString balanceComparison = BitcoinUnits::formatWithUnit(unit, balance, false, BitcoinUnits::SeparatorStyle::ALWAYS);
203-
QCOMPARE(balanceText, balanceComparison);
204-
}
203+
// Update walletModel cached balance which will trigger an update for the 'labelBalance' QLabel.
204+
walletModel.pollBalanceChanged();
205+
// Check balance in send dialog
206+
CompareBalance(walletModel, walletModel.wallet().getBalance(), sendCoinsDialog.findChild<QLabel*>("labelBalance"));
205207

206208
// Send two transactions, and verify they are added to transaction list.
207209
TransactionTableModel* transactionTableModel = walletModel.getTransactionTableModel();
@@ -221,12 +223,8 @@ void TestGUI(interfaces::Node& node)
221223
// Check current balance on OverviewPage
222224
OverviewPage overviewPage(platformStyle.get());
223225
overviewPage.setWalletModel(&walletModel);
224-
QLabel* balanceLabel = overviewPage.findChild<QLabel*>("labelBalance");
225-
QString balanceText = balanceLabel->text().trimmed();
226-
BitcoinUnit unit = walletModel.getOptionsModel()->getDisplayUnit();
227-
CAmount balance = walletModel.wallet().getBalance();
228-
QString balanceComparison = BitcoinUnits::formatWithUnit(unit, balance, false, BitcoinUnits::SeparatorStyle::ALWAYS);
229-
QCOMPARE(balanceText, balanceComparison);
226+
walletModel.pollBalanceChanged(); // Manual balance polling update
227+
CompareBalance(walletModel, walletModel.wallet().getBalance(), overviewPage.findChild<QLabel*>("labelBalance"));
230228

231229
// Check Request Payment button
232230
ReceiveCoinsDialog receiveCoinsDialog(platformStyle.get());

0 commit comments

Comments
 (0)