itest: fix make lint

This commit fixes the issues reported by the linter.
This commit is contained in:
yyforyongyu committed 2023-02-23 21:56:10 +08:00
1 parent a080375b7d
commit 2bc6aabf96
24 files changed
+127 -142

No files matched your search

+9 -4
View File
@@ -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)
}
+4
View File
@@ -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
}
+16 -5
View File
@@ -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.
+3
View File
@@ -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)
+8
View File
@@ -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
}
+1 -1
View File
@@ -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,
+3 -2
View File
@@ -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 "."
}
+6 -5
View File
@@ -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
}
+8 -4
View File
@@ -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)
}