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}}
// tslint:disable:no-parameter-reassignment
// tslint:disable-next-line:class-name
export class {{contractName}}Contract extends BaseContract {
{{#each methods}}
{{#this.constant}}

View File

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

View File

@@ -23,7 +23,7 @@ export class ERC20Wrapper {
}
public async deployDummyTokensAsync(): Promise<DummyERC20TokenContract[]> {
this._dummyTokenContracts = await Promise.all(
_.times(constants.NUM_DUMMY_ERC20_TO_DEPLOY, () =>
_.times(constants.NUM_DUMMY_ERC20_TO_DEPLOY, async () =>
DummyERC20TokenContract.deployFrom0xArtifactAsync(
artifacts.DummyERC20Token,
this._provider,
@@ -45,7 +45,7 @@ export class ERC20Wrapper {
);
return this._proxyContract;
}
public async setBalancesAndAllowancesAsync() {
public async setBalancesAndAllowancesAsync(): Promise<void> {
this._validateDummyTokenContractsExistOrThrow();
this._validateProxyContractExistsOrThrow();
const setBalancePromises: Array<Promise<string>> = [];
@@ -103,12 +103,12 @@ export class ERC20Wrapper {
const tokenAddresses = _.map(this._dummyTokenContracts, dummyTokenContract => dummyTokenContract.address);
return tokenAddresses;
}
private _validateDummyTokenContractsExistOrThrow() {
private _validateDummyTokenContractsExistOrThrow(): void {
if (_.isUndefined(this._dummyTokenContracts)) {
throw new Error('Dummy ERC20 tokens not yet deployed, please call "deployDummyTokensAsync"');
}
}
private _validateProxyContractExistsOrThrow() {
private _validateProxyContractExistsOrThrow(): void {
if (_.isUndefined(this._proxyContract)) {
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[]> {
this._dummyTokenContracts = await Promise.all(
_.times(constants.NUM_DUMMY_ERC721_TO_DEPLOY, () =>
_.times(constants.NUM_DUMMY_ERC721_TO_DEPLOY, async () =>
DummyERC721TokenContract.deployFrom0xArtifactAsync(
artifacts.DummyERC721Token,
this._provider,
@@ -45,7 +45,7 @@ export class ERC721Wrapper {
);
return this._proxyContract;
}
public async setBalancesAndAllowancesAsync() {
public async setBalancesAndAllowancesAsync(): Promise<void> {
this._validateDummyTokenContractsExistOrThrow();
this._validateProxyContractExistsOrThrow();
const setBalancePromises: Array<Promise<string>> = [];
@@ -125,17 +125,17 @@ export class ERC721Wrapper {
const tokenAddresses = _.map(this._dummyTokenContracts, dummyTokenContract => dummyTokenContract.address);
return tokenAddresses;
}
private _validateDummyTokenContractsExistOrThrow() {
private _validateDummyTokenContractsExistOrThrow(): void {
if (_.isUndefined(this._dummyTokenContracts)) {
throw new Error('Dummy ERC721 tokens not yet deployed, please call "deployDummyTokensAsync"');
}
}
private _validateProxyContractExistsOrThrow() {
private _validateProxyContractExistsOrThrow(): void {
if (_.isUndefined(this._proxyContract)) {
throw new Error('ERC721 proxy contract not yet deployed, please call "deployProxyAsync"');
}
}
private _validateBalancesAndAllowancesSetOrThrow() {
private _validateBalancesAndAllowancesSetOrThrow(): void {
if (_.keys(this._initialTokenIdsByOwner).length === 0) {
throw new Error(
'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);
return tx;
}
private async _getTxWithDecodedExchangeLogsAsync(txHash: string) {
const tx = await Web3Wrapper.awaitTransactionMinedAsync(txHash);
private async _getTxWithDecodedExchangeLogsAsync(txHash: string): Promise<TransactionReceiptWithDecodedLogs> {
const tx = await Web3Wrapper.awaitTransactionMinedAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS);
tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address);
tx.logs = _.map(tx.logs, log => this._logDecoder.decodeLogOrThrow(log));
return tx;

View File

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

View File

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

View File

@@ -197,3 +197,15 @@ export interface ProxyData {
tokenAddress?: string;
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 address: string;
let authorizable: MixinAuthorizableContract;
before(async () => {
await blockchainLifecycle.startAsync();
});
after(async () => {
await blockchainLifecycle.revertAsync();
});
before(async () => {
const accounts = await web3Wrapper.getAvailableAddressesAsync();
owner = address = accounts[0];
@@ -42,12 +48,18 @@ describe('Authorizable', () => {
).to.be.rejectedWith(constants.REVERT);
});
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);
expect(isAuthorized).to.be.true();
});
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(
authorizable.addAuthorizedAddress.sendTransactionAsync(address, { from: owner }),
).to.be.rejectedWith(constants.REVERT);
@@ -56,7 +68,10 @@ describe('Authorizable', () => {
describe('removeAuthorizedAddress', () => {
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(
authorizable.removeAuthorizedAddress.sendTransactionAsync(address, {
from: notOwner,
@@ -65,10 +80,16 @@ describe('Authorizable', () => {
});
it('should allow owner to remove 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,
);
await web3Wrapper.awaitTransactionMinedAsync(
await authorizable.removeAuthorizedAddress.sendTransactionAsync(address, {
from: owner,
});
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
const isAuthorized = await authorizable.authorized.callAsync(address);
expect(isAuthorized).to.be.false();
});
@@ -86,16 +107,22 @@ describe('Authorizable', () => {
it('should return all authorized addresses', async () => {
const initial = await authorizable.getAuthorizedAddresses.callAsync();
expect(initial).to.have.length(0);
await web3Wrapper.awaitTransactionMinedAsync(
await authorizable.addAuthorizedAddress.sendTransactionAsync(address, {
from: owner,
});
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
const afterAdd = await authorizable.getAuthorizedAddresses.callAsync();
expect(afterAdd).to.have.length(1);
expect(afterAdd).to.include(address);
await web3Wrapper.awaitTransactionMinedAsync(
await authorizable.removeAuthorizedAddress.sendTransactionAsync(address, {
from: owner,
});
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
const afterRemove = await authorizable.getAuthorizedAddresses.callAsync();
expect(afterRemove).to.have.length(0);
});

View File

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

View File

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

View File

@@ -62,6 +62,12 @@ describe('Exchange core', () => {
let zeroEx: ZeroEx;
before(async () => {
await blockchainLifecycle.startAsync();
});
after(async () => {
await blockchainLifecycle.revertAsync();
});
before(async () => {
const accounts = await web3Wrapper.getAvailableAddressesAsync();
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.ERC721, erc721Proxy.address, owner);
await web3Wrapper.awaitTransactionMinedAsync(
await erc20Proxy.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;
defaultTakerAssetAddress = erc20TokenB.address;
@@ -521,23 +533,39 @@ describe('Exchange core', () => {
});
it('should throw if maker allowances are too low to fill order', async () => {
await web3Wrapper.awaitTransactionMinedAsync(
await erc20TokenA.approve.sendTransactionAsync(erc20Proxy.address, new BigNumber(0), {
from: makerAddress,
});
expect(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(constants.REVERT);
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
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 () => {
await web3Wrapper.awaitTransactionMinedAsync(
await erc20TokenB.approve.sendTransactionAsync(erc20Proxy.address, new BigNumber(0), {
from: takerAddress,
});
expect(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(constants.REVERT);
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
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 () => {

View File

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

View File

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

View File

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

View File

@@ -24,6 +24,12 @@ describe('MixinSignatureValidator', () => {
let orderFactory: OrderFactory;
let signatureValidator: TestSignatureValidatorContract;
before(async () => {
await blockchainLifecycle.startAsync();
});
after(async () => {
await blockchainLifecycle.revertAsync();
});
before(async () => {
const accounts = await web3Wrapper.getAvailableAddressesAsync();
const makerAddress = accounts[0];
@@ -60,12 +66,12 @@ describe('MixinSignatureValidator', () => {
it('should return true with a valid signature', async () => {
const orderHashHex = orderUtils.getOrderHashHex(signedOrder);
const success = await signatureValidator.publicIsValidSignature.callAsync(
const isValidSignature = await signatureValidator.publicIsValidSignature.callAsync(
orderHashHex,
signedOrder.makerAddress,
signedOrder.signature,
);
expect(success).to.be.true();
expect(isValidSignature).to.be.true();
});
it('should return false with an invalid signature', async () => {
@@ -79,12 +85,12 @@ describe('MixinSignatureValidator', () => {
const invalidSigHex = `0x${invalidSigBuff.toString('hex')}`;
signedOrder.signature = invalidSigHex;
const orderHashHex = orderUtils.getOrderHashHex(signedOrder);
const success = await signatureValidator.publicIsValidSignature.callAsync(
const isValidSignature = await signatureValidator.publicIsValidSignature.callAsync(
orderHashHex,
signedOrder.makerAddress,
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 defaultTakerTokenAddress: string;
before(async () => {
await blockchainLifecycle.startAsync();
});
after(async () => {
await blockchainLifecycle.revertAsync();
});
before(async () => {
const accounts = await web3Wrapper.getAvailableAddressesAsync();
const usedAddresses = ([owner, senderAddress, makerAddress, takerAddress, feeRecipientAddress] = accounts);
@@ -76,7 +82,10 @@ describe('Exchange transactions', () => {
exchangeWrapper = new ExchangeWrapper(exchange);
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;
defaultTakerTokenAddress = erc20TokenB.address;

View File

@@ -53,6 +53,12 @@ describe('Exchange wrappers', () => {
let defaultMakerAssetAddress: string;
let defaultTakerAssetAddress: string;
before(async () => {
await blockchainLifecycle.startAsync();
});
after(async () => {
await blockchainLifecycle.revertAsync();
});
before(async () => {
const accounts = await web3Wrapper.getAvailableAddressesAsync();
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.ERC721, erc721Proxy.address, owner);
await web3Wrapper.awaitTransactionMinedAsync(
await erc20Proxy.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;
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 () => {
const signedOrder = orderFactory.newSignedOrder();
await web3Wrapper.awaitTransactionMinedAsync(
await erc20TokenA.approve.sendTransactionAsync(erc20Proxy.address, new BigNumber(0), {
from: makerAddress,
});
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
await exchangeWrapper.fillOrderNoThrowAsync(signedOrder, takerAddress);
await web3Wrapper.awaitTransactionMinedAsync(
await erc20TokenA.approve.sendTransactionAsync(erc20Proxy.address, constants.INITIAL_ERC20_ALLOWANCE, {
from: makerAddress,
});
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
const newBalances = await erc20Wrapper.getBalancesAsync();
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 () => {
const signedOrder = orderFactory.newSignedOrder();
await web3Wrapper.awaitTransactionMinedAsync(
await erc20TokenB.approve.sendTransactionAsync(erc20Proxy.address, new BigNumber(0), {
from: takerAddress,
});
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
await exchangeWrapper.fillOrderNoThrowAsync(signedOrder, takerAddress);
await web3Wrapper.awaitTransactionMinedAsync(
await erc20TokenB.approve.sendTransactionAsync(erc20Proxy.address, constants.INITIAL_ERC20_ALLOWANCE, {
from: takerAddress,
});
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
const newBalances = await erc20Wrapper.getBalancesAsync();
expect(newBalances).to.be.deep.equal(erc20Balances);

View File

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

View File

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

View File

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

View File

@@ -27,6 +27,12 @@ describe('UnlimitedAllowanceToken', () => {
let tokenAddress: string;
let token: DummyERC20TokenContract;
before(async () => {
await blockchainLifecycle.startAsync();
});
after(async () => {
await blockchainLifecycle.revertAsync();
});
before(async () => {
const accounts = await web3Wrapper.getAvailableAddressesAsync();
owner = accounts[0];
@@ -40,7 +46,10 @@ describe('UnlimitedAllowanceToken', () => {
constants.DUMMY_TOKEN_DECIMALS,
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;
});
beforeEach(async () => {

View File

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

View File

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

View File

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

View File

@@ -2,7 +2,7 @@ import * as _ from 'lodash';
import * as Lint from 'tslint';
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 {
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-config-0xproject": "^0.0.2",
"typescript": "2.7.1",
"uglifyjs-webpack-plugin": "^1.2.5",
"webpack": "^3.1.0",
"webpack-dev-middleware": "^1.10.0",
"webpack-dev-server": "^2.5.0"

View File

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

View File

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

View File

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

View File

@@ -2569,7 +2569,7 @@ commander@2.12.2:
version "2.12.2"
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"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.13.0.tgz#6964bca67685df7c1f1430c584f07d7597885b9c"
@@ -3753,7 +3753,7 @@ envinfo@^4.4.2:
version "4.4.2"
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"
resolved "https://registry.yarnpkg.com/errno/-/errno-0.1.7.tgz#4684d71779ad39af177e3f007996f7c67c852618"
dependencies:
@@ -11748,6 +11748,13 @@ ua-parser-js@^0.7.9:
version "0.7.17"
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:
version "2.8.29"
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"
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:
version "0.0.6"
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"
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"
resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-1.1.0.tgz#a101ebae59d6507354d71d8013950a3a8b7a5a54"
dependencies:
@@ -12765,6 +12785,12 @@ wordwrap@~0.0.2:
version "0.0.3"
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:
version "2.1.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-2.1.0.tgz#d8fc3d284dd05794fe84973caecdd1cf824fdd85"