Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
openzeppelin-contracts-upgradeable
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
俞永鹏
openzeppelin-contracts-upgradeable
Commits
3bd30f73
Unverified
Commit
3bd30f73
authored
Oct 16, 2018
by
Nicolás Venturo
Committed by
GitHub
Oct 16, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Roles.add and remove now require pre-conditions on the account. (#1421)
parent
844a96d0
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
12 deletions
+14
-12
Roles.sol
contracts/access/Roles.sol
+4
-0
Roles.test.js
test/access/Roles.test.js
+4
-5
PublicRole.behavior.js
test/access/roles/PublicRole.behavior.js
+6
-7
No files found.
contracts/access/Roles.sol
View file @
3bd30f73
...
...
@@ -14,6 +14,8 @@ library Roles {
*/
function add(Role storage role, address account) internal {
require(account != address(0));
require(!has(role, account));
role.bearer[account] = true;
}
...
...
@@ -22,6 +24,8 @@ library Roles {
*/
function remove(Role storage role, address account) internal {
require(account != address(0));
require(has(role, account));
role.bearer[account] = false;
}
...
...
test/access/Roles.test.js
View file @
3bd30f73
...
...
@@ -29,10 +29,9 @@ contract('Roles', function ([_, authorized, otherAuthorized, anyone]) {
(
await
this
.
roles
.
has
(
anyone
)).
should
.
equal
(
false
);
});
it
(
'
adds roles to an already-
assigned account'
,
async
function
()
{
it
(
'
reverts when adding roles to an already
assigned account'
,
async
function
()
{
await
this
.
roles
.
add
(
authorized
);
await
this
.
roles
.
add
(
authorized
);
(
await
this
.
roles
.
has
(
authorized
)).
should
.
equal
(
true
);
await
shouldFail
.
reverting
(
this
.
roles
.
add
(
authorized
));
});
it
(
'reverts when adding roles to the null account'
,
async
function
()
{
...
...
@@ -54,8 +53,8 @@ contract('Roles', function ([_, authorized, otherAuthorized, anyone]) {
(
await
this
.
roles
.
has
(
otherAuthorized
)).
should
.
equal
(
true
);
});
it
(
'
doesn
\'
t revert
when removing unassigned roles'
,
async
function
()
{
await
this
.
roles
.
remove
(
anyone
);
it
(
'
reverts
when removing unassigned roles'
,
async
function
()
{
await
shouldFail
.
reverting
(
this
.
roles
.
remove
(
anyone
)
);
});
it
(
'reverts when removing roles from the null account'
,
async
function
()
{
...
...
test/access/roles/PublicRole.behavior.js
View file @
3bd30f73
...
...
@@ -52,9 +52,8 @@ function shouldBehaveLikePublicRole (authorized, otherAuthorized, [anyone], role
expectEvent
.
inLogs
(
logs
,
`
${
rolename
}
Added`
,
{
account
:
anyone
});
});
it
(
'adds role to an already-assigned account'
,
async
function
()
{
await
this
.
contract
[
`add
${
rolename
}
`
](
authorized
,
{
from
:
authorized
});
(
await
this
.
contract
[
`is
${
rolename
}
`
](
authorized
)).
should
.
equal
(
true
);
it
(
'reverts when adding role to an already assigned account'
,
async
function
()
{
await
shouldFail
.
reverting
(
this
.
contract
[
`add
${
rolename
}
`
](
authorized
,
{
from
:
authorized
}));
});
it
(
'reverts when adding role to the null account'
,
async
function
()
{
...
...
@@ -74,8 +73,8 @@ function shouldBehaveLikePublicRole (authorized, otherAuthorized, [anyone], role
expectEvent
.
inLogs
(
logs
,
`
${
rolename
}
Removed`
,
{
account
:
authorized
});
});
it
(
'
doesn
\'
t revert
when removing from an unassigned account'
,
async
function
()
{
await
this
.
contract
[
`remove
${
rolename
}
`
](
anyone
);
it
(
'
reverts
when removing from an unassigned account'
,
async
function
()
{
await
shouldFail
.
reverting
(
this
.
contract
[
`remove
${
rolename
}
`
](
anyone
)
);
});
it
(
'reverts when removing role from the null account'
,
async
function
()
{
...
...
@@ -94,8 +93,8 @@ function shouldBehaveLikePublicRole (authorized, otherAuthorized, [anyone], role
expectEvent
.
inLogs
(
logs
,
`
${
rolename
}
Removed`
,
{
account
:
authorized
});
});
it
(
'
doesn
\'
t revert
when renouncing unassigned role'
,
async
function
()
{
await
this
.
contract
[
`renounce
${
rolename
}
`
]({
from
:
anyone
}
);
it
(
'
reverts
when renouncing unassigned role'
,
async
function
()
{
await
shouldFail
.
reverting
(
this
.
contract
[
`renounce
${
rolename
}
`
]({
from
:
anyone
})
);
});
});
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment