Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add validation for authorization list in genesisState.Validate() for authority module #2654

Merged
merged 2 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@

* [2615](https://github.com/zeta-chain/node/pull/2615) - Refactor cleanup of outbound trackers

### Fixes

* [2654](https://github.com/zeta-chain/node/pull/2654) - add validation for authorization list in when validating genesis state for authorization module

## v19.0.0

### Breaking Changes
Expand Down
1 change: 1 addition & 0 deletions x/authority/migrations/v2/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
9 changes: 7 additions & 2 deletions x/authority/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
36 changes: 32 additions & 4 deletions x/authority/types/genesis_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package types_test

import (
"fmt"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -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: "",
},
Expand All @@ -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{
Expand All @@ -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) {
Expand Down
Loading