Skip to content

Conversation

gillichu
Copy link

@gillichu gillichu commented May 27, 2020

The CScriptNum test (#14816) is a roundtrip test of the test framework. Thus, it would be better suited as a unit test. This is now possible with the introduction of the unit test module for the functional tests. See #18576.

This PR:

  1. Refactors the CScriptNum tests into 2 unit tests, one in script.py and one in blocktools.py.
  2. Extends the script.py CScriptNum test to trial larger numbers.

@maflcko
Copy link
Member

maflcko commented May 27, 2020

Concept ACK

It would be good to motivate the change. Maybe something like this?

The scriptnum test (#14816) is a roundtrip test of the test framwork. Thus, it would be better suited as a unit test. This is now possible with the introduction of the unit test module for the functional tests. See #18576

@gillichu gillichu changed the title Moved the CScriptNum asserts into the unit test in script.py [WIP]. Moved the CScriptNum asserts into the unit test in script.py May 27, 2020
@gillichu gillichu changed the title [WIP]. Moved the CScriptNum asserts into the unit test in script.py [WIP] Moved the CScriptNum asserts into the unit test in script.py May 27, 2020
@gillichu gillichu marked this pull request as draft May 27, 2020 17:24
@DrahtBot DrahtBot added the Tests label May 27, 2020
Copy link
Member

@glozow glozow left a comment

Choose a reason for hiding this comment

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

Concept ACK, I suggest trying to undo some of your changes in mining_basic.py so that you aren't touching any extra lines. You could squash your commits to try to make it easier to see overall changes (you'll need to do this anyway).

There's also some description/naming conventions you could take a look at in the contributing doc as well. For example, adding [test] to the commit message and PR title.

@practicalswift
Copy link
Contributor

Concept ACK: more testing is better!

Welcome as a contributor @gillichu :)

@DrahtBot
Copy link
Contributor

DrahtBot commented May 27, 2020

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

Conflicts

No conflicts as of last run.

@gillichu gillichu changed the title [WIP] Moved the CScriptNum asserts into the unit test in script.py [WIP] [test] Moved the CScriptNum asserts into the unit test in script.py May 27, 2020
@gillichu gillichu changed the title [WIP] [test] Moved the CScriptNum asserts into the unit test in script.py test: Moved the CScriptNum asserts into the unit test in script.py May 28, 2020
@gillichu gillichu marked this pull request as ready for review May 28, 2020 04:09
Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

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

Almost ACK 9d5dd87

@laanwj
Copy link
Member

laanwj commented May 28, 2020

Thanks for you contribution. Looks good to me.

A small nit: please change the git commit message to a short title (up to say, 70 characters), then an empty line, then the rest of the description. This because tools (such as git pretty=oneline) will otherwise put it all on one line instead of displaying just the title:

9d5dd8752… (pull/19082/head) [test] Migrates the CScriptNum decode tests into a unit test, moving some changes made in #14816. This was made possible by the integration of test_framework unit testing in #18576.

Copy link
Contributor

@jnewbery jnewbery left a comment

Choose a reason for hiding this comment

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

Welcome to the project @gillichu, and thanks for your contribution ! I have a couple of small suggestions inline.

Comment on lines 93 to 94
# round-trip the encoded bip34 block height commitment
assert_equal(CScriptNum.decode(coinbase_tx.vin[0].scriptSig), next_height)
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems to be a test of the create_coinbase() function in blocktools.py. It might be worth moving it to a unit test there.

@jnewbery
Copy link
Contributor

A couple more suggestions for the commit log and PR description:

  • use the imperative mood (s/Moved the CScript/Move the CScript/ and s/Migrates the CScript/Migrate the CScript/).
  • wrap the message body width at 72 or 80 characters.

See https://chris.beams.io/posts/git-commit/ for more tips on writing great commit logs.

Copy link
Member

@glozow glozow left a comment

Choose a reason for hiding this comment

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

Almost there

@@ -91,12 +91,6 @@ def assert_submitblock(block, result_str_1, result_str_2=None):
coinbase_tx.rehash()

# round-trip the encoded bip34 block height commitment
Copy link
Member

Choose a reason for hiding this comment

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

delete this comment?

Copy link
Contributor

Choose a reason for hiding this comment

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

This hasn't been deleted.

Copy link
Author

Choose a reason for hiding this comment

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

