Merge pull request #5374 from yyforyongyu/itest-use-require-sendcoin

itest: use require inside net.SendCoins
This commit is contained in:
Olaoluwa Osuntokun 2021-06-18 14:12:39 -07:00 committed by GitHub
commit 2fd75ace9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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)

@ -1004,23 +1004,15 @@ func testOnchainFundRecovery(net *lntest.NetworkHarness, t *harnessTest) {
// Send one BTC to the next P2WKH address.
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
err = net.SendCoins(
ctxt, btcutil.SatoshiPerBitcoin, node,
net.SendCoins(
ctxt, t.t, btcutil.SatoshiPerBitcoin, node,
)
if err != nil {
t.Fatalf("unable to send coins to node: %v",
err)
}
// And another to the next NP2WKH address.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
err = net.SendCoinsNP2WKH(
ctxt, btcutil.SatoshiPerBitcoin, node,
net.SendCoinsNP2WKH(
ctxt, t.t, btcutil.SatoshiPerBitcoin, node,
)
if err != nil {
t.Fatalf("unable to send coins to node: %v",
err)
}
}
}
@ -1641,15 +1633,12 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) {
// Create Carol with options to rate limit channel updates up to 2 per
// day, and create a new channel Bob->Carol.
carol, err := net.NewNode(
"Carol", []string{
carol := net.NewNode(
t.t, "Carol", []string{
"--gossip.max-channel-update-burst=2",
"--gossip.channel-update-interval=24h",
},
)
if err != nil {
t.Fatalf("unable to create new nodes: %v", err)
}
// Clean up carol's node when the test finishes.
defer shutdownAndAssert(net, t, carol)
@ -1662,10 +1651,7 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) {
// Send some coins to Carol that can be used for channel funding.
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)
if err := net.ConnectNodes(ctxb, carol, net.Bob); err != nil {
t.Fatalf("unable to connect dave to alice: %v", err)
@ -2392,16 +2378,10 @@ func testDisconnectingTargetPeer(net *lntest.NetworkHarness, t *harnessTest) {
"--maxbackoff=1m",
}
alice, err := net.NewNode("Alice", args)
if err != nil {
t.Fatalf("unable to create new node: %v", err)
}
alice := net.NewNode(t.t, "Alice", args)
defer shutdownAndAssert(net, t, alice)
bob, err := net.NewNode("Bob", args)
if err != nil {
t.Fatalf("unable to create new node: %v", err)
}
bob := net.NewNode(t.t, "Bob", args)
defer shutdownAndAssert(net, t, bob)
// Start by connecting Alice and Bob with no channels.
@ -2415,10 +2395,7 @@ func testDisconnectingTargetPeer(net *lntest.NetworkHarness, t *harnessTest) {
// Give Alice some coins so she can fund a channel.
ctxt, _ = context.WithTimeout(ctxb, 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)
chanAmt := funding.MaxBtcFundingAmount
pushAmt := btcutil.Amount(0)
@ -2563,10 +2540,7 @@ func testChannelFundingPersistence(net *lntest.NetworkHarness, t *harnessTest) {
// we'll need to create a new node instance.
const numConfs = 5
carolArgs := []string{fmt.Sprintf("--bitcoin.defaultchanconfs=%v", numConfs)}
carol, err := net.NewNode("Carol", carolArgs)
if err != nil {
t.Fatalf("unable to create new node: %v", err)
}
carol := net.NewNode(t.t, "Carol", carolArgs)
// Clean up carol's node when the test finishes.
defer shutdownAndAssert(net, t, carol)
@ -2865,10 +2839,7 @@ func testChannelUnsettledBalance(net *lntest.NetworkHarness, t *harnessTest) {
}
// Create carol in hodl mode.
carol, err := net.NewNode("Carol", []string{"--hodl.exit-settle"})
if err != nil {
t.Fatalf("unable to create new nodes: %v", err)
}
carol := net.NewNode(t.t, "Carol", []string{"--hodl.exit-settle"})
defer shutdownAndAssert(net, t, carol)
// Connect Alice to Carol.
@ -2889,7 +2860,7 @@ func testChannelUnsettledBalance(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)
@ -3165,10 +3136,7 @@ func testChannelForceClosure(net *lntest.NetworkHarness, t *harnessTest) {
ht := newHarnessTest(t, net)
args := channelType.Args()
alice, err := net.NewNode("Alice", args)
if err != nil {
t.Fatalf("unable to create new node: %v", err)
}
alice := net.NewNode(ht.t, "Alice", args)
defer shutdownAndAssert(net, ht, alice)
// Since we'd like to test failure scenarios with
@ -3176,10 +3144,7 @@ func testChannelForceClosure(net *lntest.NetworkHarness, t *harnessTest) {
// our test network: Carol.
carolArgs := []string{"--hodl.exit-settle"}
carolArgs = append(carolArgs, args...)
carol, err := net.NewNode("Carol", carolArgs)
if err != nil {
t.Fatalf("unable to create new nodes: %v", err)
}
carol := net.NewNode(ht.t, "Carol", carolArgs)
defer shutdownAndAssert(net, ht, carol)
// Each time, we'll send Alice new set of coins in
@ -3187,23 +3152,11 @@ func testChannelForceClosure(net *lntest.NetworkHarness, t *harnessTest) {
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, btcutil.SatoshiPerBitcoin, alice)
// Also give Carol some coins to allow her to sweep her
// anchor.
err = net.SendCoins(
ctxt, btcutil.SatoshiPerBitcoin, carol,
)
if err != nil {
t.Fatalf("unable to send coins to Alice: %v",
err)
}
net.SendCoins(ctxt, t, btcutil.SatoshiPerBitcoin, carol)
channelForceClosureTest(
net, ht, alice, carol, channelType,
@ -4500,10 +4453,7 @@ func testSphinxReplayPersistence(net *lntest.NetworkHarness, t *harnessTest) {
chanAmt := btcutil.Amount(100000)
// First, we'll create Dave, the receiver, and start him in hodl mode.
dave, err := net.NewNode("Dave", []string{"--hodl.exit-settle"})
if err != nil {
t.Fatalf("unable to create new nodes: %v", err)
}
dave := net.NewNode(t.t, "Dave", []string{"--hodl.exit-settle"})
// We must remember to shutdown the nodes we created for the duration
// of the tests, only leaving the two seed nodes (Alice and Bob) within
@ -4513,10 +4463,7 @@ func testSphinxReplayPersistence(net *lntest.NetworkHarness, t *harnessTest) {
// Next, we'll create Carol and establish a channel to from her to
// Dave. Carol is started in both unsafe-replay which will cause her to
// replay any pending Adds held in memory upon reconnection.
carol, err := net.NewNode("Carol", []string{"--unsafe-replay"})
if err != nil {
t.Fatalf("unable to create new nodes: %v", err)
}
carol := net.NewNode(t.t, "Carol", []string{"--unsafe-replay"})
defer shutdownAndAssert(net, t, carol)
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
@ -4524,10 +4471,8 @@ func testSphinxReplayPersistence(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)
chanPoint := openChannelAndAssert(
ctxt, t, net, carol, dave,
@ -4541,10 +4486,7 @@ func testSphinxReplayPersistence(net *lntest.NetworkHarness, t *harnessTest) {
// by paying from Carol directly to Dave, because the '--unsafe-replay'
// setup doesn't apply to locally added htlcs. In that case, the
// mailbox, that is responsible for generating the replay, is bypassed.
fred, err := net.NewNode("Fred", nil)
if err != nil {
t.Fatalf("unable to create new nodes: %v", err)
}
fred := net.NewNode(t.t, "Fred", nil)
defer shutdownAndAssert(net, t, fred)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
@ -4552,10 +4494,8 @@ func testSphinxReplayPersistence(net *lntest.NetworkHarness, t *harnessTest) {
t.Fatalf("unable to connect fred to carol: %v", err)
}
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
err = net.SendCoins(ctxt, btcutil.SatoshiPerBitcoin, fred)
if err != nil {
t.Fatalf("unable to send coins to fred: %v", err)
}
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, fred)
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPointFC := openChannelAndAssert(
ctxt, t, net, fred, carol,
@ -4738,18 +4678,17 @@ func testListChannels(net *lntest.NetworkHarness, t *harnessTest) {
const bobRemoteMaxHtlcs = 100
// Create two fresh nodes and open a channel between them.
alice, err := net.NewNode("Alice", nil)
if err != nil {
t.Fatalf("unable to create new node: %v", err)
}
alice := net.NewNode(t.t, "Alice", nil)
defer shutdownAndAssert(net, t, alice)
bob, err := net.NewNode("Bob", []string{
fmt.Sprintf("--default-remote-max-htlcs=%v", bobRemoteMaxHtlcs),
})
if err != nil {
t.Fatalf("unable to create new node: %v", err)
}
bob := net.NewNode(
t.t, "Bob", []string{
fmt.Sprintf(
"--default-remote-max-htlcs=%v",
bobRemoteMaxHtlcs,
),
},
)
defer shutdownAndAssert(net, t, bob)
// Connect Alice to Bob.
@ -4759,10 +4698,7 @@ func testListChannels(net *lntest.NetworkHarness, t *harnessTest) {
// Give Alice some coins so she can fund a channel.
ctxt, _ := context.WithTimeout(ctxb, 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)
// Open a channel with 100k satoshis between Alice and Bob with Alice
// being the sole funder of the channel. The minial HTLC amount is set to
@ -4783,7 +4719,7 @@ func testListChannels(net *lntest.NetworkHarness, t *harnessTest) {
// Wait for Alice and Bob to receive the channel edge from the
// funding manager.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
err = alice.WaitForNetworkChannelOpen(ctxt, chanPoint)
err := alice.WaitForNetworkChannelOpen(ctxt, chanPoint)
if err != nil {
t.Fatalf("alice didn't see the alice->bob channel before "+
"timeout: %v", err)
@ -4880,26 +4816,24 @@ func testUpdateChanStatus(net *lntest.NetworkHarness, t *harnessTest) {
ctxb := context.Background()
// Create two fresh nodes and open a channel between them.
alice, err := net.NewNode("Alice", []string{
"--minbackoff=10s",
"--chan-enable-timeout=1.5s",
"--chan-disable-timeout=3s",
"--chan-status-sample-interval=.5s",
})
if err != nil {
t.Fatalf("unable to create new node: %v", err)
}
alice := net.NewNode(
t.t, "Alice", []string{
"--minbackoff=10s",
"--chan-enable-timeout=1.5s",
"--chan-disable-timeout=3s",
"--chan-status-sample-interval=.5s",
},
)
defer shutdownAndAssert(net, t, alice)
bob, err := net.NewNode("Bob", []string{
"--minbackoff=10s",
"--chan-enable-timeout=1.5s",
"--chan-disable-timeout=3s",
"--chan-status-sample-interval=.5s",
})
if err != nil {
t.Fatalf("unable to create new node: %v", err)
}
bob := net.NewNode(
t.t, "Bob", []string{
"--minbackoff=10s",
"--chan-enable-timeout=1.5s",
"--chan-disable-timeout=3s",
"--chan-status-sample-interval=.5s",
},
)
defer shutdownAndAssert(net, t, bob)
// Connect Alice to Bob.
@ -4909,10 +4843,7 @@ func testUpdateChanStatus(net *lntest.NetworkHarness, t *harnessTest) {
// Give Alice some coins so she can fund a channel.
ctxt, _ := context.WithTimeout(ctxb, 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)
// Open a channel with 100k satoshis between Alice and Bob with Alice
// being the sole funder of the channel.
@ -4928,7 +4859,7 @@ func testUpdateChanStatus(net *lntest.NetworkHarness, t *harnessTest) {
// Wait for Alice and Bob to receive the channel edge from the
// funding manager.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
err = alice.WaitForNetworkChannelOpen(ctxt, chanPoint)
err := alice.WaitForNetworkChannelOpen(ctxt, chanPoint)
if err != nil {
t.Fatalf("alice didn't see the alice->bob channel before "+
"timeout: %v", err)
@ -4944,10 +4875,7 @@ func testUpdateChanStatus(net *lntest.NetworkHarness, t *harnessTest) {
// Launch a node for Carol which will connect to Alice and Bob in
// order to receive graph updates. This will ensure that the
// channel updates are propagated throughout the network.
carol, err := net.NewNode("Carol", nil)
if err != nil {
t.Fatalf("unable to create Carol's node: %v", err)
}
carol := net.NewNode(t.t, "Carol", nil)
defer shutdownAndAssert(net, t, carol)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
@ -5506,16 +5434,10 @@ func testSingleHopSendToRouteCase(net *lntest.NetworkHarness, t *harnessTest,
// is the sole funder of the channel with 100k satoshis. The network
// topology should look like:
// Carol -> 100k -> 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)
dave, err := net.NewNode("Dave", nil)
if err != nil {
t.Fatalf("unable to create new nodes: %v", err)
}
dave := net.NewNode(t.t, "Dave", nil)
defer shutdownAndAssert(net, t, dave)
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
@ -5523,10 +5445,7 @@ func testSingleHopSendToRouteCase(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)
// Open a channel with 100k satoshis between Carol and Dave with Carol
// being the sole funder of the channel.
@ -5887,10 +5806,7 @@ func testMultiHopSendToRoute(net *lntest.NetworkHarness, t *harnessTest) {
// Create Carol and establish a channel from Bob. Bob is the sole funder
// of the channel with 100k satoshis. The network topology should look like:
// Alice -> Bob -> 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)
defer shutdownAndAssert(net, t, carol)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
@ -5898,10 +5814,8 @@ func testMultiHopSendToRoute(net *lntest.NetworkHarness, t *harnessTest) {
t.Fatalf("unable to connect carol to alice: %v", err)
}
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
err = net.SendCoins(ctxt, btcutil.SatoshiPerBitcoin, net.Bob)
if err != nil {
t.Fatalf("unable to send coins to bob: %v", err)
}
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, net.Bob)
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPointBob := openChannelAndAssert(
ctxt, t, net, net.Bob, carol,
@ -6069,29 +5983,17 @@ func testSendToRouteErrorPropagation(net *lntest.NetworkHarness, t *harnessTest)
// Bob graph.
//
// The network topology should now look like: Alice -> Bob; Carol -> Charlie.
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)
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)
charlie, err := net.NewNode("Charlie", nil)
if err != nil {
t.Fatalf("unable to create new nodes: %v", err)
}
charlie := net.NewNode(t.t, "Charlie", nil)
defer shutdownAndAssert(net, t, charlie)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
err = net.SendCoins(ctxt, btcutil.SatoshiPerBitcoin, charlie)
if err != nil {
t.Fatalf("unable to send coins to charlie: %v", err)
}
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, charlie)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
if err := net.ConnectNodes(ctxt, carol, charlie); err != nil {
@ -6317,10 +6219,7 @@ func testPrivateChannels(net *lntest.NetworkHarness, t *harnessTest) {
}
// Create Dave, and a channel to Alice of 100k.
dave, err := net.NewNode("Dave", nil)
if err != nil {
t.Fatalf("unable to create new nodes: %v", err)
}
dave := net.NewNode(t.t, "Dave", nil)
defer shutdownAndAssert(net, t, dave)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
@ -6328,10 +6227,8 @@ func testPrivateChannels(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,
@ -6351,10 +6248,7 @@ func testPrivateChannels(net *lntest.NetworkHarness, t *harnessTest) {
// Next, we'll create Carol and establish a channel from her to
// Dave of 100k.
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)
@ -6362,10 +6256,8 @@ func testPrivateChannels(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,
@ -6648,10 +6540,7 @@ func testInvoiceRoutingHints(net *lntest.NetworkHarness, t *harnessTest) {
// Then, we'll create Carol's node and open a public channel between her
// and Alice. This channel will not be considered as a routing hint due
// to it being public.
carol, err := net.NewNode("Carol", nil)
if err != nil {
t.Fatalf("unable to create carol's node: %v", err)
}
carol := net.NewNode(t.t, "Carol", nil)
defer shutdownAndAssert(net, t, carol)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
@ -6689,10 +6578,7 @@ func testInvoiceRoutingHints(net *lntest.NetworkHarness, t *harnessTest) {
// and Alice. We will not include a push amount in order to not consider
// this channel as a routing hint as it will not have enough remote
// balance for the invoice's amount.
dave, err := net.NewNode("Dave", nil)
if err != nil {
t.Fatalf("unable to create dave's node: %v", err)
}
dave := net.NewNode(t.t, "Dave", nil)
defer shutdownAndAssert(net, t, dave)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
@ -6712,10 +6598,7 @@ func testInvoiceRoutingHints(net *lntest.NetworkHarness, t *harnessTest) {
// her and Alice. This time though, we'll take Eve's node down after the
// channel has been created to avoid populating routing hints for
// inactive channels.
eve, err := net.NewNode("Eve", nil)
if err != nil {
t.Fatalf("unable to create eve's node: %v", err)
}
eve := net.NewNode(t.t, "Eve", nil)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
if err := net.ConnectNodes(ctxt, net.Alice, eve); err != nil {
t.Fatalf("unable to connect alice to eve: %v", err)
@ -6741,7 +6624,7 @@ func testInvoiceRoutingHints(net *lntest.NetworkHarness, t *harnessTest) {
}
for i, chanPoint := range aliceChans {
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
err = net.Alice.WaitForNetworkChannelOpen(ctxt, chanPoint)
err := net.Alice.WaitForNetworkChannelOpen(ctxt, chanPoint)
if err != nil {
t.Fatalf("timed out waiting for channel open %s: %v",
chanNames[i], err)
@ -6762,7 +6645,7 @@ func testInvoiceRoutingHints(net *lntest.NetworkHarness, t *harnessTest) {
// Alice and Bob should be the only channel used as a routing hint.
var predErr error
var decoded *lnrpc.PayReq
err = wait.Predicate(func() bool {
err := wait.Predicate(func() bool {
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
resp, err := net.Alice.AddInvoice(ctxt, invoice)
if err != nil {
@ -6892,10 +6775,7 @@ func testMultiHopOverPrivateChannels(net *lntest.NetworkHarness, t *harnessTest)
// Next, we'll create Carol's node and open a public channel between
// her and Bob with Bob being the funder.
carol, err := net.NewNode("Carol", nil)
if err != nil {
t.Fatalf("unable to create carol's node: %v", err)
}
carol := net.NewNode(t.t, "Carol", nil)
defer shutdownAndAssert(net, t, carol)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
@ -6941,10 +6821,7 @@ func testMultiHopOverPrivateChannels(net *lntest.NetworkHarness, t *harnessTest)
// Next, we'll create Dave's node and open a private channel between him
// and Carol with Carol being the funder.
dave, err := net.NewNode("Dave", nil)
if err != nil {
t.Fatalf("unable to create dave's node: %v", err)
}
dave := net.NewNode(t.t, "Dave", nil)
defer shutdownAndAssert(net, t, dave)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
@ -6952,10 +6829,8 @@ func testMultiHopOverPrivateChannels(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,
@ -7588,10 +7463,7 @@ func testMaxPendingChannels(net *lntest.NetworkHarness, t *harnessTest) {
args := []string{
fmt.Sprintf("--maxpendingchannels=%v", maxPendingChannels),
}
carol, err := net.NewNode("Carol", args)
if err != nil {
t.Fatalf("unable to create new nodes: %v", err)
}
carol := net.NewNode(t.t, "Carol", args)
defer shutdownAndAssert(net, t, carol)
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
@ -7601,9 +7473,7 @@ func testMaxPendingChannels(net *lntest.NetworkHarness, t *harnessTest) {
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
carolBalance := btcutil.Amount(maxPendingChannels) * amount
if err := net.SendCoins(ctxt, carolBalance, carol); err != nil {
t.Fatalf("unable to send coins to carol: %v", err)
}
net.SendCoins(ctxt, t.t, carolBalance, carol)
// Send open channel requests without generating new blocks thereby
// increasing pool of pending channels. Then check that we can't open
@ -7623,7 +7493,7 @@ func testMaxPendingChannels(net *lntest.NetworkHarness, t *harnessTest) {
// Carol exhausted available amount of pending channels, next open
// channel request should cause ErrorGeneric to be sent back to Alice.
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
_, err = net.OpenChannel(
_, err := net.OpenChannel(
ctxt, net.Alice, carol,
lntest.OpenChannelParams{
Amt: amount,
@ -7750,10 +7620,7 @@ func testFailingChannel(net *lntest.NetworkHarness, t *harnessTest) {
// We'll introduce Carol, which will settle any incoming invoice with a
// totally unrelated preimage.
carol, err := net.NewNode("Carol", []string{"--hodl.bogus-settle"})
if err != nil {
t.Fatalf("unable to create new nodes: %v", err)
}
carol := net.NewNode(t.t, "Carol", []string{"--hodl.bogus-settle"})
defer shutdownAndAssert(net, t, carol)
// Let Alice connect and open a channel to Carol,
@ -7954,10 +7821,7 @@ func testGarbageCollectLinkNodes(net *lntest.NetworkHarness, t *harnessTest) {
)
// Create Carol's node and connect Alice to her.
carol, err := net.NewNode("Carol", nil)
if err != nil {
t.Fatalf("unable to create carol's node: %v", err)
}
carol := net.NewNode(t.t, "Carol", nil)
defer shutdownAndAssert(net, t, carol)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
if err := net.ConnectNodes(ctxt, net.Alice, carol); err != nil {
@ -7977,11 +7841,9 @@ func testGarbageCollectLinkNodes(net *lntest.NetworkHarness, t *harnessTest) {
// Now, create Dave's a node and also open a channel between Alice and
// him. This link will serve as the only persistent link throughout
// restarts in this test.
dave, err := net.NewNode("Dave", nil)
if err != nil {
t.Fatalf("unable to create dave's node: %v", err)
}
dave := net.NewNode(t.t, "Dave", nil)
defer shutdownAndAssert(net, t, dave)
if err := net.ConnectNodes(ctxt, net.Alice, dave); err != nil {
t.Fatalf("unable to connect alice to dave: %v", err)
}
@ -8043,7 +7905,7 @@ func testGarbageCollectLinkNodes(net *lntest.NetworkHarness, t *harnessTest) {
require.Eventually(t.t, func() bool {
return isConnected(dave.PubKeyStr)
}, defaultTimeout, 20*time.Millisecond)
err = wait.Predicate(func() bool {
err := wait.Predicate(func() bool {
return isConnected(dave.PubKeyStr)
}, defaultTimeout)
@ -8202,13 +8064,10 @@ func testRevokedCloseRetribution(net *lntest.NetworkHarness, t *harnessTest) {
// protection logic automatically. We also can't have Carol
// automatically re-connect too early, otherwise DLP would be initiated
// instead of the breach we want to provoke.
carol, err := net.NewNode(
"Carol",
carol := net.NewNode(
t.t, "Carol",
[]string{"--hodl.exit-settle", "--nolisten", "--minbackoff=1h"},
)
if err != nil {
t.Fatalf("unable to create new carol node: %v", err)
}
defer shutdownAndAssert(net, t, carol)
// We must let Bob communicate with Carol before they are able to open
@ -8221,10 +8080,7 @@ func testRevokedCloseRetribution(net *lntest.NetworkHarness, t *harnessTest) {
// Before we make a channel, we'll load up Carol with some coins sent
// directly from the miner.
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)
// In order to test Carol's response to an uncooperative channel
// closure by Bob, we'll first open up a channel between them with a
@ -8468,10 +8324,7 @@ func testRevokedCloseRetributionZeroValueRemoteOutput(net *lntest.NetworkHarness
// 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", []string{"--hodl.exit-settle"})
if err != nil {
t.Fatalf("unable to create new nodes: %v", err)
}
carol := net.NewNode(t.t, "Carol", []string{"--hodl.exit-settle"})
defer shutdownAndAssert(net, t, carol)
// Dave will be the breached party. We set --nolisten to ensure Carol
@ -8479,13 +8332,10 @@ func testRevokedCloseRetributionZeroValueRemoteOutput(net *lntest.NetworkHarness
// protection logic automatically. We also can't have Dave automatically
// re-connect too early, otherwise DLP would be initiated instead of the
// breach we want to provoke.
dave, err := net.NewNode(
"Dave",
dave := net.NewNode(
t.t, "Dave",
[]string{"--hodl.exit-settle", "--nolisten", "--minbackoff=1h"},
)
if err != nil {
t.Fatalf("unable to create new node: %v", err)
}
defer shutdownAndAssert(net, t, dave)
// We must let Dave have an open channel before she can send a node
@ -8498,10 +8348,7 @@ func testRevokedCloseRetributionZeroValueRemoteOutput(net *lntest.NetworkHarness
// Before we make a channel, we'll load up Dave with some coins sent
// directly from the miner.
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)
// In order to test Dave's response to an uncooperative channel
// closure by Carol, we'll first open up a channel between them with a
@ -8719,10 +8566,7 @@ func testRevokedCloseRetributionRemoteHodl(net *lntest.NetworkHarness,
// Since this test will result in the counterparty being left in a
// weird state, we will introduce another node into our test network:
// Carol.
carol, err := net.NewNode("Carol", []string{"--hodl.exit-settle"})
if err != nil {
t.Fatalf("unable to create new nodes: %v", err)
}
carol := net.NewNode(t.t, "Carol", []string{"--hodl.exit-settle"})
defer shutdownAndAssert(net, t, carol)
// We'll also create a new node Dave, who will have a channel with
@ -8730,13 +8574,10 @@ func testRevokedCloseRetributionRemoteHodl(net *lntest.NetworkHarness,
// with active HTLCs. Dave will be the breached party. We set
// --nolisten to ensure Carol won't be able to connect to him and
// trigger the channel data protection logic automatically.
dave, err := net.NewNode(
"Dave",
dave := net.NewNode(
t.t, "Dave",
[]string{"--hodl.exit-settle", "--nolisten"},
)
if err != nil {
t.Fatalf("unable to create new dave node: %v", err)
}
defer shutdownAndAssert(net, t, dave)
// We must let Dave communicate with Carol before they are able to open
@ -8749,10 +8590,7 @@ func testRevokedCloseRetributionRemoteHodl(net *lntest.NetworkHarness,
// Before we make a channel, we'll load up Dave with some coins sent
// directly from the miner.
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)
// In order to test Dave's response to an uncooperative channel closure
// by Carol, we'll first open up a channel between them with a
@ -9186,22 +9024,16 @@ func testRevokedCloseRetributionAltruistWatchtowerCase(
if anchors {
carolArgs = append(carolArgs, "--protocol.anchors")
}
carol, err := net.NewNode("Carol", carolArgs)
if err != nil {
t.Fatalf("unable to create new nodes: %v", err)
}
carol := net.NewNode(t.t, "Carol", carolArgs)
defer shutdownAndAssert(net, t, carol)
// Willy the watchtower will protect Dave from Carol's breach. He will
// remain online in order to punish Carol on Dave's behalf, since the
// breach will happen while Dave is offline.
willy, err := net.NewNode("Willy", []string{
willy := net.NewNode(t.t, "Willy", []string{
"--watchtower.active",
"--watchtower.externalip=" + externalIP,
})
if err != nil {
t.Fatalf("unable to create new nodes: %v", err)
}
defer shutdownAndAssert(net, t, willy)
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
@ -9246,10 +9078,7 @@ func testRevokedCloseRetributionAltruistWatchtowerCase(
if anchors {
daveArgs = append(daveArgs, "--protocol.anchors")
}
dave, err := net.NewNode("Dave", daveArgs)
if err != nil {
t.Fatalf("unable to create new node: %v", err)
}
dave := net.NewNode(t.t, "Dave", daveArgs)
defer shutdownAndAssert(net, t, dave)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
@ -9269,10 +9098,7 @@ func testRevokedCloseRetributionAltruistWatchtowerCase(
// Before we make a channel, we'll load up Dave with some coins sent
// directly from the miner.
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)
// In order to test Dave's response to an uncooperative channel
// closure by Carol, we'll first open up a channel between them with a
@ -9766,28 +9592,19 @@ func testDataLossProtection(net *lntest.NetworkHarness, t *harnessTest) {
// protection logic automatically. We also can't have Carol
// automatically re-connect too early, otherwise DLP would be initiated
// at the wrong moment.
carol, err := net.NewNode(
"Carol", []string{"--nolisten", "--minbackoff=1h"},
carol := net.NewNode(
t.t, "Carol", []string{"--nolisten", "--minbackoff=1h"},
)
if err != nil {
t.Fatalf("unable to create new carol node: %v", err)
}
defer shutdownAndAssert(net, t, carol)
// Dave will be the party losing his state.
dave, err := net.NewNode("Dave", nil)
if err != nil {
t.Fatalf("unable to create new node: %v", err)
}
dave := net.NewNode(t.t, "Dave", nil)
defer shutdownAndAssert(net, t, dave)
// Before we make a channel, we'll load up Carol with some coins sent
// directly from the miner.
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)
// timeTravel is a method that will make Carol open a channel to the
// passed node, settle a series of payments, then reset the node back
@ -10122,10 +9939,7 @@ func testRejectHTLC(net *lntest.NetworkHarness, t *harnessTest) {
ctxb := context.Background()
// Create Carol with reject htlc flag.
carol, err := net.NewNode("Carol", []string{"--rejecthtlc"})
if err != nil {
t.Fatalf("unable to create new node: %v", err)
}
carol := net.NewNode(t.t, "Carol", []string{"--rejecthtlc"})
defer shutdownAndAssert(net, t, carol)
// Connect Alice to Carol.
@ -10139,16 +9953,10 @@ func testRejectHTLC(net *lntest.NetworkHarness, t *harnessTest) {
}
// Send coins to Carol.
err = net.SendCoins(ctxb, btcutil.SatoshiPerBitcoin, carol)
if err != nil {
t.Fatalf("unable to send coins to carol: %v", err)
}
net.SendCoins(ctxb, t.t, btcutil.SatoshiPerBitcoin, carol)
// Send coins to Alice.
err = net.SendCoins(ctxb, btcutil.SatoshiPerBitcent, net.Alice)
if err != nil {
t.Fatalf("unable to send coins to alice: %v", err)
}
net.SendCoins(ctxb, t.t, btcutil.SatoshiPerBitcent, net.Alice)
// Open a channel between Alice and Carol.
ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout)
@ -10175,7 +9983,7 @@ func testRejectHTLC(net *lntest.NetworkHarness, t *harnessTest) {
genPreImage := func() []byte {
preimage := make([]byte, 32)
_, err = rand.Read(preimage)
_, err := rand.Read(preimage)
if err != nil {
t.Fatalf("unable to generate preimage: %v", err)
}
@ -10397,8 +10205,7 @@ func testGraphTopologyNtfns(net *lntest.NetworkHarness, t *harnessTest, pinned b
// Spin up Bob first, since we will need to grab his pubkey when
// starting Alice to test pinned syncing.
bob, err := net.NewNode("bob", nil)
require.NoError(t.t, err)
bob := net.NewNode(t.t, "bob", nil)
defer shutdownAndAssert(net, t, bob)
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
@ -10416,8 +10223,7 @@ func testGraphTopologyNtfns(net *lntest.NetworkHarness, t *harnessTest, pinned b
}
}
alice, err := net.NewNode("alice", aliceArgs)
require.NoError(t.t, err)
alice := net.NewNode(t.t, "alice", aliceArgs)
defer shutdownAndAssert(net, t, alice)
// Connect Alice and Bob.
@ -10427,13 +10233,11 @@ func testGraphTopologyNtfns(net *lntest.NetworkHarness, t *harnessTest, pinned b
// Alice stimmy.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
err = net.SendCoins(ctxt, btcutil.SatoshiPerBitcoin, alice)
require.NoError(t.t, err)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, alice)
// Bob stimmy.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
err = net.SendCoins(ctxt, btcutil.SatoshiPerBitcoin, bob)
require.NoError(t.t, err)
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, bob)
// Assert that Bob has the correct sync type before proceeeding.
if pinned {
@ -10582,10 +10386,7 @@ out:
if err := net.DisconnectNodes(ctxt, alice, bob); err != nil {
t.Fatalf("unable to disconnect alice and bob: %v", err)
}
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)
@ -10687,10 +10488,7 @@ func testNodeAnnouncement(net *lntest.NetworkHarness, t *harnessTest) {
lndArgs = append(lndArgs, "--externalip="+addr)
}
dave, err := net.NewNode("Dave", lndArgs)
if err != nil {
t.Fatalf("unable to create new nodes: %v", err)
}
dave := net.NewNode(t.t, "Dave", lndArgs)
defer shutdownAndAssert(net, t, dave)
// We must let Dave have an open channel before he can send a node
@ -10811,10 +10609,7 @@ func testNodeSignVerify(net *lntest.NetworkHarness, t *harnessTest) {
}
// carol is a new node that is unconnected to alice or bob.
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)
carolMsg := []byte("carol msg")
@ -11368,10 +11163,7 @@ func testSwitchCircuitPersistence(net *lntest.NetworkHarness, t *harnessTest) {
// Carol -> Dave -> Alice -> Bob
//
// First, we'll create Dave and establish a channel to Alice.
dave, err := net.NewNode("Dave", nil)
if err != nil {
t.Fatalf("unable to create new nodes: %v", err)
}
dave := net.NewNode(t.t, "Dave", nil)
defer shutdownAndAssert(net, t, dave)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
@ -11379,10 +11171,8 @@ func testSwitchCircuitPersistence(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,
@ -11404,10 +11194,7 @@ func testSwitchCircuitPersistence(net *lntest.NetworkHarness, t *harnessTest) {
// Next, we'll create Carol and establish a channel to from her to
// Dave. Carol is started in htlchodl mode so that we can disconnect the
// intermediary hops before starting the settle.
carol, err := net.NewNode("Carol", []string{"--hodl.exit-settle"})
if err != nil {
t.Fatalf("unable to create new nodes: %v", err)
}
carol := net.NewNode(t.t, "Carol", []string{"--hodl.exit-settle"})
defer shutdownAndAssert(net, t, carol)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
@ -11415,10 +11202,8 @@ func testSwitchCircuitPersistence(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,
@ -11688,10 +11473,7 @@ func testSwitchOfflineDelivery(net *lntest.NetworkHarness, t *harnessTest) {
// Carol -> Dave -> Alice -> Bob
//
// First, we'll create Dave and establish a channel to Alice.
dave, err := net.NewNode("Dave", nil)
if err != nil {
t.Fatalf("unable to create new nodes: %v", err)
}
dave := net.NewNode(t.t, "Dave", nil)
defer shutdownAndAssert(net, t, dave)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
@ -11699,10 +11481,8 @@ func testSwitchOfflineDelivery(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,
@ -11724,10 +11504,7 @@ func testSwitchOfflineDelivery(net *lntest.NetworkHarness, t *harnessTest) {
// Next, we'll create Carol and establish a channel to from her to
// Dave. Carol is started in htlchodl mode so that we can disconnect the
// intermediary hops before starting the settle.
carol, err := net.NewNode("Carol", []string{"--hodl.exit-settle"})
if err != nil {
t.Fatalf("unable to create new nodes: %v", err)
}
carol := net.NewNode(t.t, "Carol", []string{"--hodl.exit-settle"})
defer shutdownAndAssert(net, t, carol)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
@ -11735,10 +11512,8 @@ func testSwitchOfflineDelivery(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,
@ -12027,10 +11802,7 @@ func testSwitchOfflineDeliveryPersistence(net *lntest.NetworkHarness, t *harness
// Carol -> Dave -> Alice -> Bob
//
// First, we'll create Dave and establish a channel to Alice.
dave, err := net.NewNode("Dave", nil)
if err != nil {
t.Fatalf("unable to create new nodes: %v", err)
}
dave := net.NewNode(t.t, "Dave", nil)
defer shutdownAndAssert(net, t, dave)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
@ -12038,10 +11810,8 @@ func testSwitchOfflineDeliveryPersistence(net *lntest.NetworkHarness, t *harness
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,
@ -12064,10 +11834,7 @@ func testSwitchOfflineDeliveryPersistence(net *lntest.NetworkHarness, t *harness
// Next, we'll create Carol and establish a channel to from her to
// Dave. Carol is started in htlchodl mode so that we can disconnect the
// intermediary hops before starting the settle.
carol, err := net.NewNode("Carol", []string{"--hodl.exit-settle"})
if err != nil {
t.Fatalf("unable to create new nodes: %v", err)
}
carol := net.NewNode(t.t, "Carol", []string{"--hodl.exit-settle"})
defer shutdownAndAssert(net, t, carol)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
@ -12075,10 +11842,8 @@ func testSwitchOfflineDeliveryPersistence(net *lntest.NetworkHarness, t *harness
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,
@ -12360,10 +12125,7 @@ func testSwitchOfflineDeliveryOutgoingOffline(
// Carol -> Dave -> Alice -> Bob
//
// First, we'll create Dave and establish a channel to Alice.
dave, err := net.NewNode("Dave", nil)
if err != nil {
t.Fatalf("unable to create new nodes: %v", err)
}
dave := net.NewNode(t.t, "Dave", nil)
defer shutdownAndAssert(net, t, dave)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
@ -12371,10 +12133,8 @@ func testSwitchOfflineDeliveryOutgoingOffline(
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,
@ -12396,19 +12156,14 @@ func testSwitchOfflineDeliveryOutgoingOffline(
// Next, we'll create Carol and establish a channel to from her to
// Dave. Carol is started in htlchodl mode so that we can disconnect the
// intermediary hops before starting the settle.
carol, err := net.NewNode("Carol", []string{"--hodl.exit-settle"})
if err != nil {
t.Fatalf("unable to create new nodes: %v", err)
}
carol := net.NewNode(t.t, "Carol", []string{"--hodl.exit-settle"})
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
if err := net.ConnectNodes(ctxt, carol, dave); err != nil {
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,
@ -12617,10 +12372,7 @@ func testQueryRoutes(net *lntest.NetworkHarness, t *harnessTest) {
networkChans = append(networkChans, chanPointAlice)
// Create Carol and establish a channel from Bob.
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)
@ -12628,10 +12380,8 @@ func testQueryRoutes(net *lntest.NetworkHarness, t *harnessTest) {
t.Fatalf("unable to connect carol to bob: %v", err)
}
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
err = net.SendCoins(ctxt, btcutil.SatoshiPerBitcoin, net.Bob)
if err != nil {
t.Fatalf("unable to send coins to bob: %v", err)
}
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, net.Bob)
ctxt, _ = context.WithTimeout(ctxb, channelOpenTimeout)
chanPointBob := openChannelAndAssert(
ctxt, t, net, net.Bob, carol,
@ -12642,10 +12392,7 @@ func testQueryRoutes(net *lntest.NetworkHarness, t *harnessTest) {
networkChans = append(networkChans, chanPointBob)
// Create Dave and establish a channel from Carol.
dave, err := net.NewNode("Dave", nil)
if err != nil {
t.Fatalf("unable to create new nodes: %v", err)
}
dave := net.NewNode(t.t, "Dave", nil)
defer shutdownAndAssert(net, t, dave)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
@ -12653,10 +12400,8 @@ func testQueryRoutes(net *lntest.NetworkHarness, t *harnessTest) {
t.Fatalf("unable to connect dave to carol: %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,
@ -12926,10 +12671,7 @@ func testRouteFeeCutoff(net *lntest.NetworkHarness, t *harnessTest) {
// Create Carol's node and open a channel between her and Alice with
// Alice being the funder.
carol, err := net.NewNode("Carol", nil)
if err != nil {
t.Fatalf("unable to create carol's node: %v", err)
}
carol := net.NewNode(t.t, "Carol", nil)
defer shutdownAndAssert(net, t, carol)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
@ -12937,10 +12679,8 @@ func testRouteFeeCutoff(net *lntest.NetworkHarness, t *harnessTest) {
t.Fatalf("unable to connect carol to alice: %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)
chanPointAliceCarol := openChannelAndAssert(
ctxt, t, net, net.Alice, carol,
@ -12951,10 +12691,7 @@ func testRouteFeeCutoff(net *lntest.NetworkHarness, t *harnessTest) {
// Create Dave's node and open a channel between him and Bob with Bob
// being the funder.
dave, err := net.NewNode("Dave", nil)
if err != nil {
t.Fatalf("unable to create dave's node: %v", err)
}
dave := net.NewNode(t.t, "Dave", nil)
defer shutdownAndAssert(net, t, dave)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
@ -13198,15 +12935,13 @@ func testSendUpdateDisableChannel(net *lntest.NetworkHarness, t *harnessTest) {
},
)
carol, err := net.NewNode("Carol", []string{
"--minbackoff=10s",
"--chan-enable-timeout=1.5s",
"--chan-disable-timeout=3s",
"--chan-status-sample-interval=.5s",
})
if err != nil {
t.Fatalf("unable to create carol's node: %v", err)
}
carol := net.NewNode(
t.t, "Carol", []string{
"--minbackoff=10s",
"--chan-enable-timeout=1.5s",
"--chan-disable-timeout=3s",
"--chan-status-sample-interval=.5s",
})
defer shutdownAndAssert(net, t, carol)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
@ -13224,23 +12959,18 @@ func testSendUpdateDisableChannel(net *lntest.NetworkHarness, t *harnessTest) {
// We create a new node Eve that has an inactive channel timeout of
// just 2 seconds (down from the default 20m). It will be used to test
// channel updates for channels going inactive.
eve, err := net.NewNode("Eve", []string{
"--minbackoff=10s",
"--chan-enable-timeout=1.5s",
"--chan-disable-timeout=3s",
"--chan-status-sample-interval=.5s",
})
if err != nil {
t.Fatalf("unable to create eve's node: %v", err)
}
eve := net.NewNode(
t.t, "Eve", []string{
"--minbackoff=10s",
"--chan-enable-timeout=1.5s",
"--chan-disable-timeout=3s",
"--chan-status-sample-interval=.5s",
})
defer shutdownAndAssert(net, t, eve)
// Give Eve some coins.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
err = net.SendCoins(ctxt, btcutil.SatoshiPerBitcoin, eve)
if err != nil {
t.Fatalf("unable to send coins to eve: %v", err)
}
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, eve)
// Connect Eve to Carol and Bob, and open a channel to carol.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
@ -13263,10 +12993,7 @@ func testSendUpdateDisableChannel(net *lntest.NetworkHarness, t *harnessTest) {
// Launch a node for Dave which will connect to Bob in order to receive
// graph updates from. This will ensure that the channel updates are
// propagated throughout the network.
dave, err := net.NewNode("Dave", nil)
if err != nil {
t.Fatalf("unable to create dave's node: %v", err)
}
dave := net.NewNode(t.t, "Dave", nil)
defer shutdownAndAssert(net, t, dave)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
@ -13588,24 +13315,16 @@ func testSweepAllCoins(net *lntest.NetworkHarness, t *harnessTest) {
// First, we'll make a new node, ainz who'll we'll use to test wallet
// sweeping.
ainz, err := net.NewNode("Ainz", nil)
if err != nil {
t.Fatalf("unable to create new node: %v", err)
}
ainz := net.NewNode(t.t, "Ainz", nil)
defer shutdownAndAssert(net, t, ainz)
// Next, we'll give Ainz exactly 2 utxos of 1 BTC each, with one of
// them being p2wkh and the other being a n2wpkh address.
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
err = net.SendCoins(ctxt, btcutil.SatoshiPerBitcoin, ainz)
if err != nil {
t.Fatalf("unable to send coins to eve: %v", err)
}
net.SendCoins(ctxt, t.t, btcutil.SatoshiPerBitcoin, ainz)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
err = net.SendCoinsNP2WKH(ctxt, btcutil.SatoshiPerBitcoin, ainz)
if err != nil {
t.Fatalf("unable to send coins to eve: %v", err)
}
net.SendCoinsNP2WKH(ctxt, t.t, btcutil.SatoshiPerBitcoin, ainz)
// Ensure that we can't send coins to our own Pubkey.
info, err := ainz.GetInfo(ctxt, &lnrpc.GetInfoRequest{})
@ -14123,7 +13842,9 @@ func TestLightningNetworkDaemon(t *testing.T) {
testCase.name, " ", "_",
)
err = lndHarness.SetUp(cleanTestCaseName, aliceBobArgs)
err = lndHarness.SetUp(
t1, cleanTestCaseName, aliceBobArgs,
)
require.NoError(t1,
err, "unable to set up test lightning network",
)

@ -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.