aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorLeonid <logvinov.leon@gmail.com>2017-06-07 18:22:05 +0800
committerGitHub <noreply@github.com>2017-06-07 18:22:05 +0800
commit28d3528e42563f95255cee3bd7f85cc03141522e (patch)
tree9d9119c79f1ad4f1b097253ddc7ee4cac2415e58 /test
parent8ec3bec5b3de726fbf2cc828e179ac2ed1029d9f (diff)
parent8ec2f685abefd77186b9bad5d67c9b23a9c03acf (diff)
downloaddexon-sol-tools-28d3528e42563f95255cee3bd7f85cc03141522e.tar
dexon-sol-tools-28d3528e42563f95255cee3bd7f85cc03141522e.tar.gz
dexon-sol-tools-28d3528e42563f95255cee3bd7f85cc03141522e.tar.bz2
dexon-sol-tools-28d3528e42563f95255cee3bd7f85cc03141522e.tar.lz
dexon-sol-tools-28d3528e42563f95255cee3bd7f85cc03141522e.tar.xz
dexon-sol-tools-28d3528e42563f95255cee3bd7f85cc03141522e.tar.zst
dexon-sol-tools-28d3528e42563f95255cee3bd7f85cc03141522e.zip
Merge pull request #40 from 0xProject/cancelAsync
Add cancelOrderAsync
Diffstat (limited to 'test')
-rw-r--r--test/exchange_wrapper_test.ts53
-rw-r--r--test/utils/order_factory.ts4
2 files changed, 52 insertions, 5 deletions
diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts
index 370e741b4..c0068c58a 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,
@@ -158,7 +158,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,
@@ -323,6 +323,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(