|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# Copyright (c) 2020 The Bitcoin Core developers |
| 3 | +# Distributed under the MIT software license, see the accompanying |
| 4 | +# file COPYING or http://www.opensource.org/licenses/mit-license.php. |
| 5 | +"""Tests for test_framework.script.""" |
| 6 | + |
| 7 | +from test_framework.test_framework import BitcoinTestFramework |
| 8 | +from test_framework.script import bn2vch |
| 9 | +from test_framework.util import assert_equal |
| 10 | + |
| 11 | +def test_bn2vch(): |
| 12 | + assert_equal(bn2vch(0), bytes([])) |
| 13 | + assert_equal(bn2vch(1), bytes([0x01])) |
| 14 | + assert_equal(bn2vch(-1), bytes([0x81])) |
| 15 | + assert_equal(bn2vch(0x7F), bytes([0x7F])) |
| 16 | + assert_equal(bn2vch(-0x7F), bytes([0xFF])) |
| 17 | + assert_equal(bn2vch(0x80), bytes([0x80, 0x00])) |
| 18 | + assert_equal(bn2vch(-0x80), bytes([0x80, 0x80])) |
| 19 | + assert_equal(bn2vch(0xFF), bytes([0xFF, 0x00])) |
| 20 | + assert_equal(bn2vch(-0xFF), bytes([0xFF, 0x80])) |
| 21 | + assert_equal(bn2vch(0x100), bytes([0x00, 0x01])) |
| 22 | + assert_equal(bn2vch(-0x100), bytes([0x00, 0x81])) |
| 23 | + assert_equal(bn2vch(0x7FFF), bytes([0xFF, 0x7F])) |
| 24 | + assert_equal(bn2vch(-0x8000), bytes([0x00, 0x80, 0x80])) |
| 25 | + assert_equal(bn2vch(-0x7FFFFF), bytes([0xFF, 0xFF, 0xFF])) |
| 26 | + assert_equal(bn2vch(0x80000000), bytes([0x00, 0x00, 0x00, 0x80, 0x00])) |
| 27 | + assert_equal(bn2vch(-0x80000000), bytes([0x00, 0x00, 0x00, 0x80, 0x80])) |
| 28 | + assert_equal(bn2vch(0xFFFFFFFF), bytes([0xFF, 0xFF, 0xFF, 0xFF, 0x00])) |
| 29 | + |
| 30 | + assert_equal(bn2vch(123456789), bytes([0x15, 0xCD, 0x5B, 0x07])) |
| 31 | + assert_equal(bn2vch(-54321), bytes([0x31, 0xD4, 0x80])) |
| 32 | + |
| 33 | +class FrameworkTestScript(BitcoinTestFramework): |
| 34 | + def setup_network(self): |
| 35 | + pass |
| 36 | + |
| 37 | + def set_test_params(self): |
| 38 | + self.num_nodes = 0 |
| 39 | + |
| 40 | + def run_test(self): |
| 41 | + test_bn2vch() |
| 42 | + |
| 43 | +if __name__ == '__main__': |
| 44 | + FrameworkTestScript().main() |
0 commit comments