Skip to content

Commit

Permalink
Add Builder.LookupPayment & CheckForSuccessButFailureReasonIsNotNone_…
Browse files Browse the repository at this point in the history
…LND_18_Bug test.
  • Loading branch information
rsafier committed Jul 2, 2024
1 parent f1dfff6 commit a57fc52
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
2 changes: 1 addition & 1 deletion LNUnit.Tests/AbcLightningFixtureBoltDb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace LNUnit.Tests;

[TestFixture("boltdb", "lightninglabs/lnd", "daily-testing-only", "/root/.lnd", true)]
//[TestFixture("boltdb", "custom_lnd", "latest", "/home/lnd/.lnd", false)]
// [TestFixture("boltdb", "lightninglabs/lnd", "v0.17.5-beta", "/root/.lnd", false)]
public class AbcLightningAbstractTestsBoltDb : LNUnit.Tests.Abstract.AbcLightningAbstractTests
{
public AbcLightningAbstractTestsBoltDb(string dbType = "boltdb",
Expand Down
42 changes: 42 additions & 0 deletions LNUnit.Tests/Abstract/AbcLightningAbstractTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,48 @@ public async Task FailureInvoiceTimeout()
Assert.That(invoiceLookup.State == Invoice.Types.InvoiceState.Canceled);
}

[Test]
[Category("Payment")]
[Category("Invoice")]
[NonParallelizable]
// [Timeout(5000)]
public async Task CheckForSuccessButFailureReasonIsNotNone_LND_18_Bug()
{
var invoice = await Builder.GeneratePaymentRequestFromAlias("alice", new Invoice
{
Memo = "weird",
Expiry = 1000,
ValueMsat = 1003
});
//Apply HTLC hold to prevent payment from settling
await Builder.DelayAllHTLCsOnAlias("bob", 30_000); //6s
await Builder.DelayAllHTLCsOnAlias("carol", 15_000); //6s
Payment? payment = null;
var failed = false;

payment = await Builder.MakeLightningPaymentFromAlias("carol", new SendPaymentRequest
{
PaymentRequest = invoice.PaymentRequest,
FeeLimitSat = 100000000,
TimeoutSeconds = 15
});


Builder.CancelInterceptorOnAlias("bob");
Builder.CancelInterceptorOnAlias("carol");
Assert.That(payment!.Status == Payment.Types.PaymentStatus.Succeeded);
Assert.That(payment!.FailureReason == PaymentFailureReason.FailureReasonNone);
var invoiceLookup = await Builder.LookupInvoice("alice", invoice.RHash);
Assert.That(invoiceLookup != null);
Assert.That(invoiceLookup.RHash == invoice.RHash);
Assert.That(invoiceLookup.State == Invoice.Types.InvoiceState.Settled);
var paymentLookup = await Builder.LookupPayment("carol", invoiceLookup.RHash);
Assert.That(paymentLookup.Status == Payment.Types.PaymentStatus.Succeeded);
//This will pass in v0.18.0 and is changing behavior
Assert.That(paymentLookup.FailureReason != PaymentFailureReason.FailureReasonNone);
}


[Test]
[Category("Payment")]
[Category("Interceptor")]
Expand Down
12 changes: 12 additions & 0 deletions LNUnit/Setup/LNUnitBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,18 @@ await Enumerable.Range(0, count).ParallelForEachAsync(async x =>
return response.ToList();
}

public async Task<Payment> LookupPayment(string alias, ByteString hash)
{
var node = await GetNodeFromAlias(alias);
var streamingCallResponse = node.RouterClient.TrackPaymentV2(new TrackPaymentRequest()
{
NoInflightUpdates = true,
PaymentHash = hash
});
Payment? paymentResponse = null;
await foreach (var res in streamingCallResponse.ResponseStream.ReadAllAsync()) paymentResponse = res;
return paymentResponse!;
}
public async Task<Invoice?> LookupInvoice(string alias, ByteString rHash)
{
var node = await GetNodeFromAlias(alias);
Expand Down

0 comments on commit a57fc52

Please sign in to comment.