Skip to content

Commit

Permalink
chore: remove unused field (#767)
Browse files Browse the repository at this point in the history
  • Loading branch information
zakir-code authored Oct 22, 2024
1 parent 5f042cf commit dffb21a
Show file tree
Hide file tree
Showing 14 changed files with 29 additions and 65 deletions.
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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++
}
}()

Expand Down
10 changes: 0 additions & 10 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ func NewAppKeeper(
authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ConsensusAddrPrefix()),
),
appKeepers.keys[stakingtypes.StoreKey],
appCodec,
)

appKeepers.MintKeeper = mintkeeper.NewKeeper(
Expand Down Expand Up @@ -355,7 +354,6 @@ func NewAppKeeper(
appKeepers.EvmKeeper = fxevmkeeper.NewKeeper(
evmKeeper,
appKeepers.AccountKeeper,
appKeepers.BankKeeper,
)

appKeepers.Erc20Keeper = erc20keeper.NewKeeper(
Expand All @@ -381,7 +379,6 @@ func NewAppKeeper(
appKeepers.Erc20Keeper,
appKeepers.AccountKeeper,
appKeepers.EvmKeeper,
appKeepers.EvmKeeper,
authAddr,
)
appKeepers.PolygonKeeper = crosschainkeeper.NewKeeper(
Expand All @@ -396,7 +393,6 @@ func NewAppKeeper(
appKeepers.Erc20Keeper,
appKeepers.AccountKeeper,
appKeepers.EvmKeeper,
appKeepers.EvmKeeper,
authAddr,
)
appKeepers.AvalancheKeeper = crosschainkeeper.NewKeeper(
Expand All @@ -411,7 +407,6 @@ func NewAppKeeper(
appKeepers.Erc20Keeper,
appKeepers.AccountKeeper,
appKeepers.EvmKeeper,
appKeepers.EvmKeeper,
authAddr,
)
appKeepers.EthKeeper = crosschainkeeper.NewKeeper(
Expand All @@ -426,7 +421,6 @@ func NewAppKeeper(
appKeepers.Erc20Keeper,
appKeepers.AccountKeeper,
appKeepers.EvmKeeper,
appKeepers.EvmKeeper,
authAddr,
)
appKeepers.ArbitrumKeeper = crosschainkeeper.NewKeeper(
Expand All @@ -441,7 +435,6 @@ func NewAppKeeper(
appKeepers.Erc20Keeper,
appKeepers.AccountKeeper,
appKeepers.EvmKeeper,
appKeepers.EvmKeeper,
authAddr,
)
appKeepers.OptimismKeeper = crosschainkeeper.NewKeeper(
Expand All @@ -456,7 +449,6 @@ func NewAppKeeper(
appKeepers.Erc20Keeper,
appKeepers.AccountKeeper,
appKeepers.EvmKeeper,
appKeepers.EvmKeeper,
authAddr,
)
appKeepers.Layer2Keeper = crosschainkeeper.NewKeeper(
Expand All @@ -471,7 +463,6 @@ func NewAppKeeper(
appKeepers.Erc20Keeper,
appKeepers.AccountKeeper,
appKeepers.EvmKeeper,
appKeepers.EvmKeeper,
authAddr,
)
appKeepers.TronKeeper = crosschainkeeper.NewKeeper(
Expand All @@ -486,7 +477,6 @@ func NewAppKeeper(
appKeepers.Erc20Keeper,
appKeepers.AccountKeeper,
appKeepers.EvmKeeper,
appKeepers.EvmKeeper,
authAddr,
)

Expand Down
2 changes: 1 addition & 1 deletion app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
16 changes: 8 additions & 8 deletions tests/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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{
Expand Down
3 changes: 0 additions & 3 deletions tests/staking_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -28,15 +27,13 @@ import (

type StakingSuite struct {
Erc20TestSuite
abi abi.ABI
grantKey cryptotypes.PrivKey
}

func NewStakingSuite(ts *TestSuite) StakingSuite {
key := helpers.NewEthPrivKey()
return StakingSuite{
Erc20TestSuite: NewErc20TestSuite(ts),
abi: stakingprecompile.GetABI(),
grantKey: key,
}
}
Expand Down
4 changes: 1 addition & 3 deletions x/crosschain/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ type Keeper struct {
ibcTransferKeeper types.IBCTransferKeeper
erc20Keeper types.Erc20Keeper
evmKeeper types.EVMKeeper
evmErc20Keeper types.EvmERC20Keeper

authority string
callbackFrom common.Address
Expand All @@ -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))
Expand All @@ -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)),
}
Expand Down
15 changes: 5 additions & 10 deletions x/crosschain/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -48,7 +47,6 @@ type KeeperMockSuite struct {
erc20Keeper *mock.MockErc20Keeper
accountKeeper *mock.MockAccountKeeper
evmKeeper *mock.MockEVMKeeper
evmErc20Keeper *mock.MockEvmERC20Keeper
}

func TestKeeperTestSuite(t *testing.T) {
Expand All @@ -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,
})
}
}
Expand Down Expand Up @@ -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)

Expand All @@ -115,7 +111,6 @@ func (s *KeeperMockSuite) SetupTest() {
s.erc20Keeper,
s.accountKeeper,
s.evmKeeper,
s.evmErc20Keeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

Expand All @@ -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
Expand Down
13 changes: 6 additions & 7 deletions x/crosschain/precompile/contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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) {
Expand All @@ -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() {
Expand Down
6 changes: 0 additions & 6 deletions x/erc20/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -58,8 +54,6 @@ func NewKeeper(

sb := collections.NewSchemaBuilder(storeService)
k := Keeper{
cdc: cdc,
storeService: storeService,
accountKeeper: ak,
bankKeeper: bk,
evmKeeper: evmKeeper,
Expand Down
4 changes: 1 addition & 3 deletions x/evm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,17 @@ 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))
}
return &Keeper{
Keeper: ek,
accountKeeper: ak,
bankkeeper: bk,
module: common.BytesToAddress(addr),
}
}
Expand Down
4 changes: 1 addition & 3 deletions x/evm/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
}
}

Expand Down
4 changes: 1 addition & 3 deletions x/gov/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand Down
5 changes: 1 addition & 4 deletions x/staking/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

0 comments on commit dffb21a

Please sign in to comment.