diff options
author | Remco Bloemen <remco@wicked.ventures> | 2018-08-24 03:54:13 +0800 |
---|---|---|
committer | Remco Bloemen <remco@wicked.ventures> | 2018-08-25 04:45:10 +0800 |
commit | 4159e45aff14c04f2d799ec8a7b6e7f1a4894064 (patch) | |
tree | 5cfc878a54eb02aba47011bbc05ef7c175ccaf2e /packages/contracts/test/exchange/internal.ts | |
parent | 92497d7df4b61ee62acfdd58bfb98569ff67214e (diff) | |
download | dexon-sol-tools-4159e45aff14c04f2d799ec8a7b6e7f1a4894064.tar dexon-sol-tools-4159e45aff14c04f2d799ec8a7b6e7f1a4894064.tar.gz dexon-sol-tools-4159e45aff14c04f2d799ec8a7b6e7f1a4894064.tar.bz2 dexon-sol-tools-4159e45aff14c04f2d799ec8a7b6e7f1a4894064.tar.lz dexon-sol-tools-4159e45aff14c04f2d799ec8a7b6e7f1a4894064.tar.xz dexon-sol-tools-4159e45aff14c04f2d799ec8a7b6e7f1a4894064.tar.zst dexon-sol-tools-4159e45aff14c04f2d799ec8a7b6e7f1a4894064.zip |
Update tests
Diffstat (limited to 'packages/contracts/test/exchange/internal.ts')
-rw-r--r-- | packages/contracts/test/exchange/internal.ts | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/packages/contracts/test/exchange/internal.ts b/packages/contracts/test/exchange/internal.ts index 67d1d2d2c..0231cc3f1 100644 --- a/packages/contracts/test/exchange/internal.ts +++ b/packages/contracts/test/exchange/internal.ts @@ -63,6 +63,7 @@ describe('Exchange core internal functions', () => { let testExchange: TestExchangeInternalsContract; let invalidOpcodeErrorForCall: Error | undefined; let overflowErrorForSendTransaction: Error | undefined; + let divisionByZeroErrorForCall: Error | undefined; before(async () => { await blockchainLifecycle.startAsync(); @@ -79,6 +80,9 @@ describe('Exchange core internal functions', () => { overflowErrorForSendTransaction = new Error( await getRevertReasonOrErrorMessageForSendTransactionAsync(RevertReason.Uint256Overflow), ); + divisionByZeroErrorForCall = new Error( + await getRevertReasonOrErrorMessageForSendTransactionAsync(RevertReason.DivisionByZero), + ); invalidOpcodeErrorForCall = new Error(await getInvalidOpcodeErrorMessageForCallAsync()); }); // Note(albrow): Don't forget to add beforeEach and afterEach calls to reset @@ -215,26 +219,26 @@ describe('Exchange core internal functions', () => { denominator: BigNumber, target: BigNumber, ): Promise<boolean> { - const product = numerator.mul(target); if (denominator.eq(0)) { - throw invalidOpcodeErrorForCall; + throw divisionByZeroErrorForCall; } - const remainder = product.mod(denominator); - if (remainder.eq(0)) { + if (numerator.eq(0)) { + return false; + } + if (target.eq(0)) { return false; } + const product = numerator.mul(target); + const remainder = product.mod(denominator); + const remainderTimes1000 = remainder.mul('1000'); + const isError = remainderTimes1000.gt(product); if (product.greaterThan(MAX_UINT256)) { throw overflowErrorForCall; } - if (product.eq(0)) { - throw invalidOpcodeErrorForCall; - } - const remainderTimes1000000 = remainder.mul('1000000'); - if (remainderTimes1000000.greaterThan(MAX_UINT256)) { + if (remainderTimes1000.greaterThan(MAX_UINT256)) { throw overflowErrorForCall; } - const errPercentageTimes1000000 = remainderTimes1000000.dividedToIntegerBy(product); - return errPercentageTimes1000000.greaterThan('1000'); + return isError; } async function testIsRoundingErrorAsync( numerator: BigNumber, |