Skip to content

Commit fb79e3f

Browse files
committed
Include 0FC channels in chan_utils::test_anchors
1 parent df0cae9 commit fb79e3f

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
@@ -2203,8 +2203,8 @@ mod tests {
22032203
use crate::chain;
22042204
use crate::ln::chan_utils::{
22052205
get_htlc_redeemscript, get_to_countersigner_keyed_anchor_redeemscript,
2206-
BuiltCommitmentTransaction, ChannelTransactionParameters, CommitmentTransaction,
2207-
CounterpartyChannelTransactionParameters, HTLCOutputInCommitment,
2206+
shared_anchor_script_pubkey, BuiltCommitmentTransaction, ChannelTransactionParameters,
2207+
CommitmentTransaction, CounterpartyChannelTransactionParameters, HTLCOutputInCommitment,
22082208
TrustedCommitmentTransaction,
22092209
};
22102210
use crate::sign::{ChannelSigner, SignerProvider};
@@ -2250,7 +2250,7 @@ mod tests {
22502250
funding_outpoint: Some(chain::transaction::OutPoint { txid: Txid::all_zeros(), index: 0 }),
22512251
splice_parent_funding_txid: None,
22522252
channel_type_features: ChannelTypeFeatures::only_static_remote_key(),
2253-
channel_value_satoshis: 3000,
2253+
channel_value_satoshis: 4000,
22542254
};
22552255

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

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

2333-
// Generate broadcaster output and received and offered HTLC outputs, with anchors
2348+
// Generate broadcaster output and received and offered HTLC outputs, with CSV anchors
23342349
builder.channel_parameters.channel_type_features = ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies();
23352350
let tx = builder.build(3000, 0, vec![received_htlc.clone(), offered_htlc.clone()]);
23362351
assert_eq!(tx.built.transaction.output.len(), 5);
@@ -2340,6 +2355,17 @@ mod tests {
23402355
"0020b70d0649c72b38756885c7a30908d912a7898dd5d79457a7280b8e9a20f3f2bc");
23412356
assert_eq!(get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(), &keys).to_p2wsh().to_hex_string(),
23422357
"002087a3faeb1950a469c0e2db4a79b093a41b9526e5a6fc6ef5cb949bde3be379c7");
2358+
2359+
// Generate broadcaster output and received and offered HTLC outputs, with P2A anchors
2360+
builder.channel_parameters.channel_type_features = ChannelTypeFeatures::anchors_zero_fee_commitments();
2361+
let tx = builder.build(3000, 0, vec![received_htlc.clone(), offered_htlc.clone()]);
2362+
assert_eq!(tx.built.transaction.output.len(), 4);
2363+
assert_eq!(tx.built.transaction.output[1].script_pubkey, get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::anchors_zero_fee_commitments(), &keys).to_p2wsh());
2364+
assert_eq!(tx.built.transaction.output[2].script_pubkey, get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::anchors_zero_fee_commitments(), &keys).to_p2wsh());
2365+
assert_eq!(get_htlc_redeemscript(&received_htlc, &ChannelTypeFeatures::anchors_zero_fee_commitments(), &keys).to_p2wsh().to_hex_string(),
2366+
"0020e43a7c068553003fe68fcae424fb7b28ec5ce48cd8b6744b3945631389bad2fb");
2367+
assert_eq!(get_htlc_redeemscript(&offered_htlc, &ChannelTypeFeatures::anchors_zero_fee_commitments(), &keys).to_p2wsh().to_hex_string(),
2368+
"0020215d61bba56b19e9eadb6107f5a85d7f99c40f65992443f69229c290165bc00d");
23432369
}
23442370

23452371
#[test]

0 commit comments

Comments
 (0)