github.com/cosmos/cosmos-sdk@v0.50.10/x/gov/migrations/v5/store_test.go (about)

     1  package v5_test
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  
     7  	"github.com/stretchr/testify/require"
     8  
     9  	"cosmossdk.io/collections"
    10  	storetypes "cosmossdk.io/store/types"
    11  
    12  	"github.com/cosmos/cosmos-sdk/runtime"
    13  	"github.com/cosmos/cosmos-sdk/testutil"
    14  	moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
    15  	"github.com/cosmos/cosmos-sdk/x/bank"
    16  	"github.com/cosmos/cosmos-sdk/x/gov"
    17  	v4 "github.com/cosmos/cosmos-sdk/x/gov/migrations/v4"
    18  	v5 "github.com/cosmos/cosmos-sdk/x/gov/migrations/v5"
    19  	v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
    20  )
    21  
    22  func TestMigrateStore(t *testing.T) {
    23  	cdc := moduletestutil.MakeTestEncodingConfig(gov.AppModuleBasic{}, bank.AppModuleBasic{}).Codec
    24  	govKey := storetypes.NewKVStoreKey("gov")
    25  	ctx := testutil.DefaultContext(govKey, storetypes.NewTransientStoreKey("transient_test"))
    26  	store := ctx.KVStore(govKey)
    27  	storeService := runtime.NewKVStoreService(govKey)
    28  	sb := collections.NewSchemaBuilder(storeService)
    29  	constitutionCollection := collections.NewItem(sb, v5.ConstitutionKey, "constitution", collections.StringValue)
    30  
    31  	var params v1.Params
    32  	bz := store.Get(v4.ParamsKey)
    33  	require.NoError(t, cdc.Unmarshal(bz, &params))
    34  	require.NotNil(t, params)
    35  	require.Equal(t, "", params.ExpeditedThreshold)
    36  	require.Equal(t, (*time.Duration)(nil), params.ExpeditedVotingPeriod)
    37  
    38  	// Run migrations.
    39  	err := v5.MigrateStore(ctx, storeService, cdc, constitutionCollection)
    40  	require.NoError(t, err)
    41  
    42  	// Check params
    43  	bz = store.Get(v4.ParamsKey)
    44  	require.NoError(t, cdc.Unmarshal(bz, &params))
    45  	require.NotNil(t, params)
    46  	require.Equal(t, v1.DefaultParams().ExpeditedMinDeposit, params.ExpeditedMinDeposit)
    47  	require.Equal(t, v1.DefaultParams().ExpeditedThreshold, params.ExpeditedThreshold)
    48  	require.Equal(t, v1.DefaultParams().ExpeditedVotingPeriod, params.ExpeditedVotingPeriod)
    49  	require.Equal(t, v1.DefaultParams().MinDepositRatio, params.MinDepositRatio)
    50  
    51  	// Check constitution
    52  	result, err := constitutionCollection.Get(ctx)
    53  	require.NoError(t, err)
    54  	require.Equal(t, "This chain has no constitution.", result)
    55  }