diff --git a/test/AutoIncrementing.test.js b/test/AutoIncrementing.test.js index 3743387b4..5d36094ee 100644 --- a/test/AutoIncrementing.test.js +++ b/test/AutoIncrementing.test.js @@ -20,7 +20,7 @@ contract('AutoIncrementing', function ([_, owner]) { for (const expectedId of EXPECTED) { await this.mock.doThing(KEY1, { from: owner }); const actualId = await this.mock.theId(); - actualId.should.be.bignumber.eq(expectedId); + actualId.should.be.bignumber.equal(expectedId); } }); }); @@ -30,11 +30,11 @@ contract('AutoIncrementing', function ([_, owner]) { for (const expectedId of EXPECTED) { await this.mock.doThing(KEY1, { from: owner }); let actualId = await this.mock.theId(); - actualId.should.be.bignumber.eq(expectedId); + actualId.should.be.bignumber.equal(expectedId); await this.mock.doThing(KEY2, { from: owner }); actualId = await this.mock.theId(); - actualId.should.be.bignumber.eq(expectedId); + actualId.should.be.bignumber.equal(expectedId); } }); }); diff --git a/test/Bounty.test.js b/test/Bounty.test.js index a3bf7a989..c9722269e 100644 --- a/test/Bounty.test.js +++ b/test/Bounty.test.js @@ -27,7 +27,7 @@ contract('Bounty', function ([_, owner, researcher]) { await sendReward(owner, this.bounty.address, reward); const balance = await ethGetBalance(this.bounty.address); - balance.should.be.bignumber.eq(reward); + balance.should.be.bignumber.equal(reward); }); context('with reward', function () { @@ -40,7 +40,7 @@ contract('Bounty', function ([_, owner, researcher]) { await sendReward(owner, this.bounty.address, reward); const balance = await ethGetBalance(this.bounty.address); - balance.should.be.bignumber.eq(reward); + balance.should.be.bignumber.equal(reward); }); it('cannot claim reward', async function () { @@ -76,10 +76,10 @@ contract('Bounty', function ([_, owner, researcher]) { await this.bounty.withdrawPayments({ from: researcher, gasPrice: gasPrice }); const updatedBalance = await ethGetBalance(this.bounty.address); - updatedBalance.should.be.bignumber.eq(0); + updatedBalance.should.be.bignumber.equal(0); const researcherCurrBalance = await ethGetBalance(researcher); - researcherCurrBalance.sub(researcherPrevBalance).should.be.bignumber.eq(reward.sub(gasCost)); + researcherCurrBalance.sub(researcherPrevBalance).should.be.bignumber.equal(reward.sub(gasCost)); }); context('reward claimed', function () { diff --git a/test/Heritable.test.js b/test/Heritable.test.js index 6ad52a849..631975309 100644 --- a/test/Heritable.test.js +++ b/test/Heritable.test.js @@ -6,26 +6,25 @@ const NULL_ADDRESS = '0x0000000000000000000000000000000000000000'; const Heritable = artifacts.require('Heritable'); +const BigNumber = web3.BigNumber; + +require('chai') + .use(require('chai-bignumber')(BigNumber)) + .should(); + contract('Heritable', function ([_, owner, heir, anyone]) { + const heartbeatTimeout = 4141; let heritable; beforeEach(async function () { - heritable = await Heritable.new(4141, { from: owner }); + heritable = await Heritable.new(heartbeatTimeout, { from: owner }); }); it('should start off with an owner, but without heir', async function () { const heir = await heritable.heir(); - assert.equal(typeof (owner), 'string'); - assert.equal(typeof (heir), 'string'); - assert.notStrictEqual( - owner, NULL_ADDRESS, - 'Owner shouldn\'t be the null address' - ); - assert.isTrue( - heir === NULL_ADDRESS, - 'Heir should be the null address' - ); + owner.should.be.a('string').that.is.not.equal(NULL_ADDRESS); + heir.should.be.a('string').that.is.equal(NULL_ADDRESS); }); it('only owner should set heir', async function () { @@ -39,10 +38,10 @@ contract('Heritable', function ([_, owner, heir, anyone]) { it('owner can remove heir', async function () { await heritable.setHeir(heir, { from: owner }); - assert.equal(await heritable.heir(), heir); + (await heritable.heir()).should.eq(heir); await heritable.removeHeir({ from: owner }); - assert.equal(await heritable.heir(), NULL_ADDRESS); + (await heritable.heir()).should.eq(NULL_ADDRESS); }); it('heir can claim ownership only if owner is dead and timeout was reached', async function () { @@ -53,9 +52,9 @@ contract('Heritable', function ([_, owner, heir, anyone]) { await increaseTime(1); await expectThrow(heritable.claimHeirOwnership({ from: heir })); - await increaseTime(4141); + await increaseTime(heartbeatTimeout); await heritable.claimHeirOwnership({ from: heir }); - assert.isTrue(await heritable.heir() === heir); + (await heritable.heir()).should.eq(heir); }); it('only heir can proclaim death', async function () { @@ -77,7 +76,7 @@ contract('Heritable', function ([_, owner, heir, anyone]) { await expectThrow(heritable.claimHeirOwnership({ from: heir })); await heritable.proclaimDeath({ from: heir }); - await increaseTime(4141); + await increaseTime(heartbeatTimeout); await heritable.heartbeat({ from: owner }); await expectThrow(heritable.claimHeirOwnership({ from: heir })); }); @@ -86,36 +85,36 @@ contract('Heritable', function ([_, owner, heir, anyone]) { const setHeirLogs = (await heritable.setHeir(heir, { from: owner })).logs; const setHeirEvent = setHeirLogs.find(e => e.event === 'HeirChanged'); - assert.isTrue(setHeirEvent.args.owner === owner); - assert.isTrue(setHeirEvent.args.newHeir === heir); + setHeirEvent.args.owner.should.eq(owner); + setHeirEvent.args.newHeir.should.eq(heir); const heartbeatLogs = (await heritable.heartbeat({ from: owner })).logs; const heartbeatEvent = heartbeatLogs.find(e => e.event === 'OwnerHeartbeated'); - assert.isTrue(heartbeatEvent.args.owner === owner); + heartbeatEvent.args.owner.should.eq(owner); const proclaimDeathLogs = (await heritable.proclaimDeath({ from: heir })).logs; const ownerDeadEvent = proclaimDeathLogs.find(e => e.event === 'OwnerProclaimedDead'); - assert.isTrue(ownerDeadEvent.args.owner === owner); - assert.isTrue(ownerDeadEvent.args.heir === heir); + ownerDeadEvent.args.owner.should.eq(owner); + ownerDeadEvent.args.heir.should.eq(heir); - await increaseTime(4141); + await increaseTime(heartbeatTimeout); const claimHeirOwnershipLogs = (await heritable.claimHeirOwnership({ from: heir })).logs; const ownershipTransferredEvent = claimHeirOwnershipLogs.find(e => e.event === 'OwnershipTransferred'); const heirOwnershipClaimedEvent = claimHeirOwnershipLogs.find(e => e.event === 'HeirOwnershipClaimed'); - assert.isTrue(ownershipTransferredEvent.args.previousOwner === owner); - assert.isTrue(ownershipTransferredEvent.args.newOwner === heir); - assert.isTrue(heirOwnershipClaimedEvent.args.previousOwner === owner); - assert.isTrue(heirOwnershipClaimedEvent.args.newOwner === heir); + ownershipTransferredEvent.args.previousOwner.should.eq(owner); + ownershipTransferredEvent.args.newOwner.should.eq(heir); + heirOwnershipClaimedEvent.args.previousOwner.should.eq(owner); + heirOwnershipClaimedEvent.args.newOwner.should.eq(heir); }); it('timeOfDeath can be queried', async function () { - assert.equal(await heritable.timeOfDeath(), 0); + (await heritable.timeOfDeath()).should.be.bignumber.equal(0); }); it('heartbeatTimeout can be queried', async function () { - assert.equal(await heritable.heartbeatTimeout(), 4141); + (await heritable.heartbeatTimeout()).should.be.bignumber.equal(heartbeatTimeout); }); }); diff --git a/test/LimitBalance.test.js b/test/LimitBalance.test.js index 221f766f8..f096916a9 100644 --- a/test/LimitBalance.test.js +++ b/test/LimitBalance.test.js @@ -3,6 +3,12 @@ const { ethGetBalance } = require('./helpers/web3'); const LimitBalanceMock = artifacts.require('LimitBalanceMock'); +const BigNumber = web3.BigNumber; + +require('chai') + .use(require('chai-bignumber')(BigNumber)) + .should(); + contract('LimitBalance', function () { let limitBalance; @@ -14,7 +20,7 @@ contract('LimitBalance', function () { it('should expose limit', async function () { const limit = await limitBalance.limit(); - assert.equal(limit, LIMIT); + limit.should.be.bignumber.equal(LIMIT); }); it('should allow sending below limit', async function () { @@ -22,7 +28,7 @@ contract('LimitBalance', function () { await limitBalance.limitedDeposit({ value: amount }); const balance = await ethGetBalance(limitBalance.address); - assert.equal(balance, amount); + balance.should.be.bignumber.equal(amount); }); it('shouldnt allow sending above limit', async function () { @@ -35,11 +41,11 @@ contract('LimitBalance', function () { await limitBalance.limitedDeposit({ value: amount }); const balance = await ethGetBalance(limitBalance.address); - assert.equal(balance, amount); + balance.should.be.bignumber.equal(amount); await limitBalance.limitedDeposit({ value: amount }); const updatedBalance = await ethGetBalance(limitBalance.address); - assert.equal(updatedBalance, amount * 2); + updatedBalance.should.be.bignumber.equal(amount * 2); }); it('shouldnt allow multiple sends above limit', async function () { @@ -47,7 +53,7 @@ contract('LimitBalance', function () { await limitBalance.limitedDeposit({ value: amount }); const balance = await ethGetBalance(limitBalance.address); - assert.equal(balance, amount); + balance.should.be.bignumber.equal(amount); await assertRevert(limitBalance.limitedDeposit({ value: amount + 1 })); }); }); diff --git a/test/ReentrancyGuard.test.js b/test/ReentrancyGuard.test.js index b53498a10..7086f8d94 100644 --- a/test/ReentrancyGuard.test.js +++ b/test/ReentrancyGuard.test.js @@ -2,13 +2,19 @@ const { expectThrow } = require('./helpers/expectThrow'); const ReentrancyMock = artifacts.require('ReentrancyMock'); const ReentrancyAttack = artifacts.require('ReentrancyAttack'); +const BigNumber = web3.BigNumber; + +require('chai') + .use(require('chai-bignumber')(BigNumber)) + .should(); + contract('ReentrancyGuard', function () { let reentrancyMock; beforeEach(async function () { reentrancyMock = await ReentrancyMock.new(); const initialCounter = await reentrancyMock.counter(); - assert.equal(initialCounter, 0); + initialCounter.should.be.bignumber.equal(0); }); it('should not allow remote callback', async function () { diff --git a/test/SimpleSavingsWallet.test.js b/test/SimpleSavingsWallet.test.js index 5ee9fa9e4..358281645 100644 --- a/test/SimpleSavingsWallet.test.js +++ b/test/SimpleSavingsWallet.test.js @@ -3,6 +3,12 @@ const { ethGetBalance, ethSendTransaction } = require('./helpers/web3'); const SimpleSavingsWallet = artifacts.require('SimpleSavingsWallet'); +const BigNumber = web3.BigNumber; + +require('chai') + .use(require('chai-bignumber')(BigNumber)) + .should(); + contract('SimpleSavingsWallet', function ([_, owner, anyone]) { let savingsWallet; @@ -15,7 +21,7 @@ contract('SimpleSavingsWallet', function ([_, owner, anyone]) { it('should receive funds', async function () { await ethSendTransaction({ from: owner, to: savingsWallet.address, value: paymentAmount }); const balance = await ethGetBalance(savingsWallet.address); - assert.isTrue((new web3.BigNumber(paymentAmount)).equals(balance)); + balance.should.be.bignumber.equal(paymentAmount); }); it('owner can send funds', async function () { @@ -29,6 +35,6 @@ contract('SimpleSavingsWallet', function ([_, owner, anyone]) { const balance = await ethGetBalance(anyone); await savingsWallet.sendTo(anyone, paymentAmount, { from: owner }); const updatedBalance = await ethGetBalance(anyone); - assert.isTrue(balance.plus(paymentAmount).equals(updatedBalance)); + balance.plus(paymentAmount).should.be.bignumber.equal(updatedBalance); }); }); diff --git a/test/access/SignatureBouncer.test.js b/test/access/SignatureBouncer.test.js index d57ae1f7f..92134f9e8 100644 --- a/test/access/SignatureBouncer.test.js +++ b/test/access/SignatureBouncer.test.js @@ -3,7 +3,10 @@ const { getBouncerSigner } = require('../helpers/sign'); const Bouncer = artifacts.require('SignatureBouncerMock'); +const BigNumber = web3.BigNumber; + require('chai') + .use(require('chai-bignumber')(BigNumber)) .should(); const UINT_VALUE = 23; diff --git a/test/crowdsale/AllowanceCrowdsale.test.js b/test/crowdsale/AllowanceCrowdsale.test.js index da95d296c..3f26030ab 100644 --- a/test/crowdsale/AllowanceCrowdsale.test.js +++ b/test/crowdsale/AllowanceCrowdsale.test.js @@ -39,8 +39,8 @@ contract('AllowanceCrowdsale', function ([_, investor, wallet, purchaser, tokenW const { logs } = await this.crowdsale.sendTransaction({ value: value, from: investor }); const event = logs.find(e => e.event === 'TokenPurchase'); should.exist(event); - event.args.purchaser.should.equal(investor); - event.args.beneficiary.should.equal(investor); + event.args.purchaser.should.eq(investor); + event.args.beneficiary.should.eq(investor); event.args.value.should.be.bignumber.equal(value); event.args.amount.should.be.bignumber.equal(expectedTokenAmount); }); diff --git a/test/crowdsale/CappedCrowdsale.test.js b/test/crowdsale/CappedCrowdsale.test.js index 6d9b7b75f..18473dddb 100644 --- a/test/crowdsale/CappedCrowdsale.test.js +++ b/test/crowdsale/CappedCrowdsale.test.js @@ -58,19 +58,19 @@ contract('CappedCrowdsale', function ([_, wallet]) { it('should not reach cap if sent under cap', async function () { await this.crowdsale.send(lessThanCap); const capReached = await this.crowdsale.capReached(); - capReached.should.equal(false); + capReached.should.eq(false); }); it('should not reach cap if sent just under cap', async function () { await this.crowdsale.send(cap.minus(1)); const capReached = await this.crowdsale.capReached(); - capReached.should.equal(false); + capReached.should.eq(false); }); it('should reach cap if cap sent', async function () { await this.crowdsale.send(cap); const capReached = await this.crowdsale.capReached(); - capReached.should.equal(true); + capReached.should.eq(true); }); }); }); diff --git a/test/crowdsale/Crowdsale.test.js b/test/crowdsale/Crowdsale.test.js index 154de95a9..7d70ba4f5 100644 --- a/test/crowdsale/Crowdsale.test.js +++ b/test/crowdsale/Crowdsale.test.js @@ -34,8 +34,8 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) { const { logs } = await this.crowdsale.sendTransaction({ value: value, from: investor }); const event = logs.find(e => e.event === 'TokenPurchase'); should.exist(event); - event.args.purchaser.should.equal(investor); - event.args.beneficiary.should.equal(investor); + event.args.purchaser.should.eq(investor); + event.args.beneficiary.should.eq(investor); event.args.value.should.be.bignumber.equal(value); event.args.amount.should.be.bignumber.equal(expectedTokenAmount); }); @@ -59,8 +59,8 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) { const { logs } = await this.crowdsale.buyTokens(investor, { value: value, from: purchaser }); const event = logs.find(e => e.event === 'TokenPurchase'); should.exist(event); - event.args.purchaser.should.equal(purchaser); - event.args.beneficiary.should.equal(investor); + event.args.purchaser.should.eq(purchaser); + event.args.beneficiary.should.eq(investor); event.args.value.should.be.bignumber.equal(value); event.args.amount.should.be.bignumber.equal(expectedTokenAmount); }); diff --git a/test/crowdsale/MintedCrowdsale.behavior.js b/test/crowdsale/MintedCrowdsale.behavior.js index 68454d4f1..f1a9cad1f 100644 --- a/test/crowdsale/MintedCrowdsale.behavior.js +++ b/test/crowdsale/MintedCrowdsale.behavior.js @@ -22,8 +22,8 @@ function shouldBehaveLikeMintedCrowdsale ([_, investor, wallet, purchaser], rate const { logs } = await this.crowdsale.sendTransaction({ value: value, from: investor }); const event = logs.find(e => e.event === 'TokenPurchase'); should.exist(event); - event.args.purchaser.should.equal(investor); - event.args.beneficiary.should.equal(investor); + event.args.purchaser.should.eq(investor); + event.args.beneficiary.should.eq(investor); event.args.value.should.be.bignumber.equal(value); event.args.amount.should.be.bignumber.equal(expectedTokenAmount); }); diff --git a/test/crowdsale/MintedCrowdsale.test.js b/test/crowdsale/MintedCrowdsale.test.js index 94c50eccd..369c5b091 100644 --- a/test/crowdsale/MintedCrowdsale.test.js +++ b/test/crowdsale/MintedCrowdsale.test.js @@ -20,7 +20,7 @@ contract('MintedCrowdsale', function ([_, investor, wallet, purchaser]) { it('should be token owner', async function () { const owner = await this.token.owner(); - owner.should.equal(this.crowdsale.address); + owner.should.eq(this.crowdsale.address); }); shouldBehaveLikeMintedCrowdsale([_, investor, wallet, purchaser], rate, value); @@ -37,7 +37,7 @@ contract('MintedCrowdsale', function ([_, investor, wallet, purchaser]) { it('should have minter role on token', async function () { const isMinter = await this.token.hasRole(this.crowdsale.address, ROLE_MINTER); - isMinter.should.equal(true); + isMinter.should.eq(true); }); shouldBehaveLikeMintedCrowdsale([_, investor, wallet, purchaser], rate, value); diff --git a/test/crowdsale/TimedCrowdsale.test.js b/test/crowdsale/TimedCrowdsale.test.js index 351ba3455..6e62571de 100644 --- a/test/crowdsale/TimedCrowdsale.test.js +++ b/test/crowdsale/TimedCrowdsale.test.js @@ -35,10 +35,10 @@ contract('TimedCrowdsale', function ([_, investor, wallet, purchaser]) { it('should be ended only after end', async function () { let ended = await this.crowdsale.hasClosed(); - ended.should.equal(false); + ended.should.eq(false); await increaseTimeTo(this.afterClosingTime); ended = await this.crowdsale.hasClosed(); - ended.should.equal(true); + ended.should.eq(true); }); describe('accepting payments', function () { diff --git a/test/crowdsale/WhitelistedCrowdsale.test.js b/test/crowdsale/WhitelistedCrowdsale.test.js index 2335d87dd..938ec8c7d 100644 --- a/test/crowdsale/WhitelistedCrowdsale.test.js +++ b/test/crowdsale/WhitelistedCrowdsale.test.js @@ -44,9 +44,9 @@ contract('WhitelistedCrowdsale', function ([_, wallet, authorized, unauthorized, describe('reporting whitelisted', function () { it('should correctly report whitelisted addresses', async function () { const isAuthorized = await this.crowdsale.whitelist(authorized); - isAuthorized.should.equal(true); + isAuthorized.should.eq(true); const isntAuthorized = await this.crowdsale.whitelist(unauthorized); - isntAuthorized.should.equal(false); + isntAuthorized.should.eq(false); }); }); }); @@ -83,11 +83,11 @@ contract('WhitelistedCrowdsale', function ([_, wallet, authorized, unauthorized, describe('reporting whitelisted', function () { it('should correctly report whitelisted addresses', async function () { const isAuthorized = await this.crowdsale.whitelist(authorized); - isAuthorized.should.equal(true); + isAuthorized.should.eq(true); const isAnotherAuthorized = await this.crowdsale.whitelist(anotherAuthorized); - isAnotherAuthorized.should.equal(true); + isAnotherAuthorized.should.eq(true); const isntAuthorized = await this.crowdsale.whitelist(unauthorized); - isntAuthorized.should.equal(false); + isntAuthorized.should.eq(false); }); }); }); diff --git a/test/examples/SimpleToken.test.js b/test/examples/SimpleToken.test.js index ab51c6eeb..8bf095c55 100644 --- a/test/examples/SimpleToken.test.js +++ b/test/examples/SimpleToken.test.js @@ -1,40 +1,48 @@ const { decodeLogs } = require('../helpers/decodeLogs'); const SimpleToken = artifacts.require('SimpleToken'); +const BigNumber = web3.BigNumber; + +require('chai') + .use(require('chai-bignumber')(BigNumber)) + .should(); + contract('SimpleToken', function ([_, creator]) { let token; + const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'; + beforeEach(async function () { token = await SimpleToken.new({ from: creator }); }); it('has a name', async function () { const name = await token.name(); - assert.equal(name, 'SimpleToken'); + name.should.eq('SimpleToken'); }); it('has a symbol', async function () { const symbol = await token.symbol(); - assert.equal(symbol, 'SIM'); + symbol.should.eq('SIM'); }); it('has 18 decimals', async function () { const decimals = await token.decimals(); - assert(decimals.eq(18)); + decimals.should.be.bignumber.equal(18); }); it('assigns the initial total supply to the creator', async function () { const totalSupply = await token.totalSupply(); const creatorBalance = await token.balanceOf(creator); - assert(creatorBalance.eq(totalSupply)); + creatorBalance.should.be.bignumber.equal(totalSupply); const receipt = await web3.eth.getTransactionReceipt(token.transactionHash); const logs = decodeLogs(receipt.logs, SimpleToken, token.address); - assert.equal(logs.length, 1); - assert.equal(logs[0].event, 'Transfer'); - assert.equal(logs[0].args.from.valueOf(), 0x0); - assert.equal(logs[0].args.to.valueOf(), creator); - assert(logs[0].args.value.eq(totalSupply)); + logs.length.should.eq(1); + logs[0].event.should.equal('Transfer'); + logs[0].args.from.valueOf().should.equal(ZERO_ADDRESS); + logs[0].args.to.valueOf().should.equal(creator); + logs[0].args.value.should.be.bignumber.equal(totalSupply); }); }); diff --git a/test/helpers/assertJump.js b/test/helpers/assertJump.js index 09db3622b..979307088 100644 --- a/test/helpers/assertJump.js +++ b/test/helpers/assertJump.js @@ -1,10 +1,12 @@ +const should = require('chai') + .should(); + async function assertJump (promise) { try { await promise; - assert.fail('Expected invalid opcode not received'); + should.fail('Expected invalid opcode not received'); } catch (error) { - const invalidOpcodeReceived = error.message.search('invalid opcode') >= 0; - assert(invalidOpcodeReceived, `Expected "invalid opcode", got ${error} instead`); + error.message.should.include('invalid opcode', `Expected "invalid opcode", got ${error} instead`); } } diff --git a/test/helpers/assertRevert.js b/test/helpers/assertRevert.js index 063a873e3..3d1aa2e16 100644 --- a/test/helpers/assertRevert.js +++ b/test/helpers/assertRevert.js @@ -1,12 +1,14 @@ +const should = require('chai') + .should(); + async function assertRevert (promise) { try { await promise; } catch (error) { - const revertFound = error.message.search('revert') >= 0; - assert(revertFound, `Expected "revert", got ${error} instead`); + error.message.should.include('revert', `Expected "revert", got ${error} instead`); return; } - assert.fail('Expected revert not received'); + should.fail('Expected revert not received'); } module.exports = { diff --git a/test/helpers/expectThrow.js b/test/helpers/expectThrow.js index b4da86d38..f46a981c8 100644 --- a/test/helpers/expectThrow.js +++ b/test/helpers/expectThrow.js @@ -1,32 +1,26 @@ +const should = require('chai') + .should(); + async function expectThrow (promise, message) { try { await promise; } catch (error) { // Message is an optional parameter here if (message) { - assert( - error.message.search(message) >= 0, - 'Expected \'' + message + '\', got \'' + error + '\' instead', - ); + error.message.should.include(message, 'Expected \'' + message + '\', got \'' + error + '\' instead'); return; } else { // TODO: Check jump destination to destinguish between a throw // and an actual invalid jump. - const invalidOpcode = error.message.search('invalid opcode') >= 0; // TODO: When we contract A calls contract B, and B throws, instead // of an 'invalid jump', we get an 'out of gas' error. How do // we distinguish this from an actual out of gas event? (The // ganache log actually show an 'invalid jump' event.) - const outOfGas = error.message.search('out of gas') >= 0; - const revert = error.message.search('revert') >= 0; - assert( - invalidOpcode || outOfGas || revert, - 'Expected throw, got \'' + error + '\' instead', - ); + error.message.should.match(/[invalid opcode|out of gas|revert]/, 'Expected throw, got \'' + error + '\' instead'); return; } } - assert.fail('Expected throw not received'); + should.fail('Expected throw not received'); } module.exports = { diff --git a/test/library/ECRecovery.test.js b/test/library/ECRecovery.test.js index 3299e86a8..260c95541 100644 --- a/test/library/ECRecovery.test.js +++ b/test/library/ECRecovery.test.js @@ -52,7 +52,7 @@ contract('ECRecovery', function ([_, anyone]) { // Recover the signer address from the generated message and wrong signature. const addrRecovered = await ecrecovery.recover(hashMessage('Nope'), signature); - assert.notEqual(anyone, addrRecovered); + addrRecovered.should.not.eq(anyone); }); it('recover should revert when a small hash is sent', async function () { diff --git a/test/library/Math.test.js b/test/library/Math.test.js index 999b685e9..ae1a16770 100644 --- a/test/library/Math.test.js +++ b/test/library/Math.test.js @@ -1,5 +1,11 @@ const MathMock = artifacts.require('MathMock'); +const BigNumber = web3.BigNumber; + +require('chai') + .use(require('chai-bignumber')(BigNumber)) + .should(); + contract('Math', function () { const min = 1234; const max = 5678; @@ -11,24 +17,24 @@ contract('Math', function () { describe('max', function () { it('is correctly detected in first argument position', async function () { const result = await this.math.max(max, min); - assert.equal(result, max); + result.should.be.bignumber.equal(max); }); it('is correctly detected in second argument position', async function () { const result = await this.math.max(min, max); - assert.equal(result, max); + result.should.be.bignumber.equal(max); }); }); describe('min', function () { it('is correctly detected in first argument position', async function () { const result = await this.math.min(min, max); - assert.equal(result, min); + result.should.be.bignumber.equal(min); }); it('is correctly detected in second argument position', async function () { const result = await this.math.min(max, min); - assert.equal(result, min); + result.should.be.bignumber.equal(min); }); }); }); diff --git a/test/library/MerkleProof.test.js b/test/library/MerkleProof.test.js index fb5a85e10..316620528 100644 --- a/test/library/MerkleProof.test.js +++ b/test/library/MerkleProof.test.js @@ -3,6 +3,9 @@ const { sha3, bufferToHex } = require('ethereumjs-util'); const MerkleProofWrapper = artifacts.require('MerkleProofWrapper'); +require('chai') + .should(); + contract('MerkleProof', function () { let merkleProof; @@ -22,7 +25,7 @@ contract('MerkleProof', function () { const leaf = bufferToHex(sha3(elements[0])); const result = await merkleProof.verifyProof(proof, root, leaf); - assert.isOk(result, 'verifyProof did not return true for a valid proof'); + result.should.be.true; }); it('should return false for an invalid Merkle proof', async function () { @@ -39,7 +42,7 @@ contract('MerkleProof', function () { const badProof = badMerkleTree.getHexProof(badElements[0]); const result = await merkleProof.verifyProof(badProof, correctRoot, correctLeaf); - assert.isNotOk(result, 'verifyProof did not return false for an invalid proof'); + result.should.be.false; }); it('should return false for a Merkle proof of invalid length', async function () { @@ -54,7 +57,7 @@ contract('MerkleProof', function () { const leaf = bufferToHex(sha3(elements[0])); const result = await merkleProof.verifyProof(badProof, root, leaf); - assert.isNotOk(result, 'verifyProof did not return false for proof of invalid length'); + result.should.be.false; }); }); }); diff --git a/test/lifecycle/Destructible.test.js b/test/lifecycle/Destructible.test.js index 64820fde6..a2ba054c1 100644 --- a/test/lifecycle/Destructible.test.js +++ b/test/lifecycle/Destructible.test.js @@ -1,6 +1,12 @@ const DestructibleMock = artifacts.require('DestructibleMock'); const { ethGetBalance } = require('../helpers/web3'); +const BigNumber = web3.BigNumber; + +require('chai') + .use(require('chai-bignumber')(BigNumber)) + .should(); + contract('Destructible', function ([_, owner, recipient]) { beforeEach(async function () { this.destructible = await DestructibleMock.new({ from: owner }); @@ -15,13 +21,13 @@ contract('Destructible', function ([_, owner, recipient]) { const initBalance = await ethGetBalance(owner); await this.destructible.destroy({ from: owner }); const newBalance = await ethGetBalance(owner); - assert.isTrue(newBalance > initBalance); + newBalance.should.be.bignumber.gt(initBalance); }); it('should send balance to recepient after destruction', async function () { const initBalance = await ethGetBalance(recipient); await this.destructible.destroyAndSend(recipient, { from: owner }); const newBalance = await ethGetBalance(recipient); - assert.isTrue(newBalance.greaterThan(initBalance)); + newBalance.should.be.bignumber.gt(initBalance); }); }); diff --git a/test/lifecycle/Pausable.test.js b/test/lifecycle/Pausable.test.js index 683c5c509..4ff085997 100644 --- a/test/lifecycle/Pausable.test.js +++ b/test/lifecycle/Pausable.test.js @@ -1,6 +1,12 @@ const { assertRevert } = require('../helpers/assertRevert'); const PausableMock = artifacts.require('PausableMock'); +const BigNumber = web3.BigNumber; + +require('chai') + .use(require('chai-bignumber')(BigNumber)) + .should(); + contract('Pausable', function () { beforeEach(async function () { this.Pausable = await PausableMock.new(); @@ -8,27 +14,28 @@ contract('Pausable', function () { it('can perform normal process in non-pause', async function () { const count0 = await this.Pausable.count(); - assert.equal(count0, 0); + count0.should.be.bignumber.equal(0); await this.Pausable.normalProcess(); const count1 = await this.Pausable.count(); - assert.equal(count1, 1); + count1.should.be.bignumber.equal(1); }); it('can not perform normal process in pause', async function () { await this.Pausable.pause(); const count0 = await this.Pausable.count(); - assert.equal(count0, 0); + count0.should.be.bignumber.equal(0); await assertRevert(this.Pausable.normalProcess()); const count1 = await this.Pausable.count(); - assert.equal(count1, 0); + count1.should.be.bignumber.equal(0); }); it('can not take drastic measure in non-pause', async function () { await assertRevert(this.Pausable.drasticMeasure()); const drasticMeasureTaken = await this.Pausable.drasticMeasureTaken(); - assert.isFalse(drasticMeasureTaken); + + drasticMeasureTaken.should.be.false; }); it('can take a drastic measure in a pause', async function () { @@ -36,7 +43,7 @@ contract('Pausable', function () { await this.Pausable.drasticMeasure(); const drasticMeasureTaken = await this.Pausable.drasticMeasureTaken(); - assert.isTrue(drasticMeasureTaken); + drasticMeasureTaken.should.be.true; }); it('should resume allowing normal process after pause is over', async function () { @@ -45,7 +52,7 @@ contract('Pausable', function () { await this.Pausable.normalProcess(); const count0 = await this.Pausable.count(); - assert.equal(count0, 1); + count0.should.be.bignumber.equal(1); }); it('should prevent drastic measure after pause is over', async function () { @@ -55,6 +62,6 @@ contract('Pausable', function () { await assertRevert(this.Pausable.drasticMeasure()); const drasticMeasureTaken = await this.Pausable.drasticMeasureTaken(); - assert.isFalse(drasticMeasureTaken); + drasticMeasureTaken.should.be.false; }); }); diff --git a/test/lifecycle/TokenDestructible.test.js b/test/lifecycle/TokenDestructible.test.js index 393f12c33..de460bd1f 100644 --- a/test/lifecycle/TokenDestructible.test.js +++ b/test/lifecycle/TokenDestructible.test.js @@ -3,6 +3,12 @@ const { ethGetBalance } = require('../helpers/web3'); const TokenDestructible = artifacts.require('TokenDestructible'); const StandardTokenMock = artifacts.require('StandardTokenMock'); +const BigNumber = web3.BigNumber; + +require('chai') + .use(require('chai-bignumber')(BigNumber)) + .should(); + contract('TokenDestructible', function ([_, owner]) { let tokenDestructible; @@ -18,20 +24,20 @@ contract('TokenDestructible', function ([_, owner]) { await tokenDestructible.destroy([], { from: owner }); const newBalance = await ethGetBalance(owner); - assert.isTrue(newBalance > initBalance); + newBalance.should.be.bignumber.gt(initBalance); }); it('should send tokens to owner after destruction', async function () { const token = await StandardTokenMock.new(tokenDestructible.address, 100); const initContractBalance = await token.balanceOf(tokenDestructible.address); const initOwnerBalance = await token.balanceOf(owner); - assert.equal(initContractBalance, 100); - assert.equal(initOwnerBalance, 0); + initContractBalance.should.be.bignumber.equal(100); + initOwnerBalance.should.be.bignumber.equal(0); await tokenDestructible.destroy([token.address], { from: owner }); const newContractBalance = await token.balanceOf(tokenDestructible.address); const newOwnerBalance = await token.balanceOf(owner); - assert.equal(newContractBalance, 0); - assert.equal(newOwnerBalance, 100); + newContractBalance.should.be.bignumber.equal(0); + newOwnerBalance.should.be.bignumber.equal(100); }); }); diff --git a/test/ownership/CanReclaimToken.test.js b/test/ownership/CanReclaimToken.test.js index 8afa2f281..108802e21 100644 --- a/test/ownership/CanReclaimToken.test.js +++ b/test/ownership/CanReclaimToken.test.js @@ -3,6 +3,12 @@ const { expectThrow } = require('../helpers/expectThrow'); const CanReclaimToken = artifacts.require('CanReclaimToken'); const StandardTokenMock = artifacts.require('StandardTokenMock'); +const BigNumber = web3.BigNumber; + +require('chai') + .use(require('chai-bignumber')(BigNumber)) + .should(); + contract('CanReclaimToken', function ([_, owner, anyone]) { let token = null; let canReclaimToken = null; @@ -15,7 +21,7 @@ contract('CanReclaimToken', function ([_, owner, anyone]) { // Force token into contract await token.transfer(canReclaimToken.address, 10, { from: owner }); const startBalance = await token.balanceOf(canReclaimToken.address); - assert.equal(startBalance, 10); + startBalance.should.be.bignumber.equal(10); }); it('should allow owner to reclaim tokens', async function () { @@ -23,8 +29,8 @@ contract('CanReclaimToken', function ([_, owner, anyone]) { 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); + finalBalance.should.be.bignumber.equal(0); + ownerFinalBalance.sub(ownerStartBalance).should.be.bignumber.equal(10); }); it('should allow only owner to reclaim tokens', async function () { diff --git a/test/ownership/Claimable.test.js b/test/ownership/Claimable.test.js index 62a588dd6..15f56ea37 100644 --- a/test/ownership/Claimable.test.js +++ b/test/ownership/Claimable.test.js @@ -2,6 +2,12 @@ const { assertRevert } = require('../helpers/assertRevert'); const Claimable = artifacts.require('Claimable'); +const BigNumber = web3.BigNumber; + +require('chai') + .use(require('chai-bignumber')(BigNumber)) + .should(); + contract('Claimable', function ([_, owner, newOwner, anyone]) { let claimable; @@ -9,11 +15,16 @@ contract('Claimable', function ([_, owner, newOwner, anyone]) { claimable = await Claimable.new({ from: owner }); }); + it('should have an owner', async function () { + const owner = await claimable.owner(); + owner.should.not.eq(0); + }); + it('changes pendingOwner after transfer', async function () { await claimable.transferOwnership(newOwner, { from: owner }); const pendingOwner = await claimable.pendingOwner(); - assert.isTrue(pendingOwner === newOwner); + pendingOwner.should.eq(newOwner); }); it('should prevent to claimOwnership from anyone', async function () { @@ -31,7 +42,8 @@ contract('Claimable', function ([_, owner, newOwner, anyone]) { it('changes allow pending owner to claim ownership', async function () { await claimable.claimOwnership({ from: newOwner }); - assert.isTrue((await claimable.owner()) === newOwner); + + (await claimable.owner()).should.eq(newOwner); }); }); }); diff --git a/test/ownership/Contactable.test.js b/test/ownership/Contactable.test.js index 40ec213c8..6c8131f25 100644 --- a/test/ownership/Contactable.test.js +++ b/test/ownership/Contactable.test.js @@ -9,7 +9,7 @@ contract('Contactable', function () { it('should have an empty contact info', async function () { const info = await contactable.contactInformation(); - assert.isTrue(info === ''); + info.should.eq(''); }); describe('after setting the contact information', function () { @@ -21,7 +21,7 @@ contract('Contactable', function () { it('should return the setted contact information', async function () { const info = await contactable.contactInformation(); - assert.isTrue(info === contactInfo); + info.should.eq(contactInfo); }); }); }); diff --git a/test/ownership/DelayedClaimable.test.js b/test/ownership/DelayedClaimable.test.js index 8f0b307e7..1313d195c 100644 --- a/test/ownership/DelayedClaimable.test.js +++ b/test/ownership/DelayedClaimable.test.js @@ -1,5 +1,11 @@ const { assertRevert } = require('../helpers/assertRevert'); +const BigNumber = web3.BigNumber; + +require('chai') + .use(require('chai-bignumber')(BigNumber)) + .should(); + const DelayedClaimable = artifacts.require('DelayedClaimable'); contract('DelayedClaimable', function ([_, owner, newOwner]) { @@ -10,34 +16,42 @@ contract('DelayedClaimable', function ([_, owner, newOwner]) { it('can set claim blocks', async function () { 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); + end.should.be.bignumber.equal(1000); + const start = await this.delayedClaimable.start(); - assert.equal(start, 0); + start.should.be.bignumber.equal(0); }); it('changes pendingOwner after transfer successful', async function () { 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); + end.should.be.bignumber.equal(1000); + const start = await this.delayedClaimable.start(); - assert.equal(start, 0); - assert.equal((await this.delayedClaimable.pendingOwner()), newOwner); + start.should.be.bignumber.equal(0); + + (await this.delayedClaimable.pendingOwner()).should.eq(newOwner); await this.delayedClaimable.claimOwnership({ from: newOwner }); - assert.equal((await this.delayedClaimable.owner()), newOwner); + (await this.delayedClaimable.owner()).should.eq(newOwner); }); it('changes pendingOwner after transfer fails', async function () { 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); + end.should.be.bignumber.equal(110); + const start = await this.delayedClaimable.start(); - assert.equal(start, 100); - assert.equal((await this.delayedClaimable.pendingOwner()), newOwner); + start.should.be.bignumber.equal(100); + + (await this.delayedClaimable.pendingOwner()).should.eq(newOwner); await assertRevert(this.delayedClaimable.claimOwnership({ from: newOwner })); - assert.isTrue((await this.delayedClaimable.owner()) !== newOwner); + (await this.delayedClaimable.owner()).should.not.eq(newOwner); }); it('set end and start invalid values fail', async function () { diff --git a/test/ownership/HasNoContracts.test.js b/test/ownership/HasNoContracts.test.js index 7f7958222..4224c4ecb 100644 --- a/test/ownership/HasNoContracts.test.js +++ b/test/ownership/HasNoContracts.test.js @@ -18,7 +18,7 @@ contract('HasNoContracts', function ([_, owner, anyone]) { it('should allow owner to reclaim contracts', async function () { await hasNoContracts.reclaimContract(ownable.address, { from: owner }); - assert.equal((await ownable.owner()), owner); + (await ownable.owner()).should.eq(owner); }); it('should allow only owner to reclaim contracts', async function () { diff --git a/test/ownership/HasNoEther.test.js b/test/ownership/HasNoEther.test.js index 70fa35f1b..792f87f0f 100644 --- a/test/ownership/HasNoEther.test.js +++ b/test/ownership/HasNoEther.test.js @@ -33,20 +33,20 @@ contract('HasNoEther', function ([_, owner, anyone]) { it('should allow owner to reclaim ether', async function () { const startBalance = await ethGetBalance(this.hasNoEther.address); - assert.equal(startBalance, 0); + startBalance.should.be.bignumber.equal(0); // Force ether into it const forceEther = await ForceEther.new({ value: amount }); await forceEther.destroyAndSend(this.hasNoEther.address); const forcedBalance = await ethGetBalance(this.hasNoEther.address); - assert.equal(forcedBalance, amount); + forcedBalance.should.be.bignumber.equal(amount); // Reclaim 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); + finalBalance.should.be.bignumber.equal(0); ownerFinalBalance.should.be.bignumber.gt(ownerStartBalance); }); @@ -56,7 +56,7 @@ contract('HasNoEther', function ([_, owner, anyone]) { const forceEther = await ForceEther.new({ value: amount }); await forceEther.destroyAndSend(this.hasNoEther.address); const forcedBalance = await ethGetBalance(this.hasNoEther.address); - assert.equal(forcedBalance, amount); + forcedBalance.should.be.bignumber.equal(amount); // Reclaim await expectThrow(this.hasNoEther.reclaimEther({ from: anyone })); diff --git a/test/ownership/HasNoTokens.test.js b/test/ownership/HasNoTokens.test.js index 7356c5abf..8b869a1e1 100644 --- a/test/ownership/HasNoTokens.test.js +++ b/test/ownership/HasNoTokens.test.js @@ -3,6 +3,12 @@ const { expectThrow } = require('../helpers/expectThrow'); const HasNoTokens = artifacts.require('HasNoTokens'); const ERC223TokenMock = artifacts.require('ERC223TokenMock'); +const BigNumber = web3.BigNumber; + +require('chai') + .use(require('chai-bignumber')(BigNumber)) + .should(); + contract('HasNoTokens', function ([_, owner, initialAccount, anyone]) { let hasNoTokens = null; let token = null; @@ -14,8 +20,9 @@ contract('HasNoTokens', function ([_, owner, initialAccount, anyone]) { // Force token into contract await token.transfer(hasNoTokens.address, 10, { from: initialAccount }); + const startBalance = await token.balanceOf(hasNoTokens.address); - assert.equal(startBalance, 10); + startBalance.should.be.bignumber.equal(10); }); it('should not accept ERC223 tokens', async function () { @@ -25,10 +32,12 @@ contract('HasNoTokens', function ([_, owner, initialAccount, anyone]) { it('should allow owner to reclaim tokens', async function () { 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); + + finalBalance.should.be.bignumber.equal(0); + ownerFinalBalance.sub(ownerStartBalance).should.be.bignumber.equal(10); }); it('should allow only owner to reclaim tokens', async function () { diff --git a/test/payment/PullPayment.test.js b/test/payment/PullPayment.test.js index 3f130fe78..2c7268d00 100644 --- a/test/payment/PullPayment.test.js +++ b/test/payment/PullPayment.test.js @@ -15,16 +15,10 @@ contract('PullPayment', function ([_, payer, payee1, payee2]) { this.contract = await PullPaymentMock.new({ value: amount }); }); - it('can\'t call asyncSend externally', async function () { - assert.isUndefined(this.contract.asyncSend); - }); - it('can record an async payment correctly', async function () { - const AMOUNT = 100; - await this.contract.callTransfer(payee1, AMOUNT, { from: payer }); - + await this.contract.callTransfer(payee1, 100, { from: payer }); const paymentsToPayee1 = await this.contract.payments(payee1); - paymentsToPayee1.should.be.bignumber.equal(AMOUNT); + paymentsToPayee1.should.be.bignumber.equal(100); }); it('can add multiple balances on one account', async function () { diff --git a/test/payment/SplitPayment.test.js b/test/payment/SplitPayment.test.js index bd4af0961..acaa90317 100644 --- a/test/payment/SplitPayment.test.js +++ b/test/payment/SplitPayment.test.js @@ -7,22 +7,22 @@ require('chai') .should(); const { expectThrow } = require('../helpers/expectThrow'); -const EVMThrow = require('../helpers/EVMThrow.js'); +const { EVMRevert } = require('../helpers/EVMRevert.js'); const SplitPayment = artifacts.require('SplitPayment'); contract('SplitPayment', function ([_, owner, payee1, payee2, payee3, nonpayee1, payer1]) { const amount = web3.toWei(1.0, 'ether'); it('cannot be created with no payees', async function () { - await expectThrow(SplitPayment.new([], []), EVMThrow); + await expectThrow(SplitPayment.new([], []), EVMRevert); }); it('requires shares for each payee', async function () { - await expectThrow(SplitPayment.new([payee1, payee2, payee3], [20, 30]), EVMThrow); + await expectThrow(SplitPayment.new([payee1, payee2, payee3], [20, 30]), EVMRevert); }); it('requires a payee for each share', async function () { - await expectThrow(SplitPayment.new([payee1, payee2], [20, 30, 40]), EVMThrow); + await expectThrow(SplitPayment.new([payee1, payee2], [20, 30, 40]), EVMRevert); }); context('once deployed', function () { @@ -42,7 +42,7 @@ contract('SplitPayment', function ([_, owner, payee1, payee2, payee3, nonpayee1, it('should store shares if address is payee', async function () { const shares = await this.contract.shares.call(payee1); - shares.should.be.bignumber.not.equal(0); + shares.should.be.bignumber.not.eq(0); }); it('should not store shares if address is not payee', async function () { @@ -51,12 +51,12 @@ contract('SplitPayment', function ([_, owner, payee1, payee2, payee3, nonpayee1, }); it('should throw if no funds to claim', async function () { - await expectThrow(this.contract.claim({ from: payee1 }), EVMThrow); + await expectThrow(this.contract.claim({ from: payee1 }), EVMRevert); }); it('should throw if non-payee want to claim', async function () { await ethSendTransaction({ from: payer1, to: this.contract.address, value: amount }); - await expectThrow(this.contract.claim({ from: nonpayee1 }), EVMThrow); + await expectThrow(this.contract.claim({ from: nonpayee1 }), EVMRevert); }); it('should distribute funds to payees', async function () { @@ -69,18 +69,18 @@ contract('SplitPayment', function ([_, owner, payee1, payee2, payee3, nonpayee1, // distribute to payees const initAmount1 = await ethGetBalance(payee1); await this.contract.claim({ from: payee1 }); - const profit1 = await ethGetBalance(payee1) - initAmount1; - assert(Math.abs(profit1 - web3.toWei(0.20, 'ether')) < 1e16); + const profit1 = (await ethGetBalance(payee1)).sub(initAmount1); + profit1.sub(web3.toWei(0.20, 'ether')).abs().should.be.bignumber.lt(1e16); const initAmount2 = await ethGetBalance(payee2); await this.contract.claim({ from: payee2 }); - const profit2 = await ethGetBalance(payee2) - initAmount2; - assert(Math.abs(profit2 - web3.toWei(0.10, 'ether')) < 1e16); + const profit2 = (await ethGetBalance(payee2)).sub(initAmount2); + profit2.sub(web3.toWei(0.10, 'ether')).abs().should.be.bignumber.lt(1e16); const initAmount3 = await ethGetBalance(payee3); await this.contract.claim({ from: payee3 }); - const profit3 = await ethGetBalance(payee3) - initAmount3; - assert(Math.abs(profit3 - web3.toWei(0.70, 'ether')) < 1e16); + const profit3 = (await ethGetBalance(payee3)).sub(initAmount3); + profit3.sub(web3.toWei(0.70, 'ether')).abs().should.be.bignumber.lt(1e16); // end balance should be zero const endBalance = await ethGetBalance(this.contract.address); diff --git a/test/token/ERC20/CappedToken.behavior.js b/test/token/ERC20/CappedToken.behavior.js index 2521a0a3b..249d15559 100644 --- a/test/token/ERC20/CappedToken.behavior.js +++ b/test/token/ERC20/CappedToken.behavior.js @@ -1,18 +1,22 @@ const { expectThrow } = require('../../helpers/expectThrow'); +const BigNumber = web3.BigNumber; + +require('chai') + .use(require('chai-bignumber')(BigNumber)) + .should(); + function shouldBehaveLikeCappedToken (minter, [anyone], cap) { describe('capped token', function () { const from = minter; it('should start with the correct cap', async function () { - const _cap = await this.token.cap(); - - assert(cap.eq(_cap)); + (await this.token.cap()).should.be.bignumber.equal(cap); }); it('should mint when amount is less than cap', async function () { const result = await this.token.mint(anyone, cap.sub(1), { from }); - assert.equal(result.logs[0].event, 'Mint'); + result.logs[0].event.should.equal('Mint'); }); it('should fail to mint if the ammount exceeds the cap', async function () { diff --git a/test/token/ERC20/MintableToken.behavior.js b/test/token/ERC20/MintableToken.behavior.js index f274d08fd..7d34e2719 100644 --- a/test/token/ERC20/MintableToken.behavior.js +++ b/test/token/ERC20/MintableToken.behavior.js @@ -11,7 +11,7 @@ function shouldBehaveLikeMintableToken (owner, minter, [anyone]) { describe('after token creation', function () { it('sender should be token owner', async function () { const tokenOwner = await this.token.owner({ from: owner }); - tokenOwner.should.equal(owner); + tokenOwner.should.eq(owner); }); }); @@ -19,7 +19,7 @@ function shouldBehaveLikeMintableToken (owner, minter, [anyone]) { describe('when the token minting is not finished', function () { it('returns false', async function () { const mintingFinished = await this.token.mintingFinished(); - assert.equal(mintingFinished, false); + mintingFinished.should.be.false; }); }); @@ -30,7 +30,7 @@ function shouldBehaveLikeMintableToken (owner, minter, [anyone]) { it('returns true', async function () { const mintingFinished = await this.token.mintingFinished(); - assert.equal(mintingFinished, true); + mintingFinished.should.be.true; }); }); }); @@ -44,14 +44,14 @@ function shouldBehaveLikeMintableToken (owner, minter, [anyone]) { await this.token.finishMinting({ from }); const mintingFinished = await this.token.mintingFinished(); - assert.equal(mintingFinished, true); + mintingFinished.should.be.true; }); it('emits a mint finished event', async function () { const { logs } = await this.token.finishMinting({ from }); - assert.equal(logs.length, 1); - assert.equal(logs[0].event, 'MintFinished'); + logs.length.should.be.equal(1); + logs[0].event.should.eq('MintFinished'); }); }); @@ -98,17 +98,17 @@ function shouldBehaveLikeMintableToken (owner, minter, [anyone]) { await this.token.mint(owner, amount, { from }); const balance = await this.token.balanceOf(owner); - assert.equal(balance, amount); + balance.should.be.bignumber.equal(amount); }); it('emits a mint and a transfer event', async function () { const { logs } = await this.token.mint(owner, amount, { from }); - assert.equal(logs.length, 2); - assert.equal(logs[0].event, 'Mint'); - assert.equal(logs[0].args.to, owner); - assert.equal(logs[0].args.amount, amount); - assert.equal(logs[1].event, 'Transfer'); + logs.length.should.eq(2); + logs[0].event.should.eq('Mint'); + logs[0].args.to.should.eq(owner); + logs[0].args.amount.should.be.bignumber.equal(amount); + logs[1].event.should.eq('Transfer'); }); }); diff --git a/test/token/ERC20/PausableToken.test.js b/test/token/ERC20/PausableToken.test.js index b138fcc04..f8b58c2b8 100644 --- a/test/token/ERC20/PausableToken.test.js +++ b/test/token/ERC20/PausableToken.test.js @@ -15,14 +15,14 @@ contract('PausableToken', function ([_, owner, recipient, anotherAccount]) { await this.token.pause({ from }); const paused = await this.token.paused(); - assert.equal(paused, true); + paused.should.be.true; }); it('emits a Pause event', async function () { const { logs } = await this.token.pause({ from }); - assert.equal(logs.length, 1); - assert.equal(logs[0].event, 'Pause'); + logs.length.should.eq(1); + logs[0].event.should.eq('Pause'); }); }); @@ -59,14 +59,14 @@ contract('PausableToken', function ([_, owner, recipient, anotherAccount]) { await this.token.unpause({ from }); const paused = await this.token.paused(); - assert.equal(paused, false); + paused.should.be.false; }); it('emits an Unpause event', async function () { const { logs } = await this.token.unpause({ from }); - assert.equal(logs.length, 1); - assert.equal(logs[0].event, 'Unpause'); + logs.length.should.eq(1); + logs[0].event.should.eq('Unpause'); }); }); @@ -93,14 +93,14 @@ contract('PausableToken', function ([_, owner, recipient, anotherAccount]) { it('is not paused by default', async function () { const paused = await this.token.paused({ from }); - assert.equal(paused, false); + paused.should.be.false; }); it('is paused after being paused', async function () { await this.token.pause({ from }); const paused = await this.token.paused({ from }); - assert.equal(paused, true); + paused.should.be.true; }); it('is not paused after being paused and then unpaused', async function () { @@ -108,7 +108,7 @@ contract('PausableToken', function ([_, owner, recipient, anotherAccount]) { await this.token.unpause({ from }); const paused = await this.token.paused(); - assert.equal(paused, false); + paused.should.be.false; }); }); @@ -117,10 +117,10 @@ contract('PausableToken', function ([_, owner, recipient, anotherAccount]) { await this.token.transfer(recipient, 100, { from: owner }); const senderBalance = await this.token.balanceOf(owner); - assert.equal(senderBalance, 0); + senderBalance.should.be.bignumber.equal(0); const recipientBalance = await this.token.balanceOf(recipient); - assert.equal(recipientBalance, 100); + recipientBalance.should.be.bignumber.equal(100); }); it('allows to transfer when paused and then unpaused', async function () { @@ -130,10 +130,10 @@ contract('PausableToken', function ([_, owner, recipient, anotherAccount]) { await this.token.transfer(recipient, 100, { from: owner }); const senderBalance = await this.token.balanceOf(owner); - assert.equal(senderBalance, 0); + senderBalance.should.be.bignumber.equal(0); const recipientBalance = await this.token.balanceOf(recipient); - assert.equal(recipientBalance, 100); + recipientBalance.should.be.bignumber.equal(100); }); it('reverts when trying to transfer when paused', async function () { @@ -148,7 +148,7 @@ contract('PausableToken', function ([_, owner, recipient, anotherAccount]) { await this.token.approve(anotherAccount, 40, { from: owner }); const allowance = await this.token.allowance(owner, anotherAccount); - assert.equal(allowance, 40); + allowance.should.be.bignumber.equal(40); }); it('allows to transfer when paused and then unpaused', async function () { @@ -158,7 +158,7 @@ contract('PausableToken', function ([_, owner, recipient, anotherAccount]) { await this.token.approve(anotherAccount, 40, { from: owner }); const allowance = await this.token.allowance(owner, anotherAccount); - assert.equal(allowance, 40); + allowance.should.be.bignumber.equal(40); }); it('reverts when trying to transfer when paused', async function () { @@ -177,10 +177,10 @@ contract('PausableToken', function ([_, owner, recipient, anotherAccount]) { await this.token.transferFrom(owner, recipient, 40, { from: anotherAccount }); const senderBalance = await this.token.balanceOf(owner); - assert.equal(senderBalance, 60); + senderBalance.should.be.bignumber.equal(60); const recipientBalance = await this.token.balanceOf(recipient); - assert.equal(recipientBalance, 40); + recipientBalance.should.be.bignumber.equal(40); }); it('allows to transfer when paused and then unpaused', async function () { @@ -190,10 +190,10 @@ contract('PausableToken', function ([_, owner, recipient, anotherAccount]) { await this.token.transferFrom(owner, recipient, 40, { from: anotherAccount }); const senderBalance = await this.token.balanceOf(owner); - assert.equal(senderBalance, 60); + senderBalance.should.be.bignumber.equal(60); const recipientBalance = await this.token.balanceOf(recipient); - assert.equal(recipientBalance, 40); + recipientBalance.should.be.bignumber.equal(40); }); it('reverts when trying to transfer from when paused', async function () { @@ -212,7 +212,7 @@ contract('PausableToken', function ([_, owner, recipient, anotherAccount]) { await this.token.decreaseApproval(anotherAccount, 40, { from: owner }); const allowance = await this.token.allowance(owner, anotherAccount); - assert.equal(allowance, 60); + allowance.should.be.bignumber.equal(60); }); it('allows to decrease approval when paused and then unpaused', async function () { @@ -222,7 +222,7 @@ contract('PausableToken', function ([_, owner, recipient, anotherAccount]) { await this.token.decreaseApproval(anotherAccount, 40, { from: owner }); const allowance = await this.token.allowance(owner, anotherAccount); - assert.equal(allowance, 60); + allowance.should.be.bignumber.equal(60); }); it('reverts when trying to transfer when paused', async function () { @@ -241,7 +241,7 @@ contract('PausableToken', function ([_, owner, recipient, anotherAccount]) { await this.token.increaseApproval(anotherAccount, 40, { from: owner }); const allowance = await this.token.allowance(owner, anotherAccount); - assert.equal(allowance, 140); + allowance.should.be.bignumber.equal(140); }); it('allows to increase approval when paused and then unpaused', async function () { @@ -251,7 +251,7 @@ contract('PausableToken', function ([_, owner, recipient, anotherAccount]) { await this.token.increaseApproval(anotherAccount, 40, { from: owner }); const allowance = await this.token.allowance(owner, anotherAccount); - assert.equal(allowance, 140); + allowance.should.be.bignumber.equal(140); }); it('reverts when trying to increase approval when paused', async function () { diff --git a/test/token/ERC20/RBACMintableToken.behavior.js b/test/token/ERC20/RBACMintableToken.behavior.js index a2c76d6b7..b46eca40a 100644 --- a/test/token/ERC20/RBACMintableToken.behavior.js +++ b/test/token/ERC20/RBACMintableToken.behavior.js @@ -7,11 +7,11 @@ function shouldBehaveLikeRBACMintableToken (owner, [anyone]) { it('owner can add and remove a minter role', async function () { await this.token.addMinter(anyone, { from: owner }); let hasRole = await this.token.hasRole(anyone, ROLE_MINTER); - assert.equal(hasRole, true); + hasRole.should.be.true; await this.token.removeMinter(anyone, { from: owner }); hasRole = await this.token.hasRole(anyone, ROLE_MINTER); - assert.equal(hasRole, false); + hasRole.should.be.false; }); it('anyone can\'t add or remove a minter role', async function () { diff --git a/test/token/ERC20/StandardToken.test.js b/test/token/ERC20/StandardToken.test.js index 2d1119f5e..e1f357502 100644 --- a/test/token/ERC20/StandardToken.test.js +++ b/test/token/ERC20/StandardToken.test.js @@ -1,6 +1,12 @@ const { assertRevert } = require('../../helpers/assertRevert'); const StandardToken = artifacts.require('StandardTokenMock'); +const BigNumber = web3.BigNumber; + +require('chai') + .use(require('chai-bignumber')(BigNumber)) + .should(); + contract('StandardToken', function ([_, owner, recipient, anotherAccount]) { const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'; @@ -12,7 +18,7 @@ contract('StandardToken', function ([_, owner, recipient, anotherAccount]) { it('returns the total amount of tokens', async function () { const totalSupply = await this.token.totalSupply(); - assert.equal(totalSupply, 100); + totalSupply.should.be.bignumber.equal(100); }); }); @@ -21,7 +27,7 @@ contract('StandardToken', function ([_, owner, recipient, anotherAccount]) { it('returns zero', async function () { const balance = await this.token.balanceOf(anotherAccount); - assert.equal(balance, 0); + balance.should.be.bignumber.equal(0); }); }); @@ -29,7 +35,7 @@ contract('StandardToken', function ([_, owner, recipient, anotherAccount]) { it('returns the total amount of tokens', async function () { const balance = await this.token.balanceOf(owner); - assert.equal(balance, 100); + balance.should.be.bignumber.equal(100); }); }); }); @@ -53,20 +59,20 @@ contract('StandardToken', function ([_, owner, recipient, anotherAccount]) { await this.token.transfer(to, amount, { from: owner }); const senderBalance = await this.token.balanceOf(owner); - assert.equal(senderBalance, 0); + senderBalance.should.be.bignumber.equal(0); const recipientBalance = await this.token.balanceOf(to); - assert.equal(recipientBalance, amount); + recipientBalance.should.be.bignumber.equal(amount); }); it('emits a transfer event', async function () { const { logs } = await this.token.transfer(to, amount, { from: owner }); - assert.equal(logs.length, 1); - assert.equal(logs[0].event, 'Transfer'); - assert.equal(logs[0].args.from, owner); - assert.equal(logs[0].args.to, to); - assert(logs[0].args.value.eq(amount)); + logs.length.should.eq(1); + logs[0].event.should.eq('Transfer'); + logs[0].args.from.should.eq(owner); + logs[0].args.to.should.eq(to); + logs[0].args.value.should.be.bignumber.equal(amount); }); }); }); @@ -90,11 +96,11 @@ contract('StandardToken', function ([_, owner, recipient, anotherAccount]) { it('emits an approval event', async function () { const { logs } = await this.token.approve(spender, amount, { from: owner }); - assert.equal(logs.length, 1); - assert.equal(logs[0].event, 'Approval'); - assert.equal(logs[0].args.owner, owner); - assert.equal(logs[0].args.spender, spender); - assert(logs[0].args.value.eq(amount)); + logs.length.should.eq(1); + logs[0].event.should.eq('Approval'); + logs[0].args.owner.should.eq(owner); + logs[0].args.spender.should.eq(spender); + logs[0].args.value.should.be.bignumber.equal(amount); }); describe('when there was no approved amount before', function () { @@ -102,7 +108,7 @@ contract('StandardToken', function ([_, owner, recipient, anotherAccount]) { await this.token.approve(spender, amount, { from: owner }); const allowance = await this.token.allowance(owner, spender); - assert.equal(allowance, amount); + allowance.should.be.bignumber.equal(amount); }); }); @@ -115,7 +121,7 @@ contract('StandardToken', function ([_, owner, recipient, anotherAccount]) { await this.token.approve(spender, amount, { from: owner }); const allowance = await this.token.allowance(owner, spender); - assert.equal(allowance, amount); + allowance.should.be.bignumber.equal(amount); }); }); }); @@ -126,11 +132,11 @@ contract('StandardToken', function ([_, owner, recipient, anotherAccount]) { it('emits an approval event', async function () { const { logs } = await this.token.approve(spender, amount, { from: owner }); - assert.equal(logs.length, 1); - assert.equal(logs[0].event, 'Approval'); - assert.equal(logs[0].args.owner, owner); - assert.equal(logs[0].args.spender, spender); - assert(logs[0].args.value.eq(amount)); + logs.length.should.eq(1); + logs[0].event.should.eq('Approval'); + logs[0].args.owner.should.eq(owner); + logs[0].args.spender.should.eq(spender); + logs[0].args.value.should.be.bignumber.equal(amount); }); describe('when there was no approved amount before', function () { @@ -138,7 +144,7 @@ contract('StandardToken', function ([_, owner, recipient, anotherAccount]) { await this.token.approve(spender, amount, { from: owner }); const allowance = await this.token.allowance(owner, spender); - assert.equal(allowance, amount); + allowance.should.be.bignumber.equal(amount); }); }); @@ -151,7 +157,7 @@ contract('StandardToken', function ([_, owner, recipient, anotherAccount]) { await this.token.approve(spender, amount, { from: owner }); const allowance = await this.token.allowance(owner, spender); - assert.equal(allowance, amount); + allowance.should.be.bignumber.equal(amount); }); }); }); @@ -165,17 +171,17 @@ contract('StandardToken', function ([_, owner, recipient, anotherAccount]) { await this.token.approve(spender, amount, { from: owner }); const allowance = await this.token.allowance(owner, spender); - assert.equal(allowance, amount); + allowance.should.be.bignumber.equal(amount); }); it('emits an approval event', async function () { const { logs } = await this.token.approve(spender, amount, { from: owner }); - assert.equal(logs.length, 1); - assert.equal(logs[0].event, 'Approval'); - assert.equal(logs[0].args.owner, owner); - assert.equal(logs[0].args.spender, spender); - assert(logs[0].args.value.eq(amount)); + logs.length.should.eq(1); + logs[0].event.should.eq('Approval'); + logs[0].args.owner.should.eq(owner); + logs[0].args.spender.should.eq(spender); + logs[0].args.value.should.be.bignumber.equal(amount); }); }); }); @@ -198,27 +204,27 @@ contract('StandardToken', function ([_, owner, recipient, anotherAccount]) { await this.token.transferFrom(owner, to, amount, { from: spender }); const senderBalance = await this.token.balanceOf(owner); - assert.equal(senderBalance, 0); + senderBalance.should.be.bignumber.equal(0); const recipientBalance = await this.token.balanceOf(to); - assert.equal(recipientBalance, amount); + recipientBalance.should.be.bignumber.equal(amount); }); it('decreases the spender allowance', async function () { await this.token.transferFrom(owner, to, amount, { from: spender }); const allowance = await this.token.allowance(owner, spender); - assert(allowance.eq(0)); + allowance.should.be.bignumber.equal(0); }); it('emits a transfer event', async function () { const { logs } = await this.token.transferFrom(owner, to, amount, { from: spender }); - assert.equal(logs.length, 1); - assert.equal(logs[0].event, 'Transfer'); - assert.equal(logs[0].args.from, owner); - assert.equal(logs[0].args.to, to); - assert(logs[0].args.value.eq(amount)); + logs.length.should.eq(1); + logs[0].event.should.eq('Transfer'); + logs[0].args.from.should.eq(owner); + logs[0].args.to.should.eq(to); + logs[0].args.value.should.be.bignumber.equal(amount); }); }); @@ -278,11 +284,11 @@ contract('StandardToken', function ([_, owner, recipient, anotherAccount]) { it('emits an approval event', async function () { const { logs } = await this.token.decreaseApproval(spender, amount, { from: owner }); - assert.equal(logs.length, 1); - assert.equal(logs[0].event, 'Approval'); - assert.equal(logs[0].args.owner, owner); - assert.equal(logs[0].args.spender, spender); - assert(logs[0].args.value.eq(0)); + logs.length.should.eq(1); + logs[0].event.should.eq('Approval'); + logs[0].args.owner.should.eq(owner); + logs[0].args.spender.should.eq(spender); + logs[0].args.value.should.be.bignumber.equal(0); }); describe('when there was no approved amount before', function () { @@ -290,7 +296,7 @@ contract('StandardToken', function ([_, owner, recipient, anotherAccount]) { await this.token.decreaseApproval(spender, amount, { from: owner }); const allowance = await this.token.allowance(owner, spender); - assert.equal(allowance, 0); + allowance.should.be.bignumber.equal(0); }); }); @@ -305,19 +311,19 @@ contract('StandardToken', function ([_, owner, recipient, anotherAccount]) { await this.token.decreaseApproval(spender, approvedAmount - 5, { from: owner }); const allowance = await this.token.allowance(owner, spender); - assert.equal(allowance, 5); + allowance.should.be.bignumber.equal(5); }); it('sets the allowance to zero when all allowance is removed', async function () { await this.token.decreaseApproval(spender, approvedAmount, { from: owner }); const allowance = await this.token.allowance(owner, spender); - assert.equal(allowance, 0); + allowance.should.be.bignumber.equal(0); }); it('sets the allowance to zero when more than the full allowance is removed', async function () { await this.token.decreaseApproval(spender, approvedAmount + 5, { from: owner }); const allowance = await this.token.allowance(owner, spender); - assert.equal(allowance, 0); + allowance.should.be.bignumber.equal(0); }); }); }); @@ -328,11 +334,11 @@ contract('StandardToken', function ([_, owner, recipient, anotherAccount]) { it('emits an approval event', async function () { const { logs } = await this.token.decreaseApproval(spender, amount, { from: owner }); - assert.equal(logs.length, 1); - assert.equal(logs[0].event, 'Approval'); - assert.equal(logs[0].args.owner, owner); - assert.equal(logs[0].args.spender, spender); - assert(logs[0].args.value.eq(0)); + logs.length.should.eq(1); + logs[0].event.should.eq('Approval'); + logs[0].args.owner.should.eq(owner); + logs[0].args.spender.should.eq(spender); + logs[0].args.value.should.be.bignumber.equal(0); }); describe('when there was no approved amount before', function () { @@ -340,7 +346,7 @@ contract('StandardToken', function ([_, owner, recipient, anotherAccount]) { await this.token.decreaseApproval(spender, amount, { from: owner }); const allowance = await this.token.allowance(owner, spender); - assert.equal(allowance, 0); + allowance.should.be.bignumber.equal(0); }); }); @@ -353,7 +359,7 @@ contract('StandardToken', function ([_, owner, recipient, anotherAccount]) { await this.token.decreaseApproval(spender, amount, { from: owner }); const allowance = await this.token.allowance(owner, spender); - assert.equal(allowance, 1); + allowance.should.be.bignumber.equal(1); }); }); }); @@ -367,17 +373,17 @@ contract('StandardToken', function ([_, owner, recipient, anotherAccount]) { await this.token.decreaseApproval(spender, amount, { from: owner }); const allowance = await this.token.allowance(owner, spender); - assert.equal(allowance, 0); + allowance.should.be.bignumber.equal(0); }); it('emits an approval event', async function () { const { logs } = await this.token.decreaseApproval(spender, amount, { from: owner }); - assert.equal(logs.length, 1); - assert.equal(logs[0].event, 'Approval'); - assert.equal(logs[0].args.owner, owner); - assert.equal(logs[0].args.spender, spender); - assert(logs[0].args.value.eq(0)); + logs.length.should.eq(1); + logs[0].event.should.eq('Approval'); + logs[0].args.owner.should.eq(owner); + logs[0].args.spender.should.eq(spender); + logs[0].args.value.should.be.bignumber.equal(0); }); }); }); @@ -392,11 +398,11 @@ contract('StandardToken', function ([_, owner, recipient, anotherAccount]) { it('emits an approval event', async function () { const { logs } = await this.token.increaseApproval(spender, amount, { from: owner }); - assert.equal(logs.length, 1); - assert.equal(logs[0].event, 'Approval'); - assert.equal(logs[0].args.owner, owner); - assert.equal(logs[0].args.spender, spender); - assert(logs[0].args.value.eq(amount)); + logs.length.should.eq(1); + logs[0].event.should.eq('Approval'); + logs[0].args.owner.should.eq(owner); + logs[0].args.spender.should.eq(spender); + logs[0].args.value.should.be.bignumber.equal(amount); }); describe('when there was no approved amount before', function () { @@ -404,7 +410,7 @@ contract('StandardToken', function ([_, owner, recipient, anotherAccount]) { await this.token.increaseApproval(spender, amount, { from: owner }); const allowance = await this.token.allowance(owner, spender); - assert.equal(allowance, amount); + allowance.should.be.bignumber.equal(amount); }); }); @@ -417,7 +423,7 @@ contract('StandardToken', function ([_, owner, recipient, anotherAccount]) { await this.token.increaseApproval(spender, amount, { from: owner }); const allowance = await this.token.allowance(owner, spender); - assert.equal(allowance, amount + 1); + allowance.should.be.bignumber.equal(amount + 1); }); }); }); @@ -428,11 +434,11 @@ contract('StandardToken', function ([_, owner, recipient, anotherAccount]) { it('emits an approval event', async function () { const { logs } = await this.token.increaseApproval(spender, amount, { from: owner }); - assert.equal(logs.length, 1); - assert.equal(logs[0].event, 'Approval'); - assert.equal(logs[0].args.owner, owner); - assert.equal(logs[0].args.spender, spender); - assert(logs[0].args.value.eq(amount)); + logs.length.should.eq(1); + logs[0].event.should.eq('Approval'); + logs[0].args.owner.should.eq(owner); + logs[0].args.spender.should.eq(spender); + logs[0].args.value.should.be.bignumber.equal(amount); }); describe('when there was no approved amount before', function () { @@ -440,7 +446,7 @@ contract('StandardToken', function ([_, owner, recipient, anotherAccount]) { await this.token.increaseApproval(spender, amount, { from: owner }); const allowance = await this.token.allowance(owner, spender); - assert.equal(allowance, amount); + allowance.should.be.bignumber.equal(amount); }); }); @@ -453,7 +459,7 @@ contract('StandardToken', function ([_, owner, recipient, anotherAccount]) { await this.token.increaseApproval(spender, amount, { from: owner }); const allowance = await this.token.allowance(owner, spender); - assert.equal(allowance, amount + 1); + allowance.should.be.bignumber.equal(amount + 1); }); }); }); @@ -466,17 +472,17 @@ contract('StandardToken', function ([_, owner, recipient, anotherAccount]) { await this.token.increaseApproval(spender, amount, { from: owner }); const allowance = await this.token.allowance(owner, spender); - assert.equal(allowance, amount); + allowance.should.be.bignumber.equal(amount); }); it('emits an approval event', async function () { const { logs } = await this.token.increaseApproval(spender, amount, { from: owner }); - assert.equal(logs.length, 1); - assert.equal(logs[0].event, 'Approval'); - assert.equal(logs[0].args.owner, owner); - assert.equal(logs[0].args.spender, spender); - assert(logs[0].args.value.eq(amount)); + logs.length.should.eq(1); + logs[0].event.should.eq('Approval'); + logs[0].args.owner.should.eq(owner); + logs[0].args.spender.should.eq(spender); + logs[0].args.value.should.be.bignumber.equal(amount); }); }); }); diff --git a/test/token/ERC20/TokenVesting.test.js b/test/token/ERC20/TokenVesting.test.js index 8ba747457..aa2132656 100644 --- a/test/token/ERC20/TokenVesting.test.js +++ b/test/token/ERC20/TokenVesting.test.js @@ -48,7 +48,7 @@ contract('TokenVesting', function ([_, owner, beneficiary]) { const releaseTime = block.timestamp; const balance = await this.token.balanceOf(beneficiary); - balance.should.bignumber.equal(amount.mul(releaseTime - this.start).div(this.duration).floor()); + balance.should.bignumber.eq(amount.mul(releaseTime - this.start).div(this.duration).floor()); }); it('should linearly release tokens during vesting period', async function () { @@ -63,7 +63,7 @@ contract('TokenVesting', function ([_, owner, beneficiary]) { const balance = await this.token.balanceOf(beneficiary); const expectedVesting = amount.mul(now - this.start).div(this.duration).floor(); - balance.should.bignumber.equal(expectedVesting); + balance.should.bignumber.eq(expectedVesting); } }); @@ -71,7 +71,7 @@ contract('TokenVesting', function ([_, owner, beneficiary]) { await increaseTimeTo(this.start + this.duration); await this.vesting.release(this.token.address); const balance = await this.token.balanceOf(beneficiary); - balance.should.bignumber.equal(amount); + balance.should.bignumber.eq(amount); }); it('should be revoked by owner if revocable is set', async function () { @@ -94,7 +94,7 @@ contract('TokenVesting', function ([_, owner, beneficiary]) { await this.vesting.revoke(this.token.address, { from: owner }); const ownerBalance = await this.token.balanceOf(owner); - ownerBalance.should.bignumber.equal(amount.sub(vested)); + ownerBalance.should.bignumber.eq(amount.sub(vested)); }); it('should keep the vested tokens when revoked by owner', async function () { @@ -106,7 +106,7 @@ contract('TokenVesting', function ([_, owner, beneficiary]) { const vestedPost = await this.vesting.vestedAmount(this.token.address); - vestedPre.should.bignumber.equal(vestedPost); + vestedPre.should.bignumber.eq(vestedPost); }); it('should fail to be revoked a second time', async function () { diff --git a/test/token/ERC721/ERC721BasicToken.behavior.js b/test/token/ERC721/ERC721BasicToken.behavior.js index a8ac53341..0a32b6ef3 100644 --- a/test/token/ERC721/ERC721BasicToken.behavior.js +++ b/test/token/ERC721/ERC721BasicToken.behavior.js @@ -116,7 +116,7 @@ function shouldBehaveLikeERC721BasicToken (accounts) { if (approved) { it('emit only a transfer event', async function () { logs.length.should.be.equal(1); - logs[0].event.should.be.eq('Transfer'); + logs[0].event.should.be.equal('Transfer'); logs[0].args._from.should.be.equal(owner); logs[0].args._to.should.be.equal(this.to); logs[0].args._tokenId.should.be.bignumber.equal(tokenId); @@ -124,7 +124,7 @@ function shouldBehaveLikeERC721BasicToken (accounts) { } else { it('emits only a transfer event', async function () { logs.length.should.be.equal(1); - logs[0].event.should.be.eq('Transfer'); + logs[0].event.should.be.equal('Transfer'); logs[0].args._from.should.be.equal(owner); logs[0].args._to.should.be.equal(this.to); logs[0].args._tokenId.should.be.bignumber.equal(tokenId); @@ -146,7 +146,7 @@ function shouldBehaveLikeERC721BasicToken (accounts) { newOwnerToken.toNumber().should.be.equal(tokenId); const previousOwnerToken = await this.token.tokenOfOwnerByIndex(owner, 0); - previousOwnerToken.toNumber().should.not.be.equal(tokenId); + previousOwnerToken.toNumber().should.not.be.eq(tokenId); }); }; @@ -197,7 +197,7 @@ function shouldBehaveLikeERC721BasicToken (accounts) { it('emits only a transfer event', async function () { logs.length.should.be.equal(1); - logs[0].event.should.be.eq('Transfer'); + logs[0].event.should.be.equal('Transfer'); logs[0].args._from.should.be.equal(owner); logs[0].args._to.should.be.equal(owner); logs[0].args._tokenId.should.be.bignumber.equal(tokenId); @@ -278,7 +278,7 @@ function shouldBehaveLikeERC721BasicToken (accounts) { const result = await transferFun.call(this, owner, this.to, tokenId, { from: owner }); result.receipt.logs.length.should.be.equal(2); const [log] = decodeLogs([result.receipt.logs[1]], ERC721Receiver, this.receiver.address); - log.event.should.be.eq('Received'); + log.event.should.be.equal('Received'); log.args._operator.should.be.equal(owner); log.args._from.should.be.equal(owner); log.args._tokenId.toNumber().should.be.equal(tokenId); @@ -289,7 +289,7 @@ function shouldBehaveLikeERC721BasicToken (accounts) { const result = await transferFun.call(this, owner, this.to, tokenId, { from: approved }); result.receipt.logs.length.should.be.equal(2); const [log] = decodeLogs([result.receipt.logs[1]], ERC721Receiver, this.receiver.address); - log.event.should.be.eq('Received'); + log.event.should.be.equal('Received'); log.args._operator.should.be.equal(approved); log.args._from.should.be.equal(owner); log.args._tokenId.toNumber().should.be.equal(tokenId); @@ -367,7 +367,7 @@ function shouldBehaveLikeERC721BasicToken (accounts) { const itEmitsApprovalEvent = function (address) { it('emits an approval event', async function () { logs.length.should.be.equal(1); - logs[0].event.should.be.eq('Approval'); + logs[0].event.should.be.equal('Approval'); logs[0].args._owner.should.be.equal(sender); logs[0].args._approved.should.be.equal(address); logs[0].args._tokenId.should.be.bignumber.equal(tokenId); @@ -481,7 +481,7 @@ function shouldBehaveLikeERC721BasicToken (accounts) { const { logs } = await this.token.setApprovalForAll(operator, true, { from: sender }); logs.length.should.be.equal(1); - logs[0].event.should.be.eq('ApprovalForAll'); + logs[0].event.should.be.equal('ApprovalForAll'); logs[0].args._owner.should.be.equal(sender); logs[0].args._operator.should.be.equal(operator); logs[0].args._approved.should.be.true; @@ -504,7 +504,7 @@ function shouldBehaveLikeERC721BasicToken (accounts) { const { logs } = await this.token.setApprovalForAll(operator, true, { from: sender }); logs.length.should.be.equal(1); - logs[0].event.should.be.eq('ApprovalForAll'); + logs[0].event.should.be.equal('ApprovalForAll'); logs[0].args._owner.should.be.equal(sender); logs[0].args._operator.should.be.equal(operator); logs[0].args._approved.should.be.true; @@ -534,7 +534,7 @@ function shouldBehaveLikeERC721BasicToken (accounts) { const { logs } = await this.token.setApprovalForAll(operator, true, { from: sender }); logs.length.should.be.equal(1); - logs[0].event.should.be.eq('ApprovalForAll'); + logs[0].event.should.be.equal('ApprovalForAll'); logs[0].args._owner.should.be.equal(sender); logs[0].args._operator.should.be.equal(operator); logs[0].args._approved.should.be.true; diff --git a/test/token/ERC721/ERC721MintBurn.behavior.js b/test/token/ERC721/ERC721MintBurn.behavior.js index b20c2e258..cc1defa1c 100644 --- a/test/token/ERC721/ERC721MintBurn.behavior.js +++ b/test/token/ERC721/ERC721MintBurn.behavior.js @@ -41,7 +41,7 @@ function shouldBehaveLikeMintAndBurnERC721Token (accounts) { it('emits a transfer event', async function () { logs.length.should.be.equal(1); - logs[0].event.should.be.eq('Transfer'); + logs[0].event.should.be.equal('Transfer'); logs[0].args._from.should.be.equal(ZERO_ADDRESS); logs[0].args._to.should.be.equal(to); logs[0].args._tokenId.should.be.bignumber.equal(tokenId); @@ -80,7 +80,7 @@ function shouldBehaveLikeMintAndBurnERC721Token (accounts) { it('emits a burn event', async function () { logs.length.should.be.equal(1); - logs[0].event.should.be.eq('Transfer'); + logs[0].event.should.be.equal('Transfer'); logs[0].args._from.should.be.equal(sender); logs[0].args._to.should.be.equal(ZERO_ADDRESS); logs[0].args._tokenId.should.be.bignumber.equal(tokenId);