Skip to content

Commit 038d2a6

Browse files
committed
test: add test for signet miner script
1 parent 449b96e commit 038d2a6

File tree

3 files changed

+66
-1
lines changed

3 files changed

+66
-1
lines changed

Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ DIST_CONTRIB = \
4747
$(top_srcdir)/test/sanitizer_suppressions/tsan \
4848
$(top_srcdir)/test/sanitizer_suppressions/ubsan \
4949
$(top_srcdir)/contrib/linearize/linearize-data.py \
50-
$(top_srcdir)/contrib/linearize/linearize-hashes.py
50+
$(top_srcdir)/contrib/linearize/linearize-hashes.py \
51+
$(top_srcdir)/contrib/signet/miner
5152

5253
DIST_SHARE = \
5354
$(top_srcdir)/share/genbuild.sh \

test/functional/test_runner.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@
145145
'wallet_txn_doublespend.py --mineblock',
146146
'tool_wallet.py --legacy-wallet',
147147
'tool_wallet.py --descriptors',
148+
'tool_signet_miner.py --legacy-wallet',
149+
'tool_signet_miner.py --descriptors',
148150
'wallet_txn_clone.py',
149151
'wallet_txn_clone.py --segwit',
150152
'rpc_getchaintips.py',

test/functional/tool_signet_miner.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) 2022 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 miner tool"""
6+
7+
import os.path
8+
import subprocess
9+
import sys
10+
import time
11+
12+
from test_framework.key import ECKey
13+
from test_framework.script_util import key_to_p2wpkh_script
14+
from test_framework.test_framework import BitcoinTestFramework
15+
from test_framework.util import assert_equal
16+
from test_framework.wallet_util import bytes_to_wif
17+
18+
19+
CHALLENGE_PRIVATE_KEY = (42).to_bytes(32, 'big')
20+
21+
22+
class SignetMinerTest(BitcoinTestFramework):
23+
def set_test_params(self):
24+
self.chain = "signet"
25+
self.setup_clean_chain = True
26+
self.num_nodes = 1
27+
28+
# generate and specify signet challenge (simple p2wpkh script)
29+
privkey = ECKey()
30+
privkey.set(CHALLENGE_PRIVATE_KEY, True)
31+
pubkey = privkey.get_pubkey().get_bytes()
32+
challenge = key_to_p2wpkh_script(pubkey)
33+
self.extra_args = [[f'-signetchallenge={challenge.hex()}']]
34+
35+
def skip_test_if_missing_module(self):
36+
self.skip_if_no_cli()
37+
self.skip_if_no_wallet()
38+
self.skip_if_no_bitcoin_util()
39+
40+
def run_test(self):
41+
node = self.nodes[0]
42+
# import private key needed for signing block
43+
node.importprivkey(bytes_to_wif(CHALLENGE_PRIVATE_KEY))
44+
45+
# generate block with signet miner tool
46+
base_dir = self.config["environment"]["SRCDIR"]
47+
signet_miner_path = os.path.join(base_dir, "contrib", "signet", "miner")
48+
subprocess.run([
49+
sys.executable,
50+
signet_miner_path,
51+
f'--cli={node.cli.binary} -datadir={node.cli.datadir}',
52+
'generate',
53+
f'--address={node.getnewaddress()}',
54+
f'--grind-cmd={self.options.bitcoinutil} grind',
55+
'--nbits=1d00ffff',
56+
f'--set-block-time={int(time.time())}',
57+
], check=True, stderr=subprocess.STDOUT)
58+
assert_equal(node.getblockcount(), 1)
59+
60+
61+
if __name__ == "__main__":
62+
SignetMinerTest().main()

0 commit comments

Comments
 (0)