aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/test/exchange
diff options
context:
space:
mode:
authorAmir Bandeali <abandeali1@gmail.com>2018-03-09 07:58:21 +0800
committerAmir Bandeali <abandeali1@gmail.com>2018-04-21 04:56:16 +0800
commit2c44c7ea8333dd26e96acd7869ee60cc1d177da4 (patch)
tree4a35f1fd448ab10461bf6f25607d4224cc97b6fc /packages/contracts/test/exchange
parent9cc1956b4b25081810680d79b12f80727c96c1ef (diff)
downloaddexon-sol-tools-2c44c7ea8333dd26e96acd7869ee60cc1d177da4.tar
dexon-sol-tools-2c44c7ea8333dd26e96acd7869ee60cc1d177da4.tar.gz
dexon-sol-tools-2c44c7ea8333dd26e96acd7869ee60cc1d177da4.tar.bz2
dexon-sol-tools-2c44c7ea8333dd26e96acd7869ee60cc1d177da4.tar.lz
dexon-sol-tools-2c44c7ea8333dd26e96acd7869ee60cc1d177da4.tar.xz
dexon-sol-tools-2c44c7ea8333dd26e96acd7869ee60cc1d177da4.tar.zst
dexon-sol-tools-2c44c7ea8333dd26e96acd7869ee60cc1d177da4.zip
Add fillOrderNoThrow to exchange wrapper and add test
Diffstat (limited to 'packages/contracts/test/exchange')
-rw-r--r--packages/contracts/test/exchange/wrapper.ts54
1 files changed, 48 insertions, 6 deletions
diff --git a/packages/contracts/test/exchange/wrapper.ts b/packages/contracts/test/exchange/wrapper.ts
index 182578f42..e5933a7e7 100644
--- a/packages/contracts/test/exchange/wrapper.ts
+++ b/packages/contracts/test/exchange/wrapper.ts
@@ -111,15 +111,12 @@ describe('Exchange', () => {
});
beforeEach(async () => {
await blockchainLifecycle.startAsync();
+ balances = await dmyBalances.getAsync();
});
afterEach(async () => {
await blockchainLifecycle.revertAsync();
});
describe('fillOrKillOrder', () => {
- beforeEach(async () => {
- balances = await dmyBalances.getAsync();
- });
-
it('should transfer the correct amounts', async () => {
const signedOrder = orderFactory.newSignedOrder({
makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18),
@@ -187,6 +184,52 @@ describe('Exchange', () => {
});
});
+ describe('fillOrderNoThrow', () => {
+ it('should transfer the correct amounts', async () => {
+ const signedOrder = orderFactory.newSignedOrder({
+ makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18),
+ takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18),
+ });
+ const takerTokenFillAmount = signedOrder.takerTokenAmount.div(2);
+ await exWrapper.fillOrderNoThrowAsync(signedOrder, takerAddress, {
+ takerTokenFillAmount,
+ });
+
+ const newBalances = await dmyBalances.getAsync();
+
+ const makerTokenFillAmount = takerTokenFillAmount
+ .times(signedOrder.makerTokenAmount)
+ .dividedToIntegerBy(signedOrder.takerTokenAmount);
+ const makerFeeAmount = signedOrder.makerFeeAmount
+ .times(makerTokenFillAmount)
+ .dividedToIntegerBy(signedOrder.makerTokenAmount);
+ const takerFeeAmount = signedOrder.takerFeeAmount
+ .times(makerTokenFillAmount)
+ .dividedToIntegerBy(signedOrder.makerTokenAmount);
+ expect(newBalances[makerAddress][signedOrder.makerTokenAddress]).to.be.bignumber.equal(
+ balances[makerAddress][signedOrder.makerTokenAddress].minus(makerTokenFillAmount),
+ );
+ expect(newBalances[makerAddress][signedOrder.takerTokenAddress]).to.be.bignumber.equal(
+ balances[makerAddress][signedOrder.takerTokenAddress].add(takerTokenFillAmount),
+ );
+ expect(newBalances[makerAddress][zrx.address]).to.be.bignumber.equal(
+ balances[makerAddress][zrx.address].minus(makerFeeAmount),
+ );
+ expect(newBalances[takerAddress][signedOrder.takerTokenAddress]).to.be.bignumber.equal(
+ balances[takerAddress][signedOrder.takerTokenAddress].minus(takerTokenFillAmount),
+ );
+ expect(newBalances[takerAddress][signedOrder.makerTokenAddress]).to.be.bignumber.equal(
+ balances[takerAddress][signedOrder.makerTokenAddress].add(makerTokenFillAmount),
+ );
+ 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)),
+ );
+ });
+ });
+
describe('batch functions', () => {
let signedOrders: SignedOrder[];
beforeEach(async () => {
@@ -195,7 +238,6 @@ describe('Exchange', () => {
orderFactory.newSignedOrder(),
orderFactory.newSignedOrder(),
];
- balances = await dmyBalances.getAsync();
});
describe('batchFillOrders', () => {
@@ -304,7 +346,7 @@ describe('Exchange', () => {
});
});
- describe('fillOrdersUpTo', () => {
+ describe('marketFillOrders', () => {
it('should stop when the entire takerTokenFillAmount is filled', async () => {
const takerTokenFillAmount = signedOrders[0].takerTokenAmount.plus(
signedOrders[1].takerTokenAmount.div(2),