@@ -303,20 +303,8 @@ mod tests {
303
303
} }
304
304
}
305
305
306
- fn connect_blocks ( node : & mut Node , block_count : u32 ) {
307
- for i in 1 ..=block_count {
308
- let prev_blockhash = node. best_block . block_hash ( ) ;
309
- let height = node. best_block . height ( ) + 1 ;
310
- let header = BlockHeader { version : 0x20000000 , prev_blockhash, merkle_root : Default :: default ( ) , time : height, bits : 42 , nonce : 42 } ;
311
- node. best_block = BestBlock :: new ( header. block_hash ( ) , height) ;
312
- if i == block_count {
313
- node. node . best_block_updated ( & header, height) ;
314
- node. chain_monitor . best_block_updated ( & header, height) ;
315
- }
316
- }
317
- }
318
- fn confirm_transaction ( node : & mut Node , tx : & Transaction ) {
319
- for i in 1 ..=ANTI_REORG_DELAY {
306
+ fn confirm_transaction_depth ( node : & mut Node , tx : & Transaction , depth : u32 ) {
307
+ for i in 1 ..=depth {
320
308
let prev_blockhash = node. best_block . block_hash ( ) ;
321
309
let height = node. best_block . height ( ) + 1 ;
322
310
let header = BlockHeader { version : 0x20000000 , prev_blockhash, merkle_root : Default :: default ( ) , time : height, bits : 42 , nonce : 42 } ;
@@ -327,14 +315,17 @@ mod tests {
327
315
node. node . transactions_confirmed ( & header, & txdata, height) ;
328
316
node. chain_monitor . transactions_confirmed ( & header, & txdata, height) ;
329
317
} ,
330
- ANTI_REORG_DELAY => {
318
+ x if x == depth => {
331
319
node. node . best_block_updated ( & header, height) ;
332
320
node. chain_monitor . best_block_updated ( & header, height) ;
333
321
} ,
334
322
_ => { } ,
335
323
}
336
324
}
337
325
}
326
+ fn confirm_transaction ( node : & mut Node , tx : & Transaction ) {
327
+ confirm_transaction_depth ( node, tx, ANTI_REORG_DELAY ) ;
328
+ }
338
329
339
330
#[ test]
340
331
fn test_background_processor ( ) {
@@ -466,8 +457,7 @@ mod tests {
466
457
// Force close the channel and check that the SpendableOutputs event was handled.
467
458
nodes[ 0 ] . node . force_close_channel ( & nodes[ 0 ] . node . list_channels ( ) [ 0 ] . channel_id ) . unwrap ( ) ;
468
459
let commitment_tx = nodes[ 0 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . pop ( ) . unwrap ( ) ;
469
- confirm_transaction ( & mut nodes[ 0 ] , & commitment_tx) ;
470
- connect_blocks ( & mut nodes[ 0 ] , BREAKDOWN_TIMEOUT as u32 - 1 ) ;
460
+ confirm_transaction_depth ( & mut nodes[ 0 ] , & commitment_tx, BREAKDOWN_TIMEOUT as u32 ) ;
471
461
let event = receiver
472
462
. recv_timeout ( Duration :: from_secs ( EVENT_DEADLINE ) )
473
463
. expect ( "SpendableOutputs not handled within deadline" ) ;
0 commit comments