Skip to content

Commit f78ff55

Browse files
authored
fix: add validation for authorization list in genesisState.Validate() for authority module (#2654)
* add validation for authorization list * add changelog
1 parent d8a23e3 commit f78ff55

File tree

4 files changed

+44
-6
lines changed

4 files changed

+44
-6
lines changed

changelog.md

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313

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

16+
### Fixes
17+
18+
* [2654](https://github.com/zeta-chain/node/pull/2654) - add validation for authorization list in when validating genesis state for authorization module
19+
1620
## v19.0.0
1721

1822
### Breaking Changes

x/authority/migrations/v2/migrate.go

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ func MigrateStore(
1515
ctx sdk.Context,
1616
keeper authorityKeeper,
1717
) error {
18+
// It is okay to not validate here, as the authorization list is fixed and will not change
1819
keeper.SetAuthorizationList(ctx, types.DefaultAuthorizationsList())
1920
return nil
2021
}

x/authority/types/genesis.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ func (gs GenesisState) Validate() error {
1414
if err := gs.Policies.Validate(); err != nil {
1515
return err
1616
}
17-
18-
return gs.ChainInfo.Validate()
17+
if err := gs.AuthorizationList.Validate(); err != nil {
18+
return err
19+
}
20+
if err := gs.ChainInfo.Validate(); err != nil {
21+
return err
22+
}
23+
return nil
1924
}

x/authority/types/genesis_test.go

+32-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package types_test
22

33
import (
4+
"fmt"
45
"testing"
56

67
"github.com/stretchr/testify/require"
@@ -26,8 +27,9 @@ func TestGenesisState_Validate(t *testing.T) {
2627
{
2728
name: "valid genesis",
2829
gs: &types.GenesisState{
29-
Policies: sample.Policies(),
30-
ChainInfo: sample.ChainInfo(42),
30+
Policies: sample.Policies(),
31+
ChainInfo: sample.ChainInfo(42),
32+
AuthorizationList: sample.AuthorizationList("testMessage"),
3133
},
3234
errContains: "",
3335
},
@@ -42,12 +44,13 @@ func TestGenesisState_Validate(t *testing.T) {
4244
},
4345
},
4446
},
45-
ChainInfo: sample.ChainInfo(42),
47+
ChainInfo: sample.ChainInfo(42),
48+
AuthorizationList: sample.AuthorizationList("testMessage"),
4649
},
4750
errContains: "invalid address",
4851
},
4952
{
50-
name: "invalid if policies is invalid",
53+
name: "invalid if chainInfo is invalid",
5154
gs: &types.GenesisState{
5255
Policies: sample.Policies(),
5356
ChainInfo: types.ChainInfo{
@@ -63,9 +66,34 @@ func TestGenesisState_Validate(t *testing.T) {
6366
},
6467
},
6568
},
69+
AuthorizationList: sample.AuthorizationList("testMessage"),
6670
},
6771
errContains: "chain ID must be positive",
6872
},
73+
{
74+
name: "invalid if authorization list is invalid",
75+
gs: &types.GenesisState{
76+
Policies: sample.Policies(),
77+
ChainInfo: sample.ChainInfo(42),
78+
AuthorizationList: types.AuthorizationList{
79+
Authorizations: []types.Authorization{
80+
{
81+
MsgUrl: fmt.Sprintf("/zetachain/%d%s", 0, "testMessage"),
82+
AuthorizedPolicy: types.PolicyType_groupEmergency,
83+
},
84+
{
85+
MsgUrl: fmt.Sprintf("/zetachain/%d%s", 0, "testMessage"),
86+
AuthorizedPolicy: types.PolicyType_groupAdmin,
87+
},
88+
{
89+
MsgUrl: fmt.Sprintf("/zetachain/%d%s", 0, "testMessage"),
90+
AuthorizedPolicy: types.PolicyType_groupOperational,
91+
},
92+
},
93+
},
94+
},
95+
errContains: "duplicate message url",
96+
},
6997
}
7098
for _, tt := range tests {
7199
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)