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

itest: use require inside net.SendCoins
This commit is contained in:
Olaoluwa Osuntokun authored and GitHub committed 2021-06-18 14:12:39 -07:00
commit 2fd75ace9d
16 files changed
+285 -687

No files matched your search

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