mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-27 00:35:18 +00:00
Add supply migration for kava-8 (#1008)
* fix: update supply migration to add swp token supply * add full migration test with app initialization * fix: use correct chain-id in test app initialization * address review comments
This commit is contained in:
parent
a9c77f0282
commit
dd03ba5671
@ -31,6 +31,7 @@ var (
|
|||||||
GenesisTime = time.Date(2021, 8, 30, 15, 0, 0, 0, time.UTC)
|
GenesisTime = time.Date(2021, 8, 30, 15, 0, 0, 0, time.UTC)
|
||||||
ChainID = "kava-8"
|
ChainID = "kava-8"
|
||||||
SwpDelegatorRewardsPerSecond = sdk.NewCoin("swp", sdk.NewInt(198186))
|
SwpDelegatorRewardsPerSecond = sdk.NewCoin("swp", sdk.NewInt(198186))
|
||||||
|
SwpTotalSupply = sdk.NewCoin("swp", sdk.NewInt(250000000e6))
|
||||||
)
|
)
|
||||||
|
|
||||||
// Migrate translates a genesis file from kava v0.14 format to kava v0.15 format
|
// Migrate translates a genesis file from kava v0.14 format to kava v0.15 format
|
||||||
@ -74,6 +75,14 @@ func MigrateAppState(v0_14AppState genutil.AppMap) {
|
|||||||
v0_14AppState[auth.ModuleName] = v0_15Codec.MustMarshalJSON(Auth(v0_15Codec, authGenState, GenesisTime))
|
v0_14AppState[auth.ModuleName] = v0_15Codec.MustMarshalJSON(Auth(v0_15Codec, authGenState, GenesisTime))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Migrate supply app state
|
||||||
|
if v0_14AppState[supply.ModuleName] != nil {
|
||||||
|
var supplyGenState supply.GenesisState
|
||||||
|
v0_14Codec.MustUnmarshalJSON(v0_14AppState[supply.ModuleName], &supplyGenState)
|
||||||
|
delete(v0_14AppState, supply.ModuleName)
|
||||||
|
v0_14AppState[supply.ModuleName] = v0_15Codec.MustMarshalJSON(Supply(supplyGenState, SwpTotalSupply))
|
||||||
|
}
|
||||||
|
|
||||||
// Migrate incentive app state
|
// Migrate incentive app state
|
||||||
if v0_14AppState[v0_14incentive.ModuleName] != nil {
|
if v0_14AppState[v0_14incentive.ModuleName] != nil {
|
||||||
var incentiveGenState v0_14incentive.GenesisState
|
var incentiveGenState v0_14incentive.GenesisState
|
||||||
@ -258,6 +267,12 @@ func DistributeSwpTokens(genesisState auth.GenesisState) auth.GenesisState {
|
|||||||
return auth.NewGenesisState(genesisState.Params, accounts)
|
return auth.NewGenesisState(genesisState.Params, accounts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Supply adds SWP token to total supply
|
||||||
|
func Supply(supplyGenesisState supply.GenesisState, swpBalance sdk.Coin) supply.GenesisState {
|
||||||
|
supplyGenesisState.Supply = supplyGenesisState.Supply.Add(swpBalance)
|
||||||
|
return supplyGenesisState
|
||||||
|
}
|
||||||
|
|
||||||
// Committee migrates from a v0.14 committee genesis state to a v0.15 committee genesis state
|
// Committee migrates from a v0.14 committee genesis state to a v0.15 committee genesis state
|
||||||
func Committee(genesisState v0_14committee.GenesisState) v0_15committee.GenesisState {
|
func Committee(genesisState v0_14committee.GenesisState) v0_15committee.GenesisState {
|
||||||
|
|
||||||
|
@ -36,6 +36,29 @@ func TestMain(m *testing.M) {
|
|||||||
os.Exit(m.Run())
|
os.Exit(m.Run())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMigrateFull(t *testing.T) {
|
||||||
|
t.Skip() // skip to avoid having to commit a large genesis file to the repo
|
||||||
|
oldGenDoc, err := tmtypes.GenesisDocFromFile(filepath.Join("testdata", "genesis.json"))
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// 2) migrate
|
||||||
|
newGenDoc := Migrate(*oldGenDoc)
|
||||||
|
tApp := app.NewTestApp()
|
||||||
|
cdc := app.MakeCodec()
|
||||||
|
var newAppState genutil.AppMap
|
||||||
|
require.NoError(t,
|
||||||
|
cdc.UnmarshalJSON(newGenDoc.AppState, &newAppState),
|
||||||
|
)
|
||||||
|
err = app.ModuleBasics.ValidateGenesis(newAppState)
|
||||||
|
if err != nil {
|
||||||
|
require.NoError(t, err)
|
||||||
|
}
|
||||||
|
require.NotPanics(t, func() {
|
||||||
|
// this runs both InitGenesis for all modules (which panic on errors) and runs all invariants
|
||||||
|
tApp.InitializeFromGenesisStatesWithTimeAndChainID(newGenDoc.GenesisTime, newGenDoc.ChainID, app.GenesisState(newAppState))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestCommittee(t *testing.T) {
|
func TestCommittee(t *testing.T) {
|
||||||
bz, err := ioutil.ReadFile(filepath.Join("testdata", "kava-7-committee-state.json"))
|
bz, err := ioutil.ReadFile(filepath.Join("testdata", "kava-7-committee-state.json"))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
Loading…
Reference in New Issue
Block a user