@@ -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 } ;
@@ -3190,8 +3190,11 @@ mod tests {
3190
3190
use util:: ser:: { Writeable , Writer , ReadableArgs } ;
3191
3191
3192
3192
use bitcoin:: util:: hash:: Sha256dHash ;
3193
+ use bitcoin:: util:: bip143;
3193
3194
use bitcoin:: blockdata:: block:: { Block , BlockHeader } ;
3194
- use bitcoin:: blockdata:: transaction:: { Transaction , TxOut } ;
3195
+ use bitcoin:: blockdata:: transaction:: { Transaction , TxOut , TxIn , SigHashType } ;
3196
+ use bitcoin:: blockdata:: script:: { Builder , Script } ;
3197
+ use bitcoin:: blockdata:: opcodes;
3195
3198
use bitcoin:: blockdata:: constants:: genesis_block;
3196
3199
use bitcoin:: network:: constants:: Network ;
3197
3200
use bitcoin:: network:: serialize:: serialize;
@@ -7052,4 +7055,61 @@ mod tests {
7052
7055
assert_eq ! ( msg. channel_id, channel_id) ;
7053
7056
} else { panic ! ( "Unexpected result" ) ; }
7054
7057
}
7058
+
7059
+ #[ test]
7060
+ fn test_claim_sizeable_push_msat ( ) {
7061
+ // Incidentally test SpendableOutput evenet generation due to detection of to_local output on commitment tx
7062
+ let nodes = create_network ( 2 ) ;
7063
+
7064
+ let chan = create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 100000 , 99000000 ) ;
7065
+ nodes[ 1 ] . node . force_close_channel ( & chan. 2 ) ;
7066
+ let events = nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
7067
+ match events[ 0 ] {
7068
+ MessageSendEvent :: BroadcastChannelUpdate { .. } => { } ,
7069
+ _ => panic ! ( "Unexpected event" ) ,
7070
+ }
7071
+ let node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) ;
7072
+ assert_eq ! ( node_txn. len( ) , 1 ) ;
7073
+ check_spends ! ( node_txn[ 0 ] , chan. 3 . clone( ) ) ;
7074
+ 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
7075
+
7076
+ let header = BlockHeader { version : 0x20000000 , prev_blockhash : Default :: default ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
7077
+ nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ node_txn[ 0 ] . clone( ) ] } , 0 ) ;
7078
+ let events = nodes[ 1 ] . chan_monitor . simple_monitor . get_and_clear_pending_events ( ) ;
7079
+ let spend_tx = match events[ 0 ] {
7080
+ Event :: SpendableOutputs { ref outputs } => {
7081
+ match outputs[ 0 ] {
7082
+ SpendableOutputDescriptor :: DynamicOutput { ref outpoint, ref local_delayedkey, ref witness_script, ref to_self_delay } => {
7083
+ let input = TxIn {
7084
+ previous_output : outpoint. clone ( ) ,
7085
+ script_sig : Script :: new ( ) ,
7086
+ sequence : * to_self_delay as u32 ,
7087
+ witness : Vec :: new ( ) ,
7088
+ } ;
7089
+ let output = TxOut {
7090
+ script_pubkey : Builder :: new ( ) . push_opcode ( opcodes:: All :: OP_RETURN ) . into_script ( ) ,
7091
+ value : 99000 ,
7092
+ } ;
7093
+ let mut spend_tx = Transaction {
7094
+ version : 2 ,
7095
+ lock_time : 0 ,
7096
+ input : vec ! [ input] ,
7097
+ output : vec ! [ output] ,
7098
+ } ;
7099
+ let sighash = Message :: from_slice ( & bip143:: SighashComponents :: new ( & spend_tx) . sighash_all ( & spend_tx. input [ 0 ] , witness_script, 99000 ) [ ..] ) . unwrap ( ) ;
7100
+ let secp_ctx = Secp256k1 :: new ( ) ;
7101
+ let local_delaysig = secp_ctx. sign ( & sighash, local_delayedkey) ;
7102
+ spend_tx. input [ 0 ] . witness . push ( local_delaysig. serialize_der ( & secp_ctx) . to_vec ( ) ) ;
7103
+ spend_tx. input [ 0 ] . witness [ 0 ] . push ( SigHashType :: All as u8 ) ;
7104
+ spend_tx. input [ 0 ] . witness . push ( vec ! ( 0 ) ) ;
7105
+ spend_tx. input [ 0 ] . witness . push ( witness_script. clone ( ) . into_bytes ( ) ) ;
7106
+ spend_tx
7107
+ } ,
7108
+ _ => panic ! ( "Unexpected event" ) ,
7109
+ }
7110
+ } ,
7111
+ _ => panic ! ( "Unexpected event" ) ,
7112
+ } ;
7113
+ check_spends ! ( spend_tx, node_txn[ 0 ] . clone( ) ) ;
7114
+ }
7055
7115
}
0 commit comments