Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace chai.should with chai.expect #1780

Merged
merged 9 commits into from
Jun 24, 2019
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contracts/utils/Address.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pragma solidity ^0.5.0;

/**
* @dev Collection of functions related to the address type,
* @dev Collection of functions related to the address type
*/
library Address {
/**
Expand Down
18 changes: 6 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 9 additions & 7 deletions test/access/Roles.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const { expectRevert, constants } = require('openzeppelin-test-helpers');
const { ZERO_ADDRESS } = constants;

const { expect } = require('chai');

const RolesMock = artifacts.require('RolesMock');

contract('Roles', function ([_, authorized, otherAuthorized, other]) {
Expand All @@ -14,16 +16,16 @@ contract('Roles', function ([_, authorized, otherAuthorized, other]) {

context('initially', function () {
it('doesn\'t pre-assign roles', async function () {
(await this.roles.has(authorized)).should.equal(false);
(await this.roles.has(otherAuthorized)).should.equal(false);
(await this.roles.has(other)).should.equal(false);
expect(await this.roles.has(authorized)).to.equal(false);
expect(await this.roles.has(otherAuthorized)).to.equal(false);
expect(await this.roles.has(other)).to.equal(false);
});

describe('adding roles', function () {
it('adds roles to a single account', async function () {
await this.roles.add(authorized);
(await this.roles.has(authorized)).should.equal(true);
(await this.roles.has(other)).should.equal(false);
expect(await this.roles.has(authorized)).to.equal(true);
expect(await this.roles.has(other)).to.equal(false);
});

it('reverts when adding roles to an already assigned account', async function () {
Expand All @@ -46,8 +48,8 @@ contract('Roles', function ([_, authorized, otherAuthorized, other]) {
describe('removing roles', function () {
it('removes a single role', async function () {
await this.roles.remove(authorized);
(await this.roles.has(authorized)).should.equal(false);
(await this.roles.has(otherAuthorized)).should.equal(true);
expect(await this.roles.has(authorized)).to.equal(false);
expect(await this.roles.has(otherAuthorized)).to.equal(true);
});

it('reverts when removing unassigned roles', async function () {
Expand Down
16 changes: 9 additions & 7 deletions test/behaviors/access/roles/PublicRole.behavior.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const { expectRevert, constants, expectEvent } = require('openzeppelin-test-helpers');
const { ZERO_ADDRESS } = constants;

const { expect } = require('chai');

function capitalize (str) {
return str.replace(/\b\w/g, l => l.toUpperCase());
}
Expand All @@ -25,9 +27,9 @@ function shouldBehaveLikePublicRole (authorized, otherAuthorized, [other], rolen

describe('should behave like public role', function () {
beforeEach('check preconditions', async function () {
(await this.contract[`is${rolename}`](authorized)).should.equal(true);
(await this.contract[`is${rolename}`](otherAuthorized)).should.equal(true);
(await this.contract[`is${rolename}`](other)).should.equal(false);
expect(await this.contract[`is${rolename}`](authorized)).to.equal(true);
expect(await this.contract[`is${rolename}`](otherAuthorized)).to.equal(true);
expect(await this.contract[`is${rolename}`](other)).to.equal(false);
});

if (manager === undefined) { // Managed roles are only assigned by the manager, and none are set at construction
Expand Down Expand Up @@ -70,7 +72,7 @@ function shouldBehaveLikePublicRole (authorized, otherAuthorized, [other], rolen
context(`from ${manager ? 'the manager' : 'a role-haver'} account`, function () {
it('adds role to a new account', async function () {
await this.contract[`add${rolename}`](other, { from });
(await this.contract[`is${rolename}`](other)).should.equal(true);
expect(await this.contract[`is${rolename}`](other)).to.equal(true);
});

it(`emits a ${rolename}Added event`, async function () {
Expand Down Expand Up @@ -99,8 +101,8 @@ function shouldBehaveLikePublicRole (authorized, otherAuthorized, [other], rolen
context(`from ${manager ? 'the manager' : 'any'} account`, function () {
it('removes role from an already assigned account', async function () {
await this.contract[`remove${rolename}`](authorized, { from });
(await this.contract[`is${rolename}`](authorized)).should.equal(false);
(await this.contract[`is${rolename}`](otherAuthorized)).should.equal(true);
expect(await this.contract[`is${rolename}`](authorized)).to.equal(false);
expect(await this.contract[`is${rolename}`](otherAuthorized)).to.equal(true);
});

it(`emits a ${rolename}Removed event`, async function () {
Expand All @@ -125,7 +127,7 @@ function shouldBehaveLikePublicRole (authorized, otherAuthorized, [other], rolen
describe('renouncing roles', function () {
it('renounces an assigned role', async function () {
await this.contract[`renounce${rolename}`]({ from: authorized });
(await this.contract[`is${rolename}`](authorized)).should.equal(false);
expect(await this.contract[`is${rolename}`](authorized)).to.equal(false);
});

it(`emits a ${rolename}Removed event`, async function () {
Expand Down
12 changes: 7 additions & 5 deletions test/crowdsale/AllowanceCrowdsale.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const { balance, BN, constants, ether, expectEvent, expectRevert } = require('openzeppelin-test-helpers');
const { ZERO_ADDRESS } = constants;

const { expect } = require('chai');

const AllowanceCrowdsaleImpl = artifacts.require('AllowanceCrowdsaleImpl');
const SimpleToken = artifacts.require('SimpleToken');

Expand All @@ -18,7 +20,7 @@ contract('AllowanceCrowdsale', function ([_, investor, wallet, purchaser, tokenW

describe('accepting payments', function () {
it('should have token wallet', async function () {
(await this.crowdsale.tokenWallet()).should.be.equal(tokenWallet);
expect(await this.crowdsale.tokenWallet()).to.equal(tokenWallet);
});

it('should accept sends', async function () {
Expand All @@ -43,21 +45,21 @@ contract('AllowanceCrowdsale', function ([_, investor, wallet, purchaser, tokenW

it('should assign tokens to sender', async function () {
await this.crowdsale.sendTransaction({ value: value, from: investor });
(await this.token.balanceOf(investor)).should.be.bignumber.equal(expectedTokenAmount);
expect(await this.token.balanceOf(investor)).to.be.bignumber.equal(expectedTokenAmount);
});

it('should forward funds to wallet', async function () {
const balanceTracker = await balance.tracker(wallet);
await this.crowdsale.sendTransaction({ value, from: investor });
(await balanceTracker.delta()).should.be.bignumber.equal(value);
expect(await balanceTracker.delta()).to.be.bignumber.equal(value);
});
});

describe('check remaining allowance', function () {
it('should report correct allowance left', async function () {
const remainingAllowance = tokenAllowance.sub(expectedTokenAmount);
await this.crowdsale.buyTokens(investor, { value: value, from: purchaser });
(await this.crowdsale.remainingTokens()).should.be.bignumber.equal(remainingAllowance);
expect(await this.crowdsale.remainingTokens()).to.be.bignumber.equal(remainingAllowance);
});

context('when the allowance is larger than the token amount', function () {
Expand All @@ -67,7 +69,7 @@ contract('AllowanceCrowdsale', function ([_, investor, wallet, purchaser, tokenW
});

it('should report the amount instead of the allowance', async function () {
(await this.crowdsale.remainingTokens()).should.be.bignumber.equal(await this.token.balanceOf(tokenWallet));
expect(await this.crowdsale.remainingTokens()).to.be.bignumber.equal(await this.token.balanceOf(tokenWallet));
});
});
});
Expand Down
8 changes: 5 additions & 3 deletions test/crowdsale/CappedCrowdsale.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const { BN, ether, expectRevert } = require('openzeppelin-test-helpers');

const { expect } = require('chai');

const CappedCrowdsaleImpl = artifacts.require('CappedCrowdsaleImpl');
const SimpleToken = artifacts.require('SimpleToken');

Expand Down Expand Up @@ -44,17 +46,17 @@ contract('CappedCrowdsale', function ([_, wallet]) {
describe('ending', function () {
it('should not reach cap if sent under cap', async function () {
await this.crowdsale.send(lessThanCap);
(await this.crowdsale.capReached()).should.equal(false);
expect(await this.crowdsale.capReached()).to.equal(false);
});

it('should not reach cap if sent just under cap', async function () {
await this.crowdsale.send(cap.subn(1));
(await this.crowdsale.capReached()).should.equal(false);
expect(await this.crowdsale.capReached()).to.equal(false);
});

it('should reach cap if cap sent', async function () {
await this.crowdsale.send(cap);
(await this.crowdsale.capReached()).should.equal(true);
expect(await this.crowdsale.capReached()).to.equal(true);
});
});
});
Expand Down
10 changes: 6 additions & 4 deletions test/crowdsale/Crowdsale.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const { balance, BN, constants, ether, expectEvent, expectRevert } = require('openzeppelin-test-helpers');
const { ZERO_ADDRESS } = constants;

const { expect } = require('chai');

const Crowdsale = artifacts.require('CrowdsaleMock');
const SimpleToken = artifacts.require('SimpleToken');

Expand Down Expand Up @@ -86,13 +88,13 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) {

it('should assign tokens to sender', async function () {
await this.crowdsale.sendTransaction({ value: value, from: investor });
(await this.token.balanceOf(investor)).should.be.bignumber.equal(expectedTokenAmount);
expect(await this.token.balanceOf(investor)).to.be.bignumber.equal(expectedTokenAmount);
});

it('should forward funds to wallet', async function () {
const balanceTracker = await balance.tracker(wallet);
await this.crowdsale.sendTransaction({ value, from: investor });
(await balanceTracker.delta()).should.be.bignumber.equal(value);
expect(await balanceTracker.delta()).to.be.bignumber.equal(value);
});
});

Expand All @@ -109,13 +111,13 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) {

it('should assign tokens to beneficiary', async function () {
await this.crowdsale.buyTokens(investor, { value, from: purchaser });
(await this.token.balanceOf(investor)).should.be.bignumber.equal(expectedTokenAmount);
expect(await this.token.balanceOf(investor)).to.be.bignumber.equal(expectedTokenAmount);
});

it('should forward funds to wallet', async function () {
const balanceTracker = await balance.tracker(wallet);
await this.crowdsale.buyTokens(investor, { value, from: purchaser });
(await balanceTracker.delta()).should.be.bignumber.equal(value);
expect(await balanceTracker.delta()).to.be.bignumber.equal(value);
});
});
});
Expand Down
24 changes: 13 additions & 11 deletions test/crowdsale/IncreasingPriceCrowdsale.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const { BN, ether, expectRevert, time } = require('openzeppelin-test-helpers');

const { expect } = require('chai');

const IncreasingPriceCrowdsaleImpl = artifacts.require('IncreasingPriceCrowdsaleImpl');
const SimpleToken = artifacts.require('SimpleToken');

Expand Down Expand Up @@ -52,8 +54,8 @@ contract('IncreasingPriceCrowdsale', function ([_, investor, wallet, purchaser])
});

it('should have initial and final rate', async function () {
(await this.crowdsale.initialRate()).should.be.bignumber.equal(initialRate);
(await this.crowdsale.finalRate()).should.be.bignumber.equal(finalRate);
expect(await this.crowdsale.initialRate()).to.be.bignumber.equal(initialRate);
expect(await this.crowdsale.finalRate()).to.be.bignumber.equal(finalRate);
});

it('reverts when the base Crowdsale\'s rate function is called', async function () {
Expand All @@ -63,54 +65,54 @@ contract('IncreasingPriceCrowdsale', function ([_, investor, wallet, purchaser])
});

it('returns a rate of 0 before the crowdsale starts', async function () {
(await this.crowdsale.getCurrentRate()).should.be.bignumber.equal('0');
expect(await this.crowdsale.getCurrentRate()).to.be.bignumber.equal('0');
});

it('returns a rate of 0 after the crowdsale ends', async function () {
await time.increaseTo(this.afterClosingTime);
(await this.crowdsale.getCurrentRate()).should.be.bignumber.equal('0');
expect(await this.crowdsale.getCurrentRate()).to.be.bignumber.equal('0');
});

it('at start', async function () {
await time.increaseTo(this.startTime);
await this.crowdsale.buyTokens(investor, { value, from: purchaser });
(await this.token.balanceOf(investor)).should.be.bignumber.equal(value.mul(initialRate));
expect(await this.token.balanceOf(investor)).to.be.bignumber.equal(value.mul(initialRate));
});

it('at time 150', async function () {
await time.increaseTo(this.startTime.addn(150));
await this.crowdsale.buyTokens(investor, { value, from: purchaser });
(await this.token.balanceOf(investor)).should.be.bignumber.equal(value.mul(rateAtTime150));
expect(await this.token.balanceOf(investor)).to.be.bignumber.equal(value.mul(rateAtTime150));
});

it('at time 300', async function () {
await time.increaseTo(this.startTime.addn(300));
await this.crowdsale.buyTokens(investor, { value, from: purchaser });
(await this.token.balanceOf(investor)).should.be.bignumber.equal(value.mul(rateAtTime300));
expect(await this.token.balanceOf(investor)).to.be.bignumber.equal(value.mul(rateAtTime300));
});

it('at time 1500', async function () {
await time.increaseTo(this.startTime.addn(1500));
await this.crowdsale.buyTokens(investor, { value, from: purchaser });
(await this.token.balanceOf(investor)).should.be.bignumber.equal(value.mul(rateAtTime1500));
expect(await this.token.balanceOf(investor)).to.be.bignumber.equal(value.mul(rateAtTime1500));
});

it('at time 30', async function () {
await time.increaseTo(this.startTime.addn(30));
await this.crowdsale.buyTokens(investor, { value, from: purchaser });
(await this.token.balanceOf(investor)).should.be.bignumber.equal(value.mul(rateAtTime30));
expect(await this.token.balanceOf(investor)).to.be.bignumber.equal(value.mul(rateAtTime30));
});

it('at time 150000', async function () {
await time.increaseTo(this.startTime.addn(150000));
await this.crowdsale.buyTokens(investor, { value, from: purchaser });
(await this.token.balanceOf(investor)).should.be.bignumber.equal(value.mul(rateAtTime150000));
expect(await this.token.balanceOf(investor)).to.be.bignumber.equal(value.mul(rateAtTime150000));
});

it('at time 450000', async function () {
await time.increaseTo(this.startTime.addn(450000));
await this.crowdsale.buyTokens(investor, { value, from: purchaser });
(await this.token.balanceOf(investor)).should.be.bignumber.equal(value.mul(rateAtTime450000));
expect(await this.token.balanceOf(investor)).to.be.bignumber.equal(value.mul(rateAtTime450000));
});
});
});
Expand Down
Loading