aboutsummaryrefslogtreecommitdiffstats
path: root/test/exchange_wrapper_test.ts
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2017-06-07 18:48:26 +0800
committerFabio Berger <me@fabioberger.com>2017-06-07 18:48:26 +0800
commit4eee0b52f13cb382329cc7061d4377561ac1cbd3 (patch)
treec560b5b90b0ec8bee67094711b17f0c16e53e23f /test/exchange_wrapper_test.ts
parent918315e89f3408124d2e78bbd1acb58ed42d1766 (diff)
parent28d3528e42563f95255cee3bd7f85cc03141522e (diff)
downloaddexon-sol-tools-4eee0b52f13cb382329cc7061d4377561ac1cbd3.tar
dexon-sol-tools-4eee0b52f13cb382329cc7061d4377561ac1cbd3.tar.gz
dexon-sol-tools-4eee0b52f13cb382329cc7061d4377561ac1cbd3.tar.bz2
dexon-sol-tools-4eee0b52f13cb382329cc7061d4377561ac1cbd3.tar.lz
dexon-sol-tools-4eee0b52f13cb382329cc7061d4377561ac1cbd3.tar.xz
dexon-sol-tools-4eee0b52f13cb382329cc7061d4377561ac1cbd3.tar.zst
dexon-sol-tools-4eee0b52f13cb382329cc7061d4377561ac1cbd3.zip
merge master
Diffstat (limited to 'test/exchange_wrapper_test.ts')
-rw-r--r--test/exchange_wrapper_test.ts53
1 files changed, 51 insertions, 2 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;