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
b2e36314
Commit
b2e36314
authored
Jul 20, 2017
by
pooleja
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add requirement for address to not be 0 and throw error
parent
c3a30e9b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
37 deletions
+36
-37
Ownable.sol
contracts/ownership/Ownable.sol
+1
-2
Ownable.js
test/Ownable.js
+35
-35
No files found.
contracts/ownership/Ownable.sol
View file @
b2e36314
...
...
@@ -33,9 +33,8 @@ contract Ownable {
* @param newOwner The address to transfer ownership to.
*/
function transferOwnership(address newOwner) onlyOwner {
if (newOwner != address(0)) {
require(newOwner != address(0));
owner = newOwner;
}
}
}
test/Ownable.js
View file @
b2e36314
'use strict'
;
const
assertJump
=
require
(
'./helpers/assertJump'
)
;
'use strict'
const
assertJump
=
require
(
'./helpers/assertJump'
)
var
Ownable
=
artifacts
.
require
(
'../contracts/ownership/Ownable.sol'
)
;
var
Ownable
=
artifacts
.
require
(
'../contracts/ownership/Ownable.sol'
)
contract
(
'Ownable'
,
function
(
accounts
)
{
let
ownable
;
contract
(
'Ownable'
,
function
(
accounts
)
{
let
ownable
beforeEach
(
async
function
()
{
ownable
=
await
Ownable
.
new
()
;
})
;
beforeEach
(
async
function
()
{
ownable
=
await
Ownable
.
new
()
})
it
(
'should have an owner'
,
async
function
()
{
let
owner
=
await
ownable
.
owner
()
;
assert
.
isTrue
(
owner
!==
0
)
;
})
;
it
(
'should have an owner'
,
async
function
()
{
let
owner
=
await
ownable
.
owner
()
assert
.
isTrue
(
owner
!==
0
)
})
it
(
'changes owner after transfer'
,
async
function
()
{
let
other
=
accounts
[
1
]
;
await
ownable
.
transferOwnership
(
other
)
;
let
owner
=
await
ownable
.
owner
()
;
it
(
'changes owner after transfer'
,
async
function
()
{
let
other
=
accounts
[
1
]
await
ownable
.
transferOwnership
(
other
)
let
owner
=
await
ownable
.
owner
()
assert
.
isTrue
(
owner
===
other
)
;
})
;
assert
.
isTrue
(
owner
===
other
)
})
it
(
'should prevent non-owners from transfering'
,
async
function
()
{
const
other
=
accounts
[
2
]
;
const
owner
=
await
ownable
.
owner
.
call
()
;
assert
.
isTrue
(
owner
!==
other
)
;
it
(
'should prevent non-owners from transfering'
,
async
function
()
{
const
other
=
accounts
[
2
]
const
owner
=
await
ownable
.
owner
.
call
()
assert
.
isTrue
(
owner
!==
other
)
try
{
await
ownable
.
transferOwnership
(
other
,
{
from
:
other
})
;
}
catch
(
error
)
{
assertJump
(
error
)
;
await
ownable
.
transferOwnership
(
other
,
{
from
:
other
})
}
catch
(
error
)
{
assertJump
(
error
)
}
})
;
})
it
(
'should guard ownership against stuck state
'
,
async
function
()
{
let
originalOwner
=
await
ownable
.
owner
()
;
await
ownable
.
transferOwnership
(
null
,
{
from
:
originalOwner
});
let
newOwner
=
await
ownable
.
owner
();
assert
.
equal
(
originalOwner
,
newOwner
);
});
})
;
it
(
'should guard ownership against stuck state
setting owner as 0x0 address'
,
async
function
()
{
let
originalOwner
=
await
ownable
.
owner
()
try
{
await
ownable
.
transferOwnership
(
null
,
{
from
:
originalOwner
})
}
catch
(
error
)
{
assertJump
(
error
)
}
})
})
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