Add CScriptNum decode python implementation in functional suite #14816
pull instagibbs wants to merge 1 commits into bitcoin:master from instagibbs:functional_cscriptnum_decode changing 2 files +26 −2-
instagibbs commented at 3:22 pm on November 27, 2018: memberI needed this for reasons and thought it’d be good to upsteam it.
-
fanquake added the label Tests on Nov 27, 2018
-
in test/functional/test_framework/script.py:374 in 104a6bdd31 outdated
370@@ -371,11 +371,12 @@ def __init__(self, d=0): 371 372 @staticmethod 373 def encode(obj): 374+ val = obj.value
promag commented at 4:17 pm on November 27, 2018:Could discard these unrelated changes.
instagibbs commented at 4:25 pm on November 27, 2018:it reduces the verbosity of it, I can remove but seemed better to me.
promag commented at 4:34 pm on November 28, 2018:I understand but IMO it’s better without.
instagibbs commented at 4:46 pm on November 28, 2018:already removed
promag commented at 4:54 pm on November 28, 2018:Yeah I know :)in test/functional/test_framework/script.py:396 in 104a6bdd31 outdated
392+ value = vch[1:] 393+ # Mask for all but the highest result bit 394+ num_mask = (2**(len(value)*8) - 1) >> 1 395+ if len(value) == 0: 396+ return 0 397+ else :
promag commented at 4:18 pm on November 27, 2018:nit, remove extra space.
instagibbs commented at 4:43 pm on November 27, 2018:donepromag commented at 4:21 pm on November 27, 2018: memberRestarted appveyor.
I needed this for reasons and thought it’d be good to upsteam it.
Could add one reason? otherwise this is dead code.
instagibbs commented at 4:25 pm on November 27, 2018: member@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 commented at 4:28 pm on November 27, 2018: member@instagibbs I just think you could add one usage here.instagibbs force-pushed on Nov 27, 2018instagibbs force-pushed on Nov 27, 2018instagibbs force-pushed on Nov 27, 2018instagibbs commented at 4:45 pm on November 27, 2018: memberAddressed issues, and added a single usage in a test.in test/functional/mining_basic.py:74 in 9f9bd43026 outdated
70+ coinbase_tx = create_coinbase(height=next_height) 71 # sequence numbers must not be max for nLockTime to have effect 72 coinbase_tx.vin[0].nSequence = 2 ** 32 - 2 73 coinbase_tx.rehash() 74 75+ # round-tip the encoded bip34 block height commitment
Empact commented at 8:23 pm on November 27, 2018:typo: tip/trip
instagibbs commented at 1:32 pm on November 29, 2018:fixedin test/functional/test_framework/script.py:393 in 9f9bd43026 outdated
384@@ -385,6 +385,23 @@ def encode(obj): 385 r[-1] |= 0x80 386 return bytes([len(r)]) + r 387 388+ @staticmethod 389+ def decode(vch): 390+ # We assume valid push_size and minimal encoding 391+ value = vch[1:] 392+ # Mask for all but the highest result bit 393+ num_mask = (2**(len(value)*8) - 1) >> 1
promag commented at 9:57 am on November 28, 2018:nit, could move this to L401.in test/functional/test_framework/script.py:396 in 9f9bd43026 outdated
391+ value = vch[1:] 392+ # Mask for all but the highest result bit 393+ num_mask = (2**(len(value)*8) - 1) >> 1 394+ if len(value) == 0: 395+ return 0 396+ else:
promag commented at 9:57 am on November 28, 2018:nit, could remove else branch, and above justreturn 0 if len(value) == 0
.promag commented at 9:59 am on November 28, 2018: memberThanks for adding the test, I think it makes this PR more complete. I’m leaving two nits for your consideration.
utACK 9f9bd43.
in test/functional/test_framework/script.py:398 in 9f9bd43026 outdated
393+ num_mask = (2**(len(value)*8) - 1) >> 1 394+ if len(value) == 0: 395+ return 0 396+ else: 397+ result = 0 398+ for i in range(len(value)):
practicalswift commented at 12:39 pm on November 28, 2018:If @promag:s suggestion is not implemented: useenumerate
which is more idiomatic :-)in test/functional/test_framework/script.py:393 in 9f9bd43026 outdated
389+ def decode(vch): 390+ # We assume valid push_size and minimal encoding 391+ value = vch[1:] 392+ # Mask for all but the highest result bit 393+ num_mask = (2**(len(value)*8) - 1) >> 1 394+ if len(value) == 0:
practicalswift commented at 12:39 pm on November 28, 2018:If @promag:s suggestions is not implemented: Useif not value:
which is more idiomatic
instagibbs commented at 4:17 pm on November 28, 2018:fwiw I wouldn’t know hot to read that suggestion properly, sorry
practicalswift commented at 7:26 pm on November 28, 2018:Yes leave it as is - it was just a nit :-)
I just meant to say that
if sequence:
andif 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 thatvalue
is a sequence :-)instagibbs force-pushed on Nov 28, 2018instagibbs commented at 4:17 pm on November 28, 2018: membercomments addressed, added multi-byte and negative round-trip testing as wellAdd CScriptNum decode python implementation in functional suite 2012d4df23instagibbs force-pushed on Nov 29, 2018scravy approvedscravy commented at 1:35 pm on November 29, 2018: contributorutACKpromag commented at 11:21 pm on November 30, 2018: memberutACK 2012d4d, nice to have more usages.maguayo approvedmaguayo commented at 5:35 pm on December 1, 2018: noneutACKlaanwj commented at 10:27 am on December 4, 2018: memberutACK 2012d4df23b7b065ccc1dbe596073d98e428fd3dlaanwj merged this on Dec 4, 2018laanwj closed this on Dec 4, 2018
laanwj referenced this in commit 0257062e50 on Dec 4, 2018gillichu referenced this in commit 8a04208077 on May 27, 2020gillichu referenced this in commit 9d5dd8752a on May 27, 2020gillichu referenced this in commit 48d08c0899 on May 28, 2020gillichu referenced this in commit 74b863e51c on May 28, 2020gillichu referenced this in commit c368d241da on May 28, 2020gillichu referenced this in commit 401487d24e on May 28, 2020gillichu referenced this in commit ef4cce175b on May 31, 2020gillichu referenced this in commit 58c4a30b0d on May 31, 2020gillichu referenced this in commit 63cba4b7fe on Jun 1, 2020gillichu referenced this in commit 91c08205bc on Jun 2, 2020gillichu referenced this in commit 60927840ff on Jun 2, 2020gillichu referenced this in commit 7daffc6a90 on Jun 3, 2020laanwj referenced this in commit 39afe5b1c6 on Jun 4, 2020sidhujag referenced this in commit f5a1bed93b on Jun 4, 2020deadalnix referenced this in commit d6121c79b0 on Jun 24, 2020stackman27 referenced this in commit 35dc414588 on Jun 26, 2020ftrader referenced this in commit 9b59864b98 on Aug 17, 2020Fabcien referenced this in commit 2a3ba49ebb on Mar 1, 2021Munkybooty referenced this in commit 66ab55baa1 on Aug 2, 2021Munkybooty referenced this in commit 1a47ad19a2 on Aug 3, 2021Munkybooty referenced this in commit c26cda307c on Aug 5, 2021Munkybooty referenced this in commit 76c1033677 on Aug 5, 2021Munkybooty referenced this in commit e65120cc0f on Aug 8, 2021Munkybooty referenced this in commit 92563a82f3 on Aug 11, 2021Munkybooty referenced this in commit 07b22f7b2b on Aug 11, 2021Munkybooty referenced this in commit 2d5a90f3b5 on Aug 15, 2021DrahtBot locked this on Aug 16, 2022
github-metadata-mirror
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: 2024-12-22 06:12 UTC
This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me