From d41aa7af8cc484266ab1147597ced81a8c63cccd Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 19 Apr 2024 21:57:31 +0200 Subject: [PATCH] refactor(x/evidence): cleanup api (#20103) --- .../ante/testutil/expected_keepers_mocks.go | 65 ++++--------------- x/evidence/keeper/keeper_test.go | 3 - x/evidence/testutil/expected_keepers_mocks.go | 65 ------------------- x/evidence/types/expected_keepers.go | 55 +++++++--------- x/feegrant/simulation/operations.go | 7 +- 5 files changed, 40 insertions(+), 155 deletions(-) diff --git a/x/auth/ante/testutil/expected_keepers_mocks.go b/x/auth/ante/testutil/expected_keepers_mocks.go index ebe73dfecac7..d2a37f5c86a5 100644 --- a/x/auth/ante/testutil/expected_keepers_mocks.go +++ b/x/auth/ante/testutil/expected_keepers_mocks.go @@ -15,43 +15,6 @@ import ( gomock "github.com/golang/mock/gomock" ) -// MockHasEnvironment is a mock of HasEnvironment interface. -type MockHasEnvironment struct { - ctrl *gomock.Controller - recorder *MockHasEnvironmentMockRecorder -} - -// MockHasEnvironmentMockRecorder is the mock recorder for MockHasEnvironment. -type MockHasEnvironmentMockRecorder struct { - mock *MockHasEnvironment -} - -// NewMockHasEnvironment creates a new mock instance. -func NewMockHasEnvironment(ctrl *gomock.Controller) *MockHasEnvironment { - mock := &MockHasEnvironment{ctrl: ctrl} - mock.recorder = &MockHasEnvironmentMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockHasEnvironment) EXPECT() *MockHasEnvironmentMockRecorder { - return m.recorder -} - -// Environment mocks base method. -func (m *MockHasEnvironment) Environment() appmodule.Environment { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Environment") - ret0, _ := ret[0].(appmodule.Environment) - return ret0 -} - -// Environment indicates an expected call of Environment. -func (mr *MockHasEnvironmentMockRecorder) Environment() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Environment", reflect.TypeOf((*MockHasEnvironment)(nil).Environment)) -} - // MockAccountKeeper is a mock of AccountKeeper interface. type MockAccountKeeper struct { ctrl *gomock.Controller @@ -89,20 +52,6 @@ func (mr *MockAccountKeeperMockRecorder) AddressCodec() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddressCodec", reflect.TypeOf((*MockAccountKeeper)(nil).AddressCodec)) } -// Environment mocks base method. -func (m *MockAccountKeeper) Environment() appmodule.Environment { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Environment") - ret0, _ := ret[0].(appmodule.Environment) - return ret0 -} - -// Environment indicates an expected call of Environment. -func (mr *MockAccountKeeperMockRecorder) Environment() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Environment", reflect.TypeOf((*MockAccountKeeper)(nil).Environment)) -} - // GetAccount mocks base method. func (m *MockAccountKeeper) GetAccount(ctx context.Context, addr types0.AccAddress) types0.AccountI { m.ctrl.T.Helper() @@ -117,6 +66,20 @@ func (mr *MockAccountKeeperMockRecorder) GetAccount(ctx, addr interface{}) *gomo return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAccount", reflect.TypeOf((*MockAccountKeeper)(nil).GetAccount), ctx, addr) } +// GetEnvironment mocks base method. +func (m *MockAccountKeeper) GetEnvironment() appmodule.Environment { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetEnvironment") + ret0, _ := ret[0].(appmodule.Environment) + return ret0 +} + +// GetEnvironment indicates an expected call of GetEnvironment. +func (mr *MockAccountKeeperMockRecorder) GetEnvironment() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetEnvironment", reflect.TypeOf((*MockAccountKeeper)(nil).GetEnvironment)) +} + // GetModuleAddress mocks base method. func (m *MockAccountKeeper) GetModuleAddress(moduleName string) types0.AccAddress { m.ctrl.T.Helper() diff --git a/x/evidence/keeper/keeper_test.go b/x/evidence/keeper/keeper_test.go index a21edc60d7c9..0f9641a2dbfd 100644 --- a/x/evidence/keeper/keeper_test.go +++ b/x/evidence/keeper/keeper_test.go @@ -79,7 +79,6 @@ type KeeperTestSuite struct { consAddressCodec coreaddress.ConsensusAddressCodec evidenceKeeper keeper.Keeper - bankKeeper *evidencetestutil.MockBankKeeper accountKeeper *evidencetestutil.MockAccountKeeper slashingKeeper *evidencetestutil.MockSlashingKeeper stakingKeeper *evidencetestutil.MockStakingKeeper @@ -103,7 +102,6 @@ func (suite *KeeperTestSuite) SetupTest() { stakingKeeper := evidencetestutil.NewMockStakingKeeper(ctrl) slashingKeeper := evidencetestutil.NewMockSlashingKeeper(ctrl) accountKeeper := evidencetestutil.NewMockAccountKeeper(ctrl) - bankKeeper := evidencetestutil.NewMockBankKeeper(ctrl) evidenceKeeper := keeper.NewKeeper( encCfg.Codec, @@ -115,7 +113,6 @@ func (suite *KeeperTestSuite) SetupTest() { suite.stakingKeeper = stakingKeeper suite.slashingKeeper = slashingKeeper - suite.bankKeeper = bankKeeper router := types.NewRouter() router = router.AddRoute(types.RouteEquivocation, testEquivocationHandler(evidenceKeeper)) diff --git a/x/evidence/testutil/expected_keepers_mocks.go b/x/evidence/testutil/expected_keepers_mocks.go index 21b214f405d1..77aaba045a5c 100644 --- a/x/evidence/testutil/expected_keepers_mocks.go +++ b/x/evidence/testutil/expected_keepers_mocks.go @@ -254,68 +254,3 @@ func (mr *MockAccountKeeperMockRecorder) SetAccount(ctx, acc interface{}) *gomoc mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetAccount", reflect.TypeOf((*MockAccountKeeper)(nil).SetAccount), ctx, acc) } - -// MockBankKeeper is a mock of BankKeeper interface. -type MockBankKeeper struct { - ctrl *gomock.Controller - recorder *MockBankKeeperMockRecorder -} - -// MockBankKeeperMockRecorder is the mock recorder for MockBankKeeper. -type MockBankKeeperMockRecorder struct { - mock *MockBankKeeper -} - -// NewMockBankKeeper creates a new mock instance. -func NewMockBankKeeper(ctrl *gomock.Controller) *MockBankKeeper { - mock := &MockBankKeeper{ctrl: ctrl} - mock.recorder = &MockBankKeeperMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockBankKeeper) EXPECT() *MockBankKeeperMockRecorder { - return m.recorder -} - -// GetAllBalances mocks base method. -func (m *MockBankKeeper) GetAllBalances(ctx types0.Context, addr types0.AccAddress) types0.Coins { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetAllBalances", ctx, addr) - ret0, _ := ret[0].(types0.Coins) - return ret0 -} - -// GetAllBalances indicates an expected call of GetAllBalances. -func (mr *MockBankKeeperMockRecorder) GetAllBalances(ctx, addr interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAllBalances", reflect.TypeOf((*MockBankKeeper)(nil).GetAllBalances), ctx, addr) -} - -// MintCoins mocks base method. -func (m *MockBankKeeper) MintCoins(ctx types0.Context, moduleName string, amt types0.Coins) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "MintCoins", ctx, moduleName, amt) - ret0, _ := ret[0].(error) - return ret0 -} - -// MintCoins indicates an expected call of MintCoins. -func (mr *MockBankKeeperMockRecorder) MintCoins(ctx, moduleName, amt interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "MintCoins", reflect.TypeOf((*MockBankKeeper)(nil).MintCoins), ctx, moduleName, amt) -} - -// SendCoinsFromModuleToAccount mocks base method. -func (m *MockBankKeeper) SendCoinsFromModuleToAccount(ctx types0.Context, senderModule string, recipientAddr types0.AccAddress, amt types0.Coins) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SendCoinsFromModuleToAccount", ctx, senderModule, recipientAddr, amt) - ret0, _ := ret[0].(error) - return ret0 -} - -// SendCoinsFromModuleToAccount indicates an expected call of SendCoinsFromModuleToAccount. -func (mr *MockBankKeeperMockRecorder) SendCoinsFromModuleToAccount(ctx, senderModule, recipientAddr, amt interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendCoinsFromModuleToAccount", reflect.TypeOf((*MockBankKeeper)(nil).SendCoinsFromModuleToAccount), ctx, senderModule, recipientAddr, amt) -} diff --git a/x/evidence/types/expected_keepers.go b/x/evidence/types/expected_keepers.go index dbc59592b21e..3362deb8c4b6 100644 --- a/x/evidence/types/expected_keepers.go +++ b/x/evidence/types/expected_keepers.go @@ -12,37 +12,28 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -type ( - // StakingKeeper defines the staking module interface contract needed by the - // evidence module. - StakingKeeper interface { - ConsensusAddressCodec() address.Codec - ValidatorByConsAddr(context.Context, sdk.ConsAddress) (sdk.ValidatorI, error) - } +// StakingKeeper defines the staking module interface contract needed by the +// evidence module. +type StakingKeeper interface { + ConsensusAddressCodec() address.Codec + ValidatorByConsAddr(context.Context, sdk.ConsAddress) (sdk.ValidatorI, error) +} - // SlashingKeeper defines the slashing module interface contract needed by the - // evidence module. - SlashingKeeper interface { - GetPubkey(context.Context, cryptotypes.Address) (cryptotypes.PubKey, error) - IsTombstoned(context.Context, sdk.ConsAddress) bool - HasValidatorSigningInfo(context.Context, sdk.ConsAddress) bool - Tombstone(context.Context, sdk.ConsAddress) error - Slash(context.Context, sdk.ConsAddress, math.LegacyDec, int64, int64) error - SlashWithInfractionReason(context.Context, sdk.ConsAddress, math.LegacyDec, int64, int64, st.Infraction) error - SlashFractionDoubleSign(context.Context) (math.LegacyDec, error) - Jail(context.Context, sdk.ConsAddress) error - JailUntil(context.Context, sdk.ConsAddress, time.Time) error - } +// SlashingKeeper defines the slashing module interface contract needed by the +// evidence module. +type SlashingKeeper interface { + GetPubkey(context.Context, cryptotypes.Address) (cryptotypes.PubKey, error) + IsTombstoned(context.Context, sdk.ConsAddress) bool + HasValidatorSigningInfo(context.Context, sdk.ConsAddress) bool + Tombstone(context.Context, sdk.ConsAddress) error + Slash(context.Context, sdk.ConsAddress, math.LegacyDec, int64, int64) error + SlashWithInfractionReason(context.Context, sdk.ConsAddress, math.LegacyDec, int64, int64, st.Infraction) error + SlashFractionDoubleSign(context.Context) (math.LegacyDec, error) + Jail(context.Context, sdk.ConsAddress) error + JailUntil(context.Context, sdk.ConsAddress, time.Time) error +} - // AccountKeeper define the account keeper interface contracted needed by the evidence module - AccountKeeper interface { - SetAccount(ctx context.Context, acc sdk.AccountI) - } - - // BankKeeper define the account keeper interface contracted needed by the evidence module - BankKeeper interface { - MintCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error - SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error - GetAllBalances(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins - } -) +// AccountKeeper define the account keeper interface contracted needed by the evidence module +type AccountKeeper interface { + SetAccount(ctx context.Context, acc sdk.AccountI) +} diff --git a/x/feegrant/simulation/operations.go b/x/feegrant/simulation/operations.go index 78bb2950f345..c82677d4fa09 100644 --- a/x/feegrant/simulation/operations.go +++ b/x/feegrant/simulation/operations.go @@ -65,7 +65,7 @@ func WeightedOperations( ), simulation.NewWeightedOperation( weightMsgRevokeAllowance, - SimulateMsgRevokeAllowance(pCdc, txConfig, ak, bk, k, ac), + SimulateMsgRevokeAllowance(pCdc, txConfig, ak, bk, k), ), } } @@ -141,7 +141,6 @@ func SimulateMsgRevokeAllowance( ak feegrant.AccountKeeper, bk feegrant.BankKeeper, k keeper.Keeper, - ac address.Codec, ) simtypes.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, @@ -151,11 +150,11 @@ func SimulateMsgRevokeAllowance( var granterAddr sdk.AccAddress var granteeAddr sdk.AccAddress err := k.IterateAllFeeAllowances(ctx, func(grant feegrant.Grant) bool { - granter, err := ac.StringToBytes(grant.Granter) + granter, err := ak.AddressCodec().StringToBytes(grant.Granter) if err != nil { panic(err) } - grantee, err := ac.StringToBytes(grant.Grantee) + grantee, err := ak.AddressCodec().StringToBytes(grant.Grantee) if err != nil { panic(err) }