From dffb21a8ab71e17ac824db6a33d18a8f7774f457 Mon Sep 17 00:00:00 2001 From: zakir <80246097+zakir-code@users.noreply.github.com> Date: Tue, 22 Oct 2024 17:18:22 +0800 Subject: [PATCH] chore: remove unused field (#767) --- .golangci.yml | 4 ++++ app/export.go | 4 ---- app/keepers/keepers.go | 10 ---------- app/modules.go | 2 +- tests/integration_test.go | 16 ++++++++-------- tests/staking_suite.go | 3 --- x/crosschain/keeper/keeper.go | 4 +--- x/crosschain/keeper/keeper_test.go | 15 +++++---------- x/crosschain/precompile/contract_test.go | 13 ++++++------- x/erc20/keeper/keeper.go | 6 ------ x/evm/keeper/keeper.go | 4 +--- x/evm/module.go | 4 +--- x/gov/module.go | 4 +--- x/staking/keeper/keeper.go | 5 +---- 14 files changed, 29 insertions(+), 65 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index b2b25d8d..d652e142 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -78,6 +78,10 @@ linters-settings: errcheck: check-type-assertions: false check-blank: false + unused: + field-writes-are-uses: false + exported-fields-are-used: false + local-variables-are-used: false revive: # https://golangci-lint.run/usage/linters/#revive enable-all-rules: true diff --git a/app/export.go b/app/export.go index f4c3e77d..37521671 100644 --- a/app/export.go +++ b/app/export.go @@ -225,8 +225,6 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str store := ctx.KVStore(app.GetKey(stakingtypes.StoreKey)) iter := storetypes.KVStoreReversePrefixIterator(store, stakingtypes.ValidatorsKey) - counter := int16(0) - // Closure to ensure iterator doesn't leak. func() { defer iter.Close() @@ -245,8 +243,6 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str if err = app.StakingKeeper.SetValidator(ctx, validator); err != nil { panic(err) } - - counter++ } }() diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index 1f63042f..0a579cb5 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -234,7 +234,6 @@ func NewAppKeeper( authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ConsensusAddrPrefix()), ), appKeepers.keys[stakingtypes.StoreKey], - appCodec, ) appKeepers.MintKeeper = mintkeeper.NewKeeper( @@ -355,7 +354,6 @@ func NewAppKeeper( appKeepers.EvmKeeper = fxevmkeeper.NewKeeper( evmKeeper, appKeepers.AccountKeeper, - appKeepers.BankKeeper, ) appKeepers.Erc20Keeper = erc20keeper.NewKeeper( @@ -381,7 +379,6 @@ func NewAppKeeper( appKeepers.Erc20Keeper, appKeepers.AccountKeeper, appKeepers.EvmKeeper, - appKeepers.EvmKeeper, authAddr, ) appKeepers.PolygonKeeper = crosschainkeeper.NewKeeper( @@ -396,7 +393,6 @@ func NewAppKeeper( appKeepers.Erc20Keeper, appKeepers.AccountKeeper, appKeepers.EvmKeeper, - appKeepers.EvmKeeper, authAddr, ) appKeepers.AvalancheKeeper = crosschainkeeper.NewKeeper( @@ -411,7 +407,6 @@ func NewAppKeeper( appKeepers.Erc20Keeper, appKeepers.AccountKeeper, appKeepers.EvmKeeper, - appKeepers.EvmKeeper, authAddr, ) appKeepers.EthKeeper = crosschainkeeper.NewKeeper( @@ -426,7 +421,6 @@ func NewAppKeeper( appKeepers.Erc20Keeper, appKeepers.AccountKeeper, appKeepers.EvmKeeper, - appKeepers.EvmKeeper, authAddr, ) appKeepers.ArbitrumKeeper = crosschainkeeper.NewKeeper( @@ -441,7 +435,6 @@ func NewAppKeeper( appKeepers.Erc20Keeper, appKeepers.AccountKeeper, appKeepers.EvmKeeper, - appKeepers.EvmKeeper, authAddr, ) appKeepers.OptimismKeeper = crosschainkeeper.NewKeeper( @@ -456,7 +449,6 @@ func NewAppKeeper( appKeepers.Erc20Keeper, appKeepers.AccountKeeper, appKeepers.EvmKeeper, - appKeepers.EvmKeeper, authAddr, ) appKeepers.Layer2Keeper = crosschainkeeper.NewKeeper( @@ -471,7 +463,6 @@ func NewAppKeeper( appKeepers.Erc20Keeper, appKeepers.AccountKeeper, appKeepers.EvmKeeper, - appKeepers.EvmKeeper, authAddr, ) appKeepers.TronKeeper = crosschainkeeper.NewKeeper( @@ -486,7 +477,6 @@ func NewAppKeeper( appKeepers.Erc20Keeper, appKeepers.AccountKeeper, appKeepers.EvmKeeper, - appKeepers.EvmKeeper, authAddr, ) diff --git a/app/modules.go b/app/modules.go index 8fc9b3e1..5b819e3f 100644 --- a/app/modules.go +++ b/app/modules.go @@ -108,7 +108,7 @@ func appModules( bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper, app.GetSubspace(banktypes.ModuleName)), capability.NewAppModule(appCodec, *app.CapabilityKeeper, false), crisis.NewAppModule(app.CrisisKeeper, skipGenesisInvariants, app.GetSubspace(crisistypes.ModuleName)), - fxgov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(govtypes.ModuleName)), + fxgov.NewAppModule(app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(govtypes.ModuleName)), mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, nil, app.GetSubspace(minttypes.ModuleName)), slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(slashingtypes.ModuleName), app.interfaceRegistry), distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(distrtypes.ModuleName)), diff --git a/tests/integration_test.go b/tests/integration_test.go index a8e959a7..0438e093 100644 --- a/tests/integration_test.go +++ b/tests/integration_test.go @@ -21,10 +21,10 @@ import ( type IntegrationTest struct { *TestSuite crosschain []CrosschainTestSuite - erc20 Erc20TestSuite - evm EvmTestSuite - staking StakingSuite - precompile PrecompileTestSuite + // erc20 Erc20TestSuite + evm EvmTestSuite + staking StakingSuite + // precompile PrecompileTestSuite } func TestIntegrationTest(t *testing.T) { @@ -40,10 +40,10 @@ func TestIntegrationTest(t *testing.T) { NewCrosschainWithTestSuite(bsctypes.ModuleName, testSuite), NewCrosschainWithTestSuite(trontypes.ModuleName, testSuite), }, - erc20: NewErc20TestSuite(testSuite), - evm: NewEvmTestSuite(testSuite), - staking: NewStakingSuite(testSuite), - precompile: NewPrecompileTestSuite(testSuite), + // erc20: NewErc20TestSuite(testSuite), + evm: NewEvmTestSuite(testSuite), + staking: NewStakingSuite(testSuite), + // precompile: NewPrecompileTestSuite(testSuite), } if runtime.GOOS == "linux" { evmChainModules := []string{ diff --git a/tests/staking_suite.go b/tests/staking_suite.go index 5ef353f9..30766edf 100644 --- a/tests/staking_suite.go +++ b/tests/staking_suite.go @@ -12,7 +12,6 @@ import ( slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/ethereum/go-ethereum" - "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" ethtypes "github.com/ethereum/go-ethereum/core/types" @@ -28,7 +27,6 @@ import ( type StakingSuite struct { Erc20TestSuite - abi abi.ABI grantKey cryptotypes.PrivKey } @@ -36,7 +34,6 @@ func NewStakingSuite(ts *TestSuite) StakingSuite { key := helpers.NewEthPrivKey() return StakingSuite{ Erc20TestSuite: NewErc20TestSuite(ts), - abi: stakingprecompile.GetABI(), grantKey: key, } } diff --git a/x/crosschain/keeper/keeper.go b/x/crosschain/keeper/keeper.go index 7ff69f99..9aa5278c 100644 --- a/x/crosschain/keeper/keeper.go +++ b/x/crosschain/keeper/keeper.go @@ -28,7 +28,6 @@ type Keeper struct { ibcTransferKeeper types.IBCTransferKeeper erc20Keeper types.Erc20Keeper evmKeeper types.EVMKeeper - evmErc20Keeper types.EvmERC20Keeper authority string callbackFrom common.Address @@ -38,7 +37,7 @@ type Keeper struct { func NewKeeper(cdc codec.BinaryCodec, moduleName string, storeKey storetypes.StoreKey, stakingKeeper types.StakingKeeper, stakingMsgServer types.StakingMsgServer, distributionKeeper types.DistributionMsgServer, bankKeeper types.BankKeeper, ibcTransferKeeper types.IBCTransferKeeper, erc20Keeper types.Erc20Keeper, ak types.AccountKeeper, - evmKeeper types.EVMKeeper, evmErc20Keeper types.EvmERC20Keeper, authority string, + evmKeeper types.EVMKeeper, authority string, ) Keeper { if addr := ak.GetModuleAddress(moduleName); addr == nil { panic(fmt.Sprintf("%s module account has not been set", moduleName)) @@ -57,7 +56,6 @@ func NewKeeper(cdc codec.BinaryCodec, moduleName string, storeKey storetypes.Sto ibcTransferKeeper: ibcTransferKeeper, erc20Keeper: erc20Keeper, evmKeeper: evmKeeper, - evmErc20Keeper: evmErc20Keeper, authority: authority, callbackFrom: common.BytesToAddress(autytypes.NewModuleAddress(types.BridgeCallSender)), } diff --git a/x/crosschain/keeper/keeper_test.go b/x/crosschain/keeper/keeper_test.go index ba67af82..8d52e1c0 100644 --- a/x/crosschain/keeper/keeper_test.go +++ b/x/crosschain/keeper/keeper_test.go @@ -32,12 +32,11 @@ import ( type KeeperMockSuite struct { suite.Suite - ctx sdk.Context - moduleName string - wfxTokenAddr string + ctx sdk.Context + moduleName string queryClient types.QueryClient - msgServer types.MsgServer + // msgServer types.MsgServer crosschainKeeper crosschainkeeper.Keeper stakingKeeper *mock.MockStakingKeeper @@ -48,7 +47,6 @@ type KeeperMockSuite struct { erc20Keeper *mock.MockErc20Keeper accountKeeper *mock.MockAccountKeeper evmKeeper *mock.MockEVMKeeper - evmErc20Keeper *mock.MockEvmERC20Keeper } func TestKeeperTestSuite(t *testing.T) { @@ -69,8 +67,7 @@ func TestKeeperTestSuite(t *testing.T) { } for _, moduleName := range subModules { suite.Run(t, &KeeperMockSuite{ - moduleName: moduleName, - wfxTokenAddr: helpers.GenHexAddress().String(), + moduleName: moduleName, }) } } @@ -99,7 +96,6 @@ func (s *KeeperMockSuite) SetupTest() { s.erc20Keeper = mock.NewMockErc20Keeper(ctrl) s.accountKeeper = mock.NewMockAccountKeeper(ctrl) s.evmKeeper = mock.NewMockEVMKeeper(ctrl) - s.evmErc20Keeper = mock.NewMockEvmERC20Keeper(ctrl) s.accountKeeper.EXPECT().GetModuleAddress(s.moduleName).Return(authtypes.NewEmptyModuleAccount(s.moduleName).GetAddress()).Times(1) @@ -115,7 +111,6 @@ func (s *KeeperMockSuite) SetupTest() { s.erc20Keeper, s.accountKeeper, s.evmKeeper, - s.evmErc20Keeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) @@ -126,7 +121,7 @@ func (s *KeeperMockSuite) SetupTest() { queryHelper := baseapp.NewQueryServerTestHelper(s.ctx, myApp.InterfaceRegistry()) types.RegisterQueryServer(queryHelper, crosschainRouterKeeper) s.queryClient = types.NewQueryClient(queryHelper) - s.msgServer = crosschainkeeper.NewMsgServerRouterImpl(crosschainRouterKeeper) + // s.msgServer = crosschainkeeper.NewMsgServerRouterImpl(crosschainRouterKeeper) params := s.CrosschainParams() params.EnableSendToExternalPending = true diff --git a/x/crosschain/precompile/contract_test.go b/x/crosschain/precompile/contract_test.go index 0b9d9734..db82f10c 100644 --- a/x/crosschain/precompile/contract_test.go +++ b/x/crosschain/precompile/contract_test.go @@ -31,7 +31,6 @@ import ( "github.com/stretchr/testify/suite" "github.com/functionx/fx-core/v8/contract" - testscontract "github.com/functionx/fx-core/v8/tests/contract" "github.com/functionx/fx-core/v8/testutil/helpers" fxtypes "github.com/functionx/fx-core/v8/types" crosschainkeeper "github.com/functionx/fx-core/v8/x/crosschain/keeper" @@ -41,8 +40,8 @@ import ( type PrecompileTestSuite struct { helpers.BaseSuite - signer *helpers.Signer - crosschain common.Address + // signer *helpers.Signer + // crosschain common.Address } func TestPrecompileTestSuite(t *testing.T) { @@ -54,11 +53,11 @@ func (suite *PrecompileTestSuite) SetupTest() { suite.Ctx = suite.Ctx.WithMinGasPrices(sdk.NewDecCoins(sdk.NewDecCoin(fxtypes.DefaultDenom, sdkmath.OneInt()))) suite.Ctx = suite.Ctx.WithBlockGasMeter(storetypes.NewGasMeter(1e18)) - suite.signer = suite.AddTestSigner(10_000) + // suite.signer = suite.AddTestSigner(10_000) - crosschainContract, err := suite.App.EvmKeeper.DeployContract(suite.Ctx, suite.signer.Address(), contract.MustABIJson(testscontract.CrosschainTestMetaData.ABI), contract.MustDecodeHex(testscontract.CrosschainTestMetaData.Bin)) - suite.Require().NoError(err) - suite.crosschain = crosschainContract + // crosschainContract, err := suite.App.EvmKeeper.DeployContract(suite.Ctx, suite.signer.Address(), contract.MustABIJson(testscontract.CrosschainTestMetaData.ABI), contract.MustDecodeHex(testscontract.CrosschainTestMetaData.Bin)) + // suite.Require().NoError(err) + // suite.crosschain = crosschainContract } func (suite *PrecompileTestSuite) SetupSubTest() { diff --git a/x/erc20/keeper/keeper.go b/x/erc20/keeper/keeper.go index 816c5102..96bc1a60 100644 --- a/x/erc20/keeper/keeper.go +++ b/x/erc20/keeper/keeper.go @@ -19,10 +19,6 @@ import ( // Keeper of this module maintains collections of erc20. type Keeper struct { - storeService store.KVStoreService - - cdc codec.BinaryCodec - accountKeeper types.AccountKeeper bankKeeper types.BankKeeper evmKeeper types.EVMKeeper @@ -58,8 +54,6 @@ func NewKeeper( sb := collections.NewSchemaBuilder(storeService) k := Keeper{ - cdc: cdc, - storeService: storeService, accountKeeper: ak, bankKeeper: bk, evmKeeper: evmKeeper, diff --git a/x/evm/keeper/keeper.go b/x/evm/keeper/keeper.go index 425eac06..ab7fbf06 100644 --- a/x/evm/keeper/keeper.go +++ b/x/evm/keeper/keeper.go @@ -28,11 +28,10 @@ type Keeper struct { // access to account state accountKeeper fxevmtypes.AccountKeeper - bankkeeper types.BankKeeper module common.Address } -func NewKeeper(ek *evmkeeper.Keeper, ak fxevmtypes.AccountKeeper, bk types.BankKeeper) *Keeper { +func NewKeeper(ek *evmkeeper.Keeper, ak fxevmtypes.AccountKeeper) *Keeper { addr := ak.GetModuleAddress(types.ModuleName) if addr == nil { panic(fmt.Sprintf("%s module account has not been set", types.ModuleName)) @@ -40,7 +39,6 @@ func NewKeeper(ek *evmkeeper.Keeper, ak fxevmtypes.AccountKeeper, bk types.BankK return &Keeper{ Keeper: ek, accountKeeper: ak, - bankkeeper: bk, module: common.BytesToAddress(addr), } } diff --git a/x/evm/module.go b/x/evm/module.go index bf62b634..136c17c8 100644 --- a/x/evm/module.go +++ b/x/evm/module.go @@ -78,8 +78,7 @@ func (b AppModuleBasic) GetQueryCmd() *cobra.Command { type AppModule struct { AppModuleBasic evm.AppModule - keeper *keeper.Keeper - legacySubspace evmtypes.Subspace + keeper *keeper.Keeper } // NewAppModule creates a new AppModule object @@ -88,7 +87,6 @@ func NewAppModule(k *keeper.Keeper, accountKeeper evmtypes.AccountKeeper, legacy AppModule: evm.NewAppModule(k.Keeper, accountKeeper, legacySubspace), AppModuleBasic: AppModuleBasic{}, keeper: k, - legacySubspace: legacySubspace, } } diff --git a/x/gov/module.go b/x/gov/module.go index 6a30d551..f3bc0b11 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -86,18 +86,16 @@ type AppModule struct { keeper *keeper.Keeper accountKeeper govtypes.AccountKeeper bankKeeper govtypes.BankKeeper - cdc codec.Codec legacySubspace govtypes.ParamSubspace } // NewAppModule creates a new AppModule object -func NewAppModule(cdc codec.Codec, keeper *keeper.Keeper, ak govtypes.AccountKeeper, bk govtypes.BankKeeper, ss govtypes.ParamSubspace) AppModule { +func NewAppModule(keeper *keeper.Keeper, ak govtypes.AccountKeeper, bk govtypes.BankKeeper, ss govtypes.ParamSubspace) AppModule { return AppModule{ AppModuleBasic: AppModuleBasic{}, keeper: keeper, accountKeeper: ak, bankKeeper: bk, - cdc: cdc, legacySubspace: ss, } } diff --git a/x/staking/keeper/keeper.go b/x/staking/keeper/keeper.go index 595cd8b5..a8133919 100644 --- a/x/staking/keeper/keeper.go +++ b/x/staking/keeper/keeper.go @@ -2,20 +2,17 @@ package keeper import ( storetypes "cosmossdk.io/store/types" - "github.com/cosmos/cosmos-sdk/codec" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" ) type Keeper struct { *stakingkeeper.Keeper storeKey storetypes.StoreKey - cdc codec.Codec } -func NewKeeper(k *stakingkeeper.Keeper, storeKey storetypes.StoreKey, cdc codec.Codec) *Keeper { +func NewKeeper(k *stakingkeeper.Keeper, storeKey storetypes.StoreKey) *Keeper { return &Keeper{ Keeper: k, storeKey: storeKey, - cdc: cdc, } }