Commit 350aae09 by Aniket Committed by Francisco Giordano

BigNumber comparison improved (#1581)

* signing prefix added

* Minor improvement

* Successfully tested

* Minor improvements

* Minor improvements

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

This reverts commit a6889776.

* 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 230b27214fc96ab4c990b169bbc15df129bad657.
parent 63ce358f
...@@ -2,10 +2,7 @@ const { balanceDifference } = require('../balanceDifference'); ...@@ -2,10 +2,7 @@ const { balanceDifference } = require('../balanceDifference');
const send = require('../send'); const send = require('../send');
const { ether } = require('../ether'); const { ether } = require('../ether');
const BigNumber = web3.BigNumber; require('../setup');
require('chai')
.use(require('chai-bignumber')(BigNumber))
.should();
contract('balanceDifference', function ([sender, receiver]) { contract('balanceDifference', function ([sender, receiver]) {
it('returns balance increments', async function () { it('returns balance increments', async function () {
......
const { ether } = require('../ether'); const { ether } = require('../ether');
const BigNumber = web3.BigNumber; const { BigNumber } = require('../setup');
require('chai')
.use(require('chai-bignumber')(BigNumber))
.should();
describe('ether', function () { describe('ether', function () {
it('returns a BigNumber', function () { it('returns a BigNumber', function () {
......
...@@ -4,7 +4,7 @@ const shouldFail = require('../shouldFail'); ...@@ -4,7 +4,7 @@ const shouldFail = require('../shouldFail');
const EventEmitter = artifacts.require('EventEmitter'); const EventEmitter = artifacts.require('EventEmitter');
const IndirectEventEmitter = artifacts.require('IndirectEventEmitter'); const IndirectEventEmitter = artifacts.require('IndirectEventEmitter');
const { should, BigNumber } = require('../../helpers/setup'); const { should, BigNumber } = require('../setup');
describe('expectEvent', function () { describe('expectEvent', function () {
beforeEach(async function () { beforeEach(async function () {
......
...@@ -2,8 +2,7 @@ const { makeInterfaceId } = require('../makeInterfaceId'); ...@@ -2,8 +2,7 @@ const { makeInterfaceId } = require('../makeInterfaceId');
const OwnableInterfaceId = artifacts.require('OwnableInterfaceId'); const OwnableInterfaceId = artifacts.require('OwnableInterfaceId');
require('chai') require('../setup');
.should();
describe('makeInterfaceId', function () { describe('makeInterfaceId', function () {
it('calculates the EIP165 interface id from function signatures', async function () { it('calculates the EIP165 interface id from function signatures', async function () {
......
...@@ -6,10 +6,7 @@ const { ethGetBalance } = require('../web3'); ...@@ -6,10 +6,7 @@ const { ethGetBalance } = require('../web3');
const Acknowledger = artifacts.require('Acknowledger'); const Acknowledger = artifacts.require('Acknowledger');
const BigNumber = web3.BigNumber; require('../setup');
require('chai')
.use(require('chai-bignumber')(BigNumber))
.should();
contract('send', function ([sender, receiver]) { contract('send', function ([sender, receiver]) {
describe('ether', function () { describe('ether', function () {
......
const shouldFail = require('../shouldFail'); const shouldFail = require('../shouldFail');
const BigNumber = web3.BigNumber; const { should } = require('../setup');
const should = require('chai')
.use(require('chai-bignumber')(BigNumber))
.should();
const Failer = artifacts.require('Failer'); const Failer = artifacts.require('Failer');
......
const time = require('../time'); const time = require('../time');
const shouldFail = require('../shouldFail'); const shouldFail = require('../shouldFail');
const BigNumber = web3.BigNumber; require('../setup');
require('chai')
.use(require('chai-bignumber')(BigNumber))
.should();
describe('time', function () { describe('time', function () {
const TOLERANCE_SECONDS = 1; const TOLERANCE_SECONDS = 1;
......
...@@ -3,8 +3,8 @@ const MathMock = artifacts.require('MathMock'); ...@@ -3,8 +3,8 @@ const MathMock = artifacts.require('MathMock');
const { BigNumber } = require('../helpers/setup'); const { BigNumber } = require('../helpers/setup');
contract('Math', function () { contract('Math', function () {
const min = 1234; const min = new BigNumber(1234);
const max = 5678; const max = new BigNumber(5678);
beforeEach(async function () { beforeEach(async function () {
this.math = await MathMock.new(); this.math = await MathMock.new();
......
...@@ -5,16 +5,16 @@ const { ZERO_ADDRESS } = require('../../helpers/constants'); ...@@ -5,16 +5,16 @@ const { ZERO_ADDRESS } = require('../../helpers/constants');
const send = require('../../helpers/send'); const send = require('../../helpers/send');
const ERC721ReceiverMock = artifacts.require('ERC721ReceiverMock.sol'); const ERC721ReceiverMock = artifacts.require('ERC721ReceiverMock.sol');
require('../../helpers/setup'); const { BigNumber } = require('../../helpers/setup');
function shouldBehaveLikeERC721 ( function shouldBehaveLikeERC721 (
creator, creator,
minter, minter,
[owner, approved, anotherApproved, operator, anyone] [owner, approved, anotherApproved, operator, anyone]
) { ) {
const firstTokenId = 1; const firstTokenId = new BigNumber(1);
const secondTokenId = 2; const secondTokenId = new BigNumber(2);
const unknownTokenId = 3; const unknownTokenId = new BigNumber(3);
const RECEIVER_MAGIC_VALUE = '0x150b7a02'; const RECEIVER_MAGIC_VALUE = '0x150b7a02';
describe('like an ERC721', function () { describe('like an ERC721', function () {
...@@ -107,9 +107,9 @@ function shouldBehaveLikeERC721 ( ...@@ -107,9 +107,9 @@ function shouldBehaveLikeERC721 (
it('adjusts owners tokens by index', async function () { it('adjusts owners tokens by index', async function () {
if (!this.token.tokenOfOwnerByIndex) return; 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);
}); });
}; };
...@@ -173,7 +173,7 @@ function shouldBehaveLikeERC721 ( ...@@ -173,7 +173,7 @@ function shouldBehaveLikeERC721 (
const tokensListed = await Promise.all( const tokensListed = await Promise.all(
[0, 1].map(i => this.token.tokenOfOwnerByIndex(owner, i)) [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]);
}); });
}); });
......
...@@ -4,7 +4,7 @@ const { shouldSupportInterfaces } = require('../../introspection/SupportsInterfa ...@@ -4,7 +4,7 @@ const { shouldSupportInterfaces } = require('../../introspection/SupportsInterfa
const ERC721FullMock = artifacts.require('ERC721FullMock.sol'); const ERC721FullMock = artifacts.require('ERC721FullMock.sol');
require('../../helpers/setup'); const { BigNumber } = require('../../helpers/setup');
contract('ERC721Full', function ([ contract('ERC721Full', function ([
creator, creator,
...@@ -12,10 +12,10 @@ contract('ERC721Full', function ([ ...@@ -12,10 +12,10 @@ contract('ERC721Full', function ([
]) { ]) {
const name = 'Non Fungible Token'; const name = 'Non Fungible Token';
const symbol = 'NFT'; const symbol = 'NFT';
const firstTokenId = 100; const firstTokenId = new BigNumber(100);
const secondTokenId = 200; const secondTokenId = new BigNumber(200);
const thirdTokenId = 300; const thirdTokenId = new BigNumber(300);
const nonExistentTokenId = 999; const nonExistentTokenId = new BigNumber(999);
const minter = creator; const minter = creator;
...@@ -41,11 +41,11 @@ contract('ERC721Full', function ([ ...@@ -41,11 +41,11 @@ contract('ERC721Full', function ([
}); });
it('adjusts owner tokens by index', async 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 () { 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);
}); });
}); });
...@@ -55,16 +55,16 @@ contract('ERC721Full', function ([ ...@@ -55,16 +55,16 @@ contract('ERC721Full', function ([
}); });
it('removes that token from the token list of the owner', async 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 () { 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 () { it('burns all tokens', async function () {
await this.token.burn(secondTokenId, { from: owner }); 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)); await shouldFail.reverting(this.token.tokenByIndex(0));
}); });
}); });
...@@ -145,15 +145,15 @@ contract('ERC721Full', function ([ ...@@ -145,15 +145,15 @@ contract('ERC721Full', function ([
}); });
it('returns correct token IDs for target', async 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( const tokensListed = await Promise.all(
[0, 1].map(i => this.token.tokenOfOwnerByIndex(another, i)) [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 () { 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)); await shouldFail.reverting(this.token.tokenOfOwnerByIndex(owner, 0));
}); });
}); });
...@@ -164,7 +164,7 @@ contract('ERC721Full', function ([ ...@@ -164,7 +164,7 @@ contract('ERC721Full', function ([
const tokensListed = await Promise.all( const tokensListed = await Promise.all(
[0, 1].map(i => this.token.tokenByIndex(i)) [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 () { it('should revert if index is greater than supply', async function () {
...@@ -173,14 +173,14 @@ contract('ERC721Full', function ([ ...@@ -173,14 +173,14 @@ contract('ERC721Full', function ([
[firstTokenId, secondTokenId].forEach(function (tokenId) { [firstTokenId, secondTokenId].forEach(function (tokenId) {
it(`should return all tokens after burning token ${tokenId} and minting new tokens`, async function () { it(`should return all tokens after burning token ${tokenId} and minting new tokens`, async function () {
const newTokenId = 300; const newTokenId = new BigNumber(300);
const anotherNewTokenId = 400; const anotherNewTokenId = new BigNumber(400);
await this.token.burn(tokenId, { from: owner }); await this.token.burn(tokenId, { from: owner });
await this.token.mint(newOwner, newTokenId, { from: minter }); await this.token.mint(newOwner, newTokenId, { from: minter });
await this.token.mint(newOwner, anotherNewTokenId, { 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( const tokensListed = await Promise.all(
[0, 1, 2].map(i => this.token.tokenByIndex(i)) [0, 1, 2].map(i => this.token.tokenByIndex(i))
...@@ -188,7 +188,7 @@ contract('ERC721Full', function ([ ...@@ -188,7 +188,7 @@ contract('ERC721Full', function ([
const expectedTokens = [firstTokenId, secondTokenId, newTokenId, anotherNewTokenId].filter( const expectedTokens = [firstTokenId, secondTokenId, newTokenId, anotherNewTokenId].filter(
x => (x !== tokenId) x => (x !== tokenId)
); );
tokensListed.map(t => t.toNumber()).should.have.members(expectedTokens); tokensListed.should.have.deep.members(expectedTokens);
}); });
}); });
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment