@@ -131,7 +131,7 @@ async def async_routine():
131131 ctx , mining = await self .make_mining_ctx ()
132132 blockref = await mining .getTip (ctx )
133133 current_block_height = self .nodes [0 ].getchaintips ()[0 ]["height" ]
134- assert blockref .result .height == current_block_height
134+ assert_equal ( blockref .result .height , current_block_height )
135135
136136 self .log .debug ("Mine a block" )
137137 newblockref = (await wait_and_do (
@@ -152,19 +152,14 @@ def run_block_template_test(self):
152152 self .log .info ("Running BlockTemplate interface test" )
153153 block_header_size = 80
154154 timeout = 1000.0 # 1000 milliseconds
155- miniwallet = MiniWallet (self .nodes [0 ])
156155
157156 async def async_routine ():
158157 ctx , mining = await self .make_mining_ctx ()
159158 blockref = await mining .getTip (ctx )
160159
161160 async with AsyncExitStack () as stack :
162161 self .log .debug ("Create a template" )
163- opts = self .capnp_modules ['mining' ].BlockCreateOptions ()
164- opts .useMempool = True
165- opts .blockReservedWeight = 4000
166- opts .coinbaseOutputMaxAdditionalSigops = 0
167- template = await mining_create_block_template (mining , stack , ctx , opts )
162+ template = await mining_create_block_template (mining , stack , ctx , self .default_block_create_options )
168163
169164 self .log .debug ("Test some inspectors of Template" )
170165 header = (await template .getBlockHeader (ctx )).result
@@ -194,7 +189,7 @@ async def async_routine():
194189 self .log .debug ("Wait for another, get one after increase in fees in the mempool" )
195190 template4 = await wait_and_do (
196191 mining_wait_next_template (template2 , stack , ctx , waitoptions ),
197- lambda : miniwallet .send_self_transfer (fee_rate = 10 , from_node = self .nodes [0 ]))
192+ lambda : self . miniwallet .send_self_transfer (fee_rate = 10 , from_node = self .nodes [0 ]))
198193 block3 = await mining_get_block (template4 , ctx )
199194 assert_equal (len (block3 .vtx ), 2 )
200195
@@ -208,7 +203,7 @@ async def async_routine():
208203 self .log .debug ("Wait for another, get one after increase in fees in the mempool" )
209204 template6 = await wait_and_do (
210205 mining_wait_next_template (template5 , stack , ctx , waitoptions ),
211- lambda : miniwallet .send_self_transfer (fee_rate = 10 , from_node = self .nodes [0 ]))
206+ lambda : self . miniwallet .send_self_transfer (fee_rate = 10 , from_node = self .nodes [0 ]))
212207 block4 = await mining_get_block (template6 , ctx )
213208 assert_equal (len (block4 .vtx ), 3 )
214209
@@ -219,7 +214,7 @@ async def async_routine():
219214 self .log .debug ("interruptWait should abort the current wait" )
220215 async def wait_for_block ():
221216 new_waitoptions = self .capnp_modules ['mining' ].BlockWaitOptions ()
222- new_waitoptions .timeout = waitoptions . timeout * 60 # 1 minute wait
217+ new_waitoptions .timeout = timeout * 60 # 1 minute wait
223218 new_waitoptions .feeThreshold = 1
224219 template7 = await template6 .waitNext (ctx , new_waitoptions )
225220 assert_equal (template7 ._has ("result" ), False )
@@ -235,17 +230,12 @@ async def async_routine():
235230 ctx , mining = await self .make_mining_ctx ()
236231
237232 current_block_height = self .nodes [0 ].getchaintips ()[0 ]["height" ]
238- miniwallet = MiniWallet (self .nodes [0 ])
239- opts = self .capnp_modules ['mining' ].BlockCreateOptions ()
240- opts .useMempool = True
241- opts .blockReservedWeight = 4000
242- opts .coinbaseOutputMaxAdditionalSigops = 0
243233 check_opts = self .capnp_modules ['mining' ].BlockCheckOptions ()
244234
245- async with destroying ((await mining .createNewBlock (opts )).result , ctx ) as template :
235+ async with destroying ((await mining .createNewBlock (self . default_block_create_options )).result , ctx ) as template :
246236 block = await mining_get_block (template , ctx )
247- balance = miniwallet .get_balance ()
248- coinbase = await self .build_coinbase_test (template , ctx , miniwallet )
237+ balance = self . miniwallet .get_balance ()
238+ coinbase = await self .build_coinbase_test (template , ctx , self . miniwallet )
249239 # Reduce payout for balance comparison simplicity
250240 coinbase .vout [0 ].nValue = COIN
251241 block .vtx [0 ] = coinbase
@@ -276,7 +266,7 @@ async def async_routine():
276266 submitted = (await template .submitSolution (ctx , block .nVersion , block .nTime , block .nNonce , coinbase .serialize_without_witness ())).result
277267 assert_equal (submitted , False )
278268
279- self .log .debug ("Even a rejected submitBlock () mutates the template's block" )
269+ self .log .debug ("Even a rejected submitSolution () mutates the template's block" )
280270 # Can be used by clients to download and inspect the (rejected)
281271 # reconstructed block.
282272 remote_block_after = await mining_get_block (template , ctx )
@@ -289,13 +279,13 @@ async def async_routine():
289279 self .log .debug ("Block should propagate" )
290280 # Check that the IPC node actually updates its own chain
291281 assert_equal (self .nodes [0 ].getchaintips ()[0 ]["height" ], current_block_height + 1 )
292- # Stalls if a regression causes submitBlock () to accept an invalid block:
282+ # Stalls if a regression causes submitSolution () to accept an invalid block:
293283 self .sync_all ()
294284 # Check that the other node accepts the block
295285 assert_equal (self .nodes [0 ].getchaintips ()[0 ], self .nodes [1 ].getchaintips ()[0 ])
296286
297- miniwallet .rescan_utxos ()
298- assert_equal (miniwallet .get_balance (), balance + 1 )
287+ self . miniwallet .rescan_utxos ()
288+ assert_equal (self . miniwallet .get_balance (), balance + 1 )
299289 self .log .debug ("Check block should fail now, since it is a duplicate" )
300290 check = await mining .checkBlock (block .serialize (), check_opts )
301291 assert_equal (check .result , False )
@@ -304,6 +294,13 @@ async def async_routine():
304294 asyncio .run (capnp .run (async_routine ()))
305295
306296 def run_test (self ):
297+ self .miniwallet = MiniWallet (self .nodes [0 ])
298+ self .default_block_create_options = self .capnp_modules ['mining' ].BlockCreateOptions (
299+ useMempool = True ,
300+ blockReservedWeight = 4000 ,
301+ coinbaseOutputMaxAdditionalSigops = 0
302+ )
303+
307304 self .run_mining_interface_test ()
308305 self .run_block_template_test ()
309306 self .run_coinbase_and_submission_test ()
0 commit comments