Skip to content

Commit

Permalink
add migration script
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis committed Mar 1, 2024
1 parent 571e17d commit 17fde47
Show file tree
Hide file tree
Showing 41 changed files with 283 additions and 76 deletions.
2 changes: 2 additions & 0 deletions contrib/localnet/scripts/start-zetacored.sh
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ then
zetacored add-genesis-account zeta1n0rn6sne54hv7w2uu93fl48ncyqz97d3kty6sh 100000000000000000000000000azeta # Funds the localnet_gov_admin account
cat $HOME/.zetacored/config/genesis.json | jq '.app_state["authority"]["policies"]["policy_addresses"][0]["address"]="zeta1srsq755t654agc0grpxj4y3w0znktrpr9tcdgk"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json
cat $HOME/.zetacored/config/genesis.json | jq '.app_state["authority"]["policies"]["policy_addresses"][1]["address"]="zeta1srsq755t654agc0grpxj4y3w0znktrpr9tcdgk"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json
cat $HOME/.zetacored/config/genesis.json | jq '.app_state["observer"]["params"]["admin_policy"][0]["address"]="zeta1srsq755t654agc0grpxj4y3w0znktrpr9tcdgk"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json
cat $HOME/.zetacored/config/genesis.json | jq '.app_state["observer"]["params"]["admin_policy"][1]["address"]="zeta1srsq755t654agc0grpxj4y3w0znktrpr9tcdgk"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json

# give balance to runner accounts to deploy contracts directly on zEVM
# deployer
Expand Down
2 changes: 1 addition & 1 deletion testutil/keeper/mocks/crosschain/account.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion testutil/keeper/mocks/crosschain/authority.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion testutil/keeper/mocks/crosschain/bank.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion testutil/keeper/mocks/crosschain/fungible.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion testutil/keeper/mocks/crosschain/observer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion testutil/keeper/mocks/crosschain/staking.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion testutil/keeper/mocks/emissions/account.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion testutil/keeper/mocks/emissions/bank.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion testutil/keeper/mocks/emissions/observer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion testutil/keeper/mocks/emissions/staking.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion testutil/keeper/mocks/fungible/account.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion testutil/keeper/mocks/fungible/authority.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion testutil/keeper/mocks/fungible/bank.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion testutil/keeper/mocks/fungible/evm.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion testutil/keeper/mocks/fungible/observer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion testutil/keeper/mocks/observer/authority.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion testutil/keeper/mocks/observer/slashing.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion testutil/keeper/mocks/observer/staking.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions testutil/keeper/observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func initObserverKeeper(
}

