Organize test files following contracts folders structure

This commit is contained in:
Facundo Spagnuolo
2018-01-09 12:34:29 -03:00
parent 7532dab17d
commit b925b2dae6
31 changed files with 55 additions and 56 deletions

View File

@ -0,0 +1,23 @@
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);
});
it('should send balance to recepient 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(accounts[1]);
await destructible.destroyAndSend(accounts[1], { from: owner });
let newBalance = web3.eth.getBalance(accounts[1]);
assert.isTrue(newBalance.greaterThan(initBalance));
});
});

View File

@ -0,0 +1,63 @@
import assertRevert from '../helpers/assertRevert';
const PausableMock = artifacts.require('mocks/PausableMock.sol');
contract('Pausable', function (accounts) {
it('can perform normal process in non-pause', async function () {
let Pausable = await PausableMock.new();
let count0 = await Pausable.count();
assert.equal(count0, 0);
await Pausable.normalProcess();
let count1 = await Pausable.count();
assert.equal(count1, 1);
});
it('can not perform normal process in pause', async function () {
let Pausable = await PausableMock.new();
await Pausable.pause();
let count0 = await Pausable.count();
assert.equal(count0, 0);
await assertRevert(Pausable.normalProcess());
let count1 = await Pausable.count();
assert.equal(count1, 0);
});
it('can not take drastic measure in non-pause', async function () {
let Pausable = await PausableMock.new();
await assertRevert(Pausable.drasticMeasure());
const drasticMeasureTaken = await Pausable.drasticMeasureTaken();
assert.isFalse(drasticMeasureTaken);
});
it('can take a drastic measure in a pause', async function () {
let Pausable = await PausableMock.new();
await Pausable.pause();
await Pausable.drasticMeasure();
let drasticMeasureTaken = await Pausable.drasticMeasureTaken();
assert.isTrue(drasticMeasureTaken);
});
it('should resume allowing normal process after pause is over', async function () {
let Pausable = await PausableMock.new();
await Pausable.pause();
await Pausable.unpause();
await Pausable.normalProcess();
let count0 = await Pausable.count();
assert.equal(count0, 1);
});
it('should prevent drastic measure after pause is over', async function () {
let Pausable = await PausableMock.new();
await Pausable.pause();
await Pausable.unpause();
await assertRevert(Pausable.drasticMeasure());
const drasticMeasureTaken = await Pausable.drasticMeasureTaken();
assert.isFalse(drasticMeasureTaken);
});
});

View File

@ -0,0 +1,37 @@
var TokenDestructible = artifacts.require('../contracts/lifecycle/TokenDestructible.sol');
var StandardTokenMock = artifacts.require('mocks/StandardTokenMock.sol');
require('../helpers/transactionMined.js');
contract('TokenDestructible', function (accounts) {
let destructible;
beforeEach(async function () {
destructible = await TokenDestructible.new({
from: accounts[0],
value: web3.toWei('10', 'ether'),
});
});
it('should send balance to owner after destruction', async function () {
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 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);
});
});