Skip to content

Commit a759a06

Browse files
committed
Include 0FC channels in chan_utils::test_anchors
1 parent f5e07de commit a759a06

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

lightning/src/ln/chan_utils.rs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2205,8 +2205,8 @@ mod tests {
22052205
use crate::chain;
22062206
use crate::ln::chan_utils::{
22072207
get_htlc_redeemscript, get_to_countersigner_keyed_anchor_redeemscript,
2208-
BuiltCommitmentTransaction, ChannelTransactionParameters, CommitmentTransaction,
2209-
CounterpartyChannelTransactionParameters, HTLCOutputInCommitment,
2208+
shared_anchor_script_pubkey, BuiltCommitmentTransaction, ChannelTransactionParameters,
2209+
CommitmentTransaction, CounterpartyChannelTransactionParameters, HTLCOutputInCommitment,
22102210
TrustedCommitmentTransaction,
22112211
};
22122212
use crate::sign::{ChannelSigner, SignerProvider};
@@ -2252,7 +2252,7 @@ mod tests {
22522252
funding_outpoint: Some(chain::transaction::OutPoint { txid: Txid::all_zeros(), index: 0 }),
22532253
splice_parent_funding_txid: None,
22542254
channel_type_features: ChannelTypeFeatures::only_static_remote_key(),
2255-
channel_value_satoshis: 3000,
2255+
channel_value_satoshis: 4000,
22562256
};
22572257

22582258
Self {
@@ -2304,6 +2304,21 @@ mod tests {
23042304
let tx = builder.build(0, 3000, Vec::new());
23052305
assert_eq!(tx.built.transaction.output.len(), 2);
23062306

2307+
// Generate broadcaster and counterparty outputs as well as a single anchor
2308+
builder.channel_parameters.channel_type_features = ChannelTypeFeatures::anchors_zero_fee_commitments();
2309+
let tx = builder.build(1000, 2000, Vec::new());
2310+
assert_eq!(tx.built.transaction.output.len(), 3);
2311+
assert_eq!(tx.built.transaction.output[2].script_pubkey, bitcoin::address::Address::p2wpkh(&CompressedPublicKey(builder.counterparty_pubkeys.payment_point), Network::Testnet).script_pubkey());
2312+
assert_eq!(tx.built.transaction.output[0].script_pubkey, shared_anchor_script_pubkey());
2313+
2314+
// Generate broadcaster output and anchor
2315+
let tx = builder.build(3000, 0, Vec::new());
2316+
assert_eq!(tx.built.transaction.output.len(), 2);
2317+
2318+
// Generate counterparty output and anchor
2319+
let tx = builder.build(0, 3000, Vec::new());
2320+
assert_eq!(tx.built.transaction.output.len(), 2);
2321+
23072322
let received_htlc = HTLCOutputInCommitment {
23082323
offered: false,
23092324
amount_msat: 400000,
@@ -2332,7 +2347,7 @@ mod tests {
23322347
assert_eq!(get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::only_static_remote_key(), &keys).to_p2wsh().to_hex_string(),
23332348
"0020215d61bba56b19e9eadb6107f5a85d7f99c40f65992443f69229c290165bc00d");
23342349

2335-
// Generate broadcaster output and received and offered HTLC outputs, with anchors
2350+
// Generate broadcaster output and received and offered HTLC outputs, with CSV anchors
23362351
builder.channel_parameters.channel_type_features = ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies();
23372352
let tx = builder.build(3000, 0, vec![received_htlc.clone(), offered_htlc.clone()]);
23382353
assert_eq!(tx.built.transaction.output.len(), 5);
@@ -2342,6 +2357,17 @@ mod tests {
23422357
"0020b70d0649c72b38756885c7a30908d912a7898dd5d79457a7280b8e9a20f3f2bc");
23432358
assert_eq!(get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_p2wsh().to_hex_string(),
23442359
"002087a3faeb1950a469c0e2db4a79b093a41b9526e5a6fc6ef5cb949bde3be379c7");
2360+
2361+
// Generate broadcaster output and received and offered HTLC outputs, with P2A anchors
2362+
builder.channel_parameters.channel_type_features = ChannelTypeFeatures::anchors_zero_fee_commitments();
2363+
let tx = builder.build(3000, 0, vec![received_htlc.clone(), offered_htlc.clone()]);
2364+
assert_eq!(tx.built.transaction.output.len(), 4);
2365+
assert_eq!(tx.built.transaction.output[1].script_pubkey, get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::anchors_zero_fee_commitments(), &keys).to_p2wsh());
2366+
assert_eq!(tx.built.transaction.output[2].script_pubkey, get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::anchors_zero_fee_commitments(), &keys).to_p2wsh());
2367+
assert_eq!(get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::anchors_zero_fee_commitments(), &keys).to_p2wsh().to_hex_string(),
2368+
"0020e43a7c068553003fe68fcae424fb7b28ec5ce48cd8b6744b3945631389bad2fb");
2369+
assert_eq!(get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::anchors_zero_fee_commitments(), &keys).to_p2wsh().to_hex_string(),
2370+
"0020215d61bba56b19e9eadb6107f5a85d7f99c40f65992443f69229c290165bc00d");
23452371
}
23462372

23472373
#[test]

0 commit comments

Comments
 (0)