// ObserverKeeperWithMocks instantiates an observer keeper for testing purposes with the option to mock specific keepers
func ObserverKeeperWithMocks(t testing.TB, mockOptions ObserverMockOptions) (*keeper.Keeper, sdk.Context, SDKKeepers) {
func ObserverKeeperWithMocks(t testing.TB, mockOptions ObserverMockOptions) (*keeper.Keeper, sdk.Context, SDKKeepers, ZetaKeepers) {
storeKey := sdk.NewKVStoreKey(types.StoreKey)
memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey)

Expand Down Expand Up @@ -114,11 +114,13 @@ func ObserverKeeperWithMocks(t testing.TB, mockOptions ObserverMockOptions) (*ke

k.SetParams(ctx, types.DefaultParams())

return k, ctx, sdkKeepers
return k, ctx, sdkKeepers, ZetaKeepers{
AuthorityKeeper: &authorityKeeperTmp,
}
}

// ObserverKeeper instantiates an observer keeper for testing purposes
func ObserverKeeper(t testing.TB) (*keeper.Keeper, sdk.Context, SDKKeepers) {
func ObserverKeeper(t testing.TB) (*keeper.Keeper, sdk.Context, SDKKeepers, ZetaKeepers) {
return ObserverKeeperWithMocks(t, ObserverNoMocks)
}

Expand Down
2 changes: 1 addition & 1 deletion x/observer/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestGenesis(t *testing.T) {
}

// Init and export
k, ctx, _ := keepertest.ObserverKeeper(t)
k, ctx, _, _ := keepertest.ObserverKeeper(t)
observer.InitGenesis(ctx, *k, genesisState)
got := observer.ExportGenesis(ctx, *k)
require.NotNil(t, got)
Expand Down
6 changes: 3 additions & 3 deletions x/observer/keeper/chain_nonces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func TestKeeper_GetChainNonces(t *testing.T) {
t.Run("Get chain nonces", func(t *testing.T) {
k, ctx, _ := keepertest.ObserverKeeper(t)
k, ctx, _, _ := keepertest.ObserverKeeper(t)
chainNoncesList := sample.ChainNoncesList(t, 10)
for _, n := range chainNoncesList {
k.SetChainNonces(ctx, n)
Expand All @@ -22,7 +22,7 @@ func TestKeeper_GetChainNonces(t *testing.T) {
}
})
t.Run("Get chain nonces not found", func(t *testing.T) {
k, ctx, _ := keepertest.ObserverKeeper(t)
k, ctx, _, _ := keepertest.ObserverKeeper(t)
chainNoncesList := sample.ChainNoncesList(t, 10)
for _, n := range chainNoncesList {
k.SetChainNonces(ctx, n)
Expand All @@ -31,7 +31,7 @@ func TestKeeper_GetChainNonces(t *testing.T) {
require.False(t, found)
})
t.Run("Get all chain nonces", func(t *testing.T) {
k, ctx, _ := keepertest.ObserverKeeper(t)
k, ctx, _, _ := keepertest.ObserverKeeper(t)
chainNoncesList := sample.ChainNoncesList(t, 10)
for _, n := range chainNoncesList {
k.SetChainNonces(ctx, n)
Expand Down
8 changes: 4 additions & 4 deletions x/observer/keeper/chain_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

func TestKeeper_GetSupportedChainFromChainID(t *testing.T) {
t.Run("return nil if chain not found", func(t *testing.T) {
k, ctx, _ := keepertest.ObserverKeeper(t)
k, ctx, _, _ := keepertest.ObserverKeeper(t)

// no core params list
require.Nil(t, k.GetSupportedChainFromChainID(ctx, getValidEthChainIDWithIndex(t, 0)))
Expand All @@ -31,7 +31,7 @@ func TestKeeper_GetSupportedChainFromChainID(t *testing.T) {
})

t.Run("return chain if chain found", func(t *testing.T) {
k, ctx, _ := keepertest.ObserverKeeper(t)
k, ctx, _, _ := keepertest.ObserverKeeper(t)
chainID := getValidEthChainIDWithIndex(t, 0)
setSupportedChain(ctx, *k, getValidEthChainIDWithIndex(t, 1), chainID)
chain := k.GetSupportedChainFromChainID(ctx, chainID)
Expand All @@ -42,12 +42,12 @@ func TestKeeper_GetSupportedChainFromChainID(t *testing.T) {

func TestKeeper_GetSupportedChains(t *testing.T) {
t.Run("return empty list if no core params list", func(t *testing.T) {
k, ctx, _ := keepertest.ObserverKeeper(t)
k, ctx, _, _ := keepertest.ObserverKeeper(t)
require.Empty(t, k.GetSupportedChains(ctx))
})

t.Run("return list containing supported chains", func(t *testing.T) {
k, ctx, _ := keepertest.ObserverKeeper(t)
k, ctx, _, _ := keepertest.ObserverKeeper(t)

require.Greater(t, len(common.ExternalChainList()), 5)
supported1 := common.ExternalChainList()[0]
Expand Down
12 changes: 6 additions & 6 deletions x/observer/keeper/grpc_query_blame_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func TestKeeper_BlameByIdentifier(t *testing.T) {
k, ctx, _ := keepertest.ObserverKeeper(t)
k, ctx, _, _ := keepertest.ObserverKeeper(t)
var chainId int64 = 97
var nonce uint64 = 101
digest := "85f5e10431f69bc2a14046a13aabaefc660103b6de7a84f75c4b96181d03f0b5"
Expand All @@ -31,7 +31,7 @@ func TestKeeper_BlameByIdentifier(t *testing.T) {
}

func TestKeeper_BlameByChainAndNonce(t *testing.T) {
k, ctx, _ := keepertest.ObserverKeeper(t)
k, ctx, _, _ := keepertest.ObserverKeeper(t)
var chainId int64 = 97
var nonce uint64 = 101
digest := "85f5e10431f69bc2a14046a13aabaefc660103b6de7a84f75c4b96181d03f0b5"
Expand All @@ -52,7 +52,7 @@ func TestKeeper_BlameByChainAndNonce(t *testing.T) {

func TestKeeper_BlameAll(t *testing.T) {
t.Run("GetBlameRecord by limit ", func(t *testing.T) {
k, ctx, _ := keepertest.ObserverKeeper(t)
k, ctx, _, _ := keepertest.ObserverKeeper(t)
blameList := sample.BlameRecordsList(t, 10)
for _, record := range blameList {
k.SetBlame(ctx, record)
Expand All @@ -69,7 +69,7 @@ func TestKeeper_BlameAll(t *testing.T) {
require.Equal(t, len(blameList), int(pageRes.Total))
})
t.Run("GetBlameRecord by offset ", func(t *testing.T) {
k, ctx, _ := keepertest.ObserverKeeper(t)
k, ctx, _, _ := keepertest.ObserverKeeper(t)
blameList := sample.BlameRecordsList(t, 20)
offset := 10
for _, record := range blameList {
Expand All @@ -88,7 +88,7 @@ func TestKeeper_BlameAll(t *testing.T) {
require.Equal(t, len(blameList), int(pageRes.Total))
})
t.Run("GetAllBlameRecord", func(t *testing.T) {
k, ctx, _ := keepertest.ObserverKeeper(t)
k, ctx, _, _ := keepertest.ObserverKeeper(t)
blameList := sample.BlameRecordsList(t, 100)
for _, record := range blameList {
k.SetBlame(ctx, record)
Expand All @@ -103,7 +103,7 @@ func TestKeeper_BlameAll(t *testing.T) {
require.Equal(t, blameList, rst)
})
t.Run("Get no records if nothing is set", func(t *testing.T) {
k, ctx, _ := keepertest.ObserverKeeper(t)
k, ctx, _, _ := keepertest.ObserverKeeper(t)
rst := k.GetAllBlame(ctx)
require.Len(t, rst, 0)
})
Expand Down
4 changes: 2 additions & 2 deletions x/observer/keeper/grpc_query_nonces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

func TestChainNoncesQuerySingle(t *testing.T) {
k, ctx, _ := keepertest.ObserverKeeper(t)
k, ctx, _, _ := keepertest.ObserverKeeper(t)
wctx := sdk.WrapSDKContext(ctx)
chainNonces := sample.ChainNoncesList(t, 2)
for _, nonce := range chainNonces {
Expand Down Expand Up @@ -59,7 +59,7 @@ func TestChainNoncesQuerySingle(t *testing.T) {
}

func TestChainNoncesQueryPaginated(t *testing.T) {
k, ctx, _ := keepertest.ObserverKeeper(t)
k, ctx, _, _ := keepertest.ObserverKeeper(t)
wctx := sdk.WrapSDKContext(ctx)
chainNonces := sample.ChainNoncesList(t, 5)
for _, nonce := range chainNonces {
Expand Down
6 changes: 6 additions & 0 deletions x/observer/keeper/migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
v4 "github.com/zeta-chain/zetacore/x/observer/migrations/v4"
v5 "github.com/zeta-chain/zetacore/x/observer/migrations/v5"
v6 "github.com/zeta-chain/zetacore/x/observer/migrations/v6"
v7 "github.com/zeta-chain/zetacore/x/observer/migrations/v7"
)

// Migrator is a struct for handling in-place store migrations.
Expand Down Expand Up @@ -42,3 +43,8 @@ func (m Migrator) Migrate4to5(ctx sdk.Context) error {
func (m Migrator) Migrate5to6(ctx sdk.Context) error {
return v6.MigrateStore(ctx, m.observerKeeper)
}

// Migrate6to7 migrates the store from consensus version 6 to 7
func (m Migrator) Migrate6to7(ctx sdk.Context) error {
return v7.MigrateStore(ctx, m.observerKeeper)
}
2 changes: 1 addition & 1 deletion x/observer/keeper/msg_server_add_block_header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func TestMsgServer_AddBlockHeader(t *testing.T) {
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
k, ctx, _ := keepertest.ObserverKeeper(t)
k, ctx, _, _ := keepertest.ObserverKeeper(t)
srv := keeper.NewMsgServerImpl(*k)
k.SetObserverSet(ctx, types.ObserverSet{
ObserverList: []string{observerAddress.String()},
Expand Down
6 changes: 3 additions & 3 deletions x/observer/keeper/msg_server_remove_chain_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

func TestMsgServer_RemoveChainParams(t *testing.T) {
t.Run("can update chain params", func(t *testing.T) {
k, ctx, _ := keepertest.ObserverKeeperWithMocks(t, keepertest.ObserverMockOptions{
k, ctx, _, _ := keepertest.ObserverKeeperWithMocks(t, keepertest.ObserverMockOptions{
UseAuthorityMock: true,
})
srv := keeper.NewMsgServerImpl(*k)
Expand Down Expand Up @@ -82,7 +82,7 @@ func TestMsgServer_RemoveChainParams(t *testing.T) {
})

t.Run("cannot remove chain params if not authorized", func(t *testing.T) {
k, ctx, _ := keepertest.ObserverKeeperWithMocks(t, keepertest.ObserverMockOptions{
k, ctx, _, _ := keepertest.ObserverKeeperWithMocks(t, keepertest.ObserverMockOptions{
UseAuthorityMock: true,
})
srv := keeper.NewMsgServerImpl(*k)
Expand All @@ -99,7 +99,7 @@ func TestMsgServer_RemoveChainParams(t *testing.T) {
})

t.Run("cannot remove if chain ID not found", func(t *testing.T) {
k, ctx, _ := keepertest.ObserverKeeperWithMocks(t, keepertest.ObserverMockOptions{
k, ctx, _, _ := keepertest.ObserverKeeperWithMocks(t, keepertest.ObserverMockOptions{
UseAuthorityMock: true,
})
srv := keeper.NewMsgServerImpl(*k)
Expand Down
4 changes: 2 additions & 2 deletions x/observer/keeper/msg_server_update_chain_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

func TestMsgServer_UpdateChainParams(t *testing.T) {
t.Run("can update chain params", func(t *testing.T) {
k, ctx, _ := keepertest.ObserverKeeperWithMocks(t, keepertest.ObserverMockOptions{
k, ctx, _, _ := keepertest.ObserverKeeperWithMocks(t, keepertest.ObserverMockOptions{
UseAuthorityMock: true,
})
srv := keeper.NewMsgServerImpl(*k)
Expand Down Expand Up @@ -104,7 +104,7 @@ func TestMsgServer_UpdateChainParams(t *testing.T) {
})

t.Run("cannot update chain params if not authorized", func(t *testing.T) {
k, ctx, _ := keepertest.ObserverKeeperWithMocks(t, keepertest.ObserverMockOptions{
k, ctx, _, _ := keepertest.ObserverKeeperWithMocks(t, keepertest.ObserverMockOptions{
UseAuthorityMock: true,
})
srv := keeper.NewMsgServerImpl(*k)
Expand Down
4 changes: 2 additions & 2 deletions x/observer/keeper/msg_server_update_crosschain_flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

func TestMsgServer_UpdateCrosschainFlags(t *testing.T) {
t.Run("can update crosschain flags", func(t *testing.T) {
k, ctx, _ := keepertest.ObserverKeeperWithMocks(t, keepertest.ObserverMockOptions{
k, ctx, _, _ := keepertest.ObserverKeeperWithMocks(t, keepertest.ObserverMockOptions{
UseAuthorityMock: true,
})
srv := keeper.NewMsgServerImpl(*k)
Expand Down Expand Up @@ -150,7 +150,7 @@ func TestMsgServer_UpdateCrosschainFlags(t *testing.T) {
})

t.Run("cannot update crosschain flags if not authorized", func(t *testing.T) {
k, ctx, _ := keepertest.ObserverKeeperWithMocks(t, keepertest.ObserverMockOptions{
k, ctx, _, _ := keepertest.ObserverKeeperWithMocks(t, keepertest.ObserverMockOptions{
UseAuthorityMock: true,
})
srv := keeper.NewMsgServerImpl(*k)
Expand Down
Loading

0 comments on commit 17fde47

Please sign in to comment.