Skip to content

Commit dc0ba72

Browse files
authored
Merge pull request #9566 from yyforyongyu/improve-itest
lntest+itest: change the method signature of `AssertPaymentStatus`
2 parents dfd43c9 + 2d5a2ce commit dc0ba72

9 files changed

+49
-43
lines changed

itest/lnd_experimental_endorsement.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func testEndorsement(ht *lntest.HarnessTest, aliceEndorse bool) {
7676

7777
var preimage lntypes.Preimage
7878
copy(preimage[:], invoice.RPreimage)
79-
ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_SUCCEEDED)
79+
ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_SUCCEEDED)
8080
}
8181

8282
func validateEndorsedAndResume(ht *lntest.HarnessTest,

itest/lnd_forward_interceptor_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func testForwardInterceptorDedupHtlc(ht *lntest.HarnessTest) {
122122
// We expect one in flight payment since we held the htlcs.
123123
var preimage lntypes.Preimage
124124
copy(preimage[:], invoice.RPreimage)
125-
ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_IN_FLIGHT)
125+
ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_IN_FLIGHT)
126126

127127
// At this point if we have more than one held htlcs then we should
128128
// fail. This means we hold the same htlc twice which is a risk we want
@@ -275,7 +275,7 @@ func testForwardInterceptorBasic(ht *lntest.HarnessTest) {
275275
copy(preimage[:], testCase.invoice.RPreimage)
276276

277277
payment := ht.AssertPaymentStatus(
278-
alice, preimage, lnrpc.Payment_IN_FLIGHT,
278+
alice, preimage.Hash(), lnrpc.Payment_IN_FLIGHT,
279279
)
280280
expectedAmt := testCase.invoice.ValueMsat
281281
require.Equal(ht, expectedAmt, payment.ValueMsat,
@@ -408,7 +408,7 @@ func testForwardInterceptorRestart(ht *lntest.HarnessTest) {
408408
// The payment should now be in flight.
409409
var preimage lntypes.Preimage
410410
copy(preimage[:], invoice.RPreimage)
411-
ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_IN_FLIGHT)
411+
ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_IN_FLIGHT)
412412

413413
// We don't resume the payment on Carol, so it should be held there.
414414
// We now restart first Bob, then Alice, so we can make sure we've
@@ -456,7 +456,7 @@ func testForwardInterceptorRestart(ht *lntest.HarnessTest) {
456456

457457
// Assert that the payment was successful.
458458
ht.AssertPaymentStatus(
459-
alice, preimage, lnrpc.Payment_SUCCEEDED,
459+
alice, preimage.Hash(), lnrpc.Payment_SUCCEEDED,
460460
func(p *lnrpc.Payment) error {
461461
recordsEqual := reflect.DeepEqual(
462462
lntest.CustomRecordsWithUnendorsed(

itest/lnd_hold_persistence_test.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,7 @@ func testHoldInvoicePersistence(ht *lntest.HarnessTest) {
185185
payStream := alice.RPC.TrackPaymentV2(hash[:])
186186
ht.ReceiveTrackPayment(payStream)
187187

188-
ht.AssertPaymentStatus(
189-
alice, preimg, lnrpc.Payment_IN_FLIGHT,
190-
)
188+
ht.AssertPaymentStatus(alice, hash, lnrpc.Payment_IN_FLIGHT)
191189
}
192190

193191
// Settle invoices half the invoices, cancel the rest.
@@ -211,11 +209,11 @@ func testHoldInvoicePersistence(ht *lntest.HarnessTest) {
211209
for i, preimg := range preimages {
212210
if i%2 == 0 {
213211
ht.AssertPaymentStatus(
214-
alice, preimg, lnrpc.Payment_SUCCEEDED,
212+
alice, preimg.Hash(), lnrpc.Payment_SUCCEEDED,
215213
)
216214
} else {
217215
payment := ht.AssertPaymentStatus(
218-
alice, preimg, lnrpc.Payment_FAILED,
216+
alice, preimg.Hash(), lnrpc.Payment_FAILED,
219217
)
220218
require.Equal(ht, reason, payment.FailureReason,
221219
"wrong failure reason")

itest/lnd_htlc_timeout_resolver_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ func testHtlcTimeoutResolverExtractPreimageRemote(ht *lntest.HarnessTest) {
197197
// Finally, check that the Alice's payment is marked as succeeded as
198198
// Bob has settled the htlc using the preimage extracted from Carol's
199199
// 2nd level success tx.
200-
ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_SUCCEEDED)
200+
ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_SUCCEEDED)
201201

202202
// Mine a block to clean the mempool.
203203
ht.MineBlocksAndAssertNumTxes(1, 2)
@@ -371,7 +371,7 @@ func testHtlcTimeoutResolverExtractPreimageLocal(ht *lntest.HarnessTest) {
371371
// Finally, check that the Alice's payment is marked as succeeded as
372372
// Bob has settled the htlc using the preimage extracted from Carol's
373373
// direct spend tx.
374-
ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_SUCCEEDED)
374+
ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_SUCCEEDED)
375375

376376
// NOTE: for non-standby nodes there's no need to clean up the force
377377
// close as long as the mempool is cleaned.

itest/lnd_mpp_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ func testSendToRouteMultiPath(ht *lntest.HarnessTest) {
200200
copy(preimage[:], invoices[0].RPreimage)
201201

202202
payment := ht.AssertPaymentStatus(
203-
hn, preimage, lnrpc.Payment_SUCCEEDED,
203+
hn, preimage.Hash(), lnrpc.Payment_SUCCEEDED,
204204
)
205205

206206
htlcs := payment.Htlcs

itest/lnd_multi-hop_force_close_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ func runMultiHopReceiverPreimageClaim(ht *lntest.HarnessTest,
894894
ht.AssertNumActiveHtlcs(alice, 0)
895895

896896
// Check that the Alice's payment is correctly marked succeeded.
897-
ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_SUCCEEDED)
897+
ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_SUCCEEDED)
898898

899899
// Carol's pending channel report should now show two outputs under
900900
// limbo: her commitment output, as well as the second-layer claim
@@ -1918,7 +1918,7 @@ func runLocalClaimIncomingHTLC(ht *lntest.HarnessTest,
19181918

19191919
// Finally, check that the Alice's payment is correctly marked
19201920
// succeeded.
1921-
ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_SUCCEEDED)
1921+
ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_SUCCEEDED)
19221922
}
19231923

19241924
// testLocalClaimIncomingHTLCLeasedZeroConf tests
@@ -2221,7 +2221,7 @@ func runLocalClaimIncomingHTLCLeased(ht *lntest.HarnessTest,
22212221

22222222
// Finally, check that the Alice's payment is correctly marked
22232223
// succeeded.
2224-
ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_SUCCEEDED)
2224+
ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_SUCCEEDED)
22252225
}
22262226

22272227
// testLocalPreimageClaimAnchorZeroConf tests `runLocalPreimageClaim` with
@@ -2575,7 +2575,7 @@ func runLocalPreimageClaim(ht *lntest.HarnessTest,
25752575

25762576
// Finally, check that the Alice's payment is correctly marked
25772577
// succeeded.
2578-
ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_SUCCEEDED)
2578+
ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_SUCCEEDED)
25792579
}
25802580

25812581
// testLocalPreimageClaimLeasedZeroConf tests `runLocalPreimageClaim` with
@@ -2839,7 +2839,7 @@ func runLocalPreimageClaimLeased(ht *lntest.HarnessTest,
28392839
ht.AssertInvoiceState(stream, lnrpc.Invoice_SETTLED)
28402840

28412841
// Check that the Alice's payment is correctly marked succeeded.
2842-
ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_SUCCEEDED)
2842+
ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_SUCCEEDED)
28432843

