aboutsummaryrefslogtreecommitdiff
path: root/test/functional/test_framework/script.py
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@protonmail.com>2020-06-04 17:26:47 +0200
committerWladimir J. van der Laan <laanwj@protonmail.com>2020-06-04 17:28:55 +0200
commit39afe5b1c68c5979b2ef2f03b60ec6a57901328f (patch)
tree8e8a201d370d839fc7fd054727bf01b6b6853df0 /test/functional/test_framework/script.py
parent365f1082e1e6ff1c2f53552c3871223e87a9d43f (diff)
parent7daffc6a90a797ce7c365a893a31a31b0206985c (diff)
downloadbitcoin-39afe5b1c68c5979b2ef2f03b60ec6a57901328f.tar.xz
Merge #19082: test: Moved the CScriptNum asserts into the unit test in script.py
7daffc6a90a797ce7c365a893a31a31b0206985c [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 7daffc6a90a797ce7c365a893a31a31b0206985c Tree-SHA512: 17a04a4bfff1b1817bfc167824c679455d9e06e6e0164c00a7e44f8aa5041c5f5080adcc1452fd80ba1a6d8409f976c982bc481d686c434edf97a5893a32a436
Diffstat (limited to 'test/functional/test_framework/script.py')
-rw-r--r--test/functional/test_framework/script.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/test/functional/test_framework/script.py b/test/functional/test_framework/script.py
index bc1b5b26fc..cc5f8307d3 100644
--- a/test/functional/test_framework/script.py
+++ b/test/functional/test_framework/script.py
@@ -732,3 +732,9 @@ class TestFrameworkScript(unittest.TestCase):
self.assertEqual(bn2vch(0xFFFFFFFF), bytes([0xFF, 0xFF, 0xFF, 0xFF, 0x00]))
self.assertEqual(bn2vch(123456789), bytes([0x15, 0xCD, 0x5B, 0x07]))
self.assertEqual(bn2vch(-54321), bytes([0x31, 0xD4, 0x80]))
+
+ def test_cscriptnum_encoding(self):
+ # round-trip negative and multi-byte CScriptNums
+ values = [0, 1, -1, -2, 127, 128, -255, 256, (1 << 15) - 1, -(1 << 16), (1 << 24) - 1, (1 << 31), 1 - (1 << 32), 1 << 40, 1500, -1500]
+ for value in values:
+ self.assertEqual(CScriptNum.decode(CScriptNum.encode(CScriptNum(value))), value)