github.com/cosmos/cosmos-sdk@v0.50.10/x/crisis/migrations/v2/migrate_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/crisis"
    15  	v2 "github.com/cosmos/cosmos-sdk/x/crisis/migrations/v2"
    16  	"github.com/cosmos/cosmos-sdk/x/crisis/types"
    17  )
    18  
    19  type mockSubspace struct {
    20  	constantFee sdk.Coin
    21  }
    22  
    23  func newMockSubspace(fee sdk.Coin) mockSubspace {
    24  	return mockSubspace{constantFee: fee}
    25  }
    26  
    27  func (ms mockSubspace) Get(ctx sdk.Context, key []byte, ptr interface{}) {
    28  	*ptr.(*sdk.Coin) = ms.constantFee
    29  }
    30  
    31  func TestMigrate(t *testing.T) {
    32  	cdc := moduletestutil.MakeTestEncodingConfig(crisis.AppModuleBasic{}).Codec
    33  	storeKey := storetypes.NewKVStoreKey(v2.ModuleName)
    34  	storeService := runtime.NewKVStoreService(storeKey)
    35  	tKey := storetypes.NewTransientStoreKey("transient_test")
    36  	ctx := testutil.DefaultContext(storeKey, tKey)
    37  	store := ctx.KVStore(storeKey)
    38  
    39  	legacySubspace := newMockSubspace(types.DefaultGenesisState().ConstantFee)
    40  	require.NoError(t, v2.MigrateStore(ctx, storeService, legacySubspace, cdc))
    41  
    42  	var res sdk.Coin
    43  	bz := store.Get(v2.ConstantFeeKey)
    44  	require.NoError(t, cdc.Unmarshal(bz, &res))
    45  	require.NotNil(t, res)
    46  	require.Equal(t, legacySubspace.constantFee, res)
    47  }