diff options
author | Fabio Berger <me@fabioberger.com> | 2017-06-07 18:48:26 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2017-06-07 18:48:26 +0800 |
commit | 4eee0b52f13cb382329cc7061d4377561ac1cbd3 (patch) | |
tree | c560b5b90b0ec8bee67094711b17f0c16e53e23f /test | |
parent | 918315e89f3408124d2e78bbd1acb58ed42d1766 (diff) | |
parent | 28d3528e42563f95255cee3bd7f85cc03141522e (diff) | |
download | dexon-0x-contracts-4eee0b52f13cb382329cc7061d4377561ac1cbd3.tar.gz dexon-0x-contracts-4eee0b52f13cb382329cc7061d4377561ac1cbd3.tar.zst dexon-0x-contracts-4eee0b52f13cb382329cc7061d4377561ac1cbd3.zip |
merge master
Diffstat (limited to 'test')
-rw-r--r-- | test/exchange_wrapper_test.ts | 53 | ||||
-rw-r--r-- | test/utils/order_factory.ts | 4 |
2 files changed, 52 insertions, 5 deletions
diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts index 9ef20736f..ff2121de1 100644 --- a/test/exchange_wrapper_test.ts +++ b/test/exchange_wrapper_test.ts @@ -4,13 +4,13 @@ import * as Web3 from 'web3'; import * as BigNumber from 'bignumber.js'; import {chaiSetup} from './utils/chai_setup'; import ChaiBigNumber = require('chai-bignumber'); -import * as chaiAsPromised from 'chai-as-promised'; import promisify = require('es6-promisify'); import {web3Factory} from './utils/web3_factory'; import {ZeroEx} from '../src/0x.js'; import {BlockchainLifecycle} from './utils/blockchain_lifecycle'; import { Token, + Order, SignedOrder, SubscriptionOpts, ExchangeEvents, @@ -236,7 +236,7 @@ describe('ExchangeWrapper', () => { )).to.be.rejectedWith(ExchangeContractErrs.TRANSACTION_SENDER_IS_NOT_FILL_ORDER_TAKER); }); it('should throw when order is expired', async () => { - const expirationInPast = new BigNumber(42); + const expirationInPast = new BigNumber(1496826058); // 7th Jun 2017 const fillableAmount = new BigNumber(5); const signedOrder = await fillScenarios.createFillableSignedOrderAsync( makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, expirationInPast, @@ -424,6 +424,55 @@ describe('ExchangeWrapper', () => { }); }); }); + describe('#cancelOrderAsync', () => { + let makerTokenAddress: string; + let takerTokenAddress: string; + let coinbase: string; + let makerAddress: string; + let takerAddress: string; + const fillableAmount = new BigNumber(5); + let signedOrder: SignedOrder; + let orderHashHex: string; + const cancelAmount = new BigNumber(3); + beforeEach(async () => { + [coinbase, makerAddress, takerAddress] = userAddresses; + const [makerToken, takerToken] = tokenUtils.getNonProtocolTokens(); + makerTokenAddress = makerToken.address; + takerTokenAddress = takerToken.address; + signedOrder = await fillScenarios.createFillableSignedOrderAsync( + makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, + ); + orderHashHex = await zeroEx.getOrderHashHexAsync(signedOrder); + }); + describe('failed cancels', () => { + it('should throw when cancel amount is zero', async () => { + const zeroCancelAmount = new BigNumber(0); + return expect(zeroEx.exchange.cancelOrderAsync(signedOrder, zeroCancelAmount)) + .to.be.rejectedWith(ExchangeContractErrs.ORDER_CANCEL_AMOUNT_ZERO); + }); + it('should throw when order is expired', async () => { + const expirationInPast = new BigNumber(1496826058); // 7th Jun 2017 + const expiredSignedOrder = await fillScenarios.createFillableSignedOrderAsync( + makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount, expirationInPast, + ); + orderHashHex = await zeroEx.getOrderHashHexAsync(expiredSignedOrder); + return expect(zeroEx.exchange.cancelOrderAsync(expiredSignedOrder, cancelAmount)) + .to.be.rejectedWith(ExchangeContractErrs.ORDER_CANCEL_EXPIRED); + }); + it('should throw when order is already cancelled or filled', async () => { + await zeroEx.exchange.cancelOrderAsync(signedOrder, fillableAmount); + return expect(zeroEx.exchange.cancelOrderAsync(signedOrder, fillableAmount)) + .to.be.rejectedWith(ExchangeContractErrs.ORDER_ALREADY_CANCELLED_OR_FILLED); + }); + }); + describe('successful cancels', () => { + it('should cancel an order', async () => { + await zeroEx.exchange.cancelOrderAsync(signedOrder, cancelAmount); + const cancelledAmount = await zeroEx.exchange.getCanceledTakerAmountAsync(orderHashHex); + expect(cancelledAmount).to.be.bignumber.equal(cancelAmount); + }); + }); + }); describe('tests that require partially filled order', () => { let makerTokenAddress: string; let takerTokenAddress: string; diff --git a/test/utils/order_factory.ts b/test/utils/order_factory.ts index 6f5fa7286..a1cc243c6 100644 --- a/test/utils/order_factory.ts +++ b/test/utils/order_factory.ts @@ -1,9 +1,7 @@ import * as _ from 'lodash'; import * as BigNumber from 'bignumber.js'; -import {SignedOrder, Token} from '../../src/types'; +import {SignedOrder} from '../../src/types'; import {ZeroEx} from '../../src/0x.js'; -import {constants} from './constants'; -import * as ExchangeArtifacts from '../../src/artifacts/Exchange.json'; export const orderFactory = { async createSignedOrderAsync( |