Skip to content

Commit 9be2246

Browse files
committed
Test: Introduce test for p2pk signet chains (reusable as param generator)
1 parent 37a3064 commit 9be2246

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

test/functional/feature_signet.py

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) 2018-2018 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+
"""Test signet
6+
7+
Test chains that use signed blocks instead of pow (signets).
8+
"""
9+
10+
from binascii import hexlify
11+
import os
12+
13+
from test_framework import key, script
14+
from test_framework.test_framework import BitcoinTestFramework
15+
from test_framework.util import (
16+
assert_equal,
17+
connect_nodes_bi,
18+
hex_str_to_bytes,
19+
)
20+
21+
class SignetTest(BitcoinTestFramework):
22+
23+
def add_options(self, parser):
24+
parser.add_argument('--config_path', dest='config_path', default='',
25+
help='Path to write down the generated config for signet into files.')
26+
27+
def set_test_params(self):
28+
self.setup_clean_chain = True
29+
self.num_nodes = 3
30+
self.extra_args = [[
31+
'-fallbackfee=0.00001',
32+
'-addresstype=legacy',
33+
'-deprecatedrpc=validateaddress',
34+
'-bech32_hrp=sb',
35+
'-pchmessagestart=F0C7706A',
36+
'-pubkeyprefix=125',
37+
'-scriptprefix=87',
38+
'-secretprefix=217',
39+
'-extpubkeyprefix=043587CF',
40+
'-extprvkeyprefix=04358394',
41+
]] * 3
42+
43+
def setup_network(self):
44+
45+
self.add_nodes(self.num_nodes, self.extra_args)
46+
47+
self.start_node(2)
48+
addr = self.nodes[2].getnewaddress()
49+
k = key.CECKey()
50+
pub = self.nodes[2].validateaddress(addr)['pubkey']
51+
k.set_pubkey(hex_str_to_bytes(pub))
52+
pubkey = key.CPubKey(k.get_pubkey())
53+
wif = self.nodes[2].dumpprivkey(addr)
54+
bscript = script.CScript([pubkey, script.OP_CHECKSIG])
55+
blockscript = hexlify(bscript).decode('ascii')
56+
57+
if self.options.config_path == '':
58+
self.log.info('Generated wif %s' % wif)
59+
self.log.info('Generated blockscript %s' % blockscript)
60+
else:
61+
with open(os.path.join(self.options.config_path, 'wif.txt'), 'w', encoding='utf8') as f:
62+
f.write(wif + '\n')
63+
with open(os.path.join(self.options.config_path, 'signet_blockscript.txt'), 'w', encoding='utf8') as f:
64+
f.write(blockscript + '\n')
65+
66+
for i in range(2):
67+
self.extra_args[i].append('-signet_blockscript=%s' % blockscript)
68+
self.start_node(i)
69+
self.nodes[i].importprivkey(wif)
70+
for i in range(2):
71+
connect_nodes_bi(self.nodes, i, i + 1)
72+
self.sync_all([self.nodes[0:1]])
73+
74+
def run_test(self):
75+
76+
self.nodes[0].generate(100)
77+
self.sync_all([self.nodes[0:1]])
78+
self.nodes[1].generate(100)
79+
self.sync_all([self.nodes[0:1]])
80+
81+
assert_equal(self.nodes[0].getblockcount(), self.nodes[1].getblockcount())
82+
83+
if __name__ == '__main__':
84+
SignetTest().main()

test/functional/test_runner.py

+1
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
'p2p_invalid_block.py',
120120
'p2p_invalid_tx.py',
121121
'rpc_createmultisig.py',
122+
'feature_signet.py',
122123
'feature_versionbits_warning.py',
123124
'rpc_preciousblock.py',
124125
'wallet_importprunedfunds.py',

0 commit comments

Comments
 (0)