-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
## Description missed the test coverage in last audit. ref: #13988 #13456 --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable) (cherry picked from commit e087566) Co-authored-by: atheeshp <59333759+atheeshp@users.noreply.github.com>
- Loading branch information
1 parent
7f50dfa
commit 7217de3
Showing
4 changed files
with
114 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"cosmossdk.io/math" | ||
"github.com/golang/mock/gomock" | ||
"github.com/stretchr/testify/suite" | ||
|
||
"github.com/cosmos/cosmos-sdk/codec" | ||
storetypes "github.com/cosmos/cosmos-sdk/store/types" | ||
"github.com/cosmos/cosmos-sdk/testutil" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" | ||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" | ||
"github.com/cosmos/cosmos-sdk/x/mint" | ||
"github.com/cosmos/cosmos-sdk/x/mint/keeper" | ||
minttestutil "github.com/cosmos/cosmos-sdk/x/mint/testutil" | ||
"github.com/cosmos/cosmos-sdk/x/mint/types" | ||
) | ||
|
||
var minterAcc = authtypes.NewEmptyModuleAccount(types.ModuleName, authtypes.Minter) | ||
|
||
type GenesisTestSuite struct { | ||
suite.Suite | ||
|
||
sdkCtx sdk.Context | ||
keeper keeper.Keeper | ||
cdc codec.BinaryCodec | ||
accountKeeper types.AccountKeeper | ||
key *storetypes.KVStoreKey | ||
} | ||
|
||
func TestGenesisTestSuite(t *testing.T) { | ||
suite.Run(t, new(GenesisTestSuite)) | ||
} | ||
|
||
func (s *GenesisTestSuite) SetupTest() { | ||
key := sdk.NewKVStoreKey(types.StoreKey) | ||
testCtx := testutil.DefaultContextWithDB(s.T(), key, sdk.NewTransientStoreKey("transient_test")) | ||
encCfg := moduletestutil.MakeTestEncodingConfig(mint.AppModuleBasic{}) | ||
|
||
// gomock initializations | ||
ctrl := gomock.NewController(s.T()) | ||
s.cdc = codec.NewProtoCodec(encCfg.InterfaceRegistry) | ||
s.sdkCtx = testCtx.Ctx | ||
s.key = key | ||
|
||
stakingKeeper := minttestutil.NewMockStakingKeeper(ctrl) | ||
accountKeeper := minttestutil.NewMockAccountKeeper(ctrl) | ||
bankKeeper := minttestutil.NewMockBankKeeper(ctrl) | ||
s.accountKeeper = accountKeeper | ||
accountKeeper.EXPECT().GetModuleAddress(minterAcc.Name).Return(minterAcc.GetAddress()) | ||
accountKeeper.EXPECT().GetModuleAccount(s.sdkCtx, minterAcc.Name).Return(minterAcc) | ||
|
||
s.keeper = keeper.NewKeeper(s.cdc, key, stakingKeeper, accountKeeper, bankKeeper, "", "") | ||
} | ||
|
||
func (s *GenesisTestSuite) TestImportExportGenesis() { | ||
genesisState := types.DefaultGenesisState() | ||
genesisState.Minter = types.NewMinter(sdk.NewDecWithPrec(20, 2), math.LegacyNewDec(1)) | ||
genesisState.Params = types.NewParams( | ||
"testDenom", | ||
sdk.NewDecWithPrec(15, 2), | ||
sdk.NewDecWithPrec(22, 2), | ||
sdk.NewDecWithPrec(9, 2), | ||
sdk.NewDecWithPrec(69, 2), | ||
uint64(60*60*8766/5), | ||
) | ||
|
||
s.keeper.InitGenesis(s.sdkCtx, s.accountKeeper, genesisState) | ||
|
||
minter := s.keeper.GetMinter(s.sdkCtx) | ||
s.Require().Equal(genesisState.Minter, minter) | ||
|
||
invalidCtx := testutil.DefaultContextWithDB(s.T(), s.key, sdk.NewTransientStoreKey("transient_test")) | ||
s.Require().Panics(func() { s.keeper.GetMinter(invalidCtx.Ctx) }, "stored minter should not have been nil") | ||
params := s.keeper.GetParams(s.sdkCtx) | ||
s.Require().Equal(genesisState.Params, params) | ||
|
||
genesisState2 := s.keeper.ExportGenesis(s.sdkCtx) | ||
s.Require().Equal(genesisState, genesisState2) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters