diff --git a/contracts/utils/test/safe_math.ts b/contracts/utils/test/safe_math.ts index d273767434..51ac43662b 100644 --- a/contracts/utils/test/safe_math.ts +++ b/contracts/utils/test/safe_math.ts @@ -10,7 +10,7 @@ chaiSetup.configure(); const expect = chai.expect; const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); -function toBN(a: number | string): BigNumber { +function toBigNumber(a: number | string): BigNumber { return new BigNumber(a); } @@ -29,18 +29,18 @@ describe('SafeMath', () => { describe('_safeMul', () => { it('should return zero if first argument is zero', async () => { - const result = await safeMath.externalSafeMul.callAsync(constants.ZERO_AMOUNT, toBN(1)); + const result = await safeMath.externalSafeMul.callAsync(constants.ZERO_AMOUNT, toBigNumber(1)); expect(result).bignumber.to.be.eq(constants.ZERO_AMOUNT); }); it('should return zero if second argument is zero', async () => { - const result = await safeMath.externalSafeMul.callAsync(toBN(1), constants.ZERO_AMOUNT); + const result = await safeMath.externalSafeMul.callAsync(toBigNumber(1), constants.ZERO_AMOUNT); expect(result).bignumber.to.be.eq(constants.ZERO_AMOUNT); }); it('should revert if the multiplication overflows', async () => { - const a = toBN('0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'); // The largest uint256 number - const b = toBN(2); + const a = toBigNumber('0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'); // The largest uint256 number + const b = toBigNumber(2); const expectedError = new SafeMathRevertErrors.SafeMathError( SafeMathRevertErrors.SafeMathErrorCodes.Uint256MultiplicationOverflow, a, @@ -50,35 +50,35 @@ describe('SafeMath', () => { }); it("should calculate correct value for values that don't overflow", async () => { - const result = await safeMath.externalSafeMul.callAsync(toBN(15), toBN(13)); - expect(result).bignumber.to.be.eq(toBN(195)); + const result = await safeMath.externalSafeMul.callAsync(toBigNumber(15), toBigNumber(13)); + expect(result).bignumber.to.be.eq(toBigNumber(195)); }); }); describe('_safeDiv', () => { it('should return the correct value if both values are the same', async () => { - const result = await safeMath.externalSafeDiv.callAsync(toBN(1), toBN(1)); - expect(result).bignumber.to.be.eq(toBN(1)); + const result = await safeMath.externalSafeDiv.callAsync(toBigNumber(1), toBigNumber(1)); + expect(result).bignumber.to.be.eq(toBigNumber(1)); }); it('should return the correct value if the values are different', async () => { - const result = await safeMath.externalSafeDiv.callAsync(toBN(3), toBN(2)); - expect(result).bignumber.to.be.eq(toBN(1)); + const result = await safeMath.externalSafeDiv.callAsync(toBigNumber(3), toBigNumber(2)); + expect(result).bignumber.to.be.eq(toBigNumber(1)); }); it('should return zero if the numerator is smaller than the denominator', async () => { - const result = await safeMath.externalSafeDiv.callAsync(toBN(2), toBN(3)); + const result = await safeMath.externalSafeDiv.callAsync(toBigNumber(2), toBigNumber(3)); expect(result).bignumber.to.be.eq(constants.ZERO_AMOUNT); }); it('should return zero if first argument is zero', async () => { - const result = await safeMath.externalSafeDiv.callAsync(constants.ZERO_AMOUNT, toBN(1)); + const result = await safeMath.externalSafeDiv.callAsync(constants.ZERO_AMOUNT, toBigNumber(1)); expect(result).bignumber.to.be.eq(constants.ZERO_AMOUNT); }); it('should revert if second argument is zero', async () => { const errMessage = 'VM Exception while processing transaction: invalid opcode'; - return expect(safeMath.externalSafeDiv.callAsync(toBN(1), constants.ZERO_AMOUNT)).to.be.rejectedWith( + return expect(safeMath.externalSafeDiv.callAsync(toBigNumber(1), constants.ZERO_AMOUNT)).to.be.rejectedWith( errMessage, ); }); @@ -86,8 +86,8 @@ describe('SafeMath', () => { describe('_safeSub', () => { it('should revert if the subtraction underflows', async () => { - const a = toBN(0); - const b = toBN(1); + const a = toBigNumber(0); + const b = toBigNumber(1); const expectedError = new SafeMathRevertErrors.SafeMathError( SafeMathRevertErrors.SafeMathErrorCodes.Uint256SubtractionUnderflow, a, @@ -102,15 +102,15 @@ describe('SafeMath', () => { }); it('should calculate correct value for values that are not equal', async () => { - const result = await safeMath.externalSafeSub.callAsync(toBN(15), toBN(13)); - expect(result).bignumber.to.be.eq(toBN(2)); + const result = await safeMath.externalSafeSub.callAsync(toBigNumber(15), toBigNumber(13)); + expect(result).bignumber.to.be.eq(toBigNumber(2)); }); }); describe('_safeAdd', () => { it('should revert if the addition overflows', async () => { - const a = toBN('0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'); // The largest uint256 number - const b = toBN(1); + const a = toBigNumber('0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'); // The largest uint256 number + const b = toBigNumber(1); const expectedError = new SafeMathRevertErrors.SafeMathError( SafeMathRevertErrors.SafeMathErrorCodes.Uint256AdditionOverflow, a, @@ -120,25 +120,25 @@ describe('SafeMath', () => { }); it('should calculate correct value if addition does not overflow', async () => { - const result = await safeMath.externalSafeAdd.callAsync(toBN(15), toBN(13)); - expect(result).bignumber.to.be.eq(toBN(28)); + const result = await safeMath.externalSafeAdd.callAsync(toBigNumber(15), toBigNumber(13)); + expect(result).bignumber.to.be.eq(toBigNumber(28)); }); it('should calculate correct value if first argument is zero', async () => { - const result = await safeMath.externalSafeAdd.callAsync(constants.ZERO_AMOUNT, toBN(13)); - expect(result).bignumber.to.be.eq(toBN(13)); + const result = await safeMath.externalSafeAdd.callAsync(constants.ZERO_AMOUNT, toBigNumber(13)); + expect(result).bignumber.to.be.eq(toBigNumber(13)); }); it('should calculate correct value if second argument is zero', async () => { - const result = await safeMath.externalSafeAdd.callAsync(toBN(13), constants.ZERO_AMOUNT); - expect(result).bignumber.to.be.eq(toBN(13)); + const result = await safeMath.externalSafeAdd.callAsync(toBigNumber(13), constants.ZERO_AMOUNT); + expect(result).bignumber.to.be.eq(toBigNumber(13)); }); }); describe('_maxUint256', () => { it('should return first argument if it is greater than the second', async () => { - const result = await safeMath.externalMaxUint256.callAsync(toBN(13), constants.ZERO_AMOUNT); - expect(result).bignumber.to.be.eq(toBN(13)); + const result = await safeMath.externalMaxUint256.callAsync(toBigNumber(13), constants.ZERO_AMOUNT); + expect(result).bignumber.to.be.eq(toBigNumber(13)); }); it('should return first argument if it is equal the second', async () => { @@ -147,15 +147,15 @@ describe('SafeMath', () => { }); it('should return second argument if it is greater than the first', async () => { - const result = await safeMath.externalMaxUint256.callAsync(constants.ZERO_AMOUNT, toBN(13)); - expect(result).bignumber.to.be.eq(toBN(13)); + const result = await safeMath.externalMaxUint256.callAsync(constants.ZERO_AMOUNT, toBigNumber(13)); + expect(result).bignumber.to.be.eq(toBigNumber(13)); }); }); describe('_minUint256', () => { it('should return first argument if it is less than the second', async () => { - const result = await safeMath.externalMaxUint256.callAsync(constants.ZERO_AMOUNT, toBN(13)); - expect(result).bignumber.to.be.eq(toBN(13)); + const result = await safeMath.externalMaxUint256.callAsync(constants.ZERO_AMOUNT, toBigNumber(13)); + expect(result).bignumber.to.be.eq(toBigNumber(13)); }); it('should return first argument if it is equal the second', async () => { @@ -164,8 +164,8 @@ describe('SafeMath', () => { }); it('should return second argument if it is less than the first', async () => { - const result = await safeMath.externalMaxUint256.callAsync(toBN(13), constants.ZERO_AMOUNT); - expect(result).bignumber.to.be.eq(toBN(13)); + const result = await safeMath.externalMaxUint256.callAsync(toBigNumber(13), constants.ZERO_AMOUNT); + expect(result).bignumber.to.be.eq(toBigNumber(13)); }); }); });