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

Authorizer: Rename hasPermissions function #138

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion packages/authorizer/certora/specs/Authorizer.spec
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ methods {
// Authorizer
function ANYONE() external returns (address) envfree => ALWAYS(0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF);
function ANYWHERE() external returns (address) envfree => ALWAYS(0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF);
function hasPermissions(address,address) external returns (bool) envfree;
function hasAnyPermission(address,address) external returns (bool) envfree;
function hasPermission(address,address,bytes4) external returns (bool) envfree;
function isAuthorized(address,address,bytes4,uint256[]) external returns (bool) envfree;
function getPermissionParams(address,address,bytes4) external returns (IAuthorizer.Param[]) envfree;
Expand Down
2 changes: 1 addition & 1 deletion packages/authorizer/contracts/Authorized.sol
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ contract Authorized is IAuthorized, Initializable, AuthorizedHelpers {
* @param who Address asking permissions for
*/
function _hasPermissions(address who) internal view returns (bool) {
lgalende marked this conversation as resolved.
Show resolved Hide resolved
return IAuthorizer(authorizer).hasPermissions(who, address(this));
return IAuthorizer(authorizer).hasAnyPermission(who, address(this));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/authorizer/contracts/Authorizer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ contract Authorizer is IAuthorizer, AuthorizedHelpers, Initializable, Reentrancy
* @param who Address asking permission for
* @param where Target address asking permission for
*/
function hasPermissions(address who, address where) external view override returns (bool) {
function hasAnyPermission(address who, address where) external view override returns (bool) {
return _permissionsLists[who][where].count > 0;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/authorizer/contracts/interfaces/IAuthorizer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ interface IAuthorizer {
* @param who Address asking permission for
* @param where Target address asking permission for
*/
function hasPermissions(address who, address where) external view returns (bool);
function hasAnyPermission(address who, address where) external view returns (bool);

/**
* @dev Tells the number of permissions `who` has on `where`
Expand Down
60 changes: 30 additions & 30 deletions packages/authorizer/test/Authorizer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('Authorizer', () => {
const authorizeRole = authorizer.interface.getSighash('authorize')
const unauthorizeRole = authorizer.interface.getSighash('unauthorize')

expect(await authorizer.hasPermissions(admin.address, authorizer.address)).to.be.true
expect(await authorizer.hasAnyPermission(admin.address, authorizer.address)).to.be.true
expect(await authorizer.getPermissionsLength(admin.address, authorizer.address)).to.be.equal(2)

expect(await authorizer.isAuthorized(admin.address, authorizer.address, authorizeRole, [])).to.be.true
Expand All @@ -46,7 +46,7 @@ describe('Authorizer', () => {
expect(await authorizer.hasPermission(admin.address, authorizer.address, authorizeRole)).to.be.true
expect(await authorizer.hasPermission(admin.address, authorizer.address, unauthorizeRole)).to.be.true

expect(await authorizer.hasPermissions(anotherAdmin.address, authorizer.address)).to.be.true
expect(await authorizer.hasAnyPermission(anotherAdmin.address, authorizer.address)).to.be.true
expect(await authorizer.getPermissionsLength(anotherAdmin.address, authorizer.address)).to.be.equal(2)

expect(await authorizer.isAuthorized(anotherAdmin.address, authorizer.address, authorizeRole, [])).to.be.true
Expand All @@ -57,23 +57,23 @@ describe('Authorizer', () => {
})

it('does not allow admins on other permissions or other targets', async () => {
expect(await authorizer.hasPermissions(WHO, WHERE)).to.be.false
expect(await authorizer.hasAnyPermission(WHO, WHERE)).to.be.false
expect(await authorizer.getPermissionsLength(WHO, WHERE)).to.be.equal(0)

expect(await authorizer.isAuthorized(WHO, WHERE, WHAT, [])).to.be.false
expect(await authorizer.isAuthorized(WHO, WHERE, WHAT, [0, 1])).to.be.false

expect(await authorizer.hasPermission(WHO, WHERE, WHAT)).to.be.false

expect(await authorizer.hasPermissions(ANYONE, WHERE)).to.be.false
expect(await authorizer.hasAnyPermission(ANYONE, WHERE)).to.be.false
expect(await authorizer.getPermissionsLength(ANYONE, WHERE)).to.be.equal(0)

expect(await authorizer.isAuthorized(ANYONE, WHERE, WHAT, [])).to.be.false
expect(await authorizer.isAuthorized(ANYONE, WHERE, WHAT, [0, 1])).to.be.false

expect(await authorizer.hasPermission(ANYONE, WHERE, WHAT)).to.be.false

expect(await authorizer.hasPermissions(WHO, ANYWHERE)).to.be.false
expect(await authorizer.hasAnyPermission(WHO, ANYWHERE)).to.be.false
expect(await authorizer.getPermissionsLength(WHO, ANYWHERE)).to.be.equal(0)

expect(await authorizer.isAuthorized(WHO, ANYWHERE, WHAT, [])).to.be.false
Expand Down Expand Up @@ -116,27 +116,27 @@ describe('Authorizer', () => {
it('increments the number of permissions correctly', async () => {
await authorizer.authorize(WHO, WHERE, WHAT, PARAMS)

expect(await authorizer.hasPermissions(WHO, WHERE)).to.be.true
expect(await authorizer.hasAnyPermission(WHO, WHERE)).to.be.true
expect(await authorizer.getPermissionsLength(WHO, WHERE)).to.be.equal(1)

await authorizer.authorize(WHO, WHERE, WHAT, PARAMS)

expect(await authorizer.hasPermissions(WHO, WHERE)).to.be.true
expect(await authorizer.hasAnyPermission(WHO, WHERE)).to.be.true
expect(await authorizer.getPermissionsLength(WHO, WHERE)).to.be.equal(1)

await authorizer.authorize(WHO, WHERE, WHAT2, PARAMS)

expect(await authorizer.hasPermissions(WHO, WHERE)).to.be.true
expect(await authorizer.hasAnyPermission(WHO, WHERE)).to.be.true
expect(await authorizer.getPermissionsLength(WHO, WHERE)).to.be.equal(2)

await authorizer.authorize(WHO, WHERE2, WHAT2, PARAMS)

expect(await authorizer.hasPermissions(WHO, WHERE)).to.be.true
expect(await authorizer.hasAnyPermission(WHO, WHERE)).to.be.true
expect(await authorizer.getPermissionsLength(WHO, WHERE)).to.be.equal(2)

await authorizer.authorize(WHO2, WHERE, WHAT2, PARAMS)

expect(await authorizer.hasPermissions(WHO, WHERE)).to.be.true
expect(await authorizer.hasAnyPermission(WHO, WHERE)).to.be.true
expect(await authorizer.getPermissionsLength(WHO, WHERE)).to.be.equal(2)
})
})
Expand Down Expand Up @@ -508,24 +508,24 @@ describe('Authorizer', () => {
it('decrements the number of permissions correctly', async () => {
await authorizer.unauthorize(WHO, WHERE, WHAT)

expect(await authorizer.hasPermissions(WHO, WHERE)).to.be.false
expect(await authorizer.hasAnyPermission(WHO, WHERE)).to.be.false
expect(await authorizer.getPermissionsLength(WHO, WHERE)).to.be.equal(0)

await authorizer.authorize(WHO, WHERE, WHAT, [])
await authorizer.authorize(WHO, WHERE, WHAT2, [])

expect(await authorizer.hasPermissions(WHO, WHERE)).to.be.true
expect(await authorizer.hasAnyPermission(WHO, WHERE)).to.be.true
expect(await authorizer.getPermissionsLength(WHO, WHERE)).to.be.equal(2)

await authorizer.unauthorize(WHO, WHERE, WHAT)
await authorizer.unauthorize(WHO, WHERE, WHAT)

expect(await authorizer.hasPermissions(WHO, WHERE)).to.be.true
expect(await authorizer.hasAnyPermission(WHO, WHERE)).to.be.true
expect(await authorizer.getPermissionsLength(WHO, WHERE)).to.be.equal(1)

await authorizer.unauthorize(WHO, WHERE, WHAT2)

expect(await authorizer.hasPermissions(WHO, WHERE)).to.be.false
expect(await authorizer.hasAnyPermission(WHO, WHERE)).to.be.false
expect(await authorizer.getPermissionsLength(WHO, WHERE)).to.be.equal(0)
})
})
Expand Down Expand Up @@ -631,12 +631,12 @@ describe('Authorizer', () => {
})

it('someone does not have permissions', async () => {
expect(await authorizer.hasPermissions(someone, WHERE)).to.be.false
expect(await authorizer.hasAnyPermission(someone, WHERE)).to.be.false
expect(await authorizer.getPermissionsLength(someone, WHERE)).to.be.equal(0)
})

it('anyone does not have permission', async () => {
expect(await authorizer.hasPermissions(ANYONE, WHERE)).to.be.false
expect(await authorizer.hasAnyPermission(ANYONE, WHERE)).to.be.false
expect(await authorizer.getPermissionsLength(ANYONE, WHERE)).to.be.equal(0)
})
})
Expand All @@ -652,12 +652,12 @@ describe('Authorizer', () => {
})

it('someone has permissions', async () => {
expect(await authorizer.hasPermissions(someone, WHERE)).to.be.true
expect(await authorizer.hasAnyPermission(someone, WHERE)).to.be.true
expect(await authorizer.getPermissionsLength(someone, WHERE)).to.be.equal(1)
})

it('anyone does not have permission', async () => {
expect(await authorizer.hasPermissions(ANYONE, WHERE)).to.be.false
expect(await authorizer.hasAnyPermission(ANYONE, WHERE)).to.be.false
expect(await authorizer.getPermissionsLength(ANYONE, WHERE)).to.be.equal(0)
})
})
Expand All @@ -677,12 +677,12 @@ describe('Authorizer', () => {
})

it('someone does not have permissions', async () => {
expect(await authorizer.hasPermissions(someone, WHERE)).to.be.false
expect(await authorizer.hasAnyPermission(someone, WHERE)).to.be.false
expect(await authorizer.getPermissionsLength(someone, WHERE)).to.be.equal(0)
})

it('anyone has permissions', async () => {
expect(await authorizer.hasPermissions(ANYONE, WHERE)).to.be.true
expect(await authorizer.hasAnyPermission(ANYONE, WHERE)).to.be.true
expect(await authorizer.getPermissionsLength(ANYONE, WHERE)).to.be.equal(1)
})
})
Expand All @@ -700,12 +700,12 @@ describe('Authorizer', () => {
})

it('someone has permissions', async () => {
expect(await authorizer.hasPermissions(someone, WHERE)).to.be.true
expect(await authorizer.hasAnyPermission(someone, WHERE)).to.be.true
expect(await authorizer.getPermissionsLength(someone, WHERE)).to.be.equal(1)
})

it('anyone has permissions', async () => {
expect(await authorizer.hasPermissions(ANYONE, WHERE)).to.be.true
expect(await authorizer.hasAnyPermission(ANYONE, WHERE)).to.be.true
expect(await authorizer.getPermissionsLength(ANYONE, WHERE)).to.be.equal(1)
})
})
Expand All @@ -727,12 +727,12 @@ describe('Authorizer', () => {
})

it('does not have permissions over somewhere', async () => {
expect(await authorizer.hasPermissions(WHO, somewhere)).to.be.false
expect(await authorizer.hasAnyPermission(WHO, somewhere)).to.be.false
expect(await authorizer.getPermissionsLength(WHO, somewhere)).to.be.equal(0)
})

it('does not have permissions over anywhere', async () => {
expect(await authorizer.hasPermissions(WHO, ANYWHERE)).to.be.false
expect(await authorizer.hasAnyPermission(WHO, ANYWHERE)).to.be.false
expect(await authorizer.getPermissionsLength(WHO, ANYWHERE)).to.be.equal(0)
})
})
Expand All @@ -748,12 +748,12 @@ describe('Authorizer', () => {
})

it('has permissions over somewhere', async () => {
expect(await authorizer.hasPermissions(WHO, somewhere)).to.be.true
expect(await authorizer.hasAnyPermission(WHO, somewhere)).to.be.true
expect(await authorizer.getPermissionsLength(WHO, somewhere)).to.be.equal(1)
})

it('does not have permissions over anywhere', async () => {
expect(await authorizer.hasPermissions(WHO, ANYWHERE)).to.be.false
expect(await authorizer.hasAnyPermission(WHO, ANYWHERE)).to.be.false
expect(await authorizer.getPermissionsLength(WHO, ANYWHERE)).to.be.equal(0)
})
})
Expand All @@ -773,12 +773,12 @@ describe('Authorizer', () => {
})

it('does not have permissions over somewhere', async () => {
expect(await authorizer.hasPermissions(WHO, somewhere)).to.be.false
expect(await authorizer.hasAnyPermission(WHO, somewhere)).to.be.false
expect(await authorizer.getPermissionsLength(WHO, somewhere)).to.be.equal(0)
})

it('has permissions over anywhere', async () => {
expect(await authorizer.hasPermissions(WHO, ANYWHERE)).to.be.true
expect(await authorizer.hasAnyPermission(WHO, ANYWHERE)).to.be.true
expect(await authorizer.getPermissionsLength(WHO, ANYWHERE)).to.be.equal(1)
})
})
Expand All @@ -796,12 +796,12 @@ describe('Authorizer', () => {
})

it('has permissions over somewhere', async () => {
expect(await authorizer.hasPermissions(WHO, somewhere)).to.be.true
expect(await authorizer.hasAnyPermission(WHO, somewhere)).to.be.true
expect(await authorizer.getPermissionsLength(WHO, somewhere)).to.be.equal(1)
})

it('has permissions over anywhere', async () => {
expect(await authorizer.hasPermissions(WHO, ANYWHERE)).to.be.true
expect(await authorizer.hasAnyPermission(WHO, ANYWHERE)).to.be.true
expect(await authorizer.getPermissionsLength(WHO, ANYWHERE)).to.be.equal(1)
})
})
Expand Down
Loading