aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/test/exchange/core.ts
diff options
context:
space:
mode:
authorAmir Bandeali <abandeali1@gmail.com>2018-03-30 02:08:52 +0800
committerAmir Bandeali <abandeali1@gmail.com>2018-04-21 04:56:17 +0800
commit75f77f3e8675c468d88456aec02561732c7646fb (patch)
tree6cbc55dca9fda65c7872e078ff134cf86107356c /packages/contracts/test/exchange/core.ts
parent7a66da5a51603d4d87d644f3635f8c7f1d00bb36 (diff)
downloaddexon-0x-contracts-75f77f3e8675c468d88456aec02561732c7646fb.tar.gz
dexon-0x-contracts-75f77f3e8675c468d88456aec02561732c7646fb.tar.zst
dexon-0x-contracts-75f77f3e8675c468d88456aec02561732c7646fb.zip
Add marketBuyOrders, rename variables, and fx old tests
Diffstat (limited to 'packages/contracts/test/exchange/core.ts')
-rw-r--r--packages/contracts/test/exchange/core.ts366
1 files changed, 157 insertions, 209 deletions
diff --git a/packages/contracts/test/exchange/core.ts b/packages/contracts/test/exchange/core.ts
index f3ab94139..b9ad309fc 100644
--- a/packages/contracts/test/exchange/core.ts
+++ b/packages/contracts/test/exchange/core.ts
@@ -19,7 +19,6 @@ import { Balances } from '../../src/utils/balances';
import { constants } from '../../src/utils/constants';
import { crypto } from '../../src/utils/crypto';
import { ExchangeWrapper } from '../../src/utils/exchange_wrapper';
-import { LogDecoder } from '../../src/utils/log_decoder';
import { OrderFactory } from '../../src/utils/order_factory';
import { orderUtils } from '../../src/utils/order_utils';
import { BalancesByOwner, ContractName, ExchangeContractErrs, SignatureType, SignedOrder } from '../../src/utils/types';
@@ -30,7 +29,6 @@ import { provider, web3Wrapper } from '../utils/web3_wrapper';
chaiSetup.configure();
const expect = chai.expect;
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
-const logDecoder = new LogDecoder(constants.TESTRPC_NETWORK_ID);
describe('Exchange', () => {
let makerAddress: string;
@@ -90,10 +88,10 @@ describe('Exchange', () => {
feeRecipientAddress,
makerTokenAddress: rep.address,
takerTokenAddress: dgd.address,
- makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18),
- takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18),
- makerFeeAmount: ZeroEx.toBaseUnitAmount(new BigNumber(1), 18),
- takerFeeAmount: ZeroEx.toBaseUnitAmount(new BigNumber(1), 18),
+ makerSellAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18),
+ makerBuyAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18),
+ makerFee: ZeroEx.toBaseUnitAmount(new BigNumber(1), 18),
+ takerFee: ZeroEx.toBaseUnitAmount(new BigNumber(1), 18),
};
const privateKey = constants.TESTRPC_PRIVATE_KEYS[0];
orderFactory = new OrderFactory(privateKey, defaultOrderParams);
@@ -145,80 +143,80 @@ describe('Exchange', () => {
it('should create an unfillable order', async () => {
signedOrder = orderFactory.newSignedOrder({
- makerTokenAmount: new BigNumber(1001),
- takerTokenAmount: new BigNumber(3),
+ makerSellAmount: new BigNumber(1001),
+ makerBuyAmount: new BigNumber(3),
});
- const filledTakerTokenAmountBefore = await exWrapper.getFilledTakerTokenAmountAsync(
+ const makerAmountBoughtBefore = await exWrapper.getMakerAmountBoughtAsync(
orderUtils.getOrderHashHex(signedOrder),
);
- expect(filledTakerTokenAmountBefore).to.be.bignumber.equal(0);
+ expect(makerAmountBoughtBefore).to.be.bignumber.equal(0);
const fillTakerTokenAmount1 = new BigNumber(2);
await exWrapper.fillOrderAsync(signedOrder, takerAddress, {
- takerTokenFillAmount: fillTakerTokenAmount1,
+ takerSellAmount: fillTakerTokenAmount1,
});
- const filledTakerTokenAmountAfter1 = await exWrapper.getFilledTakerTokenAmountAsync(
+ const filledTakerTokenAmountAfter1 = await exWrapper.getMakerAmountBoughtAsync(
orderUtils.getOrderHashHex(signedOrder),
);
expect(filledTakerTokenAmountAfter1).to.be.bignumber.equal(fillTakerTokenAmount1);
const fillTakerTokenAmount2 = new BigNumber(1);
await exWrapper.fillOrderAsync(signedOrder, takerAddress, {
- takerTokenFillAmount: fillTakerTokenAmount2,
+ takerSellAmount: fillTakerTokenAmount2,
});
- const filledTakerTokenAmountAfter2 = await exWrapper.getFilledTakerTokenAmountAsync(
+ const filledTakerTokenAmountAfter2 = await exWrapper.getMakerAmountBoughtAsync(
orderUtils.getOrderHashHex(signedOrder),
);
expect(filledTakerTokenAmountAfter2).to.be.bignumber.equal(filledTakerTokenAmountAfter1);
});
- it('should transfer the correct amounts when makerTokenAmount === takerTokenAmount', async () => {
+ it('should transfer the correct amounts when makerSellAmount === makerBuyAmount', async () => {
signedOrder = orderFactory.newSignedOrder({
- makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18),
- takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18),
+ makerSellAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18),
+ makerBuyAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18),
});
- const filledTakerTokenAmountBefore = await exWrapper.getFilledTakerTokenAmountAsync(
+ const makerAmountBoughtBefore = await exWrapper.getMakerAmountBoughtAsync(
orderUtils.getOrderHashHex(signedOrder),
);
- expect(filledTakerTokenAmountBefore).to.be.bignumber.equal(0);
+ expect(makerAmountBoughtBefore).to.be.bignumber.equal(0);
- const takerTokenFillAmount = signedOrder.takerTokenAmount.div(2);
- await exWrapper.fillOrderAsync(signedOrder, takerAddress, { takerTokenFillAmount });
+ const takerSellAmount = signedOrder.makerBuyAmount.div(2);
+ await exWrapper.fillOrderAsync(signedOrder, takerAddress, { takerSellAmount });
- const filledTakerTokenAmountAfter = await exWrapper.getFilledTakerTokenAmountAsync(
+ const makerAmountBoughtAfter = await exWrapper.getMakerAmountBoughtAsync(
orderUtils.getOrderHashHex(signedOrder),
);
- expect(filledTakerTokenAmountAfter).to.be.bignumber.equal(takerTokenFillAmount);
+ expect(makerAmountBoughtAfter).to.be.bignumber.equal(takerSellAmount);
const newBalances = await dmyBalances.getAsync();
- const makerTokenFillAmount = takerTokenFillAmount
- .times(signedOrder.makerTokenAmount)
- .dividedToIntegerBy(signedOrder.takerTokenAmount);
- const makerFeePaid = signedOrder.makerFeeAmount
- .times(makerTokenFillAmount)
- .dividedToIntegerBy(signedOrder.makerTokenAmount);
- const takerFeePaid = signedOrder.takerFeeAmount
- .times(makerTokenFillAmount)
- .dividedToIntegerBy(signedOrder.makerTokenAmount);
+ const makerAmountSold = takerSellAmount
+ .times(signedOrder.makerSellAmount)
+ .dividedToIntegerBy(signedOrder.makerBuyAmount);
+ const makerFeePaid = signedOrder.makerFee
+ .times(makerAmountSold)
+ .dividedToIntegerBy(signedOrder.makerSellAmount);
+ const takerFeePaid = signedOrder.takerFee
+ .times(makerAmountSold)
+ .dividedToIntegerBy(signedOrder.makerSellAmount);
expect(newBalances[makerAddress][signedOrder.makerTokenAddress]).to.be.bignumber.equal(
- balances[makerAddress][signedOrder.makerTokenAddress].minus(makerTokenFillAmount),
+ balances[makerAddress][signedOrder.makerTokenAddress].minus(makerAmountSold),
);
expect(newBalances[makerAddress][signedOrder.takerTokenAddress]).to.be.bignumber.equal(
- balances[makerAddress][signedOrder.takerTokenAddress].add(takerTokenFillAmount),
+ balances[makerAddress][signedOrder.takerTokenAddress].add(takerSellAmount),
);
expect(newBalances[makerAddress][zrx.address]).to.be.bignumber.equal(
balances[makerAddress][zrx.address].minus(makerFeePaid),
);
expect(newBalances[takerAddress][signedOrder.takerTokenAddress]).to.be.bignumber.equal(
- balances[takerAddress][signedOrder.takerTokenAddress].minus(takerTokenFillAmount),
+ balances[takerAddress][signedOrder.takerTokenAddress].minus(takerSellAmount),
);
expect(newBalances[takerAddress][signedOrder.makerTokenAddress]).to.be.bignumber.equal(
- balances[takerAddress][signedOrder.makerTokenAddress].add(makerTokenFillAmount),
+ balances[takerAddress][signedOrder.makerTokenAddress].add(makerAmountSold),
);
expect(newBalances[takerAddress][zrx.address]).to.be.bignumber.equal(
balances[takerAddress][zrx.address].minus(takerFeePaid),
@@ -228,50 +226,50 @@ describe('Exchange', () => {
);
});
- it('should transfer the correct amounts when makerTokenAmount > takerTokenAmount', async () => {
+ it('should transfer the correct amounts when makerSellAmount > makerBuyAmount', async () => {
signedOrder = orderFactory.newSignedOrder({
- makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18),
- takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18),
+ makerSellAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18),
+ makerBuyAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18),
});
- const filledTakerTokenAmountBefore = await exWrapper.getFilledTakerTokenAmountAsync(
+ const makerAmountBoughtBefore = await exWrapper.getMakerAmountBoughtAsync(
orderUtils.getOrderHashHex(signedOrder),
);
- expect(filledTakerTokenAmountBefore).to.be.bignumber.equal(0);
+ expect(makerAmountBoughtBefore).to.be.bignumber.equal(0);
- const takerTokenFillAmount = signedOrder.takerTokenAmount.div(2);
- await exWrapper.fillOrderAsync(signedOrder, takerAddress, { takerTokenFillAmount });
+ const takerSellAmount = signedOrder.makerBuyAmount.div(2);
+ await exWrapper.fillOrderAsync(signedOrder, takerAddress, { takerSellAmount });
- const filledTakerTokenAmountAfter = await exWrapper.getFilledTakerTokenAmountAsync(
+ const makerAmountBoughtAfter = await exWrapper.getMakerAmountBoughtAsync(
orderUtils.getOrderHashHex(signedOrder),
);
- expect(filledTakerTokenAmountAfter).to.be.bignumber.equal(takerTokenFillAmount);
+ expect(makerAmountBoughtAfter).to.be.bignumber.equal(takerSellAmount);
const newBalances = await dmyBalances.getAsync();
- const makerTokenFillAmount = takerTokenFillAmount
- .times(signedOrder.makerTokenAmount)
- .dividedToIntegerBy(signedOrder.takerTokenAmount);
- const makerFeePaid = signedOrder.makerFeeAmount
- .times(makerTokenFillAmount)
- .dividedToIntegerBy(signedOrder.makerTokenAmount);
- const takerFeePaid = signedOrder.takerFeeAmount
- .times(makerTokenFillAmount)
- .dividedToIntegerBy(signedOrder.makerTokenAmount);
+ const makerAmountSold = takerSellAmount
+ .times(signedOrder.makerSellAmount)
+ .dividedToIntegerBy(signedOrder.makerBuyAmount);
+ const makerFeePaid = signedOrder.makerFee
+ .times(makerAmountSold)
+ .dividedToIntegerBy(signedOrder.makerSellAmount);
+ const takerFeePaid = signedOrder.takerFee
+ .times(makerAmountSold)
+ .dividedToIntegerBy(signedOrder.makerSellAmount);
expect(newBalances[makerAddress][signedOrder.makerTokenAddress]).to.be.bignumber.equal(
- balances[makerAddress][signedOrder.makerTokenAddress].minus(makerTokenFillAmount),
+ balances[makerAddress][signedOrder.makerTokenAddress].minus(makerAmountSold),
);
expect(newBalances[makerAddress][signedOrder.takerTokenAddress]).to.be.bignumber.equal(
- balances[makerAddress][signedOrder.takerTokenAddress].add(takerTokenFillAmount),
+ balances[makerAddress][signedOrder.takerTokenAddress].add(takerSellAmount),
);
expect(newBalances[makerAddress][zrx.address]).to.be.bignumber.equal(
balances[makerAddress][zrx.address].minus(makerFeePaid),
);
expect(newBalances[takerAddress][signedOrder.takerTokenAddress]).to.be.bignumber.equal(
- balances[takerAddress][signedOrder.takerTokenAddress].minus(takerTokenFillAmount),
+ balances[takerAddress][signedOrder.takerTokenAddress].minus(takerSellAmount),
);
expect(newBalances[takerAddress][signedOrder.makerTokenAddress]).to.be.bignumber.equal(
- balances[takerAddress][signedOrder.makerTokenAddress].add(makerTokenFillAmount),
+ balances[takerAddress][signedOrder.makerTokenAddress].add(makerAmountSold),
);
expect(newBalances[takerAddress][zrx.address]).to.be.bignumber.equal(
balances[takerAddress][zrx.address].minus(takerFeePaid),
@@ -281,50 +279,50 @@ describe('Exchange', () => {
);
});
- it('should transfer the correct amounts when makerTokenAmount < takerTokenAmount', async () => {
+ it('should transfer the correct amounts when makerSellAmount < makerBuyAmount', async () => {
signedOrder = orderFactory.newSignedOrder({
- makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18),
- takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18),
+ makerSellAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18),
+ makerBuyAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18),
});
- const filledTakerTokenAmountBefore = await exWrapper.getFilledTakerTokenAmountAsync(
+ const makerAmountBoughtBefore = await exWrapper.getMakerAmountBoughtAsync(
orderUtils.getOrderHashHex(signedOrder),
);
- expect(filledTakerTokenAmountBefore).to.be.bignumber.equal(0);
+ expect(makerAmountBoughtBefore).to.be.bignumber.equal(0);
- const takerTokenFillAmount = signedOrder.takerTokenAmount.div(2);
- await exWrapper.fillOrderAsync(signedOrder, takerAddress, { takerTokenFillAmount });
+ const takerSellAmount = signedOrder.makerBuyAmount.div(2);
+ await exWrapper.fillOrderAsync(signedOrder, takerAddress, { takerSellAmount });
- const filledTakerTokenAmountAfter = await exWrapper.getFilledTakerTokenAmountAsync(
+ const makerAmountBoughtAfter = await exWrapper.getMakerAmountBoughtAsync(
orderUtils.getOrderHashHex(signedOrder),
);
- expect(filledTakerTokenAmountAfter).to.be.bignumber.equal(takerTokenFillAmount);
+ expect(makerAmountBoughtAfter).to.be.bignumber.equal(takerSellAmount);
const newBalances = await dmyBalances.getAsync();
- const makerTokenFillAmount = takerTokenFillAmount
- .times(signedOrder.makerTokenAmount)
- .dividedToIntegerBy(signedOrder.takerTokenAmount);
- const makerFeePaid = signedOrder.makerFeeAmount
- .times(makerTokenFillAmount)
- .dividedToIntegerBy(signedOrder.makerTokenAmount);
- const takerFeePaid = signedOrder.takerFeeAmount
- .times(makerTokenFillAmount)
- .dividedToIntegerBy(signedOrder.makerTokenAmount);
+ const makerAmountSold = takerSellAmount
+ .times(signedOrder.makerSellAmount)
+ .dividedToIntegerBy(signedOrder.makerBuyAmount);
+ const makerFeePaid = signedOrder.makerFee
+ .times(makerAmountSold)
+ .dividedToIntegerBy(signedOrder.makerSellAmount);
+ const takerFeePaid = signedOrder.takerFee
+ .times(makerAmountSold)
+ .dividedToIntegerBy(signedOrder.makerSellAmount);
expect(newBalances[makerAddress][signedOrder.makerTokenAddress]).to.be.bignumber.equal(
- balances[makerAddress][signedOrder.makerTokenAddress].minus(makerTokenFillAmount),
+ balances[makerAddress][signedOrder.makerTokenAddress].minus(makerAmountSold),
);
expect(newBalances[makerAddress][signedOrder.takerTokenAddress]).to.be.bignumber.equal(
- balances[makerAddress][signedOrder.takerTokenAddress].add(takerTokenFillAmount),
+ balances[makerAddress][signedOrder.takerTokenAddress].add(takerSellAmount),
);
expect(newBalances[makerAddress][zrx.address]).to.be.bignumber.equal(
balances[makerAddress][zrx.address].minus(makerFeePaid),
);
expect(newBalances[takerAddress][signedOrder.takerTokenAddress]).to.be.bignumber.equal(
- balances[takerAddress][signedOrder.takerTokenAddress].minus(takerTokenFillAmount),
+ balances[takerAddress][signedOrder.takerTokenAddress].minus(takerSellAmount),
);
expect(newBalances[takerAddress][signedOrder.makerTokenAddress]).to.be.bignumber.equal(
- balances[takerAddress][signedOrder.makerTokenAddress].add(makerTokenFillAmount),
+ balances[takerAddress][signedOrder.makerTokenAddress].add(makerAmountSold),
);
expect(newBalances[takerAddress][zrx.address]).to.be.bignumber.equal(
balances[takerAddress][zrx.address].minus(takerFeePaid),
@@ -337,49 +335,49 @@ describe('Exchange', () => {
it('should transfer the correct amounts when taker is specified and order is claimed by taker', async () => {
signedOrder = orderFactory.newSignedOrder({
takerAddress,
- makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18),
- takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18),
+ makerSellAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18),
+ makerBuyAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18),
});
- const filledTakerTokenAmountBefore = await exWrapper.getFilledTakerTokenAmountAsync(
+ const makerAmountBoughtBefore = await exWrapper.getMakerAmountBoughtAsync(
orderUtils.getOrderHashHex(signedOrder),
);
- expect(filledTakerTokenAmountBefore).to.be.bignumber.equal(0);
+ expect(makerAmountBoughtBefore).to.be.bignumber.equal(0);
- const takerTokenFillAmount = signedOrder.takerTokenAmount.div(2);
- await exWrapper.fillOrderAsync(signedOrder, takerAddress, { takerTokenFillAmount });
+ const takerSellAmount = signedOrder.makerBuyAmount.div(2);
+ await exWrapper.fillOrderAsync(signedOrder, takerAddress, { takerSellAmount });
- const filledTakerTokenAmountAfter = await exWrapper.getFilledTakerTokenAmountAsync(
+ const makerAmountBoughtAfter = await exWrapper.getMakerAmountBoughtAsync(
orderUtils.getOrderHashHex(signedOrder),
);
- const expectedFillAmountTAfter = takerTokenFillAmount.add(filledTakerTokenAmountBefore);
- expect(filledTakerTokenAmountAfter).to.be.bignumber.equal(expectedFillAmountTAfter);
+ const expectedMakerAmountBoughtAfter = takerSellAmount.add(makerAmountBoughtBefore);
+ expect(makerAmountBoughtAfter).to.be.bignumber.equal(expectedMakerAmountBoughtAfter);
const newBalances = await dmyBalances.getAsync();
- const makerTokenFillAmount = takerTokenFillAmount
- .times(signedOrder.makerTokenAmount)
- .dividedToIntegerBy(signedOrder.takerTokenAmount);
- const makerFeePaid = signedOrder.makerFeeAmount
- .times(makerTokenFillAmount)
- .dividedToIntegerBy(signedOrder.makerTokenAmount);
- const takerFeePaid = signedOrder.takerFeeAmount
- .times(makerTokenFillAmount)
- .dividedToIntegerBy(signedOrder.makerTokenAmount);
+ const makerAmountSold = takerSellAmount
+ .times(signedOrder.makerSellAmount)
+ .dividedToIntegerBy(signedOrder.makerBuyAmount);
+ const makerFeePaid = signedOrder.makerFee
+ .times(makerAmountSold)
+ .dividedToIntegerBy(signedOrder.makerSellAmount);
+ const takerFeePaid = signedOrder.takerFee
+ .times(makerAmountSold)
+ .dividedToIntegerBy(signedOrder.makerSellAmount);
expect(newBalances[makerAddress][signedOrder.makerTokenAddress]).to.be.bignumber.equal(
- balances[makerAddress][signedOrder.makerTokenAddress].minus(makerTokenFillAmount),
+ balances[makerAddress][signedOrder.makerTokenAddress].minus(makerAmountSold),
);
expect(newBalances[makerAddress][signedOrder.takerTokenAddress]).to.be.bignumber.equal(
- balances[makerAddress][signedOrder.takerTokenAddress].add(takerTokenFillAmount),
+ balances[makerAddress][signedOrder.takerTokenAddress].add(takerSellAmount),
);
expect(newBalances[makerAddress][zrx.address]).to.be.bignumber.equal(
balances[makerAddress][zrx.address].minus(makerFeePaid),
);
expect(newBalances[takerAddress][signedOrder.takerTokenAddress]).to.be.bignumber.equal(
- balances[takerAddress][signedOrder.takerTokenAddress].minus(takerTokenFillAmount),
+ balances[takerAddress][signedOrder.takerTokenAddress].minus(takerSellAmount),
);
expect(newBalances[takerAddress][signedOrder.makerTokenAddress]).to.be.bignumber.equal(
- balances[takerAddress][signedOrder.makerTokenAddress].add(makerTokenFillAmount),
+ balances[takerAddress][signedOrder.makerTokenAddress].add(makerAmountSold),
);
expect(newBalances[takerAddress][zrx.address]).to.be.bignumber.equal(
balances[takerAddress][zrx.address].minus(takerFeePaid),
@@ -389,69 +387,63 @@ describe('Exchange', () => {
);
});
- it('should fill remaining value if takerTokenFillAmount > remaining takerTokenAmount', async () => {
- const takerTokenFillAmount = signedOrder.takerTokenAmount.div(2);
- await exWrapper.fillOrderAsync(signedOrder, takerAddress, { takerTokenFillAmount });
+ it('should fill remaining value if takerSellAmount > remaining makerBuyAmount', async () => {
+ const takerSellAmount = signedOrder.makerBuyAmount.div(2);
+ await exWrapper.fillOrderAsync(signedOrder, takerAddress, { takerSellAmount });
const res = await exWrapper.fillOrderAsync(signedOrder, takerAddress, {
- takerTokenFillAmount: signedOrder.takerTokenAmount,
+ takerSellAmount: signedOrder.makerBuyAmount,
});
- const log = logDecoder.decodeLogOrThrow(res.logs[0]) as LogWithDecodedArgs<LogFillContractEventArgs>;
- expect(log.args.takerTokenFilledAmount).to.be.bignumber.equal(
- signedOrder.takerTokenAmount.minus(takerTokenFillAmount),
- );
+ const log = res.logs[0] as LogWithDecodedArgs<LogFillContractEventArgs>;
+ expect(log.args.makerAmountBought).to.be.bignumber.equal(signedOrder.makerBuyAmount.minus(takerSellAmount));
const newBalances = await dmyBalances.getAsync();
expect(newBalances[makerAddress][signedOrder.makerTokenAddress]).to.be.bignumber.equal(
- balances[makerAddress][signedOrder.makerTokenAddress].minus(signedOrder.makerTokenAmount),
+ balances[makerAddress][signedOrder.makerTokenAddress].minus(signedOrder.makerSellAmount),
);
expect(newBalances[makerAddress][signedOrder.takerTokenAddress]).to.be.bignumber.equal(
- balances[makerAddress][signedOrder.takerTokenAddress].add(signedOrder.takerTokenAmount),
+ balances[makerAddress][signedOrder.takerTokenAddress].add(signedOrder.makerBuyAmount),
);
expect(newBalances[makerAddress][zrx.address]).to.be.bignumber.equal(
- balances[makerAddress][zrx.address].minus(signedOrder.makerFeeAmount),
+ balances[makerAddress][zrx.address].minus(signedOrder.makerFee),
);
expect(newBalances[takerAddress][signedOrder.takerTokenAddress]).to.be.bignumber.equal(
- balances[takerAddress][signedOrder.takerTokenAddress].minus(signedOrder.takerTokenAmount),
+ balances[takerAddress][signedOrder.takerTokenAddress].minus(signedOrder.makerBuyAmount),
);
expect(newBalances[takerAddress][signedOrder.makerTokenAddress]).to.be.bignumber.equal(
- balances[takerAddress][signedOrder.makerTokenAddress].add(signedOrder.makerTokenAmount),
+ balances[takerAddress][signedOrder.makerTokenAddress].add(signedOrder.makerSellAmount),
);
expect(newBalances[takerAddress][zrx.address]).to.be.bignumber.equal(
- balances[takerAddress][zrx.address].minus(signedOrder.takerFeeAmount),
+ balances[takerAddress][zrx.address].minus(signedOrder.takerFee),
);
expect(newBalances[feeRecipientAddress][zrx.address]).to.be.bignumber.equal(
- balances[feeRecipientAddress][zrx.address].add(
- signedOrder.makerFeeAmount.add(signedOrder.takerFeeAmount),
- ),
+ balances[feeRecipientAddress][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(signedOrder, takerAddress, {
- takerTokenFillAmount: signedOrder.takerTokenAmount.div(divisor),
+ takerSellAmount: signedOrder.makerBuyAmount.div(divisor),
});
expect(res.logs).to.have.length(1);
- const log = logDecoder.decodeLogOrThrow(res.logs[0]) as LogWithDecodedArgs<LogFillContractEventArgs>;
+ const log = res.logs[0] as LogWithDecodedArgs<LogFillContractEventArgs>;
const logArgs = log.args;
- const expectedFilledMakerTokenAmount = signedOrder.makerTokenAmount.div(divisor);
- const expectedFilledTakerTokenAmount = signedOrder.takerTokenAmount.div(divisor);
- const expectedFeeMPaid = signedOrder.makerFeeAmount.div(divisor);
- const expectedFeeTPaid = signedOrder.takerFeeAmount.div(divisor);
- const tokensHashBuff = crypto.solSHA3([signedOrder.makerTokenAddress, signedOrder.takerTokenAddress]);
- const expectedTokens = ethUtil.bufferToHex(tokensHashBuff);
+ const expectedFilledMakerTokenAmount = signedOrder.makerSellAmount.div(divisor);
+ const expectedFilledTakerTokenAmount = signedOrder.makerBuyAmount.div(divisor);
+ const expectedFeeMPaid = signedOrder.makerFee.div(divisor);
+ const expectedFeeTPaid = signedOrder.takerFee.div(divisor);
expect(signedOrder.makerAddress).to.be.equal(logArgs.makerAddress);
expect(takerAddress).to.be.equal(logArgs.takerAddress);
expect(signedOrder.feeRecipientAddress).to.be.equal(logArgs.feeRecipientAddress);
expect(signedOrder.makerTokenAddress).to.be.equal(logArgs.makerTokenAddress);
expect(signedOrder.takerTokenAddress).to.be.equal(logArgs.takerTokenAddress);
- expect(expectedFilledMakerTokenAmount).to.be.bignumber.equal(logArgs.makerTokenFilledAmount);
- expect(expectedFilledTakerTokenAmount).to.be.bignumber.equal(logArgs.takerTokenFilledAmount);
- expect(expectedFeeMPaid).to.be.bignumber.equal(logArgs.makerFeeAmountPaid);
- expect(expectedFeeTPaid).to.be.bignumber.equal(logArgs.takerFeeAmountPaid);
+ expect(expectedFilledMakerTokenAmount).to.be.bignumber.equal(logArgs.makerAmountSold);
+ expect(expectedFilledTakerTokenAmount).to.be.bignumber.equal(logArgs.makerAmountBought);
+ expect(expectedFeeMPaid).to.be.bignumber.equal(logArgs.makerFeePaid);
+ expect(expectedFeeTPaid).to.be.bignumber.equal(logArgs.takerFeePaid);
expect(orderUtils.getOrderHashHex(signedOrder)).to.be.equal(logArgs.orderHash);
});
@@ -461,43 +453,41 @@ describe('Exchange', () => {
});
const divisor = 2;
const res = await exWrapper.fillOrderAsync(signedOrder, takerAddress, {
- takerTokenFillAmount: signedOrder.takerTokenAmount.div(divisor),
+ takerSellAmount: signedOrder.makerBuyAmount.div(divisor),
});
expect(res.logs).to.have.length(1);
- const log = logDecoder.decodeLogOrThrow(res.logs[0]) as LogWithDecodedArgs<LogFillContractEventArgs>;
+ const log = res.logs[0] as LogWithDecodedArgs<LogFillContractEventArgs>;
const logArgs = log.args;
- const expectedFilledMakerTokenAmount = signedOrder.makerTokenAmount.div(divisor);
- const expectedFilledTakerTokenAmount = signedOrder.takerTokenAmount.div(divisor);
+ const expectedFilledMakerTokenAmount = signedOrder.makerSellAmount.div(divisor);
+ const expectedFilledTakerTokenAmount = signedOrder.makerBuyAmount.div(divisor);
const expectedFeeMPaid = new BigNumber(0);
const expectedFeeTPaid = new BigNumber(0);
- const tokensHashBuff = crypto.solSHA3([signedOrder.makerTokenAddress, signedOrder.takerTokenAddress]);
- const expectedTokens = ethUtil.bufferToHex(tokensHashBuff);
expect(signedOrder.makerAddress).to.be.equal(logArgs.makerAddress);
expect(takerAddress).to.be.equal(logArgs.takerAddress);
expect(signedOrder.feeRecipientAddress).to.be.equal(logArgs.feeRecipientAddress);
expect(signedOrder.makerTokenAddress).to.be.equal(logArgs.makerTokenAddress);
expect(signedOrder.takerTokenAddress).to.be.equal(logArgs.takerTokenAddress);
- expect(expectedFilledMakerTokenAmount).to.be.bignumber.equal(logArgs.makerTokenFilledAmount);
- expect(expectedFilledTakerTokenAmount).to.be.bignumber.equal(logArgs.takerTokenFilledAmount);
- expect(expectedFeeMPaid).to.be.bignumber.equal(logArgs.makerFeeAmountPaid);
- expect(expectedFeeTPaid).to.be.bignumber.equal(logArgs.takerFeeAmountPaid);
+ expect(expectedFilledMakerTokenAmount).to.be.bignumber.equal(logArgs.makerAmountSold);
+ expect(expectedFilledTakerTokenAmount).to.be.bignumber.equal(logArgs.makerAmountBought);
+ expect(expectedFeeMPaid).to.be.bignumber.equal(logArgs.makerFeePaid);
+ expect(expectedFeeTPaid).to.be.bignumber.equal(logArgs.takerFeePaid);
expect(orderUtils.getOrderHashHex(signedOrder)).to.be.equal(logArgs.orderHash);
});
it('should throw when taker is specified and order is claimed by other', async () => {
signedOrder = orderFactory.newSignedOrder({
takerAddress: feeRecipientAddress,
- makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18),
- takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18),
+ makerSellAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18),
+ makerBuyAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18),
});
return expect(exWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(constants.REVERT);
});
it('should throw if signature is invalid', async () => {
signedOrder = orderFactory.newSignedOrder({
- makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(10), 18),
+ makerSellAmount: ZeroEx.toBaseUnitAmount(new BigNumber(10), 18),
});
const invalidR = ethUtil.sha3('invalidR');
@@ -509,35 +499,9 @@ describe('Exchange', () => {
return expect(exWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(constants.REVERT);
});
- it('should throw if makerTokenAmount is 0', async () => {
- signedOrder = orderFactory.newSignedOrder({
- makerTokenAmount: new BigNumber(0),
- });
-
- return expect(exWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(constants.REVERT);
- });
-
- it('should throw if takerTokenAmount is 0', async () => {
- signedOrder = orderFactory.newSignedOrder({
- takerTokenAmount: new BigNumber(0),
- });
-
- return expect(exWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(constants.REVERT);
- });
-
- it('should throw if takerTokenFillAmount is 0', async () => {
- signedOrder = orderFactory.newSignedOrder();
-
- return expect(
- exWrapper.fillOrderAsync(signedOrder, takerAddress, {
- takerTokenFillAmount: new BigNumber(0),
- }),
- ).to.be.rejectedWith(constants.REVERT);
- });
-
it('should throw if maker balances are too low to fill order', async () => {
signedOrder = orderFactory.newSignedOrder({
- makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100000), 18),
+ makerSellAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100000), 18),
});
return expect(exWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(constants.REVERT);
@@ -545,7 +509,7 @@ describe('Exchange', () => {
it('should throw if taker balances are too low to fill order', async () => {
signedOrder = orderFactory.newSignedOrder({
- takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100000), 18),
+ makerBuyAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100000), 18),
});
return expect(exWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(constants.REVERT);
@@ -588,7 +552,7 @@ describe('Exchange', () => {
const res = await exWrapper.fillOrderAsync(signedOrder, takerAddress);
expect(res.logs).to.have.length(1);
- const log = logDecoder.decodeLogOrThrow(res.logs[0]) as LogWithDecodedArgs<LogErrorContractEventArgs>;
+ const log = res.logs[0] as LogWithDecodedArgs<LogErrorContractEventArgs>;
const errCode = log.args.errorId;
expect(errCode).to.be.equal(ExchangeContractErrs.ERROR_ORDER_EXPIRED);
});
@@ -599,7 +563,7 @@ describe('Exchange', () => {
const res = await exWrapper.fillOrderAsync(signedOrder, takerAddress);
expect(res.logs).to.have.length(1);
- const log = logDecoder.decodeLogOrThrow(res.logs[0]) as LogWithDecodedArgs<LogErrorContractEventArgs>;
+ const log = res.logs[0] as LogWithDecodedArgs<LogErrorContractEventArgs>;
const errCode = log.args.errorId;
expect(errCode).to.be.equal(ExchangeContractErrs.ERROR_ORDER_FULLY_FILLED);
});
@@ -615,26 +579,10 @@ describe('Exchange', () => {
return expect(exWrapper.cancelOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(constants.REVERT);
});
- it('should throw if makerTokenAmount is 0', async () => {
- signedOrder = orderFactory.newSignedOrder({
- makerTokenAmount: new BigNumber(0),
- });
-
- return expect(exWrapper.cancelOrderAsync(signedOrder, makerAddress)).to.be.rejectedWith(constants.REVERT);
- });
-
- it('should throw if takerTokenAmount is 0', async () => {
- signedOrder = orderFactory.newSignedOrder({
- takerTokenAmount: new BigNumber(0),
- });
-
- return expect(exWrapper.cancelOrderAsync(signedOrder, makerAddress)).to.be.rejectedWith(constants.REVERT);
- });
-
it('should be able to cancel a full order', async () => {
await exWrapper.cancelOrderAsync(signedOrder, makerAddress);
await exWrapper.fillOrderAsync(signedOrder, takerAddress, {
- takerTokenFillAmount: signedOrder.takerTokenAmount.div(2),
+ takerSellAmount: signedOrder.makerBuyAmount.div(2),
});
const newBalances = await dmyBalances.getAsync();
@@ -646,7 +594,7 @@ describe('Exchange', () => {
const res = await exWrapper.cancelOrderAsync(signedOrder, makerAddress);
expect(res.logs).to.have.length(1);
- const log = logDecoder.decodeLogOrThrow(res.logs[0]) as LogWithDecodedArgs<LogCancelContractEventArgs>;
+ const log = res.logs[0] as LogWithDecodedArgs<LogCancelContractEventArgs>;
const logArgs = log.args;
expect(signedOrder.makerAddress).to.be.equal(logArgs.makerAddress);
@@ -661,7 +609,7 @@ describe('Exchange', () => {
const res = await exWrapper.cancelOrderAsync(signedOrder, makerAddress);
expect(res.logs).to.have.length(1);
- const log = logDecoder.decodeLogOrThrow(res.logs[0]) as LogWithDecodedArgs<LogErrorContractEventArgs>;
+ const log = res.logs[0] as LogWithDecodedArgs<LogErrorContractEventArgs>;
const errCode = log.args.errorId;
expect(errCode).to.be.equal(ExchangeContractErrs.ERROR_ORDER_CANCELLED);
});
@@ -673,7 +621,7 @@ describe('Exchange', () => {
const res = await exWrapper.cancelOrderAsync(signedOrder, makerAddress);
expect(res.logs).to.have.length(1);
- const log = logDecoder.decodeLogOrThrow(res.logs[0]) as LogWithDecodedArgs<LogErrorContractEventArgs>;
+ const log = res.logs[0] as LogWithDecodedArgs<LogErrorContractEventArgs>;
const errCode = log.args.errorId;
expect(errCode).to.be.equal(ExchangeContractErrs.ERROR_ORDER_EXPIRED);
});
@@ -707,33 +655,33 @@ describe('Exchange', () => {
balances = await dmyBalances.getAsync();
const signedOrders = await Promise.all([
orderFactory.newSignedOrder({
- makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(9), 18),
- takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(9), 18),
+ makerSellAmount: ZeroEx.toBaseUnitAmount(new BigNumber(9), 18),
+ makerBuyAmount: ZeroEx.toBaseUnitAmount(new BigNumber(9), 18),
salt: new BigNumber(0),
}),
orderFactory.newSignedOrder({
- makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(79), 18),
- takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(79), 18),
+ makerSellAmount: ZeroEx.toBaseUnitAmount(new BigNumber(79), 18),
+ makerBuyAmount: ZeroEx.toBaseUnitAmount(new BigNumber(79), 18),
salt: new BigNumber(1),
}),
orderFactory.newSignedOrder({
- makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(979), 18),
- takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(979), 18),
+ makerSellAmount: ZeroEx.toBaseUnitAmount(new BigNumber(979), 18),
+ makerBuyAmount: ZeroEx.toBaseUnitAmount(new BigNumber(979), 18),
salt: new BigNumber(2),
}),
orderFactory.newSignedOrder({
- makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(7979), 18),
- takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(7979), 18),
+ makerSellAmount: ZeroEx.toBaseUnitAmount(new BigNumber(7979), 18),
+ makerBuyAmount: ZeroEx.toBaseUnitAmount(new BigNumber(7979), 18),
salt: new BigNumber(3),
}),
]);
await exWrapper.batchFillOrdersNoThrowAsync(signedOrders, takerAddress);
const newBalances = await dmyBalances.getAsync();
- const fillMakerTokenAmount = signedOrders[2].makerTokenAmount.add(signedOrders[3].makerTokenAmount);
- const fillTakerTokenAmount = signedOrders[2].takerTokenAmount.add(signedOrders[3].takerTokenAmount);
- const makerFeeAmount = signedOrders[2].makerFeeAmount.add(signedOrders[3].makerFeeAmount);
- const takerFeeAmount = signedOrders[2].takerFeeAmount.add(signedOrders[3].takerFeeAmount);
+ const fillMakerTokenAmount = signedOrders[2].makerSellAmount.add(signedOrders[3].makerSellAmount);
+ const fillTakerTokenAmount = signedOrders[2].makerBuyAmount.add(signedOrders[3].makerBuyAmount);
+ const makerFee = signedOrders[2].makerFee.add(signedOrders[3].makerFee);
+ const takerFee = signedOrders[2].takerFee.add(signedOrders[3].takerFee);
expect(newBalances[makerAddress][signedOrders[3].makerTokenAddress]).to.be.bignumber.equal(
balances[makerAddress][signedOrders[3].makerTokenAddress].minus(fillMakerTokenAmount),
);
@@ -741,7 +689,7 @@ describe('Exchange', () => {
balances[makerAddress][signedOrders[3].takerTokenAddress].add(fillTakerTokenAmount),
);
expect(newBalances[makerAddress][zrx.address]).to.be.bignumber.equal(
- balances[makerAddress][zrx.address].minus(makerFeeAmount),
+ balances[makerAddress][zrx.address].minus(makerFee),
);
expect(newBalances[takerAddress][signedOrders[3].takerTokenAddress]).to.be.bignumber.equal(
balances[takerAddress][signedOrders[3].takerTokenAddress].minus(fillTakerTokenAmount),
@@ -750,10 +698,10 @@ describe('Exchange', () => {
balances[takerAddress][signedOrders[3].makerTokenAddress].add(fillMakerTokenAmount),
);
expect(newBalances[takerAddress][zrx.address]).to.be.bignumber.equal(
- balances[takerAddress][zrx.address].minus(takerFeeAmount),
+ balances[takerAddress][zrx.address].minus(takerFee),
);
expect(newBalances[feeRecipientAddress][zrx.address]).to.be.bignumber.equal(
- balances[feeRecipientAddress][zrx.address].add(makerFeeAmount.add(takerFeeAmount)),
+ balances[feeRecipientAddress][zrx.address].add(makerFee.add(takerFee)),
);
});
});