Skip to content

Commit

Permalink
ci: Fix linter complaint (backport #9645) (#9647)
Browse files Browse the repository at this point in the history
* ci: Fix linter complaint (#9645)

Fixes a very silly linter complaint that makes absolutely no sense and is blocking the merging of several PRs.

---

- [x] Tests written/updated, or no tests needed
- [x] `CHANGELOG_PENDING.md` updated, or no changelog entry needed
- [x] Updated relevant documentation (`docs/`) and code comments, or no
      documentation updates needed

(cherry picked from commit 83b7f4ad5bc77a56fdb51ec39ae13c1204dde6e0)

* Resolve conflicts

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* ci: Sync golangci-lint config with main

Minus the spelling configuration that restricts spelling to US English
only.

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* make format

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Remove usage of deprecated io/ioutil package

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Remove unused mockBlockStore

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* blockchain/v2: Remove unused method

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Bulk fix lints

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* lint: Ignore auto-generated query PEG

Signed-off-by: Thane Thomson <connect@thanethomson.com>

Signed-off-by: Thane Thomson <connect@thanethomson.com>
Co-authored-by: Thane Thomson <connect@thanethomson.com>
  • Loading branch information
tnasu and thanethomson committed Jul 21, 2023
1 parent 949633b commit 2c7511b
Show file tree
Hide file tree
Showing 68 changed files with 300 additions and 352 deletions.
39 changes: 6 additions & 33 deletions abci/example/kvstore/kvstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ package kvstore

import (
"fmt"
"io/ioutil"
"os"
"sort"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/tendermint/tendermint/abci/types"
Expand Down Expand Up @@ -73,7 +72,7 @@ func TestKVStoreKV(t *testing.T) {
}

func TestPersistentKVStoreKV(t *testing.T) {
dir, err := ioutil.TempDir("/tmp", "abci-kvstore-test") // TODO
dir, err := os.MkdirTemp("/tmp", "abci-kvstore-test") // TODO
if err != nil {
t.Fatal(err)
}
Expand All @@ -89,7 +88,7 @@ func TestPersistentKVStoreKV(t *testing.T) {
}

func TestPersistentKVStoreInfo(t *testing.T) {
dir, err := ioutil.TempDir("/tmp", "abci-kvstore-test") // TODO
dir, err := os.MkdirTemp("/tmp", "abci-kvstore-test") // TODO
if err != nil {
t.Fatal(err)
}
Expand All @@ -116,12 +115,11 @@ func TestPersistentKVStoreInfo(t *testing.T) {
if resInfo.LastBlockHeight != height {
t.Fatalf("expected height of %d, got %d", height, resInfo.LastBlockHeight)
}

}

// add a validator, remove a validator, update a validator
func TestValUpdates(t *testing.T) {
dir, err := ioutil.TempDir("/tmp", "abci-kvstore-test") // TODO
dir, err := os.MkdirTemp("/tmp", "abci-kvstore-test") // TODO
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -183,18 +181,15 @@ func TestValUpdates(t *testing.T) {
vals1 = append([]types.ValidatorUpdate{v1}, vals1[1:]...)
vals2 = kvstore.Validators()
valsEqual(t, vals1, vals2)

for _, v := range vals2 {
existInPersistStore(t, kvstore, v)
}
}

func makeApplyBlock(
t *testing.T,
kvstore ocabci.Application,
heightInt int,
diff []types.ValidatorUpdate,
txs ...[]byte) {
txs ...[]byte,
) {
// make and apply block
height := int64(heightInt)
hash := []byte("foo")
Expand All @@ -212,28 +207,6 @@ func makeApplyBlock(
kvstore.Commit()

valsEqual(t, diff, resEndBlock.ValidatorUpdates)

}

func existInPersistStore(t *testing.T, kvstore ocabci.Application, v types.ValidatorUpdate) {
// success
pubkeyStr, _ := MakeValSetChangeTxAndMore(v.PubKey, v.Power)
resQuery := kvstore.Query(types.RequestQuery{Path: "/val", Data: []byte(pubkeyStr)})
assert.False(t, resQuery.IsErr(), resQuery)
assert.Equal(t, "", resQuery.Log)
// failures
{
// default Query: does not exist
r := kvstore.Query(types.RequestQuery{Path: "/val_", Data: []byte(pubkeyStr)})
assert.False(t, r.IsErr(), r)
assert.Contains(t, r.Log, "does not exist")
}
{
// Query: does not exist
r := kvstore.Query(types.RequestQuery{Path: "/val", Data: []byte{}})
assert.False(t, r.IsErr(), r)
assert.Equal(t, "", resQuery.Log)
}
}

// order doesn't matter
Expand Down
37 changes: 9 additions & 28 deletions blockchain/v2/reactor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,28 +65,7 @@ func (mp mockPeer) String() string { return fmt.Sprintf("%v", mp.id) }
func (mp mockPeer) SetRemovalFailed() {}
func (mp mockPeer) GetRemovalFailed() bool { return false }

// nolint:unused // ignore
type mockBlockStore struct {
blocks map[int64]*types.Block
}

// nolint:unused // ignore
func (ml *mockBlockStore) Height() int64 {
return int64(len(ml.blocks))
}

// nolint:unused // ignore
func (ml *mockBlockStore) LoadBlock(height int64) *types.Block {
return ml.blocks[height]
}

// nolint:unused // ignore
func (ml *mockBlockStore) SaveBlock(block *types.Block, part *types.PartSet, commit *types.Commit) {
ml.blocks[block.Height] = block
}

type mockBlockApplier struct {
}
type mockBlockApplier struct{}

// XXX: Add whitelist/blacklist?
func (mba *mockBlockApplier) ApplyBlock(
Expand Down Expand Up @@ -358,9 +337,8 @@ func newTestReactor(p testReactorParams) *BlockchainReactor {
// }

func TestReactorHelperMode(t *testing.T) {
var (
channelID = byte(0x40)
)
channelID := byte(0x40)

config := cfg.ResetTestRoot("blockchain_reactor_v2_test")
defer os.RemoveAll(config.RootDir)
genDoc, privVals := randGenesisDoc(config.ChainID(), 1, false, 30)
Expand Down Expand Up @@ -475,7 +453,8 @@ type testApp struct {
}

func randGenesisDoc(chainID string, numValidators int, randPower bool, minPower int64) (
*types.GenesisDoc, []types.PrivValidator) {
*types.GenesisDoc, []types.PrivValidator,
) {
validators := make([]types.GenesisValidator, numValidators)
privValidators := make([]types.PrivValidator, numValidators)
for i := 0; i < numValidators; i++ {
Expand All @@ -500,7 +479,8 @@ func randGenesisDoc(chainID string, numValidators int, randPower bool, minPower
func newReactorStore(
genDoc *types.GenesisDoc,
privVals []types.PrivValidator,
maxBlockHeight int64) (*store.BlockStore, sm.State, *sm.BlockExecutor) {
maxBlockHeight int64,
) (*store.BlockStore, sm.State, *sm.BlockExecutor) {
if len(privVals) != 1 {
panic("only support one validator")
}
Expand All @@ -524,7 +504,8 @@ func newReactorStore(

db := dbm.NewMemDB()
stateStore = sm.NewStore(db, sm.StoreOptions{
DiscardABCIResponses: false},
DiscardABCIResponses: false,
},
)
blockExec := sm.NewBlockExecutor(stateStore, log.TestingLogger(), proxyApp.Consensus(),
mock.Mempool{}, sm.EmptyEvidencePool{})
Expand Down
5 changes: 0 additions & 5 deletions blockchain/v2/routine.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ func (rt *Routine) setLogger(logger log.Logger) {
rt.logger = logger
}

// nolint:unused
func (rt *Routine) setMetrics(metrics *Metrics) {
rt.metrics = metrics
}

func (rt *Routine) start() {
rt.logger.Info("routine start", "msg", log.NewLazySprintf("%s: run", rt.name))
running := atomic.CompareAndSwapUint32(rt.running, uint32(0), uint32(1))
Expand Down
1 change: 0 additions & 1 deletion cmd/ostracon/commands/debug/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ func zipDir(src, dest string) error {
_, err = io.Copy(headerWriter, file)
return err
})

}

// copyFile copies a file from src to dest and returns an error upon failure. The
Expand Down
3 changes: 2 additions & 1 deletion cmd/ostracon/commands/reindex_event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"

dbm "github.com/tendermint/tm-db"

abcitypes "github.com/tendermint/tendermint/abci/types"
prototmstate "github.com/tendermint/tendermint/proto/tendermint/state"

Expand All @@ -17,7 +19,6 @@ import (
"github.com/Finschia/ostracon/state/mocks"
txmocks "github.com/Finschia/ostracon/state/txindex/mocks"
"github.com/Finschia/ostracon/types"
dbm "github.com/tendermint/tm-db"
)

const (
Expand Down
11 changes: 3 additions & 8 deletions cmd/ostracon/commands/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package commands

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strconv"
Expand All @@ -18,9 +17,7 @@ import (
tmos "github.com/Finschia/ostracon/libs/os"
)

var (
defaultRoot = os.ExpandEnv("$HOME/.some/test/dir")
)
var defaultRoot = os.ExpandEnv("$HOME/.some/test/dir")

// clearConfig clears env vars, the given root dir, and resets viper.
func clearConfig(dir string) {
Expand Down Expand Up @@ -88,7 +85,6 @@ func TestRootHome(t *testing.T) {
}

func TestRootFlagsEnv(t *testing.T) {

// defaults
defaults := cfg.DefaultConfig()
defaultLogLvl := defaults.LogLevel
Expand Down Expand Up @@ -116,7 +112,6 @@ func TestRootFlagsEnv(t *testing.T) {
}

func TestRootConfig(t *testing.T) {

// write non-default config
nonDefaultLogLvl := "abc:debug"
cvals := map[string]string{
Expand All @@ -140,7 +135,7 @@ func TestRootConfig(t *testing.T) {

// XXX: path must match cfg.defaultConfigPath
configFilePath := filepath.Join(defaultRoot, "config")
err := tmos.EnsureDir(configFilePath, 0700)
err := tmos.EnsureDir(configFilePath, 0o700)
require.Nil(t, err)

// write the non-defaults to a different path
Expand Down Expand Up @@ -168,5 +163,5 @@ func WriteConfigVals(dir string, vals map[string]string) error {
data += fmt.Sprintf("%s = \"%s\"\n", k, v)
}
cfile := filepath.Join(dir, "config.toml")
return ioutil.WriteFile(cfile, []byte(data), 0600)
return os.WriteFile(cfile, []byte(data), 0o600)
}
2 changes: 1 addition & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ func TestDefaultConfig(t *testing.T) {
assert.Equal("/foo/bar", cfg.GenesisFile())
assert.Equal("/opt/data", cfg.DBDir())
assert.Equal("/foo/wal/mem", cfg.Mempool.WalDir())

}

func TestConfigValidateBasic(t *testing.T) {
Expand Down Expand Up @@ -169,6 +168,7 @@ func TestFastSyncConfigValidateBasic(t *testing.T) {
assert.Error(t, cfg.ValidateBasic())
}

//nolint:lll
func TestConsensusConfig_ValidateBasic(t *testing.T) {
// nolint: lll
testcases := map[string]struct {
Expand Down
12 changes: 6 additions & 6 deletions config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

// DefaultDirPerm is the default permissions used when creating directories.
const DefaultDirPerm = 0700
const DefaultDirPerm = 0o700

var configTemplate *template.Template

Expand Down Expand Up @@ -63,7 +63,7 @@ func WriteConfigFile(configFilePath string, config *Config) {
panic(err)
}

tmos.MustWriteFile(configFilePath, buffer.Bytes(), 0644)
tmos.MustWriteFile(configFilePath, buffer.Bytes(), 0o644)
}

// Note: any changes to the comments/variables/mapstructure
Expand Down Expand Up @@ -630,12 +630,12 @@ func ResetTestRootWithChainID(testName string, chainID string) *Config {
chainID = "ostracon_test"
}
testGenesis := fmt.Sprintf(testGenesisFmt, chainID)
tmos.MustWriteFile(genesisFilePath, []byte(testGenesis), 0644)
tmos.MustWriteFile(genesisFilePath, []byte(testGenesis), 0o644)
}
// we always overwrite the priv val
tmos.MustWriteFile(privKeyFilePath, []byte(testPrivValidatorKey), 0644)
tmos.MustWriteFile(privStateFilePath, []byte(testPrivValidatorState), 0644)
tmos.MustWriteFile(nodeKeyFilePath, []byte(testNodeKey), 0644)
tmos.MustWriteFile(privKeyFilePath, []byte(testPrivValidatorKey), 0o644)
tmos.MustWriteFile(privStateFilePath, []byte(testPrivValidatorState), 0o644)
tmos.MustWriteFile(nodeKeyFilePath, []byte(testNodeKey), 0o644)

config := TestConfig().SetRoot(rootDir)
return config
Expand Down
9 changes: 4 additions & 5 deletions config/toml_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package config

import (
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand All @@ -23,15 +22,15 @@ func TestEnsureRoot(t *testing.T) {
require := require.New(t)

// setup temp dir for test
tmpDir, err := ioutil.TempDir("", "config-test")
tmpDir, err := os.MkdirTemp("", "config-test")
require.Nil(err)
defer os.RemoveAll(tmpDir)

// create root dir
EnsureRoot(tmpDir)

// make sure config is set properly
data, err := ioutil.ReadFile(filepath.Join(tmpDir, defaultConfigFilePath))
data, err := os.ReadFile(filepath.Join(tmpDir, defaultConfigFilePath))
require.Nil(err)

if !checkConfig(string(data)) {
Expand All @@ -52,7 +51,7 @@ func TestEnsureTestRoot(t *testing.T) {
rootDir := cfg.RootDir

// make sure config is set properly
data, err := ioutil.ReadFile(filepath.Join(rootDir, defaultConfigFilePath))
data, err := os.ReadFile(filepath.Join(rootDir, defaultConfigFilePath))
require.Nil(err)

if !checkConfig(string(data)) {
Expand All @@ -68,7 +67,7 @@ func checkConfig(configFile string) bool {
var valid bool

// list of words we expect in the config
var elems = []string{
elems := []string{
"moniker",
"seeds",
"proxy_app",
Expand Down
Loading

0 comments on commit 2c7511b

Please sign in to comment.