28442844
// With the script-enforced lease commitment type, Alice and Bob still
28452845
// haven't been able to sweep their respective commit outputs due to

itest/lnd_payment_test.go

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,10 @@ func testPaymentSucceededHTLCRemoteSwept(ht *lntest.HarnessTest) {
9898

9999
// We also check the payments are marked as IN_FLIGHT in Alice's
100100
// database.
101-
ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_IN_FLIGHT)
102-
ht.AssertPaymentStatus(alice, dustPreimage, lnrpc.Payment_IN_FLIGHT)
101+
ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_IN_FLIGHT)
102+
ht.AssertPaymentStatus(
103+
alice, dustPreimage.Hash(), lnrpc.Payment_IN_FLIGHT,
104+
)
103105

104106
// Bob should have two incoming HTLC.
105107
ht.AssertIncomingHTLCActive(bob, chanPoint, payHash[:])
@@ -166,12 +168,12 @@ func testPaymentSucceededHTLCRemoteSwept(ht *lntest.HarnessTest) {
166168
dustPayStream := alice.RPC.TrackPaymentV2(dustPayHash[:])
167169

168170
// Check that the dust payment is failed in both the stream and DB.
169-
ht.AssertPaymentStatus(alice, dustPreimage, lnrpc.Payment_FAILED)
171+
ht.AssertPaymentStatus(alice, dustPreimage.Hash(), lnrpc.Payment_FAILED)
170172
ht.AssertPaymentStatusFromStream(dustPayStream, lnrpc.Payment_FAILED)
171173

172174
// We expect the non-dust payment to marked as succeeded in Alice's
173175
// database and also from her stream.
174-
ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_SUCCEEDED)
176+
ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_SUCCEEDED)
175177
ht.AssertPaymentStatusFromStream(payStream, lnrpc.Payment_SUCCEEDED)
176178
}
177179

@@ -263,8 +265,10 @@ func runTestPaymentHTLCTimeout(ht *lntest.HarnessTest, restartAlice bool) {
263265

264266
// We also check the payments are marked as IN_FLIGHT in Alice's
265267
// database.
266-
ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_IN_FLIGHT)
267-
ht.AssertPaymentStatus(alice, dustPreimage, lnrpc.Payment_IN_FLIGHT)
268+
ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_IN_FLIGHT)
269+
ht.AssertPaymentStatus(
270+
alice, dustPreimage.Hash(), lnrpc.Payment_IN_FLIGHT,
271+
)
268272

269273
// Bob should have two incoming HTLC.
270274
ht.AssertIncomingHTLCActive(bob, chanPoint, payHash[:])
@@ -310,14 +314,14 @@ func runTestPaymentHTLCTimeout(ht *lntest.HarnessTest, restartAlice bool) {
310314
// mark the non-dust payment as succeeded.
311315
//
312316
// Check that the dust payment is failed in both the stream and DB.
313-
ht.AssertPaymentStatus(alice, dustPreimage, lnrpc.Payment_FAILED)
317+
ht.AssertPaymentStatus(alice, dustPreimage.Hash(), lnrpc.Payment_FAILED)
314318
ht.AssertPaymentStatusFromStream(dustPayStream, lnrpc.Payment_FAILED)
315319

316320
// Check that the non-dust payment is still in-flight.
317321
//
318322
// NOTE: we don't check the payment status from the stream here as
319323
// there's no new status being sent.
320-
ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_IN_FLIGHT)
324+
ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_IN_FLIGHT)
321325

322326
// We now have two possible cases for the non-dust payment:
323327
// - Bob stays offline, and Alice will sweep her outgoing HTLC, which
@@ -335,7 +339,7 @@ func runTestPaymentHTLCTimeout(ht *lntest.HarnessTest, restartAlice bool) {
335339

336340
// We expect the non-dust payment to marked as failed in Alice's
337341
// database and also from her stream.
338-
ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_FAILED)
342+
ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_FAILED)
339343
ht.AssertPaymentStatusFromStream(payStream, lnrpc.Payment_FAILED)
340344
}
341345

@@ -1114,7 +1118,7 @@ func sendPaymentInterceptAndCancel(ht *lntest.HarnessTest,
11141118
var preimage lntypes.Preimage
11151119
copy(preimage[:], invoice.RPreimage)
11161120
payment := ht.AssertPaymentStatus(
1117-
alice, preimage, lnrpc.Payment_IN_FLIGHT,
1121+
alice, preimage.Hash(), lnrpc.Payment_IN_FLIGHT,
11181122
)
11191123
reasonNone := lnrpc.PaymentFailureReason_FAILURE_REASON_NONE
11201124
require.Equal(ht, reasonNone, payment.FailureReason)
@@ -1127,7 +1131,7 @@ func sendPaymentInterceptAndCancel(ht *lntest.HarnessTest,
11271131
require.NoError(ht, err, "failed to send request")
11281132

11291133
// Assert that the payment status is as expected.
1130-
ht.AssertPaymentStatus(alice, preimage, expectedPaymentStatus)
1134+
ht.AssertPaymentStatus(alice, preimage.Hash(), expectedPaymentStatus)
11311135

11321136
// Since the payment context was cancelled, no further payment attempts
11331137
// should've been made, and we observe FAILURE_REASON_CANCELED.
@@ -1245,7 +1249,7 @@ func runSendToRouteFailHTLCTimeout(ht *lntest.HarnessTest, restartAlice bool) {
12451249
}()
12461250

12471251
// Check that the payment is in-flight.
1248-
ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_IN_FLIGHT)
1252+
ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_IN_FLIGHT)
12491253

