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
65c97117
Commit
65c97117
authored
Feb 21, 2017
by
Manuel Aráoz
Committed by
GitHub
Feb 21, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #147 from fabioberger/refactor/modifiers
Update modifiers to throw and update corresponding tests
parents
c10a2cf1
3d6988cf
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
52 additions
and
26 deletions
+52
-26
DayLimit.sol
contracts/DayLimit.sol
+3
-2
Claimable.sol
contracts/ownership/Claimable.sol
+4
-2
Ownable.sol
contracts/ownership/Ownable.sol
+3
-2
Shareable.sol
contracts/ownership/Shareable.sol
+3
-2
Claimable.js
test/Claimable.js
+14
-8
DayLimit.js
test/DayLimit.js
+16
-5
Ownable.js
test/Ownable.js
+9
-5
No files found.
contracts/DayLimit.sol
View file @
65c97117
...
@@ -58,8 +58,9 @@ contract DayLimit {
...
@@ -58,8 +58,9 @@ contract DayLimit {
// simple modifier for daily limit.
// simple modifier for daily limit.
modifier limitedDaily(uint _value) {
modifier limitedDaily(uint _value) {
if (underLimit(_value)) {
if (
!
underLimit(_value)) {
_
;
throw
;
}
}
_;
}
}
}
}
contracts/ownership/Claimable.sol
View file @
65c97117
...
@@ -13,8 +13,10 @@ contract Claimable is Ownable {
...
@@ -13,8 +13,10 @@ contract Claimable is Ownable {
address public pendingOwner;
address public pendingOwner;
modifier onlyPendingOwner() {
modifier onlyPendingOwner() {
if (msg.sender == pendingOwner)
if (msg.sender != pendingOwner) {
_;
throw;
}
_;
}
}
function transferOwnership(address newOwner) onlyOwner {
function transferOwnership(address newOwner) onlyOwner {
...
...
contracts/ownership/Ownable.sol
View file @
65c97117
...
@@ -15,9 +15,10 @@ contract Ownable {
...
@@ -15,9 +15,10 @@ contract Ownable {
}
}
modifier onlyOwner() {
modifier onlyOwner() {
if (msg.sender
=
= owner) {
if (msg.sender
!
= owner) {
_
;
throw
;
}
}
_;
}
}
function transferOwnership(address newOwner) onlyOwner {
function transferOwnership(address newOwner) onlyOwner {
...
...
contracts/ownership/Shareable.sol
View file @
65c97117
...
@@ -39,9 +39,10 @@ contract Shareable {
...
@@ -39,9 +39,10 @@ contract Shareable {
// simple single-sig function modifier.
// simple single-sig function modifier.
modifier onlyOwner {
modifier onlyOwner {
if (isOwner(msg.sender)) {
if (
!
isOwner(msg.sender)) {
_
;
throw
;
}
}
_;
}
}
// multi-sig function modifier: the operation must have an intrinsic hash in order
// multi-sig function modifier: the operation must have an intrinsic hash in order
...
...
test/Claimable.js
View file @
65c97117
'use strict'
;
'use strict'
;
const
assertJump
=
require
(
'./helpers/assertJump'
);
var
Claimable
=
artifacts
.
require
(
'../contracts/ownership/Claimable.sol'
);
var
Claimable
=
artifacts
.
require
(
'../contracts/ownership/Claimable.sol'
);
...
@@ -23,17 +24,22 @@ contract('Claimable', function(accounts) {
...
@@ -23,17 +24,22 @@ contract('Claimable', function(accounts) {
});
});
it
(
'should prevent to claimOwnership from no pendingOwner'
,
async
function
()
{
it
(
'should prevent to claimOwnership from no pendingOwner'
,
async
function
()
{
claimable
.
claimOwnership
({
from
:
accounts
[
2
]});
try
{
let
owner
=
await
claimable
.
owner
();
await
claimable
.
claimOwnership
({
from
:
accounts
[
2
]});
}
catch
(
error
)
{
assert
.
isTrue
(
owner
!==
accounts
[
2
]);
assertJump
(
error
);
}
});
});
it
(
'should prevent non-owners from transfering'
,
async
function
()
{
it
(
'should prevent non-owners from transfering'
,
async
function
()
{
await
claimable
.
transferOwnership
(
accounts
[
2
],
{
from
:
accounts
[
2
]});
const
other
=
accounts
[
2
];
let
pendingOwner
=
await
claimable
.
pendingOwner
();
const
owner
=
await
claimable
.
owner
.
call
();
assert
.
isTrue
(
owner
!==
other
);
assert
.
isFalse
(
pendingOwner
===
accounts
[
2
]);
try
{
await
claimable
.
transferOwnership
(
other
,
{
from
:
other
});
}
catch
(
error
)
{
assertJump
(
error
);
}
});
});
describe
(
'after initiating a transfer'
,
function
()
{
describe
(
'after initiating a transfer'
,
function
()
{
...
...
test/DayLimit.js
View file @
65c97117
'use strict'
;
'use strict'
;
const
assertJump
=
require
(
'./helpers/assertJump'
);
var
DayLimitMock
=
artifacts
.
require
(
'helpers/DayLimitMock.sol'
);
var
DayLimitMock
=
artifacts
.
require
(
'helpers/DayLimitMock.sol'
);
...
@@ -32,9 +33,11 @@ contract('DayLimit', function(accounts) {
...
@@ -32,9 +33,11 @@ contract('DayLimit', function(accounts) {
let
spentToday
=
await
dayLimit
.
spentToday
();
let
spentToday
=
await
dayLimit
.
spentToday
();
assert
.
equal
(
spentToday
,
8
);
assert
.
equal
(
spentToday
,
8
);
await
dayLimit
.
attemptSpend
(
3
);
try
{
spentToday
=
await
dayLimit
.
spentToday
();
await
dayLimit
.
attemptSpend
(
3
);
assert
.
equal
(
spentToday
,
8
);
}
catch
(
error
)
{
assertJump
(
error
);
}
});
});
it
(
'should allow spending if daily limit is reached and then set higher'
,
async
function
()
{
it
(
'should allow spending if daily limit is reached and then set higher'
,
async
function
()
{
...
@@ -45,7 +48,11 @@ contract('DayLimit', function(accounts) {
...
@@ -45,7 +48,11 @@ contract('DayLimit', function(accounts) {
let
spentToday
=
await
dayLimit
.
spentToday
();
let
spentToday
=
await
dayLimit
.
spentToday
();
assert
.
equal
(
spentToday
,
8
);
assert
.
equal
(
spentToday
,
8
);
await
dayLimit
.
attemptSpend
(
3
);
try
{
await
dayLimit
.
attemptSpend
(
3
);
}
catch
(
error
)
{
assertJump
(
error
);
}
spentToday
=
await
dayLimit
.
spentToday
();
spentToday
=
await
dayLimit
.
spentToday
();
assert
.
equal
(
spentToday
,
8
);
assert
.
equal
(
spentToday
,
8
);
...
@@ -63,7 +70,11 @@ contract('DayLimit', function(accounts) {
...
@@ -63,7 +70,11 @@ contract('DayLimit', function(accounts) {
let
spentToday
=
await
dayLimit
.
spentToday
();
let
spentToday
=
await
dayLimit
.
spentToday
();
assert
.
equal
(
spentToday
,
8
);
assert
.
equal
(
spentToday
,
8
);
await
dayLimit
.
attemptSpend
(
3
);
try
{
await
dayLimit
.
attemptSpend
(
3
);
}
catch
(
error
)
{
assertJump
(
error
);
}
spentToday
=
await
dayLimit
.
spentToday
();
spentToday
=
await
dayLimit
.
spentToday
();
assert
.
equal
(
spentToday
,
8
);
assert
.
equal
(
spentToday
,
8
);
...
...
test/Ownable.js
View file @
65c97117
'use strict'
;
'use strict'
;
const
assertJump
=
require
(
'./helpers/assertJump'
);
var
Ownable
=
artifacts
.
require
(
'../contracts/ownership/Ownable.sol'
);
var
Ownable
=
artifacts
.
require
(
'../contracts/ownership/Ownable.sol'
);
...
@@ -23,11 +24,14 @@ contract('Ownable', function(accounts) {
...
@@ -23,11 +24,14 @@ contract('Ownable', function(accounts) {
});
});
it
(
'should prevent non-owners from transfering'
,
async
function
()
{
it
(
'should prevent non-owners from transfering'
,
async
function
()
{
let
other
=
accounts
[
2
];
const
other
=
accounts
[
2
];
await
ownable
.
transferOwnership
(
other
,
{
from
:
accounts
[
2
]});
const
owner
=
await
ownable
.
owner
.
call
();
let
owner
=
await
ownable
.
owner
();
assert
.
isTrue
(
owner
!==
other
);
try
{
assert
.
isFalse
(
owner
===
other
);
await
ownable
.
transferOwnership
(
other
,
{
from
:
other
});
}
catch
(
error
)
{
assertJump
(
error
);
}
});
});
it
(
'should guard ownership against stuck state'
,
async
function
()
{
it
(
'should guard ownership against stuck state'
,
async
function
()
{
...
...
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