mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-14 12:05:18 +00:00
4eef80b47f
* remove references to savings rate * removing savings rate module account in auth migration * use compact json * fix non-determinism is cdp migration
60 lines
1.5 KiB
Go
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)
|
|
|
|
}
|