diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-06-08 17:31:40 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-06-08 17:31:40 +0800 |
commit | c1322717802d652090fb374ac706cb1abf6c26be (patch) | |
tree | efc3905da0882f1e23b896f06a59e48122bd3532 /test/exchange_wrapper_test.ts | |
parent | 5d464d87e07003c231fca55e87b95cc7e1e9e978 (diff) | |
parent | c6645f9f4f470323086d9004cf603a68091d71a3 (diff) | |
download | dexon-0x-contracts-c1322717802d652090fb374ac706cb1abf6c26be.tar dexon-0x-contracts-c1322717802d652090fb374ac706cb1abf6c26be.tar.gz dexon-0x-contracts-c1322717802d652090fb374ac706cb1abf6c26be.tar.bz2 dexon-0x-contracts-c1322717802d652090fb374ac706cb1abf6c26be.tar.lz dexon-0x-contracts-c1322717802d652090fb374ac706cb1abf6c26be.tar.xz dexon-0x-contracts-c1322717802d652090fb374ac706cb1abf6c26be.tar.zst dexon-0x-contracts-c1322717802d652090fb374ac706cb1abf6c26be.zip |
Merge branch 'master' into batchFillAsync
Diffstat (limited to 'test/exchange_wrapper_test.ts')
-rw-r--r-- | test/exchange_wrapper_test.ts | 84 |
1 files changed, 78 insertions, 6 deletions
diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts index bd2536741..2d7810bcc 100644 --- a/test/exchange_wrapper_test.ts +++ b/test/exchange_wrapper_test.ts @@ -122,6 +122,81 @@ describe('ExchangeWrapper', () => { expect(isValid).to.be.true(); }); }); + describe('#fillOrKillOrderAsync', () => { + let makerTokenAddress: string; + let takerTokenAddress: string; + let coinbase: string; + let makerAddress: string; + let takerAddress: string; + let feeRecipient: string; + const fillTakerAmount = new BigNumber(5); + before(async () => { + [coinbase, makerAddress, takerAddress, feeRecipient] = userAddresses; + tokens = await zeroEx.tokenRegistry.getTokensAsync(); + const [makerToken, takerToken] = tokenUtils.getNonProtocolTokens(); + makerTokenAddress = makerToken.address; + takerTokenAddress = takerToken.address; + }); + describe('failed fillOrKill', () => { + it('should throw if remaining fillAmount is less then the desired fillAmount', async () => { + const fillableAmount = new BigNumber(5); + const signedOrder = await fillScenarios.createFillableSignedOrderAsync( + makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, + ); + const tooLargeFillAmount = new BigNumber(7); + const fillAmountDifference = tooLargeFillAmount.minus(fillableAmount); + await zeroEx.token.transferAsync(takerTokenAddress, coinbase, takerAddress, fillAmountDifference); + await zeroEx.token.setProxyAllowanceAsync(takerTokenAddress, takerAddress, tooLargeFillAmount); + await zeroEx.token.transferAsync(makerTokenAddress, coinbase, makerAddress, fillAmountDifference); + await zeroEx.token.setProxyAllowanceAsync(makerTokenAddress, makerAddress, tooLargeFillAmount); + + return expect(zeroEx.exchange.fillOrKillOrderAsync( + signedOrder, tooLargeFillAmount, takerAddress, + )).to.be.rejectedWith(ExchangeContractErrs.INSUFFICIENT_REMAINING_FILL_AMOUNT); + }); + }); + describe('successful fills', () => { + it('should fill a valid order', async () => { + const fillableAmount = new BigNumber(5); + const signedOrder = await fillScenarios.createFillableSignedOrderAsync( + makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, + ); + expect(await zeroEx.token.getBalanceAsync(makerTokenAddress, makerAddress)) + .to.be.bignumber.equal(fillableAmount); + expect(await zeroEx.token.getBalanceAsync(takerTokenAddress, makerAddress)) + .to.be.bignumber.equal(0); + expect(await zeroEx.token.getBalanceAsync(makerTokenAddress, takerAddress)) + .to.be.bignumber.equal(0); + expect(await zeroEx.token.getBalanceAsync(takerTokenAddress, takerAddress)) + .to.be.bignumber.equal(fillableAmount); + await zeroEx.exchange.fillOrKillOrderAsync(signedOrder, fillTakerAmount, takerAddress); + expect(await zeroEx.token.getBalanceAsync(makerTokenAddress, makerAddress)) + .to.be.bignumber.equal(fillableAmount.minus(fillTakerAmount)); + expect(await zeroEx.token.getBalanceAsync(takerTokenAddress, makerAddress)) + .to.be.bignumber.equal(fillTakerAmount); + expect(await zeroEx.token.getBalanceAsync(makerTokenAddress, takerAddress)) + .to.be.bignumber.equal(fillTakerAmount); + expect(await zeroEx.token.getBalanceAsync(takerTokenAddress, takerAddress)) + .to.be.bignumber.equal(fillableAmount.minus(fillTakerAmount)); + }); + it('should partially fill a valid order', async () => { + const fillableAmount = new BigNumber(5); + const signedOrder = await fillScenarios.createFillableSignedOrderAsync( + makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, + ); + const partialFillAmount = new BigNumber(3); + await zeroEx.exchange.fillOrKillOrderAsync(signedOrder, partialFillAmount, takerAddress); + expect(await zeroEx.token.getBalanceAsync(makerTokenAddress, makerAddress)) + .to.be.bignumber.equal(fillableAmount.minus(partialFillAmount)); + expect(await zeroEx.token.getBalanceAsync(takerTokenAddress, makerAddress)) + .to.be.bignumber.equal(partialFillAmount); + expect(await zeroEx.token.getBalanceAsync(makerTokenAddress, takerAddress)) + .to.be.bignumber.equal(partialFillAmount); + expect(await zeroEx.token.getBalanceAsync(takerTokenAddress, takerAddress)) + .to.be.bignumber.equal(fillableAmount.minus(partialFillAmount)); + }); + }); + }); describe('fill order(s)', () => { let makerTokenAddress: string; let takerTokenAddress: string; @@ -134,6 +209,7 @@ describe('ExchangeWrapper', () => { const shouldCheckTransfer = false; before(async () => { [coinbase, makerAddress, takerAddress, feeRecipient] = userAddresses; + tokens = await zeroEx.tokenRegistry.getTokensAsync(); const [makerToken, takerToken] = tokenUtils.getNonProtocolTokens(); makerTokenAddress = makerToken.address; takerTokenAddress = takerToken.address; @@ -434,18 +510,14 @@ describe('ExchangeWrapper', () => { ]; }); describe('failed batch cancels', () => { - it('should throw when orders are empty', async () => { - return expect(zeroEx.exchange.batchCancelOrderAsync([])) - .to.be.rejectedWith('Can not cancel an empty batch'); - }); it('should throw when orders have different makers', async () => { - const signedOrderWithADifferentMaker = await fillScenarios.createFillableSignedOrderAsync( + const signedOrderWithDifferentMaker = await fillScenarios.createFillableSignedOrderAsync( makerTokenAddress, takerTokenAddress, takerAddress, takerAddress, fillableAmount, ); return expect(zeroEx.exchange.batchCancelOrderAsync([ cancelBatch[0], { - order: signedOrderWithADifferentMaker, + order: signedOrderWithDifferentMaker, takerTokenCancelAmount: cancelAmount, }, ])).to.be.rejectedWith('Can not cancel orders from multiple makers in a single batch'); |