gillichu
commented at 5:07 pm on May 27, 2020:
none
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:
Refactors the CScriptNum tests into 2 unit tests, one in script.py and one in blocktools.py.
Extends the script.py CScriptNum test to trial larger numbers.
MarcoFalke
commented at 5:18 pm on May 27, 2020:
member
Concept ACK
It would be good to motivate the change. Maybe something like this?
gillichu renamed this:
Moved the CScriptNum asserts into the unit test in script.py
[WIP]. Moved the CScriptNum asserts into the unit test in script.py
on May 27, 2020
gillichu renamed this:
[WIP]. Moved the CScriptNum asserts into the unit test in script.py
[WIP] Moved the CScriptNum asserts into the unit test in script.py
on May 27, 2020
in
test/functional/test_framework/script.py:763
in
4b38a1cd1boutdated
758+ # sequence numbers must not be max for nLockTime to have effect
759+ coinbase_tx.vin[0].nSequence = 2 ** 32 - 2
760+ coinbase_tx.rehash()
761+
762+ # round-trip the encoded bip34 block height commitment
763+ self.assert_equal(CScriptNum.decode(coinbase_tx.vin[0].scriptSig), next_height)
I think for a unit test it could make sense to simply hard-code the value of coinbase_tx.vin[0].scriptSig instead of computing it every single time by mining 200 blocks.
gillichu marked this as a draft
on May 27, 2020
in
test/functional/mining_basic.py:94
in
0107629e29outdated
87- # sequence numbers must not be max for nLockTime to have effect
88- coinbase_tx.vin[0].nSequence = 2 ** 32 - 2
89- coinbase_tx.rehash()
90-
91- # round-trip the encoded bip34 block height commitment
92- assert_equal(CScriptNum.decode(coinbase_tx.vin[0].scriptSig), next_height)
Correct. I missed that this is not the coinbase from the previous generatetoaddress. It seems the test was moved, so this should be correct now in master.
DrahtBot added the label
Tests
on May 27, 2020
in
test/functional/mining_basic.py:98
in
fba67c6672outdated
I think you should only really be touching these 4 lines in mining_basic.py. The first assertion should stay like Marco said, and you’ll need to keep the import statement in order for it to work.
in
test/functional/test_framework/script.py:735
in
fba67c6672outdated
nit: maybe name this test_cscriptnum_encoding or something else more specific? Since there are other encode/decode functions in this file, i.e. for CScriptOp.
in
test/functional/test_framework/script.py:736
in
fba67c6672outdated
Yes—more tests would be welcome here IMO,
Maybe the list of test numbers in scriptnum_tests.cpp also comes in useful here.
glozow
commented at 7:02 pm on May 27, 2020:
member
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
commented at 7:06 pm on May 27, 2020:
contributor
DrahtBot
commented at 7:47 pm on May 27, 2020:
member
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
Conflicts
No conflicts as of last run.
gillichu force-pushed
on May 27, 2020
gillichu renamed this:
[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
on May 27, 2020
gillichu force-pushed
on May 27, 2020
gillichu renamed this:
[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
on May 28, 2020
gillichu marked this as ready for review
on May 28, 2020
in
test/functional/mining_basic.py:89
in
9d5dd8752aoutdated
81@@ -83,20 +82,12 @@ def assert_submitblock(block, result_str_1, result_str_2=None):
82 self.log.info("getblocktemplate: Test capability advertised")
83 assert 'proposal' in tmpl['capabilities']
84 assert 'coinbasetxn' not in tmpl
85-
86 next_height = int(tmpl["height"])
87 coinbase_tx = create_coinbase(height=next_height)
88- # sequence numbers must not be max for nLockTime to have effect
Any reason to remove this comment and the empty lines?
MarcoFalke approved
MarcoFalke
commented at 11:34 am on May 28, 2020:
member
Almost ACK9d5dd8752a1bc89f7fcfc1a9b6e0d042b9c20616
laanwj
commented at 2:59 pm on May 28, 2020:
member
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:
09d5dd8752… (pull/19082/head) [test] Migrates the CScriptNum decode tests into a unit test, moving some changes made in [#14816](/bitcoin-bitcoin/14816/). This was made possible by the integration of test_framework unit testing in [#18576](/bitcoin-bitcoin/18576/).
gillichu force-pushed
on May 28, 2020
gillichu force-pushed
on May 28, 2020
gillichu force-pushed
on May 28, 2020
gillichu force-pushed
on May 28, 2020
in
test/functional/test_framework/script.py:739
in
401487d24eoutdated
Question: I’m not too familiar with what “catch python regression” means 😕 so I’m kind of confused about the difference betweentest_cscriptnum_encoding and test_cscriptnum_encoding_large. Could they be combined in the values array?
DrahtBot added the label
Needs rebase
on Jun 1, 2020
gillichu force-pushed
on Jun 2, 2020
gillichu force-pushed
on Jun 2, 2020
DrahtBot removed the label
Needs rebase
on Jun 2, 2020
[test] CScriptNum Decode Check as Unit Tests
Migrates the CScriptNum decode tests into a unit test, and moved some
changes made in #14816. Made possible by the integration of
test_framework unit testing in #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.
7daffc6a90
gillichu force-pushed
on Jun 3, 2020
gillichu
commented at 8:31 pm on June 3, 2020:
none
rebased the branch, addressed review comments and updated tests. thanks for the review @laanwj@gzhao408@jnewbery comments have been addressed!
jnewbery
commented at 3:03 am on June 4, 2020:
member
Thanks @gillichu. I think the PR title, commit summary and commit details could be made a bit clearer:
switch to indicative mood (eg “test: Moved the CScriptNum asserts into the unit test in script.py” -> “Add CScriptNum and create_coinbase unit tests”, “Migrates the CScriptNum decode tests” -> “Migrate the CScriptNum decode tests”, etc)
no need to include the complete history ("… changes made in #14816", “… integration of test_framework unit testing in #18576.”).
laanwj
commented at 3:26 pm on June 4, 2020:
member
ACK7daffc6a90a797ce7c365a893a31a31b0206985c
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 merged this
on Jun 4, 2020
laanwj closed this
on Jun 4, 2020
sidhujag referenced this in commit
f5a1bed93b
on Jun 4, 2020
fanquake referenced this in commit
45a6811d36
on Jun 11, 2020
sidhujag referenced this in commit
2bd52568a8
on Jun 11, 2020
Fabcien referenced this in commit
2a3ba49ebb
on Mar 1, 2021
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: 2025-05-19 18:12 UTC
This site is hosted by @0xB10C More mirrored repositories can be found on mirror.b10c.me