0g-chain/contrib/kava-3/params_test.go
Ruaridh 4a8b5696cb
v0.8 Migration Scripts (#518)
* initial sketch

* add module migrations

* add migrations for all accout types

* test account migration

* add tendermint migration and migrate cmd

* remove need for errors pkg dependency

* add bech32 decoding fork

* add suggested params and cmd to write them

* add basic upgrade instructions

* fix tests

* address some migration todos

* tidy contrib folder

* finalize params values

* align cdp init genesis with other modules

* add tendermint and distribution test
add custom distribution migration to patch bug

* add staking migration test

* add slashing, evidence tests, refactor auth tests

* add full migration test

* remove go-amino dependency from go.mod
also tidy up unused indirect dependencies

* address remaining TODOs

* remove commented out code from legacy types

* add spot/liquidation markets ids to kava-3 params

* Apply suggestions from code review

Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>

* address code review suggestions

* add validate genesis to migrate test

* refactor add params func

* remove commented out code from old types

* fix add params

* add deputy address

* add tests using exported kava-2 state

* incorporate new cdp params from master

* update params from review

Co-authored-by: Kevin Davis <karzak@users.noreply.github.com>

* add deputy account

* add committee permissions for new params

Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
Co-authored-by: Kevin Davis <karzak@users.noreply.github.com>
2020-06-03 15:35:00 -04:00

43 lines
1.3 KiB
Go

package kava3
import (
"path/filepath"
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/x/genutil"
"github.com/kava-labs/kava/app"
"github.com/kava-labs/kava/migrate/v0_8"
v032tendermint "github.com/kava-labs/kava/migrate/v0_8/tendermint/v0_32"
)
func TestAddSuggestedParams(t *testing.T) {
tApp := app.NewTestApp() // also sets the bech32 prefix on sdk.Config
cdc := app.MakeCodec()
// 1) load an exported kava-2 state and migrate to kava v0.8 format (avoids storing v0.8 state that can get out of date)
oldGenDoc, err := v032tendermint.GenesisDocFromFile(filepath.Join("../../migrate/v0_8/testdata", "kava-2.json"))
require.NoError(t, err)
genDoc := v0_8.Migrate(*oldGenDoc)
// 2) add params
newGenDoc, err := AddSuggestedParams(cdc, genDoc, "new-chain-id", time.Date(1998, 1, 0, 0, 0, 0, 0, time.UTC))
require.NoError(t, err)
// 3) check new genesis is valid
var newAppState genutil.AppMap
require.NoError(t,
cdc.UnmarshalJSON(newGenDoc.AppState, &newAppState),
)
require.NoError(t,
app.ModuleBasics.ValidateGenesis(newAppState),
)
require.NotPanics(t, func() {
// this runs both InitGenesis for all modules (which panic on errors) and runs all invariants
tApp.InitializeFromGenesisStates(app.GenesisState(newAppState))
})
}