Merge pull request #3194 from halseth/listpayments-test-on-chain-settle
[integration tests]: restart Alice after on-chain settle
This commit is contained in:
commit
bed485f0a9
@ -195,6 +195,13 @@ func testMultiHopHtlcLocalChainClaim(net *lntest.NetworkHarness, t *harnessTest)
|
||||
}
|
||||
}
|
||||
|
||||
// At this point we suspend Alice to make sure she'll handle the
|
||||
// on-chain settle after a restart.
|
||||
restartAlice, err := net.SuspendNode(net.Alice)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to suspend alice: %v", err)
|
||||
}
|
||||
|
||||
// Mine a block to confirm the two transactions (+ the coinbase).
|
||||
block = mineBlocks(t, net, 1, 2)[0]
|
||||
if len(block.Transactions) != 3 {
|
||||
@ -285,6 +292,12 @@ func testMultiHopHtlcLocalChainClaim(net *lntest.NetworkHarness, t *harnessTest)
|
||||
bobSecondLevelCSV := uint32(defaultCSV)
|
||||
carolSecondLevelCSV--
|
||||
|
||||
// Now that the preimage from Bob has hit the chain, restart Alice to
|
||||
// ensure she'll pick it up.
|
||||
if err := restartAlice(); err != nil {
|
||||
t.Fatalf("unable to restart alice: %v", err)
|
||||
}
|
||||
|
||||
// If we then mine 3 additional blocks, Carol's second level tx should
|
||||
// mature, and she can pull the funds from it with a sweep tx.
|
||||
if _, err := net.Miner.Node.Generate(carolSecondLevelCSV); err != nil {
|
||||
@ -393,6 +406,16 @@ func testMultiHopHtlcLocalChainClaim(net *lntest.NetworkHarness, t *harnessTest)
|
||||
if err != nil {
|
||||
t.Fatalf(predErr.Error())
|
||||
}
|
||||
|
||||
// Finally, check that the Alice's payment is correctly marked
|
||||
// succeeded.
|
||||
ctxt, _ = context.WithTimeout(ctxt, defaultTimeout)
|
||||
err = checkPaymentStatus(
|
||||
ctxt, net.Alice, preimage, lnrpc.Payment_SUCCEEDED,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
// waitForInvoiceAccepted waits until the specified invoice moved to the
|
||||
@ -421,3 +444,57 @@ func waitForInvoiceAccepted(t *harnessTest, node *lntest.HarnessNode,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// checkPaymentStatus asserts that the given node list a payment with the given
|
||||
// preimage has the expected status.
|
||||
func checkPaymentStatus(ctxt context.Context, node *lntest.HarnessNode,
|
||||
preimage lntypes.Preimage, status lnrpc.Payment_PaymentStatus) error {
|
||||
|
||||
req := &lnrpc.ListPaymentsRequest{
|
||||
IncludeIncomplete: true,
|
||||
}
|
||||
paymentsResp, err := node.ListPayments(ctxt, req)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error when obtaining Alice payments: %v",
|
||||
err)
|
||||
}
|
||||
|
||||
payHash := preimage.Hash()
|
||||
var found bool
|
||||
for _, p := range paymentsResp.Payments {
|
||||
if p.PaymentHash != payHash.String() {
|
||||
continue
|
||||
}
|
||||
|
||||
found = true
|
||||
if p.Status != status {
|
||||
return fmt.Errorf("expected payment status "+
|
||||
"%v, got %v", status, p.Status)
|
||||
}
|
||||
|
||||
switch status {
|
||||
|
||||
// If this expected status is SUCCEEDED, we expect the final preimage.
|
||||
case lnrpc.Payment_SUCCEEDED:
|
||||
if p.PaymentPreimage != preimage.String() {
|
||||
return fmt.Errorf("preimage doesn't match: %v vs %v",
|
||||
p.PaymentPreimage, preimage.String())
|
||||
}
|
||||
|
||||
// Otherwise we expect an all-zero preimage.
|
||||
default:
|
||||
if p.PaymentPreimage != (lntypes.Preimage{}).String() {
|
||||
return fmt.Errorf("expected zero preimage, got %v",
|
||||
p.PaymentPreimage)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if !found {
|
||||
return fmt.Errorf("payment with payment hash %v not found "+
|
||||
"in response", payHash)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -298,6 +298,16 @@ func testMultiHopReceiverChainClaim(net *lntest.NetworkHarness, t *harnessTest)
|
||||
"%d sat", invoiceAmt, invoice.AmtPaidSat)
|
||||
}
|
||||
|
||||
// Finally, check that the Alice's payment is correctly marked
|
||||
// succeeded.
|
||||
ctxt, _ = context.WithTimeout(ctxt, defaultTimeout)
|
||||
err = checkPaymentStatus(
|
||||
ctxt, net.Alice, preimage, lnrpc.Payment_SUCCEEDED,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf(err.Error())
|
||||
}
|
||||
|
||||
// We'll close out the channel between Alice and Bob, then shutdown
|
||||
// carol to conclude the test.
|
||||
ctxt, _ = context.WithTimeout(ctxb, channelCloseTimeout)
|
||||
|
@ -332,4 +332,14 @@ func testMultiHopHtlcRemoteChainClaim(net *lntest.NetworkHarness, t *harnessTest
|
||||
t.Fatalf("expected invoice to be settled with %d sat, got "+
|
||||
"%d sat", invoiceAmt, invoice.AmtPaidSat)
|
||||
}
|
||||
|
||||
// Finally, check that the Alice's payment is correctly marked
|
||||
// succeeded.
|
||||
ctxt, _ = context.WithTimeout(ctxt, defaultTimeout)
|
||||
err = checkPaymentStatus(
|
||||
ctxt, net.Alice, preimage, lnrpc.Payment_SUCCEEDED,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf(err.Error())
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user