diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-02-07 20:41:30 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-02-07 20:41:30 +0800 |
commit | 568e4d33f29db2f5c0195585438e18ab4b2aea18 (patch) | |
tree | 4f2372dc040f4354d51cfb2229391cfd7c033264 /packages/contracts/test/exchange/wrapper.ts | |
parent | fd004032cb23998184a78ac4a0a486ef1bd04c25 (diff) | |
download | dexon-sol-tools-568e4d33f29db2f5c0195585438e18ab4b2aea18.tar dexon-sol-tools-568e4d33f29db2f5c0195585438e18ab4b2aea18.tar.gz dexon-sol-tools-568e4d33f29db2f5c0195585438e18ab4b2aea18.tar.bz2 dexon-sol-tools-568e4d33f29db2f5c0195585438e18ab4b2aea18.tar.lz dexon-sol-tools-568e4d33f29db2f5c0195585438e18ab4b2aea18.tar.xz dexon-sol-tools-568e4d33f29db2f5c0195585438e18ab4b2aea18.tar.zst dexon-sol-tools-568e4d33f29db2f5c0195585438e18ab4b2aea18.zip |
Use Order and SignedOrder type from 0x.js
Diffstat (limited to 'packages/contracts/test/exchange/wrapper.ts')
-rw-r--r-- | packages/contracts/test/exchange/wrapper.ts | 154 |
1 files changed, 73 insertions, 81 deletions
diff --git a/packages/contracts/test/exchange/wrapper.ts b/packages/contracts/test/exchange/wrapper.ts index 02d722ed5..b4ac12730 100644 --- a/packages/contracts/test/exchange/wrapper.ts +++ b/packages/contracts/test/exchange/wrapper.ts @@ -1,4 +1,4 @@ -import { ZeroEx } from '0x.js'; +import { SignedOrder, ZeroEx } from '0x.js'; import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils'; import { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; @@ -13,9 +13,7 @@ import { TokenTransferProxyContract } from '../../src/contract_wrappers/generate import { Balances } from '../../util/balances'; import { constants } from '../../util/constants'; import { ExchangeWrapper } from '../../util/exchange_wrapper'; -import { Order } from '../../util/order'; import { OrderFactory } from '../../util/order_factory'; -import { SignedOrder } from '../../util/signed_order'; import { BalancesByOwner, ContractName } from '../../util/types'; import { chaiSetup } from '../utils/chai_setup'; import { deployer } from '../utils/deployer'; @@ -77,15 +75,15 @@ describe('Exchange', () => { exchangeContractAddress: exchange.address, maker, feeRecipient, - makerToken: rep.address, - takerToken: dgd.address, + makerTokenAddress: rep.address, + takerTokenAddress: dgd.address, makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18), takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18), makerFee: ZeroEx.toBaseUnitAmount(new BigNumber(1), 18), takerFee: ZeroEx.toBaseUnitAmount(new BigNumber(1), 18), }; - orderFactory = new OrderFactory(web3Wrapper, defaultOrderParams); + orderFactory = new OrderFactory(zeroEx, defaultOrderParams); dmyBalances = new Balances([rep, dgd, zrx], [maker, taker, feeRecipient]); await Promise.all([ rep.approve.sendTransactionAsync(tokenTransferProxy.address, INIT_ALLOW, { from: maker }), @@ -118,7 +116,7 @@ describe('Exchange', () => { makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18), takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18), }); - const fillTakerTokenAmount = order.params.takerTokenAmount.div(2); + const fillTakerTokenAmount = order.takerTokenAmount.div(2); await exWrapper.fillOrKillOrderAsync(order, taker, { fillTakerTokenAmount, }); @@ -126,26 +124,22 @@ describe('Exchange', () => { const newBalances = await dmyBalances.getAsync(); const fillMakerTokenAmount = fillTakerTokenAmount - .times(order.params.makerTokenAmount) - .dividedToIntegerBy(order.params.takerTokenAmount); - const makerFee = order.params.makerFee - .times(fillMakerTokenAmount) - .dividedToIntegerBy(order.params.makerTokenAmount); - const takerFee = order.params.takerFee - .times(fillMakerTokenAmount) - .dividedToIntegerBy(order.params.makerTokenAmount); - expect(newBalances[maker][order.params.makerToken]).to.be.bignumber.equal( - balances[maker][order.params.makerToken].minus(fillMakerTokenAmount), + .times(order.makerTokenAmount) + .dividedToIntegerBy(order.takerTokenAmount); + const makerFee = order.makerFee.times(fillMakerTokenAmount).dividedToIntegerBy(order.makerTokenAmount); + const takerFee = order.takerFee.times(fillMakerTokenAmount).dividedToIntegerBy(order.makerTokenAmount); + expect(newBalances[maker][order.makerTokenAddress]).to.be.bignumber.equal( + balances[maker][order.makerTokenAddress].minus(fillMakerTokenAmount), ); - expect(newBalances[maker][order.params.takerToken]).to.be.bignumber.equal( - balances[maker][order.params.takerToken].add(fillTakerTokenAmount), + expect(newBalances[maker][order.takerTokenAddress]).to.be.bignumber.equal( + balances[maker][order.takerTokenAddress].add(fillTakerTokenAmount), ); expect(newBalances[maker][zrx.address]).to.be.bignumber.equal(balances[maker][zrx.address].minus(makerFee)); - expect(newBalances[taker][order.params.takerToken]).to.be.bignumber.equal( - balances[taker][order.params.takerToken].minus(fillTakerTokenAmount), + expect(newBalances[taker][order.takerTokenAddress]).to.be.bignumber.equal( + balances[taker][order.takerTokenAddress].minus(fillTakerTokenAmount), ); - expect(newBalances[taker][order.params.makerToken]).to.be.bignumber.equal( - balances[taker][order.params.makerToken].add(fillMakerTokenAmount), + expect(newBalances[taker][order.makerTokenAddress]).to.be.bignumber.equal( + balances[taker][order.makerTokenAddress].add(fillMakerTokenAmount), ); expect(newBalances[taker][zrx.address]).to.be.bignumber.equal(balances[taker][zrx.address].minus(takerFee)); expect(newBalances[feeRecipient][zrx.address]).to.be.bignumber.equal( @@ -155,7 +149,7 @@ describe('Exchange', () => { it('should throw if an order is expired', async () => { const order = await orderFactory.newSignedOrderAsync({ - expirationTimestampInSec: new BigNumber(Math.floor((Date.now() - 10000) / 1000)), + expirationUnixTimestampSec: new BigNumber(Math.floor((Date.now() - 10000) / 1000)), }); return expect(exWrapper.fillOrKillOrderAsync(order, taker)).to.be.rejectedWith(constants.REVERT); @@ -166,7 +160,7 @@ describe('Exchange', () => { const from = taker; await exWrapper.fillOrderAsync(order, from, { - fillTakerTokenAmount: order.params.takerTokenAmount.div(2), + fillTakerTokenAmount: order.takerTokenAmount.div(2), }); return expect(exWrapper.fillOrKillOrderAsync(order, taker)).to.be.rejectedWith(constants.REVERT); @@ -187,25 +181,25 @@ describe('Exchange', () => { describe('batchFillOrders', () => { it('should transfer the correct amounts', async () => { const fillTakerTokenAmounts: BigNumber[] = []; - const makerToken = rep.address; - const takerToken = dgd.address; + const makerTokenAddress = rep.address; + const takerTokenAddress = dgd.address; orders.forEach(order => { - const fillTakerTokenAmount = order.params.takerTokenAmount.div(2); + const fillTakerTokenAmount = order.takerTokenAmount.div(2); const fillMakerTokenAmount = fillTakerTokenAmount - .times(order.params.makerTokenAmount) - .dividedToIntegerBy(order.params.takerTokenAmount); - const makerFee = order.params.makerFee + .times(order.makerTokenAmount) + .dividedToIntegerBy(order.takerTokenAmount); + const makerFee = order.makerFee .times(fillMakerTokenAmount) - .dividedToIntegerBy(order.params.makerTokenAmount); - const takerFee = order.params.takerFee + .dividedToIntegerBy(order.makerTokenAmount); + const takerFee = order.takerFee .times(fillMakerTokenAmount) - .dividedToIntegerBy(order.params.makerTokenAmount); + .dividedToIntegerBy(order.makerTokenAmount); fillTakerTokenAmounts.push(fillTakerTokenAmount); - balances[maker][makerToken] = balances[maker][makerToken].minus(fillMakerTokenAmount); - balances[maker][takerToken] = balances[maker][takerToken].add(fillTakerTokenAmount); + balances[maker][makerTokenAddress] = balances[maker][makerTokenAddress].minus(fillMakerTokenAmount); + balances[maker][takerTokenAddress] = balances[maker][takerTokenAddress].add(fillTakerTokenAmount); balances[maker][zrx.address] = balances[maker][zrx.address].minus(makerFee); - balances[taker][makerToken] = balances[taker][makerToken].add(fillMakerTokenAmount); - balances[taker][takerToken] = balances[taker][takerToken].minus(fillTakerTokenAmount); + balances[taker][makerTokenAddress] = balances[taker][makerTokenAddress].add(fillMakerTokenAmount); + balances[taker][takerTokenAddress] = balances[taker][takerTokenAddress].minus(fillTakerTokenAmount); balances[taker][zrx.address] = balances[taker][zrx.address].minus(takerFee); balances[feeRecipient][zrx.address] = balances[feeRecipient][zrx.address].add( makerFee.add(takerFee), @@ -224,25 +218,25 @@ describe('Exchange', () => { describe('batchFillOrKillOrders', () => { it('should transfer the correct amounts', async () => { const fillTakerTokenAmounts: BigNumber[] = []; - const makerToken = rep.address; - const takerToken = dgd.address; + const makerTokenAddress = rep.address; + const takerTokenAddress = dgd.address; orders.forEach(order => { - const fillTakerTokenAmount = order.params.takerTokenAmount.div(2); + const fillTakerTokenAmount = order.takerTokenAmount.div(2); const fillMakerTokenAmount = fillTakerTokenAmount - .times(order.params.makerTokenAmount) - .dividedToIntegerBy(order.params.takerTokenAmount); - const makerFee = order.params.makerFee + .times(order.makerTokenAmount) + .dividedToIntegerBy(order.takerTokenAmount); + const makerFee = order.makerFee .times(fillMakerTokenAmount) - .dividedToIntegerBy(order.params.makerTokenAmount); - const takerFee = order.params.takerFee + .dividedToIntegerBy(order.makerTokenAmount); + const takerFee = order.takerFee .times(fillMakerTokenAmount) - .dividedToIntegerBy(order.params.makerTokenAmount); + .dividedToIntegerBy(order.makerTokenAmount); fillTakerTokenAmounts.push(fillTakerTokenAmount); - balances[maker][makerToken] = balances[maker][makerToken].minus(fillMakerTokenAmount); - balances[maker][takerToken] = balances[maker][takerToken].add(fillTakerTokenAmount); + balances[maker][makerTokenAddress] = balances[maker][makerTokenAddress].minus(fillMakerTokenAmount); + balances[maker][takerTokenAddress] = balances[maker][takerTokenAddress].add(fillTakerTokenAmount); balances[maker][zrx.address] = balances[maker][zrx.address].minus(makerFee); - balances[taker][makerToken] = balances[taker][makerToken].add(fillMakerTokenAmount); - balances[taker][takerToken] = balances[taker][takerToken].minus(fillTakerTokenAmount); + balances[taker][makerTokenAddress] = balances[taker][makerTokenAddress].add(fillMakerTokenAmount); + balances[taker][takerTokenAddress] = balances[taker][takerTokenAddress].minus(fillTakerTokenAmount); balances[taker][zrx.address] = balances[taker][zrx.address].minus(takerFee); balances[feeRecipient][zrx.address] = balances[feeRecipient][zrx.address].add( makerFee.add(takerFee), @@ -260,7 +254,7 @@ describe('Exchange', () => { it('should throw if a single order does not fill the expected amount', async () => { const fillTakerTokenAmounts: BigNumber[] = []; orders.forEach(order => { - const fillTakerTokenAmount = order.params.takerTokenAmount.div(2); + const fillTakerTokenAmount = order.takerTokenAmount.div(2); fillTakerTokenAmounts.push(fillTakerTokenAmount); }); @@ -276,34 +270,32 @@ describe('Exchange', () => { describe('fillOrdersUpTo', () => { it('should stop when the entire fillTakerTokenAmount is filled', async () => { - const fillTakerTokenAmount = orders[0].params.takerTokenAmount.plus( - orders[1].params.takerTokenAmount.div(2), - ); + const fillTakerTokenAmount = orders[0].takerTokenAmount.plus(orders[1].takerTokenAmount.div(2)); await exWrapper.fillOrdersUpToAsync(orders, taker, { fillTakerTokenAmount, }); const newBalances = await dmyBalances.getAsync(); - const fillMakerTokenAmount = orders[0].params.makerTokenAmount.add( - orders[1].params.makerTokenAmount.dividedToIntegerBy(2), + const fillMakerTokenAmount = orders[0].makerTokenAmount.add( + orders[1].makerTokenAmount.dividedToIntegerBy(2), ); - const makerFee = orders[0].params.makerFee.add(orders[1].params.makerFee.dividedToIntegerBy(2)); - const takerFee = orders[0].params.takerFee.add(orders[1].params.takerFee.dividedToIntegerBy(2)); - expect(newBalances[maker][orders[0].params.makerToken]).to.be.bignumber.equal( - balances[maker][orders[0].params.makerToken].minus(fillMakerTokenAmount), + const makerFee = orders[0].makerFee.add(orders[1].makerFee.dividedToIntegerBy(2)); + const takerFee = orders[0].takerFee.add(orders[1].takerFee.dividedToIntegerBy(2)); + expect(newBalances[maker][orders[0].makerTokenAddress]).to.be.bignumber.equal( + balances[maker][orders[0].makerTokenAddress].minus(fillMakerTokenAmount), ); - expect(newBalances[maker][orders[0].params.takerToken]).to.be.bignumber.equal( - balances[maker][orders[0].params.takerToken].add(fillTakerTokenAmount), + expect(newBalances[maker][orders[0].takerTokenAddress]).to.be.bignumber.equal( + balances[maker][orders[0].takerTokenAddress].add(fillTakerTokenAmount), ); expect(newBalances[maker][zrx.address]).to.be.bignumber.equal( balances[maker][zrx.address].minus(makerFee), ); - expect(newBalances[taker][orders[0].params.takerToken]).to.be.bignumber.equal( - balances[taker][orders[0].params.takerToken].minus(fillTakerTokenAmount), + expect(newBalances[taker][orders[0].takerTokenAddress]).to.be.bignumber.equal( + balances[taker][orders[0].takerTokenAddress].minus(fillTakerTokenAmount), ); - expect(newBalances[taker][orders[0].params.makerToken]).to.be.bignumber.equal( - balances[taker][orders[0].params.makerToken].add(fillMakerTokenAmount), + expect(newBalances[taker][orders[0].makerTokenAddress]).to.be.bignumber.equal( + balances[taker][orders[0].makerTokenAddress].add(fillMakerTokenAmount), ); expect(newBalances[taker][zrx.address]).to.be.bignumber.equal( balances[taker][zrx.address].minus(takerFee), @@ -316,22 +308,22 @@ describe('Exchange', () => { it('should fill all orders if cannot fill entire fillTakerTokenAmount', async () => { const fillTakerTokenAmount = ZeroEx.toBaseUnitAmount(new BigNumber(100000), 18); orders.forEach(order => { - balances[maker][order.params.makerToken] = balances[maker][order.params.makerToken].minus( - order.params.makerTokenAmount, + balances[maker][order.makerTokenAddress] = balances[maker][order.makerTokenAddress].minus( + order.makerTokenAmount, ); - balances[maker][order.params.takerToken] = balances[maker][order.params.takerToken].add( - order.params.takerTokenAmount, + balances[maker][order.takerTokenAddress] = balances[maker][order.takerTokenAddress].add( + order.takerTokenAmount, ); - balances[maker][zrx.address] = balances[maker][zrx.address].minus(order.params.makerFee); - balances[taker][order.params.makerToken] = balances[taker][order.params.makerToken].add( - order.params.makerTokenAmount, + balances[maker][zrx.address] = balances[maker][zrx.address].minus(order.makerFee); + balances[taker][order.makerTokenAddress] = balances[taker][order.makerTokenAddress].add( + order.makerTokenAmount, ); - balances[taker][order.params.takerToken] = balances[taker][order.params.takerToken].minus( - order.params.takerTokenAmount, + balances[taker][order.takerTokenAddress] = balances[taker][order.takerTokenAddress].minus( + order.takerTokenAmount, ); - balances[taker][zrx.address] = balances[taker][zrx.address].minus(order.params.takerFee); + balances[taker][zrx.address] = balances[taker][zrx.address].minus(order.takerFee); balances[feeRecipient][zrx.address] = balances[feeRecipient][zrx.address].add( - order.params.makerFee.add(order.params.takerFee), + order.makerFee.add(order.takerFee), ); }); await exWrapper.fillOrdersUpToAsync(orders, taker, { @@ -342,10 +334,10 @@ describe('Exchange', () => { expect(newBalances).to.be.deep.equal(balances); }); - it('should throw when an order does not use the same takerToken', async () => { + it('should throw when an order does not use the same takerTokenAddress', async () => { orders = await Promise.all([ orderFactory.newSignedOrderAsync(), - orderFactory.newSignedOrderAsync({ takerToken: zrx.address }), + orderFactory.newSignedOrderAsync({ takerTokenAddress: zrx.address }), orderFactory.newSignedOrderAsync(), ]); @@ -359,7 +351,7 @@ describe('Exchange', () => { describe('batchCancelOrders', () => { it('should be able to cancel multiple orders', async () => { - const cancelTakerTokenAmounts = _.map(orders, order => order.params.takerTokenAmount); + const cancelTakerTokenAmounts = _.map(orders, order => order.takerTokenAmount); await exWrapper.batchCancelOrdersAsync(orders, maker, { cancelTakerTokenAmounts, }); |