Skip to content

Commit 6ee32aa

Browse files
Sjorsajtowns
andcommitted
test: signet tool genpsbt and solvepsbt commands
Co-authored-by: Anthony Towns <aj@erisian.com.au>
1 parent 0a99d99 commit 6ee32aa

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

test/functional/tool_signet_miner.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Test signet miner tool"""
66

7+
import json
78
import os.path
89
import shlex
910
import subprocess
@@ -83,6 +84,38 @@ def mine_block(self, node):
8384
], check=True, stderr=subprocess.STDOUT)
8485
assert_equal(node.getblockcount(), n_blocks + 1)
8586

87+
# generate block using the signet miner tool genpsbt and solvepsbt commands
88+
def mine_block_manual(self, node, *, sign):
89+
n_blocks = node.getblockcount()
90+
base_dir = self.config["environment"]["SRCDIR"]
91+
signet_miner_path = os.path.join(base_dir, "contrib", "signet", "miner")
92+
rpc_argv = node.binaries.rpc_argv() + [f"-datadir={node.cli.datadir}"]
93+
util_argv = node.binaries.util_argv() + ["grind"]
94+
base_cmd = [
95+
sys.executable,
96+
signet_miner_path,
97+
f'--cli={shlex.join(rpc_argv)}',
98+
]
99+
100+
template = node.getblocktemplate(dict(rules=["signet","segwit"]))
101+
genpsbt = subprocess.run(base_cmd + [
102+
'genpsbt',
103+
f'--address={node.getnewaddress()}',
104+
'--poolnum=98',
105+
], check=True, input=json.dumps(template).encode('utf8'), capture_output=True)
106+
psbt = genpsbt.stdout.decode('utf8').strip()
107+
if sign:
108+
self.log.debug("Sign the PSBT")
109+
res = node.walletprocesspsbt(psbt=psbt, sign=True, sighashtype='ALL')
110+
assert res['complete']
111+
psbt = res['psbt']
112+
solvepsbt = subprocess.run(base_cmd + [
113+
'solvepsbt',
114+
f'--grind-cmd={shlex.join(util_argv)}',
115+
], check=True, input=psbt.encode('utf8'), capture_output=True)
116+
node.submitblock(solvepsbt.stdout.decode('utf8').strip())
117+
assert_equal(node.getblockcount(), n_blocks + 1)
118+
86119
def run_test(self):
87120
self.log.info("Signet node with single signature challenge")
88121
node = self.nodes[0]
@@ -92,6 +125,10 @@ def run_test(self):
92125
# MUST include signet commitment
93126
assert get_signet_commitment(get_segwit_commitment(node))
94127

128+
self.log.info("Mine manually using genpsbt and solvepsbt")
129+
self.mine_block_manual(node, sign=True)
130+
assert get_signet_commitment(get_segwit_commitment(node))
131+
95132
node = self.nodes[1]
96133
self.log.info("Signet node with trivial challenge (OP_TRUE)")
97134
self.mine_block(node)
@@ -109,6 +146,9 @@ def run_test(self):
109146
self.mine_block(node)
110147
assert get_signet_commitment(get_segwit_commitment(node)) is None
111148

149+
self.log.info("Manual mining with a trivial challenge doesn't require a PSBT")
150+
self.mine_block_manual(node, sign=False)
151+
assert get_signet_commitment(get_segwit_commitment(node)) is None
112152

113153

114154
if __name__ == "__main__":

0 commit comments

Comments
 (0)