aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/test/exchange
diff options
context:
space:
mode:
authorGreg Hysen <greg.hysen@gmail.com>2018-03-16 04:58:54 +0800
committerAmir Bandeali <abandeali1@gmail.com>2018-04-21 04:56:17 +0800
commitaeb0742434471c0a4cb28bebf569b0d4af6b4485 (patch)
tree9921cd5df2b80041a0655948961ddb95743e82cc /packages/contracts/test/exchange
parente98b4ea26d90d5d356972fcf038eeef50ebd31f3 (diff)
downloaddexon-sol-tools-aeb0742434471c0a4cb28bebf569b0d4af6b4485.tar
dexon-sol-tools-aeb0742434471c0a4cb28bebf569b0d4af6b4485.tar.gz
dexon-sol-tools-aeb0742434471c0a4cb28bebf569b0d4af6b4485.tar.bz2
dexon-sol-tools-aeb0742434471c0a4cb28bebf569b0d4af6b4485.tar.lz
dexon-sol-tools-aeb0742434471c0a4cb28bebf569b0d4af6b4485.tar.xz
dexon-sol-tools-aeb0742434471c0a4cb28bebf569b0d4af6b4485.tar.zst
dexon-sol-tools-aeb0742434471c0a4cb28bebf569b0d4af6b4485.zip
Implementation and tests in the protocol for cancelling all orders up to a specific time
Diffstat (limited to 'packages/contracts/test/exchange')
-rw-r--r--packages/contracts/test/exchange/core.ts67
1 files changed, 67 insertions, 0 deletions
diff --git a/packages/contracts/test/exchange/core.ts b/packages/contracts/test/exchange/core.ts
index 1612ecdcc..3b787953b 100644
--- a/packages/contracts/test/exchange/core.ts
+++ b/packages/contracts/test/exchange/core.ts
@@ -741,4 +741,71 @@ describe('Exchange', () => {
expect(errCode).to.be.equal(ExchangeContractErrs.ERROR_ORDER_EXPIRED);
});
});
+
+ describe('cancelOrdersBefore', () => {
+ it('should fail to set timestamp less than existing CancelBefore timestamp', async () => {
+ const timestamp = new BigNumber(1);
+ await exWrapper.cancelOrdersBeforeAsync(timestamp, makerAddress);
+ const lesser_timestamp = new BigNumber(0);
+ return expect(
+ exWrapper.cancelOrdersBeforeAsync(lesser_timestamp, makerAddress),
+ ).to.be.rejectedWith(constants.REVERT);
+ });
+
+ it('should fail to set timestamp equal to existing CancelBefore timestamp', async () => {
+ const timestamp = new BigNumber(1);
+ await exWrapper.cancelOrdersBeforeAsync(timestamp, makerAddress);
+ return expect(
+ exWrapper.cancelOrdersBeforeAsync(timestamp, makerAddress),
+ ).to.be.rejectedWith(constants.REVERT);
+ });
+
+ it('should cancel only orders with a timestamp less than CancelBefore timestamp', async () => {
+ // Cancel all transactions with a timestamp less than 1
+ const timestamp = new BigNumber(1);
+ await exWrapper.cancelOrdersBeforeAsync(timestamp, makerAddress);
+
+ // Create 3 orders with timestamps 0,1,2
+ // Since we cancelled with timestamp=1, orders with timestamp<1 will not be processed
+ balances = await dmyBalances.getAsync();
+ const signedOrders = await Promise.all([
+ orderFactory.newSignedOrder({
+ makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(17), 18),
+ takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(17), 18),
+ salt: new BigNumber(0)}),
+ orderFactory.newSignedOrder({
+ makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(97), 18),
+ takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(97), 18),
+ salt: new BigNumber(1)}),
+ orderFactory.newSignedOrder({
+ makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(979), 18),
+ takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(979), 18),
+ salt: new BigNumber(2)}),
+ ]);
+ await exWrapper.batchFillOrdersNoThrowAsync(signedOrders, takerAddress);
+
+ const newBalances = await dmyBalances.getAsync();
+ const fillMakerTokenAmount = signedOrders[1].makerTokenAmount.add(signedOrders[2].makerTokenAmount);
+ const fillTakerTokenAmount = signedOrders[1].takerTokenAmount.add(signedOrders[2].takerTokenAmount);
+ const makerFeeAmount = signedOrders[1].makerFeeAmount.add(signedOrders[2].makerFeeAmount);
+ const takerFeeAmount = signedOrders[1].takerFeeAmount.add(signedOrders[2].takerFeeAmount);
+ expect(newBalances[makerAddress][signedOrders[2].makerTokenAddress]).to.be.bignumber.equal(
+ balances[makerAddress][signedOrders[2].makerTokenAddress].minus(fillMakerTokenAmount),
+ );
+ expect(newBalances[makerAddress][signedOrders[2].takerTokenAddress]).to.be.bignumber.equal(
+ balances[makerAddress][signedOrders[2].takerTokenAddress].add(fillTakerTokenAmount),
+ );
+ expect(newBalances[makerAddress][zrx.address]).to.be.bignumber.equal(balances[makerAddress][zrx.address].minus(makerFeeAmount));
+ expect(newBalances[takerAddress][signedOrders[2].takerTokenAddress]).to.be.bignumber.equal(
+ balances[takerAddress][signedOrders[2].takerTokenAddress].minus(fillTakerTokenAmount),
+ );
+ expect(newBalances[takerAddress][signedOrders[2].makerTokenAddress]).to.be.bignumber.equal(
+ balances[takerAddress][signedOrders[2].makerTokenAddress].add(fillMakerTokenAmount),
+ );
+ expect(newBalances[takerAddress][zrx.address]).to.be.bignumber.equal(balances[takerAddress][zrx.address].minus(takerFeeAmount));
+ expect(newBalances[feeRecipientAddress][zrx.address]).to.be.bignumber.equal(
+ balances[feeRecipientAddress][zrx.address].add(makerFeeAmount.add(takerFeeAmount)),
+ );
+ });
+ });
}); // tslint:disable-line:max-file-line-count