aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/test
diff options
context:
space:
mode:
authorAmir Bandeali <abandeali1@gmail.com>2018-03-30 03:38:13 +0800
committerAmir Bandeali <abandeali1@gmail.com>2018-04-21 04:56:17 +0800
commit0c74a3bc6610a9c71bf2c5111138ae3e162cffd6 (patch)
tree5ee33615d71824285f0da796c6e40926a3d01656 /packages/contracts/test
parent75f77f3e8675c468d88456aec02561732c7646fb (diff)
downloaddexon-sol-tools-0c74a3bc6610a9c71bf2c5111138ae3e162cffd6.tar
dexon-sol-tools-0c74a3bc6610a9c71bf2c5111138ae3e162cffd6.tar.gz
dexon-sol-tools-0c74a3bc6610a9c71bf2c5111138ae3e162cffd6.tar.bz2
dexon-sol-tools-0c74a3bc6610a9c71bf2c5111138ae3e162cffd6.tar.lz
dexon-sol-tools-0c74a3bc6610a9c71bf2c5111138ae3e162cffd6.tar.xz
dexon-sol-tools-0c74a3bc6610a9c71bf2c5111138ae3e162cffd6.tar.zst
dexon-sol-tools-0c74a3bc6610a9c71bf2c5111138ae3e162cffd6.zip
Add tests for marketBuyOrders
Diffstat (limited to 'packages/contracts/test')
-rw-r--r--packages/contracts/test/exchange/wrapper.ts174
1 files changed, 172 insertions, 2 deletions
diff --git a/packages/contracts/test/exchange/wrapper.ts b/packages/contracts/test/exchange/wrapper.ts
index 00e703b2f..295d5b204 100644
--- a/packages/contracts/test/exchange/wrapper.ts
+++ b/packages/contracts/test/exchange/wrapper.ts
@@ -539,7 +539,7 @@ describe('Exchange', () => {
});
});
- describe('marketFillOrders', () => {
+ describe('marketSellOrders', () => {
it('should stop when the entire takerSellAmount is filled', async () => {
const takerSellAmount = signedOrders[0].makerBuyAmount.plus(signedOrders[1].makerBuyAmount.div(2));
await exWrapper.marketSellOrdersAsync(signedOrders, takerAddress, {
@@ -624,7 +624,7 @@ describe('Exchange', () => {
});
});
- describe('marketFillOrdersNoThrow', () => {
+ describe('marketSellOrdersNoThrow', () => {
it('should stop when the entire takerSellAmount is filled', async () => {
const takerSellAmount = signedOrders[0].makerBuyAmount.plus(signedOrders[1].makerBuyAmount.div(2));
await exWrapper.marketSellOrdersNoThrowAsync(signedOrders, takerAddress, {
@@ -709,6 +709,176 @@ describe('Exchange', () => {
});
});
+ describe('marketBuyOrders', () => {
+ it('should stop when the entire takerBuyAmount is filled', async () => {
+ const takerBuyAmount = signedOrders[0].makerSellAmount.plus(signedOrders[1].makerSellAmount.div(2));
+ await exWrapper.marketBuyOrdersAsync(signedOrders, takerAddress, {
+ takerBuyAmount,
+ });
+
+ const newBalances = await dmyBalances.getAsync();
+
+ const makerAmountBought = signedOrders[0].makerBuyAmount.add(
+ signedOrders[1].makerBuyAmount.dividedToIntegerBy(2),
+ );
+ const makerFee = signedOrders[0].makerFee.add(signedOrders[1].makerFee.dividedToIntegerBy(2));
+ const takerFee = signedOrders[0].takerFee.add(signedOrders[1].takerFee.dividedToIntegerBy(2));
+ expect(newBalances[makerAddress][signedOrders[0].makerTokenAddress]).to.be.bignumber.equal(
+ balances[makerAddress][signedOrders[0].makerTokenAddress].minus(takerBuyAmount),
+ );
+ expect(newBalances[makerAddress][signedOrders[0].takerTokenAddress]).to.be.bignumber.equal(
+ balances[makerAddress][signedOrders[0].takerTokenAddress].add(makerAmountBought),
+ );
+ expect(newBalances[makerAddress][zrx.address]).to.be.bignumber.equal(
+ balances[makerAddress][zrx.address].minus(makerFee),
+ );
+ expect(newBalances[takerAddress][signedOrders[0].takerTokenAddress]).to.be.bignumber.equal(
+ balances[takerAddress][signedOrders[0].takerTokenAddress].minus(makerAmountBought),
+ );
+ expect(newBalances[takerAddress][signedOrders[0].makerTokenAddress]).to.be.bignumber.equal(
+ balances[takerAddress][signedOrders[0].makerTokenAddress].add(takerBuyAmount),
+ );
+ expect(newBalances[takerAddress][zrx.address]).to.be.bignumber.equal(
+ balances[takerAddress][zrx.address].minus(takerFee),
+ );
+ expect(newBalances[feeRecipientAddress][zrx.address]).to.be.bignumber.equal(
+ balances[feeRecipientAddress][zrx.address].add(makerFee.add(takerFee)),
+ );
+ });
+
+ it('should fill all signedOrders if cannot fill entire takerBuyAmount', async () => {
+ const takerBuyAmount = ZeroEx.toBaseUnitAmount(new BigNumber(100000), 18);
+ _.forEach(signedOrders, signedOrder => {
+ balances[makerAddress][signedOrder.makerTokenAddress] = balances[makerAddress][
+ signedOrder.makerTokenAddress
+ ].minus(signedOrder.makerSellAmount);
+ balances[makerAddress][signedOrder.takerTokenAddress] = balances[makerAddress][
+ signedOrder.takerTokenAddress
+ ].add(signedOrder.makerBuyAmount);
+ balances[makerAddress][zrx.address] = balances[makerAddress][zrx.address].minus(
+ signedOrder.makerFee,
+ );
+ balances[takerAddress][signedOrder.makerTokenAddress] = balances[takerAddress][
+ signedOrder.makerTokenAddress
+ ].add(signedOrder.makerSellAmount);
+ balances[takerAddress][signedOrder.takerTokenAddress] = balances[takerAddress][
+ signedOrder.takerTokenAddress
+ ].minus(signedOrder.makerBuyAmount);
+ balances[takerAddress][zrx.address] = balances[takerAddress][zrx.address].minus(
+ signedOrder.takerFee,
+ );
+ balances[feeRecipientAddress][zrx.address] = balances[feeRecipientAddress][zrx.address].add(
+ signedOrder.makerFee.add(signedOrder.takerFee),
+ );
+ });
+ await exWrapper.marketBuyOrdersAsync(signedOrders, takerAddress, {
+ takerBuyAmount,
+ });
+
+ const newBalances = await dmyBalances.getAsync();
+ expect(newBalances).to.be.deep.equal(balances);
+ });
+
+ it('should throw when an signedOrder does not use the same makerTokenAddress', async () => {
+ signedOrders = [
+ orderFactory.newSignedOrder(),
+ orderFactory.newSignedOrder({ makerTokenAddress: zrx.address }),
+ orderFactory.newSignedOrder(),
+ ];
+
+ return expect(
+ exWrapper.marketBuyOrdersAsync(signedOrders, takerAddress, {
+ takerBuyAmount: ZeroEx.toBaseUnitAmount(new BigNumber(1000), 18),
+ }),
+ ).to.be.rejectedWith(constants.REVERT);
+ });
+ });
+
+ describe('marketBuyOrdersNoThrow', () => {
+ it('should stop when the entire takerBuyAmount is filled', async () => {
+ const takerBuyAmount = signedOrders[0].makerSellAmount.plus(signedOrders[1].makerSellAmount.div(2));
+ await exWrapper.marketBuyOrdersNoThrowAsync(signedOrders, takerAddress, {
+ takerBuyAmount,
+ });
+
+ const newBalances = await dmyBalances.getAsync();
+
+ const makerAmountBought = signedOrders[0].makerBuyAmount.add(
+ signedOrders[1].makerBuyAmount.dividedToIntegerBy(2),
+ );
+ const makerFee = signedOrders[0].makerFee.add(signedOrders[1].makerFee.dividedToIntegerBy(2));
+ const takerFee = signedOrders[0].takerFee.add(signedOrders[1].takerFee.dividedToIntegerBy(2));
+ expect(newBalances[makerAddress][signedOrders[0].makerTokenAddress]).to.be.bignumber.equal(
+ balances[makerAddress][signedOrders[0].makerTokenAddress].minus(takerBuyAmount),
+ );
+ expect(newBalances[makerAddress][signedOrders[0].takerTokenAddress]).to.be.bignumber.equal(
+ balances[makerAddress][signedOrders[0].takerTokenAddress].add(makerAmountBought),
+ );
+ expect(newBalances[makerAddress][zrx.address]).to.be.bignumber.equal(
+ balances[makerAddress][zrx.address].minus(makerFee),
+ );
+ expect(newBalances[takerAddress][signedOrders[0].takerTokenAddress]).to.be.bignumber.equal(
+ balances[takerAddress][signedOrders[0].takerTokenAddress].minus(makerAmountBought),
+ );
+ expect(newBalances[takerAddress][signedOrders[0].makerTokenAddress]).to.be.bignumber.equal(
+ balances[takerAddress][signedOrders[0].makerTokenAddress].add(takerBuyAmount),
+ );
+ expect(newBalances[takerAddress][zrx.address]).to.be.bignumber.equal(
+ balances[takerAddress][zrx.address].minus(takerFee),
+ );
+ expect(newBalances[feeRecipientAddress][zrx.address]).to.be.bignumber.equal(
+ balances[feeRecipientAddress][zrx.address].add(makerFee.add(takerFee)),
+ );
+ });
+
+ it('should fill all signedOrders if cannot fill entire takerSellAmount', async () => {
+ const takerSellAmount = ZeroEx.toBaseUnitAmount(new BigNumber(100000), 18);
+ _.forEach(signedOrders, signedOrder => {
+ balances[makerAddress][signedOrder.makerTokenAddress] = balances[makerAddress][
+ signedOrder.makerTokenAddress
+ ].minus(signedOrder.makerSellAmount);
+ balances[makerAddress][signedOrder.takerTokenAddress] = balances[makerAddress][
+ signedOrder.takerTokenAddress
+ ].add(signedOrder.makerBuyAmount);
+ balances[makerAddress][zrx.address] = balances[makerAddress][zrx.address].minus(
+ signedOrder.makerFee,
+ );
+ balances[takerAddress][signedOrder.makerTokenAddress] = balances[takerAddress][
+ signedOrder.makerTokenAddress
+ ].add(signedOrder.makerSellAmount);
+ balances[takerAddress][signedOrder.takerTokenAddress] = balances[takerAddress][
+ signedOrder.takerTokenAddress
+ ].minus(signedOrder.makerBuyAmount);
+ balances[takerAddress][zrx.address] = balances[takerAddress][zrx.address].minus(
+ signedOrder.takerFee,
+ );
+ balances[feeRecipientAddress][zrx.address] = balances[feeRecipientAddress][zrx.address].add(
+ signedOrder.makerFee.add(signedOrder.takerFee),
+ );
+ });
+ await exWrapper.marketSellOrdersNoThrowAsync(signedOrders, takerAddress, {
+ takerSellAmount,
+ });
+
+ const newBalances = await dmyBalances.getAsync();
+ expect(newBalances).to.be.deep.equal(balances);
+ });
+
+ it('should throw when a signedOrder does not use the same makerTokenAddress', async () => {
+ signedOrders = [
+ orderFactory.newSignedOrder(),
+ orderFactory.newSignedOrder({ makerTokenAddress: zrx.address }),
+ orderFactory.newSignedOrder(),
+ ];
+
+ return expect(
+ exWrapper.marketBuyOrdersNoThrowAsync(signedOrders, takerAddress, {
+ takerBuyAmount: ZeroEx.toBaseUnitAmount(new BigNumber(1000), 18),
+ }),
+ ).to.be.rejectedWith(constants.REVERT);
+ });
+ });
+
describe('batchCancelOrders', () => {
it('should be able to cancel multiple signedOrders', async () => {
const takerTokenCancelAmounts = _.map(signedOrders, signedOrder => signedOrder.makerBuyAmount);