@@ -2206,7 +2206,8 @@ mod tests {
22062206 use super :: { ChannelPublicKeys , CounterpartyCommitmentSecrets } ;
22072207 use crate :: chain;
22082208 use crate :: ln:: chan_utils:: {
2209- get_htlc_redeemscript, get_to_countersigner_keyed_anchor_redeemscript,
2209+ get_htlc_redeemscript, get_keyed_anchor_redeemscript,
2210+ get_to_countersigner_keyed_anchor_redeemscript, shared_anchor_script_pubkey,
22102211 BuiltCommitmentTransaction , ChannelTransactionParameters , CommitmentTransaction ,
22112212 CounterpartyChannelTransactionParameters , HTLCOutputInCommitment ,
22122213 TrustedCommitmentTransaction ,
@@ -2254,7 +2255,7 @@ mod tests {
22542255 funding_outpoint : Some ( chain:: transaction:: OutPoint { txid : Txid :: all_zeros ( ) , index : 0 } ) ,
22552256 splice_parent_funding_txid : None ,
22562257 channel_type_features : ChannelTypeFeatures :: only_static_remote_key ( ) ,
2257- channel_value_satoshis : 3000 ,
2258+ channel_value_satoshis : 4000 ,
22582259 } ;
22592260
22602261 Self {
@@ -2297,14 +2298,42 @@ mod tests {
22972298 let tx = builder. build ( 1000 , 2000 , Vec :: new ( ) ) ;
22982299 assert_eq ! ( tx. built. transaction. output. len( ) , 4 ) ;
22992300 assert_eq ! ( tx. built. transaction. output[ 3 ] . script_pubkey, get_to_countersigner_keyed_anchor_redeemscript( & builder. counterparty_pubkeys. payment_point) . to_p2wsh( ) ) ;
2301+ assert_eq ! ( tx. built. transaction. output[ 0 ] . script_pubkey, get_keyed_anchor_redeemscript( & builder. channel_parameters. holder_pubkeys. funding_pubkey) . to_p2wsh( ) ) ;
2302+ assert_eq ! ( tx. built. transaction. output[ 0 ] . value. to_sat( ) , 330 ) ;
2303+ assert_eq ! ( tx. built. transaction. output[ 1 ] . script_pubkey, get_keyed_anchor_redeemscript( & builder. counterparty_pubkeys. funding_pubkey) . to_p2wsh( ) ) ;
2304+ assert_eq ! ( tx. built. transaction. output[ 1 ] . value. to_sat( ) , 330 ) ;
23002305
23012306 // Generate broadcaster output and anchor
23022307 let tx = builder. build ( 3000 , 0 , Vec :: new ( ) ) ;
23032308 assert_eq ! ( tx. built. transaction. output. len( ) , 2 ) ;
2309+ assert_eq ! ( tx. built. transaction. output[ 0 ] . script_pubkey, get_keyed_anchor_redeemscript( & builder. channel_parameters. holder_pubkeys. funding_pubkey) . to_p2wsh( ) ) ;
2310+ assert_eq ! ( tx. built. transaction. output[ 0 ] . value. to_sat( ) , 330 ) ;
23042311
23052312 // Generate counterparty output and anchor
23062313 let tx = builder. build ( 0 , 3000 , Vec :: new ( ) ) ;
23072314 assert_eq ! ( tx. built. transaction. output. len( ) , 2 ) ;
2315+ assert_eq ! ( tx. built. transaction. output[ 0 ] . script_pubkey, get_keyed_anchor_redeemscript( & builder. counterparty_pubkeys. funding_pubkey) . to_p2wsh( ) ) ;
2316+ assert_eq ! ( tx. built. transaction. output[ 0 ] . value. to_sat( ) , 330 ) ;
2317+
2318+ // Generate broadcaster and counterparty outputs as well as a single anchor
2319+ builder. channel_parameters . channel_type_features = ChannelTypeFeatures :: anchors_zero_fee_commitments ( ) ;
2320+ let tx = builder. build ( 1000 , 2000 , Vec :: new ( ) ) ;
2321+ assert_eq ! ( tx. built. transaction. output. len( ) , 3 ) ;
2322+ assert_eq ! ( tx. built. transaction. output[ 2 ] . script_pubkey, bitcoin:: address:: Address :: p2wpkh( & CompressedPublicKey ( builder. counterparty_pubkeys. payment_point) , Network :: Testnet ) . script_pubkey( ) ) ;
2323+ assert_eq ! ( tx. built. transaction. output[ 0 ] . script_pubkey, shared_anchor_script_pubkey( ) ) ;
2324+ assert_eq ! ( tx. built. transaction. output[ 0 ] . value. to_sat( ) , 240 ) ; // remember total channel value is 4000sat
2325+
2326+ // Generate broadcaster output and anchor
2327+ let tx = builder. build ( 3000 , 0 , Vec :: new ( ) ) ;
2328+ assert_eq ! ( tx. built. transaction. output. len( ) , 2 ) ;
2329+ assert_eq ! ( tx. built. transaction. output[ 0 ] . script_pubkey, shared_anchor_script_pubkey( ) ) ;
2330+ assert_eq ! ( tx. built. transaction. output[ 0 ] . value. to_sat( ) , 240 ) ; // remember total channel value is 4000sat
2331+
2332+ // Generate counterparty output and anchor
2333+ let tx = builder. build ( 0 , 3000 , Vec :: new ( ) ) ;
2334+ assert_eq ! ( tx. built. transaction. output. len( ) , 2 ) ;
2335+ assert_eq ! ( tx. built. transaction. output[ 0 ] . script_pubkey, shared_anchor_script_pubkey( ) ) ;
2336+ assert_eq ! ( tx. built. transaction. output[ 0 ] . value. to_sat( ) , 240 ) ; // remember total channel value is 4000sat
23082337
23092338 let received_htlc = HTLCOutputInCommitment {
23102339 offered : false ,
@@ -2322,7 +2351,7 @@ mod tests {
23222351 transaction_output_index : None ,
23232352 } ;
23242353
2325- // Generate broadcaster output and received and offered HTLC outputs, w/o anchors
2354+ // Generate broadcaster output and received and offered HTLC outputs, w/o anchors
23262355 builder. channel_parameters . channel_type_features = ChannelTypeFeatures :: only_static_remote_key ( ) ;
23272356 let tx = builder. build ( 3000 , 0 , vec ! [ received_htlc. clone( ) , offered_htlc. clone( ) ] ) ;
23282357 let keys = tx. trust ( ) . keys ( ) ;
@@ -2334,16 +2363,33 @@ mod tests {
23342363 assert_eq ! ( get_htlc_redeemscript( & offered_htlc, & ChannelTypeFeatures :: only_static_remote_key( ) , & keys) . to_p2wsh( ) . to_hex_string( ) ,
23352364 "0020215d61bba56b19e9eadb6107f5a85d7f99c40f65992443f69229c290165bc00d" ) ;
23362365
2337- // Generate broadcaster output and received and offered HTLC outputs, with anchors
2366+ // Generate broadcaster output and received and offered HTLC outputs, with keyed anchors
23382367 builder. channel_parameters . channel_type_features = ChannelTypeFeatures :: anchors_zero_htlc_fee_and_dependencies ( ) ;
23392368 let tx = builder. build ( 3000 , 0 , vec ! [ received_htlc. clone( ) , offered_htlc. clone( ) ] ) ;
23402369 assert_eq ! ( tx. built. transaction. output. len( ) , 5 ) ;
2370+ assert_eq ! ( tx. built. transaction. output[ 0 ] . script_pubkey, get_keyed_anchor_redeemscript( & builder. channel_parameters. holder_pubkeys. funding_pubkey) . to_p2wsh( ) ) ;
2371+ assert_eq ! ( tx. built. transaction. output[ 0 ] . value. to_sat( ) , 330 ) ;
2372+ assert_eq ! ( tx. built. transaction. output[ 1 ] . script_pubkey, get_keyed_anchor_redeemscript( & builder. counterparty_pubkeys. funding_pubkey) . to_p2wsh( ) ) ;
2373+ assert_eq ! ( tx. built. transaction. output[ 1 ] . value. to_sat( ) , 330 ) ;
23412374 assert_eq ! ( tx. built. transaction. output[ 2 ] . script_pubkey, get_htlc_redeemscript( & received_htlc, & ChannelTypeFeatures :: anchors_zero_htlc_fee_and_dependencies( ) , & keys) . to_p2wsh( ) ) ;
23422375 assert_eq ! ( tx. built. transaction. output[ 3 ] . script_pubkey, get_htlc_redeemscript( & offered_htlc, & ChannelTypeFeatures :: anchors_zero_htlc_fee_and_dependencies( ) , & keys) . to_p2wsh( ) ) ;
23432376 assert_eq ! ( get_htlc_redeemscript( & received_htlc, & ChannelTypeFeatures :: anchors_zero_htlc_fee_and_dependencies( ) , & keys) . to_p2wsh( ) . to_hex_string( ) ,
23442377 "0020b70d0649c72b38756885c7a30908d912a7898dd5d79457a7280b8e9a20f3f2bc" ) ;
23452378 assert_eq ! ( get_htlc_redeemscript( & offered_htlc, & ChannelTypeFeatures :: anchors_zero_htlc_fee_and_dependencies( ) , & keys) . to_p2wsh( ) . to_hex_string( ) ,
23462379 "002087a3faeb1950a469c0e2db4a79b093a41b9526e5a6fc6ef5cb949bde3be379c7" ) ;
2380+
2381+ // Generate broadcaster output and received and offered HTLC outputs, with P2A anchors
2382+ builder. channel_parameters . channel_type_features = ChannelTypeFeatures :: anchors_zero_fee_commitments ( ) ;
2383+ let tx = builder. build ( 3000 , 0 , vec ! [ received_htlc. clone( ) , offered_htlc. clone( ) ] ) ;
2384+ assert_eq ! ( tx. built. transaction. output. len( ) , 4 ) ;
2385+ assert_eq ! ( tx. built. transaction. output[ 0 ] . script_pubkey, shared_anchor_script_pubkey( ) ) ;
2386+ assert_eq ! ( tx. built. transaction. output[ 0 ] . value. to_sat( ) , 0 ) ;
2387+ assert_eq ! ( tx. built. transaction. output[ 1 ] . script_pubkey, get_htlc_redeemscript( & received_htlc, & ChannelTypeFeatures :: anchors_zero_fee_commitments( ) , & keys) . to_p2wsh( ) ) ;
2388+ assert_eq ! ( tx. built. transaction. output[ 2 ] . script_pubkey, get_htlc_redeemscript( & offered_htlc, & ChannelTypeFeatures :: anchors_zero_fee_commitments( ) , & keys) . to_p2wsh( ) ) ;
2389+ assert_eq ! ( get_htlc_redeemscript( & received_htlc, & ChannelTypeFeatures :: anchors_zero_fee_commitments( ) , & keys) . to_p2wsh( ) . to_hex_string( ) ,
2390+ "0020e43a7c068553003fe68fcae424fb7b28ec5ce48cd8b6744b3945631389bad2fb" ) ;
2391+ assert_eq ! ( get_htlc_redeemscript( & offered_htlc, & ChannelTypeFeatures :: anchors_zero_fee_commitments( ) , & keys) . to_p2wsh( ) . to_hex_string( ) ,
2392+ "0020215d61bba56b19e9eadb6107f5a85d7f99c40f65992443f69229c290165bc00d" ) ;
23472393 }
23482394
23492395 #[ test]
0 commit comments