itest: breakdown testSendDirectPayment
Also fixes a wrong usage of `ht.Subtest`.
This commit is contained in:
2 files changed
+40
-73
No files matched your search
@@ -168,8 +168,12 @@ var allTestCases = []*lntest.TestCase{
|
|||||||
TestFunc: testListPayments,
|
TestFunc: testListPayments,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "send direct payment",
|
Name: "send direct payment anchor",
|
||||||
TestFunc: testSendDirectPayment,
|
TestFunc: testSendDirectPaymentAnchor,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "send direct payment simple taproot",
|
||||||
|
TestFunc: testSendDirectPaymentSimpleTaproot,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "immediate payment after channel opened",
|
Name: "immediate payment after channel opened",
|
||||||
|
|||||||
+34
-71
@@ -339,28 +339,18 @@ func runTestPaymentHTLCTimeout(ht *lntest.HarnessTest, restartAlice bool) {
|
|||||||
ht.AssertPaymentStatusFromStream(payStream, lnrpc.Payment_FAILED)
|
ht.AssertPaymentStatusFromStream(payStream, lnrpc.Payment_FAILED)
|
||||||
}
|
}
|
||||||
|
|
||||||
// testSendDirectPayment creates a topology Alice->Bob and then tests that
|
// runSendDirectPayment opens a channel between Alice and Bob using the
|
||||||
// Alice can send a direct payment to Bob. This test modifies the fee estimator
|
// specified params. It then sends a payment from Alice to Bob and asserts it
|
||||||
// to return floor fee rate(1 sat/vb).
|
// being successful.
|
||||||
func testSendDirectPayment(ht *lntest.HarnessTest) {
|
func runSendDirectPayment(ht *lntest.HarnessTest, cfgs [][]string,
|
||||||
// Grab Alice and Bob's nodes for convenience.
|
|
||||||
alice := ht.NewNodeWithCoins("Alice", nil)
|
|
||||||
bob := ht.NewNodeWithCoins("Bob", nil)
|
|
||||||
|
|
||||||
// Create a list of commitment types we want to test.
|
|
||||||
commitmentTypes := []lnrpc.CommitmentType{
|
|
||||||
lnrpc.CommitmentType_ANCHORS,
|
|
||||||
lnrpc.CommitmentType_SIMPLE_TAPROOT,
|
|
||||||
}
|
|
||||||
|
|
||||||
// testSendPayment opens a channel between Alice and Bob using the
|
|
||||||
// specified params. It then sends a payment from Alice to Bob and
|
|
||||||
// asserts it being successful.
|
|
||||||
testSendPayment := func(ht *lntest.HarnessTest,
|
|
||||||
params lntest.OpenChannelParams) {
|
params lntest.OpenChannelParams) {
|
||||||
|
|
||||||
// Check that there are no payments before test.
|
// Set the fee estimate to 1sat/vbyte.
|
||||||
chanPoint := ht.OpenChannel(alice, bob, params)
|
ht.SetFeeEstimate(250)
|
||||||
|
|
||||||
|
// Create a two-hop network: Alice -> Bob.
|
||||||
|
_, nodes := ht.CreateSimpleNetwork(cfgs, params)
|
||||||
|
alice, bob := nodes[0], nodes[1]
|
||||||
|
|
||||||
// Now that the channel is open, create an invoice for Bob
|
// Now that the channel is open, create an invoice for Bob
|
||||||
// which expects a payment of 1000 satoshis from Alice paid via
|
// which expects a payment of 1000 satoshis from Alice paid via
|
||||||
@@ -407,67 +397,40 @@ func testSendDirectPayment(ht *lntest.HarnessTest) {
|
|||||||
// matches the invoice that we paid.
|
// matches the invoice that we paid.
|
||||||
require.Equal(ht, invoiceResp.PaymentRequest, p.PaymentRequest,
|
require.Equal(ht, invoiceResp.PaymentRequest, p.PaymentRequest,
|
||||||
"incorrect payreq")
|
"incorrect payreq")
|
||||||
|
}
|
||||||
|
|
||||||
// Delete all payments from Alice. DB should have no payments.
|
// testSendDirectPaymentAnchor creates a topology Alice->Bob using anchor
|
||||||
alice.RPC.DeleteAllPayments()
|
// channel and then tests that Alice can send a direct payment to Bob.
|
||||||
ht.AssertNumPayments(alice, 0)
|
func testSendDirectPaymentAnchor(ht *lntest.HarnessTest) {
|
||||||
|
// Create a two-hop network: Alice -> Bob using anchor channel.
|
||||||
// TODO(yy): remove the sleep once the following bug is fixed.
|
|
||||||
// When the invoice is reported settled, the commitment dance
|
|
||||||
// is not yet finished, which can cause an error when closing
|
|
||||||
// the channel, saying there's active HTLCs. We need to
|
|
||||||
// investigate this issue and reverse the order to, first
|
|
||||||
// finish the commitment dance, then report the invoice as
|
|
||||||
// settled.
|
|
||||||
time.Sleep(2 * time.Second)
|
|
||||||
|
|
||||||
// Close the channel.
|
|
||||||
//
|
//
|
||||||
// NOTE: This implicitly tests that the channel link is active
|
// Prepare params.
|
||||||
// before closing this channel. The above payment will trigger
|
params := lntest.OpenChannelParams{Amt: chanAmt}
|
||||||
// a commitment dance in both of the nodes. If the node fails
|
cfg := node.CfgAnchor
|
||||||
// to update the commitment state, we will fail to close the
|
cfgs := [][]string{cfg, cfg}
|
||||||
// channel as the link won't be active.
|
|
||||||
ht.CloseChannel(alice, chanPoint)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Run the test cases.
|
runSendDirectPayment(ht, cfgs, params)
|
||||||
for _, ct := range commitmentTypes {
|
}
|
||||||
ht.Run(ct.String(), func(t *testing.T) {
|
|
||||||
st := ht.Subtest(t)
|
|
||||||
|
|
||||||
// Set the fee estimate to 1sat/vbyte.
|
// testSendDirectPaymentSimpleTaproot creates a topology Alice->Bob using
|
||||||
st.SetFeeEstimate(250)
|
// simple taproot channel and then tests that Alice can send a direct payment
|
||||||
|
// to Bob.
|
||||||
|
func testSendDirectPaymentSimpleTaproot(ht *lntest.HarnessTest) {
|
||||||
|
c := lnrpc.CommitmentType_SIMPLE_TAPROOT
|
||||||
|
|
||||||
// Restart the nodes with the specified commitment type.
|
// Create a two-hop network: Alice -> Bob using simple taproot channel.
|
||||||
args := lntest.NodeArgsForCommitType(ct)
|
|
||||||
st.RestartNodeWithExtraArgs(alice, args)
|
|
||||||
st.RestartNodeWithExtraArgs(bob, args)
|
|
||||||
|
|
||||||
// Make sure they are connected.
|
|
||||||
st.EnsureConnected(alice, bob)
|
|
||||||
|
|
||||||
// There's a bug that causes the funding to be failed
|
|
||||||
// due to the `ListCoins` cannot find the utxos.
|
|
||||||
//
|
//
|
||||||
// TODO(yy): remove this line to fix the ListCoins bug.
|
// Prepare params.
|
||||||
st.FundCoins(btcutil.SatoshiPerBitcoin, alice)
|
|
||||||
|
|
||||||
// Open a channel with 100k satoshis between Alice and
|
|
||||||
// Bob with Alice being the sole funder of the channel.
|
|
||||||
params := lntest.OpenChannelParams{
|
params := lntest.OpenChannelParams{
|
||||||
Amt: 100_000,
|
Amt: chanAmt,
|
||||||
CommitmentType: ct,
|
CommitmentType: c,
|
||||||
|
Private: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open private channel for taproot channels.
|
cfg := node.CfgSimpleTaproot
|
||||||
if ct == lnrpc.CommitmentType_SIMPLE_TAPROOT {
|
cfgs := [][]string{cfg, cfg}
|
||||||
params.Private = true
|
|
||||||
}
|
|
||||||
|
|
||||||
testSendPayment(st, params)
|
runSendDirectPayment(ht, cfgs, params)
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func testListPayments(ht *lntest.HarnessTest) {
|
func testListPayments(ht *lntest.HarnessTest) {
|
||||||
|
|||||||
Reference in new issue
Block a user