From 4544df47da94c4735f1787f1d4d0926d1c6f665e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Venturo?= Date: Thu, 2 Aug 2018 16:55:31 -0300 Subject: [PATCH] =?UTF-8?q?All=20tests=20now=20use=20account=20names,=20an?= =?UTF-8?q?d=20dont=20use=20accounts[0]=20(except=20ERC=E2=80=A6=20(#1137)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * All tests now use account names, and dont use accounts[0] (except ERC721) * Added account names to some missing contracts. --- test/Heritable.test.js | 35 ++++---------- test/LimitBalance.test.js | 2 +- test/ReentrancyGuard.test.js | 2 +- test/SimpleSavingsWallet.test.js | 17 ++++--- test/examples/SampleCrowdsale.test.js | 7 +-- test/examples/SimpleToken.test.js | 3 +- .../SupportsInterfaceWithLookup.test.js | 2 +- test/library/ECRecovery.test.js | 12 ++--- test/library/Math.test.js | 2 +- test/library/MerkleProof.test.js | 2 +- test/lifecycle/Destructible.test.js | 20 ++++---- test/lifecycle/Pausable.test.js | 2 +- test/lifecycle/TokenDestructible.test.js | 7 +-- test/ownership/CanReclaimToken.test.js | 16 +++---- test/ownership/Claimable.test.js | 25 ++-------- test/ownership/Contactable.test.js | 2 +- test/ownership/DelayedClaimable.test.js | 36 +++++++-------- test/ownership/HasNoContracts.test.js | 17 +++---- test/ownership/HasNoEther.test.js | 46 +++++++++---------- test/ownership/HasNoTokens.test.js | 16 +++---- test/ownership/Ownable.behaviour.js | 31 ++++--------- test/ownership/Ownable.test.js | 6 +-- test/ownership/Superuser.test.js | 11 +---- test/ownership/Whitelist.test.js | 11 +---- test/ownership/rbac/RBAC.test.js | 27 ++++------- test/payment/ConditionalEscrow.test.js | 9 ++-- test/payment/Escrow.test.js | 6 +-- test/payment/PullPayment.test.js | 41 ++++++++--------- test/payment/RefundEscrow.test.js | 4 +- test/payment/SplitPayment.test.js | 2 +- test/token/ERC20/BurnableToken.behaviour.js | 10 ++-- test/token/ERC20/BurnableToken.test.js | 6 +-- test/token/ERC20/CappedToken.behaviour.js | 12 ++--- test/token/ERC20/CappedToken.test.js | 11 ++--- test/token/ERC20/DetailedERC20.test.js | 2 +- test/token/ERC20/MintableToken.behaviour.js | 6 +-- test/token/ERC20/MintableToken.test.js | 6 +-- test/token/ERC20/RBACCappedToken.test.js | 12 ++--- .../ERC20/RBACMintableToken.behaviour.js | 18 ++++---- test/token/ERC20/RBACMintableToken.test.js | 6 +-- .../token/ERC20/StandardBurnableToken.test.js | 4 +- 41 files changed, 211 insertions(+), 301 deletions(-) diff --git a/test/Heritable.test.js b/test/Heritable.test.js index 8a703bbd6ec..6ad52a849e8 100644 --- a/test/Heritable.test.js +++ b/test/Heritable.test.js @@ -6,13 +6,11 @@ const NULL_ADDRESS = '0x0000000000000000000000000000000000000000'; const Heritable = artifacts.require('Heritable'); -contract('Heritable', function (accounts) { +contract('Heritable', function ([_, owner, heir, anyone]) { let heritable; - let owner; beforeEach(async function () { - heritable = await Heritable.new(4141); - owner = await heritable.owner(); + heritable = await Heritable.new(4141, { from: owner }); }); it('should start off with an owner, but without heir', async function () { @@ -31,12 +29,8 @@ contract('Heritable', function (accounts) { }); it('only owner should set heir', async function () { - const newHeir = accounts[1]; - const someRandomAddress = accounts[2]; - assert.isTrue(owner !== someRandomAddress); - - await heritable.setHeir(newHeir, { from: owner }); - await expectThrow(heritable.setHeir(newHeir, { from: someRandomAddress })); + await heritable.setHeir(heir, { from: owner }); + await expectThrow(heritable.setHeir(heir, { from: anyone })); }); it('owner can\'t be heir', async function () { @@ -44,18 +38,14 @@ contract('Heritable', function (accounts) { }); it('owner can remove heir', async function () { - const newHeir = accounts[1]; - await heritable.setHeir(newHeir, { from: owner }); - let heir = await heritable.heir(); - - assert.notStrictEqual(heir, NULL_ADDRESS); - await heritable.removeHeir(); - heir = await heritable.heir(); - assert.isTrue(heir === NULL_ADDRESS); + await heritable.setHeir(heir, { from: owner }); + assert.equal(await heritable.heir(), heir); + + await heritable.removeHeir({ from: owner }); + assert.equal(await heritable.heir(), NULL_ADDRESS); }); it('heir can claim ownership only if owner is dead and timeout was reached', async function () { - const heir = accounts[1]; await heritable.setHeir(heir, { from: owner }); await expectThrow(heritable.claimHeirOwnership({ from: heir })); @@ -69,20 +59,17 @@ contract('Heritable', function (accounts) { }); it('only heir can proclaim death', async function () { - const someRandomAddress = accounts[2]; await assertRevert(heritable.proclaimDeath({ from: owner })); - await assertRevert(heritable.proclaimDeath({ from: someRandomAddress })); + await assertRevert(heritable.proclaimDeath({ from: anyone })); }); it('heir can\'t proclaim death if owner is death', async function () { - const heir = accounts[1]; await heritable.setHeir(heir, { from: owner }); await heritable.proclaimDeath({ from: heir }); await assertRevert(heritable.proclaimDeath({ from: heir })); }); it('heir can\'t claim ownership if owner heartbeats', async function () { - const heir = accounts[1]; await heritable.setHeir(heir, { from: owner }); await heritable.proclaimDeath({ from: heir }); @@ -96,8 +83,6 @@ contract('Heritable', function (accounts) { }); it('should log events appropriately', async function () { - const heir = accounts[1]; - const setHeirLogs = (await heritable.setHeir(heir, { from: owner })).logs; const setHeirEvent = setHeirLogs.find(e => e.event === 'HeirChanged'); diff --git a/test/LimitBalance.test.js b/test/LimitBalance.test.js index 7029d6047b7..221f766f843 100644 --- a/test/LimitBalance.test.js +++ b/test/LimitBalance.test.js @@ -3,7 +3,7 @@ const { ethGetBalance } = require('./helpers/web3'); const LimitBalanceMock = artifacts.require('LimitBalanceMock'); -contract('LimitBalance', function (accounts) { +contract('LimitBalance', function () { let limitBalance; beforeEach(async function () { diff --git a/test/ReentrancyGuard.test.js b/test/ReentrancyGuard.test.js index 8a6e4ccf923..564edbd1b1c 100644 --- a/test/ReentrancyGuard.test.js +++ b/test/ReentrancyGuard.test.js @@ -2,7 +2,7 @@ const { expectThrow } = require('./helpers/expectThrow'); const ReentrancyMock = artifacts.require('ReentrancyMock'); const ReentrancyAttack = artifacts.require('ReentrancyAttack'); -contract('ReentrancyGuard', function (accounts) { +contract('ReentrancyGuard', function () { let reentrancyMock; beforeEach(async function () { diff --git a/test/SimpleSavingsWallet.test.js b/test/SimpleSavingsWallet.test.js index 4409e286194..5ee9fa9e436 100644 --- a/test/SimpleSavingsWallet.test.js +++ b/test/SimpleSavingsWallet.test.js @@ -3,15 +3,13 @@ const { ethGetBalance, ethSendTransaction } = require('./helpers/web3'); const SimpleSavingsWallet = artifacts.require('SimpleSavingsWallet'); -contract('SimpleSavingsWallet', function (accounts) { +contract('SimpleSavingsWallet', function ([_, owner, anyone]) { let savingsWallet; - let owner; const paymentAmount = 4242; beforeEach(async function () { - savingsWallet = await SimpleSavingsWallet.new(4141); - owner = await savingsWallet.owner(); + savingsWallet = await SimpleSavingsWallet.new(4141, { from: owner }); }); it('should receive funds', async function () { @@ -22,14 +20,15 @@ contract('SimpleSavingsWallet', function (accounts) { it('owner can send funds', async function () { // Receive payment so we have some money to spend. - await ethSendTransaction({ from: accounts[9], to: savingsWallet.address, value: 1000000 }); + await ethSendTransaction({ from: anyone, to: savingsWallet.address, value: 1000000 }); + await expectThrow(savingsWallet.sendTo(0, paymentAmount, { from: owner })); await expectThrow(savingsWallet.sendTo(savingsWallet.address, paymentAmount, { from: owner })); - await expectThrow(savingsWallet.sendTo(accounts[1], 0, { from: owner })); + await expectThrow(savingsWallet.sendTo(anyone, 0, { from: owner })); - const balance = await ethGetBalance(accounts[1]); - await savingsWallet.sendTo(accounts[1], paymentAmount, { from: owner }); - const updatedBalance = await ethGetBalance(accounts[1]); + const balance = await ethGetBalance(anyone); + await savingsWallet.sendTo(anyone, paymentAmount, { from: owner }); + const updatedBalance = await ethGetBalance(anyone); assert.isTrue(balance.plus(paymentAmount).equals(updatedBalance)); }); }); diff --git a/test/examples/SampleCrowdsale.test.js b/test/examples/SampleCrowdsale.test.js index bc325846590..b55416321b6 100644 --- a/test/examples/SampleCrowdsale.test.js +++ b/test/examples/SampleCrowdsale.test.js @@ -16,7 +16,7 @@ require('chai') const SampleCrowdsale = artifacts.require('SampleCrowdsale'); const SampleCrowdsaleToken = artifacts.require('SampleCrowdsaleToken'); -contract('SampleCrowdsale', function ([owner, wallet, investor]) { +contract('SampleCrowdsale', function ([_, owner, wallet, investor]) { const RATE = new BigNumber(10); const GOAL = ether(10); const CAP = ether(20); @@ -33,9 +33,10 @@ contract('SampleCrowdsale', function ([owner, wallet, investor]) { this.token = await SampleCrowdsaleToken.new({ from: owner }); this.crowdsale = await SampleCrowdsale.new( - this.openingTime, this.closingTime, RATE, wallet, CAP, this.token.address, GOAL + this.openingTime, this.closingTime, RATE, wallet, CAP, this.token.address, GOAL, + { from: owner } ); - await this.token.transferOwnership(this.crowdsale.address); + await this.token.transferOwnership(this.crowdsale.address, { from: owner }); }); it('should create crowdsale with correct parameters', async function () { diff --git a/test/examples/SimpleToken.test.js b/test/examples/SimpleToken.test.js index 193ca430353..ab51c6eeb4e 100644 --- a/test/examples/SimpleToken.test.js +++ b/test/examples/SimpleToken.test.js @@ -1,9 +1,8 @@ const { decodeLogs } = require('../helpers/decodeLogs'); const SimpleToken = artifacts.require('SimpleToken'); -contract('SimpleToken', accounts => { +contract('SimpleToken', function ([_, creator]) { let token; - const creator = accounts[0]; beforeEach(async function () { token = await SimpleToken.new({ from: creator }); diff --git a/test/introspection/SupportsInterfaceWithLookup.test.js b/test/introspection/SupportsInterfaceWithLookup.test.js index 746b7caa326..e8bccdf4345 100644 --- a/test/introspection/SupportsInterfaceWithLookup.test.js +++ b/test/introspection/SupportsInterfaceWithLookup.test.js @@ -6,7 +6,7 @@ const SupportsInterfaceWithLookup = artifacts.require('SupportsInterfaceWithLook require('chai') .should(); -contract('SupportsInterfaceWithLookup', function (accounts) { +contract('SupportsInterfaceWithLookup', function () { beforeEach(async function () { this.mock = await SupportsInterfaceWithLookup.new(); }); diff --git a/test/library/ECRecovery.test.js b/test/library/ECRecovery.test.js index 75551eef6ba..3299e86a8fe 100644 --- a/test/library/ECRecovery.test.js +++ b/test/library/ECRecovery.test.js @@ -6,7 +6,7 @@ const ECRecoveryMock = artifacts.require('ECRecoveryMock'); require('chai') .should(); -contract('ECRecovery', function (accounts) { +contract('ECRecovery', function ([_, anyone]) { let ecrecovery; const TEST_MESSAGE = 'OpenZeppelin'; @@ -36,28 +36,28 @@ contract('ECRecovery', function (accounts) { it('recover using web3.eth.sign()', async function () { // Create the signature using account[0] - const signature = signMessage(accounts[0], web3.sha3(TEST_MESSAGE)); + const signature = signMessage(anyone, web3.sha3(TEST_MESSAGE)); // Recover the signer address from the generated message and signature. const addrRecovered = await ecrecovery.recover( hashMessage(TEST_MESSAGE), signature ); - addrRecovered.should.eq(accounts[0]); + addrRecovered.should.eq(anyone); }); it('recover using web3.eth.sign() should return wrong signer', async function () { // Create the signature using account[0] - const signature = signMessage(accounts[0], web3.sha3(TEST_MESSAGE)); + const signature = signMessage(anyone, web3.sha3(TEST_MESSAGE)); // Recover the signer address from the generated message and wrong signature. const addrRecovered = await ecrecovery.recover(hashMessage('Nope'), signature); - assert.notEqual(accounts[0], addrRecovered); + assert.notEqual(anyone, addrRecovered); }); it('recover should revert when a small hash is sent', async function () { // Create the signature using account[0] - const signature = signMessage(accounts[0], TEST_MESSAGE); + const signature = signMessage(anyone, TEST_MESSAGE); try { await expectThrow( ecrecovery.recover(hashMessage(TEST_MESSAGE).substring(2), signature) diff --git a/test/library/Math.test.js b/test/library/Math.test.js index f0087876452..d079a848fd0 100644 --- a/test/library/Math.test.js +++ b/test/library/Math.test.js @@ -1,6 +1,6 @@ const MathMock = artifacts.require('MathMock'); -contract('Math', function (accounts) { +contract('Math', function () { let math; beforeEach(async function () { diff --git a/test/library/MerkleProof.test.js b/test/library/MerkleProof.test.js index 7a9e56c050c..fb5a85e1071 100644 --- a/test/library/MerkleProof.test.js +++ b/test/library/MerkleProof.test.js @@ -3,7 +3,7 @@ const { sha3, bufferToHex } = require('ethereumjs-util'); const MerkleProofWrapper = artifacts.require('MerkleProofWrapper'); -contract('MerkleProof', function (accounts) { +contract('MerkleProof', function () { let merkleProof; beforeEach(async function () { diff --git a/test/lifecycle/Destructible.test.js b/test/lifecycle/Destructible.test.js index 74d5910ac8a..64820fde6c3 100644 --- a/test/lifecycle/Destructible.test.js +++ b/test/lifecycle/Destructible.test.js @@ -1,29 +1,27 @@ const DestructibleMock = artifacts.require('DestructibleMock'); const { ethGetBalance } = require('../helpers/web3'); -contract('Destructible', function (accounts) { +contract('Destructible', function ([_, owner, recipient]) { beforeEach(async function () { - this.destructible = await DestructibleMock.new({ from: accounts[0] }); + this.destructible = await DestructibleMock.new({ from: owner }); await web3.eth.sendTransaction({ - from: accounts[0], + from: owner, to: this.destructible.address, value: web3.toWei('10', 'ether'), }); - - this.owner = await this.destructible.owner(); }); it('should send balance to owner after destruction', async function () { - const initBalance = await ethGetBalance(this.owner); - await this.destructible.destroy({ from: this.owner }); - const newBalance = await ethGetBalance(this.owner); + const initBalance = await ethGetBalance(owner); + await this.destructible.destroy({ from: owner }); + const newBalance = await ethGetBalance(owner); assert.isTrue(newBalance > initBalance); }); it('should send balance to recepient after destruction', async function () { - const initBalance = await ethGetBalance(accounts[1]); - await this.destructible.destroyAndSend(accounts[1], { from: this.owner }); - const newBalance = await ethGetBalance(accounts[1]); + const initBalance = await ethGetBalance(recipient); + await this.destructible.destroyAndSend(recipient, { from: owner }); + const newBalance = await ethGetBalance(recipient); assert.isTrue(newBalance.greaterThan(initBalance)); }); }); diff --git a/test/lifecycle/Pausable.test.js b/test/lifecycle/Pausable.test.js index 1c33e2d01b4..683c5c50955 100644 --- a/test/lifecycle/Pausable.test.js +++ b/test/lifecycle/Pausable.test.js @@ -1,7 +1,7 @@ const { assertRevert } = require('../helpers/assertRevert'); const PausableMock = artifacts.require('PausableMock'); -contract('Pausable', function (accounts) { +contract('Pausable', function () { beforeEach(async function () { this.Pausable = await PausableMock.new(); }); diff --git a/test/lifecycle/TokenDestructible.test.js b/test/lifecycle/TokenDestructible.test.js index f9ec04ded77..393f12c3320 100644 --- a/test/lifecycle/TokenDestructible.test.js +++ b/test/lifecycle/TokenDestructible.test.js @@ -3,17 +3,14 @@ const { ethGetBalance } = require('../helpers/web3'); const TokenDestructible = artifacts.require('TokenDestructible'); const StandardTokenMock = artifacts.require('StandardTokenMock'); -contract('TokenDestructible', function (accounts) { +contract('TokenDestructible', function ([_, owner]) { let tokenDestructible; - let owner; beforeEach(async function () { tokenDestructible = await TokenDestructible.new({ - from: accounts[0], + from: owner, value: web3.toWei('10', 'ether'), }); - - owner = await tokenDestructible.owner(); }); it('should send balance to owner after destruction', async function () { diff --git a/test/ownership/CanReclaimToken.test.js b/test/ownership/CanReclaimToken.test.js index a50c05f9f82..3fe166bbcde 100644 --- a/test/ownership/CanReclaimToken.test.js +++ b/test/ownership/CanReclaimToken.test.js @@ -3,24 +3,24 @@ const { expectThrow } = require('../helpers/expectThrow'); const CanReclaimToken = artifacts.require('CanReclaimToken'); const BasicTokenMock = artifacts.require('BasicTokenMock'); -contract('CanReclaimToken', function (accounts) { +contract('CanReclaimToken', function ([_, owner, anyone]) { let token = null; let canReclaimToken = null; beforeEach(async function () { // Create contract and token - token = await BasicTokenMock.new(accounts[0], 100); - canReclaimToken = await CanReclaimToken.new(); + token = await BasicTokenMock.new(owner, 100, { from: owner }); + canReclaimToken = await CanReclaimToken.new({ from: owner }); // Force token into contract - await token.transfer(canReclaimToken.address, 10); + await token.transfer(canReclaimToken.address, 10, { from: owner }); 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 ownerStartBalance = await token.balanceOf(owner); + await canReclaimToken.reclaimToken(token.address, { from: owner }); + const ownerFinalBalance = await token.balanceOf(owner); const finalBalance = await token.balanceOf(canReclaimToken.address); assert.equal(finalBalance, 0); assert.equal(ownerFinalBalance - ownerStartBalance, 10); @@ -28,7 +28,7 @@ contract('CanReclaimToken', function (accounts) { it('should allow only owner to reclaim tokens', async function () { await expectThrow( - canReclaimToken.reclaimToken(token.address, { from: accounts[1] }), + canReclaimToken.reclaimToken(token.address, { from: anyone }) ); }); }); diff --git a/test/ownership/Claimable.test.js b/test/ownership/Claimable.test.js index b9e3d6a7d9f..1ff8522bd93 100644 --- a/test/ownership/Claimable.test.js +++ b/test/ownership/Claimable.test.js @@ -2,51 +2,36 @@ const { assertRevert } = require('../helpers/assertRevert'); const Claimable = artifacts.require('Claimable'); -contract('Claimable', function (accounts) { +contract('Claimable', function ([_, owner, newOwner, anyone]) { let claimable; beforeEach(async function () { claimable = await Claimable.new(); }); - it('should have an owner', async function () { - const owner = await claimable.owner(); - assert.isTrue(owner !== 0); - }); - it('changes pendingOwner after transfer', async function () { - const newOwner = accounts[1]; await claimable.transferOwnership(newOwner); const pendingOwner = await claimable.pendingOwner(); assert.isTrue(pendingOwner === newOwner); }); - it('should prevent to claimOwnership from no pendingOwner', async function () { - await assertRevert(claimable.claimOwnership({ from: accounts[2] })); + it('should prevent to claimOwnership from anyone', async function () { + await assertRevert(claimable.claimOwnership({ from: anyone })); }); it('should prevent non-owners from transfering', async function () { - const other = accounts[2]; - const owner = await claimable.owner.call(); - - assert.isTrue(owner !== other); - await assertRevert(claimable.transferOwnership(other, { from: other })); + await assertRevert(claimable.transferOwnership(anyone, { from: anyone })); }); describe('after initiating a transfer', function () { - let newOwner; - beforeEach(async function () { - newOwner = accounts[1]; await claimable.transferOwnership(newOwner); }); it('changes allow pending owner to claim ownership', async function () { await claimable.claimOwnership({ from: newOwner }); - const owner = await claimable.owner(); - - assert.isTrue(owner === newOwner); + assert.isTrue((await claimable.owner()) === newOwner); }); }); }); diff --git a/test/ownership/Contactable.test.js b/test/ownership/Contactable.test.js index 0d1de0fc7c9..40ec213c892 100644 --- a/test/ownership/Contactable.test.js +++ b/test/ownership/Contactable.test.js @@ -1,6 +1,6 @@ const Contactable = artifacts.require('Contactable'); -contract('Contactable', function (accounts) { +contract('Contactable', function () { let contactable; beforeEach(async function () { diff --git a/test/ownership/DelayedClaimable.test.js b/test/ownership/DelayedClaimable.test.js index 64b5293be5f..8f0b307e774 100644 --- a/test/ownership/DelayedClaimable.test.js +++ b/test/ownership/DelayedClaimable.test.js @@ -2,14 +2,14 @@ const { assertRevert } = require('../helpers/assertRevert'); const DelayedClaimable = artifacts.require('DelayedClaimable'); -contract('DelayedClaimable', function (accounts) { +contract('DelayedClaimable', function ([_, owner, newOwner]) { beforeEach(async function () { - this.delayedClaimable = await DelayedClaimable.new(); + this.delayedClaimable = await DelayedClaimable.new({ from: owner }); }); it('can set claim blocks', async function () { - await this.delayedClaimable.transferOwnership(accounts[2]); - await this.delayedClaimable.setLimits(0, 1000); + await this.delayedClaimable.transferOwnership(newOwner, { from: owner }); + await this.delayedClaimable.setLimits(0, 1000, { from: owner }); const end = await this.delayedClaimable.end(); assert.equal(end, 1000); const start = await this.delayedClaimable.start(); @@ -17,35 +17,31 @@ contract('DelayedClaimable', function (accounts) { }); it('changes pendingOwner after transfer successful', async function () { - await this.delayedClaimable.transferOwnership(accounts[2]); - await this.delayedClaimable.setLimits(0, 1000); + await this.delayedClaimable.transferOwnership(newOwner, { from: owner }); + await this.delayedClaimable.setLimits(0, 1000, { from: owner }); const end = await this.delayedClaimable.end(); assert.equal(end, 1000); const start = await this.delayedClaimable.start(); assert.equal(start, 0); - const pendingOwner = await this.delayedClaimable.pendingOwner(); - assert.equal(pendingOwner, accounts[2]); - await this.delayedClaimable.claimOwnership({ from: accounts[2] }); - const owner = await this.delayedClaimable.owner(); - assert.equal(owner, accounts[2]); + assert.equal((await this.delayedClaimable.pendingOwner()), newOwner); + await this.delayedClaimable.claimOwnership({ from: newOwner }); + assert.equal((await this.delayedClaimable.owner()), newOwner); }); it('changes pendingOwner after transfer fails', async function () { - await this.delayedClaimable.transferOwnership(accounts[1]); - await this.delayedClaimable.setLimits(100, 110); + await this.delayedClaimable.transferOwnership(newOwner, { from: owner }); + await this.delayedClaimable.setLimits(100, 110, { from: owner }); const end = await this.delayedClaimable.end(); assert.equal(end, 110); const start = await this.delayedClaimable.start(); assert.equal(start, 100); - const pendingOwner = await this.delayedClaimable.pendingOwner(); - assert.equal(pendingOwner, accounts[1]); - await assertRevert(this.delayedClaimable.claimOwnership({ from: accounts[1] })); - const owner = await this.delayedClaimable.owner(); - assert.isTrue(owner !== accounts[1]); + assert.equal((await this.delayedClaimable.pendingOwner()), newOwner); + await assertRevert(this.delayedClaimable.claimOwnership({ from: newOwner })); + assert.isTrue((await this.delayedClaimable.owner()) !== newOwner); }); it('set end and start invalid values fail', async function () { - await this.delayedClaimable.transferOwnership(accounts[1]); - await assertRevert(this.delayedClaimable.setLimits(1001, 1000)); + await this.delayedClaimable.transferOwnership(newOwner, { from: owner }); + await assertRevert(this.delayedClaimable.setLimits(1001, 1000, { from: owner })); }); }); diff --git a/test/ownership/HasNoContracts.test.js b/test/ownership/HasNoContracts.test.js index cc56a46e7a3..7f79582227e 100644 --- a/test/ownership/HasNoContracts.test.js +++ b/test/ownership/HasNoContracts.test.js @@ -3,30 +3,27 @@ const { expectThrow } = require('../helpers/expectThrow'); const Ownable = artifacts.require('Ownable'); const HasNoContracts = artifacts.require('HasNoContracts'); -contract('HasNoContracts', function (accounts) { +contract('HasNoContracts', function ([_, owner, anyone]) { let hasNoContracts = null; let ownable = null; beforeEach(async () => { // Create contract and token - hasNoContracts = await HasNoContracts.new(); - ownable = await Ownable.new(); + hasNoContracts = await HasNoContracts.new({ from: owner }); + ownable = await Ownable.new({ from: owner }); // Force ownership into contract - await ownable.transferOwnership(hasNoContracts.address); - const owner = await ownable.owner(); - assert.equal(owner, hasNoContracts.address); + await ownable.transferOwnership(hasNoContracts.address, { from: owner }); }); it('should allow owner to reclaim contracts', async function () { - await hasNoContracts.reclaimContract(ownable.address); - const owner = await ownable.owner(); - assert.equal(owner, accounts[0]); + await hasNoContracts.reclaimContract(ownable.address, { from: owner }); + assert.equal((await ownable.owner()), owner); }); it('should allow only owner to reclaim contracts', async function () { await expectThrow( - hasNoContracts.reclaimContract(ownable.address, { from: accounts[1] }), + hasNoContracts.reclaimContract(ownable.address, { from: anyone }) ); }); }); diff --git a/test/ownership/HasNoEther.test.js b/test/ownership/HasNoEther.test.js index 7e52a21eb8f..70fa35f1bf4 100644 --- a/test/ownership/HasNoEther.test.js +++ b/test/ownership/HasNoEther.test.js @@ -4,11 +4,17 @@ const { ethSendTransaction, ethGetBalance } = require('../helpers/web3'); const HasNoEtherTest = artifacts.require('HasNoEtherTest'); const ForceEther = artifacts.require('ForceEther'); -contract('HasNoEther', function (accounts) { +const BigNumber = web3.BigNumber; + +require('chai') + .use(require('chai-bignumber')(BigNumber)) + .should(); + +contract('HasNoEther', function ([_, owner, anyone]) { const amount = web3.toWei('1', 'ether'); - it('should be constructible', async function () { - await HasNoEtherTest.new(); + beforeEach(async function () { + this.hasNoEther = await HasNoEtherTest.new({ from: owner }); }); it('should not accept ether in constructor', async function () { @@ -16,49 +22,43 @@ contract('HasNoEther', function (accounts) { }); it('should not accept ether', async function () { - const hasNoEther = await HasNoEtherTest.new(); - await expectThrow( ethSendTransaction({ - from: accounts[1], - to: hasNoEther.address, + from: owner, + to: this.hasNoEther.address, value: amount, }), ); }); it('should allow owner to reclaim ether', async function () { - // Create contract - const hasNoEther = await HasNoEtherTest.new(); - const startBalance = await ethGetBalance(hasNoEther.address); + const startBalance = await ethGetBalance(this.hasNoEther.address); assert.equal(startBalance, 0); // Force ether into it const forceEther = await ForceEther.new({ value: amount }); - await forceEther.destroyAndSend(hasNoEther.address); - const forcedBalance = await ethGetBalance(hasNoEther.address); + await forceEther.destroyAndSend(this.hasNoEther.address); + const forcedBalance = await ethGetBalance(this.hasNoEther.address); assert.equal(forcedBalance, amount); // Reclaim - const ownerStartBalance = await ethGetBalance(accounts[0]); - await hasNoEther.reclaimEther(); - const ownerFinalBalance = await ethGetBalance(accounts[0]); - const finalBalance = await ethGetBalance(hasNoEther.address); + const ownerStartBalance = await ethGetBalance(owner); + await this.hasNoEther.reclaimEther({ from: owner }); + const ownerFinalBalance = await ethGetBalance(owner); + const finalBalance = await ethGetBalance(this.hasNoEther.address); assert.equal(finalBalance, 0); - assert.isTrue(ownerFinalBalance.greaterThan(ownerStartBalance)); + + ownerFinalBalance.should.be.bignumber.gt(ownerStartBalance); }); it('should allow only owner to reclaim ether', async function () { - // Create contract - const hasNoEther = await HasNoEtherTest.new({ from: accounts[0] }); - // Force ether into it const forceEther = await ForceEther.new({ value: amount }); - await forceEther.destroyAndSend(hasNoEther.address); - const forcedBalance = await ethGetBalance(hasNoEther.address); + await forceEther.destroyAndSend(this.hasNoEther.address); + const forcedBalance = await ethGetBalance(this.hasNoEther.address); assert.equal(forcedBalance, amount); // Reclaim - await expectThrow(hasNoEther.reclaimEther({ from: accounts[1] })); + await expectThrow(this.hasNoEther.reclaimEther({ from: anyone })); }); }); diff --git a/test/ownership/HasNoTokens.test.js b/test/ownership/HasNoTokens.test.js index 5dd499fe242..6e8f35fdb19 100644 --- a/test/ownership/HasNoTokens.test.js +++ b/test/ownership/HasNoTokens.test.js @@ -3,17 +3,17 @@ const { expectThrow } = require('../helpers/expectThrow'); const HasNoTokens = artifacts.require('HasNoTokens'); const ERC223TokenMock = artifacts.require('ERC223TokenMock'); -contract('HasNoTokens', function (accounts) { +contract('HasNoTokens', function ([_, owner, initialAccount, anyone]) { let hasNoTokens = null; let token = null; beforeEach(async () => { // Create contract and token - hasNoTokens = await HasNoTokens.new(); - token = await ERC223TokenMock.new(accounts[0], 100); + hasNoTokens = await HasNoTokens.new({ from: owner }); + token = await ERC223TokenMock.new(initialAccount, 100); // Force token into contract - await token.transfer(hasNoTokens.address, 10); + await token.transfer(hasNoTokens.address, 10, { from: initialAccount }); const startBalance = await token.balanceOf(hasNoTokens.address); assert.equal(startBalance, 10); }); @@ -23,9 +23,9 @@ contract('HasNoTokens', function (accounts) { }); it('should allow owner to reclaim tokens', async function () { - const ownerStartBalance = await token.balanceOf(accounts[0]); - await hasNoTokens.reclaimToken(token.address); - const ownerFinalBalance = await token.balanceOf(accounts[0]); + const ownerStartBalance = await token.balanceOf(owner); + await hasNoTokens.reclaimToken(token.address, { from: owner }); + const ownerFinalBalance = await token.balanceOf(owner); const finalBalance = await token.balanceOf(hasNoTokens.address); assert.equal(finalBalance, 0); assert.equal(ownerFinalBalance - ownerStartBalance, 10); @@ -33,7 +33,7 @@ contract('HasNoTokens', function (accounts) { it('should allow only owner to reclaim tokens', async function () { await expectThrow( - hasNoTokens.reclaimToken(token.address, { from: accounts[1] }), + hasNoTokens.reclaimToken(token.address, { from: anyone }) ); }); }); diff --git a/test/ownership/Ownable.behaviour.js b/test/ownership/Ownable.behaviour.js index c45cde7e420..aa95e04e2ce 100644 --- a/test/ownership/Ownable.behaviour.js +++ b/test/ownership/Ownable.behaviour.js @@ -6,45 +6,32 @@ const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'; require('chai') .should(); -function shouldBehaveLikeOwnable (accounts) { +function shouldBehaveLikeOwnable (owner, [anyone]) { describe('as an ownable', function () { it('should have an owner', async function () { - const owner = await this.ownable.owner(); - owner.should.not.eq(ZERO_ADDRESS); + (await this.ownable.owner()).should.eq(owner); }); it('changes owner after transfer', async function () { - const other = accounts[1]; - await this.ownable.transferOwnership(other); - const owner = await this.ownable.owner(); - - owner.should.eq(other); + await this.ownable.transferOwnership(anyone, { from: owner }); + (await this.ownable.owner()).should.eq(anyone); }); it('should prevent non-owners from transfering', async function () { - const other = accounts[2]; - const owner = await this.ownable.owner.call(); - owner.should.not.eq(other); - await expectThrow(this.ownable.transferOwnership(other, { from: other }), EVMRevert); + await expectThrow(this.ownable.transferOwnership(anyone, { from: anyone }), EVMRevert); }); it('should guard ownership against stuck state', async function () { - const originalOwner = await this.ownable.owner(); - await expectThrow(this.ownable.transferOwnership(null, { from: originalOwner }), EVMRevert); + await expectThrow(this.ownable.transferOwnership(null, { from: owner }), EVMRevert); }); it('loses owner after renouncement', async function () { - await this.ownable.renounceOwnership(); - const owner = await this.ownable.owner(); - - owner.should.eq(ZERO_ADDRESS); + await this.ownable.renounceOwnership({ from: owner }); + (await this.ownable.owner()).should.eq(ZERO_ADDRESS); }); it('should prevent non-owners from renouncement', async function () { - const other = accounts[2]; - const owner = await this.ownable.owner.call(); - owner.should.not.eq(other); - await expectThrow(this.ownable.renounceOwnership({ from: other }), EVMRevert); + await expectThrow(this.ownable.renounceOwnership({ from: anyone }), EVMRevert); }); }); } diff --git a/test/ownership/Ownable.test.js b/test/ownership/Ownable.test.js index fea51b77a9b..d93446682da 100644 --- a/test/ownership/Ownable.test.js +++ b/test/ownership/Ownable.test.js @@ -2,10 +2,10 @@ const { shouldBehaveLikeOwnable } = require('./Ownable.behaviour'); const Ownable = artifacts.require('Ownable'); -contract('Ownable', function (accounts) { +contract('Ownable', function ([_, owner, ...otherAccounts]) { beforeEach(async function () { - this.ownable = await Ownable.new(); + this.ownable = await Ownable.new({ from: owner }); }); - shouldBehaveLikeOwnable(accounts); + shouldBehaveLikeOwnable(owner, otherAccounts); }); diff --git a/test/ownership/Superuser.test.js b/test/ownership/Superuser.test.js index cf0674bd3af..e27b89cc854 100644 --- a/test/ownership/Superuser.test.js +++ b/test/ownership/Superuser.test.js @@ -6,16 +6,9 @@ const Superuser = artifacts.require('Superuser'); require('chai') .should(); -contract('Superuser', function (accounts) { - const [ - firstOwner, - newSuperuser, - newOwner, - anyone, - ] = accounts; - +contract('Superuser', function ([_, firstOwner, newSuperuser, newOwner, anyone]) { beforeEach(async function () { - this.superuser = await Superuser.new(); + this.superuser = await Superuser.new({ from: firstOwner }); }); context('in normal conditions', () => { diff --git a/test/ownership/Whitelist.test.js b/test/ownership/Whitelist.test.js index 812e560cf7f..85ddba21b13 100644 --- a/test/ownership/Whitelist.test.js +++ b/test/ownership/Whitelist.test.js @@ -6,18 +6,11 @@ const WhitelistMock = artifacts.require('WhitelistMock'); require('chai') .should(); -contract('Whitelist', function (accounts) { - const [ - owner, - whitelistedAddress1, - whitelistedAddress2, - anyone, - ] = accounts; - +contract('Whitelist', function ([_, owner, whitelistedAddress1, whitelistedAddress2, anyone]) { const whitelistedAddresses = [whitelistedAddress1, whitelistedAddress2]; beforeEach(async function () { - this.mock = await WhitelistMock.new(); + this.mock = await WhitelistMock.new({ from: owner }); this.role = await this.mock.ROLE_WHITELISTED(); }); diff --git a/test/ownership/rbac/RBAC.test.js b/test/ownership/rbac/RBAC.test.js index 68c3a075e96..284c57bb74b 100644 --- a/test/ownership/rbac/RBAC.test.js +++ b/test/ownership/rbac/RBAC.test.js @@ -8,18 +8,11 @@ require('chai') const ROLE_ADVISOR = 'advisor'; -contract('RBAC', function (accounts) { +contract('RBAC', function ([_, admin, anyone, advisor, otherAdvisor, futureAdvisor]) { let mock; - const [ - admin, - anyone, - futureAdvisor, - ...advisors - ] = accounts; - beforeEach(async () => { - mock = await RBACMock.new(advisors, { from: admin }); + mock = await RBACMock.new([advisor, otherAdvisor], { from: admin }); }); context('in normal conditions', () => { @@ -30,30 +23,28 @@ contract('RBAC', function (accounts) { await mock.onlyAdvisorsCanDoThis({ from: admin }); }); it('allows advisors to call #onlyAdvisorsCanDoThis', async () => { - await mock.onlyAdvisorsCanDoThis({ from: advisors[0] }); + await mock.onlyAdvisorsCanDoThis({ from: advisor }); }); it('allows admin to call #eitherAdminOrAdvisorCanDoThis', async () => { await mock.eitherAdminOrAdvisorCanDoThis({ from: admin }); }); it('allows advisors to call #eitherAdminOrAdvisorCanDoThis', async () => { - await mock.eitherAdminOrAdvisorCanDoThis({ from: advisors[0] }); + await mock.eitherAdminOrAdvisorCanDoThis({ from: advisor }); }); it('does not allow admins to call #nobodyCanDoThis', async () => { await expectThrow(mock.nobodyCanDoThis({ from: admin })); }); it('does not allow advisors to call #nobodyCanDoThis', async () => { - await expectThrow(mock.nobodyCanDoThis({ from: advisors[0] })); + await expectThrow(mock.nobodyCanDoThis({ from: advisor })); }); it('does not allow anyone to call #nobodyCanDoThis', async () => { await expectThrow(mock.nobodyCanDoThis({ from: anyone })); }); it('allows an admin to remove an advisor\'s role', async () => { - await mock.removeAdvisor(advisors[0], { from: admin }) - ; + await mock.removeAdvisor(advisor, { from: admin }); }); it('allows admins to #adminRemoveRole', async () => { - await mock.adminRemoveRole(advisors[3], ROLE_ADVISOR, { from: admin }) - ; + await mock.adminRemoveRole(advisor, ROLE_ADVISOR, { from: admin }); }); it('announces a RoleAdded event on addRole', async () => { @@ -73,10 +64,10 @@ contract('RBAC', function (accounts) { context('in adversarial conditions', () => { it('does not allow an advisor to remove another advisor', async () => { - await expectThrow(mock.removeAdvisor(advisors[1], { from: advisors[0] })); + await expectThrow(mock.removeAdvisor(otherAdvisor, { from: advisor })); }); it('does not allow "anyone" to remove an advisor', async () => { - await expectThrow(mock.removeAdvisor(advisors[0], { from: anyone })); + await expectThrow(mock.removeAdvisor(advisor, { from: anyone })); }); }); }); diff --git a/test/payment/ConditionalEscrow.test.js b/test/payment/ConditionalEscrow.test.js index ff4e0ba36c3..c1191c02a8e 100644 --- a/test/payment/ConditionalEscrow.test.js +++ b/test/payment/ConditionalEscrow.test.js @@ -10,24 +10,21 @@ require('chai') const ConditionalEscrowMock = artifacts.require('ConditionalEscrowMock'); -contract('ConditionalEscrow', function (accounts) { - const owner = accounts[0]; - +contract('ConditionalEscrow', function ([_, owner, payee, ...otherAccounts]) { beforeEach(async function () { this.escrow = await ConditionalEscrowMock.new({ from: owner }); }); context('when withdrawal is allowed', function () { beforeEach(async function () { - await Promise.all(accounts.map(payee => this.escrow.setAllowed(payee, true))); + await Promise.all(otherAccounts.map(payee => this.escrow.setAllowed(payee, true))); }); - shouldBehaveLikeEscrow(owner, accounts.slice(1)); + shouldBehaveLikeEscrow(owner, otherAccounts); }); context('when withdrawal is disallowed', function () { const amount = web3.toWei(23.0, 'ether'); - const payee = accounts[1]; beforeEach(async function () { await this.escrow.setAllowed(payee, false); diff --git a/test/payment/Escrow.test.js b/test/payment/Escrow.test.js index 7047cfd9cfa..73d3aac0ee0 100644 --- a/test/payment/Escrow.test.js +++ b/test/payment/Escrow.test.js @@ -2,12 +2,10 @@ const { shouldBehaveLikeEscrow } = require('./Escrow.behaviour'); const Escrow = artifacts.require('Escrow'); -contract('Escrow', function (accounts) { - const owner = accounts[0]; - +contract('Escrow', function ([_, owner, ...otherAccounts]) { beforeEach(async function () { this.escrow = await Escrow.new({ from: owner }); }); - shouldBehaveLikeEscrow(owner, accounts.slice(1)); + shouldBehaveLikeEscrow(owner, otherAccounts); }); diff --git a/test/payment/PullPayment.test.js b/test/payment/PullPayment.test.js index 9609fd4598f..3f130fe7840 100644 --- a/test/payment/PullPayment.test.js +++ b/test/payment/PullPayment.test.js @@ -8,7 +8,7 @@ require('chai') const PullPaymentMock = artifacts.require('PullPaymentMock'); -contract('PullPayment', function (accounts) { +contract('PullPayment', function ([_, payer, payee1, payee2]) { const amount = web3.toWei(17.0, 'ether'); beforeEach(async function () { @@ -21,44 +21,43 @@ contract('PullPayment', function (accounts) { it('can record an async payment correctly', async function () { const AMOUNT = 100; - await this.contract.callTransfer(accounts[0], AMOUNT); + await this.contract.callTransfer(payee1, AMOUNT, { from: payer }); - const paymentsToAccount0 = await this.contract.payments(accounts[0]); - paymentsToAccount0.should.be.bignumber.equal(AMOUNT); + const paymentsToPayee1 = await this.contract.payments(payee1); + paymentsToPayee1.should.be.bignumber.equal(AMOUNT); }); it('can add multiple balances on one account', async function () { - await this.contract.callTransfer(accounts[0], 200); - await this.contract.callTransfer(accounts[0], 300); - const paymentsToAccount0 = await this.contract.payments(accounts[0]); - paymentsToAccount0.should.be.bignumber.equal(500); + await this.contract.callTransfer(payee1, 200, { from: payer }); + await this.contract.callTransfer(payee1, 300, { from: payer }); + const paymentsToPayee1 = await this.contract.payments(payee1); + paymentsToPayee1.should.be.bignumber.equal(500); }); it('can add balances on multiple accounts', async function () { - await this.contract.callTransfer(accounts[0], 200); - await this.contract.callTransfer(accounts[1], 300); + await this.contract.callTransfer(payee1, 200, { from: payer }); + await this.contract.callTransfer(payee2, 300, { from: payer }); - const paymentsToAccount0 = await this.contract.payments(accounts[0]); - paymentsToAccount0.should.be.bignumber.equal(200); + const paymentsToPayee1 = await this.contract.payments(payee1); + paymentsToPayee1.should.be.bignumber.equal(200); - const paymentsToAccount1 = await this.contract.payments(accounts[1]); - paymentsToAccount1.should.be.bignumber.equal(300); + const paymentsToPayee2 = await this.contract.payments(payee2); + paymentsToPayee2.should.be.bignumber.equal(300); }); it('can withdraw payment', async function () { - const payee = accounts[1]; - const initialBalance = await ethGetBalance(payee); + const initialBalance = await ethGetBalance(payee1); - await this.contract.callTransfer(payee, amount); + await this.contract.callTransfer(payee1, amount, { from: payer }); - const payment1 = await this.contract.payments(payee); + const payment1 = await this.contract.payments(payee1); payment1.should.be.bignumber.equal(amount); - await this.contract.withdrawPayments({ from: payee }); - const payment2 = await this.contract.payments(payee); + await this.contract.withdrawPayments({ from: payee1 }); + const payment2 = await this.contract.payments(payee1); payment2.should.be.bignumber.equal(0); - const balance = await ethGetBalance(payee); + const balance = await ethGetBalance(payee1); Math.abs(balance - initialBalance - amount).should.be.lt(1e16); }); }); diff --git a/test/payment/RefundEscrow.test.js b/test/payment/RefundEscrow.test.js index 524a5e30625..278ecccd8ca 100644 --- a/test/payment/RefundEscrow.test.js +++ b/test/payment/RefundEscrow.test.js @@ -11,7 +11,7 @@ require('chai') const RefundEscrow = artifacts.require('RefundEscrow'); -contract('RefundEscrow', function ([owner, beneficiary, refundee1, refundee2]) { +contract('RefundEscrow', function ([_, owner, beneficiary, refundee1, refundee2]) { const amount = web3.toWei(54.0, 'ether'); const refundees = [refundee1, refundee2]; @@ -92,7 +92,7 @@ contract('RefundEscrow', function ([owner, beneficiary, refundee1, refundee2]) { it('refunds refundees', async function () { for (const refundee of [refundee1, refundee2]) { const refundeeInitialBalance = await ethGetBalance(refundee); - await this.escrow.withdraw(refundee); + await this.escrow.withdraw(refundee, { from: owner }); const refundeeFinalBalance = await ethGetBalance(refundee); refundeeFinalBalance.sub(refundeeInitialBalance).should.be.bignumber.equal(amount); diff --git a/test/payment/SplitPayment.test.js b/test/payment/SplitPayment.test.js index ec46ef4b5cd..50ded9e81cf 100644 --- a/test/payment/SplitPayment.test.js +++ b/test/payment/SplitPayment.test.js @@ -10,7 +10,7 @@ const { expectThrow } = require('../helpers/expectThrow'); const EVMThrow = require('../helpers/EVMThrow.js'); const SplitPayment = artifacts.require('SplitPayment'); -contract('SplitPayment', function ([owner, payee1, payee2, payee3, nonpayee1, payer1]) { +contract('SplitPayment', function ([_, owner, payee1, payee2, payee3, nonpayee1, payer1]) { const amount = web3.toWei(1.0, 'ether'); beforeEach(async function () { diff --git a/test/token/ERC20/BurnableToken.behaviour.js b/test/token/ERC20/BurnableToken.behaviour.js index 6b22e0f40a9..6a852aa42d7 100644 --- a/test/token/ERC20/BurnableToken.behaviour.js +++ b/test/token/ERC20/BurnableToken.behaviour.js @@ -8,19 +8,17 @@ require('chai') .use(require('chai-bignumber')(BigNumber)) .should(); -function shouldBehaveLikeBurnableToken ([owner], initialBalance) { +function shouldBehaveLikeBurnableToken (owner, initialBalance) { describe('as a basic burnable token', function () { - const from = owner; - describe('when the given amount is not greater than balance of the sender', function () { const amount = 100; beforeEach(async function () { - ({ logs: this.logs } = await this.token.burn(amount, { from })); + ({ logs: this.logs } = await this.token.burn(amount, { from: owner })); }); it('burns the requested amount', async function () { - const balance = await this.token.balanceOf(from); + const balance = await this.token.balanceOf(owner); balance.should.be.bignumber.equal(initialBalance - amount); }); @@ -42,7 +40,7 @@ function shouldBehaveLikeBurnableToken ([owner], initialBalance) { const amount = initialBalance + 1; it('reverts', async function () { - await assertRevert(this.token.burn(amount, { from })); + await assertRevert(this.token.burn(amount, { from: owner })); }); }); }); diff --git a/test/token/ERC20/BurnableToken.test.js b/test/token/ERC20/BurnableToken.test.js index 4e1f3fa0c0d..001212872a9 100644 --- a/test/token/ERC20/BurnableToken.test.js +++ b/test/token/ERC20/BurnableToken.test.js @@ -1,12 +1,12 @@ const { shouldBehaveLikeBurnableToken } = require('./BurnableToken.behaviour'); const BurnableTokenMock = artifacts.require('BurnableTokenMock'); -contract('BurnableToken', function ([owner]) { +contract('BurnableToken', function ([_, owner]) { const initialBalance = 1000; beforeEach(async function () { - this.token = await BurnableTokenMock.new(owner, initialBalance); + this.token = await BurnableTokenMock.new(owner, initialBalance, { from: owner }); }); - shouldBehaveLikeBurnableToken([owner], initialBalance); + shouldBehaveLikeBurnableToken(owner, initialBalance); }); diff --git a/test/token/ERC20/CappedToken.behaviour.js b/test/token/ERC20/CappedToken.behaviour.js index bc63f22926a..2521a0a3bdb 100644 --- a/test/token/ERC20/CappedToken.behaviour.js +++ b/test/token/ERC20/CappedToken.behaviour.js @@ -1,6 +1,6 @@ const { expectThrow } = require('../../helpers/expectThrow'); -function shouldBehaveLikeCappedToken ([owner, anotherAccount, minter, cap]) { +function shouldBehaveLikeCappedToken (minter, [anyone], cap) { describe('capped token', function () { const from = minter; @@ -11,18 +11,18 @@ function shouldBehaveLikeCappedToken ([owner, anotherAccount, minter, cap]) { }); it('should mint when amount is less than cap', async function () { - const result = await this.token.mint(owner, cap.sub(1), { from }); + const result = await this.token.mint(anyone, cap.sub(1), { from }); assert.equal(result.logs[0].event, 'Mint'); }); it('should fail to mint if the ammount exceeds the cap', async function () { - await this.token.mint(owner, cap.sub(1), { from }); - await expectThrow(this.token.mint(owner, 100, { from })); + await this.token.mint(anyone, cap.sub(1), { from }); + await expectThrow(this.token.mint(anyone, 100, { from })); }); it('should fail to mint after cap is reached', async function () { - await this.token.mint(owner, cap, { from }); - await expectThrow(this.token.mint(owner, 1, { from })); + await this.token.mint(anyone, cap, { from }); + await expectThrow(this.token.mint(anyone, 1, { from })); }); }); } diff --git a/test/token/ERC20/CappedToken.test.js b/test/token/ERC20/CappedToken.test.js index 39da808ef0e..dcc912d98a8 100644 --- a/test/token/ERC20/CappedToken.test.js +++ b/test/token/ERC20/CappedToken.test.js @@ -4,14 +4,13 @@ const { shouldBehaveLikeCappedToken } = require('./CappedToken.behaviour'); const CappedToken = artifacts.require('CappedToken'); -contract('Capped', function ([owner, anotherAccount]) { - const _cap = ether(1000); +contract('Capped', function ([_, owner, ...otherAccounts]) { + const cap = ether(1000); beforeEach(async function () { - this.token = await CappedToken.new(_cap, { from: owner }); + this.token = await CappedToken.new(cap, { from: owner }); }); - shouldBehaveLikeCappedToken([owner, anotherAccount, owner, _cap]); - - shouldBehaveLikeMintableToken([owner, anotherAccount, owner]); + shouldBehaveLikeCappedToken(owner, otherAccounts, cap); + shouldBehaveLikeMintableToken(owner, owner, otherAccounts); }); diff --git a/test/token/ERC20/DetailedERC20.test.js b/test/token/ERC20/DetailedERC20.test.js index 0b60a79f518..9460f04ff47 100644 --- a/test/token/ERC20/DetailedERC20.test.js +++ b/test/token/ERC20/DetailedERC20.test.js @@ -6,7 +6,7 @@ require('chai') const DetailedERC20Mock = artifacts.require('DetailedERC20Mock'); -contract('DetailedERC20', accounts => { +contract('DetailedERC20', function () { let detailedERC20 = null; const _name = 'My Detailed ERC20'; diff --git a/test/token/ERC20/MintableToken.behaviour.js b/test/token/ERC20/MintableToken.behaviour.js index 38a8b7dc3c1..f274d08fd47 100644 --- a/test/token/ERC20/MintableToken.behaviour.js +++ b/test/token/ERC20/MintableToken.behaviour.js @@ -6,7 +6,7 @@ require('chai') .use(require('chai-bignumber')(BigNumber)) .should(); -function shouldBehaveLikeMintableToken ([owner, anotherAccount, minter]) { +function shouldBehaveLikeMintableToken (owner, minter, [anyone]) { describe('as a basic mintable token', function () { describe('after token creation', function () { it('sender should be token owner', async function () { @@ -67,7 +67,7 @@ function shouldBehaveLikeMintableToken ([owner, anotherAccount, minter]) { }); describe('when the sender is not the token owner', function () { - const from = anotherAccount; + const from = anyone; describe('when the token minting was not finished', function () { it('reverts', async function () { @@ -124,7 +124,7 @@ function shouldBehaveLikeMintableToken ([owner, anotherAccount, minter]) { }); describe('when the sender has not the minting permission', function () { - const from = anotherAccount; + const from = anyone; describe('when the token minting is not finished', function () { it('reverts', async function () { diff --git a/test/token/ERC20/MintableToken.test.js b/test/token/ERC20/MintableToken.test.js index faf3c64d2bc..c5303b8cfe3 100644 --- a/test/token/ERC20/MintableToken.test.js +++ b/test/token/ERC20/MintableToken.test.js @@ -1,12 +1,10 @@ const { shouldBehaveLikeMintableToken } = require('./MintableToken.behaviour'); const MintableToken = artifacts.require('MintableToken'); -contract('MintableToken', function ([owner, anotherAccount]) { - const minter = owner; - +contract('MintableToken', function ([_, owner, ...otherAccounts]) { beforeEach(async function () { this.token = await MintableToken.new({ from: owner }); }); - shouldBehaveLikeMintableToken([owner, anotherAccount, minter]); + shouldBehaveLikeMintableToken(owner, owner, otherAccounts); }); diff --git a/test/token/ERC20/RBACCappedToken.test.js b/test/token/ERC20/RBACCappedToken.test.js index cb457c979bf..284100f3d97 100644 --- a/test/token/ERC20/RBACCappedToken.test.js +++ b/test/token/ERC20/RBACCappedToken.test.js @@ -5,15 +5,15 @@ const { shouldBehaveLikeCappedToken } = require('./CappedToken.behaviour'); const RBACCappedTokenMock = artifacts.require('RBACCappedTokenMock'); -contract('RBACCappedToken', function ([owner, anotherAccount, minter]) { - const _cap = ether(1000); +contract('RBACCappedToken', function ([_, owner, minter, ...otherAccounts]) { + const cap = ether(1000); beforeEach(async function () { - this.token = await RBACCappedTokenMock.new(_cap, { from: owner }); + this.token = await RBACCappedTokenMock.new(cap, { from: owner }); await this.token.addMinter(minter, { from: owner }); }); - shouldBehaveLikeMintableToken([owner, anotherAccount, minter]); - shouldBehaveLikeRBACMintableToken([owner, anotherAccount]); - shouldBehaveLikeCappedToken([owner, anotherAccount, minter, _cap]); + shouldBehaveLikeMintableToken(owner, minter, otherAccounts); + shouldBehaveLikeRBACMintableToken(owner, otherAccounts); + shouldBehaveLikeCappedToken(minter, otherAccounts, cap); }); diff --git a/test/token/ERC20/RBACMintableToken.behaviour.js b/test/token/ERC20/RBACMintableToken.behaviour.js index 7ca3cc3caed..a2c76d6b709 100644 --- a/test/token/ERC20/RBACMintableToken.behaviour.js +++ b/test/token/ERC20/RBACMintableToken.behaviour.js @@ -2,26 +2,26 @@ const { expectThrow } = require('../../helpers/expectThrow'); const ROLE_MINTER = 'minter'; -function shouldBehaveLikeRBACMintableToken ([owner, anotherAccount]) { +function shouldBehaveLikeRBACMintableToken (owner, [anyone]) { describe('handle roles', function () { it('owner can add and remove a minter role', async function () { - await this.token.addMinter(anotherAccount, { from: owner }); - let hasRole = await this.token.hasRole(anotherAccount, ROLE_MINTER); + await this.token.addMinter(anyone, { from: owner }); + let hasRole = await this.token.hasRole(anyone, ROLE_MINTER); assert.equal(hasRole, true); - await this.token.removeMinter(anotherAccount, { from: owner }); - hasRole = await this.token.hasRole(anotherAccount, ROLE_MINTER); + await this.token.removeMinter(anyone, { from: owner }); + hasRole = await this.token.hasRole(anyone, ROLE_MINTER); assert.equal(hasRole, false); }); - it('another account can\'t add or remove a minter role', async function () { + it('anyone can\'t add or remove a minter role', async function () { await expectThrow( - this.token.addMinter(anotherAccount, { from: anotherAccount }) + this.token.addMinter(anyone, { from: anyone }) ); - await this.token.addMinter(anotherAccount, { from: owner }); + await this.token.addMinter(anyone, { from: owner }); await expectThrow( - this.token.removeMinter(anotherAccount, { from: anotherAccount }) + this.token.removeMinter(anyone, { from: anyone }) ); }); }); diff --git a/test/token/ERC20/RBACMintableToken.test.js b/test/token/ERC20/RBACMintableToken.test.js index 2617bfb61b0..a3a5fae4656 100644 --- a/test/token/ERC20/RBACMintableToken.test.js +++ b/test/token/ERC20/RBACMintableToken.test.js @@ -3,12 +3,12 @@ const { shouldBehaveLikeMintableToken } = require('./MintableToken.behaviour'); const RBACMintableToken = artifacts.require('RBACMintableToken'); -contract('RBACMintableToken', function ([owner, anotherAccount, minter]) { +contract('RBACMintableToken', function ([_, owner, minter, ...otherAccounts]) { beforeEach(async function () { this.token = await RBACMintableToken.new({ from: owner }); await this.token.addMinter(minter, { from: owner }); }); - shouldBehaveLikeRBACMintableToken([owner, anotherAccount, minter]); - shouldBehaveLikeMintableToken([owner, anotherAccount, minter]); + shouldBehaveLikeRBACMintableToken(owner, otherAccounts); + shouldBehaveLikeMintableToken(owner, minter, otherAccounts); }); diff --git a/test/token/ERC20/StandardBurnableToken.test.js b/test/token/ERC20/StandardBurnableToken.test.js index 897f7d686e2..13fdbe36d4c 100644 --- a/test/token/ERC20/StandardBurnableToken.test.js +++ b/test/token/ERC20/StandardBurnableToken.test.js @@ -10,14 +10,14 @@ require('chai') .use(require('chai-bignumber')(BigNumber)) .should(); -contract('StandardBurnableToken', function ([owner, burner]) { +contract('StandardBurnableToken', function ([_, owner, burner]) { const initialBalance = 1000; beforeEach(async function () { this.token = await StandardBurnableTokenMock.new(owner, initialBalance); }); - shouldBehaveLikeBurnableToken([owner], initialBalance); + shouldBehaveLikeBurnableToken(owner, initialBalance); describe('burnFrom', function () { describe('on success', function () {