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]() {
99 QString preexisting_r_address;
100 QString r_label(
"already here (r)");
103 QString preexisting_s_address;
104 QString s_label(
"already here (s)");
107 QString new_address_a;
108 QString new_address_b;
110 std::tie(r_key_dest, preexisting_r_address) = build_address();
111 std::tie(s_key_dest, preexisting_s_address) = build_address();
112 std::tie(std::ignore, new_address_a) = build_address();
113 std::tie(std::ignore, new_address_b) = build_address();
121 auto check_addbook_size = [&
wallet](
int expected_size) {
123 QCOMPARE(static_cast<int>(
wallet->m_address_book.size()), expected_size);
127 check_addbook_size(2);
133 QVERIFY(optionsModel.Init(
error));
140 editAddressDialog.setModel(walletModel.getAddressTableModel());
143 address_book.setModel(walletModel.getAddressTableModel());
144 auto table_view = address_book.findChild<QTableView*>(
"tableView");
145 QCOMPARE(table_view->model()->rowCount(), 1);
147 EditAddressAndSubmit(
148 &editAddressDialog, QString(
"uhoh"), preexisting_r_address,
150 "Address \"%1\" already exists as a receiving address with label " 151 "\"%2\" and so cannot be added as a sending address." 152 ).arg(preexisting_r_address).arg(r_label));
153 check_addbook_size(2);
154 QCOMPARE(table_view->model()->rowCount(), 1);
156 EditAddressAndSubmit(
157 &editAddressDialog, QString(
"uhoh, different"), preexisting_s_address,
159 "The entered address \"%1\" is already in the address book with " 161 ).arg(preexisting_s_address).arg(s_label));
162 check_addbook_size(2);
163 QCOMPARE(table_view->model()->rowCount(), 1);
167 EditAddressAndSubmit(
168 &editAddressDialog, QString(
"io - new A"), new_address_a, QString(
""));
169 check_addbook_size(3);
170 QCOMPARE(table_view->model()->rowCount(), 2);
172 EditAddressAndSubmit(
173 &editAddressDialog, QString(
"io - new B"), new_address_b, QString(
""));
174 check_addbook_size(4);
175 QCOMPARE(table_view->model()->rowCount(), 3);
177 auto search_line = address_book.findChild<QLineEdit*>(
"searchLineEdit");
179 search_line->setText(r_label);
180 QCOMPARE(table_view->model()->rowCount(), 0);
182 search_line->setText(s_label);
183 QCOMPARE(table_view->model()->rowCount(), 1);
185 search_line->setText(
"io");
186 QCOMPARE(table_view->model()->rowCount(), 2);
189 search_line->setText(
"io?new");
190 QCOMPARE(table_view->model()->rowCount(), 0);
191 search_line->setText(
"io???new");
192 QCOMPARE(table_view->model()->rowCount(), 2);
195 search_line->setText(
"io*new");
196 QCOMPARE(table_view->model()->rowCount(), 2);
197 search_line->setText(
"*");
198 QCOMPARE(table_view->model()->rowCount(), 3);
200 search_line->setText(preexisting_r_address);
201 QCOMPARE(table_view->model()->rowCount(), 0);
203 search_line->setText(preexisting_s_address);
204 QCOMPARE(table_view->model()->rowCount(), 1);
206 search_line->setText(new_address_a);
207 QCOMPARE(table_view->model()->rowCount(), 1);
209 search_line->setText(new_address_b);
210 QCOMPARE(table_view->model()->rowCount(), 1);
212 search_line->setText(
"");
213 QCOMPARE(table_view->model()->rowCount(), 3);
221 if (QApplication::platformName() ==
"minimal") {
226 QWARN(
"Skipping AddressBookTests on mac build with 'minimal' platform set due to Qt bugs. To run AppTests, invoke " 227 "with 'QT_QPA_PLATFORM=cocoa test_bitcoin-qt' on mac, or else use a linux or windows build.");
231 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
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.
void MakeNewKey(bool fCompressed)
Generate a new private key using a cryptographic PRNG.
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::variant< CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown > CTxDestination
A txout script categorized into standard templates.
std::unique_ptr< WalletDatabase > CreateMockableWalletDatabase(MockableData records)
Interface from Qt to configuration data structure for Bitcoin client.
bool error(const char *fmt, const Args &... args)
Interface to Bitcoin wallet from Qt view code.
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
Reference to chain client that should used to load or create wallets opened by the gui...
Top-level interface for a bitcoin node (bitcoind process).
bool AddWallet(WalletContext &context, const std::shared_ptr< CWallet > &wallet)
#define Assert(val)
Identity function.