Skip to content

Commit afe7b5b

Browse files
test(lsps4): add unit tests for splice action helpers and cooldown
1 parent f6c56da commit afe7b5b

1 file changed

Lines changed: 85 additions & 0 deletions

File tree

lightning-liquidity/src/lsps4/service.rs

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,4 +1033,89 @@ where
10331033
},
10341034
}
10351035
}
1036+
}
1037+
1038+
#[cfg(test)]
1039+
mod tests {
1040+
use super::*;
1041+
1042+
#[test]
1043+
fn test_htlc_processing_actions_is_empty() {
1044+
let empty = HtlcProcessingActions {
1045+
forwards: vec![],
1046+
new_channel_needed_msat: None,
1047+
splice_needed: None,
1048+
channel_count: 0,
1049+
};
1050+
assert!(empty.is_empty());
1051+
1052+
let with_channel = HtlcProcessingActions {
1053+
forwards: vec![],
1054+
new_channel_needed_msat: Some(100_000),
1055+
splice_needed: None,
1056+
channel_count: 0,
1057+
};
1058+
assert!(!with_channel.is_empty());
1059+
1060+
let with_splice = HtlcProcessingActions {
1061+
forwards: vec![],
1062+
new_channel_needed_msat: None,
1063+
splice_needed: Some(SpliceAction {
1064+
channel_id: ChannelId::from_bytes([0; 32]),
1065+
user_channel_id: 0,
1066+
amt_to_forward_msat: 50_000,
1067+
}),
1068+
channel_count: 1,
1069+
};
1070+
assert!(!with_splice.is_empty());
1071+
}
1072+
1073+
#[test]
1074+
fn test_needs_liquidity_action() {
1075+
let no_action = HtlcProcessingActions {
1076+
forwards: vec![],
1077+
new_channel_needed_msat: None,
1078+
splice_needed: None,
1079+
channel_count: 0,
1080+
};
1081+
assert!(!no_action.needs_liquidity_action());
1082+
1083+
let needs_channel = HtlcProcessingActions {
1084+
forwards: vec![],
1085+
new_channel_needed_msat: Some(100_000),
1086+
splice_needed: None,
1087+
channel_count: 0,
1088+
};
1089+
assert!(needs_channel.needs_liquidity_action());
1090+
1091+
let needs_splice = HtlcProcessingActions {
1092+
forwards: vec![],
1093+
new_channel_needed_msat: None,
1094+
splice_needed: Some(SpliceAction {
1095+
channel_id: ChannelId::from_bytes([0; 32]),
1096+
user_channel_id: 0,
1097+
amt_to_forward_msat: 50_000,
1098+
}),
1099+
channel_count: 1,
1100+
};
1101+
assert!(needs_splice.needs_liquidity_action());
1102+
}
1103+
1104+
#[test]
1105+
fn test_cooldown_auto_expires() {
1106+
// Verify the cooldown constant is less than HTLC expiry
1107+
assert!(LIQUIDITY_COOLDOWN_SECS < HTLC_EXPIRY_THRESHOLD_SECS);
1108+
}
1109+
1110+
#[test]
1111+
fn test_splice_action_fields() {
1112+
let action = SpliceAction {
1113+
channel_id: ChannelId::from_bytes([1; 32]),
1114+
user_channel_id: 42,
1115+
amt_to_forward_msat: 1_000_000,
1116+
};
1117+
assert_eq!(action.channel_id, ChannelId::from_bytes([1; 32]));
1118+
assert_eq!(action.user_channel_id, 42);
1119+
assert_eq!(action.amt_to_forward_msat, 1_000_000);
1120+
}
10361121
}

0 commit comments

Comments
 (0)