itest: use require inside net.SendCoins

This commit refactored the function SendCoins to take a new *testing.T
so the unexpected error is handled inside it.
This commit is contained in:
yyforyongyu 2021-06-10 01:29:22 +08:00
parent b42bb87c81
commit 6515c575bd
No known key found for this signature in database
GPG Key ID: 9BCD95C4FF296868
12 changed files with 105 additions and 243 deletions

@ -1351,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

@ -849,15 +849,10 @@ func testChanRestoreScenario(t *harnessTest, net *lntest.NetworkHarness,
// 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 {

@ -313,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(

@ -43,8 +43,7 @@ func testBasicChannelFunding(net *lntest.NetworkHarness, t *harnessTest) {
// 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 := net.NewNode(t.t, "Dave", daveArgs)
@ -53,7 +52,7 @@ func testBasicChannelFunding(net *lntest.NetworkHarness, t *harnessTest) {
// 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(
@ -263,8 +262,7 @@ func testUnconfirmedChannelFunding(net *lntest.NetworkHarness, t *harnessTest) {
// 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.
@ -391,13 +389,12 @@ func testExternalFundingChanPoint(net *lntest.NetworkHarness, t *harnessTest) {
// 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,15 +30,12 @@ func testMaxChannelSize(net *lntest.NetworkHarness, t *harnessTest) {
// 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)
}

@ -296,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(

@ -55,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,
@ -86,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,

@ -219,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,
@ -274,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

@ -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{
@ -190,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()

@ -31,16 +31,13 @@ func testPsbtChanFunding(net *lntest.NetworkHarness, t *harnessTest) {
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)
}
}
}
@ -1659,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)
@ -2406,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)
@ -3166,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,
@ -4477,10 +4451,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,
@ -4502,10 +4474,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,
@ -4708,10 +4678,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
@ -4732,7 +4699,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)
@ -4856,10 +4823,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.
@ -4875,7 +4839,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)
@ -5461,10 +5425,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.
@ -5833,10 +5794,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,
@ -6008,19 +5967,13 @@ func testSendToRouteErrorPropagation(net *lntest.NetworkHarness, t *harnessTest)
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 := 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 {
@ -6254,10 +6207,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,
@ -6285,10 +6236,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,
@ -6860,10 +6809,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,
@ -7506,9 +7453,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
@ -8115,10 +8060,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
@ -8386,10 +8328,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
@ -8631,10 +8570,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
@ -9142,10 +9078,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
@ -9651,10 +9584,7 @@ func testDataLossProtection(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)
// 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
@ -10003,16 +9933,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)
@ -10039,7 +9963,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)
}
@ -10289,13 +10213,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 {
@ -11229,10 +11151,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,
@ -11262,10 +11182,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,
@ -11543,10 +11461,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,
@ -11576,10 +11492,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,
@ -11876,10 +11790,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,
@ -11910,10 +11822,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,
@ -12203,10 +12113,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,
@ -12234,10 +12142,8 @@ func testSwitchOfflineDeliveryOutgoingOffline(
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,
@ -12454,10 +12360,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,
@ -12476,10 +12380,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,
@ -12757,10 +12659,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,
@ -13050,10 +12950,7 @@ func testSendUpdateDisableChannel(net *lntest.NetworkHarness, t *harnessTest) {
// 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)
@ -13404,15 +13301,10 @@ func testSweepAllCoins(net *lntest.NetworkHarness, t *harnessTest) {
// 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{})

@ -29,15 +29,12 @@ func testWumboChannels(net *lntest.NetworkHarness, t *harnessTest) {
// 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)
}