Skip to content

Commit ca10707

Browse files
committed
itest+lntest: assert payment is failed once the htlc times out
1 parent faa3110 commit ca10707

File tree

2 files changed

+37
-7
lines changed

2 files changed

+37
-7
lines changed

itest/lnd_multi-hop_force_close_test.go

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,11 @@ func runLocalClaimOutgoingHTLC(ht *lntest.HarnessTest,
357357
// We'll create two random payment hashes unknown to carol, then send
358358
// each of them by manually specifying the HTLC details.
359359
carolPubKey := carol.PubKey[:]
360-
dustPayHash := ht.Random32Bytes()
361-
payHash := ht.Random32Bytes()
360+
361+
preimageDust := ht.RandomPreimage()
362+
preimage := ht.RandomPreimage()
363+
dustPayHash := preimageDust.Hash()
364+
payHash := preimage.Hash()
362365

363366
// If this is a taproot channel, then we'll need to make some manual
364367
// route hints so Alice can actually find a route.
@@ -370,7 +373,7 @@ func runLocalClaimOutgoingHTLC(ht *lntest.HarnessTest,
370373
req := &routerrpc.SendPaymentRequest{
371374
Dest: carolPubKey,
372375
Amt: int64(dustHtlcAmt),
373-
PaymentHash: dustPayHash,
376+
PaymentHash: dustPayHash[:],
374377
FinalCltvDelta: finalCltvDelta,
375378
FeeLimitMsat: noFeeLimitMsat,
376379
RouteHints: routeHints,
@@ -380,7 +383,7 @@ func runLocalClaimOutgoingHTLC(ht *lntest.HarnessTest,
380383
req = &routerrpc.SendPaymentRequest{
381384
Dest: carolPubKey,
382385
Amt: int64(htlcAmt),
383-
PaymentHash: payHash,
386+
PaymentHash: payHash[:],
384387
FinalCltvDelta: finalCltvDelta,
385388
FeeLimitMsat: noFeeLimitMsat,
386389
RouteHints: routeHints,
@@ -530,6 +533,25 @@ func runLocalClaimOutgoingHTLC(ht *lntest.HarnessTest,
530533
// Once this transaction has been confirmed, Bob should detect that he
531534
// no longer has any pending channels.
532535
ht.AssertNumPendingForceClose(bob, 0)
536+
537+
// Now that Bob has claimed his HTLCs, Alice should mark the two
538+
// payments as failed.
539+
//
540+
// Alice will mark this payment as failed with no route as the only
541+
// route she has is Alice->Bob->Carol. This won't be the case if she
542+
// has a second route, as another attempt will be tried.
543+
//
544+
// TODO(yy): we should instead mark this payment as timed out if she has
545+
// a second route to try this payment, which is the timeout set by Alice
546+
// when sending the payment.
547+
expectedReason := lnrpc.PaymentFailureReason_FAILURE_REASON_NO_ROUTE
548+
p := ht.AssertPaymentFailureReason(alice, preimage, expectedReason)
549+
require.Equal(ht, lnrpc.Failure_PERMANENT_CHANNEL_FAILURE,
550+
p.Htlcs[0].Failure.Code)
551+
552+
p = ht.AssertPaymentFailureReason(alice, preimageDust, expectedReason)
553+
require.Equal(ht, lnrpc.Failure_PERMANENT_CHANNEL_FAILURE,
554+
p.Htlcs[0].Failure.Code)
533555
}
534556

535557
// testMultiHopReceiverPreimageClaimAnchor tests

lntest/harness_assertion.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,8 +1600,11 @@ func (h *HarnessTest) AssertPaymentStatus(hn *node.HarnessNode,
16001600

16011601
// AssertPaymentFailureReason asserts that the given node lists a payment with
16021602
// the given preimage which has the expected failure reason.
1603-
func (h *HarnessTest) AssertPaymentFailureReason(hn *node.HarnessNode,
1604-
preimage lntypes.Preimage, reason lnrpc.PaymentFailureReason) {
1603+
func (h *HarnessTest) AssertPaymentFailureReason(
1604+
hn *node.HarnessNode, preimage lntypes.Preimage,
1605+
reason lnrpc.PaymentFailureReason) *lnrpc.Payment {
1606+
1607+
var payment *lnrpc.Payment
16051608

16061609
payHash := preimage.Hash()
16071610
err := wait.NoError(func() error {
@@ -1610,14 +1613,19 @@ func (h *HarnessTest) AssertPaymentFailureReason(hn *node.HarnessNode,
16101613
return err
16111614
}
16121615

1616+
payment = p
1617+
16131618
if reason == p.FailureReason {
16141619
return nil
16151620
}
16161621

16171622
return fmt.Errorf("payment: %v failure reason not match, "+
1618-
"want %s got %s", payHash, reason, p.Status)
1623+
"want %s(%d) got %s(%d)", payHash, reason, reason,
1624+
p.FailureReason, p.FailureReason)
16191625
}, DefaultTimeout)
16201626
require.NoError(h, err, "timeout checking payment failure reason")
1627+
1628+
return payment
16211629
}
16221630

16231631
// AssertActiveNodesSynced asserts all active nodes have synced to the chain.

0 commit comments

Comments
 (0)