diff options
author | Leonid <logvinov.leon@gmail.com> | 2018-02-09 01:15:10 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-09 01:15:10 +0800 |
commit | 254d3f53e2cd09eed3eb6b8ce841f546d01dcdcd (patch) | |
tree | ff8e4c1e59bcc71253f39ee92dc9740941504f37 /packages/contracts/test/exchange | |
parent | eebf205817d3d812a40158d146110c7868a42bf0 (diff) | |
parent | 876517d4580c864359898c572df8e081430c32ce (diff) | |
download | dexon-sol-tools-254d3f53e2cd09eed3eb6b8ce841f546d01dcdcd.tar dexon-sol-tools-254d3f53e2cd09eed3eb6b8ce841f546d01dcdcd.tar.gz dexon-sol-tools-254d3f53e2cd09eed3eb6b8ce841f546d01dcdcd.tar.bz2 dexon-sol-tools-254d3f53e2cd09eed3eb6b8ce841f546d01dcdcd.tar.lz dexon-sol-tools-254d3f53e2cd09eed3eb6b8ce841f546d01dcdcd.tar.xz dexon-sol-tools-254d3f53e2cd09eed3eb6b8ce841f546d01dcdcd.tar.zst dexon-sol-tools-254d3f53e2cd09eed3eb6b8ce841f546d01dcdcd.zip |
Merge pull request #377 from 0xProject/feature/signed_unsigned_order_contracts
Use SignedOrder and Order types from 0x.js
Diffstat (limited to 'packages/contracts/test/exchange')
-rw-r--r-- | packages/contracts/test/exchange/core.ts | 481 | ||||
-rw-r--r-- | packages/contracts/test/exchange/helpers.ts | 30 | ||||
-rw-r--r-- | packages/contracts/test/exchange/wrapper.ts | 211 |
3 files changed, 367 insertions, 355 deletions
diff --git a/packages/contracts/test/exchange/core.ts b/packages/contracts/test/exchange/core.ts index 5cedaddc9..9cfc68418 100644 --- a/packages/contracts/test/exchange/core.ts +++ b/packages/contracts/test/exchange/core.ts @@ -3,6 +3,7 @@ import { LogErrorContractEventArgs, LogFillContractEventArgs, LogWithDecodedArgs, + SignedOrder, TransactionReceiptWithDecodedLogs, ZeroEx, } from '0x.js'; @@ -20,7 +21,6 @@ import { Balances } from '../../util/balances'; import { constants } from '../../util/constants'; import { crypto } from '../../util/crypto'; import { ExchangeWrapper } from '../../util/exchange_wrapper'; -import { Order } from '../../util/order'; import { OrderFactory } from '../../util/order_factory'; import { BalancesByOwner, ContractName, ExchangeContractErrs } from '../../util/types'; import { chaiSetup } from '../utils/chai_setup'; @@ -46,7 +46,7 @@ describe('Exchange', () => { let exchange: ExchangeContract; let tokenTransferProxy: TokenTransferProxyContract; - let order: Order; + let signedOrder: SignedOrder; let balances: BalancesByOwner; let exWrapper: ExchangeWrapper; let dmyBalances: Balances; @@ -84,14 +84,14 @@ 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, INITIAL_ALLOWANCE, { @@ -147,80 +147,85 @@ describe('Exchange', () => { describe('fillOrder', () => { beforeEach(async () => { balances = await dmyBalances.getAsync(); - order = await orderFactory.newSignedOrderAsync(); + signedOrder = await orderFactory.newSignedOrderAsync(); }); it('should create an unfillable order', async () => { - order = await orderFactory.newSignedOrderAsync({ + signedOrder = await orderFactory.newSignedOrderAsync({ makerTokenAmount: new BigNumber(1001), takerTokenAmount: new BigNumber(3), }); - const filledTakerTokenAmountBefore = await zeroEx.exchange.getFilledTakerAmountAsync(order.params - .orderHashHex as string); + const filledTakerTokenAmountBefore = await zeroEx.exchange.getFilledTakerAmountAsync( + ZeroEx.getOrderHashHex(signedOrder), + ); expect(filledTakerTokenAmountBefore).to.be.bignumber.equal(0); const fillTakerTokenAmount1 = new BigNumber(2); - await exWrapper.fillOrderAsync(order, taker, { + await exWrapper.fillOrderAsync(signedOrder, taker, { fillTakerTokenAmount: fillTakerTokenAmount1, }); - const filledTakerTokenAmountAfter1 = await zeroEx.exchange.getFilledTakerAmountAsync(order.params - .orderHashHex as string); + const filledTakerTokenAmountAfter1 = await zeroEx.exchange.getFilledTakerAmountAsync( + ZeroEx.getOrderHashHex(signedOrder), + ); expect(filledTakerTokenAmountAfter1).to.be.bignumber.equal(fillTakerTokenAmount1); const fillTakerTokenAmount2 = new BigNumber(1); - await exWrapper.fillOrderAsync(order, taker, { + await exWrapper.fillOrderAsync(signedOrder, taker, { fillTakerTokenAmount: fillTakerTokenAmount2, }); - const filledTakerTokenAmountAfter2 = await zeroEx.exchange.getFilledTakerAmountAsync(order.params - .orderHashHex as string); + const filledTakerTokenAmountAfter2 = await zeroEx.exchange.getFilledTakerAmountAsync( + ZeroEx.getOrderHashHex(signedOrder), + ); expect(filledTakerTokenAmountAfter2).to.be.bignumber.equal(filledTakerTokenAmountAfter1); }); it('should transfer the correct amounts when makerTokenAmount === takerTokenAmount', async () => { - order = await orderFactory.newSignedOrderAsync({ + signedOrder = await orderFactory.newSignedOrderAsync({ makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18), takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18), }); - const filledTakerTokenAmountBefore = await zeroEx.exchange.getFilledTakerAmountAsync(order.params - .orderHashHex as string); + const filledTakerTokenAmountBefore = await zeroEx.exchange.getFilledTakerAmountAsync( + ZeroEx.getOrderHashHex(signedOrder), + ); expect(filledTakerTokenAmountBefore).to.be.bignumber.equal(0); - const fillTakerTokenAmount = order.params.takerTokenAmount.div(2); - await exWrapper.fillOrderAsync(order, taker, { fillTakerTokenAmount }); + const fillTakerTokenAmount = signedOrder.takerTokenAmount.div(2); + await exWrapper.fillOrderAsync(signedOrder, taker, { fillTakerTokenAmount }); - const filledTakerTokenAmountAfter = await zeroEx.exchange.getFilledTakerAmountAsync(order.params - .orderHashHex as string); + const filledTakerTokenAmountAfter = await zeroEx.exchange.getFilledTakerAmountAsync( + ZeroEx.getOrderHashHex(signedOrder), + ); expect(filledTakerTokenAmountAfter).to.be.bignumber.equal(fillTakerTokenAmount); const newBalances = await dmyBalances.getAsync(); const fillMakerTokenAmount = fillTakerTokenAmount - .times(order.params.makerTokenAmount) - .dividedToIntegerBy(order.params.takerTokenAmount); - const paidMakerFee = order.params.makerFee + .times(signedOrder.makerTokenAmount) + .dividedToIntegerBy(signedOrder.takerTokenAmount); + const paidMakerFee = signedOrder.makerFee .times(fillMakerTokenAmount) - .dividedToIntegerBy(order.params.makerTokenAmount); - const paidTakerFee = order.params.takerFee + .dividedToIntegerBy(signedOrder.makerTokenAmount); + const paidTakerFee = signedOrder.takerFee .times(fillMakerTokenAmount) - .dividedToIntegerBy(order.params.makerTokenAmount); - expect(newBalances[maker][order.params.makerToken]).to.be.bignumber.equal( - balances[maker][order.params.makerToken].minus(fillMakerTokenAmount), + .dividedToIntegerBy(signedOrder.makerTokenAmount); + expect(newBalances[maker][signedOrder.makerTokenAddress]).to.be.bignumber.equal( + balances[maker][signedOrder.makerTokenAddress].minus(fillMakerTokenAmount), ); - expect(newBalances[maker][order.params.takerToken]).to.be.bignumber.equal( - balances[maker][order.params.takerToken].add(fillTakerTokenAmount), + expect(newBalances[maker][signedOrder.takerTokenAddress]).to.be.bignumber.equal( + balances[maker][signedOrder.takerTokenAddress].add(fillTakerTokenAmount), ); expect(newBalances[maker][zrx.address]).to.be.bignumber.equal( balances[maker][zrx.address].minus(paidMakerFee), ); - expect(newBalances[taker][order.params.takerToken]).to.be.bignumber.equal( - balances[taker][order.params.takerToken].minus(fillTakerTokenAmount), + expect(newBalances[taker][signedOrder.takerTokenAddress]).to.be.bignumber.equal( + balances[taker][signedOrder.takerTokenAddress].minus(fillTakerTokenAmount), ); - expect(newBalances[taker][order.params.makerToken]).to.be.bignumber.equal( - balances[taker][order.params.makerToken].add(fillMakerTokenAmount), + expect(newBalances[taker][signedOrder.makerTokenAddress]).to.be.bignumber.equal( + balances[taker][signedOrder.makerTokenAddress].add(fillMakerTokenAmount), ); expect(newBalances[taker][zrx.address]).to.be.bignumber.equal( balances[taker][zrx.address].minus(paidTakerFee), @@ -231,47 +236,49 @@ describe('Exchange', () => { }); it('should transfer the correct amounts when makerTokenAmount > takerTokenAmount', async () => { - order = await orderFactory.newSignedOrderAsync({ + signedOrder = await orderFactory.newSignedOrderAsync({ makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18), takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18), }); - const filledTakerTokenAmountBefore = await zeroEx.exchange.getFilledTakerAmountAsync(order.params - .orderHashHex as string); + const filledTakerTokenAmountBefore = await zeroEx.exchange.getFilledTakerAmountAsync( + ZeroEx.getOrderHashHex(signedOrder), + ); expect(filledTakerTokenAmountBefore).to.be.bignumber.equal(0); - const fillTakerTokenAmount = order.params.takerTokenAmount.div(2); - await exWrapper.fillOrderAsync(order, taker, { fillTakerTokenAmount }); + const fillTakerTokenAmount = signedOrder.takerTokenAmount.div(2); + await exWrapper.fillOrderAsync(signedOrder, taker, { fillTakerTokenAmount }); - const filledTakerTokenAmountAfter = await zeroEx.exchange.getFilledTakerAmountAsync(order.params - .orderHashHex as string); + const filledTakerTokenAmountAfter = await zeroEx.exchange.getFilledTakerAmountAsync( + ZeroEx.getOrderHashHex(signedOrder), + ); expect(filledTakerTokenAmountAfter).to.be.bignumber.equal(fillTakerTokenAmount); const newBalances = await dmyBalances.getAsync(); const fillMakerTokenAmount = fillTakerTokenAmount - .times(order.params.makerTokenAmount) - .dividedToIntegerBy(order.params.takerTokenAmount); - const paidMakerFee = order.params.makerFee + .times(signedOrder.makerTokenAmount) + .dividedToIntegerBy(signedOrder.takerTokenAmount); + const paidMakerFee = signedOrder.makerFee .times(fillMakerTokenAmount) - .dividedToIntegerBy(order.params.makerTokenAmount); - const paidTakerFee = order.params.takerFee + .dividedToIntegerBy(signedOrder.makerTokenAmount); + const paidTakerFee = signedOrder.takerFee .times(fillMakerTokenAmount) - .dividedToIntegerBy(order.params.makerTokenAmount); - expect(newBalances[maker][order.params.makerToken]).to.be.bignumber.equal( - balances[maker][order.params.makerToken].minus(fillMakerTokenAmount), + .dividedToIntegerBy(signedOrder.makerTokenAmount); + expect(newBalances[maker][signedOrder.makerTokenAddress]).to.be.bignumber.equal( + balances[maker][signedOrder.makerTokenAddress].minus(fillMakerTokenAmount), ); - expect(newBalances[maker][order.params.takerToken]).to.be.bignumber.equal( - balances[maker][order.params.takerToken].add(fillTakerTokenAmount), + expect(newBalances[maker][signedOrder.takerTokenAddress]).to.be.bignumber.equal( + balances[maker][signedOrder.takerTokenAddress].add(fillTakerTokenAmount), ); expect(newBalances[maker][zrx.address]).to.be.bignumber.equal( balances[maker][zrx.address].minus(paidMakerFee), ); - expect(newBalances[taker][order.params.takerToken]).to.be.bignumber.equal( - balances[taker][order.params.takerToken].minus(fillTakerTokenAmount), + expect(newBalances[taker][signedOrder.takerTokenAddress]).to.be.bignumber.equal( + balances[taker][signedOrder.takerTokenAddress].minus(fillTakerTokenAmount), ); - expect(newBalances[taker][order.params.makerToken]).to.be.bignumber.equal( - balances[taker][order.params.makerToken].add(fillMakerTokenAmount), + expect(newBalances[taker][signedOrder.makerTokenAddress]).to.be.bignumber.equal( + balances[taker][signedOrder.makerTokenAddress].add(fillMakerTokenAmount), ); expect(newBalances[taker][zrx.address]).to.be.bignumber.equal( balances[taker][zrx.address].minus(paidTakerFee), @@ -282,47 +289,49 @@ describe('Exchange', () => { }); it('should transfer the correct amounts when makerTokenAmount < takerTokenAmount', async () => { - order = await orderFactory.newSignedOrderAsync({ + signedOrder = await orderFactory.newSignedOrderAsync({ makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18), takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18), }); - const filledTakerTokenAmountBefore = await zeroEx.exchange.getFilledTakerAmountAsync(order.params - .orderHashHex as string); + const filledTakerTokenAmountBefore = await zeroEx.exchange.getFilledTakerAmountAsync( + ZeroEx.getOrderHashHex(signedOrder), + ); expect(filledTakerTokenAmountBefore).to.be.bignumber.equal(0); - const fillTakerTokenAmount = order.params.takerTokenAmount.div(2); - await exWrapper.fillOrderAsync(order, taker, { fillTakerTokenAmount }); + const fillTakerTokenAmount = signedOrder.takerTokenAmount.div(2); + await exWrapper.fillOrderAsync(signedOrder, taker, { fillTakerTokenAmount }); - const filledTakerTokenAmountAfter = await zeroEx.exchange.getFilledTakerAmountAsync(order.params - .orderHashHex as string); + const filledTakerTokenAmountAfter = await zeroEx.exchange.getFilledTakerAmountAsync( + ZeroEx.getOrderHashHex(signedOrder), + ); expect(filledTakerTokenAmountAfter).to.be.bignumber.equal(fillTakerTokenAmount); const newBalances = await dmyBalances.getAsync(); const fillMakerTokenAmount = fillTakerTokenAmount - .times(order.params.makerTokenAmount) - .dividedToIntegerBy(order.params.takerTokenAmount); - const paidMakerFee = order.params.makerFee + .times(signedOrder.makerTokenAmount) + .dividedToIntegerBy(signedOrder.takerTokenAmount); + const paidMakerFee = signedOrder.makerFee .times(fillMakerTokenAmount) - .dividedToIntegerBy(order.params.makerTokenAmount); - const paidTakerFee = order.params.takerFee + .dividedToIntegerBy(signedOrder.makerTokenAmount); + const paidTakerFee = signedOrder.takerFee .times(fillMakerTokenAmount) - .dividedToIntegerBy(order.params.makerTokenAmount); - expect(newBalances[maker][order.params.makerToken]).to.be.bignumber.equal( - balances[maker][order.params.makerToken].minus(fillMakerTokenAmount), + .dividedToIntegerBy(signedOrder.makerTokenAmount); + expect(newBalances[maker][signedOrder.makerTokenAddress]).to.be.bignumber.equal( + balances[maker][signedOrder.makerTokenAddress].minus(fillMakerTokenAmount), ); - expect(newBalances[maker][order.params.takerToken]).to.be.bignumber.equal( - balances[maker][order.params.takerToken].add(fillTakerTokenAmount), + expect(newBalances[maker][signedOrder.takerTokenAddress]).to.be.bignumber.equal( + balances[maker][signedOrder.takerTokenAddress].add(fillTakerTokenAmount), ); expect(newBalances[maker][zrx.address]).to.be.bignumber.equal( balances[maker][zrx.address].minus(paidMakerFee), ); - expect(newBalances[taker][order.params.takerToken]).to.be.bignumber.equal( - balances[taker][order.params.takerToken].minus(fillTakerTokenAmount), + expect(newBalances[taker][signedOrder.takerTokenAddress]).to.be.bignumber.equal( + balances[taker][signedOrder.takerTokenAddress].minus(fillTakerTokenAmount), ); - expect(newBalances[taker][order.params.makerToken]).to.be.bignumber.equal( - balances[taker][order.params.makerToken].add(fillMakerTokenAmount), + expect(newBalances[taker][signedOrder.makerTokenAddress]).to.be.bignumber.equal( + balances[taker][signedOrder.makerTokenAddress].add(fillMakerTokenAmount), ); expect(newBalances[taker][zrx.address]).to.be.bignumber.equal( balances[taker][zrx.address].minus(paidTakerFee), @@ -333,49 +342,51 @@ describe('Exchange', () => { }); it('should transfer the correct amounts when taker is specified and order is claimed by taker', async () => { - order = await orderFactory.newSignedOrderAsync({ + signedOrder = await orderFactory.newSignedOrderAsync({ taker, makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18), takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18), }); - const filledTakerTokenAmountBefore = await zeroEx.exchange.getFilledTakerAmountAsync(order.params - .orderHashHex as string); + const filledTakerTokenAmountBefore = await zeroEx.exchange.getFilledTakerAmountAsync( + ZeroEx.getOrderHashHex(signedOrder), + ); expect(filledTakerTokenAmountBefore).to.be.bignumber.equal(0); - const fillTakerTokenAmount = order.params.takerTokenAmount.div(2); - await exWrapper.fillOrderAsync(order, taker, { fillTakerTokenAmount }); + const fillTakerTokenAmount = signedOrder.takerTokenAmount.div(2); + await exWrapper.fillOrderAsync(signedOrder, taker, { fillTakerTokenAmount }); - const filledTakerTokenAmountAfter = await zeroEx.exchange.getFilledTakerAmountAsync(order.params - .orderHashHex as string); + const filledTakerTokenAmountAfter = await zeroEx.exchange.getFilledTakerAmountAsync( + ZeroEx.getOrderHashHex(signedOrder), + ); const expectedFillAmountTAfter = fillTakerTokenAmount.add(filledTakerTokenAmountBefore); expect(filledTakerTokenAmountAfter).to.be.bignumber.equal(expectedFillAmountTAfter); const newBalances = await dmyBalances.getAsync(); const fillMakerTokenAmount = fillTakerTokenAmount - .times(order.params.makerTokenAmount) - .dividedToIntegerBy(order.params.takerTokenAmount); - const paidMakerFee = order.params.makerFee + .times(signedOrder.makerTokenAmount) + .dividedToIntegerBy(signedOrder.takerTokenAmount); + const paidMakerFee = signedOrder.makerFee .times(fillMakerTokenAmount) - .dividedToIntegerBy(order.params.makerTokenAmount); - const paidTakerFee = order.params.takerFee + .dividedToIntegerBy(signedOrder.makerTokenAmount); + const paidTakerFee = signedOrder.takerFee .times(fillMakerTokenAmount) - .dividedToIntegerBy(order.params.makerTokenAmount); - expect(newBalances[maker][order.params.makerToken]).to.be.bignumber.equal( - balances[maker][order.params.makerToken].minus(fillMakerTokenAmount), + .dividedToIntegerBy(signedOrder.makerTokenAmount); + expect(newBalances[maker][signedOrder.makerTokenAddress]).to.be.bignumber.equal( + balances[maker][signedOrder.makerTokenAddress].minus(fillMakerTokenAmount), ); - expect(newBalances[maker][order.params.takerToken]).to.be.bignumber.equal( - balances[maker][order.params.takerToken].add(fillTakerTokenAmount), + expect(newBalances[maker][signedOrder.takerTokenAddress]).to.be.bignumber.equal( + balances[maker][signedOrder.takerTokenAddress].add(fillTakerTokenAmount), ); expect(newBalances[maker][zrx.address]).to.be.bignumber.equal( balances[maker][zrx.address].minus(paidMakerFee), ); - expect(newBalances[taker][order.params.takerToken]).to.be.bignumber.equal( - balances[taker][order.params.takerToken].minus(fillTakerTokenAmount), + expect(newBalances[taker][signedOrder.takerTokenAddress]).to.be.bignumber.equal( + balances[taker][signedOrder.takerTokenAddress].minus(fillTakerTokenAmount), ); - expect(newBalances[taker][order.params.makerToken]).to.be.bignumber.equal( - balances[taker][order.params.makerToken].add(fillMakerTokenAmount), + expect(newBalances[taker][signedOrder.makerTokenAddress]).to.be.bignumber.equal( + balances[taker][signedOrder.makerTokenAddress].add(fillMakerTokenAmount), ); expect(newBalances[taker][zrx.address]).to.be.bignumber.equal( balances[taker][zrx.address].minus(paidTakerFee), @@ -386,141 +397,141 @@ describe('Exchange', () => { }); it('should fill remaining value if fillTakerTokenAmount > remaining takerTokenAmount', async () => { - const fillTakerTokenAmount = order.params.takerTokenAmount.div(2); - await exWrapper.fillOrderAsync(order, taker, { fillTakerTokenAmount }); + const fillTakerTokenAmount = signedOrder.takerTokenAmount.div(2); + await exWrapper.fillOrderAsync(signedOrder, taker, { fillTakerTokenAmount }); - const res = await exWrapper.fillOrderAsync(order, taker, { - fillTakerTokenAmount: order.params.takerTokenAmount, + const res = await exWrapper.fillOrderAsync(signedOrder, taker, { + fillTakerTokenAmount: signedOrder.takerTokenAmount, }); const log = res.logs[0] as LogWithDecodedArgs<LogFillContractEventArgs>; expect(log.args.filledTakerTokenAmount).to.be.bignumber.equal( - order.params.takerTokenAmount.minus(fillTakerTokenAmount), + signedOrder.takerTokenAmount.minus(fillTakerTokenAmount), ); const newBalances = await dmyBalances.getAsync(); - expect(newBalances[maker][order.params.makerToken]).to.be.bignumber.equal( - balances[maker][order.params.makerToken].minus(order.params.makerTokenAmount), + expect(newBalances[maker][signedOrder.makerTokenAddress]).to.be.bignumber.equal( + balances[maker][signedOrder.makerTokenAddress].minus(signedOrder.makerTokenAmount), ); - expect(newBalances[maker][order.params.takerToken]).to.be.bignumber.equal( - balances[maker][order.params.takerToken].add(order.params.takerTokenAmount), + expect(newBalances[maker][signedOrder.takerTokenAddress]).to.be.bignumber.equal( + balances[maker][signedOrder.takerTokenAddress].add(signedOrder.takerTokenAmount), ); expect(newBalances[maker][zrx.address]).to.be.bignumber.equal( - balances[maker][zrx.address].minus(order.params.makerFee), + balances[maker][zrx.address].minus(signedOrder.makerFee), ); - expect(newBalances[taker][order.params.takerToken]).to.be.bignumber.equal( - balances[taker][order.params.takerToken].minus(order.params.takerTokenAmount), + expect(newBalances[taker][signedOrder.takerTokenAddress]).to.be.bignumber.equal( + balances[taker][signedOrder.takerTokenAddress].minus(signedOrder.takerTokenAmount), ); - expect(newBalances[taker][order.params.makerToken]).to.be.bignumber.equal( - balances[taker][order.params.makerToken].add(order.params.makerTokenAmount), + expect(newBalances[taker][signedOrder.makerTokenAddress]).to.be.bignumber.equal( + balances[taker][signedOrder.makerTokenAddress].add(signedOrder.makerTokenAmount), ); expect(newBalances[taker][zrx.address]).to.be.bignumber.equal( - balances[taker][zrx.address].minus(order.params.takerFee), + balances[taker][zrx.address].minus(signedOrder.takerFee), ); expect(newBalances[feeRecipient][zrx.address]).to.be.bignumber.equal( - balances[feeRecipient][zrx.address].add(order.params.makerFee.add(order.params.takerFee)), + balances[feeRecipient][zrx.address].add(signedOrder.makerFee.add(signedOrder.takerFee)), ); }); it('should log 1 event with the correct arguments when order has a feeRecipient', async () => { const divisor = 2; - const res = await exWrapper.fillOrderAsync(order, taker, { - fillTakerTokenAmount: order.params.takerTokenAmount.div(divisor), + const res = await exWrapper.fillOrderAsync(signedOrder, taker, { + fillTakerTokenAmount: signedOrder.takerTokenAmount.div(divisor), }); expect(res.logs).to.have.length(1); const logArgs = (res.logs[0] as LogWithDecodedArgs<LogFillContractEventArgs>).args; - const expectedFilledMakerTokenAmount = order.params.makerTokenAmount.div(divisor); - const expectedFilledTakerTokenAmount = order.params.takerTokenAmount.div(divisor); - const expectedFeeMPaid = order.params.makerFee.div(divisor); - const expectedFeeTPaid = order.params.takerFee.div(divisor); - const tokensHashBuff = crypto.solSHA3([order.params.makerToken, order.params.takerToken]); + const expectedFilledMakerTokenAmount = signedOrder.makerTokenAmount.div(divisor); + const expectedFilledTakerTokenAmount = signedOrder.takerTokenAmount.div(divisor); + const expectedFeeMPaid = signedOrder.makerFee.div(divisor); + const expectedFeeTPaid = signedOrder.takerFee.div(divisor); + const tokensHashBuff = crypto.solSHA3([signedOrder.makerTokenAddress, signedOrder.takerTokenAddress]); const expectedTokens = ethUtil.bufferToHex(tokensHashBuff); - expect(order.params.maker).to.be.equal(logArgs.maker); + expect(signedOrder.maker).to.be.equal(logArgs.maker); expect(taker).to.be.equal(logArgs.taker); - expect(order.params.feeRecipient).to.be.equal(logArgs.feeRecipient); - expect(order.params.makerToken).to.be.equal(logArgs.makerToken); - expect(order.params.takerToken).to.be.equal(logArgs.takerToken); + expect(signedOrder.feeRecipient).to.be.equal(logArgs.feeRecipient); + expect(signedOrder.makerTokenAddress).to.be.equal(logArgs.makerToken); + expect(signedOrder.takerTokenAddress).to.be.equal(logArgs.takerToken); expect(expectedFilledMakerTokenAmount).to.be.bignumber.equal(logArgs.filledMakerTokenAmount); expect(expectedFilledTakerTokenAmount).to.be.bignumber.equal(logArgs.filledTakerTokenAmount); expect(expectedFeeMPaid).to.be.bignumber.equal(logArgs.paidMakerFee); expect(expectedFeeTPaid).to.be.bignumber.equal(logArgs.paidTakerFee); expect(expectedTokens).to.be.equal(logArgs.tokens); - expect(order.params.orderHashHex).to.be.equal(logArgs.orderHash); + expect(ZeroEx.getOrderHashHex(signedOrder)).to.be.equal(logArgs.orderHash); }); it('should log 1 event with the correct arguments when order has no feeRecipient', async () => { - order = await orderFactory.newSignedOrderAsync({ + signedOrder = await orderFactory.newSignedOrderAsync({ feeRecipient: ZeroEx.NULL_ADDRESS, }); const divisor = 2; - const res = await exWrapper.fillOrderAsync(order, taker, { - fillTakerTokenAmount: order.params.takerTokenAmount.div(divisor), + const res = await exWrapper.fillOrderAsync(signedOrder, taker, { + fillTakerTokenAmount: signedOrder.takerTokenAmount.div(divisor), }); expect(res.logs).to.have.length(1); const logArgs = (res.logs[0] as LogWithDecodedArgs<LogFillContractEventArgs>).args; - const expectedFilledMakerTokenAmount = order.params.makerTokenAmount.div(divisor); - const expectedFilledTakerTokenAmount = order.params.takerTokenAmount.div(divisor); + const expectedFilledMakerTokenAmount = signedOrder.makerTokenAmount.div(divisor); + const expectedFilledTakerTokenAmount = signedOrder.takerTokenAmount.div(divisor); const expectedFeeMPaid = new BigNumber(0); const expectedFeeTPaid = new BigNumber(0); - const tokensHashBuff = crypto.solSHA3([order.params.makerToken, order.params.takerToken]); + const tokensHashBuff = crypto.solSHA3([signedOrder.makerTokenAddress, signedOrder.takerTokenAddress]); const expectedTokens = ethUtil.bufferToHex(tokensHashBuff); - expect(order.params.maker).to.be.equal(logArgs.maker); + expect(signedOrder.maker).to.be.equal(logArgs.maker); expect(taker).to.be.equal(logArgs.taker); - expect(order.params.feeRecipient).to.be.equal(logArgs.feeRecipient); - expect(order.params.makerToken).to.be.equal(logArgs.makerToken); - expect(order.params.takerToken).to.be.equal(logArgs.takerToken); + expect(signedOrder.feeRecipient).to.be.equal(logArgs.feeRecipient); + expect(signedOrder.makerTokenAddress).to.be.equal(logArgs.makerToken); + expect(signedOrder.takerTokenAddress).to.be.equal(logArgs.takerToken); expect(expectedFilledMakerTokenAmount).to.be.bignumber.equal(logArgs.filledMakerTokenAmount); expect(expectedFilledTakerTokenAmount).to.be.bignumber.equal(logArgs.filledTakerTokenAmount); expect(expectedFeeMPaid).to.be.bignumber.equal(logArgs.paidMakerFee); expect(expectedFeeTPaid).to.be.bignumber.equal(logArgs.paidTakerFee); expect(expectedTokens).to.be.equal(logArgs.tokens); - expect(order.params.orderHashHex).to.be.equal(logArgs.orderHash); + expect(ZeroEx.getOrderHashHex(signedOrder)).to.be.equal(logArgs.orderHash); }); it('should throw when taker is specified and order is claimed by other', async () => { - order = await orderFactory.newSignedOrderAsync({ + signedOrder = await orderFactory.newSignedOrderAsync({ taker: feeRecipient, makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18), takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18), }); - return expect(exWrapper.fillOrderAsync(order, taker)).to.be.rejectedWith(constants.REVERT); + return expect(exWrapper.fillOrderAsync(signedOrder, taker)).to.be.rejectedWith(constants.REVERT); }); it('should throw if signature is invalid', async () => { - order = await orderFactory.newSignedOrderAsync({ + signedOrder = await orderFactory.newSignedOrderAsync({ makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(10), 18), }); - order.params.r = ethUtil.bufferToHex(ethUtil.sha3('invalidR')); - order.params.s = ethUtil.bufferToHex(ethUtil.sha3('invalidS')); - return expect(exWrapper.fillOrderAsync(order, taker)).to.be.rejectedWith(constants.REVERT); + signedOrder.ecSignature.r = ethUtil.bufferToHex(ethUtil.sha3('invalidR')); + signedOrder.ecSignature.s = ethUtil.bufferToHex(ethUtil.sha3('invalidS')); + return expect(exWrapper.fillOrderAsync(signedOrder, taker)).to.be.rejectedWith(constants.REVERT); }); it('should throw if makerTokenAmount is 0', async () => { - order = await orderFactory.newSignedOrderAsync({ + signedOrder = await orderFactory.newSignedOrderAsync({ makerTokenAmount: new BigNumber(0), }); - return expect(exWrapper.fillOrderAsync(order, taker)).to.be.rejectedWith(constants.REVERT); + return expect(exWrapper.fillOrderAsync(signedOrder, taker)).to.be.rejectedWith(constants.REVERT); }); it('should throw if takerTokenAmount is 0', async () => { - order = await orderFactory.newSignedOrderAsync({ + signedOrder = await orderFactory.newSignedOrderAsync({ takerTokenAmount: new BigNumber(0), }); - return expect(exWrapper.fillOrderAsync(order, taker)).to.be.rejectedWith(constants.REVERT); + return expect(exWrapper.fillOrderAsync(signedOrder, taker)).to.be.rejectedWith(constants.REVERT); }); it('should throw if fillTakerTokenAmount is 0', async () => { - order = await orderFactory.newSignedOrderAsync(); + signedOrder = await orderFactory.newSignedOrderAsync(); return expect( - exWrapper.fillOrderAsync(order, taker, { + exWrapper.fillOrderAsync(signedOrder, taker, { fillTakerTokenAmount: new BigNumber(0), }), ).to.be.rejectedWith(constants.REVERT); @@ -528,23 +539,23 @@ describe('Exchange', () => { it('should not change balances if maker balances are too low to fill order and \ shouldThrowOnInsufficientBalanceOrAllowance = false', async () => { - order = await orderFactory.newSignedOrderAsync({ + signedOrder = await orderFactory.newSignedOrderAsync({ makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100000), 18), }); - await exWrapper.fillOrderAsync(order, taker); + await exWrapper.fillOrderAsync(signedOrder, taker); const newBalances = await dmyBalances.getAsync(); expect(newBalances).to.be.deep.equal(balances); }); it('should throw if maker balances are too low to fill order and \ shouldThrowOnInsufficientBalanceOrAllowance = true', async () => { - order = await orderFactory.newSignedOrderAsync({ + signedOrder = await orderFactory.newSignedOrderAsync({ makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100000), 18), }); return expect( - exWrapper.fillOrderAsync(order, taker, { + exWrapper.fillOrderAsync(signedOrder, taker, { shouldThrowOnInsufficientBalanceOrAllowance: true, }), ).to.be.rejectedWith(constants.REVERT); @@ -552,23 +563,23 @@ describe('Exchange', () => { it('should not change balances if taker balances are too low to fill order and \ shouldThrowOnInsufficientBalanceOrAllowance = false', async () => { - order = await orderFactory.newSignedOrderAsync({ + signedOrder = await orderFactory.newSignedOrderAsync({ takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100000), 18), }); - await exWrapper.fillOrderAsync(order, taker); + await exWrapper.fillOrderAsync(signedOrder, taker); const newBalances = await dmyBalances.getAsync(); expect(newBalances).to.be.deep.equal(balances); }); it('should throw if taker balances are too low to fill order and \ shouldThrowOnInsufficientBalanceOrAllowance = true', async () => { - order = await orderFactory.newSignedOrderAsync({ + signedOrder = await orderFactory.newSignedOrderAsync({ takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100000), 18), }); return expect( - exWrapper.fillOrderAsync(order, taker, { + exWrapper.fillOrderAsync(signedOrder, taker, { shouldThrowOnInsufficientBalanceOrAllowance: true, }), ).to.be.rejectedWith(constants.REVERT); @@ -577,7 +588,7 @@ describe('Exchange', () => { it('should not change balances if maker allowances are too low to fill order and \ shouldThrowOnInsufficientBalanceOrAllowance = false', async () => { await rep.approve.sendTransactionAsync(tokenTransferProxy.address, new BigNumber(0), { from: maker }); - await exWrapper.fillOrderAsync(order, taker); + await exWrapper.fillOrderAsync(signedOrder, taker); await rep.approve.sendTransactionAsync(tokenTransferProxy.address, INITIAL_ALLOWANCE, { from: maker, }); @@ -590,7 +601,7 @@ describe('Exchange', () => { shouldThrowOnInsufficientBalanceOrAllowance = true', async () => { await rep.approve.sendTransactionAsync(tokenTransferProxy.address, new BigNumber(0), { from: maker }); expect( - exWrapper.fillOrderAsync(order, taker, { + exWrapper.fillOrderAsync(signedOrder, taker, { shouldThrowOnInsufficientBalanceOrAllowance: true, }), ).to.be.rejectedWith(constants.REVERT); @@ -602,7 +613,7 @@ describe('Exchange', () => { it('should not change balances if taker allowances are too low to fill order and \ shouldThrowOnInsufficientBalanceOrAllowance = false', async () => { await dgd.approve.sendTransactionAsync(tokenTransferProxy.address, new BigNumber(0), { from: taker }); - await exWrapper.fillOrderAsync(order, taker); + await exWrapper.fillOrderAsync(signedOrder, taker); await dgd.approve.sendTransactionAsync(tokenTransferProxy.address, INITIAL_ALLOWANCE, { from: taker, }); @@ -615,7 +626,7 @@ describe('Exchange', () => { shouldThrowOnInsufficientBalanceOrAllowance = true', async () => { await dgd.approve.sendTransactionAsync(tokenTransferProxy.address, new BigNumber(0), { from: taker }); expect( - exWrapper.fillOrderAsync(order, taker, { + exWrapper.fillOrderAsync(signedOrder, taker, { shouldThrowOnInsufficientBalanceOrAllowance: true, }), ).to.be.rejectedWith(constants.REVERT); @@ -624,54 +635,54 @@ describe('Exchange', () => { }); }); - it('should not change balances if makerToken is ZRX, makerTokenAmount + makerFee > maker balance, \ + it('should not change balances if makerTokenAddress is ZRX, makerTokenAmount + makerFee > maker balance, \ and shouldThrowOnInsufficientBalanceOrAllowance = false', async () => { const makerZRXBalance = new BigNumber(balances[maker][zrx.address]); - order = await orderFactory.newSignedOrderAsync({ - makerToken: zrx.address, + signedOrder = await orderFactory.newSignedOrderAsync({ + makerTokenAddress: zrx.address, makerTokenAmount: makerZRXBalance, makerFee: new BigNumber(1), }); - await exWrapper.fillOrderAsync(order, taker); + await exWrapper.fillOrderAsync(signedOrder, taker); const newBalances = await dmyBalances.getAsync(); expect(newBalances).to.be.deep.equal(balances); }); - it('should not change balances if makerToken is ZRX, makerTokenAmount + makerFee > maker allowance, \ + it('should not change balances if makerTokenAddress is ZRX, makerTokenAmount + makerFee > maker allowance, \ and shouldThrowOnInsufficientBalanceOrAllowance = false', async () => { const makerZRXAllowance = await zrx.allowance(maker, tokenTransferProxy.address); - order = await orderFactory.newSignedOrderAsync({ - makerToken: zrx.address, + signedOrder = await orderFactory.newSignedOrderAsync({ + makerTokenAddress: zrx.address, makerTokenAmount: new BigNumber(makerZRXAllowance), makerFee: new BigNumber(1), }); - await exWrapper.fillOrderAsync(order, taker); + await exWrapper.fillOrderAsync(signedOrder, taker); const newBalances = await dmyBalances.getAsync(); expect(newBalances).to.be.deep.equal(balances); }); - it('should not change balances if takerToken is ZRX, takerTokenAmount + takerFee > taker balance, \ + it('should not change balances if takerTokenAddress is ZRX, takerTokenAmount + takerFee > taker balance, \ and shouldThrowOnInsufficientBalanceOrAllowance = false', async () => { const takerZRXBalance = new BigNumber(balances[taker][zrx.address]); - order = await orderFactory.newSignedOrderAsync({ - takerToken: zrx.address, + signedOrder = await orderFactory.newSignedOrderAsync({ + takerTokenAddress: zrx.address, takerTokenAmount: takerZRXBalance, takerFee: new BigNumber(1), }); - await exWrapper.fillOrderAsync(order, taker); + await exWrapper.fillOrderAsync(signedOrder, taker); const newBalances = await dmyBalances.getAsync(); expect(newBalances).to.be.deep.equal(balances); }); - it('should not change balances if takerToken is ZRX, takerTokenAmount + takerFee > taker allowance, \ + it('should not change balances if takerTokenAddress is ZRX, takerTokenAmount + takerFee > taker allowance, \ and shouldThrowOnInsufficientBalanceOrAllowance = false', async () => { const takerZRXAllowance = await zrx.allowance(taker, tokenTransferProxy.address); - order = await orderFactory.newSignedOrderAsync({ - takerToken: zrx.address, + signedOrder = await orderFactory.newSignedOrderAsync({ + takerTokenAddress: zrx.address, takerTokenAmount: new BigNumber(takerZRXAllowance), takerFee: new BigNumber(1), }); - await exWrapper.fillOrderAsync(order, taker); + await exWrapper.fillOrderAsync(signedOrder, taker); const newBalances = await dmyBalances.getAsync(); expect(newBalances).to.be.deep.equal(balances); }); @@ -683,33 +694,33 @@ describe('Exchange', () => { from: taker, }); - order = await orderFactory.newSignedOrderAsync({ - takerToken: maliciousToken.address, + signedOrder = await orderFactory.newSignedOrderAsync({ + takerTokenAddress: maliciousToken.address, }); return expect( - exWrapper.fillOrderAsync(order, taker, { + exWrapper.fillOrderAsync(signedOrder, taker, { shouldThrowOnInsufficientBalanceOrAllowance: false, }), ).to.be.rejectedWith(constants.REVERT); }); it('should not change balances if an order is expired', async () => { - order = await orderFactory.newSignedOrderAsync({ - expirationTimestampInSec: new BigNumber(Math.floor((Date.now() - 10000) / 1000)), + signedOrder = await orderFactory.newSignedOrderAsync({ + expirationUnixTimestampSec: new BigNumber(Math.floor((Date.now() - 10000) / 1000)), }); - await exWrapper.fillOrderAsync(order, taker); + await exWrapper.fillOrderAsync(signedOrder, taker); const newBalances = await dmyBalances.getAsync(); expect(newBalances).to.be.deep.equal(balances); }); it('should log an error event if an order is expired', async () => { - order = await orderFactory.newSignedOrderAsync({ - expirationTimestampInSec: new BigNumber(Math.floor((Date.now() - 10000) / 1000)), + signedOrder = await orderFactory.newSignedOrderAsync({ + expirationUnixTimestampSec: new BigNumber(Math.floor((Date.now() - 10000) / 1000)), }); - const res = await exWrapper.fillOrderAsync(order, taker); + const res = await exWrapper.fillOrderAsync(signedOrder, taker); expect(res.logs).to.have.length(1); const log = res.logs[0] as LogWithDecodedArgs<LogErrorContractEventArgs>; const errCode = log.args.errorId.toNumber(); @@ -717,10 +728,10 @@ describe('Exchange', () => { }); it('should log an error event if no value is filled', async () => { - order = await orderFactory.newSignedOrderAsync({}); - await exWrapper.fillOrderAsync(order, taker); + signedOrder = await orderFactory.newSignedOrderAsync({}); + await exWrapper.fillOrderAsync(signedOrder, taker); - const res = await exWrapper.fillOrderAsync(order, taker); + const res = await exWrapper.fillOrderAsync(signedOrder, taker); expect(res.logs).to.have.length(1); const log = res.logs[0] as LogWithDecodedArgs<LogErrorContractEventArgs>; const errCode = log.args.errorId.toNumber(); @@ -731,43 +742,43 @@ describe('Exchange', () => { describe('cancelOrder', () => { beforeEach(async () => { balances = await dmyBalances.getAsync(); - order = await orderFactory.newSignedOrderAsync(); + signedOrder = await orderFactory.newSignedOrderAsync(); }); it('should throw if not sent by maker', async () => { - return expect(exWrapper.cancelOrderAsync(order, taker)).to.be.rejectedWith(constants.REVERT); + return expect(exWrapper.cancelOrderAsync(signedOrder, taker)).to.be.rejectedWith(constants.REVERT); }); it('should throw if makerTokenAmount is 0', async () => { - order = await orderFactory.newSignedOrderAsync({ + signedOrder = await orderFactory.newSignedOrderAsync({ makerTokenAmount: new BigNumber(0), }); - return expect(exWrapper.cancelOrderAsync(order, maker)).to.be.rejectedWith(constants.REVERT); + return expect(exWrapper.cancelOrderAsync(signedOrder, maker)).to.be.rejectedWith(constants.REVERT); }); it('should throw if takerTokenAmount is 0', async () => { - order = await orderFactory.newSignedOrderAsync({ + signedOrder = await orderFactory.newSignedOrderAsync({ takerTokenAmount: new BigNumber(0), }); - return expect(exWrapper.cancelOrderAsync(order, maker)).to.be.rejectedWith(constants.REVERT); + return expect(exWrapper.cancelOrderAsync(signedOrder, maker)).to.be.rejectedWith(constants.REVERT); }); it('should throw if cancelTakerTokenAmount is 0', async () => { - order = await orderFactory.newSignedOrderAsync(); + signedOrder = await orderFactory.newSignedOrderAsync(); return expect( - exWrapper.cancelOrderAsync(order, maker, { + exWrapper.cancelOrderAsync(signedOrder, maker, { cancelTakerTokenAmount: new BigNumber(0), }), ).to.be.rejectedWith(constants.REVERT); }); it('should be able to cancel a full order', async () => { - await exWrapper.cancelOrderAsync(order, maker); - await exWrapper.fillOrderAsync(order, taker, { - fillTakerTokenAmount: order.params.takerTokenAmount.div(2), + await exWrapper.cancelOrderAsync(signedOrder, maker); + await exWrapper.fillOrderAsync(signedOrder, taker, { + fillTakerTokenAmount: signedOrder.takerTokenAmount.div(2), }); const newBalances = await dmyBalances.getAsync(); @@ -775,43 +786,43 @@ describe('Exchange', () => { }); it('should be able to cancel part of an order', async () => { - const cancelTakerTokenAmount = order.params.takerTokenAmount.div(2); - await exWrapper.cancelOrderAsync(order, maker, { + const cancelTakerTokenAmount = signedOrder.takerTokenAmount.div(2); + await exWrapper.cancelOrderAsync(signedOrder, maker, { cancelTakerTokenAmount, }); - const res = await exWrapper.fillOrderAsync(order, taker, { - fillTakerTokenAmount: order.params.takerTokenAmount, + const res = await exWrapper.fillOrderAsync(signedOrder, taker, { + fillTakerTokenAmount: signedOrder.takerTokenAmount, }); const log = res.logs[0] as LogWithDecodedArgs<LogFillContractEventArgs>; expect(log.args.filledTakerTokenAmount).to.be.bignumber.equal( - order.params.takerTokenAmount.minus(cancelTakerTokenAmount), + signedOrder.takerTokenAmount.minus(cancelTakerTokenAmount), ); const newBalances = await dmyBalances.getAsync(); const cancelMakerTokenAmount = cancelTakerTokenAmount - .times(order.params.makerTokenAmount) - .dividedToIntegerBy(order.params.takerTokenAmount); - const paidMakerFee = order.params.makerFee + .times(signedOrder.makerTokenAmount) + .dividedToIntegerBy(signedOrder.takerTokenAmount); + const paidMakerFee = signedOrder.makerFee .times(cancelMakerTokenAmount) - .dividedToIntegerBy(order.params.makerTokenAmount); - const paidTakerFee = order.params.takerFee + .dividedToIntegerBy(signedOrder.makerTokenAmount); + const paidTakerFee = signedOrder.takerFee .times(cancelMakerTokenAmount) - .dividedToIntegerBy(order.params.makerTokenAmount); - expect(newBalances[maker][order.params.makerToken]).to.be.bignumber.equal( - balances[maker][order.params.makerToken].minus(cancelMakerTokenAmount), + .dividedToIntegerBy(signedOrder.makerTokenAmount); + expect(newBalances[maker][signedOrder.makerTokenAddress]).to.be.bignumber.equal( + balances[maker][signedOrder.makerTokenAddress].minus(cancelMakerTokenAmount), ); - expect(newBalances[maker][order.params.takerToken]).to.be.bignumber.equal( - balances[maker][order.params.takerToken].add(cancelTakerTokenAmount), + expect(newBalances[maker][signedOrder.takerTokenAddress]).to.be.bignumber.equal( + balances[maker][signedOrder.takerTokenAddress].add(cancelTakerTokenAmount), ); expect(newBalances[maker][zrx.address]).to.be.bignumber.equal( balances[maker][zrx.address].minus(paidMakerFee), ); - expect(newBalances[taker][order.params.takerToken]).to.be.bignumber.equal( - balances[taker][order.params.takerToken].minus(cancelTakerTokenAmount), + expect(newBalances[taker][signedOrder.takerTokenAddress]).to.be.bignumber.equal( + balances[taker][signedOrder.takerTokenAddress].minus(cancelTakerTokenAmount), ); - expect(newBalances[taker][order.params.makerToken]).to.be.bignumber.equal( - balances[taker][order.params.makerToken].add(cancelMakerTokenAmount), + expect(newBalances[taker][signedOrder.makerTokenAddress]).to.be.bignumber.equal( + balances[taker][signedOrder.makerTokenAddress].add(cancelMakerTokenAmount), ); expect(newBalances[taker][zrx.address]).to.be.bignumber.equal( balances[taker][zrx.address].minus(paidTakerFee), @@ -823,32 +834,32 @@ describe('Exchange', () => { it('should log 1 event with correct arguments', async () => { const divisor = 2; - const res = await exWrapper.cancelOrderAsync(order, maker, { - cancelTakerTokenAmount: order.params.takerTokenAmount.div(divisor), + const res = await exWrapper.cancelOrderAsync(signedOrder, maker, { + cancelTakerTokenAmount: signedOrder.takerTokenAmount.div(divisor), }); expect(res.logs).to.have.length(1); const log = res.logs[0] as LogWithDecodedArgs<LogCancelContractEventArgs>; const logArgs = log.args; - const expectedCancelledMakerTokenAmount = order.params.makerTokenAmount.div(divisor); - const expectedCancelledTakerTokenAmount = order.params.takerTokenAmount.div(divisor); - const tokensHashBuff = crypto.solSHA3([order.params.makerToken, order.params.takerToken]); + const expectedCancelledMakerTokenAmount = signedOrder.makerTokenAmount.div(divisor); + const expectedCancelledTakerTokenAmount = signedOrder.takerTokenAmount.div(divisor); + const tokensHashBuff = crypto.solSHA3([signedOrder.makerTokenAddress, signedOrder.takerTokenAddress]); const expectedTokens = ethUtil.bufferToHex(tokensHashBuff); - expect(order.params.maker).to.be.equal(logArgs.maker); - expect(order.params.feeRecipient).to.be.equal(logArgs.feeRecipient); - expect(order.params.makerToken).to.be.equal(logArgs.makerToken); - expect(order.params.takerToken).to.be.equal(logArgs.takerToken); + expect(signedOrder.maker).to.be.equal(logArgs.maker); + expect(signedOrder.feeRecipient).to.be.equal(logArgs.feeRecipient); + expect(signedOrder.makerTokenAddress).to.be.equal(logArgs.makerToken); + expect(signedOrder.takerTokenAddress).to.be.equal(logArgs.takerToken); expect(expectedCancelledMakerTokenAmount).to.be.bignumber.equal(logArgs.cancelledMakerTokenAmount); expect(expectedCancelledTakerTokenAmount).to.be.bignumber.equal(logArgs.cancelledTakerTokenAmount); expect(expectedTokens).to.be.equal(logArgs.tokens); - expect(order.params.orderHashHex).to.be.equal(logArgs.orderHash); + expect(ZeroEx.getOrderHashHex(signedOrder)).to.be.equal(logArgs.orderHash); }); it('should not log events if no value is cancelled', async () => { - await exWrapper.cancelOrderAsync(order, maker); + await exWrapper.cancelOrderAsync(signedOrder, maker); - const res = await exWrapper.cancelOrderAsync(order, maker); + const res = await exWrapper.cancelOrderAsync(signedOrder, maker); expect(res.logs).to.have.length(1); const log = res.logs[0] as LogWithDecodedArgs<LogErrorContractEventArgs>; const errCode = log.args.errorId.toNumber(); @@ -856,11 +867,11 @@ describe('Exchange', () => { }); it('should not log events if order is expired', async () => { - order = await orderFactory.newSignedOrderAsync({ - expirationTimestampInSec: new BigNumber(Math.floor((Date.now() - 10000) / 1000)), + signedOrder = await orderFactory.newSignedOrderAsync({ + expirationUnixTimestampSec: new BigNumber(Math.floor((Date.now() - 10000) / 1000)), }); - const res = await exWrapper.cancelOrderAsync(order, maker); + const res = await exWrapper.cancelOrderAsync(signedOrder, maker); expect(res.logs).to.have.length(1); const log = res.logs[0] as LogWithDecodedArgs<LogErrorContractEventArgs>; const errCode = log.args.errorId.toNumber(); diff --git a/packages/contracts/test/exchange/helpers.ts b/packages/contracts/test/exchange/helpers.ts index 33bf8b803..5fe00225e 100644 --- a/packages/contracts/test/exchange/helpers.ts +++ b/packages/contracts/test/exchange/helpers.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'; @@ -8,7 +8,6 @@ import ethUtil = require('ethereumjs-util'); import { ExchangeContract } from '../../src/contract_wrappers/generated/exchange'; import { constants } from '../../util/constants'; import { ExchangeWrapper } from '../../util/exchange_wrapper'; -import { Order } from '../../util/order'; import { OrderFactory } from '../../util/order_factory'; import { ContractName } from '../../util/types'; import { chaiSetup } from '../utils/chai_setup'; @@ -25,7 +24,7 @@ describe('Exchange', () => { let maker: string; let feeRecipient: string; - let order: Order; + let signedOrder: SignedOrder; let exchangeWrapper: ExchangeWrapper; let orderFactory: OrderFactory; @@ -58,8 +57,8 @@ describe('Exchange', () => { makerFee: ZeroEx.toBaseUnitAmount(new BigNumber(1), 18), takerFee: ZeroEx.toBaseUnitAmount(new BigNumber(1), 18), }; - orderFactory = new OrderFactory(web3Wrapper, defaultOrderParams); - order = await orderFactory.newSignedOrderAsync(); + orderFactory = new OrderFactory(zeroEx, defaultOrderParams); + signedOrder = await orderFactory.newSignedOrderAsync(); }); beforeEach(async () => { @@ -70,28 +69,31 @@ describe('Exchange', () => { }); describe('getOrderHash', () => { it('should output the correct orderHash', async () => { - const orderHashHex = await exchangeWrapper.getOrderHashAsync(order); - expect(order.params.orderHashHex).to.be.equal(orderHashHex); + const orderHashHex = await exchangeWrapper.getOrderHashAsync(signedOrder); + expect(ZeroEx.getOrderHashHex(signedOrder)).to.be.equal(orderHashHex); }); }); describe('isValidSignature', () => { beforeEach(async () => { - order = await orderFactory.newSignedOrderAsync(); + signedOrder = await orderFactory.newSignedOrderAsync(); }); it('should return true with a valid signature', async () => { - const success = await exchangeWrapper.isValidSignatureAsync(order); - const isValidSignature = order.isValidSignature(); + const success = await exchangeWrapper.isValidSignatureAsync(signedOrder); + const orderHashHex = ZeroEx.getOrderHashHex(signedOrder); + const isValidSignature = ZeroEx.isValidSignature(orderHashHex, signedOrder.ecSignature, signedOrder.maker); expect(isValidSignature).to.be.true(); expect(success).to.be.true(); }); it('should return false with an invalid signature', async () => { - order.params.r = ethUtil.bufferToHex(ethUtil.sha3('invalidR')); - order.params.s = ethUtil.bufferToHex(ethUtil.sha3('invalidS')); - const success = await exchangeWrapper.isValidSignatureAsync(order); - expect(order.isValidSignature()).to.be.false(); + signedOrder.ecSignature.r = ethUtil.bufferToHex(ethUtil.sha3('invalidR')); + signedOrder.ecSignature.s = ethUtil.bufferToHex(ethUtil.sha3('invalidS')); + const success = await exchangeWrapper.isValidSignatureAsync(signedOrder); + const orderHashHex = ZeroEx.getOrderHashHex(signedOrder); + const isValidSignature = ZeroEx.isValidSignature(orderHashHex, signedOrder.ecSignature, signedOrder.maker); + expect(isValidSignature).to.be.false(); expect(success).to.be.false(); }); }); diff --git a/packages/contracts/test/exchange/wrapper.ts b/packages/contracts/test/exchange/wrapper.ts index b1851a55c..bf5a89222 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,7 +13,6 @@ 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 { BalancesByOwner, ContractName } from '../../util/types'; import { chaiSetup } from '../utils/chai_setup'; @@ -76,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 }), @@ -113,38 +112,38 @@ describe('Exchange', () => { }); it('should transfer the correct amounts', async () => { - const order = await orderFactory.newSignedOrderAsync({ + const signedOrder = await orderFactory.newSignedOrderAsync({ makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18), takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18), }); - const fillTakerTokenAmount = order.params.takerTokenAmount.div(2); - await exWrapper.fillOrKillOrderAsync(order, taker, { + const fillTakerTokenAmount = signedOrder.takerTokenAmount.div(2); + await exWrapper.fillOrKillOrderAsync(signedOrder, taker, { fillTakerTokenAmount, }); const newBalances = await dmyBalances.getAsync(); const fillMakerTokenAmount = fillTakerTokenAmount - .times(order.params.makerTokenAmount) - .dividedToIntegerBy(order.params.takerTokenAmount); - const makerFee = order.params.makerFee + .times(signedOrder.makerTokenAmount) + .dividedToIntegerBy(signedOrder.takerTokenAmount); + const makerFee = signedOrder.makerFee .times(fillMakerTokenAmount) - .dividedToIntegerBy(order.params.makerTokenAmount); - const takerFee = order.params.takerFee + .dividedToIntegerBy(signedOrder.makerTokenAmount); + const takerFee = signedOrder.takerFee .times(fillMakerTokenAmount) - .dividedToIntegerBy(order.params.makerTokenAmount); - expect(newBalances[maker][order.params.makerToken]).to.be.bignumber.equal( - balances[maker][order.params.makerToken].minus(fillMakerTokenAmount), + .dividedToIntegerBy(signedOrder.makerTokenAmount); + expect(newBalances[maker][signedOrder.makerTokenAddress]).to.be.bignumber.equal( + balances[maker][signedOrder.makerTokenAddress].minus(fillMakerTokenAmount), ); - expect(newBalances[maker][order.params.takerToken]).to.be.bignumber.equal( - balances[maker][order.params.takerToken].add(fillTakerTokenAmount), + expect(newBalances[maker][signedOrder.takerTokenAddress]).to.be.bignumber.equal( + balances[maker][signedOrder.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][signedOrder.takerTokenAddress]).to.be.bignumber.equal( + balances[taker][signedOrder.takerTokenAddress].minus(fillTakerTokenAmount), ); - expect(newBalances[taker][order.params.makerToken]).to.be.bignumber.equal( - balances[taker][order.params.makerToken].add(fillMakerTokenAmount), + expect(newBalances[taker][signedOrder.makerTokenAddress]).to.be.bignumber.equal( + balances[taker][signedOrder.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( @@ -152,30 +151,30 @@ 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)), + it('should throw if an signedOrder is expired', async () => { + const signedOrder = await orderFactory.newSignedOrderAsync({ + expirationUnixTimestampSec: new BigNumber(Math.floor((Date.now() - 10000) / 1000)), }); - return expect(exWrapper.fillOrKillOrderAsync(order, taker)).to.be.rejectedWith(constants.REVERT); + return expect(exWrapper.fillOrKillOrderAsync(signedOrder, taker)).to.be.rejectedWith(constants.REVERT); }); it('should throw if entire fillTakerTokenAmount not filled', async () => { - const order = await orderFactory.newSignedOrderAsync(); + const signedOrder = await orderFactory.newSignedOrderAsync(); const from = taker; - await exWrapper.fillOrderAsync(order, from, { - fillTakerTokenAmount: order.params.takerTokenAmount.div(2), + await exWrapper.fillOrderAsync(signedOrder, from, { + fillTakerTokenAmount: signedOrder.takerTokenAmount.div(2), }); - return expect(exWrapper.fillOrKillOrderAsync(order, taker)).to.be.rejectedWith(constants.REVERT); + return expect(exWrapper.fillOrKillOrderAsync(signedOrder, taker)).to.be.rejectedWith(constants.REVERT); }); }); describe('batch functions', () => { - let orders: Order[]; + let signedOrders: SignedOrder[]; beforeEach(async () => { - orders = await Promise.all([ + signedOrders = await Promise.all([ orderFactory.newSignedOrderAsync(), orderFactory.newSignedOrderAsync(), orderFactory.newSignedOrderAsync(), @@ -186,32 +185,32 @@ describe('Exchange', () => { describe('batchFillOrders', () => { it('should transfer the correct amounts', async () => { const fillTakerTokenAmounts: BigNumber[] = []; - const makerToken = rep.address; - const takerToken = dgd.address; - orders.forEach(order => { - const fillTakerTokenAmount = order.params.takerTokenAmount.div(2); + const makerTokenAddress = rep.address; + const takerTokenAddress = dgd.address; + signedOrders.forEach(signedOrder => { + const fillTakerTokenAmount = signedOrder.takerTokenAmount.div(2); const fillMakerTokenAmount = fillTakerTokenAmount - .times(order.params.makerTokenAmount) - .dividedToIntegerBy(order.params.takerTokenAmount); - const makerFee = order.params.makerFee + .times(signedOrder.makerTokenAmount) + .dividedToIntegerBy(signedOrder.takerTokenAmount); + const makerFee = signedOrder.makerFee .times(fillMakerTokenAmount) - .dividedToIntegerBy(order.params.makerTokenAmount); - const takerFee = order.params.takerFee + .dividedToIntegerBy(signedOrder.makerTokenAmount); + const takerFee = signedOrder.takerFee .times(fillMakerTokenAmount) - .dividedToIntegerBy(order.params.makerTokenAmount); + .dividedToIntegerBy(signedOrder.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), ); }); - await exWrapper.batchFillOrdersAsync(orders, taker, { + await exWrapper.batchFillOrdersAsync(signedOrders, taker, { fillTakerTokenAmounts, }); @@ -223,32 +222,32 @@ describe('Exchange', () => { describe('batchFillOrKillOrders', () => { it('should transfer the correct amounts', async () => { const fillTakerTokenAmounts: BigNumber[] = []; - const makerToken = rep.address; - const takerToken = dgd.address; - orders.forEach(order => { - const fillTakerTokenAmount = order.params.takerTokenAmount.div(2); + const makerTokenAddress = rep.address; + const takerTokenAddress = dgd.address; + signedOrders.forEach(signedOrder => { + const fillTakerTokenAmount = signedOrder.takerTokenAmount.div(2); const fillMakerTokenAmount = fillTakerTokenAmount - .times(order.params.makerTokenAmount) - .dividedToIntegerBy(order.params.takerTokenAmount); - const makerFee = order.params.makerFee + .times(signedOrder.makerTokenAmount) + .dividedToIntegerBy(signedOrder.takerTokenAmount); + const makerFee = signedOrder.makerFee .times(fillMakerTokenAmount) - .dividedToIntegerBy(order.params.makerTokenAmount); - const takerFee = order.params.takerFee + .dividedToIntegerBy(signedOrder.makerTokenAmount); + const takerFee = signedOrder.takerFee .times(fillMakerTokenAmount) - .dividedToIntegerBy(order.params.makerTokenAmount); + .dividedToIntegerBy(signedOrder.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), ); }); - await exWrapper.batchFillOrKillOrdersAsync(orders, taker, { + await exWrapper.batchFillOrKillOrdersAsync(signedOrders, taker, { fillTakerTokenAmounts, }); @@ -256,17 +255,17 @@ describe('Exchange', () => { expect(newBalances).to.be.deep.equal(balances); }); - it('should throw if a single order does not fill the expected amount', async () => { + it('should throw if a single signedOrder does not fill the expected amount', async () => { const fillTakerTokenAmounts: BigNumber[] = []; - orders.forEach(order => { - const fillTakerTokenAmount = order.params.takerTokenAmount.div(2); + signedOrders.forEach(signedOrder => { + const fillTakerTokenAmount = signedOrder.takerTokenAmount.div(2); fillTakerTokenAmounts.push(fillTakerTokenAmount); }); - await exWrapper.fillOrKillOrderAsync(orders[0], taker); + await exWrapper.fillOrKillOrderAsync(signedOrders[0], taker); return expect( - exWrapper.batchFillOrKillOrdersAsync(orders, taker, { + exWrapper.batchFillOrKillOrdersAsync(signedOrders, taker, { fillTakerTokenAmounts, }), ).to.be.rejectedWith(constants.REVERT); @@ -275,34 +274,34 @@ 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 = signedOrders[0].takerTokenAmount.plus( + signedOrders[1].takerTokenAmount.div(2), ); - await exWrapper.fillOrdersUpToAsync(orders, taker, { + await exWrapper.fillOrdersUpToAsync(signedOrders, taker, { fillTakerTokenAmount, }); const newBalances = await dmyBalances.getAsync(); - const fillMakerTokenAmount = orders[0].params.makerTokenAmount.add( - orders[1].params.makerTokenAmount.dividedToIntegerBy(2), + const fillMakerTokenAmount = signedOrders[0].makerTokenAmount.add( + signedOrders[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 = signedOrders[0].makerFee.add(signedOrders[1].makerFee.dividedToIntegerBy(2)); + const takerFee = signedOrders[0].takerFee.add(signedOrders[1].takerFee.dividedToIntegerBy(2)); + expect(newBalances[maker][signedOrders[0].makerTokenAddress]).to.be.bignumber.equal( + balances[maker][signedOrders[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][signedOrders[0].takerTokenAddress]).to.be.bignumber.equal( + balances[maker][signedOrders[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][signedOrders[0].takerTokenAddress]).to.be.bignumber.equal( + balances[taker][signedOrders[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][signedOrders[0].makerTokenAddress]).to.be.bignumber.equal( + balances[taker][signedOrders[0].makerTokenAddress].add(fillMakerTokenAmount), ); expect(newBalances[taker][zrx.address]).to.be.bignumber.equal( balances[taker][zrx.address].minus(takerFee), @@ -312,28 +311,28 @@ describe('Exchange', () => { ); }); - it('should fill all orders if cannot fill entire fillTakerTokenAmount', async () => { + it('should fill all signedOrders 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, + signedOrders.forEach(signedOrder => { + balances[maker][signedOrder.makerTokenAddress] = balances[maker][ + signedOrder.makerTokenAddress + ].minus(signedOrder.makerTokenAmount); + balances[maker][signedOrder.takerTokenAddress] = balances[maker][signedOrder.takerTokenAddress].add( + signedOrder.takerTokenAmount, ); - balances[maker][order.params.takerToken] = balances[maker][order.params.takerToken].add( - order.params.takerTokenAmount, + balances[maker][zrx.address] = balances[maker][zrx.address].minus(signedOrder.makerFee); + balances[taker][signedOrder.makerTokenAddress] = balances[taker][signedOrder.makerTokenAddress].add( + signedOrder.makerTokenAmount, ); - 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[taker][order.params.takerToken] = balances[taker][order.params.takerToken].minus( - order.params.takerTokenAmount, - ); - balances[taker][zrx.address] = balances[taker][zrx.address].minus(order.params.takerFee); + balances[taker][signedOrder.takerTokenAddress] = balances[taker][ + signedOrder.takerTokenAddress + ].minus(signedOrder.takerTokenAmount); + balances[taker][zrx.address] = balances[taker][zrx.address].minus(signedOrder.takerFee); balances[feeRecipient][zrx.address] = balances[feeRecipient][zrx.address].add( - order.params.makerFee.add(order.params.takerFee), + signedOrder.makerFee.add(signedOrder.takerFee), ); }); - await exWrapper.fillOrdersUpToAsync(orders, taker, { + await exWrapper.fillOrdersUpToAsync(signedOrders, taker, { fillTakerTokenAmount, }); @@ -341,15 +340,15 @@ describe('Exchange', () => { expect(newBalances).to.be.deep.equal(balances); }); - it('should throw when an order does not use the same takerToken', async () => { - orders = await Promise.all([ + it('should throw when an signedOrder does not use the same takerTokenAddress', async () => { + signedOrders = await Promise.all([ orderFactory.newSignedOrderAsync(), - orderFactory.newSignedOrderAsync({ takerToken: zrx.address }), + orderFactory.newSignedOrderAsync({ takerTokenAddress: zrx.address }), orderFactory.newSignedOrderAsync(), ]); return expect( - exWrapper.fillOrdersUpToAsync(orders, taker, { + exWrapper.fillOrdersUpToAsync(signedOrders, taker, { fillTakerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(1000), 18), }), ).to.be.rejectedWith(constants.REVERT); @@ -357,13 +356,13 @@ describe('Exchange', () => { }); describe('batchCancelOrders', () => { - it('should be able to cancel multiple orders', async () => { - const cancelTakerTokenAmounts = _.map(orders, order => order.params.takerTokenAmount); - await exWrapper.batchCancelOrdersAsync(orders, maker, { + it('should be able to cancel multiple signedOrders', async () => { + const cancelTakerTokenAmounts = _.map(signedOrders, signedOrder => signedOrder.takerTokenAmount); + await exWrapper.batchCancelOrdersAsync(signedOrders, maker, { cancelTakerTokenAmounts, }); - await exWrapper.batchFillOrdersAsync(orders, taker, { + await exWrapper.batchFillOrdersAsync(signedOrders, taker, { fillTakerTokenAmounts: cancelTakerTokenAmounts, }); const newBalances = await dmyBalances.getAsync(); |