Skip to content

Commit

Permalink
Add mincommision param tests
Browse files Browse the repository at this point in the history
  • Loading branch information
giansalex committed Oct 26, 2021
1 parent 48b6f9d commit 5e5b996
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
32 changes: 32 additions & 0 deletions x/staking/migrations/v045/store_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package v045_test

import (
"testing"

"github.com/stretchr/testify/require"

"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
v045staking "github.com/cosmos/cosmos-sdk/x/staking/migrations/v045"
"github.com/cosmos/cosmos-sdk/x/staking/types"
)

func TestStoreMigration(t *testing.T) {
encCfg := simapp.MakeTestEncodingConfig()
stakingKey := sdk.NewKVStoreKey("staking")
tStakingKey := sdk.NewTransientStoreKey("transient_test")
ctx := testutil.DefaultContext(stakingKey, tStakingKey)
paramstore := paramtypes.NewSubspace(encCfg.Codec, encCfg.Amino, stakingKey, tStakingKey, "staking")

// Check no params
require.False(t, paramstore.Has(ctx, types.KeyMinCommissionRate))

// Run migrations.
err := v045staking.MigrateStore(ctx, stakingKey, encCfg.Codec, paramstore)
require.NoError(t, err)

// Make sure the new params are set.
require.True(t, paramstore.Has(ctx, types.KeyMinCommissionRate))
}
15 changes: 15 additions & 0 deletions x/staking/types/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/stretchr/testify/require"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/staking/types"
)

Expand All @@ -21,3 +22,17 @@ func TestParamsEqual(t *testing.T) {
ok = p1.Equal(p2)
require.False(t, ok)
}

func Test_validateParams(t *testing.T) {
params := types.DefaultParams()

// default params have no error
require.NoError(t, params.Validate())

// validate mincommision
params.MinCommissionRate = sdk.NewDec(-1)
require.Error(t, params.Validate())

params.MinCommissionRate = sdk.NewDec(2)
require.Error(t, params.Validate())
}

0 comments on commit 5e5b996

Please sign in to comment.