aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/test
diff options
context:
space:
mode:
Diffstat (limited to 'packages/contracts/test')
-rw-r--r--packages/contracts/test/ether_token.ts (renamed from packages/contracts/test/ts/ether_token.ts)60
-rw-r--r--packages/contracts/test/exchange/core.ts (renamed from packages/contracts/test/ts/exchange/core.ts)217
-rw-r--r--packages/contracts/test/exchange/helpers.ts (renamed from packages/contracts/test/ts/exchange/helpers.ts)54
-rw-r--r--packages/contracts/test/exchange/wrapper.ts (renamed from packages/contracts/test/ts/exchange/wrapper.ts)95
-rw-r--r--packages/contracts/test/multi_sig_with_time_lock.ts191
-rw-r--r--packages/contracts/test/multi_sig_with_time_lock_except_remove_auth_addr.ts181
-rw-r--r--packages/contracts/test/token_registry.ts (renamed from packages/contracts/test/ts/token_registry.ts)55
-rw-r--r--packages/contracts/test/token_transfer_proxy/auth.ts (renamed from packages/contracts/test/ts/token_transfer_proxy/auth.ts)80
-rw-r--r--packages/contracts/test/token_transfer_proxy/transfer_from.ts (renamed from packages/contracts/test/ts/token_transfer_proxy/transfer_from.ts)48
-rw-r--r--packages/contracts/test/ts/multi_sig_with_time_lock.ts115
-rw-r--r--packages/contracts/test/ts/multi_sig_with_time_lock_except_remove_auth_addr.ts150
-rw-r--r--packages/contracts/test/ts/unlimited_allowance_token.ts127
-rw-r--r--packages/contracts/test/unlimited_allowance_token.ts (renamed from packages/contracts/test/ts/unlimited_allowance_token_v2.ts)35
-rw-r--r--packages/contracts/test/utils/chai_setup.ts (renamed from packages/contracts/test/ts/utils/chai_setup.ts)0
-rw-r--r--packages/contracts/test/utils/deployer.ts16
-rw-r--r--packages/contracts/test/zrx_token.ts (renamed from packages/contracts/test/ts/zrx_token.ts)72
16 files changed, 779 insertions, 717 deletions
diff --git a/packages/contracts/test/ts/ether_token.ts b/packages/contracts/test/ether_token.ts
index f807cdaa3..4c70534ee 100644
--- a/packages/contracts/test/ts/ether_token.ts
+++ b/packages/contracts/test/ether_token.ts
@@ -1,46 +1,46 @@
import { ZeroEx, ZeroExError } from '0x.js';
+import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils';
import { BigNumber, promisify } from '@0xproject/utils';
+import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as chai from 'chai';
-import Web3 = require('web3');
-import { Artifacts } from '../../util/artifacts';
-import { constants } from '../../util/constants';
+import { constants } from '../util/constants';
+import { ContractName } from '../util/types';
import { chaiSetup } from './utils/chai_setup';
-
-const { EtherToken } = new Artifacts(artifacts);
+import { deployer } from './utils/deployer';
chaiSetup.configure();
const expect = chai.expect;
+const web3 = web3Factory.create();
+const web3Wrapper = new Web3Wrapper(web3.currentProvider);
+const blockchainLifecycle = new BlockchainLifecycle();
-// 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`.
-const web3: Web3 = (global as any).web3;
-
-contract('EtherToken', (accounts: string[]) => {
- const account = accounts[0];
+describe('EtherToken', () => {
+ let account: string;
const gasPrice = ZeroEx.toBaseUnitAmount(new BigNumber(20), 9);
let zeroEx: ZeroEx;
let etherTokenAddress: string;
-
before(async () => {
- etherTokenAddress = EtherToken.address;
+ const accounts = await web3Wrapper.getAvailableAddressesAsync();
+ account = accounts[0];
+
+ const etherToken = await deployer.deployAsync(ContractName.EtherToken);
+ etherTokenAddress = etherToken.address;
zeroEx = new ZeroEx(web3.currentProvider, {
gasPrice,
networkId: constants.TESTRPC_NETWORK_ID,
});
});
-
- const sendTransactionAsync = promisify<string>(web3.eth.sendTransaction);
- const getEthBalanceAsync = async (owner: string) => {
- const balanceStr = await promisify<string>(web3.eth.getBalance)(owner);
- const balance = new BigNumber(balanceStr);
- return balance;
- };
-
+ beforeEach(async () => {
+ await blockchainLifecycle.startAsync();
+ });
+ afterEach(async () => {
+ await blockchainLifecycle.revertAsync();
+ });
describe('deposit', () => {
it('should throw if caller attempts to deposit more Ether than caller balance', async () => {
- const initEthBalance = await getEthBalanceAsync(account);
+ const initEthBalance = await web3Wrapper.getBalanceInWeiAsync(account);
const ethToDeposit = initEthBalance.plus(1);
return expect(zeroEx.etherToken.depositAsync(etherTokenAddress, ethToDeposit, account)).to.be.rejectedWith(
@@ -49,7 +49,7 @@ contract('EtherToken', (accounts: string[]) => {
});
it('should convert deposited Ether to wrapped Ether tokens', async () => {
- const initEthBalance = await getEthBalanceAsync(account);
+ const initEthBalance = await web3Wrapper.getBalanceInWeiAsync(account);
const initEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account);
const ethToDeposit = new BigNumber(web3.toWei(1, 'ether'));
@@ -58,7 +58,7 @@ contract('EtherToken', (accounts: string[]) => {
const receipt = await zeroEx.awaitTransactionMinedAsync(txHash);
const ethSpentOnGas = gasPrice.times(receipt.gasUsed);
- const finalEthBalance = await getEthBalanceAsync(account);
+ const finalEthBalance = await web3Wrapper.getBalanceInWeiAsync(account);
const finalEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account);
expect(finalEthBalance).to.be.bignumber.equal(initEthBalance.minus(ethToDeposit.plus(ethSpentOnGas)));
@@ -77,8 +77,10 @@ contract('EtherToken', (accounts: string[]) => {
});
it('should convert ether tokens to ether with sufficient balance', async () => {
+ const ethToDeposit = new BigNumber(web3.toWei(1, 'ether'));
+ await zeroEx.etherToken.depositAsync(etherTokenAddress, ethToDeposit, account);
const initEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account);
- const initEthBalance = await getEthBalanceAsync(account);
+ const initEthBalance = await web3Wrapper.getBalanceInWeiAsync(account);
const ethTokensToWithdraw = initEthTokenBalance;
expect(ethTokensToWithdraw).to.not.be.bignumber.equal(0);
const txHash = await zeroEx.etherToken.withdrawAsync(etherTokenAddress, ethTokensToWithdraw, account, {
@@ -87,7 +89,7 @@ contract('EtherToken', (accounts: string[]) => {
const receipt = await zeroEx.awaitTransactionMinedAsync(txHash);
const ethSpentOnGas = gasPrice.times(receipt.gasUsed);
- const finalEthBalance = await getEthBalanceAsync(account);
+ const finalEthBalance = await web3Wrapper.getBalanceInWeiAsync(account);
const finalEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account);
expect(finalEthBalance).to.be.bignumber.equal(
@@ -99,12 +101,12 @@ contract('EtherToken', (accounts: string[]) => {
describe('fallback', () => {
it('should convert sent ether to ether tokens', async () => {
- const initEthBalance = await getEthBalanceAsync(account);
+ const initEthBalance = await web3Wrapper.getBalanceInWeiAsync(account);
const initEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account);
const ethToDeposit = ZeroEx.toBaseUnitAmount(new BigNumber(1), 18);
- const txHash = await sendTransactionAsync({
+ const txHash = await web3Wrapper.sendTransactionAsync({
from: account,
to: etherTokenAddress,
value: ethToDeposit,
@@ -114,7 +116,7 @@ contract('EtherToken', (accounts: string[]) => {
const receipt = await zeroEx.awaitTransactionMinedAsync(txHash);
const ethSpentOnGas = gasPrice.times(receipt.gasUsed);
- const finalEthBalance = await getEthBalanceAsync(account);
+ const finalEthBalance = await web3Wrapper.getBalanceInWeiAsync(account);
const finalEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account);
expect(finalEthBalance).to.be.bignumber.equal(initEthBalance.minus(ethToDeposit.plus(ethSpentOnGas)));
diff --git a/packages/contracts/test/ts/exchange/core.ts b/packages/contracts/test/exchange/core.ts
index 770ef0c43..10816d2d6 100644
--- a/packages/contracts/test/ts/exchange/core.ts
+++ b/packages/contracts/test/exchange/core.ts
@@ -1,41 +1,47 @@
-import { ZeroEx } from '0x.js';
+import {
+ LogCancelContractEventArgs,
+ LogErrorContractEventArgs,
+ LogFillContractEventArgs,
+ LogWithDecodedArgs,
+ TransactionReceiptWithDecodedLogs,
+ ZeroEx,
+} from '0x.js';
+import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils';
import { BigNumber } from '@0xproject/utils';
+import { Web3Wrapper } from '@0xproject/web3-wrapper';
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 { Balances } from '../../util/balances';
+import { constants } from '../../util/constants';
+import { crypto } from '../../util/crypto';
+import { ExchangeWrapper } from '../../util/exchange_wrapper';
+import { Order } from '../../util/order';
+import { OrderFactory } from '../../util/order_factory';
+import { BalancesByOwner, ContractName, ExchangeContractErrs } from '../../util/types';
import { chaiSetup } from '../utils/chai_setup';
+import { deployer } from '../utils/deployer';
chaiSetup.configure();
const expect = chai.expect;
-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`.
-const web3: Web3 = (global as any).web3;
-
-contract('Exchange', (accounts: string[]) => {
- const maker = accounts[0];
- const tokenOwner = accounts[0];
- const taker = accounts[1] || accounts[accounts.length - 1];
- const feeRecipient = accounts[2] || accounts[accounts.length - 1];
-
+const web3 = web3Factory.create();
+const web3Wrapper = new Web3Wrapper(web3.currentProvider);
+const blockchainLifecycle = new BlockchainLifecycle();
+
+describe('Exchange', () => {
+ let maker: string;
+ let tokenOwner: string;
+ let taker: string;
+ let feeRecipient: string;
const INITIAL_BALANCE = ZeroEx.toBaseUnitAmount(new BigNumber(10000), 18);
const INITIAL_ALLOWANCE = ZeroEx.toBaseUnitAmount(new BigNumber(10000), 18);
- let rep: ContractInstance;
- let dgd: ContractInstance;
- let zrx: ContractInstance;
- let exchange: ContractInstance;
- let tokenRegistry: ContractInstance;
+ let rep: Web3.ContractInstance;
+ let dgd: Web3.ContractInstance;
+ let zrx: Web3.ContractInstance;
+ let exchange: Web3.ContractInstance;
+ let tokenTransferProxy: Web3.ContractInstance;
let order: Order;
let balances: BalancesByOwner;
@@ -46,66 +52,69 @@ contract('Exchange', (accounts: string[]) => {
let zeroEx: ZeroEx;
before(async () => {
- [tokenRegistry, exchange] = await Promise.all([TokenRegistry.deployed(), Exchange.deployed()]);
- exWrapper = new ExchangeWrapper(exchange);
+ const accounts = await web3Wrapper.getAvailableAddressesAsync();
+ maker = accounts[0];
+ [tokenOwner, taker, feeRecipient] = accounts;
+ [rep, dgd, zrx] = await Promise.all([
+ deployer.deployAsync(ContractName.DummyToken),
+ deployer.deployAsync(ContractName.DummyToken),
+ deployer.deployAsync(ContractName.DummyToken),
+ ]);
+ tokenTransferProxy = await deployer.deployAsync(ContractName.TokenTransferProxy);
+ exchange = await deployer.deployAsync(ContractName.Exchange, [zrx.address, tokenTransferProxy.address]);
+ await tokenTransferProxy.addAuthorizedAddress(exchange.address, { from: accounts[0] });
zeroEx = new ZeroEx(web3.currentProvider, {
exchangeContractAddress: exchange.address,
networkId: constants.TESTRPC_NETWORK_ID,
});
-
- const [repAddress, dgdAddress, zrxAddress] = await Promise.all([
- tokenRegistry.getTokenAddressBySymbol('REP'),
- tokenRegistry.getTokenAddressBySymbol('DGD'),
- tokenRegistry.getTokenAddressBySymbol('ZRX'),
- ]);
+ exWrapper = new ExchangeWrapper(exchange, zeroEx);
const defaultOrderParams = {
- exchangeContractAddress: Exchange.address,
+ exchangeContractAddress: exchange.address,
maker,
feeRecipient,
- makerToken: repAddress,
- takerToken: dgdAddress,
+ makerToken: rep.address,
+ takerToken: dgd.address,
makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18),
takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18),
makerFee: ZeroEx.toBaseUnitAmount(new BigNumber(1), 18),
takerFee: ZeroEx.toBaseUnitAmount(new BigNumber(1), 18),
};
- orderFactory = new OrderFactory(defaultOrderParams);
-
- [rep, dgd, zrx] = await Promise.all([
- DummyToken.at(repAddress),
- DummyToken.at(dgdAddress),
- DummyToken.at(zrxAddress),
- ]);
+ orderFactory = new OrderFactory(web3Wrapper, defaultOrderParams);
dmyBalances = new Balances([rep, dgd, zrx], [maker, taker, feeRecipient]);
await Promise.all([
- rep.approve(TokenTransferProxy.address, INITIAL_ALLOWANCE, {
+ rep.approve(tokenTransferProxy.address, INITIAL_ALLOWANCE, {
from: maker,
}),
- rep.approve(TokenTransferProxy.address, INITIAL_ALLOWANCE, {
+ 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, {
+ dgd.approve(tokenTransferProxy.address, INITIAL_ALLOWANCE, {
from: maker,
}),
- dgd.approve(TokenTransferProxy.address, INITIAL_ALLOWANCE, {
+ 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, {
+ zrx.approve(tokenTransferProxy.address, INITIAL_ALLOWANCE, {
from: maker,
}),
- zrx.approve(TokenTransferProxy.address, INITIAL_ALLOWANCE, {
+ zrx.approve(tokenTransferProxy.address, INITIAL_ALLOWANCE, {
from: taker,
}),
zrx.setBalance(maker, INITIAL_BALANCE, { from: tokenOwner }),
zrx.setBalance(taker, INITIAL_BALANCE, { from: tokenOwner }),
]);
});
-
+ beforeEach(async () => {
+ await blockchainLifecycle.startAsync();
+ });
+ afterEach(async () => {
+ await blockchainLifecycle.revertAsync();
+ });
describe('internal functions', () => {
it('should include transferViaTokenTransferProxy', () => {
expect(exchange.transferViaTokenTransferProxy).to.be.undefined();
@@ -136,9 +145,8 @@ 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 as string);
expect(filledTakerTokenAmountBefore).to.be.bignumber.equal(0);
const fillTakerTokenAmount1 = new BigNumber(2);
@@ -146,9 +154,8 @@ contract('Exchange', (accounts: string[]) => {
fillTakerTokenAmount: fillTakerTokenAmount1,
});
- const filledTakerTokenAmountAfter1 = await zeroEx.exchange.getFilledTakerAmountAsync(
- order.params.orderHashHex,
- );
+ const filledTakerTokenAmountAfter1 = await zeroEx.exchange.getFilledTakerAmountAsync(order.params
+ .orderHashHex as string);
expect(filledTakerTokenAmountAfter1).to.be.bignumber.equal(fillTakerTokenAmount1);
const fillTakerTokenAmount2 = new BigNumber(1);
@@ -156,9 +163,8 @@ contract('Exchange', (accounts: string[]) => {
fillTakerTokenAmount: fillTakerTokenAmount2,
});
- const filledTakerTokenAmountAfter2 = await zeroEx.exchange.getFilledTakerAmountAsync(
- order.params.orderHashHex,
- );
+ const filledTakerTokenAmountAfter2 = await zeroEx.exchange.getFilledTakerAmountAsync(order.params
+ .orderHashHex as string);
expect(filledTakerTokenAmountAfter2).to.be.bignumber.equal(filledTakerTokenAmountAfter1);
});
@@ -168,17 +174,15 @@ 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 as string);
expect(filledTakerTokenAmountBefore).to.be.bignumber.equal(0);
const fillTakerTokenAmount = order.params.takerTokenAmount.div(2);
await exWrapper.fillOrderAsync(order, taker, { fillTakerTokenAmount });
- const filledTakerTokenAmountAfter = await zeroEx.exchange.getFilledTakerAmountAsync(
- order.params.orderHashHex,
- );
+ const filledTakerTokenAmountAfter = await zeroEx.exchange.getFilledTakerAmountAsync(order.params
+ .orderHashHex as string);
expect(filledTakerTokenAmountAfter).to.be.bignumber.equal(fillTakerTokenAmount);
const newBalances = await dmyBalances.getAsync();
@@ -221,17 +225,15 @@ 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 as string);
expect(filledTakerTokenAmountBefore).to.be.bignumber.equal(0);
const fillTakerTokenAmount = order.params.takerTokenAmount.div(2);
await exWrapper.fillOrderAsync(order, taker, { fillTakerTokenAmount });
- const filledTakerTokenAmountAfter = await zeroEx.exchange.getFilledTakerAmountAsync(
- order.params.orderHashHex,
- );
+ const filledTakerTokenAmountAfter = await zeroEx.exchange.getFilledTakerAmountAsync(order.params
+ .orderHashHex as string);
expect(filledTakerTokenAmountAfter).to.be.bignumber.equal(fillTakerTokenAmount);
const newBalances = await dmyBalances.getAsync();
@@ -274,17 +276,15 @@ 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 as string);
expect(filledTakerTokenAmountBefore).to.be.bignumber.equal(0);
const fillTakerTokenAmount = order.params.takerTokenAmount.div(2);
await exWrapper.fillOrderAsync(order, taker, { fillTakerTokenAmount });
- const filledTakerTokenAmountAfter = await zeroEx.exchange.getFilledTakerAmountAsync(
- order.params.orderHashHex,
- );
+ const filledTakerTokenAmountAfter = await zeroEx.exchange.getFilledTakerAmountAsync(order.params
+ .orderHashHex as string);
expect(filledTakerTokenAmountAfter).to.be.bignumber.equal(fillTakerTokenAmount);
const newBalances = await dmyBalances.getAsync();
@@ -328,17 +328,15 @@ 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 as string);
expect(filledTakerTokenAmountBefore).to.be.bignumber.equal(0);
const fillTakerTokenAmount = order.params.takerTokenAmount.div(2);
await exWrapper.fillOrderAsync(order, taker, { fillTakerTokenAmount });
- const filledTakerTokenAmountAfter = await zeroEx.exchange.getFilledTakerAmountAsync(
- order.params.orderHashHex,
- );
+ const filledTakerTokenAmountAfter = await zeroEx.exchange.getFilledTakerAmountAsync(order.params
+ .orderHashHex as string);
const expectedFillAmountTAfter = fillTakerTokenAmount.add(filledTakerTokenAmountBefore);
expect(filledTakerTokenAmountAfter).to.be.bignumber.equal(expectedFillAmountTAfter);
@@ -383,8 +381,8 @@ contract('Exchange', (accounts: string[]) => {
const res = await exWrapper.fillOrderAsync(order, taker, {
fillTakerTokenAmount: order.params.takerTokenAmount,
});
-
- expect(res.logs[0].args.filledTakerTokenAmount).to.be.bignumber.equal(
+ const log = res.logs[0] as LogWithDecodedArgs<LogFillContractEventArgs>;
+ expect(log.args.filledTakerTokenAmount).to.be.bignumber.equal(
order.params.takerTokenAmount.minus(fillTakerTokenAmount),
);
const newBalances = await dmyBalances.getAsync();
@@ -419,7 +417,7 @@ contract('Exchange', (accounts: string[]) => {
});
expect(res.logs).to.have.length(1);
- const logArgs = res.logs[0].args;
+ const logArgs = (res.logs[0] as LogWithDecodedArgs<LogFillContractEventArgs>).args;
const expectedFilledMakerTokenAmount = order.params.makerTokenAmount.div(divisor);
const expectedFilledTakerTokenAmount = order.params.takerTokenAmount.div(divisor);
const expectedFeeMPaid = order.params.makerFee.div(divisor);
@@ -450,7 +448,7 @@ contract('Exchange', (accounts: string[]) => {
});
expect(res.logs).to.have.length(1);
- const logArgs = res.logs[0].args;
+ const logArgs = (res.logs[0] as LogWithDecodedArgs<LogFillContractEventArgs>).args;
const expectedFilledMakerTokenAmount = order.params.makerTokenAmount.div(divisor);
const expectedFilledTakerTokenAmount = order.params.takerTokenAmount.div(divisor);
const expectedFeeMPaid = new BigNumber(0);
@@ -567,9 +565,9 @@ contract('Exchange', (accounts: string[]) => {
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 });
+ await rep.approve(tokenTransferProxy.address, 0, { from: maker });
await exWrapper.fillOrderAsync(order, taker);
- await rep.approve(TokenTransferProxy.address, INITIAL_ALLOWANCE, {
+ await rep.approve(tokenTransferProxy.address, INITIAL_ALLOWANCE, {
from: maker,
});
@@ -579,22 +577,22 @@ contract('Exchange', (accounts: string[]) => {
it('should throw if maker allowances are too low to fill order and \
shouldThrowOnInsufficientBalanceOrAllowance = true', async () => {
- await rep.approve(TokenTransferProxy.address, 0, { from: maker });
+ 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, {
+ 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 });
+ await dgd.approve(tokenTransferProxy.address, 0, { from: taker });
await exWrapper.fillOrderAsync(order, taker);
- await dgd.approve(TokenTransferProxy.address, INITIAL_ALLOWANCE, {
+ await dgd.approve(tokenTransferProxy.address, INITIAL_ALLOWANCE, {
from: taker,
});
@@ -604,13 +602,13 @@ contract('Exchange', (accounts: string[]) => {
it('should throw if taker allowances are too low to fill order and \
shouldThrowOnInsufficientBalanceOrAllowance = true', async () => {
- await dgd.approve(TokenTransferProxy.address, 0, { from: taker });
+ 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, {
+ await dgd.approve(tokenTransferProxy.address, INITIAL_ALLOWANCE, {
from: taker,
});
});
@@ -630,7 +628,7 @@ contract('Exchange', (accounts: string[]) => {
it('should not change balances if makerToken is ZRX, makerTokenAmount + makerFee > maker allowance, \
and shouldThrowOnInsufficientBalanceOrAllowance = false', async () => {
- const makerZRXAllowance = await zrx.allowance(maker, TokenTransferProxy.address);
+ const makerZRXAllowance = await zrx.allowance(maker, tokenTransferProxy.address);
order = await orderFactory.newSignedOrderAsync({
makerToken: zrx.address,
makerTokenAmount: new BigNumber(makerZRXAllowance),
@@ -656,7 +654,7 @@ contract('Exchange', (accounts: string[]) => {
it('should not change balances if takerToken is ZRX, takerTokenAmount + takerFee > taker allowance, \
and shouldThrowOnInsufficientBalanceOrAllowance = false', async () => {
- const takerZRXAllowance = await zrx.allowance(taker, TokenTransferProxy.address);
+ const takerZRXAllowance = await zrx.allowance(taker, tokenTransferProxy.address);
order = await orderFactory.newSignedOrderAsync({
takerToken: zrx.address,
takerTokenAmount: new BigNumber(takerZRXAllowance),
@@ -669,8 +667,8 @@ 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 });
+ const maliciousToken = await deployer.deployAsync(ContractName.MaliciousToken);
+ await maliciousToken.approve(tokenTransferProxy.address, INITIAL_ALLOWANCE, { from: taker });
order = await orderFactory.newSignedOrderAsync({
takerToken: maliciousToken.address,
@@ -700,16 +698,19 @@ contract('Exchange', (accounts: string[]) => {
const res = await exWrapper.fillOrderAsync(order, taker);
expect(res.logs).to.have.length(1);
- const errCode = res.logs[0].args.errorId.toNumber();
+ const log = res.logs[0] as LogWithDecodedArgs<LogErrorContractEventArgs>;
+ const errCode = log.args.errorId.toNumber();
expect(errCode).to.be.equal(ExchangeContractErrs.ERROR_ORDER_EXPIRED);
});
it('should log an error event if no value is filled', async () => {
+ order = await orderFactory.newSignedOrderAsync({});
await exWrapper.fillOrderAsync(order, taker);
const res = await exWrapper.fillOrderAsync(order, taker);
expect(res.logs).to.have.length(1);
- const errCode = res.logs[0].args.errorId.toNumber();
+ const log = res.logs[0] as LogWithDecodedArgs<LogErrorContractEventArgs>;
+ const errCode = log.args.errorId.toNumber();
expect(errCode).to.be.equal(ExchangeContractErrs.ERROR_ORDER_FULLY_FILLED_OR_CANCELLED);
});
});
@@ -769,7 +770,8 @@ contract('Exchange', (accounts: string[]) => {
const res = await exWrapper.fillOrderAsync(order, taker, {
fillTakerTokenAmount: order.params.takerTokenAmount,
});
- expect(res.logs[0].args.filledTakerTokenAmount).to.be.bignumber.equal(
+ const log = res.logs[0] as LogWithDecodedArgs<LogFillContractEventArgs>;
+ expect(log.args.filledTakerTokenAmount).to.be.bignumber.equal(
order.params.takerTokenAmount.minus(cancelTakerTokenAmount),
);
@@ -813,7 +815,8 @@ contract('Exchange', (accounts: string[]) => {
});
expect(res.logs).to.have.length(1);
- const logArgs = res.logs[0].args;
+ const log = res.logs[0] as LogWithDecodedArgs<LogCancelContractEventArgs>;
+ const logArgs = log.args;
const expectedCancelledMakerTokenAmount = order.params.makerTokenAmount.div(divisor);
const expectedCancelledTakerTokenAmount = order.params.takerTokenAmount.div(divisor);
const tokensHashBuff = crypto.solSHA3([order.params.makerToken, order.params.takerToken]);
@@ -834,7 +837,8 @@ contract('Exchange', (accounts: string[]) => {
const res = await exWrapper.cancelOrderAsync(order, maker);
expect(res.logs).to.have.length(1);
- const errCode = res.logs[0].args.errorId.toNumber();
+ const log = res.logs[0] as LogWithDecodedArgs<LogErrorContractEventArgs>;
+ const errCode = log.args.errorId.toNumber();
expect(errCode).to.be.equal(ExchangeContractErrs.ERROR_ORDER_FULLY_FILLED_OR_CANCELLED);
});
@@ -845,7 +849,8 @@ contract('Exchange', (accounts: string[]) => {
const res = await exWrapper.cancelOrderAsync(order, maker);
expect(res.logs).to.have.length(1);
- const errCode = res.logs[0].args.errorId.toNumber();
+ const log = res.logs[0] as LogWithDecodedArgs<LogErrorContractEventArgs>;
+ const errCode = log.args.errorId.toNumber();
expect(errCode).to.be.equal(ExchangeContractErrs.ERROR_ORDER_EXPIRED);
});
});
diff --git a/packages/contracts/test/ts/exchange/helpers.ts b/packages/contracts/test/exchange/helpers.ts
index 95f68e419..5efce41a4 100644
--- a/packages/contracts/test/ts/exchange/helpers.ts
+++ b/packages/contracts/test/exchange/helpers.ts
@@ -1,52 +1,68 @@
import { ZeroEx } from '0x.js';
+import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils';
import { BigNumber } from '@0xproject/utils';
+import { Web3Wrapper } from '@0xproject/web3-wrapper';
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 { constants } from '../../util/constants';
+import { ExchangeWrapper } from '../../util/exchange_wrapper';
+import { Order } from '../../util/order';
+import { OrderFactory } from '../../util/order_factory';
+import { ContractName } from '../../util/types';
import { chaiSetup } from '../utils/chai_setup';
+import { deployer } from '../utils/deployer';
chaiSetup.configure();
const expect = chai.expect;
-const { Exchange, TokenRegistry } = new Artifacts(artifacts);
+const web3 = web3Factory.create();
+const web3Wrapper = new Web3Wrapper(web3.currentProvider);
+const blockchainLifecycle = new BlockchainLifecycle();
-contract('Exchange', (accounts: string[]) => {
- const maker = accounts[0];
- const feeRecipient = accounts[1] || accounts[accounts.length - 1];
+describe('Exchange', () => {
+ let maker: string;
+ let feeRecipient: string;
let order: Order;
let exchangeWrapper: ExchangeWrapper;
let orderFactory: OrderFactory;
before(async () => {
- const [tokenRegistry, exchange] = await Promise.all([TokenRegistry.deployed(), Exchange.deployed()]);
- exchangeWrapper = new ExchangeWrapper(exchange);
- const [repAddress, dgdAddress] = await Promise.all([
- tokenRegistry.getTokenAddressBySymbol('REP'),
- tokenRegistry.getTokenAddressBySymbol('DGD'),
+ const accounts = await web3Wrapper.getAvailableAddressesAsync();
+ [maker, feeRecipient] = accounts;
+ const tokenRegistry = await deployer.deployAsync(ContractName.TokenRegistry);
+ const tokenTransferProxy = await deployer.deployAsync(ContractName.TokenTransferProxy);
+ const [rep, dgd, zrx] = await Promise.all([
+ deployer.deployAsync(ContractName.DummyToken),
+ deployer.deployAsync(ContractName.DummyToken),
+ deployer.deployAsync(ContractName.DummyToken),
]);
+ const exchange = await deployer.deployAsync(ContractName.Exchange, [zrx.address, tokenTransferProxy.address]);
+ await tokenTransferProxy.addAuthorizedAddress(exchange.address, { from: accounts[0] });
+ const zeroEx = new ZeroEx(web3.currentProvider, { networkId: constants.TESTRPC_NETWORK_ID });
+ exchangeWrapper = new ExchangeWrapper(exchange, zeroEx);
const defaultOrderParams = {
- exchangeContractAddress: Exchange.address,
+ exchangeContractAddress: exchange.address,
maker,
feeRecipient,
- makerToken: repAddress,
- takerToken: dgdAddress,
+ makerToken: rep.address,
+ takerToken: dgd.address,
makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18),
takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18),
makerFee: ZeroEx.toBaseUnitAmount(new BigNumber(1), 18),
takerFee: ZeroEx.toBaseUnitAmount(new BigNumber(1), 18),
};
- orderFactory = new OrderFactory(defaultOrderParams);
+ orderFactory = new OrderFactory(web3Wrapper, defaultOrderParams);
+ order = await orderFactory.newSignedOrderAsync();
});
beforeEach(async () => {
- order = await orderFactory.newSignedOrderAsync();
+ await blockchainLifecycle.startAsync();
+ });
+ afterEach(async () => {
+ await blockchainLifecycle.revertAsync();
});
-
describe('getOrderHash', () => {
it('should output the correct orderHash', async () => {
const orderHashHex = await exchangeWrapper.getOrderHashAsync(order);
diff --git a/packages/contracts/test/ts/exchange/wrapper.ts b/packages/contracts/test/exchange/wrapper.ts
index e69e08bcf..acdf481a9 100644
--- a/packages/contracts/test/ts/exchange/wrapper.ts
+++ b/packages/contracts/test/exchange/wrapper.ts
@@ -1,35 +1,41 @@
import { ZeroEx } from '0x.js';
+import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils';
import { BigNumber } from '@0xproject/utils';
+import { Web3Wrapper } from '@0xproject/web3-wrapper';
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 * as Web3 from 'web3';
+
+import { Balances } from '../../util/balances';
+import { constants } from '../../util/constants';
+import { ExchangeWrapper } from '../../util/exchange_wrapper';
+import { Order } from '../../util/order';
+import { OrderFactory } from '../../util/order_factory';
+import { BalancesByOwner, ContractName } from '../../util/types';
import { chaiSetup } from '../utils/chai_setup';
+import { deployer } from '../utils/deployer';
chaiSetup.configure();
const expect = chai.expect;
-const { Exchange, TokenTransferProxy, DummyToken, TokenRegistry } = new Artifacts(artifacts);
+const web3 = web3Factory.create();
+const web3Wrapper = new Web3Wrapper(web3.currentProvider);
+const blockchainLifecycle = new BlockchainLifecycle();
-contract('Exchange', (accounts: string[]) => {
- const maker = accounts[0];
- const tokenOwner = accounts[0];
- const taker = accounts[1] || accounts[accounts.length - 1];
- const feeRecipient = accounts[2] || accounts[accounts.length - 1];
+describe('Exchange', () => {
+ let maker: string;
+ let tokenOwner: string;
+ let taker: string;
+ let feeRecipient: string;
const INIT_BAL = ZeroEx.toBaseUnitAmount(new BigNumber(10000), 18);
const INIT_ALLOW = ZeroEx.toBaseUnitAmount(new BigNumber(10000), 18);
- let rep: ContractInstance;
- let dgd: ContractInstance;
- let zrx: ContractInstance;
- let exchange: ContractInstance;
- let tokenRegistry: ContractInstance;
+ let rep: Web3.ContractInstance;
+ let dgd: Web3.ContractInstance;
+ let zrx: Web3.ContractInstance;
+ let exchange: Web3.ContractInstance;
+ let tokenRegistry: Web3.ContractInstance;
+ let tokenTransferProxy: Web3.ContractInstance;
let balances: BalancesByOwner;
@@ -38,49 +44,56 @@ contract('Exchange', (accounts: string[]) => {
let orderFactory: OrderFactory;
before(async () => {
- [tokenRegistry, exchange] = await Promise.all([TokenRegistry.deployed(), Exchange.deployed()]);
- exWrapper = new ExchangeWrapper(exchange);
- const [repAddress, dgdAddress, zrxAddress] = await Promise.all([
- tokenRegistry.getTokenAddressBySymbol('REP'),
- tokenRegistry.getTokenAddressBySymbol('DGD'),
- tokenRegistry.getTokenAddressBySymbol('ZRX'),
+ const accounts = await web3Wrapper.getAvailableAddressesAsync();
+ tokenOwner = accounts[0];
+ [maker, taker, feeRecipient] = accounts;
+ [rep, dgd, zrx] = await Promise.all([
+ deployer.deployAsync(ContractName.DummyToken),
+ deployer.deployAsync(ContractName.DummyToken),
+ deployer.deployAsync(ContractName.DummyToken),
]);
+ tokenRegistry = await deployer.deployAsync(ContractName.TokenRegistry);
+ tokenTransferProxy = await deployer.deployAsync(ContractName.TokenTransferProxy);
+ exchange = await deployer.deployAsync(ContractName.Exchange, [zrx.address, tokenTransferProxy.address]);
+ await tokenTransferProxy.addAuthorizedAddress(exchange.address, { from: accounts[0] });
+ const zeroEx = new ZeroEx(web3.currentProvider, { networkId: constants.TESTRPC_NETWORK_ID });
+ exWrapper = new ExchangeWrapper(exchange, zeroEx);
const defaultOrderParams = {
- exchangeContractAddress: Exchange.address,
+ exchangeContractAddress: exchange.address,
maker,
feeRecipient,
- makerToken: repAddress,
- takerToken: dgdAddress,
+ makerToken: rep.address,
+ takerToken: dgd.address,
makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18),
takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18),
makerFee: ZeroEx.toBaseUnitAmount(new BigNumber(1), 18),
takerFee: ZeroEx.toBaseUnitAmount(new BigNumber(1), 18),
};
- orderFactory = new OrderFactory(defaultOrderParams);
- [rep, dgd, zrx] = await Promise.all([
- DummyToken.at(repAddress),
- DummyToken.at(dgdAddress),
- DummyToken.at(zrxAddress),
- ]);
+ orderFactory = new OrderFactory(web3Wrapper, defaultOrderParams);
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.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.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.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 }),
]);
});
-
+ beforeEach(async () => {
+ await blockchainLifecycle.startAsync();
+ });
+ afterEach(async () => {
+ await blockchainLifecycle.revertAsync();
+ });
describe('fillOrKillOrder', () => {
beforeEach(async () => {
balances = await dmyBalances.getAsync();
diff --git a/packages/contracts/test/multi_sig_with_time_lock.ts b/packages/contracts/test/multi_sig_with_time_lock.ts
new file mode 100644
index 000000000..bd64be1ba
--- /dev/null
+++ b/packages/contracts/test/multi_sig_with_time_lock.ts
@@ -0,0 +1,191 @@
+import { LogWithDecodedArgs, ZeroEx } from '0x.js';
+import { BlockchainLifecycle, RPC, web3Factory } from '@0xproject/dev-utils';
+import { AbiDecoder, BigNumber } from '@0xproject/utils';
+import { Web3Wrapper } from '@0xproject/web3-wrapper';
+import * as chai from 'chai';
+import * as Web3 from '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 { ContractName, SubmissionContractEventArgs } from '../util/types';
+
+import { chaiSetup } from './utils/chai_setup';
+import { deployer } from './utils/deployer';
+
+const MULTI_SIG_ABI = artifacts.MultiSigWalletWithTimeLockArtifact.networks[constants.TESTRPC_NETWORK_ID].abi;
+chaiSetup.configure();
+const expect = chai.expect;
+
+const web3 = web3Factory.create();
+const web3Wrapper = new Web3Wrapper(web3.currentProvider);
+const blockchainLifecycle = new BlockchainLifecycle();
+const zeroEx = new ZeroEx(web3.currentProvider, { networkId: constants.TESTRPC_NETWORK_ID });
+const abiDecoder = new AbiDecoder([MULTI_SIG_ABI]);
+
+describe('MultiSigWalletWithTimeLock', () => {
+ let owners: string[];
+ before(async () => {
+ const accounts = await web3Wrapper.getAvailableAddressesAsync();
+ owners = [accounts[0], accounts[1]];
+ });
+ const SIGNATURES_REQUIRED = 2;
+ const SECONDS_TIME_LOCKED = 10000;
+
+ let multiSig: Web3.ContractInstance;
+ let multiSigWrapper: MultiSigWrapper;
+ let txId: number;
+ let initialSecondsTimeLocked: number;
+ let rpc: RPC;
+
+ before(async () => {
+ rpc = new RPC();
+ });
+ beforeEach(async () => {
+ await blockchainLifecycle.startAsync();
+ });
+ afterEach(async () => {
+ await blockchainLifecycle.revertAsync();
+ });
+
+ describe('changeTimeLock', () => {
+ describe('initially non-time-locked', async () => {
+ before('deploy a walet', async () => {
+ multiSig = await deployer.deployAsync(ContractName.MultiSigWalletWithTimeLock, [
+ owners,
+ SIGNATURES_REQUIRED,
+ 0,
+ ]);
+ multiSigWrapper = new MultiSigWrapper(multiSig);
+
+ const secondsTimeLocked = await multiSig.secondsTimeLocked();
+ initialSecondsTimeLocked = secondsTimeLocked.toNumber();
+ });
+ it('should throw when not called by wallet', async () => {
+ return expect(multiSig.changeTimeLock(SECONDS_TIME_LOCKED, { from: owners[0] })).to.be.rejectedWith(
+ constants.REVERT,
+ );
+ });
+
+ it('should throw without enough confirmations', async () => {
+ const destination = multiSig.address;
+ const from = owners[0];
+ const dataParams = {
+ name: 'changeTimeLock',
+ abi: MULTI_SIG_ABI,
+ args: [SECONDS_TIME_LOCKED],
+ };
+ const txHash = await multiSigWrapper.submitTransactionAsync(destination, from, dataParams);
+ const subRes = await zeroEx.awaitTransactionMinedAsync(txHash);
+ const log = abiDecoder.tryToDecodeLogOrNoop(subRes.logs[0]) as LogWithDecodedArgs<
+ SubmissionContractEventArgs
+ >;
+
+ txId = log.args.transactionId.toNumber();
+ return expect(multiSig.executeTransaction(txId, { from: owners[0] })).to.be.rejectedWith(
+ constants.REVERT,
+ );
+ });
+
+ it('should set confirmation time with enough confirmations', async () => {
+ const destination = multiSig.address;
+ const from = owners[0];
+ const dataParams = {
+ name: 'changeTimeLock',
+ abi: MULTI_SIG_ABI,
+ args: [SECONDS_TIME_LOCKED],
+ };
+ let txHash = await multiSigWrapper.submitTransactionAsync(destination, from, dataParams);
+ const subRes = await zeroEx.awaitTransactionMinedAsync(txHash);
+ const log = abiDecoder.tryToDecodeLogOrNoop(subRes.logs[0]) as LogWithDecodedArgs<
+ SubmissionContractEventArgs
+ >;
+
+ txId = log.args.transactionId.toNumber();
+ txHash = await multiSig.confirmTransaction(txId, { from: owners[1] });
+ const res = await zeroEx.awaitTransactionMinedAsync(txHash);
+ expect(res.logs).to.have.length(2);
+
+ const blockNum = await web3Wrapper.getBlockNumberAsync();
+ const blockInfo = await web3Wrapper.getBlockAsync(blockNum);
+ const timestamp = new BigNumber(blockInfo.timestamp);
+ const confirmationTimeBigNum = new BigNumber(await multiSig.confirmationTimes.call(txId));
+
+ expect(timestamp).to.be.bignumber.equal(confirmationTimeBigNum);
+ });
+
+ it('should be executable with enough confirmations and secondsTimeLocked of 0', async () => {
+ const destination = multiSig.address;
+ const from = owners[0];
+ const dataParams = {
+ name: 'changeTimeLock',
+ abi: MULTI_SIG_ABI,
+ args: [SECONDS_TIME_LOCKED],
+ };
+ let txHash = await multiSigWrapper.submitTransactionAsync(destination, from, dataParams);
+ const subRes = await zeroEx.awaitTransactionMinedAsync(txHash);
+ const log = abiDecoder.tryToDecodeLogOrNoop(subRes.logs[0]) as LogWithDecodedArgs<
+ SubmissionContractEventArgs
+ >;
+
+ txId = log.args.transactionId.toNumber();
+ txHash = await multiSig.confirmTransaction(txId, { from: owners[1] });
+
+ expect(initialSecondsTimeLocked).to.be.equal(0);
+
+ txHash = await multiSig.executeTransaction(txId, { from: owners[0] });
+ const res = await zeroEx.awaitTransactionMinedAsync(txHash);
+ expect(res.logs).to.have.length(2);
+
+ const secondsTimeLocked = new BigNumber(await multiSig.secondsTimeLocked.call());
+ expect(secondsTimeLocked).to.be.bignumber.equal(SECONDS_TIME_LOCKED);
+ });
+ });
+ describe('initially time-locked', async () => {
+ before('deploy a walet', async () => {
+ multiSig = await deployer.deployAsync(ContractName.MultiSigWalletWithTimeLock, [
+ owners,
+ SIGNATURES_REQUIRED,
+ SECONDS_TIME_LOCKED,
+ ]);
+ multiSigWrapper = new MultiSigWrapper(multiSig);
+
+ const secondsTimeLocked = await multiSig.secondsTimeLocked();
+ initialSecondsTimeLocked = secondsTimeLocked.toNumber();
+ const destination = multiSig.address;
+ const from = owners[0];
+ const dataParams = {
+ name: 'changeTimeLock',
+ abi: MULTI_SIG_ABI,
+ args: [newSecondsTimeLocked],
+ };
+ let txHash = await multiSigWrapper.submitTransactionAsync(destination, from, dataParams);
+ const subRes = await zeroEx.awaitTransactionMinedAsync(txHash);
+ const log = abiDecoder.tryToDecodeLogOrNoop(subRes.logs[0]) as LogWithDecodedArgs<
+ SubmissionContractEventArgs
+ >;
+ txId = log.args.transactionId.toNumber();
+ txHash = await multiSig.confirmTransaction(txId, {
+ from: owners[1],
+ });
+ const confRes = await zeroEx.awaitTransactionMinedAsync(txHash);
+ expect(confRes.logs).to.have.length(2);
+ });
+ const newSecondsTimeLocked = 0;
+ it('should throw if it has enough confirmations but is not past the time lock', async () => {
+ return expect(multiSig.executeTransaction(txId, { from: owners[0] })).to.be.rejectedWith(
+ constants.REVERT,
+ );
+ });
+
+ it('should execute if it has enough confirmations and is past the time lock', async () => {
+ await rpc.increaseTimeAsync(SECONDS_TIME_LOCKED);
+ await multiSig.executeTransaction(txId, { from: owners[0] });
+
+ const secondsTimeLocked = new BigNumber(await multiSig.secondsTimeLocked.call());
+ expect(secondsTimeLocked).to.be.bignumber.equal(newSecondsTimeLocked);
+ });
+ });
+ });
+});
diff --git a/packages/contracts/test/multi_sig_with_time_lock_except_remove_auth_addr.ts b/packages/contracts/test/multi_sig_with_time_lock_except_remove_auth_addr.ts
new file mode 100644
index 000000000..f6b7c1d53
--- /dev/null
+++ b/packages/contracts/test/multi_sig_with_time_lock_except_remove_auth_addr.ts
@@ -0,0 +1,181 @@
+import { LogWithDecodedArgs, ZeroEx } from '0x.js';
+import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils';
+import { AbiDecoder } from '@0xproject/utils';
+import { Web3Wrapper } from '@0xproject/web3-wrapper';
+import * as chai from 'chai';
+import * as Web3 from 'web3';
+
+import { artifacts } from '../util/artifacts';
+import { constants } from '../util/constants';
+import { crypto } from '../util/crypto';
+import { MultiSigWrapper } from '../util/multi_sig_wrapper';
+import { ContractName, SubmissionContractEventArgs, TransactionDataParams } from '../util/types';
+
+import { chaiSetup } from './utils/chai_setup';
+import { deployer } from './utils/deployer';
+const PROXY_ABI = artifacts.TokenTransferProxyArtifact.networks[constants.TESTRPC_NETWORK_ID].abi;
+const MUTISIG_WALLET_WITH_TIME_LOCK_EXCEPT_REMOVE_AUTHORIZED_ADDRESS_ABI =
+ artifacts.MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressArtifact.networks[constants.TESTRPC_NETWORK_ID]
+ .abi;
+
+chaiSetup.configure();
+const expect = chai.expect;
+const web3 = web3Factory.create();
+const web3Wrapper = new Web3Wrapper(web3.currentProvider);
+const blockchainLifecycle = new BlockchainLifecycle();
+const abiDecoder = new AbiDecoder([MUTISIG_WALLET_WITH_TIME_LOCK_EXCEPT_REMOVE_AUTHORIZED_ADDRESS_ABI]);
+
+describe('MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', () => {
+ const zeroEx = new ZeroEx(web3.currentProvider, { networkId: constants.TESTRPC_NETWORK_ID });
+ let owners: string[];
+ const requiredApprovals = 2;
+ const SECONDS_TIME_LOCKED = 1000000;
+
+ // initialize fake addresses
+ let authorizedAddress: string;
+ let unauthorizedAddress: string;
+
+ let tokenTransferProxy: Web3.ContractInstance;
+ let multiSig: Web3.ContractInstance;
+ let multiSigWrapper: MultiSigWrapper;
+
+ let validDestination: string;
+ before(async () => {
+ const accounts = await web3Wrapper.getAvailableAddressesAsync();
+ owners = [accounts[0], accounts[1]];
+ [authorizedAddress, unauthorizedAddress] = accounts;
+ const initialOwner = accounts[0];
+ tokenTransferProxy = await deployer.deployAsync(ContractName.TokenTransferProxy);
+ await tokenTransferProxy.addAuthorizedAddress(authorizedAddress, {
+ from: initialOwner,
+ });
+ multiSig = await deployer.deployAsync(ContractName.MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress, [
+ owners,
+ requiredApprovals,
+ SECONDS_TIME_LOCKED,
+ tokenTransferProxy.address,
+ ]);
+ await tokenTransferProxy.transferOwnership(multiSig.address, {
+ from: initialOwner,
+ });
+ multiSigWrapper = new MultiSigWrapper(multiSig);
+ validDestination = tokenTransferProxy.address;
+ });
+ beforeEach(async () => {
+ await blockchainLifecycle.startAsync();
+ });
+ afterEach(async () => {
+ await blockchainLifecycle.revertAsync();
+ });
+
+ 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.REVERT);
+ });
+
+ it('should return true if data is for removeAuthorizedAddress', async () => {
+ const data = MultiSigWrapper.encodeFnArgs('removeAuthorizedAddress', PROXY_ABI, [owners[0]]);
+ const isFunctionRemoveAuthorizedAddress = await multiSig.isFunctionRemoveAuthorizedAddress.call(data);
+ expect(isFunctionRemoveAuthorizedAddress).to.be.true();
+ });
+ });
+
+ describe('executeRemoveAuthorizedAddress', () => {
+ it('should throw without the required confirmations', async () => {
+ const dataParams: TransactionDataParams = {
+ name: 'removeAuthorizedAddress',
+ abi: PROXY_ABI,
+ args: [authorizedAddress],
+ };
+ const txHash = await multiSigWrapper.submitTransactionAsync(validDestination, owners[0], dataParams);
+ const res = await zeroEx.awaitTransactionMinedAsync(txHash);
+ const log = abiDecoder.tryToDecodeLogOrNoop(res.logs[0]) as LogWithDecodedArgs<SubmissionContractEventArgs>;
+ const txId = log.args.transactionId.toString();
+
+ return expect(multiSig.executeRemoveAuthorizedAddress(txId, { from: owners[1] })).to.be.rejectedWith(
+ constants.REVERT,
+ );
+ });
+
+ it('should throw if tx destination is not the tokenTransferProxy', async () => {
+ const invalidTokenTransferProxy = await deployer.deployAsync(ContractName.TokenTransferProxy);
+ const invalidDestination = invalidTokenTransferProxy.address;
+ const dataParams: TransactionDataParams = {
+ name: 'removeAuthorizedAddress',
+ abi: PROXY_ABI,
+ args: [authorizedAddress],
+ };
+ const txHash = await multiSigWrapper.submitTransactionAsync(invalidDestination, owners[0], dataParams);
+ const res = await zeroEx.awaitTransactionMinedAsync(txHash);
+ const log = abiDecoder.tryToDecodeLogOrNoop(res.logs[0]) as LogWithDecodedArgs<SubmissionContractEventArgs>;
+ const txId = log.args.transactionId.toString();
+ await multiSig.confirmTransaction(txId, { from: owners[1] });
+ const isConfirmed = await multiSig.isConfirmed.call(txId);
+ expect(isConfirmed).to.be.true();
+
+ return expect(multiSig.executeRemoveAuthorizedAddress(txId, { from: owners[1] })).to.be.rejectedWith(
+ constants.REVERT,
+ );
+ });
+
+ it('should throw if tx data is not for removeAuthorizedAddress', async () => {
+ const dataParams: TransactionDataParams = {
+ name: 'addAuthorizedAddress',
+ abi: PROXY_ABI,
+ args: [unauthorizedAddress],
+ };
+ const txHash = await multiSigWrapper.submitTransactionAsync(validDestination, owners[0], dataParams);
+ const res = await zeroEx.awaitTransactionMinedAsync(txHash);
+ const log = abiDecoder.tryToDecodeLogOrNoop(res.logs[0]) as LogWithDecodedArgs<SubmissionContractEventArgs>;
+ const txId = log.args.transactionId.toString();
+ await multiSig.confirmTransaction(txId, { from: owners[1] });
+ const isConfirmed = await multiSig.isConfirmed.call(txId);
+ expect(isConfirmed).to.be.true();
+
+ return expect(multiSig.executeRemoveAuthorizedAddress(txId, { from: owners[1] })).to.be.rejectedWith(
+ constants.REVERT,
+ );
+ });
+
+ it('should execute removeAuthorizedAddress for valid tokenTransferProxy if fully confirmed', async () => {
+ const dataParams: TransactionDataParams = {
+ name: 'removeAuthorizedAddress',
+ abi: PROXY_ABI,
+ args: [authorizedAddress],
+ };
+ const txHash = await multiSigWrapper.submitTransactionAsync(validDestination, owners[0], dataParams);
+ const res = await zeroEx.awaitTransactionMinedAsync(txHash);
+ const log = abiDecoder.tryToDecodeLogOrNoop(res.logs[0]) as LogWithDecodedArgs<SubmissionContractEventArgs>;
+ const txId = log.args.transactionId.toString();
+ await multiSig.confirmTransaction(txId, { from: owners[1] });
+ const isConfirmed = await multiSig.isConfirmed.call(txId);
+ expect(isConfirmed).to.be.true();
+ await multiSig.executeRemoveAuthorizedAddress(txId, { from: owners[1] });
+ const isAuthorized = await tokenTransferProxy.authorized.call(authorizedAddress);
+ expect(isAuthorized).to.be.false();
+ });
+
+ it('should throw if already executed', async () => {
+ const dataParams: TransactionDataParams = {
+ name: 'removeAuthorizedAddress',
+ abi: PROXY_ABI,
+ args: [authorizedAddress],
+ };
+ const txHash = await multiSigWrapper.submitTransactionAsync(validDestination, owners[0], dataParams);
+ const res = await zeroEx.awaitTransactionMinedAsync(txHash);
+ const log = abiDecoder.tryToDecodeLogOrNoop(res.logs[0]) as LogWithDecodedArgs<SubmissionContractEventArgs>;
+ const txId = log.args.transactionId.toString();
+ await multiSig.confirmTransaction(txId, { from: owners[1] });
+ const isConfirmed = await multiSig.isConfirmed(txId);
+ expect(isConfirmed).to.be.true();
+ await multiSig.executeRemoveAuthorizedAddress(txId, { from: owners[1] });
+ const tx = await multiSig.transactions(txId);
+ const isExecuted = tx[3];
+ expect(isExecuted).to.be.true();
+ return expect(multiSig.executeRemoveAuthorizedAddress(txId, { from: owners[1] })).to.be.rejectedWith(
+ constants.REVERT,
+ );
+ });
+ });
+});
diff --git a/packages/contracts/test/ts/token_registry.ts b/packages/contracts/test/token_registry.ts
index d1c551565..2a270dc2f 100644
--- a/packages/contracts/test/ts/token_registry.ts
+++ b/packages/contracts/test/token_registry.ts
@@ -1,22 +1,42 @@
import { ZeroEx } from '0x.js';
+import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils';
+import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as chai from 'chai';
import ethUtil = require('ethereumjs-util');
import * as _ from 'lodash';
+import * as Web3 from 'web3';
-import { Artifacts } from '../../util/artifacts';
-import { constants } from '../../util/constants';
-import { TokenRegWrapper } from '../../util/token_registry_wrapper';
-import { ContractInstance } from '../../util/types';
+import { constants } from '../util/constants';
+import { TokenRegWrapper } from '../util/token_registry_wrapper';
+import { ContractName } from '../util/types';
import { chaiSetup } from './utils/chai_setup';
+import { deployer } from './utils/deployer';
-const { TokenRegistry } = new Artifacts(artifacts);
chaiSetup.configure();
const expect = chai.expect;
-
-contract('TokenRegistry', (accounts: string[]) => {
- const owner = accounts[0];
- const notOwner = accounts[1];
+const web3 = web3Factory.create();
+const web3Wrapper = new Web3Wrapper(web3.currentProvider);
+const blockchainLifecycle = new BlockchainLifecycle();
+
+describe('TokenRegistry', () => {
+ let owner: string;
+ let notOwner: string;
+ let tokenReg: Web3.ContractInstance;
+ let tokenRegWrapper: TokenRegWrapper;
+ before(async () => {
+ const accounts = await web3Wrapper.getAvailableAddressesAsync();
+ owner = accounts[0];
+ notOwner = accounts[1];
+ tokenReg = await deployer.deployAsync(ContractName.TokenRegistry);
+ tokenRegWrapper = new TokenRegWrapper(tokenReg);
+ });
+ beforeEach(async () => {
+ await blockchainLifecycle.startAsync();
+ });
+ afterEach(async () => {
+ await blockchainLifecycle.revertAsync();
+ });
const tokenAddress1 = `0x${ethUtil.setLength(ethUtil.toBuffer('0x1'), 20, false).toString('hex')}`;
const tokenAddress2 = `0x${ethUtil.setLength(ethUtil.toBuffer('0x2'), 20, false).toString('hex')}`;
@@ -48,14 +68,6 @@ contract('TokenRegistry', (accounts: string[]) => {
swarmHash: constants.NULL_BYTES,
};
- let tokenReg: ContractInstance;
- let tokenRegWrapper: TokenRegWrapper;
-
- beforeEach(async () => {
- tokenReg = await TokenRegistry.new();
- tokenRegWrapper = new TokenRegWrapper(tokenReg);
- });
-
describe('addToken', () => {
it('should throw when not called by owner', async () => {
return expect(tokenRegWrapper.addTokenAsync(token1, notOwner)).to.be.rejectedWith(constants.REVERT);
@@ -125,10 +137,9 @@ contract('TokenRegistry', (accounts: string[]) => {
});
it('should change the token name when called by owner', async () => {
- const res = await tokenReg.setTokenName(token1.address, token2.name, {
+ 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),
@@ -165,8 +176,7 @@ contract('TokenRegistry', (accounts: string[]) => {
});
it('should change the token symbol when called by owner', async () => {
- const res = await tokenReg.setTokenSymbol(token1.address, token2.symbol, { from: owner });
- expect(res.logs).to.have.length(1);
+ await tokenReg.setTokenSymbol(token1.address, token2.symbol, { from: owner });
const [newData, oldData] = await Promise.all([
tokenRegWrapper.getTokenBySymbolAsync(token2.symbol),
tokenRegWrapper.getTokenBySymbolAsync(token1.symbol),
@@ -207,10 +217,9 @@ contract('TokenRegistry', (accounts: string[]) => {
it('should remove token metadata when called by owner', async () => {
const index = 0;
- const res = await tokenReg.removeToken(token1.address, index, {
+ 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);
});
diff --git a/packages/contracts/test/ts/token_transfer_proxy/auth.ts b/packages/contracts/test/token_transfer_proxy/auth.ts
index 9ae0a8fc3..b2bfc6b65 100644
--- a/packages/contracts/test/ts/token_transfer_proxy/auth.ts
+++ b/packages/contracts/test/token_transfer_proxy/auth.ts
@@ -1,44 +1,50 @@
+import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils';
+import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as chai from 'chai';
+import * as Web3 from 'web3';
-import { constants } from '../../../util/constants';
-import { ContractInstance } from '../../../util/types';
+import { constants } from '../../util/constants';
+import { ContractName } from '../../util/types';
import { chaiSetup } from '../utils/chai_setup';
+import { deployer } from '../utils/deployer';
chaiSetup.configure();
const expect = chai.expect;
-const TokenTransferProxy = artifacts.require('./db/TokenTransferProxy.sol');
-
-contract('TokenTransferProxy', (accounts: string[]) => {
- const owner = accounts[0];
- const notOwner = accounts[1];
-
- let tokenTransferProxy: ContractInstance;
- let authorized: string;
- let notAuthorized = owner;
+const web3 = web3Factory.create();
+const web3Wrapper = new Web3Wrapper(web3.currentProvider);
+const blockchainLifecycle = new BlockchainLifecycle();
+describe('TokenTransferProxy', () => {
+ let owner: string;
+ let notOwner: string;
+ let address: string;
+ let tokenTransferProxy: Web3.ContractInstance;
before(async () => {
- tokenTransferProxy = await TokenTransferProxy.deployed();
+ const accounts = await web3Wrapper.getAvailableAddressesAsync();
+ owner = address = accounts[0];
+ notOwner = accounts[1];
+ tokenTransferProxy = await deployer.deployAsync(ContractName.TokenTransferProxy);
+ });
+ beforeEach(async () => {
+ await blockchainLifecycle.startAsync();
+ });
+ afterEach(async () => {
+ await blockchainLifecycle.revertAsync();
});
-
describe('addAuthorizedAddress', () => {
it('should throw if not called by owner', async () => {
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,
- });
- authorized = notAuthorized;
- notAuthorized = null;
- const isAuthorized = await tokenTransferProxy.authorized.call(authorized);
+ await tokenTransferProxy.addAuthorizedAddress(address, { from: owner });
+ const isAuthorized = await tokenTransferProxy.authorized(address);
expect(isAuthorized).to.be.true();
});
-
it('should throw if owner attempts to authorize a duplicate address', async () => {
- return expect(tokenTransferProxy.addAuthorizedAddress(authorized, { from: owner })).to.be.rejectedWith(
+ await tokenTransferProxy.addAuthorizedAddress(address, { from: owner });
+ return expect(tokenTransferProxy.addAuthorizedAddress(address, { from: owner })).to.be.rejectedWith(
constants.REVERT,
);
});
@@ -46,27 +52,26 @@ contract('TokenTransferProxy', (accounts: string[]) => {
describe('removeAuthorizedAddress', () => {
it('should throw if not called by owner', async () => {
+ await tokenTransferProxy.addAuthorizedAddress(address, { from: owner });
return expect(
- tokenTransferProxy.removeAuthorizedAddress(authorized, {
+ tokenTransferProxy.removeAuthorizedAddress(address, {
from: notOwner,
}),
).to.be.rejectedWith(constants.REVERT);
});
it('should allow owner to remove an authorized address', async () => {
- await tokenTransferProxy.removeAuthorizedAddress(authorized, {
+ await tokenTransferProxy.addAuthorizedAddress(address, { from: owner });
+ await tokenTransferProxy.removeAuthorizedAddress(address, {
from: owner,
});
- notAuthorized = authorized;
- authorized = null;
-
- const isAuthorized = await tokenTransferProxy.authorized.call(notAuthorized);
+ const isAuthorized = await tokenTransferProxy.authorized(address);
expect(isAuthorized).to.be.false();
});
it('should throw if owner attempts to remove an address that is not authorized', async () => {
return expect(
- tokenTransferProxy.removeAuthorizedAddress(notAuthorized, {
+ tokenTransferProxy.removeAuthorizedAddress(address, {
from: owner,
}),
).to.be.rejectedWith(constants.REVERT);
@@ -76,24 +81,19 @@ contract('TokenTransferProxy', (accounts: string[]) => {
describe('getAuthorizedAddresses', () => {
it('should return all authorized addresses', async () => {
const initial = await tokenTransferProxy.getAuthorizedAddresses();
- expect(initial).to.have.length(1);
- await tokenTransferProxy.addAuthorizedAddress(notAuthorized, {
+ expect(initial).to.have.length(0);
+ await tokenTransferProxy.addAuthorizedAddress(address, {
from: owner,
});
-
- authorized = notAuthorized;
- notAuthorized = null;
const afterAdd = await tokenTransferProxy.getAuthorizedAddresses();
- expect(afterAdd).to.have.length(2);
- expect(afterAdd).to.include(authorized);
+ expect(afterAdd).to.have.length(1);
+ expect(afterAdd).to.include(address);
- await tokenTransferProxy.removeAuthorizedAddress(authorized, {
+ await tokenTransferProxy.removeAuthorizedAddress(address, {
from: owner,
});
- notAuthorized = authorized;
- authorized = null;
const afterRemove = await tokenTransferProxy.getAuthorizedAddresses();
- expect(afterRemove).to.have.length(1);
+ expect(afterRemove).to.have.length(0);
});
});
});
diff --git a/packages/contracts/test/ts/token_transfer_proxy/transfer_from.ts b/packages/contracts/test/token_transfer_proxy/transfer_from.ts
index e1aff6dae..bd7adcfae 100644
--- a/packages/contracts/test/ts/token_transfer_proxy/transfer_from.ts
+++ b/packages/contracts/test/token_transfer_proxy/transfer_from.ts
@@ -1,47 +1,55 @@
+import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils';
+import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as chai from 'chai';
+import * as Web3 from 'web3';
-import { Artifacts } from '../../../util/artifacts';
-import { Balances } from '../../../util/balances';
-import { constants } from '../../../util/constants';
-import { ContractInstance } from '../../../util/types';
+import { Balances } from '../../util/balances';
+import { constants } from '../../util/constants';
+import { ContractName } from '../../util/types';
import { chaiSetup } from '../utils/chai_setup';
+import { deployer } from '../utils/deployer';
chaiSetup.configure();
const expect = chai.expect;
-const { TokenTransferProxy, DummyToken, TokenRegistry } = new Artifacts(artifacts);
+const web3 = web3Factory.create();
+const web3Wrapper = new Web3Wrapper(web3.currentProvider);
+const blockchainLifecycle = new BlockchainLifecycle();
-contract('TokenTransferProxy', (accounts: string[]) => {
+describe('TokenTransferProxy', () => {
+ let accounts: string[];
+ let owner: string;
+ let notAuthorized: string;
const INIT_BAL = 100000000;
const INIT_ALLOW = 100000000;
- const owner = accounts[0];
- const notAuthorized = owner;
-
- let tokenTransferProxy: ContractInstance;
- let tokenRegistry: ContractInstance;
- let rep: ContractInstance;
+ let tokenTransferProxy: Web3.ContractInstance;
+ let rep: Web3.ContractInstance;
let dmyBalances: Balances;
before(async () => {
- [tokenTransferProxy, tokenRegistry] = await Promise.all([
- TokenTransferProxy.deployed(),
- TokenRegistry.deployed(),
- ]);
- const repAddress = await tokenRegistry.getTokenAddressBySymbol('REP');
- rep = DummyToken.at(repAddress);
+ accounts = await web3Wrapper.getAvailableAddressesAsync();
+ owner = notAuthorized = accounts[0];
+ tokenTransferProxy = await deployer.deployAsync(ContractName.TokenTransferProxy);
+ rep = await deployer.deployAsync(ContractName.DummyToken);
dmyBalances = new Balances([rep], [accounts[0], accounts[1]]);
await Promise.all([
- rep.approve(TokenTransferProxy.address, INIT_ALLOW, {
+ rep.approve(tokenTransferProxy.address, INIT_ALLOW, {
from: accounts[0],
}),
rep.setBalance(accounts[0], INIT_BAL, { from: owner }),
- rep.approve(TokenTransferProxy.address, INIT_ALLOW, {
+ rep.approve(tokenTransferProxy.address, INIT_ALLOW, {
from: accounts[1],
}),
rep.setBalance(accounts[1], INIT_BAL, { from: owner }),
]);
});
+ beforeEach(async () => {
+ await blockchainLifecycle.startAsync();
+ });
+ afterEach(async () => {
+ await blockchainLifecycle.revertAsync();
+ });
describe('transferFrom', () => {
it('should throw when called by an unauthorized address', async () => {
diff --git a/packages/contracts/test/ts/multi_sig_with_time_lock.ts b/packages/contracts/test/ts/multi_sig_with_time_lock.ts
deleted file mode 100644
index ea939a758..000000000
--- a/packages/contracts/test/ts/multi_sig_with_time_lock.ts
+++ /dev/null
@@ -1,115 +0,0 @@
-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 * 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';
-
-const { MultiSigWalletWithTimeLock } = new Artifacts(artifacts);
-
-const MULTI_SIG_ABI = (multiSigWalletJSON as any).abi;
-chaiSetup.configure();
-const expect = chai.expect;
-
-// 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`.
-const web3: Web3 = (global as any).web3;
-
-contract('MultiSigWalletWithTimeLock', (accounts: string[]) => {
- const owners = [accounts[0], accounts[1]];
- const SECONDS_TIME_LOCKED = 10000;
-
- let multiSig: ContractInstance;
- let multiSigWrapper: MultiSigWrapper;
- let txId: number;
- let initialSecondsTimeLocked: number;
- let rpc: RPC;
-
- before(async () => {
- multiSig = await MultiSigWalletWithTimeLock.deployed();
- multiSigWrapper = new MultiSigWrapper(multiSig);
-
- const secondsTimeLocked = await multiSig.secondsTimeLocked.call();
- initialSecondsTimeLocked = secondsTimeLocked.toNumber();
- 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.REVERT,
- );
- });
-
- it('should throw without enough confirmations', async () => {
- const destination = multiSig.address;
- const from = owners[0];
- const dataParams = {
- name: 'changeTimeLock',
- abi: MULTI_SIG_ABI,
- args: [SECONDS_TIME_LOCKED],
- };
- const subRes = await multiSigWrapper.submitTransactionAsync(destination, from, dataParams);
-
- txId = subRes.logs[0].args.transactionId.toNumber();
- 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] });
- 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);
- const timestamp = new BigNumber(blockInfo.timestamp);
- const confirmationTimeBigNum = new BigNumber(await multiSig.confirmationTimes.call(txId));
-
- expect(timestamp).to.be.bignumber.equal(confirmationTimeBigNum);
- });
-
- it('should be executable with enough confirmations and secondsTimeLocked of 0', async () => {
- expect(initialSecondsTimeLocked).to.be.equal(0);
-
- const res = await multiSig.executeTransaction(txId);
- expect(res.logs).to.have.length(2);
-
- const secondsTimeLocked = new BigNumber(await multiSig.secondsTimeLocked.call());
- expect(secondsTimeLocked).to.be.bignumber.equal(SECONDS_TIME_LOCKED);
- });
-
- const newSecondsTimeLocked = 0;
- it('should throw if it has enough confirmations but is not past the time lock', async () => {
- const destination = multiSig.address;
- const from = owners[0];
- const dataParams = {
- name: 'changeTimeLock',
- abi: MULTI_SIG_ABI,
- args: [newSecondsTimeLocked],
- };
- const subRes = await multiSigWrapper.submitTransactionAsync(destination, from, dataParams);
-
- txId = subRes.logs[0].args.transactionId.toNumber();
- 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.REVERT);
- });
-
- it('should execute if it has enough confirmations and is past the time lock', async () => {
- await rpc.increaseTimeAsync(SECONDS_TIME_LOCKED);
- await multiSig.executeTransaction(txId);
-
- const secondsTimeLocked = new BigNumber(await multiSig.secondsTimeLocked.call());
- expect(secondsTimeLocked).to.be.bignumber.equal(newSecondsTimeLocked);
- });
- });
-});
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
deleted file mode 100644
index 62aa625fe..000000000
--- a/packages/contracts/test/ts/multi_sig_with_time_lock_except_remove_auth_addr.ts
+++ /dev/null
@@ -1,150 +0,0 @@
-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);
-const PROXY_ABI = (tokenTransferProxyJSON as any).abi;
-
-chaiSetup.configure();
-const expect = chai.expect;
-
-contract('MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', (accounts: string[]) => {
- const owners = [accounts[0], accounts[1]];
- const requiredApprovals = 2;
- 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')}`;
-
- let tokenTransferProxy: ContractInstance;
- let multiSig: ContractInstance;
- let multiSigWrapper: MultiSigWrapper;
-
- let validDestination: string;
-
- beforeEach(async () => {
- const initialOwner = accounts[0];
- 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,
- });
- multiSigWrapper = new MultiSigWrapper(multiSig);
- validDestination = tokenTransferProxy.address;
- });
-
- 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.REVERT);
- });
-
- it('should return true if data is for removeAuthorizedAddress', async () => {
- const data = MultiSigWrapper.encodeFnArgs('removeAuthorizedAddress', PROXY_ABI, [owners[0]]);
- const isFunctionRemoveAuthorizedAddress = await multiSig.isFunctionRemoveAuthorizedAddress.call(data);
- expect(isFunctionRemoveAuthorizedAddress).to.be.true();
- });
- });
-
- describe('executeRemoveAuthorizedAddress', () => {
- it('should throw without the required confirmations', async () => {
- const dataParams: TransactionDataParams = {
- name: 'removeAuthorizedAddress',
- abi: PROXY_ABI,
- args: [authorizedAddress],
- };
- 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.REVERT);
- });
-
- it('should throw if tx destination is not the tokenTransferProxy', async () => {
- const invalidTokenTransferProxy = await TokenTransferProxy.new();
- const invalidDestination = invalidTokenTransferProxy.address;
- const dataParams: TransactionDataParams = {
- name: 'removeAuthorizedAddress',
- abi: PROXY_ABI,
- args: [authorizedAddress],
- };
- const res = await multiSigWrapper.submitTransactionAsync(invalidDestination, owners[0], dataParams);
- const txId = res.logs[0].args.transactionId.toString();
- 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.REVERT);
- });
-
- it('should throw if tx data is not for removeAuthorizedAddress', async () => {
- const dataParams: TransactionDataParams = {
- name: 'addAuthorizedAddress',
- abi: PROXY_ABI,
- args: [unauthorizedAddress],
- };
- const res = await multiSigWrapper.submitTransactionAsync(validDestination, owners[0], dataParams);
- const txId = res.logs[0].args.transactionId.toString();
- 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.REVERT);
- });
-
- it('should execute removeAuthorizedAddress for valid tokenTransferProxy if fully confirmed', async () => {
- const dataParams: TransactionDataParams = {
- name: 'removeAuthorizedAddress',
- abi: PROXY_ABI,
- args: [authorizedAddress],
- };
- const res = await multiSigWrapper.submitTransactionAsync(validDestination, owners[0], dataParams);
- const txId = res.logs[0].args.transactionId.toString();
- await multiSig.confirmTransaction(txId, { from: owners[1] });
- const isConfirmed = await multiSig.isConfirmed.call(txId);
- expect(isConfirmed).to.be.true();
- await multiSig.executeRemoveAuthorizedAddress(txId);
-
- const isAuthorized = await tokenTransferProxy.authorized.call(authorizedAddress);
- expect(isAuthorized).to.be.false();
- });
-
- it('should throw if already executed', async () => {
- const dataParams: TransactionDataParams = {
- name: 'removeAuthorizedAddress',
- abi: PROXY_ABI,
- args: [authorizedAddress],
- };
- const res = await multiSigWrapper.submitTransactionAsync(validDestination, owners[0], dataParams);
- const txId = res.logs[0].args.transactionId.toString();
- 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.REVERT);
- });
- });
-});
diff --git a/packages/contracts/test/ts/unlimited_allowance_token.ts b/packages/contracts/test/ts/unlimited_allowance_token.ts
deleted file mode 100644
index c90a52095..000000000
--- a/packages/contracts/test/ts/unlimited_allowance_token.ts
+++ /dev/null
@@ -1,127 +0,0 @@
-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 { DummyToken } = new Artifacts(artifacts);
-const web3: Web3 = (global as any).web3;
-chaiSetup.configure();
-const expect = chai.expect;
-
-contract('UnlimitedAllowanceToken', (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 DummyToken.new({ from: owner });
- await token.mint(MAX_MINT_VALUE, { from: owner });
- tokenAddress = token.address;
- });
-
- describe('transfer', () => {
- 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 return false 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);
- const didReturnTrue = await token.transferFrom.call(owner, spender, amountToTransfer, { from: spender });
- expect(didReturnTrue).to.be.false();
- });
-
- it('should return false 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();
-
- 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 });
- 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/unlimited_allowance_token_v2.ts b/packages/contracts/test/unlimited_allowance_token.ts
index 1b29a02ba..34d2ba33b 100644
--- a/packages/contracts/test/ts/unlimited_allowance_token_v2.ts
+++ b/packages/contracts/test/unlimited_allowance_token.ts
@@ -1,37 +1,48 @@
import { ZeroEx } from '0x.js';
+import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils';
import { BigNumber } from '@0xproject/utils';
+import { Web3Wrapper } from '@0xproject/web3-wrapper';
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 { constants } from '../util/constants';
+import { ContractName } from '../util/types';
import { chaiSetup } from './utils/chai_setup';
+import { deployer } from './utils/deployer';
-const { DummyTokenV2 } = new Artifacts(artifacts);
-const web3: Web3 = (global as any).web3;
+const web3 = web3Factory.create();
+const web3Wrapper = new Web3Wrapper(web3.currentProvider);
chaiSetup.configure();
const expect = chai.expect;
+const blockchainLifecycle = new BlockchainLifecycle();
-contract('UnlimitedAllowanceTokenV2', (accounts: string[]) => {
+describe('UnlimitedAllowanceToken', () => {
+ let owner: string;
+ let spender: 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;
+ let token: Web3.ContractInstance;
- beforeEach(async () => {
- token = await DummyTokenV2.new({ from: owner });
+ before(async () => {
+ const accounts = await web3Wrapper.getAvailableAddressesAsync();
+ owner = accounts[0];
+ spender = accounts[1];
+ token = await deployer.deployAsync(ContractName.DummyToken);
await token.mint(MAX_MINT_VALUE, { from: owner });
tokenAddress = token.address;
});
-
+ beforeEach(async () => {
+ await blockchainLifecycle.startAsync();
+ });
+ afterEach(async () => {
+ await blockchainLifecycle.revertAsync();
+ });
describe('transfer', () => {
it('should throw if owner has insufficient balance', async () => {
const ownerBalance = await zeroEx.token.getBalanceAsync(tokenAddress, owner);
diff --git a/packages/contracts/test/ts/utils/chai_setup.ts b/packages/contracts/test/utils/chai_setup.ts
index 078edd309..078edd309 100644
--- a/packages/contracts/test/ts/utils/chai_setup.ts
+++ b/packages/contracts/test/utils/chai_setup.ts
diff --git a/packages/contracts/test/utils/deployer.ts b/packages/contracts/test/utils/deployer.ts
new file mode 100644
index 000000000..dc41e41e2
--- /dev/null
+++ b/packages/contracts/test/utils/deployer.ts
@@ -0,0 +1,16 @@
+import { Deployer } from '@0xproject/deployer';
+import { devConstants } from '@0xproject/dev-utils';
+import * as path from 'path';
+
+import { constants } from '../../util/constants';
+
+const deployerOpts = {
+ artifactsDir: path.resolve('artifacts'),
+ jsonrpcPort: devConstants.RPC_PORT,
+ networkId: constants.TESTRPC_NETWORK_ID,
+ defaults: {
+ gas: devConstants.GAS_ESTIMATE,
+ },
+};
+
+export const deployer = new Deployer(deployerOpts);
diff --git a/packages/contracts/test/ts/zrx_token.ts b/packages/contracts/test/zrx_token.ts
index 766c94c2a..1844a67af 100644
--- a/packages/contracts/test/ts/zrx_token.ts
+++ b/packages/contracts/test/zrx_token.ts
@@ -1,60 +1,70 @@
import { ZeroEx } from '0x.js';
+import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils';
import { BigNumber } from '@0xproject/utils';
+import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as chai from 'chai';
-import Web3 = require('web3');
+import * as Web3 from 'web3';
-import { Artifacts } from '../../util/artifacts';
-import { constants } from '../../util/constants';
-import { ContractInstance } from '../../util/types';
+import { constants } from '../util/constants';
+import { ContractName } from '../util/types';
import { chaiSetup } from './utils/chai_setup';
+import { deployer } from './utils/deployer';
chaiSetup.configure();
const expect = chai.expect;
-const { Exchange, ZRXToken } = new Artifacts(artifacts);
-const web3: Web3 = (global as any).web3;
+const web3 = web3Factory.create();
+const web3Wrapper = new Web3Wrapper(web3.currentProvider);
+const blockchainLifecycle = new BlockchainLifecycle();
-contract('ZRXToken', (accounts: string[]) => {
- const owner = accounts[0];
- const spender = accounts[1];
+describe('ZRXToken', () => {
+ let owner: string;
+ let spender: string;
let zeroEx: ZeroEx;
let MAX_UINT: BigNumber;
- let zrx: ContractInstance;
+ let zrx: Web3.ContractInstance;
let zrxAddress: string;
- beforeEach(async () => {
+ before(async () => {
+ const accounts = await web3Wrapper.getAvailableAddressesAsync();
+ owner = accounts[0];
+ spender = accounts[1];
zeroEx = new ZeroEx(web3.currentProvider, {
- exchangeContractAddress: Exchange.address,
networkId: constants.TESTRPC_NETWORK_ID,
});
- zrx = await ZRXToken.new();
+ zrx = await deployer.deployAsync(ContractName.ZRXToken);
zrxAddress = zrx.address;
MAX_UINT = zeroEx.token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS;
});
-
+ beforeEach(async () => {
+ await blockchainLifecycle.startAsync();
+ });
+ afterEach(async () => {
+ await blockchainLifecycle.revertAsync();
+ });
describe('constants', () => {
it('should have 18 decimals', async () => {
- const decimals = new BigNumber(await zrx.decimals.call());
+ const decimals = new BigNumber(await zrx.decimals());
const expectedDecimals = 18;
expect(decimals).to.be.bignumber.equal(expectedDecimals);
});
it('should have a total supply of 1 billion tokens', async () => {
- const totalSupply = new BigNumber(await zrx.totalSupply.call());
+ const totalSupply = new BigNumber(await zrx.totalSupply());
const expectedTotalSupply = 1000000000;
expect(ZeroEx.toUnitAmount(totalSupply, 18)).to.be.bignumber.equal(expectedTotalSupply);
});
it('should be named 0x Protocol Token', async () => {
- const name = await zrx.name.call();
+ const name = await zrx.name();
const expectedName = '0x Protocol Token';
expect(name).to.be.equal(expectedName);
});
it('should have the symbol ZRX', async () => {
- const symbol = await zrx.symbol.call();
+ const symbol = await zrx.symbol();
const expectedSymbol = 'ZRX';
expect(symbol).to.be.equal(expectedSymbol);
});
@@ -63,7 +73,7 @@ contract('ZRXToken', (accounts: string[]) => {
describe('constructor', () => {
it('should initialize owner balance to totalSupply', async () => {
const ownerBalance = await zeroEx.token.getBalanceAsync(zrxAddress, owner);
- const totalSupply = new BigNumber(await zrx.totalSupply.call());
+ const totalSupply = new BigNumber(await zrx.totalSupply());
expect(totalSupply).to.be.bignumber.equal(ownerBalance);
});
});
@@ -73,8 +83,7 @@ contract('ZRXToken', (accounts: string[]) => {
const receiver = spender;
const initOwnerBalance = await zeroEx.token.getBalanceAsync(zrxAddress, owner);
const amountToTransfer = new BigNumber(1);
- const txHash = await zeroEx.token.transferAsync(zrxAddress, owner, receiver, amountToTransfer);
- await zeroEx.awaitTransactionMinedAsync(txHash);
+ await zeroEx.token.transferAsync(zrxAddress, owner, receiver, amountToTransfer);
const finalOwnerBalance = await zeroEx.token.getBalanceAsync(zrxAddress, owner);
const finalReceiverBalance = await zeroEx.token.getBalanceAsync(zrxAddress, receiver);
@@ -96,10 +105,9 @@ 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);
- const txHash = await zeroEx.token.setAllowanceAsync(zrxAddress, owner, spender, amountToTransfer, {
+ 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 });
expect(didReturnTrue).to.be.false();
});
@@ -126,14 +134,12 @@ 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, {
+ 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, {
+ 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);
@@ -144,12 +150,10 @@ contract('ZRXToken', (accounts: string[]) => {
const initSpenderBalance = await zeroEx.token.getBalanceAsync(zrxAddress, spender);
const amountToTransfer = initOwnerBalance;
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, {
+ await zeroEx.token.setAllowanceAsync(zrxAddress, owner, spender, initSpenderAllowance);
+ 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);
const newSpenderBalance = await zeroEx.token.getBalanceAsync(zrxAddress, spender);
@@ -161,12 +165,10 @@ 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;
- let txHash = await zeroEx.token.setAllowanceAsync(zrxAddress, owner, spender, amountToTransfer);
- await zeroEx.awaitTransactionMinedAsync(txHash);
- txHash = await zeroEx.token.transferFromAsync(zrxAddress, owner, spender, spender, amountToTransfer, {
+ await zeroEx.token.setAllowanceAsync(zrxAddress, owner, spender, amountToTransfer);
+ 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(newSpenderAllowance).to.be.bignumber.equal(0);