aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/test/exchange/internal.ts
diff options
context:
space:
mode:
authorRemco Bloemen <remco@wicked.ventures>2018-08-24 06:19:29 +0800
committerRemco Bloemen <remco@wicked.ventures>2018-08-25 05:09:51 +0800
commit7f78d7da9dd13d1f0068a292bcd1ee3c5439d5a8 (patch)
tree9711ad39a1ed8d1827f0d8c234e0a8cce07f2d12 /packages/contracts/test/exchange/internal.ts
parent6734f2f1bcdab8f0d50524a26195707da00bd8ed (diff)
downloaddexon-sol-tools-7f78d7da9dd13d1f0068a292bcd1ee3c5439d5a8.tar
dexon-sol-tools-7f78d7da9dd13d1f0068a292bcd1ee3c5439d5a8.tar.gz
dexon-sol-tools-7f78d7da9dd13d1f0068a292bcd1ee3c5439d5a8.tar.bz2
dexon-sol-tools-7f78d7da9dd13d1f0068a292bcd1ee3c5439d5a8.tar.lz
dexon-sol-tools-7f78d7da9dd13d1f0068a292bcd1ee3c5439d5a8.tar.xz
dexon-sol-tools-7f78d7da9dd13d1f0068a292bcd1ee3c5439d5a8.tar.zst
dexon-sol-tools-7f78d7da9dd13d1f0068a292bcd1ee3c5439d5a8.zip
Add tests
Diffstat (limited to 'packages/contracts/test/exchange/internal.ts')
-rw-r--r--packages/contracts/test/exchange/internal.ts43
1 files changed, 43 insertions, 0 deletions
diff --git a/packages/contracts/test/exchange/internal.ts b/packages/contracts/test/exchange/internal.ts
index 48e1e620c..0c6ab3707 100644
--- a/packages/contracts/test/exchange/internal.ts
+++ b/packages/contracts/test/exchange/internal.ts
@@ -294,6 +294,49 @@ describe('Exchange core internal functions', () => {
);
});
+ describe('isRoundingErrorCeil', async () => {
+ async function referenceIsRoundingErrorAsync(
+ numerator: BigNumber,
+ denominator: BigNumber,
+ target: BigNumber,
+ ): Promise<boolean> {
+ if (denominator.eq(0)) {
+ throw divisionByZeroErrorForCall;
+ }
+ if (numerator.eq(0)) {
+ return false;
+ }
+ if (target.eq(0)) {
+ return false;
+ }
+ const product = numerator.mul(target);
+ const remainder = product.mod(denominator);
+ const error = denominator.sub(remainder).mod(denominator);
+ const errorTimes1000 = error.mul('1000');
+ const isError = errorTimes1000.gt(product);
+ if (product.greaterThan(MAX_UINT256)) {
+ throw overflowErrorForCall;
+ }
+ if (errorTimes1000.greaterThan(MAX_UINT256)) {
+ throw overflowErrorForCall;
+ }
+ return isError;
+ }
+ async function testIsRoundingErrorCeilAsync(
+ numerator: BigNumber,
+ denominator: BigNumber,
+ target: BigNumber,
+ ): Promise<boolean> {
+ return testExchange.publicIsRoundingErrorCeil.callAsync(numerator, denominator, target);
+ }
+ await testCombinatoriallyWithReferenceFuncAsync(
+ 'isRoundingErrorCeil',
+ referenceIsRoundingErrorAsync,
+ testIsRoundingErrorCeilAsync,
+ [uint256Values, uint256Values, uint256Values],
+ );
+ });
+
describe('updateFilledState', async () => {
// Note(albrow): Since updateFilledState modifies the state by calling
// sendTransaction, we must reset the state after each test.