Skip to content

Commit

Permalink
use sub function for get required group
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis committed Apr 17, 2024
1 parent 785e788 commit c2c0409
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 6 deletions.
7 changes: 1 addition & 6 deletions x/lightclient/keeper/msg_server_update_verification_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,8 @@ func (k msgServer) UpdateVerificationFlags(goCtx context.Context, msg *types.Msg
) {
ctx := sdk.UnwrapSDKContext(goCtx)

requiredGroup := authoritytypes.PolicyType_groupEmergency
if msg.VerificationFlags.EthTypeChainEnabled || msg.VerificationFlags.BtcTypeChainEnabled {
requiredGroup = authoritytypes.PolicyType_groupOperational
}

// check permission
if !k.GetAuthorityKeeper().IsAuthorized(ctx, msg.Creator, requiredGroup) {
if !k.GetAuthorityKeeper().IsAuthorized(ctx, msg.Creator, msg.GetRequireGroup()) {
return &types.MsgUpdateVerificationFlagsResponse{}, authoritytypes.ErrUnauthorized
}

Expand Down
11 changes: 11 additions & 0 deletions x/lightclient/types/message_update_verification_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
cosmoserrors "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
authoritytypes "github.com/zeta-chain/zetacore/x/authority/types"
)

const (
Expand Down Expand Up @@ -49,3 +50,13 @@ func (msg *MsgUpdateVerificationFlags) ValidateBasic() error {
}
return nil
}

// GetRequireGroup returns the required group to execute the message
func (msg *MsgUpdateVerificationFlags) GetRequireGroup() authoritytypes.PolicyType {
requiredGroup := authoritytypes.PolicyType_groupEmergency
if msg.VerificationFlags.EthTypeChainEnabled || msg.VerificationFlags.BtcTypeChainEnabled {
requiredGroup = authoritytypes.PolicyType_groupOperational
}

return requiredGroup
}
56 changes: 56 additions & 0 deletions x/lightclient/types/message_update_verification_flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/stretchr/testify/require"
"github.com/zeta-chain/zetacore/testutil/sample"
authoritytypes "github.com/zeta-chain/zetacore/x/authority/types"
"github.com/zeta-chain/zetacore/x/lightclient/types"
)

Expand Down Expand Up @@ -115,3 +116,58 @@ func TestMsgUpdateVerificationFlags_GetSignBytes(t *testing.T) {
msg.GetSignBytes()
})
}

func TestMsgUpdateVerificationFlags_GetRequireGroup(t *testing.T) {
tests := []struct {
name string
msg types.MsgUpdateVerificationFlags
want authoritytypes.PolicyType
}{
{
name: "groupEmergency",
msg: types.MsgUpdateVerificationFlags{
VerificationFlags: types.VerificationFlags{
EthTypeChainEnabled: false,
BtcTypeChainEnabled: false,
},
},
want: authoritytypes.PolicyType_groupEmergency,
},
{
name: "groupOperational",
msg: types.MsgUpdateVerificationFlags{
VerificationFlags: types.VerificationFlags{
EthTypeChainEnabled: true,
BtcTypeChainEnabled: false,
},
},
want: authoritytypes.PolicyType_groupOperational,
},
{
name: "groupOperational",
msg: types.MsgUpdateVerificationFlags{
VerificationFlags: types.VerificationFlags{
EthTypeChainEnabled: false,
BtcTypeChainEnabled: true,
},
},
want: authoritytypes.PolicyType_groupOperational,
},
{
name: "groupOperational",
msg: types.MsgUpdateVerificationFlags{
VerificationFlags: types.VerificationFlags{
EthTypeChainEnabled: true,
BtcTypeChainEnabled: true,
},
},
want: authoritytypes.PolicyType_groupOperational,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := tt.msg.GetRequireGroup()
require.Equal(t, tt.want, got)
})
}
}

0 comments on commit c2c0409

Please sign in to comment.