|
5 | 5 | #include <qt/test/wallettests.h>
|
6 | 6 | #include <qt/test/util.h>
|
7 | 7 |
|
| 8 | +#include <wallet/coincontrol.h> |
8 | 9 | #include <interfaces/chain.h>
|
9 | 10 | #include <interfaces/node.h>
|
10 | 11 | #include <key_io.h>
|
@@ -136,6 +137,42 @@ void CompareBalance(WalletModel& walletModel, CAmount expected_balance, QLabel*
|
136 | 137 | QCOMPARE(balance_label_to_check->text().trimmed(), balanceComparison);
|
137 | 138 | }
|
138 | 139 |
|
| 140 | +// Verify the 'useAvailableBalance' functionality. With and without manually selected coins. |
| 141 | +// Case 1: No coin control selected coins. |
| 142 | +// 'useAvailableBalance' should fill the amount edit box with the total available balance |
| 143 | +// Case 2: With coin control selected coins. |
| 144 | +// 'useAvailableBalance' should fill the amount edit box with the sum of the selected coins values. |
| 145 | +void VerifyUseAvailableBalance(SendCoinsDialog& sendCoinsDialog, const WalletModel& walletModel) |
| 146 | +{ |
| 147 | + // Verify first entry amount and "useAvailableBalance" button |
| 148 | + QVBoxLayout* entries = sendCoinsDialog.findChild<QVBoxLayout*>("entries"); |
| 149 | + QVERIFY(entries->count() == 1); // only one entry |
| 150 | + SendCoinsEntry* send_entry = qobject_cast<SendCoinsEntry*>(entries->itemAt(0)->widget()); |
| 151 | + QVERIFY(send_entry->getValue().amount == 0); |
| 152 | + // Now click "useAvailableBalance", check updated balance (the entire wallet balance should be set) |
| 153 | + Q_EMIT send_entry->useAvailableBalance(send_entry); |
| 154 | + QVERIFY(send_entry->getValue().amount == walletModel.getCachedBalance().balance); |
| 155 | + |
| 156 | + // Now manually select two coins and click on "useAvailableBalance". Then check updated balance |
| 157 | + // (only the sum of the selected coins should be set). |
| 158 | + int COINS_TO_SELECT = 2; |
| 159 | + auto coins = walletModel.wallet().listCoins(); |
| 160 | + CAmount sum_selected_coins = 0; |
| 161 | + int selected = 0; |
| 162 | + QVERIFY(coins.size() == 1); // context check, coins received only on one destination |
| 163 | + for (const auto& [outpoint, tx_out] : coins.begin()->second) { |
| 164 | + sendCoinsDialog.getCoinControl()->Select(outpoint); |
| 165 | + sum_selected_coins += tx_out.txout.nValue; |
| 166 | + if (++selected == COINS_TO_SELECT) break; |
| 167 | + } |
| 168 | + QVERIFY(selected == COINS_TO_SELECT); |
| 169 | + |
| 170 | + // Now that we have 2 coins selected, "useAvailableBalance" should update the balance label only with |
| 171 | + // the sum of them. |
| 172 | + Q_EMIT send_entry->useAvailableBalance(send_entry); |
| 173 | + QVERIFY(send_entry->getValue().amount == sum_selected_coins); |
| 174 | +} |
| 175 | + |
139 | 176 | //! Simple qt wallet tests.
|
140 | 177 | //
|
141 | 178 | // Test widgets can be debugged interactively calling show() on them and
|
@@ -207,6 +244,9 @@ void TestGUI(interfaces::Node& node)
|
207 | 244 | // Check balance in send dialog
|
208 | 245 | CompareBalance(walletModel, walletModel.wallet().getBalance(), sendCoinsDialog.findChild<QLabel*>("labelBalance"));
|
209 | 246 |
|
| 247 | + // Check 'UseAvailableBalance' functionality |
| 248 | + VerifyUseAvailableBalance(sendCoinsDialog, walletModel); |
| 249 | + |
210 | 250 | // Send two transactions, and verify they are added to transaction list.
|
211 | 251 | TransactionTableModel* transactionTableModel = walletModel.getTransactionTableModel();
|
212 | 252 | QCOMPARE(transactionTableModel->rowCount({}), 105);
|
|
0 commit comments