Skip to content

Commit 4761fe3

Browse files
committed
itest: refactor invoice payment helpers
1 parent a2229e9 commit 4761fe3

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

itest/assets_test.go

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -820,8 +820,8 @@ func createAndPayNormalInvoiceWithBtc(t *testing.T, src, dst *HarnessNode,
820820
payInvoiceWithSatoshi(t, src, invoiceResp)
821821
}
822822

823-
func createAndPayNormalInvoice(t *testing.T, src, rfqPeer, dst *HarnessNode,
824-
amountSat btcutil.Amount, assetID []byte, opts ...payOpt) uint64 {
823+
func createNormalInvoice(t *testing.T, dst *HarnessNode,
824+
amountSat btcutil.Amount) *lnrpc.AddInvoiceResponse {
825825

826826
ctxb := context.Background()
827827
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
@@ -835,6 +835,13 @@ func createAndPayNormalInvoice(t *testing.T, src, rfqPeer, dst *HarnessNode,
835835
})
836836
require.NoError(t, err)
837837

838+
return invoiceResp
839+
}
840+
841+
func createAndPayNormalInvoice(t *testing.T, src, rfqPeer, dst *HarnessNode,
842+
amountSat btcutil.Amount, assetID []byte, opts ...payOpt) uint64 {
843+
844+
invoiceResp := createNormalInvoice(t, dst, amountSat)
838845
numUnits, _ := payInvoiceWithAssets(
839846
t, src, rfqPeer, invoiceResp.PaymentRequest, assetID, opts...,
840847
)
@@ -874,19 +881,27 @@ func payInvoiceWithSatoshi(t *testing.T, payer *HarnessNode,
874881
}
875882

876883
func payInvoiceWithSatoshiLastHop(t *testing.T, payer *HarnessNode,
877-
invoice *lnrpc.AddInvoiceResponse, hopPub []byte,
878-
expectedStatus lnrpc.Payment_PaymentStatus) {
884+
invoice *lnrpc.AddInvoiceResponse, hops [][]byte, opts ...payOpt) {
885+
886+
cfg := defaultPayConfig()
887+
for _, opt := range opts {
888+
opt(cfg)
889+
}
879890

880891
ctxb := context.Background()
881892
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
882893
defer cancel()
883894

895+
decodedInvoice, err := payer.DecodePayReq(ctxt, &lnrpc.PayReqString{
896+
PayReq: invoice.PaymentRequest,
897+
})
898+
require.NoError(t, err)
899+
884900
routeRes, err := payer.RouterClient.BuildRoute(
885901
ctxb, &routerrpc.BuildRouteRequest{
886-
AmtMsat: 17800,
887-
FinalCltvDelta: 80,
888-
PaymentAddr: invoice.PaymentAddr,
889-
HopPubkeys: [][]byte{hopPub},
902+
AmtMsat: decodedInvoice.NumMsat,
903+
PaymentAddr: invoice.PaymentAddr,
904+
HopPubkeys: hops,
890905
},
891906
)
892907
require.NoError(t, err)
@@ -897,11 +912,13 @@ func payInvoiceWithSatoshiLastHop(t *testing.T, payer *HarnessNode,
897912
Route: routeRes.Route,
898913
},
899914
)
915+
require.NoError(t, err)
900916

901-
switch expectedStatus {
917+
switch cfg.payStatus {
902918
case lnrpc.Payment_FAILED:
903919
require.NoError(t, err)
904920
require.Equal(t, lnrpc.HTLCAttempt_FAILED, res.Status)
921+
require.NotNil(t, res.Failure)
905922
require.Nil(t, res.Preimage)
906923

907924
case lnrpc.Payment_SUCCEEDED:

itest/litd_custom_channels_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2042,9 +2042,10 @@ func testCustomChannelsLiquidityEdgeCases(ctx context.Context,
20422042

20432043
// Yara pays Dave with enough satoshis, but Charlie will not settle as
20442044
// he expects assets.
2045-
payInvoiceWithSatoshiLastHop(
2046-
t.t, yara, invoiceResp, dave.PubKey[:], lnrpc.Payment_FAILED,
2047-
)
2045+
hops := [][]byte{dave.PubKey[:]}
2046+
payInvoiceWithSatoshiLastHop(t.t, yara, invoiceResp, hops, withFailure(
2047+
lnrpc.Payment_FAILED, 0,
2048+
))
20482049

20492050
t.lndHarness.LNDHarness.AssertInvoiceState(stream, lnrpc.Invoice_OPEN)
20502051

0 commit comments

Comments
 (0)