mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-02-23 14:40:30 +01:00
Merge pull request #5374 from yyforyongyu/itest-use-require-sendcoin
itest: use require inside net.SendCoins
This commit is contained in:
commit
2fd75ace9d
16 changed files with 285 additions and 687 deletions
|
@ -12,6 +12,7 @@ import (
|
|||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
|
@ -26,6 +27,7 @@ import (
|
|||
"github.com/lightningnetwork/lnd/lntest/wait"
|
||||
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/stretchr/testify/require"
|
||||
"google.golang.org/grpc/grpclog"
|
||||
)
|
||||
|
||||
|
@ -144,7 +146,9 @@ func (f *fakeLogger) Println(args ...interface{}) {}
|
|||
// rpc clients capable of communicating with the initial seeder nodes are
|
||||
// created. Nodes are initialized with the given extra command line flags, which
|
||||
// should be formatted properly - "--arg=value".
|
||||
func (n *NetworkHarness) SetUp(testCase string, lndArgs []string) error {
|
||||
func (n *NetworkHarness) SetUp(t *testing.T,
|
||||
testCase string, lndArgs []string) error {
|
||||
|
||||
// Swap out grpc's default logger with out fake logger which drops the
|
||||
// statements on the floor.
|
||||
grpclog.SetLogger(&fakeLogger{})
|
||||
|
@ -153,32 +157,16 @@ func (n *NetworkHarness) SetUp(testCase string, lndArgs []string) error {
|
|||
// Start the initial seeder nodes within the test network, then connect
|
||||
// their respective RPC clients.
|
||||
var wg sync.WaitGroup
|
||||
errChan := make(chan error, 2)
|
||||
wg.Add(2)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
node, err := n.NewNode("Alice", lndArgs)
|
||||
if err != nil {
|
||||
errChan <- err
|
||||
return
|
||||
}
|
||||
n.Alice = node
|
||||
n.Alice = n.NewNode(t, "Alice", lndArgs)
|
||||
}()
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
node, err := n.NewNode("Bob", lndArgs)
|
||||
if err != nil {
|
||||
errChan <- err
|
||||
return
|
||||
}
|
||||
n.Bob = node
|
||||
n.Bob = n.NewNode(t, "Bob", lndArgs)
|
||||
}()
|
||||
wg.Wait()
|
||||
select {
|
||||
case err := <-errChan:
|
||||
return err
|
||||
default:
|
||||
}
|
||||
|
||||
// First, make a connection between the two nodes. This will wait until
|
||||
// both nodes are fully started since the Connect RPC is guarded behind
|
||||
|
@ -346,10 +334,15 @@ func (n *NetworkHarness) NewNodeEtcd(name string, etcdCfg *etcd.Config,
|
|||
// NewNode fully initializes a returns a new HarnessNode bound to the
|
||||
// current instance of the network harness. The created node is running, but
|
||||
// not yet connected to other nodes within the network.
|
||||
func (n *NetworkHarness) NewNode(name string, extraArgs []string) (*HarnessNode,
|
||||
error) {
|
||||
func (n *NetworkHarness) NewNode(t *testing.T,
|
||||
name string, extraArgs []string) *HarnessNode {
|
||||
|
||||
return n.newNode(name, extraArgs, false, nil, n.embeddedEtcd, true)
|
||||
node, err := n.newNode(
|
||||
name, extraArgs, false, nil, n.embeddedEtcd, true,
|
||||
)
|
||||
require.NoErrorf(t, err, "unable to create new node for %s", name)
|
||||
|
||||
return node
|
||||
}
|
||||
|
||||
// NewNodeWithSeed fully initializes a new HarnessNode after creating a fresh
|
||||
|
@ -1358,36 +1351,45 @@ func (n *NetworkHarness) DumpLogs(node *HarnessNode) (string, error) {
|
|||
// SendCoins attempts to send amt satoshis from the internal mining node to the
|
||||
// targeted lightning node using a P2WKH address. 6 blocks are mined after in
|
||||
// order to confirm the transaction.
|
||||
func (n *NetworkHarness) SendCoins(ctx context.Context, amt btcutil.Amount,
|
||||
target *HarnessNode) error {
|
||||
func (n *NetworkHarness) SendCoins(ctx context.Context, t *testing.T,
|
||||
amt btcutil.Amount, target *HarnessNode) {
|
||||
|
||||
return n.sendCoins(
|
||||
err := n.sendCoins(
|
||||
ctx, amt, target, lnrpc.AddressType_WITNESS_PUBKEY_HASH,
|
||||
true,
|
||||
)
|
||||
require.NoErrorf(t, err, "unable to send coins for %s", target.Cfg.Name)
|
||||
}
|
||||
|
||||
// SendCoinsUnconfirmed sends coins from the internal mining node to the target
|
||||
// lightning node using a P2WPKH address. No blocks are mined after, so the
|
||||
// transaction remains unconfirmed.
|
||||
func (n *NetworkHarness) SendCoinsUnconfirmed(ctx context.Context,
|
||||
amt btcutil.Amount, target *HarnessNode) error {
|
||||
t *testing.T, amt btcutil.Amount, target *HarnessNode) {
|
||||
|
||||
return n.sendCoins(
|
||||
err := n.sendCoins(
|
||||
ctx, amt, target, lnrpc.AddressType_WITNESS_PUBKEY_HASH,
|
||||
false,
|
||||
)
|
||||
require.NoErrorf(
|
||||
t, err, "unable to send unconfirmed coins for %s",
|
||||
target.Cfg.Name,
|
||||
)
|
||||
}
|
||||
|
||||
// SendCoinsNP2WKH attempts to send amt satoshis from the internal mining node
|
||||
// to the targeted lightning node using a NP2WKH address.
|
||||
func (n *NetworkHarness) SendCoinsNP2WKH(ctx context.Context,
|
||||
amt btcutil.Amount, target *HarnessNode) error {
|
||||
t *testing.T, amt btcutil.Amount, target *HarnessNode) {
|
||||
|
||||
return n.sendCoins(
|
||||
err := n.sendCoins(
|
||||
ctx, amt, target, lnrpc.AddressType_NESTED_PUBKEY_HASH,
|
||||
true,
|
||||
)
|
||||
require.NoErrorf(
|
||||
t, err, "unable to send NP2WKH coins for %s",
|
||||
target.Cfg.Name,
|
||||
)
|
||||
}
|
||||
|
||||
// sendCoins attempts to send amt satoshis from the internal mining node to the
|
||||
|
|
|
@ -433,10 +433,7 @@ func testChannelBackupUpdates(net *lntest.NetworkHarness, t *harnessTest) {
|
|||
backupDir, chanbackup.DefaultBackupFileName,
|
||||
)
|
||||
carolArgs := fmt.Sprintf("--backupfilepath=%v", backupFilePath)
|
||||
carol, err := net.NewNode("carol", []string{carolArgs})
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create new node: %v", err)
|
||||
}
|
||||
carol := net.NewNode(t.t, "carol", []string{carolArgs})
|
||||
defer shutdownAndAssert(net, t, carol)
|
||||
|
||||
// Next, we'll register for streaming notifications for changes to the
|
||||
|
@ -605,10 +602,7 @@ func testExportChannelBackup(net *lntest.NetworkHarness, t *harnessTest) {
|
|||
// First, we'll create our primary test node: Carol. We'll use Carol to
|
||||
// open channels and also export backups that we'll examine throughout
|
||||
// the test.
|
||||
carol, err := net.NewNode("carol", nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create new node: %v", err)
|
||||
}
|
||||
carol := net.NewNode(t.t, "carol", nil)
|
||||
defer shutdownAndAssert(net, t, carol)
|
||||
|
||||
// With Carol up, we'll now connect her to Alice, and open a channel
|
||||
|
@ -849,24 +843,16 @@ func testChanRestoreScenario(t *harnessTest, net *lntest.NetworkHarness,
|
|||
defer func() {
|
||||
shutdownAndAssert(net, t, dave)
|
||||
}()
|
||||
carol, err := net.NewNode("carol", nodeArgs)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to make new node: %v", err)
|
||||
}
|
||||
carol := net.NewNode(t.t, "carol", nodeArgs)
|
||||
defer shutdownAndAssert(net, t, carol)
|
||||
|
||||
// Now that our new nodes are created, we'll give them some coins for
|
||||
// channel opening and anchor sweeping.
|
||||
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
|
||||
err = net.SendCoins(ctxt, btcutil.SatoshiPerBitcoin, carol)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send coins to dave: %v", err)
|
||||
}
|
||||
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, carol)
|
||||
|
||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||
err = net.SendCoins(ctxt, btcutil.SatoshiPerBitcoin, dave)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send coins to dave: %v", err)
|
||||
}
|
||||
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, dave)
|
||||
|
||||
var from, to *lntest.HarnessNode
|
||||
if testCase.initiator {
|
||||
|
|
|
@ -44,16 +44,13 @@ type interceptorTestCase struct {
|
|||
// valid payment (invoice is settled).
|
||||
func testForwardInterceptor(net *lntest.NetworkHarness, t *harnessTest) {
|
||||
// Initialize the test context with 3 connected nodes.
|
||||
alice, err := net.NewNode("alice", nil)
|
||||
require.NoError(t.t, err, "unable to create alice")
|
||||
alice := net.NewNode(t.t, "alice", nil)
|
||||
defer shutdownAndAssert(net, t, alice)
|
||||
|
||||
bob, err := net.NewNode("bob", nil)
|
||||
require.NoError(t.t, err, "unable to create bob")
|
||||
bob := net.NewNode(t.t, "bob", nil)
|
||||
defer shutdownAndAssert(net, t, alice)
|
||||
|
||||
carol, err := net.NewNode("carol", nil)
|
||||
require.NoError(t.t, err, "unable to create carol")
|
||||
carol := net.NewNode(t.t, "carol", nil)
|
||||
defer shutdownAndAssert(net, t, alice)
|
||||
|
||||
testContext := newInterceptorTestContext(t, net, alice, bob, carol)
|
||||
|
@ -316,8 +313,7 @@ func (c *interceptorTestContext) openChannel(from, to *lntest.HarnessNode,
|
|||
ctxb := context.Background()
|
||||
|
||||
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
|
||||
err := c.net.SendCoins(ctxt, btcutil.SatoshiPerBitcoin, from)
|
||||
require.NoError(c.t.t, err, "unable to send coins")
|
||||
c.net.SendCoins(ctxt, c.t.t, btcutil.SatoshiPerBitcoin, from)
|
||||
|
||||
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
|
||||
chanPoint := openChannelAndAssert(
|
||||
|
|
|
@ -37,25 +37,22 @@ func testBasicChannelFunding(net *lntest.NetworkHarness, t *harnessTest) {
|
|||
// preferentially signal the legacy commitment format. We do
|
||||
// the same for Dave shortly below.
|
||||
carolArgs := carolCommitType.Args()
|
||||
carol, err := net.NewNode("Carol", carolArgs)
|
||||
require.NoError(t.t, err, "unable to create new node")
|
||||
carol := net.NewNode(t.t, "Carol", carolArgs)
|
||||
defer shutdownAndAssert(net, t, carol)
|
||||
|
||||
// Each time, we'll send Carol a new set of coins in order to
|
||||
// fund the channel.
|
||||
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
|
||||
err = net.SendCoins(ctxt, btcutil.SatoshiPerBitcoin, carol)
|
||||
require.NoError(t.t, err, "unable to send coins to carol")
|
||||
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, carol)
|
||||
|
||||
daveArgs := daveCommitType.Args()
|
||||
dave, err := net.NewNode("Dave", daveArgs)
|
||||
require.NoError(t.t, err, "unable to create new node")
|
||||
dave := net.NewNode(t.t, "Dave", daveArgs)
|
||||
defer shutdownAndAssert(net, t, dave)
|
||||
|
||||
// Before we start the test, we'll ensure both sides are
|
||||
// connected to the funding flow can properly be executed.
|
||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||
err = net.EnsureConnected(ctxt, carol, dave)
|
||||
err := net.EnsureConnected(ctxt, carol, dave)
|
||||
require.NoError(t.t, err, "unable to connect peers")
|
||||
|
||||
carolChan, daveChan, closeChan, err := basicChannelFundingTest(
|
||||
|
@ -260,14 +257,12 @@ func testUnconfirmedChannelFunding(net *lntest.NetworkHarness, t *harnessTest) {
|
|||
)
|
||||
|
||||
// We'll start off by creating a node for Carol.
|
||||
carol, err := net.NewNode("Carol", nil)
|
||||
require.NoError(t.t, err, "unable to create carol's node")
|
||||
carol := net.NewNode(t.t, "Carol", nil)
|
||||
defer shutdownAndAssert(net, t, carol)
|
||||
|
||||
// We'll send her some confirmed funds.
|
||||
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
|
||||
err = net.SendCoins(ctxt, 2*chanAmt, carol)
|
||||
require.NoError(t.t, err, "unable to send coins to carol")
|
||||
net.SendCoins(ctxt, t.t, 2*chanAmt, carol)
|
||||
|
||||
// Now let Carol send some funds to herself, making a unconfirmed
|
||||
// change output.
|
||||
|
@ -385,24 +380,21 @@ func testExternalFundingChanPoint(net *lntest.NetworkHarness, t *harnessTest) {
|
|||
|
||||
// First, we'll create two new nodes that we'll use to open channel
|
||||
// between for this test.
|
||||
carol, err := net.NewNode("carol", nil)
|
||||
require.NoError(t.t, err)
|
||||
carol := net.NewNode(t.t, "carol", nil)
|
||||
defer shutdownAndAssert(net, t, carol)
|
||||
|
||||
dave, err := net.NewNode("dave", nil)
|
||||
require.NoError(t.t, err)
|
||||
dave := net.NewNode(t.t, "dave", nil)
|
||||
defer shutdownAndAssert(net, t, dave)
|
||||
|
||||
// Carol will be funding the channel, so we'll send some coins over to
|
||||
// her and ensure they have enough confirmations before we proceed.
|
||||
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
|
||||
err = net.SendCoins(ctxt, btcutil.SatoshiPerBitcoin, carol)
|
||||
require.NoError(t.t, err)
|
||||
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, carol)
|
||||
|
||||
// Before we start the test, we'll ensure both sides are connected to
|
||||
// the funding flow can properly be executed.
|
||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||
err = net.EnsureConnected(ctxt, carol, dave)
|
||||
err := net.EnsureConnected(ctxt, carol, dave)
|
||||
require.NoError(t.t, err)
|
||||
|
||||
// At this point, we're ready to simulate our external channel funding
|
||||
|
|
|
@ -30,10 +30,7 @@ func testHoldInvoicePersistence(net *lntest.NetworkHarness, t *harnessTest) {
|
|||
)
|
||||
|
||||
// Create carol, and clean up when the test finishes.
|
||||
carol, err := net.NewNode("Carol", nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create new nodes: %v", err)
|
||||
}
|
||||
carol := net.NewNode(t.t, "Carol", nil)
|
||||
defer shutdownAndAssert(net, t, carol)
|
||||
|
||||
// Connect Alice to Carol.
|
||||
|
@ -56,7 +53,7 @@ func testHoldInvoicePersistence(net *lntest.NetworkHarness, t *harnessTest) {
|
|||
// Wait for Alice and Carol to receive the channel edge from the
|
||||
// funding manager.
|
||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||
err = net.Alice.WaitForNetworkChannelOpen(ctxt, chanPointAlice)
|
||||
err := net.Alice.WaitForNetworkChannelOpen(ctxt, chanPointAlice)
|
||||
if err != nil {
|
||||
t.Fatalf("alice didn't see the alice->carol channel before "+
|
||||
"timeout: %v", err)
|
||||
|
|
|
@ -18,33 +18,24 @@ import (
|
|||
func testMaxChannelSize(net *lntest.NetworkHarness, t *harnessTest) {
|
||||
// We'll make two new nodes, both wumbo but with the default
|
||||
// limit on maximum channel size (10 BTC)
|
||||
wumboNode, err := net.NewNode(
|
||||
"wumbo", []string{"--protocol.wumbo-channels"},
|
||||
wumboNode := net.NewNode(
|
||||
t.t, "wumbo", []string{"--protocol.wumbo-channels"},
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create new node: %v", err)
|
||||
}
|
||||
defer shutdownAndAssert(net, t, wumboNode)
|
||||
|
||||
wumboNode2, err := net.NewNode(
|
||||
"wumbo2", []string{"--protocol.wumbo-channels"},
|
||||
wumboNode2 := net.NewNode(
|
||||
t.t, "wumbo2", []string{"--protocol.wumbo-channels"},
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create new node: %v", err)
|
||||
}
|
||||
defer shutdownAndAssert(net, t, wumboNode2)
|
||||
|
||||
// We'll send 11 BTC to the wumbo node so it can test the wumbo soft limit.
|
||||
ctxb := context.Background()
|
||||
err = net.SendCoins(ctxb, 11*btcutil.SatoshiPerBitcoin, wumboNode)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send coins to wumbo node: %v", err)
|
||||
}
|
||||
net.SendCoins(ctxb, t.t, 11*btcutil.SatoshiPerBitcoin, wumboNode)
|
||||
|
||||
// Next we'll connect both nodes, then attempt to make a wumbo channel
|
||||
// funding request, which should fail as it exceeds the default wumbo
|
||||
// soft limit of 10 BTC.
|
||||
err = net.EnsureConnected(ctxb, wumboNode, wumboNode2)
|
||||
err := net.EnsureConnected(ctxb, wumboNode, wumboNode2)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to connect peers: %v", err)
|
||||
}
|
||||
|
@ -67,10 +58,7 @@ func testMaxChannelSize(net *lntest.NetworkHarness, t *harnessTest) {
|
|||
|
||||
// Next we'll create a non-wumbo node to verify that it enforces the
|
||||
// BOLT-02 channel size limit and rejects our funding request.
|
||||
miniNode, err := net.NewNode("mini", nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create new node: %v", err)
|
||||
}
|
||||
miniNode := net.NewNode(t.t, "mini", nil)
|
||||
defer shutdownAndAssert(net, t, miniNode)
|
||||
|
||||
err = net.EnsureConnected(ctxb, wumboNode, miniNode)
|
||||
|
@ -95,13 +83,15 @@ func testMaxChannelSize(net *lntest.NetworkHarness, t *harnessTest) {
|
|||
|
||||
// We'll now make another wumbo node with appropriate maximum channel size
|
||||
// to accept our wumbo channel funding.
|
||||
wumboNode3, err := net.NewNode(
|
||||
"wumbo3", []string{"--protocol.wumbo-channels",
|
||||
fmt.Sprintf("--maxchansize=%v", int64(funding.MaxBtcFundingAmountWumbo+1))},
|
||||
wumboNode3 := net.NewNode(
|
||||
t.t, "wumbo3", []string{
|
||||
"--protocol.wumbo-channels",
|
||||
fmt.Sprintf(
|
||||
"--maxchansize=%v",
|
||||
int64(funding.MaxBtcFundingAmountWumbo+1),
|
||||
),
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create new node: %v", err)
|
||||
}
|
||||
defer shutdownAndAssert(net, t, wumboNode3)
|
||||
|
||||
// Creating a wumbo channel between these two nodes should succeed.
|
||||
|
|
|
@ -257,32 +257,14 @@ func newMppTestContext(t *harnessTest,
|
|||
|
||||
ctxb := context.Background()
|
||||
|
||||
alice, err := net.NewNode("alice", nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create alice: %v", err)
|
||||
}
|
||||
|
||||
bob, err := net.NewNode("bob", []string{"--accept-amp"})
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create bob: %v", err)
|
||||
}
|
||||
alice := net.NewNode(t.t, "alice", nil)
|
||||
bob := net.NewNode(t.t, "bob", []string{"--accept-amp"})
|
||||
|
||||
// Create a five-node context consisting of Alice, Bob and three new
|
||||
// nodes.
|
||||
carol, err := net.NewNode("carol", nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create carol: %v", err)
|
||||
}
|
||||
|
||||
dave, err := net.NewNode("dave", nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create dave: %v", err)
|
||||
}
|
||||
|
||||
eve, err := net.NewNode("eve", nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create eve: %v", err)
|
||||
}
|
||||
carol := net.NewNode(t.t, "carol", nil)
|
||||
dave := net.NewNode(t.t, "dave", nil)
|
||||
eve := net.NewNode(t.t, "eve", nil)
|
||||
|
||||
// Connect nodes to ensure propagation of channels.
|
||||
nodes := []*lntest.HarnessNode{alice, bob, carol, dave, eve}
|
||||
|
@ -314,10 +296,7 @@ func (c *mppTestContext) openChannel(from, to *lntest.HarnessNode, chanSize btcu
|
|||
ctxb := context.Background()
|
||||
|
||||
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
|
||||
err := c.net.SendCoins(ctxt, btcutil.SatoshiPerBitcoin, from)
|
||||
if err != nil {
|
||||
c.t.Fatalf("unable to send coins : %v", err)
|
||||
}
|
||||
c.net.SendCoins(ctxt, c.t.t, btcutil.SatoshiPerBitcoin, from)
|
||||
|
||||
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
|
||||
chanPoint := openChannelAndAssert(
|
||||
|
|
|
@ -88,10 +88,7 @@ func testHtlcErrorPropagation(net *lntest.NetworkHarness, t *harnessTest) {
|
|||
|
||||
// Since we'd like to test some multi-hop failure scenarios, we'll
|
||||
// introduce another node into our test network: Carol.
|
||||
carol, err := net.NewNode("Carol", nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create new nodes: %v", err)
|
||||
}
|
||||
carol := net.NewNode(t.t, "Carol", nil)
|
||||
|
||||
// Next, we'll create a connection from Bob to Carol, and open a
|
||||
// channel between them so we have the topology: Alice -> Bob -> Carol.
|
||||
|
|
|
@ -47,10 +47,7 @@ func testMultiHopPayments(net *lntest.NetworkHarness, t *harnessTest) {
|
|||
// First, we'll create Dave and establish a channel to Alice. Dave will
|
||||
// be running an older node that requires the legacy onion payload.
|
||||
daveArgs := []string{"--protocol.legacy.onion"}
|
||||
dave, err := net.NewNode("Dave", daveArgs)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create new nodes: %v", err)
|
||||
}
|
||||
dave := net.NewNode(t.t, "Dave", daveArgs)
|
||||
defer shutdownAndAssert(net, t, dave)
|
||||
|
||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||
|
@ -58,10 +55,8 @@ func testMultiHopPayments(net *lntest.NetworkHarness, t *harnessTest) {
|
|||
t.Fatalf("unable to connect dave to alice: %v", err)
|
||||
}
|
||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||
err = net.SendCoins(ctxt, btcutil.SatoshiPerBitcoin, dave)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send coins to dave: %v", err)
|
||||
}
|
||||
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, dave)
|
||||
|
||||
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
|
||||
chanPointDave := openChannelAndAssert(
|
||||
ctxt, t, net, dave, net.Alice,
|
||||
|
@ -81,10 +76,7 @@ func testMultiHopPayments(net *lntest.NetworkHarness, t *harnessTest) {
|
|||
|
||||
// Next, we'll create Carol and establish a channel to from her to
|
||||
// Dave.
|
||||
carol, err := net.NewNode("Carol", nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create new nodes: %v", err)
|
||||
}
|
||||
carol := net.NewNode(t.t, "Carol", nil)
|
||||
defer shutdownAndAssert(net, t, carol)
|
||||
|
||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||
|
@ -92,10 +84,8 @@ func testMultiHopPayments(net *lntest.NetworkHarness, t *harnessTest) {
|
|||
t.Fatalf("unable to connect carol to dave: %v", err)
|
||||
}
|
||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||
err = net.SendCoins(ctxt, btcutil.SatoshiPerBitcoin, carol)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send coins to carol: %v", err)
|
||||
}
|
||||
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, carol)
|
||||
|
||||
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
|
||||
chanPointCarol := openChannelAndAssert(
|
||||
ctxt, t, net, carol, dave,
|
||||
|
|
|
@ -81,16 +81,10 @@ func testMultiHopHtlcClaims(net *lntest.NetworkHarness, t *harnessTest) {
|
|||
ht := newHarnessTest(t, net)
|
||||
|
||||
args := commitType.Args()
|
||||
alice, err := net.NewNode("Alice", args)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create new node: %v", err)
|
||||
}
|
||||
alice := net.NewNode(t, "Alice", args)
|
||||
defer shutdownAndAssert(net, ht, alice)
|
||||
|
||||
bob, err := net.NewNode("Bob", args)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create new node: %v", err)
|
||||
}
|
||||
bob := net.NewNode(t, "Bob", args)
|
||||
defer shutdownAndAssert(net, ht, bob)
|
||||
|
||||
ctxb := context.Background()
|
||||
|
@ -225,16 +219,10 @@ func createThreeHopNetwork(t *harnessTest, net *lntest.NetworkHarness,
|
|||
// Make sure there are enough utxos for anchoring.
|
||||
for i := 0; i < 2; i++ {
|
||||
ctxt, _ = context.WithTimeout(context.Background(), defaultTimeout)
|
||||
err = net.SendCoins(ctxt, btcutil.SatoshiPerBitcoin, alice)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send coins to Alice: %v", err)
|
||||
}
|
||||
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, alice)
|
||||
|
||||
ctxt, _ = context.WithTimeout(context.Background(), defaultTimeout)
|
||||
err = net.SendCoins(ctxt, btcutil.SatoshiPerBitcoin, bob)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send coins to Bob: %v", err)
|
||||
}
|
||||
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, bob)
|
||||
}
|
||||
|
||||
// We'll start the test by creating a channel between Alice and Bob,
|
||||
|
@ -267,10 +255,8 @@ func createThreeHopNetwork(t *harnessTest, net *lntest.NetworkHarness,
|
|||
if carolHodl {
|
||||
carolFlags = append(carolFlags, "--hodl.exit-settle")
|
||||
}
|
||||
carol, err := net.NewNode("Carol", carolFlags)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create new node: %v", err)
|
||||
}
|
||||
carol := net.NewNode(t.t, "Carol", carolFlags)
|
||||
|
||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||
if err := net.ConnectNodes(ctxt, bob, carol); err != nil {
|
||||
t.Fatalf("unable to connect bob to carol: %v", err)
|
||||
|
@ -282,10 +268,7 @@ func createThreeHopNetwork(t *harnessTest, net *lntest.NetworkHarness,
|
|||
// positively-yielding transaction.
|
||||
for i := 0; i < 2; i++ {
|
||||
ctxt, _ = context.WithTimeout(context.Background(), defaultTimeout)
|
||||
err = net.SendCoins(ctxt, btcutil.SatoshiPerBitcoin, carol)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send coins to Carol: %v", err)
|
||||
}
|
||||
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, carol)
|
||||
}
|
||||
|
||||
// We'll then create a channel from Bob to Carol. After this channel is
|
||||
|
|
|
@ -30,10 +30,7 @@ func testNetworkConnectionTimeout(net *lntest.NetworkHarness, t *harnessTest) {
|
|||
|
||||
// First, test the global timeout settings.
|
||||
// Create Carol with a connection timeout of 1 millisecond.
|
||||
carol, err := net.NewNode("Carol", []string{"--connectiontimeout=1ms"})
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create new node carol: %v", err)
|
||||
}
|
||||
carol := net.NewNode(t.t, "Carol", []string{"--connectiontimeout=1ms"})
|
||||
defer shutdownAndAssert(net, t, carol)
|
||||
|
||||
// Try to connect Carol to a non-routable IP address, which should give
|
||||
|
@ -48,10 +45,7 @@ func testNetworkConnectionTimeout(net *lntest.NetworkHarness, t *harnessTest) {
|
|||
|
||||
// Second, test timeout on the connect peer request.
|
||||
// Create Dave with the default timeout setting.
|
||||
dave, err := net.NewNode("Dave", nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create new node dave: %v", err)
|
||||
}
|
||||
dave := net.NewNode(t.t, "Dave", nil)
|
||||
defer shutdownAndAssert(net, t, dave)
|
||||
|
||||
// Try to connect Dave to a non-routable IP address, using a timeout
|
||||
|
|
|
@ -32,10 +32,7 @@ func testCPFP(net *lntest.NetworkHarness, t *harnessTest) {
|
|||
// send to Bob.
|
||||
ctxb := context.Background()
|
||||
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
|
||||
err := net.SendCoins(ctxt, btcutil.SatoshiPerBitcoin, net.Alice)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send coins to alice: %v", err)
|
||||
}
|
||||
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, net.Alice)
|
||||
|
||||
// Create an address for Bob to send the coins to.
|
||||
addrReq := &lnrpc.NewAddressRequest{
|
||||
|
@ -172,19 +169,15 @@ func testCPFP(net *lntest.NetworkHarness, t *harnessTest) {
|
|||
func testAnchorReservedValue(net *lntest.NetworkHarness, t *harnessTest) {
|
||||
// Start two nodes supporting anchor channels.
|
||||
args := commitTypeAnchors.Args()
|
||||
alice, err := net.NewNode("Alice", args)
|
||||
require.NoError(t.t, err)
|
||||
|
||||
alice := net.NewNode(t.t, "Alice", args)
|
||||
defer shutdownAndAssert(net, t, alice)
|
||||
|
||||
bob, err := net.NewNode("Bob", args)
|
||||
require.NoError(t.t, err)
|
||||
|
||||
bob := net.NewNode(t.t, "Bob", args)
|
||||
defer shutdownAndAssert(net, t, bob)
|
||||
|
||||
ctxb := context.Background()
|
||||
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
|
||||
err = net.ConnectNodes(ctxt, alice, bob)
|
||||
err := net.ConnectNodes(ctxt, alice, bob)
|
||||
require.NoError(t.t, err)
|
||||
|
||||
// Send just enough coins for Alice to open a channel without a change output.
|
||||
|
@ -194,10 +187,8 @@ func testAnchorReservedValue(net *lntest.NetworkHarness, t *harnessTest) {
|
|||
)
|
||||
|
||||
ctxt, _ = context.WithTimeout(context.Background(), defaultTimeout)
|
||||
err = net.SendCoins(ctxt, chanAmt+feeEst, alice)
|
||||
require.NoError(t.t, err)
|
||||
net.SendCoins(ctxt, t.t, chanAmt+feeEst, alice)
|
||||
|
||||
// Alice opens a channel that would consume all the funds in her
|
||||
// wallet, without a change output. This should not be allowed.
|
||||
resErr := lnwallet.ErrReservedValueInvalidated.Error()
|
||||
|
||||
|
|
|
@ -25,23 +25,19 @@ func testPsbtChanFunding(net *lntest.NetworkHarness, t *harnessTest) {
|
|||
// First, we'll create two new nodes that we'll use to open channels
|
||||
// between for this test. Dave gets some coins that will be used to
|
||||
// fund the PSBT, just to make sure that Carol has an empty wallet.
|
||||
carol, err := net.NewNode("carol", nil)
|
||||
require.NoError(t.t, err)
|
||||
carol := net.NewNode(t.t, "carol", nil)
|
||||
defer shutdownAndAssert(net, t, carol)
|
||||
|
||||
dave, err := net.NewNode("dave", nil)
|
||||
require.NoError(t.t, err)
|
||||
dave := net.NewNode(t.t, "dave", nil)
|
||||
defer shutdownAndAssert(net, t, dave)
|
||||
err = net.SendCoins(ctxb, btcutil.SatoshiPerBitcoin, dave)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send coins to dave: %v", err)
|
||||
}
|
||||
|
||||
net.SendCoins(ctxb, t.t, btcutil.SatoshiPerBitcoin, dave)
|
||||
|
||||
// Before we start the test, we'll ensure both sides are connected so
|
||||
// the funding flow can be properly executed.
|
||||
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
|
||||
defer cancel()
|
||||
err = net.EnsureConnected(ctxt, carol, dave)
|
||||
err := net.EnsureConnected(ctxt, carol, dave)
|
||||
require.NoError(t.t, err)
|
||||
err = net.EnsureConnected(ctxt, carol, net.Alice)
|
||||
require.NoError(t.t, err)
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -606,12 +606,10 @@ func testWalletImportAccountScenario(net *lntest.NetworkHarness, t *harnessTest,
|
|||
|
||||
// We'll start our test by having two nodes, Carol and Dave. Carol's
|
||||
// default wallet account will be imported into Dave's node.
|
||||
carol, err := net.NewNode("carol", nil)
|
||||
require.NoError(t.t, err)
|
||||
carol := net.NewNode(t.t, "carol", nil)
|
||||
defer shutdownAndAssert(net, t, carol)
|
||||
|
||||
dave, err := net.NewNode("dave", nil)
|
||||
require.NoError(t.t, err)
|
||||
dave := net.NewNode(t.t, "dave", nil)
|
||||
defer shutdownAndAssert(net, t, dave)
|
||||
|
||||
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
|
||||
|
@ -754,12 +752,10 @@ func testWalletImportPubKeyScenario(net *lntest.NetworkHarness, t *harnessTest,
|
|||
const utxoAmt int64 = btcutil.SatoshiPerBitcoin
|
||||
|
||||
// We'll start our test by having two nodes, Carol and Dave.
|
||||
carol, err := net.NewNode("carol", nil)
|
||||
require.NoError(t.t, err)
|
||||
carol := net.NewNode(t.t, "carol", nil)
|
||||
defer shutdownAndAssert(net, t, carol)
|
||||
|
||||
dave, err := net.NewNode("dave", nil)
|
||||
require.NoError(t.t, err)
|
||||
dave := net.NewNode(t.t, "dave", nil)
|
||||
defer shutdownAndAssert(net, t, dave)
|
||||
|
||||
// We'll define a helper closure that we'll use throughout the test to
|
||||
|
|
|
@ -19,31 +19,22 @@ func testWumboChannels(net *lntest.NetworkHarness, t *harnessTest) {
|
|||
//
|
||||
// We'll make two new nodes, with one of them signalling support for
|
||||
// wumbo channels while the other doesn't.
|
||||
wumboNode, err := net.NewNode(
|
||||
"wumbo", []string{"--protocol.wumbo-channels"},
|
||||
wumboNode := net.NewNode(
|
||||
t.t, "wumbo", []string{"--protocol.wumbo-channels"},
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create new node: %v", err)
|
||||
}
|
||||
defer shutdownAndAssert(net, t, wumboNode)
|
||||
miniNode, err := net.NewNode("mini", nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create new node: %v", err)
|
||||
}
|
||||
miniNode := net.NewNode(t.t, "mini", nil)
|
||||
defer shutdownAndAssert(net, t, miniNode)
|
||||
|
||||
// We'll send coins to the wumbo node, as it'll be the one imitating
|
||||
// the channel funding.
|
||||
ctxb := context.Background()
|
||||
err = net.SendCoins(ctxb, btcutil.SatoshiPerBitcoin, wumboNode)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send coins to carol: %v", err)
|
||||
}
|
||||
net.SendCoins(ctxb, t.t, btcutil.SatoshiPerBitcoin, wumboNode)
|
||||
|
||||
// Next we'll connect both nodes, then attempt to make a wumbo channel
|
||||
// funding request to the mini node we created above. The wumbo request
|
||||
// should fail as the node isn't advertising wumbo channels.
|
||||
err = net.EnsureConnected(ctxb, wumboNode, miniNode)
|
||||
err := net.EnsureConnected(ctxb, wumboNode, miniNode)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to connect peers: %v", err)
|
||||
}
|
||||
|
@ -67,12 +58,9 @@ func testWumboChannels(net *lntest.NetworkHarness, t *harnessTest) {
|
|||
|
||||
// We'll now make another wumbo node to accept our wumbo channel
|
||||
// funding.
|
||||
wumboNode2, err := net.NewNode(
|
||||
"wumbo2", []string{"--protocol.wumbo-channels"},
|
||||
wumboNode2 := net.NewNode(
|
||||
t.t, "wumbo2", []string{"--protocol.wumbo-channels"},
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create new node: %v", err)
|
||||
}
|
||||
defer shutdownAndAssert(net, t, wumboNode2)
|
||||
|
||||
// Creating a wumbo channel between these two nodes should succeed.
|
||||
|
|
Loading…
Add table
Reference in a new issue