mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-11-10 14:17:56 +01:00
invoices/test: fix data race in TestMppPaymentWithOverpayment
Details of race: - A global testInvoice is used in various invoice related tests. - All tests are running with t.Parallel. - TestMppPaymentWithOverpayment passes a reference to the testInvoice to AddInvoice which writes the AddIndex. - TestMultipleSetHeightExpiry reads the testInvoice to make a copy.
This commit is contained in:
@@ -936,8 +936,9 @@ func TestMppPaymentWithOverpayment(t *testing.T) {
|
|||||||
ctx := newTestContext(t, nil)
|
ctx := newTestContext(t, nil)
|
||||||
|
|
||||||
// Add the invoice.
|
// Add the invoice.
|
||||||
|
invoice := *testInvoice
|
||||||
_, err := ctx.registry.AddInvoice(
|
_, err := ctx.registry.AddInvoice(
|
||||||
testInvoice, testInvoicePaymentHash,
|
&invoice, testInvoicePaymentHash,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@@ -953,7 +954,7 @@ func TestMppPaymentWithOverpayment(t *testing.T) {
|
|||||||
// Send htlc 1.
|
// Send htlc 1.
|
||||||
hodlChan1 := make(chan interface{}, 1)
|
hodlChan1 := make(chan interface{}, 1)
|
||||||
resolution, err := ctx.registry.NotifyExitHopHtlc(
|
resolution, err := ctx.registry.NotifyExitHopHtlc(
|
||||||
testInvoicePaymentHash, testInvoice.Terms.Value/2,
|
testInvoicePaymentHash, invoice.Terms.Value/2,
|
||||||
testHtlcExpiry, testCurrentHeight, getCircuitKey(11),
|
testHtlcExpiry, testCurrentHeight, getCircuitKey(11),
|
||||||
hodlChan1, mppPayload,
|
hodlChan1, mppPayload,
|
||||||
)
|
)
|
||||||
@@ -968,7 +969,7 @@ func TestMppPaymentWithOverpayment(t *testing.T) {
|
|||||||
hodlChan2 := make(chan interface{}, 1)
|
hodlChan2 := make(chan interface{}, 1)
|
||||||
resolution, err = ctx.registry.NotifyExitHopHtlc(
|
resolution, err = ctx.registry.NotifyExitHopHtlc(
|
||||||
testInvoicePaymentHash,
|
testInvoicePaymentHash,
|
||||||
testInvoice.Terms.Value/2+overpayment, testHtlcExpiry,
|
invoice.Terms.Value/2+overpayment, testHtlcExpiry,
|
||||||
testCurrentHeight, getCircuitKey(12), hodlChan2,
|
testCurrentHeight, getCircuitKey(12), hodlChan2,
|
||||||
mppPayload,
|
mppPayload,
|
||||||
)
|
)
|
||||||
@@ -996,7 +997,7 @@ func TestMppPaymentWithOverpayment(t *testing.T) {
|
|||||||
t.Fatal("expected invoice to be settled")
|
t.Fatal("expected invoice to be settled")
|
||||||
}
|
}
|
||||||
|
|
||||||
return inv.AmtPaid == testInvoice.Terms.Value+overpayment
|
return inv.AmtPaid == invoice.Terms.Value+overpayment
|
||||||
}
|
}
|
||||||
if err := quick.Check(f, nil); err != nil {
|
if err := quick.Check(f, nil); err != nil {
|
||||||
t.Fatalf("amount incorrect: %v", err)
|
t.Fatalf("amount incorrect: %v", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user