From 3ba0031c81919a6385164b4bec4300704029f275 Mon Sep 17 00:00:00 2001 From: Jayden Lee <41176085+tkxkd0159@users.noreply.github.com> Date: Tue, 25 Jun 2024 17:20:00 +0900 Subject: [PATCH] lint --- .golangci.yml | 4 ++++ ante/ante.go | 5 +++-- ante/ante_test.go | 3 ++- app/app.go | 34 +++++++++++++++++------------- app/app_test.go | 7 ++++--- app/export.go | 4 ++-- app/genesis_account_test.go | 4 ++-- app/wasm_filter.go | 8 ++++--- app/wasm_filter_test.go | 10 ++++----- cli_test/cli_test.go | 11 ++++++---- cli_test/test_helpers.go | 18 ++++++++++++++-- cmd/fnsad/cmd/genaccounts_test.go | 7 ++++--- cmd/fnsad/cmd/root.go | 14 ++++++++----- cmd/fnsad/cmd/root_test.go | 3 ++- cmd/fnsad/cmd/testnet.go | 35 ++++++++++++++++--------------- cmd/fnsad/cmd/testnet_test.go | 3 ++- cmd/fnsad/main.go | 7 ++++--- 17 files changed, 108 insertions(+), 69 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 300ed9ca..bba134bf 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -72,7 +72,11 @@ linters-settings: sections: - standard # Standard section: captures all standard packages. - default # Default section: contains all imports that could not be matched to another section type. + - prefix(github.com/Finschia/ostracon) + - prefix(github.com/Finschia/ibc-go) + - prefix(github.com/Finschia/wasmd) - prefix(github.com/Finschia/finschia-sdk) + - prefix(github.com/Finschia/finschia) run: # default concurrency is a available CPU number concurrency: 4 diff --git a/ante/ante.go b/ante/ante.go index b8610ce3..75774ef2 100644 --- a/ante/ante.go +++ b/ante/ante.go @@ -4,11 +4,12 @@ import ( ibcante "github.com/cosmos/ibc-go/v4/modules/core/ante" ibckeeper "github.com/cosmos/ibc-go/v4/modules/core/keeper" + wasmkeeper "github.com/Finschia/wasmd/x/wasm/keeper" + wasmtypes "github.com/Finschia/wasmd/x/wasm/types" + sdk "github.com/Finschia/finschia-sdk/types" sdkerrors "github.com/Finschia/finschia-sdk/types/errors" "github.com/Finschia/finschia-sdk/x/auth/ante" - wasmkeeper "github.com/Finschia/wasmd/x/wasm/keeper" - wasmtypes "github.com/Finschia/wasmd/x/wasm/types" ) // HandlerOptions extend the SDK's AnteHandler options by requiring the IBC diff --git a/ante/ante_test.go b/ante/ante_test.go index e9443297..e44dcd35 100644 --- a/ante/ante_test.go +++ b/ante/ante_test.go @@ -7,6 +7,8 @@ import ( "github.com/stretchr/testify/suite" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + ocrand "github.com/Finschia/ostracon/libs/rand" + "github.com/Finschia/finschia-sdk/client" "github.com/Finschia/finschia-sdk/client/tx" cryptotypes "github.com/Finschia/finschia-sdk/crypto/types" @@ -15,7 +17,6 @@ import ( sdk "github.com/Finschia/finschia-sdk/types" "github.com/Finschia/finschia-sdk/types/tx/signing" xauthsigning "github.com/Finschia/finschia-sdk/x/auth/signing" - ocrand "github.com/Finschia/ostracon/libs/rand" linkapp "github.com/Finschia/finschia/v4/app" linkhelpers "github.com/Finschia/finschia/v4/app/helpers" diff --git a/app/app.go b/app/app.go index 0afa3d2b..c561267b 100644 --- a/app/app.go +++ b/app/app.go @@ -30,6 +30,17 @@ import ( tmproto "github.com/tendermint/tendermint/proto/tendermint/types" dbm "github.com/tendermint/tm-db" + ocabci "github.com/Finschia/ostracon/abci/types" + "github.com/Finschia/ostracon/libs/log" + ostos "github.com/Finschia/ostracon/libs/os" + + "github.com/Finschia/wasmd/x/wasm" + wasmclient "github.com/Finschia/wasmd/x/wasm/client" + wasmkeeper "github.com/Finschia/wasmd/x/wasm/keeper" + "github.com/Finschia/wasmd/x/wasmplus" + wasmpluskeeper "github.com/Finschia/wasmd/x/wasmplus/keeper" + wasmplustypes "github.com/Finschia/wasmd/x/wasmplus/types" + "github.com/Finschia/finschia-sdk/baseapp" "github.com/Finschia/finschia-sdk/client" nodeservice "github.com/Finschia/finschia-sdk/client/grpc/node" @@ -120,23 +131,16 @@ import ( upgradeclient "github.com/Finschia/finschia-sdk/x/upgrade/client" upgradekeeper "github.com/Finschia/finschia-sdk/x/upgrade/keeper" upgradetypes "github.com/Finschia/finschia-sdk/x/upgrade/types" - ocabci "github.com/Finschia/ostracon/abci/types" - "github.com/Finschia/ostracon/libs/log" - ostos "github.com/Finschia/ostracon/libs/os" - "github.com/Finschia/wasmd/x/wasm" - wasmclient "github.com/Finschia/wasmd/x/wasm/client" - wasmkeeper "github.com/Finschia/wasmd/x/wasm/keeper" - "github.com/Finschia/wasmd/x/wasmplus" - wasmpluskeeper "github.com/Finschia/wasmd/x/wasmplus/keeper" - wasmplustypes "github.com/Finschia/wasmd/x/wasmplus/types" appante "github.com/Finschia/finschia/v4/ante" appparams "github.com/Finschia/finschia/v4/app/params" _ "github.com/Finschia/finschia/v4/client/docs/statik" // unnamed import of statik for swagger UI support ) -const appName = "Finschia" -const upgradeName = "v4-Marigold" +const ( + appName = "Finschia" + upgradeName = "v4-Marigold" +) var ( // DefaultNodeHome default home directories for the application daemon @@ -216,7 +220,7 @@ var ( // LinkApp extends an ABCI application, but with most of its parameters exported. // They are exported for convenience in creating helper functions, as object // capabilities aren't needed for testing. -type LinkApp struct { // nolint: golint +type LinkApp struct { //nolint: golint *baseapp.BaseApp legacyAmino *codec.LegacyAmino appCodec codec.Codec @@ -504,7 +508,7 @@ func NewLinkApp( /**** Module Options ****/ /**** Module Options ****/ - var skipGenesisInvariants = false + skipGenesisInvariants := false opt := appOpts.Get(crisis.FlagSkipGenesisInvariants) if opt, ok := opt.(bool); ok { skipGenesisInvariants = opt @@ -699,7 +703,7 @@ func NewLinkApp( wasmkeeper.NewWasmSnapshotter(app.CommitMultiStore(), &app.WasmKeeper.Keeper), ) if err != nil { - panic(fmt.Errorf("failed to register snapshot extension: %s", err)) + panic(fmt.Errorf("failed to register snapshot extension: %w", err)) } } @@ -890,7 +894,7 @@ func (app *LinkApp) setupUpgradeStoreLoaders() { func (app *LinkApp) setupUpgradeHandlers() { app.UpgradeKeeper.SetUpgradeHandler( upgradeName, - func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { return app.mm.RunMigrations(ctx, app.configurator, fromVM) }) } diff --git a/app/app_test.go b/app/app_test.go index c5247f00..a7f7cc2d 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -13,6 +13,10 @@ import ( tmproto "github.com/tendermint/tendermint/proto/tendermint/types" dbm "github.com/tendermint/tm-db" + "github.com/Finschia/ostracon/libs/log" + + "github.com/Finschia/wasmd/x/wasmplus" + "github.com/Finschia/finschia-sdk/baseapp" "github.com/Finschia/finschia-sdk/simapp" "github.com/Finschia/finschia-sdk/tests/mocks" @@ -38,8 +42,6 @@ import ( "github.com/Finschia/finschia-sdk/x/staking" tokenmodule "github.com/Finschia/finschia-sdk/x/token/module" "github.com/Finschia/finschia-sdk/x/upgrade" - "github.com/Finschia/ostracon/libs/log" - "github.com/Finschia/wasmd/x/wasmplus" ) func TestSimAppExportAndBlockedAddrs(t *testing.T) { @@ -125,7 +127,6 @@ func TestRunMigrations(t *testing.T) { } for _, tc := range testCases { - tc := tc t.Run(tc.name, func(t *testing.T) { var err error diff --git a/app/export.go b/app/export.go index 86131af5..a9dd4915 100644 --- a/app/export.go +++ b/app/export.go @@ -73,7 +73,7 @@ func (app *LinkApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [ // withdraw all validator commission app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) { - _, _ = app.DistrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator()) // nolint: errcheck + _, _ = app.DistrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator()) //nolint: errcheck return false }) @@ -86,7 +86,7 @@ func (app *LinkApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [ } delAddr := sdk.MustAccAddressFromBech32(delegation.DelegatorAddress) - _, _ = app.DistrKeeper.WithdrawDelegationRewards(ctx, delAddr, valAddr) // nolint: errcheck + _, _ = app.DistrKeeper.WithdrawDelegationRewards(ctx, delAddr, valAddr) //nolint: errcheck } // clear validator slash events diff --git a/app/genesis_account_test.go b/app/genesis_account_test.go index 268c2b3b..8383ed52 100644 --- a/app/genesis_account_test.go +++ b/app/genesis_account_test.go @@ -6,11 +6,12 @@ import ( "github.com/stretchr/testify/require" + "github.com/Finschia/ostracon/crypto" + "github.com/Finschia/finschia-sdk/crypto/keys/secp256k1" "github.com/Finschia/finschia-sdk/simapp" sdk "github.com/Finschia/finschia-sdk/types" authtypes "github.com/Finschia/finschia-sdk/x/auth/types" - "github.com/Finschia/ostracon/crypto" ) func TestSimGenesisAccountValidate(t *testing.T) { @@ -80,7 +81,6 @@ func TestSimGenesisAccountValidate(t *testing.T) { } for _, tc := range testCases { - tc := tc t.Run(tc.name, func(t *testing.T) { require.Equal(t, tc.wantErr, tc.sga.Validate() != nil) }) diff --git a/app/wasm_filter.go b/app/wasm_filter.go index 6b4e41dc..c93638ab 100644 --- a/app/wasm_filter.go +++ b/app/wasm_filter.go @@ -3,13 +3,15 @@ package app import ( "strings" + wasmvmtypes "github.com/Finschia/wasmvm/types" + + wasmkeeper "github.com/Finschia/wasmd/x/wasm/keeper" + wasmtypes "github.com/Finschia/wasmd/x/wasm/types" + "github.com/Finschia/finschia-sdk/codec" codectypes "github.com/Finschia/finschia-sdk/codec/types" sdk "github.com/Finschia/finschia-sdk/types" sdkerrors "github.com/Finschia/finschia-sdk/types/errors" - wasmkeeper "github.com/Finschia/wasmd/x/wasm/keeper" - wasmtypes "github.com/Finschia/wasmd/x/wasm/types" - wasmvmtypes "github.com/Finschia/wasmvm/types" ) func filteredStargateMsgEncoders(cdc codec.Codec) *wasmkeeper.MessageEncoders { diff --git a/app/wasm_filter_test.go b/app/wasm_filter_test.go index 14237c44..01f3fc7e 100644 --- a/app/wasm_filter_test.go +++ b/app/wasm_filter_test.go @@ -3,17 +3,18 @@ package app import ( "testing" - "github.com/golang/protobuf/proto" // nolint: staticcheck + wasmvmtypes "github.com/Finschia/wasmvm/types" + "github.com/golang/protobuf/proto" //nolint: staticcheck "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + wasmkeeper "github.com/Finschia/wasmd/x/wasm/keeper" + wasmtypes "github.com/Finschia/wasmd/x/wasm/types" + codectypes "github.com/Finschia/finschia-sdk/codec/types" sdk "github.com/Finschia/finschia-sdk/types" banktypes "github.com/Finschia/finschia-sdk/x/bank/types" govtypes "github.com/Finschia/finschia-sdk/x/gov/types" - wasmkeeper "github.com/Finschia/wasmd/x/wasm/keeper" - wasmtypes "github.com/Finschia/wasmd/x/wasm/types" - wasmvmtypes "github.com/Finschia/wasmvm/types" ) func TestFilteredStargateMsgEncoders(t *testing.T) { @@ -123,7 +124,6 @@ func TestFilteredStargateMsgEncoders(t *testing.T) { } encodingConfig := MakeEncodingConfig() for name, tc := range cases { - tc := tc t.Run(name, func(t *testing.T) { var ctx sdk.Context encoder := wasmkeeper.DefaultEncoders(encodingConfig.Marshaler, tc.transferPortSource) diff --git a/cli_test/cli_test.go b/cli_test/cli_test.go index 7b5d433d..e0722375 100644 --- a/cli_test/cli_test.go +++ b/cli_test/cli_test.go @@ -17,13 +17,14 @@ import ( "github.com/stretchr/testify/require" + osttypes "github.com/Finschia/ostracon/types" + "github.com/Finschia/finschia-sdk/client/flags" "github.com/Finschia/finschia-sdk/crypto/keys/ed25519" sdk "github.com/Finschia/finschia-sdk/types" "github.com/Finschia/finschia-sdk/types/tx" gov "github.com/Finschia/finschia-sdk/x/gov/types" minttypes "github.com/Finschia/finschia-sdk/x/mint/types" - osttypes "github.com/Finschia/ostracon/types" "github.com/Finschia/finschia/v4/app" ) @@ -654,7 +655,7 @@ func TestFnsadSubmitCommunityPoolSpendProposal(t *testing.T) { defer f.Cleanup() // create some inflation - var cdc, amino = app.MakeCodecs() + cdc, amino := app.MakeCodecs() genesisState := f.GenesisState() inflationMin := sdk.MustNewDecFromStr("10000.0") var mintData minttypes.GenesisState @@ -1040,7 +1041,8 @@ func TestFnsadMultisignSortSignatures(t *testing.T) { // Multisign, keys in different order out, err = f.TxMultisign(unsignedTxFile.Name(), keyFooBarBaz, []string{ - bazSignatureFile.Name(), fooSignatureFile.Name()}) + bazSignatureFile.Name(), fooSignatureFile.Name(), + }) require.NoError(t, err) // Write the output to disk @@ -1101,7 +1103,8 @@ func TestFnsadMultisign(t *testing.T) { // Multisign out, err = f.TxMultisign(unsignedTxFile.Name(), keyFooBarBaz, []string{ - fooSignatureFile.Name(), barSignatureFile.Name()}) + fooSignatureFile.Name(), barSignatureFile.Name(), + }) require.NoError(t, err) // Write the output to disk diff --git a/cli_test/test_helpers.go b/cli_test/test_helpers.go index 9580f7ce..882186d5 100644 --- a/cli_test/test_helpers.go +++ b/cli_test/test_helpers.go @@ -25,6 +25,7 @@ import ( osthttp "github.com/Finschia/ostracon/rpc/client/http" ostctypes "github.com/Finschia/ostracon/rpc/core/types" osttypes "github.com/Finschia/ostracon/types" + wasmcli "github.com/Finschia/wasmd/x/wasm/client/cli" wasmtypes "github.com/Finschia/wasmd/x/wasm/types" @@ -61,6 +62,7 @@ import ( stakingcli "github.com/Finschia/finschia-sdk/x/staking/client/cli" staking "github.com/Finschia/finschia-sdk/x/staking/types" "github.com/Finschia/finschia-sdk/x/stakingplus" + "github.com/Finschia/finschia/v4/app" fnsacmd "github.com/Finschia/finschia/v4/cmd/fnsad/cmd" fnsatypes "github.com/Finschia/finschia/v4/types" @@ -169,6 +171,7 @@ type Fixtures struct { } func getHomeDir(t *testing.T) string { + t.Helper() tmpDir := path.Join(os.ExpandEnv("$HOME"), ".fnsatest") err := os.MkdirAll(tmpDir, os.ModePerm) require.NoError(t, err) @@ -179,6 +182,7 @@ func getHomeDir(t *testing.T) string { // NewFixtures creates a new instance of Fixtures with many vars set func NewFixtures(t *testing.T, homeDir string) *Fixtures { + t.Helper() if err := os.MkdirAll(filepath.Join(homeDir, "config/"), os.ModePerm); err != nil { panic(err) } @@ -201,6 +205,7 @@ func NewFixtures(t *testing.T, homeDir string) *Fixtures { } func newTCPAddr(t *testing.T) (addr, port string) { + t.Helper() portI := atomic.AddInt32(&curPort, 1) require.Less(t, portI, int32(32768), "A new port should be less than ip_local_port_range.min") @@ -210,6 +215,7 @@ func newTCPAddr(t *testing.T) (addr, port string) { } func newGRPCAddr(t *testing.T) (addr, port string) { + t.Helper() portI := atomic.AddInt32(&curPort, 1) require.Less(t, portI, int32(32768), "A new port should be less than ip_local_port_range.min") @@ -265,6 +271,7 @@ func (f Fixtures) GenesisState() app.GenesisState { // InitFixtures is called at the beginning of a test and initializes a chain // with 1 validator. func InitFixtures(t *testing.T) (f *Fixtures) { + t.Helper() f = NewFixtures(t, getHomeDir(t)) // add foo and bar keys to the keystore @@ -1118,6 +1125,7 @@ type FixtureGroup struct { } func NewFixtureGroup(t *testing.T) *FixtureGroup { + t.Helper() fg := &FixtureGroup{ T: t, fixturesMap: make(map[string]*Fixtures), @@ -1130,6 +1138,7 @@ func NewFixtureGroup(t *testing.T) *FixtureGroup { } func InitFixturesGroup(t *testing.T, numOfNodes ...int) *FixtureGroup { + t.Helper() nodeNumber := 4 if len(numOfNodes) == 1 { nodeNumber = numOfNodes[0] @@ -1181,7 +1190,7 @@ func (fg *FixtureGroup) initNodes(numberOfNodes int) { } for _, f := range fg.fixturesMap { - err := os.WriteFile(f.GenesisFile(), fg.genesisFileContent, os.ModePerm) + err := os.WriteFile(f.GenesisFile(), fg.genesisFileContent, 0o600) require.NoError(t, err) } } @@ -1228,7 +1237,7 @@ func (fg *FixtureGroup) AddFullNode(flags ...string) *Fixtures { if len(fg.genesisFileContent) == 0 { panic("genesis file is not loaded") } - err := os.WriteFile(f.GenesisFile(), fg.genesisFileContent, os.ModePerm) + err := os.WriteFile(f.GenesisFile(), fg.genesisFileContent, 0o600) require.NoError(t, err) } @@ -1333,6 +1342,7 @@ func addFlags(args string, flags ...string) []string { // Write the given string to a new temporary file func WriteToNewTempFile(t *testing.T, s string) *os.File { + t.Helper() fp, err := os.CreateTemp(os.TempDir(), "cosmos_cli_test_") require.Nil(t, err) _, err = fp.WriteString(s) @@ -1341,6 +1351,7 @@ func WriteToNewTempFile(t *testing.T, s string) *os.File { } func MarshalTx(t *testing.T, stdTx tx.Tx) []byte { + t.Helper() cdc, _ := app.MakeCodecs() bz, err := cdc.MarshalJSON(&stdTx) require.NoError(t, err) @@ -1348,18 +1359,21 @@ func MarshalTx(t *testing.T, stdTx tx.Tx) []byte { } func UnmarshalTx(t *testing.T, s []byte) (stdTx tx.Tx) { + t.Helper() cdc, _ := app.MakeCodecs() require.Nil(t, cdc.UnmarshalJSON(s, &stdTx)) return } func UnmarshalTxResponse(t *testing.T, s []byte) (txResp sdk.TxResponse) { + t.Helper() cdc, _ := app.MakeCodecs() require.Nil(t, cdc.UnmarshalJSON(s, &txResp)) return } func newTestnetConfig(t *testing.T, genesisState map[string]json.RawMessage, chainID, minGasPrices string) testnet.Config { + t.Helper() encodingCfg := app.MakeEncodingConfig() cfg := testnet.Config{ Codec: encodingCfg.Marshaler, diff --git a/cmd/fnsad/cmd/genaccounts_test.go b/cmd/fnsad/cmd/genaccounts_test.go index 7981ac4a..79fdc75c 100644 --- a/cmd/fnsad/cmd/genaccounts_test.go +++ b/cmd/fnsad/cmd/genaccounts_test.go @@ -8,6 +8,8 @@ import ( "github.com/spf13/viper" "github.com/stretchr/testify/require" + "github.com/Finschia/ostracon/libs/log" + "github.com/Finschia/finschia-sdk/client" "github.com/Finschia/finschia-sdk/client/flags" "github.com/Finschia/finschia-sdk/crypto/hd" @@ -20,7 +22,6 @@ import ( "github.com/Finschia/finschia-sdk/types/module" "github.com/Finschia/finschia-sdk/x/genutil" genutiltest "github.com/Finschia/finschia-sdk/x/genutil/client/testutil" - "github.com/Finschia/ostracon/libs/log" ) var testMbm = module.NewBasicManager(genutil.AppModuleBasic{}) @@ -65,7 +66,6 @@ func TestAddGenesisAccountCmd(t *testing.T) { } for _, tc := range tests { - tc := tc t.Run(tc.name, func(t *testing.T) { home := t.TempDir() logger := log.NewNopLogger() @@ -96,7 +96,8 @@ func TestAddGenesisAccountCmd(t *testing.T) { cmd.SetArgs([]string{ tc.addr, tc.denom, - fmt.Sprintf("--%s=home", flags.FlagHome)}) + fmt.Sprintf("--%s=home", flags.FlagHome), + }) if tc.expectErr { require.Error(t, cmd.ExecuteContext(ctx)) diff --git a/cmd/fnsad/cmd/root.go b/cmd/fnsad/cmd/root.go index 287243bd..7ecd41f1 100644 --- a/cmd/fnsad/cmd/root.go +++ b/cmd/fnsad/cmd/root.go @@ -13,6 +13,12 @@ import ( "github.com/spf13/viper" dbm "github.com/tendermint/tm-db" + ostcli "github.com/Finschia/ostracon/libs/cli" + "github.com/Finschia/ostracon/libs/log" + + "github.com/Finschia/wasmd/x/wasm" + wasmkeeper "github.com/Finschia/wasmd/x/wasm/keeper" + "github.com/Finschia/finschia-sdk/baseapp" "github.com/Finschia/finschia-sdk/client" "github.com/Finschia/finschia-sdk/client/config" @@ -33,10 +39,6 @@ import ( banktypes "github.com/Finschia/finschia-sdk/x/bank/types" "github.com/Finschia/finschia-sdk/x/crisis" genutilcli "github.com/Finschia/finschia-sdk/x/genutil/client/cli" - ostcli "github.com/Finschia/ostracon/libs/cli" - "github.com/Finschia/ostracon/libs/log" - "github.com/Finschia/wasmd/x/wasm" - wasmkeeper "github.com/Finschia/wasmd/x/wasm/keeper" "github.com/Finschia/finschia/v4/app" "github.com/Finschia/finschia/v4/app/params" @@ -178,6 +180,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) { keys.Commands(app.DefaultNodeHome), ) } + func addModuleInitFlags(startCmd *cobra.Command) { crisis.AddModuleInitFlags(startCmd) } @@ -297,7 +300,8 @@ func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts serverty func createSimappAndExport( logger log.Logger, db dbm.DB, traceStore io.Writer, height int64, forZeroHeight bool, jailAllowedAddrs []string, - appOpts servertypes.AppOptions) (servertypes.ExportedApp, error) { + appOpts servertypes.AppOptions, +) (servertypes.ExportedApp, error) { encCfg := app.MakeEncodingConfig() // Ideally, we would reuse the one created by NewRootCmd. encCfg.Marshaler = codec.NewProtoCodec(encCfg.InterfaceRegistry) var linkApp *app.LinkApp diff --git a/cmd/fnsad/cmd/root_test.go b/cmd/fnsad/cmd/root_test.go index 1fc47373..8362f178 100644 --- a/cmd/fnsad/cmd/root_test.go +++ b/cmd/fnsad/cmd/root_test.go @@ -7,10 +7,11 @@ import ( "github.com/stretchr/testify/require" dbm "github.com/tendermint/tm-db" + "github.com/Finschia/ostracon/libs/log" + "github.com/Finschia/finschia-sdk/client/flags" "github.com/Finschia/finschia-sdk/server" "github.com/Finschia/finschia-sdk/store/types" - "github.com/Finschia/ostracon/libs/log" ) func TestNewApp(t *testing.T) { diff --git a/cmd/fnsad/cmd/testnet.go b/cmd/fnsad/cmd/testnet.go index 17f0cec4..ed5e42ed 100644 --- a/cmd/fnsad/cmd/testnet.go +++ b/cmd/fnsad/cmd/testnet.go @@ -12,6 +12,12 @@ import ( "github.com/spf13/cobra" + ostconfig "github.com/Finschia/ostracon/config" + ostos "github.com/Finschia/ostracon/libs/os" + ostrand "github.com/Finschia/ostracon/libs/rand" + "github.com/Finschia/ostracon/types" + osttime "github.com/Finschia/ostracon/types/time" + "github.com/Finschia/finschia-sdk/client" "github.com/Finschia/finschia-sdk/client/flags" "github.com/Finschia/finschia-sdk/client/tx" @@ -28,11 +34,6 @@ import ( "github.com/Finschia/finschia-sdk/x/genutil" genutiltypes "github.com/Finschia/finschia-sdk/x/genutil/types" stakingtypes "github.com/Finschia/finschia-sdk/x/staking/types" - ostconfig "github.com/Finschia/ostracon/config" - ostos "github.com/Finschia/ostracon/libs/os" - ostrand "github.com/Finschia/ostracon/libs/rand" - "github.com/Finschia/ostracon/types" - osttime "github.com/Finschia/ostracon/types/time" ) var ( @@ -64,15 +65,15 @@ Example: serverCtx := server.GetServerContextFromCmd(cmd) config := serverCtx.Config - outputDir, _ := cmd.Flags().GetString(flagOutputDir) // nolint: errcheck - keyringBackend, _ := cmd.Flags().GetString(flags.FlagKeyringBackend) // nolint: errcheck - chainID, _ := cmd.Flags().GetString(flags.FlagChainID) // nolint: errcheck - minGasPrices, _ := cmd.Flags().GetString(server.FlagMinGasPrices) // nolint: errcheck - nodeDirPrefix, _ := cmd.Flags().GetString(flagNodeDirPrefix) // nolint: errcheck - nodeDaemonHome, _ := cmd.Flags().GetString(flagNodeDaemonHome) // nolint: errcheck - startingIPAddress, _ := cmd.Flags().GetString(flagStartingIPAddress) // nolint: errcheck - numValidators, _ := cmd.Flags().GetInt(flagNumValidators) // nolint: errcheck - algo, _ := cmd.Flags().GetString(flags.FlagKeyAlgorithm) // nolint: errcheck + outputDir, _ := cmd.Flags().GetString(flagOutputDir) //nolint: errcheck + keyringBackend, _ := cmd.Flags().GetString(flags.FlagKeyringBackend) //nolint: errcheck + chainID, _ := cmd.Flags().GetString(flags.FlagChainID) //nolint: errcheck + minGasPrices, _ := cmd.Flags().GetString(server.FlagMinGasPrices) //nolint: errcheck + nodeDirPrefix, _ := cmd.Flags().GetString(flagNodeDirPrefix) //nolint: errcheck + nodeDaemonHome, _ := cmd.Flags().GetString(flagNodeDaemonHome) //nolint: errcheck + startingIPAddress, _ := cmd.Flags().GetString(flagStartingIPAddress) //nolint: errcheck + numValidators, _ := cmd.Flags().GetInt(flagNumValidators) //nolint: errcheck + algo, _ := cmd.Flags().GetString(flags.FlagKeyAlgorithm) //nolint: errcheck return InitTestnet( clientCtx, cmd, config, mbm, genBalIterator, outputDir, chainID, minGasPrices, @@ -128,7 +129,7 @@ func InitTestnet( appConfig.Telemetry.EnableHostnameLabel = false appConfig.Telemetry.GlobalLabels = [][]string{{"chain_id", chainID}} - // nolint: prealloc + //nolint: prealloc var ( genAccounts []authtypes.GenesisAccount genBalances []banktypes.Balance @@ -387,12 +388,12 @@ func writeFile(name string, dir string, contents []byte) error { writePath := dir file := filepath.Join(writePath, name) - err := ostos.EnsureDir(writePath, 0755) + err := ostos.EnsureDir(writePath, 0o755) if err != nil { return err } - err = ostos.WriteFile(file, contents, 0644) + err = ostos.WriteFile(file, contents, 0o644) if err != nil { return err } diff --git a/cmd/fnsad/cmd/testnet_test.go b/cmd/fnsad/cmd/testnet_test.go index 286248f7..9bc1ae41 100644 --- a/cmd/fnsad/cmd/testnet_test.go +++ b/cmd/fnsad/cmd/testnet_test.go @@ -8,13 +8,14 @@ import ( "github.com/spf13/viper" "github.com/stretchr/testify/require" + "github.com/Finschia/ostracon/libs/log" + "github.com/Finschia/finschia-sdk/client" "github.com/Finschia/finschia-sdk/client/flags" "github.com/Finschia/finschia-sdk/server" banktypes "github.com/Finschia/finschia-sdk/x/bank/types" genutiltest "github.com/Finschia/finschia-sdk/x/genutil/client/testutil" genutiltypes "github.com/Finschia/finschia-sdk/x/genutil/types" - "github.com/Finschia/ostracon/libs/log" "github.com/Finschia/finschia/v4/app" ) diff --git a/cmd/fnsad/main.go b/cmd/fnsad/main.go index b6c0593c..75d2c6b8 100644 --- a/cmd/fnsad/main.go +++ b/cmd/fnsad/main.go @@ -1,6 +1,7 @@ package main import ( + "errors" "os" "github.com/Finschia/finschia-sdk/server" @@ -14,10 +15,10 @@ func main() { rootCmd, _ := cmd.NewRootCmd() if err := svrcmd.Execute(rootCmd, app.DefaultNodeHome); err != nil { - switch e := err.(type) { - case server.ErrorCode: + var e server.ErrorCode + switch { + case errors.As(err, &e): os.Exit(e.Code) - default: os.Exit(1) }