Skip to content

Commit a733ad5

Browse files
committed
Add bn2vch test to functional tests
1 parent a3ad645 commit a733ad5

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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()

test/functional/test_runner.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@
222222
'rpc_help.py',
223223
'feature_help.py',
224224
'feature_shutdown.py',
225+
'framework_test_script.py',
225226
# Don't append tests at the end to avoid merge conflicts
226227
# Put them in a random line within the section that fits their approximate run-time
227228
]
@@ -614,7 +615,7 @@ def was_successful(self):
614615
def check_script_prefixes():
615616
"""Check that test scripts start with one of the allowed name prefixes."""
616617

617-
good_prefixes_re = re.compile("(example|feature|interface|mempool|mining|p2p|rpc|wallet|tool)_")
618+
good_prefixes_re = re.compile("^(example|feature|interface|mempool|mining|p2p|rpc|wallet|tool|framework_test)_")
618619
bad_script_names = [script for script in ALL_SCRIPTS if good_prefixes_re.match(script) is None]
619620

620621
if bad_script_names:

0 commit comments

Comments
 (0)