Merge pull request #187 from DavidKnott/change-killable-contract-to-destructible
Change killable to destructible and kill to destroypull/185/head
commit
0328250554
@ -0,0 +1,15 @@ |
||||
pragma solidity ^0.4.8; |
||||
|
||||
|
||||
import "../ownership/Ownable.sol"; |
||||
|
||||
|
||||
/* |
||||
* Destructible |
||||
* Base contract that can be destroyed by owner. All funds in contract will be sent to the owner. |
||||
*/ |
||||
contract Destructible is Ownable { |
||||
function destroy() onlyOwner { |
||||
selfdestruct(owner); |
||||
} |
||||
} |
@ -1,15 +0,0 @@ |
||||
pragma solidity ^0.4.8; |
||||
|
||||
|
||||
import "../ownership/Ownable.sol"; |
||||
|
||||
|
||||
/* |
||||
* Killable |
||||
* Base contract that can be killed by owner. All funds in contract will be sent to the owner. |
||||
*/ |
||||
contract Killable is Ownable { |
||||
function kill() onlyOwner { |
||||
selfdestruct(owner); |
||||
} |
||||
} |
@ -1,11 +1,11 @@ |
||||
Killable |
||||
Destructible |
||||
============================================= |
||||
|
||||
Base contract that can be killed by owner. |
||||
Base contract that can be destroyed by owner. |
||||
|
||||
Inherits from contract Ownable. |
||||
|
||||
kill( ) onlyOwner |
||||
destroy( ) onlyOwner |
||||
""""""""""""""""""" |
||||
|
||||
Destroys the contract and sends funds back to the owner. |
@ -0,0 +1,18 @@ |
||||
'use strict'; |
||||
|
||||
var Destructible = artifacts.require('../contracts/lifecycle/Destructible.sol'); |
||||
require('./helpers/transactionMined.js'); |
||||
|
||||
contract('Destructible', function(accounts) { |
||||
|
||||
it('should send balance to owner after destruction', async function() { |
||||
let destructible = await Destructible.new({from: accounts[0], value: web3.toWei('10','ether')}); |
||||
let owner = await destructible.owner(); |
||||
let initBalance = web3.eth.getBalance(owner); |
||||
await destructible.destroy({from: owner}); |
||||
let newBalance = web3.eth.getBalance(owner); |
||||
|
||||
assert.isTrue(newBalance > initBalance); |
||||
}); |
||||
|
||||
}); |
@ -1,18 +0,0 @@ |
||||
'use strict'; |
||||
|
||||
var Killable = artifacts.require('../contracts/lifecycle/Killable.sol'); |
||||
require('./helpers/transactionMined.js'); |
||||
|
||||
contract('Killable', function(accounts) { |
||||
|
||||
it('should send balance to owner after death', async function() { |
||||
let killable = await Killable.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); |
||||
}); |
||||
|
||||
}); |
@ -0,0 +1,32 @@ |
||||
'use strict'; |
||||
|
||||
var TokenDestructible = artifacts.require('../contracts/lifecycle/TokenDestructible.sol'); |
||||
var StandardTokenMock = artifacts.require("./helpers/StandardTokenMock.sol"); |
||||
require('./helpers/transactionMined.js'); |
||||
|
||||
contract('TokenDestructible', function(accounts) { |
||||
|
||||
it('should send balance to owner after destruction', async function() { |
||||
let destructible = await TokenDestructible.new({from: accounts[0], value: web3.toWei('10','ether')}); |
||||
let owner = await destructible.owner(); |
||||
let initBalance = web3.eth.getBalance(owner); |
||||
await destructible.destroy([], {from: owner}); |
||||
let newBalance = web3.eth.getBalance(owner); |
||||
assert.isTrue(newBalance > initBalance); |
||||
}); |
||||
|
||||
it('should send tokens to owner after destruction', async function() { |
||||
let destructible = await TokenDestructible.new({from: accounts[0], value: web3.toWei('10','ether')}); |
||||
let owner = await destructible.owner(); |
||||
let token = await StandardTokenMock.new(destructible.address, 100); |
||||
let initContractBalance = await token.balanceOf(destructible.address); |
||||
let initOwnerBalance = await token.balanceOf(owner); |
||||
assert.equal(initContractBalance, 100); |
||||
assert.equal(initOwnerBalance, 0); |
||||
await destructible.destroy([token.address], {from: owner}); |
||||
let newContractBalance = await token.balanceOf(destructible.address); |
||||
let newOwnerBalance = await token.balanceOf(owner); |
||||
assert.equal(newContractBalance, 0); |
||||
assert.equal(newOwnerBalance, 100); |
||||
}); |
||||
}); |
@ -1,32 +0,0 @@ |
||||
'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); |
||||
}); |
||||
}); |
Loading…
Reference in new issue