-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
119 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package v8 | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/zeta-chain/zetacore/pkg/chains" | ||
"github.com/zeta-chain/zetacore/x/observer/types" | ||
) | ||
|
||
type observerKeeper interface { | ||
GetParamsIfExists(ctx sdk.Context) (params types.Params) | ||
SetParams(ctx sdk.Context, params types.Params) | ||
} | ||
|
||
// MigrateStore performs in-place store migrations from v6 to v7 | ||
func MigrateStore(ctx sdk.Context, observerKeeper observerKeeper) error { | ||
ctx.Logger().Info("Migrating observer store from v6 to v7") | ||
params := observerKeeper.GetParamsIfExists(ctx) | ||
for _, ob := range params.ObserverParams { | ||
chain := chains.GetChainFromChainID(ob.Chain.ChainId) | ||
ob.Chain = chain | ||
} | ||
observerKeeper.SetParams(ctx, params) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package v8_test | ||
|
||
import ( | ||
"testing" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/stretchr/testify/require" | ||
"github.com/zeta-chain/zetacore/pkg/chains" | ||
keepertest "github.com/zeta-chain/zetacore/testutil/keeper" | ||
v8 "github.com/zeta-chain/zetacore/x/observer/migrations/v8" | ||
"github.com/zeta-chain/zetacore/x/observer/types" | ||
) | ||
|
||
func Test_MigrateStore(t *testing.T) { | ||
tt := []struct { | ||
name string | ||
params types.Params | ||
chainList []*chains.Chain | ||
}{ | ||
{ | ||
name: "privnet params", | ||
params: LegacyParamsForNetwork(chains.NetworkType_PRIVNET), | ||
chainList: chains.ChainListByNetworkType(chains.NetworkType_PRIVNET), | ||
}, | ||
{ | ||
name: "testnet params", | ||
params: LegacyParamsForNetwork(chains.NetworkType_TESTNET), | ||
chainList: chains.ChainListByNetworkType(chains.NetworkType_TESTNET), | ||
}, | ||
{ | ||
name: "mainnet params", | ||
params: LegacyParamsForNetwork(chains.NetworkType_MAINNET), | ||
chainList: chains.ChainListByNetworkType(chains.NetworkType_MAINNET), | ||
}, | ||
} | ||
for _, tc := range tt { | ||
t.Run(tc.name, func(t *testing.T) { | ||
k, ctx, _, _ := keepertest.ObserverKeeper(t) | ||
k.SetParams(ctx, tc.params) | ||
|
||
chainListOld := make([]chains.Chain, len(tc.params.ObserverParams)) | ||
for i, ob := range tc.params.ObserverParams { | ||
chainListOld[i] = *ob.Chain | ||
} | ||
|
||
err := v8.MigrateStore(ctx, k) | ||
require.NoError(t, err) | ||
|
||
params := k.GetParamsIfExists(ctx) | ||
chainListNew := make([]chains.Chain, len(params.ObserverParams)) | ||
for i, ob := range params.ObserverParams { | ||
chainListNew[i] = *ob.Chain | ||
} | ||
chainListTest := make([]chains.Chain, len(tc.chainList)) | ||
for i, chain := range tc.chainList { | ||
chainListTest[i] = *chain | ||
} | ||
require.NotEqual(t, chainListTest, chainListOld) | ||
require.Equal(t, chainListTest, chainListNew) | ||
}) | ||
|
||
} | ||
|
||
} | ||
|
||
func LegacyParamsForNetwork(networkType chains.NetworkType) types.Params { | ||
chainList := chains.ChainListByNetworkType(networkType) | ||
observerParams := make([]*types.ObserverParams, len(chainList)) | ||
for i, chain := range chainList { | ||
observerParams[i] = &types.ObserverParams{ | ||
IsSupported: true, | ||
// Set chain-Id and chain-name only for legacy params | ||
Chain: &chains.Chain{ChainId: chain.ChainId, ChainName: chain.ChainName}, | ||
BallotThreshold: sdk.MustNewDecFromStr("0.66"), | ||
MinObserverDelegation: sdk.MustNewDecFromStr("1000000000000000000000"), | ||
} | ||
} | ||
return types.NewParams(observerParams, types.DefaultAdminPolicy(), 100) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters