mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-26 00:05:18 +00:00
feat: pricefeed migrations (#846)
This commit is contained in:
parent
4753504a68
commit
3bf40b97f9
@ -20,6 +20,8 @@ import (
|
||||
v0_13incentive "github.com/kava-labs/kava/x/incentive"
|
||||
v0_11incentive "github.com/kava-labs/kava/x/incentive/legacy/v0_11"
|
||||
"github.com/kava-labs/kava/x/kavadist"
|
||||
v0_11pricefeed "github.com/kava-labs/kava/x/pricefeed"
|
||||
v0_13pricefeed "github.com/kava-labs/kava/x/pricefeed"
|
||||
validatorvesting "github.com/kava-labs/kava/x/validator-vesting"
|
||||
)
|
||||
|
||||
@ -441,7 +443,7 @@ func Bep3(genesisState bep3.GenesisState) bep3.GenesisState {
|
||||
return bep3.NewGenesisState(newParams, newSwaps, newSupplies, genesisState.PreviousBlockTime)
|
||||
}
|
||||
|
||||
// Committee migrates from a v0.11 (or v0.12) committee genesis state to a v0.13 committee genesis stat
|
||||
// Committee migrates from a v0.11 (or v0.12) committee genesis state to a v0.13 committee genesis state
|
||||
func Committee(genesisState v0_11committee.GenesisState) v0_13committee.GenesisState {
|
||||
committees := []v0_13committee.Committee{}
|
||||
votes := []v0_13committee.Vote{}
|
||||
@ -556,6 +558,28 @@ func Committee(genesisState v0_11committee.GenesisState) v0_13committee.GenesisS
|
||||
genesisState.NextProposalID, committees, proposals, votes)
|
||||
}
|
||||
|
||||
// Pricefeed migrates from a v0.11 (or v0.12) pricefeed genesis state to a v0.13 pricefeed genesis state
|
||||
func Pricefeed(genesisState v0_11pricefeed.GenesisState) v0_13pricefeed.GenesisState {
|
||||
newMarkets := v0_13pricefeed.Markets{}
|
||||
oracles := genesisState.Params.Markets[0].Oracles
|
||||
|
||||
for _, m := range genesisState.Params.Markets {
|
||||
newMarkets = append(newMarkets, m)
|
||||
}
|
||||
usdx := v0_11pricefeed.NewMarket("usdx:usd", "usdx", "usd", oracles, true)
|
||||
newMarkets = append(newMarkets, usdx)
|
||||
|
||||
newPrices := v0_13pricefeed.PostedPrices{}
|
||||
|
||||
for _, p := range genesisState.PostedPrices {
|
||||
if p.Expiry.After(GenesisTime) {
|
||||
newPrices = append(newPrices, p)
|
||||
}
|
||||
}
|
||||
|
||||
return v0_13pricefeed.NewGenesisState(v0_13pricefeed.NewParams(newMarkets), newPrices)
|
||||
}
|
||||
|
||||
func removeIndex(accs authexported.GenesisAccounts, index int) authexported.GenesisAccounts {
|
||||
ret := make(authexported.GenesisAccounts, 0)
|
||||
ret = append(ret, accs[:index]...)
|
||||
|
@ -23,6 +23,7 @@ import (
|
||||
v0_11hard "github.com/kava-labs/kava/x/hard/legacy/v0_11"
|
||||
v0_13incentive "github.com/kava-labs/kava/x/incentive"
|
||||
v0_11incentive "github.com/kava-labs/kava/x/incentive/legacy/v0_11"
|
||||
v0_11pricefeed "github.com/kava-labs/kava/x/pricefeed"
|
||||
validatorvesting "github.com/kava-labs/kava/x/validator-vesting"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
@ -178,6 +179,19 @@ func TestCommittee(t *testing.T) {
|
||||
require.Equal(t, len(oldSPCP.AllowedMarkets), len(newSPCP.AllowedMarkets))
|
||||
}
|
||||
|
||||
func TestPricefeed(t *testing.T) {
|
||||
cdc := app.MakeCodec()
|
||||
bz, err := ioutil.ReadFile(filepath.Join("testdata", "kava-4-pricefeed-state.json"))
|
||||
require.NoError(t, err)
|
||||
var oldPricefeedGenState v0_11pricefeed.GenesisState
|
||||
require.NotPanics(t, func() {
|
||||
cdc.MustUnmarshalJSON(bz, &oldPricefeedGenState)
|
||||
})
|
||||
newGenState := Pricefeed(oldPricefeedGenState)
|
||||
err = newGenState.Validate()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, len(oldPricefeedGenState.Params.Markets)+1, len(newGenState.Params.Markets))
|
||||
}
|
||||
func TestBep3(t *testing.T) {
|
||||
bz, err := ioutil.ReadFile(filepath.Join("testdata", "kava-4-bep3-state.json"))
|
||||
require.NoError(t, err)
|
||||
|
1
migrate/v0_13/testdata/kava-4-pricefeed-state.json
vendored
Normal file
1
migrate/v0_13/testdata/kava-4-pricefeed-state.json
vendored
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user