Skip to content

Commit

Permalink
tests: Check that we handle missing fields
Browse files Browse the repository at this point in the history
Adds a check that we return "continue" on the htlc_accepted_hook if we
don't understand an onion payload in the lsp client plugin because of
missing fields.

Signed-off-by: Peter Neuroth <[email protected]>
  • Loading branch information
nepet committed Nov 25, 2024
1 parent 4be92a9 commit 09fc51f
Show file tree
Hide file tree
Showing 3 changed files with 227 additions and 166 deletions.
8 changes: 6 additions & 2 deletions libs/gl-plugin/src/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,12 @@ pub async fn on_htlc_accepted(plugin: Plugin, v: Value) -> Result<Value, anyhow:
let onion_amt = match req.onion.forward_msat {
Some(a) => a,
None => {
// An onion without an `amt_to_forward` is unorthodox and can not
// be processed by this plugin. Skip it.
// An onion payload without an `amt_to_forward` is unorthodox and
// can not be processed by this plugin. Skip it.
log::debug!(
"lsp-plugin: got an onion payload={} without an amt forward_msat.",
req.onion.payload
);
return Ok(serde_json::to_value(HtlcAcceptedResponse {
result: "continue".to_string(),
..Default::default()
Expand Down
7 changes: 7 additions & 0 deletions libs/gl-plugin/src/tlv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,13 @@ impl<'de> Deserialize<'de> for SerializedTlvStream {
}
}

impl std::fmt::Display for SerializedTlvStream {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let s = hex::encode(SerializedTlvStream::to_bytes(self.clone()));
write!(f, "{s}")
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
Loading

0 comments on commit 09fc51f

Please sign in to comment.