[test] fundrawtransaction: lock watch-only shared address #12265

pull kallewoof wants to merge 1 commits into bitcoin:master from kallewoof:test-fundrawtransaction-lockunspent changing 2 files +30 −1
  1. kallewoof commented at 2:04 AM on January 25, 2018: member

    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).

  2. fanquake added the label Tests on Jan 25, 2018
  3. promag commented at 9:52 AM on January 25, 2018: member

    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.

  4. kallewoof force-pushed on Jan 25, 2018
  5. kallewoof commented at 10:08 AM on January 25, 2018: member

    @promag That's a good point. I moved parts of it into util as find_vout_for_address.

  6. in test/functional/rpc_fundrawtransaction.py:492 in 3e5644b3c3 outdated
     487 | @@ -472,6 +488,8 @@ def run_test(self):
     488 |          connect_nodes_bi(self.nodes,1,2)
     489 |          connect_nodes_bi(self.nodes,0,2)
     490 |          connect_nodes_bi(self.nodes,0,3)
     491 | +        # Again lock the watchonly UTXO or nodes[0] may spend it
     492 | +        self.nodes[0].lockunspent(False, [{"txid": watchonly_txid, "vout": watchonly_vout}])
    


    promag commented at 10:16 AM on January 25, 2018:

    Nit, add comment like "because restarting a node looses the locked unspents" (you may find better wording).


    kallewoof commented at 10:21 AM on January 25, 2018:

    Done!

  7. kallewoof force-pushed on Jan 25, 2018
  8. in test/functional/test_framework/util.py:581 in 167e6a5c9b outdated
     576 | +    given address.
     577 | +    Returns -1 if not found, or the vout (index) if found.
     578 | +    """
     579 | +    tx = node.getrawtransaction(txid, True)
     580 | +    for i in range(len(tx["vout"])):
     581 | +        o = tx["vout"][i]
    


    promag commented at 10:38 AM on January 25, 2018:

    Nit, inline o below (only used once).


    kallewoof commented at 11:10 PM on January 25, 2018:

    Good point. Fixed.

  9. promag commented at 10:40 AM on January 25, 2018: member

    ACK.

    Just want to point that if *rawtransaction were used instead of sendtoaddress then the vout would be known.

  10. kallewoof force-pushed on Jan 25, 2018
  11. laanwj commented at 4:37 PM on February 15, 2018: member

    utACK - can you please change the commit message of f3ebd07 to the format

    <title (one line)>
    <empty line>
    <description... (possibly multiple lines)>
    

    Otherwise tooling that parses the commit messages will make it into one long title.

  12. kallewoof force-pushed on Feb 16, 2018
  13. kallewoof commented at 1:36 AM on February 16, 2018: member

    @laanwj Oops, didn't realize you needed an empty line. Fixed.

  14. in test/functional/rpc_fundrawtransaction.py:73 in 8477b83a5f outdated
      66 | @@ -57,6 +67,12 @@ def run_test(self):
      67 |          watchonly_amount = Decimal(200)
      68 |          self.nodes[3].importpubkey(watchonly_pubkey, "", True)
      69 |          watchonly_txid = self.nodes[0].sendtoaddress(watchonly_address, watchonly_amount)
      70 | +
      71 | +        # Lock UTXO so nodes[0] doesn't accidentally spend it
      72 | +        watchonly_vout = find_vout_for_address(self.nodes[0], watchonly_txid, watchonly_address)
      73 | +        assert watchonly_vout != -1 # it must exist
    


    MarcoFalke commented at 4:10 AM on February 16, 2018:

    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.


    kallewoof commented at 4:13 AM on February 16, 2018:

    You mean assert watchonly_vout is not None and not return anything in find_v..?


    kallewoof commented at 4:14 AM on February 16, 2018:

    Actually nevermind, I'll move the assert instead.

  15. kallewoof force-pushed on Feb 16, 2018
  16. in test/functional/rpc_fundrawtransaction.py:7 in 7309980591 outdated
       4 | @@ -5,7 +5,17 @@
       5 |  """Test the fundrawtransaction RPC."""
       6 |  
       7 |  from test_framework.test_framework import BitcoinTestFramework
       8 | -from test_framework.util import *
       9 | +from decimal import Decimal
    


    jnewbery commented at 6:05 PM on April 4, 2018:

    nit: please place standard library imports above local project imports

  17. jnewbery commented at 6:18 PM on April 4, 2018: member

    Tested ACK 73099805915ad11b264bc22040015eb3ac137b2b with one nit.

    Commits can be squashed IMO.

  18. [test] fundrawtransaction: lock watch-only shared address
    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.
    891beb0f8a
  19. kallewoof force-pushed on Apr 6, 2018
  20. kallewoof commented at 4:34 AM on April 6, 2018: member

    @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.

  21. promag commented at 11:54 AM on April 6, 2018: member

    utACK 891beb0.

  22. in test/functional/test_framework/util.py:579 in 891beb0f8a
     574 | +    """
     575 | +    Locate the vout index of the given transaction sending to the
     576 | +    given address. Raises runtime error exception if not found.
     577 | +    """
     578 | +    tx = node.getrawtransaction(txid, True)
     579 | +    for i in range(len(tx["vout"])):
    


    jnewbery commented at 7:48 PM on April 9, 2018:

    Alternatively:

        for i, vout in enumerate(tx["vout"]):
            if any([addr == a for a in vout["scriptPubKey"]["addresses"]]):
                return i
    

    kallewoof commented at 2:18 AM on April 10, 2018:

    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.


    jnewbery commented at 1:28 PM on April 10, 2018:

    Agreed, no need to change the branch for just this change

  23. jnewbery commented at 7:48 PM on April 9, 2018: member

    Tested ACK 891beb0f8a09810b179e39a680b579c2f6516db7

  24. laanwj merged this on May 9, 2018
  25. laanwj closed this on May 9, 2018

  26. laanwj referenced this in commit 1834d4d9f0 on May 9, 2018
  27. kallewoof deleted the branch on May 9, 2018
  28. jasonbcox referenced this in commit 84472df3da on Sep 27, 2019
  29. PastaPastaPasta referenced this in commit beb7b975d6 on Jun 17, 2020
  30. PastaPastaPasta referenced this in commit 0425b71610 on Jun 27, 2020
  31. PastaPastaPasta referenced this in commit a5275cb868 on Jun 28, 2020
  32. PastaPastaPasta referenced this in commit ffb4158774 on Jun 29, 2020
  33. MarcoFalke locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-14 18:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me