test: get and decode tx with a single `gettransaction` RPC call #23287

pull theStack wants to merge 1 commits into bitcoin:master from theStack:202110-test-fetch_and_decode_tx_with_single_RPC_call changing 6 files +10 −16
  1. theStack commented at 2:20 PM on October 15, 2021: member

    Rather than subsequently calling gettransaction and decoderawtransaction to get the decoded information for a specific tx-id, we can simply use the verbose version of gettransaction, which returns this in a 'decoded' key. I.e.

    node.decoderawtransaction(node.gettransaction(txid)['hex'])
    

    can simply be replaced by:

    node.gettransaction(txid=txid, verbose=True)['decoded']
    

    Rationale: shorter code, shorter test logs, less RPC calls.

  2. fanquake added the label Tests on Oct 15, 2021
  3. amadeuszpawlik commented at 4:58 PM on October 15, 2021: contributor

    Tested ACK c045207fb4a96f3cbdf7841ecab5c36323ea01a3. Ran the tests and reviewed the changes.

  4. brunoerg commented at 7:42 PM on October 15, 2021: member

    Concept ACK

    I think mempool_packages.py (line 68 and 69) could be also included here, couldn't it?

  5. promag commented at 8:00 PM on October 15, 2021: member

    Code review ACK c045207fb4a96f3cbdf7841ecab5c36323ea01a3. Didn't check if same approach could be applied in other places.

  6. shaavan commented at 2:25 PM on October 16, 2021: contributor

    Concept ACK

    This PR simplifies the code and RPC calls around getting a transaction and decoding it. I was able to successfully compile the PR on Ubuntu 20.04 without any errors. Nice catch, @theStack!

    I think mempool_packages.py (line 68 and 69) could be also included here, couldn't it?

    I think this is a valid suggestion. I tried to implement this myself while testing, and I was able to successfully do so in the following way:

    # We need the wtxids to check P2P announcements
    -            fulltx = self.nodes[0].getrawtransaction(txid)
    -            witnesstx = self.nodes[0].decoderawtransaction(fulltx, True)
    +            witnesstx = self.nodes[0].gettransaction(txid=txid, verbose=True)['decoded']
                 witness_chain.append(witnesstx['hash'])
    
  7. brunoerg approved
  8. brunoerg commented at 3:18 PM on October 16, 2021: member

    tACK c045207fb4a96f3cbdf7841ecab5c36323ea01a3

  9. brunoerg commented at 3:19 PM on October 16, 2021: member

    I think mempool_packages.py (line 68 and 69) could be also included here, couldn't it?

    I think this is a valid suggestion. I tried to implement this myself while testing, and I was able to successfully do so in the following way:

    # We need the wtxids to check P2P announcements
    -            fulltx = self.nodes[0].getrawtransaction(txid)
    -            witnesstx = self.nodes[0].decoderawtransaction(fulltx, True)
    +            witnesstx = self.nodes[0].gettransaction(txid=txid, verbose=True)['decoded']
                 witness_chain.append(witnesstx['hash'])
    

    Great! I am gonna check if there are other places it could be applied

  10. stratospher commented at 3:21 PM on October 16, 2021: contributor

    Tested ACK c045207

    Verified that the output dictionary produced for a specific tx-id in both the master and PR are the same. There’s 1 more instance where this change can be applied:

    In test/functional/rpc_rawtransaction.py:

  11. amadeuszpawlik approved
  12. test: get and decode tx with a single `gettransaction` RPC call
    Rather than subsequently calling `gettransaction` and
    `decoderawtransaction` to get the decoded information  for a specific
    tx-id, we can simply use the verbose version of `gettransaction`, which
    returns this in a 'decoded' key. I.e.
    
    node.decoderawtransaction(node.gettransaction(txid)['hex'])
    
    can be replaced by:
    
    node.gettransaction(txid=txid, verbose=True)['decoded']
    130ee48108
  13. theStack force-pushed on Oct 17, 2021
  14. theStack commented at 4:18 PM on October 17, 2021: member

    Thanks for all the reviews! Force-pushed with the substitution also done in mempool_packages.py, as suggested by @brunoerg and @shaavan (https://github.com/bitcoin/bitcoin/pull/23287#issuecomment-944615929, #23287#pullrequestreview-781363806). @stratospher: Note that I intentionally didn't change anything in rpc_rawtransaction.py, as I think this test's focus are RPCs that cope with raw transactions (like decoderawtransaction).

  15. stratospher commented at 6:43 PM on October 17, 2021: contributor

    tested ACK 130ee48

    @stratospher: Note that I intentionally didn't change anything in rpc_rawtransaction.py, as I think this test's focus are RPCs that cope with raw transactions (like decoderawtransaction). @theStack, Thanks for clarifying. That makes total sense!

  16. lsilva01 approved
  17. lsilva01 commented at 5:13 AM on October 18, 2021: contributor

    Tested ACK 130ee48 on Ubuntu 20.04.

  18. shaavan approved
  19. shaavan commented at 11:44 AM on October 18, 2021: contributor

    ACK 130ee481082d2612d452d7d69131ade935b225b5

  20. amadeuszpawlik commented at 4:41 PM on October 19, 2021: contributor

    tACK 130ee481082d2612d452d7d69131ade935b225b5

  21. in test/functional/mempool_packages.py:68 in 130ee48108
      64 | @@ -65,8 +65,7 @@ def run_test(self):
      65 |              value = sent_value
      66 |              chain.append(txid)
      67 |              # We need the wtxids to check P2P announcements
      68 | -            fulltx = self.nodes[0].getrawtransaction(txid)
      69 | -            witnesstx = self.nodes[0].decoderawtransaction(fulltx, True)
      70 | +            witnesstx = self.nodes[0].gettransaction(txid=txid, verbose=True)['decoded']
    


    MarcoFalke commented at 8:05 AM on October 21, 2021:

    this is a wallet rpc and eventually the mempool tests shouldn't depend on bdb or sqlite

  22. MarcoFalke merged this on Oct 21, 2021
  23. MarcoFalke closed this on Oct 21, 2021

  24. sidhujag referenced this in commit a991499680 on Oct 21, 2021
  25. DrahtBot locked this on Oct 30, 2022

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 21:13 UTC

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