Merge branch 'v2-prototype' into refactor/contracts/remove0xjsDep

* v2-prototype:
  Fix tslint issues
  Add `are` to boolean naming conventions
  Fix tslint
  Fix the tsutils version, fixing ts typings issue
  Rename some variables in multi_sig_with_time_lock.ts
  Remove extra awaitTransactionMinedAsync calls
  Update artifacts
  Update yarn.lock
  Fix warnings in Metacoin
  Upgrade UglifyJS to include ES6 support
  Add CancelOrder and MatchOrder types
  Add missing return types
  Ignore classnames linter rule
  Apply changes to test/exchange/match_orders.ts
  Fix some unhandled promise rejections
  Add awaitTransactionMinedAsync after every sent transaction
  Add missing blockchainLifecycle calls to contracts tests

# Conflicts:
#	packages/contracts/src/utils/exchange_wrapper.ts
#	packages/contracts/test/asset_proxy/proxies.ts
#	packages/contracts/test/exchange/dispatcher.ts
#	packages/contracts/test/multi_sig_with_time_lock.ts
This commit is contained in:
Fabio Berger
2018-05-22 13:02:21 -07:00
31 changed files with 526 additions and 221 deletions

View File

@@ -31,6 +31,7 @@ export enum {{contractName}}Events {
{{/if}} {{/if}}
// tslint:disable:no-parameter-reassignment // tslint:disable:no-parameter-reassignment
// tslint:disable-next-line:class-name
export class {{contractName}}Contract extends BaseContract { export class {{contractName}}Contract extends BaseContract {
{{#each methods}} {{#each methods}}
{{#this.constant}} {{#this.constant}}

View File

@@ -20,6 +20,7 @@ export const constants = {
INVALID_OPCODE: 'invalid opcode', INVALID_OPCODE: 'invalid opcode',
REVERT: 'revert', REVERT: 'revert',
TESTRPC_NETWORK_ID: 50, TESTRPC_NETWORK_ID: 50,
AWAIT_TRANSACTION_MINED_MS: 100,
MAX_ETHERTOKEN_WITHDRAW_GAS: 43000, MAX_ETHERTOKEN_WITHDRAW_GAS: 43000,
MAX_TOKEN_TRANSFERFROM_GAS: 80000, MAX_TOKEN_TRANSFERFROM_GAS: 80000,
MAX_TOKEN_APPROVE_GAS: 60000, MAX_TOKEN_APPROVE_GAS: 60000,

View File

@@ -23,7 +23,7 @@ export class ERC20Wrapper {
} }
public async deployDummyTokensAsync(): Promise<DummyERC20TokenContract[]> { public async deployDummyTokensAsync(): Promise<DummyERC20TokenContract[]> {
this._dummyTokenContracts = await Promise.all( this._dummyTokenContracts = await Promise.all(
_.times(constants.NUM_DUMMY_ERC20_TO_DEPLOY, () => _.times(constants.NUM_DUMMY_ERC20_TO_DEPLOY, async () =>
DummyERC20TokenContract.deployFrom0xArtifactAsync( DummyERC20TokenContract.deployFrom0xArtifactAsync(
artifacts.DummyERC20Token, artifacts.DummyERC20Token,
this._provider, this._provider,
@@ -45,7 +45,7 @@ export class ERC20Wrapper {
); );
return this._proxyContract; return this._proxyContract;
} }
public async setBalancesAndAllowancesAsync() { public async setBalancesAndAllowancesAsync(): Promise<void> {
this._validateDummyTokenContractsExistOrThrow(); this._validateDummyTokenContractsExistOrThrow();
this._validateProxyContractExistsOrThrow(); this._validateProxyContractExistsOrThrow();
const setBalancePromises: Array<Promise<string>> = []; const setBalancePromises: Array<Promise<string>> = [];
@@ -103,12 +103,12 @@ export class ERC20Wrapper {
const tokenAddresses = _.map(this._dummyTokenContracts, dummyTokenContract => dummyTokenContract.address); const tokenAddresses = _.map(this._dummyTokenContracts, dummyTokenContract => dummyTokenContract.address);
return tokenAddresses; return tokenAddresses;
} }
private _validateDummyTokenContractsExistOrThrow() { private _validateDummyTokenContractsExistOrThrow(): void {
if (_.isUndefined(this._dummyTokenContracts)) { if (_.isUndefined(this._dummyTokenContracts)) {
throw new Error('Dummy ERC20 tokens not yet deployed, please call "deployDummyTokensAsync"'); throw new Error('Dummy ERC20 tokens not yet deployed, please call "deployDummyTokensAsync"');
} }
} }
private _validateProxyContractExistsOrThrow() { private _validateProxyContractExistsOrThrow(): void {
if (_.isUndefined(this._proxyContract)) { if (_.isUndefined(this._proxyContract)) {
throw new Error('ERC20 proxy contract not yet deployed, please call "deployProxyAsync"'); throw new Error('ERC20 proxy contract not yet deployed, please call "deployProxyAsync"');
} }

View File

@@ -25,7 +25,7 @@ export class ERC721Wrapper {
} }
public async deployDummyTokensAsync(): Promise<DummyERC721TokenContract[]> { public async deployDummyTokensAsync(): Promise<DummyERC721TokenContract[]> {
this._dummyTokenContracts = await Promise.all( this._dummyTokenContracts = await Promise.all(
_.times(constants.NUM_DUMMY_ERC721_TO_DEPLOY, () => _.times(constants.NUM_DUMMY_ERC721_TO_DEPLOY, async () =>
DummyERC721TokenContract.deployFrom0xArtifactAsync( DummyERC721TokenContract.deployFrom0xArtifactAsync(
artifacts.DummyERC721Token, artifacts.DummyERC721Token,
this._provider, this._provider,
@@ -45,7 +45,7 @@ export class ERC721Wrapper {
); );
return this._proxyContract; return this._proxyContract;
} }
public async setBalancesAndAllowancesAsync() { public async setBalancesAndAllowancesAsync(): Promise<void> {
this._validateDummyTokenContractsExistOrThrow(); this._validateDummyTokenContractsExistOrThrow();
this._validateProxyContractExistsOrThrow(); this._validateProxyContractExistsOrThrow();
const setBalancePromises: Array<Promise<string>> = []; const setBalancePromises: Array<Promise<string>> = [];
@@ -125,17 +125,17 @@ export class ERC721Wrapper {
const tokenAddresses = _.map(this._dummyTokenContracts, dummyTokenContract => dummyTokenContract.address); const tokenAddresses = _.map(this._dummyTokenContracts, dummyTokenContract => dummyTokenContract.address);
return tokenAddresses; return tokenAddresses;
} }
private _validateDummyTokenContractsExistOrThrow() { private _validateDummyTokenContractsExistOrThrow(): void {
if (_.isUndefined(this._dummyTokenContracts)) { if (_.isUndefined(this._dummyTokenContracts)) {
throw new Error('Dummy ERC721 tokens not yet deployed, please call "deployDummyTokensAsync"'); throw new Error('Dummy ERC721 tokens not yet deployed, please call "deployDummyTokensAsync"');
} }
} }
private _validateProxyContractExistsOrThrow() { private _validateProxyContractExistsOrThrow(): void {
if (_.isUndefined(this._proxyContract)) { if (_.isUndefined(this._proxyContract)) {
throw new Error('ERC721 proxy contract not yet deployed, please call "deployProxyAsync"'); throw new Error('ERC721 proxy contract not yet deployed, please call "deployProxyAsync"');
} }
} }
private _validateBalancesAndAllowancesSetOrThrow() { private _validateBalancesAndAllowancesSetOrThrow(): void {
if (_.keys(this._initialTokenIdsByOwner).length === 0) { if (_.keys(this._initialTokenIdsByOwner).length === 0) {
throw new Error( throw new Error(
'Dummy ERC721 balances and allowances not yet set, please call "setBalancesAndAllowancesAsync"', 'Dummy ERC721 balances and allowances not yet set, please call "setBalancesAndAllowancesAsync"',

View File

@@ -244,8 +244,8 @@ export class ExchangeWrapper {
const tx = await this._getTxWithDecodedExchangeLogsAsync(txHash); const tx = await this._getTxWithDecodedExchangeLogsAsync(txHash);
return tx; return tx;
} }
private async _getTxWithDecodedExchangeLogsAsync(txHash: string) { private async _getTxWithDecodedExchangeLogsAsync(txHash: string): Promise<TransactionReceiptWithDecodedLogs> {
const tx = await Web3Wrapper.awaitTransactionMinedAsync(txHash); const tx = await Web3Wrapper.awaitTransactionMinedAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS);
tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address); tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address);
tx.logs = _.map(tx.logs, log => this._logDecoder.decodeLogOrThrow(log)); tx.logs = _.map(tx.logs, log => this._logDecoder.decodeLogOrThrow(log));
return tx; return tx;

View File

@@ -5,7 +5,7 @@ import { orderUtils } from './order_utils';
import { BatchCancelOrders, BatchFillOrders, MarketBuyOrders, MarketSellOrders, SignedOrder } from './types'; import { BatchCancelOrders, BatchFillOrders, MarketBuyOrders, MarketSellOrders, SignedOrder } from './types';
export const formatters = { export const formatters = {
createBatchFill(signedOrders: SignedOrder[], takerAssetFillAmounts: BigNumber[] = []) { createBatchFill(signedOrders: SignedOrder[], takerAssetFillAmounts: BigNumber[] = []): BatchFillOrders {
const batchFill: BatchFillOrders = { const batchFill: BatchFillOrders = {
orders: [], orders: [],
signatures: [], signatures: [],
@@ -21,7 +21,7 @@ export const formatters = {
}); });
return batchFill; return batchFill;
}, },
createMarketSellOrders(signedOrders: SignedOrder[], takerAssetFillAmount: BigNumber) { createMarketSellOrders(signedOrders: SignedOrder[], takerAssetFillAmount: BigNumber): MarketSellOrders {
const marketSellOrders: MarketSellOrders = { const marketSellOrders: MarketSellOrders = {
orders: [], orders: [],
signatures: [], signatures: [],
@@ -34,7 +34,7 @@ export const formatters = {
}); });
return marketSellOrders; return marketSellOrders;
}, },
createMarketBuyOrders(signedOrders: SignedOrder[], makerAssetFillAmount: BigNumber) { createMarketBuyOrders(signedOrders: SignedOrder[], makerAssetFillAmount: BigNumber): MarketBuyOrders {
const marketBuyOrders: MarketBuyOrders = { const marketBuyOrders: MarketBuyOrders = {
orders: [], orders: [],
signatures: [], signatures: [],
@@ -47,7 +47,7 @@ export const formatters = {
}); });
return marketBuyOrders; return marketBuyOrders;
}, },
createBatchCancel(signedOrders: SignedOrder[]) { createBatchCancel(signedOrders: SignedOrder[]): BatchCancelOrders {
const batchCancel: BatchCancelOrders = { const batchCancel: BatchCancelOrders = {
orders: [], orders: [],
}; };

View File

@@ -4,7 +4,7 @@ import ethUtil = require('ethereumjs-util');
import * as _ from 'lodash'; import * as _ from 'lodash';
import { crypto } from './crypto'; import { crypto } from './crypto';
import { OrderStruct, SignatureType, SignedOrder, UnsignedOrder } from './types'; import { CancelOrder, MatchOrder, OrderStruct, SignatureType, SignedOrder, UnsignedOrder } from './types';
export const orderUtils = { export const orderUtils = {
createFill: (signedOrder: SignedOrder, takerAssetFillAmount?: BigNumber) => { createFill: (signedOrder: SignedOrder, takerAssetFillAmount?: BigNumber) => {
@@ -15,7 +15,7 @@ export const orderUtils = {
}; };
return fill; return fill;
}, },
createCancel(signedOrder: SignedOrder, takerAssetCancelAmount?: BigNumber) { createCancel(signedOrder: SignedOrder, takerAssetCancelAmount?: BigNumber): CancelOrder {
const cancel = { const cancel = {
order: orderUtils.getOrderStruct(signedOrder), order: orderUtils.getOrderStruct(signedOrder),
takerAssetCancelAmount: takerAssetCancelAmount || signedOrder.takerAssetAmount, takerAssetCancelAmount: takerAssetCancelAmount || signedOrder.takerAssetAmount,
@@ -80,7 +80,7 @@ export const orderUtils = {
const orderHashHex = `0x${orderHashBuff.toString('hex')}`; const orderHashHex = `0x${orderHashBuff.toString('hex')}`;
return orderHashHex; return orderHashHex;
}, },
createMatchOrders(signedOrderLeft: SignedOrder, signedOrderRight: SignedOrder) { createMatchOrders(signedOrderLeft: SignedOrder, signedOrderRight: SignedOrder): MatchOrder {
const fill = { const fill = {
left: orderUtils.getOrderStruct(signedOrderLeft), left: orderUtils.getOrderStruct(signedOrderLeft),
right: orderUtils.getOrderStruct(signedOrderRight), right: orderUtils.getOrderStruct(signedOrderRight),

View File

@@ -197,3 +197,15 @@ export interface ProxyData {
tokenAddress?: string; tokenAddress?: string;
data?: any; data?: any;
} }
export interface CancelOrder {
order: OrderStruct;
takerAssetCancelAmount: BigNumber;
}
export interface MatchOrder {
left: OrderStruct;
right: OrderStruct;
leftSignature: string;
rightSignature: string;
}

View File

@@ -19,6 +19,12 @@ describe('Authorizable', () => {
let notOwner: string; let notOwner: string;
let address: string; let address: string;
let authorizable: MixinAuthorizableContract; let authorizable: MixinAuthorizableContract;
before(async () => {
await blockchainLifecycle.startAsync();
});
after(async () => {
await blockchainLifecycle.revertAsync();
});
before(async () => { before(async () => {
const accounts = await web3Wrapper.getAvailableAddressesAsync(); const accounts = await web3Wrapper.getAvailableAddressesAsync();
owner = address = accounts[0]; owner = address = accounts[0];
@@ -42,12 +48,18 @@ describe('Authorizable', () => {
).to.be.rejectedWith(constants.REVERT); ).to.be.rejectedWith(constants.REVERT);
}); });
it('should allow owner to add an authorized address', async () => { it('should allow owner to add an authorized address', async () => {
await authorizable.addAuthorizedAddress.sendTransactionAsync(address, { from: owner }); await web3Wrapper.awaitTransactionMinedAsync(
await authorizable.addAuthorizedAddress.sendTransactionAsync(address, { from: owner }),
constants.AWAIT_TRANSACTION_MINED_MS,
);
const isAuthorized = await authorizable.authorized.callAsync(address); const isAuthorized = await authorizable.authorized.callAsync(address);
expect(isAuthorized).to.be.true(); expect(isAuthorized).to.be.true();
}); });
it('should throw if owner attempts to authorize a duplicate address', async () => { it('should throw if owner attempts to authorize a duplicate address', async () => {
await authorizable.addAuthorizedAddress.sendTransactionAsync(address, { from: owner }); await web3Wrapper.awaitTransactionMinedAsync(
await authorizable.addAuthorizedAddress.sendTransactionAsync(address, { from: owner }),
constants.AWAIT_TRANSACTION_MINED_MS,
);
return expect( return expect(
authorizable.addAuthorizedAddress.sendTransactionAsync(address, { from: owner }), authorizable.addAuthorizedAddress.sendTransactionAsync(address, { from: owner }),
).to.be.rejectedWith(constants.REVERT); ).to.be.rejectedWith(constants.REVERT);
@@ -56,7 +68,10 @@ describe('Authorizable', () => {
describe('removeAuthorizedAddress', () => { describe('removeAuthorizedAddress', () => {
it('should throw if not called by owner', async () => { it('should throw if not called by owner', async () => {
await authorizable.addAuthorizedAddress.sendTransactionAsync(address, { from: owner }); await web3Wrapper.awaitTransactionMinedAsync(
await authorizable.addAuthorizedAddress.sendTransactionAsync(address, { from: owner }),
constants.AWAIT_TRANSACTION_MINED_MS,
);
return expect( return expect(
authorizable.removeAuthorizedAddress.sendTransactionAsync(address, { authorizable.removeAuthorizedAddress.sendTransactionAsync(address, {
from: notOwner, from: notOwner,
@@ -65,10 +80,16 @@ describe('Authorizable', () => {
}); });
it('should allow owner to remove an authorized address', async () => { it('should allow owner to remove an authorized address', async () => {
await authorizable.addAuthorizedAddress.sendTransactionAsync(address, { from: owner }); await web3Wrapper.awaitTransactionMinedAsync(
await authorizable.removeAuthorizedAddress.sendTransactionAsync(address, { await authorizable.addAuthorizedAddress.sendTransactionAsync(address, { from: owner }),
from: owner, constants.AWAIT_TRANSACTION_MINED_MS,
}); );
await web3Wrapper.awaitTransactionMinedAsync(
await authorizable.removeAuthorizedAddress.sendTransactionAsync(address, {
from: owner,
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
const isAuthorized = await authorizable.authorized.callAsync(address); const isAuthorized = await authorizable.authorized.callAsync(address);
expect(isAuthorized).to.be.false(); expect(isAuthorized).to.be.false();
}); });
@@ -86,16 +107,22 @@ describe('Authorizable', () => {
it('should return all authorized addresses', async () => { it('should return all authorized addresses', async () => {
const initial = await authorizable.getAuthorizedAddresses.callAsync(); const initial = await authorizable.getAuthorizedAddresses.callAsync();
expect(initial).to.have.length(0); expect(initial).to.have.length(0);
await authorizable.addAuthorizedAddress.sendTransactionAsync(address, { await web3Wrapper.awaitTransactionMinedAsync(
from: owner, await authorizable.addAuthorizedAddress.sendTransactionAsync(address, {
}); from: owner,
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
const afterAdd = await authorizable.getAuthorizedAddresses.callAsync(); const afterAdd = await authorizable.getAuthorizedAddresses.callAsync();
expect(afterAdd).to.have.length(1); expect(afterAdd).to.have.length(1);
expect(afterAdd).to.include(address); expect(afterAdd).to.include(address);
await authorizable.removeAuthorizedAddress.sendTransactionAsync(address, { await web3Wrapper.awaitTransactionMinedAsync(
from: owner, await authorizable.removeAuthorizedAddress.sendTransactionAsync(address, {
}); from: owner,
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
const afterRemove = await authorizable.getAuthorizedAddresses.callAsync(); const afterRemove = await authorizable.getAuthorizedAddresses.callAsync();
expect(afterRemove).to.have.length(0); expect(afterRemove).to.have.length(0);
}); });

View File

@@ -36,6 +36,12 @@ describe('Asset Transfer Proxies', () => {
let erc721Wrapper: ERC721Wrapper; let erc721Wrapper: ERC721Wrapper;
let erc721MakerTokenId: BigNumber; let erc721MakerTokenId: BigNumber;
before(async () => {
await blockchainLifecycle.startAsync();
});
after(async () => {
await blockchainLifecycle.revertAsync();
});
before(async () => { before(async () => {
const accounts = await web3Wrapper.getAvailableAddressesAsync(); const accounts = await web3Wrapper.getAvailableAddressesAsync();
const usedAddresses = ([owner, notAuthorized, exchangeAddress, makerAddress, takerAddress] = accounts); const usedAddresses = ([owner, notAuthorized, exchangeAddress, makerAddress, takerAddress] = accounts);
@@ -46,18 +52,24 @@ describe('Asset Transfer Proxies', () => {
[zrxToken] = await erc20Wrapper.deployDummyTokensAsync(); [zrxToken] = await erc20Wrapper.deployDummyTokensAsync();
erc20Proxy = await erc20Wrapper.deployProxyAsync(); erc20Proxy = await erc20Wrapper.deployProxyAsync();
await erc20Wrapper.setBalancesAndAllowancesAsync(); await erc20Wrapper.setBalancesAndAllowancesAsync();
await erc20Proxy.addAuthorizedAddress.sendTransactionAsync(exchangeAddress, { await web3Wrapper.awaitTransactionMinedAsync(
from: owner, await erc20Proxy.addAuthorizedAddress.sendTransactionAsync(exchangeAddress, {
}); from: owner,
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
[erc721Token] = await erc721Wrapper.deployDummyTokensAsync(); [erc721Token] = await erc721Wrapper.deployDummyTokensAsync();
erc721Proxy = await erc721Wrapper.deployProxyAsync(); erc721Proxy = await erc721Wrapper.deployProxyAsync();
await erc721Wrapper.setBalancesAndAllowancesAsync(); await erc721Wrapper.setBalancesAndAllowancesAsync();
const erc721Balances = await erc721Wrapper.getBalancesAsync(); const erc721Balances = await erc721Wrapper.getBalancesAsync();
erc721MakerTokenId = erc721Balances[makerAddress][erc721Token.address][0]; erc721MakerTokenId = erc721Balances[makerAddress][erc721Token.address][0];
await erc721Proxy.addAuthorizedAddress.sendTransactionAsync(exchangeAddress, { await web3Wrapper.awaitTransactionMinedAsync(
from: owner, await erc721Proxy.addAuthorizedAddress.sendTransactionAsync(exchangeAddress, {
}); from: owner,
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
}); });
beforeEach(async () => { beforeEach(async () => {
await blockchainLifecycle.startAsync(); await blockchainLifecycle.startAsync();
@@ -73,12 +85,15 @@ describe('Asset Transfer Proxies', () => {
// Perform a transfer from makerAddress to takerAddress // Perform a transfer from makerAddress to takerAddress
const erc20Balances = await erc20Wrapper.getBalancesAsync(); const erc20Balances = await erc20Wrapper.getBalancesAsync();
const amount = new BigNumber(10); const amount = new BigNumber(10);
await erc20Proxy.transferFrom.sendTransactionAsync( await web3Wrapper.awaitTransactionMinedAsync(
encodedProxyMetadata, await erc20Proxy.transferFrom.sendTransactionAsync(
makerAddress, encodedProxyMetadata,
takerAddress, makerAddress,
amount, takerAddress,
{ from: exchangeAddress }, amount,
{ from: exchangeAddress },
),
constants.AWAIT_TRANSACTION_MINED_MS,
); );
// Verify transfer was successful // Verify transfer was successful
const newBalances = await erc20Wrapper.getBalancesAsync(); const newBalances = await erc20Wrapper.getBalancesAsync();
@@ -96,12 +111,15 @@ describe('Asset Transfer Proxies', () => {
// Perform a transfer from makerAddress to takerAddress // Perform a transfer from makerAddress to takerAddress
const erc20Balances = await erc20Wrapper.getBalancesAsync(); const erc20Balances = await erc20Wrapper.getBalancesAsync();
const amount = new BigNumber(0); const amount = new BigNumber(0);
await erc20Proxy.transferFrom.sendTransactionAsync( await web3Wrapper.awaitTransactionMinedAsync(
encodedProxyMetadata, await erc20Proxy.transferFrom.sendTransactionAsync(
makerAddress, encodedProxyMetadata,
takerAddress, makerAddress,
amount, takerAddress,
{ from: exchangeAddress }, amount,
{ from: exchangeAddress },
),
constants.AWAIT_TRANSACTION_MINED_MS,
); );
// Verify transfer was successful // Verify transfer was successful
const newBalances = await erc20Wrapper.getBalancesAsync(); const newBalances = await erc20Wrapper.getBalancesAsync();
@@ -119,9 +137,12 @@ describe('Asset Transfer Proxies', () => {
// Create allowance less than transfer amount. Set allowance on proxy. // Create allowance less than transfer amount. Set allowance on proxy.
const allowance = new BigNumber(0); const allowance = new BigNumber(0);
const transferAmount = new BigNumber(10); const transferAmount = new BigNumber(10);
await zrxToken.approve.sendTransactionAsync(erc20Proxy.address, allowance, { await web3Wrapper.awaitTransactionMinedAsync(
from: makerAddress, await zrxToken.approve.sendTransactionAsync(erc20Proxy.address, allowance, {
}); from: makerAddress,
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
// Perform a transfer; expect this to fail. // Perform a transfer; expect this to fail.
return expect( return expect(
erc20Proxy.transferFrom.sendTransactionAsync( erc20Proxy.transferFrom.sendTransactionAsync(
@@ -172,7 +193,7 @@ describe('Asset Transfer Proxies', () => {
amounts, amounts,
{ from: exchangeAddress }, { from: exchangeAddress },
); );
const res = await web3Wrapper.awaitTransactionMinedAsync(txHash); const res = await web3Wrapper.awaitTransactionMinedAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS);
const newBalances = await erc20Wrapper.getBalancesAsync(); const newBalances = await erc20Wrapper.getBalancesAsync();
expect(res.logs.length).to.equal(numTransfers); expect(res.logs.length).to.equal(numTransfers);
@@ -193,7 +214,7 @@ describe('Asset Transfer Proxies', () => {
const toAddresses = _.times(numTransfers, () => takerAddress); const toAddresses = _.times(numTransfers, () => takerAddress);
const amounts = _.times(numTransfers, () => amount); const amounts = _.times(numTransfers, () => amount);
expect( return expect(
erc20Proxy.batchTransferFrom.sendTransactionAsync( erc20Proxy.batchTransferFrom.sendTransactionAsync(
assetMetadata, assetMetadata,
fromAddresses, fromAddresses,
@@ -225,12 +246,15 @@ describe('Asset Transfer Proxies', () => {
// Perform a transfer from makerAddress to takerAddress // Perform a transfer from makerAddress to takerAddress
const erc20Balances = await erc20Wrapper.getBalancesAsync(); const erc20Balances = await erc20Wrapper.getBalancesAsync();
const amount = new BigNumber(1); const amount = new BigNumber(1);
await erc721Proxy.transferFrom.sendTransactionAsync( await web3Wrapper.awaitTransactionMinedAsync(
encodedProxyMetadata, await erc721Proxy.transferFrom.sendTransactionAsync(
makerAddress, encodedProxyMetadata,
takerAddress, makerAddress,
amount, takerAddress,
{ from: exchangeAddress }, amount,
{ from: exchangeAddress },
),
constants.AWAIT_TRANSACTION_MINED_MS,
); );
// Verify transfer was successful // Verify transfer was successful
const newOwnerMakerAsset = await erc721Token.ownerOf.callAsync(erc721MakerTokenId); const newOwnerMakerAsset = await erc721Token.ownerOf.callAsync(erc721MakerTokenId);
@@ -290,9 +314,12 @@ describe('Asset Transfer Proxies', () => {
erc721MakerTokenId, erc721MakerTokenId,
); );
// Remove transfer approval for makerAddress. // Remove transfer approval for makerAddress.
await erc721Token.setApprovalForAll.sendTransactionAsync(erc721Proxy.address, false, { await web3Wrapper.awaitTransactionMinedAsync(
from: makerAddress, await erc721Token.setApprovalForAll.sendTransactionAsync(erc721Proxy.address, false, {
}); from: makerAddress,
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
// Perform a transfer; expect this to fail. // Perform a transfer; expect this to fail.
const amount = new BigNumber(1); const amount = new BigNumber(1);
return expect( return expect(
@@ -349,7 +376,7 @@ describe('Asset Transfer Proxies', () => {
amounts, amounts,
{ from: exchangeAddress }, { from: exchangeAddress },
); );
const res = await web3Wrapper.awaitTransactionMinedAsync(txHash); const res = await web3Wrapper.awaitTransactionMinedAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS);
expect(res.logs.length).to.equal(numTransfers); expect(res.logs.length).to.equal(numTransfers);
const newOwnerMakerAssetA = await erc721Token.ownerOf.callAsync(makerTokenIdA); const newOwnerMakerAssetA = await erc721Token.ownerOf.callAsync(makerTokenIdA);
@@ -371,7 +398,7 @@ describe('Asset Transfer Proxies', () => {
const toAddresses = _.times(numTransfers, () => takerAddress); const toAddresses = _.times(numTransfers, () => takerAddress);
const amounts = _.times(numTransfers, () => new BigNumber(1)); const amounts = _.times(numTransfers, () => new BigNumber(1));
expect( return expect(
erc721Proxy.batchTransferFrom.sendTransactionAsync( erc721Proxy.batchTransferFrom.sendTransactionAsync(
assetMetadata, assetMetadata,
fromAddresses, fromAddresses,

View File

@@ -21,6 +21,13 @@ describe('EtherToken', () => {
const gasPrice = Web3Wrapper.toBaseUnitAmount(new BigNumber(20), 9); const gasPrice = Web3Wrapper.toBaseUnitAmount(new BigNumber(20), 9);
let zeroEx: ZeroEx; let zeroEx: ZeroEx;
let etherTokenAddress: string; let etherTokenAddress: string;
before(async () => {
await blockchainLifecycle.startAsync();
});
after(async () => {
await blockchainLifecycle.revertAsync();
});
before(async () => { before(async () => {
const accounts = await web3Wrapper.getAvailableAddressesAsync(); const accounts = await web3Wrapper.getAvailableAddressesAsync();
account = accounts[0]; account = accounts[0];
@@ -55,7 +62,7 @@ describe('EtherToken', () => {
const ethToDeposit = new BigNumber(Web3Wrapper.toWei(new BigNumber(1))); const ethToDeposit = new BigNumber(Web3Wrapper.toWei(new BigNumber(1)));
const txHash = await zeroEx.etherToken.depositAsync(etherTokenAddress, ethToDeposit, account); const txHash = await zeroEx.etherToken.depositAsync(etherTokenAddress, ethToDeposit, account);
const receipt = await zeroEx.awaitTransactionMinedAsync(txHash); const receipt = await zeroEx.awaitTransactionMinedAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS);
const ethSpentOnGas = gasPrice.times(receipt.gasUsed); const ethSpentOnGas = gasPrice.times(receipt.gasUsed);
const finalEthBalance = await web3Wrapper.getBalanceInWeiAsync(account); const finalEthBalance = await web3Wrapper.getBalanceInWeiAsync(account);
@@ -86,7 +93,7 @@ describe('EtherToken', () => {
const txHash = await zeroEx.etherToken.withdrawAsync(etherTokenAddress, ethTokensToWithdraw, account, { const txHash = await zeroEx.etherToken.withdrawAsync(etherTokenAddress, ethTokensToWithdraw, account, {
gasLimit: constants.MAX_ETHERTOKEN_WITHDRAW_GAS, gasLimit: constants.MAX_ETHERTOKEN_WITHDRAW_GAS,
}); });
const receipt = await zeroEx.awaitTransactionMinedAsync(txHash); const receipt = await zeroEx.awaitTransactionMinedAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS);
const ethSpentOnGas = gasPrice.times(receipt.gasUsed); const ethSpentOnGas = gasPrice.times(receipt.gasUsed);
const finalEthBalance = await web3Wrapper.getBalanceInWeiAsync(account); const finalEthBalance = await web3Wrapper.getBalanceInWeiAsync(account);
@@ -113,7 +120,7 @@ describe('EtherToken', () => {
gasPrice, gasPrice,
}); });
const receipt = await zeroEx.awaitTransactionMinedAsync(txHash); const receipt = await zeroEx.awaitTransactionMinedAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS);
const ethSpentOnGas = gasPrice.times(receipt.gasUsed); const ethSpentOnGas = gasPrice.times(receipt.gasUsed);
const finalEthBalance = await web3Wrapper.getBalanceInWeiAsync(account); const finalEthBalance = await web3Wrapper.getBalanceInWeiAsync(account);

View File

@@ -62,6 +62,12 @@ describe('Exchange core', () => {
let zeroEx: ZeroEx; let zeroEx: ZeroEx;
before(async () => {
await blockchainLifecycle.startAsync();
});
after(async () => {
await blockchainLifecycle.revertAsync();
});
before(async () => { before(async () => {
const accounts = await web3Wrapper.getAvailableAddressesAsync(); const accounts = await web3Wrapper.getAvailableAddressesAsync();
const usedAddresses = ([owner, makerAddress, takerAddress, feeRecipientAddress] = accounts); const usedAddresses = ([owner, makerAddress, takerAddress, feeRecipientAddress] = accounts);
@@ -94,12 +100,18 @@ describe('Exchange core', () => {
await exchangeWrapper.registerAssetProxyAsync(AssetProxyId.ERC20, erc20Proxy.address, owner); await exchangeWrapper.registerAssetProxyAsync(AssetProxyId.ERC20, erc20Proxy.address, owner);
await exchangeWrapper.registerAssetProxyAsync(AssetProxyId.ERC721, erc721Proxy.address, owner); await exchangeWrapper.registerAssetProxyAsync(AssetProxyId.ERC721, erc721Proxy.address, owner);
await erc20Proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { await web3Wrapper.awaitTransactionMinedAsync(
from: owner, await erc20Proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, {
}); from: owner,
await erc721Proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { }),
from: owner, constants.AWAIT_TRANSACTION_MINED_MS,
}); );
await web3Wrapper.awaitTransactionMinedAsync(
await erc721Proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, {
from: owner,
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
defaultMakerAssetAddress = erc20TokenA.address; defaultMakerAssetAddress = erc20TokenA.address;
defaultTakerAssetAddress = erc20TokenB.address; defaultTakerAssetAddress = erc20TokenB.address;
@@ -521,23 +533,39 @@ describe('Exchange core', () => {
}); });
it('should throw if maker allowances are too low to fill order', async () => { it('should throw if maker allowances are too low to fill order', async () => {
await erc20TokenA.approve.sendTransactionAsync(erc20Proxy.address, new BigNumber(0), { await web3Wrapper.awaitTransactionMinedAsync(
from: makerAddress, await erc20TokenA.approve.sendTransactionAsync(erc20Proxy.address, new BigNumber(0), {
}); from: makerAddress,
expect(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(constants.REVERT); }),
await erc20TokenA.approve.sendTransactionAsync(erc20Proxy.address, constants.INITIAL_ERC20_ALLOWANCE, { constants.AWAIT_TRANSACTION_MINED_MS,
from: makerAddress, );
}); await expect(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(
constants.REVERT,
);
await web3Wrapper.awaitTransactionMinedAsync(
await erc20TokenA.approve.sendTransactionAsync(erc20Proxy.address, constants.INITIAL_ERC20_ALLOWANCE, {
from: makerAddress,
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
}); });
it('should throw if taker allowances are too low to fill order', async () => { it('should throw if taker allowances are too low to fill order', async () => {
await erc20TokenB.approve.sendTransactionAsync(erc20Proxy.address, new BigNumber(0), { await web3Wrapper.awaitTransactionMinedAsync(
from: takerAddress, await erc20TokenB.approve.sendTransactionAsync(erc20Proxy.address, new BigNumber(0), {
}); from: takerAddress,
expect(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(constants.REVERT); }),
await erc20TokenB.approve.sendTransactionAsync(erc20Proxy.address, constants.INITIAL_ERC20_ALLOWANCE, { constants.AWAIT_TRANSACTION_MINED_MS,
from: takerAddress, );
}); await expect(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(
constants.REVERT,
);
await web3Wrapper.awaitTransactionMinedAsync(
await erc20TokenB.approve.sendTransactionAsync(erc20Proxy.address, constants.INITIAL_ERC20_ALLOWANCE, {
from: takerAddress,
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
}); });
it('should not change erc20Balances if an order is expired', async () => { it('should not change erc20Balances if an order is expired', async () => {

View File

@@ -35,6 +35,12 @@ describe('AssetProxyDispatcher', () => {
let erc20Wrapper: ERC20Wrapper; let erc20Wrapper: ERC20Wrapper;
let erc721Wrapper: ERC721Wrapper; let erc721Wrapper: ERC721Wrapper;
before(async () => {
await blockchainLifecycle.startAsync();
});
after(async () => {
await blockchainLifecycle.revertAsync();
});
before(async () => { before(async () => {
// Setup accounts & addresses // Setup accounts & addresses
const accounts = await web3Wrapper.getAvailableAddressesAsync(); const accounts = await web3Wrapper.getAvailableAddressesAsync();
@@ -55,12 +61,18 @@ describe('AssetProxyDispatcher', () => {
provider, provider,
txDefaults, txDefaults,
); );
await erc20Proxy.addAuthorizedAddress.sendTransactionAsync(assetProxyDispatcher.address, { await web3Wrapper.awaitTransactionMinedAsync(
from: owner, await erc20Proxy.addAuthorizedAddress.sendTransactionAsync(assetProxyDispatcher.address, {
}); from: owner,
await erc721Proxy.addAuthorizedAddress.sendTransactionAsync(assetProxyDispatcher.address, { }),
from: owner, constants.AWAIT_TRANSACTION_MINED_MS,
}); );
await web3Wrapper.awaitTransactionMinedAsync(
await erc721Proxy.addAuthorizedAddress.sendTransactionAsync(assetProxyDispatcher.address, {
from: owner,
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
}); });
beforeEach(async () => { beforeEach(async () => {
await blockchainLifecycle.startAsync(); await blockchainLifecycle.startAsync();
@@ -71,11 +83,14 @@ describe('AssetProxyDispatcher', () => {
describe('registerAssetProxy', () => { describe('registerAssetProxy', () => {
it('should record proxy upon registration', async () => { it('should record proxy upon registration', async () => {
const prevProxyAddress = constants.NULL_ADDRESS; const prevProxyAddress = constants.NULL_ADDRESS;
await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync( await web3Wrapper.awaitTransactionMinedAsync(
AssetProxyId.ERC20, await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync(
erc20Proxy.address, AssetProxyId.ERC20,
prevProxyAddress, erc20Proxy.address,
{ from: owner }, prevProxyAddress,
{ from: owner },
),
constants.AWAIT_TRANSACTION_MINED_MS,
); );
const proxyAddress = await assetProxyDispatcher.getAssetProxy.callAsync(AssetProxyId.ERC20); const proxyAddress = await assetProxyDispatcher.getAssetProxy.callAsync(AssetProxyId.ERC20);
expect(proxyAddress).to.be.equal(erc20Proxy.address); expect(proxyAddress).to.be.equal(erc20Proxy.address);
@@ -84,21 +99,27 @@ describe('AssetProxyDispatcher', () => {
it('should be able to record multiple proxies', async () => { it('should be able to record multiple proxies', async () => {
// Record first proxy // Record first proxy
const prevERC20ProxyAddress = constants.NULL_ADDRESS; const prevERC20ProxyAddress = constants.NULL_ADDRESS;
await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync( await web3Wrapper.awaitTransactionMinedAsync(
AssetProxyId.ERC20, await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync(
erc20Proxy.address, AssetProxyId.ERC20,
prevERC20ProxyAddress, erc20Proxy.address,
{ from: owner }, prevERC20ProxyAddress,
{ from: owner },
),
constants.AWAIT_TRANSACTION_MINED_MS,
); );
let proxyAddress = await assetProxyDispatcher.getAssetProxy.callAsync(AssetProxyId.ERC20); let proxyAddress = await assetProxyDispatcher.getAssetProxy.callAsync(AssetProxyId.ERC20);
expect(proxyAddress).to.be.equal(erc20Proxy.address); expect(proxyAddress).to.be.equal(erc20Proxy.address);
// Record another proxy // Record another proxy
const prevERC721ProxyAddress = constants.NULL_ADDRESS; const prevERC721ProxyAddress = constants.NULL_ADDRESS;
await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync( await web3Wrapper.awaitTransactionMinedAsync(
AssetProxyId.ERC721, await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync(
erc721Proxy.address, AssetProxyId.ERC721,
prevERC721ProxyAddress, erc721Proxy.address,
{ from: owner }, prevERC721ProxyAddress,
{ from: owner },
),
constants.AWAIT_TRANSACTION_MINED_MS,
); );
proxyAddress = await assetProxyDispatcher.getAssetProxy.callAsync(AssetProxyId.ERC721); proxyAddress = await assetProxyDispatcher.getAssetProxy.callAsync(AssetProxyId.ERC721);
expect(proxyAddress).to.be.equal(erc721Proxy.address); expect(proxyAddress).to.be.equal(erc721Proxy.address);
@@ -107,11 +128,14 @@ describe('AssetProxyDispatcher', () => {
it('should replace proxy address upon re-registration', async () => { it('should replace proxy address upon re-registration', async () => {
// Initial registration // Initial registration
const prevProxyAddress = constants.NULL_ADDRESS; const prevProxyAddress = constants.NULL_ADDRESS;
await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync( await web3Wrapper.awaitTransactionMinedAsync(
AssetProxyId.ERC20, await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync(
erc20Proxy.address, AssetProxyId.ERC20,
prevProxyAddress, erc20Proxy.address,
{ from: owner }, prevProxyAddress,
{ from: owner },
),
constants.AWAIT_TRANSACTION_MINED_MS,
); );
let proxyAddress = await assetProxyDispatcher.getAssetProxy.callAsync(AssetProxyId.ERC20); let proxyAddress = await assetProxyDispatcher.getAssetProxy.callAsync(AssetProxyId.ERC20);
expect(proxyAddress).to.be.equal(erc20Proxy.address); expect(proxyAddress).to.be.equal(erc20Proxy.address);
@@ -124,11 +148,14 @@ describe('AssetProxyDispatcher', () => {
// Register new ERC20 Transfer Proxy contract // Register new ERC20 Transfer Proxy contract
const newAddress = newErc20TransferProxy.address; const newAddress = newErc20TransferProxy.address;
const currentAddress = erc20Proxy.address; const currentAddress = erc20Proxy.address;
await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync( await web3Wrapper.awaitTransactionMinedAsync(
AssetProxyId.ERC20, await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync(
newAddress, AssetProxyId.ERC20,
currentAddress, newAddress,
{ from: owner }, currentAddress,
{ from: owner },
),
constants.AWAIT_TRANSACTION_MINED_MS,
); );
// Verify new asset proxy has replaced initial version // Verify new asset proxy has replaced initial version
proxyAddress = await assetProxyDispatcher.getAssetProxy.callAsync(AssetProxyId.ERC20); proxyAddress = await assetProxyDispatcher.getAssetProxy.callAsync(AssetProxyId.ERC20);
@@ -138,11 +165,14 @@ describe('AssetProxyDispatcher', () => {
it('should throw if registering with incorrect "currentAssetProxyAddress" field', async () => { it('should throw if registering with incorrect "currentAssetProxyAddress" field', async () => {
// Initial registration // Initial registration
const prevProxyAddress = constants.NULL_ADDRESS; const prevProxyAddress = constants.NULL_ADDRESS;
await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync( await web3Wrapper.awaitTransactionMinedAsync(
AssetProxyId.ERC20, await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync(
erc20Proxy.address, AssetProxyId.ERC20,
prevProxyAddress, erc20Proxy.address,
{ from: owner }, prevProxyAddress,
{ from: owner },
),
constants.AWAIT_TRANSACTION_MINED_MS,
); );
const proxyAddress = await assetProxyDispatcher.getAssetProxy.callAsync(AssetProxyId.ERC20); const proxyAddress = await assetProxyDispatcher.getAssetProxy.callAsync(AssetProxyId.ERC20);
expect(proxyAddress).to.be.equal(erc20Proxy.address); expect(proxyAddress).to.be.equal(erc20Proxy.address);
@@ -160,21 +190,27 @@ describe('AssetProxyDispatcher', () => {
it('should be able to reset proxy address to NULL', async () => { it('should be able to reset proxy address to NULL', async () => {
// Initial registration // Initial registration
const prevProxyAddress = constants.NULL_ADDRESS; const prevProxyAddress = constants.NULL_ADDRESS;
await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync( await web3Wrapper.awaitTransactionMinedAsync(
AssetProxyId.ERC20, await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync(
erc20Proxy.address, AssetProxyId.ERC20,
prevProxyAddress, erc20Proxy.address,
{ from: owner }, prevProxyAddress,
{ from: owner },
),
constants.AWAIT_TRANSACTION_MINED_MS,
); );
const proxyAddress = await assetProxyDispatcher.getAssetProxy.callAsync(AssetProxyId.ERC20); const proxyAddress = await assetProxyDispatcher.getAssetProxy.callAsync(AssetProxyId.ERC20);
expect(proxyAddress).to.be.equal(erc20Proxy.address); expect(proxyAddress).to.be.equal(erc20Proxy.address);
// The following transaction will reset the proxy address // The following transaction will reset the proxy address
const newProxyAddress = constants.NULL_ADDRESS; const newProxyAddress = constants.NULL_ADDRESS;
await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync( await web3Wrapper.awaitTransactionMinedAsync(
AssetProxyId.ERC20, await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync(
newProxyAddress, AssetProxyId.ERC20,
erc20Proxy.address, newProxyAddress,
{ from: owner }, erc20Proxy.address,
{ from: owner },
),
constants.AWAIT_TRANSACTION_MINED_MS,
); );
const finalProxyAddress = await assetProxyDispatcher.getAssetProxy.callAsync(AssetProxyId.ERC20); const finalProxyAddress = await assetProxyDispatcher.getAssetProxy.callAsync(AssetProxyId.ERC20);
expect(finalProxyAddress).to.be.equal(newProxyAddress); expect(finalProxyAddress).to.be.equal(newProxyAddress);
@@ -208,11 +244,14 @@ describe('AssetProxyDispatcher', () => {
describe('getAssetProxy', () => { describe('getAssetProxy', () => {
it('should return correct address of registered proxy', async () => { it('should return correct address of registered proxy', async () => {
const prevProxyAddress = constants.NULL_ADDRESS; const prevProxyAddress = constants.NULL_ADDRESS;
await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync( await web3Wrapper.awaitTransactionMinedAsync(
AssetProxyId.ERC20, await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync(
erc20Proxy.address, AssetProxyId.ERC20,
prevProxyAddress, erc20Proxy.address,
{ from: owner }, prevProxyAddress,
{ from: owner },
),
constants.AWAIT_TRANSACTION_MINED_MS,
); );
const proxyAddress = await assetProxyDispatcher.getAssetProxy.callAsync(AssetProxyId.ERC20); const proxyAddress = await assetProxyDispatcher.getAssetProxy.callAsync(AssetProxyId.ERC20);
expect(proxyAddress).to.be.equal(erc20Proxy.address); expect(proxyAddress).to.be.equal(erc20Proxy.address);
@@ -228,23 +267,29 @@ describe('AssetProxyDispatcher', () => {
it('should dispatch transfer to registered proxy', async () => { it('should dispatch transfer to registered proxy', async () => {
// Register ERC20 proxy // Register ERC20 proxy
const prevProxyAddress = constants.NULL_ADDRESS; const prevProxyAddress = constants.NULL_ADDRESS;
await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync( await web3Wrapper.awaitTransactionMinedAsync(
AssetProxyId.ERC20, await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync(
erc20Proxy.address, AssetProxyId.ERC20,
prevProxyAddress, erc20Proxy.address,
{ from: owner }, prevProxyAddress,
{ from: owner },
),
constants.AWAIT_TRANSACTION_MINED_MS,
); );
// Construct metadata for ERC20 proxy // Construct metadata for ERC20 proxy
const encodedProxyMetadata = assetProxyUtils.encodeERC20ProxyData(zrxToken.address); const encodedProxyMetadata = assetProxyUtils.encodeERC20ProxyData(zrxToken.address);
// Perform a transfer from makerAddress to takerAddress // Perform a transfer from makerAddress to takerAddress
const erc20Balances = await erc20Wrapper.getBalancesAsync(); const erc20Balances = await erc20Wrapper.getBalancesAsync();
const amount = new BigNumber(10); const amount = new BigNumber(10);
await assetProxyDispatcher.publicDispatchTransferFrom.sendTransactionAsync( await web3Wrapper.awaitTransactionMinedAsync(
encodedProxyMetadata, await assetProxyDispatcher.publicDispatchTransferFrom.sendTransactionAsync(
makerAddress, encodedProxyMetadata,
takerAddress, makerAddress,
amount, takerAddress,
{ from: owner }, amount,
{ from: owner },
),
constants.AWAIT_TRANSACTION_MINED_MS,
); );
// Verify transfer was successful // Verify transfer was successful
const newBalances = await erc20Wrapper.getBalancesAsync(); const newBalances = await erc20Wrapper.getBalancesAsync();

View File

@@ -24,6 +24,12 @@ describe('Exchange libs', () => {
let orderFactory: OrderFactory; let orderFactory: OrderFactory;
let libs: TestLibsContract; let libs: TestLibsContract;
before(async () => {
await blockchainLifecycle.startAsync();
});
after(async () => {
await blockchainLifecycle.revertAsync();
});
before(async () => { before(async () => {
const accounts = await web3Wrapper.getAvailableAddressesAsync(); const accounts = await web3Wrapper.getAvailableAddressesAsync();
const makerAddress = accounts[0]; const makerAddress = accounts[0];

View File

@@ -77,6 +77,12 @@ describe('matchOrders', () => {
let matchOrderTester: MatchOrderTester; let matchOrderTester: MatchOrderTester;
before(async () => {
await blockchainLifecycle.startAsync();
});
after(async () => {
await blockchainLifecycle.revertAsync();
});
before(async () => { before(async () => {
// Create accounts // Create accounts
const accounts = await web3Wrapper.getAvailableAddressesAsync(); const accounts = await web3Wrapper.getAvailableAddressesAsync();
@@ -114,12 +120,18 @@ describe('matchOrders', () => {
await exchangeWrapper.registerAssetProxyAsync(AssetProxyId.ERC20, erc20Proxy.address, owner); await exchangeWrapper.registerAssetProxyAsync(AssetProxyId.ERC20, erc20Proxy.address, owner);
await exchangeWrapper.registerAssetProxyAsync(AssetProxyId.ERC721, erc721Proxy.address, owner); await exchangeWrapper.registerAssetProxyAsync(AssetProxyId.ERC721, erc721Proxy.address, owner);
// Authorize ERC20 and ERC721 trades by exchange // Authorize ERC20 and ERC721 trades by exchange
await erc20Proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { await web3Wrapper.awaitTransactionMinedAsync(
from: owner, await erc20Proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, {
}); from: owner,
await erc721Proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { }),
from: owner, constants.AWAIT_TRANSACTION_MINED_MS,
}); );
await web3Wrapper.awaitTransactionMinedAsync(
await erc721Proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, {
from: owner,
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
// Set default addresses // Set default addresses
defaultERC20MakerAssetAddress = erc20TokenA.address; defaultERC20MakerAssetAddress = erc20TokenA.address;
defaultERC20TakerAssetAddress = erc20TokenB.address; defaultERC20TakerAssetAddress = erc20TokenB.address;

View File

@@ -24,6 +24,12 @@ describe('MixinSignatureValidator', () => {
let orderFactory: OrderFactory; let orderFactory: OrderFactory;
let signatureValidator: TestSignatureValidatorContract; let signatureValidator: TestSignatureValidatorContract;
before(async () => {
await blockchainLifecycle.startAsync();
});
after(async () => {
await blockchainLifecycle.revertAsync();
});
before(async () => { before(async () => {
const accounts = await web3Wrapper.getAvailableAddressesAsync(); const accounts = await web3Wrapper.getAvailableAddressesAsync();
const makerAddress = accounts[0]; const makerAddress = accounts[0];
@@ -60,12 +66,12 @@ describe('MixinSignatureValidator', () => {
it('should return true with a valid signature', async () => { it('should return true with a valid signature', async () => {
const orderHashHex = orderUtils.getOrderHashHex(signedOrder); const orderHashHex = orderUtils.getOrderHashHex(signedOrder);
const success = await signatureValidator.publicIsValidSignature.callAsync( const isValidSignature = await signatureValidator.publicIsValidSignature.callAsync(
orderHashHex, orderHashHex,
signedOrder.makerAddress, signedOrder.makerAddress,
signedOrder.signature, signedOrder.signature,
); );
expect(success).to.be.true(); expect(isValidSignature).to.be.true();
}); });
it('should return false with an invalid signature', async () => { it('should return false with an invalid signature', async () => {
@@ -79,12 +85,12 @@ describe('MixinSignatureValidator', () => {
const invalidSigHex = `0x${invalidSigBuff.toString('hex')}`; const invalidSigHex = `0x${invalidSigBuff.toString('hex')}`;
signedOrder.signature = invalidSigHex; signedOrder.signature = invalidSigHex;
const orderHashHex = orderUtils.getOrderHashHex(signedOrder); const orderHashHex = orderUtils.getOrderHashHex(signedOrder);
const success = await signatureValidator.publicIsValidSignature.callAsync( const isValidSignature = await signatureValidator.publicIsValidSignature.callAsync(
orderHashHex, orderHashHex,
signedOrder.makerAddress, signedOrder.makerAddress,
signedOrder.signature, signedOrder.signature,
); );
expect(success).to.be.false(); expect(isValidSignature).to.be.false();
}); });
}); });
}); });

View File

@@ -57,6 +57,12 @@ describe('Exchange transactions', () => {
let defaultMakerTokenAddress: string; let defaultMakerTokenAddress: string;
let defaultTakerTokenAddress: string; let defaultTakerTokenAddress: string;
before(async () => {
await blockchainLifecycle.startAsync();
});
after(async () => {
await blockchainLifecycle.revertAsync();
});
before(async () => { before(async () => {
const accounts = await web3Wrapper.getAvailableAddressesAsync(); const accounts = await web3Wrapper.getAvailableAddressesAsync();
const usedAddresses = ([owner, senderAddress, makerAddress, takerAddress, feeRecipientAddress] = accounts); const usedAddresses = ([owner, senderAddress, makerAddress, takerAddress, feeRecipientAddress] = accounts);
@@ -76,7 +82,10 @@ describe('Exchange transactions', () => {
exchangeWrapper = new ExchangeWrapper(exchange); exchangeWrapper = new ExchangeWrapper(exchange);
await exchangeWrapper.registerAssetProxyAsync(AssetProxyId.ERC20, erc20Proxy.address, owner); await exchangeWrapper.registerAssetProxyAsync(AssetProxyId.ERC20, erc20Proxy.address, owner);
await erc20Proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { from: owner }); await web3Wrapper.awaitTransactionMinedAsync(
await erc20Proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { from: owner }),
constants.AWAIT_TRANSACTION_MINED_MS,
);
defaultMakerTokenAddress = erc20TokenA.address; defaultMakerTokenAddress = erc20TokenA.address;
defaultTakerTokenAddress = erc20TokenB.address; defaultTakerTokenAddress = erc20TokenB.address;

View File

@@ -53,6 +53,12 @@ describe('Exchange wrappers', () => {
let defaultMakerAssetAddress: string; let defaultMakerAssetAddress: string;
let defaultTakerAssetAddress: string; let defaultTakerAssetAddress: string;
before(async () => {
await blockchainLifecycle.startAsync();
});
after(async () => {
await blockchainLifecycle.revertAsync();
});
before(async () => { before(async () => {
const accounts = await web3Wrapper.getAvailableAddressesAsync(); const accounts = await web3Wrapper.getAvailableAddressesAsync();
const usedAddresses = ([owner, makerAddress, takerAddress, feeRecipientAddress] = accounts); const usedAddresses = ([owner, makerAddress, takerAddress, feeRecipientAddress] = accounts);
@@ -81,12 +87,18 @@ describe('Exchange wrappers', () => {
await exchangeWrapper.registerAssetProxyAsync(AssetProxyId.ERC20, erc20Proxy.address, owner); await exchangeWrapper.registerAssetProxyAsync(AssetProxyId.ERC20, erc20Proxy.address, owner);
await exchangeWrapper.registerAssetProxyAsync(AssetProxyId.ERC721, erc721Proxy.address, owner); await exchangeWrapper.registerAssetProxyAsync(AssetProxyId.ERC721, erc721Proxy.address, owner);
await erc20Proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { await web3Wrapper.awaitTransactionMinedAsync(
from: owner, await erc20Proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, {
}); from: owner,
await erc721Proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { }),
from: owner, constants.AWAIT_TRANSACTION_MINED_MS,
}); );
await web3Wrapper.awaitTransactionMinedAsync(
await erc721Proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, {
from: owner,
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
defaultMakerAssetAddress = erc20TokenA.address; defaultMakerAssetAddress = erc20TokenA.address;
defaultTakerAssetAddress = erc20TokenB.address; defaultTakerAssetAddress = erc20TokenB.address;
@@ -244,13 +256,19 @@ describe('Exchange wrappers', () => {
it('should not change erc20Balances if maker allowances are too low to fill order', async () => { it('should not change erc20Balances if maker allowances are too low to fill order', async () => {
const signedOrder = orderFactory.newSignedOrder(); const signedOrder = orderFactory.newSignedOrder();
await erc20TokenA.approve.sendTransactionAsync(erc20Proxy.address, new BigNumber(0), { await web3Wrapper.awaitTransactionMinedAsync(
from: makerAddress, await erc20TokenA.approve.sendTransactionAsync(erc20Proxy.address, new BigNumber(0), {
}); from: makerAddress,
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
await exchangeWrapper.fillOrderNoThrowAsync(signedOrder, takerAddress); await exchangeWrapper.fillOrderNoThrowAsync(signedOrder, takerAddress);
await erc20TokenA.approve.sendTransactionAsync(erc20Proxy.address, constants.INITIAL_ERC20_ALLOWANCE, { await web3Wrapper.awaitTransactionMinedAsync(
from: makerAddress, await erc20TokenA.approve.sendTransactionAsync(erc20Proxy.address, constants.INITIAL_ERC20_ALLOWANCE, {
}); from: makerAddress,
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
const newBalances = await erc20Wrapper.getBalancesAsync(); const newBalances = await erc20Wrapper.getBalancesAsync();
expect(newBalances).to.be.deep.equal(erc20Balances); expect(newBalances).to.be.deep.equal(erc20Balances);
@@ -258,13 +276,19 @@ describe('Exchange wrappers', () => {
it('should not change erc20Balances if taker allowances are too low to fill order', async () => { it('should not change erc20Balances if taker allowances are too low to fill order', async () => {
const signedOrder = orderFactory.newSignedOrder(); const signedOrder = orderFactory.newSignedOrder();
await erc20TokenB.approve.sendTransactionAsync(erc20Proxy.address, new BigNumber(0), { await web3Wrapper.awaitTransactionMinedAsync(
from: takerAddress, await erc20TokenB.approve.sendTransactionAsync(erc20Proxy.address, new BigNumber(0), {
}); from: takerAddress,
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
await exchangeWrapper.fillOrderNoThrowAsync(signedOrder, takerAddress); await exchangeWrapper.fillOrderNoThrowAsync(signedOrder, takerAddress);
await erc20TokenB.approve.sendTransactionAsync(erc20Proxy.address, constants.INITIAL_ERC20_ALLOWANCE, { await web3Wrapper.awaitTransactionMinedAsync(
from: takerAddress, await erc20TokenB.approve.sendTransactionAsync(erc20Proxy.address, constants.INITIAL_ERC20_ALLOWANCE, {
}); from: takerAddress,
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
const newBalances = await erc20Wrapper.getBalancesAsync(); const newBalances = await erc20Wrapper.getBalancesAsync();
expect(newBalances).to.be.deep.equal(erc20Balances); expect(newBalances).to.be.deep.equal(erc20Balances);

View File

@@ -32,6 +32,12 @@ describe('LibBytes', () => {
const testBytes32 = '0x102030405060708090a0b0c0d0e0f0102030405060708090a0b0c0d0e0f01020'; const testBytes32 = '0x102030405060708090a0b0c0d0e0f0102030405060708090a0b0c0d0e0f01020';
const testUint256 = new BigNumber(testBytes32, 16); const testUint256 = new BigNumber(testBytes32, 16);
before(async () => {
await blockchainLifecycle.startAsync();
});
after(async () => {
await blockchainLifecycle.revertAsync();
});
before(async () => { before(async () => {
// Setup accounts & addresses // Setup accounts & addresses
const accounts = await web3Wrapper.getAvailableAddressesAsync(); const accounts = await web3Wrapper.getAvailableAddressesAsync();

View File

@@ -44,6 +44,12 @@ describe('MultiSigWalletWithTimeLock', () => {
describe('changeTimeLock', () => { describe('changeTimeLock', () => {
describe('initially non-time-locked', async () => { describe('initially non-time-locked', async () => {
before(async () => {
await blockchainLifecycle.startAsync();
});
after(async () => {
await blockchainLifecycle.revertAsync();
});
before('deploy a wallet', async () => { before('deploy a wallet', async () => {
multiSig = await MultiSigWalletWithTimeLockContract.deployFrom0xArtifactAsync( multiSig = await MultiSigWalletWithTimeLockContract.deployFrom0xArtifactAsync(
artifacts.MultiSigWalletWithTimeLock, artifacts.MultiSigWalletWithTimeLock,
@@ -73,8 +79,11 @@ describe('MultiSigWalletWithTimeLock', () => {
args: [SECONDS_TIME_LOCKED.toNumber()], args: [SECONDS_TIME_LOCKED.toNumber()],
}; };
const txHash = await multiSigWrapper.submitTransactionAsync(destination, from, dataParams); const txHash = await multiSigWrapper.submitTransactionAsync(destination, from, dataParams);
const subRes = await web3Wrapper.awaitTransactionMinedAsync(txHash); const txReceipt = await web3Wrapper.awaitTransactionMinedAsync(
const log = abiDecoder.tryToDecodeLogOrNoop(subRes.logs[0]) as LogWithDecodedArgs< txHash,
constants.AWAIT_TRANSACTION_MINED_MS,
);
const log = abiDecoder.tryToDecodeLogOrNoop(txReceipt.logs[0]) as LogWithDecodedArgs<
SubmissionContractEventArgs SubmissionContractEventArgs
>; >;
@@ -93,14 +102,17 @@ describe('MultiSigWalletWithTimeLock', () => {
args: [SECONDS_TIME_LOCKED.toNumber()], args: [SECONDS_TIME_LOCKED.toNumber()],
}; };
let txHash = await multiSigWrapper.submitTransactionAsync(destination, from, dataParams); let txHash = await multiSigWrapper.submitTransactionAsync(destination, from, dataParams);
const subRes = await web3Wrapper.awaitTransactionMinedAsync(txHash); const txReceipt = await web3Wrapper.awaitTransactionMinedAsync(
const log = abiDecoder.tryToDecodeLogOrNoop(subRes.logs[0]) as LogWithDecodedArgs< txHash,
constants.AWAIT_TRANSACTION_MINED_MS,
);
const log = abiDecoder.tryToDecodeLogOrNoop(txReceipt.logs[0]) as LogWithDecodedArgs<
SubmissionContractEventArgs SubmissionContractEventArgs
>; >;
txId = log.args.transactionId; txId = log.args.transactionId;
txHash = await multiSig.confirmTransaction.sendTransactionAsync(txId, { from: owners[1] }); txHash = await multiSig.confirmTransaction.sendTransactionAsync(txId, { from: owners[1] });
const res = await web3Wrapper.awaitTransactionMinedAsync(txHash); const res = await web3Wrapper.awaitTransactionMinedAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS);
expect(res.logs).to.have.length(2); expect(res.logs).to.have.length(2);
const blockNum = await web3Wrapper.getBlockNumberAsync(); const blockNum = await web3Wrapper.getBlockNumberAsync();
@@ -120,18 +132,22 @@ describe('MultiSigWalletWithTimeLock', () => {
args: [SECONDS_TIME_LOCKED.toNumber()], args: [SECONDS_TIME_LOCKED.toNumber()],
}; };
let txHash = await multiSigWrapper.submitTransactionAsync(destination, from, dataParams); let txHash = await multiSigWrapper.submitTransactionAsync(destination, from, dataParams);
const subRes = await web3Wrapper.awaitTransactionMinedAsync(txHash); const txReceipt = await web3Wrapper.awaitTransactionMinedAsync(
const log = abiDecoder.tryToDecodeLogOrNoop(subRes.logs[0]) as LogWithDecodedArgs< txHash,
constants.AWAIT_TRANSACTION_MINED_MS,
);
const log = abiDecoder.tryToDecodeLogOrNoop(txReceipt.logs[0]) as LogWithDecodedArgs<
SubmissionContractEventArgs SubmissionContractEventArgs
>; >;
txId = log.args.transactionId; txId = log.args.transactionId;
txHash = await multiSig.confirmTransaction.sendTransactionAsync(txId, { from: owners[1] }); txHash = await multiSig.confirmTransaction.sendTransactionAsync(txId, { from: owners[1] });
await web3Wrapper.awaitTransactionMinedAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS);
expect(initialSecondsTimeLocked).to.be.equal(0); expect(initialSecondsTimeLocked).to.be.equal(0);
txHash = await multiSig.executeTransaction.sendTransactionAsync(txId, { from: owners[0] }); txHash = await multiSig.executeTransaction.sendTransactionAsync(txId, { from: owners[0] });
const res = await web3Wrapper.awaitTransactionMinedAsync(txHash); const res = await web3Wrapper.awaitTransactionMinedAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS);
expect(res.logs).to.have.length(2); expect(res.logs).to.have.length(2);
const secondsTimeLocked = new BigNumber(await multiSig.secondsTimeLocked.callAsync()); const secondsTimeLocked = new BigNumber(await multiSig.secondsTimeLocked.callAsync());
@@ -139,6 +155,12 @@ describe('MultiSigWalletWithTimeLock', () => {
}); });
}); });
describe('initially time-locked', async () => { describe('initially time-locked', async () => {
before(async () => {
await blockchainLifecycle.startAsync();
});
after(async () => {
await blockchainLifecycle.revertAsync();
});
before('deploy a wallet', async () => { before('deploy a wallet', async () => {
multiSig = await MultiSigWalletWithTimeLockContract.deployFrom0xArtifactAsync( multiSig = await MultiSigWalletWithTimeLockContract.deployFrom0xArtifactAsync(
artifacts.MultiSigWalletWithTimeLock, artifacts.MultiSigWalletWithTimeLock,
@@ -160,16 +182,19 @@ describe('MultiSigWalletWithTimeLock', () => {
args: [newSecondsTimeLocked], args: [newSecondsTimeLocked],
}; };
let txHash = await multiSigWrapper.submitTransactionAsync(destination, from, dataParams); let txHash = await multiSigWrapper.submitTransactionAsync(destination, from, dataParams);
const subRes = await web3Wrapper.awaitTransactionMinedAsync(txHash); let txReceipt = await web3Wrapper.awaitTransactionMinedAsync(
const log = abiDecoder.tryToDecodeLogOrNoop(subRes.logs[0]) as LogWithDecodedArgs< txHash,
constants.AWAIT_TRANSACTION_MINED_MS,
);
const log = abiDecoder.tryToDecodeLogOrNoop(txReceipt.logs[0]) as LogWithDecodedArgs<
SubmissionContractEventArgs SubmissionContractEventArgs
>; >;
txId = log.args.transactionId; txId = log.args.transactionId;
txHash = await multiSig.confirmTransaction.sendTransactionAsync(txId, { txHash = await multiSig.confirmTransaction.sendTransactionAsync(txId, {
from: owners[1], from: owners[1],
}); });
const confRes = await web3Wrapper.awaitTransactionMinedAsync(txHash); txReceipt = await web3Wrapper.awaitTransactionMinedAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS);
expect(confRes.logs).to.have.length(2); expect(txReceipt.logs).to.have.length(2);
}); });
const newSecondsTimeLocked = 0; const newSecondsTimeLocked = 0;
it('should throw if it has enough confirmations but is not past the time lock', async () => { it('should throw if it has enough confirmations but is not past the time lock', async () => {
@@ -180,7 +205,10 @@ describe('MultiSigWalletWithTimeLock', () => {
it('should execute if it has enough confirmations and is past the time lock', async () => { it('should execute if it has enough confirmations and is past the time lock', async () => {
await web3Wrapper.increaseTimeAsync(SECONDS_TIME_LOCKED.toNumber()); await web3Wrapper.increaseTimeAsync(SECONDS_TIME_LOCKED.toNumber());
await multiSig.executeTransaction.sendTransactionAsync(txId, { from: owners[0] }); await web3Wrapper.awaitTransactionMinedAsync(
await multiSig.executeTransaction.sendTransactionAsync(txId, { from: owners[0] }),
constants.AWAIT_TRANSACTION_MINED_MS,
);
const secondsTimeLocked = new BigNumber(await multiSig.secondsTimeLocked.callAsync()); const secondsTimeLocked = new BigNumber(await multiSig.secondsTimeLocked.callAsync());
expect(secondsTimeLocked).to.be.bignumber.equal(newSecondsTimeLocked); expect(secondsTimeLocked).to.be.bignumber.equal(newSecondsTimeLocked);

View File

@@ -23,6 +23,12 @@ describe('TokenRegistry', () => {
let notOwner: string; let notOwner: string;
let tokenReg: TokenRegistryContract; let tokenReg: TokenRegistryContract;
let tokenRegWrapper: TokenRegWrapper; let tokenRegWrapper: TokenRegWrapper;
before(async () => {
await blockchainLifecycle.startAsync();
});
after(async () => {
await blockchainLifecycle.revertAsync();
});
before(async () => { before(async () => {
const accounts = await web3Wrapper.getAvailableAddressesAsync(); const accounts = await web3Wrapper.getAvailableAddressesAsync();
owner = accounts[0]; owner = accounts[0];
@@ -136,9 +142,12 @@ describe('TokenRegistry', () => {
}); });
it('should change the token name when called by owner', async () => { it('should change the token name when called by owner', async () => {
await tokenReg.setTokenName.sendTransactionAsync(token1.address, token2.name, { await web3Wrapper.awaitTransactionMinedAsync(
from: owner, await tokenReg.setTokenName.sendTransactionAsync(token1.address, token2.name, {
}); from: owner,
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
const [newData, oldData] = await Promise.all([ const [newData, oldData] = await Promise.all([
tokenRegWrapper.getTokenByNameAsync(token2.name), tokenRegWrapper.getTokenByNameAsync(token2.name),
tokenRegWrapper.getTokenByNameAsync(token1.name), tokenRegWrapper.getTokenByNameAsync(token1.name),
@@ -175,7 +184,10 @@ describe('TokenRegistry', () => {
}); });
it('should change the token symbol when called by owner', async () => { it('should change the token symbol when called by owner', async () => {
await tokenReg.setTokenSymbol.sendTransactionAsync(token1.address, token2.symbol, { from: owner }); await web3Wrapper.awaitTransactionMinedAsync(
await tokenReg.setTokenSymbol.sendTransactionAsync(token1.address, token2.symbol, { from: owner }),
constants.AWAIT_TRANSACTION_MINED_MS,
);
const [newData, oldData] = await Promise.all([ const [newData, oldData] = await Promise.all([
tokenRegWrapper.getTokenBySymbolAsync(token2.symbol), tokenRegWrapper.getTokenBySymbolAsync(token2.symbol),
tokenRegWrapper.getTokenBySymbolAsync(token1.symbol), tokenRegWrapper.getTokenBySymbolAsync(token1.symbol),
@@ -216,9 +228,12 @@ describe('TokenRegistry', () => {
it('should remove token metadata when called by owner', async () => { it('should remove token metadata when called by owner', async () => {
const index = new BigNumber(0); const index = new BigNumber(0);
await tokenReg.removeToken.sendTransactionAsync(token1.address, index, { await web3Wrapper.awaitTransactionMinedAsync(
from: owner, await tokenReg.removeToken.sendTransactionAsync(token1.address, index, {
}); from: owner,
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
const tokenData = await tokenRegWrapper.getTokenMetaDataAsync(token1.address); const tokenData = await tokenRegWrapper.getTokenMetaDataAsync(token1.address);
expect(tokenData).to.be.deep.equal(nullToken); expect(tokenData).to.be.deep.equal(nullToken);
}); });

View File

@@ -27,6 +27,12 @@ describe('UnlimitedAllowanceToken', () => {
let tokenAddress: string; let tokenAddress: string;
let token: DummyERC20TokenContract; let token: DummyERC20TokenContract;
before(async () => {
await blockchainLifecycle.startAsync();
});
after(async () => {
await blockchainLifecycle.revertAsync();
});
before(async () => { before(async () => {
const accounts = await web3Wrapper.getAvailableAddressesAsync(); const accounts = await web3Wrapper.getAvailableAddressesAsync();
owner = accounts[0]; owner = accounts[0];
@@ -40,7 +46,10 @@ describe('UnlimitedAllowanceToken', () => {
constants.DUMMY_TOKEN_DECIMALS, constants.DUMMY_TOKEN_DECIMALS,
constants.DUMMY_TOKEN_TOTAL_SUPPLY, constants.DUMMY_TOKEN_TOTAL_SUPPLY,
); );
await token.mint.sendTransactionAsync(MAX_MINT_VALUE, { from: owner }); await web3Wrapper.awaitTransactionMinedAsync(
await token.mint.sendTransactionAsync(MAX_MINT_VALUE, { from: owner }),
constants.AWAIT_TRANSACTION_MINED_MS,
);
tokenAddress = token.address; tokenAddress = token.address;
}); });
beforeEach(async () => { beforeEach(async () => {

View File

@@ -55,10 +55,10 @@ export class MatchOrderTester {
realERC20BalancesByOwner: ERC20BalancesByOwner, realERC20BalancesByOwner: ERC20BalancesByOwner,
expectedNewERC721TokenIdsByOwner: ERC721TokenIdsByOwner, expectedNewERC721TokenIdsByOwner: ERC721TokenIdsByOwner,
realERC721TokenIdsByOwner: ERC721TokenIdsByOwner, realERC721TokenIdsByOwner: ERC721TokenIdsByOwner,
) { ): boolean {
// ERC20 Balances // ERC20 Balances
const erc20BalancesMatch = _.isEqual(expectedNewERC20BalancesByOwner, realERC20BalancesByOwner); const doesErc20BalancesMatch = _.isEqual(expectedNewERC20BalancesByOwner, realERC20BalancesByOwner);
if (!erc20BalancesMatch) { if (!doesErc20BalancesMatch) {
return false; return false;
} }
// ERC721 Token Ids // ERC721 Token Ids
@@ -75,8 +75,11 @@ export class MatchOrderTester {
_.sortBy(tokenIds); _.sortBy(tokenIds);
}); });
}); });
const erc721TokenIdsMatch = _.isEqual(sortedExpectedNewERC721TokenIdsByOwner, sortedNewERC721TokenIdsByOwner); const doesErc721TokenIdsMatch = _.isEqual(
return erc721TokenIdsMatch; sortedExpectedNewERC721TokenIdsByOwner,
sortedNewERC721TokenIdsByOwner,
);
return doesErc721TokenIdsMatch;
} }
/// @dev Constructs new MatchOrderTester. /// @dev Constructs new MatchOrderTester.
/// @param exchangeWrapper Used to call to the Exchange. /// @param exchangeWrapper Used to call to the Exchange.
@@ -156,13 +159,13 @@ export class MatchOrderTester {
expectedTransferAmounts, expectedTransferAmounts,
); );
// Assert our expected balances are equal to the actual balances // Assert our expected balances are equal to the actual balances
const expectedBalancesMatchRealBalances = MatchOrderTester._compareExpectedAndRealBalances( const didExpectedBalancesMatchRealBalances = MatchOrderTester._compareExpectedAndRealBalances(
expectedERC20BalancesByOwner, expectedERC20BalancesByOwner,
newERC20BalancesByOwner, newERC20BalancesByOwner,
expectedERC721TokenIdsByOwner, expectedERC721TokenIdsByOwner,
newERC721TokenIdsByOwner, newERC721TokenIdsByOwner,
); );
expect(expectedBalancesMatchRealBalances).to.be.true(); expect(didExpectedBalancesMatchRealBalances).to.be.true();
return [newERC20BalancesByOwner, newERC721TokenIdsByOwner]; return [newERC20BalancesByOwner, newERC721TokenIdsByOwner];
} }
/// @dev Calculates expected transfer amounts between order makers, fee recipients, and /// @dev Calculates expected transfer amounts between order makers, fee recipients, and

View File

@@ -26,6 +26,12 @@ describe('ZRXToken', () => {
let zrxToken: ZRXTokenContract; let zrxToken: ZRXTokenContract;
let zrxAddress: string; let zrxAddress: string;
before(async () => {
await blockchainLifecycle.startAsync();
});
after(async () => {
await blockchainLifecycle.revertAsync();
});
before(async () => { before(async () => {
const accounts = await web3Wrapper.getAvailableAddressesAsync(); const accounts = await web3Wrapper.getAvailableAddressesAsync();
owner = accounts[0]; owner = accounts[0];

View File

@@ -1,4 +1,4 @@
pragma solidity ^0.4.21; pragma solidity ^0.4.24;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
contract Metacoin { contract Metacoin {
@@ -16,7 +16,7 @@ contract Metacoin {
uint32 callback; uint32 callback;
} }
function Metacoin() public { constructor () public {
balances[msg.sender] = 10000; balances[msg.sender] = 10000;
} }
@@ -24,7 +24,7 @@ contract Metacoin {
if (balances[msg.sender] < transferData.amount) return false; if (balances[msg.sender] < transferData.amount) return false;
balances[msg.sender] -= transferData.amount; balances[msg.sender] -= transferData.amount;
balances[transferData.to] += transferData.amount; balances[transferData.to] += transferData.amount;
Transfer(msg.sender, transferData.to, transferData.amount); emit Transfer(msg.sender, transferData.to, transferData.amount);
return true; return true;
} }

View File

@@ -2,7 +2,7 @@ import * as _ from 'lodash';
import * as Lint from 'tslint'; import * as Lint from 'tslint';
import * as ts from 'typescript'; import * as ts from 'typescript';
const VALID_BOOLEAN_PREFIXES = ['is', 'does', 'should', 'was', 'has', 'can', 'did', 'would']; const VALID_BOOLEAN_PREFIXES = ['is', 'does', 'should', 'was', 'has', 'can', 'did', 'would', 'are'];
export class Rule extends Lint.Rules.TypedRule { export class Rule extends Lint.Rules.TypedRule {
public static FAILURE_STRING = `Boolean variable names should begin with: ${VALID_BOOLEAN_PREFIXES.join(', ')}`; public static FAILURE_STRING = `Boolean variable names should begin with: ${VALID_BOOLEAN_PREFIXES.join(', ')}`;

View File

@@ -88,6 +88,7 @@
"tslint": "5.8.0", "tslint": "5.8.0",
"tslint-config-0xproject": "^0.0.2", "tslint-config-0xproject": "^0.0.2",
"typescript": "2.7.1", "typescript": "2.7.1",
"uglifyjs-webpack-plugin": "^1.2.5",
"webpack": "^3.1.0", "webpack": "^3.1.0",
"webpack-dev-middleware": "^1.10.0", "webpack-dev-middleware": "^1.10.0",
"webpack-dev-server": "^2.5.0" "webpack-dev-server": "^2.5.0"

View File

@@ -61,13 +61,13 @@ export const Menu: React.StatelessComponent<MenuProps> = (props: MenuProps) => {
return ( return (
<div> <div>
{_.map(props.menuItemEntries, entry => { {_.map(props.menuItemEntries, entry => {
const selected = entry.to === props.selectedPath; const isSelected = entry.to === props.selectedPath;
return ( return (
<MenuItem key={entry.to} to={entry.to}> <MenuItem key={entry.to} to={entry.to}>
<MenuItemLabel <MenuItemLabel
title={entry.labelText} title={entry.labelText}
iconName={entry.iconName} iconName={entry.iconName}
selected={selected} selected={isSelected}
theme={props.theme} theme={props.theme}
/> />
</MenuItem> </MenuItem>

View File

@@ -466,8 +466,8 @@ export class Portal extends React.Component<PortalProps, PortalState> {
this.props.dispatcher.updateScreenWidth(newScreenWidth); this.props.dispatcher.updateScreenWidth(newScreenWidth);
} }
private _isSmallScreen(): boolean { private _isSmallScreen(): boolean {
const result = this.props.screenWidth === ScreenWidths.Sm; const isSmallScreen = this.props.screenWidth === ScreenWidths.Sm;
return result; return isSmallScreen;
} }
} }

View File

@@ -1,5 +1,6 @@
const path = require('path'); const path = require('path');
const webpack = require('webpack'); const webpack = require('webpack');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
module.exports = { module.exports = {
entry: ['./ts/index.tsx'], entry: ['./ts/index.tsx'],
@@ -76,9 +77,14 @@ module.exports = {
NODE_ENV: JSON.stringify(process.env.NODE_ENV), NODE_ENV: JSON.stringify(process.env.NODE_ENV),
}, },
}), }),
new webpack.optimize.UglifyJsPlugin({ // TODO: Revert to webpack bundled version with webpack v4.
mangle: { // The v3 series bundled version does not support ES6 and
except: ['BigNumber'], // fails to build.
new UglifyJsPlugin({
uglifyOptions: {
mangle: {
reserved: ['BigNumber'],
},
}, },
}), }),
] ]

View File

@@ -2569,7 +2569,7 @@ commander@2.12.2:
version "2.12.2" version "2.12.2"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.12.2.tgz#0f5946c427ed9ec0d91a46bb9def53e54650e555" resolved "https://registry.yarnpkg.com/commander/-/commander-2.12.2.tgz#0f5946c427ed9ec0d91a46bb9def53e54650e555"
commander@2.13.0: commander@2.13.0, commander@~2.13.0:
version "2.13.0" version "2.13.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.13.0.tgz#6964bca67685df7c1f1430c584f07d7597885b9c" resolved "https://registry.yarnpkg.com/commander/-/commander-2.13.0.tgz#6964bca67685df7c1f1430c584f07d7597885b9c"
@@ -3753,7 +3753,7 @@ envinfo@^4.4.2:
version "4.4.2" version "4.4.2"
resolved "https://registry.yarnpkg.com/envinfo/-/envinfo-4.4.2.tgz#472c49f3a8b9bca73962641ce7cb692bf623cd1c" resolved "https://registry.yarnpkg.com/envinfo/-/envinfo-4.4.2.tgz#472c49f3a8b9bca73962641ce7cb692bf623cd1c"
errno@^0.1.1, errno@^0.1.3, errno@~0.1.1: errno@^0.1.1, errno@^0.1.3, errno@~0.1.1, errno@~0.1.7:
version "0.1.7" version "0.1.7"
resolved "https://registry.yarnpkg.com/errno/-/errno-0.1.7.tgz#4684d71779ad39af177e3f007996f7c67c852618" resolved "https://registry.yarnpkg.com/errno/-/errno-0.1.7.tgz#4684d71779ad39af177e3f007996f7c67c852618"
dependencies: dependencies:
@@ -11748,6 +11748,13 @@ ua-parser-js@^0.7.9:
version "0.7.17" version "0.7.17"
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.17.tgz#e9ec5f9498b9ec910e7ae3ac626a805c4d09ecac" resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.17.tgz#e9ec5f9498b9ec910e7ae3ac626a805c4d09ecac"
uglify-es@^3.3.4:
version "3.3.9"
resolved "https://registry.yarnpkg.com/uglify-es/-/uglify-es-3.3.9.tgz#0c1c4f0700bed8dbc124cdb304d2592ca203e677"
dependencies:
commander "~2.13.0"
source-map "~0.6.1"
uglify-js@^2.6, uglify-js@^2.8.29: uglify-js@^2.6, uglify-js@^2.8.29:
version "2.8.29" version "2.8.29"
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-2.8.29.tgz#29c5733148057bb4e1f75df35b7a9cb72e6a59dd" resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-2.8.29.tgz#29c5733148057bb4e1f75df35b7a9cb72e6a59dd"
@@ -11769,6 +11776,19 @@ uglifyjs-webpack-plugin@^0.4.6:
uglify-js "^2.8.29" uglify-js "^2.8.29"
webpack-sources "^1.0.1" webpack-sources "^1.0.1"
uglifyjs-webpack-plugin@^1.2.5:
version "1.2.5"
resolved "https://registry.yarnpkg.com/uglifyjs-webpack-plugin/-/uglifyjs-webpack-plugin-1.2.5.tgz#2ef8387c8f1a903ec5e44fa36f9f3cbdcea67641"
dependencies:
cacache "^10.0.4"
find-cache-dir "^1.0.0"
schema-utils "^0.4.5"
serialize-javascript "^1.4.0"
source-map "^0.6.1"
uglify-es "^3.3.4"
webpack-sources "^1.1.0"
worker-farm "^1.5.2"
uid-number@^0.0.6: uid-number@^0.0.6:
version "0.0.6" version "0.0.6"
resolved "https://registry.yarnpkg.com/uid-number/-/uid-number-0.0.6.tgz#0ea10e8035e8eb5b8e4449f06da1c730663baa81" resolved "https://registry.yarnpkg.com/uid-number/-/uid-number-0.0.6.tgz#0ea10e8035e8eb5b8e4449f06da1c730663baa81"
@@ -12628,7 +12648,7 @@ webpack-node-externals@^1.6.0:
version "1.7.2" version "1.7.2"
resolved "https://registry.yarnpkg.com/webpack-node-externals/-/webpack-node-externals-1.7.2.tgz#6e1ee79ac67c070402ba700ef033a9b8d52ac4e3" resolved "https://registry.yarnpkg.com/webpack-node-externals/-/webpack-node-externals-1.7.2.tgz#6e1ee79ac67c070402ba700ef033a9b8d52ac4e3"
webpack-sources@^1.0.1: webpack-sources@^1.0.1, webpack-sources@^1.1.0:
version "1.1.0" version "1.1.0"
resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-1.1.0.tgz#a101ebae59d6507354d71d8013950a3a8b7a5a54" resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-1.1.0.tgz#a101ebae59d6507354d71d8013950a3a8b7a5a54"
dependencies: dependencies:
@@ -12765,6 +12785,12 @@ wordwrap@~0.0.2:
version "0.0.3" version "0.0.3"
resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-0.0.3.tgz#a3d5da6cd5c0bc0008d37234bbaf1bed63059107" resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-0.0.3.tgz#a3d5da6cd5c0bc0008d37234bbaf1bed63059107"
worker-farm@^1.5.2:
version "1.6.0"
resolved "https://registry.yarnpkg.com/worker-farm/-/worker-farm-1.6.0.tgz#aecc405976fab5a95526180846f0dba288f3a4a0"
dependencies:
errno "~0.1.7"
wrap-ansi@^2.0.0: wrap-ansi@^2.0.0:
version "2.1.0" version "2.1.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-2.1.0.tgz#d8fc3d284dd05794fe84973caecdd1cf824fdd85" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-2.1.0.tgz#d8fc3d284dd05794fe84973caecdd1cf824fdd85"