@@ -3176,7 +3176,7 @@ mod tests {
3176
3176
use chain:: chaininterface;
3177
3177
use chain:: transaction:: OutPoint ;
3178
3178
use chain:: chaininterface:: { ChainListener , ChainWatchInterface } ;
3179
- use chain:: keysinterface:: KeysInterface ;
3179
+ use chain:: keysinterface:: { KeysInterface , SpendableOutputDescriptor } ;
3180
3180
use chain:: keysinterface;
3181
3181
use ln:: channelmanager:: { ChannelManager , ChannelManagerReadArgs , OnionKeys , PaymentFailReason , RAACommitmentOrder } ;
3182
3182
use ln:: channelmonitor:: { ChannelMonitor , ChannelMonitorUpdateErr , CLTV_CLAIM_BUFFER , HTLC_FAIL_TIMEOUT_BLOCKS , ManyChannelMonitor } ;
@@ -3191,8 +3191,11 @@ mod tests {
3191
3191
use util:: config:: UserConfig ;
3192
3192
3193
3193
use bitcoin:: util:: hash:: Sha256dHash ;
3194
+ use bitcoin:: util:: bip143;
3194
3195
use bitcoin:: blockdata:: block:: { Block , BlockHeader } ;
3195
- use bitcoin:: blockdata:: transaction:: { Transaction , TxOut } ;
3196
+ use bitcoin:: blockdata:: transaction:: { Transaction , TxOut , TxIn , SigHashType } ;
3197
+ use bitcoin:: blockdata:: script:: { Builder , Script } ;
3198
+ use bitcoin:: blockdata:: opcodes;
3196
3199
use bitcoin:: blockdata:: constants:: genesis_block;
3197
3200
use bitcoin:: network:: constants:: Network ;
3198
3201
use bitcoin:: network:: serialize:: serialize;
@@ -7060,4 +7063,61 @@ mod tests {
7060
7063
assert_eq ! ( msg. channel_id, channel_id) ;
7061
7064
} else { panic ! ( "Unexpected result" ) ; }
7062
7065
}
7066
+
7067
+ #[ test]
7068
+ fn test_claim_sizeable_push_msat ( ) {
7069
+ // Incidentally test SpendableOutput evenet generation due to detection of to_local output on commitment tx
7070
+ let nodes = create_network ( 2 ) ;
7071
+
7072
+ let chan = create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 100000 , 99000000 ) ;
7073
+ nodes[ 1 ] . node . force_close_channel ( & chan. 2 ) ;
7074
+ let events = nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
7075
+ match events[ 0 ] {
7076
+ MessageSendEvent :: BroadcastChannelUpdate { .. } => { } ,
7077
+ _ => panic ! ( "Unexpected event" ) ,
7078
+ }
7079
+ let node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) ;
7080
+ assert_eq ! ( node_txn. len( ) , 1 ) ;
7081
+ check_spends ! ( node_txn[ 0 ] , chan. 3 . clone( ) ) ;
7082
+ assert_eq ! ( node_txn[ 0 ] . output. len( ) , 2 ) ; // We can't force trimming of to_remote output as channel_reserve_satoshis block us to do so at channel opening
7083
+
7084
+ let header = BlockHeader { version : 0x20000000 , prev_blockhash : Default :: default ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
7085
+ nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ node_txn[ 0 ] . clone( ) ] } , 0 ) ;
7086
+ let events = nodes[ 1 ] . chan_monitor . simple_monitor . get_and_clear_pending_events ( ) ;
7087
+ let spend_tx = match events[ 0 ] {
7088
+ Event :: SpendableOutputs { ref outputs } => {
7089
+ match outputs[ 0 ] {
7090
+ SpendableOutputDescriptor :: DynamicOutput { ref outpoint, ref local_delayedkey, ref witness_script, ref to_self_delay } => {
7091
+ let input = TxIn {
7092
+ previous_output : outpoint. clone ( ) ,
7093
+ script_sig : Script :: new ( ) ,
7094
+ sequence : * to_self_delay as u32 ,
7095
+ witness : Vec :: new ( ) ,
7096
+ } ;
7097
+ let output = TxOut {
7098
+ script_pubkey : Builder :: new ( ) . push_opcode ( opcodes:: All :: OP_RETURN ) . into_script ( ) ,
7099
+ value : 99000 ,
7100
+ } ;
7101
+ let mut spend_tx = Transaction {
7102
+ version : 2 ,
7103
+ lock_time : 0 ,
7104
+ input : vec ! [ input] ,
7105
+ output : vec ! [ output] ,
7106
+ } ;
7107
+ let sighash = Message :: from_slice ( & bip143:: SighashComponents :: new ( & spend_tx) . sighash_all ( & spend_tx. input [ 0 ] , witness_script, 99000 ) [ ..] ) . unwrap ( ) ;
7108
+ let secp_ctx = Secp256k1 :: new ( ) ;
7109
+ let local_delaysig = secp_ctx. sign ( & sighash, local_delayedkey) ;
7110
+ spend_tx. input [ 0 ] . witness . push ( local_delaysig. serialize_der ( & secp_ctx) . to_vec ( ) ) ;
7111
+ spend_tx. input [ 0 ] . witness [ 0 ] . push ( SigHashType :: All as u8 ) ;
7112
+ spend_tx. input [ 0 ] . witness . push ( vec ! ( 0 ) ) ;
7113
+ spend_tx. input [ 0 ] . witness . push ( witness_script. clone ( ) . into_bytes ( ) ) ;
7114
+ spend_tx
7115
+ } ,
7116
+ _ => panic ! ( "Unexpected event" ) ,
7117
+ }
7118
+ } ,
7119
+ _ => panic ! ( "Unexpected event" ) ,
7120
+ } ;
7121
+ check_spends ! ( spend_tx, node_txn[ 0 ] . clone( ) ) ;
7122
+ }
7063
7123
}
0 commit comments