mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
lint: enable deprecation checks
Enable staticcheck's SA1019 check in golangci-lint so deprecated identifiers are caught in CI. Replace deprecated standard library and bbolt APIs with their current equivalents. Keep intentional compatibility reads and writes of deprecated Loop RPC fields behind narrow nolint annotations, because older clients and persisted liquidity parameters still depend on those fields.
This commit is contained in:
parent
d324b4bfd8
commit
5d8a5019cf
12 changed files with 42 additions and 52 deletions
|
|
@ -2,8 +2,6 @@ package loopdb
|
|||
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
|
|
@ -48,9 +46,7 @@ func TestMigrationUpdates(t *testing.T) {
|
|||
ctxb := context.Background()
|
||||
|
||||
// Restore a legacy database.
|
||||
tempDirName, err := ioutil.TempDir("", "clientstore")
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(tempDirName)
|
||||
tempDirName := t.TempDir()
|
||||
|
||||
tempPath := filepath.Join(tempDirName, dbFileName)
|
||||
db, err := bbolt.Open(tempPath, 0600, nil)
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import (
|
|||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
"go.etcd.io/bbolt"
|
||||
bbolterrors "go.etcd.io/bbolt/errors"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -197,9 +198,9 @@ func NewBoltSwapStore(dbPath string, chainParams *chaincfg.Params) (
|
|||
bdb, err := bboltOpen(path, 0600, &bbolt.Options{
|
||||
Timeout: DefaultLoopDBTimeout,
|
||||
})
|
||||
if errors.Is(err, bbolt.ErrTimeout) {
|
||||
if errors.Is(err, bbolterrors.ErrTimeout) {
|
||||
return nil, fmt.Errorf("%w: couldn't obtain exclusive lock on "+
|
||||
"%s, timed out after %v", bbolt.ErrTimeout, path,
|
||||
"%s, timed out after %v", bbolterrors.ErrTimeout, path,
|
||||
DefaultLoopDBTimeout)
|
||||
}
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
|
@ -18,6 +17,7 @@ import (
|
|||
"github.com/lightningnetwork/lnd/routing/route"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.etcd.io/bbolt"
|
||||
bbolterrors "go.etcd.io/bbolt/errors"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -62,7 +62,7 @@ func TestNewBoltSwapStoreTimeout(t *testing.T) {
|
|||
bboltOpen = origOpen
|
||||
})
|
||||
|
||||
wrappedErr := fmt.Errorf("wrapped: %w", bbolt.ErrTimeout)
|
||||
wrappedErr := fmt.Errorf("wrapped: %w", bbolterrors.ErrTimeout)
|
||||
bboltOpen = func(path string, mode os.FileMode,
|
||||
options *bbolt.Options) (*bbolt.DB, error) {
|
||||
|
||||
|
|
@ -74,7 +74,7 @@ func TestNewBoltSwapStoreTimeout(t *testing.T) {
|
|||
|
||||
store, err := NewBoltSwapStore(tempDir, &chaincfg.MainNetParams)
|
||||
require.Nil(t, store)
|
||||
require.ErrorIs(t, err, bbolt.ErrTimeout)
|
||||
require.ErrorIs(t, err, bbolterrors.ErrTimeout)
|
||||
require.ErrorContains(t, err, "couldn't obtain exclusive lock")
|
||||
}
|
||||
|
||||
|
|
@ -142,10 +142,7 @@ func TestLoopOutStore(t *testing.T) {
|
|||
// testLoopOutStore tests the basic functionality of the current bbolt
|
||||
// swap store for specific swap parameters.
|
||||
func testLoopOutStore(t *testing.T, pendingSwap *LoopOutContract) {
|
||||
tempDirName, err := ioutil.TempDir("", "clientstore")
|
||||
require.NoError(t, err)
|
||||
|
||||
defer os.RemoveAll(tempDirName)
|
||||
tempDirName := t.TempDir()
|
||||
|
||||
store, err := NewBoltSwapStore(tempDirName, &chaincfg.MainNetParams)
|
||||
require.NoError(t, err)
|
||||
|
|
@ -284,9 +281,7 @@ func TestLoopInStore(t *testing.T) {
|
|||
}
|
||||
|
||||
func testLoopInStore(t *testing.T, pendingSwap LoopInContract) {
|
||||
tempDirName, err := ioutil.TempDir("", "clientstore")
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(tempDirName)
|
||||
tempDirName := t.TempDir()
|
||||
|
||||
store, err := NewBoltSwapStore(tempDirName, &chaincfg.MainNetParams)
|
||||
require.NoError(t, err)
|
||||
|
|
@ -366,11 +361,7 @@ func testLoopInStore(t *testing.T, pendingSwap LoopInContract) {
|
|||
// TestVersionNew tests that a new database is initialized with the current
|
||||
// version.
|
||||
func TestVersionNew(t *testing.T) {
|
||||
tempDirName, err := ioutil.TempDir("", "clientstore")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(tempDirName)
|
||||
tempDirName := t.TempDir()
|
||||
|
||||
store, err := NewBoltSwapStore(tempDirName, &chaincfg.MainNetParams)
|
||||
if err != nil {
|
||||
|
|
@ -390,11 +381,7 @@ func TestVersionNew(t *testing.T) {
|
|||
// TestVersionMigrated tests that an existing version zero database is migrated
|
||||
// to the latest version.
|
||||
func TestVersionMigrated(t *testing.T) {
|
||||
tempDirName, err := ioutil.TempDir("", "clientstore")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(tempDirName)
|
||||
tempDirName := t.TempDir()
|
||||
|
||||
createVersionZeroDb(t, tempDirName)
|
||||
|
||||
|
|
@ -459,11 +446,7 @@ func TestLegacyOutgoingChannel(t *testing.T) {
|
|||
}
|
||||
|
||||
// Restore a legacy database.
|
||||
tempDirName, err := ioutil.TempDir("", "clientstore")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(tempDirName)
|
||||
tempDirName := t.TempDir()
|
||||
|
||||
tempPath := filepath.Join(tempDirName, dbFileName)
|
||||
db, err := bbolt.Open(tempPath, 0600, nil)
|
||||
|
|
@ -498,9 +481,7 @@ func TestLegacyOutgoingChannel(t *testing.T) {
|
|||
// TestLiquidityParams checks that reading and writing to liquidty bucket are
|
||||
// as expected.
|
||||
func TestLiquidityParams(t *testing.T) {
|
||||
tempDirName, err := ioutil.TempDir("", "clientstore")
|
||||
require.NoError(t, err, "failed to db")
|
||||
defer os.RemoveAll(tempDirName)
|
||||
tempDirName := t.TempDir()
|
||||
|
||||
ctxb := context.Background()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue