-
Notifications
You must be signed in to change notification settings - Fork 37.7k
[test] fundrawtransaction: lock watch-only shared address #12265
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] fundrawtransaction: lock watch-only shared address #12265
Conversation
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.
Concept ACK.
Another approach is to use listunspent --addresses [watchonly_address]
.
Either way maybe you could extract this "lock unspents by txid and address" to a separate function, it sure makes the test easier to read and might be useful elsewhere.
e3c9a2b
to
3e5644b
Compare
@promag That's a good point. I moved parts of it into util as |
@@ -472,6 +488,8 @@ def run_test(self): | |||
connect_nodes_bi(self.nodes,1,2) | |||
connect_nodes_bi(self.nodes,0,2) | |||
connect_nodes_bi(self.nodes,0,3) | |||
# Again lock the watchonly UTXO or nodes[0] may spend it | |||
self.nodes[0].lockunspent(False, [{"txid": watchonly_txid, "vout": watchonly_vout}]) |
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, add comment like "because restarting a node looses the locked unspents" (you may find better wording).
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.
Done!
3e5644b
to
167e6a5
Compare
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.
ACK.
Just want to point that if *rawtransaction
were used instead of sendtoaddress
then the vout would be known.
""" | ||
tx = node.getrawtransaction(txid, True) | ||
for i in range(len(tx["vout"])): | ||
o = tx["vout"][i] |
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, inline o
below (only used once).
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.
Good point. Fixed.
167e6a5
to
f3ebd07
Compare
utACK - can you please change the commit message of f3ebd07 to the format
Otherwise tooling that parses the commit messages will make it into one long title. |
f3ebd07
to
8477b83
Compare
@laanwj Oops, didn't realize you needed an empty line. Fixed. |
|
||
# Lock UTXO so nodes[0] doesn't accidentally spend it | ||
watchonly_vout = find_vout_for_address(self.nodes[0], watchonly_txid, watchonly_address) | ||
assert watchonly_vout != -1 # it must exist |
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.
You can move the assert into find_vout_for_address
.
If you don't want to do that, note that python is not type safe, so you don't have to return an integer. None
works just fine.
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.
You mean assert watchonly_vout is not None
and not return anything in find_v..
?
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.
Actually nevermind, I'll move the assert instead.
8477b83
to
7309980
Compare
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.
Tested ACK 73099805915ad11b264bc22040015eb3ac137b2b with one nit.
Commits can be squashed IMO.
@@ -5,7 +5,17 @@ | |||
"""Test the fundrawtransaction RPC.""" | |||
|
|||
from test_framework.test_framework import BitcoinTestFramework | |||
from test_framework.util import * | |||
from decimal import Decimal |
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: please place standard library imports above local project imports
self.nodes[0] creates an address which is watch-only-shared with self.nodes[3]. If nodes[0] spends the associated UTXO during any of its sends later, the watchonly test will fail, as nodes[3] now has insufficient funds. Note that this also adds a new find_vout_for_address function to the test framework.
7309980
to
891beb0
Compare
@jnewbery Squashed. I kept them split to make it obvious to reviewers that I am adding a new utility function, not just fixing something in a specific test. |
utACK 891beb0. |
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.
Tested ACK 891beb0
given address. Raises runtime error exception if not found. | ||
""" | ||
tx = node.getrawtransaction(txid, True) | ||
for i in range(len(tx["vout"])): |
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.
Alternatively:
for i, vout in enumerate(tx["vout"]):
if any([addr == a for a in vout["scriptPubKey"]["addresses"]]):
return i
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.
Thanks! It doesn't feel strictly necessary but it's marginally better. Will do if this needs a rebase or gets more requests for other changes.
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.
Agreed, no need to change the branch for just this change
utACK 891beb0 |
891beb0 [test] fundrawtransaction: lock watch-only shared address (Karl-Johan Alm) Pull request description: `self.nodes[0]` creates an address which is watch-only-shared with `self.nodes[3]`. If `nodes[0]` spends the associated UTXO during any of its sends later, the watchonly test will fail, as `nodes[3]` now has insufficient funds. I ran into this in #12257 and this commit is in that PR as well, but I figured I'd split it out (and remove from there once/if merged). Tree-SHA512: d04a04b1ecebe82127cccd47c1b3de311bf07f4b51dff80db20ea2f142e1d5c4a85ed6180c5c0b081d550e238c742e119b953f60f487deac5a3f3536e1a8d9fe
Summary: 891beb0 [test] fundrawtransaction: lock watch-only shared address (Karl-Johan Alm) Pull request description: `self.nodes[0]` creates an address which is watch-only-shared with `self.nodes[3]`. If `nodes[0]` spends the associated UTXO during any of its sends later, the watchonly test will fail, as `nodes[3]` now has insufficient funds. I ran into this in #12257 and this commit is in that PR as well, but I figured I'd split it out (and remove from there once/if merged). Tree-SHA512: d04a04b1ecebe82127cccd47c1b3de311bf07f4b51dff80db20ea2f142e1d5c4a85ed6180c5c0b081d550e238c742e119b953f60f487deac5a3f3536e1a8d9fe Backport of Core PR12265 bitcoin/bitcoin#12265 Test Plan: test_runner.py Reviewers: deadalnix, Fabien, jasonbcox, O1 Bitcoin ABC, #bitcoin_abc Reviewed By: deadalnix, O1 Bitcoin ABC, #bitcoin_abc Differential Revision: https://reviews.bitcoinabc.org/D4153
…d address 891beb0 [test] fundrawtransaction: lock watch-only shared address (Karl-Johan Alm) Pull request description: `self.nodes[0]` creates an address which is watch-only-shared with `self.nodes[3]`. If `nodes[0]` spends the associated UTXO during any of its sends later, the watchonly test will fail, as `nodes[3]` now has insufficient funds. I ran into this in bitcoin#12257 and this commit is in that PR as well, but I figured I'd split it out (and remove from there once/if merged). Tree-SHA512: d04a04b1ecebe82127cccd47c1b3de311bf07f4b51dff80db20ea2f142e1d5c4a85ed6180c5c0b081d550e238c742e119b953f60f487deac5a3f3536e1a8d9fe
…d address 891beb0 [test] fundrawtransaction: lock watch-only shared address (Karl-Johan Alm) Pull request description: `self.nodes[0]` creates an address which is watch-only-shared with `self.nodes[3]`. If `nodes[0]` spends the associated UTXO during any of its sends later, the watchonly test will fail, as `nodes[3]` now has insufficient funds. I ran into this in bitcoin#12257 and this commit is in that PR as well, but I figured I'd split it out (and remove from there once/if merged). Tree-SHA512: d04a04b1ecebe82127cccd47c1b3de311bf07f4b51dff80db20ea2f142e1d5c4a85ed6180c5c0b081d550e238c742e119b953f60f487deac5a3f3536e1a8d9fe
…d address 891beb0 [test] fundrawtransaction: lock watch-only shared address (Karl-Johan Alm) Pull request description: `self.nodes[0]` creates an address which is watch-only-shared with `self.nodes[3]`. If `nodes[0]` spends the associated UTXO during any of its sends later, the watchonly test will fail, as `nodes[3]` now has insufficient funds. I ran into this in bitcoin#12257 and this commit is in that PR as well, but I figured I'd split it out (and remove from there once/if merged). Tree-SHA512: d04a04b1ecebe82127cccd47c1b3de311bf07f4b51dff80db20ea2f142e1d5c4a85ed6180c5c0b081d550e238c742e119b953f60f487deac5a3f3536e1a8d9fe
…d address 891beb0 [test] fundrawtransaction: lock watch-only shared address (Karl-Johan Alm) Pull request description: `self.nodes[0]` creates an address which is watch-only-shared with `self.nodes[3]`. If `nodes[0]` spends the associated UTXO during any of its sends later, the watchonly test will fail, as `nodes[3]` now has insufficient funds. I ran into this in bitcoin#12257 and this commit is in that PR as well, but I figured I'd split it out (and remove from there once/if merged). Tree-SHA512: d04a04b1ecebe82127cccd47c1b3de311bf07f4b51dff80db20ea2f142e1d5c4a85ed6180c5c0b081d550e238c742e119b953f60f487deac5a3f3536e1a8d9fe
self.nodes[0]
creates an address which is watch-only-shared withself.nodes[3]
. Ifnodes[0]
spends the associated UTXO during any of its sends later, the watchonly test will fail, asnodes[3]
now has insufficient funds.I ran into this in #12257 and this commit is in that PR as well, but I figured I'd split it out (and remove from there once/if merged).