Skip to content

Commit

Permalink
fix isGranted (#618)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rekard0 authored Oct 29, 2024
1 parent 562330f commit 2f4ae4c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
6 changes: 4 additions & 2 deletions packages/contracts/src/core/permission/PermissionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,15 @@ abstract contract PermissionManager is Initializable {
// If this permission is not set, continue.
}

// Generic caller (`_who: ANY_ADDR`) condition check
// Generic caller (`_who: ANY_ADDR`)
{
// This permission can only be granted in conjunction with a condition via the `grantWithCondition` function.
address genericCallerPermission = permissionsHashed[
permissionHash({_where: _where, _who: ANY_ADDR, _permissionId: _permissionId})
];

// If the permission was granted directly to (`_who: ANY_ADDR`), return `true`.
if (genericCallerPermission == ALLOW_FLAG) return true;

// If the permission was granted with a condition, check the condition and return the result.
if (genericCallerPermission != UNSET_FLAG) {
return
Expand Down
13 changes: 12 additions & 1 deletion packages/contracts/test/core/permission/permission-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ interface SingleTargetPermission {
permissionId: string;
}

describe('Core: PermissionManager', function () {
describe.only('Core: PermissionManager', function () {
let pm: PermissionManagerTest;
let signers: SignerWithAddress[];
let ownerSigner: SignerWithAddress;
Expand Down Expand Up @@ -1101,6 +1101,17 @@ describe('Core: PermissionManager', function () {
)
).to.be.true;
});

it('returns `true` if the permission is granted to `_who == ANY_ADDR`', async () => {
await pm.grant(pm.address, ANY_ADDR, ADMIN_PERMISSION_ID);
const isGranted = await pm.callStatic.isGranted(
pm.address,
otherSigner.address,
ADMIN_PERMISSION_ID,
[]
);
expect(isGranted).to.be.equal(true);
});
});

describe('_hasPermission', () => {
Expand Down

0 comments on commit 2f4ae4c

Please sign in to comment.