Sorry about that :( I'll watch my changes more carefully next time, and look for a chance to take this out in the future.

@bitcoin bitcoin deleted a comment from kantornnam Jun 1, 2020
@bitcoin bitcoin deleted a comment from kantornnam Jun 1, 2020
@bitcoin bitcoin deleted a comment from kantornnam Jun 1, 2020
@bitcoin bitcoin deleted a comment from kantornnam Jun 1, 2020
@bitcoin bitcoin deleted a comment from kantornnam Jun 1, 2020
@bitcoin bitcoin deleted a comment from kantornnam Jun 1, 2020
@bitcoin bitcoin deleted a comment from kantornnam Jun 1, 2020
@bitcoin bitcoin deleted a comment from kantornnam Jun 1, 2020
@bitcoin bitcoin deleted a comment from kantornnam Jun 1, 2020
@bitcoin bitcoin deleted a comment from kantornnam Jun 1, 2020
Migrates the CScriptNum decode tests into a unit test, and moved some
changes made in bitcoin#14816. Made possible by the integration of
test_framework unit testing in bitcoin#18576. Further extends the original
test with larger ints, similar to the scriptnum_tests.cpp file. Adds
test to blocktools.py testing fn create_coinbase() with CScriptNum
decode.
@gillichu
Copy link
Author

gillichu commented Jun 3, 2020

rebased the branch, addressed review comments and updated tests. thanks for the review @laanwj @gzhao408 @jnewbery comments have been addressed!

@jnewbery
Copy link
Contributor

jnewbery commented Jun 4, 2020

Thanks @gillichu. I think the PR title, commit summary and commit details could be made a bit clearer:

@laanwj
Copy link
Member

laanwj commented Jun 4, 2020

ACK 7daffc6
Looks good to me now!
Please keep the additional suggestions in mind for a next PR, but I don't think we should keep iterating on the commit message too much.

@laanwj laanwj merged commit 39afe5b into bitcoin:master Jun 4, 2020
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jun 4, 2020
… test in script.py

7daffc6 [test] CScriptNum Decode Check as Unit Tests (Gillian Chu)

Pull request description:

  The CScriptNum test (bitcoin#14816) is a roundtrip test of the test framework. Thus, it would be better suited as a unit test. This is now possible with the introduction of the unit test module for the functional tests. See bitcoin#18576.

  This PR:
  1. Refactors the CScriptNum tests into 2 unit tests, one in script.py and one in blocktools.py.
  2. Extends the script.py CScriptNum test to trial larger numbers.

ACKs for top commit:
  laanwj:
    ACK 7daffc6

Tree-SHA512: 17a04a4bfff1b1817bfc167824c679455d9e06e6e0164c00a7e44f8aa5041c5f5080adcc1452fd80ba1a6d8409f976c982bc481d686c434edf97a5893a32a436
fanquake added a commit that referenced this pull request Jun 11, 2020
fa98e10 test: Remove leftover comment in mining_basic (MarcoFalke)
faedb50 test: pep-8 mining_basic (MarcoFalke)

Pull request description:

  Remove an accidental leftover comment from #19082, which no longer applies and thus might be confusing

ACKs for top commit:
  adamjonas:
    code review ACK fa98e10

Tree-SHA512: c7f7f8f579b3c6e92f45769be0a7af1a421438a3f5524db5278b2269511a9e0e08f44e3836afb26727644035897ee51ff8296d13ce23030549e7403f57b40e40
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jun 11, 2020
fa98e10 test: Remove leftover comment in mining_basic (MarcoFalke)
faedb50 test: pep-8 mining_basic (MarcoFalke)

Pull request description:

  Remove an accidental leftover comment from bitcoin#19082, which no longer applies and thus might be confusing

ACKs for top commit:
  adamjonas:
    code review ACK fa98e10

Tree-SHA512: c7f7f8f579b3c6e92f45769be0a7af1a421438a3f5524db5278b2269511a9e0e08f44e3836afb26727644035897ee51ff8296d13ce23030549e7403f57b40e40
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Mar 1, 2021
Summary:
> Migrates the CScriptNum decode tests into a unit test, and moved some
> changes made in [[bitcoin/bitcoin#14816 | core#14816]]. Made possible by the integration of
> test_framework unit testing in [[bitcoin/bitcoin#18576 | core#18576]]. Further extends the original
> test with larger ints, similar to the scriptnum_tests.cpp file. Adds
> test to blocktools.py testing fn create_coinbase() with CScriptNum
> decode.

Backport note:

The functional tests are usually executed individually via a `subprocess`. This means the `get_srcdir()` function in cdefs.py is able to find the proper source directory, because the parent directory of the python process is the project root that contains `src/`.

But when we run the new test_framework unit test, the process currently running is `test_runner.py` itself which is located in the build directory.
So cdefs.py finds the wrong `src/` directory, the one located in the build directory, which does not contain `consensus.h`.
I fixed this by setting the environment variable `SRCDIR` in `test_runner.py` before calling the unittest `unittest.TestLoader().loadTestsFromName` machinery which causes `cdefs.py` to be imported.

This is a backport of [[bitcoin/bitcoin#19082 | core#19082]]

Test Plan: `ninja check-functional`

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D9276
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 16, 2022
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.

7 participants