diff --git a/changelog.md b/changelog.md index 28dd19e9e1..06f41f7038 100644 --- a/changelog.md +++ b/changelog.md @@ -15,6 +15,7 @@ ### Fixes +* [2654](https://github.com/zeta-chain/node/pull/2654) - add validation for authorization list in when validating genesis state for authorization module * [2672](https://github.com/zeta-chain/node/pull/2672) - check observer set for duplicates when adding a new observer or updating an existing one ## v19.0.0 diff --git a/x/authority/migrations/v2/migrate.go b/x/authority/migrations/v2/migrate.go index e2f33cf8e8..8eb747fced 100644 --- a/x/authority/migrations/v2/migrate.go +++ b/x/authority/migrations/v2/migrate.go @@ -15,6 +15,7 @@ func MigrateStore( ctx sdk.Context, keeper authorityKeeper, ) error { + // It is okay to not validate here, as the authorization list is fixed and will not change keeper.SetAuthorizationList(ctx, types.DefaultAuthorizationsList()) return nil } diff --git a/x/authority/types/genesis.go b/x/authority/types/genesis.go index 8a35955104..5f823811dc 100644 --- a/x/authority/types/genesis.go +++ b/x/authority/types/genesis.go @@ -14,6 +14,11 @@ func (gs GenesisState) Validate() error { if err := gs.Policies.Validate(); err != nil { return err } - - return gs.ChainInfo.Validate() + if err := gs.AuthorizationList.Validate(); err != nil { + return err + } + if err := gs.ChainInfo.Validate(); err != nil { + return err + } + return nil } diff --git a/x/authority/types/genesis_test.go b/x/authority/types/genesis_test.go index 3d2fde6873..92771cdcb3 100644 --- a/x/authority/types/genesis_test.go +++ b/x/authority/types/genesis_test.go @@ -1,6 +1,7 @@ package types_test import ( + "fmt" "testing" "github.com/stretchr/testify/require" @@ -26,8 +27,9 @@ func TestGenesisState_Validate(t *testing.T) { { name: "valid genesis", gs: &types.GenesisState{ - Policies: sample.Policies(), - ChainInfo: sample.ChainInfo(42), + Policies: sample.Policies(), + ChainInfo: sample.ChainInfo(42), + AuthorizationList: sample.AuthorizationList("testMessage"), }, errContains: "", }, @@ -42,12 +44,13 @@ func TestGenesisState_Validate(t *testing.T) { }, }, }, - ChainInfo: sample.ChainInfo(42), + ChainInfo: sample.ChainInfo(42), + AuthorizationList: sample.AuthorizationList("testMessage"), }, errContains: "invalid address", }, { - name: "invalid if policies is invalid", + name: "invalid if chainInfo is invalid", gs: &types.GenesisState{ Policies: sample.Policies(), ChainInfo: types.ChainInfo{ @@ -63,9 +66,34 @@ func TestGenesisState_Validate(t *testing.T) { }, }, }, + AuthorizationList: sample.AuthorizationList("testMessage"), }, errContains: "chain ID must be positive", }, + { + name: "invalid if authorization list is invalid", + gs: &types.GenesisState{ + Policies: sample.Policies(), + ChainInfo: sample.ChainInfo(42), + AuthorizationList: types.AuthorizationList{ + Authorizations: []types.Authorization{ + { + MsgUrl: fmt.Sprintf("/zetachain/%d%s", 0, "testMessage"), + AuthorizedPolicy: types.PolicyType_groupEmergency, + }, + { + MsgUrl: fmt.Sprintf("/zetachain/%d%s", 0, "testMessage"), + AuthorizedPolicy: types.PolicyType_groupAdmin, + }, + { + MsgUrl: fmt.Sprintf("/zetachain/%d%s", 0, "testMessage"), + AuthorizedPolicy: types.PolicyType_groupOperational, + }, + }, + }, + }, + errContains: "duplicate message url", + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {