27#include <QApplication>
47void EditAddressAndSubmit(
49 const QString& label,
const QString& address, QString expected_msg)
53 dialog->findChild<QLineEdit*>(
"labelEdit")->setText(label);
58 QCOMPARE(warning_text, expected_msg);
84 wallet->SetupDescriptorScriptPubKeyMans();
87 auto build_address{[]() {
95 QString preexisting_r_address;
96 QString r_label(
"already here (r)");
99 QString preexisting_s_address;
100 QString s_label(
"already here (s)");
103 QString new_address_a;
104 QString new_address_b;
106 std::tie(r_key_dest, preexisting_r_address) = build_address();
107 std::tie(s_key_dest, preexisting_s_address) = build_address();
108 std::tie(std::ignore, new_address_a) = build_address();
109 std::tie(std::ignore, new_address_b) = build_address();
117 auto check_addbook_size = [&
wallet](
int expected_size) {
119 QCOMPARE(
static_cast<int>(
wallet->m_address_book.size()), expected_size);
123 check_addbook_size(2);
129 QVERIFY(optionsModel.Init(error));
136 editAddressDialog.setModel(walletModel.getAddressTableModel());
139 address_book.setModel(walletModel.getAddressTableModel());
140 auto table_view = address_book.findChild<QTableView*>(
"tableView");
141 QCOMPARE(table_view->model()->rowCount(), 1);
143 EditAddressAndSubmit(
144 &editAddressDialog, QString(
"uhoh"), preexisting_r_address,
146 "Address \"%1\" already exists as a receiving address with label "
147 "\"%2\" and so cannot be added as a sending address."
148 ).arg(preexisting_r_address).arg(r_label));
149 check_addbook_size(2);
150 QCOMPARE(table_view->model()->rowCount(), 1);
152 EditAddressAndSubmit(
153 &editAddressDialog, QString(
"uhoh, different"), preexisting_s_address,
155 "The entered address \"%1\" is already in the address book with "
157 ).arg(preexisting_s_address).arg(s_label));
158 check_addbook_size(2);
159 QCOMPARE(table_view->model()->rowCount(), 1);
163 EditAddressAndSubmit(
164 &editAddressDialog, QString(
"io - new A"), new_address_a, QString(
""));
165 check_addbook_size(3);
166 QCOMPARE(table_view->model()->rowCount(), 2);
168 EditAddressAndSubmit(
169 &editAddressDialog, QString(
"io - new B"), new_address_b, QString(
""));
170 check_addbook_size(4);
171 QCOMPARE(table_view->model()->rowCount(), 3);
173 auto search_line = address_book.findChild<QLineEdit*>(
"searchLineEdit");
175 search_line->setText(r_label);
176 QCOMPARE(table_view->model()->rowCount(), 0);
178 search_line->setText(s_label);
179 QCOMPARE(table_view->model()->rowCount(), 1);
181 search_line->setText(
"io");
182 QCOMPARE(table_view->model()->rowCount(), 2);
185 search_line->setText(
"io?new");
186 QCOMPARE(table_view->model()->rowCount(), 0);
187 search_line->setText(
"io???new");
188 QCOMPARE(table_view->model()->rowCount(), 2);
191 search_line->setText(
"io*new");
192 QCOMPARE(table_view->model()->rowCount(), 2);
193 search_line->setText(
"*");
194 QCOMPARE(table_view->model()->rowCount(), 3);
196 search_line->setText(preexisting_r_address);
197 QCOMPARE(table_view->model()->rowCount(), 0);
199 search_line->setText(preexisting_s_address);
200 QCOMPARE(table_view->model()->rowCount(), 1);
202 search_line->setText(new_address_a);
203 QCOMPARE(table_view->model()->rowCount(), 1);
205 search_line->setText(new_address_b);
206 QCOMPARE(table_view->model()->rowCount(), 1);
208 search_line->setText(
"");
209 QCOMPARE(table_view->model()->rowCount(), 3);
217 if (QApplication::platformName() ==
"minimal") {
222 qWarning() <<
"Skipping AddressBookTests on mac build with 'minimal' platform set due to Qt bugs. To run AppTests, invoke "
223 "with 'QT_QPA_PLATFORM=cocoa test_bitcoin-qt' on mac, or else use a linux or windows build.";
227 TestAddAddressesToSendBook(
m_node);
std::variant< CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, PayToAnchor, WitnessUnknown > CTxDestination
A txout script categorized into standard templates.
#define Assert(val)
Identity function.
Widget that shows a list of sending or receiving addresses.
@ ForEditing
Open address book for editing.
interfaces::Node & m_node
CPubKey GetPubKey() const
Compute the public key from a private key.
Model for Bitcoin network client.
Dialog for editing an address and associated information.
Interface from Qt to configuration data structure for Bitcoin client.
Line edit that can be marked as "invalid" to show input validation feedback.
Interface to Bitcoin wallet from Qt view code.
Top-level interface for a bitcoin node (bitcoind process).
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
CKey GenerateRandomKey(bool compressed) noexcept
std::string EncodeDestination(const CTxDestination &dest)
std::unique_ptr< WalletLoader > MakeWalletLoader(Chain &chain, ArgsManager &args)
Return implementation of ChainClient interface for a wallet loader.
std::unique_ptr< Wallet > MakeWallet(wallet::WalletContext &context, const std::shared_ptr< wallet::CWallet > &wallet)
Return implementation of Wallet interface.
std::unique_ptr< WalletDatabase > CreateMockableWalletDatabase(MockableData records)
bool AddWallet(WalletContext &context, const std::shared_ptr< CWallet > &wallet)
@ WALLET_FLAG_DESCRIPTORS
Indicate that this wallet supports DescriptorScriptPubKeyMan.
bool RemoveWallet(WalletContext &context, const std::shared_ptr< CWallet > &wallet, std::optional< bool > load_on_start, std::vector< bilingual_str > &warnings)
void ConfirmMessage(QString *text, std::chrono::milliseconds msec)
Press "Ok" button in message box dialog.
Testing fixture that pre-creates a 100-block REGTEST-mode block chain.
interfaces::WalletLoader * wallet_loader
std::unique_ptr< interfaces::Chain > chain
WalletContext struct containing references to state shared between CWallet instances,...