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
525a5522
Commit
525a5522
authored
Mar 14, 2017
by
Remco Bloemen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add TokenKillable
parent
9c5975a7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
0 deletions
+62
-0
TokenKillable.sol
contracts/lifecycle/TokenKillable.sol
+30
-0
TokenKillable.js
test/TokenKillable.js
+32
-0
No files found.
contracts/lifecycle/TokenKillable.sol
0 → 100644
View file @
525a5522
pragma solidity ^0.4.8;
import "../ownership/Ownable.sol";
import "../token/ERC20Basic.sol";
/// @title TokenKillable:
/// @author Remco Bloemen <remco@2π.com>
///.Base contract that can be killed by owner. All funds in contract including
/// listed tokens will be sent to the owner
contract TokenKillable is Ownable {
/// @notice Terminate contract and refund to owner
/// @param tokens List of addresses of ERC20 or ERC20Basic token contracts to
// refund
/// @notice The called token contracts could try to re-enter this contract.
// Only supply token contracts you
function kill(address[] tokens) onlyOwner {
// Transfer tokens to owner
for(uint i = 0; i < tokens.length; i++) {
ERC20Basic token = ERC20Basic(tokens[i]);
uint256 balance = token.balanceOf(this);
token.transfer(owner, balance);
}
// Transfer Eth to owner and terminate contract
selfdestruct(owner);
}
}
test/TokenKillable.js
0 → 100644
View file @
525a5522
'use strict'
;
var
TokenKillable
=
artifacts
.
require
(
'../contracts/lifecycle/TokenKillable.sol'
);
var
StandardTokenMock
=
artifacts
.
require
(
"./helpers/StandardTokenMock.sol"
);
require
(
'./helpers/transactionMined.js'
);
contract
(
'TokenKillable'
,
function
(
accounts
)
{
it
(
'should send balance to owner after death'
,
async
function
()
{
let
killable
=
await
TokenKillable
.
new
({
from
:
accounts
[
0
],
value
:
web3
.
toWei
(
'10'
,
'ether'
)});
let
owner
=
await
killable
.
owner
();
let
initBalance
=
web3
.
eth
.
getBalance
(
owner
);
await
killable
.
kill
([],
{
from
:
owner
});
let
newBalance
=
web3
.
eth
.
getBalance
(
owner
);
assert
.
isTrue
(
newBalance
>
initBalance
);
});
it
(
'should send tokens to owner after death'
,
async
function
()
{
let
killable
=
await
TokenKillable
.
new
({
from
:
accounts
[
0
],
value
:
web3
.
toWei
(
'10'
,
'ether'
)});
let
owner
=
await
killable
.
owner
();
let
token
=
await
StandardTokenMock
.
new
(
killable
.
address
,
100
);
let
initContractBalance
=
await
token
.
balanceOf
(
killable
.
address
);
let
initOwnerBalance
=
await
token
.
balanceOf
(
owner
);
assert
.
equal
(
initContractBalance
,
100
);
assert
.
equal
(
initOwnerBalance
,
0
);
await
killable
.
kill
([
token
.
address
],
{
from
:
owner
});
let
newContractBalance
=
await
token
.
balanceOf
(
killable
.
address
);
let
newOwnerBalance
=
await
token
.
balanceOf
(
owner
);
assert
.
equal
(
newContractBalance
,
0
);
assert
.
equal
(
newOwnerBalance
,
100
);
});
});
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