Skip to content

Commit

Permalink
BigNumber comparison improved (#1581)
Browse files Browse the repository at this point in the history
* signing prefix added

* Minor improvement

* Successfully tested

* Minor improvements

* Minor improvements

* Revert "Dangling commas are now required. (#1359)"

This reverts commit a688977.

* updates

* fixes #1404

* approve failing test

* suggested changes done

* ISafeERC20 removed

* conflict fixes

* added examples

* fixes #706

* linting

* fixes #204

* file fixing

* deep bignumber comparison removed

* Update SafeERC20Helper.sol

* Update IERC20.sol

* Update SafeERC20.sol

* Update package-lock.json

* Revert "deep bignumber comparison removed"

This reverts commit 230b272.
  • Loading branch information
Aniket-Engg authored and frangio committed Jan 4, 2019
1 parent 63ce358 commit 350aae0
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 50 deletions.
5 changes: 1 addition & 4 deletions test/helpers/test/balanceDifference.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ const { balanceDifference } = require('../balanceDifference');
const send = require('../send');
const { ether } = require('../ether');

const BigNumber = web3.BigNumber;
require('chai')
.use(require('chai-bignumber')(BigNumber))
.should();
require('../setup');

contract('balanceDifference', function ([sender, receiver]) {
it('returns balance increments', async function () {
Expand Down
5 changes: 1 addition & 4 deletions test/helpers/test/ether.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
const { ether } = require('../ether');

const BigNumber = web3.BigNumber;
require('chai')
.use(require('chai-bignumber')(BigNumber))
.should();
const { BigNumber } = require('../setup');

describe('ether', function () {
it('returns a BigNumber', function () {
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/test/expectEvent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const shouldFail = require('../shouldFail');
const EventEmitter = artifacts.require('EventEmitter');
const IndirectEventEmitter = artifacts.require('IndirectEventEmitter');

const { should, BigNumber } = require('../../helpers/setup');
const { should, BigNumber } = require('../setup');

describe('expectEvent', function () {
beforeEach(async function () {
Expand Down
3 changes: 1 addition & 2 deletions test/helpers/test/makeInterfaceId.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ const { makeInterfaceId } = require('../makeInterfaceId');

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

require('chai')
.should();
require('../setup');

describe('makeInterfaceId', function () {
it('calculates the EIP165 interface id from function signatures', async function () {
Expand Down
5 changes: 1 addition & 4 deletions test/helpers/test/send.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ const { ethGetBalance } = require('../web3');

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

const BigNumber = web3.BigNumber;
require('chai')
.use(require('chai-bignumber')(BigNumber))
.should();
require('../setup');

contract('send', function ([sender, receiver]) {
describe('ether', function () {
Expand Down
5 changes: 1 addition & 4 deletions test/helpers/test/shouldFail.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
const shouldFail = require('../shouldFail');

const BigNumber = web3.BigNumber;
const should = require('chai')
.use(require('chai-bignumber')(BigNumber))
.should();
const { should } = require('../setup');

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

Expand Down
5 changes: 1 addition & 4 deletions test/helpers/test/time.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
const time = require('../time');
const shouldFail = require('../shouldFail');

const BigNumber = web3.BigNumber;
require('chai')
.use(require('chai-bignumber')(BigNumber))
.should();
require('../setup');

describe('time', function () {
const TOLERANCE_SECONDS = 1;
Expand Down
4 changes: 2 additions & 2 deletions test/math/Math.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ const MathMock = artifacts.require('MathMock');
const { BigNumber } = require('../helpers/setup');

contract('Math', function () {
const min = 1234;
const max = 5678;
const min = new BigNumber(1234);
const max = new BigNumber(5678);

beforeEach(async function () {
this.math = await MathMock.new();
Expand Down
14 changes: 7 additions & 7 deletions test/token/ERC721/ERC721.behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ const { ZERO_ADDRESS } = require('../../helpers/constants');
const send = require('../../helpers/send');

const ERC721ReceiverMock = artifacts.require('ERC721ReceiverMock.sol');
require('../../helpers/setup');
const { BigNumber } = require('../../helpers/setup');

function shouldBehaveLikeERC721 (
creator,
minter,
[owner, approved, anotherApproved, operator, anyone]
) {
const firstTokenId = 1;
const secondTokenId = 2;
const unknownTokenId = 3;
const firstTokenId = new BigNumber(1);
const secondTokenId = new BigNumber(2);
const unknownTokenId = new BigNumber(3);
const RECEIVER_MAGIC_VALUE = '0x150b7a02';

describe('like an ERC721', function () {
Expand Down Expand Up @@ -107,9 +107,9 @@ function shouldBehaveLikeERC721 (
it('adjusts owners tokens by index', async function () {
if (!this.token.tokenOfOwnerByIndex) return;

(await this.token.tokenOfOwnerByIndex(this.toWhom, 0)).toNumber().should.be.equal(tokenId);
(await this.token.tokenOfOwnerByIndex(this.toWhom, 0)).should.be.bignumber.equal(tokenId);

(await this.token.tokenOfOwnerByIndex(owner, 0)).toNumber().should.not.be.equal(tokenId);
(await this.token.tokenOfOwnerByIndex(owner, 0)).should.not.be.bignumber.equal(tokenId);
});
};

Expand Down Expand Up @@ -173,7 +173,7 @@ function shouldBehaveLikeERC721 (
const tokensListed = await Promise.all(
[0, 1].map(i => this.token.tokenOfOwnerByIndex(owner, i))
);
tokensListed.map(t => t.toNumber()).should.have.members([firstTokenId, secondTokenId]);
tokensListed.should.have.deep.members([firstTokenId, secondTokenId]);
});
});

Expand Down
36 changes: 18 additions & 18 deletions test/token/ERC721/ERC721Full.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ const { shouldSupportInterfaces } = require('../../introspection/SupportsInterfa

const ERC721FullMock = artifacts.require('ERC721FullMock.sol');

require('../../helpers/setup');
const { BigNumber } = require('../../helpers/setup');

contract('ERC721Full', function ([
creator,
...accounts
]) {
const name = 'Non Fungible Token';
const symbol = 'NFT';
const firstTokenId = 100;
const secondTokenId = 200;
const thirdTokenId = 300;
const nonExistentTokenId = 999;
const firstTokenId = new BigNumber(100);
const secondTokenId = new BigNumber(200);
const thirdTokenId = new BigNumber(300);
const nonExistentTokenId = new BigNumber(999);

const minter = creator;

Expand All @@ -41,11 +41,11 @@ contract('ERC721Full', function ([
});

it('adjusts owner tokens by index', async function () {
(await this.token.tokenOfOwnerByIndex(newOwner, 0)).toNumber().should.be.equal(thirdTokenId);
(await this.token.tokenOfOwnerByIndex(newOwner, 0)).should.be.bignumber.equal(thirdTokenId);
});

it('adjusts all tokens list', async function () {
(await this.token.tokenByIndex(2)).toNumber().should.be.equal(thirdTokenId);
(await this.token.tokenByIndex(2)).should.be.bignumber.equal(thirdTokenId);
});
});

Expand All @@ -55,16 +55,16 @@ contract('ERC721Full', function ([
});

it('removes that token from the token list of the owner', async function () {
(await this.token.tokenOfOwnerByIndex(owner, 0)).toNumber().should.be.equal(secondTokenId);
(await this.token.tokenOfOwnerByIndex(owner, 0)).should.be.bignumber.equal(secondTokenId);
});

it('adjusts all tokens list', async function () {
(await this.token.tokenByIndex(0)).toNumber().should.be.equal(secondTokenId);
(await this.token.tokenByIndex(0)).should.be.bignumber.equal(secondTokenId);
});

it('burns all tokens', async function () {
await this.token.burn(secondTokenId, { from: owner });
(await this.token.totalSupply()).toNumber().should.be.equal(0);
(await this.token.totalSupply()).should.be.bignumber.equal(0);
await shouldFail.reverting(this.token.tokenByIndex(0));
});
});
Expand Down Expand Up @@ -145,15 +145,15 @@ contract('ERC721Full', function ([
});

it('returns correct token IDs for target', async function () {
(await this.token.balanceOf(another)).toNumber().should.be.equal(2);
(await this.token.balanceOf(another)).should.be.bignumber.equal(2);
const tokensListed = await Promise.all(
[0, 1].map(i => this.token.tokenOfOwnerByIndex(another, i))
);
tokensListed.map(t => t.toNumber()).should.have.members([firstTokenId, secondTokenId]);
tokensListed.should.have.deep.members([firstTokenId, secondTokenId]);
});

it('returns empty collection for original owner', async function () {
(await this.token.balanceOf(owner)).toNumber().should.be.equal(0);
(await this.token.balanceOf(owner)).should.be.bignumber.equal(0);
await shouldFail.reverting(this.token.tokenOfOwnerByIndex(owner, 0));
});
});
Expand All @@ -164,7 +164,7 @@ contract('ERC721Full', function ([
const tokensListed = await Promise.all(
[0, 1].map(i => this.token.tokenByIndex(i))
);
tokensListed.map(t => t.toNumber()).should.have.members([firstTokenId, secondTokenId]);
tokensListed.should.have.deep.members([firstTokenId, secondTokenId]);
});

it('should revert if index is greater than supply', async function () {
Expand All @@ -173,22 +173,22 @@ contract('ERC721Full', function ([

[firstTokenId, secondTokenId].forEach(function (tokenId) {
it(`should return all tokens after burning token ${tokenId} and minting new tokens`, async function () {
const newTokenId = 300;
const anotherNewTokenId = 400;
const newTokenId = new BigNumber(300);
const anotherNewTokenId = new BigNumber(400);

await this.token.burn(tokenId, { from: owner });
await this.token.mint(newOwner, newTokenId, { from: minter });
await this.token.mint(newOwner, anotherNewTokenId, { from: minter });

(await this.token.totalSupply()).toNumber().should.be.equal(3);
(await this.token.totalSupply()).should.be.bignumber.equal(3);

const tokensListed = await Promise.all(
[0, 1, 2].map(i => this.token.tokenByIndex(i))
);
const expectedTokens = [firstTokenId, secondTokenId, newTokenId, anotherNewTokenId].filter(
x => (x !== tokenId)
);
tokensListed.map(t => t.toNumber()).should.have.members(expectedTokens);
tokensListed.should.have.deep.members(expectedTokens);
});
});
});
Expand Down

0 comments on commit 350aae0

Please sign in to comment.