From 19d78e1c4133748388b4a74a9d2b674b6b658396 Mon Sep 17 00:00:00 2001 From: Sjors Provoost Date: Fri, 13 Sep 2024 10:02:26 +0200 Subject: [PATCH] test: signet tool genpsbt and solvepsbt commands Co-authored-by: Anthony Towns --- test/functional/tool_signet_miner.py | 38 ++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/test/functional/tool_signet_miner.py b/test/functional/tool_signet_miner.py index 651f0cdb6d670..e763124f9d5b0 100755 --- a/test/functional/tool_signet_miner.py +++ b/test/functional/tool_signet_miner.py @@ -4,6 +4,7 @@ # file COPYING or http://www.opensource.org/licenses/mit-license.php. """Test signet miner tool""" +import json import os.path import subprocess import sys @@ -79,6 +80,36 @@ def mine_block(self, node): ], check=True, stderr=subprocess.STDOUT) assert_equal(node.getblockcount(), n_blocks + 1) + # generate block using the signet miner tool genpsbt and solvepsbt commands + def mine_block_manual(self, node, sign): + n_blocks = node.getblockcount() + base_dir = self.config["environment"]["SRCDIR"] + signet_miner_path = os.path.join(base_dir, "contrib", "signet", "miner") + base_cmd = [ + sys.executable, + signet_miner_path, + f'--cli={node.cli.binary} -datadir={node.cli.datadir}', + ] + + template = node.getblocktemplate(dict(rules=["signet","segwit"])) + genpsbt = subprocess.run(base_cmd + [ + 'genpsbt', + f'--address={node.getnewaddress()}', + '--poolnum=98', + ], check=True, input=json.dumps(template).encode('utf8'), capture_output=True) + psbt = genpsbt.stdout.decode('utf8').strip() + if sign: + self.log.debug("Sign the PSBT") + res = node.walletprocesspsbt(psbt=psbt, sign=True, sighashtype='ALL') + assert res['complete'] + psbt = res['psbt'] + solvepsbt = subprocess.run(base_cmd + [ + 'solvepsbt', + f'--grind-cmd={self.options.bitcoinutil} grind', + ], check=True, input=psbt.encode('utf8'), capture_output=True) + node.submitblock(solvepsbt.stdout.decode('utf8').strip()) + assert_equal(node.getblockcount(), n_blocks + 1) + def run_test(self): self.log.info("Signet node with single signature challenge") node = self.nodes[0] @@ -88,6 +119,10 @@ def run_test(self): # MUST include signet commitment assert get_signet_commitment(get_segwit_commitment(node)) + self.log.info("Mine manually using genpsbt and solvepsbt") + self.mine_block_manual(node, True) + assert get_signet_commitment(get_segwit_commitment(node)) + node = self.nodes[1] self.log.info("Signet node with trivial challenge (OP_TRUE)") self.mine_block(node) @@ -100,6 +135,9 @@ def run_test(self): self.mine_block(node) assert get_signet_commitment(get_segwit_commitment(node)) is None + self.log.info("Manual mining with a trivial challenge doesn't require a PSBT") + self.mine_block_manual(node, False) + assert get_signet_commitment(get_segwit_commitment(node)) is None if __name__ == "__main__":