aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorLeonid <logvinov.leon@gmail.com>2017-10-16 16:40:20 +0800
committerGitHub <noreply@github.com>2017-10-16 16:40:20 +0800
commita798f32cc89b61788856073265d20ad3812576ae (patch)
tree43a7ee4b5dab08091178b09985e180ab8de7f53f /test
parentc8b54f3bac33f28c315c7018b3185f59e9a474dc (diff)
parentdf5fe4a84f3c5ee8946fa615428c5b9de8f8b06f (diff)
downloaddexon-sol-tools-a798f32cc89b61788856073265d20ad3812576ae.tar
dexon-sol-tools-a798f32cc89b61788856073265d20ad3812576ae.tar.gz
dexon-sol-tools-a798f32cc89b61788856073265d20ad3812576ae.tar.bz2
dexon-sol-tools-a798f32cc89b61788856073265d20ad3812576ae.tar.lz
dexon-sol-tools-a798f32cc89b61788856073265d20ad3812576ae.tar.xz
dexon-sol-tools-a798f32cc89b61788856073265d20ad3812576ae.tar.zst
dexon-sol-tools-a798f32cc89b61788856073265d20ad3812576ae.zip
Merge branch 'development' into setFillOrKillToUseRequestInterface
Diffstat (limited to 'test')
-rw-r--r--test/0x.js_test.ts6
-rw-r--r--test/ether_token_wrapper_test.ts1
-rw-r--r--test/exchange_transfer_simulator_test.ts4
-rw-r--r--test/exchange_wrapper_test.ts22
-rw-r--r--test/order_validation_test.ts38
-rw-r--r--test/token_wrapper_test.ts29
-rw-r--r--test/utils/fill_scenarios.ts2
7 files changed, 67 insertions, 35 deletions
diff --git a/test/0x.js_test.ts b/test/0x.js_test.ts
index cc6b91e99..dd5dd19b1 100644
--- a/test/0x.js_test.ts
+++ b/test/0x.js_test.ts
@@ -4,7 +4,7 @@ import {chaiSetup} from './utils/chai_setup';
import 'mocha';
import * as BigNumber from 'bignumber.js';
import * as Sinon from 'sinon';
-import {ZeroEx, Order, ZeroExError, LogWithDecodedArgs} from '../src';
+import {ZeroEx, Order, ZeroExError, LogWithDecodedArgs, ApprovalContractEventArgs, TokenEvents} from '../src';
import {constants} from './utils/constants';
import {TokenUtils} from './utils/token_utils';
import {web3Factory} from './utils/web3_factory';
@@ -223,8 +223,8 @@ describe('ZeroEx library', () => {
const proxyAddress = await zeroEx.proxy.getContractAddressAsync();
const txHash = await zeroEx.token.setUnlimitedProxyAllowanceAsync(zrxTokenAddress, coinbase);
const txReceiptWithDecodedLogs = await zeroEx.awaitTransactionMinedAsync(txHash);
- const log = txReceiptWithDecodedLogs.logs[0] as LogWithDecodedArgs;
- expect(log.event).to.be.equal('Approval');
+ const log = txReceiptWithDecodedLogs.logs[0] as LogWithDecodedArgs<ApprovalContractEventArgs>;
+ expect(log.event).to.be.equal(TokenEvents.Approval);
expect(log.args._owner).to.be.equal(coinbase);
expect(log.args._spender).to.be.equal(proxyAddress);
expect(log.args._value).to.be.bignumber.equal(zeroEx.token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS);
diff --git a/test/ether_token_wrapper_test.ts b/test/ether_token_wrapper_test.ts
index f50aac48b..389ec1619 100644
--- a/test/ether_token_wrapper_test.ts
+++ b/test/ether_token_wrapper_test.ts
@@ -3,7 +3,6 @@ import * as chai from 'chai';
import {chaiSetup} from './utils/chai_setup';
import * as Web3 from 'web3';
import * as BigNumber from 'bignumber.js';
-import promisify = require('es6-promisify');
import {web3Factory} from './utils/web3_factory';
import {ZeroEx, ZeroExError} from '../src';
import {BlockchainLifecycle} from './utils/blockchain_lifecycle';
diff --git a/test/exchange_transfer_simulator_test.ts b/test/exchange_transfer_simulator_test.ts
index 6ad2c007c..ee24f4fe4 100644
--- a/test/exchange_transfer_simulator_test.ts
+++ b/test/exchange_transfer_simulator_test.ts
@@ -1,12 +1,10 @@
import * as chai from 'chai';
import * as BigNumber from 'bignumber.js';
-import * as Web3 from 'web3';
import {chaiSetup} from './utils/chai_setup';
import {web3Factory} from './utils/web3_factory';
-import {ZeroEx, SignedOrder, ExchangeContractErrs, Token} from '../src';
+import {ZeroEx, ExchangeContractErrs, Token} from '../src';
import {TradeSide, TransferType} from '../src/types';
import {BlockchainLifecycle} from './utils/blockchain_lifecycle';
-import {FillScenarios} from './utils/fill_scenarios';
import {ExchangeTransferSimulator} from '../src/utils/exchange_transfer_simulator';
chaiSetup.configure();
diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts
index 8c5344b37..f3f16643e 100644
--- a/test/exchange_wrapper_test.ts
+++ b/test/exchange_wrapper_test.ts
@@ -3,8 +3,6 @@ import * as chai from 'chai';
import * as Web3 from 'web3';
import * as BigNumber from 'bignumber.js';
import {chaiSetup} from './utils/chai_setup';
-import ChaiBigNumber = require('chai-bignumber');
-import promisify = require('es6-promisify');
import {web3Factory} from './utils/web3_factory';
import {BlockchainLifecycle} from './utils/blockchain_lifecycle';
import {
@@ -16,15 +14,14 @@ import {
ContractEvent,
ExchangeContractErrs,
OrderCancellationRequest,
- LogFillContractEventArgs,
OrderFillRequest,
+ LogFillContractEventArgs,
+ LogCancelContractEventArgs,
LogEvent,
} from '../src';
import {DoneCallback, BlockParamLiteral} from '../src/types';
import {FillScenarios} from './utils/fill_scenarios';
import {TokenUtils} from './utils/token_utils';
-import {assert} from '../src/utils/assert';
-import {TokenTransferProxyWrapper} from '../src/contract_wrappers/token_transfer_proxy_wrapper';
chaiSetup.configure();
const expect = chai.expect;
@@ -650,7 +647,7 @@ 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 callback = (logEvent: LogEvent) => {
+ const callback = (logEvent: LogEvent<LogFillContractEventArgs>) => {
expect(logEvent.event).to.be.equal(ExchangeEvents.LogFill);
done();
};
@@ -664,7 +661,7 @@ describe('ExchangeWrapper', () => {
});
it('Should receive the LogCancel event when an order is cancelled', (done: DoneCallback) => {
(async () => {
- const callback = (logEvent: LogEvent) => {
+ const callback = (logEvent: LogEvent<LogCancelContractEventArgs>) => {
expect(logEvent.event).to.be.equal(ExchangeEvents.LogCancel);
done();
};
@@ -676,7 +673,7 @@ describe('ExchangeWrapper', () => {
});
it('Outstanding subscriptions are cancelled when zeroEx.setProviderAsync called', (done: DoneCallback) => {
(async () => {
- const callbackNeverToBeCalled = (logEvent: LogEvent) => {
+ const callbackNeverToBeCalled = (logEvent: LogEvent<LogFillContractEventArgs>) => {
done(new Error('Expected this subscription to have been cancelled'));
};
await zeroEx.exchange.subscribeAsync(
@@ -686,7 +683,7 @@ describe('ExchangeWrapper', () => {
const newProvider = web3Factory.getRpcProvider();
await zeroEx.setProviderAsync(newProvider);
- const callback = (logEvent: LogEvent) => {
+ const callback = (logEvent: LogEvent<LogFillContractEventArgs>) => {
expect(logEvent.event).to.be.equal(ExchangeEvents.LogFill);
done();
};
@@ -700,7 +697,7 @@ describe('ExchangeWrapper', () => {
});
it('Should cancel subscription when unsubscribe called', (done: DoneCallback) => {
(async () => {
- const callbackNeverToBeCalled = (logEvent: LogEvent) => {
+ const callbackNeverToBeCalled = (logEvent: LogEvent<LogFillContractEventArgs>) => {
done(new Error('Expected this subscription to have been cancelled'));
};
const subscriptionToken = await zeroEx.exchange.subscribeAsync(
@@ -810,11 +807,12 @@ describe('ExchangeWrapper', () => {
const indexFilterValues = {
maker: differentMakerAddress,
};
- const logs = await zeroEx.exchange.getLogsAsync(
+ const logs = await zeroEx.exchange.getLogsAsync<LogFillContractEventArgs>(
eventName, subscriptionOpts, indexFilterValues,
);
expect(logs).to.have.length(1);
- expect(logs[0].args.maker).to.be.equal(differentMakerAddress);
+ const args = logs[0].args;
+ expect(args.maker).to.be.equal(differentMakerAddress);
});
});
});
diff --git a/test/order_validation_test.ts b/test/order_validation_test.ts
index 6f9388a69..784fa9ec4 100644
--- a/test/order_validation_test.ts
+++ b/test/order_validation_test.ts
@@ -1,7 +1,6 @@
import * as chai from 'chai';
import * as Web3 from 'web3';
import * as BigNumber from 'bignumber.js';
-import promisify = require('es6-promisify');
import * as Sinon from 'sinon';
import {chaiSetup} from './utils/chai_setup';
import {web3Factory} from './utils/web3_factory';
@@ -35,7 +34,6 @@ describe('OrderValidation', () => {
let orderValidationUtils: OrderValidationUtils;
const fillableAmount = new BigNumber(5);
const fillTakerAmount = new BigNumber(5);
- const shouldThrowOnInsufficientBalanceOrAllowance = false;
before(async () => {
web3 = web3Factory.create();
zeroEx = new ZeroEx(web3.currentProvider);
@@ -257,5 +255,41 @@ describe('OrderValidation', () => {
),
).to.be.true();
});
+ it('should call exchangeTransferSimulator.transferFrom with correct values for an open order', async () => {
+ const makerFee = new BigNumber(2);
+ const takerFee = new BigNumber(2);
+ const signedOrder = await fillScenarios.createFillableSignedOrderWithFeesAsync(
+ makerTokenAddress, takerTokenAddress, makerFee, takerFee,
+ makerAddress, ZeroEx.NULL_ADDRESS, fillableAmount, feeRecipient,
+ );
+ await orderValidationUtils.validateFillOrderBalancesAllowancesThrowIfInvalidAsync(
+ exchangeTransferSimulator, signedOrder, fillableAmount, takerAddress, zrxTokenAddress,
+ );
+ expect(transferFromAsync.callCount).to.be.equal(4);
+ expect(
+ transferFromAsync.getCall(0).calledWith(
+ makerTokenAddress, makerAddress, takerAddress, bigNumberMatch(fillableAmount),
+ TradeSide.Maker, TransferType.Trade,
+ ),
+ ).to.be.true();
+ expect(
+ transferFromAsync.getCall(1).calledWith(
+ takerTokenAddress, takerAddress, makerAddress, bigNumberMatch(fillableAmount),
+ TradeSide.Taker, TransferType.Trade,
+ ),
+ ).to.be.true();
+ expect(
+ transferFromAsync.getCall(2).calledWith(
+ zrxTokenAddress, makerAddress, feeRecipient, bigNumberMatch(makerFee),
+ TradeSide.Maker, TransferType.Fee,
+ ),
+ ).to.be.true();
+ expect(
+ transferFromAsync.getCall(3).calledWith(
+ zrxTokenAddress, takerAddress, feeRecipient, bigNumberMatch(takerFee),
+ TradeSide.Taker, TransferType.Fee,
+ ),
+ ).to.be.true();
+ });
});
});
diff --git a/test/token_wrapper_test.ts b/test/token_wrapper_test.ts
index 50f2db2ac..f1f6543b7 100644
--- a/test/token_wrapper_test.ts
+++ b/test/token_wrapper_test.ts
@@ -14,6 +14,7 @@ import {
ContractEvent,
TransferContractEventArgs,
ApprovalContractEventArgs,
+ TokenContractEventArgs,
LogWithDecodedArgs,
LogEvent,
} from '../src';
@@ -357,9 +358,9 @@ describe('TokenWrapper', () => {
// Source: https://github.com/mochajs/mocha/issues/2407
it('Should receive the Transfer event when tokens are transfered', (done: DoneCallback) => {
(async () => {
- const callback = (logEvent: LogEvent) => {
+ const callback = (logEvent: LogEvent<TransferContractEventArgs>) => {
expect(logEvent).to.not.be.undefined();
- const args = logEvent.args as any as TransferContractEventArgs;
+ const args = logEvent.args;
expect(args._from).to.be.equal(coinbase);
expect(args._to).to.be.equal(addressWithoutFunds);
expect(args._value).to.be.bignumber.equal(transferAmount);
@@ -372,9 +373,9 @@ describe('TokenWrapper', () => {
});
it('Should receive the Approval event when allowance is being set', (done: DoneCallback) => {
(async () => {
- const callback = (logEvent: LogEvent) => {
+ const callback = (logEvent: LogEvent<ApprovalContractEventArgs>) => {
expect(logEvent).to.not.be.undefined();
- const args = logEvent.args as any as ApprovalContractEventArgs;
+ const args = logEvent.args;
expect(args._owner).to.be.equal(coinbase);
expect(args._spender).to.be.equal(addressWithoutFunds);
expect(args._value).to.be.bignumber.equal(allowanceAmount);
@@ -387,13 +388,13 @@ describe('TokenWrapper', () => {
});
it('Outstanding subscriptions are cancelled when zeroEx.setProviderAsync called', (done: DoneCallback) => {
(async () => {
- const callbackNeverToBeCalled = (logEvent: LogEvent) => {
+ const callbackNeverToBeCalled = (logEvent: LogEvent<TransferContractEventArgs>) => {
done(new Error('Expected this subscription to have been cancelled'));
};
zeroEx.token.subscribe(
tokenAddress, TokenEvents.Transfer, indexFilterValues, callbackNeverToBeCalled,
);
- const callbackToBeCalled = (logEvent: LogEvent) => {
+ const callbackToBeCalled = (logEvent: LogEvent<TransferContractEventArgs>) => {
done();
};
const newProvider = web3Factory.getRpcProvider();
@@ -406,7 +407,7 @@ describe('TokenWrapper', () => {
});
it('Should cancel subscription when unsubscribe called', (done: DoneCallback) => {
(async () => {
- const callbackNeverToBeCalled = (logEvent: LogEvent) => {
+ const callbackNeverToBeCalled = (logEvent: LogEvent<TokenContractEventArgs>) => {
done(new Error('Expected this subscription to have been cancelled'));
};
const subscriptionToken = zeroEx.token.subscribe(
@@ -435,14 +436,15 @@ describe('TokenWrapper', () => {
await zeroEx.awaitTransactionMinedAsync(txHash);
const eventName = TokenEvents.Approval;
const indexFilterValues = {};
- const logs = await zeroEx.token.getLogsAsync(
+ const logs = await zeroEx.token.getLogsAsync<ApprovalContractEventArgs>(
tokenAddress, eventName, subscriptionOpts, indexFilterValues,
);
expect(logs).to.have.length(1);
+ const args = logs[0].args;
expect(logs[0].event).to.be.equal(eventName);
- expect(logs[0].args._owner).to.be.equal(coinbase);
- expect(logs[0].args._spender).to.be.equal(tokenTransferProxyAddress);
- expect(logs[0].args._value).to.be.bignumber.equal(zeroEx.token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS);
+ expect(args._owner).to.be.equal(coinbase);
+ expect(args._spender).to.be.equal(tokenTransferProxyAddress);
+ expect(args._value).to.be.bignumber.equal(zeroEx.token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS);
});
it('should only get the logs with the correct event name', async () => {
txHash = await zeroEx.token.setUnlimitedProxyAllowanceAsync(tokenAddress, coinbase);
@@ -463,11 +465,12 @@ describe('TokenWrapper', () => {
const indexFilterValues = {
_owner: coinbase,
};
- const logs = await zeroEx.token.getLogsAsync(
+ const logs = await zeroEx.token.getLogsAsync<ApprovalContractEventArgs>(
tokenAddress, eventName, subscriptionOpts, indexFilterValues,
);
expect(logs).to.have.length(1);
- expect(logs[0].args._owner).to.be.equal(coinbase);
+ const args = logs[0].args;
+ expect(args._owner).to.be.equal(coinbase);
});
});
});
diff --git a/test/utils/fill_scenarios.ts b/test/utils/fill_scenarios.ts
index e305759f6..c399c7bf4 100644
--- a/test/utils/fill_scenarios.ts
+++ b/test/utils/fill_scenarios.ts
@@ -91,7 +91,7 @@ export class FillScenarios {
}
private async increaseBalanceAndAllowanceAsync(
tokenAddress: string, address: string, amount: BigNumber.BigNumber): Promise<void> {
- if (amount.isZero()) {
+ if (amount.isZero() || address === ZeroEx.NULL_ADDRESS) {
return; // noop
}
await Promise.all([