refactor HasNoTokens.sol

This commit is contained in:
SylTi
2017-08-03 13:21:51 +02:00
parent b50894aabe
commit 406004a99a
3 changed files with 61 additions and 12 deletions

35
test/CanReclaimToken.js Normal file
View File

@ -0,0 +1,35 @@
'use strict';
import expectThrow from './helpers/expectThrow';
import toPromise from './helpers/toPromise';
const CanReclaimToken = artifacts.require('../contracts/ownership/CanReclaimToken.sol');
const BasicTokenMock = artifacts.require("./helpers/BasicTokenMock.sol");
contract('CanReclaimToken', function(accounts) {
let token = null;
let canReclaimToken = null;
beforeEach(async () => {
// Create contract and token
token = await BasicTokenMock.new(accounts[0], 100);
canReclaimToken = await CanReclaimToken.new();
// Force token into contract
await token.transfer(canReclaimToken.address, 10);
const startBalance = await token.balanceOf(canReclaimToken.address);
assert.equal(startBalance, 10);
});
it('should allow owner to reclaim tokens', async function() {
const ownerStartBalance = await token.balanceOf(accounts[0]);
await canReclaimToken.reclaimToken(token.address);
const ownerFinalBalance = await token.balanceOf(accounts[0]);
const finalBalance = await token.balanceOf(canReclaimToken.address);
assert.equal(finalBalance, 0);
assert.equal(ownerFinalBalance - ownerStartBalance, 10);
});
it('should allow only owner to reclaim tokens', async function() {
await expectThrow(
canReclaimToken.reclaimToken(token.address, {from: accounts[1]}),
);
});
});