Skip to content

Commit

Permalink
Assert that lnd node indeed receive the amount
Browse files Browse the repository at this point in the history
  • Loading branch information
contrun committed Feb 13, 2025
1 parent df40935 commit 3d36aa8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 13 deletions.
24 changes: 24 additions & 0 deletions src/cch/tests/lnd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,30 @@ impl LndNode {
.expect("add hold invoice")
.into_inner()
}

pub async fn get_balance_sats(&mut self) -> u64 {
let response = self
.lnd
.client
.lightning()
.channel_balance(lnd::tonic_lnd::lnrpc::ChannelBalanceRequest::default())
.await
.expect("get wallet balance")
.into_inner();
response.local_balance.expect("local balance exists").sat
}

pub async fn get_balance_msats(&mut self) -> u64 {
let response = self
.lnd
.client
.lightning()
.channel_balance(lnd::tonic_lnd::lnrpc::ChannelBalanceRequest::default())
.await
.expect("get wallet balance")
.into_inner();
response.local_balance.expect("local balance exists").msat
}
}

#[cfg_attr(not(feature = "lnd-tests"), ignore)]
Expand Down
25 changes: 12 additions & 13 deletions src/cch/tests/payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@ async fn test_cross_chain_payment() {
.await;
let lightning_channel_2 = lnd_node.open_channel_with(hub.get_lnd_node_mut()).await;

let lnd_amount = 100000;
let add_invoice_result = lnd_node.add_invoice(lnd_amount as u64).await;
let lnd_amount_sats = 100;
let lnd_amount_msats = lnd_amount_sats * 1000;
let add_invoice_result = lnd_node.add_invoice(lnd_amount_msats).await;
let lnd_old_amount = lnd_node.get_balance_sats().await;

let hash = Hash256::try_from(add_invoice_result.r_hash.as_slice()).expect("valid hash");

Expand All @@ -112,17 +114,13 @@ async fn test_cross_chain_payment() {

hub.insert_invoice(fiber_invoice.clone(), None);

// assert_eq!(
// fiber_invoice.payee_pub_key().copied(),
// Some(hub.pubkey.into())
// );
let hub_amount = fiber_invoice.amount.expect("has amount");
// assert!(
// hub_amount >= lnd_amount,
// "hub should receive more money than lnd, but we have hub_amount: {}, lnd_amount: {}",
// hub_amount,
// lnd_amount
// );
assert!(
hub_amount >= lnd_amount_sats.try_into().expect("valid amount"),
"hub should receive more money than lnd, but we have hub_amount: {}, lnd_amount: {}",
hub_amount,
lnd_amount_sats
);

let res = fiber_node
.send_payment(SendPaymentCommand {
Expand Down Expand Up @@ -160,5 +158,6 @@ async fn test_cross_chain_payment() {
let hub_new_amount = hub.get_local_balance_from_channel(fiber_channel);
assert_eq!(hub_new_amount, hub_old_amount + hub_amount);

// TODO: assert that lnd_node received the payment
let lnd_new_amount = lnd_node.get_balance_sats().await;
assert_eq!(lnd_new_amount, lnd_old_amount + lnd_amount_sats);
}

0 comments on commit 3d36aa8

Please sign in to comment.