-
Notifications
You must be signed in to change notification settings - Fork 36.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add CScriptNum decode python implementation in functional suite #14816
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Restarted appveyor.
I needed this for reasons and thought it'd be good to upsteam it.
Could add one reason? otherwise this is dead code.
@@ -371,11 +371,12 @@ def __init__(self, d=0): | |||
|
|||
@staticmethod | |||
def encode(obj): | |||
val = obj.value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could discard these unrelated changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it reduces the verbosity of it, I can remove but seemed better to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand but IMO it's better without.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
already removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I know :)
num_mask = (2**(len(value)*8) - 1) >> 1 | ||
if len(value) == 0: | ||
return 0 | ||
else : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, remove extra space.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@promag it can(should?) be used in tests in the future. Allows extraction of blockheight from the coinbase transaction, for example. I can think a bit more where to stick this into a test, which I noted in the OP. |
@instagibbs I just think you could add one usage here. |
920ed73
to
9f9bd43
Compare
Addressed issues, and added a single usage in a test. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding the test, I think it makes this PR more complete. I'm leaving two nits for your consideration.
utACK 9f9bd43.
# We assume valid push_size and minimal encoding | ||
value = vch[1:] | ||
# Mask for all but the highest result bit | ||
num_mask = (2**(len(value)*8) - 1) >> 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, could move this to L401.
num_mask = (2**(len(value)*8) - 1) >> 1 | ||
if len(value) == 0: | ||
return 0 | ||
else: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, could remove else branch, and above just return 0 if len(value) == 0
.
return 0 | ||
else: | ||
result = 0 | ||
for i in range(len(value)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If @promag:s suggestion is not implemented: use enumerate
which is more idiomatic :-)
value = vch[1:] | ||
# Mask for all but the highest result bit | ||
num_mask = (2**(len(value)*8) - 1) >> 1 | ||
if len(value) == 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If @promag:s suggestions is not implemented: Use if not value:
which is more idiomatic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fwiw I wouldn't know hot to read that suggestion properly, sorry
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes leave it as is - it was just a nit :-)
I just meant to say that if sequence:
and if not sequence:
are very common Python idioms for checking non-emptiness and emptiness of sequences. Perhaps this is not the ideal case for my suggestion since it is not obvious from the variable name that value
is a sequence :-)
9f9bd43
to
dd27c1c
Compare
comments addressed, added multi-byte and negative round-trip testing as well |
test/functional/mining_basic.py
Outdated
# sequence numbers must not be max for nLockTime to have effect | ||
coinbase_tx.vin[0].nSequence = 2 ** 32 - 2 | ||
coinbase_tx.rehash() | ||
|
||
# round-tip the encoded bip34 block height commitment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: tip/trip
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
dd27c1c
to
2012d4d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK
utACK 2012d4d, nice to have more usages. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK
utACK 2012d4d |
…al suite 2012d4d Add CScriptNum decode python implementation in functional suite (Gregory Sanders) Pull request description: I needed this for reasons and thought it'd be good to upsteam it. Tree-SHA512: 6ea89fa2a5f5a7759ba722f2b4ed5cd6423ebfff4e83ac8b8b5c935e6aa479684e626c5f41fa020816d2a9079a99af5564e30808594d5c13e3b51ec9b474926d
…some changes made in bitcoin#14816. This was made possible by the integration of test_framework unit testing in bitcoin#18576.
…some changes made in bitcoin#14816. This was made possible by the integration of test_framework unit testing in bitcoin#18576.
Migrates the CScriptNum decode tests into a unit test, moving some changes made in bitcoin#14816. This was made possible by the integration of test_framework unit testing in bitcoin#18576.
Migrates the CScriptNum decode tests into a unit test, moving some changes made in bitcoin#14816. This was made possible by the integration of test_framework unit testing in bitcoin#18576.
Migrates the CScriptNum decode tests into a unit test, moving some changes made in bitcoin#14816. This was made possible by the integration of test_framework unit testing in bitcoin#18576.
Migrates the CScriptNum decode tests into a unit test, moving some changes made in bitcoin#14816. This was made possible by the integration of test_framework unit testing in bitcoin#18576. Also adds a unit test testing the decode method with larger ints, similar to the scriptnum_tests.cpp file.
Migrates the CScriptNum decode tests into a unit test, moving some changes made in bitcoin#14816. This was made possible by the integration of test_framework unit testing in bitcoin#18576. Also extends the original test with larger ints, similar to the scriptnum_tests.cpp file.
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.
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.
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.
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.
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.
…n script.py 7daffc6 [test] CScriptNum Decode Check as Unit Tests (Gillian Chu) Pull request description: 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. ACKs for top commit: laanwj: ACK 7daffc6 Tree-SHA512: 17a04a4bfff1b1817bfc167824c679455d9e06e6e0164c00a7e44f8aa5041c5f5080adcc1452fd80ba1a6d8409f976c982bc481d686c434edf97a5893a32a436
… 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
…al suite Summary: 2012d4df2 Add CScriptNum decode python implementation in functional suite (Gregory Sanders) Pull request description: I needed this for reasons and thought it'd be good to upsteam it. Tree-SHA512: 6ea89fa2a5f5a7759ba722f2b4ed5cd6423ebfff4e83ac8b8b5c935e6aa479684e626c5f41fa020816d2a9079a99af5564e30808594d5c13e3b51ec9b474926d Backport of Core [[bitcoin/bitcoin#14816 | PR14816]] Test Plan: `test_runner.py mining_basic` Reviewers: #bitcoin_abc, majcosta Reviewed By: #bitcoin_abc, majcosta Subscribers: majcosta Differential Revision: https://reviews.bitcoinabc.org/D6713
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.
…al suite Summary: 2012d4df2 Add CScriptNum decode python implementation in functional suite (Gregory Sanders) Pull request description: I needed this for reasons and thought it'd be good to upsteam it. Tree-SHA512: 6ea89fa2a5f5a7759ba722f2b4ed5cd6423ebfff4e83ac8b8b5c935e6aa479684e626c5f41fa020816d2a9079a99af5564e30808594d5c13e3b51ec9b474926d Backport of Core [[bitcoin/bitcoin#14816 | PR14816]] Test Plan: `test_runner.py mining_basic` Reviewers: #bitcoin_abc, majcosta Reviewed By: #bitcoin_abc, majcosta Subscribers: majcosta Differential Revision: https://reviews.bitcoinabc.org/D6713
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
…unctional suite 2012d4d Add CScriptNum decode python implementation in functional suite (Gregory Sanders) Pull request description: I needed this for reasons and thought it'd be good to upsteam it. Tree-SHA512: 6ea89fa2a5f5a7759ba722f2b4ed5cd6423ebfff4e83ac8b8b5c935e6aa479684e626c5f41fa020816d2a9079a99af5564e30808594d5c13e3b51ec9b474926d # Conflicts: # test/functional/mining_basic.py
…unctional suite 2012d4d Add CScriptNum decode python implementation in functional suite (Gregory Sanders) Pull request description: I needed this for reasons and thought it'd be good to upsteam it. Tree-SHA512: 6ea89fa2a5f5a7759ba722f2b4ed5cd6423ebfff4e83ac8b8b5c935e6aa479684e626c5f41fa020816d2a9079a99af5564e30808594d5c13e3b51ec9b474926d # Conflicts: # test/functional/mining_basic.py
…unctional suite 2012d4d Add CScriptNum decode python implementation in functional suite (Gregory Sanders) Pull request description: I needed this for reasons and thought it'd be good to upsteam it. Tree-SHA512: 6ea89fa2a5f5a7759ba722f2b4ed5cd6423ebfff4e83ac8b8b5c935e6aa479684e626c5f41fa020816d2a9079a99af5564e30808594d5c13e3b51ec9b474926d # Conflicts: # test/functional/mining_basic.py
…unctional suite 2012d4d Add CScriptNum decode python implementation in functional suite (Gregory Sanders) Pull request description: I needed this for reasons and thought it'd be good to upsteam it. Tree-SHA512: 6ea89fa2a5f5a7759ba722f2b4ed5cd6423ebfff4e83ac8b8b5c935e6aa479684e626c5f41fa020816d2a9079a99af5564e30808594d5c13e3b51ec9b474926d # Conflicts: # test/functional/mining_basic.py
…unctional suite 2012d4d Add CScriptNum decode python implementation in functional suite (Gregory Sanders) Pull request description: I needed this for reasons and thought it'd be good to upsteam it. Tree-SHA512: 6ea89fa2a5f5a7759ba722f2b4ed5cd6423ebfff4e83ac8b8b5c935e6aa479684e626c5f41fa020816d2a9079a99af5564e30808594d5c13e3b51ec9b474926d # Conflicts: # test/functional/mining_basic.py
…unctional suite 2012d4d Add CScriptNum decode python implementation in functional suite (Gregory Sanders) Pull request description: I needed this for reasons and thought it'd be good to upsteam it. Tree-SHA512: 6ea89fa2a5f5a7759ba722f2b4ed5cd6423ebfff4e83ac8b8b5c935e6aa479684e626c5f41fa020816d2a9079a99af5564e30808594d5c13e3b51ec9b474926d
…unctional suite 2012d4d Add CScriptNum decode python implementation in functional suite (Gregory Sanders) Pull request description: I needed this for reasons and thought it'd be good to upsteam it. Tree-SHA512: 6ea89fa2a5f5a7759ba722f2b4ed5cd6423ebfff4e83ac8b8b5c935e6aa479684e626c5f41fa020816d2a9079a99af5564e30808594d5c13e3b51ec9b474926d
…unctional suite 2012d4d Add CScriptNum decode python implementation in functional suite (Gregory Sanders) Pull request description: I needed this for reasons and thought it'd be good to upsteam it. Tree-SHA512: 6ea89fa2a5f5a7759ba722f2b4ed5cd6423ebfff4e83ac8b8b5c935e6aa479684e626c5f41fa020816d2a9079a99af5564e30808594d5c13e3b51ec9b474926d
I needed this for reasons and thought it'd be good to upsteam it.