github.com/cosmos/cosmos-sdk@v0.50.10/x/mint/keeper/keeper_test.go (about) 1 package keeper_test 2 3 import ( 4 "testing" 5 6 "github.com/golang/mock/gomock" 7 "github.com/stretchr/testify/suite" 8 9 "cosmossdk.io/math" 10 storetypes "cosmossdk.io/store/types" 11 12 "github.com/cosmos/cosmos-sdk/runtime" 13 "github.com/cosmos/cosmos-sdk/testutil" 14 sdk "github.com/cosmos/cosmos-sdk/types" 15 moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" 16 authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" 17 govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" 18 "github.com/cosmos/cosmos-sdk/x/mint" 19 "github.com/cosmos/cosmos-sdk/x/mint/keeper" 20 minttestutil "github.com/cosmos/cosmos-sdk/x/mint/testutil" 21 "github.com/cosmos/cosmos-sdk/x/mint/types" 22 ) 23 24 type IntegrationTestSuite struct { 25 suite.Suite 26 27 mintKeeper keeper.Keeper 28 ctx sdk.Context 29 msgServer types.MsgServer 30 stakingKeeper *minttestutil.MockStakingKeeper 31 bankKeeper *minttestutil.MockBankKeeper 32 } 33 34 func TestKeeperTestSuite(t *testing.T) { 35 suite.Run(t, new(IntegrationTestSuite)) 36 } 37 38 func (s *IntegrationTestSuite) SetupTest() { 39 encCfg := moduletestutil.MakeTestEncodingConfig(mint.AppModuleBasic{}) 40 key := storetypes.NewKVStoreKey(types.StoreKey) 41 storeService := runtime.NewKVStoreService(key) 42 testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) 43 s.ctx = testCtx.Ctx 44 45 // gomock initializations 46 ctrl := gomock.NewController(s.T()) 47 accountKeeper := minttestutil.NewMockAccountKeeper(ctrl) 48 bankKeeper := minttestutil.NewMockBankKeeper(ctrl) 49 stakingKeeper := minttestutil.NewMockStakingKeeper(ctrl) 50 51 accountKeeper.EXPECT().GetModuleAddress(types.ModuleName).Return(sdk.AccAddress{}) 52 53 s.mintKeeper = keeper.NewKeeper( 54 encCfg.Codec, 55 storeService, 56 stakingKeeper, 57 accountKeeper, 58 bankKeeper, 59 authtypes.FeeCollectorName, 60 authtypes.NewModuleAddress(govtypes.ModuleName).String(), 61 ) 62 s.stakingKeeper = stakingKeeper 63 s.bankKeeper = bankKeeper 64 65 s.Require().Equal(testCtx.Ctx.Logger().With("module", "x/"+types.ModuleName), 66 s.mintKeeper.Logger(testCtx.Ctx)) 67 68 err := s.mintKeeper.Params.Set(s.ctx, types.DefaultParams()) 69 s.Require().NoError(err) 70 s.Require().NoError(s.mintKeeper.Minter.Set(s.ctx, types.DefaultInitialMinter())) 71 72 s.msgServer = keeper.NewMsgServerImpl(s.mintKeeper) 73 } 74 75 func (s *IntegrationTestSuite) TestAliasFunctions() { 76 stakingTokenSupply := math.NewIntFromUint64(100000000000) 77 s.stakingKeeper.EXPECT().StakingTokenSupply(s.ctx).Return(stakingTokenSupply, nil) 78 tokenSupply, err := s.mintKeeper.StakingTokenSupply(s.ctx) 79 s.Require().NoError(err) 80 s.Require().Equal(tokenSupply, stakingTokenSupply) 81 82 bondedRatio := math.LegacyNewDecWithPrec(15, 2) 83 s.stakingKeeper.EXPECT().BondedRatio(s.ctx).Return(bondedRatio, nil) 84 ratio, err := s.mintKeeper.BondedRatio(s.ctx) 85 s.Require().NoError(err) 86 s.Require().Equal(ratio, bondedRatio) 87 88 coins := sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(1000000))) 89 s.bankKeeper.EXPECT().MintCoins(s.ctx, types.ModuleName, coins).Return(nil) 90 s.Require().Equal(s.mintKeeper.MintCoins(s.ctx, sdk.NewCoins()), nil) 91 s.Require().Nil(s.mintKeeper.MintCoins(s.ctx, coins)) 92 93 fees := sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(1000))) 94 s.bankKeeper.EXPECT().SendCoinsFromModuleToModule(s.ctx, types.ModuleName, authtypes.FeeCollectorName, fees).Return(nil) 95 s.Require().Nil(s.mintKeeper.AddCollectedFees(s.ctx, fees)) 96 }