test: add validation for gettxout RPC response #30226

pull alfonsoromanz wants to merge 2 commits into bitcoin:master from alfonsoromanz:missing-test changing 5 files +33 −4
  1. alfonsoromanz commented at 8:18 AM on June 5, 2024: contributor

    Added a new test in test/functional/rpc_blockchain.py to validate the gettxout RPC response. This new test ensures all response elements are verified, including bestblock, confirmations, value, coinbase, and scriptPubKey details.

    Also renamed the method get_scriptPubKey from test/functional/test_framework/wallet.py to the modern name get_output_script as suggested by maflcko (https://github.com/bitcoin/bitcoin/pull/30226#discussion_r1925491846)

  2. brunoerg commented at 12:18 PM on June 5, 2024: contributor

    Why not just expanding the tests in wallet_basic.py?

  3. DrahtBot commented at 12:18 PM on June 5, 2024: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/30226.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK fjahr, maflcko, brunoerg

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    No conflicts as of last run.

  4. alfonsoromanz commented at 2:47 PM on June 5, 2024: contributor

    Why not just expanding the tests in wallet_basic.py?

    I initially added the test to rpc_blockchain.py because that file focuses on testing RPC commands from src/rpc/blockchain.cpp, and "gettxout" is one of those commands. However, I'm open to expanding the tests in wallet_basic.py if that is preferred.

  5. in test/functional/rpc_blockchain.py:411 in 6cd0276145 outdated
     406 | +        txout = node.gettxout(txid, 0)
     407 | +
     408 | +        # Validate the gettxout response
     409 | +        assert_equal(txout['bestblock'], best_block_hash)
     410 | +        assert_equal(txout['confirmations'], 1)
     411 | +        assert_equal(txout['value'], create_coinbase(HEIGHT).vout[0].nValue / 100000000)
    


    kevkevinpal commented at 1:08 AM on June 14, 2024:

    Should we use COIN here instead of 100000000

    found in bitcoin/test/functional/test_framework/messages.py


    alfonsoromanz commented at 8:50 AM on June 18, 2024:

    Done. Thanks

  6. in test/functional/rpc_blockchain.py:394 in 6cd0276145 outdated
     389 | @@ -388,6 +390,33 @@ def _test_gettxoutsetinfo(self):
     390 |          # Unknown hash_type raises an error
     391 |          assert_raises_rpc_error(-8, "'foo hash' is not a valid hash_type", node.gettxoutsetinfo, "foo hash")
     392 |  
     393 | +    def _test_gettxout(self):
     394 | +        self.log.info("Test gettxout")
    


    kevkevinpal commented at 1:11 AM on June 14, 2024:

    This logs seems a bit vague, a more descriptive log would be useful


    alfonsoromanz commented at 8:52 AM on June 18, 2024:

    Yeah, I agree. I was following the same log structure used by other tests in this file. I changed it to "Validating gettxout RPC response". Let me know if that's better. Thanks

  7. alfonsoromanz force-pushed on Jun 18, 2024
  8. alfonsoromanz commented at 12:32 PM on September 18, 2024: contributor

    Hey @maflcko, sorry for tagging you, but I would appreciate some additional feedback on this PR.

    I believe rpc_blockchain.py is a suitable place to test the "gettxout" RPC call/response, as it already handles similar RPC commands like "gettxoutsetinfo." However, brunoerg suggested moving this test to wallet_basic.py.

    I would value your input on this. I'm open to moving the test if that's the more appropriate approach.

  9. DrahtBot added the label CI failed on Sep 18, 2024
  10. DrahtBot commented at 12:38 PM on September 18, 2024: contributor

    <!--85328a0da195eb286784d51f73fa0af9-->

    🚧 At least one of the CI tasks failed. <sub>Debug: https://github.com/bitcoin/bitcoin/runs/26357289945</sub>

    <details><summary>Hints</summary>

    Make sure to run all tests locally, according to the documentation.

    The failure may happen due to a number of reasons, for example:

    • Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch.

    • A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test.

    • An intermittent issue.

    Leave a comment here, if you need help tracking down a confusing failure.

    </details>

  11. maflcko commented at 12:42 PM on September 18, 2024: member

    I believe rpc_blockchain.py is a suitable place to test the "gettxout" RPC call/response, as it already handles similar RPC commands like "gettxoutsetinfo." However, brunoerg suggested moving this test to wallet_basic.py.

    I don't think wallet_*.py makes sense, because gettxout is not a wallet RPC. This would mean the test doesn't run at all unless a wallet is compiled in. The current place seems fine.

    However, the CI fails.

  12. alfonsoromanz commented at 12:49 PM on September 18, 2024: contributor

    I don't think wallet_*.py makes sense, because gettxout is not a wallet RPC. This would mean the test doesn't run at all unless a wallet is compiled in. The current place seems fine.

    However, the CI fails.

    Thanks. Yes I just noticed the failure on the lint job. I will check it and push the fix.

  13. maflcko commented at 12:57 PM on September 18, 2024: member

    You'll probably have to rebase, as it may be a silent conflict.

  14. alfonsoromanz force-pushed on Sep 18, 2024
  15. DrahtBot removed the label CI failed on Sep 18, 2024
  16. DrahtBot added the label Tests on Sep 18, 2024
  17. alfonsoromanz commented at 3:39 PM on September 18, 2024: contributor

    You'll probably have to rebase, as it may be a silent conflict.

    Yes, that was it. I've rebased and resolved the conflict. Thanks for your help!

  18. DrahtBot added the label CI failed on Oct 19, 2024
  19. DrahtBot removed the label CI failed on Oct 23, 2024
  20. maflcko commented at 3:08 PM on January 22, 2025: member

    lgtm ACK 11b90e4319319db702d602a68d22c87054781582

  21. in test/functional/rpc_blockchain.py:416 in 11b90e4319 outdated
     411 | +        assert_equal(txout['bestblock'], best_block_hash)
     412 | +        assert_equal(txout['confirmations'], 1)
     413 | +        assert_equal(txout['value'], create_coinbase(HEIGHT).vout[0].nValue / COIN)
     414 | +        assert_equal(txout['scriptPubKey']['address'], self.wallet.get_address())
     415 | +        assert_equal(txout['scriptPubKey']['hex'], self.wallet.get_scriptPubKey().hex())
     416 | +        decoded_script = node.decodescript(self.wallet.get_scriptPubKey().hex())
    


    maflcko commented at 3:10 PM on January 22, 2025:
            decoded_script = node.decodescript(self.wallet.get_output_script().hex())
    

    unrelated, but the method can be renamed to use the modern name


    alfonsoromanz commented at 11:18 AM on January 24, 2025:

    I tried the suggested change, but encountered

    decoded_script = node.decodescript(self.wallet.get_output_script().hex())
    AttributeError: 'MiniWallet' object has no attribute 'get_output_script'
    

    I synced my fork and rebased master in my local branch, but the implementation for get_output_script doesn't seem to be present. Am I missing something?


    maflcko commented at 11:25 AM on January 24, 2025:

    I wanted to suggest to rename the method wholesale, as it isn't used widely and this pull is adding two new calls.


    alfonsoromanz commented at 11:53 AM on January 24, 2025:

    Ok, I understand now. I can make this change in the current PR while also addressing fjahr's feedback. Unless you think it's not worth invalidating the two ACKs, but it might be a good time to do it.


    alfonsoromanz commented at 9:04 PM on January 24, 2025:

    Done in 723440c5b8eb3a815c80bfb37ad195b5448b25ed

  22. fanquake requested review from fjahr on Jan 22, 2025
  23. in test/functional/rpc_blockchain.py:413 in 11b90e4319 outdated
     408 | +        txout = node.gettxout(txid, 0)
     409 | +
     410 | +        # Validate the gettxout response
     411 | +        assert_equal(txout['bestblock'], best_block_hash)
     412 | +        assert_equal(txout['confirmations'], 1)
     413 | +        assert_equal(txout['value'], create_coinbase(HEIGHT).vout[0].nValue / COIN)
    


    fjahr commented at 4:46 PM on January 22, 2025:

    nit: I find this a bit weird to use create_coinbase here for this. It's not a big deal but just using a fixed value would have been fine and a bit simpler IMO.


    alfonsoromanz commented at 9:05 PM on January 24, 2025:

    Done, thanks!

  24. fjahr commented at 4:59 PM on January 22, 2025: contributor

    Code review ACK 11b90e4319319db702d602a68d22c87054781582

  25. test: add validation for gettxout RPC response fa0232a3e0
  26. test framework, wallet: rename get_scriptPubKey method to get_output_script 723440c5b8
  27. alfonsoromanz force-pushed on Jan 24, 2025
  28. fjahr commented at 6:38 PM on January 25, 2025: contributor

    reACK 723440c5b8eb3a815c80bfb37ad195b5448b25ed

    Just FYI, for changes of the test framework just using the prefix of test is fine.

  29. DrahtBot requested review from maflcko on Jan 25, 2025
  30. maflcko commented at 12:04 PM on February 5, 2025: member

    lgtm ACK 723440c5b8eb3a815c80bfb37ad195b5448b25ed

  31. brunoerg approved
  32. brunoerg commented at 1:01 PM on February 5, 2025: contributor

    code review ACK 723440c5b8eb3a815c80bfb37ad195b5448b25ed

  33. fanquake merged this on Feb 5, 2025
  34. fanquake closed this on Feb 5, 2025

  35. sedited referenced this in commit f78a01a560 on Feb 22, 2025
  36. stickies-v referenced this in commit d760fd3dda on Mar 17, 2025
  37. stickies-v referenced this in commit cc83553352 on Mar 17, 2025
  38. stickies-v referenced this in commit 2614933f06 on Mar 17, 2025
  39. stickies-v referenced this in commit b70418c5fc on Mar 17, 2025
  40. stickies-v referenced this in commit 69f8a1fe50 on Mar 17, 2025
  41. bug-castercv502 referenced this in commit d15545ffaa on Sep 28, 2025
  42. bitcoin locked this on Feb 5, 2026

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-05-02 03:13 UTC

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