27 #include <QApplication> 29 #include <QMessageBox> 47 void 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 QWARN(
"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::unique_ptr< interfaces::Chain > chain
CPubKey GetPubKey() const
Compute the public key from a private key.
std::unique_ptr< Wallet > MakeWallet(wallet::WalletContext &context, const std::shared_ptr< wallet::CWallet > &wallet)
Return implementation of Wallet interface.
Open address book for editing.
Line edit that can be marked as "invalid" to show input validation feedback.
interfaces::Node & m_node
CKey GenerateRandomKey(bool compressed) noexcept
void ConfirmMessage(QString *text, std::chrono::milliseconds msec)
Press "Ok" button in message box dialog.
std::unique_ptr< WalletLoader > MakeWalletLoader(Chain &chain, ArgsManager &args)
Return implementation of ChainClient interface for a wallet loader.
Indicate that this wallet supports DescriptorScriptPubKeyMan.
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
Testing fixture that pre-creates a 100-block REGTEST-mode block chain.
Widget that shows a list of sending or receiving addresses.
Model for Bitcoin network client.
bool RemoveWallet(WalletContext &context, const std::shared_ptr< CWallet > &wallet, std::optional< bool > load_on_start, std::vector< bilingual_str > &warnings)
std::unique_ptr< WalletDatabase > CreateMockableWalletDatabase(MockableData records)
Interface from Qt to configuration data structure for Bitcoin client.
Interface to Bitcoin wallet from Qt view code.
std::variant< CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, PayToAnchor, WitnessUnknown > CTxDestination
A txout script categorized into standard templates.
Dialog for editing an address and associated information.
WalletContext struct containing references to state shared between CWallet instances, like the reference to the chain interface, and the list of opened wallets.
CTxDestination GetDestinationForKey(const CPubKey &key, OutputType type)
Get a destination of the requested type (if possible) to the specified key.
std::string EncodeDestination(const CTxDestination &dest)
An encapsulated private key.
std::shared_ptr< CWallet > wallet
interfaces::WalletLoader * wallet_loader
Top-level interface for a bitcoin node (bitcoind process).
bool AddWallet(WalletContext &context, const std::shared_ptr< CWallet > &wallet)
#define Assert(val)
Identity function.