-
Notifications
You must be signed in to change notification settings - Fork 38.6k
test: add unit test for wallet watch-only methods involving PubKeys #16786
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: add unit test for wallet watch-only methods involving PubKeys #16786
Conversation
|
This is currently failing on Travis: wallet/test/wallet_tests.cpp(381): Entering test case "WatchOnlyPubKeys"
Assertion failed: lock cs_wallet not held in wallet/wallet.cpp:578; locks held:
unknown location(0): fatal error: in "wallet_tests/WatchOnlyPubKeys": signal: SIGABRT (application abort requested)
wallet/test/wallet_tests.cpp(357): last checkpoint
wallet/test/wallet_tests.cpp(381): Leaving test case "WatchOnlyPubKeys"; testing time: 138195uswallet/test/wallet_tests.cpp:362:5: error: calling function 'RemoveWatchOnly' requires holding mutex 'wallet.cs_wallet' exclusively [-Werror,-Wthread-safety-analysis]
wallet.RemoveWatchOnly(p2pk);
^
1 error generated.You'll need to add some locking |
Thanks, done (f74dc7ea05cf466077c6f46910ae4228373656e4). It took me quite a while to reproduce this warning, obviously it only appears compiling with clang (which makes sense after looking at src/threadsafety.h, where all the defines like e.g. EXCLUSIVE_LOCKS_REQUIRED are empty for g++). |
src/wallet/test/wallet_tests.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe also assert what found_pubkey ends up being in this situation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
found_pubkey isn't touched when no PubKey is found, but of course this fact can be tested as well by asserting it to be a newly constructed (and thus invalid) PubKey.
|
you should just squash the 2 commits together |
f74dc7e to
d0e1d33
Compare
src/wallet/test/wallet_tests.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: braces
As above, you should also check that found_pubkey is the default CPubKey.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since GetWatchPubKey doesn't modify the passed PubKey if it returns false, it would still have the same contents as before, so in this case the correct assertion would be found_pubkey == add_pubkey. To not confuse the reader (one could wrongly assume that this assert checks for an explicit modification by the function in this case as well), I add the comment // passed key is unchanged for those two cases.
d613804 to
3a219e8
Compare
instagibbs
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK
achow101
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review ACK 3a219e82304c7f62d75369d6ee55111f601cc892
The motivation for this addition was to unit test the function wallet.cpp:ExtractPubKey() (see recent change in commit 798a589) which is however static and only indirectly available via the public methods AddWatchOnly(), LoadWatchOnly() and RemoveWatchOnly(). Since the first of those methods also stores the addresses to the disk, the second, simpler one was chosen which only operates in memory. test: add missing wallet lock for test case WatchOnlyPubKeys test: test case WatchOnlyPubKeys, suggested review changes by instagibbs test: test case WatchOnlyPubKeys, suggested review changes by achow101 test: test case WatchOnlyPubKeys, s/isPubKeyFullyValid/is_pubkey_fully_valid
601698c to
a57a1d4
Compare
|
@instagibbs @achow101 Thanks for your reviews! |
|
ACK a57a1d4 As an aside, in case anyone wants to test P2PK functionality (on testnet), here's a fun tool: https://github.com/dianerey/bech32p2pkaddress (no need to provide inputs in the Python script, just use When you import a pubkey using Although the above scenarios are rather contrived, should we have some RPC methods check if a pubkey is on a curve? |
|
@Sjors: Thanks for the review!
Are you sure that
|
|
Oops, I just changed one character in the pubkey hex thinking that would do the trick, but of course with a compressed pubkey such a tweaked point is most likely still on the curve.
|
Okay 👍
Looking at the code, |
|
Since there has been no activity for three weeks: is there anything else I can do for this PR? |
|
reACK a57a1d4 just squashed |
Sjors
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re-ACK a57a1d4
…ving PubKeys a57a1d4 test: add unit test for wallet watch-only methods involving PubKeys (Sebastian Falbesoner) Pull request description: The motivation for this addition was to unit test the function `wallet.cpp:ExtractPubKey()` (see recent change in commit 798a589) which is however static and only indirectly available via the public methods `AddWatchOnly()`, `LoadWatchOnly()` and `RemoveWatchOnly()`. Since the first of those methods also stores the addresses to the disk, the second, simpler one was chosen which only operates in memory. ACKs for top commit: Sjors: ACK a57a1d4 instagibbs: reACK a57a1d4 Sjors: re-ACK a57a1d4 Tree-SHA512: 92a242204ab533022cd848662997372c41815b1265d07b3d96305697f801db29a5ba5668337faf4bea702bec1451972529afd6665927fb142aaf91700a338b26
…s involving PubKeys a57a1d4 test: add unit test for wallet watch-only methods involving PubKeys (Sebastian Falbesoner) Pull request description: The motivation for this addition was to unit test the function `wallet.cpp:ExtractPubKey()` (see recent change in commit 798a589) which is however static and only indirectly available via the public methods `AddWatchOnly()`, `LoadWatchOnly()` and `RemoveWatchOnly()`. Since the first of those methods also stores the addresses to the disk, the second, simpler one was chosen which only operates in memory. ACKs for top commit: Sjors: ACK a57a1d4 instagibbs: reACK bitcoin@a57a1d4 Sjors: re-ACK a57a1d4 Tree-SHA512: 92a242204ab533022cd848662997372c41815b1265d07b3d96305697f801db29a5ba5668337faf4bea702bec1451972529afd6665927fb142aaf91700a338b26
…s involving PubKeys a57a1d4 test: add unit test for wallet watch-only methods involving PubKeys (Sebastian Falbesoner) Pull request description: The motivation for this addition was to unit test the function `wallet.cpp:ExtractPubKey()` (see recent change in commit 798a589) which is however static and only indirectly available via the public methods `AddWatchOnly()`, `LoadWatchOnly()` and `RemoveWatchOnly()`. Since the first of those methods also stores the addresses to the disk, the second, simpler one was chosen which only operates in memory. ACKs for top commit: Sjors: ACK a57a1d4 instagibbs: reACK bitcoin@a57a1d4 Sjors: re-ACK a57a1d4 Tree-SHA512: 92a242204ab533022cd848662997372c41815b1265d07b3d96305697f801db29a5ba5668337faf4bea702bec1451972529afd6665927fb142aaf91700a338b26
The motivation for this addition was to unit test the function
wallet.cpp:ExtractPubKey()(see recent change in commit 798a589) which is however static and only indirectly available via the public methodsAddWatchOnly(),LoadWatchOnly()andRemoveWatchOnly(). Since the first of those methods also stores the addresses to the disk, the second, simpler one was chosen which only operates in memory.