aboutsummaryrefslogtreecommitdiffstats
path: root/contracts
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2018-11-24 00:57:28 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2018-12-03 19:09:28 +0800
commitde39ec3c97217f675c6b670d24e4b9d080e4016a (patch)
tree1e6e674a49cfc7c2af5bc5a585dc1b8ef5d50e1b /contracts
parent665a85554852cb00608bed079ec0c87587aaed18 (diff)
downloaddexon-0x-contracts-de39ec3c97217f675c6b670d24e4b9d080e4016a.tar.gz
dexon-0x-contracts-de39ec3c97217f675c6b670d24e4b9d080e4016a.tar.zst
dexon-0x-contracts-de39ec3c97217f675c6b670d24e4b9d080e4016a.zip
Remove duplicates combinatorial utils from core contracts
Diffstat (limited to 'contracts')
-rw-r--r--contracts/core/test/exchange/internal.ts4
-rw-r--r--contracts/core/test/utils/combinatorial_utils.ts113
-rw-r--r--contracts/test-utils/src/index.ts1
3 files changed, 4 insertions, 114 deletions
diff --git a/contracts/core/test/exchange/internal.ts b/contracts/core/test/exchange/internal.ts
index cff8f630c..972f5efb6 100644
--- a/contracts/core/test/exchange/internal.ts
+++ b/contracts/core/test/exchange/internal.ts
@@ -1,10 +1,13 @@
import {
+ bytes32Values,
chaiSetup,
constants,
FillResults,
getRevertReasonOrErrorMessageForSendTransactionAsync,
provider,
+ testCombinatoriallyWithReferenceFuncAsync,
txDefaults,
+ uint256Values,
web3Wrapper,
} from '@0x/contracts-test-utils';
import { BlockchainLifecycle } from '@0x/dev-utils';
@@ -15,7 +18,6 @@ import * as _ from 'lodash';
import { TestExchangeInternalsContract } from '../../generated-wrappers/test_exchange_internals';
import { artifacts } from '../../src/artifacts';
-import { bytes32Values, testCombinatoriallyWithReferenceFuncAsync, uint256Values } from '../utils/combinatorial_utils';
chaiSetup.configure();
const expect = chai.expect;
diff --git a/contracts/core/test/utils/combinatorial_utils.ts b/contracts/core/test/utils/combinatorial_utils.ts
deleted file mode 100644
index d6e339f94..000000000
--- a/contracts/core/test/utils/combinatorial_utils.ts
+++ /dev/null
@@ -1,113 +0,0 @@
-import { BigNumber } from '@0x/utils';
-import * as combinatorics from 'js-combinatorics';
-
-import { testWithReferenceFuncAsync } from '@0x/contracts-test-utils';
-
-// A set of values corresponding to the uint256 type in Solidity. This set
-// contains some notable edge cases, including some values which will overflow
-// the uint256 type when used in different mathematical operations.
-export const uint256Values = [
- new BigNumber(0),
- new BigNumber(1),
- new BigNumber(2),
- // Non-trivial big number.
- new BigNumber(2).pow(64),
- // Max that does not overflow when squared.
- new BigNumber(2).pow(128).minus(1),
- // Min that does overflow when squared.
- new BigNumber(2).pow(128),
- // Max that does not overflow when doubled.
- new BigNumber(2).pow(255).minus(1),
- // Min that does overflow when doubled.
- new BigNumber(2).pow(255),
- // Max that does not overflow.
- new BigNumber(2).pow(256).minus(1),
-];
-
-// A set of values corresponding to the bytes32 type in Solidity.
-export const bytes32Values = [
- // Min
- '0x0000000000000000000000000000000000000000000000000000000000000000',
- '0x0000000000000000000000000000000000000000000000000000000000000001',
- '0x0000000000000000000000000000000000000000000000000000000000000002',
- // Non-trivial big number.
- '0x000000000000f000000000000000000000000000000000000000000000000000',
- // Max
- '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
-];
-
-export async function testCombinatoriallyWithReferenceFuncAsync<P0, P1, R>(
- name: string,
- referenceFunc: (p0: P0, p1: P1) => Promise<R>,
- testFunc: (p0: P0, p1: P1) => Promise<R>,
- allValues: [P0[], P1[]],
-): Promise<void>;
-export async function testCombinatoriallyWithReferenceFuncAsync<P0, P1, P2, R>(
- name: string,
- referenceFunc: (p0: P0, p1: P1, p2: P2) => Promise<R>,
- testFunc: (p0: P0, p1: P1, p2: P2) => Promise<R>,
- allValues: [P0[], P1[], P2[]],
-): Promise<void>;
-export async function testCombinatoriallyWithReferenceFuncAsync<P0, P1, P2, P3, R>(
- name: string,
- referenceFunc: (p0: P0, p1: P1, p2: P2, p3: P3) => Promise<R>,
- testFunc: (p0: P0, p1: P1, p2: P2, p3: P3) => Promise<R>,
- allValues: [P0[], P1[], P2[], P3[]],
-): Promise<void>;
-export async function testCombinatoriallyWithReferenceFuncAsync<P0, P1, P2, P3, P4, R>(
- name: string,
- referenceFunc: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4) => Promise<R>,
- testFunc: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4) => Promise<R>,
- allValues: [P0[], P1[], P2[], P3[], P4[]],
-): Promise<void>;
-
-/**
- * Uses combinatorics to test the behavior of a test function by comparing it to
- * the expected behavior (defined by a reference function) for a large number of
- * possible input values.
- *
- * First generates test cases by taking the cartesian product of the given
- * values. Each test case is a set of N values corresponding to the N arguments
- * for the test func and the reference func. For each test case, first the
- * reference function will be called to obtain an "expected result", or if the
- * reference function throws/rejects, an "expected error". Next, the test
- * function will be called to obtain an "actual result", or if the test function
- * throws/rejects, an "actual error". Each test case passes if at least one of
- * the following conditions is met:
- *
- * 1) Neither the reference function or the test function throw and the
- * "expected result" equals the "actual result".
- *
- * 2) Both the reference function and the test function throw and the "actual
- * error" message *contains* the "expected error" message.
- *
- * The first test case which does not meet one of these conditions will cause
- * the entire test to fail and this function will throw/reject.
- *
- * @param referenceFuncAsync a reference function implemented in pure
- * JavaScript/TypeScript which accepts N arguments and returns the "expected
- * result" or "expected error" for a given test case.
- * @param testFuncAsync a test function which, e.g., makes a call or sends a
- * transaction to a contract. It accepts the same N arguments returns the
- * "actual result" or "actual error" for a given test case.
- * @param values an array of N arrays. Each inner array is a set of possible
- * values which are passed into both the reference function and the test
- * function.
- * @return A Promise that resolves if the test passes and rejects if the test
- * fails, according to the rules described above.
- */
-export async function testCombinatoriallyWithReferenceFuncAsync(
- name: string,
- referenceFuncAsync: (...args: any[]) => Promise<any>,
- testFuncAsync: (...args: any[]) => Promise<any>,
- allValues: any[],
-): Promise<void> {
- const testCases = combinatorics.cartesianProduct(...allValues);
- let counter = 0;
- testCases.forEach(async testCase => {
- counter += 1;
- it(`${name} ${counter}/${testCases.length}`, async () => {
- await testWithReferenceFuncAsync(referenceFuncAsync, testFuncAsync, testCase as any);
- });
- });
-}
diff --git a/contracts/test-utils/src/index.ts b/contracts/test-utils/src/index.ts
index efd57903c..7880de0bf 100644
--- a/contracts/test-utils/src/index.ts
+++ b/contracts/test-utils/src/index.ts
@@ -24,6 +24,7 @@ export { profiler } from './profiler';
export { coverage } from './coverage';
export { addressUtils } from './address_utils';
export { OrderFactory } from './order_factory';
+export { bytes32Values, testCombinatoriallyWithReferenceFuncAsync, uint256Values } from './combinatorial_utils';
export { TransactionFactory } from './transaction_factory';
export { testWithReferenceFuncAsync } from './test_with_reference';
export {