Skip to content

Commit

Permalink
skip case when permission is 0
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-nguy committed Feb 6, 2023
1 parent b2322c5 commit 889be1c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions x/cronos/keeper/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ func (k Keeper) GetPermissions(ctx sdk.Context, address sdk.AccAddress) uint64 {

// HasPermission check if an account has a specific permission. by default cronos admin has all permissions
func (k Keeper) HasPermission(ctx sdk.Context, account sdk.AccAddress, permissionsToCheck uint64) bool {
// case when no permission is needed
if permissionsToCheck == 0 {
return true
}
admin := k.GetParams(ctx).CronosAdmin
permission := k.GetPermissions(ctx, account)
mask := permission & permissionsToCheck
Expand Down
3 changes: 3 additions & 0 deletions x/cronos/keeper/permissions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ func (suite *KeeperTestSuite) TestHasPermissions() {
address := common.BytesToAddress(priv.PubKey().Address().Bytes())
cosmosAddress := sdk.AccAddress(address.Bytes())

suite.Require().Equal(true, keeper.HasPermission(suite.ctx, cosmosAddress, 0))
suite.Require().Equal(true, keeper.HasPermission(suite.ctx, cosmosAddress, 0))

suite.Require().Equal(false, keeper.HasPermission(suite.ctx, cosmosAddress, CanChangeTokenMapping))
suite.Require().Equal(false, keeper.HasPermission(suite.ctx, cosmosAddress, CanTurnBridge))

Expand Down

0 comments on commit 889be1c

Please sign in to comment.