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 = [&
wallet]() {
98 QString preexisting_r_address;
99 QString r_label(
"already here (r)");
102 QString preexisting_s_address;
103 QString s_label(
"already here (s)");
106 QString new_address_a;
107 QString new_address_b;
109 std::tie(r_key_dest, preexisting_r_address) = build_address();
110 std::tie(s_key_dest, preexisting_s_address) = build_address();
111 std::tie(std::ignore, new_address_a) = build_address();
112 std::tie(std::ignore, new_address_b) = build_address();
120 auto check_addbook_size = [&
wallet](
int expected_size) {
122 QCOMPARE(
static_cast<int>(
wallet->m_address_book.size()), expected_size);
126 check_addbook_size(2);
132 QVERIFY(optionsModel.Init(error));
139 editAddressDialog.setModel(walletModel.getAddressTableModel());
142 address_book.setModel(walletModel.getAddressTableModel());
143 auto table_view = address_book.findChild<QTableView*>(
"tableView");
144 QCOMPARE(table_view->model()->rowCount(), 1);
146 EditAddressAndSubmit(
147 &editAddressDialog, QString(
"uhoh"), preexisting_r_address,
149 "Address \"%1\" already exists as a receiving address with label "
150 "\"%2\" and so cannot be added as a sending address."
151 ).arg(preexisting_r_address).arg(r_label));
152 check_addbook_size(2);
153 QCOMPARE(table_view->model()->rowCount(), 1);
155 EditAddressAndSubmit(
156 &editAddressDialog, QString(
"uhoh, different"), preexisting_s_address,
158 "The entered address \"%1\" is already in the address book with "
160 ).arg(preexisting_s_address).arg(s_label));
161 check_addbook_size(2);
162 QCOMPARE(table_view->model()->rowCount(), 1);
166 EditAddressAndSubmit(
167 &editAddressDialog, QString(
"io - new A"), new_address_a, QString(
""));
168 check_addbook_size(3);
169 QCOMPARE(table_view->model()->rowCount(), 2);
171 EditAddressAndSubmit(
172 &editAddressDialog, QString(
"io - new B"), new_address_b, QString(
""));
173 check_addbook_size(4);
174 QCOMPARE(table_view->model()->rowCount(), 3);
176 auto search_line = address_book.findChild<QLineEdit*>(
"searchLineEdit");
178 search_line->setText(r_label);
179 QCOMPARE(table_view->model()->rowCount(), 0);
181 search_line->setText(s_label);
182 QCOMPARE(table_view->model()->rowCount(), 1);
184 search_line->setText(
"io");
185 QCOMPARE(table_view->model()->rowCount(), 2);
188 search_line->setText(
"io?new");
189 QCOMPARE(table_view->model()->rowCount(), 0);
190 search_line->setText(
"io???new");
191 QCOMPARE(table_view->model()->rowCount(), 2);
194 search_line->setText(
"io*new");
195 QCOMPARE(table_view->model()->rowCount(), 2);
196 search_line->setText(
"*");
197 QCOMPARE(table_view->model()->rowCount(), 3);
199 search_line->setText(preexisting_r_address);
200 QCOMPARE(table_view->model()->rowCount(), 0);
202 search_line->setText(preexisting_s_address);
203 QCOMPARE(table_view->model()->rowCount(), 1);
205 search_line->setText(new_address_a);
206 QCOMPARE(table_view->model()->rowCount(), 1);
208 search_line->setText(new_address_b);
209 QCOMPARE(table_view->model()->rowCount(), 1);
211 search_line->setText(
"");
212 QCOMPARE(table_view->model()->rowCount(), 3);
220 if (QApplication::platformName() ==
"minimal") {
225 qWarning() <<
"Skipping AddressBookTests on mac build with 'minimal' platform set due to Qt bugs. To run AppTests, invoke "
226 "with 'QT_QPA_PLATFORM=cocoa test_bitcoin-qt' on mac, or else use a linux or windows build.";
230 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
An encapsulated private key.
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)
CTxDestination GetDestinationForKey(const CPubKey &key, OutputType type)
Get a destination of the requested type (if possible) to the specified key.
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,...