package v3_test

import (
	"testing"

	"github.com/stretchr/testify/require"

	storetypes "cosmossdk.io/store/types"

	"git.cw.tr/mukan-network/mukan-sdk/testutil"
	moduletestutil "git.cw.tr/mukan-network/mukan-sdk/types/module/testutil"
	paramtypes "git.cw.tr/mukan-network/mukan-sdk/x/params/types"
	v3 "git.cw.tr/mukan-network/mukan-sdk/x/staking/migrations/v3"
	"git.cw.tr/mukan-network/mukan-sdk/x/staking/types"
)

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

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

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

	// Make sure the new params are set.
	require.True(t, paramstore.Has(ctx, types.KeyMinCommissionRate))
}
