Skip to content

Commit d0e6a25

Browse files
committed
itest: assert failure reason for normal invoice payments
1 parent 66f0af1 commit d0e6a25

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

itest/assets_test.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ func sendAssetKeySendPayment(t *testing.T, src, dst *HarnessNode, amt uint64,
719719
expectedReason := failReason.UnwrapOr(
720720
lnrpc.PaymentFailureReason_FAILURE_REASON_NONE,
721721
)
722-
require.Equal(t, result.FailureReason, expectedReason)
722+
require.Equal(t, expectedReason, result.FailureReason)
723723
}
724724

725725
func sendKeySendPayment(t *testing.T, src, dst *HarnessNode,
@@ -772,7 +772,10 @@ func createAndPayNormalInvoiceWithBtc(t *testing.T, src, dst *HarnessNode,
772772
})
773773
require.NoError(t, err)
774774

775-
payInvoiceWithSatoshi(t, src, invoiceResp, lnrpc.Payment_SUCCEEDED)
775+
payInvoiceWithSatoshi(
776+
t, src, invoiceResp, lnrpc.Payment_SUCCEEDED,
777+
fn.None[lnrpc.PaymentFailureReason](),
778+
)
776779
}
777780

778781
func createAndPayNormalInvoice(t *testing.T, src, rfqPeer, dst *HarnessNode,
@@ -800,7 +803,8 @@ func createAndPayNormalInvoice(t *testing.T, src, rfqPeer, dst *HarnessNode,
800803

801804
func payInvoiceWithSatoshi(t *testing.T, payer *HarnessNode,
802805
invoice *lnrpc.AddInvoiceResponse,
803-
expectedStatus lnrpc.Payment_PaymentStatus) {
806+
expectedStatus lnrpc.Payment_PaymentStatus,
807+
failReason fn.Option[lnrpc.PaymentFailureReason]) {
804808

805809
ctxb := context.Background()
806810
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
@@ -818,6 +822,11 @@ func payInvoiceWithSatoshi(t *testing.T, payer *HarnessNode,
818822
result, err := getPaymentResult(stream)
819823
require.NoError(t, err)
820824
require.Equal(t, expectedStatus, result.Status)
825+
826+
expectedReason := failReason.UnwrapOr(
827+
lnrpc.PaymentFailureReason_FAILURE_REASON_NONE,
828+
)
829+
require.Equal(t, expectedReason, result.FailureReason)
821830
}
822831

823832
func payInvoiceWithSatoshiLastHop(t *testing.T, payer *HarnessNode,

itest/litd_custom_channels_test.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import (
1818
"github.com/lightninglabs/taproot-assets/tapchannel"
1919
"github.com/lightninglabs/taproot-assets/taprpc"
2020
"github.com/lightninglabs/taproot-assets/taprpc/mintrpc"
21+
oraclerpc "github.com/lightninglabs/taproot-assets/taprpc/priceoraclerpc"
22+
"github.com/lightninglabs/taproot-assets/taprpc/rfqrpc"
2123
tchrpc "github.com/lightninglabs/taproot-assets/taprpc/tapchannelrpc"
2224
"github.com/lightninglabs/taproot-assets/taprpc/universerpc"
2325
"github.com/lightninglabs/taproot-assets/tapscript"
@@ -48,6 +50,10 @@ var (
4850
shortTimeout = time.Second * 5
4951

5052
defaultPaymentStatus = fn.None[lnrpc.Payment_PaymentStatus]()
53+
54+
// nolint: lll
55+
errNoBalance = lnrpc.PaymentFailureReason_FAILURE_REASON_INSUFFICIENT_BALANCE
56+
errNoRoute = lnrpc.PaymentFailureReason_FAILURE_REASON_NO_ROUTE
5157
)
5258

5359
var (
@@ -528,6 +534,7 @@ func testCustomChannels(_ context.Context, net *NetworkHarness,
528534
)
529535
payInvoiceWithSatoshi(
530536
t.t, charlie, invoiceResp, lnrpc.Payment_FAILED,
537+
fn.None[lnrpc.PaymentFailureReason](),
531538
)
532539
logBalance(t.t, nodes, assetID, "after asset invoice paid with sats")
533540

@@ -574,7 +581,10 @@ func testCustomChannels(_ context.Context, net *NetworkHarness,
574581
invoiceResp = createAssetInvoice(
575582
t.t, erin, fabia, fabiaInvoiceAssetAmount2, assetID,
576583
)
577-
payInvoiceWithSatoshi(t.t, dave, invoiceResp, lnrpc.Payment_SUCCEEDED)
584+
payInvoiceWithSatoshi(
585+
t.t, dave, invoiceResp, lnrpc.Payment_SUCCEEDED,
586+
fn.None[lnrpc.PaymentFailureReason](),
587+
)
578588
logBalance(t.t, nodes, assetID, "after invoice")
579589

580590
erinAssetBalance -= fabiaInvoiceAssetAmount2
@@ -1006,7 +1016,10 @@ func testCustomChannelsGroupedAsset(_ context.Context, net *NetworkHarness,
10061016
invoiceResp = createAssetInvoice(
10071017
t.t, erin, fabia, fabiaInvoiceAssetAmount2, assetID,
10081018
)
1009-
payInvoiceWithSatoshi(t.t, dave, invoiceResp, lnrpc.Payment_SUCCEEDED)
1019+
payInvoiceWithSatoshi(
1020+
t.t, dave, invoiceResp, lnrpc.Payment_SUCCEEDED,
1021+
fn.None[lnrpc.PaymentFailureReason](),
1022+
)
10101023
logBalance(t.t, nodes, assetID, "after invoice")
10111024

10121025
erinAssetBalance -= fabiaInvoiceAssetAmount2
@@ -2015,7 +2028,10 @@ func testCustomChannelsLiquidityEdgeCases(_ context.Context,
20152028
// channels, where the total asset value is less than the default anchor
20162029
// amount of 354 sats.
20172030
invoiceResp = createAssetInvoice(t.t, dave, charlie, 1, assetID)
2018-
payInvoiceWithSatoshi(t.t, yara, invoiceResp, lnrpc.Payment_FAILED)
2031+
payInvoiceWithSatoshi(
2032+
t.t, yara, invoiceResp, lnrpc.Payment_FAILED,
2033+
fn.Some(lnrpc.PaymentFailureReason_FAILURE_REASON_NO_ROUTE),
2034+
)
20192035

20202036
logBalance(t.t, nodes, assetID, "after small payment (asset "+
20212037
"invoice, <354sats)")
@@ -2686,7 +2702,7 @@ func testCustomChannelsOraclePricing(_ context.Context,
26862702
)
26872703
}
26882704

2689-
// testCustomChannelsFee tests the whether the custom channel funding process
2705+
// testCustomChannelsFee tests whether the custom channel funding process
26902706
// fails if the proposed fee rate is lower than the minimum relay fee.
26912707
func testCustomChannelsFee(_ context.Context,
26922708
net *NetworkHarness, t *harnessTest) {

0 commit comments

Comments
 (0)