mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-28 17:53:30 +02:00
lntemp+itest: refactor testBatchChanFunding
This commit is contained in:
parent
21097feb85
commit
1d7c568fcf
@ -405,3 +405,30 @@ func (h *HarnessRPC) GetRecoveryInfo(
|
|||||||
|
|
||||||
return resp
|
return resp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BatchOpenChannel makes a RPC call to BatchOpenChannel and asserts.
|
||||||
|
func (h *HarnessRPC) BatchOpenChannel(
|
||||||
|
req *lnrpc.BatchOpenChannelRequest) *lnrpc.BatchOpenChannelResponse {
|
||||||
|
|
||||||
|
ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
resp, err := h.LN.BatchOpenChannel(ctxt, req)
|
||||||
|
require.NoErrorf(h, err, "failed to batch open channel")
|
||||||
|
|
||||||
|
return resp
|
||||||
|
}
|
||||||
|
|
||||||
|
// BatchOpenChannelAssertErr makes a RPC call to BatchOpenChannel and asserts
|
||||||
|
// there's an error returned.
|
||||||
|
func (h *HarnessRPC) BatchOpenChannelAssertErr(
|
||||||
|
req *lnrpc.BatchOpenChannelRequest) error {
|
||||||
|
|
||||||
|
ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
_, err := h.LN.BatchOpenChannel(ctxt, req)
|
||||||
|
require.Error(h, err, "expecte batch open channel fail")
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
@ -131,4 +131,8 @@ var allTestCasesTemp = []*lntemp.TestCase{
|
|||||||
Name: "funding flow persistence",
|
Name: "funding flow persistence",
|
||||||
TestFunc: testChannelFundingPersistence,
|
TestFunc: testChannelFundingPersistence,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "batch channel funding",
|
||||||
|
TestFunc: testBatchChanFunding,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package itest
|
package itest
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -16,7 +15,6 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/lnrpc/signrpc"
|
"github.com/lightningnetwork/lnd/lnrpc/signrpc"
|
||||||
"github.com/lightningnetwork/lnd/lntemp"
|
"github.com/lightningnetwork/lnd/lntemp"
|
||||||
"github.com/lightningnetwork/lnd/lntemp/node"
|
"github.com/lightningnetwork/lnd/lntemp/node"
|
||||||
"github.com/lightningnetwork/lnd/lntest"
|
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
@ -680,23 +678,20 @@ func testChannelFundingPersistence(ht *lntemp.HarnessTest) {
|
|||||||
|
|
||||||
// testBatchChanFunding makes sure multiple channels can be opened in one batch
|
// testBatchChanFunding makes sure multiple channels can be opened in one batch
|
||||||
// transaction in an atomic way.
|
// transaction in an atomic way.
|
||||||
func testBatchChanFunding(net *lntest.NetworkHarness, t *harnessTest) {
|
func testBatchChanFunding(ht *lntemp.HarnessTest) {
|
||||||
ctxb := context.Background()
|
|
||||||
|
|
||||||
// First, we'll create two new nodes that we'll use to open channels
|
// First, we'll create two new nodes that we'll use to open channels
|
||||||
// to during this test. Carol has a high minimum funding amount that
|
// to during this test. Carol has a high minimum funding amount that
|
||||||
// we'll use to trigger an error during the batch channel open.
|
// we'll use to trigger an error during the batch channel open.
|
||||||
carol := net.NewNode(t.t, "carol", []string{"--minchansize=200000"})
|
carol := ht.NewNode("carol", []string{"--minchansize=200000"})
|
||||||
defer shutdownAndAssert(net, t, carol)
|
dave := ht.NewNode("dave", nil)
|
||||||
|
|
||||||
dave := net.NewNode(t.t, "dave", nil)
|
alice, bob := ht.Alice, ht.Bob
|
||||||
defer shutdownAndAssert(net, t, dave)
|
|
||||||
|
|
||||||
// Before we start the test, we'll ensure Alice is connected to Carol
|
// Before we start the test, we'll ensure Alice is connected to Carol
|
||||||
// and Dave so she can open channels to both of them (and Bob).
|
// and Dave so she can open channels to both of them (and Bob).
|
||||||
net.EnsureConnected(t.t, net.Alice, net.Bob)
|
ht.EnsureConnected(alice, bob)
|
||||||
net.EnsureConnected(t.t, net.Alice, carol)
|
ht.EnsureConnected(alice, carol)
|
||||||
net.EnsureConnected(t.t, net.Alice, dave)
|
ht.EnsureConnected(alice, dave)
|
||||||
|
|
||||||
// Let's create our batch TX request. This first one should fail as we
|
// Let's create our batch TX request. This first one should fail as we
|
||||||
// open a channel to Carol that is too small for her min chan size.
|
// open a channel to Carol that is too small for her min chan size.
|
||||||
@ -704,7 +699,7 @@ func testBatchChanFunding(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
SatPerVbyte: 12,
|
SatPerVbyte: 12,
|
||||||
MinConfs: 1,
|
MinConfs: 1,
|
||||||
Channels: []*lnrpc.BatchOpenChannel{{
|
Channels: []*lnrpc.BatchOpenChannel{{
|
||||||
NodePubkey: net.Bob.PubKey[:],
|
NodePubkey: bob.PubKey[:],
|
||||||
LocalFundingAmount: 100_000,
|
LocalFundingAmount: 100_000,
|
||||||
}, {
|
}, {
|
||||||
NodePubkey: carol.PubKey[:],
|
NodePubkey: carol.PubKey[:],
|
||||||
@ -715,22 +710,16 @@ func testBatchChanFunding(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
}},
|
}},
|
||||||
}
|
}
|
||||||
|
|
||||||
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
|
err := alice.RPC.BatchOpenChannelAssertErr(batchReq)
|
||||||
defer cancel()
|
require.Contains(ht, err.Error(), "initial negotiation failed")
|
||||||
_, err := net.Alice.BatchOpenChannel(ctxt, batchReq)
|
|
||||||
require.Error(t.t, err)
|
|
||||||
require.Contains(t.t, err.Error(), "initial negotiation failed")
|
|
||||||
|
|
||||||
// Let's fix the minimum amount for Carol now and try again.
|
// Let's fix the minimum amount for Alice now and try again.
|
||||||
batchReq.Channels[1].LocalFundingAmount = 200_000
|
batchReq.Channels[1].LocalFundingAmount = 200_000
|
||||||
ctxt, cancel = context.WithTimeout(ctxb, defaultTimeout)
|
batchResp := alice.RPC.BatchOpenChannel(batchReq)
|
||||||
defer cancel()
|
require.Len(ht, batchResp.PendingChannels, 3)
|
||||||
batchResp, err := net.Alice.BatchOpenChannel(ctxt, batchReq)
|
|
||||||
require.NoError(t.t, err)
|
|
||||||
require.Len(t.t, batchResp.PendingChannels, 3)
|
|
||||||
|
|
||||||
txHash, err := chainhash.NewHash(batchResp.PendingChannels[0].Txid)
|
txHash, err := chainhash.NewHash(batchResp.PendingChannels[0].Txid)
|
||||||
require.NoError(t.t, err)
|
require.NoError(ht, err)
|
||||||
|
|
||||||
chanPoint1 := &lnrpc.ChannelPoint{
|
chanPoint1 := &lnrpc.ChannelPoint{
|
||||||
FundingTxid: &lnrpc.ChannelPoint_FundingTxidBytes{
|
FundingTxid: &lnrpc.ChannelPoint_FundingTxidBytes{
|
||||||
@ -751,23 +740,16 @@ func testBatchChanFunding(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
OutputIndex: batchResp.PendingChannels[2].OutputIndex,
|
OutputIndex: batchResp.PendingChannels[2].OutputIndex,
|
||||||
}
|
}
|
||||||
|
|
||||||
block := mineBlocks(t, net, 6, 1)[0]
|
block := ht.MineBlocksAndAssertNumTxes(6, 1)[0]
|
||||||
assertTxInBlock(t, block, txHash)
|
ht.Miner.AssertTxInBlock(block, txHash)
|
||||||
err = net.Alice.WaitForNetworkChannelOpen(chanPoint1)
|
ht.AssertTopologyChannelOpen(alice, chanPoint1)
|
||||||
require.NoError(t.t, err)
|
ht.AssertTopologyChannelOpen(alice, chanPoint2)
|
||||||
err = net.Alice.WaitForNetworkChannelOpen(chanPoint2)
|
ht.AssertTopologyChannelOpen(alice, chanPoint3)
|
||||||
require.NoError(t.t, err)
|
|
||||||
err = net.Alice.WaitForNetworkChannelOpen(chanPoint3)
|
|
||||||
require.NoError(t.t, err)
|
|
||||||
|
|
||||||
// With the channel open, ensure that it is counted towards Carol's
|
// With the channel open, ensure that it is counted towards Alice's
|
||||||
// total channel balance.
|
// total channel balance.
|
||||||
balReq := &lnrpc.ChannelBalanceRequest{}
|
balRes := alice.RPC.ChannelBalance()
|
||||||
ctxt, cancel = context.WithTimeout(ctxb, defaultTimeout)
|
require.NotEqual(ht, int64(0), balRes.LocalBalance.Sat)
|
||||||
defer cancel()
|
|
||||||
balRes, err := net.Alice.ChannelBalance(ctxt, balReq)
|
|
||||||
require.NoError(t.t, err)
|
|
||||||
require.NotEqual(t.t, int64(0), balRes.LocalBalance.Sat)
|
|
||||||
|
|
||||||
// Next, to make sure the channel functions as normal, we'll make some
|
// Next, to make sure the channel functions as normal, we'll make some
|
||||||
// payments within the channel.
|
// payments within the channel.
|
||||||
@ -776,23 +758,16 @@ func testBatchChanFunding(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
Memo: "new chans",
|
Memo: "new chans",
|
||||||
Value: int64(payAmt),
|
Value: int64(payAmt),
|
||||||
}
|
}
|
||||||
ctxt, cancel = context.WithTimeout(ctxb, defaultTimeout)
|
resp := carol.RPC.AddInvoice(invoice)
|
||||||
defer cancel()
|
ht.CompletePaymentRequests(alice, []string{resp.PaymentRequest})
|
||||||
resp, err := carol.AddInvoice(ctxt, invoice)
|
|
||||||
require.NoError(t.t, err)
|
|
||||||
err = completePaymentRequests(
|
|
||||||
net.Alice, net.Alice.RouterClient,
|
|
||||||
[]string{resp.PaymentRequest}, true,
|
|
||||||
)
|
|
||||||
require.NoError(t.t, err)
|
|
||||||
|
|
||||||
// To conclude, we'll close the newly created channel between Carol and
|
// To conclude, we'll close the newly created channel between Carol and
|
||||||
// Dave. This function will also block until the channel is closed and
|
// Dave. This function will also block until the channel is closed and
|
||||||
// will additionally assert the relevant channel closing post
|
// will additionally assert the relevant channel closing post
|
||||||
// conditions.
|
// conditions.
|
||||||
closeChannelAndAssert(t, net, net.Alice, chanPoint1, false)
|
ht.CloseChannel(alice, chanPoint1)
|
||||||
closeChannelAndAssert(t, net, net.Alice, chanPoint2, false)
|
ht.CloseChannel(alice, chanPoint2)
|
||||||
closeChannelAndAssert(t, net, net.Alice, chanPoint3, false)
|
ht.CloseChannel(alice, chanPoint3)
|
||||||
}
|
}
|
||||||
|
|
||||||
// deriveFundingShim creates a channel funding shim by deriving the necessary
|
// deriveFundingShim creates a channel funding shim by deriving the necessary
|
||||||
|
@ -227,10 +227,6 @@ var allTestCases = []*testCase{
|
|||||||
name: "sign psbt",
|
name: "sign psbt",
|
||||||
test: testSignPsbt,
|
test: testSignPsbt,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: "batch channel funding",
|
|
||||||
test: testBatchChanFunding,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: "psbt channel funding single step",
|
name: "psbt channel funding single step",
|
||||||
test: testPsbtChanFundingSingleStep,
|
test: testPsbtChanFundingSingleStep,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user