@@ -2284,7 +2284,7 @@ mod tests {
2284
2284
use rand:: { thread_rng, Rng } ;
2285
2285
2286
2286
use std:: cell:: RefCell ;
2287
- use std:: collections:: HashMap ;
2287
+ use std:: collections:: { BTreeSet , HashMap } ;
2288
2288
use std:: default:: Default ;
2289
2289
use std:: rc:: Rc ;
2290
2290
use std:: sync:: { Arc , Mutex } ;
@@ -3496,7 +3496,6 @@ mod tests {
3496
3496
#[ test]
3497
3497
fn claim_htlc_outputs_shared_tx ( ) {
3498
3498
// Node revoked old state, htlcs haven't time out yet, claim them in shared justice tx
3499
-
3500
3499
let nodes = create_network ( 2 ) ;
3501
3500
3502
3501
// Create some new channel:
@@ -3510,6 +3509,9 @@ mod tests {
3510
3509
3511
3510
// Get the will-be-revoked local txn from node[0]
3512
3511
let revoked_local_txn = nodes[ 0 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & chan_1. 2 ) . unwrap ( ) . last_local_commitment_txn . clone ( ) ;
3512
+ assert_eq ! ( revoked_local_txn. len( ) , 2 ) ; // commitment tx + 1 HTLC-Timeout tx
3513
+ assert_eq ! ( revoked_local_txn[ 0 ] . input. len( ) , 1 ) ;
3514
+ assert_eq ! ( revoked_local_txn[ 0 ] . input[ 0 ] . previous_output. txid, chan_1. 3 . txid( ) ) ;
3513
3515
3514
3516
//Revoke the old state
3515
3517
claim_payment ( & nodes[ 0 ] , & vec ! ( & nodes[ 1 ] ) [ ..] , payment_preimage_1) ;
@@ -3526,32 +3528,29 @@ mod tests {
3526
3528
let mut revoked_tx_map = HashMap :: new ( ) ;
3527
3529
revoked_tx_map. insert ( revoked_local_txn[ 0 ] . txid ( ) , revoked_local_txn[ 0 ] . clone ( ) ) ;
3528
3530
3529
- assert_eq ! ( node_txn[ 0 ] . input. len( ) , 2 ) ;
3531
+ assert_eq ! ( node_txn[ 0 ] . input. len( ) , 3 ) ; // Claim the revoked output + both revoked HTLC outputs
3530
3532
node_txn[ 0 ] . verify ( & revoked_tx_map) . unwrap ( ) ;
3531
-
3532
- assert_eq ! ( node_txn[ 3 ] . input. len( ) , 2 ) ;
3533
- node_txn[ 3 ] . verify ( & revoked_tx_map) . unwrap ( ) ;
3534
-
3535
- assert_eq ! ( node_txn[ 0 ] . txid( ) , node_txn[ 3 ] . txid( ) ) ; // justice tx is duplicated due to block re-scanning
3536
-
3537
- let witness_script_1 = node_txn[ 0 ] . clone ( ) . input [ 0 ] . witness . pop ( ) . unwrap ( ) ;
3538
- let witness_script_2 = node_txn[ 0 ] . clone ( ) . input [ 1 ] . witness . pop ( ) . unwrap ( ) ;
3539
- if witness_script_1. len ( ) > 133 {
3540
- assert_eq ! ( witness_script_1. len( ) , 138 ) ;
3541
- assert_eq ! ( witness_script_2. len( ) , 133 ) ;
3542
- } else {
3543
- assert_eq ! ( witness_script_1. len( ) , 133 ) ;
3544
- assert_eq ! ( witness_script_2. len( ) , 138 ) ;
3545
- }
3546
-
3533
+ assert_eq ! ( node_txn[ 0 ] , node_txn[ 3 ] ) ; // justice tx is duplicated due to block re-scanning
3534
+
3535
+ let mut witness_lens = BTreeSet :: new ( ) ;
3536
+ witness_lens. insert ( node_txn[ 0 ] . input [ 0 ] . witness . clone ( ) . pop ( ) . unwrap ( ) . len ( ) ) ;
3537
+ witness_lens. insert ( node_txn[ 0 ] . input [ 1 ] . witness . clone ( ) . pop ( ) . unwrap ( ) . len ( ) ) ;
3538
+ witness_lens. insert ( node_txn[ 0 ] . input [ 2 ] . witness . clone ( ) . pop ( ) . unwrap ( ) . len ( ) ) ;
3539
+ assert_eq ! ( witness_lens. len( ) , 3 ) ;
3540
+ assert_eq ! ( * witness_lens. iter( ) . skip( 0 ) . next( ) . unwrap( ) , 77 ) ; // revoked to_local
3541
+ assert_eq ! ( * witness_lens. iter( ) . skip( 1 ) . next( ) . unwrap( ) , 133 ) ; // revoked offered HTLC
3542
+ assert_eq ! ( * witness_lens. iter( ) . skip( 2 ) . next( ) . unwrap( ) , 138 ) ; // revoked received HTLC
3543
+
3544
+ // Next nodes[1] broadcasts its current local tx state:
3547
3545
assert_eq ! ( node_txn[ 1 ] . input. len( ) , 1 ) ;
3548
- let witness_script = node_txn[ 1 ] . clone ( ) . input [ 0 ] . witness . pop ( ) . unwrap ( ) ;
3549
- assert_eq ! ( witness_script. len( ) , 71 ) ; // Spending funding tx unique txoutput, tx broadcasted by ChannelManager
3546
+ assert_eq ! ( node_txn[ 1 ] . input[ 0 ] . previous_output. txid, chan_1. 3 . txid( ) ) ; //Spending funding tx unique txouput, tx broadcasted by ChannelManager
3550
3547
3551
3548
assert_eq ! ( node_txn[ 2 ] . input. len( ) , 1 ) ;
3552
3549
let witness_script = node_txn[ 2 ] . clone ( ) . input [ 0 ] . witness . pop ( ) . unwrap ( ) ;
3553
- assert_eq ! ( witness_script. len( ) , 133 ) ; //Spending a offered htlc output
3554
-
3550
+ assert_eq ! ( witness_script. len( ) , 133 ) ; //Spending an offered htlc output
3551
+ assert_eq ! ( node_txn[ 2 ] . input[ 0 ] . previous_output. txid, node_txn[ 1 ] . txid( ) ) ;
3552
+ assert_ne ! ( node_txn[ 2 ] . input[ 0 ] . previous_output. txid, node_txn[ 0 ] . input[ 0 ] . previous_output. txid) ;
3553
+ assert_ne ! ( node_txn[ 2 ] . input[ 0 ] . previous_output. txid, node_txn[ 0 ] . input[ 1 ] . previous_output. txid) ;
3555
3554
}
3556
3555
get_announce_close_broadcast_events ( & nodes, 0 , 1 ) ;
3557
3556
assert_eq ! ( nodes[ 0 ] . node. list_channels( ) . len( ) , 0 ) ;
0 commit comments