* Add BigNumber support to expectEvent/inLogs (#1026)
* switched direct logs array check to expectEvent method in AllowanceCrowdsale.test.js
* Refactor expectEvent.inLogs function to use simple value number check
* Introduced should.be.bignumber method to compare BigNumber values
* Use expectEvent to test logs (#1232)
* Removed trailing space
(cherry picked from commit 536262f2ec)
This commit is contained in:
@ -61,12 +61,11 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
|
||||
it('emits a transfer event', async function () {
|
||||
const { logs } = await this.token.transfer(to, amount, { from: owner });
|
||||
|
||||
const event = expectEvent.inLogs(logs, 'Transfer', {
|
||||
expectEvent.inLogs(logs, 'Transfer', {
|
||||
from: owner,
|
||||
to: to,
|
||||
value: amount
|
||||
});
|
||||
|
||||
event.args.value.should.be.bignumber.equal(amount);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -90,11 +89,11 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
|
||||
it('emits an approval event', async function () {
|
||||
const { logs } = await this.token.approve(spender, amount, { from: owner });
|
||||
|
||||
logs.length.should.equal(1);
|
||||
logs[0].event.should.equal('Approval');
|
||||
logs[0].args.owner.should.equal(owner);
|
||||
logs[0].args.spender.should.equal(spender);
|
||||
logs[0].args.value.should.be.bignumber.equal(amount);
|
||||
expectEvent.inLogs(logs, 'Approval', {
|
||||
owner: owner,
|
||||
spender: spender,
|
||||
value: amount
|
||||
});
|
||||
});
|
||||
|
||||
describe('when there was no approved amount before', function () {
|
||||
@ -124,11 +123,11 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
|
||||
it('emits an approval event', async function () {
|
||||
const { logs } = await this.token.approve(spender, amount, { from: owner });
|
||||
|
||||
logs.length.should.equal(1);
|
||||
logs[0].event.should.equal('Approval');
|
||||
logs[0].args.owner.should.equal(owner);
|
||||
logs[0].args.spender.should.equal(spender);
|
||||
logs[0].args.value.should.be.bignumber.equal(amount);
|
||||
expectEvent.inLogs(logs, 'Approval', {
|
||||
owner: owner,
|
||||
spender: spender,
|
||||
value: amount
|
||||
});
|
||||
});
|
||||
|
||||
describe('when there was no approved amount before', function () {
|
||||
@ -194,11 +193,11 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
|
||||
it('emits a transfer event', async function () {
|
||||
const { logs } = await this.token.transferFrom(owner, to, amount, { from: spender });
|
||||
|
||||
logs.length.should.equal(1);
|
||||
logs[0].event.should.equal('Transfer');
|
||||
logs[0].args.from.should.equal(owner);
|
||||
logs[0].args.to.should.equal(to);
|
||||
logs[0].args.value.should.be.bignumber.equal(amount);
|
||||
expectEvent.inLogs(logs, 'Transfer', {
|
||||
from: owner,
|
||||
to: to,
|
||||
value: amount
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -269,11 +268,11 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
|
||||
it('emits an approval event', async function () {
|
||||
const { logs } = await this.token.decreaseAllowance(spender, approvedAmount, { from: owner });
|
||||
|
||||
logs.length.should.equal(1);
|
||||
logs[0].event.should.equal('Approval');
|
||||
logs[0].args.owner.should.equal(owner);
|
||||
logs[0].args.spender.should.equal(spender);
|
||||
logs[0].args.value.should.be.bignumber.equal(0);
|
||||
expectEvent.inLogs(logs, 'Approval', {
|
||||
owner: owner,
|
||||
spender: spender,
|
||||
value: 0
|
||||
});
|
||||
});
|
||||
|
||||
it('decreases the spender allowance subtracting the requested amount', async function () {
|
||||
@ -326,11 +325,11 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
|
||||
it('emits an approval event', async function () {
|
||||
const { logs } = await this.token.increaseAllowance(spender, amount, { from: owner });
|
||||
|
||||
logs.length.should.equal(1);
|
||||
logs[0].event.should.equal('Approval');
|
||||
logs[0].args.owner.should.equal(owner);
|
||||
logs[0].args.spender.should.equal(spender);
|
||||
logs[0].args.value.should.be.bignumber.equal(amount);
|
||||
expectEvent.inLogs(logs, 'Approval', {
|
||||
owner: owner,
|
||||
spender: spender,
|
||||
value: amount
|
||||
});
|
||||
});
|
||||
|
||||
describe('when there was no approved amount before', function () {
|
||||
@ -360,11 +359,11 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
|
||||
it('emits an approval event', async function () {
|
||||
const { logs } = await this.token.increaseAllowance(spender, amount, { from: owner });
|
||||
|
||||
logs.length.should.equal(1);
|
||||
logs[0].event.should.equal('Approval');
|
||||
logs[0].args.owner.should.equal(owner);
|
||||
logs[0].args.spender.should.equal(spender);
|
||||
logs[0].args.value.should.be.bignumber.equal(amount);
|
||||
expectEvent.inLogs(logs, 'Approval', {
|
||||
owner: owner,
|
||||
spender: spender,
|
||||
value: amount
|
||||
});
|
||||
});
|
||||
|
||||
describe('when there was no approved amount before', function () {
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
const expectEvent = require('../../helpers/expectEvent');
|
||||
const { assertRevert } = require('../../helpers/assertRevert');
|
||||
|
||||
const ERC20PausableMock = artifacts.require('ERC20PausableMock');
|
||||
@ -30,8 +31,7 @@ contract('ERC20Pausable', function ([_, pauser, otherPauser, recipient, anotherA
|
||||
it('emits a Pause event', async function () {
|
||||
const { logs } = await this.token.pause({ from });
|
||||
|
||||
logs.length.should.equal(1);
|
||||
logs[0].event.should.equal('Paused');
|
||||
expectEvent.inLogs(logs, 'Paused');
|
||||
});
|
||||
});
|
||||
|
||||
@ -72,8 +72,7 @@ contract('ERC20Pausable', function ([_, pauser, otherPauser, recipient, anotherA
|
||||
it('emits an Unpause event', async function () {
|
||||
const { logs } = await this.token.unpause({ from });
|
||||
|
||||
logs.length.should.equal(1);
|
||||
logs[0].event.should.equal('Unpaused');
|
||||
expectEvent.inLogs(logs, 'Unpaused');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -29,10 +29,11 @@ function shouldBehaveLikeERC20Burnable (owner, initialBalance, [burner]) {
|
||||
});
|
||||
|
||||
it('emits a transfer event', async function () {
|
||||
const event = expectEvent.inLogs(this.logs, 'Transfer');
|
||||
event.args.from.should.equal(owner);
|
||||
event.args.to.should.equal(ZERO_ADDRESS);
|
||||
event.args.value.should.be.bignumber.equal(amount);
|
||||
expectEvent.inLogs(this.logs, 'Transfer', {
|
||||
from: owner,
|
||||
to: ZERO_ADDRESS,
|
||||
value: amount
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
@ -74,10 +75,11 @@ function shouldBehaveLikeERC20Burnable (owner, initialBalance, [burner]) {
|
||||
});
|
||||
|
||||
it('emits a transfer event', async function () {
|
||||
const event = expectEvent.inLogs(this.logs, 'Transfer');
|
||||
event.args.from.should.equal(owner);
|
||||
event.args.to.should.equal(ZERO_ADDRESS);
|
||||
event.args.value.should.be.bignumber.equal(amount);
|
||||
expectEvent.inLogs(this.logs, 'Transfer', {
|
||||
from: owner,
|
||||
to: ZERO_ADDRESS,
|
||||
value: amount
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@ -34,11 +34,11 @@ function shouldBehaveLikeERC20Mintable (minter, [anyone]) {
|
||||
});
|
||||
|
||||
it('emits a mint and a transfer event', async function () {
|
||||
const transferEvent = expectEvent.inLogs(this.logs, 'Transfer', {
|
||||
expectEvent.inLogs(this.logs, 'Transfer', {
|
||||
from: ZERO_ADDRESS,
|
||||
to: anyone,
|
||||
value: amount
|
||||
});
|
||||
transferEvent.args.value.should.be.bignumber.equal(amount);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user