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
7e44204d
Commit
7e44204d
authored
May 03, 2018
by
Paweł Winnicki
Committed by
Francisco Giordano
May 03, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added function to renounce ownership (#907)
parent
4a10f727
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
0 deletions
+23
-0
Ownable.sol
contracts/ownership/Ownable.sol
+8
-0
Ownable.test.js
test/ownership/Ownable.test.js
+15
-0
No files found.
contracts/ownership/Ownable.sol
View file @
7e44204d
...
@@ -10,6 +10,7 @@ contract Ownable {
...
@@ -10,6 +10,7 @@ contract Ownable {
address public owner;
address public owner;
event OwnershipRenounced(address indexed previousOwner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
...
@@ -39,4 +40,11 @@ contract Ownable {
...
@@ -39,4 +40,11 @@ contract Ownable {
owner = newOwner;
owner = newOwner;
}
}
/**
* @dev Allows the current owner to relinquish control of the contract.
*/
function renounceOwnership() public onlyOwner {
emit OwnershipRenounced(owner);
owner = address(0);
}
}
}
test/ownership/Ownable.test.js
View file @
7e44204d
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
import
assertRevert
from
'../helpers/assertRevert'
;
import
assertRevert
from
'../helpers/assertRevert'
;
var
Ownable
=
artifacts
.
require
(
'Ownable'
);
var
Ownable
=
artifacts
.
require
(
'Ownable'
);
const
ZERO_ADDRESS
=
'0x0000000000000000000000000000000000000000'
;
contract
(
'Ownable'
,
function
(
accounts
)
{
contract
(
'Ownable'
,
function
(
accounts
)
{
let
ownable
;
let
ownable
;
...
@@ -34,4 +35,18 @@ contract('Ownable', function (accounts) {
...
@@ -34,4 +35,18 @@ contract('Ownable', function (accounts) {
let
originalOwner
=
await
ownable
.
owner
();
let
originalOwner
=
await
ownable
.
owner
();
await
assertRevert
(
ownable
.
transferOwnership
(
null
,
{
from
:
originalOwner
}));
await
assertRevert
(
ownable
.
transferOwnership
(
null
,
{
from
:
originalOwner
}));
});
});
it
(
'loses owner after renouncement'
,
async
function
()
{
await
ownable
.
renounceOwnership
();
let
owner
=
await
ownable
.
owner
();
assert
.
isTrue
(
owner
===
ZERO_ADDRESS
);
});
it
(
'should prevent non-owners from renouncement'
,
async
function
()
{
const
other
=
accounts
[
2
];
const
owner
=
await
ownable
.
owner
.
call
();
assert
.
isTrue
(
owner
!==
other
);
await
assertRevert
(
ownable
.
renounceOwnership
({
from
:
other
}));
});
});
});
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