Skip to content

Commit

Permalink
test(mint): enhance tests for the token model v2
Browse files Browse the repository at this point in the history
  • Loading branch information
ccamel committed Dec 4, 2023
1 parent a18e700 commit bfdf5d1
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 90 deletions.
6 changes: 2 additions & 4 deletions x/mint/client/cli/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,15 @@ func TestGetCmdQueryParams(t *testing.T) {
"json output",
[]string{fmt.Sprintf("--%s=1", flags.FlagHeight), fmt.Sprintf("--%s=json", flags.FlagOutput)},
`[--height=1 --output=json]`,
`{"mint_denom":"","inflation_coef":"0","bonding_adjustment":"0","target_bonding_ratio":"0","blocks_per_year":"0"}`,
`{"mint_denom":"","inflation_coef":"0","blocks_per_year":"0"}`,
},
{
"text output",
[]string{fmt.Sprintf("--%s=1", flags.FlagHeight), fmt.Sprintf("--%s=text", flags.FlagOutput)},
`[--height=1 --output=text]`,
`blocks_per_year: "0"
bonding_adjustment: "0"
inflation_coef: "0"
mint_denom: ""
target_bonding_ratio: "0"`,
mint_denom: ""`,
},
}

Expand Down
2 changes: 0 additions & 2 deletions x/mint/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ func (s *GenesisTestSuite) TestImportExportGenesis() {
genesisState.Params = types.NewParams(
"testDenom",
sdk.NewDecWithPrec(69, 2),
sdk.NewDecWithPrec(14, 2),
sdk.NewDecWithPrec(56, 2),
uint64(60*60*8766/5),
)

Expand Down
38 changes: 6 additions & 32 deletions x/mint/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,44 +77,18 @@ func (s *IntegrationTestSuite) TestParams() {
{
name: "set invalid params",
input: types.Params{
MintDenom: sdk.DefaultBondDenom,
BondingAdjustment: sdk.NewDecWithPrec(-13, 2),
TargetBondingRatio: sdk.NewDecWithPrec(25, 2),
InflationCoef: sdk.NewDecWithPrec(73, 2),
BlocksPerYear: uint64(60 * 60 * 8766 / 5),
},
expectErr: true,
},
{
name: "set invalid params",
input: types.Params{
MintDenom: sdk.DefaultBondDenom,
BondingAdjustment: sdk.NewDecWithPrec(13, 2),
TargetBondingRatio: sdk.NewDecWithPrec(-25, 2),
InflationCoef: sdk.NewDecWithPrec(73, 2),
BlocksPerYear: uint64(60 * 60 * 8766 / 5),
},
expectErr: true,
},
{
name: "set invalid params",
input: types.Params{
MintDenom: sdk.DefaultBondDenom,
BondingAdjustment: sdk.NewDecWithPrec(13, 2),
TargetBondingRatio: sdk.NewDecWithPrec(25, 2),
InflationCoef: sdk.NewDecWithPrec(-73, 2),
BlocksPerYear: uint64(60 * 60 * 8766 / 5),
MintDenom: sdk.DefaultBondDenom,
InflationCoef: sdk.NewDecWithPrec(-73, 2),
BlocksPerYear: uint64(60 * 60 * 8766 / 5),
},
expectErr: true,
},
{
name: "set full valid params",
input: types.Params{
MintDenom: sdk.DefaultBondDenom,
BondingAdjustment: sdk.NewDecWithPrec(13, 2),
TargetBondingRatio: sdk.NewDecWithPrec(25, 2),
InflationCoef: sdk.NewDecWithPrec(73, 2),
BlocksPerYear: uint64(60 * 60 * 8766 / 5),
MintDenom: sdk.DefaultBondDenom,
InflationCoef: sdk.NewDecWithPrec(73, 2),
BlocksPerYear: uint64(60 * 60 * 8766 / 5),
},
expectErr: false,
},
Expand Down
44 changes: 6 additions & 38 deletions x/mint/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,44 +19,14 @@ func (s *IntegrationTestSuite) TestUpdateParams() {
},
expectErr: true,
},
{
name: "set invalid params for bonding adjustment (negative value)",
request: &types.MsgUpdateParams{
Authority: s.mintKeeper.GetAuthority(),
Params: types.Params{
MintDenom: sdk.DefaultBondDenom,
BondingAdjustment: sdk.NewDecWithPrec(-13, 2),
TargetBondingRatio: sdk.NewDecWithPrec(25, 2),
InflationCoef: sdk.NewDecWithPrec(73, 2),
BlocksPerYear: uint64(60 * 60 * 8766 / 5),
},
},
expectErr: true,
},
{
name: "set invalid params for target bonding ratio (negative value)",
request: &types.MsgUpdateParams{
Authority: s.mintKeeper.GetAuthority(),
Params: types.Params{
MintDenom: sdk.DefaultBondDenom,
BondingAdjustment: sdk.NewDecWithPrec(13, 2),
TargetBondingRatio: sdk.NewDecWithPrec(-25, 2),
InflationCoef: sdk.NewDecWithPrec(73, 2),
BlocksPerYear: uint64(60 * 60 * 8766 / 5),
},
},
expectErr: true,
},
{
name: "set invalid params for inflation coef (negative value)",
request: &types.MsgUpdateParams{
Authority: s.mintKeeper.GetAuthority(),
Params: types.Params{
MintDenom: sdk.DefaultBondDenom,
BondingAdjustment: sdk.NewDecWithPrec(13, 2),
TargetBondingRatio: sdk.NewDecWithPrec(25, 2),
InflationCoef: sdk.NewDecWithPrec(-73, 2),
BlocksPerYear: uint64(60 * 60 * 8766 / 5),
MintDenom: sdk.DefaultBondDenom,
InflationCoef: sdk.NewDecWithPrec(-73, 2),
BlocksPerYear: uint64(60 * 60 * 8766 / 5),
},
},
expectErr: true,
Expand All @@ -66,11 +36,9 @@ func (s *IntegrationTestSuite) TestUpdateParams() {
request: &types.MsgUpdateParams{
Authority: s.mintKeeper.GetAuthority(),
Params: types.Params{
MintDenom: sdk.DefaultBondDenom,
BondingAdjustment: sdk.NewDecWithPrec(13, 2),
TargetBondingRatio: sdk.NewDecWithPrec(25, 2),
InflationCoef: sdk.NewDecWithPrec(73, 2),
BlocksPerYear: uint64(60 * 60 * 8766 / 5),
MintDenom: sdk.DefaultBondDenom,
InflationCoef: sdk.NewDecWithPrec(73, 2),
BlocksPerYear: uint64(60 * 60 * 8766 / 5),
},
},
expectErr: false,
Expand Down
18 changes: 7 additions & 11 deletions x/mint/simulation/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,18 @@ func TestRandomizedGenState(t *testing.T) {
var mintGenesis types.GenesisState
simState.Cdc.MustUnmarshalJSON(simState.GenState[types.ModuleName], &mintGenesis)

dec1, _ := sdk.NewDecFromStr("0.073000000000000000")
dec2, _ := sdk.NewDecFromStr("2.500000000000000000")
dec3, _ := sdk.NewDecFromStr("0.660000000000000000")
inflationCoef := sdk.NewDecWithPrec(3, 2)
bondedRatio := sdk.NewDecWithPrec(2, 1)
minter, _ := types.NewMinterWithInflationCoef(inflationCoef, bondedRatio, simState.InitialStake)

require.Equal(t, uint64(6311520), mintGenesis.Params.BlocksPerYear)
require.Equal(t, dec1, mintGenesis.Params.InflationCoef)
require.Equal(t, dec2, mintGenesis.Params.BondingAdjustment)
require.Equal(t, dec3, mintGenesis.Params.TargetBondingRatio)
require.Equal(t, "0.073000000000000000", mintGenesis.Params.InflationCoef.String())
require.Equal(t, "stake", mintGenesis.Params.MintDenom)
require.Equal(t, "0stake",
mintGenesis.Minter.BlockProvision(mintGenesis.Params).String())
require.Equal(t, "170.000000000000000000",
mintGenesis.Minter.NextAnnualProvisions(mintGenesis.Params, simState.InitialStake).String())
require.Equal(t, "0.109500000000000000", mintGenesis.Minter.NextInflation(mintGenesis.Params, sdk.NewDecWithPrec(66, 2)).String())
require.Equal(t, "0stake", mintGenesis.Minter.BlockProvision(mintGenesis.Params).String())
require.Equal(t, "0.170000000000000000", mintGenesis.Minter.Inflation.String())
require.Equal(t, "170.000000000000000000", mintGenesis.Minter.AnnualProvisions.String())
require.Equal(t, "0.150000000000000000", minter.Inflation.String())
require.Equal(t, "150.000000000000000000", minter.AnnualProvisions.String())
}

// TestRandomizedGenState tests abnormal scenarios of applying RandomizedGenState.
Expand Down
4 changes: 1 addition & 3 deletions x/mint/simulation/proposals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ func TestProposalMsgs(t *testing.T) {

assert.Equal(t, sdk.AccAddress(address.Module("gov")).String(), msgUpdateParams.Authority)
assert.Equal(t, uint64(122877), msgUpdateParams.Params.BlocksPerYear)
assert.DeepEqual(t, sdk.NewDecWithPrec(7, 2), msgUpdateParams.Params.TargetBondingRatio)
assert.DeepEqual(t, sdk.NewDecWithPrec(95, 2), msgUpdateParams.Params.InflationCoef)
assert.DeepEqual(t, sdk.NewDecWithPrec(6, 1), msgUpdateParams.Params.BondingAdjustment)
assert.Equal(t, "xKGLwQvuyN", msgUpdateParams.Params.MintDenom)
assert.Equal(t, "eAerqyNEUz", msgUpdateParams.Params.MintDenom)
}

0 comments on commit bfdf5d1

Please sign in to comment.