diff options
author | Alex Browne <stephenalexbrowne@gmail.com> | 2018-07-27 13:09:55 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-27 13:09:55 +0800 |
commit | 554d5f97df55779beed35ef73214e80b386d7927 (patch) | |
tree | eaf73ce6cbd61d96d541c08d7e2d640f02f32083 /packages/contracts/test/exchange/fill_order.ts | |
parent | 95c627f581ec8d724a0c737cbbf5b53b96765f6e (diff) | |
download | dexon-0x-contracts-554d5f97df55779beed35ef73214e80b386d7927.tar dexon-0x-contracts-554d5f97df55779beed35ef73214e80b386d7927.tar.gz dexon-0x-contracts-554d5f97df55779beed35ef73214e80b386d7927.tar.bz2 dexon-0x-contracts-554d5f97df55779beed35ef73214e80b386d7927.tar.lz dexon-0x-contracts-554d5f97df55779beed35ef73214e80b386d7927.tar.xz dexon-0x-contracts-554d5f97df55779beed35ef73214e80b386d7927.tar.zst dexon-0x-contracts-554d5f97df55779beed35ef73214e80b386d7927.zip |
Add combinatorial tests for internal Exchange functions (#807)
* WIP add combinatorial tests for internal Exchange functions
* Change combinitorial testing strategy based on feedback
* Check value of filled[orderHash] in updateFilledState tests
* Add combinatorial tests for addFillResults
* Add combinatorial tests for getPartialAmount
* Implement generic `testWithReferenceFuncAsync`
* Implement generic `testCombinatoriallyWithReferenceFuncAsync`
* Add combinatorial tests for isRoundingError
* Add combinatorial tests for calculateFillResults
* Add support for Geth in internal contract tests
* Fix contract artifacts
* Change DECIMAL_PLACES to 78 and add a note.
* Document new functions in utils
* Optimize tests by only reseting state when needed
* Rename/move some files
* Print parameter names on failure in testWithReferenceFuncAsync
* Add to changelog for utils package
* Appease various linters
* Rename some more things related to FillOrderCombinatorialUtils
* Remove .only from test/exchange/internal.ts
* Remove old test for isRoundingError and getPartialAmount
* Appease linters again
* Remove old todos
* Fix typos, add comments, rename some things
* Re-add some LibMath tests
* Update contract internal tests to use new SafeMath revert reasons
* Apply PR feedback from Amir
* Apply PR feedback from Remco
* Re-add networks to ZRXToken artifact
* Remove duplicate Whitelist in compiler.json
Diffstat (limited to 'packages/contracts/test/exchange/fill_order.ts')
-rw-r--r-- | packages/contracts/test/exchange/fill_order.ts | 51 |
1 files changed, 27 insertions, 24 deletions
diff --git a/packages/contracts/test/exchange/fill_order.ts b/packages/contracts/test/exchange/fill_order.ts index 029bd66e2..1494fe093 100644 --- a/packages/contracts/test/exchange/fill_order.ts +++ b/packages/contracts/test/exchange/fill_order.ts @@ -2,7 +2,10 @@ import { BlockchainLifecycle } from '@0xproject/dev-utils'; import * as _ from 'lodash'; import { chaiSetup } from '../utils/chai_setup'; -import { CoreCombinatorialUtils, coreCombinatorialUtilsFactoryAsync } from '../utils/core_combinatorial_utils'; +import { + FillOrderCombinatorialUtils, + fillOrderCombinatorialUtilsFactoryAsync, +} from '../utils/fill_order_combinatorial_utils'; import { AllowanceAmountScenario, AssetDataScenario, @@ -47,11 +50,11 @@ const defaultFillScenario = { }; describe('FillOrder Tests', () => { - let coreCombinatorialUtils: CoreCombinatorialUtils; + let fillOrderCombinatorialUtils: FillOrderCombinatorialUtils; before(async () => { await blockchainLifecycle.startAsync(); - coreCombinatorialUtils = await coreCombinatorialUtilsFactoryAsync(web3Wrapper, txDefaults); + fillOrderCombinatorialUtils = await fillOrderCombinatorialUtilsFactoryAsync(web3Wrapper, txDefaults); }); after(async () => { await blockchainLifecycle.revertAsync(); @@ -67,19 +70,19 @@ describe('FillOrder Tests', () => { _.forEach(fillScenarios, fillScenario => { const description = `Combinatorial OrderFill: ${JSON.stringify(fillScenario)}`; it(description, async () => { - await coreCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario); + await fillOrderCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario); }); }); }; - const allFillScenarios = CoreCombinatorialUtils.generateFillOrderCombinations(); + const allFillScenarios = FillOrderCombinatorialUtils.generateFillOrderCombinations(); describe('Combinatorially generated fills orders', () => test(allFillScenarios)); it('should transfer the correct amounts when makerAssetAmount === takerAssetAmount', async () => { const fillScenario = { ...defaultFillScenario, }; - await coreCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario); + await fillOrderCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario); }); it('should transfer the correct amounts when makerAssetAmount > takerAssetAmount', async () => { const fillScenario = { @@ -89,7 +92,7 @@ describe('FillOrder Tests', () => { takerAssetAmountScenario: OrderAssetAmountScenario.Small, }, }; - await coreCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario); + await fillOrderCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario); }); it('should transfer the correct amounts when makerAssetAmount < takerAssetAmount', async () => { const fillScenario = { @@ -99,7 +102,7 @@ describe('FillOrder Tests', () => { makerAssetAmountScenario: OrderAssetAmountScenario.Small, }, }; - await coreCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario); + await fillOrderCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario); }); it('should transfer the correct amounts when taker is specified and order is claimed by taker', async () => { const fillScenario = { @@ -109,14 +112,14 @@ describe('FillOrder Tests', () => { takerScenario: TakerScenario.CorrectlySpecified, }, }; - await coreCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario); + await fillOrderCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario); }); it('should fill remaining value if takerAssetFillAmount > remaining takerAssetAmount', async () => { const fillScenario = { ...defaultFillScenario, takerAssetFillAmountScenario: TakerAssetFillAmountScenario.GreaterThanRemainingFillableTakerAssetAmount, }; - await coreCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario); + await fillOrderCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario); }); it('should throw when taker is specified and order is claimed by other', async () => { const fillScenario = { @@ -126,7 +129,7 @@ describe('FillOrder Tests', () => { takerScenario: TakerScenario.IncorrectlySpecified, }, }; - await coreCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario); + await fillOrderCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario); }); it('should throw if makerAssetAmount is 0', async () => { @@ -138,7 +141,7 @@ describe('FillOrder Tests', () => { }, takerAssetFillAmountScenario: TakerAssetFillAmountScenario.GreaterThanRemainingFillableTakerAssetAmount, }; - await coreCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario); + await fillOrderCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario); }); it('should throw if takerAssetAmount is 0', async () => { @@ -150,7 +153,7 @@ describe('FillOrder Tests', () => { }, takerAssetFillAmountScenario: TakerAssetFillAmountScenario.GreaterThanRemainingFillableTakerAssetAmount, }; - await coreCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario); + await fillOrderCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario); }); it('should throw if takerAssetFillAmount is 0', async () => { @@ -158,7 +161,7 @@ describe('FillOrder Tests', () => { ...defaultFillScenario, takerAssetFillAmountScenario: TakerAssetFillAmountScenario.Zero, }; - await coreCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario); + await fillOrderCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario); }); it('should throw if an order is expired', async () => { @@ -169,7 +172,7 @@ describe('FillOrder Tests', () => { expirationTimeSecondsScenario: ExpirationTimeSecondsScenario.InPast, }, }; - await coreCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario); + await fillOrderCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario); }); it('should throw if maker erc20Balances are too low to fill order', async () => { @@ -180,7 +183,7 @@ describe('FillOrder Tests', () => { traderAssetBalance: BalanceAmountScenario.TooLow, }, }; - await coreCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario); + await fillOrderCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario); }); it('should throw if taker erc20Balances are too low to fill order', async () => { @@ -191,7 +194,7 @@ describe('FillOrder Tests', () => { traderAssetBalance: BalanceAmountScenario.TooLow, }, }; - await coreCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario); + await fillOrderCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario); }); it('should throw if maker allowances are too low to fill order', async () => { @@ -202,7 +205,7 @@ describe('FillOrder Tests', () => { traderAssetAllowance: AllowanceAmountScenario.TooLow, }, }; - await coreCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario); + await fillOrderCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario); }); it('should throw if taker allowances are too low to fill order', async () => { @@ -213,7 +216,7 @@ describe('FillOrder Tests', () => { traderAssetAllowance: AllowanceAmountScenario.TooLow, }, }; - await coreCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario); + await fillOrderCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario); }); }); @@ -228,7 +231,7 @@ describe('FillOrder Tests', () => { }, takerAssetFillAmountScenario: TakerAssetFillAmountScenario.ExactlyRemainingFillableTakerAssetAmount, }; - await coreCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario); + await fillOrderCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario); }); it('should successfully fill order when makerAsset is ERC721 and takerAsset is ERC20', async () => { @@ -241,7 +244,7 @@ describe('FillOrder Tests', () => { }, takerAssetFillAmountScenario: TakerAssetFillAmountScenario.ExactlyRemainingFillableTakerAssetAmount, }; - await coreCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario, true); + await fillOrderCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario, true); }); it('should successfully fill order when makerAsset is ERC20 and takerAsset is ERC721', async () => { @@ -254,7 +257,7 @@ describe('FillOrder Tests', () => { }, takerAssetFillAmountScenario: TakerAssetFillAmountScenario.ExactlyRemainingFillableTakerAssetAmount, }; - await coreCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario); + await fillOrderCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario); }); it('should successfully fill order when makerAsset is ERC721 and approveAll is set for it', async () => { @@ -271,7 +274,7 @@ describe('FillOrder Tests', () => { traderAssetAllowance: AllowanceAmountScenario.Unlimited, }, }; - await coreCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario); + await fillOrderCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario); }); it('should successfully fill order when makerAsset and takerAsset are ERC721 and approveAll is set for them', async () => { @@ -292,7 +295,7 @@ describe('FillOrder Tests', () => { traderAssetAllowance: AllowanceAmountScenario.Unlimited, }, }; - await coreCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario); + await fillOrderCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario); }); }); }); |