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
5716492e
Commit
5716492e
authored
Nov 29, 2017
by
zava
Committed by
Alejandro Santander
Jan 18, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
setHeartbeatTimeout: public --> internal
parent
c7807c5b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
28 deletions
+8
-28
Inheritable.sol
contracts/ownership/Inheritable.sol
+6
-6
Inheritable.js
test/Inheritable.js
+2
-22
No files found.
contracts/ownership/Inheritable.sol
View file @
5716492e
...
...
@@ -41,7 +41,7 @@ contract Inheritable is Ownable {
* before the heir can take ownership.
*/
function Inheritable(uint _heartbeatTimeout) public {
heartbeatTimeout = _heartbeatTimeout
;
setHeartbeatTimeout(_heartbeatTimeout)
;
}
function setHeir(address newHeir) public onlyOwner {
...
...
@@ -58,11 +58,6 @@ contract Inheritable is Ownable {
heir = 0;
}
function setHeartbeatTimeout(uint newHeartbeatTimeout) public onlyOwner {
require(ownerLives());
heartbeatTimeout = newHeartbeatTimeout;
}
/**
* @dev Heir can pronounce the owners death. To inherit the ownership, they will
* have to wait for `heartbeatTimeout` seconds.
...
...
@@ -92,6 +87,11 @@ contract Inheritable is Ownable {
timeOfDeath = 0;
}
function setHeartbeatTimeout(uint newHeartbeatTimeout) internal onlyOwner {
require(ownerLives());
heartbeatTimeout = newHeartbeatTimeout;
}
function ownerLives() internal constant returns (bool) {
return timeOfDeath == 0;
}
...
...
test/Inheritable.js
View file @
5716492e
...
...
@@ -14,7 +14,7 @@ contract('Inheritable', function(accounts) {
let
owner
beforeEach
(
async
function
()
{
inheritable
=
await
Inheritable
.
new
()
inheritable
=
await
Inheritable
.
new
(
4141
)
owner
=
await
inheritable
.
owner
()
})
...
...
@@ -58,28 +58,9 @@ contract('Inheritable', function(accounts) {
assert
.
isTrue
(
heir
===
NULL_ADDRESS
)
})
it
(
'owner can set heartbeatTimeout only if they are alive'
,
async
function
()
{
const
newTimeout
=
41414141
await
inheritable
.
setHeartbeatTimeout
(
newTimeout
,
{
from
:
owner
})
assert
.
isTrue
((
await
inheritable
.
heartbeatTimeout
()).
equals
(
new
web3
.
BigNumber
(
newTimeout
)))
const
heir
=
accounts
[
1
]
await
inheritable
.
setHeir
(
heir
,
{
from
:
owner
})
await
inheritable
.
proclaimDeath
({
from
:
heir
})
try
{
await
inheritable
.
setHeartbeatTimeout
(
newTimeout
,
{
from
:
owner
})
assert
.
fail
(
'should have thrown before'
)
}
catch
(
error
)
{
assertJump
(
error
)
}
})
it
(
'heir can inherit only if owner is dead and timeout was reached'
,
async
function
()
{
const
heir
=
accounts
[
1
]
await
inheritable
.
setHeir
(
heir
,
{
from
:
owner
})
await
inheritable
.
setHeartbeatTimeout
(
4141
,
{
from
:
owner
})
try
{
await
inheritable
.
inherit
({
from
:
heir
})
...
...
@@ -99,13 +80,11 @@ contract('Inheritable', function(accounts) {
await
increaseTime
(
4141
)
await
inheritable
.
inherit
({
from
:
heir
})
})
it
(
'heir can
\'
t inherit if owner heartbeats'
,
async
function
()
{
const
heir
=
accounts
[
1
]
await
inheritable
.
setHeir
(
heir
,
{
from
:
owner
})
await
inheritable
.
setHeartbeatTimeout
(
4141
,
{
from
:
owner
})
await
inheritable
.
proclaimDeath
({
from
:
heir
})
await
inheritable
.
heartbeat
({
from
:
owner
})
...
...
@@ -147,6 +126,7 @@ contract('Inheritable', function(accounts) {
assert
.
isTrue
(
ownerDeadEvent
.
args
.
owner
===
owner
)
assert
.
isTrue
(
ownerDeadEvent
.
args
.
heir
===
heir
)
await
increaseTime
(
4141
)
const
inheritLogs
=
(
await
inheritable
.
inherit
({
from
:
heir
})).
logs
const
ownershipTransferredEvent
=
inheritLogs
.
find
(
e
=>
e
.
event
===
'Inherited'
)
...
...
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