Skip to content

Commit

Permalink
test: signet tool genpsbt and solvepsbt commands
Browse files Browse the repository at this point in the history
Co-authored-by: Anthony Towns <[email protected]>
  • Loading branch information
Sjors and ajtowns committed Sep 13, 2024
1 parent b0b77eb commit 19d78e1
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions test/functional/tool_signet_miner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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)
Expand All @@ -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__":
Expand Down

0 comments on commit 19d78e1

Please sign in to comment.