From d491c284c4851febfae4089ae38f2a0b9310abcf Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Wed, 2 Aug 2023 17:31:36 +0200 Subject: [PATCH] refactor(staking): remove expected distribution keeper (#17261) (cherry picked from commit 6937c7642bd6a2ca58ed4b1b6b29a987ac5b526a) --- x/distribution/README.md | 21 +++++--- x/gov/testutil/expected_keepers_mocks.go | 2 +- x/staking/testutil/expected_keepers_mocks.go | 51 -------------------- x/staking/types/expected_keepers.go | 6 --- 4 files changed, 15 insertions(+), 65 deletions(-) diff --git a/x/distribution/README.md b/x/distribution/README.md index bd7153218291..32858fd696db 100644 --- a/x/distribution/README.md +++ b/x/distribution/README.md @@ -352,15 +352,22 @@ The transaction fails if the amount cannot be transferred from the sender to the ```go func (k Keeper) FundCommunityPool(ctx context.Context, amount sdk.Coins, sender sdk.AccAddress) error { - if err := k.bankKeeper.SendCoinsFromAccountToModule(ctx, sender, types.ModuleName, amount); err != nil { - return err - } + if err := k.bankKeeper.SendCoinsFromAccountToModule(ctx, sender, types.ModuleName, amount); err != nil { + return err + } - feePool := k.GetFeePool(ctx) - feePool.CommunityPool = feePool.CommunityPool.Add(sdk.NewDecCoinsFromCoins(amount...)...) - k.SetFeePool(ctx, feePool) + feePool, err := k.FeePool.Get(ctx) + if err != nil { + return err + } + + feePool.CommunityPool = feePool.CommunityPool.Add(sdk.NewDecCoinsFromCoins(amount...)...) + + if err := k.FeePool.Set(ctx, feePool); err != nil { + return err + } - return nil + return nil } ``` diff --git a/x/gov/testutil/expected_keepers_mocks.go b/x/gov/testutil/expected_keepers_mocks.go index 1a7c78d61df6..0dc0ac0b6365 100644 --- a/x/gov/testutil/expected_keepers_mocks.go +++ b/x/gov/testutil/expected_keepers_mocks.go @@ -1,7 +1,7 @@ // Code generated by MockGen. DO NOT EDIT. // Source: x/gov/testutil/expected_keepers.go -// Package mock_testutil is a generated GoMock package. +// Package testutil is a generated GoMock package. package testutil import ( diff --git a/x/staking/testutil/expected_keepers_mocks.go b/x/staking/testutil/expected_keepers_mocks.go index e66027edd2e7..e40bbd84d63e 100644 --- a/x/staking/testutil/expected_keepers_mocks.go +++ b/x/staking/testutil/expected_keepers_mocks.go @@ -15,57 +15,6 @@ import ( gomock "github.com/golang/mock/gomock" ) -// MockDistributionKeeper is a mock of DistributionKeeper interface. -type MockDistributionKeeper struct { - ctrl *gomock.Controller - recorder *MockDistributionKeeperMockRecorder -} - -// MockDistributionKeeperMockRecorder is the mock recorder for MockDistributionKeeper. -type MockDistributionKeeperMockRecorder struct { - mock *MockDistributionKeeper -} - -// NewMockDistributionKeeper creates a new mock instance. -func NewMockDistributionKeeper(ctrl *gomock.Controller) *MockDistributionKeeper { - mock := &MockDistributionKeeper{ctrl: ctrl} - mock.recorder = &MockDistributionKeeperMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockDistributionKeeper) EXPECT() *MockDistributionKeeperMockRecorder { - return m.recorder -} - -// GetFeePoolCommunityCoins mocks base method. -func (m *MockDistributionKeeper) GetFeePoolCommunityCoins(ctx context.Context) types.DecCoins { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetFeePoolCommunityCoins", ctx) - ret0, _ := ret[0].(types.DecCoins) - return ret0 -} - -// GetFeePoolCommunityCoins indicates an expected call of GetFeePoolCommunityCoins. -func (mr *MockDistributionKeeperMockRecorder) GetFeePoolCommunityCoins(ctx interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetFeePoolCommunityCoins", reflect.TypeOf((*MockDistributionKeeper)(nil).GetFeePoolCommunityCoins), ctx) -} - -// GetValidatorOutstandingRewardsCoins mocks base method. -func (m *MockDistributionKeeper) GetValidatorOutstandingRewardsCoins(ctx context.Context, val types.ValAddress) types.DecCoins { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetValidatorOutstandingRewardsCoins", ctx, val) - ret0, _ := ret[0].(types.DecCoins) - return ret0 -} - -// GetValidatorOutstandingRewardsCoins indicates an expected call of GetValidatorOutstandingRewardsCoins. -func (mr *MockDistributionKeeperMockRecorder) GetValidatorOutstandingRewardsCoins(ctx, val interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetValidatorOutstandingRewardsCoins", reflect.TypeOf((*MockDistributionKeeper)(nil).GetValidatorOutstandingRewardsCoins), ctx, val) -} - // MockAccountKeeper is a mock of AccountKeeper interface. type MockAccountKeeper struct { ctrl *gomock.Controller diff --git a/x/staking/types/expected_keepers.go b/x/staking/types/expected_keepers.go index 9ab221103179..5e45733d0af7 100644 --- a/x/staking/types/expected_keepers.go +++ b/x/staking/types/expected_keepers.go @@ -9,12 +9,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -// DistributionKeeper expected distribution keeper (noalias) -type DistributionKeeper interface { - GetFeePoolCommunityCoins(ctx context.Context) sdk.DecCoins - GetValidatorOutstandingRewardsCoins(ctx context.Context, val sdk.ValAddress) sdk.DecCoins -} - // AccountKeeper defines the expected account keeper (noalias) type AccountKeeper interface { AddressCodec() address.Codec