BigNumber comparison improved (#1581)
* signing prefix added * Minor improvement * Successfully tested * Minor improvements * Minor improvements * Revert "Dangling commas are now required. (#1359)" This reverts commita6889776f4. * 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 commit230b27214f.
This commit is contained in:
committed by
Francisco Giordano
parent
63ce358f30
commit
350aae09d2
@ -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 () {
|
||||
|
||||
@ -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 () {
|
||||
|
||||
@ -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 () {
|
||||
|
||||
@ -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 () {
|
||||
|
||||
@ -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 () {
|
||||
|
||||
@ -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');
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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 () {
|
||||
@ -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);
|
||||
});
|
||||
};
|
||||
|
||||
@ -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]);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@ const { shouldSupportInterfaces } = require('../../introspection/SupportsInterfa
|
||||
|
||||
const ERC721FullMock = artifacts.require('ERC721FullMock.sol');
|
||||
|
||||
require('../../helpers/setup');
|
||||
const { BigNumber } = require('../../helpers/setup');
|
||||
|
||||
contract('ERC721Full', function ([
|
||||
creator,
|
||||
@ -12,10 +12,10 @@ contract('ERC721Full', function ([
|
||||
]) {
|
||||
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;
|
||||
|
||||
@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
@ -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));
|
||||
});
|
||||
});
|
||||
@ -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));
|
||||
});
|
||||
});
|
||||
@ -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 () {
|
||||
@ -173,14 +173,14 @@ 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))
|
||||
@ -188,7 +188,7 @@ contract('ERC721Full', function ([
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user