Skip to content

Commit

Permalink
itest: update payInvoiceWithAssets to take optional pay status
Browse files Browse the repository at this point in the history
This is useful as sometimes we just want to return once the HTLC has
been accepted, like when we're paying hodl invoices.
  • Loading branch information
Roasbeef committed Nov 21, 2024
1 parent c22cb75 commit d73c6ed
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 26 deletions.
20 changes: 12 additions & 8 deletions itest/assets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ func sendAssetKeySendPayment(t *testing.T, src, dst *HarnessNode, amt uint64,
})
require.NoError(t, err)

result, err := getAssetPaymentResult(stream)
result, err := getAssetPaymentResult(stream, false)
require.NoError(t, err)
require.Equal(t, expectedStatus, result.Status)

Expand Down Expand Up @@ -786,7 +786,8 @@ func createAndPayNormalInvoice(t *testing.T, src, rfqPeer, dst *HarnessNode,
require.NoError(t, err)

numUnits, _ := payInvoiceWithAssets(
t, src, rfqPeer, invoiceResp, assetID, smallShards,
t, src, rfqPeer, invoiceResp.PaymentRequest, assetID, smallShards,
fn.None[lnrpc.Payment_PaymentStatus](),
)

return numUnits
Expand Down Expand Up @@ -851,8 +852,9 @@ func payInvoiceWithSatoshiLastHop(t *testing.T, payer *HarnessNode,
}

func payInvoiceWithAssets(t *testing.T, payer, rfqPeer *HarnessNode,
invoice *lnrpc.AddInvoiceResponse, assetID []byte,
smallShards bool) (uint64, rfqmath.BigIntFixedPoint) {
payReq string, assetID []byte, smallShards bool,
expectedPayStatus fn.Option[lnrpc.Payment_PaymentStatus]) (uint64,
rfqmath.BigIntFixedPoint) {

ctxb := context.Background()
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
Expand All @@ -861,12 +863,12 @@ func payInvoiceWithAssets(t *testing.T, payer, rfqPeer *HarnessNode,
payerTapd := newTapClient(t, payer)

decodedInvoice, err := payer.DecodePayReq(ctxt, &lnrpc.PayReqString{
PayReq: invoice.PaymentRequest,
PayReq: payReq,
})
require.NoError(t, err)

sendReq := &routerrpc.SendPaymentRequest{
PaymentRequest: invoice.PaymentRequest,
PaymentRequest: payReq,
TimeoutSeconds: int32(PaymentTimeout.Seconds()),
FeeLimitMsat: 1_000_000,
}
Expand Down Expand Up @@ -906,9 +908,11 @@ func payInvoiceWithAssets(t *testing.T, payer, rfqPeer *HarnessNode,
"with SCID %d", numUnits, msatPerUnit, peerPubKey,
acceptedQuote.Scid)

result, err := getAssetPaymentResult(stream)
expectedStatus := expectedPayStatus.UnwrapOr(lnrpc.Payment_SUCCEEDED)

result, err := getAssetPaymentResult(stream, expectedPayStatus.IsSome())
require.NoError(t, err)
require.Equal(t, lnrpc.Payment_SUCCEEDED, result.Status)
require.Equal(t, expectedStatus, result.Status)

return numUnits, *rate
}
Expand Down
13 changes: 10 additions & 3 deletions itest/litd_accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,8 @@ func getPaymentResult(stream routerrpc.Router_SendPaymentV2Client) (
}

func getAssetPaymentResult(
s tapchannelrpc.TaprootAssetChannels_SendPaymentClient) (*lnrpc.Payment,
error) {
s tapchannelrpc.TaprootAssetChannels_SendPaymentClient,
isHodl bool) (*lnrpc.Payment, error) {

// No idea why it makes a difference whether we wait before calling
// s.Recv() or not, but it does. Without the sleep, the test will fail
Expand All @@ -456,7 +456,14 @@ func getAssetPaymentResult(
return nil, fmt.Errorf("unexpected message: %v", msg)
}

if payment.Status != lnrpc.Payment_IN_FLIGHT {
// If this is a hodl payment, then we'll return the first expected
// response. Otherwise, we'll wait until the in flight clears to we can
// observe the other payment states.
switch {
case isHodl:
return payment, nil

case payment.Status != lnrpc.Payment_IN_FLIGHT:
return payment, nil
}
}
Expand Down
76 changes: 61 additions & 15 deletions itest/litd_custom_channels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ var (
}

shortTimeout = time.Second * 5

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

var (
Expand Down Expand Up @@ -222,7 +224,10 @@ func testCustomChannelsLarge(_ context.Context, net *NetworkHarness,
invoiceResp := createAssetInvoice(
t.t, erin, fabia, fabiaInvoiceAssetAmount, assetID,
)
payInvoiceWithAssets(t.t, charlie, dave, invoiceResp, assetID, false)
payInvoiceWithAssets(
t.t, charlie, dave, invoiceResp.PaymentRequest, assetID, false,
defaultPaymentStatus,
)
logBalance(t.t, nodes, assetID, "after invoice")

invoiceResp2 := createAssetInvoice(
Expand All @@ -234,15 +239,21 @@ func testCustomChannelsLarge(_ context.Context, net *NetworkHarness,
// amount of zero.
time.Sleep(time.Second * 1)

payInvoiceWithAssets(t.t, fabia, erin, invoiceResp2, assetID, false)
payInvoiceWithAssets(
t.t, fabia, erin, invoiceResp2.PaymentRequest, assetID, false,
defaultPaymentStatus,
)
logBalance(t.t, nodes, assetID, "after invoice 2")

// Now we send a large invoice from Charlie to Dave.
const largeInvoiceAmount = 100_000
invoiceResp3 := createAssetInvoice(
t.t, charlie, dave, largeInvoiceAmount, assetID,
)
payInvoiceWithAssets(t.t, charlie, dave, invoiceResp3, assetID, false)
payInvoiceWithAssets(
t.t, charlie, dave, invoiceResp3.PaymentRequest, assetID, false,
defaultPaymentStatus,
)
logBalance(t.t, nodes, assetID, "after invoice 3")

// Make sure the invoice on the receiver side and the payment on the
Expand Down Expand Up @@ -431,7 +442,10 @@ func testCustomChannels(_ context.Context, net *NetworkHarness,
invoiceResp := createAssetInvoice(
t.t, dave, charlie, charlieInvoiceAmount, assetID,
)
payInvoiceWithAssets(t.t, dave, charlie, invoiceResp, assetID, true)
payInvoiceWithAssets(
t.t, dave, charlie, invoiceResp.PaymentRequest, assetID, true,
defaultPaymentStatus,
)
logBalance(t.t, nodes, assetID, "after invoice back")

// Make sure the invoice on the receiver side and the payment on the
Expand Down Expand Up @@ -493,7 +507,10 @@ func testCustomChannels(_ context.Context, net *NetworkHarness,
invoiceResp = createAssetInvoice(
t.t, charlie, dave, daveInvoiceAssetAmount, assetID,
)
payInvoiceWithAssets(t.t, charlie, dave, invoiceResp, assetID, true)
payInvoiceWithAssets(
t.t, charlie, dave, invoiceResp.PaymentRequest, assetID, true,
defaultPaymentStatus,
)
logBalance(t.t, nodes, assetID, "after invoice")

charlieAssetBalance -= daveInvoiceAssetAmount
Expand Down Expand Up @@ -535,7 +552,10 @@ func testCustomChannels(_ context.Context, net *NetworkHarness,
invoiceResp = createAssetInvoice(
t.t, erin, fabia, fabiaInvoiceAssetAmount1, assetID,
)
payInvoiceWithAssets(t.t, charlie, dave, invoiceResp, assetID, true)
payInvoiceWithAssets(
t.t, charlie, dave, invoiceResp.PaymentRequest, assetID, true,
defaultPaymentStatus,
)
logBalance(t.t, nodes, assetID, "after invoice")

charlieAssetBalance -= fabiaInvoiceAssetAmount1
Expand Down Expand Up @@ -569,7 +589,10 @@ func testCustomChannels(_ context.Context, net *NetworkHarness,
invoiceResp = createAssetInvoice(
t.t, erin, fabia, fabiaInvoiceAssetAmount3, assetID,
)
payInvoiceWithAssets(t.t, charlie, dave, invoiceResp, assetID, true)
payInvoiceWithAssets(
t.t, charlie, dave, invoiceResp.PaymentRequest, assetID, true,
defaultPaymentStatus,
)
logBalance(t.t, nodes, assetID, "after invoice")

charlieAssetBalance -= fabiaInvoiceAssetAmount3
Expand All @@ -587,7 +610,10 @@ func testCustomChannels(_ context.Context, net *NetworkHarness,
invoiceResp = createAssetInvoice(
t.t, dave, yara, yaraInvoiceAssetAmount1, assetID,
)
payInvoiceWithAssets(t.t, charlie, dave, invoiceResp, assetID, true)
payInvoiceWithAssets(
t.t, charlie, dave, invoiceResp.PaymentRequest, assetID, true,
defaultPaymentStatus,
)
logBalance(t.t, nodes, assetID, "after asset-to-asset")

charlieAssetBalance -= yaraInvoiceAssetAmount1
Expand Down Expand Up @@ -920,7 +946,10 @@ func testCustomChannelsGroupedAsset(_ context.Context, net *NetworkHarness,
invoiceResp := createAssetInvoice(
t.t, charlie, dave, daveInvoiceAssetAmount, assetID,
)
payInvoiceWithAssets(t.t, charlie, dave, invoiceResp, assetID, true)
payInvoiceWithAssets(
t.t, charlie, dave, invoiceResp.PaymentRequest, assetID, true,
defaultPaymentStatus,
)
logBalance(t.t, nodes, assetID, "after invoice")

// Make sure the invoice on the receiver side and the payment on the
Expand Down Expand Up @@ -955,7 +984,10 @@ func testCustomChannelsGroupedAsset(_ context.Context, net *NetworkHarness,
invoiceResp = createAssetInvoice(
t.t, erin, fabia, fabiaInvoiceAssetAmount1, assetID,
)
payInvoiceWithAssets(t.t, charlie, dave, invoiceResp, assetID, true)
payInvoiceWithAssets(
t.t, charlie, dave, invoiceResp.PaymentRequest, assetID, true,
defaultPaymentStatus,
)
logBalance(t.t, nodes, assetID, "after invoice")

charlieAssetBalance -= fabiaInvoiceAssetAmount1
Expand Down Expand Up @@ -989,7 +1021,10 @@ func testCustomChannelsGroupedAsset(_ context.Context, net *NetworkHarness,
invoiceResp = createAssetInvoice(
t.t, erin, fabia, fabiaInvoiceAssetAmount3, assetID,
)
payInvoiceWithAssets(t.t, charlie, dave, invoiceResp, assetID, true)
payInvoiceWithAssets(
t.t, charlie, dave, invoiceResp.PaymentRequest, assetID, true,
defaultPaymentStatus,
)
logBalance(t.t, nodes, assetID, "after invoice")

charlieAssetBalance -= fabiaInvoiceAssetAmount3
Expand All @@ -1007,7 +1042,10 @@ func testCustomChannelsGroupedAsset(_ context.Context, net *NetworkHarness,
invoiceResp = createAssetInvoice(
t.t, dave, yara, yaraInvoiceAssetAmount1, assetID,
)
payInvoiceWithAssets(t.t, charlie, dave, invoiceResp, assetID, true)
payInvoiceWithAssets(
t.t, charlie, dave, invoiceResp.PaymentRequest, assetID, true,
defaultPaymentStatus,
)
logBalance(t.t, nodes, assetID, "after asset-to-asset")

charlieAssetBalance -= yaraInvoiceAssetAmount1
Expand Down Expand Up @@ -1916,7 +1954,11 @@ func testCustomChannelsLiquidityEdgeCases(_ context.Context,
invoiceResp := createAssetInvoice(
t.t, charlie, dave, bigAssetAmount, assetID,
)
payInvoiceWithAssets(t.t, charlie, dave, invoiceResp, assetID, false)

payInvoiceWithAssets(
t.t, charlie, dave, invoiceResp.PaymentRequest, assetID, false,
defaultPaymentStatus,
)

logBalance(t.t, nodes, assetID, "after big asset payment (asset "+
"invoice, direct)")
Expand Down Expand Up @@ -1959,7 +2001,10 @@ func testCustomChannelsLiquidityEdgeCases(_ context.Context,
t.t, dave, charlie, bigAssetAmount, assetID,
)

payInvoiceWithAssets(t.t, yara, dave, invoiceResp, assetID, false)
payInvoiceWithAssets(
t.t, yara, dave, invoiceResp.PaymentRequest, assetID, false,
defaultPaymentStatus,
)

logBalance(t.t, nodes, assetID, "after big asset payment (asset "+
"invoice, multi-hop)")
Expand Down Expand Up @@ -2516,7 +2561,8 @@ func testCustomChannelsOraclePricing(_ context.Context,
require.EqualValues(t.t, 153_333_242, decodedInvoice.NumMsat)

numUnits, rate := payInvoiceWithAssets(
t.t, charlie, dave, invoiceResp, assetID, false,
t.t, charlie, dave, invoiceResp.PaymentRequest, assetID, false,
defaultPaymentStatus,
)
logBalance(t.t, nodes, assetID, "after invoice")

Expand Down

0 comments on commit d73c6ed

Please sign in to comment.