Skip to content

Tests: Cleanup create_transaction implementations - #13669

Merged
maflcko merged 3 commits into
bitcoin:masterfrom
conscott:create_tx_cleanup
Aug 9, 2018
Merged

maflcko merged 3 commits into
bitcoin:masterfrom
conscott:create_tx_cleanup

Conversation

@conscott

Copy link
Copy Markdown
Contributor

There currently exist seven (1, 2 3, 4, 5, 6, 7) implementations of a function called something similar to create_transaction in the functional tests, some of which are exact copies of each other.

This PR aims to clean this up into three different cases implemented in blocktools.py

  1. create_tx_with_script: Return transaction object spending generic tx output optionally specifying scriptSig and scriptPubKey
  2. create_transaction: Return transaction object spending coinbase tx
  3. create_raw_transaction: Return raw transaction (hex string) spending coinbase tx

I am not committed to any of these function names, so I'll gladly take suggestions on there.

Additionally there are some related cleanups to feature_block.py tests, specifically removing the PreviousSpendableOutput object, which seems like an unnecessary layer given that every instance spends the 0 output.

@fanquake fanquake added the Tests label Jul 15, 2018
@conscott
conscott force-pushed the create_tx_cleanup branch from d9592da to 41b8251 Compare July 15, 2018 11:48
@fanquake
fanquake requested review from jnewbery and maflcko July 15, 2018 12:30
@DrahtBot

Copy link
Copy Markdown
Contributor
Note to reviewers: This pull request conflicts with the following ones:

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.

@jnewbery

Copy link
Copy Markdown
Contributor

Concept ACK. I intend to review this.

My personal preference would be to split this into smaller commits (eg one just removing the PreviousSpendableOutput object, and then one each for the three new functions if possible). That would make it a bit easier to review.

@conscott

Copy link
Copy Markdown
Contributor Author

Thanks @jnewbery - Agreed. I'll try to split this up better.

@conscott
conscott force-pushed the create_tx_cleanup branch from 41b8251 to 83e35da Compare July 31, 2018 08:24
@conscott

Copy link
Copy Markdown
Contributor Author

I have split this up into 3 commits now.

@jnewbery jnewbery left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tested ACK 83e35dae61f3c41d7adf8b00d6120a98fea5ca79. Nice tidyup!

A few nits inline. Up to you whether you want to take them.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I actually prefer the argument ordering before (ie all TxIn fields (prevtx, n, script_sig) then all TxOut fields (amount, script_pub_key)). I like the renames (sig => script_sig and value => amount).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

