Skip to content

Commit

Permalink
itest: assert failure reason for normal invoice payments
Browse files Browse the repository at this point in the history
  • Loading branch information
guggero committed Dec 4, 2024
1 parent 66f0af1 commit d0e6a25
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
15 changes: 12 additions & 3 deletions itest/assets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ func sendAssetKeySendPayment(t *testing.T, src, dst *HarnessNode, amt uint64,
expectedReason := failReason.UnwrapOr(
lnrpc.PaymentFailureReason_FAILURE_REASON_NONE,
)
require.Equal(t, result.FailureReason, expectedReason)
require.Equal(t, expectedReason, result.FailureReason)
}

func sendKeySendPayment(t *testing.T, src, dst *HarnessNode,
Expand Down Expand Up @@ -772,7 +772,10 @@ func createAndPayNormalInvoiceWithBtc(t *testing.T, src, dst *HarnessNode,
})
require.NoError(t, err)

payInvoiceWithSatoshi(t, src, invoiceResp, lnrpc.Payment_SUCCEEDED)
payInvoiceWithSatoshi(
t, src, invoiceResp, lnrpc.Payment_SUCCEEDED,
fn.None[lnrpc.PaymentFailureReason](),
)
}

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

func payInvoiceWithSatoshi(t *testing.T, payer *HarnessNode,
invoice *lnrpc.AddInvoiceResponse,
expectedStatus lnrpc.Payment_PaymentStatus) {
expectedStatus lnrpc.Payment_PaymentStatus,
failReason fn.Option[lnrpc.PaymentFailureReason]) {

ctxb := context.Background()
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
Expand All @@ -818,6 +822,11 @@ func payInvoiceWithSatoshi(t *testing.T, payer *HarnessNode,
result, err := getPaymentResult(stream)
require.NoError(t, err)
require.Equal(t, expectedStatus, result.Status)

expectedReason := failReason.UnwrapOr(
lnrpc.PaymentFailureReason_FAILURE_REASON_NONE,
)
require.Equal(t, expectedReason, result.FailureReason)
}

func payInvoiceWithSatoshiLastHop(t *testing.T, payer *HarnessNode,
Expand Down
24 changes: 20 additions & 4 deletions itest/litd_custom_channels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"github.com/lightninglabs/taproot-assets/tapchannel"
"github.com/lightninglabs/taproot-assets/taprpc"
"github.com/lightninglabs/taproot-assets/taprpc/mintrpc"
oraclerpc "github.com/lightninglabs/taproot-assets/taprpc/priceoraclerpc"
"github.com/lightninglabs/taproot-assets/taprpc/rfqrpc"
tchrpc "github.com/lightninglabs/taproot-assets/taprpc/tapchannelrpc"
"github.com/lightninglabs/taproot-assets/taprpc/universerpc"
"github.com/lightninglabs/taproot-assets/tapscript"
Expand Down Expand Up @@ -48,6 +50,10 @@ var (
shortTimeout = time.Second * 5

defaultPaymentStatus = fn.None[lnrpc.Payment_PaymentStatus]()

// nolint: lll
errNoBalance = lnrpc.PaymentFailureReason_FAILURE_REASON_INSUFFICIENT_BALANCE
errNoRoute = lnrpc.PaymentFailureReason_FAILURE_REASON_NO_ROUTE
)

var (
Expand Down Expand Up @@ -528,6 +534,7 @@ func testCustomChannels(_ context.Context, net *NetworkHarness,
)
payInvoiceWithSatoshi(
t.t, charlie, invoiceResp, lnrpc.Payment_FAILED,
fn.None[lnrpc.PaymentFailureReason](),
)
logBalance(t.t, nodes, assetID, "after asset invoice paid with sats")

Expand Down Expand Up @@ -574,7 +581,10 @@ func testCustomChannels(_ context.Context, net *NetworkHarness,
invoiceResp = createAssetInvoice(
t.t, erin, fabia, fabiaInvoiceAssetAmount2, assetID,
)
payInvoiceWithSatoshi(t.t, dave, invoiceResp, lnrpc.Payment_SUCCEEDED)
payInvoiceWithSatoshi(
t.t, dave, invoiceResp, lnrpc.Payment_SUCCEEDED,
fn.None[lnrpc.PaymentFailureReason](),
)
logBalance(t.t, nodes, assetID, "after invoice")

erinAssetBalance -= fabiaInvoiceAssetAmount2
Expand Down Expand Up @@ -1006,7 +1016,10 @@ func testCustomChannelsGroupedAsset(_ context.Context, net *NetworkHarness,
invoiceResp = createAssetInvoice(
t.t, erin, fabia, fabiaInvoiceAssetAmount2, assetID,
)
payInvoiceWithSatoshi(t.t, dave, invoiceResp, lnrpc.Payment_SUCCEEDED)
payInvoiceWithSatoshi(
t.t, dave, invoiceResp, lnrpc.Payment_SUCCEEDED,
fn.None[lnrpc.PaymentFailureReason](),
)
logBalance(t.t, nodes, assetID, "after invoice")

erinAssetBalance -= fabiaInvoiceAssetAmount2
Expand Down Expand Up @@ -2015,7 +2028,10 @@ func testCustomChannelsLiquidityEdgeCases(_ context.Context,
// channels, where the total asset value is less than the default anchor
// amount of 354 sats.
invoiceResp = createAssetInvoice(t.t, dave, charlie, 1, assetID)
payInvoiceWithSatoshi(t.t, yara, invoiceResp, lnrpc.Payment_FAILED)
payInvoiceWithSatoshi(
t.t, yara, invoiceResp, lnrpc.Payment_FAILED,
fn.Some(lnrpc.PaymentFailureReason_FAILURE_REASON_NO_ROUTE),
)

logBalance(t.t, nodes, assetID, "after small payment (asset "+
"invoice, <354sats)")
Expand Down Expand Up @@ -2686,7 +2702,7 @@ func testCustomChannelsOraclePricing(_ context.Context,
)
}

// testCustomChannelsFee tests the whether the custom channel funding process
// testCustomChannelsFee tests whether the custom channel funding process
// fails if the proposed fee rate is lower than the minimum relay fee.
func testCustomChannelsFee(_ context.Context,
net *NetworkHarness, t *harnessTest) {
Expand Down

0 comments on commit d0e6a25

Please sign in to comment.