lnd_test: use one timeout context per AddInvoice
This commit is contained in:
1 file changed
+24
-40
+24
-40
@@ -625,9 +625,8 @@ func makeFakePayHash(t *harnessTest) []byte {
|
|||||||
|
|
||||||
// createPayReqs is a helper method that will create a slice of payment
|
// createPayReqs is a helper method that will create a slice of payment
|
||||||
// requests for the given node.
|
// requests for the given node.
|
||||||
func createPayReqs(ctx context.Context, node *lntest.HarnessNode,
|
func createPayReqs(node *lntest.HarnessNode, paymentAmt btcutil.Amount,
|
||||||
paymentAmt btcutil.Amount, numInvoices int) ([]string, [][]byte,
|
numInvoices int) ([]string, [][]byte, []*lnrpc.Invoice, error) {
|
||||||
[]*lnrpc.Invoice, error) {
|
|
||||||
|
|
||||||
payReqs := make([]string, numInvoices)
|
payReqs := make([]string, numInvoices)
|
||||||
rHashes := make([][]byte, numInvoices)
|
rHashes := make([][]byte, numInvoices)
|
||||||
@@ -644,7 +643,10 @@ func createPayReqs(ctx context.Context, node *lntest.HarnessNode,
|
|||||||
RPreimage: preimage,
|
RPreimage: preimage,
|
||||||
Value: int64(paymentAmt),
|
Value: int64(paymentAmt),
|
||||||
}
|
}
|
||||||
resp, err := node.AddInvoice(ctx, invoice)
|
ctxt, _ := context.WithTimeout(
|
||||||
|
context.Background(), defaultTimeout,
|
||||||
|
)
|
||||||
|
resp, err := node.AddInvoice(ctxt, invoice)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, nil, fmt.Errorf("unable to add "+
|
return nil, nil, nil, fmt.Errorf("unable to add "+
|
||||||
"invoice: %v", err)
|
"invoice: %v", err)
|
||||||
@@ -4045,9 +4047,8 @@ func testMultiHopPayments(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
// satoshis with a different preimage each time.
|
// satoshis with a different preimage each time.
|
||||||
const numPayments = 5
|
const numPayments = 5
|
||||||
const paymentAmt = 1000
|
const paymentAmt = 1000
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
|
||||||
payReqs, _, _, err := createPayReqs(
|
payReqs, _, _, err := createPayReqs(
|
||||||
ctxt, net.Bob, paymentAmt, numPayments,
|
net.Bob, paymentAmt, numPayments,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create pay reqs: %v", err)
|
t.Fatalf("unable to create pay reqs: %v", err)
|
||||||
@@ -4270,9 +4271,8 @@ func testSingleHopSendToRoute(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
// Create 5 invoices for Bob, which expect a payment from Alice for 1k
|
// Create 5 invoices for Bob, which expect a payment from Alice for 1k
|
||||||
// satoshis with a different preimage each time.
|
// satoshis with a different preimage each time.
|
||||||
const numPayments = 5
|
const numPayments = 5
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
|
||||||
_, rHashes, _, err := createPayReqs(
|
_, rHashes, _, err := createPayReqs(
|
||||||
ctxt, net.Bob, paymentAmt, numPayments,
|
net.Bob, paymentAmt, numPayments,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create pay reqs: %v", err)
|
t.Fatalf("unable to create pay reqs: %v", err)
|
||||||
@@ -4455,9 +4455,8 @@ func testMultiHopSendToRoute(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
// Create 5 invoices for Carol, which expect a payment from Alice for 1k
|
// Create 5 invoices for Carol, which expect a payment from Alice for 1k
|
||||||
// satoshis with a different preimage each time.
|
// satoshis with a different preimage each time.
|
||||||
const numPayments = 5
|
const numPayments = 5
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
|
||||||
_, rHashes, _, err := createPayReqs(
|
_, rHashes, _, err := createPayReqs(
|
||||||
ctxt, carol, paymentAmt, numPayments,
|
carol, paymentAmt, numPayments,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create pay reqs: %v", err)
|
t.Fatalf("unable to create pay reqs: %v", err)
|
||||||
@@ -4982,9 +4981,8 @@ func testPrivateChannels(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
// by only using one of the channels.
|
// by only using one of the channels.
|
||||||
const numPayments = 2
|
const numPayments = 2
|
||||||
const paymentAmt = 70000
|
const paymentAmt = 70000
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
|
||||||
payReqs, _, _, err := createPayReqs(
|
payReqs, _, _, err := createPayReqs(
|
||||||
ctxt, net.Bob, paymentAmt, numPayments,
|
net.Bob, paymentAmt, numPayments,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create pay reqs: %v", err)
|
t.Fatalf("unable to create pay reqs: %v", err)
|
||||||
@@ -5039,9 +5037,8 @@ func testPrivateChannels(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
// Alice should also be able to route payments using this channel,
|
// Alice should also be able to route payments using this channel,
|
||||||
// so send two payments of 60k back to Carol.
|
// so send two payments of 60k back to Carol.
|
||||||
const paymentAmt60k = 60000
|
const paymentAmt60k = 60000
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
|
||||||
payReqs, _, _, err = createPayReqs(
|
payReqs, _, _, err = createPayReqs(
|
||||||
ctxt, carol, paymentAmt60k, numPayments,
|
carol, paymentAmt60k, numPayments,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create pay reqs: %v", err)
|
t.Fatalf("unable to create pay reqs: %v", err)
|
||||||
@@ -5702,9 +5699,8 @@ func testInvoiceSubscriptions(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
|
|
||||||
// We'll now add 3 more invoices to Bob's invoice registry.
|
// We'll now add 3 more invoices to Bob's invoice registry.
|
||||||
const numInvoices = 3
|
const numInvoices = 3
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
|
||||||
payReqs, _, newInvoices, err := createPayReqs(
|
payReqs, _, newInvoices, err := createPayReqs(
|
||||||
ctxt, net.Bob, paymentAmt, numInvoices,
|
net.Bob, paymentAmt, numInvoices,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create pay reqs: %v", err)
|
t.Fatalf("unable to create pay reqs: %v", err)
|
||||||
@@ -6720,9 +6716,8 @@ func testRevokedCloseRetribution(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
|
|
||||||
// With the channel open, we'll create a few invoices for Bob that
|
// With the channel open, we'll create a few invoices for Bob that
|
||||||
// Carol will pay to in order to advance the state of the channel.
|
// Carol will pay to in order to advance the state of the channel.
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
|
||||||
bobPayReqs, _, _, err := createPayReqs(
|
bobPayReqs, _, _, err := createPayReqs(
|
||||||
ctxt, net.Bob, paymentAmt, numInvoices,
|
net.Bob, paymentAmt, numInvoices,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create pay reqs: %v", err)
|
t.Fatalf("unable to create pay reqs: %v", err)
|
||||||
@@ -6984,9 +6979,8 @@ func testRevokedCloseRetributionZeroValueRemoteOutput(net *lntest.NetworkHarness
|
|||||||
|
|
||||||
// With the channel open, we'll create a few invoices for Carol that
|
// With the channel open, we'll create a few invoices for Carol that
|
||||||
// Dave will pay to in order to advance the state of the channel.
|
// Dave will pay to in order to advance the state of the channel.
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
|
||||||
carolPayReqs, _, _, err := createPayReqs(
|
carolPayReqs, _, _, err := createPayReqs(
|
||||||
ctxt, carol, paymentAmt, numInvoices,
|
carol, paymentAmt, numInvoices,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create pay reqs: %v", err)
|
t.Fatalf("unable to create pay reqs: %v", err)
|
||||||
@@ -7236,9 +7230,8 @@ func testRevokedCloseRetributionRemoteHodl(net *lntest.NetworkHarness,
|
|||||||
|
|
||||||
// With the channel open, we'll create a few invoices for Carol that
|
// With the channel open, we'll create a few invoices for Carol that
|
||||||
// Dave will pay to in order to advance the state of the channel.
|
// Dave will pay to in order to advance the state of the channel.
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
|
||||||
carolPayReqs, _, _, err := createPayReqs(
|
carolPayReqs, _, _, err := createPayReqs(
|
||||||
ctxt, carol, paymentAmt, numInvoices,
|
carol, paymentAmt, numInvoices,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create pay reqs: %v", err)
|
t.Fatalf("unable to create pay reqs: %v", err)
|
||||||
@@ -7299,9 +7292,8 @@ func testRevokedCloseRetributionRemoteHodl(net *lntest.NetworkHarness,
|
|||||||
// At this point, we'll also send over a set of HTLC's from Carol to
|
// At this point, we'll also send over a set of HTLC's from Carol to
|
||||||
// Dave. This ensures that the final revoked transaction has HTLC's in
|
// Dave. This ensures that the final revoked transaction has HTLC's in
|
||||||
// both directions.
|
// both directions.
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
|
||||||
davePayReqs, _, _, err := createPayReqs(
|
davePayReqs, _, _, err := createPayReqs(
|
||||||
ctxt, dave, paymentAmt, numInvoices,
|
dave, paymentAmt, numInvoices,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create pay reqs: %v", err)
|
t.Fatalf("unable to create pay reqs: %v", err)
|
||||||
@@ -7690,9 +7682,8 @@ func testDataLossProtection(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
// the channel.
|
// the channel.
|
||||||
// TODO(halseth): have dangling HTLCs on the commitment, able to
|
// TODO(halseth): have dangling HTLCs on the commitment, able to
|
||||||
// retrive funds?
|
// retrive funds?
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
|
||||||
payReqs, _, _, err := createPayReqs(
|
payReqs, _, _, err := createPayReqs(
|
||||||
ctxt, node, paymentAmt, numInvoices,
|
node, paymentAmt, numInvoices,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create pay reqs: %v", err)
|
t.Fatalf("unable to create pay reqs: %v", err)
|
||||||
@@ -8878,9 +8869,8 @@ func testAsyncPayments(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
|
|
||||||
// With the channel open, we'll create invoices for Bob that Alice
|
// With the channel open, we'll create invoices for Bob that Alice
|
||||||
// will pay to in order to advance the state of the channel.
|
// will pay to in order to advance the state of the channel.
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
|
||||||
bobPayReqs, _, _, err := createPayReqs(
|
bobPayReqs, _, _, err := createPayReqs(
|
||||||
ctxt, net.Bob, paymentAmt, numInvoices,
|
net.Bob, paymentAmt, numInvoices,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create pay reqs: %v", err)
|
t.Fatalf("unable to create pay reqs: %v", err)
|
||||||
@@ -9030,9 +9020,8 @@ func testBidirectionalAsyncPayments(net *lntest.NetworkHarness, t *harnessTest)
|
|||||||
|
|
||||||
// With the channel open, we'll create invoices for Bob that Alice
|
// With the channel open, we'll create invoices for Bob that Alice
|
||||||
// will pay to in order to advance the state of the channel.
|
// will pay to in order to advance the state of the channel.
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
|
||||||
bobPayReqs, _, _, err := createPayReqs(
|
bobPayReqs, _, _, err := createPayReqs(
|
||||||
ctxt, net.Bob, paymentAmt, numInvoices,
|
net.Bob, paymentAmt, numInvoices,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create pay reqs: %v", err)
|
t.Fatalf("unable to create pay reqs: %v", err)
|
||||||
@@ -9040,9 +9029,8 @@ func testBidirectionalAsyncPayments(net *lntest.NetworkHarness, t *harnessTest)
|
|||||||
|
|
||||||
// With the channel open, we'll create invoices for Alice that Bob
|
// With the channel open, we'll create invoices for Alice that Bob
|
||||||
// will pay to in order to advance the state of the channel.
|
// will pay to in order to advance the state of the channel.
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
|
||||||
alicePayReqs, _, _, err := createPayReqs(
|
alicePayReqs, _, _, err := createPayReqs(
|
||||||
ctxt, net.Alice, paymentAmt, numInvoices,
|
net.Alice, paymentAmt, numInvoices,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create pay reqs: %v", err)
|
t.Fatalf("unable to create pay reqs: %v", err)
|
||||||
@@ -11143,9 +11131,8 @@ func testSwitchCircuitPersistence(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
// satoshis with a different preimage each time.
|
// satoshis with a different preimage each time.
|
||||||
const numPayments = 5
|
const numPayments = 5
|
||||||
const paymentAmt = 1000
|
const paymentAmt = 1000
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
|
||||||
payReqs, _, _, err := createPayReqs(
|
payReqs, _, _, err := createPayReqs(
|
||||||
ctxt, carol, paymentAmt, numPayments,
|
carol, paymentAmt, numPayments,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create pay reqs: %v", err)
|
t.Fatalf("unable to create pay reqs: %v", err)
|
||||||
@@ -11483,9 +11470,8 @@ func testSwitchOfflineDelivery(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
// satoshis with a different preimage each time.
|
// satoshis with a different preimage each time.
|
||||||
const numPayments = 5
|
const numPayments = 5
|
||||||
const paymentAmt = 1000
|
const paymentAmt = 1000
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
|
||||||
payReqs, _, _, err := createPayReqs(
|
payReqs, _, _, err := createPayReqs(
|
||||||
ctxt, carol, paymentAmt, numPayments,
|
carol, paymentAmt, numPayments,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create pay reqs: %v", err)
|
t.Fatalf("unable to create pay reqs: %v", err)
|
||||||
@@ -11831,9 +11817,8 @@ func testSwitchOfflineDeliveryPersistence(net *lntest.NetworkHarness, t *harness
|
|||||||
// satoshis with a different preimage each time.
|
// satoshis with a different preimage each time.
|
||||||
const numPayments = 5
|
const numPayments = 5
|
||||||
const paymentAmt = 1000
|
const paymentAmt = 1000
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
|
||||||
payReqs, _, _, err := createPayReqs(
|
payReqs, _, _, err := createPayReqs(
|
||||||
ctxt, carol, paymentAmt, numPayments,
|
carol, paymentAmt, numPayments,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create pay reqs: %v", err)
|
t.Fatalf("unable to create pay reqs: %v", err)
|
||||||
@@ -12182,9 +12167,8 @@ func testSwitchOfflineDeliveryOutgoingOffline(
|
|||||||
// satoshis with a different preimage each time.
|
// satoshis with a different preimage each time.
|
||||||
const numPayments = 5
|
const numPayments = 5
|
||||||
const paymentAmt = 1000
|
const paymentAmt = 1000
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
|
||||||
payReqs, _, _, err := createPayReqs(
|
payReqs, _, _, err := createPayReqs(
|
||||||
ctxt, carol, paymentAmt, numPayments,
|
carol, paymentAmt, numPayments,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create pay reqs: %v", err)
|
t.Fatalf("unable to create pay reqs: %v", err)
|
||||||
|
|||||||
Reference in new issue
Block a user