Skip to content

Conversation

theStack
Copy link
Contributor

@theStack theStack commented Jul 16, 2022

This PR adds missing test coverage for the decodepsbt RPC in the case that a PSBT with on of the per-input preimage types (PSBT_IN_RIPEMD160, PSBT_IN_SHA256, PSBT_IN_HASH160, PSBT_IN_HASH256; see BIP 174) is passed. As preparation, the first four commits move the already existing helpers for (de)serialization of PSBTs and PSBTMaps from the signet miner to the test framework (in a new module psbt.py), which should be quite useful for further tests to easily create PSBTs.

@theStack theStack force-pushed the 202207-test-add_more_decodepsbt_tests branch from 0095429 to 4dc573e Compare July 16, 2022 14:24
@DrahtBot
Copy link
Contributor

DrahtBot commented Jul 16, 2022

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #23127 (tests: Use test framework utils where possible by vincenzopalazzo)
  • #20892 (tests: Run both descriptor and legacy tests within a single test invocation by achow101)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@brunoerg
Copy link
Contributor

Concept ACK

@achow101
Copy link
Member

ACK 4dc573e

@fanquake fanquake requested a review from instagibbs July 18, 2022 20:29
Copy link
Contributor

@brunoerg brunoerg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

crACK 4dc573e

@instagibbs
Copy link
Member

concept ACK, moving the PSBT utility functions into the testing framework proper is something I wanted regardless

theStack added 4 commits July 19, 2022 15:40
…ner)

-BEGIN VERIFY SCRIPT-
sed -i s/FromBinary/from_binary/g ./contrib/signet/miner
-END VERIFY SCRIPT-
Can be easily reviewed with `--color-moved=dimmed-zebra`.
Can be easily reviewed with `--color-moved=dimmed-zebra`.
Also take use of the constants in the signet miner to get rid of
magic numbers and increase readability and maintainability.
@theStack theStack force-pushed the 202207-test-add_more_decodepsbt_tests branch from 4dc573e to 94dbcdc Compare July 19, 2022 13:43
@theStack
Copy link
Contributor Author

Rebased on master (due to trivial merge conflict in rpc_psbt.py after commit d2ed976, #25590), should be easy to re-review.

Copy link
Member

@instagibbs instagibbs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good aside from one question of mine

@@ -775,5 +788,37 @@ def test_psbt_input_keys(psbt_input, keys):
self.nodes[0].sendrawtransaction(rawtx)
self.generate(self.nodes[0], 1)

self.log.info("Test decoding PSBT with per-input preimage types")
# note that the decodepsbt RPC doesn't check whether preimages and hashes match
hash_ripemd160, preimage_ripemd160 = os.urandom(20), os.urandom(50)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the first instance of urandom in the test framework. Can we make it seed-determined instead, so that failures can be diagnosed easier?

If we don't expect failures due to randomness, we probably shouldn't do it at all then.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I agree that seed-determined randomness is preferred here. Moved the random_bytes helper (which uses random.getrandbits) from the taproot test to the utils library and used that instead. Note that Python 3.9 offers random.randbytes(), but unfortunately we have Python 3.6 as minimum requirement.

@theStack theStack force-pushed the 202207-test-add_more_decodepsbt_tests branch from 94dbcdc to 71a751f Compare July 19, 2022 15:47
@theStack
Copy link
Contributor Author

Force-pushed with feedback taken from instagibb's review comment, i.e. the random bytes are now generated with the random module and hence could be reproduced by passing a PRNG seed (which is printed out in the test framework log).

@achow101
Copy link
Member

ACK 71a751f

@achow101 achow101 merged commit d67f89b into bitcoin:master Jul 20, 2022
@theStack theStack deleted the 202207-test-add_more_decodepsbt_tests branch July 20, 2022 21:42
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jul 21, 2022
@bitcoin bitcoin locked and limited conversation to collaborators Jul 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants