Skip to content

Commit f3e6ce7

Browse files
committed
test: add external signer test
Includes a mock to mimick the HWI interace.
1 parent 8cf543f commit f3e6ce7

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed

test/functional/mocks/signer.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) 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+
6+
import os
7+
import sys
8+
import argparse
9+
import json
10+
11+
def perform_pre_checks():
12+
mock_result_path = os.path.join(os.getcwd(), "mock_result")
13+
if(os.path.isfile(mock_result_path)):
14+
with open(mock_result_path, "r", encoding="utf8") as f:
15+
mock_result = f.read()
16+
if mock_result[0]:
17+
sys.stdout.write(mock_result[2:])
18+
sys.exit(int(mock_result[0]))
19+
20+
parser = argparse.ArgumentParser(prog='./signer.py', description='External signer mock')
21+
subparsers = parser.add_subparsers(description='Commands', dest='command')
22+
subparsers.required = True
23+
24+
args = parser.parse_args()
25+
26+
perform_pre_checks()
27+
28+
args.func(args)

test/functional/test_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
'wallet_listtransactions.py --legacy-wallet',
112112
'wallet_listtransactions.py --descriptors',
113113
'feature_taproot.py',
114+
'wallet_signer.py --descriptors',
114115
# vv Tests less than 60s vv
115116
'p2p_sendheaders.py',
116117
'wallet_importmulti.py --legacy-wallet',

test/functional/wallet_signer.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) 2017-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 external signer.
6+
7+
Verify that a bitcoind node can use an external signer command
8+
"""
9+
import os
10+
import platform
11+
12+
from test_framework.test_framework import BitcoinTestFramework
13+
from test_framework.util import (
14+
assert_equal,
15+
assert_raises_rpc_error,
16+
)
17+
18+
19+
class SignerTest(BitcoinTestFramework):
20+
def mock_signer_path(self):
21+
path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mocks', 'signer.py')
22+
if platform.system() == "Windows":
23+
return "py " + path
24+
else:
25+
return path
26+
27+
def set_test_params(self):
28+
self.num_nodes = 3
29+
30+
self.extra_args = [
31+
[],
32+
[f"-signer={self.mock_signer_path()}", '-keypool=10'],
33+
[f"-signer={self.mock_signer_path()}", '-keypool=10'],
34+
["-signer=fake.py"],
35+
]
36+
37+
def skip_test_if_missing_module(self):
38+
self.skip_if_no_wallet()
39+
self.skip_if_no_external_signer()
40+
41+
def set_mock_result(self, node, res):
42+
with open(os.path.join(node.cwd, "mock_result"), "w", encoding="utf8") as f:
43+
f.write(res)
44+
45+
def clear_mock_result(self, node):
46+
os.remove(os.path.join(node.cwd, "mock_result"))
47+
48+
def run_test(self):
49+
self.log.debug(f"-signer={self.mock_signer_path()}")
50+
51+
if __name__ == '__main__':
52+
SignerTest().main()

0 commit comments

Comments
 (0)