4
4
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
5
"""Test signet miner tool"""
6
6
7
+ import json
7
8
import os .path
8
9
import shlex
9
10
import subprocess
@@ -83,6 +84,38 @@ def mine_block(self, node):
83
84
], check = True , stderr = subprocess .STDOUT )
84
85
assert_equal (node .getblockcount (), n_blocks + 1 )
85
86
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
+
86
119
def run_test (self ):
87
120
self .log .info ("Signet node with single signature challenge" )
88
121
node = self .nodes [0 ]
@@ -92,6 +125,10 @@ def run_test(self):
92
125
# MUST include signet commitment
93
126
assert get_signet_commitment (get_segwit_commitment (node ))
94
127
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
+
95
132
node = self .nodes [1 ]
96
133
self .log .info ("Signet node with trivial challenge (OP_TRUE)" )
97
134
self .mine_block (node )
@@ -109,6 +146,9 @@ def run_test(self):
109
146
self .mine_block (node )
110
147
assert get_signet_commitment (get_segwit_commitment (node )) is None
111
148
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
112
152
113
153
114
154
if __name__ == "__main__" :
0 commit comments