Skip to content

Conversation

@jamesob
Copy link
Contributor

@jamesob jamesob commented Mar 29, 2018

Addresses #12796.

When a user attempts to add to the address book a sending address which is already present as a receiving address, they're presented with a confusing error indicating the address is already present in the book, despite the fact that this row is currently invisible.

selection_011

This change adds a more specific error message indicating its existence as a receiving address (as discussed in the linked issue).

selection_016

This change also adds some tests exercising use of the address book via QT. Adding so much test code for such a trivial change may seem weird, but it's my hope that this will make further test-writing for address book usage (and other QT features) more approachable.


if (bad_addr_purpose == "receive" &&
(mode == NewSendingAddress || mode == EditSendingAddress)) {
fmt_str = "Receiving address \"%1\" cannot be added as a sending address.";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible (or desirable) to include the label of the address that can't be added along with the raw address string in these error messages? Seems like this would provide more context.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's a good idea. Will add.

@jamesob jamesob force-pushed the 2018-03-27-send-recv-addressbook-error branch from 9af990a to 97318bc Compare March 30, 2018 14:04
@jamesob
Copy link
Contributor Author

jamesob commented Mar 30, 2018

Incorporated @ryanofsky's feedback and rebased (diff).

@jamesob jamesob force-pushed the 2018-03-27-send-recv-addressbook-error branch from 97318bc to af66060 Compare March 30, 2018 18:11
@promag
Copy link
Contributor

promag commented Apr 1, 2018

Concept ACK. Will review later.

@jamesob jamesob force-pushed the 2018-03-27-send-recv-addressbook-error branch from af66060 to a540696 Compare April 2, 2018 13:44
@jamesob
Copy link
Contributor Author

jamesob commented Apr 2, 2018

Fixed Travis failures (unchecked db_cxx.h include, whitespace) and rebased.

Copy link
Contributor

@jnewbery jnewbery left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested ACK a5406962daa18a20e21eda8b578bccfad1630fd4

Looks great. Thanks for the new tests!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would should

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, fixed.

@jamesob jamesob force-pushed the 2018-03-27-send-recv-addressbook-error branch from a540696 to 2d15e9c Compare April 2, 2018 15:27
@jamesob
Copy link
Contributor Author

jamesob commented Apr 2, 2018

Thanks for the review, @jnewbery. Typo fixed and rebased.

 $ diff -u <(git diff master...a540696) <(git diff master...2d15e9c)

--- /proc/self/fd/11    2018-04-02 11:30:04.855218939 -0400
+++ /proc/self/fd/12    2018-04-02 11:30:04.855218939 -0400
@@ -192,7 +192,7 @@
      Mode mode;
 diff --git a/src/qt/test/addressbooktests.cpp b/src/qt/test/addressbooktests.cpp
 new file mode 100644
-index 0000000000..bc9ace14d7
+index 0000000000..84c765e48a
 --- /dev/null
 +++ b/src/qt/test/addressbooktests.cpp
 @@ -0,0 +1,140 @@
@@ -243,7 +243,7 @@
 + *
 + * There are three cases tested:
 + *
-+ *   - new_address: a new address would should add as a send address successfully.
++ *   - new_address: a new address which should add as a send address successfully.
 + *   - existing_s_address: an existing sending address which won't add successfully.
 + *   - existing_r_address: an existing receiving address which won't add successfully.
 + *

@jnewbery
Copy link
Contributor

jnewbery commented Apr 2, 2018

reACK 2d15e9ce7d2ca4cc48ce0010e3c1c227a81f3b78

@jamesob jamesob force-pushed the 2018-03-27-send-recv-addressbook-error branch 2 times, most recently from c42cbc1 to 4e531b1 Compare April 9, 2018 20:46
@jamesob
Copy link
Contributor Author

jamesob commented Apr 9, 2018

Rebased, conflicts from the #10244 merge resolved.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This list of optional arguments slightly scares me. How much diff would it be to remove the defaults and change all the places this is called to pass in nullptr?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are ~9 replacements this'd entail, so not too bad. Willfix.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused?

qt/test/addressbooktests.cpp: In function ‘void {anonymous}::TestAddAddressesToSendBook()’:
qt/test/addressbooktests.cpp:109:24: warning: unused variable ‘addressTableModel’ [-Wunused-variable]
     AddressTableModel* addressTableModel = walletModel.getAddressTableModel();
                        ^

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is added in the wrong commit (commit Add tests for address book manipulation via EditAddressDialog instead of commit Introduce qt/test/util with a generalized ConfirmMessage). The intermediate commit fails linking.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for spotting this.

@jamesob jamesob force-pushed the 2018-03-27-send-recv-addressbook-error branch 2 times, most recently from ba55832 to 2251fdc Compare April 10, 2018 16:33
@jamesob
Copy link
Contributor Author

jamesob commented Apr 10, 2018

Rebased and addressed @jnewbery's feedback (thanks!):

  • Reworked getAddress definition and calls to remove use of default params (9db4652)
  • Moved the qt/test/util.cpp makefile inclusion to the right commit (82e8fce)
  • Removed the unused addressTableModel

Copy link
Contributor

@jnewbery jnewbery left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nearly there!


class AddressTablePriv;
class WalletModel;
class CAddressBookData;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forward declaration unused. Please remove

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks. Will spend some time figuring out a sensible clang-tidy config to catch this sort of stuff.

@jamesob jamesob force-pushed the 2018-03-27-send-recv-addressbook-error branch from 2251fdc to 41180ac Compare April 10, 2018 17:47
@jnewbery
Copy link
Contributor

utACK 41180ac. Good stuff!

"Address \"%1\" already exists as a receiving address with label "
"\"%2\" and so cannot be added as a sending address.";
}
return tr(fmt_str.c_str()).arg(ui->addressEdit->text()).arg(existing_label);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess with this, the new translation strings won't end up in the auto. generated translation source file?
Maybe use the tr().arg() part twice above or use the QT_TR_NOOP() (http://doc.qt.io/qt-5/qtglobal.html#QT_TR_NOOP)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, fixed.

@jamesob jamesob force-pushed the 2018-03-27-send-recv-addressbook-error branch from 41180ac to 2dd9606 Compare April 10, 2018 19:07
@jamesob
Copy link
Contributor Author

jamesob commented Apr 10, 2018

Incorporated @jonasschnelli's good feedback about tr() usage. I've also recompiled the EN qt locale with cd src/ && make translate and have squashed that in.

@jnewbery
Copy link
Contributor

utACK the change to editaddressdialog.cpp. Not sure about bitcoin_en.ts - is that something that usually gets changed in each commit, or just once before a release?

@jamesob
Copy link
Contributor Author

jamesob commented Apr 10, 2018

@jnewbery happy to revert the change to bitcoin_en.ts, but @jonasschnelli seemed to think it'd be best to squash them in. The documentation on translation also seems to suggest that the EN locale file should be changed in tandem with QT strings:

src/qt/locale/bitcoin_en.ts is treated in a special way. It is used as the source for all other translations. Whenever a string in the source code is changed, this file must be updated to reflect those changes.

@jamesob jamesob force-pushed the 2018-03-27-send-recv-addressbook-error branch from 2dd9606 to e6e1da3 Compare April 10, 2018 20:28
@jamesob
Copy link
Contributor Author

jamesob commented Apr 10, 2018

Reverted EN locale changes per @jonasschnelli's advice on IRC.

@jnewbery
Copy link
Contributor

utACK e6e1da33783408182e52fa73a11b6559ee0022f7

Copy link
Contributor

@jonasschnelli jonasschnelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK e6e1da33783408182e52fa73a11b6559ee0022f7

@jamesob
Copy link
Contributor Author

jamesob commented Apr 16, 2018

Any other feedback here?

jamesob added 4 commits April 25, 2018 13:08
Also make all arguments to getAddress required and document args at call sites.
Addresses bitcoin#12796.

When we're unable to add a sending address to the address book because it
already exists as a receiving address, display a message indicating as much.
This should help avoid confusion about an address supposedly already in the
book but which isn't currently visible in the interface.
ConfirmMessage is reused in future tests apart from its single usage here.
…ialog

Also modifies corresponding QT code to allow for use within test cases.
@jamesob jamesob force-pushed the 2018-03-27-send-recv-addressbook-error branch from e6e1da3 to 5109fc4 Compare April 25, 2018 17:13
@laanwj
Copy link
Member

laanwj commented Apr 25, 2018

utACK 5109fc4

@laanwj laanwj merged commit 5109fc4 into bitcoin:master Apr 25, 2018
laanwj added a commit that referenced this pull request Apr 25, 2018
…ests

5109fc4 [tests] [qt] Add tests for address book manipulation via EditAddressDialog (James O'Beirne)
9c01be1 [tests] [qt] Introduce qt/test/util with a generalized ConfirmMessage (James O'Beirne)
8cdcaee [qt] Display more helpful message when adding a send address has failed (James O'Beirne)
c5b2770 Add purpose arg to Wallet::getAddress (James O'Beirne)

Pull request description:

  Addresses #12796.

  When a user attempts to add to the address book a sending address which is already present as a receiving address, they're presented with a confusing error indicating the address is already present in the book, despite the fact that this row is currently invisible.

  ![selection_011](https://user-images.githubusercontent.com/73197/38096704-8a2948d2-3341-11e8-9632-7d563201f28c.jpg)

  This change adds a more specific error message indicating its existence as a receiving address (as discussed in the linked issue).

  ![selection_016](https://user-images.githubusercontent.com/73197/38198467-fa26164e-365a-11e8-8fc5-ddab9caf2fbd.jpg)

  This change also adds some tests exercising use of the address book via QT. Adding so much test code for such a trivial change may seem weird, but it's my hope that this will make further test-writing for address book usage (and other QT features) more approachable.

Tree-SHA512: fbdd5564f7a9a2380bbe437f3378e8d4d5fd9201efff4879b72bc23f2cc1c2eecaf2b811994c25070ee052422e48e47901787c2e62cc584774a997fe6a2a327a
Copy link
Contributor

@jimpo jimpo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In commit [tests] [qt] Introduce qt/test/util with a generalized ConfirmMessage, new files are missing copyright notice headers.

I tried testing manually. The error message when adding a new address works as expected. However, when editing an existing address book entry and changing the address, the behavior is pretty funky. If the address was previously in the address book, it will close the dialog and do nothing, displaying no error. If it is not in the address book, it will edit the entry but also change the label to the address, despite the label in the form not changing.


bool isMultiwallet();

AddressTableModel* getAddressTableModel() const { return addressTableModel; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commit: [tests] [qt] Add tests for address book manipulation via EditAddressDialog

This method is already defined on line 139 but without const. I think the non-const variant is actually better because it returns a non-const pointer. (While technically allowed, it feels wrong to me to return a non-const pointer to a member from a const method).

bool firstRun;
wallet.LoadWallet(firstRun);

auto build_address = [&wallet]() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commit: [tests] [qt] Add tests for address book manipulation via EditAddressDialog

nit: Any particular reason for this to be a lambda expression instead of a regular function in the anonymous namespace?

wallet.SetAddressBook(s_key_dest, s_label.toStdString(), "send");
}

auto check_addbook_size = [&wallet](int expected_size) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Also could be a regular function.

check_addbook_size(2);

// Initialize relevant QT models.
std::unique_ptr<const PlatformStyle> platformStyle(PlatformStyle::instantiate("other"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commit: [tests] [qt] Add tests for address book manipulation via EditAddressDialog

nit: camelCase vs snake_case of local variables in this function is inconsistent (r_key_dest vs platformStyle). I think snake_case is preferred for new code.

@promag promag mentioned this pull request Apr 29, 2018
UdjinM6 pushed a commit to UdjinM6/dash that referenced this pull request May 22, 2021
…, add tests

5109fc4 [tests] [qt] Add tests for address book manipulation via EditAddressDialog (James O'Beirne)
9c01be1 [tests] [qt] Introduce qt/test/util with a generalized ConfirmMessage (James O'Beirne)
8cdcaee [qt] Display more helpful message when adding a send address has failed (James O'Beirne)
c5b2770 Add purpose arg to Wallet::getAddress (James O'Beirne)

Pull request description:

  Addresses bitcoin#12796.

  When a user attempts to add to the address book a sending address which is already present as a receiving address, they're presented with a confusing error indicating the address is already present in the book, despite the fact that this row is currently invisible.

  ![selection_011](https://user-images.githubusercontent.com/73197/38096704-8a2948d2-3341-11e8-9632-7d563201f28c.jpg)

  This change adds a more specific error message indicating its existence as a receiving address (as discussed in the linked issue).

  ![selection_016](https://user-images.githubusercontent.com/73197/38198467-fa26164e-365a-11e8-8fc5-ddab9caf2fbd.jpg)

  This change also adds some tests exercising use of the address book via QT. Adding so much test code for such a trivial change may seem weird, but it's my hope that this will make further test-writing for address book usage (and other QT features) more approachable.

Tree-SHA512: fbdd5564f7a9a2380bbe437f3378e8d4d5fd9201efff4879b72bc23f2cc1c2eecaf2b811994c25070ee052422e48e47901787c2e62cc584774a997fe6a2a327a
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants