Merge pull request #9566 from yyforyongyu/improve-itest

lntest+itest: change the method signature of `AssertPaymentStatus`
This commit is contained in:
Oliver Gugger 2025-02-28 07:52:49 -06:00 committed by GitHub
commit dc0ba72271
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 49 additions and 43 deletions

View file

@ -76,7 +76,7 @@ func testEndorsement(ht *lntest.HarnessTest, aliceEndorse bool) {
var preimage lntypes.Preimage var preimage lntypes.Preimage
copy(preimage[:], invoice.RPreimage) copy(preimage[:], invoice.RPreimage)
ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_SUCCEEDED) ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_SUCCEEDED)
} }
func validateEndorsedAndResume(ht *lntest.HarnessTest, func validateEndorsedAndResume(ht *lntest.HarnessTest,

View file

@ -122,7 +122,7 @@ func testForwardInterceptorDedupHtlc(ht *lntest.HarnessTest) {
// We expect one in flight payment since we held the htlcs. // We expect one in flight payment since we held the htlcs.
var preimage lntypes.Preimage var preimage lntypes.Preimage
copy(preimage[:], invoice.RPreimage) copy(preimage[:], invoice.RPreimage)
ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_IN_FLIGHT) ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_IN_FLIGHT)
// At this point if we have more than one held htlcs then we should // At this point if we have more than one held htlcs then we should
// fail. This means we hold the same htlc twice which is a risk we want // fail. This means we hold the same htlc twice which is a risk we want
@ -275,7 +275,7 @@ func testForwardInterceptorBasic(ht *lntest.HarnessTest) {
copy(preimage[:], testCase.invoice.RPreimage) copy(preimage[:], testCase.invoice.RPreimage)
payment := ht.AssertPaymentStatus( payment := ht.AssertPaymentStatus(
alice, preimage, lnrpc.Payment_IN_FLIGHT, alice, preimage.Hash(), lnrpc.Payment_IN_FLIGHT,
) )
expectedAmt := testCase.invoice.ValueMsat expectedAmt := testCase.invoice.ValueMsat
require.Equal(ht, expectedAmt, payment.ValueMsat, require.Equal(ht, expectedAmt, payment.ValueMsat,
@ -408,7 +408,7 @@ func testForwardInterceptorRestart(ht *lntest.HarnessTest) {
// The payment should now be in flight. // The payment should now be in flight.
var preimage lntypes.Preimage var preimage lntypes.Preimage
copy(preimage[:], invoice.RPreimage) copy(preimage[:], invoice.RPreimage)
ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_IN_FLIGHT) ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_IN_FLIGHT)
// We don't resume the payment on Carol, so it should be held there. // We don't resume the payment on Carol, so it should be held there.
// We now restart first Bob, then Alice, so we can make sure we've // We now restart first Bob, then Alice, so we can make sure we've
@ -456,7 +456,7 @@ func testForwardInterceptorRestart(ht *lntest.HarnessTest) {
// Assert that the payment was successful. // Assert that the payment was successful.
ht.AssertPaymentStatus( ht.AssertPaymentStatus(
alice, preimage, lnrpc.Payment_SUCCEEDED, alice, preimage.Hash(), lnrpc.Payment_SUCCEEDED,
func(p *lnrpc.Payment) error { func(p *lnrpc.Payment) error {
recordsEqual := reflect.DeepEqual( recordsEqual := reflect.DeepEqual(
lntest.CustomRecordsWithUnendorsed( lntest.CustomRecordsWithUnendorsed(

View file

@ -185,9 +185,7 @@ func testHoldInvoicePersistence(ht *lntest.HarnessTest) {
payStream := alice.RPC.TrackPaymentV2(hash[:]) payStream := alice.RPC.TrackPaymentV2(hash[:])
ht.ReceiveTrackPayment(payStream) ht.ReceiveTrackPayment(payStream)
ht.AssertPaymentStatus( ht.AssertPaymentStatus(alice, hash, lnrpc.Payment_IN_FLIGHT)
alice, preimg, lnrpc.Payment_IN_FLIGHT,
)
} }
// Settle invoices half the invoices, cancel the rest. // Settle invoices half the invoices, cancel the rest.
@ -211,11 +209,11 @@ func testHoldInvoicePersistence(ht *lntest.HarnessTest) {
for i, preimg := range preimages { for i, preimg := range preimages {
if i%2 == 0 { if i%2 == 0 {
ht.AssertPaymentStatus( ht.AssertPaymentStatus(
alice, preimg, lnrpc.Payment_SUCCEEDED, alice, preimg.Hash(), lnrpc.Payment_SUCCEEDED,
) )
} else { } else {
payment := ht.AssertPaymentStatus( payment := ht.AssertPaymentStatus(
alice, preimg, lnrpc.Payment_FAILED, alice, preimg.Hash(), lnrpc.Payment_FAILED,
) )
require.Equal(ht, reason, payment.FailureReason, require.Equal(ht, reason, payment.FailureReason,
"wrong failure reason") "wrong failure reason")

View file

@ -197,7 +197,7 @@ func testHtlcTimeoutResolverExtractPreimageRemote(ht *lntest.HarnessTest) {
// Finally, check that the Alice's payment is marked as succeeded as // Finally, check that the Alice's payment is marked as succeeded as
// Bob has settled the htlc using the preimage extracted from Carol's // Bob has settled the htlc using the preimage extracted from Carol's
// 2nd level success tx. // 2nd level success tx.
ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_SUCCEEDED) ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_SUCCEEDED)
// Mine a block to clean the mempool. // Mine a block to clean the mempool.
ht.MineBlocksAndAssertNumTxes(1, 2) ht.MineBlocksAndAssertNumTxes(1, 2)
@ -371,7 +371,7 @@ func testHtlcTimeoutResolverExtractPreimageLocal(ht *lntest.HarnessTest) {
// Finally, check that the Alice's payment is marked as succeeded as // Finally, check that the Alice's payment is marked as succeeded as
// Bob has settled the htlc using the preimage extracted from Carol's // Bob has settled the htlc using the preimage extracted from Carol's
// direct spend tx. // direct spend tx.
ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_SUCCEEDED) ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_SUCCEEDED)
// NOTE: for non-standby nodes there's no need to clean up the force // NOTE: for non-standby nodes there's no need to clean up the force
// close as long as the mempool is cleaned. // close as long as the mempool is cleaned.

View file

@ -200,7 +200,7 @@ func testSendToRouteMultiPath(ht *lntest.HarnessTest) {
copy(preimage[:], invoices[0].RPreimage) copy(preimage[:], invoices[0].RPreimage)
payment := ht.AssertPaymentStatus( payment := ht.AssertPaymentStatus(
hn, preimage, lnrpc.Payment_SUCCEEDED, hn, preimage.Hash(), lnrpc.Payment_SUCCEEDED,
) )
htlcs := payment.Htlcs htlcs := payment.Htlcs

View file

@ -894,7 +894,7 @@ func runMultiHopReceiverPreimageClaim(ht *lntest.HarnessTest,
ht.AssertNumActiveHtlcs(alice, 0) ht.AssertNumActiveHtlcs(alice, 0)
// Check that the Alice's payment is correctly marked succeeded. // Check that the Alice's payment is correctly marked succeeded.
ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_SUCCEEDED) ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_SUCCEEDED)
// Carol's pending channel report should now show two outputs under // Carol's pending channel report should now show two outputs under
// limbo: her commitment output, as well as the second-layer claim // limbo: her commitment output, as well as the second-layer claim
@ -1918,7 +1918,7 @@ func runLocalClaimIncomingHTLC(ht *lntest.HarnessTest,
// Finally, check that the Alice's payment is correctly marked // Finally, check that the Alice's payment is correctly marked
// succeeded. // succeeded.
ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_SUCCEEDED) ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_SUCCEEDED)
} }
// testLocalClaimIncomingHTLCLeasedZeroConf tests // testLocalClaimIncomingHTLCLeasedZeroConf tests
@ -2221,7 +2221,7 @@ func runLocalClaimIncomingHTLCLeased(ht *lntest.HarnessTest,
// Finally, check that the Alice's payment is correctly marked // Finally, check that the Alice's payment is correctly marked
// succeeded. // succeeded.
ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_SUCCEEDED) ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_SUCCEEDED)
} }
// testLocalPreimageClaimAnchorZeroConf tests `runLocalPreimageClaim` with // testLocalPreimageClaimAnchorZeroConf tests `runLocalPreimageClaim` with
@ -2575,7 +2575,7 @@ func runLocalPreimageClaim(ht *lntest.HarnessTest,
// Finally, check that the Alice's payment is correctly marked // Finally, check that the Alice's payment is correctly marked
// succeeded. // succeeded.
ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_SUCCEEDED) ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_SUCCEEDED)
} }
// testLocalPreimageClaimLeasedZeroConf tests `runLocalPreimageClaim` with // testLocalPreimageClaimLeasedZeroConf tests `runLocalPreimageClaim` with
@ -2839,7 +2839,7 @@ func runLocalPreimageClaimLeased(ht *lntest.HarnessTest,
ht.AssertInvoiceState(stream, lnrpc.Invoice_SETTLED) ht.AssertInvoiceState(stream, lnrpc.Invoice_SETTLED)
// Check that the Alice's payment is correctly marked succeeded. // Check that the Alice's payment is correctly marked succeeded.
ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_SUCCEEDED) ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_SUCCEEDED)
// With the script-enforced lease commitment type, Alice and Bob still // With the script-enforced lease commitment type, Alice and Bob still
// haven't been able to sweep their respective commit outputs due to // haven't been able to sweep their respective commit outputs due to

View file

@ -98,8 +98,10 @@ func testPaymentSucceededHTLCRemoteSwept(ht *lntest.HarnessTest) {
// We also check the payments are marked as IN_FLIGHT in Alice's // We also check the payments are marked as IN_FLIGHT in Alice's
// database. // database.
ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_IN_FLIGHT) ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_IN_FLIGHT)
ht.AssertPaymentStatus(alice, dustPreimage, lnrpc.Payment_IN_FLIGHT) ht.AssertPaymentStatus(
alice, dustPreimage.Hash(), lnrpc.Payment_IN_FLIGHT,
)
// Bob should have two incoming HTLC. // Bob should have two incoming HTLC.
ht.AssertIncomingHTLCActive(bob, chanPoint, payHash[:]) ht.AssertIncomingHTLCActive(bob, chanPoint, payHash[:])
@ -166,12 +168,12 @@ func testPaymentSucceededHTLCRemoteSwept(ht *lntest.HarnessTest) {
dustPayStream := alice.RPC.TrackPaymentV2(dustPayHash[:]) dustPayStream := alice.RPC.TrackPaymentV2(dustPayHash[:])
// Check that the dust payment is failed in both the stream and DB. // Check that the dust payment is failed in both the stream and DB.
ht.AssertPaymentStatus(alice, dustPreimage, lnrpc.Payment_FAILED) ht.AssertPaymentStatus(alice, dustPreimage.Hash(), lnrpc.Payment_FAILED)
ht.AssertPaymentStatusFromStream(dustPayStream, lnrpc.Payment_FAILED) ht.AssertPaymentStatusFromStream(dustPayStream, lnrpc.Payment_FAILED)
// We expect the non-dust payment to marked as succeeded in Alice's // We expect the non-dust payment to marked as succeeded in Alice's
// database and also from her stream. // database and also from her stream.
ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_SUCCEEDED) ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_SUCCEEDED)
ht.AssertPaymentStatusFromStream(payStream, lnrpc.Payment_SUCCEEDED) ht.AssertPaymentStatusFromStream(payStream, lnrpc.Payment_SUCCEEDED)
} }
@ -263,8 +265,10 @@ func runTestPaymentHTLCTimeout(ht *lntest.HarnessTest, restartAlice bool) {
// We also check the payments are marked as IN_FLIGHT in Alice's // We also check the payments are marked as IN_FLIGHT in Alice's
// database. // database.
ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_IN_FLIGHT) ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_IN_FLIGHT)
ht.AssertPaymentStatus(alice, dustPreimage, lnrpc.Payment_IN_FLIGHT) ht.AssertPaymentStatus(
alice, dustPreimage.Hash(), lnrpc.Payment_IN_FLIGHT,
)
// Bob should have two incoming HTLC. // Bob should have two incoming HTLC.
ht.AssertIncomingHTLCActive(bob, chanPoint, payHash[:]) ht.AssertIncomingHTLCActive(bob, chanPoint, payHash[:])
@ -310,14 +314,14 @@ func runTestPaymentHTLCTimeout(ht *lntest.HarnessTest, restartAlice bool) {
// mark the non-dust payment as succeeded. // mark the non-dust payment as succeeded.
// //
// Check that the dust payment is failed in both the stream and DB. // Check that the dust payment is failed in both the stream and DB.
ht.AssertPaymentStatus(alice, dustPreimage, lnrpc.Payment_FAILED) ht.AssertPaymentStatus(alice, dustPreimage.Hash(), lnrpc.Payment_FAILED)
ht.AssertPaymentStatusFromStream(dustPayStream, lnrpc.Payment_FAILED) ht.AssertPaymentStatusFromStream(dustPayStream, lnrpc.Payment_FAILED)
// Check that the non-dust payment is still in-flight. // Check that the non-dust payment is still in-flight.
// //
// NOTE: we don't check the payment status from the stream here as // NOTE: we don't check the payment status from the stream here as
// there's no new status being sent. // there's no new status being sent.
ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_IN_FLIGHT) ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_IN_FLIGHT)
// We now have two possible cases for the non-dust payment: // We now have two possible cases for the non-dust payment:
// - Bob stays offline, and Alice will sweep her outgoing HTLC, which // - Bob stays offline, and Alice will sweep her outgoing HTLC, which
@ -335,7 +339,7 @@ func runTestPaymentHTLCTimeout(ht *lntest.HarnessTest, restartAlice bool) {
// We expect the non-dust payment to marked as failed in Alice's // We expect the non-dust payment to marked as failed in Alice's
// database and also from her stream. // database and also from her stream.
ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_FAILED) ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_FAILED)
ht.AssertPaymentStatusFromStream(payStream, lnrpc.Payment_FAILED) ht.AssertPaymentStatusFromStream(payStream, lnrpc.Payment_FAILED)
} }
@ -1114,7 +1118,7 @@ func sendPaymentInterceptAndCancel(ht *lntest.HarnessTest,
var preimage lntypes.Preimage var preimage lntypes.Preimage
copy(preimage[:], invoice.RPreimage) copy(preimage[:], invoice.RPreimage)
payment := ht.AssertPaymentStatus( payment := ht.AssertPaymentStatus(
alice, preimage, lnrpc.Payment_IN_FLIGHT, alice, preimage.Hash(), lnrpc.Payment_IN_FLIGHT,
) )
reasonNone := lnrpc.PaymentFailureReason_FAILURE_REASON_NONE reasonNone := lnrpc.PaymentFailureReason_FAILURE_REASON_NONE
require.Equal(ht, reasonNone, payment.FailureReason) require.Equal(ht, reasonNone, payment.FailureReason)
@ -1127,7 +1131,7 @@ func sendPaymentInterceptAndCancel(ht *lntest.HarnessTest,
require.NoError(ht, err, "failed to send request") require.NoError(ht, err, "failed to send request")
// Assert that the payment status is as expected. // Assert that the payment status is as expected.
ht.AssertPaymentStatus(alice, preimage, expectedPaymentStatus) ht.AssertPaymentStatus(alice, preimage.Hash(), expectedPaymentStatus)
// Since the payment context was cancelled, no further payment attempts // Since the payment context was cancelled, no further payment attempts
// should've been made, and we observe FAILURE_REASON_CANCELED. // should've been made, and we observe FAILURE_REASON_CANCELED.
@ -1245,7 +1249,7 @@ func runSendToRouteFailHTLCTimeout(ht *lntest.HarnessTest, restartAlice bool) {
}() }()
// Check that the payment is in-flight. // Check that the payment is in-flight.
ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_IN_FLIGHT) ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_IN_FLIGHT)
// Construct a route to send the dust payment. // Construct a route to send the dust payment.
go func() { go func() {
@ -1281,7 +1285,9 @@ func runSendToRouteFailHTLCTimeout(ht *lntest.HarnessTest, restartAlice bool) {
}() }()
// Check that the dust payment is in-flight. // Check that the dust payment is in-flight.
ht.AssertPaymentStatus(alice, dustPreimage, lnrpc.Payment_IN_FLIGHT) ht.AssertPaymentStatus(
alice, dustPreimage.Hash(), lnrpc.Payment_IN_FLIGHT,
)
// Bob should have two incoming HTLC. // Bob should have two incoming HTLC.
ht.AssertIncomingHTLCActive(bob, chanPoint, payHash[:]) ht.AssertIncomingHTLCActive(bob, chanPoint, payHash[:])
@ -1323,14 +1329,14 @@ func runSendToRouteFailHTLCTimeout(ht *lntest.HarnessTest, restartAlice bool) {
// HTLC is resolved onchain. // HTLC is resolved onchain.
// //
// Check that the dust payment is failed in both the stream and DB. // Check that the dust payment is failed in both the stream and DB.
ht.AssertPaymentStatus(alice, dustPreimage, lnrpc.Payment_FAILED) ht.AssertPaymentStatus(alice, dustPreimage.Hash(), lnrpc.Payment_FAILED)
ht.AssertPaymentStatusFromStream(dustPayStream, lnrpc.Payment_FAILED) ht.AssertPaymentStatusFromStream(dustPayStream, lnrpc.Payment_FAILED)
// Check that the non-dust payment is still in-flight. // Check that the non-dust payment is still in-flight.
// //
// NOTE: we don't check the payment status from the stream here as // NOTE: we don't check the payment status from the stream here as
// there's no new status being sent. // there's no new status being sent.
ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_IN_FLIGHT) ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_IN_FLIGHT)
// We now have two possible cases for the non-dust payment: // We now have two possible cases for the non-dust payment:
// - Bob stays offline, and Alice will sweep her outgoing HTLC, which // - Bob stays offline, and Alice will sweep her outgoing HTLC, which
@ -1348,6 +1354,6 @@ func runSendToRouteFailHTLCTimeout(ht *lntest.HarnessTest, restartAlice bool) {
// We expect the non-dust payment to marked as failed in Alice's // We expect the non-dust payment to marked as failed in Alice's
// database and also from her stream. // database and also from her stream.
ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_FAILED) ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_FAILED)
ht.AssertPaymentStatusFromStream(payStream, lnrpc.Payment_FAILED) ht.AssertPaymentStatusFromStream(payStream, lnrpc.Payment_FAILED)
} }

View file

@ -509,7 +509,7 @@ func (b *blindedForwardTest) sendToRoute(route *lnrpc.Route,
require.NoError(b.ht, err) require.NoError(b.ht, err)
pmt := b.ht.AssertPaymentStatus( pmt := b.ht.AssertPaymentStatus(
b.alice, preimage, lnrpc.Payment_FAILED, b.alice, preimage.Hash(), lnrpc.Payment_FAILED,
) )
require.Len(b.ht, pmt.Htlcs, 1) require.Len(b.ht, pmt.Htlcs, 1)

View file

@ -1550,16 +1550,15 @@ func (h *HarnessTest) findPayment(hn *node.HarnessNode,
// PaymentCheck is a function that checks a payment for a specific condition. // PaymentCheck is a function that checks a payment for a specific condition.
type PaymentCheck func(*lnrpc.Payment) error type PaymentCheck func(*lnrpc.Payment) error
// AssertPaymentStatus asserts that the given node list a payment with the // AssertPaymentStatus asserts that the given node list a payment with the given
// given preimage has the expected status. It also checks that the payment has // payment hash has the expected status. It also checks that the payment has the
// the expected preimage, which is empty when it's not settled and matches the // expected preimage, which is empty when it's not settled and matches the given
// given preimage when it's succeeded. // preimage when it's succeeded.
func (h *HarnessTest) AssertPaymentStatus(hn *node.HarnessNode, func (h *HarnessTest) AssertPaymentStatus(hn *node.HarnessNode,
preimage lntypes.Preimage, status lnrpc.Payment_PaymentStatus, payHash lntypes.Hash, status lnrpc.Payment_PaymentStatus,
checks ...PaymentCheck) *lnrpc.Payment { checks ...PaymentCheck) *lnrpc.Payment {
var target *lnrpc.Payment var target *lnrpc.Payment
payHash := preimage.Hash()
err := wait.NoError(func() error { err := wait.NoError(func() error {
p, err := h.findPayment(hn, payHash.String()) p, err := h.findPayment(hn, payHash.String())
@ -1581,8 +1580,11 @@ func (h *HarnessTest) AssertPaymentStatus(hn *node.HarnessNode,
// If this expected status is SUCCEEDED, we expect the final // If this expected status is SUCCEEDED, we expect the final
// preimage. // preimage.
case lnrpc.Payment_SUCCEEDED: case lnrpc.Payment_SUCCEEDED:
require.Equal(h, preimage.String(), target.PaymentPreimage, preimage, err := lntypes.MakePreimageFromStr(
"preimage not match") target.PaymentPreimage,
)
require.NoError(h, err, "fail to make preimage")
require.Equal(h, payHash, preimage.Hash(), "preimage not match")
// Otherwise we expect an all-zero preimage. // Otherwise we expect an all-zero preimage.
default: default: