aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/test
diff options
context:
space:
mode:
Diffstat (limited to 'packages/contracts/test')
-rw-r--r--packages/contracts/test/ts/ether_token.ts38
-rw-r--r--packages/contracts/test/ts/exchange/core.ts586
-rw-r--r--packages/contracts/test/ts/exchange/helpers.ts24
-rw-r--r--packages/contracts/test/ts/exchange/wrapper.ts255
-rw-r--r--packages/contracts/test/ts/multi_sig_with_time_lock.ts36
-rw-r--r--packages/contracts/test/ts/multi_sig_with_time_lock_except_remove_auth_addr.ts61
-rw-r--r--packages/contracts/test/ts/token_registry.ts102
-rw-r--r--packages/contracts/test/ts/token_transfer_proxy/auth.ts46
-rw-r--r--packages/contracts/test/ts/token_transfer_proxy/transfer_from.ts52
-rw-r--r--packages/contracts/test/ts/unlimited_allowance_token.ts (renamed from packages/contracts/test/ts/unlimitedAllowanceToken.ts)44
-rw-r--r--packages/contracts/test/ts/unlimited_allowance_token_v2.ts141
-rw-r--r--packages/contracts/test/ts/zrx_token.ts (renamed from packages/contracts/test/ts/zrxToken.ts)59
12 files changed, 889 insertions, 555 deletions
diff --git a/packages/contracts/test/ts/ether_token.ts b/packages/contracts/test/ts/ether_token.ts
index dbb4d2ee6..f807cdaa3 100644
--- a/packages/contracts/test/ts/ether_token.ts
+++ b/packages/contracts/test/ts/ether_token.ts
@@ -1,14 +1,14 @@
-import {ZeroEx, ZeroExError} from '0x.js';
-import {promisify} from '@0xproject/utils';
-import {BigNumber} from 'bignumber.js';
+import { ZeroEx, ZeroExError } from '0x.js';
+import { BigNumber, promisify } from '@0xproject/utils';
import * as chai from 'chai';
import Web3 = require('web3');
-import {Artifacts} from '../../util/artifacts';
+import { Artifacts } from '../../util/artifacts';
+import { constants } from '../../util/constants';
-import {chaiSetup} from './utils/chai_setup';
+import { chaiSetup } from './utils/chai_setup';
-const {EtherToken} = new Artifacts(artifacts);
+const { EtherToken } = new Artifacts(artifacts);
chaiSetup.configure();
const expect = chai.expect;
@@ -22,11 +22,12 @@ contract('EtherToken', (accounts: string[]) => {
const gasPrice = ZeroEx.toBaseUnitAmount(new BigNumber(20), 9);
let zeroEx: ZeroEx;
let etherTokenAddress: string;
+
before(async () => {
etherTokenAddress = EtherToken.address;
zeroEx = new ZeroEx(web3.currentProvider, {
- gasPrice,
- etherTokenContractAddress: etherTokenAddress,
+ gasPrice,
+ networkId: constants.TESTRPC_NETWORK_ID,
});
});
@@ -42,8 +43,9 @@ contract('EtherToken', (accounts: string[]) => {
const initEthBalance = await getEthBalanceAsync(account);
const ethToDeposit = initEthBalance.plus(1);
- return expect(zeroEx.etherToken.depositAsync(ethToDeposit, account))
- .to.be.rejectedWith(ZeroExError.InsufficientEthBalanceForDeposit);
+ return expect(zeroEx.etherToken.depositAsync(etherTokenAddress, ethToDeposit, account)).to.be.rejectedWith(
+ ZeroExError.InsufficientEthBalanceForDeposit,
+ );
});
it('should convert deposited Ether to wrapped Ether tokens', async () => {
@@ -52,7 +54,7 @@ contract('EtherToken', (accounts: string[]) => {
const ethToDeposit = new BigNumber(web3.toWei(1, 'ether'));
- const txHash = await zeroEx.etherToken.depositAsync(ethToDeposit, account);
+ const txHash = await zeroEx.etherToken.depositAsync(etherTokenAddress, ethToDeposit, account);
const receipt = await zeroEx.awaitTransactionMinedAsync(txHash);
const ethSpentOnGas = gasPrice.times(receipt.gasUsed);
@@ -69,8 +71,9 @@ contract('EtherToken', (accounts: string[]) => {
const initEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account);
const ethTokensToWithdraw = initEthTokenBalance.plus(1);
- return expect(zeroEx.etherToken.withdrawAsync(ethTokensToWithdraw, account))
- .to.be.rejectedWith(ZeroExError.InsufficientWEthBalanceForWithdrawal);
+ return expect(
+ zeroEx.etherToken.withdrawAsync(etherTokenAddress, ethTokensToWithdraw, account),
+ ).to.be.rejectedWith(ZeroExError.InsufficientWEthBalanceForWithdrawal);
});
it('should convert ether tokens to ether with sufficient balance', async () => {
@@ -78,15 +81,18 @@ contract('EtherToken', (accounts: string[]) => {
const initEthBalance = await getEthBalanceAsync(account);
const ethTokensToWithdraw = initEthTokenBalance;
expect(ethTokensToWithdraw).to.not.be.bignumber.equal(0);
- const txHash = await zeroEx.etherToken.withdrawAsync(ethTokensToWithdraw, account);
+ const txHash = await zeroEx.etherToken.withdrawAsync(etherTokenAddress, ethTokensToWithdraw, account, {
+ gasLimit: constants.MAX_ETHERTOKEN_WITHDRAW_GAS,
+ });
const receipt = await zeroEx.awaitTransactionMinedAsync(txHash);
const ethSpentOnGas = gasPrice.times(receipt.gasUsed);
const finalEthBalance = await getEthBalanceAsync(account);
const finalEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account);
- expect(finalEthBalance).to.be.bignumber
- .equal(initEthBalance.plus(ethTokensToWithdraw.minus(ethSpentOnGas)));
+ expect(finalEthBalance).to.be.bignumber.equal(
+ initEthBalance.plus(ethTokensToWithdraw.minus(ethSpentOnGas)),
+ );
expect(finalEthTokenBalance).to.be.bignumber.equal(initEthTokenBalance.minus(ethTokensToWithdraw));
});
});
diff --git a/packages/contracts/test/ts/exchange/core.ts b/packages/contracts/test/ts/exchange/core.ts
index daf46ca37..770ef0c43 100644
--- a/packages/contracts/test/ts/exchange/core.ts
+++ b/packages/contracts/test/ts/exchange/core.ts
@@ -1,28 +1,22 @@
-import {ZeroEx} from '0x.js';
-import {BigNumber} from 'bignumber.js';
+import { ZeroEx } from '0x.js';
+import { BigNumber } from '@0xproject/utils';
import * as chai from 'chai';
import ethUtil = require('ethereumjs-util');
import * as Web3 from 'web3';
-import {Artifacts} from '../../../util/artifacts';
-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, ContractInstance, ExchangeContractErrs} from '../../../util/types';
-import {chaiSetup} from '../utils/chai_setup';
+import { Artifacts } from '../../../util/artifacts';
+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, ContractInstance, ExchangeContractErrs } from '../../../util/types';
+import { chaiSetup } from '../utils/chai_setup';
chaiSetup.configure();
const expect = chai.expect;
-const {
- Exchange,
- TokenTransferProxy,
- DummyToken,
- TokenRegistry,
- MaliciousToken,
-} = new Artifacts(artifacts);
+const { Exchange, TokenTransferProxy, DummyToken, TokenRegistry, MaliciousToken } = new Artifacts(artifacts);
// In order to benefit from type-safety, we re-assign the global web3 instance injected by Truffle
// with type `any` to a variable of type `Web3`.
@@ -52,13 +46,11 @@ contract('Exchange', (accounts: string[]) => {
let zeroEx: ZeroEx;
before(async () => {
- [tokenRegistry, exchange] = await Promise.all([
- TokenRegistry.deployed(),
- Exchange.deployed(),
- ]);
+ [tokenRegistry, exchange] = await Promise.all([TokenRegistry.deployed(), Exchange.deployed()]);
exWrapper = new ExchangeWrapper(exchange);
zeroEx = new ZeroEx(web3.currentProvider, {
exchangeContractAddress: exchange.address,
+ networkId: constants.TESTRPC_NETWORK_ID,
});
const [repAddress, dgdAddress, zrxAddress] = await Promise.all([
@@ -87,18 +79,30 @@ contract('Exchange', (accounts: string[]) => {
]);
dmyBalances = new Balances([rep, dgd, zrx], [maker, taker, feeRecipient]);
await Promise.all([
- rep.approve(TokenTransferProxy.address, INITIAL_ALLOWANCE, {from: maker}),
- rep.approve(TokenTransferProxy.address, INITIAL_ALLOWANCE, {from: taker}),
- rep.setBalance(maker, INITIAL_BALANCE, {from: tokenOwner}),
- rep.setBalance(taker, INITIAL_BALANCE, {from: tokenOwner}),
- dgd.approve(TokenTransferProxy.address, INITIAL_ALLOWANCE, {from: maker}),
- dgd.approve(TokenTransferProxy.address, INITIAL_ALLOWANCE, {from: taker}),
- dgd.setBalance(maker, INITIAL_BALANCE, {from: tokenOwner}),
- dgd.setBalance(taker, INITIAL_BALANCE, {from: tokenOwner}),
- zrx.approve(TokenTransferProxy.address, INITIAL_ALLOWANCE, {from: maker}),
- zrx.approve(TokenTransferProxy.address, INITIAL_ALLOWANCE, {from: taker}),
- zrx.setBalance(maker, INITIAL_BALANCE, {from: tokenOwner}),
- zrx.setBalance(taker, INITIAL_BALANCE, {from: tokenOwner}),
+ rep.approve(TokenTransferProxy.address, INITIAL_ALLOWANCE, {
+ from: maker,
+ }),
+ rep.approve(TokenTransferProxy.address, INITIAL_ALLOWANCE, {
+ from: taker,
+ }),
+ rep.setBalance(maker, INITIAL_BALANCE, { from: tokenOwner }),
+ rep.setBalance(taker, INITIAL_BALANCE, { from: tokenOwner }),
+ dgd.approve(TokenTransferProxy.address, INITIAL_ALLOWANCE, {
+ from: maker,
+ }),
+ dgd.approve(TokenTransferProxy.address, INITIAL_ALLOWANCE, {
+ from: taker,
+ }),
+ dgd.setBalance(maker, INITIAL_BALANCE, { from: tokenOwner }),
+ dgd.setBalance(taker, INITIAL_BALANCE, { from: tokenOwner }),
+ zrx.approve(TokenTransferProxy.address, INITIAL_ALLOWANCE, {
+ from: maker,
+ }),
+ zrx.approve(TokenTransferProxy.address, INITIAL_ALLOWANCE, {
+ from: taker,
+ }),
+ zrx.setBalance(maker, INITIAL_BALANCE, { from: tokenOwner }),
+ zrx.setBalance(taker, INITIAL_BALANCE, { from: tokenOwner }),
]);
});
@@ -132,22 +136,29 @@ contract('Exchange', (accounts: string[]) => {
takerTokenAmount: new BigNumber(3),
});
- const filledTakerTokenAmountBefore =
- await zeroEx.exchange.getFilledTakerAmountAsync(order.params.orderHashHex);
+ const filledTakerTokenAmountBefore = await zeroEx.exchange.getFilledTakerAmountAsync(
+ order.params.orderHashHex,
+ );
expect(filledTakerTokenAmountBefore).to.be.bignumber.equal(0);
const fillTakerTokenAmount1 = new BigNumber(2);
- await exWrapper.fillOrderAsync(order, taker, {fillTakerTokenAmount: fillTakerTokenAmount1});
+ await exWrapper.fillOrderAsync(order, taker, {
+ fillTakerTokenAmount: fillTakerTokenAmount1,
+ });
- const filledTakerTokenAmountAfter1 =
- await zeroEx.exchange.getFilledTakerAmountAsync(order.params.orderHashHex);
+ const filledTakerTokenAmountAfter1 = await zeroEx.exchange.getFilledTakerAmountAsync(
+ order.params.orderHashHex,
+ );
expect(filledTakerTokenAmountAfter1).to.be.bignumber.equal(fillTakerTokenAmount1);
const fillTakerTokenAmount2 = new BigNumber(1);
- await exWrapper.fillOrderAsync(order, taker, {fillTakerTokenAmount: fillTakerTokenAmount2});
+ await exWrapper.fillOrderAsync(order, taker, {
+ fillTakerTokenAmount: fillTakerTokenAmount2,
+ });
- const filledTakerTokenAmountAfter2 =
- await zeroEx.exchange.getFilledTakerAmountAsync(order.params.orderHashHex);
+ const filledTakerTokenAmountAfter2 = await zeroEx.exchange.getFilledTakerAmountAsync(
+ order.params.orderHashHex,
+ );
expect(filledTakerTokenAmountAfter2).to.be.bignumber.equal(filledTakerTokenAmountAfter1);
});
@@ -157,42 +168,51 @@ contract('Exchange', (accounts: string[]) => {
takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18),
});
- const filledTakerTokenAmountBefore =
- await zeroEx.exchange.getFilledTakerAmountAsync(order.params.orderHashHex);
+ const filledTakerTokenAmountBefore = await zeroEx.exchange.getFilledTakerAmountAsync(
+ order.params.orderHashHex,
+ );
expect(filledTakerTokenAmountBefore).to.be.bignumber.equal(0);
const fillTakerTokenAmount = order.params.takerTokenAmount.div(2);
- await exWrapper.fillOrderAsync(order, taker, {fillTakerTokenAmount});
+ await exWrapper.fillOrderAsync(order, taker, { fillTakerTokenAmount });
- const filledTakerTokenAmountAfter =
- await zeroEx.exchange.getFilledTakerAmountAsync(order.params.orderHashHex);
+ const filledTakerTokenAmountAfter = await zeroEx.exchange.getFilledTakerAmountAsync(
+ order.params.orderHashHex,
+ );
expect(filledTakerTokenAmountAfter).to.be.bignumber.equal(fillTakerTokenAmount);
const newBalances = await dmyBalances.getAsync();
const fillMakerTokenAmount = fillTakerTokenAmount
- .times(order.params.makerTokenAmount)
- .dividedToIntegerBy(order.params.takerTokenAmount);
+ .times(order.params.makerTokenAmount)
+ .dividedToIntegerBy(order.params.takerTokenAmount);
const paidMakerFee = order.params.makerFee
- .times(fillMakerTokenAmount)
- .dividedToIntegerBy(order.params.makerTokenAmount);
+ .times(fillMakerTokenAmount)
+ .dividedToIntegerBy(order.params.makerTokenAmount);
const paidTakerFee = order.params.takerFee
- .times(fillMakerTokenAmount)
- .dividedToIntegerBy(order.params.makerTokenAmount);
- expect(newBalances[maker][order.params.makerToken])
- .to.be.bignumber.equal(balances[maker][order.params.makerToken].minus(fillMakerTokenAmount));
- expect(newBalances[maker][order.params.takerToken])
- .to.be.bignumber.equal(balances[maker][order.params.takerToken].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][order.params.makerToken])
- .to.be.bignumber.equal(balances[taker][order.params.makerToken].add(fillMakerTokenAmount));
- expect(newBalances[taker][zrx.address]).to.be.bignumber
- .equal(balances[taker][zrx.address].minus(paidTakerFee));
- expect(newBalances[feeRecipient][zrx.address])
- .to.be.bignumber.equal(balances[feeRecipient][zrx.address].add(paidMakerFee.add(paidTakerFee)));
+ .times(fillMakerTokenAmount)
+ .dividedToIntegerBy(order.params.makerTokenAmount);
+ expect(newBalances[maker][order.params.makerToken]).to.be.bignumber.equal(
+ balances[maker][order.params.makerToken].minus(fillMakerTokenAmount),
+ );
+ expect(newBalances[maker][order.params.takerToken]).to.be.bignumber.equal(
+ balances[maker][order.params.takerToken].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][order.params.makerToken]).to.be.bignumber.equal(
+ balances[taker][order.params.makerToken].add(fillMakerTokenAmount),
+ );
+ expect(newBalances[taker][zrx.address]).to.be.bignumber.equal(
+ balances[taker][zrx.address].minus(paidTakerFee),
+ );
+ expect(newBalances[feeRecipient][zrx.address]).to.be.bignumber.equal(
+ balances[feeRecipient][zrx.address].add(paidMakerFee.add(paidTakerFee)),
+ );
});
it('should transfer the correct amounts when makerTokenAmount > takerTokenAmount', async () => {
@@ -201,42 +221,51 @@ contract('Exchange', (accounts: string[]) => {
takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18),
});
- const filledTakerTokenAmountBefore =
- await zeroEx.exchange.getFilledTakerAmountAsync(order.params.orderHashHex);
+ const filledTakerTokenAmountBefore = await zeroEx.exchange.getFilledTakerAmountAsync(
+ order.params.orderHashHex,
+ );
expect(filledTakerTokenAmountBefore).to.be.bignumber.equal(0);
const fillTakerTokenAmount = order.params.takerTokenAmount.div(2);
- await exWrapper.fillOrderAsync(order, taker, {fillTakerTokenAmount});
+ await exWrapper.fillOrderAsync(order, taker, { fillTakerTokenAmount });
- const filledTakerTokenAmountAfter =
- await zeroEx.exchange.getFilledTakerAmountAsync(order.params.orderHashHex);
+ const filledTakerTokenAmountAfter = await zeroEx.exchange.getFilledTakerAmountAsync(
+ order.params.orderHashHex,
+ );
expect(filledTakerTokenAmountAfter).to.be.bignumber.equal(fillTakerTokenAmount);
const newBalances = await dmyBalances.getAsync();
const fillMakerTokenAmount = fillTakerTokenAmount
- .times(order.params.makerTokenAmount)
- .dividedToIntegerBy(order.params.takerTokenAmount);
+ .times(order.params.makerTokenAmount)
+ .dividedToIntegerBy(order.params.takerTokenAmount);
const paidMakerFee = order.params.makerFee
- .times(fillMakerTokenAmount)
- .dividedToIntegerBy(order.params.makerTokenAmount);
+ .times(fillMakerTokenAmount)
+ .dividedToIntegerBy(order.params.makerTokenAmount);
const paidTakerFee = order.params.takerFee
- .times(fillMakerTokenAmount)
- .dividedToIntegerBy(order.params.makerTokenAmount);
- expect(newBalances[maker][order.params.makerToken])
- .to.be.bignumber.equal(balances[maker][order.params.makerToken].minus(fillMakerTokenAmount));
- expect(newBalances[maker][order.params.takerToken])
- .to.be.bignumber.equal(balances[maker][order.params.takerToken].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][order.params.makerToken])
- .to.be.bignumber.equal(balances[taker][order.params.makerToken].add(fillMakerTokenAmount));
- expect(newBalances[taker][zrx.address]).to.be.bignumber
- .equal(balances[taker][zrx.address].minus(paidTakerFee));
- expect(newBalances[feeRecipient][zrx.address])
- .to.be.bignumber.equal(balances[feeRecipient][zrx.address].add(paidMakerFee.add(paidTakerFee)));
+ .times(fillMakerTokenAmount)
+ .dividedToIntegerBy(order.params.makerTokenAmount);
+ expect(newBalances[maker][order.params.makerToken]).to.be.bignumber.equal(
+ balances[maker][order.params.makerToken].minus(fillMakerTokenAmount),
+ );
+ expect(newBalances[maker][order.params.takerToken]).to.be.bignumber.equal(
+ balances[maker][order.params.takerToken].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][order.params.makerToken]).to.be.bignumber.equal(
+ balances[taker][order.params.makerToken].add(fillMakerTokenAmount),
+ );
+ expect(newBalances[taker][zrx.address]).to.be.bignumber.equal(
+ balances[taker][zrx.address].minus(paidTakerFee),
+ );
+ expect(newBalances[feeRecipient][zrx.address]).to.be.bignumber.equal(
+ balances[feeRecipient][zrx.address].add(paidMakerFee.add(paidTakerFee)),
+ );
});
it('should transfer the correct amounts when makerTokenAmount < takerTokenAmount', async () => {
@@ -245,42 +274,51 @@ contract('Exchange', (accounts: string[]) => {
takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18),
});
- const filledTakerTokenAmountBefore =
- await zeroEx.exchange.getFilledTakerAmountAsync(order.params.orderHashHex);
+ const filledTakerTokenAmountBefore = await zeroEx.exchange.getFilledTakerAmountAsync(
+ order.params.orderHashHex,
+ );
expect(filledTakerTokenAmountBefore).to.be.bignumber.equal(0);
const fillTakerTokenAmount = order.params.takerTokenAmount.div(2);
- await exWrapper.fillOrderAsync(order, taker, {fillTakerTokenAmount});
+ await exWrapper.fillOrderAsync(order, taker, { fillTakerTokenAmount });
- const filledTakerTokenAmountAfter =
- await zeroEx.exchange.getFilledTakerAmountAsync(order.params.orderHashHex);
+ const filledTakerTokenAmountAfter = await zeroEx.exchange.getFilledTakerAmountAsync(
+ order.params.orderHashHex,
+ );
expect(filledTakerTokenAmountAfter).to.be.bignumber.equal(fillTakerTokenAmount);
const newBalances = await dmyBalances.getAsync();
const fillMakerTokenAmount = fillTakerTokenAmount
- .times(order.params.makerTokenAmount)
- .dividedToIntegerBy(order.params.takerTokenAmount);
+ .times(order.params.makerTokenAmount)
+ .dividedToIntegerBy(order.params.takerTokenAmount);
const paidMakerFee = order.params.makerFee
- .times(fillMakerTokenAmount)
- .dividedToIntegerBy(order.params.makerTokenAmount);
+ .times(fillMakerTokenAmount)
+ .dividedToIntegerBy(order.params.makerTokenAmount);
const paidTakerFee = order.params.takerFee
- .times(fillMakerTokenAmount)
- .dividedToIntegerBy(order.params.makerTokenAmount);
- expect(newBalances[maker][order.params.makerToken])
- .to.be.bignumber.equal(balances[maker][order.params.makerToken].minus(fillMakerTokenAmount));
- expect(newBalances[maker][order.params.takerToken])
- .to.be.bignumber.equal(balances[maker][order.params.takerToken].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][order.params.makerToken])
- .to.be.bignumber.equal(balances[taker][order.params.makerToken].add(fillMakerTokenAmount));
- expect(newBalances[taker][zrx.address]).to.be.bignumber
- .equal(balances[taker][zrx.address].minus(paidTakerFee));
- expect(newBalances[feeRecipient][zrx.address])
- .to.be.bignumber.equal(balances[feeRecipient][zrx.address].add(paidMakerFee.add(paidTakerFee)));
+ .times(fillMakerTokenAmount)
+ .dividedToIntegerBy(order.params.makerTokenAmount);
+ expect(newBalances[maker][order.params.makerToken]).to.be.bignumber.equal(
+ balances[maker][order.params.makerToken].minus(fillMakerTokenAmount),
+ );
+ expect(newBalances[maker][order.params.takerToken]).to.be.bignumber.equal(
+ balances[maker][order.params.takerToken].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][order.params.makerToken]).to.be.bignumber.equal(
+ balances[taker][order.params.makerToken].add(fillMakerTokenAmount),
+ );
+ expect(newBalances[taker][zrx.address]).to.be.bignumber.equal(
+ balances[taker][zrx.address].minus(paidTakerFee),
+ );
+ expect(newBalances[feeRecipient][zrx.address]).to.be.bignumber.equal(
+ balances[feeRecipient][zrx.address].add(paidMakerFee.add(paidTakerFee)),
+ );
});
it('should transfer the correct amounts when taker is specified and order is claimed by taker', async () => {
@@ -290,78 +328,95 @@ contract('Exchange', (accounts: string[]) => {
takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18),
});
- const filledTakerTokenAmountBefore =
- await zeroEx.exchange.getFilledTakerAmountAsync(order.params.orderHashHex);
+ const filledTakerTokenAmountBefore = await zeroEx.exchange.getFilledTakerAmountAsync(
+ order.params.orderHashHex,
+ );
expect(filledTakerTokenAmountBefore).to.be.bignumber.equal(0);
const fillTakerTokenAmount = order.params.takerTokenAmount.div(2);
- await exWrapper.fillOrderAsync(order, taker, {fillTakerTokenAmount});
+ await exWrapper.fillOrderAsync(order, taker, { fillTakerTokenAmount });
- const filledTakerTokenAmountAfter =
- await zeroEx.exchange.getFilledTakerAmountAsync(order.params.orderHashHex);
+ const filledTakerTokenAmountAfter = await zeroEx.exchange.getFilledTakerAmountAsync(
+ order.params.orderHashHex,
+ );
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);
+ .times(order.params.makerTokenAmount)
+ .dividedToIntegerBy(order.params.takerTokenAmount);
const paidMakerFee = order.params.makerFee
- .times(fillMakerTokenAmount)
- .dividedToIntegerBy(order.params.makerTokenAmount);
+ .times(fillMakerTokenAmount)
+ .dividedToIntegerBy(order.params.makerTokenAmount);
const paidTakerFee = order.params.takerFee
- .times(fillMakerTokenAmount)
- .dividedToIntegerBy(order.params.makerTokenAmount);
- expect(newBalances[maker][order.params.makerToken])
- .to.be.bignumber.equal(balances[maker][order.params.makerToken].minus(fillMakerTokenAmount));
- expect(newBalances[maker][order.params.takerToken])
- .to.be.bignumber.equal(balances[maker][order.params.takerToken].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][order.params.makerToken])
- .to.be.bignumber.equal(balances[taker][order.params.makerToken].add(fillMakerTokenAmount));
- expect(newBalances[taker][zrx.address]).to.be.bignumber
- .equal(balances[taker][zrx.address].minus(paidTakerFee));
- expect(newBalances[feeRecipient][zrx.address])
- .to.be.bignumber.equal(balances[feeRecipient][zrx.address].add(paidMakerFee.add(paidTakerFee)));
+ .times(fillMakerTokenAmount)
+ .dividedToIntegerBy(order.params.makerTokenAmount);
+ expect(newBalances[maker][order.params.makerToken]).to.be.bignumber.equal(
+ balances[maker][order.params.makerToken].minus(fillMakerTokenAmount),
+ );
+ expect(newBalances[maker][order.params.takerToken]).to.be.bignumber.equal(
+ balances[maker][order.params.takerToken].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][order.params.makerToken]).to.be.bignumber.equal(
+ balances[taker][order.params.makerToken].add(fillMakerTokenAmount),
+ );
+ expect(newBalances[taker][zrx.address]).to.be.bignumber.equal(
+ balances[taker][zrx.address].minus(paidTakerFee),
+ );
+ expect(newBalances[feeRecipient][zrx.address]).to.be.bignumber.equal(
+ balances[feeRecipient][zrx.address].add(paidMakerFee.add(paidTakerFee)),
+ );
});
it('should fill remaining value if fillTakerTokenAmount > remaining takerTokenAmount', async () => {
const fillTakerTokenAmount = order.params.takerTokenAmount.div(2);
- await exWrapper.fillOrderAsync(order, taker, {fillTakerTokenAmount});
+ await exWrapper.fillOrderAsync(order, taker, { fillTakerTokenAmount });
- const res = await exWrapper.fillOrderAsync(order, taker,
- {fillTakerTokenAmount: order.params.takerTokenAmount});
+ const res = await exWrapper.fillOrderAsync(order, taker, {
+ fillTakerTokenAmount: order.params.takerTokenAmount,
+ });
- expect(res.logs[0].args.filledTakerTokenAmount)
- .to.be.bignumber.equal(order.params.takerTokenAmount.minus(fillTakerTokenAmount));
+ expect(res.logs[0].args.filledTakerTokenAmount).to.be.bignumber.equal(
+ order.params.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][order.params.takerToken])
- .to.be.bignumber.equal(balances[maker][order.params.takerToken].add(order.params.takerTokenAmount));
- expect(newBalances[maker][zrx.address])
- .to.be.bignumber.equal(balances[maker][zrx.address].minus(order.params.makerFee));
- expect(newBalances[taker][order.params.takerToken])
- .to.be.bignumber.equal(balances[taker][order.params.takerToken].minus(order.params.takerTokenAmount));
- expect(newBalances[taker][order.params.makerToken])
- .to.be.bignumber.equal(balances[taker][order.params.makerToken].add(order.params.makerTokenAmount));
- expect(newBalances[taker][zrx.address])
- .to.be.bignumber.equal(balances[taker][zrx.address].minus(order.params.takerFee));
- expect(newBalances[feeRecipient][zrx.address])
- .to.be.bignumber.equal(
- balances[feeRecipient][zrx.address].add(order.params.makerFee.add(order.params.takerFee)),
- );
+ expect(newBalances[maker][order.params.makerToken]).to.be.bignumber.equal(
+ balances[maker][order.params.makerToken].minus(order.params.makerTokenAmount),
+ );
+ expect(newBalances[maker][order.params.takerToken]).to.be.bignumber.equal(
+ balances[maker][order.params.takerToken].add(order.params.takerTokenAmount),
+ );
+ expect(newBalances[maker][zrx.address]).to.be.bignumber.equal(
+ balances[maker][zrx.address].minus(order.params.makerFee),
+ );
+ expect(newBalances[taker][order.params.takerToken]).to.be.bignumber.equal(
+ balances[taker][order.params.takerToken].minus(order.params.takerTokenAmount),
+ );
+ expect(newBalances[taker][order.params.makerToken]).to.be.bignumber.equal(
+ balances[taker][order.params.makerToken].add(order.params.makerTokenAmount),
+ );
+ expect(newBalances[taker][zrx.address]).to.be.bignumber.equal(
+ balances[taker][zrx.address].minus(order.params.takerFee),
+ );
+ expect(newBalances[feeRecipient][zrx.address]).to.be.bignumber.equal(
+ balances[feeRecipient][zrx.address].add(order.params.makerFee.add(order.params.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(order, taker, {
+ fillTakerTokenAmount: order.params.takerTokenAmount.div(divisor),
+ });
expect(res.logs).to.have.length(1);
const logArgs = res.logs[0].args;
@@ -390,8 +445,9 @@ contract('Exchange', (accounts: string[]) => {
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(order, taker, {
+ fillTakerTokenAmount: order.params.takerTokenAmount.div(divisor),
+ });
expect(res.logs).to.have.length(1);
const logArgs = res.logs[0].args;
@@ -422,7 +478,7 @@ contract('Exchange', (accounts: string[]) => {
takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18),
});
- return expect(exWrapper.fillOrderAsync(order, taker)).to.be.rejectedWith(constants.INVALID_OPCODE);
+ return expect(exWrapper.fillOrderAsync(order, taker)).to.be.rejectedWith(constants.REVERT);
});
it('should throw if signature is invalid', async () => {
@@ -432,7 +488,7 @@ contract('Exchange', (accounts: string[]) => {
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.INVALID_OPCODE);
+ return expect(exWrapper.fillOrderAsync(order, taker)).to.be.rejectedWith(constants.REVERT);
});
it('should throw if makerTokenAmount is 0', async () => {
@@ -440,7 +496,7 @@ contract('Exchange', (accounts: string[]) => {
makerTokenAmount: new BigNumber(0),
});
- return expect(exWrapper.fillOrderAsync(order, taker)).to.be.rejectedWith(constants.INVALID_OPCODE);
+ return expect(exWrapper.fillOrderAsync(order, taker)).to.be.rejectedWith(constants.REVERT);
});
it('should throw if takerTokenAmount is 0', async () => {
@@ -448,19 +504,21 @@ contract('Exchange', (accounts: string[]) => {
takerTokenAmount: new BigNumber(0),
});
- return expect(exWrapper.fillOrderAsync(order, taker)).to.be.rejectedWith(constants.INVALID_OPCODE);
+ return expect(exWrapper.fillOrderAsync(order, taker)).to.be.rejectedWith(constants.REVERT);
});
it('should throw if fillTakerTokenAmount is 0', async () => {
order = await orderFactory.newSignedOrderAsync();
- return expect(exWrapper.fillOrderAsync(order, taker, {fillTakerTokenAmount: new BigNumber(0)}))
- .to.be.rejectedWith(constants.INVALID_OPCODE);
+ return expect(
+ exWrapper.fillOrderAsync(order, taker, {
+ fillTakerTokenAmount: new BigNumber(0),
+ }),
+ ).to.be.rejectedWith(constants.REVERT);
});
it('should not change balances if maker balances are too low to fill order and \
- shouldThrowOnInsufficientBalanceOrAllowance = false',
- async () => {
+ shouldThrowOnInsufficientBalanceOrAllowance = false', async () => {
order = await orderFactory.newSignedOrderAsync({
makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100000), 18),
});
@@ -471,19 +529,20 @@ contract('Exchange', (accounts: string[]) => {
});
it('should throw if maker balances are too low to fill order and \
- shouldThrowOnInsufficientBalanceOrAllowance = true',
- async () => {
+ shouldThrowOnInsufficientBalanceOrAllowance = true', async () => {
order = await orderFactory.newSignedOrderAsync({
makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100000), 18),
});
- return expect(exWrapper.fillOrderAsync(order, taker, {shouldThrowOnInsufficientBalanceOrAllowance: true}))
- .to.be.rejectedWith(constants.INVALID_OPCODE);
+ return expect(
+ exWrapper.fillOrderAsync(order, taker, {
+ shouldThrowOnInsufficientBalanceOrAllowance: true,
+ }),
+ ).to.be.rejectedWith(constants.REVERT);
});
it('should not change balances if taker balances are too low to fill order and \
- shouldThrowOnInsufficientBalanceOrAllowance = false',
- async () => {
+ shouldThrowOnInsufficientBalanceOrAllowance = false', async () => {
order = await orderFactory.newSignedOrderAsync({
takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100000), 18),
});
@@ -494,59 +553,70 @@ contract('Exchange', (accounts: string[]) => {
});
it('should throw if taker balances are too low to fill order and \
- shouldThrowOnInsufficientBalanceOrAllowance = true',
- async () => {
+ shouldThrowOnInsufficientBalanceOrAllowance = true', async () => {
order = await orderFactory.newSignedOrderAsync({
takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100000), 18),
});
- return expect(exWrapper.fillOrderAsync(order, taker, {shouldThrowOnInsufficientBalanceOrAllowance: true}))
- .to.be.rejectedWith(constants.INVALID_OPCODE);
+ return expect(
+ exWrapper.fillOrderAsync(order, taker, {
+ shouldThrowOnInsufficientBalanceOrAllowance: true,
+ }),
+ ).to.be.rejectedWith(constants.REVERT);
});
it('should not change balances if maker allowances are too low to fill order and \
- shouldThrowOnInsufficientBalanceOrAllowance = false',
- async () => {
- await rep.approve(TokenTransferProxy.address, 0, {from: maker});
+ shouldThrowOnInsufficientBalanceOrAllowance = false', async () => {
+ await rep.approve(TokenTransferProxy.address, 0, { from: maker });
await exWrapper.fillOrderAsync(order, taker);
- await rep.approve(TokenTransferProxy.address, INITIAL_ALLOWANCE, {from: maker});
+ await rep.approve(TokenTransferProxy.address, INITIAL_ALLOWANCE, {
+ from: maker,
+ });
const newBalances = await dmyBalances.getAsync();
expect(newBalances).to.be.deep.equal(balances);
});
it('should throw if maker allowances are too low to fill order and \
- shouldThrowOnInsufficientBalanceOrAllowance = true',
- async () => {
- await rep.approve(TokenTransferProxy.address, 0, {from: maker});
- expect(exWrapper.fillOrderAsync(order, taker, {shouldThrowOnInsufficientBalanceOrAllowance: true}))
- .to.be.rejectedWith(constants.INVALID_OPCODE);
- await rep.approve(TokenTransferProxy.address, INITIAL_ALLOWANCE, {from: maker});
+ shouldThrowOnInsufficientBalanceOrAllowance = true', async () => {
+ await rep.approve(TokenTransferProxy.address, 0, { from: maker });
+ expect(
+ exWrapper.fillOrderAsync(order, taker, {
+ shouldThrowOnInsufficientBalanceOrAllowance: true,
+ }),
+ ).to.be.rejectedWith(constants.REVERT);
+ await rep.approve(TokenTransferProxy.address, INITIAL_ALLOWANCE, {
+ from: maker,
+ });
});
it('should not change balances if taker allowances are too low to fill order and \
- shouldThrowOnInsufficientBalanceOrAllowance = false',
- async () => {
- await dgd.approve(TokenTransferProxy.address, 0, {from: taker});
+ shouldThrowOnInsufficientBalanceOrAllowance = false', async () => {
+ await dgd.approve(TokenTransferProxy.address, 0, { from: taker });
await exWrapper.fillOrderAsync(order, taker);
- await dgd.approve(TokenTransferProxy.address, INITIAL_ALLOWANCE, {from: taker});
+ await dgd.approve(TokenTransferProxy.address, INITIAL_ALLOWANCE, {
+ from: taker,
+ });
const newBalances = await dmyBalances.getAsync();
expect(newBalances).to.be.deep.equal(balances);
});
it('should throw if taker allowances are too low to fill order and \
- shouldThrowOnInsufficientBalanceOrAllowance = true',
- async () => {
- await dgd.approve(TokenTransferProxy.address, 0, {from: taker});
- expect(exWrapper.fillOrderAsync(order, taker, {shouldThrowOnInsufficientBalanceOrAllowance: true}))
- .to.be.rejectedWith(constants.INVALID_OPCODE);
- await dgd.approve(TokenTransferProxy.address, INITIAL_ALLOWANCE, {from: taker});
+ shouldThrowOnInsufficientBalanceOrAllowance = true', async () => {
+ await dgd.approve(TokenTransferProxy.address, 0, { from: taker });
+ expect(
+ exWrapper.fillOrderAsync(order, taker, {
+ shouldThrowOnInsufficientBalanceOrAllowance: true,
+ }),
+ ).to.be.rejectedWith(constants.REVERT);
+ await dgd.approve(TokenTransferProxy.address, INITIAL_ALLOWANCE, {
+ from: taker,
+ });
});
it('should not change balances if makerToken is ZRX, makerTokenAmount + makerFee > maker balance, \
- and shouldThrowOnInsufficientBalanceOrAllowance = false',
- async () => {
+ and shouldThrowOnInsufficientBalanceOrAllowance = false', async () => {
const makerZRXBalance = new BigNumber(balances[maker][zrx.address]);
order = await orderFactory.newSignedOrderAsync({
makerToken: zrx.address,
@@ -559,8 +629,7 @@ contract('Exchange', (accounts: string[]) => {
});
it('should not change balances if makerToken is ZRX, makerTokenAmount + makerFee > maker allowance, \
- and shouldThrowOnInsufficientBalanceOrAllowance = false',
- async () => {
+ and shouldThrowOnInsufficientBalanceOrAllowance = false', async () => {
const makerZRXAllowance = await zrx.allowance(maker, TokenTransferProxy.address);
order = await orderFactory.newSignedOrderAsync({
makerToken: zrx.address,
@@ -573,8 +642,7 @@ contract('Exchange', (accounts: string[]) => {
});
it('should not change balances if takerToken is ZRX, takerTokenAmount + takerFee > taker balance, \
- and shouldThrowOnInsufficientBalanceOrAllowance = false',
- async () => {
+ and shouldThrowOnInsufficientBalanceOrAllowance = false', async () => {
const takerZRXBalance = new BigNumber(balances[taker][zrx.address]);
order = await orderFactory.newSignedOrderAsync({
takerToken: zrx.address,
@@ -587,8 +655,7 @@ contract('Exchange', (accounts: string[]) => {
});
it('should not change balances if takerToken is ZRX, takerTokenAmount + takerFee > taker allowance, \
- and shouldThrowOnInsufficientBalanceOrAllowance = false',
- async () => {
+ and shouldThrowOnInsufficientBalanceOrAllowance = false', async () => {
const takerZRXAllowance = await zrx.allowance(taker, TokenTransferProxy.address);
order = await orderFactory.newSignedOrderAsync({
takerToken: zrx.address,
@@ -603,14 +670,17 @@ contract('Exchange', (accounts: string[]) => {
it('should throw if getBalance or getAllowance attempts to change state and \
shouldThrowOnInsufficientBalanceOrAllowance = false', async () => {
const maliciousToken = await MaliciousToken.new();
- await maliciousToken.approve(TokenTransferProxy.address, INITIAL_ALLOWANCE, {from: taker});
+ await maliciousToken.approve(TokenTransferProxy.address, INITIAL_ALLOWANCE, { from: taker });
order = await orderFactory.newSignedOrderAsync({
takerToken: maliciousToken.address,
});
- return expect(exWrapper.fillOrderAsync(order, taker, {shouldThrowOnInsufficientBalanceOrAllowance: false}))
- .to.be.rejectedWith(constants.INVALID_OPCODE);
+ return expect(
+ exWrapper.fillOrderAsync(order, taker, {
+ shouldThrowOnInsufficientBalanceOrAllowance: false,
+ }),
+ ).to.be.rejectedWith(constants.REVERT);
});
it('should not change balances if an order is expired', async () => {
@@ -651,7 +721,7 @@ contract('Exchange', (accounts: string[]) => {
});
it('should throw if not sent by maker', async () => {
- return expect(exWrapper.cancelOrderAsync(order, taker)).to.be.rejectedWith(constants.INVALID_OPCODE);
+ return expect(exWrapper.cancelOrderAsync(order, taker)).to.be.rejectedWith(constants.REVERT);
});
it('should throw if makerTokenAmount is 0', async () => {
@@ -659,7 +729,7 @@ contract('Exchange', (accounts: string[]) => {
makerTokenAmount: new BigNumber(0),
});
- return expect(exWrapper.cancelOrderAsync(order, maker)).to.be.rejectedWith(constants.INVALID_OPCODE);
+ return expect(exWrapper.cancelOrderAsync(order, maker)).to.be.rejectedWith(constants.REVERT);
});
it('should throw if takerTokenAmount is 0', async () => {
@@ -667,19 +737,24 @@ contract('Exchange', (accounts: string[]) => {
takerTokenAmount: new BigNumber(0),
});
- return expect(exWrapper.cancelOrderAsync(order, maker)).to.be.rejectedWith(constants.INVALID_OPCODE);
+ return expect(exWrapper.cancelOrderAsync(order, maker)).to.be.rejectedWith(constants.REVERT);
});
it('should throw if cancelTakerTokenAmount is 0', async () => {
order = await orderFactory.newSignedOrderAsync();
- return expect(exWrapper.cancelOrderAsync(order, maker, {cancelTakerTokenAmount: new BigNumber(0)}))
- .to.be.rejectedWith(constants.INVALID_OPCODE);
+ return expect(
+ exWrapper.cancelOrderAsync(order, 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.fillOrderAsync(order, taker, {
+ fillTakerTokenAmount: order.params.takerTokenAmount.div(2),
+ });
const newBalances = await dmyBalances.getAsync();
expect(newBalances).to.be.deep.equal(balances);
@@ -687,43 +762,55 @@ contract('Exchange', (accounts: string[]) => {
it('should be able to cancel part of an order', async () => {
const cancelTakerTokenAmount = order.params.takerTokenAmount.div(2);
- await exWrapper.cancelOrderAsync(order, maker, {cancelTakerTokenAmount});
+ await exWrapper.cancelOrderAsync(order, maker, {
+ cancelTakerTokenAmount,
+ });
- const res = await exWrapper.fillOrderAsync(order, taker,
- {fillTakerTokenAmount: order.params.takerTokenAmount});
- expect(res.logs[0].args.filledTakerTokenAmount)
- .to.be.bignumber.equal(order.params.takerTokenAmount.minus(cancelTakerTokenAmount));
+ const res = await exWrapper.fillOrderAsync(order, taker, {
+ fillTakerTokenAmount: order.params.takerTokenAmount,
+ });
+ expect(res.logs[0].args.filledTakerTokenAmount).to.be.bignumber.equal(
+ order.params.takerTokenAmount.minus(cancelTakerTokenAmount),
+ );
const newBalances = await dmyBalances.getAsync();
const cancelMakerTokenAmount = cancelTakerTokenAmount
- .times(order.params.makerTokenAmount)
- .dividedToIntegerBy(order.params.takerTokenAmount);
+ .times(order.params.makerTokenAmount)
+ .dividedToIntegerBy(order.params.takerTokenAmount);
const paidMakerFee = order.params.makerFee
- .times(cancelMakerTokenAmount)
- .dividedToIntegerBy(order.params.makerTokenAmount);
+ .times(cancelMakerTokenAmount)
+ .dividedToIntegerBy(order.params.makerTokenAmount);
const paidTakerFee = order.params.takerFee
- .times(cancelMakerTokenAmount)
- .dividedToIntegerBy(order.params.makerTokenAmount);
- expect(newBalances[maker][order.params.makerToken])
- .to.be.bignumber.equal(balances[maker][order.params.makerToken].minus(cancelMakerTokenAmount));
- expect(newBalances[maker][order.params.takerToken])
- .to.be.bignumber.equal(balances[maker][order.params.takerToken].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][order.params.makerToken])
- .to.be.bignumber.equal(balances[taker][order.params.makerToken].add(cancelMakerTokenAmount));
- expect(newBalances[taker][zrx.address]).to.be.bignumber
- .equal(balances[taker][zrx.address].minus(paidTakerFee));
- expect(newBalances[feeRecipient][zrx.address])
- .to.be.bignumber.equal(balances[feeRecipient][zrx.address].add(paidMakerFee.add(paidTakerFee)));
+ .times(cancelMakerTokenAmount)
+ .dividedToIntegerBy(order.params.makerTokenAmount);
+ expect(newBalances[maker][order.params.makerToken]).to.be.bignumber.equal(
+ balances[maker][order.params.makerToken].minus(cancelMakerTokenAmount),
+ );
+ expect(newBalances[maker][order.params.takerToken]).to.be.bignumber.equal(
+ balances[maker][order.params.takerToken].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][order.params.makerToken]).to.be.bignumber.equal(
+ balances[taker][order.params.makerToken].add(cancelMakerTokenAmount),
+ );
+ expect(newBalances[taker][zrx.address]).to.be.bignumber.equal(
+ balances[taker][zrx.address].minus(paidTakerFee),
+ );
+ expect(newBalances[feeRecipient][zrx.address]).to.be.bignumber.equal(
+ balances[feeRecipient][zrx.address].add(paidMakerFee.add(paidTakerFee)),
+ );
});
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(order, maker, {
+ cancelTakerTokenAmount: order.params.takerTokenAmount.div(divisor),
+ });
expect(res.logs).to.have.length(1);
const logArgs = res.logs[0].args;
@@ -747,7 +834,6 @@ contract('Exchange', (accounts: string[]) => {
const res = await exWrapper.cancelOrderAsync(order, maker);
expect(res.logs).to.have.length(1);
- const errId = res.logs[0].args.errorId.toNumber();
const errCode = res.logs[0].args.errorId.toNumber();
expect(errCode).to.be.equal(ExchangeContractErrs.ERROR_ORDER_FULLY_FILLED_OR_CANCELLED);
});
diff --git a/packages/contracts/test/ts/exchange/helpers.ts b/packages/contracts/test/ts/exchange/helpers.ts
index a39f4d9e2..95f68e419 100644
--- a/packages/contracts/test/ts/exchange/helpers.ts
+++ b/packages/contracts/test/ts/exchange/helpers.ts
@@ -1,21 +1,18 @@
-import {ZeroEx} from '0x.js';
-import {BigNumber} from 'bignumber.js';
+import { ZeroEx } from '0x.js';
+import { BigNumber } from '@0xproject/utils';
import * as chai from 'chai';
import ethUtil = require('ethereumjs-util');
-import {Artifacts} from '../../../util/artifacts';
-import {ExchangeWrapper} from '../../../util/exchange_wrapper';
-import {Order} from '../../../util/order';
-import {OrderFactory} from '../../../util/order_factory';
-import {chaiSetup} from '../utils/chai_setup';
+import { Artifacts } from '../../../util/artifacts';
+import { ExchangeWrapper } from '../../../util/exchange_wrapper';
+import { Order } from '../../../util/order';
+import { OrderFactory } from '../../../util/order_factory';
+import { chaiSetup } from '../utils/chai_setup';
chaiSetup.configure();
const expect = chai.expect;
-const {
- Exchange,
- TokenRegistry,
-} = new Artifacts(artifacts);
+const { Exchange, TokenRegistry } = new Artifacts(artifacts);
contract('Exchange', (accounts: string[]) => {
const maker = accounts[0];
@@ -26,10 +23,7 @@ contract('Exchange', (accounts: string[]) => {
let orderFactory: OrderFactory;
before(async () => {
- const [tokenRegistry, exchange] = await Promise.all([
- TokenRegistry.deployed(),
- Exchange.deployed(),
- ]);
+ const [tokenRegistry, exchange] = await Promise.all([TokenRegistry.deployed(), Exchange.deployed()]);
exchangeWrapper = new ExchangeWrapper(exchange);
const [repAddress, dgdAddress] = await Promise.all([
tokenRegistry.getTokenAddressBySymbol('REP'),
diff --git a/packages/contracts/test/ts/exchange/wrapper.ts b/packages/contracts/test/ts/exchange/wrapper.ts
index c40d60104..e69e08bcf 100644
--- a/packages/contracts/test/ts/exchange/wrapper.ts
+++ b/packages/contracts/test/ts/exchange/wrapper.ts
@@ -1,25 +1,20 @@
-import {ZeroEx} from '0x.js';
-import {BigNumber} from 'bignumber.js';
+import { ZeroEx } from '0x.js';
+import { BigNumber } from '@0xproject/utils';
import * as chai from 'chai';
import * as _ from 'lodash';
-import {Artifacts} from '../../../util/artifacts';
-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, ContractInstance} from '../../../util/types';
-import {chaiSetup} from '../utils/chai_setup';
+import { Artifacts } from '../../../util/artifacts';
+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, ContractInstance } from '../../../util/types';
+import { chaiSetup } from '../utils/chai_setup';
chaiSetup.configure();
const expect = chai.expect;
-const {
- Exchange,
- TokenTransferProxy,
- DummyToken,
- TokenRegistry,
-} = new Artifacts(artifacts);
+const { Exchange, TokenTransferProxy, DummyToken, TokenRegistry } = new Artifacts(artifacts);
contract('Exchange', (accounts: string[]) => {
const maker = accounts[0];
@@ -43,10 +38,7 @@ contract('Exchange', (accounts: string[]) => {
let orderFactory: OrderFactory;
before(async () => {
- [tokenRegistry, exchange] = await Promise.all([
- TokenRegistry.deployed(),
- Exchange.deployed(),
- ]);
+ [tokenRegistry, exchange] = await Promise.all([TokenRegistry.deployed(), Exchange.deployed()]);
exWrapper = new ExchangeWrapper(exchange);
const [repAddress, dgdAddress, zrxAddress] = await Promise.all([
tokenRegistry.getTokenAddressBySymbol('REP'),
@@ -74,18 +66,18 @@ contract('Exchange', (accounts: string[]) => {
]);
dmyBalances = new Balances([rep, dgd, zrx], [maker, taker, feeRecipient]);
await Promise.all([
- rep.approve(TokenTransferProxy.address, INIT_ALLOW, {from: maker}),
- rep.approve(TokenTransferProxy.address, INIT_ALLOW, {from: taker}),
- rep.setBalance(maker, INIT_BAL, {from: tokenOwner}),
- rep.setBalance(taker, INIT_BAL, {from: tokenOwner}),
- dgd.approve(TokenTransferProxy.address, INIT_ALLOW, {from: maker}),
- dgd.approve(TokenTransferProxy.address, INIT_ALLOW, {from: taker}),
- dgd.setBalance(maker, INIT_BAL, {from: tokenOwner}),
- dgd.setBalance(taker, INIT_BAL, {from: tokenOwner}),
- zrx.approve(TokenTransferProxy.address, INIT_ALLOW, {from: maker}),
- zrx.approve(TokenTransferProxy.address, INIT_ALLOW, {from: taker}),
- zrx.setBalance(maker, INIT_BAL, {from: tokenOwner}),
- zrx.setBalance(taker, INIT_BAL, {from: tokenOwner}),
+ rep.approve(TokenTransferProxy.address, INIT_ALLOW, { from: maker }),
+ rep.approve(TokenTransferProxy.address, INIT_ALLOW, { from: taker }),
+ rep.setBalance(maker, INIT_BAL, { from: tokenOwner }),
+ rep.setBalance(taker, INIT_BAL, { from: tokenOwner }),
+ dgd.approve(TokenTransferProxy.address, INIT_ALLOW, { from: maker }),
+ dgd.approve(TokenTransferProxy.address, INIT_ALLOW, { from: taker }),
+ dgd.setBalance(maker, INIT_BAL, { from: tokenOwner }),
+ dgd.setBalance(taker, INIT_BAL, { from: tokenOwner }),
+ zrx.approve(TokenTransferProxy.address, INIT_ALLOW, { from: maker }),
+ zrx.approve(TokenTransferProxy.address, INIT_ALLOW, { from: taker }),
+ zrx.setBalance(maker, INIT_BAL, { from: tokenOwner }),
+ zrx.setBalance(taker, INIT_BAL, { from: tokenOwner }),
]);
});
@@ -100,31 +92,38 @@ contract('Exchange', (accounts: string[]) => {
takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18),
});
const fillTakerTokenAmount = order.params.takerTokenAmount.div(2);
- await exWrapper.fillOrKillOrderAsync(order, taker, {fillTakerTokenAmount});
+ await exWrapper.fillOrKillOrderAsync(order, taker, {
+ fillTakerTokenAmount,
+ });
const newBalances = await dmyBalances.getAsync();
const fillMakerTokenAmount = fillTakerTokenAmount
- .times(order.params.makerTokenAmount)
- .dividedToIntegerBy(order.params.takerTokenAmount);
+ .times(order.params.makerTokenAmount)
+ .dividedToIntegerBy(order.params.takerTokenAmount);
const makerFee = order.params.makerFee
- .times(fillMakerTokenAmount)
- .dividedToIntegerBy(order.params.makerTokenAmount);
+ .times(fillMakerTokenAmount)
+ .dividedToIntegerBy(order.params.makerTokenAmount);
const takerFee = order.params.takerFee
- .times(fillMakerTokenAmount)
- .dividedToIntegerBy(order.params.makerTokenAmount);
- expect(newBalances[maker][order.params.makerToken])
- .to.be.bignumber.equal(balances[maker][order.params.makerToken].minus(fillMakerTokenAmount));
- expect(newBalances[maker][order.params.takerToken])
- .to.be.bignumber.equal(balances[maker][order.params.takerToken].add(fillTakerTokenAmount));
+ .times(fillMakerTokenAmount)
+ .dividedToIntegerBy(order.params.makerTokenAmount);
+ expect(newBalances[maker][order.params.makerToken]).to.be.bignumber.equal(
+ balances[maker][order.params.makerToken].minus(fillMakerTokenAmount),
+ );
+ expect(newBalances[maker][order.params.takerToken]).to.be.bignumber.equal(
+ balances[maker][order.params.takerToken].add(fillTakerTokenAmount),
+ );
expect(newBalances[maker][zrx.address]).to.be.bignumber.equal(balances[maker][zrx.address].minus(makerFee));
- expect(newBalances[taker][order.params.takerToken])
- .to.be.bignumber.equal(balances[taker][order.params.takerToken].minus(fillTakerTokenAmount));
- expect(newBalances[taker][order.params.makerToken])
- .to.be.bignumber.equal(balances[taker][order.params.makerToken].add(fillMakerTokenAmount));
+ expect(newBalances[taker][order.params.takerToken]).to.be.bignumber.equal(
+ balances[taker][order.params.takerToken].minus(fillTakerTokenAmount),
+ );
+ expect(newBalances[taker][order.params.makerToken]).to.be.bignumber.equal(
+ balances[taker][order.params.makerToken].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(balances[feeRecipient][zrx.address].add(makerFee.add(takerFee)));
+ expect(newBalances[feeRecipient][zrx.address]).to.be.bignumber.equal(
+ balances[feeRecipient][zrx.address].add(makerFee.add(takerFee)),
+ );
});
it('should throw if an order is expired', async () => {
@@ -132,18 +131,18 @@ contract('Exchange', (accounts: string[]) => {
expirationTimestampInSec: new BigNumber(Math.floor((Date.now() - 10000) / 1000)),
});
- return expect(exWrapper.fillOrKillOrderAsync(order, taker))
- .to.be.rejectedWith(constants.INVALID_OPCODE);
+ return expect(exWrapper.fillOrKillOrderAsync(order, taker)).to.be.rejectedWith(constants.REVERT);
});
it('should throw if entire fillTakerTokenAmount not filled', async () => {
const order = await orderFactory.newSignedOrderAsync();
const from = taker;
- await exWrapper.fillOrderAsync(order, from, {fillTakerTokenAmount: order.params.takerTokenAmount.div(2)});
+ await exWrapper.fillOrderAsync(order, from, {
+ fillTakerTokenAmount: order.params.takerTokenAmount.div(2),
+ });
- return expect(exWrapper.fillOrKillOrderAsync(order, taker))
- .to.be.rejectedWith(constants.INVALID_OPCODE);
+ return expect(exWrapper.fillOrKillOrderAsync(order, taker)).to.be.rejectedWith(constants.REVERT);
});
});
@@ -166,14 +165,14 @@ contract('Exchange', (accounts: string[]) => {
orders.forEach(order => {
const fillTakerTokenAmount = order.params.takerTokenAmount.div(2);
const fillMakerTokenAmount = fillTakerTokenAmount
- .times(order.params.makerTokenAmount)
- .dividedToIntegerBy(order.params.takerTokenAmount);
+ .times(order.params.makerTokenAmount)
+ .dividedToIntegerBy(order.params.takerTokenAmount);
const makerFee = order.params.makerFee
- .times(fillMakerTokenAmount)
- .dividedToIntegerBy(order.params.makerTokenAmount);
+ .times(fillMakerTokenAmount)
+ .dividedToIntegerBy(order.params.makerTokenAmount);
const takerFee = order.params.takerFee
- .times(fillMakerTokenAmount)
- .dividedToIntegerBy(order.params.makerTokenAmount);
+ .times(fillMakerTokenAmount)
+ .dividedToIntegerBy(order.params.makerTokenAmount);
fillTakerTokenAmounts.push(fillTakerTokenAmount);
balances[maker][makerToken] = balances[maker][makerToken].minus(fillMakerTokenAmount);
balances[maker][takerToken] = balances[maker][takerToken].add(fillTakerTokenAmount);
@@ -181,11 +180,14 @@ contract('Exchange', (accounts: string[]) => {
balances[taker][makerToken] = balances[taker][makerToken].add(fillMakerTokenAmount);
balances[taker][takerToken] = balances[taker][takerToken].minus(fillTakerTokenAmount);
balances[taker][zrx.address] = balances[taker][zrx.address].minus(takerFee);
- balances[feeRecipient][zrx.address] =
- balances[feeRecipient][zrx.address].add(makerFee.add(takerFee));
+ balances[feeRecipient][zrx.address] = balances[feeRecipient][zrx.address].add(
+ makerFee.add(takerFee),
+ );
});
- await exWrapper.batchFillOrdersAsync(orders, taker, {fillTakerTokenAmounts});
+ await exWrapper.batchFillOrdersAsync(orders, taker, {
+ fillTakerTokenAmounts,
+ });
const newBalances = await dmyBalances.getAsync();
expect(newBalances).to.be.deep.equal(balances);
@@ -200,14 +202,14 @@ contract('Exchange', (accounts: string[]) => {
orders.forEach(order => {
const fillTakerTokenAmount = order.params.takerTokenAmount.div(2);
const fillMakerTokenAmount = fillTakerTokenAmount
- .times(order.params.makerTokenAmount)
- .dividedToIntegerBy(order.params.takerTokenAmount);
+ .times(order.params.makerTokenAmount)
+ .dividedToIntegerBy(order.params.takerTokenAmount);
const makerFee = order.params.makerFee
- .times(fillMakerTokenAmount)
- .dividedToIntegerBy(order.params.makerTokenAmount);
+ .times(fillMakerTokenAmount)
+ .dividedToIntegerBy(order.params.makerTokenAmount);
const takerFee = order.params.takerFee
- .times(fillMakerTokenAmount)
- .dividedToIntegerBy(order.params.makerTokenAmount);
+ .times(fillMakerTokenAmount)
+ .dividedToIntegerBy(order.params.makerTokenAmount);
fillTakerTokenAmounts.push(fillTakerTokenAmount);
balances[maker][makerToken] = balances[maker][makerToken].minus(fillMakerTokenAmount);
balances[maker][takerToken] = balances[maker][takerToken].add(fillTakerTokenAmount);
@@ -215,11 +217,14 @@ contract('Exchange', (accounts: string[]) => {
balances[taker][makerToken] = balances[taker][makerToken].add(fillMakerTokenAmount);
balances[taker][takerToken] = balances[taker][takerToken].minus(fillTakerTokenAmount);
balances[taker][zrx.address] = balances[taker][zrx.address].minus(takerFee);
- balances[feeRecipient][zrx.address] =
- balances[feeRecipient][zrx.address].add(makerFee.add(takerFee));
+ balances[feeRecipient][zrx.address] = balances[feeRecipient][zrx.address].add(
+ makerFee.add(takerFee),
+ );
});
- await exWrapper.batchFillOrKillOrdersAsync(orders, taker, {fillTakerTokenAmounts});
+ await exWrapper.batchFillOrKillOrdersAsync(orders, taker, {
+ fillTakerTokenAmounts,
+ });
const newBalances = await dmyBalances.getAsync();
expect(newBalances).to.be.deep.equal(balances);
@@ -227,8 +232,6 @@ contract('Exchange', (accounts: string[]) => {
it('should throw if a single order does not fill the expected amount', async () => {
const fillTakerTokenAmounts: BigNumber[] = [];
- const makerToken = rep.address;
- const takerToken = dgd.address;
orders.forEach(order => {
const fillTakerTokenAmount = order.params.takerTokenAmount.div(2);
fillTakerTokenAmounts.push(fillTakerTokenAmount);
@@ -236,57 +239,77 @@ contract('Exchange', (accounts: string[]) => {
await exWrapper.fillOrKillOrderAsync(orders[0], taker);
- return expect(exWrapper.batchFillOrKillOrdersAsync(orders, taker, {fillTakerTokenAmounts}))
- .to.be.rejectedWith(constants.INVALID_OPCODE);
+ return expect(
+ exWrapper.batchFillOrKillOrdersAsync(orders, taker, {
+ fillTakerTokenAmounts,
+ }),
+ ).to.be.rejectedWith(constants.REVERT);
});
});
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));
- await exWrapper.fillOrdersUpToAsync(orders, taker, {fillTakerTokenAmount});
+ const fillTakerTokenAmount = orders[0].params.takerTokenAmount.plus(
+ orders[1].params.takerTokenAmount.div(2),
+ );
+ await exWrapper.fillOrdersUpToAsync(orders, taker, {
+ fillTakerTokenAmount,
+ });
const newBalances = await dmyBalances.getAsync();
const fillMakerTokenAmount = orders[0].params.makerTokenAmount.add(
- orders[1].params.makerTokenAmount.dividedToIntegerBy(2));
+ orders[1].params.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));
- expect(newBalances[maker][orders[0].params.takerToken])
- .to.be.bignumber.equal(balances[maker][orders[0].params.takerToken].add(fillTakerTokenAmount));
- expect(newBalances[maker][zrx.address]).to.be.bignumber
- .equal(balances[maker][zrx.address].minus(makerFee));
- expect(newBalances[taker][orders[0].params.takerToken])
- .to.be.bignumber.equal(balances[taker][orders[0].params.takerToken].minus(fillTakerTokenAmount));
- expect(newBalances[taker][orders[0].params.makerToken])
- .to.be.bignumber.equal(balances[taker][orders[0].params.makerToken].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(balances[feeRecipient][zrx.address].add(makerFee.add(takerFee)));
+ expect(newBalances[maker][orders[0].params.makerToken]).to.be.bignumber.equal(
+ balances[maker][orders[0].params.makerToken].minus(fillMakerTokenAmount),
+ );
+ expect(newBalances[maker][orders[0].params.takerToken]).to.be.bignumber.equal(
+ balances[maker][orders[0].params.takerToken].add(fillTakerTokenAmount),
+ );
+ expect(newBalances[maker][zrx.address]).to.be.bignumber.equal(
+ balances[maker][zrx.address].minus(makerFee),
+ );
+ expect(newBalances[taker][orders[0].params.takerToken]).to.be.bignumber.equal(
+ balances[taker][orders[0].params.takerToken].minus(fillTakerTokenAmount),
+ );
+ expect(newBalances[taker][orders[0].params.makerToken]).to.be.bignumber.equal(
+ balances[taker][orders[0].params.makerToken].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(
+ balances[feeRecipient][zrx.address].add(makerFee.add(takerFee)),
+ );
});
it('should fill all orders if cannot fill entire fillTakerTokenAmount', async () => {
const fillTakerTokenAmount = ZeroEx.toBaseUnitAmount(new BigNumber(100000), 18);
orders.forEach(order => {
- balances[maker][order.params.makerToken] = balances[maker][order.params.makerToken]
- .minus(order.params.makerTokenAmount);
- balances[maker][order.params.takerToken] = balances[maker][order.params.takerToken]
- .add(order.params.takerTokenAmount);
- balances[maker][zrx.address] = balances[maker][zrx.address]
- .minus(order.params.makerFee);
- balances[taker][order.params.makerToken] = balances[taker][order.params.makerToken]
- .add(order.params.makerTokenAmount);
- balances[taker][order.params.takerToken] = balances[taker][order.params.takerToken]
- .minus(order.params.takerTokenAmount);
+ balances[maker][order.params.makerToken] = balances[maker][order.params.makerToken].minus(
+ order.params.makerTokenAmount,
+ );
+ balances[maker][order.params.takerToken] = balances[maker][order.params.takerToken].add(
+ order.params.takerTokenAmount,
+ );
+ balances[maker][zrx.address] = balances[maker][zrx.address].minus(order.params.makerFee);
+ balances[taker][order.params.makerToken] = balances[taker][order.params.makerToken].add(
+ order.params.makerTokenAmount,
+ );
+ balances[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[feeRecipient][zrx.address] =
- balances[feeRecipient][zrx.address].add(order.params.makerFee.add(order.params.takerFee));
+ balances[feeRecipient][zrx.address] = balances[feeRecipient][zrx.address].add(
+ order.params.makerFee.add(order.params.takerFee),
+ );
+ });
+ await exWrapper.fillOrdersUpToAsync(orders, taker, {
+ fillTakerTokenAmount,
});
- await exWrapper.fillOrdersUpToAsync(orders, taker, {fillTakerTokenAmount});
const newBalances = await dmyBalances.getAsync();
expect(newBalances).to.be.deep.equal(balances);
@@ -295,24 +318,28 @@ contract('Exchange', (accounts: string[]) => {
it('should throw when an order does not use the same takerToken', async () => {
orders = await Promise.all([
orderFactory.newSignedOrderAsync(),
- orderFactory.newSignedOrderAsync({takerToken: zrx.address}),
+ orderFactory.newSignedOrderAsync({ takerToken: zrx.address }),
orderFactory.newSignedOrderAsync(),
]);
return expect(
- exWrapper.fillOrdersUpToAsync(
- orders, taker, {fillTakerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(1000), 18)}),
- ).to.be.rejectedWith(constants.INVALID_OPCODE);
+ exWrapper.fillOrdersUpToAsync(orders, taker, {
+ fillTakerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(1000), 18),
+ }),
+ ).to.be.rejectedWith(constants.REVERT);
});
});
describe('batchCancelOrders', () => {
it('should be able to cancel multiple orders', async () => {
const cancelTakerTokenAmounts = _.map(orders, order => order.params.takerTokenAmount);
- await exWrapper.batchCancelOrdersAsync(orders, maker, {cancelTakerTokenAmounts});
+ await exWrapper.batchCancelOrdersAsync(orders, maker, {
+ cancelTakerTokenAmounts,
+ });
- const res = await exWrapper.batchFillOrdersAsync(
- orders, taker, {fillTakerTokenAmounts: cancelTakerTokenAmounts});
+ await exWrapper.batchFillOrdersAsync(orders, taker, {
+ fillTakerTokenAmounts: cancelTakerTokenAmounts,
+ });
const newBalances = await dmyBalances.getAsync();
expect(balances).to.be.deep.equal(newBalances);
});
diff --git a/packages/contracts/test/ts/multi_sig_with_time_lock.ts b/packages/contracts/test/ts/multi_sig_with_time_lock.ts
index 6dd4dc3b2..ea939a758 100644
--- a/packages/contracts/test/ts/multi_sig_with_time_lock.ts
+++ b/packages/contracts/test/ts/multi_sig_with_time_lock.ts
@@ -1,18 +1,18 @@
-import {promisify} from '@0xproject/utils';
-import {BigNumber} from 'bignumber.js';
+import { RPC } from '@0xproject/dev-utils';
+import { BigNumber, promisify } from '@0xproject/utils';
import * as chai from 'chai';
import Web3 = require('web3');
import * as multiSigWalletJSON from '../../build/contracts/MultiSigWalletWithTimeLock.json';
-import {Artifacts} from '../../util/artifacts';
-import {constants} from '../../util/constants';
-import {MultiSigWrapper} from '../../util/multi_sig_wrapper';
-import {RPC} from '../../util/rpc';
-import {ContractInstance} from '../../util/types';
+import * as truffleConf from '../../truffle.js';
+import { Artifacts } from '../../util/artifacts';
+import { constants } from '../../util/constants';
+import { MultiSigWrapper } from '../../util/multi_sig_wrapper';
+import { ContractInstance } from '../../util/types';
-import {chaiSetup} from './utils/chai_setup';
+import { chaiSetup } from './utils/chai_setup';
-const {MultiSigWalletWithTimeLock} = new Artifacts(artifacts);
+const { MultiSigWalletWithTimeLock } = new Artifacts(artifacts);
const MULTI_SIG_ABI = (multiSigWalletJSON as any).abi;
chaiSetup.configure();
@@ -38,13 +38,15 @@ contract('MultiSigWalletWithTimeLock', (accounts: string[]) => {
const secondsTimeLocked = await multiSig.secondsTimeLocked.call();
initialSecondsTimeLocked = secondsTimeLocked.toNumber();
- rpc = new RPC();
+ const rpcUrl = `http://${truffleConf.networks.development.host}:${truffleConf.networks.development.port}`;
+ rpc = new RPC(rpcUrl);
});
describe('changeTimeLock', () => {
it('should throw when not called by wallet', async () => {
- return expect(multiSig.changeTimeLock(SECONDS_TIME_LOCKED, {from: owners[0]}))
- .to.be.rejectedWith(constants.INVALID_OPCODE);
+ return expect(multiSig.changeTimeLock(SECONDS_TIME_LOCKED, { from: owners[0] })).to.be.rejectedWith(
+ constants.REVERT,
+ );
});
it('should throw without enough confirmations', async () => {
@@ -58,11 +60,11 @@ contract('MultiSigWalletWithTimeLock', (accounts: string[]) => {
const subRes = await multiSigWrapper.submitTransactionAsync(destination, from, dataParams);
txId = subRes.logs[0].args.transactionId.toNumber();
- return expect(multiSig.executeTransaction(txId)).to.be.rejectedWith(constants.INVALID_OPCODE);
+ return expect(multiSig.executeTransaction(txId)).to.be.rejectedWith(constants.REVERT);
});
it('should set confirmation time with enough confirmations', async () => {
- const res = await multiSig.confirmTransaction(txId, {from: owners[1]});
+ const res = await multiSig.confirmTransaction(txId, { from: owners[1] });
expect(res.logs).to.have.length(2);
const blockNum = await promisify<number>(web3.eth.getBlockNumber)();
const blockInfo = await promisify<Web3.BlockWithoutTransactionData>(web3.eth.getBlock)(blockNum);
@@ -94,10 +96,12 @@ contract('MultiSigWalletWithTimeLock', (accounts: string[]) => {
const subRes = await multiSigWrapper.submitTransactionAsync(destination, from, dataParams);
txId = subRes.logs[0].args.transactionId.toNumber();
- const confRes = await multiSig.confirmTransaction(txId, {from: owners[1]});
+ const confRes = await multiSig.confirmTransaction(txId, {
+ from: owners[1],
+ });
expect(confRes.logs).to.have.length(2);
- return expect(multiSig.executeTransaction(txId)).to.be.rejectedWith(constants.INVALID_OPCODE);
+ return expect(multiSig.executeTransaction(txId)).to.be.rejectedWith(constants.REVERT);
});
it('should execute if it has enough confirmations and is past the time lock', async () => {
diff --git a/packages/contracts/test/ts/multi_sig_with_time_lock_except_remove_auth_addr.ts b/packages/contracts/test/ts/multi_sig_with_time_lock_except_remove_auth_addr.ts
index 97ccac2bd..62aa625fe 100644
--- a/packages/contracts/test/ts/multi_sig_with_time_lock_except_remove_auth_addr.ts
+++ b/packages/contracts/test/ts/multi_sig_with_time_lock_except_remove_auth_addr.ts
@@ -1,14 +1,14 @@
import * as chai from 'chai';
import * as tokenTransferProxyJSON from '../../build/contracts/TokenTransferProxy.json';
-import {Artifacts} from '../../util/artifacts';
-import {constants} from '../../util/constants';
-import {crypto} from '../../util/crypto';
-import {MultiSigWrapper} from '../../util/multi_sig_wrapper';
-import {ContractInstance, TransactionDataParams} from '../../util/types';
-
-import {chaiSetup} from './utils/chai_setup';
-const {TokenTransferProxy, MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress} = new Artifacts(artifacts);
+import { Artifacts } from '../../util/artifacts';
+import { constants } from '../../util/constants';
+import { crypto } from '../../util/crypto';
+import { MultiSigWrapper } from '../../util/multi_sig_wrapper';
+import { ContractInstance, TransactionDataParams } from '../../util/types';
+
+import { chaiSetup } from './utils/chai_setup';
+const { TokenTransferProxy, MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress } = new Artifacts(artifacts);
const PROXY_ABI = (tokenTransferProxyJSON as any).abi;
chaiSetup.configure();
@@ -20,8 +20,14 @@ contract('MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', (accounts: s
const SECONDS_TIME_LOCKED = 1000000;
// initialize fake addresses
- const authorizedAddress = `0x${crypto.solSHA3([accounts[0]]).slice(0, 20).toString('hex')}`;
- const unauthorizedAddress = `0x${crypto.solSHA3([accounts[1]]).slice(0, 20).toString('hex')}`;
+ const authorizedAddress = `0x${crypto
+ .solSHA3([accounts[0]])
+ .slice(0, 20)
+ .toString('hex')}`;
+ const unauthorizedAddress = `0x${crypto
+ .solSHA3([accounts[1]])
+ .slice(0, 20)
+ .toString('hex')}`;
let tokenTransferProxy: ContractInstance;
let multiSig: ContractInstance;
@@ -31,11 +37,19 @@ contract('MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', (accounts: s
beforeEach(async () => {
const initialOwner = accounts[0];
- tokenTransferProxy = await TokenTransferProxy.new({from: initialOwner});
- await tokenTransferProxy.addAuthorizedAddress(authorizedAddress, {from: initialOwner});
+ tokenTransferProxy = await TokenTransferProxy.new({ from: initialOwner });
+ await tokenTransferProxy.addAuthorizedAddress(authorizedAddress, {
+ from: initialOwner,
+ });
multiSig = await MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress.new(
- owners, requiredApprovals, SECONDS_TIME_LOCKED, tokenTransferProxy.address);
- await tokenTransferProxy.transferOwnership(multiSig.address, {from: initialOwner});
+ owners,
+ requiredApprovals,
+ SECONDS_TIME_LOCKED,
+ tokenTransferProxy.address,
+ );
+ await tokenTransferProxy.transferOwnership(multiSig.address, {
+ from: initialOwner,
+ });
multiSigWrapper = new MultiSigWrapper(multiSig);
validDestination = tokenTransferProxy.address;
});
@@ -43,8 +57,7 @@ contract('MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', (accounts: s
describe('isFunctionRemoveAuthorizedAddress', () => {
it('should throw if data is not for removeAuthorizedAddress', async () => {
const data = MultiSigWrapper.encodeFnArgs('addAuthorizedAddress', PROXY_ABI, [owners[0]]);
- return expect(multiSig.isFunctionRemoveAuthorizedAddress.call(data))
- .to.be.rejectedWith(constants.INVALID_OPCODE);
+ return expect(multiSig.isFunctionRemoveAuthorizedAddress.call(data)).to.be.rejectedWith(constants.REVERT);
});
it('should return true if data is for removeAuthorizedAddress', async () => {
@@ -64,7 +77,7 @@ contract('MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', (accounts: s
const res = await multiSigWrapper.submitTransactionAsync(validDestination, owners[0], dataParams);
const txId = res.logs[0].args.transactionId.toString();
- return expect(multiSig.executeRemoveAuthorizedAddress(txId)).to.be.rejectedWith(constants.INVALID_OPCODE);
+ return expect(multiSig.executeRemoveAuthorizedAddress(txId)).to.be.rejectedWith(constants.REVERT);
});
it('should throw if tx destination is not the tokenTransferProxy', async () => {
@@ -77,11 +90,11 @@ contract('MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', (accounts: s
};
const res = await multiSigWrapper.submitTransactionAsync(invalidDestination, owners[0], dataParams);
const txId = res.logs[0].args.transactionId.toString();
- await multiSig.confirmTransaction(txId, {from: owners[1]});
+ await multiSig.confirmTransaction(txId, { from: owners[1] });
const isConfirmed = await multiSig.isConfirmed.call(txId);
expect(isConfirmed).to.be.true();
- return expect(multiSig.executeRemoveAuthorizedAddress(txId)).to.be.rejectedWith(constants.INVALID_OPCODE);
+ return expect(multiSig.executeRemoveAuthorizedAddress(txId)).to.be.rejectedWith(constants.REVERT);
});
it('should throw if tx data is not for removeAuthorizedAddress', async () => {
@@ -92,11 +105,11 @@ contract('MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', (accounts: s
};
const res = await multiSigWrapper.submitTransactionAsync(validDestination, owners[0], dataParams);
const txId = res.logs[0].args.transactionId.toString();
- await multiSig.confirmTransaction(txId, {from: owners[1]});
+ await multiSig.confirmTransaction(txId, { from: owners[1] });
const isConfirmed = await multiSig.isConfirmed.call(txId);
expect(isConfirmed).to.be.true();
- return expect(multiSig.executeRemoveAuthorizedAddress(txId)).to.be.rejectedWith(constants.INVALID_OPCODE);
+ return expect(multiSig.executeRemoveAuthorizedAddress(txId)).to.be.rejectedWith(constants.REVERT);
});
it('should execute removeAuthorizedAddress for valid tokenTransferProxy if fully confirmed', async () => {
@@ -107,7 +120,7 @@ contract('MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', (accounts: s
};
const res = await multiSigWrapper.submitTransactionAsync(validDestination, owners[0], dataParams);
const txId = res.logs[0].args.transactionId.toString();
- await multiSig.confirmTransaction(txId, {from: owners[1]});
+ await multiSig.confirmTransaction(txId, { from: owners[1] });
const isConfirmed = await multiSig.isConfirmed.call(txId);
expect(isConfirmed).to.be.true();
await multiSig.executeRemoveAuthorizedAddress(txId);
@@ -124,14 +137,14 @@ contract('MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', (accounts: s
};
const res = await multiSigWrapper.submitTransactionAsync(validDestination, owners[0], dataParams);
const txId = res.logs[0].args.transactionId.toString();
- await multiSig.confirmTransaction(txId, {from: owners[1]});
+ await multiSig.confirmTransaction(txId, { from: owners[1] });
const isConfirmed = await multiSig.isConfirmed.call(txId);
expect(isConfirmed).to.be.true();
await multiSig.executeRemoveAuthorizedAddress(txId);
const tx = await multiSig.transactions.call(txId);
const isExecuted = tx[3];
expect(isExecuted).to.be.true();
- return expect(multiSig.executeRemoveAuthorizedAddress(txId)).to.be.rejectedWith(constants.INVALID_OPCODE);
+ return expect(multiSig.executeRemoveAuthorizedAddress(txId)).to.be.rejectedWith(constants.REVERT);
});
});
});
diff --git a/packages/contracts/test/ts/token_registry.ts b/packages/contracts/test/ts/token_registry.ts
index ed0bbf55b..d1c551565 100644
--- a/packages/contracts/test/ts/token_registry.ts
+++ b/packages/contracts/test/ts/token_registry.ts
@@ -1,16 +1,16 @@
-import {ZeroEx} from '0x.js';
+import { ZeroEx } from '0x.js';
import * as chai from 'chai';
import ethUtil = require('ethereumjs-util');
import * as _ from 'lodash';
-import {Artifacts} from '../../util/artifacts';
-import {constants} from '../../util/constants';
-import {TokenRegWrapper} from '../../util/token_registry_wrapper';
-import {ContractInstance} from '../../util/types';
+import { Artifacts } from '../../util/artifacts';
+import { constants } from '../../util/constants';
+import { TokenRegWrapper } from '../../util/token_registry_wrapper';
+import { ContractInstance } from '../../util/types';
-import {chaiSetup} from './utils/chai_setup';
+import { chaiSetup } from './utils/chai_setup';
-const {TokenRegistry} = new Artifacts(artifacts);
+const { TokenRegistry } = new Artifacts(artifacts);
chaiSetup.configure();
const expect = chai.expect;
@@ -58,7 +58,7 @@ contract('TokenRegistry', (accounts: string[]) => {
describe('addToken', () => {
it('should throw when not called by owner', async () => {
- return expect(tokenRegWrapper.addTokenAsync(token1, notOwner)).to.be.rejectedWith(constants.INVALID_OPCODE);
+ return expect(tokenRegWrapper.addTokenAsync(token1, notOwner)).to.be.rejectedWith(constants.REVERT);
});
it('should add token metadata when called by owner', async () => {
@@ -70,27 +70,31 @@ contract('TokenRegistry', (accounts: string[]) => {
it('should throw if token already exists', async () => {
await tokenRegWrapper.addTokenAsync(token1, owner);
- return expect(tokenRegWrapper.addTokenAsync(token1, owner)).to.be.rejectedWith(constants.INVALID_OPCODE);
+ return expect(tokenRegWrapper.addTokenAsync(token1, owner)).to.be.rejectedWith(constants.REVERT);
});
it('should throw if token address is null', async () => {
- return expect(tokenRegWrapper.addTokenAsync(nullToken, owner)).to.be.rejectedWith(constants.INVALID_OPCODE);
+ return expect(tokenRegWrapper.addTokenAsync(nullToken, owner)).to.be.rejectedWith(constants.REVERT);
});
it('should throw if name already exists', async () => {
await tokenRegWrapper.addTokenAsync(token1, owner);
- const duplicateNameToken = _.assign({}, token2, {name: token1.name});
+ const duplicateNameToken = _.assign({}, token2, { name: token1.name });
- return expect(tokenRegWrapper.addTokenAsync(duplicateNameToken, owner))
- .to.be.rejectedWith(constants.INVALID_OPCODE);
+ return expect(tokenRegWrapper.addTokenAsync(duplicateNameToken, owner)).to.be.rejectedWith(
+ constants.REVERT,
+ );
});
it('should throw if symbol already exists', async () => {
await tokenRegWrapper.addTokenAsync(token1, owner);
- const duplicateSymbolToken = _.assign({}, token2, {symbol: token1.symbol});
+ const duplicateSymbolToken = _.assign({}, token2, {
+ symbol: token1.symbol,
+ });
- return expect(tokenRegWrapper.addTokenAsync(duplicateSymbolToken, owner))
- .to.be.rejectedWith(constants.INVALID_OPCODE);
+ return expect(tokenRegWrapper.addTokenAsync(duplicateSymbolToken, owner)).to.be.rejectedWith(
+ constants.REVERT,
+ );
});
});
@@ -115,19 +119,22 @@ contract('TokenRegistry', (accounts: string[]) => {
describe('setTokenName', () => {
it('should throw when not called by owner', async () => {
- return expect(tokenReg.setTokenName(token1.address, token2.name, {from: notOwner}))
- .to.be.rejectedWith(constants.INVALID_OPCODE);
+ return expect(
+ tokenReg.setTokenName(token1.address, token2.name, { from: notOwner }),
+ ).to.be.rejectedWith(constants.REVERT);
});
it('should change the token name when called by owner', async () => {
- const res = await tokenReg.setTokenName(token1.address, token2.name, {from: owner});
+ const res = await tokenReg.setTokenName(token1.address, token2.name, {
+ from: owner,
+ });
expect(res.logs).to.have.length(1);
const [newData, oldData] = await Promise.all([
tokenRegWrapper.getTokenByNameAsync(token2.name),
tokenRegWrapper.getTokenByNameAsync(token1.name),
]);
- const expectedNewData = _.assign({}, token1, {name: token2.name});
+ const expectedNewData = _.assign({}, token1, { name: token2.name });
const expectedOldData = nullToken;
expect(newData).to.be.deep.equal(expectedNewData);
expect(oldData).to.be.deep.equal(expectedOldData);
@@ -136,31 +143,36 @@ contract('TokenRegistry', (accounts: string[]) => {
it('should throw if the name already exists', async () => {
await tokenRegWrapper.addTokenAsync(token2, owner);
- return expect(tokenReg.setTokenName(token1.address, token2.name, {from: owner}))
- .to.be.rejectedWith(constants.INVALID_OPCODE);
+ return expect(tokenReg.setTokenName(token1.address, token2.name, { from: owner })).to.be.rejectedWith(
+ constants.REVERT,
+ );
});
it('should throw if token does not exist', async () => {
- return expect(tokenReg.setTokenName(nullToken.address, token2.name, {from: owner}))
- .to.be.rejectedWith(constants.INVALID_OPCODE);
+ return expect(
+ tokenReg.setTokenName(nullToken.address, token2.name, { from: owner }),
+ ).to.be.rejectedWith(constants.REVERT);
});
});
describe('setTokenSymbol', () => {
it('should throw when not called by owner', async () => {
- return expect(tokenReg.setTokenSymbol(token1.address, token2.symbol, {from: notOwner}))
- .to.be.rejectedWith(constants.INVALID_OPCODE);
+ return expect(
+ tokenReg.setTokenSymbol(token1.address, token2.symbol, {
+ from: notOwner,
+ }),
+ ).to.be.rejectedWith(constants.REVERT);
});
it('should change the token symbol when called by owner', async () => {
- const res = await tokenReg.setTokenSymbol(token1.address, token2.symbol, {from: owner});
+ const res = await tokenReg.setTokenSymbol(token1.address, token2.symbol, { from: owner });
expect(res.logs).to.have.length(1);
const [newData, oldData] = await Promise.all([
tokenRegWrapper.getTokenBySymbolAsync(token2.symbol),
tokenRegWrapper.getTokenBySymbolAsync(token1.symbol),
]);
- const expectedNewData = _.assign({}, token1, {symbol: token2.symbol});
+ const expectedNewData = _.assign({}, token1, { symbol: token2.symbol });
const expectedOldData = nullToken;
expect(newData).to.be.deep.equal(expectedNewData);
expect(oldData).to.be.deep.equal(expectedOldData);
@@ -169,26 +181,35 @@ contract('TokenRegistry', (accounts: string[]) => {
it('should throw if the symbol already exists', async () => {
await tokenRegWrapper.addTokenAsync(token2, owner);
- return expect(tokenReg.setTokenSymbol(token1.address, token2.symbol, {from: owner}))
- .to.be.rejectedWith(constants.INVALID_OPCODE);
+ return expect(
+ tokenReg.setTokenSymbol(token1.address, token2.symbol, {
+ from: owner,
+ }),
+ ).to.be.rejectedWith(constants.REVERT);
});
it('should throw if token does not exist', async () => {
- return expect(tokenReg.setTokenSymbol(nullToken.address, token2.symbol, {from: owner}))
- .to.be.rejectedWith(constants.INVALID_OPCODE);
+ return expect(
+ tokenReg.setTokenSymbol(nullToken.address, token2.symbol, {
+ from: owner,
+ }),
+ ).to.be.rejectedWith(constants.REVERT);
});
});
describe('removeToken', () => {
it('should throw if not called by owner', async () => {
const index = 0;
- return expect(tokenReg.removeToken(token1.address, index, {from: notOwner}))
- .to.be.rejectedWith(constants.INVALID_OPCODE);
+ return expect(tokenReg.removeToken(token1.address, index, { from: notOwner })).to.be.rejectedWith(
+ constants.REVERT,
+ );
});
it('should remove token metadata when called by owner', async () => {
const index = 0;
- const res = await tokenReg.removeToken(token1.address, index, {from: owner});
+ const res = await tokenReg.removeToken(token1.address, index, {
+ from: owner,
+ });
expect(res.logs).to.have.length(1);
const tokenData = await tokenRegWrapper.getTokenMetaDataAsync(token1.address);
expect(tokenData).to.be.deep.equal(nullToken);
@@ -196,17 +217,18 @@ contract('TokenRegistry', (accounts: string[]) => {
it('should throw if token does not exist', async () => {
const index = 0;
- return expect(tokenReg.removeToken(nullToken.address, index, {from: owner}))
- .to.be.rejectedWith(constants.INVALID_OPCODE);
+ return expect(tokenReg.removeToken(nullToken.address, index, { from: owner })).to.be.rejectedWith(
+ constants.REVERT,
+ );
});
it('should throw if token at given index does not match address', async () => {
await tokenRegWrapper.addTokenAsync(token2, owner);
const incorrectIndex = 0;
- return expect(tokenReg.removeToken(token2.address, incorrectIndex, {from: owner}))
- .to.be.rejectedWith(constants.INVALID_OPCODE);
+ return expect(tokenReg.removeToken(token2.address, incorrectIndex, { from: owner })).to.be.rejectedWith(
+ constants.REVERT,
+ );
});
-
});
});
});
diff --git a/packages/contracts/test/ts/token_transfer_proxy/auth.ts b/packages/contracts/test/ts/token_transfer_proxy/auth.ts
index 785fbc016..9ae0a8fc3 100644
--- a/packages/contracts/test/ts/token_transfer_proxy/auth.ts
+++ b/packages/contracts/test/ts/token_transfer_proxy/auth.ts
@@ -1,8 +1,8 @@
import * as chai from 'chai';
-import {constants} from '../../../util/constants';
-import {ContractInstance} from '../../../util/types';
-import {chaiSetup} from '../utils/chai_setup';
+import { constants } from '../../../util/constants';
+import { ContractInstance } from '../../../util/types';
+import { chaiSetup } from '../utils/chai_setup';
chaiSetup.configure();
const expect = chai.expect;
@@ -22,12 +22,15 @@ contract('TokenTransferProxy', (accounts: string[]) => {
describe('addAuthorizedAddress', () => {
it('should throw if not called by owner', async () => {
- return expect(tokenTransferProxy.addAuthorizedAddress(notOwner, {from: notOwner}))
- .to.be.rejectedWith(constants.INVALID_OPCODE);
+ return expect(tokenTransferProxy.addAuthorizedAddress(notOwner, { from: notOwner })).to.be.rejectedWith(
+ constants.REVERT,
+ );
});
it('should allow owner to add an authorized address', async () => {
- await tokenTransferProxy.addAuthorizedAddress(notAuthorized, {from: owner});
+ await tokenTransferProxy.addAuthorizedAddress(notAuthorized, {
+ from: owner,
+ });
authorized = notAuthorized;
notAuthorized = null;
const isAuthorized = await tokenTransferProxy.authorized.call(authorized);
@@ -35,19 +38,25 @@ contract('TokenTransferProxy', (accounts: string[]) => {
});
it('should throw if owner attempts to authorize a duplicate address', async () => {
- return expect(tokenTransferProxy.addAuthorizedAddress(authorized, {from: owner}))
- .to.be.rejectedWith(constants.INVALID_OPCODE);
+ return expect(tokenTransferProxy.addAuthorizedAddress(authorized, { from: owner })).to.be.rejectedWith(
+ constants.REVERT,
+ );
});
});
describe('removeAuthorizedAddress', () => {
it('should throw if not called by owner', async () => {
- return expect(tokenTransferProxy.removeAuthorizedAddress(authorized, {from: notOwner}))
- .to.be.rejectedWith(constants.INVALID_OPCODE);
+ return expect(
+ tokenTransferProxy.removeAuthorizedAddress(authorized, {
+ from: notOwner,
+ }),
+ ).to.be.rejectedWith(constants.REVERT);
});
it('should allow owner to remove an authorized address', async () => {
- await tokenTransferProxy.removeAuthorizedAddress(authorized, {from: owner});
+ await tokenTransferProxy.removeAuthorizedAddress(authorized, {
+ from: owner,
+ });
notAuthorized = authorized;
authorized = null;
@@ -56,8 +65,11 @@ contract('TokenTransferProxy', (accounts: string[]) => {
});
it('should throw if owner attempts to remove an address that is not authorized', async () => {
- return expect(tokenTransferProxy.removeAuthorizedAddress(notAuthorized, {from: owner}))
- .to.be.rejectedWith(constants.INVALID_OPCODE);
+ return expect(
+ tokenTransferProxy.removeAuthorizedAddress(notAuthorized, {
+ from: owner,
+ }),
+ ).to.be.rejectedWith(constants.REVERT);
});
});
@@ -65,7 +77,9 @@ contract('TokenTransferProxy', (accounts: string[]) => {
it('should return all authorized addresses', async () => {
const initial = await tokenTransferProxy.getAuthorizedAddresses();
expect(initial).to.have.length(1);
- await tokenTransferProxy.addAuthorizedAddress(notAuthorized, {from: owner});
+ await tokenTransferProxy.addAuthorizedAddress(notAuthorized, {
+ from: owner,
+ });
authorized = notAuthorized;
notAuthorized = null;
@@ -73,7 +87,9 @@ contract('TokenTransferProxy', (accounts: string[]) => {
expect(afterAdd).to.have.length(2);
expect(afterAdd).to.include(authorized);
- await tokenTransferProxy.removeAuthorizedAddress(authorized, {from: owner});
+ await tokenTransferProxy.removeAuthorizedAddress(authorized, {
+ from: owner,
+ });
notAuthorized = authorized;
authorized = null;
const afterRemove = await tokenTransferProxy.getAuthorizedAddresses();
diff --git a/packages/contracts/test/ts/token_transfer_proxy/transfer_from.ts b/packages/contracts/test/ts/token_transfer_proxy/transfer_from.ts
index 6e0bfdc1a..e1aff6dae 100644
--- a/packages/contracts/test/ts/token_transfer_proxy/transfer_from.ts
+++ b/packages/contracts/test/ts/token_transfer_proxy/transfer_from.ts
@@ -1,18 +1,14 @@
import * as chai from 'chai';
-import {Artifacts} from '../../../util/artifacts';
-import {Balances} from '../../../util/balances';
-import {constants} from '../../../util/constants';
-import {ContractInstance} from '../../../util/types';
-import {chaiSetup} from '../utils/chai_setup';
+import { Artifacts } from '../../../util/artifacts';
+import { Balances } from '../../../util/balances';
+import { constants } from '../../../util/constants';
+import { ContractInstance } from '../../../util/types';
+import { chaiSetup } from '../utils/chai_setup';
chaiSetup.configure();
const expect = chai.expect;
-const {
- TokenTransferProxy,
- DummyToken,
- TokenRegistry,
-} = new Artifacts(artifacts);
+const { TokenTransferProxy, DummyToken, TokenRegistry } = new Artifacts(artifacts);
contract('TokenTransferProxy', (accounts: string[]) => {
const INIT_BAL = 100000000;
@@ -36,32 +32,42 @@ contract('TokenTransferProxy', (accounts: string[]) => {
dmyBalances = new Balances([rep], [accounts[0], accounts[1]]);
await Promise.all([
- rep.approve(TokenTransferProxy.address, INIT_ALLOW, {from: accounts[0]}),
- rep.setBalance(accounts[0], INIT_BAL, {from: owner}),
- rep.approve(TokenTransferProxy.address, INIT_ALLOW, {from: accounts[1]}),
- rep.setBalance(accounts[1], INIT_BAL, {from: owner}),
+ rep.approve(TokenTransferProxy.address, INIT_ALLOW, {
+ from: accounts[0],
+ }),
+ rep.setBalance(accounts[0], INIT_BAL, { from: owner }),
+ rep.approve(TokenTransferProxy.address, INIT_ALLOW, {
+ from: accounts[1],
+ }),
+ rep.setBalance(accounts[1], INIT_BAL, { from: owner }),
]);
});
describe('transferFrom', () => {
it('should throw when called by an unauthorized address', async () => {
- expect(tokenTransferProxy.transferFrom(rep.address, accounts[0], accounts[1], 1000, {from: notAuthorized}))
- .to.be.rejectedWith(constants.INVALID_OPCODE);
+ expect(
+ tokenTransferProxy.transferFrom(rep.address, accounts[0], accounts[1], 1000, { from: notAuthorized }),
+ ).to.be.rejectedWith(constants.REVERT);
});
it('should allow an authorized address to transfer', async () => {
const balances = await dmyBalances.getAsync();
- await tokenTransferProxy.addAuthorizedAddress(notAuthorized, {from: owner});
+ await tokenTransferProxy.addAuthorizedAddress(notAuthorized, {
+ from: owner,
+ });
const transferAmt = 10000;
- await tokenTransferProxy.transferFrom(rep.address, accounts[0], accounts[1],
- transferAmt, {from: notAuthorized});
+ await tokenTransferProxy.transferFrom(rep.address, accounts[0], accounts[1], transferAmt, {
+ from: notAuthorized,
+ });
const newBalances = await dmyBalances.getAsync();
- expect(newBalances[accounts[0]][rep.address])
- .to.be.bignumber.equal(balances[accounts[0]][rep.address].minus(transferAmt));
- expect(newBalances[accounts[1]][rep.address])
- .to.be.bignumber.equal(balances[accounts[1]][rep.address].add(transferAmt));
+ expect(newBalances[accounts[0]][rep.address]).to.be.bignumber.equal(
+ balances[accounts[0]][rep.address].minus(transferAmt),
+ );
+ expect(newBalances[accounts[1]][rep.address]).to.be.bignumber.equal(
+ balances[accounts[1]][rep.address].add(transferAmt),
+ );
});
});
});
diff --git a/packages/contracts/test/ts/unlimitedAllowanceToken.ts b/packages/contracts/test/ts/unlimited_allowance_token.ts
index ca3fcd7d2..c90a52095 100644
--- a/packages/contracts/test/ts/unlimitedAllowanceToken.ts
+++ b/packages/contracts/test/ts/unlimited_allowance_token.ts
@@ -1,20 +1,24 @@
-import {ZeroEx} from '0x.js';
-import {BigNumber} from 'bignumber.js';
+import { ZeroEx } from '0x.js';
+import { BigNumber } from '@0xproject/utils';
import * as chai from 'chai';
import * as Web3 from 'web3';
-import {Artifacts} from '../../util/artifacts';
-import {ContractInstance} from '../../util/types';
+import { Artifacts } from '../../util/artifacts';
+import { constants } from '../../util/constants';
+import { ContractInstance } from '../../util/types';
-import {chaiSetup} from './utils/chai_setup';
+import { chaiSetup } from './utils/chai_setup';
-const {DummyToken} = new Artifacts(artifacts);
+const { DummyToken } = new Artifacts(artifacts);
const web3: Web3 = (global as any).web3;
chaiSetup.configure();
const expect = chai.expect;
contract('UnlimitedAllowanceToken', (accounts: string[]) => {
- const zeroEx = new ZeroEx(web3.currentProvider);
+ const config = {
+ networkId: constants.TESTRPC_NETWORK_ID,
+ };
+ const zeroEx = new ZeroEx(web3.currentProvider, config);
const owner = accounts[0];
const spender = accounts[1];
@@ -23,8 +27,8 @@ contract('UnlimitedAllowanceToken', (accounts: string[]) => {
let token: ContractInstance;
beforeEach(async () => {
- token = await DummyToken.new({from: owner});
- await token.mint(MAX_MINT_VALUE, {from: owner});
+ token = await DummyToken.new({ from: owner });
+ await token.mint(MAX_MINT_VALUE, { from: owner });
tokenAddress = token.address;
});
@@ -44,7 +48,9 @@ contract('UnlimitedAllowanceToken', (accounts: string[]) => {
});
it('should return true on a 0 value transfer', async () => {
- const didReturnTrue = await token.transfer.call(spender, 0, {from: owner});
+ const didReturnTrue = await token.transfer.call(spender, 0, {
+ from: owner,
+ });
expect(didReturnTrue).to.be.true();
});
});
@@ -54,7 +60,7 @@ contract('UnlimitedAllowanceToken', (accounts: string[]) => {
const ownerBalance = await zeroEx.token.getBalanceAsync(tokenAddress, owner);
const amountToTransfer = ownerBalance.plus(1);
await zeroEx.token.setAllowanceAsync(tokenAddress, owner, spender, amountToTransfer);
- const didReturnTrue = await token.transferFrom.call(owner, spender, amountToTransfer, {from: spender});
+ const didReturnTrue = await token.transferFrom.call(owner, spender, amountToTransfer, { from: spender });
expect(didReturnTrue).to.be.false();
});
@@ -66,13 +72,13 @@ contract('UnlimitedAllowanceToken', (accounts: string[]) => {
const spenderAllowanceIsInsufficient = spenderAllowance.cmp(amountToTransfer) < 0;
expect(spenderAllowanceIsInsufficient).to.be.true();
- const didReturnTrue = await token.transferFrom.call(owner, spender, amountToTransfer, {from: spender});
+ const didReturnTrue = await token.transferFrom.call(owner, spender, amountToTransfer, { from: spender });
expect(didReturnTrue).to.be.false();
});
it('should return true on a 0 value transfer', async () => {
const amountToTransfer = 0;
- const didReturnTrue = await token.transferFrom.call(owner, spender, amountToTransfer, {from: spender});
+ const didReturnTrue = await token.transferFrom.call(owner, spender, amountToTransfer, { from: spender });
expect(didReturnTrue).to.be.true();
});
@@ -81,7 +87,9 @@ contract('UnlimitedAllowanceToken', (accounts: string[]) => {
const amountToTransfer = initOwnerBalance;
const initSpenderAllowance = zeroEx.token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS;
await zeroEx.token.setAllowanceAsync(tokenAddress, owner, spender, initSpenderAllowance);
- await zeroEx.token.transferFromAsync(tokenAddress, owner, spender, spender, amountToTransfer);
+ await zeroEx.token.transferFromAsync(tokenAddress, owner, spender, spender, amountToTransfer, {
+ gasLimit: constants.MAX_TOKEN_TRANSFERFROM_GAS,
+ });
const newSpenderAllowance = await zeroEx.token.getAllowanceAsync(tokenAddress, owner, spender);
expect(initSpenderAllowance).to.be.bignumber.equal(newSpenderAllowance);
@@ -92,7 +100,9 @@ contract('UnlimitedAllowanceToken', (accounts: string[]) => {
const amountToTransfer = initOwnerBalance;
const initSpenderAllowance = initOwnerBalance;
await zeroEx.token.setAllowanceAsync(tokenAddress, owner, spender, initSpenderAllowance);
- await zeroEx.token.transferFromAsync(tokenAddress, owner, spender, spender, amountToTransfer);
+ await zeroEx.token.transferFromAsync(tokenAddress, owner, spender, spender, amountToTransfer, {
+ gasLimit: constants.MAX_TOKEN_TRANSFERFROM_GAS,
+ });
const newOwnerBalance = await zeroEx.token.getBalanceAsync(tokenAddress, owner);
const newSpenderBalance = await zeroEx.token.getBalanceAsync(tokenAddress, spender);
@@ -106,7 +116,9 @@ contract('UnlimitedAllowanceToken', (accounts: string[]) => {
const amountToTransfer = initOwnerBalance;
const initSpenderAllowance = initOwnerBalance;
await zeroEx.token.setAllowanceAsync(tokenAddress, owner, spender, initSpenderAllowance);
- await zeroEx.token.transferFromAsync(tokenAddress, owner, spender, spender, amountToTransfer);
+ await zeroEx.token.transferFromAsync(tokenAddress, owner, spender, spender, amountToTransfer, {
+ gasLimit: constants.MAX_TOKEN_TRANSFERFROM_GAS,
+ });
const newSpenderAllowance = await zeroEx.token.getAllowanceAsync(tokenAddress, owner, spender);
expect(newSpenderAllowance).to.be.bignumber.equal(0);
diff --git a/packages/contracts/test/ts/unlimited_allowance_token_v2.ts b/packages/contracts/test/ts/unlimited_allowance_token_v2.ts
new file mode 100644
index 000000000..1b29a02ba
--- /dev/null
+++ b/packages/contracts/test/ts/unlimited_allowance_token_v2.ts
@@ -0,0 +1,141 @@
+import { ZeroEx } from '0x.js';
+import { BigNumber } from '@0xproject/utils';
+import * as chai from 'chai';
+import * as Web3 from 'web3';
+
+import { Artifacts } from '../../util/artifacts';
+import { constants } from '../../util/constants';
+import { ContractInstance } from '../../util/types';
+
+import { chaiSetup } from './utils/chai_setup';
+
+const { DummyTokenV2 } = new Artifacts(artifacts);
+const web3: Web3 = (global as any).web3;
+chaiSetup.configure();
+const expect = chai.expect;
+
+contract('UnlimitedAllowanceTokenV2', (accounts: string[]) => {
+ const config = {
+ networkId: constants.TESTRPC_NETWORK_ID,
+ };
+ const zeroEx = new ZeroEx(web3.currentProvider, config);
+ const owner = accounts[0];
+ const spender = accounts[1];
+
+ const MAX_MINT_VALUE = new BigNumber(100000000000000000000);
+ let tokenAddress: string;
+ let token: ContractInstance;
+
+ beforeEach(async () => {
+ token = await DummyTokenV2.new({ from: owner });
+ await token.mint(MAX_MINT_VALUE, { from: owner });
+ tokenAddress = token.address;
+ });
+
+ describe('transfer', () => {
+ it('should throw if owner has insufficient balance', async () => {
+ const ownerBalance = await zeroEx.token.getBalanceAsync(tokenAddress, owner);
+ const amountToTransfer = ownerBalance.plus(1);
+ return expect(token.transfer.call(spender, amountToTransfer, { from: owner })).to.be.rejectedWith(
+ constants.REVERT,
+ );
+ });
+
+ it('should transfer balance from sender to receiver', async () => {
+ const receiver = spender;
+ const initOwnerBalance = await zeroEx.token.getBalanceAsync(tokenAddress, owner);
+ const amountToTransfer = new BigNumber(1);
+ await zeroEx.token.transferAsync(tokenAddress, owner, receiver, amountToTransfer);
+ const finalOwnerBalance = await zeroEx.token.getBalanceAsync(tokenAddress, owner);
+ const finalReceiverBalance = await zeroEx.token.getBalanceAsync(tokenAddress, receiver);
+
+ const expectedFinalOwnerBalance = initOwnerBalance.minus(amountToTransfer);
+ const expectedFinalReceiverBalance = amountToTransfer;
+ expect(finalOwnerBalance).to.be.bignumber.equal(expectedFinalOwnerBalance);
+ expect(finalReceiverBalance).to.be.bignumber.equal(expectedFinalReceiverBalance);
+ });
+
+ it('should return true on a 0 value transfer', async () => {
+ const didReturnTrue = await token.transfer.call(spender, 0, {
+ from: owner,
+ });
+ expect(didReturnTrue).to.be.true();
+ });
+ });
+
+ describe('transferFrom', () => {
+ it('should throw if owner has insufficient balance', async () => {
+ const ownerBalance = await zeroEx.token.getBalanceAsync(tokenAddress, owner);
+ const amountToTransfer = ownerBalance.plus(1);
+ await zeroEx.token.setAllowanceAsync(tokenAddress, owner, spender, amountToTransfer);
+ return expect(
+ token.transferFrom.call(owner, spender, amountToTransfer, {
+ from: spender,
+ }),
+ ).to.be.rejectedWith(constants.REVERT);
+ });
+
+ it('should throw if spender has insufficient allowance', async () => {
+ const ownerBalance = await zeroEx.token.getBalanceAsync(tokenAddress, owner);
+ const amountToTransfer = ownerBalance;
+
+ const spenderAllowance = await zeroEx.token.getAllowanceAsync(tokenAddress, owner, spender);
+ const spenderAllowanceIsInsufficient = spenderAllowance.cmp(amountToTransfer) < 0;
+ expect(spenderAllowanceIsInsufficient).to.be.true();
+
+ return expect(
+ token.transferFrom.call(owner, spender, amountToTransfer, {
+ from: spender,
+ }),
+ ).to.be.rejectedWith(constants.REVERT);
+ });
+
+ it('should return true on a 0 value transfer', async () => {
+ const amountToTransfer = 0;
+ const didReturnTrue = await token.transferFrom.call(owner, spender, amountToTransfer, { from: spender });
+ expect(didReturnTrue).to.be.true();
+ });
+
+ it('should not modify spender allowance if spender allowance is 2^256 - 1', async () => {
+ const initOwnerBalance = await zeroEx.token.getBalanceAsync(tokenAddress, owner);
+ const amountToTransfer = initOwnerBalance;
+ const initSpenderAllowance = zeroEx.token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS;
+ await zeroEx.token.setAllowanceAsync(tokenAddress, owner, spender, initSpenderAllowance);
+ await zeroEx.token.transferFromAsync(tokenAddress, owner, spender, spender, amountToTransfer, {
+ gasLimit: constants.MAX_TOKEN_TRANSFERFROM_GAS,
+ });
+
+ const newSpenderAllowance = await zeroEx.token.getAllowanceAsync(tokenAddress, owner, spender);
+ expect(initSpenderAllowance).to.be.bignumber.equal(newSpenderAllowance);
+ });
+
+ it('should transfer the correct balances if spender has sufficient allowance', async () => {
+ const initOwnerBalance = await zeroEx.token.getBalanceAsync(tokenAddress, owner);
+ const amountToTransfer = initOwnerBalance;
+ const initSpenderAllowance = initOwnerBalance;
+ await zeroEx.token.setAllowanceAsync(tokenAddress, owner, spender, initSpenderAllowance);
+ await zeroEx.token.transferFromAsync(tokenAddress, owner, spender, spender, amountToTransfer, {
+ gasLimit: constants.MAX_TOKEN_TRANSFERFROM_GAS,
+ });
+
+ const newOwnerBalance = await zeroEx.token.getBalanceAsync(tokenAddress, owner);
+ const newSpenderBalance = await zeroEx.token.getBalanceAsync(tokenAddress, spender);
+
+ expect(newOwnerBalance).to.be.bignumber.equal(0);
+ expect(newSpenderBalance).to.be.bignumber.equal(initOwnerBalance);
+ });
+
+ it('should modify allowance if spender has sufficient allowance less than 2^256 - 1', async () => {
+ const initOwnerBalance = await zeroEx.token.getBalanceAsync(tokenAddress, owner);
+ const amountToTransfer = initOwnerBalance;
+ const initSpenderAllowance = initOwnerBalance;
+ await zeroEx.token.setAllowanceAsync(tokenAddress, owner, spender, initSpenderAllowance);
+ await zeroEx.token.transferFromAsync(tokenAddress, owner, spender, spender, amountToTransfer, {
+ gasLimit: constants.MAX_TOKEN_TRANSFERFROM_GAS,
+ });
+
+ const newSpenderAllowance = await zeroEx.token.getAllowanceAsync(tokenAddress, owner, spender);
+ expect(newSpenderAllowance).to.be.bignumber.equal(0);
+ });
+ });
+});
diff --git a/packages/contracts/test/ts/zrxToken.ts b/packages/contracts/test/ts/zrx_token.ts
index 471ee93f2..766c94c2a 100644
--- a/packages/contracts/test/ts/zrxToken.ts
+++ b/packages/contracts/test/ts/zrx_token.ts
@@ -1,16 +1,17 @@
-import {ZeroEx} from '0x.js';
-import {BigNumber} from 'bignumber.js';
+import { ZeroEx } from '0x.js';
+import { BigNumber } from '@0xproject/utils';
import * as chai from 'chai';
import Web3 = require('web3');
-import {Artifacts} from '../../util/artifacts';
-import {ContractInstance} from '../../util/types';
+import { Artifacts } from '../../util/artifacts';
+import { constants } from '../../util/constants';
+import { ContractInstance } from '../../util/types';
-import {chaiSetup} from './utils/chai_setup';
+import { chaiSetup } from './utils/chai_setup';
chaiSetup.configure();
const expect = chai.expect;
-const {Exchange, ZRXToken} = new Artifacts(artifacts);
+const { Exchange, ZRXToken } = new Artifacts(artifacts);
const web3: Web3 = (global as any).web3;
contract('ZRXToken', (accounts: string[]) => {
@@ -25,10 +26,11 @@ contract('ZRXToken', (accounts: string[]) => {
beforeEach(async () => {
zeroEx = new ZeroEx(web3.currentProvider, {
- exchangeContractAddress: Exchange.address,
+ exchangeContractAddress: Exchange.address,
+ networkId: constants.TESTRPC_NETWORK_ID,
});
- zrxAddress = await zeroEx.exchange.getZRXTokenAddressAsync();
- zrx = await ZRXToken.at(zrxAddress);
+ zrx = await ZRXToken.new();
+ zrxAddress = zrx.address;
MAX_UINT = zeroEx.token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS;
});
@@ -83,7 +85,9 @@ contract('ZRXToken', (accounts: string[]) => {
});
it('should return true on a 0 value transfer', async () => {
- const didReturnTrue = await zrx.transfer.call(spender, 0, {from: owner});
+ const didReturnTrue = await zrx.transfer.call(spender, 0, {
+ from: owner,
+ });
expect(didReturnTrue).to.be.true();
});
});
@@ -92,13 +96,12 @@ contract('ZRXToken', (accounts: string[]) => {
it('should return false if owner has insufficient balance', async () => {
const ownerBalance = await zeroEx.token.getBalanceAsync(zrxAddress, owner);
const amountToTransfer = ownerBalance.plus(1);
- let txHash = await zeroEx.token.setAllowanceAsync(zrxAddress, owner, spender, amountToTransfer);
+ const txHash = await zeroEx.token.setAllowanceAsync(zrxAddress, owner, spender, amountToTransfer, {
+ gasLimit: constants.MAX_TOKEN_APPROVE_GAS,
+ });
await zeroEx.awaitTransactionMinedAsync(txHash);
- const didReturnTrue = await zrx.transferFrom.call(owner, spender, amountToTransfer, {from: spender});
+ const didReturnTrue = await zrx.transferFrom.call(owner, spender, amountToTransfer, { from: spender });
expect(didReturnTrue).to.be.false();
- // Reset allowance
- txHash = await zeroEx.token.setAllowanceAsync(zrxAddress, owner, spender, new BigNumber(0));
- await zeroEx.awaitTransactionMinedAsync(txHash);
});
it('should return false if spender has insufficient allowance', async () => {
@@ -109,13 +112,13 @@ contract('ZRXToken', (accounts: string[]) => {
const spenderAllowanceIsInsufficient = spenderAllowance.cmp(amountToTransfer) < 0;
expect(spenderAllowanceIsInsufficient).to.be.true();
- const didReturnTrue = await zrx.transferFrom.call(owner, spender, amountToTransfer, {from: spender});
+ const didReturnTrue = await zrx.transferFrom.call(owner, spender, amountToTransfer, { from: spender });
expect(didReturnTrue).to.be.false();
});
it('should return true on a 0 value transfer', async () => {
const amountToTransfer = 0;
- const didReturnTrue = await zrx.transferFrom.call(owner, spender, amountToTransfer, {from: spender});
+ const didReturnTrue = await zrx.transferFrom.call(owner, spender, amountToTransfer, { from: spender });
expect(didReturnTrue).to.be.true();
});
@@ -123,16 +126,17 @@ contract('ZRXToken', (accounts: string[]) => {
const initOwnerBalance = await zeroEx.token.getBalanceAsync(zrxAddress, owner);
const amountToTransfer = initOwnerBalance;
const initSpenderAllowance = MAX_UINT;
- let txHash = await zeroEx.token.setAllowanceAsync(zrxAddress, owner, spender, initSpenderAllowance);
+ let txHash = await zeroEx.token.setAllowanceAsync(zrxAddress, owner, spender, initSpenderAllowance, {
+ gasLimit: constants.MAX_TOKEN_APPROVE_GAS,
+ });
await zeroEx.awaitTransactionMinedAsync(txHash);
- txHash = await zeroEx.token.transferFromAsync(zrxAddress, owner, spender, spender, amountToTransfer);
+ txHash = await zeroEx.token.transferFromAsync(zrxAddress, owner, spender, spender, amountToTransfer, {
+ gasLimit: constants.MAX_TOKEN_TRANSFERFROM_GAS,
+ });
await zeroEx.awaitTransactionMinedAsync(txHash);
const newSpenderAllowance = await zeroEx.token.getAllowanceAsync(zrxAddress, owner, spender);
expect(initSpenderAllowance).to.be.bignumber.equal(newSpenderAllowance);
- // Restore balance
- txHash = await zeroEx.token.transferAsync(zrxAddress, spender, owner, amountToTransfer);
- await zeroEx.awaitTransactionMinedAsync(txHash);
});
it('should transfer the correct balances if spender has sufficient allowance', async () => {
@@ -142,7 +146,9 @@ contract('ZRXToken', (accounts: string[]) => {
const initSpenderAllowance = initOwnerBalance;
let txHash = await zeroEx.token.setAllowanceAsync(zrxAddress, owner, spender, initSpenderAllowance);
await zeroEx.awaitTransactionMinedAsync(txHash);
- txHash = await zeroEx.token.transferFromAsync(zrxAddress, owner, spender, spender, amountToTransfer);
+ txHash = await zeroEx.token.transferFromAsync(zrxAddress, owner, spender, spender, amountToTransfer, {
+ gasLimit: constants.MAX_TOKEN_TRANSFERFROM_GAS,
+ });
await zeroEx.awaitTransactionMinedAsync(txHash);
const newOwnerBalance = await zeroEx.token.getBalanceAsync(zrxAddress, owner);
@@ -155,10 +161,11 @@ contract('ZRXToken', (accounts: string[]) => {
it('should modify allowance if spender has sufficient allowance less than 2^256 - 1', async () => {
const initOwnerBalance = await zeroEx.token.getBalanceAsync(zrxAddress, owner);
const amountToTransfer = initOwnerBalance;
- const initSpenderAllowance = initOwnerBalance;
- let txHash = await zeroEx.token.setAllowanceAsync(zrxAddress, owner, spender, initSpenderAllowance);
+ let txHash = await zeroEx.token.setAllowanceAsync(zrxAddress, owner, spender, amountToTransfer);
await zeroEx.awaitTransactionMinedAsync(txHash);
- txHash = await zeroEx.token.transferFromAsync(zrxAddress, owner, spender, spender, amountToTransfer);
+ txHash = await zeroEx.token.transferFromAsync(zrxAddress, owner, spender, spender, amountToTransfer, {
+ gasLimit: constants.MAX_TOKEN_TRANSFERFROM_GAS,
+ });
await zeroEx.awaitTransactionMinedAsync(txHash);
const newSpenderAllowance = await zeroEx.token.getAllowanceAsync(zrxAddress, owner, spender);