github.com/cosmos/cosmos-sdk@v0.50.10/x/mint/migrations/v2/migrator_test.go (about)

     1  package v2_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/require"
     7  
     8  	storetypes "cosmossdk.io/store/types"
     9  
    10  	"github.com/cosmos/cosmos-sdk/runtime"
    11  	"github.com/cosmos/cosmos-sdk/testutil"
    12  	sdk "github.com/cosmos/cosmos-sdk/types"
    13  	moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
    14  	"github.com/cosmos/cosmos-sdk/x/mint"
    15  	"github.com/cosmos/cosmos-sdk/x/mint/exported"
    16  	v2 "github.com/cosmos/cosmos-sdk/x/mint/migrations/v2"
    17  	"github.com/cosmos/cosmos-sdk/x/mint/types"
    18  )
    19  
    20  type mockSubspace struct {
    21  	ps types.Params
    22  }
    23  
    24  func newMockSubspace(ps types.Params) mockSubspace {
    25  	return mockSubspace{ps: ps}
    26  }
    27  
    28  func (ms mockSubspace) GetParamSet(ctx sdk.Context, ps exported.ParamSet) {
    29  	*ps.(*types.Params) = ms.ps
    30  }
    31  
    32  func TestMigrate(t *testing.T) {
    33  	encCfg := moduletestutil.MakeTestEncodingConfig(mint.AppModuleBasic{})
    34  	cdc := encCfg.Codec
    35  
    36  	storeKey := storetypes.NewKVStoreKey(v2.ModuleName)
    37  	tKey := storetypes.NewTransientStoreKey("transient_test")
    38  	ctx := testutil.DefaultContext(storeKey, tKey)
    39  	kvStoreService := runtime.NewKVStoreService(storeKey)
    40  	store := kvStoreService.OpenKVStore(ctx)
    41  
    42  	legacySubspace := newMockSubspace(types.DefaultParams())
    43  	require.NoError(t, v2.Migrate(ctx, store, legacySubspace, cdc))
    44  
    45  	var res types.Params
    46  	bz, err := store.Get(v2.ParamsKey)
    47  	require.NoError(t, err)
    48  	require.NoError(t, cdc.Unmarshal(bz, &res))
    49  	require.Equal(t, legacySubspace.ps, res)
    50  }