mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 09:53:54 +01:00
itest: fix make lint
This commit fixes the issues reported by the linter.
This commit is contained in:
parent
a080375b7d
commit
2bc6aabf96
@ -376,6 +376,8 @@ func testChannelBackupRestoreBasic(ht *lntest.HarnessTest) {
|
||||
// Now that we have Dave's backup file, we'll
|
||||
// create a new nodeRestorer that will restore
|
||||
// using the on-disk channel.backup.
|
||||
//
|
||||
//nolint:lll
|
||||
backup := &lnrpc.RestoreChanBackupRequest_MultiChanBackup{
|
||||
MultiChanBackup: multi,
|
||||
}
|
||||
@ -606,7 +608,7 @@ func runChanRestoreScenarioCommitTypes(ht *lntest.HarnessTest,
|
||||
_, minerHeight := ht.Miner.GetBestBlock()
|
||||
thawHeight := uint32(minerHeight + thawHeightDelta)
|
||||
|
||||
fundingShim, _, _ = deriveFundingShim(
|
||||
fundingShim, _ = deriveFundingShim(
|
||||
ht, dave, carol, crs.params.Amt, thawHeight, true,
|
||||
)
|
||||
crs.params.FundingShim = fundingShim
|
||||
@ -1022,17 +1024,20 @@ func testExportChannelBackup(ht *lntest.HarnessTest) {
|
||||
require.NoError(ht, err, "timeout checking num single backup")
|
||||
}
|
||||
|
||||
assertMultiBackupFound := func() func(bool, map[wire.OutPoint]struct{}) {
|
||||
assertMultiBackupFound := func() func(bool,
|
||||
map[wire.OutPoint]struct{}) {
|
||||
|
||||
chanSnapshot := carol.RPC.ExportAllChanBackups()
|
||||
|
||||
return func(found bool, chanPoints map[wire.OutPoint]struct{}) {
|
||||
num := len(chanSnapshot.MultiChanBackup.MultiChanBackup)
|
||||
|
||||
switch {
|
||||
case found && chanSnapshot.MultiChanBackup == nil:
|
||||
require.Fail(ht, "multi-backup not present")
|
||||
|
||||
case !found && chanSnapshot.MultiChanBackup != nil &&
|
||||
(len(chanSnapshot.MultiChanBackup.MultiChanBackup) !=
|
||||
chanbackup.NilMultiSizePacked):
|
||||
num != chanbackup.NilMultiSizePacked:
|
||||
|
||||
require.Fail(ht, "found multi-backup when "+
|
||||
"non should be found")
|
||||
@ -1295,8 +1300,9 @@ func createLegacyRevocationChannel(ht *lntest.HarnessTest,
|
||||
}
|
||||
fundResp := from.RPC.FundPsbt(fundReq)
|
||||
|
||||
// We have a PSBT that has no witness data yet, which is exactly what we
|
||||
// need for the next step of verifying the PSBT with the funding intents.
|
||||
// We have a PSBT that has no witness data yet, which is exactly what
|
||||
// we need for the next step of verifying the PSBT with the funding
|
||||
// intents.
|
||||
msg := &lnrpc.FundingTransitionMsg{
|
||||
Trigger: &lnrpc.FundingTransitionMsg_PsbtVerify{
|
||||
PsbtVerify: &lnrpc.FundingPsbtVerify{
|
||||
|
@ -602,6 +602,18 @@ func channelForceClosureTest(ht *lntest.HarnessTest,
|
||||
|
||||
// checkForceClosedChannelNumHtlcs verifies that a force closed channel
|
||||
// has the proper number of htlcs.
|
||||
checkPendingChannelNumHtlcs := func(
|
||||
forceClose lntest.PendingForceClose) error {
|
||||
|
||||
if len(forceClose.PendingHtlcs) != numInvoices {
|
||||
return fmt.Errorf("expected force closed channel to "+
|
||||
"have %d pending htlcs, found %d instead",
|
||||
numInvoices, len(forceClose.PendingHtlcs))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
err = wait.NoError(func() error {
|
||||
// Now that the commit output has been fully swept, check to
|
||||
// see that the channel remains open for the pending htlc
|
||||
@ -613,7 +625,7 @@ func channelForceClosureTest(ht *lntest.HarnessTest,
|
||||
// The commitment funds will have been recovered after the
|
||||
// commit txn was included in the last block. The htlc funds
|
||||
// will be shown in limbo.
|
||||
err := checkPendingChannelNumHtlcs(forceClose, numInvoices)
|
||||
err := checkPendingChannelNumHtlcs(forceClose)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -661,7 +673,7 @@ func channelForceClosureTest(ht *lntest.HarnessTest,
|
||||
|
||||
// We should now be at the block just before the utxo nursery
|
||||
// will attempt to broadcast the htlc timeout transactions.
|
||||
err = checkPendingChannelNumHtlcs(forceClose, numInvoices)
|
||||
err = checkPendingChannelNumHtlcs(forceClose)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -704,9 +716,9 @@ func channelForceClosureTest(ht *lntest.HarnessTest,
|
||||
|
||||
// Retrieve each htlc timeout txn from the mempool, and ensure it is
|
||||
// well-formed. This entails verifying that each only spends from
|
||||
// output, and that that output is from the commitment txn. In case
|
||||
// this is an anchor channel, the transactions are aggregated by the
|
||||
// sweeper into one.
|
||||
// output, and that output is from the commitment txn. In case this is
|
||||
// an anchor channel, the transactions are aggregated by the sweeper
|
||||
// into one.
|
||||
numInputs := 1
|
||||
if channelType == lnrpc.CommitmentType_ANCHORS {
|
||||
numInputs = numInvoices + 1
|
||||
@ -798,7 +810,7 @@ func channelForceClosureTest(ht *lntest.HarnessTest,
|
||||
|
||||
// We record the htlc amount less fees here, so that we know
|
||||
// what value to expect for the second stage of our htlc
|
||||
// htlc resolution.
|
||||
// resolution.
|
||||
htlcLessFees = uint64(outputs[0].Value)
|
||||
}
|
||||
|
||||
@ -840,7 +852,7 @@ func channelForceClosureTest(ht *lntest.HarnessTest,
|
||||
return fmt.Errorf("htlc funds should still be in limbo")
|
||||
}
|
||||
|
||||
return checkPendingChannelNumHtlcs(forceClose, numInvoices)
|
||||
return checkPendingChannelNumHtlcs(forceClose)
|
||||
}, defaultTimeout)
|
||||
require.NoError(ht, err, "timeout while checking force closed channel")
|
||||
|
||||
@ -915,7 +927,7 @@ func channelForceClosureTest(ht *lntest.HarnessTest,
|
||||
forceClose := ht.AssertChannelPendingForceClose(
|
||||
alice, chanPoint,
|
||||
)
|
||||
err := checkPendingChannelNumHtlcs(forceClose, numInvoices)
|
||||
err := checkPendingChannelNumHtlcs(forceClose)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -1111,23 +1123,6 @@ func checkCommitmentMaturity(forceClose lntest.PendingForceClose,
|
||||
return nil
|
||||
}
|
||||
|
||||
// checkForceClosedChannelNumHtlcs verifies that a force closed channel has the
|
||||
// proper number of htlcs.
|
||||
//
|
||||
// NOTE: only used in current test file.
|
||||
func checkPendingChannelNumHtlcs(
|
||||
forceClose *lnrpc.PendingChannelsResponse_ForceClosedChannel,
|
||||
expectedNumHtlcs int) error {
|
||||
|
||||
if len(forceClose.PendingHtlcs) != expectedNumHtlcs {
|
||||
return fmt.Errorf("expected force closed channel to have %d "+
|
||||
"pending htlcs, found %d instead", expectedNumHtlcs,
|
||||
len(forceClose.PendingHtlcs))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// checkPendingHtlcStageAndMaturity uniformly tests all pending htlc's belonging
|
||||
// to a force closed channel, testing for the expected stage number, blocks till
|
||||
// maturity, and the maturity height.
|
||||
|
@ -167,9 +167,9 @@ func testUpdateChannelPolicy(ht *lntest.HarnessTest) {
|
||||
payAmt = btcutil.Amount(4)
|
||||
amtSat := int64(payAmt)
|
||||
amtMSat := int64(lnwire.NewMSatFromSatoshis(payAmt))
|
||||
routes.Routes[0].Hops[0].AmtToForward = amtSat // nolint:staticcheck
|
||||
routes.Routes[0].Hops[0].AmtToForward = amtSat
|
||||
routes.Routes[0].Hops[0].AmtToForwardMsat = amtMSat
|
||||
routes.Routes[0].Hops[1].AmtToForward = amtSat // nolint:staticcheck
|
||||
routes.Routes[0].Hops[1].AmtToForward = amtSat
|
||||
routes.Routes[0].Hops[1].AmtToForwardMsat = amtMSat
|
||||
|
||||
// Send the payment with the modified value.
|
||||
@ -200,9 +200,9 @@ func testUpdateChannelPolicy(ht *lntest.HarnessTest) {
|
||||
payAmt = btcutil.Amount(5)
|
||||
amtSat = int64(payAmt)
|
||||
amtMSat = int64(lnwire.NewMSatFromSatoshis(payAmt))
|
||||
routes.Routes[0].Hops[0].AmtToForward = amtSat // nolint:staticcheck
|
||||
routes.Routes[0].Hops[0].AmtToForward = amtSat
|
||||
routes.Routes[0].Hops[0].AmtToForwardMsat = amtMSat
|
||||
routes.Routes[0].Hops[1].AmtToForward = amtSat // nolint:staticcheck
|
||||
routes.Routes[0].Hops[1].AmtToForward = amtSat
|
||||
routes.Routes[0].Hops[1].AmtToForwardMsat = amtMSat
|
||||
|
||||
// Manually set the MPP payload a new for each payment since
|
||||
|
@ -416,6 +416,7 @@ func (c *interceptorTestScenario) prepareTestCases() []*interceptorTestCase {
|
||||
t.invoice = invoice
|
||||
t.payAddr = payReq.PaymentAddr
|
||||
}
|
||||
|
||||
return cases
|
||||
}
|
||||
|
||||
|
@ -501,7 +501,7 @@ func testExternalFundingChanPoint(ht *lntest.HarnessTest) {
|
||||
// a transaction that will never be published.
|
||||
const thawHeight uint32 = 10
|
||||
const chanSize = funding.MaxBtcFundingAmount
|
||||
fundingShim1, chanPoint1, _ := deriveFundingShim(
|
||||
fundingShim1, chanPoint1 := deriveFundingShim(
|
||||
ht, carol, dave, chanSize, thawHeight, false,
|
||||
)
|
||||
ht.OpenChannelAssertPending(
|
||||
@ -517,7 +517,7 @@ func testExternalFundingChanPoint(ht *lntest.HarnessTest) {
|
||||
// externally funded, we should still be able to open another one. Let's
|
||||
// do exactly that now. For this one we publish the transaction so we
|
||||
// can mine it later.
|
||||
fundingShim2, chanPoint2, _ := deriveFundingShim(
|
||||
fundingShim2, chanPoint2 := deriveFundingShim(
|
||||
ht, carol, dave, chanSize, thawHeight, true,
|
||||
)
|
||||
|
||||
@ -801,7 +801,7 @@ func testBatchChanFunding(ht *lntest.HarnessTest) {
|
||||
func deriveFundingShim(ht *lntest.HarnessTest,
|
||||
carol, dave *node.HarnessNode, chanSize btcutil.Amount,
|
||||
thawHeight uint32, publish bool) (*lnrpc.FundingShim,
|
||||
*lnrpc.ChannelPoint, *chainhash.Hash) {
|
||||
*lnrpc.ChannelPoint) {
|
||||
|
||||
keyLoc := &signrpc.KeyLocator{KeyFamily: 9999}
|
||||
carolFundingKey := carol.RPC.DeriveKey(keyLoc)
|
||||
@ -887,5 +887,5 @@ func deriveFundingShim(ht *lntest.HarnessTest,
|
||||
}
|
||||
fundingShim.GetChanPointShim().RemoteKey = daveFundingKey.RawKeyBytes
|
||||
|
||||
return fundingShim, chanPoint, txid
|
||||
return fundingShim, chanPoint
|
||||
}
|
||||
|
@ -964,7 +964,8 @@ func testListAddresses(ht *lntest.HarnessTest) {
|
||||
})
|
||||
generatedAddr[resp.Address] = addressDetails{
|
||||
Balance: 400_000,
|
||||
Type: walletrpc.AddressType_HYBRID_NESTED_WITNESS_PUBKEY_HASH,
|
||||
Type: walletrpc.
|
||||
AddressType_HYBRID_NESTED_WITNESS_PUBKEY_HASH,
|
||||
}
|
||||
|
||||
for addr, addressDetail := range generatedAddr {
|
||||
|
@ -46,7 +46,6 @@ func testHtlcErrorPropagation(ht *lntest.HarnessTest) {
|
||||
// channel between them so we have the topology: Alice -> Bob -> Carol.
|
||||
// The channel created will be of lower capacity that the one created
|
||||
// above.
|
||||
const bobChanAmt = funding.MaxBtcFundingAmount
|
||||
chanPointBob := ht.OpenChannel(
|
||||
bob, carol, lntest.OpenChannelParams{Amt: chanAmt},
|
||||
)
|
||||
|
@ -1774,7 +1774,7 @@ func createThreeHopNetwork(ht *lntest.HarnessTest,
|
||||
if c == lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE {
|
||||
_, minerHeight := ht.Miner.GetBestBlock()
|
||||
thawHeight = uint32(minerHeight + thawHeightDelta)
|
||||
aliceFundingShim, _, _ = deriveFundingShim(
|
||||
aliceFundingShim, _ = deriveFundingShim(
|
||||
ht, alice, bob, chanAmt, thawHeight, true,
|
||||
)
|
||||
}
|
||||
@ -1807,7 +1807,7 @@ func createThreeHopNetwork(ht *lntest.HarnessTest,
|
||||
// open, our topology looks like: A -> B -> C.
|
||||
var bobFundingShim *lnrpc.FundingShim
|
||||
if c == lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE {
|
||||
bobFundingShim, _, _ = deriveFundingShim(
|
||||
bobFundingShim, _ = deriveFundingShim(
|
||||
ht, bob, carol, chanAmt, thawHeight, true,
|
||||
)
|
||||
}
|
||||
|
@ -172,6 +172,7 @@ func runCPFP(ht *lntest.HarnessTest, alice, bob *node.HarnessNode) {
|
||||
return fmt.Errorf("expected 0 pending sweeps, found %d",
|
||||
len(resp.PendingSweeps))
|
||||
}
|
||||
|
||||
return nil
|
||||
}, defaultTimeout)
|
||||
require.NoError(ht, err, "timeout checking bob's pending sweeps")
|
||||
@ -276,6 +277,7 @@ func testAnchorReservedValue(ht *lntest.HarnessTest) {
|
||||
}
|
||||
|
||||
balance = resp.TotalBalance
|
||||
|
||||
return nil
|
||||
}, defaultTimeout)
|
||||
require.NoError(ht, err, "timeout checking alice's balance")
|
||||
|
@ -2,8 +2,6 @@ package itest
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec/v2"
|
||||
@ -1183,39 +1181,6 @@ func deriveInternalKey(ht *lntest.HarnessTest,
|
||||
return keyDesc, parsedPubKey, fullDerivationPath
|
||||
}
|
||||
|
||||
// receiveChanUpdate waits until a message is received on the stream or the
|
||||
// context is canceled. The context must have a timeout or must be canceled
|
||||
// in case no message is received, otherwise this function will block forever.
|
||||
func receiveChanUpdate(ctx context.Context,
|
||||
stream lnrpc.Lightning_OpenChannelClient) (*lnrpc.OpenStatusUpdate,
|
||||
error) {
|
||||
|
||||
chanMsg := make(chan *lnrpc.OpenStatusUpdate)
|
||||
errChan := make(chan error)
|
||||
go func() {
|
||||
// Consume one message. This will block until the message is
|
||||
// received.
|
||||
resp, err := stream.Recv()
|
||||
if err != nil {
|
||||
errChan <- err
|
||||
return
|
||||
}
|
||||
chanMsg <- resp
|
||||
}()
|
||||
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return nil, fmt.Errorf("timeout reached before chan pending " +
|
||||
"update sent")
|
||||
|
||||
case err := <-errChan:
|
||||
return nil, err
|
||||
|
||||
case updateMsg := <-chanMsg:
|
||||
return updateMsg, nil
|
||||
}
|
||||
}
|
||||
|
||||
// sendAllCoinsToAddrType sweeps all coins from the wallet and sends them to a
|
||||
// new address of the given type.
|
||||
func sendAllCoinsToAddrType(ht *lntest.HarnessTest,
|
||||
|
@ -476,6 +476,8 @@ func testSendToRouteErrorPropagation(ht *lntest.HarnessTest) {
|
||||
// testPrivateChannels tests that a private channel can be used for
|
||||
// routing by the two endpoints of the channel, but is not known by
|
||||
// the rest of the nodes in the graph.
|
||||
//
|
||||
//nolint:dupword
|
||||
func testPrivateChannels(ht *lntest.HarnessTest) {
|
||||
const chanAmt = btcutil.Amount(100000)
|
||||
|
||||
@ -1285,7 +1287,8 @@ func testRouteFeeCutoff(ht *lntest.HarnessTest) {
|
||||
case *lnrpc.FeeLimit_Fixed:
|
||||
sendReq.FeeLimitMsat = 1000 * limit.Fixed
|
||||
case *lnrpc.FeeLimit_Percent:
|
||||
sendReq.FeeLimitMsat = 1000 * paymentAmt * limit.Percent / 100
|
||||
sendReq.FeeLimitMsat = 1000 * paymentAmt *
|
||||
limit.Percent / 100
|
||||
}
|
||||
|
||||
result := ht.SendPaymentAssertSettled(alice, sendReq)
|
||||
|
@ -131,11 +131,6 @@ func testSwitchOfflineDelivery(ht *lntest.HarnessTest) {
|
||||
// Wait until all outstanding htlcs in the network have been settled.
|
||||
s.assertHTLCs(ht, 0)
|
||||
|
||||
// When asserting the amount of satoshis moved, we'll factor in the
|
||||
// default base fee, as we didn't modify the fee structure when
|
||||
// creating the seed nodes in the network.
|
||||
const baseFee = 1
|
||||
|
||||
// At this point all the channels within our proto network should be
|
||||
// shifted by 5k satoshis in the direction of Carol, the sink within the
|
||||
// payment flow generated above. The order of asserts corresponds to
|
||||
@ -174,6 +169,8 @@ func testSwitchOfflineDelivery(ht *lntest.HarnessTest) {
|
||||
// 3. Carol --- Dave X Alice <-- Bob settle last hop
|
||||
// 4. Carol --- Dave X X Bob restart Alice
|
||||
// 5. Carol <-- Dave <-- Alice --- Bob expect settle to propagate
|
||||
//
|
||||
//nolint:dupword
|
||||
func testSwitchOfflineDeliveryPersistence(ht *lntest.HarnessTest) {
|
||||
// Setup our test scenario. We should now have four nodes running with
|
||||
// three channels.
|
||||
@ -260,6 +257,8 @@ func testSwitchOfflineDeliveryPersistence(ht *lntest.HarnessTest) {
|
||||
// 3. Carol --- Dave X Alice <-- Bob settle last hop
|
||||
// 4. Carol --- Dave X X shutdown Bob, restart Alice
|
||||
// 5. Carol <-- Dave <-- Alice X expect settle to propagate
|
||||
//
|
||||
//nolint:dupword
|
||||
func testSwitchOfflineDeliveryOutgoingOffline(ht *lntest.HarnessTest) {
|
||||
// Setup our test scenario. We should now have four nodes running with
|
||||
// three channels. Note that we won't call the cleanUp function here as
|
||||
|
@ -260,9 +260,7 @@ func testTaprootSignOutputRawScriptSpend(ht *lntest.HarnessTest,
|
||||
require.NoError(ht, err)
|
||||
|
||||
// Send some coins to the generated tapscript address.
|
||||
p2trOutpoint, p2trPkScript := sendToTaprootOutput(
|
||||
ht, alice, taprootKey, testAmount,
|
||||
)
|
||||
p2trOutpoint, p2trPkScript := sendToTaprootOutput(ht, alice, taprootKey)
|
||||
|
||||
// Spend the output again, this time back to a p2wkh address.
|
||||
p2wkhAddr, p2wkhPkScript := newAddrWithScript(
|
||||
@ -413,9 +411,7 @@ func testTaprootSignOutputRawKeySpendBip86(ht *lntest.HarnessTest,
|
||||
taprootKey := txscript.ComputeTaprootKeyNoScript(internalKey)
|
||||
|
||||
// Send some coins to the generated tapscript address.
|
||||
p2trOutpoint, p2trPkScript := sendToTaprootOutput(
|
||||
ht, alice, taprootKey, testAmount,
|
||||
)
|
||||
p2trOutpoint, p2trPkScript := sendToTaprootOutput(ht, alice, taprootKey)
|
||||
|
||||
// Spend the output again, this time back to a p2wkh address.
|
||||
p2wkhAddr, p2wkhPkScript := newAddrWithScript(
|
||||
@ -514,9 +510,7 @@ func testTaprootSignOutputRawKeySpendRootHash(ht *lntest.HarnessTest,
|
||||
taprootKey := txscript.ComputeTaprootOutputKey(internalKey, rootHash[:])
|
||||
|
||||
// Send some coins to the generated tapscript address.
|
||||
p2trOutpoint, p2trPkScript := sendToTaprootOutput(
|
||||
ht, alice, taprootKey, testAmount,
|
||||
)
|
||||
p2trOutpoint, p2trPkScript := sendToTaprootOutput(ht, alice, taprootKey)
|
||||
|
||||
// Spend the output again, this time back to a p2wkh address.
|
||||
p2wkhAddr, p2wkhPkScript := newAddrWithScript(
|
||||
@ -601,9 +595,7 @@ func testTaprootMuSig2KeySpendBip86(ht *lntest.HarnessTest,
|
||||
)
|
||||
|
||||
// Send some coins to the generated tapscript address.
|
||||
p2trOutpoint, p2trPkScript := sendToTaprootOutput(
|
||||
ht, alice, taprootKey, testAmount,
|
||||
)
|
||||
p2trOutpoint, p2trPkScript := sendToTaprootOutput(ht, alice, taprootKey)
|
||||
|
||||
// Spend the output again, this time back to a p2wkh address.
|
||||
p2wkhAddr, p2wkhPkScript := newAddrWithScript(
|
||||
@ -733,9 +725,7 @@ func testTaprootMuSig2KeySpendRootHash(ht *lntest.HarnessTest,
|
||||
)
|
||||
|
||||
// Send some coins to the generated tapscript address.
|
||||
p2trOutpoint, p2trPkScript := sendToTaprootOutput(
|
||||
ht, alice, taprootKey, testAmount,
|
||||
)
|
||||
p2trOutpoint, p2trPkScript := sendToTaprootOutput(ht, alice, taprootKey)
|
||||
|
||||
// Spend the output again, this time back to a p2wkh address.
|
||||
p2wkhAddr, p2wkhPkScript := newAddrWithScript(
|
||||
@ -870,9 +860,7 @@ func testTaprootMuSig2ScriptSpend(ht *lntest.HarnessTest,
|
||||
tapscript := input.TapscriptFullTree(internalKey, leaf1)
|
||||
|
||||
// Send some coins to the generated tapscript address.
|
||||
p2trOutpoint, p2trPkScript := sendToTaprootOutput(
|
||||
ht, alice, taprootKey, testAmount,
|
||||
)
|
||||
p2trOutpoint, p2trPkScript := sendToTaprootOutput(ht, alice, taprootKey)
|
||||
|
||||
// Spend the output again, this time back to a p2wkh address.
|
||||
p2wkhAddr, p2wkhPkScript := newAddrWithScript(
|
||||
@ -951,9 +939,7 @@ func testTaprootMuSig2CombinedLeafKeySpend(ht *lntest.HarnessTest,
|
||||
require.NoError(ht, err)
|
||||
|
||||
// Send some coins to the generated tapscript address.
|
||||
p2trOutpoint, p2trPkScript := sendToTaprootOutput(
|
||||
ht, alice, taprootKey, testAmount,
|
||||
)
|
||||
p2trOutpoint, p2trPkScript := sendToTaprootOutput(ht, alice, taprootKey)
|
||||
|
||||
// Spend the output again, this time back to a p2wkh address.
|
||||
p2wkhAddr, p2wkhPkScript := newAddrWithScript(
|
||||
@ -1151,9 +1137,7 @@ func testTaprootImportTapscriptFullTree(ht *lntest.HarnessTest,
|
||||
require.Equal(ht, calculatedAddr.String(), importResp.P2TrAddress)
|
||||
|
||||
// Send some coins to the generated tapscript address.
|
||||
p2trOutpoint, p2trPkScript := sendToTaprootOutput(
|
||||
ht, alice, taprootKey, testAmount,
|
||||
)
|
||||
p2trOutpoint, p2trPkScript := sendToTaprootOutput(ht, alice, taprootKey)
|
||||
p2trOutputRPC := &lnrpc.OutPoint{
|
||||
TxidBytes: p2trOutpoint.Hash[:],
|
||||
OutputIndex: p2trOutpoint.Index,
|
||||
@ -1221,9 +1205,7 @@ func testTaprootImportTapscriptPartialReveal(ht *lntest.HarnessTest,
|
||||
require.Equal(ht, calculatedAddr.String(), importResp.P2TrAddress)
|
||||
|
||||
// Send some coins to the generated tapscript address.
|
||||
p2trOutpoint, p2trPkScript := sendToTaprootOutput(
|
||||
ht, alice, taprootKey, testAmount,
|
||||
)
|
||||
p2trOutpoint, p2trPkScript := sendToTaprootOutput(ht, alice, taprootKey)
|
||||
|
||||
p2trOutputRPC := &lnrpc.OutPoint{
|
||||
TxidBytes: p2trOutpoint.Hash[:],
|
||||
@ -1280,9 +1262,7 @@ func testTaprootImportTapscriptRootHashOnly(ht *lntest.HarnessTest,
|
||||
require.Equal(ht, calculatedAddr.String(), importResp.P2TrAddress)
|
||||
|
||||
// Send some coins to the generated tapscript address.
|
||||
p2trOutpoint, p2trPkScript := sendToTaprootOutput(
|
||||
ht, alice, taprootKey, testAmount,
|
||||
)
|
||||
p2trOutpoint, p2trPkScript := sendToTaprootOutput(ht, alice, taprootKey)
|
||||
|
||||
p2trOutputRPC := &lnrpc.OutPoint{
|
||||
TxidBytes: p2trOutpoint.Hash[:],
|
||||
@ -1339,9 +1319,7 @@ func testTaprootImportTapscriptFullKey(ht *lntest.HarnessTest,
|
||||
require.Equal(ht, calculatedAddr.String(), importResp.P2TrAddress)
|
||||
|
||||
// Send some coins to the generated tapscript address.
|
||||
p2trOutpoint, p2trPkScript := sendToTaprootOutput(
|
||||
ht, alice, taprootKey, testAmount,
|
||||
)
|
||||
p2trOutpoint, p2trPkScript := sendToTaprootOutput(ht, alice, taprootKey)
|
||||
|
||||
p2trOutputRPC := &lnrpc.OutPoint{
|
||||
TxidBytes: p2trOutpoint.Hash[:],
|
||||
@ -1480,7 +1458,7 @@ func newAddrWithScript(ht *lntest.HarnessTest, node *node.HarnessNode,
|
||||
// sendToTaprootOutput sends coins to a p2tr output of the given taproot key and
|
||||
// mines a block to confirm the coins.
|
||||
func sendToTaprootOutput(ht *lntest.HarnessTest, hn *node.HarnessNode,
|
||||
taprootKey *btcec.PublicKey, amt int64) (wire.OutPoint, []byte) {
|
||||
taprootKey *btcec.PublicKey) (wire.OutPoint, []byte) {
|
||||
|
||||
tapScriptAddr, err := btcutil.NewAddressTaproot(
|
||||
schnorr.SerializePubKey(taprootKey), harnessNetParams,
|
||||
@ -1492,7 +1470,7 @@ func sendToTaprootOutput(ht *lntest.HarnessTest, hn *node.HarnessNode,
|
||||
// Send some coins to the generated tapscript address.
|
||||
req := &lnrpc.SendCoinsRequest{
|
||||
Addr: tapScriptAddr.String(),
|
||||
Amount: amt,
|
||||
Amount: testAmount,
|
||||
}
|
||||
hn.RPC.SendCoins(req)
|
||||
|
||||
|
@ -9,8 +9,6 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
type pendingChan *lnrpc.PendingChannelsResponse_PendingChannel
|
||||
|
||||
// testWipeForwardingPackagesLocal tests that when a channel is closed, either
|
||||
// through local force close, remote close, or coop close, all the forwarding
|
||||
// packages of that particular channel are deleted. The test creates a
|
||||
|
@ -312,6 +312,7 @@ func optionScidAliasScenario(ht *lntest.HarnessTest, chantype, private bool) {
|
||||
require.Len(ht, decodedReq.RouteHints, 0)
|
||||
payReq := daveInvoiceResp2.PaymentRequest
|
||||
ht.CompletePaymentRequests(bob, []string{payReq})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -103,7 +103,7 @@ func NewBackend(miner string, netParams *chaincfg.Params) (
|
||||
netParams, nil, args, node.GetBtcdBinary(),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("unable to create btcd node: %v",
|
||||
return nil, nil, fmt.Errorf("unable to create btcd node: %w",
|
||||
err)
|
||||
}
|
||||
|
||||
@ -112,11 +112,16 @@ func NewBackend(miner string, netParams *chaincfg.Params) (
|
||||
// are already blocks present, which will take a bit longer than the
|
||||
// 1 second the default settings amount to. Doubling both values will
|
||||
// give us retries up to 4 seconds.
|
||||
chainBackend.MaxConnRetries = rpctest.DefaultMaxConnectionRetries * 2
|
||||
chainBackend.ConnectionRetryTimeout = rpctest.DefaultConnectionRetryTimeout * 2
|
||||
const (
|
||||
maxConnRetries = rpctest.DefaultMaxConnectionRetries * 2
|
||||
connRetryTimeout = rpctest.DefaultConnectionRetryTimeout * 2
|
||||
)
|
||||
|
||||
chainBackend.MaxConnRetries = maxConnRetries
|
||||
chainBackend.ConnectionRetryTimeout = connRetryTimeout
|
||||
|
||||
if err := chainBackend.SetUp(false, 0); err != nil {
|
||||
return nil, nil, fmt.Errorf("unable to set up btcd backend: %v",
|
||||
return nil, nil, fmt.Errorf("unable to set up btcd backend: %w",
|
||||
err)
|
||||
}
|
||||
|
||||
|
@ -61,6 +61,8 @@ var _ WebFeeService = (*FeeService)(nil)
|
||||
|
||||
// Start spins up a go-routine to serve fee estimates.
|
||||
func NewFeeService(t *testing.T) *FeeService {
|
||||
t.Helper()
|
||||
|
||||
port := node.NextAvailablePort()
|
||||
f := FeeService{
|
||||
T: t,
|
||||
@ -82,6 +84,7 @@ func NewFeeService(t *testing.T) *FeeService {
|
||||
Addr: listenAddr,
|
||||
Handler: mux,
|
||||
}
|
||||
|
||||
return &f
|
||||
}
|
||||
|
||||
@ -123,6 +126,7 @@ func (f *FeeService) Stop() error {
|
||||
require.NoError(f, err, "cannot stop fee api")
|
||||
|
||||
f.wg.Wait()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -37,6 +37,10 @@ const (
|
||||
// numBlocksOpenChannel specifies the number of blocks mined when
|
||||
// opening a channel.
|
||||
numBlocksOpenChannel = 6
|
||||
|
||||
// lndErrorChanSize specifies the buffer size used to receive errors
|
||||
// from lnd process.
|
||||
lndErrorChanSize = 10
|
||||
)
|
||||
|
||||
// TestCase defines a test case that's been used in the integration test.
|
||||
@ -84,7 +88,7 @@ type HarnessTest struct {
|
||||
// runCtx is a context with cancel method. It's used to signal when the
|
||||
// node needs to quit, and used as the parent context when spawning
|
||||
// children contexts for RPC requests.
|
||||
runCtx context.Context
|
||||
runCtx context.Context //nolint:containedctx
|
||||
cancel context.CancelFunc
|
||||
|
||||
// stopChainBackend points to the cleanup function returned by the
|
||||
@ -101,10 +105,13 @@ type HarnessTest struct {
|
||||
func NewHarnessTest(t *testing.T, lndBinary string, feeService WebFeeService,
|
||||
dbBackend node.DatabaseBackend) *HarnessTest {
|
||||
|
||||
t.Helper()
|
||||
|
||||
// Create the run context.
|
||||
ctxt, cancel := context.WithCancel(context.Background())
|
||||
|
||||
manager := newNodeManager(lndBinary, dbBackend)
|
||||
|
||||
return &HarnessTest{
|
||||
T: t,
|
||||
manager: manager,
|
||||
@ -113,7 +120,7 @@ func NewHarnessTest(t *testing.T, lndBinary string, feeService WebFeeService,
|
||||
cancel: cancel,
|
||||
// We need to use buffered channel here as we don't want to
|
||||
// block sending errors.
|
||||
lndErrorChan: make(chan error, 10),
|
||||
lndErrorChan: make(chan error, lndErrorChanSize),
|
||||
}
|
||||
}
|
||||
|
||||
@ -188,6 +195,8 @@ func (h *HarnessTest) SetupStandbyNodes() {
|
||||
Type: lnrpc.AddressType_WITNESS_PUBKEY_HASH,
|
||||
}
|
||||
|
||||
const initialFund = 10 * btcutil.SatoshiPerBitcoin
|
||||
|
||||
// Load up the wallets of the seeder nodes with 10 outputs of 10 BTC
|
||||
// each.
|
||||
nodes := []*node.HarnessNode{h.Alice, h.Bob}
|
||||
@ -206,7 +215,7 @@ func (h *HarnessTest) SetupStandbyNodes() {
|
||||
|
||||
output := &wire.TxOut{
|
||||
PkScript: addrScript,
|
||||
Value: 10 * btcutil.SatoshiPerBitcoin,
|
||||
Value: initialFund,
|
||||
}
|
||||
h.Miner.SendOutput(output, defaultMinerFeeRate)
|
||||
}
|
||||
@ -222,7 +231,7 @@ func (h *HarnessTest) SetupStandbyNodes() {
|
||||
h.WaitForBlockchainSync(h.Bob)
|
||||
|
||||
// Now block until both wallets have fully synced up.
|
||||
expectedBalance := int64(btcutil.SatoshiPerBitcoin * 100)
|
||||
const expectedBalance = 10 * initialFund
|
||||
err := wait.NoError(func() error {
|
||||
aliceResp := h.Alice.RPC.WalletBalance()
|
||||
bobResp := h.Bob.RPC.WalletBalance()
|
||||
@ -285,6 +294,8 @@ func (h *HarnessTest) RunTestCase(testCase *TestCase) {
|
||||
// resetStandbyNodes resets all standby nodes by attaching the new testing.T
|
||||
// and restarting them with the original config.
|
||||
func (h *HarnessTest) resetStandbyNodes(t *testing.T) {
|
||||
t.Helper()
|
||||
|
||||
for _, hn := range h.manager.standbyNodes {
|
||||
// Inherit the testing.T.
|
||||
h.T = t
|
||||
@ -312,7 +323,7 @@ func (h *HarnessTest) Subtest(t *testing.T) *HarnessTest {
|
||||
Miner: h.Miner,
|
||||
standbyNodes: h.standbyNodes,
|
||||
feeService: h.feeService,
|
||||
lndErrorChan: make(chan error, 10),
|
||||
lndErrorChan: make(chan error, lndErrorChanSize),
|
||||
}
|
||||
|
||||
// Inherit context from the main test.
|
||||
|
@ -38,6 +38,7 @@ func (h *HarnessTest) WaitForBlockchainSync(hn *node.HarnessNode) {
|
||||
if resp.SyncedToChain {
|
||||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf("%s is not synced to chain", hn.Name())
|
||||
}, DefaultTimeout)
|
||||
|
||||
@ -231,8 +232,10 @@ func (h *HarnessTest) AssertNumEdges(hn *node.HarnessNode,
|
||||
// slice.
|
||||
edges = chanGraph.Edges[old:]
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
return errNumNotMatched(hn.Name(), "num of channel edges",
|
||||
expected, total-old, total, old)
|
||||
}, DefaultTimeout)
|
||||
|
@ -55,6 +55,7 @@ type HarnessMiner struct {
|
||||
// NewMiner creates a new miner using btcd backend with the default log file
|
||||
// dir and name.
|
||||
func NewMiner(ctxt context.Context, t *testing.T) *HarnessMiner {
|
||||
t.Helper()
|
||||
return newMiner(ctxt, t, minerLogDir, minerLogFilename)
|
||||
}
|
||||
|
||||
@ -72,6 +73,8 @@ func NewTempMiner(ctxt context.Context, t *testing.T,
|
||||
func newMiner(ctxb context.Context, t *testing.T, minerDirName,
|
||||
logFilename string) *HarnessMiner {
|
||||
|
||||
t.Helper()
|
||||
|
||||
handler := &rpcclient.NotificationHandlers{}
|
||||
btcdBinary := node.GetBtcdBinary()
|
||||
baseLogPath := fmt.Sprintf("%s/%s", node.GetLogDir(), minerDirName)
|
||||
@ -92,6 +95,7 @@ func newMiner(ctxb context.Context, t *testing.T, minerDirName,
|
||||
require.NoError(t, err, "unable to create mining node")
|
||||
|
||||
ctxt, cancel := context.WithCancel(ctxb)
|
||||
|
||||
return &HarnessMiner{
|
||||
T: t,
|
||||
Harness: miner,
|
||||
@ -137,6 +141,7 @@ func (h *HarnessMiner) Stop() {
|
||||
func (h *HarnessMiner) GetBestBlock() (*chainhash.Hash, int32) {
|
||||
blockHash, height, err := h.Client.GetBestBlock()
|
||||
require.NoError(h, err, "failed to GetBestBlock")
|
||||
|
||||
return blockHash, height
|
||||
}
|
||||
|
||||
@ -145,6 +150,7 @@ func (h *HarnessMiner) GetBestBlock() (*chainhash.Hash, int32) {
|
||||
func (h *HarnessMiner) GetRawMempool() []*chainhash.Hash {
|
||||
mempool, err := h.Client.GetRawMempool()
|
||||
require.NoError(h, err, "unable to get mempool")
|
||||
|
||||
return mempool
|
||||
}
|
||||
|
||||
@ -161,6 +167,7 @@ func (h *HarnessMiner) GenerateBlocks(num uint32) []*chainhash.Hash {
|
||||
func (h *HarnessMiner) GetBlock(blockHash *chainhash.Hash) *wire.MsgBlock {
|
||||
block, err := h.Client.GetBlock(blockHash)
|
||||
require.NoError(h, err, "unable to get block")
|
||||
|
||||
return block
|
||||
}
|
||||
|
||||
@ -289,6 +296,7 @@ func (h *HarnessMiner) AssertTxInMempool(txid *chainhash.Hash) *wire.MsgTx {
|
||||
}, wait.MinerMempoolTimeout)
|
||||
|
||||
require.NoError(h, err, "timeout checking mempool")
|
||||
|
||||
return msgTx
|
||||
}
|
||||
|
||||
|
@ -79,7 +79,7 @@ func (nm *nodeManager) newNode(t *testing.T, name string, extraArgs []string,
|
||||
BackendCfg: nm.chainBackend,
|
||||
ExtraArgs: extraArgs,
|
||||
FeeURL: nm.feeServiceURL,
|
||||
DbBackend: nm.dbBackend,
|
||||
DBBackend: nm.dbBackend,
|
||||
NodeID: nm.nextNodeID(),
|
||||
LndBinary: nm.lndBinary,
|
||||
NetParams: harnessNetParams,
|
||||
|
@ -116,7 +116,7 @@ type BaseNodeConfig struct {
|
||||
|
||||
FeeURL string
|
||||
|
||||
DbBackend DatabaseBackend
|
||||
DBBackend DatabaseBackend
|
||||
PostgresDsn string
|
||||
|
||||
// NodeID is a unique ID used to identify the node.
|
||||
@ -240,7 +240,7 @@ func (cfg *BaseNodeConfig) GenArgs() []string {
|
||||
args = append(args, "--noseedbackup")
|
||||
}
|
||||
|
||||
switch cfg.DbBackend {
|
||||
switch cfg.DBBackend {
|
||||
case BackendEtcd:
|
||||
args = append(args, "--db.backend=etcd")
|
||||
args = append(args, "--db.etcd.embedded")
|
||||
@ -349,6 +349,7 @@ func GetLogDir() string {
|
||||
if logSubDir != nil && *logSubDir != "" {
|
||||
return *logSubDir
|
||||
}
|
||||
|
||||
return "."
|
||||
}
|
||||
|
||||
|
@ -116,7 +116,7 @@ func NewHarnessNode(t *testing.T, cfg *BaseNodeConfig) (*HarnessNode, error) {
|
||||
|
||||
// Create temporary database.
|
||||
var dbName string
|
||||
if cfg.DbBackend == BackendPostgres {
|
||||
if cfg.DBBackend == BackendPostgres {
|
||||
var err error
|
||||
dbName, err = createTempPgDb()
|
||||
if err != nil {
|
||||
@ -374,7 +374,7 @@ func (hn *HarnessNode) StartLndCmd(ctxb context.Context) error {
|
||||
hn.runCtx, hn.cancel = context.WithCancel(ctxb)
|
||||
|
||||
args := hn.Cfg.GenArgs()
|
||||
hn.cmd = exec.Command(hn.Cfg.LndBinary, args...) //nolint:gosec
|
||||
hn.cmd = exec.Command(hn.Cfg.LndBinary, args...)
|
||||
|
||||
// Redirect stderr output to buffer
|
||||
var errb bytes.Buffer
|
||||
@ -649,9 +649,10 @@ func (hn *HarnessNode) waitForProcessExit() {
|
||||
// Otherwise, we print the error, break the select and save
|
||||
// logs.
|
||||
hn.printErrf("wait process exit got err: %v", err)
|
||||
|
||||
break
|
||||
|
||||
case <-time.After(wait.DefaultTimeout * 2):
|
||||
case <-time.After(wait.DefaultTimeout):
|
||||
hn.printErrf("timeout waiting for process to exit")
|
||||
}
|
||||
|
||||
@ -783,7 +784,7 @@ func (hn *HarnessNode) Kill() error {
|
||||
|
||||
// printErrf prints an error to the console.
|
||||
func (hn *HarnessNode) printErrf(format string, a ...interface{}) {
|
||||
fmt.Printf("itest error from [%s:%s]: %s\n", // nolint:forbidigo
|
||||
fmt.Printf("itest error from [%s:%s]: %s\n", //nolint:forbidigo
|
||||
hn.Cfg.LogFilenamePrefix, hn.Cfg.Name,
|
||||
fmt.Sprintf(format, a...))
|
||||
}
|
||||
@ -945,7 +946,7 @@ func finalizeLogfile(hn *HarnessNode) {
|
||||
// finalizeEtcdLog saves the etcd log files when test ends.
|
||||
func finalizeEtcdLog(hn *HarnessNode) {
|
||||
// Exit early if this is not etcd backend.
|
||||
if hn.Cfg.DbBackend != BackendEtcd {
|
||||
if hn.Cfg.DBBackend != BackendEtcd {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -162,10 +162,12 @@ func NodeArgsForCommitType(commitType lnrpc.CommitmentType) []string {
|
||||
// function provides a simple way to allow test balance assertions to take fee
|
||||
// calculations into account.
|
||||
func CalcStaticFee(c lnrpc.CommitmentType, numHTLCs int) btcutil.Amount {
|
||||
//nolint:lll
|
||||
const (
|
||||
htlcWeight = input.HTLCWeight
|
||||
anchorSize = 330
|
||||
anchorSize = 330 * 2
|
||||
defaultSatPerVByte = lnwallet.DefaultAnchorsCommitMaxFeeRateSatPerVByte
|
||||
scale = 1000
|
||||
)
|
||||
|
||||
var (
|
||||
@ -180,10 +182,10 @@ func CalcStaticFee(c lnrpc.CommitmentType, numHTLCs int) btcutil.Amount {
|
||||
// channels.
|
||||
if CommitTypeHasAnchors(c) {
|
||||
feePerKw = chainfee.SatPerKVByte(
|
||||
defaultSatPerVByte * 1000,
|
||||
defaultSatPerVByte * scale,
|
||||
).FeePerKWeight()
|
||||
commitWeight = input.AnchorCommitWeight
|
||||
anchors = 2 * anchorSize
|
||||
anchors = anchorSize
|
||||
}
|
||||
|
||||
return feePerKw.FeeForWeight(int64(commitWeight+htlcWeight*numHTLCs)) +
|
||||
@ -194,7 +196,9 @@ func CalcStaticFee(c lnrpc.CommitmentType, numHTLCs int) btcutil.Amount {
|
||||
// funding manager's config, which corresponds to the maximum MaxHTLC value we
|
||||
// allow users to set when updating a channel policy.
|
||||
func CalculateMaxHtlc(chanCap btcutil.Amount) uint64 {
|
||||
reserve := lnwire.NewMSatFromSatoshis(chanCap / 100)
|
||||
const ratio = 100
|
||||
reserve := lnwire.NewMSatFromSatoshis(chanCap / ratio)
|
||||
max := lnwire.NewMSatFromSatoshis(chanCap) - reserve
|
||||
|
||||
return uint64(max)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user