0g-chain/migrate/v0_13/migrate_test.go
Kevin Davis 4eef80b47f
[R4R] CDP module migrations from v0.11 -> v0.13 (#769)
* remove references to savings rate

* removing savings rate module account in auth migration

* use compact json

* fix non-determinism is cdp migration
2021-01-21 10:37:35 -07:00

60 lines
1.5 KiB
Go

package v0_13
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/kava-labs/kava/app"
v0_11cdp "github.com/kava-labs/kava/x/cdp/legacy/v0_11"
"github.com/stretchr/testify/require"
)
func TestMain(m *testing.M) {
config := sdk.GetConfig()
app.SetBech32AddressPrefixes(config)
app.SetBip44CoinType(config)
os.Exit(m.Run())
}
func TestMigrateCdp(t *testing.T) {
bz, err := ioutil.ReadFile(filepath.Join("testdata", "kava-4-cdp-state-block-500000.json"))
require.NoError(t, err)
var oldGenState v0_11cdp.GenesisState
cdc := app.MakeCodec()
require.NotPanics(t, func() {
cdc.MustUnmarshalJSON(bz, &oldGenState)
})
newGenState := MigrateCDP(oldGenState)
err = newGenState.Validate()
require.NoError(t, err)
require.Equal(t, len(newGenState.Params.CollateralParams), len(newGenState.PreviousAccumulationTimes))
cdp1 := newGenState.CDPs[0]
require.Equal(t, sdk.OneDec(), cdp1.InterestFactor)
}
func TestMigrateAuth(t *testing.T) {
bz, err := ioutil.ReadFile(filepath.Join("testdata", "kava-4-auth-state-block-500000.json"))
require.NoError(t, err)
var oldGenState auth.GenesisState
cdc := app.MakeCodec()
require.NotPanics(t, func() {
cdc.MustUnmarshalJSON(bz, &oldGenState)
})
newGenState := MigrateAuth(oldGenState)
err = auth.ValidateGenesis(newGenState)
require.NoError(t, err)
require.Equal(t, len(oldGenState.Accounts), len(newGenState.Accounts)+1)
}