12501254
// Construct a route to send the dust payment.
12511255
go func() {
@@ -1281,7 +1285,9 @@ func runSendToRouteFailHTLCTimeout(ht *lntest.HarnessTest, restartAlice bool) {
12811285
}()
12821286

12831287
// Check that the dust payment is in-flight.
1284-
ht.AssertPaymentStatus(alice, dustPreimage, lnrpc.Payment_IN_FLIGHT)
1288+
ht.AssertPaymentStatus(
1289+
alice, dustPreimage.Hash(), lnrpc.Payment_IN_FLIGHT,
1290+
)
12851291

12861292
// Bob should have two incoming HTLC.
12871293
ht.AssertIncomingHTLCActive(bob, chanPoint, payHash[:])
@@ -1323,14 +1329,14 @@ func runSendToRouteFailHTLCTimeout(ht *lntest.HarnessTest, restartAlice bool) {
13231329
// HTLC is resolved onchain.
13241330
//
13251331
// Check that the dust payment is failed in both the stream and DB.
1326-
ht.AssertPaymentStatus(alice, dustPreimage, lnrpc.Payment_FAILED)
1332+
ht.AssertPaymentStatus(alice, dustPreimage.Hash(), lnrpc.Payment_FAILED)
13271333
ht.AssertPaymentStatusFromStream(dustPayStream, lnrpc.Payment_FAILED)
13281334

13291335
// Check that the non-dust payment is still in-flight.
13301336
//
13311337
// NOTE: we don't check the payment status from the stream here as
13321338
// there's no new status being sent.
1333-
ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_IN_FLIGHT)
1339+
ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_IN_FLIGHT)
13341340

13351341
// We now have two possible cases for the non-dust payment:
13361342
// - Bob stays offline, and Alice will sweep her outgoing HTLC, which
@@ -1348,6 +1354,6 @@ func runSendToRouteFailHTLCTimeout(ht *lntest.HarnessTest, restartAlice bool) {
13481354

13491355
// We expect the non-dust payment to marked as failed in Alice's
13501356
// database and also from her stream.
1351-
ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_FAILED)
1357+
ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_FAILED)
13521358
ht.AssertPaymentStatusFromStream(payStream, lnrpc.Payment_FAILED)
13531359
}

itest/lnd_route_blinding_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ func (b *blindedForwardTest) sendToRoute(route *lnrpc.Route,
509509
require.NoError(b.ht, err)
510510

511511
pmt := b.ht.AssertPaymentStatus(
512-
b.alice, preimage, lnrpc.Payment_FAILED,
512+
b.alice, preimage.Hash(), lnrpc.Payment_FAILED,
513513
)
514514
require.Len(b.ht, pmt.Htlcs, 1)
515515

lntest/harness_assertion.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,16 +1550,15 @@ func (h *HarnessTest) findPayment(hn *node.HarnessNode,
15501550
// PaymentCheck is a function that checks a payment for a specific condition.
15511551
type PaymentCheck func(*lnrpc.Payment) error
15521552

1553-
// AssertPaymentStatus asserts that the given node list a payment with the
1554-
// given preimage has the expected status. It also checks that the payment has
1555-
// the expected preimage, which is empty when it's not settled and matches the
1556-
// given preimage when it's succeeded.
1553+
// AssertPaymentStatus asserts that the given node list a payment with the given
1554+
// payment hash has the expected status. It also checks that the payment has the
1555+
// expected preimage, which is empty when it's not settled and matches the given
1556+
// preimage when it's succeeded.
15571557
func (h *HarnessTest) AssertPaymentStatus(hn *node.HarnessNode,
1558-
preimage lntypes.Preimage, status lnrpc.Payment_PaymentStatus,
1558+
payHash lntypes.Hash, status lnrpc.Payment_PaymentStatus,
15591559
checks ...PaymentCheck) *lnrpc.Payment {
15601560

15611561
var target *lnrpc.Payment
1562-
payHash := preimage.Hash()
15631562

15641563
err := wait.NoError(func() error {
15651564
p, err := h.findPayment(hn, payHash.String())
@@ -1581,8 +1580,11 @@ func (h *HarnessTest) AssertPaymentStatus(hn *node.HarnessNode,
15811580
// If this expected status is SUCCEEDED, we expect the final
15821581
// preimage.
15831582
case lnrpc.Payment_SUCCEEDED:
1584-
require.Equal(h, preimage.String(), target.PaymentPreimage,
1585-
"preimage not match")
1583+
preimage, err := lntypes.MakePreimageFromStr(
1584+
target.PaymentPreimage,
1585+
)
1586+
require.NoError(h, err, "fail to make preimage")
1587+
require.Equal(h, payHash, preimage.Hash(), "preimage not match")
15861588

15871589
// Otherwise we expect an all-zero preimage.
15881590
default:

0 commit comments

Comments
 (0)