aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-06-09 00:14:29 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-06-09 00:14:29 +0800
commit6eb192f0ea056bc84e04df1845f484a906ad392c (patch)
tree643d52ce23bcc7fd34499c245a4ae335432399ea
parentcd25d38118de90f8282dc8e5e2b4ffb02fde9990 (diff)
downloaddexon-sol-tools-6eb192f0ea056bc84e04df1845f484a906ad392c.tar
dexon-sol-tools-6eb192f0ea056bc84e04df1845f484a906ad392c.tar.gz
dexon-sol-tools-6eb192f0ea056bc84e04df1845f484a906ad392c.tar.bz2
dexon-sol-tools-6eb192f0ea056bc84e04df1845f484a906ad392c.tar.lz
dexon-sol-tools-6eb192f0ea056bc84e04df1845f484a906ad392c.tar.xz
dexon-sol-tools-6eb192f0ea056bc84e04df1845f484a906ad392c.tar.zst
dexon-sol-tools-6eb192f0ea056bc84e04df1845f484a906ad392c.zip
Add tests for fillOrdersUpTo
-rw-r--r--src/contract_wrappers/exchange_wrapper.ts14
-rw-r--r--test/exchange_wrapper_test.ts34
2 files changed, 41 insertions, 7 deletions
diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts
index 524ebdc0f..afaa89c94 100644
--- a/src/contract_wrappers/exchange_wrapper.ts
+++ b/src/contract_wrappers/exchange_wrapper.ts
@@ -180,10 +180,10 @@ export class ExchangeWrapper extends ContractWrapper {
* If fill amount is reached - it succeeds and doesn't fill the rest of the orders.
* If fill amount is not reached - it just fills all the orders.
*/
- public async fillOrderUpToAsync(signedOrders: SignedOrder[], takerTokenFillAmount: BigNumber.BigNumber,
- shouldCheckTransfer: boolean, takerAddress: string): Promise<void> {
+ public async fillOrdersUpToAsync(signedOrders: SignedOrder[], takerTokenFillAmount: BigNumber.BigNumber,
+ shouldCheckTransfer: boolean, takerAddress: string): Promise<void> {
const takerTokenAddresses = _.map(signedOrders, signedOrder => signedOrder.takerTokenAddress);
- assert.assert(_.uniq(takerTokenAddresses).length === 1,
+ assert.assert(_.uniq(takerTokenAddresses).length <= 1,
ExchangeContractErrs.MULTIPLE_TAKER_TOKENS_IN_FILL_UP_TO);
assert.isBigNumber('takerTokenFillAmount', takerTokenFillAmount);
assert.isBoolean('shouldCheckTransfer', shouldCheckTransfer);
@@ -395,11 +395,8 @@ export class ExchangeWrapper extends ContractWrapper {
* All orders must be from the same maker.
*/
public async batchCancelOrderAsync(orderCancellationRequests: OrderCancellationRequest[]): Promise<void> {
- if (_.isEmpty(orderCancellationRequests)) {
- return; // no-op
- }
const makers = _.map(orderCancellationRequests, cancellationRequest => cancellationRequest.order.maker);
- assert.assert(_.uniq(makers).length === 1, ExchangeContractErrs.MULTIPLE_MAKERS_IN_SINGLE_CANCEL_BATCH);
+ assert.assert(_.uniq(makers).length <= 1, ExchangeContractErrs.MULTIPLE_MAKERS_IN_SINGLE_CANCEL_BATCH);
const maker = makers[0];
await assert.isSenderAddressAsync('maker', maker, this.web3Wrapper);
_.forEach(orderCancellationRequests,
@@ -414,6 +411,9 @@ export class ExchangeWrapper extends ContractWrapper {
cancellationRequest.order, cancellationRequest.takerTokenCancelAmount,
);
});
+ if (_.isEmpty(orderCancellationRequests)) {
+ return; // no-op
+ }
const exchangeInstance = await this.getExchangeContractAsync();
const orderAddressesValuesAndTakerTokenCancelAmounts = _.map(orderCancellationRequests, cancellationRequest => {
return [
diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts
index e3d8be1c0..4a1dbaed6 100644
--- a/test/exchange_wrapper_test.ts
+++ b/test/exchange_wrapper_test.ts
@@ -367,6 +367,40 @@ describe('ExchangeWrapper', () => {
});
});
});
+ describe('#fillOrdersUpTo', () => {
+ let signedOrder: SignedOrder;
+ let signedOrderHashHex: string;
+ let anotherSignedOrder: SignedOrder;
+ let anotherOrderHashHex: string;
+ let signedOrders: SignedOrder[];
+ const fillUpToAmount = fillableAmount.plus(fillableAmount).minus(1);
+ beforeEach(async () => {
+ signedOrder = await fillScenarios.createFillableSignedOrderAsync(
+ makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount,
+ );
+ signedOrderHashHex = await zeroEx.getOrderHashHexAsync(signedOrder);
+ anotherSignedOrder = await fillScenarios.createFillableSignedOrderAsync(
+ makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount,
+ );
+ anotherOrderHashHex = await zeroEx.getOrderHashHexAsync(anotherSignedOrder);
+ signedOrders = [signedOrder, anotherSignedOrder];
+ });
+ describe('successful batch fills', () => {
+ it('should no-op for an empty batch', async () => {
+ await zeroEx.exchange.fillOrdersUpToAsync([], fillUpToAmount, shouldCheckTransfer, takerAddress);
+ });
+ it('should successfully fill up to specified amount', async () => {
+ await zeroEx.exchange.fillOrdersUpToAsync(
+ signedOrders, fillUpToAmount, shouldCheckTransfer, takerAddress,
+ );
+ const filledAmount = await zeroEx.exchange.getFilledTakerAmountAsync(signedOrderHashHex);
+ const anotherFilledAmount = await zeroEx.exchange.getFilledTakerAmountAsync(anotherOrderHashHex);
+ expect(filledAmount).to.be.bignumber.equal(fillableAmount);
+ const remainingFillAmount = fillUpToAmount.minus(filledAmount);
+ expect(anotherFilledAmount).to.be.bignumber.equal(remainingFillAmount);
+ });
+ });
+ });
});
describe('cancel order(s)', () => {
let makerTokenAddress: string;