import * as mocha from 'mocha'; import * as chai from 'chai'; import {bigNumberValidation} from '../src/big-number-validation'; import BigNumber from 'bignumber.js'; const expect = chai.expect; /* tslint:disable:no-unused-expression */ describe('BigNumberVerification', () => { it('should convert a large number to BigNumber', () => { const tooLarge = 10000000000000000; const num = bigNumberValidation.valueToBigNumber(tooLarge); expect(num.toString()).to.equal('10000000000000000'); }); it('should convert a string to BigNumber', () => { const str = '123456'; const num = bigNumberValidation.valueToBigNumber(str); expect(num.toNumber()).to.equal(123456); }); it('should convert non-numeric to BigNumber', () => { const str = 'asd@#^&'; const num = bigNumberValidation.valueToBigNumber(str); expect(num.toNumber()).to.equal(0); }); it('should parse a non-number and return 0', () => { const undy = bigNumberValidation.valueToBigNumber(undefined); const nuuu = bigNumberValidation.valueToBigNumber(null); expect(undy.toNumber()).to.equal(0); expect(nuuu.toNumber()).to.equal(0); }); it('should parse a BigNumber', () => { const num = bigNumberValidation.valueToBigNumber(new BigNumber(20)); expect(num.toNumber()).to.equal(20); }); it('should reject a negative number', () => { expect(bigNumberValidation.isValidUint256('-1')).is.false; }); it('should reject a number larger than a uint256', () => { const biggestNum: string = '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'; expect(bigNumberValidation.isValidUint256(biggestNum)).is.false; }); it('should reject a number that isn\'t hex', () => { expect(bigNumberValidation.isValidUint256('0xZZZ')).is.false; }); it('should reject a number that is an empty string', () => { expect(bigNumberValidation.isValidUint256('')).is.false; }); it('should accept a number in base 10', () => { expect(bigNumberValidation.isValidNumber('10')).is.true; expect(bigNumberValidation.isBase10('10')).is.true; expect(bigNumberValidation.isValidUint256('10')).is.true; }); it('should accept a number in base 16', () => { expect(bigNumberValidation.isValidNumber('0xdeadbeefcafe')).is.true; expect(bigNumberValidation.isBase16('0xdeadbeefcafe')).is.true; expect(bigNumberValidation.isValidUint256('0xdeadbeefcafe')).is.true; }); });