aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/test/exchange/combinatorial_tests.ts
blob: 754af9b08b8556cb6fd065858d69e6eba856a7e7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { BlockchainLifecycle } from '@0xproject/dev-utils';
import * as _ from 'lodash';

import { chaiSetup } from '../../src/utils/chai_setup';
import { CoreCombinatorialUtils, coreCombinatorialUtilsFactoryAsync } from '../../src/utils/core_combinatorial_utils';
import { provider, txDefaults, web3Wrapper } from '../../src/utils/web3_wrapper';

import { FillScenario, OrderScenario, TakerAssetFillAmountScenario } from '../../src/utils/types';

chaiSetup.configure();
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);

describe('Combinatorial tests', () => {
    let coreCombinatorialUtils: CoreCombinatorialUtils;

    before(async () => {
        await blockchainLifecycle.startAsync();
        coreCombinatorialUtils = await coreCombinatorialUtilsFactoryAsync(web3Wrapper, txDefaults);
    });
    after(async () => {
        await blockchainLifecycle.revertAsync();
    });
    beforeEach(async () => {
        await blockchainLifecycle.startAsync();
    });
    afterEach(async () => {
        await blockchainLifecycle.revertAsync();
    });
    const test = (fillScenarios: FillScenario[]) => {
        _.forEach(fillScenarios, fillScenario => {
            const orderScenario = fillScenario.orderScenario;
            const description = `Combinatorial OrderFill: ${orderScenario.feeRecipientScenario} ${
                orderScenario.makerAssetAmountScenario
            } ${orderScenario.takerAssetAmountScenario} ${orderScenario.makerFeeScenario} ${
                orderScenario.takerFeeScenario
            } ${orderScenario.expirationTimeSecondsScenario} ${orderScenario.makerAssetDataScenario} ${
                orderScenario.takerAssetDataScenario
            }`;
            it(description, async () => {
                await coreCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario);
            });
        });
    };

    const allFillScenarios = CoreCombinatorialUtils.generateFillOrderCombinations();

    describe('Fills orders', () => test(allFillScenarios));
});