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);
83 wallet->SetupDescriptorScriptPubKeyMans();
86 auto build_address{[]() {
94 QString preexisting_r_address;
95 QString r_label(
"already here (r)");
98 QString preexisting_s_address;
99 QString s_label(
"already here (s)");
102 QString new_address_a;
103 QString new_address_b;
105 std::tie(r_key_dest, preexisting_r_address) = build_address();
106 std::tie(s_key_dest, preexisting_s_address) = build_address();
107 std::tie(std::ignore, new_address_a) = build_address();
108 std::tie(std::ignore, new_address_b) = build_address();
116 auto check_addbook_size = [&
wallet](
int expected_size) {
118 QCOMPARE(
static_cast<int>(
wallet->m_address_book.size()), expected_size);
122 check_addbook_size(2);
128 QVERIFY(optionsModel.Init(error));
135 editAddressDialog.setModel(walletModel.getAddressTableModel());
138 address_book.setModel(walletModel.getAddressTableModel());
139 auto table_view = address_book.findChild<QTableView*>(
"tableView");
140 QCOMPARE(table_view->model()->rowCount(), 1);
142 EditAddressAndSubmit(
143 &editAddressDialog, QString(
"uhoh"), preexisting_r_address,
145 "Address \"%1\" already exists as a receiving address with label "
146 "\"%2\" and so cannot be added as a sending address."
147 ).arg(preexisting_r_address).arg(r_label));
148 check_addbook_size(2);
149 QCOMPARE(table_view->model()->rowCount(), 1);
151 EditAddressAndSubmit(
152 &editAddressDialog, QString(
"uhoh, different"), preexisting_s_address,
154 "The entered address \"%1\" is already in the address book with "
156 ).arg(preexisting_s_address).arg(s_label));
157 check_addbook_size(2);
158 QCOMPARE(table_view->model()->rowCount(), 1);
162 EditAddressAndSubmit(
163 &editAddressDialog, QString(
"io - new A"), new_address_a, QString(
""));
164 check_addbook_size(3);
165 QCOMPARE(table_view->model()->rowCount(), 2);
167 EditAddressAndSubmit(
168 &editAddressDialog, QString(
"io - new B"), new_address_b, QString(
""));
169 check_addbook_size(4);
170 QCOMPARE(table_view->model()->rowCount(), 3);
172 auto search_line = address_book.findChild<QLineEdit*>(
"searchLineEdit");
174 search_line->setText(r_label);
175 QCOMPARE(table_view->model()->rowCount(), 0);
177 search_line->setText(s_label);
178 QCOMPARE(table_view->model()->rowCount(), 1);
180 search_line->setText(
"io");
181 QCOMPARE(table_view->model()->rowCount(), 2);
184 search_line->setText(
"io?new");
185 QCOMPARE(table_view->model()->rowCount(), 0);
186 search_line->setText(
"io???new");
187 QCOMPARE(table_view->model()->rowCount(), 2);
190 search_line->setText(
"io*new");
191 QCOMPARE(table_view->model()->rowCount(), 2);
192 search_line->setText(
"*");
193 QCOMPARE(table_view->model()->rowCount(), 3);
195 search_line->setText(preexisting_r_address);
196 QCOMPARE(table_view->model()->rowCount(), 0);
198 search_line->setText(preexisting_s_address);
199 QCOMPARE(table_view->model()->rowCount(), 1);
201 search_line->setText(new_address_a);
202 QCOMPARE(table_view->model()->rowCount(), 1);
204 search_line->setText(new_address_b);
205 QCOMPARE(table_view->model()->rowCount(), 1);
207 search_line->setText(
"");
208 QCOMPARE(table_view->model()->rowCount(), 3);
216 if (QApplication::platformName() ==
"minimal") {
221 qWarning() <<
"Skipping AddressBookTests on mac build with 'minimal' platform set due to Qt bugs. To run AppTests, invoke "
222 "with 'QT_QPA_PLATFORM=cocoa test_bitcoin-qt' on mac, or else use a linux or windows build.";
226 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,...