2023-05-19 23:01:46 +00:00
|
|
|
package v2_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"github.com/cosmos/cosmos-sdk/testutil"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2024-02-06 22:54:10 +00:00
|
|
|
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
|
2023-05-19 23:01:46 +00:00
|
|
|
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
|
|
|
|
|
2024-04-24 07:10:22 +00:00
|
|
|
v2evmutil "github.com/0glabs/0g-chain/x/evmutil/migrations/v2"
|
|
|
|
"github.com/0glabs/0g-chain/x/evmutil/types"
|
2023-05-19 23:01:46 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestStoreMigrationAddsKeyTableIncludingNewParam(t *testing.T) {
|
2024-02-06 22:54:10 +00:00
|
|
|
encCfg := moduletestutil.MakeTestEncodingConfig()
|
2023-05-19 23:01:46 +00:00
|
|
|
evmutilKey := sdk.NewKVStoreKey(types.ModuleName)
|
|
|
|
tEvmutilKey := sdk.NewTransientStoreKey("transient_test")
|
|
|
|
ctx := testutil.DefaultContext(evmutilKey, tEvmutilKey)
|
|
|
|
paramstore := paramtypes.NewSubspace(encCfg.Codec, encCfg.Amino, evmutilKey, tEvmutilKey, types.ModuleName)
|
|
|
|
|
|
|
|
// Check param doesn't exist before
|
2023-05-23 19:32:27 +00:00
|
|
|
require.False(t, paramstore.Has(ctx, types.KeyAllowedCosmosDenoms))
|
2023-05-19 23:01:46 +00:00
|
|
|
|
|
|
|
// Run migrations.
|
|
|
|
err := v2evmutil.MigrateStore(ctx, paramstore)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// Make sure the new params are set.
|
2023-05-23 19:32:27 +00:00
|
|
|
require.True(t, paramstore.Has(ctx, types.KeyAllowedCosmosDenoms))
|
2023-05-19 23:01:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestStoreMigrationSetsNewParamOnExistingKeyTable(t *testing.T) {
|
2024-02-06 22:54:10 +00:00
|
|
|
encCfg := moduletestutil.MakeTestEncodingConfig()
|
2023-05-19 23:01:46 +00:00
|
|
|
evmutilKey := sdk.NewKVStoreKey(types.ModuleName)
|
|
|
|
tEvmutilKey := sdk.NewTransientStoreKey("transient_test")
|
|
|
|
ctx := testutil.DefaultContext(evmutilKey, tEvmutilKey)
|
|
|
|
paramstore := paramtypes.NewSubspace(encCfg.Codec, encCfg.Amino, evmutilKey, tEvmutilKey, types.ModuleName)
|
|
|
|
paramstore.WithKeyTable(types.ParamKeyTable())
|
|
|
|
|
|
|
|
// expect it to have key table
|
|
|
|
require.True(t, paramstore.HasKeyTable())
|
|
|
|
// expect it to not have new param
|
2023-05-23 19:32:27 +00:00
|
|
|
require.False(t, paramstore.Has(ctx, types.KeyAllowedCosmosDenoms))
|
2023-05-19 23:01:46 +00:00
|
|
|
|
|
|
|
// Run migrations.
|
|
|
|
err := v2evmutil.MigrateStore(ctx, paramstore)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// Make sure the new params are set.
|
2023-05-23 19:32:27 +00:00
|
|
|
require.True(t, paramstore.Has(ctx, types.KeyAllowedCosmosDenoms))
|
2023-05-19 23:01:46 +00:00
|
|
|
}
|