aboutsummaryrefslogtreecommitdiffstats
path: root/test/exchange_wrapper_test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'test/exchange_wrapper_test.ts')
-rw-r--r--test/exchange_wrapper_test.ts131
1 files changed, 93 insertions, 38 deletions
diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts
index 7835de993..873ff48db 100644
--- a/test/exchange_wrapper_test.ts
+++ b/test/exchange_wrapper_test.ts
@@ -1,4 +1,5 @@
import 'mocha';
+import * as _ from 'lodash';
import * as chai from 'chai';
import * as Web3 from 'web3';
import * as BigNumber from 'bignumber.js';
@@ -23,6 +24,7 @@ import {DoneCallback} from '../src/types';
import {FillScenarios} from './utils/fill_scenarios';
import {TokenUtils} from './utils/token_utils';
import {assert} from '../src/utils/assert';
+import {ProxyWrapper} from '../src/contract_wrappers/proxy_wrapper';
chaiSetup.configure();
const expect = chai.expect;
@@ -38,14 +40,16 @@ describe('ExchangeWrapper', () => {
let userAddresses: string[];
let zrxTokenAddress: string;
let fillScenarios: FillScenarios;
+ let exchangeContractAddress: string;
before(async () => {
web3 = web3Factory.create();
zeroEx = new ZeroEx(web3.currentProvider);
+ [exchangeContractAddress] = await zeroEx.exchange.getAvailableContractAddressesAsync();
userAddresses = await promisify(web3.eth.getAccounts)();
tokens = await zeroEx.tokenRegistry.getTokensAsync();
tokenUtils = new TokenUtils(tokens);
zrxTokenAddress = tokenUtils.getProtocolTokenOrThrow().address;
- fillScenarios = new FillScenarios(zeroEx, userAddresses, tokens, zrxTokenAddress);
+ fillScenarios = new FillScenarios(zeroEx, userAddresses, tokens, zrxTokenAddress, exchangeContractAddress);
});
beforeEach(async () => {
await blockchainLifecycle.startAsync();
@@ -392,11 +396,11 @@ describe('ExchangeWrapper', () => {
signedOrder = await fillScenarios.createFillableSignedOrderAsync(
makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount,
);
- signedOrderHashHex = await zeroEx.getOrderHashHexAsync(signedOrder);
+ signedOrderHashHex = zeroEx.getOrderHashHex(signedOrder);
anotherSignedOrder = await fillScenarios.createFillableSignedOrderAsync(
makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount,
);
- anotherOrderHashHex = await zeroEx.getOrderHashHexAsync(anotherSignedOrder);
+ anotherOrderHashHex = zeroEx.getOrderHashHex(anotherSignedOrder);
orderFillBatch = [
{
signedOrder,
@@ -414,8 +418,12 @@ describe('ExchangeWrapper', () => {
});
it('should successfully fill multiple orders', async () => {
await zeroEx.exchange.batchFillOrderAsync(orderFillBatch, shouldCheckTransfer, takerAddress);
- const filledAmount = await zeroEx.exchange.getFilledTakerAmountAsync(signedOrderHashHex);
- const anotherFilledAmount = await zeroEx.exchange.getFilledTakerAmountAsync(anotherOrderHashHex);
+ const filledAmount = await zeroEx.exchange.getFilledTakerAmountAsync(
+ signedOrderHashHex, exchangeContractAddress,
+ );
+ const anotherFilledAmount = await zeroEx.exchange.getFilledTakerAmountAsync(
+ anotherOrderHashHex, exchangeContractAddress,
+ );
expect(filledAmount).to.be.bignumber.equal(fillTakerAmount);
expect(anotherFilledAmount).to.be.bignumber.equal(fillTakerAmount);
});
@@ -432,11 +440,11 @@ describe('ExchangeWrapper', () => {
signedOrder = await fillScenarios.createFillableSignedOrderAsync(
makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount,
);
- signedOrderHashHex = await zeroEx.getOrderHashHexAsync(signedOrder);
+ signedOrderHashHex = zeroEx.getOrderHashHex(signedOrder);
anotherSignedOrder = await fillScenarios.createFillableSignedOrderAsync(
makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount,
);
- anotherOrderHashHex = await zeroEx.getOrderHashHexAsync(anotherSignedOrder);
+ anotherOrderHashHex = zeroEx.getOrderHashHex(anotherSignedOrder);
signedOrders = [signedOrder, anotherSignedOrder];
});
describe('successful batch fills', () => {
@@ -447,8 +455,12 @@ describe('ExchangeWrapper', () => {
await zeroEx.exchange.fillOrdersUpToAsync(
signedOrders, fillUpToAmount, shouldCheckTransfer, takerAddress,
);
- const filledAmount = await zeroEx.exchange.getFilledTakerAmountAsync(signedOrderHashHex);
- const anotherFilledAmount = await zeroEx.exchange.getFilledTakerAmountAsync(anotherOrderHashHex);
+ const filledAmount = await zeroEx.exchange.getFilledTakerAmountAsync(
+ signedOrderHashHex, exchangeContractAddress,
+ );
+ const anotherFilledAmount = await zeroEx.exchange.getFilledTakerAmountAsync(
+ anotherOrderHashHex, exchangeContractAddress,
+ );
expect(filledAmount).to.be.bignumber.equal(fillableAmount);
const remainingFillAmount = fillableAmount.minus(1);
expect(anotherFilledAmount).to.be.bignumber.equal(remainingFillAmount);
@@ -480,7 +492,7 @@ describe('ExchangeWrapper', () => {
signedOrder = await fillScenarios.createFillableSignedOrderAsync(
makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount,
);
- orderHashHex = await zeroEx.getOrderHashHexAsync(signedOrder);
+ orderHashHex = zeroEx.getOrderHashHex(signedOrder);
});
describe('#cancelOrderAsync', () => {
describe('failed cancels', () => {
@@ -495,7 +507,7 @@ describe('ExchangeWrapper', () => {
makerTokenAddress, takerTokenAddress, makerAddress, takerAddress,
fillableAmount, expirationInPast,
);
- orderHashHex = await zeroEx.getOrderHashHexAsync(expiredSignedOrder);
+ orderHashHex = zeroEx.getOrderHashHex(expiredSignedOrder);
return expect(zeroEx.exchange.cancelOrderAsync(expiredSignedOrder, cancelAmount))
.to.be.rejectedWith(ExchangeContractErrs.ORDER_CANCEL_EXPIRED);
});
@@ -508,7 +520,9 @@ describe('ExchangeWrapper', () => {
describe('successful cancels', () => {
it('should cancel an order', async () => {
await zeroEx.exchange.cancelOrderAsync(signedOrder, cancelAmount);
- const cancelledAmount = await zeroEx.exchange.getCanceledTakerAmountAsync(orderHashHex);
+ const cancelledAmount = await zeroEx.exchange.getCanceledTakerAmountAsync(
+ orderHashHex, exchangeContractAddress,
+ );
expect(cancelledAmount).to.be.bignumber.equal(cancelAmount);
});
it('should return cancelled amount', async () => {
@@ -525,7 +539,7 @@ describe('ExchangeWrapper', () => {
anotherSignedOrder = await fillScenarios.createFillableSignedOrderAsync(
makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount,
);
- anotherOrderHashHex = await zeroEx.getOrderHashHexAsync(anotherSignedOrder);
+ anotherOrderHashHex = zeroEx.getOrderHashHex(anotherSignedOrder);
cancelBatch = [
{
order: signedOrder,
@@ -554,9 +568,12 @@ describe('ExchangeWrapper', () => {
describe('successful batch cancels', () => {
it('should cancel a batch of orders', async () => {
await zeroEx.exchange.batchCancelOrderAsync(cancelBatch);
- const cancelledAmount = await zeroEx.exchange.getCanceledTakerAmountAsync(orderHashHex);
+ const cancelledAmount = await zeroEx.exchange.getCanceledTakerAmountAsync(
+ orderHashHex, exchangeContractAddress,
+ );
const anotherCancelledAmount = await zeroEx.exchange.getCanceledTakerAmountAsync(
- anotherOrderHashHex);
+ anotherOrderHashHex, exchangeContractAddress,
+ );
expect(cancelledAmount).to.be.bignumber.equal(cancelAmount);
expect(anotherCancelledAmount).to.be.bignumber.equal(cancelAmount);
});
@@ -583,53 +600,73 @@ describe('ExchangeWrapper', () => {
signedOrder = await fillScenarios.createPartiallyFilledSignedOrderAsync(
makerTokenAddress, takerTokenAddress, takerAddress, fillableAmount, partialFillAmount,
);
- orderHash = await zeroEx.getOrderHashHexAsync(signedOrder);
+ orderHash = zeroEx.getOrderHashHex(signedOrder);
});
describe('#getUnavailableTakerAmountAsync', () => {
it ('should throw if passed an invalid orderHash', async () => {
const invalidOrderHashHex = '0x123';
- return expect(zeroEx.exchange.getUnavailableTakerAmountAsync(invalidOrderHashHex)).to.be.rejected();
+ return expect(zeroEx.exchange.getUnavailableTakerAmountAsync(
+ invalidOrderHashHex, exchangeContractAddress,
+ )).to.be.rejected();
});
it ('should return zero if passed a valid but non-existent orderHash', async () => {
- const unavailableValueT = await zeroEx.exchange.getUnavailableTakerAmountAsync(NON_EXISTENT_ORDER_HASH);
+ const unavailableValueT = await zeroEx.exchange.getUnavailableTakerAmountAsync(
+ NON_EXISTENT_ORDER_HASH, exchangeContractAddress,
+ );
expect(unavailableValueT).to.be.bignumber.equal(0);
});
it ('should return the unavailableValueT for a valid and partially filled orderHash', async () => {
- const unavailableValueT = await zeroEx.exchange.getUnavailableTakerAmountAsync(orderHash);
+ const unavailableValueT = await zeroEx.exchange.getUnavailableTakerAmountAsync(
+ orderHash, exchangeContractAddress,
+ );
expect(unavailableValueT).to.be.bignumber.equal(partialFillAmount);
});
});
describe('#getFilledTakerAmountAsync', () => {
it ('should throw if passed an invalid orderHash', async () => {
const invalidOrderHashHex = '0x123';
- return expect(zeroEx.exchange.getFilledTakerAmountAsync(invalidOrderHashHex)).to.be.rejected();
+ return expect(zeroEx.exchange.getFilledTakerAmountAsync(
+ invalidOrderHashHex, exchangeContractAddress,
+ )).to.be.rejected();
});
it ('should return zero if passed a valid but non-existent orderHash', async () => {
- const filledValueT = await zeroEx.exchange.getFilledTakerAmountAsync(NON_EXISTENT_ORDER_HASH);
+ const filledValueT = await zeroEx.exchange.getFilledTakerAmountAsync(
+ NON_EXISTENT_ORDER_HASH, exchangeContractAddress,
+ );
expect(filledValueT).to.be.bignumber.equal(0);
});
it ('should return the filledValueT for a valid and partially filled orderHash', async () => {
- const filledValueT = await zeroEx.exchange.getFilledTakerAmountAsync(orderHash);
+ const filledValueT = await zeroEx.exchange.getFilledTakerAmountAsync(
+ orderHash, exchangeContractAddress,
+ );
expect(filledValueT).to.be.bignumber.equal(partialFillAmount);
});
});
describe('#getCanceledTakerAmountAsync', () => {
it ('should throw if passed an invalid orderHash', async () => {
const invalidOrderHashHex = '0x123';
- return expect(zeroEx.exchange.getCanceledTakerAmountAsync(invalidOrderHashHex)).to.be.rejected();
+ return expect(zeroEx.exchange.getCanceledTakerAmountAsync(
+ invalidOrderHashHex, exchangeContractAddress,
+ )).to.be.rejected();
});
it ('should return zero if passed a valid but non-existent orderHash', async () => {
- const cancelledValueT = await zeroEx.exchange.getCanceledTakerAmountAsync(NON_EXISTENT_ORDER_HASH);
+ const cancelledValueT = await zeroEx.exchange.getCanceledTakerAmountAsync(
+ NON_EXISTENT_ORDER_HASH, exchangeContractAddress,
+ );
expect(cancelledValueT).to.be.bignumber.equal(0);
});
it ('should return the cancelledValueT for a valid and partially filled orderHash', async () => {
- const cancelledValueT = await zeroEx.exchange.getCanceledTakerAmountAsync(orderHash);
+ const cancelledValueT = await zeroEx.exchange.getCanceledTakerAmountAsync(
+ orderHash, exchangeContractAddress,
+ );
expect(cancelledValueT).to.be.bignumber.equal(0);
});
it ('should return the cancelledValueT for a valid and cancelled orderHash', async () => {
const cancelAmount = fillableAmount.minus(partialFillAmount);
await zeroEx.exchange.cancelOrderAsync(signedOrder, cancelAmount);
- const cancelledValueT = await zeroEx.exchange.getCanceledTakerAmountAsync(orderHash);
+ const cancelledValueT = await zeroEx.exchange.getCanceledTakerAmountAsync(
+ orderHash, exchangeContractAddress,
+ );
expect(cancelledValueT).to.be.bignumber.equal(cancelAmount);
});
});
@@ -672,11 +709,13 @@ describe('ExchangeWrapper', () => {
// Source: https://github.com/mochajs/mocha/issues/2407
it('Should receive the LogFill event when an order is filled', (done: DoneCallback) => {
(async () => {
- const zeroExEvent = await zeroEx.exchange.subscribeAsync(ExchangeEvents.LogFill, subscriptionOpts,
- indexFilterValues);
+ const zeroExEvent = await zeroEx.exchange.subscribeAsync(
+ ExchangeEvents.LogFill, subscriptionOpts, indexFilterValues, exchangeContractAddress,
+ );
zeroExEvent.watch((err: Error, event: ContractEvent) => {
expect(err).to.be.null();
expect(event).to.not.be.undefined();
+ expect(event.event).to.be.equal('LogFill');
done();
});
await zeroEx.exchange.fillOrderAsync(
@@ -686,11 +725,13 @@ describe('ExchangeWrapper', () => {
});
it('Should receive the LogCancel event when an order is cancelled', (done: DoneCallback) => {
(async () => {
- const zeroExEvent = await zeroEx.exchange.subscribeAsync(ExchangeEvents.LogCancel, subscriptionOpts,
- indexFilterValues);
+ const zeroExEvent = await zeroEx.exchange.subscribeAsync(
+ ExchangeEvents.LogCancel, subscriptionOpts, indexFilterValues, exchangeContractAddress,
+ );
zeroExEvent.watch((err: Error, event: ContractEvent) => {
expect(err).to.be.null();
expect(event).to.not.be.undefined();
+ expect(event.event).to.be.equal('LogCancel');
done();
});
await zeroEx.exchange.cancelOrderAsync(signedOrder, cancelTakerAmountInBaseUnits);
@@ -699,7 +740,7 @@ describe('ExchangeWrapper', () => {
it('Outstanding subscriptions are cancelled when zeroEx.setProviderAsync called', (done: DoneCallback) => {
(async () => {
const eventSubscriptionToBeCancelled = await zeroEx.exchange.subscribeAsync(
- ExchangeEvents.LogFill, subscriptionOpts, indexFilterValues,
+ ExchangeEvents.LogFill, subscriptionOpts, indexFilterValues, exchangeContractAddress,
);
eventSubscriptionToBeCancelled.watch((err: Error, event: ContractEvent) => {
done(new Error('Expected this subscription to have been cancelled'));
@@ -709,11 +750,12 @@ describe('ExchangeWrapper', () => {
await zeroEx.setProviderAsync(newProvider);
const eventSubscriptionToStay = await zeroEx.exchange.subscribeAsync(
- ExchangeEvents.LogFill, subscriptionOpts, indexFilterValues,
+ ExchangeEvents.LogFill, subscriptionOpts, indexFilterValues, exchangeContractAddress,
);
eventSubscriptionToStay.watch((err: Error, event: ContractEvent) => {
expect(err).to.be.null();
expect(event).to.not.be.undefined();
+ expect(event.event).to.be.equal('LogFill');
done();
});
await zeroEx.exchange.fillOrderAsync(
@@ -724,7 +766,7 @@ describe('ExchangeWrapper', () => {
it('Should stop watch for events when stopWatchingAsync called on the eventEmitter', (done: DoneCallback) => {
(async () => {
const eventSubscriptionToBeStopped = await zeroEx.exchange.subscribeAsync(
- ExchangeEvents.LogFill, subscriptionOpts, indexFilterValues,
+ ExchangeEvents.LogFill, subscriptionOpts, indexFilterValues, exchangeContractAddress,
);
eventSubscriptionToBeStopped.watch((err: Error, event: ContractEvent) => {
done(new Error('Expected this subscription to have been stopped'));
@@ -770,16 +812,29 @@ describe('ExchangeWrapper', () => {
const signedOrder = await fillScenarios.createFillableSignedOrderAsync(
makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount,
);
- const orderHash = await zeroEx.getOrderHashHexAsync(signedOrder);
+ const orderHash = zeroEx.getOrderHashHex(signedOrder);
const orderHashFromContract = await (zeroEx.exchange as any)
._getOrderHashHexUsingContractCallAsync(signedOrder);
expect(orderHash).to.equal(orderHashFromContract);
});
});
- describe('#getContractAddressAsync', () => {
- it('returns the exchange contract address', async () => {
- const exchangeAddress = await zeroEx.exchange.getContractAddressAsync();
- assert.isETHAddressHex('exchangeAddress', exchangeAddress);
+ describe('#getAvailableContractAddressesAsync', () => {
+ it('returns the exchange contract addresses', async () => {
+ const exchangeAddresses = await zeroEx.exchange.getAvailableContractAddressesAsync();
+ _.map(exchangeAddresses, exchangeAddress => {
+ assert.isETHAddressHex('exchangeAddress', exchangeAddress);
+ });
+ });
+ });
+ describe('#getProxyAuthorizedContractAddressesAsync', () => {
+ it('returns the Proxy authorized exchange contract addresses', async () => {
+ const exchangeAddresses = await zeroEx.exchange.getProxyAuthorizedContractAddressesAsync();
+ for (const exchangeAddress of exchangeAddresses) {
+ assert.isETHAddressHex('exchangeAddress', exchangeAddress);
+ const proxyWrapper = (zeroEx as any)._proxyWrapper as ProxyWrapper;
+ const isAuthorized = await proxyWrapper.isAuthorizedAsync(exchangeAddress);
+ expect(isAuthorized).to.be.true();
+ }
});
});
});