itest: refactor testPaymentFollowingChannelOpen
This commit is contained in:
3 files changed
+28
-51
No files matched your search
@@ -183,4 +183,8 @@ var allTestCasesTemp = []*lntemp.TestCase{
|
|||||||
Name: "list outgoing payments",
|
Name: "list outgoing payments",
|
||||||
TestFunc: testListPayments,
|
TestFunc: testListPayments,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "immediate payment after channel opened",
|
||||||
|
TestFunc: testPaymentFollowingChannelOpen,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
@@ -100,81 +100,58 @@ func testListPayments(ht *lntemp.HarnessTest) {
|
|||||||
// subsystems trying to update the channel state in the db. We follow this
|
// subsystems trying to update the channel state in the db. We follow this
|
||||||
// transition with a payment that updates the commitment state and verify that
|
// transition with a payment that updates the commitment state and verify that
|
||||||
// the pending state is up to date.
|
// the pending state is up to date.
|
||||||
func testPaymentFollowingChannelOpen(net *lntest.NetworkHarness, t *harnessTest) {
|
func testPaymentFollowingChannelOpen(ht *lntemp.HarnessTest) {
|
||||||
ctxb := context.Background()
|
|
||||||
|
|
||||||
const paymentAmt = btcutil.Amount(100)
|
const paymentAmt = btcutil.Amount(100)
|
||||||
channelCapacity := paymentAmt * 1000
|
channelCapacity := paymentAmt * 1000
|
||||||
|
|
||||||
// We first establish a channel between Alice and Bob.
|
// We first establish a channel between Alice and Bob.
|
||||||
pendingUpdate, err := net.OpenPendingChannel(
|
alice, bob := ht.Alice, ht.Bob
|
||||||
net.Alice, net.Bob, channelCapacity, 0,
|
p := lntemp.OpenChannelParams{
|
||||||
)
|
Amt: channelCapacity,
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("unable to open channel: %v", err)
|
|
||||||
}
|
}
|
||||||
|
pendingUpdate := ht.OpenChannelAssertPending(alice, bob, p)
|
||||||
|
|
||||||
// At this point, the channel's funding transaction will have been
|
// At this point, the channel's funding transaction will have been
|
||||||
// broadcast, but not confirmed. Alice and Bob's nodes
|
// broadcast, but not confirmed. Alice and Bob's nodes
|
||||||
// should reflect this when queried via RPC.
|
// should reflect this when queried via RPC.
|
||||||
assertNumOpenChannelsPending(t, net.Alice, net.Bob, 1)
|
ht.AssertNodesNumPendingOpenChannels(alice, bob, 1)
|
||||||
|
|
||||||
// We are restarting Bob's node to let the link be created for the
|
// We are restarting Bob's node to let the link be created for the
|
||||||
// pending channel.
|
// pending channel.
|
||||||
if err := net.RestartNode(net.Bob, nil); err != nil {
|
ht.RestartNode(bob)
|
||||||
t.Fatalf("Bob restart failed: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// We ensure that Bob reconnects to Alice.
|
// We ensure that Bob reconnects to Alice.
|
||||||
net.EnsureConnected(t.t, net.Bob, net.Alice)
|
ht.EnsureConnected(bob, alice)
|
||||||
|
|
||||||
// We mine one block for the channel to be confirmed.
|
// We mine six blocks for the channel to be confirmed.
|
||||||
_ = mineBlocks(t, net, 6, 1)[0]
|
ht.MineBlocksAndAssertNumTxes(6, 1)
|
||||||
|
|
||||||
// We verify that the channel is open from both nodes point of view.
|
// We verify that the channel is open from both nodes point of view.
|
||||||
assertNumOpenChannelsPending(t, net.Alice, net.Bob, 0)
|
chanPoint := lntemp.ChanPointFromPendingUpdate(pendingUpdate)
|
||||||
|
ht.AssertNodesNumPendingOpenChannels(alice, bob, 0)
|
||||||
|
ht.AssertChannelExists(alice, chanPoint)
|
||||||
|
ht.AssertChannelExists(bob, chanPoint)
|
||||||
|
|
||||||
// With the channel open, we'll create invoices for Bob that Alice will
|
// With the channel open, we'll create invoices for Bob that Alice will
|
||||||
// pay to in order to advance the state of the channel.
|
// pay to in order to advance the state of the channel.
|
||||||
bobPayReqs, _, _, err := createPayReqs(
|
bobPayReqs, _, _ := ht.CreatePayReqs(bob, paymentAmt, 1)
|
||||||
net.Bob, paymentAmt, 1,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("unable to create pay reqs: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send payment to Bob so that a channel update to disk will be
|
// Send payment to Bob so that a channel update to disk will be
|
||||||
// executed.
|
// executed.
|
||||||
sendAndAssertSuccess(
|
ht.CompletePaymentRequests(alice, []string{bobPayReqs[0]})
|
||||||
t, net.Alice, &routerrpc.SendPaymentRequest{
|
|
||||||
PaymentRequest: bobPayReqs[0],
|
|
||||||
TimeoutSeconds: 60,
|
|
||||||
FeeLimitSat: 1000000,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
// At this point we want to make sure the channel is opened and not
|
// TODO(yy): remove the sleep once the following bug is fixed.
|
||||||
// pending.
|
// When the invoice is reported settled, the commitment dance is not
|
||||||
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
|
// yet finished, which can cause an error when closing the channel,
|
||||||
defer cancel()
|
// saying there's active HTLCs. We need to investigate this issue and
|
||||||
res, err := net.Bob.ListChannels(ctxt, &lnrpc.ListChannelsRequest{})
|
// reverse the order to, first finish the commitment dance, then report
|
||||||
if err != nil {
|
// the invoice as settled.
|
||||||
t.Fatalf("unable to list bob channels: %v", err)
|
time.Sleep(2 * time.Second)
|
||||||
}
|
|
||||||
if len(res.Channels) == 0 {
|
|
||||||
t.Fatalf("bob list of channels is empty")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Finally, immediately close the channel. This function will also
|
// Finally, immediately close the channel. This function will also
|
||||||
// block until the channel is closed and will additionally assert the
|
// block until the channel is closed and will additionally assert the
|
||||||
// relevant channel closing post conditions.
|
// relevant channel closing post conditions.
|
||||||
chanPoint := &lnrpc.ChannelPoint{
|
ht.CloseChannel(alice, chanPoint)
|
||||||
FundingTxid: &lnrpc.ChannelPoint_FundingTxidBytes{
|
|
||||||
FundingTxidBytes: pendingUpdate.Txid,
|
|
||||||
},
|
|
||||||
OutputIndex: pendingUpdate.OutputIndex,
|
|
||||||
}
|
|
||||||
closeChannelAndAssert(t, net, net.Alice, chanPoint, false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// testAsyncPayments tests the performance of the async payments.
|
// testAsyncPayments tests the performance of the async payments.
|
||||||
|
|||||||
@@ -170,10 +170,6 @@ var allTestCases = []*testCase{
|
|||||||
name: "delete macaroon id",
|
name: "delete macaroon id",
|
||||||
test: testDeleteMacaroonID,
|
test: testDeleteMacaroonID,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: "immediate payment after channel opened",
|
|
||||||
test: testPaymentFollowingChannelOpen,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: "psbt channel funding",
|
name: "psbt channel funding",
|
||||||
test: testPsbtChanFunding,
|
test: testPsbtChanFunding,
|
||||||
|
|||||||
Reference in new issue
Block a user