Skip to content

Commit

Permalink
Merge pull request fedimint#2907 from justinmoon/invalid-invoice
Browse files Browse the repository at this point in the history
Reactivate test_gateway_client_pay_invalid_invoice and improve documentation
  • Loading branch information
dpc committed Aug 4, 2023
2 parents 7852050 + b4b95a3 commit 10a9950
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
6 changes: 5 additions & 1 deletion fedimint-testing/src/ln/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ pub trait LightningTest: ILnRpcClient {
) -> ln_gateway::Result<Invoice>;

/// Creates an invoice that is not payable
fn invalid_invoice(
///
/// * Mocks use hard-coded invoice description to fail the payment
/// * Real fixtures won't be able to route to randomly generated node pubkey
fn unpayable_invoice(
&self,
amount: Amount,
expiry_time: Option<u64>,
Expand All @@ -38,6 +41,7 @@ pub trait LightningTest: ILnRpcClient {
// `FakeLightningTest` will fail to pay any invoice with
// `INVALID_INVOICE_DESCRIPTION` in the description of the invoice.
Ok(InvoiceBuilder::new(Currency::Regtest)
.payee_pub_key(kp.public_key())
.description(INVALID_INVOICE_DESCRIPTION.to_string())
.payment_hash(sha256::Hash::hash(&Preimage([0; 32]).0))
.current_timestamp()
Expand Down
14 changes: 4 additions & 10 deletions gateway/ln-gateway/src/ng/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ use ln_gateway::ng::{
GatewayClientExt, GatewayClientModule, GatewayClientStateMachines, GatewayExtPayStates,
GatewayExtReceiveStates, GatewayMeta, Htlc, GW_ANNOUNCEMENT_TTL,
};
use tracing::info;
use url::Url;

fn fixtures() -> Fixtures {
Expand Down Expand Up @@ -189,12 +188,7 @@ async fn test_gateway_cannot_claim_invalid_preimage() -> anyhow::Result<()> {
}

#[tokio::test(flavor = "multi_thread")]
async fn test_gateway_client_pay_invalid_invoice() -> anyhow::Result<()> {
if Fixtures::is_real_test() {
info!("Skipping test meant to run only with mocks");
return Ok(());
}

async fn test_gateway_client_pay_unpayable_invoice() -> anyhow::Result<()> {
gateway_test(
|gateway, other_lightning_client, fed, user_client| async move {
let gateway = gateway.remove_client(&fed).await;
Expand All @@ -203,9 +197,9 @@ async fn test_gateway_client_pay_invalid_invoice() -> anyhow::Result<()> {
user_client.receive_money(outpoint).await?;
assert_eq!(user_client.get_balance().await, sats(1000));

// Create test invalid invoice
// Create invoice that cannout be paid
let invoice = other_lightning_client
.invalid_invoice(sats(250), None)
.unpayable_invoice(sats(250), None)
.unwrap();

// User client pays test invoice
Expand Down Expand Up @@ -360,7 +354,7 @@ async fn test_gateway_client_intercept_htlc_invalid_offer() -> anyhow::Result<()
assert_eq!(gateway.get_balance().await, sats(1000));

// Create test invoice
let invoice = other_lightning_client.invalid_invoice(sats(250), None)?;
let invoice = other_lightning_client.unpayable_invoice(sats(250), None)?;

// Create offer with a preimage that doesn't correspond to the payment hash of
// the invoice
Expand Down

0 comments on commit 10a9950

Please sign in to comment.