-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add migration for authorization list (#2366)
* add migration for authorization list * add changelog * add forced migration to fix upgrade tests * make fmt --------- Co-authored-by: Alex Gartner <[email protected]>
- Loading branch information
Showing
8 changed files
with
87 additions
and
2 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 keeper | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
v2 "github.com/zeta-chain/zetacore/x/authority/migrations/v2" | ||
) | ||
|
||
// Migrator is a struct for handling in-place store migrations. | ||
type Migrator struct { | ||
authorityKeeper Keeper | ||
} | ||
|
||
// NewMigrator returns a new Migrator for the authority module. | ||
func NewMigrator(keeper Keeper) Migrator { | ||
return Migrator{ | ||
authorityKeeper: keeper, | ||
} | ||
} | ||
|
||
// Migrate1to2 migrates the authority store from consensus version 1 to 2 | ||
func (m Migrator) Migrate1to2(ctx sdk.Context) error { | ||
return v2.MigrateStore(ctx, m.authorityKeeper) | ||
} |
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,21 @@ | ||
package v2 | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/zeta-chain/zetacore/x/authority/types" | ||
) | ||
|
||
type authorityKeeper interface { | ||
SetAuthorizationList(ctx sdk.Context, list types.AuthorizationList) | ||
} | ||
|
||
// MigrateStore migrates the authority module state from the consensus version 1 to 2 | ||
func MigrateStore( | ||
ctx sdk.Context, | ||
keeper authorityKeeper, | ||
) error { | ||
ctx.Logger().Info("Migrating authority store from version 1 to 2") | ||
keeper.SetAuthorizationList(ctx, types.DefaultAuthorizationsList()) | ||
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,28 @@ | ||
package v2_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
keepertest "github.com/zeta-chain/zetacore/testutil/keeper" | ||
v2 "github.com/zeta-chain/zetacore/x/authority/migrations/v2" | ||
"github.com/zeta-chain/zetacore/x/authority/types" | ||
) | ||
|
||
func TestMigrateStore(t *testing.T) { | ||
t.Run("Set authorization list", func(t *testing.T) { | ||
k, ctx := keepertest.AuthorityKeeper(t) | ||
|
||
list, found := k.GetAuthorizationList(ctx) | ||
require.False(t, found) | ||
require.Equal(t, types.AuthorizationList{}, list) | ||
|
||
err := v2.MigrateStore(ctx, *k) | ||
require.NoError(t, err) | ||
|
||
list, found = k.GetAuthorizationList(ctx) | ||
require.True(t, found) | ||
require.Equal(t, types.DefaultAuthorizationsList(), list) | ||
}) | ||
} |
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