👍 - you are right, it makes more sense that way now that you mention it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for improving the comment. Can be improved further by stating that this is a one-input, one-output transaction.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: comment could be improved by:

  • saying this is spending the first output of transaction txid (I don't see why this function is specific to spending a coinbase tx).
  • stating that node must be able to sign for the txout provided
  • stating that the node must not be running multiple wallets

@conscott
conscott force-pushed the create_tx_cleanup branch 2 times, most recently from 588d563 to 44bbcee Compare August 9, 2018 11:13
@conscott

conscott commented Aug 9, 2018

Copy link
Copy Markdown
Contributor Author

Rebased on updated based on @jnewbery comments

@jnewbery

jnewbery commented Aug 9, 2018

Copy link
Copy Markdown
Contributor

utACK 44bbcee

This is great. Cuts down on a lot of code duplication and improves commenting. 💯

@maflcko

maflcko commented Aug 9, 2018

Copy link
Copy Markdown
Member

utACK 44bbcee

@maflcko
maflcko merged commit 44bbcee into bitcoin:master Aug 9, 2018
maflcko pushed a commit that referenced this pull request Aug 9, 2018
44bbcee [Tests] Cleanup feature_block.py, remove unnecessary PreviousSpendableOutput object (Conor Scott)
736f941 [Tests] Cleanup extra instances of create_transaction (Conor Scott)
1576518 [Tests] Rename create_tx and move to blocktools.py (Conor Scott)

Pull request description:

  There currently exist seven ([1](https://github.com/bitcoin/bitcoin/blob/master/test/functional/feature_cltv.py#L52-L60), [2](https://github.com/bitcoin/bitcoin/blob/master/test/functional/feature_csv_activation.py#L88-L95) [3](https://github.com/bitcoin/bitcoin/blob/master/test/functional/feature_dersig.py#L40-L48), [4](https://github.com/bitcoin/bitcoin/blob/master/test/functional/feature_nulldummy.py#L100-L108), [5](https://github.com/bitcoin/bitcoin/blob/master/test/functional/test_framework/util.py#L529-L535), [6](https://github.com/bitcoin/bitcoin/blob/master/test/functional/test_framework/blocktools.py#L120-L129), [7](https://github.com/bitcoin/bitcoin/blob/master/test/functional/feature_block.py#L1218-L1220)) implementations of a function called something similar to `create_transaction` in the functional tests, some of which are exact copies of each other.

  This PR aims to clean this up into [three different cases implemented in blocktools.py](https://github.com/conscott/bitcoin/blob/create_tx_cleanup/test/functional/test_framework/blocktools.py#L121-L149)
  1. `create_tx_with_script`: Return transaction object spending generic tx output optionally specifying scriptSig and scriptPubKey
  2. `create_transaction`: Return transaction object spending coinbase tx
  2. `create_raw_transaction`: Return raw transaction (hex string) spending coinbase tx

  I am not committed to any of these function names, so I'll gladly take suggestions on there.

  Additionally there are some related cleanups to feature_block.py tests, specifically removing the [PreviousSpendableOutput](https://github.com/conscott/bitcoin/blob/master/test/functional/feature_block.py#L51-L54) object, which seems like an unnecessary layer given that every instance spends the 0 output.

Tree-SHA512: 63c6233b6f0942c81ba1ca67ea6770809b8c9409314c6d4cf8e5a3991cb9ee92b22bebe88c0dde45cd71e754eb351230c4c404b70ff118f5f43c034452ada65c
@conscott
conscott deleted the create_tx_cleanup branch August 10, 2018 11:04
UdjinM6 pushed a commit to UdjinM6/dash that referenced this pull request Jul 6, 2021
44bbcee [Tests] Cleanup feature_block.py, remove unnecessary PreviousSpendableOutput object (Conor Scott)
736f941 [Tests] Cleanup extra instances of create_transaction (Conor Scott)
1576518 [Tests] Rename create_tx and move to blocktools.py (Conor Scott)

Pull request description:

  There currently exist seven ([1](https://github.com/bitcoin/bitcoin/blob/master/test/functional/feature_cltv.py#L52-L60), [2](https://github.com/bitcoin/bitcoin/blob/master/test/functional/feature_csv_activation.py#L88-L95) [3](https://github.com/bitcoin/bitcoin/blob/master/test/functional/feature_dersig.py#L40-L48), [4](https://github.com/bitcoin/bitcoin/blob/master/test/functional/feature_nulldummy.py#L100-L108), [5](https://github.com/bitcoin/bitcoin/blob/master/test/functional/test_framework/util.py#L529-L535), [6](https://github.com/bitcoin/bitcoin/blob/master/test/functional/test_framework/blocktools.py#L120-L129), [7](https://github.com/bitcoin/bitcoin/blob/master/test/functional/feature_block.py#L1218-L1220)) implementations of a function called something similar to `create_transaction` in the functional tests, some of which are exact copies of each other.

  This PR aims to clean this up into [three different cases implemented in blocktools.py](https://github.com/conscott/bitcoin/blob/create_tx_cleanup/test/functional/test_framework/blocktools.py#L121-L149)
  1. `create_tx_with_script`: Return transaction object spending generic tx output optionally specifying scriptSig and scriptPubKey
  2. `create_transaction`: Return transaction object spending coinbase tx
  2. `create_raw_transaction`: Return raw transaction (hex string) spending coinbase tx

  I am not committed to any of these function names, so I'll gladly take suggestions on there.

  Additionally there are some related cleanups to feature_block.py tests, specifically removing the [PreviousSpendableOutput](https://github.com/conscott/bitcoin/blob/master/test/functional/feature_block.py#L51-L54) object, which seems like an unnecessary layer given that every instance spends the 0 output.

Tree-SHA512: 63c6233b6f0942c81ba1ca67ea6770809b8c9409314c6d4cf8e5a3991cb9ee92b22bebe88c0dde45cd71e754eb351230c4c404b70ff118f5f43c034452ada65c
UdjinM6 pushed a commit to UdjinM6/dash that referenced this pull request Jul 6, 2021
44bbcee [Tests] Cleanup feature_block.py, remove unnecessary PreviousSpendableOutput object (Conor Scott)
736f941 [Tests] Cleanup extra instances of create_transaction (Conor Scott)
1576518 [Tests] Rename create_tx and move to blocktools.py (Conor Scott)

Pull request description:

  There currently exist seven ([1](https://github.com/bitcoin/bitcoin/blob/master/test/functional/feature_cltv.py#L52-L60), [2](https://github.com/bitcoin/bitcoin/blob/master/test/functional/feature_csv_activation.py#L88-L95) [3](https://github.com/bitcoin/bitcoin/blob/master/test/functional/feature_dersig.py#L40-L48), [4](https://github.com/bitcoin/bitcoin/blob/master/test/functional/feature_nulldummy.py#L100-L108), [5](https://github.com/bitcoin/bitcoin/blob/master/test/functional/test_framework/util.py#L529-L535), [6](https://github.com/bitcoin/bitcoin/blob/master/test/functional/test_framework/blocktools.py#L120-L129), [7](https://github.com/bitcoin/bitcoin/blob/master/test/functional/feature_block.py#L1218-L1220)) implementations of a function called something similar to `create_transaction` in the functional tests, some of which are exact copies of each other.

  This PR aims to clean this up into [three different cases implemented in blocktools.py](https://github.com/conscott/bitcoin/blob/create_tx_cleanup/test/functional/test_framework/blocktools.py#L121-L149)
  1. `create_tx_with_script`: Return transaction object spending generic tx output optionally specifying scriptSig and scriptPubKey
  2. `create_transaction`: Return transaction object spending coinbase tx
  2. `create_raw_transaction`: Return raw transaction (hex string) spending coinbase tx

  I am not committed to any of these function names, so I'll gladly take suggestions on there.

  Additionally there are some related cleanups to feature_block.py tests, specifically removing the [PreviousSpendableOutput](https://github.com/conscott/bitcoin/blob/master/test/functional/feature_block.py#L51-L54) object, which seems like an unnecessary layer given that every instance spends the 0 output.

Tree-SHA512: 63c6233b6f0942c81ba1ca67ea6770809b8c9409314c6d4cf8e5a3991cb9ee92b22bebe88c0dde45cd71e754eb351230c4c404b70ff118f5f43c034452ada65c
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
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