Changed before for beforeAll, refactored Bouncer tests. (#1094)

* Changed before for beforeAll, refactored Bouncer tests.

* Fixed linter errors.

* fix: updates for SignatureBouncer tests and voucher construction
This commit is contained in:
Nicolás Venturo
2018-07-20 12:25:40 -03:00
committed by GitHub
parent ce0c3274ee
commit 67b67b791e
16 changed files with 338 additions and 310 deletions

View File

@ -2,20 +2,21 @@ var Destructible = artifacts.require('Destructible');
const { ethGetBalance } = require('../helpers/web3');
contract('Destructible', function (accounts) {
beforeEach(async function () {
this.destructible = await Destructible.new({ from: accounts[0], value: web3.toWei('10', 'ether') });
this.owner = await this.destructible.owner();
});
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 = await ethGetBalance(owner);
await destructible.destroy({ from: owner });
let newBalance = await ethGetBalance(owner);
let initBalance = await ethGetBalance(this.owner);
await this.destructible.destroy({ from: this.owner });
let newBalance = await ethGetBalance(this.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 = await ethGetBalance(accounts[1]);
await destructible.destroyAndSend(accounts[1], { from: owner });
await this.destructible.destroyAndSend(accounts[1], { from: this.owner });
let newBalance = await ethGetBalance(accounts[1]);
assert.isTrue(newBalance.greaterThan(initBalance));
});

View File

@ -2,61 +2,59 @@ const { assertRevert } = require('../helpers/assertRevert');
const PausableMock = artifacts.require('PausableMock');
contract('Pausable', function (accounts) {
beforeEach(async function () {
this.Pausable = await PausableMock.new();
});
it('can perform normal process in non-pause', async function () {
let Pausable = await PausableMock.new();
let count0 = await Pausable.count();
let count0 = await this.Pausable.count();
assert.equal(count0, 0);
await Pausable.normalProcess();
let count1 = await Pausable.count();
await this.Pausable.normalProcess();
let count1 = await this.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();
await this.Pausable.pause();
let count0 = await this.Pausable.count();
assert.equal(count0, 0);
await assertRevert(Pausable.normalProcess());
let count1 = await Pausable.count();
await assertRevert(this.Pausable.normalProcess());
let count1 = await this.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();
await assertRevert(this.Pausable.drasticMeasure());
const drasticMeasureTaken = await this.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();
await this.Pausable.pause();
await this.Pausable.drasticMeasure();
let drasticMeasureTaken = await this.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();
await this.Pausable.pause();
await this.Pausable.unpause();
await this.Pausable.normalProcess();
let count0 = await this.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 this.Pausable.pause();
await this.Pausable.unpause();
await assertRevert(Pausable.drasticMeasure());
await assertRevert(this.Pausable.drasticMeasure());
const drasticMeasureTaken = await Pausable.drasticMeasureTaken();
const drasticMeasureTaken = await this.Pausable.drasticMeasureTaken();
assert.isFalse(drasticMeasureTaken);
});
});

View File

@ -5,16 +5,18 @@ var StandardTokenMock = artifacts.require('StandardTokenMock');
contract('TokenDestructible', function (accounts) {
let destructible;
let owner;
beforeEach(async function () {
destructible = await TokenDestructible.new({
from: accounts[0],
value: web3.toWei('10', 'ether'),
});
owner = await destructible.owner();
});
it('should send balance to owner after destruction', async function () {
let owner = await destructible.owner();
let initBalance = await ethGetBalance(owner);
await destructible.destroy([], { from: owner });
let newBalance = await ethGetBalance(owner);
@ -22,7 +24,6 @@ contract('TokenDestructible', function (accounts) {
});
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);