Skip to content
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

Merged
merged 1 commit into from Dec 4, 2018

Conversation

@instagibbs
Copy link
Member

@instagibbs instagibbs commented Nov 27, 2018

I needed this for reasons and thought it'd be good to upsteam it.

@fanquake fanquake added the Tests label Nov 27, 2018
Copy link
Member

@promag promag left a comment

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
Copy link
Member

@promag promag Nov 27, 2018

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.

Copy link
Member Author

@instagibbs instagibbs Nov 27, 2018

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.

Copy link
Member

@promag promag Nov 28, 2018

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.

Copy link
Member Author

@instagibbs instagibbs Nov 28, 2018

Choose a reason for hiding this comment

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

already removed

Copy link
Member

@promag promag Nov 28, 2018

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 :
Copy link
Member

@promag promag Nov 27, 2018

Choose a reason for hiding this comment

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

nit, remove extra space.

Copy link
Member Author

@instagibbs instagibbs Nov 27, 2018

Choose a reason for hiding this comment

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

done

@instagibbs
Copy link
Member Author

@instagibbs instagibbs commented Nov 27, 2018

@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.

@promag
Copy link
Member

@promag promag commented Nov 27, 2018

@instagibbs I just think you could add one usage here.

@instagibbs instagibbs force-pushed the functional_cscriptnum_decode branch 3 times, most recently from 920ed73 to 9f9bd43 Nov 27, 2018
@instagibbs
Copy link
Member Author

@instagibbs instagibbs commented Nov 27, 2018

Addressed issues, and added a single usage in a test.

Copy link
Member

@promag promag left a comment

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
Copy link
Member

@promag promag Nov 28, 2018

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:
Copy link
Member

@promag promag Nov 28, 2018

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)):
Copy link
Contributor

@practicalswift practicalswift Nov 28, 2018

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:
Copy link
Contributor

@practicalswift practicalswift Nov 28, 2018

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

Copy link
Member Author

@instagibbs instagibbs Nov 28, 2018

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

Copy link
Contributor

@practicalswift practicalswift Nov 28, 2018

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 :-)

@instagibbs instagibbs force-pushed the functional_cscriptnum_decode branch from 9f9bd43 to dd27c1c Nov 28, 2018
@instagibbs
Copy link
Member Author

@instagibbs instagibbs commented Nov 28, 2018

comments addressed, added multi-byte and negative round-trip testing as well

# 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
Copy link
Member

@Empact Empact Nov 28, 2018

Choose a reason for hiding this comment

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

typo: tip/trip

Copy link
Member Author

@instagibbs instagibbs Nov 29, 2018

Choose a reason for hiding this comment

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

fixed

@instagibbs instagibbs force-pushed the functional_cscriptnum_decode branch from dd27c1c to 2012d4d Nov 29, 2018
scravy
scravy approved these changes Nov 29, 2018
Copy link
Contributor

@scravy scravy left a comment

utACK

@promag
Copy link
Member

@promag promag commented Nov 30, 2018

utACK 2012d4d, nice to have more usages.

maguayo
maguayo approved these changes Dec 1, 2018
Copy link

@maguayo maguayo left a comment

utACK

@laanwj
Copy link
Member

@laanwj laanwj commented Dec 4, 2018

utACK 2012d4d

@laanwj laanwj merged commit 2012d4d into bitcoin:master Dec 4, 2018
2 checks passed
laanwj added a commit that referenced this issue Dec 4, 2018
…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
gillichu pushed a commit to gillichu/bitcoin that referenced this issue May 27, 2020
…some changes made in bitcoin#14816. This was made possible by the integration of test_framework unit testing in bitcoin#18576.
gillichu pushed a commit to gillichu/bitcoin that referenced this issue May 27, 2020
…some changes made in bitcoin#14816. This was made possible by the integration of test_framework unit testing in bitcoin#18576.
gillichu pushed a commit to gillichu/bitcoin that referenced this issue May 28, 2020
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.
gillichu pushed a commit to gillichu/bitcoin that referenced this issue May 28, 2020
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.
gillichu pushed a commit to gillichu/bitcoin that referenced this issue May 28, 2020
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.
gillichu pushed a commit to gillichu/bitcoin that referenced this issue May 28, 2020
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.
gillichu pushed a commit to gillichu/bitcoin that referenced this issue May 31, 2020
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.
gillichu pushed a commit to gillichu/bitcoin that referenced this issue May 31, 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 pushed a commit to gillichu/bitcoin that referenced this issue 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 pushed a commit to gillichu/bitcoin that referenced this issue Jun 2, 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 pushed a commit to gillichu/bitcoin that referenced this issue Jun 2, 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 pushed a commit to gillichu/bitcoin that referenced this issue Jun 3, 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.
laanwj added a commit that referenced this issue Jun 4, 2020
…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
sidhujag added a commit to syscoin/syscoin that referenced this issue 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
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this issue Jun 24, 2020
…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
stackman27 added a commit to stackman27/bitcoin that referenced this issue Jun 26, 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.
ftrader added a commit to bitcoin-cash-node/bitcoin-cash-node that referenced this issue Aug 17, 2020
…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
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this issue 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
Munkybooty added a commit to Munkybooty/dash that referenced this issue Aug 2, 2021
…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
Munkybooty added a commit to Munkybooty/dash that referenced this issue Aug 3, 2021
…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
Munkybooty added a commit to Munkybooty/dash that referenced this issue Aug 5, 2021
…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
Munkybooty added a commit to Munkybooty/dash that referenced this issue Aug 5, 2021
…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
Munkybooty added a commit to Munkybooty/dash that referenced this issue Aug 8, 2021
…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
Munkybooty added a commit to Munkybooty/dash that referenced this issue Aug 11, 2021
…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
Munkybooty added a commit to Munkybooty/dash that referenced this issue Aug 11, 2021
…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
Munkybooty added a commit to Munkybooty/dash that referenced this issue Aug 15, 2021
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

8 participants