mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-04 01:36:24 +01:00
itest: manage context timeout inside completePaymentRequests
This commit is contained in:
parent
5a94919b7e
commit
a6c5255e77
13 changed files with 39 additions and 79 deletions
|
@ -968,7 +968,7 @@ func testChanRestoreScenario(t *harnessTest, net *lntest.NetworkHarness,
|
|||
}
|
||||
|
||||
err = completePaymentRequests(
|
||||
ctxt, from, from.RouterClient,
|
||||
from, from.RouterClient,
|
||||
[]string{invoiceResp.PaymentRequest}, true,
|
||||
)
|
||||
if err != nil {
|
||||
|
|
|
@ -1444,9 +1444,8 @@ func testFailingChannel(net *lntest.NetworkHarness, t *harnessTest) {
|
|||
|
||||
// Send the payment from Alice to Carol. We expect Carol to attempt to
|
||||
// settle this payment with the wrong preimage.
|
||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||
err = completePaymentRequests(
|
||||
ctxt, net.Alice, net.Alice.RouterClient, carolPayReqs, false,
|
||||
net.Alice, net.Alice.RouterClient, carolPayReqs, false,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send payments: %v", err)
|
||||
|
|
|
@ -194,9 +194,8 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) {
|
|||
t.Fatalf("unable to add invoice: %v", err)
|
||||
}
|
||||
|
||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||
err = completePaymentRequests(
|
||||
ctxt, net.Alice, net.Alice.RouterClient,
|
||||
net.Alice, net.Alice.RouterClient,
|
||||
[]string{resp.PaymentRequest}, true,
|
||||
)
|
||||
|
||||
|
@ -377,9 +376,8 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) {
|
|||
t.Fatalf("unable to add invoice: %v", err)
|
||||
}
|
||||
|
||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||
err = completePaymentRequests(
|
||||
ctxt, net.Alice, net.Alice.RouterClient,
|
||||
net.Alice, net.Alice.RouterClient,
|
||||
[]string{resp.PaymentRequest}, true,
|
||||
)
|
||||
if err != nil {
|
||||
|
|
|
@ -440,10 +440,8 @@ func testExternalFundingChanPoint(net *lntest.NetworkHarness, t *harnessTest) {
|
|||
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
|
||||
resp, err := dave.AddInvoice(ctxt, invoice)
|
||||
require.NoError(t.t, err)
|
||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||
err = completePaymentRequests(
|
||||
ctxt, carol, carol.RouterClient, []string{resp.PaymentRequest},
|
||||
true,
|
||||
carol, carol.RouterClient, []string{resp.PaymentRequest}, true,
|
||||
)
|
||||
require.NoError(t.t, err)
|
||||
|
||||
|
|
|
@ -883,9 +883,8 @@ func testDataLossProtection(net *lntest.NetworkHarness, t *harnessTest) {
|
|||
|
||||
// Send payments from Carol using 3 of the payment hashes
|
||||
// generated above.
|
||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||
err = completePaymentRequests(
|
||||
ctxt, carol, carol.RouterClient,
|
||||
carol, carol.RouterClient,
|
||||
payReqs[:numInvoices/2], true,
|
||||
)
|
||||
if err != nil {
|
||||
|
@ -931,10 +930,8 @@ func testDataLossProtection(net *lntest.NetworkHarness, t *harnessTest) {
|
|||
|
||||
// Finally, send more payments from , using the remaining
|
||||
// payment hashes.
|
||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||
err = completePaymentRequests(
|
||||
ctxt, carol, carol.RouterClient,
|
||||
payReqs[numInvoices/2:], true,
|
||||
carol, carol.RouterClient, payReqs[numInvoices/2:], true,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send payments: %v", err)
|
||||
|
@ -1185,9 +1182,8 @@ func testRejectHTLC(net *lntest.NetworkHarness, t *harnessTest) {
|
|||
}
|
||||
|
||||
// Alice pays Carols invoice.
|
||||
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
|
||||
err = completePaymentRequests(
|
||||
ctxt, net.Alice, net.Alice.RouterClient,
|
||||
net.Alice, net.Alice.RouterClient,
|
||||
[]string{resp.PaymentRequest}, true,
|
||||
)
|
||||
if err != nil {
|
||||
|
@ -1211,9 +1207,8 @@ func testRejectHTLC(net *lntest.NetworkHarness, t *harnessTest) {
|
|||
}
|
||||
|
||||
// Carol pays Bobs invoice.
|
||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||
err = completePaymentRequests(
|
||||
ctxt, carol, carol.RouterClient,
|
||||
carol, carol.RouterClient,
|
||||
[]string{resp.PaymentRequest}, true,
|
||||
)
|
||||
if err != nil {
|
||||
|
@ -1240,9 +1235,8 @@ func testRejectHTLC(net *lntest.NetworkHarness, t *harnessTest) {
|
|||
// Alice attempts to pay Bobs invoice. This payment should be rejected since
|
||||
// we are using Carol as an intermediary hop, Carol is running lnd with
|
||||
// --rejecthtlc.
|
||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||
err = completePaymentRequests(
|
||||
ctxt, net.Alice, net.Alice.RouterClient,
|
||||
net.Alice, net.Alice.RouterClient,
|
||||
[]string{resp.PaymentRequest}, true,
|
||||
)
|
||||
if err == nil {
|
||||
|
|
|
@ -198,10 +198,7 @@ func testMultiHopPayments(net *lntest.NetworkHarness, t *harnessTest) {
|
|||
|
||||
// Using Carol as the source, pay to the 5 invoices from Bob created
|
||||
// above.
|
||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||
err = completePaymentRequests(
|
||||
ctxt, carol, carol.RouterClient, payReqs, true,
|
||||
)
|
||||
err = completePaymentRequests(carol, carol.RouterClient, payReqs, true)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send payments: %v", err)
|
||||
}
|
||||
|
|
|
@ -770,9 +770,8 @@ func testInvoiceSubscriptions(net *lntest.NetworkHarness, t *harnessTest) {
|
|||
|
||||
// We'll now have Bob settle out the remainder of these invoices so we
|
||||
// can test that all settled invoices are properly notified.
|
||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||
err = completePaymentRequests(
|
||||
ctxt, net.Alice, net.Alice.RouterClient, payReqs, true,
|
||||
net.Alice, net.Alice.RouterClient, payReqs, true,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send payment: %v", err)
|
||||
|
|
|
@ -233,10 +233,8 @@ func testPsbtChanFunding(net *lntest.NetworkHarness, t *harnessTest) {
|
|||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||
resp, err := dave.AddInvoice(ctxt, invoice)
|
||||
require.NoError(t.t, err)
|
||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||
err = completePaymentRequests(
|
||||
ctxt, carol, carol.RouterClient, []string{resp.PaymentRequest},
|
||||
true,
|
||||
carol, carol.RouterClient, []string{resp.PaymentRequest}, true,
|
||||
)
|
||||
require.NoError(t.t, err)
|
||||
|
||||
|
|
|
@ -79,10 +79,8 @@ func testRevokedCloseRetribution(net *lntest.NetworkHarness, t *harnessTest) {
|
|||
|
||||
// Send payments from Carol to Bob using 3 of Bob's payment hashes
|
||||
// generated above.
|
||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||
err = completePaymentRequests(
|
||||
ctxt, carol, carol.RouterClient, bobPayReqs[:numInvoices/2],
|
||||
true,
|
||||
carol, carol.RouterClient, bobPayReqs[:numInvoices/2], true,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send payments: %v", err)
|
||||
|
@ -126,10 +124,8 @@ func testRevokedCloseRetribution(net *lntest.NetworkHarness, t *harnessTest) {
|
|||
|
||||
// Finally, send payments from Carol to Bob, consuming Bob's remaining
|
||||
// payment hashes.
|
||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||
err = completePaymentRequests(
|
||||
ctxt, carol, carol.RouterClient, bobPayReqs[numInvoices/2:],
|
||||
true,
|
||||
carol, carol.RouterClient, bobPayReqs[numInvoices/2:], true,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send payments: %v", err)
|
||||
|
@ -358,9 +354,8 @@ func testRevokedCloseRetributionZeroValueRemoteOutput(net *lntest.NetworkHarness
|
|||
|
||||
// Finally, send payments from Dave to Carol, consuming Carol's remaining
|
||||
// payment hashes.
|
||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||
err = completePaymentRequests(
|
||||
ctxt, dave, dave.RouterClient, carolPayReqs, false,
|
||||
dave, dave.RouterClient, carolPayReqs, false,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send payments: %v", err)
|
||||
|
@ -597,10 +592,8 @@ func testRevokedCloseRetributionRemoteHodl(net *lntest.NetworkHarness,
|
|||
|
||||
// Send payments from Dave to Carol using 3 of Carol's payment hashes
|
||||
// generated above.
|
||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||
err = completePaymentRequests(
|
||||
ctxt, dave, dave.RouterClient, carolPayReqs[:numInvoices/2],
|
||||
false,
|
||||
dave, dave.RouterClient, carolPayReqs[:numInvoices/2], false,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send payments: %v", err)
|
||||
|
@ -618,10 +611,8 @@ func testRevokedCloseRetributionRemoteHodl(net *lntest.NetworkHarness,
|
|||
|
||||
// Send payments from Carol to Dave using 3 of Dave's payment hashes
|
||||
// generated above.
|
||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||
err = completePaymentRequests(
|
||||
ctxt, carol, carol.RouterClient, davePayReqs[:numInvoices/2],
|
||||
false,
|
||||
carol, carol.RouterClient, davePayReqs[:numInvoices/2], false,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send payments: %v", err)
|
||||
|
@ -658,10 +649,8 @@ func testRevokedCloseRetributionRemoteHodl(net *lntest.NetworkHarness,
|
|||
|
||||
// Finally, send payments from Dave to Carol, consuming Carol's
|
||||
// remaining payment hashes.
|
||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||
err = completePaymentRequests(
|
||||
ctxt, dave, dave.RouterClient, carolPayReqs[numInvoices/2:],
|
||||
false,
|
||||
dave, dave.RouterClient, carolPayReqs[numInvoices/2:], false,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send payments: %v", err)
|
||||
|
@ -1082,7 +1071,7 @@ func testRevokedCloseRetributionAltruistWatchtowerCase(
|
|||
// Finally, send payments from Dave to Carol, consuming Carol's remaining
|
||||
// payment hashes.
|
||||
err = completePaymentRequests(
|
||||
ctxb, dave, dave.RouterClient, carolPayReqs, false,
|
||||
dave, dave.RouterClient, carolPayReqs, false,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send payments: %v", err)
|
||||
|
|
|
@ -884,10 +884,7 @@ func testPrivateChannels(net *lntest.NetworkHarness, t *harnessTest) {
|
|||
time.Sleep(time.Millisecond * 50)
|
||||
|
||||
// Let Carol pay the invoices.
|
||||
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
|
||||
err = completePaymentRequests(
|
||||
ctxt, carol, carol.RouterClient, payReqs, true,
|
||||
)
|
||||
err = completePaymentRequests(carol, carol.RouterClient, payReqs, true)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send payments: %v", err)
|
||||
}
|
||||
|
@ -942,9 +939,8 @@ func testPrivateChannels(net *lntest.NetworkHarness, t *harnessTest) {
|
|||
time.Sleep(time.Millisecond * 50)
|
||||
|
||||
// Let Bob pay the invoices.
|
||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||
err = completePaymentRequests(
|
||||
ctxt, net.Alice, net.Alice.RouterClient, payReqs, true,
|
||||
net.Alice, net.Alice.RouterClient, payReqs, true,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send payments: %v", err)
|
||||
|
@ -1115,11 +1111,10 @@ func testUpdateChannelPolicyForPrivateChannel(net *lntest.NetworkHarness,
|
|||
|
||||
// Alice pays the invoices. She will use the updated baseFeeMSat in the
|
||||
// payment
|
||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||
payReqs := []string{resp.PaymentRequest}
|
||||
require.NoError(t.t,
|
||||
completePaymentRequests(
|
||||
ctxt, net.Alice, net.Alice.RouterClient, payReqs, true,
|
||||
net.Alice, net.Alice.RouterClient, payReqs, true,
|
||||
), "unable to send payment",
|
||||
)
|
||||
|
||||
|
@ -1510,9 +1505,8 @@ func testMultiHopOverPrivateChannels(net *lntest.NetworkHarness, t *harnessTest)
|
|||
|
||||
// Let Alice pay the invoice.
|
||||
payReqs := []string{resp.PaymentRequest}
|
||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||
err = completePaymentRequests(
|
||||
ctxt, net.Alice, net.Alice.RouterClient, payReqs, true,
|
||||
net.Alice, net.Alice.RouterClient, payReqs, true,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send payments from alice to dave: %v", err)
|
||||
|
|
|
@ -157,9 +157,8 @@ func testSwitchCircuitPersistence(net *lntest.NetworkHarness, t *harnessTest) {
|
|||
|
||||
// Using Carol as the source, pay to the 5 invoices from Bob created
|
||||
// above.
|
||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||
err = completePaymentRequests(
|
||||
ctxt, net.Bob, net.Bob.RouterClient, payReqs, false,
|
||||
net.Bob, net.Bob.RouterClient, payReqs, false,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send payments: %v", err)
|
||||
|
@ -262,9 +261,8 @@ func testSwitchCircuitPersistence(net *lntest.NetworkHarness, t *harnessTest) {
|
|||
|
||||
// Using Carol as the source, pay to the 5 invoices from Bob created
|
||||
// above.
|
||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||
err = completePaymentRequests(
|
||||
ctxt, net.Bob, net.Bob.RouterClient, payReqs, true,
|
||||
net.Bob, net.Bob.RouterClient, payReqs, true,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send payments: %v", err)
|
||||
|
@ -445,9 +443,8 @@ func testSwitchOfflineDelivery(net *lntest.NetworkHarness, t *harnessTest) {
|
|||
|
||||
// Using Carol as the source, pay to the 5 invoices from Bob created
|
||||
// above.
|
||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||
err = completePaymentRequests(
|
||||
ctxt, net.Bob, net.Bob.RouterClient, payReqs, false,
|
||||
net.Bob, net.Bob.RouterClient, payReqs, false,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send payments: %v", err)
|
||||
|
@ -568,9 +565,8 @@ func testSwitchOfflineDelivery(net *lntest.NetworkHarness, t *harnessTest) {
|
|||
|
||||
// Using Carol as the source, pay to the 5 invoices from Bob created
|
||||
// above.
|
||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||
err = completePaymentRequests(
|
||||
ctxt, net.Bob, net.Bob.RouterClient, payReqs, true,
|
||||
net.Bob, net.Bob.RouterClient, payReqs, true,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send payments: %v", err)
|
||||
|
@ -743,9 +739,8 @@ func testSwitchOfflineDeliveryPersistence(net *lntest.NetworkHarness, t *harness
|
|||
|
||||
// Using Carol as the source, pay to the 5 invoices from Bob created
|
||||
// above.
|
||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||
err = completePaymentRequests(
|
||||
ctxt, net.Bob, net.Bob.RouterClient, payReqs, false,
|
||||
net.Bob, net.Bob.RouterClient, payReqs, false,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send payments: %v", err)
|
||||
|
@ -861,9 +856,8 @@ func testSwitchOfflineDeliveryPersistence(net *lntest.NetworkHarness, t *harness
|
|||
|
||||
// Using Carol as the source, pay to the 5 invoices from Bob created
|
||||
// above.
|
||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||
err = completePaymentRequests(
|
||||
ctxt, net.Bob, net.Bob.RouterClient, payReqs, true,
|
||||
net.Bob, net.Bob.RouterClient, payReqs, true,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send payments: %v", err)
|
||||
|
@ -1034,9 +1028,8 @@ func testSwitchOfflineDeliveryOutgoingOffline(
|
|||
|
||||
// Using Carol as the source, pay to the 5 invoices from Bob created
|
||||
// above.
|
||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||
err = completePaymentRequests(
|
||||
ctxt, net.Bob, net.Bob.RouterClient, payReqs, false,
|
||||
net.Bob, net.Bob.RouterClient, payReqs, false,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send payments: %v", err)
|
||||
|
|
|
@ -513,10 +513,8 @@ func fundChanAndCloseFromImportedAccount(t *harnessTest, srcNode, destNode,
|
|||
})
|
||||
require.NoError(t.t, err)
|
||||
|
||||
ctxt, cancel = context.WithTimeout(ctxb, defaultTimeout)
|
||||
defer cancel()
|
||||
err = completePaymentRequests(
|
||||
ctxt, srcNode, srcNode.RouterClient,
|
||||
srcNode, srcNode.RouterClient,
|
||||
[]string{resp.PaymentRequest}, true,
|
||||
)
|
||||
require.NoError(t.t, err)
|
||||
|
|
|
@ -25,16 +25,19 @@ import (
|
|||
// completePaymentRequests sends payments from a lightning node to complete all
|
||||
// payment requests. If the awaitResponse parameter is true, this function
|
||||
// does not return until all payments successfully complete without errors.
|
||||
func completePaymentRequests(ctx context.Context, client lnrpc.LightningClient,
|
||||
func completePaymentRequests(client lnrpc.LightningClient,
|
||||
routerClient routerrpc.RouterClient, paymentRequests []string,
|
||||
awaitResponse bool) error {
|
||||
|
||||
ctxb := context.Background()
|
||||
ctx, cancel := context.WithTimeout(ctxb, defaultTimeout)
|
||||
defer cancel()
|
||||
|
||||
// We start by getting the current state of the client's channels. This
|
||||
// is needed to ensure the payments actually have been committed before
|
||||
// we return.
|
||||
ctxt, _ := context.WithTimeout(ctx, defaultTimeout)
|
||||
req := &lnrpc.ListChannelsRequest{}
|
||||
listResp, err := client.ListChannels(ctxt, req)
|
||||
listResp, err := client.ListChannels(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -95,7 +98,7 @@ func completePaymentRequests(ctx context.Context, client lnrpc.LightningClient,
|
|||
// the send before cancelling the request. We wait for the number of
|
||||
// updates to one of our channels has increased before we return.
|
||||
err = wait.Predicate(func() bool {
|
||||
ctxt, _ = context.WithTimeout(ctx, defaultTimeout)
|
||||
ctxt, _ := context.WithTimeout(ctx, defaultTimeout)
|
||||
newListResp, err := client.ListChannels(ctxt, req)
|
||||
if err != nil {
|
||||
return false
|
||||
|
|
Loading…
Add table
Reference in a new issue