aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/test
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-06-07 18:27:03 +0800
committerFabio Berger <me@fabioberger.com>2018-06-07 18:27:03 +0800
commit73429fc7202ff7b58eb64a7e0b939b971f16a27e (patch)
tree6abd050f91750c819e98045d21cd8952a0e14071 /packages/contracts/test
parentcb754ee1253622974e751e4a8d723a424250c878 (diff)
parente0bc01eea1c20e0afda296f331c6a475e062b59c (diff)
downloaddexon-sol-tools-73429fc7202ff7b58eb64a7e0b939b971f16a27e.tar.gz
dexon-sol-tools-73429fc7202ff7b58eb64a7e0b939b971f16a27e.tar.zst
dexon-sol-tools-73429fc7202ff7b58eb64a7e0b939b971f16a27e.zip
merge v2-prototype
Diffstat (limited to 'packages/contracts/test')
-rw-r--r--packages/contracts/test/asset_proxy/authorizable.ts21
-rw-r--r--packages/contracts/test/asset_proxy/proxies.ts46
-rw-r--r--packages/contracts/test/asset_proxy_owner.ts45
-rw-r--r--packages/contracts/test/ether_token.ts13
-rw-r--r--packages/contracts/test/exchange/core.ts128
-rw-r--r--packages/contracts/test/exchange/dispatcher.ts21
-rw-r--r--packages/contracts/test/exchange/libs.ts1
-rw-r--r--packages/contracts/test/exchange/match_orders.ts51
-rw-r--r--packages/contracts/test/exchange/signature_validator.ts1
-rw-r--r--packages/contracts/test/exchange/transactions.ts31
-rw-r--r--packages/contracts/test/exchange/wrapper.ts76
-rw-r--r--packages/contracts/test/libraries/lib_bytes.ts55
-rw-r--r--packages/contracts/test/multi_sig_with_time_lock.ts26
-rw-r--r--packages/contracts/test/token_registry.ts55
-rw-r--r--packages/contracts/test/unlimited_allowance_token.ts20
-rw-r--r--packages/contracts/test/zrx_token.ts3
16 files changed, 303 insertions, 290 deletions
diff --git a/packages/contracts/test/asset_proxy/authorizable.ts b/packages/contracts/test/asset_proxy/authorizable.ts
index 6ceebf089..347d060d6 100644
--- a/packages/contracts/test/asset_proxy/authorizable.ts
+++ b/packages/contracts/test/asset_proxy/authorizable.ts
@@ -1,11 +1,10 @@
-import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils';
-import { Web3Wrapper } from '@0xproject/web3-wrapper';
+import { BlockchainLifecycle } from '@0xproject/dev-utils';
import * as chai from 'chai';
import 'make-promises-safe';
-import * as Web3 from 'web3';
import { MixinAuthorizableContract } from '../../src/generated_contract_wrappers/mixin_authorizable';
import { artifacts } from '../../src/utils/artifacts';
+import { expectRevertOrAlwaysFailingTransactionAsync } from '../../src/utils/assertions';
import { chaiSetup } from '../../src/utils/chai_setup';
import { constants } from '../../src/utils/constants';
import { provider, txDefaults, web3Wrapper } from '../../src/utils/web3_wrapper';
@@ -44,9 +43,9 @@ describe('Authorizable', () => {
});
describe('addAuthorizedAddress', () => {
it('should throw if not called by owner', async () => {
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
authorizable.addAuthorizedAddress.sendTransactionAsync(notOwner, { from: notOwner }),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
it('should allow owner to add an authorized address', async () => {
await web3Wrapper.awaitTransactionSuccessAsync(
@@ -61,9 +60,9 @@ describe('Authorizable', () => {
await authorizable.addAuthorizedAddress.sendTransactionAsync(address, { from: owner }),
constants.AWAIT_TRANSACTION_MINED_MS,
);
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
authorizable.addAuthorizedAddress.sendTransactionAsync(address, { from: owner }),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
});
@@ -73,11 +72,11 @@ describe('Authorizable', () => {
await authorizable.addAuthorizedAddress.sendTransactionAsync(address, { from: owner }),
constants.AWAIT_TRANSACTION_MINED_MS,
);
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
authorizable.removeAuthorizedAddress.sendTransactionAsync(address, {
from: notOwner,
}),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
it('should allow owner to remove an authorized address', async () => {
@@ -96,11 +95,11 @@ describe('Authorizable', () => {
});
it('should throw if owner attempts to remove an address that is not authorized', async () => {
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
authorizable.removeAuthorizedAddress.sendTransactionAsync(address, {
from: owner,
}),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
});
diff --git a/packages/contracts/test/asset_proxy/proxies.ts b/packages/contracts/test/asset_proxy/proxies.ts
index 39dfb9938..bf2aa8f70 100644
--- a/packages/contracts/test/asset_proxy/proxies.ts
+++ b/packages/contracts/test/asset_proxy/proxies.ts
@@ -1,15 +1,14 @@
import { BlockchainLifecycle } from '@0xproject/dev-utils';
import { assetProxyUtils } from '@0xproject/order-utils';
-import { AssetProxyId } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import * as chai from 'chai';
import * as _ from 'lodash';
-import * as Web3 from 'web3';
-import { DummyERC20TokenContract } from '../../src/generated_contract_wrappers/dummy_e_r_c20_token';
-import { DummyERC721TokenContract } from '../../src/generated_contract_wrappers/dummy_e_r_c721_token';
-import { ERC20ProxyContract } from '../../src/generated_contract_wrappers/e_r_c20_proxy';
-import { ERC721ProxyContract } from '../../src/generated_contract_wrappers/e_r_c721_proxy';
+import { DummyERC20TokenContract } from '../../src/generated_contract_wrappers/generated/dummy_e_r_c20_token';
+import { DummyERC721TokenContract } from '../../src/generated_contract_wrappers/generated/dummy_e_r_c721_token';
+import { ERC20ProxyContract } from '../../src/generated_contract_wrappers/generated/e_r_c20_proxy';
+import { ERC721ProxyContract } from '../../src/generated_contract_wrappers/generated/e_r_c721_proxy';
+import { expectRevertOrAlwaysFailingTransactionAsync } from '../../src/utils/assertions';
import { chaiSetup } from '../../src/utils/chai_setup';
import { constants } from '../../src/utils/constants';
import { ERC20Wrapper } from '../../src/utils/erc20_wrapper';
@@ -144,7 +143,7 @@ describe('Asset Transfer Proxies', () => {
constants.AWAIT_TRANSACTION_MINED_MS,
);
// Perform a transfer; expect this to fail.
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
erc20Proxy.transferFrom.sendTransactionAsync(
encodedProxyMetadata,
makerAddress,
@@ -152,7 +151,7 @@ describe('Asset Transfer Proxies', () => {
transferAmount,
{ from: notAuthorized },
),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
it('should throw if requesting address is not authorized', async () => {
@@ -160,7 +159,7 @@ describe('Asset Transfer Proxies', () => {
const encodedProxyMetadata = assetProxyUtils.encodeERC20ProxyData(zrxToken.address);
// Perform a transfer from makerAddress to takerAddress
const amount = new BigNumber(10);
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
erc20Proxy.transferFrom.sendTransactionAsync(
encodedProxyMetadata,
makerAddress,
@@ -170,7 +169,7 @@ describe('Asset Transfer Proxies', () => {
from: notAuthorized,
},
),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
});
@@ -217,7 +216,7 @@ describe('Asset Transfer Proxies', () => {
const toAddresses = _.times(numTransfers, () => takerAddress);
const amounts = _.times(numTransfers, () => amount);
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
erc20Proxy.batchTransferFrom.sendTransactionAsync(
assetMetadata,
fromAddresses,
@@ -225,7 +224,7 @@ describe('Asset Transfer Proxies', () => {
amounts,
{ from: notAuthorized },
),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
});
@@ -247,7 +246,6 @@ describe('Asset Transfer Proxies', () => {
const ownerMakerAsset = await erc721Token.ownerOf.callAsync(erc721MakerTokenId);
expect(ownerMakerAsset).to.be.bignumber.equal(makerAddress);
// Perform a transfer from makerAddress to takerAddress
- const erc20Balances = await erc20Wrapper.getBalancesAsync();
const amount = new BigNumber(1);
await web3Wrapper.awaitTransactionSuccessAsync(
await erc721Proxy.transferFrom.sendTransactionAsync(
@@ -274,9 +272,8 @@ describe('Asset Transfer Proxies', () => {
const ownerMakerAsset = await erc721Token.ownerOf.callAsync(erc721MakerTokenId);
expect(ownerMakerAsset).to.be.bignumber.equal(makerAddress);
// Perform a transfer from makerAddress to takerAddress
- const erc20Balances = await erc20Wrapper.getBalancesAsync();
const amount = new BigNumber(0);
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
erc721Proxy.transferFrom.sendTransactionAsync(
encodedProxyMetadata,
makerAddress,
@@ -284,7 +281,7 @@ describe('Asset Transfer Proxies', () => {
amount,
{ from: exchangeAddress },
),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
it('should throw if transferring > 1 amount of a token', async () => {
@@ -297,9 +294,8 @@ describe('Asset Transfer Proxies', () => {
const ownerMakerAsset = await erc721Token.ownerOf.callAsync(erc721MakerTokenId);
expect(ownerMakerAsset).to.be.bignumber.equal(makerAddress);
// Perform a transfer from makerAddress to takerAddress
- const erc20Balances = await erc20Wrapper.getBalancesAsync();
const amount = new BigNumber(500);
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
erc721Proxy.transferFrom.sendTransactionAsync(
encodedProxyMetadata,
makerAddress,
@@ -307,7 +303,7 @@ describe('Asset Transfer Proxies', () => {
amount,
{ from: exchangeAddress },
),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
it('should throw if allowances are too low', async () => {
@@ -325,7 +321,7 @@ describe('Asset Transfer Proxies', () => {
);
// Perform a transfer; expect this to fail.
const amount = new BigNumber(1);
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
erc20Proxy.transferFrom.sendTransactionAsync(
encodedProxyMetadata,
makerAddress,
@@ -335,7 +331,7 @@ describe('Asset Transfer Proxies', () => {
from: notAuthorized,
},
),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
it('should throw if requesting address is not authorized', async () => {
@@ -346,7 +342,7 @@ describe('Asset Transfer Proxies', () => {
);
// Perform a transfer from makerAddress to takerAddress
const amount = new BigNumber(1);
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
erc721Proxy.transferFrom.sendTransactionAsync(
encodedProxyMetadata,
makerAddress,
@@ -354,7 +350,7 @@ describe('Asset Transfer Proxies', () => {
amount,
{ from: notAuthorized },
),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
});
@@ -404,7 +400,7 @@ describe('Asset Transfer Proxies', () => {
const toAddresses = _.times(numTransfers, () => takerAddress);
const amounts = _.times(numTransfers, () => new BigNumber(1));
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
erc721Proxy.batchTransferFrom.sendTransactionAsync(
assetMetadata,
fromAddresses,
@@ -412,7 +408,7 @@ describe('Asset Transfer Proxies', () => {
amounts,
{ from: notAuthorized },
),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
});
diff --git a/packages/contracts/test/asset_proxy_owner.ts b/packages/contracts/test/asset_proxy_owner.ts
index 9618e1905..cbe429b12 100644
--- a/packages/contracts/test/asset_proxy_owner.ts
+++ b/packages/contracts/test/asset_proxy_owner.ts
@@ -2,9 +2,7 @@ import { BlockchainLifecycle } from '@0xproject/dev-utils';
import { BigNumber } from '@0xproject/utils';
import * as chai from 'chai';
import { LogWithDecodedArgs } from 'ethereum-types';
-import * as _ from 'lodash';
import 'make-promises-safe';
-import * as Web3 from 'web3';
import {
AssetProxyOwnerContract,
@@ -15,15 +13,20 @@ import {
} from '../src/generated_contract_wrappers/asset_proxy_owner';
import { MixinAuthorizableContract } from '../src/generated_contract_wrappers/mixin_authorizable';
import { artifacts } from '../src/utils/artifacts';
+import {
+ expectRevertOrAlwaysFailingTransactionAsync,
+ expectRevertOrContractCallFailedAsync,
+} from '../src/utils/assertions';
import { chaiSetup } from '../src/utils/chai_setup';
import { constants } from '../src/utils/constants';
+import { increaseTimeAndMineBlockAsync } from '../src/utils/increase_time';
import { MultiSigWrapper } from '../src/utils/multi_sig_wrapper';
import { provider, txDefaults, web3Wrapper } from '../src/utils/web3_wrapper';
chaiSetup.configure();
const expect = chai.expect;
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
-
+// tslint:disable:no-unnecessary-type-assertion
describe('AssetProxyOwner', () => {
let owners: string[];
let authorized: string;
@@ -101,7 +104,7 @@ describe('AssetProxyOwner', () => {
});
it('should throw if a null address is included in assetProxyContracts', async () => {
const assetProxyContractAddresses = [erc20Proxy.address, constants.NULL_ADDRESS];
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
AssetProxyOwnerContract.deployFrom0xArtifactAsync(
artifacts.AssetProxyOwner,
provider,
@@ -111,7 +114,7 @@ describe('AssetProxyOwner', () => {
REQUIRED_APPROVALS,
SECONDS_TIME_LOCKED,
),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
});
@@ -120,9 +123,9 @@ describe('AssetProxyOwner', () => {
const notRemoveAuthorizedAddressData = erc20Proxy.addAuthorizedAddress.getABIEncodedTransactionData(
owners[0],
);
- return expect(
+ return expectRevertOrContractCallFailedAsync(
multiSig.isFunctionRemoveAuthorizedAddress.callAsync(notRemoveAuthorizedAddressData),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
it('should return true if data is for removeAuthorizedAddress', async () => {
@@ -139,9 +142,9 @@ describe('AssetProxyOwner', () => {
describe('registerAssetProxy', () => {
it('should throw if not called by multisig', async () => {
const isRegistered = true;
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
multiSig.registerAssetProxy.sendTransactionAsync(erc20Proxy.address, isRegistered, { from: owners[0] }),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
it('should register an address if called by multisig after timelock', async () => {
@@ -156,11 +159,12 @@ describe('AssetProxyOwner', () => {
registerAssetProxyData,
owners[0],
);
+
const log = submitTxRes.logs[0] as LogWithDecodedArgs<SubmissionContractEventArgs>;
const txId = log.args.transactionId;
await multiSigWrapper.confirmTransactionAsync(txId, owners[1]);
- await web3Wrapper.increaseTimeAsync(SECONDS_TIME_LOCKED.toNumber());
+ await increaseTimeAndMineBlockAsync(SECONDS_TIME_LOCKED.toNumber());
const executeTxRes = await multiSigWrapper.executeTransactionAsync(txId, owners[0]);
const registerLog = executeTxRes.logs[0] as LogWithDecodedArgs<AssetProxyRegistrationContractEventArgs>;
@@ -187,7 +191,7 @@ describe('AssetProxyOwner', () => {
const txId = log.args.transactionId;
await multiSigWrapper.confirmTransactionAsync(txId, owners[1]);
- await web3Wrapper.increaseTimeAsync(SECONDS_TIME_LOCKED.toNumber());
+ await increaseTimeAndMineBlockAsync(SECONDS_TIME_LOCKED.toNumber());
const executeTxRes = await multiSigWrapper.executeTransactionAsync(txId, owners[0]);
const failureLog = executeTxRes.logs[0] as LogWithDecodedArgs<ExecutionFailureContractEventArgs>;
@@ -239,7 +243,7 @@ describe('AssetProxyOwner', () => {
await multiSigWrapper.confirmTransactionAsync(erc20AddAuthorizedAddressTxId, owners[1]);
await multiSigWrapper.confirmTransactionAsync(erc721AddAuthorizedAddressTxId, owners[1]);
- await web3Wrapper.increaseTimeAsync(SECONDS_TIME_LOCKED.toNumber());
+ await increaseTimeAndMineBlockAsync(SECONDS_TIME_LOCKED.toNumber());
await multiSigWrapper.executeTransactionAsync(registerAssetProxyTxId, owners[0]);
await multiSigWrapper.executeTransactionAsync(erc20AddAuthorizedAddressTxId, owners[0]);
await multiSigWrapper.executeTransactionAsync(erc721AddAuthorizedAddressTxId, owners[0]);
@@ -257,9 +261,9 @@ describe('AssetProxyOwner', () => {
const log = res.logs[0] as LogWithDecodedArgs<SubmissionContractEventArgs>;
const txId = log.args.transactionId;
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
multiSig.executeRemoveAuthorizedAddress.sendTransactionAsync(txId, { from: owners[1] }),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
it('should throw if tx destination is not registered', async () => {
@@ -276,9 +280,9 @@ describe('AssetProxyOwner', () => {
await multiSigWrapper.confirmTransactionAsync(txId, owners[1]);
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
multiSig.executeRemoveAuthorizedAddress.sendTransactionAsync(txId, { from: owners[1] }),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
it('should throw if tx data is not for removeAuthorizedAddress', async () => {
@@ -296,9 +300,9 @@ describe('AssetProxyOwner', () => {
await multiSigWrapper.confirmTransactionAsync(txId, owners[1]);
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
multiSig.executeRemoveAuthorizedAddress.sendTransactionAsync(txId, { from: owners[1] }),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
it('should execute removeAuthorizedAddress for registered address if fully confirmed', async () => {
@@ -349,9 +353,10 @@ describe('AssetProxyOwner', () => {
const isExecuted = tx[3];
expect(isExecuted).to.equal(true);
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
multiSig.executeRemoveAuthorizedAddress.sendTransactionAsync(txId, { from: owners[1] }),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
});
});
+// tslint:enable:no-unnecessary-type-assertion
diff --git a/packages/contracts/test/ether_token.ts b/packages/contracts/test/ether_token.ts
index 000ea6e46..e2fc69aee 100644
--- a/packages/contracts/test/ether_token.ts
+++ b/packages/contracts/test/ether_token.ts
@@ -1,11 +1,12 @@
-import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils';
-import { BigNumber, promisify } from '@0xproject/utils';
+import { BlockchainLifecycle } from '@0xproject/dev-utils';
+import { BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as chai from 'chai';
import 'make-promises-safe';
import { WETH9Contract } from '../src/generated_contract_wrappers/weth9';
import { artifacts } from '../src/utils/artifacts';
+import { expectInsufficientFundsAsync, expectRevertOrAlwaysFailingTransactionAsync } from '../src/utils/assertions';
import { chaiSetup } from '../src/utils/chai_setup';
import { constants } from '../src/utils/constants';
import { provider, txDefaults, web3Wrapper } from '../src/utils/web3_wrapper';
@@ -45,9 +46,7 @@ describe('EtherToken', () => {
const initEthBalance = await web3Wrapper.getBalanceInWeiAsync(account);
const ethToDeposit = initEthBalance.plus(1);
- return expect(etherToken.deposit.sendTransactionAsync({ value: ethToDeposit })).to.be.rejectedWith(
- "ender doesn't have enough funds to send tx.",
- );
+ return expectInsufficientFundsAsync(etherToken.deposit.sendTransactionAsync({ value: ethToDeposit }));
});
it('should convert deposited Ether to wrapped Ether tokens', async () => {
@@ -76,8 +75,8 @@ describe('EtherToken', () => {
const initEthTokenBalance = await etherToken.balanceOf.callAsync(account);
const ethTokensToWithdraw = initEthTokenBalance.plus(1);
- return expect(etherToken.withdraw.sendTransactionAsync(ethTokensToWithdraw)).to.be.rejectedWith(
- constants.REVERT,
+ return expectRevertOrAlwaysFailingTransactionAsync(
+ etherToken.withdraw.sendTransactionAsync(ethTokensToWithdraw),
);
});
diff --git a/packages/contracts/test/exchange/core.ts b/packages/contracts/test/exchange/core.ts
index 1201ef3d9..bee74cca8 100644
--- a/packages/contracts/test/exchange/core.ts
+++ b/packages/contracts/test/exchange/core.ts
@@ -1,5 +1,5 @@
import { BlockchainLifecycle } from '@0xproject/dev-utils';
-import { assetProxyUtils, crypto, orderHashUtils } from '@0xproject/order-utils';
+import { assetProxyUtils, orderHashUtils } from '@0xproject/order-utils';
import { AssetProxyId, SignedOrder } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
@@ -18,20 +18,20 @@ import {
FillContractEventArgs,
} from '../../src/generated_contract_wrappers/exchange';
import { artifacts } from '../../src/utils/artifacts';
+import { expectRevertOrAlwaysFailingTransactionAsync } from '../../src/utils/assertions';
import { chaiSetup } from '../../src/utils/chai_setup';
import { constants } from '../../src/utils/constants';
import { ERC20Wrapper } from '../../src/utils/erc20_wrapper';
import { ERC721Wrapper } from '../../src/utils/erc721_wrapper';
import { ExchangeWrapper } from '../../src/utils/exchange_wrapper';
import { OrderFactory } from '../../src/utils/order_factory';
-import { orderUtils } from '../../src/utils/order_utils';
-import { ContractName, ERC20BalancesByOwner, OrderStatus } from '../../src/utils/types';
+import { ERC20BalancesByOwner } from '../../src/utils/types';
import { provider, txDefaults, web3Wrapper } from '../../src/utils/web3_wrapper';
chaiSetup.configure();
const expect = chai.expect;
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
-
+// tslint:disable:no-unnecessary-type-assertion
describe('Exchange core', () => {
let makerAddress: string;
let owner: string;
@@ -415,8 +415,8 @@ describe('Exchange core', () => {
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18),
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(200), 18),
});
- return expect(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(
- constants.REVERT,
+ return expectRevertOrAlwaysFailingTransactionAsync(
+ exchangeWrapper.fillOrderAsync(signedOrder, takerAddress),
);
});
@@ -432,8 +432,8 @@ describe('Exchange core', () => {
const invalidSigBuff = Buffer.concat([v, invalidR, invalidS, signatureType]);
const invalidSigHex = `0x${invalidSigBuff.toString('hex')}`;
signedOrder.signature = invalidSigHex;
- return expect(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(
- constants.REVERT,
+ return expectRevertOrAlwaysFailingTransactionAsync(
+ exchangeWrapper.fillOrderAsync(signedOrder, takerAddress),
);
});
@@ -442,8 +442,8 @@ describe('Exchange core', () => {
makerAssetAmount: new BigNumber(0),
});
- return expect(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(
- constants.REVERT,
+ return expectRevertOrAlwaysFailingTransactionAsync(
+ exchangeWrapper.fillOrderAsync(signedOrder, takerAddress),
);
});
@@ -452,19 +452,19 @@ describe('Exchange core', () => {
takerAssetAmount: new BigNumber(0),
});
- return expect(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(
- constants.REVERT,
+ return expectRevertOrAlwaysFailingTransactionAsync(
+ exchangeWrapper.fillOrderAsync(signedOrder, takerAddress),
);
});
it('should throw if takerAssetFillAmount is 0', async () => {
signedOrder = orderFactory.newSignedOrder();
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, {
takerAssetFillAmount: new BigNumber(0),
}),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
it('should throw if maker erc20Balances are too low to fill order', async () => {
@@ -472,8 +472,8 @@ describe('Exchange core', () => {
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100000), 18),
});
- return expect(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(
- constants.REVERT,
+ return expectRevertOrAlwaysFailingTransactionAsync(
+ exchangeWrapper.fillOrderAsync(signedOrder, takerAddress),
);
});
@@ -481,9 +481,8 @@ describe('Exchange core', () => {
signedOrder = orderFactory.newSignedOrder({
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100000), 18),
});
-
- return expect(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(
- constants.REVERT,
+ return expectRevertOrAlwaysFailingTransactionAsync(
+ exchangeWrapper.fillOrderAsync(signedOrder, takerAddress),
);
});
@@ -494,11 +493,8 @@ describe('Exchange core', () => {
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
- // HACK: `rejectWith` returns a "promise-like" type, but not an actual "Promise", so TSLint
- // complains, even though we do need to `await` it. So we disable the TSLint error below.
- // tslint:disable-next-line:await-promise
- await expect(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(
- constants.REVERT,
+ return expectRevertOrAlwaysFailingTransactionAsync(
+ exchangeWrapper.fillOrderAsync(signedOrder, takerAddress),
);
});
@@ -509,11 +505,8 @@ describe('Exchange core', () => {
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
- // HACK: `rejectWith` returns a "promise-like" type, but not an actual "Promise", so TSLint
- // complains, even though we do need to `await` it. So we disable the TSLint error below.
- // tslint:disable-next-line:await-promise
- await expect(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(
- constants.REVERT,
+ return expectRevertOrAlwaysFailingTransactionAsync(
+ exchangeWrapper.fillOrderAsync(signedOrder, takerAddress),
);
});
@@ -521,16 +514,16 @@ describe('Exchange core', () => {
signedOrder = orderFactory.newSignedOrder({
expirationTimeSeconds: new BigNumber(Math.floor((Date.now() - 10000) / 1000)),
});
- return expect(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(
- constants.REVERT,
+ return expectRevertOrAlwaysFailingTransactionAsync(
+ exchangeWrapper.fillOrderAsync(signedOrder, takerAddress),
);
});
it('should throw if no value is filled', async () => {
signedOrder = orderFactory.newSignedOrder();
await exchangeWrapper.fillOrderAsync(signedOrder, takerAddress);
- return expect(exchangeWrapper.fillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(
- constants.REVERT,
+ return expectRevertOrAlwaysFailingTransactionAsync(
+ exchangeWrapper.fillOrderAsync(signedOrder, takerAddress),
);
});
});
@@ -542,8 +535,8 @@ describe('Exchange core', () => {
});
it('should throw if not sent by maker', async () => {
- return expect(exchangeWrapper.cancelOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(
- constants.REVERT,
+ return expectRevertOrAlwaysFailingTransactionAsync(
+ exchangeWrapper.cancelOrderAsync(signedOrder, takerAddress),
);
});
@@ -552,8 +545,8 @@ describe('Exchange core', () => {
makerAssetAmount: new BigNumber(0),
});
- return expect(exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress)).to.be.rejectedWith(
- constants.REVERT,
+ return expectRevertOrAlwaysFailingTransactionAsync(
+ exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress),
);
});
@@ -562,22 +555,21 @@ describe('Exchange core', () => {
takerAssetAmount: new BigNumber(0),
});
- return expect(exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress)).to.be.rejectedWith(
- constants.REVERT,
+ return expectRevertOrAlwaysFailingTransactionAsync(
+ exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress),
);
});
it('should be able to cancel a full order', async () => {
await exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress);
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, {
takerAssetFillAmount: signedOrder.takerAssetAmount.div(2),
}),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
it('should log 1 event with correct arguments', async () => {
- const divisor = 2;
const res = await exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress);
expect(res.logs).to.have.length(1);
@@ -593,8 +585,8 @@ describe('Exchange core', () => {
it('should throw if already cancelled', async () => {
await exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress);
- return expect(exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress)).to.be.rejectedWith(
- constants.REVERT,
+ return expectRevertOrAlwaysFailingTransactionAsync(
+ exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress),
);
});
@@ -602,8 +594,8 @@ describe('Exchange core', () => {
signedOrder = orderFactory.newSignedOrder({
expirationTimeSeconds: new BigNumber(Math.floor((Date.now() - 10000) / 1000)),
});
- return expect(exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress)).to.be.rejectedWith(
- constants.REVERT,
+ return expectRevertOrAlwaysFailingTransactionAsync(
+ exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress),
);
});
@@ -619,11 +611,11 @@ describe('Exchange core', () => {
});
const fillTakerAssetAmount2 = new BigNumber(1);
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, {
takerAssetFillAmount: fillTakerAssetAmount2,
}),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
});
@@ -632,16 +624,16 @@ describe('Exchange core', () => {
const makerEpoch = new BigNumber(1);
await exchangeWrapper.cancelOrdersUpToAsync(makerEpoch, makerAddress);
const lesserMakerEpoch = new BigNumber(0);
- return expect(exchangeWrapper.cancelOrdersUpToAsync(lesserMakerEpoch, makerAddress)).to.be.rejectedWith(
- constants.REVERT,
+ return expectRevertOrAlwaysFailingTransactionAsync(
+ exchangeWrapper.cancelOrdersUpToAsync(lesserMakerEpoch, makerAddress),
);
});
it('should fail to set makerEpoch equal to existing makerEpoch', async () => {
const makerEpoch = new BigNumber(1);
await exchangeWrapper.cancelOrdersUpToAsync(makerEpoch, makerAddress);
- return expect(exchangeWrapper.cancelOrdersUpToAsync(makerEpoch, makerAddress)).to.be.rejectedWith(
- constants.REVERT,
+ return expectRevertOrAlwaysFailingTransactionAsync(
+ exchangeWrapper.cancelOrdersUpToAsync(makerEpoch, makerAddress),
);
});
@@ -675,7 +667,12 @@ describe('Exchange core', () => {
salt: new BigNumber(3),
}),
];
- await exchangeWrapper.batchFillOrdersNoThrowAsync(signedOrders, takerAddress);
+ await exchangeWrapper.batchFillOrdersNoThrowAsync(signedOrders, takerAddress, {
+ // HACK(albrow): We need to hardcode the gas estimate here because
+ // the Geth gas estimator doesn't work with the way we use
+ // delegatecall and swallow errors.
+ gas: 490000,
+ });
const newBalances = await erc20Wrapper.getBalancesAsync();
const fillMakerAssetAmount = signedOrders[2].makerAssetAmount.add(signedOrders[3].makerAssetAmount);
@@ -724,6 +721,7 @@ describe('Exchange core', () => {
expect(initialOwnerTakerAsset).to.be.bignumber.equal(takerAddress);
// Call Exchange
const takerAssetFillAmount = signedOrder.takerAssetAmount;
+ // tslint:disable-next-line:no-unused-variable
const res = await exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount });
// Verify post-conditions
const newOwnerMakerAsset = await erc721Token.ownerOf.callAsync(makerAssetId);
@@ -749,9 +747,9 @@ describe('Exchange core', () => {
expect(initialOwnerTakerAsset).to.be.bignumber.equal(takerAddress);
// Call Exchange
const takerAssetFillAmount = signedOrder.takerAssetAmount;
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount }),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
it('should throw when taker does not own the token with id takerAssetId', async () => {
@@ -771,9 +769,9 @@ describe('Exchange core', () => {
expect(initialOwnerTakerAsset).to.be.bignumber.not.equal(takerAddress);
// Call Exchange
const takerAssetFillAmount = signedOrder.takerAssetAmount;
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount }),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
it('should throw when makerAssetAmount is greater than 1', async () => {
@@ -793,9 +791,9 @@ describe('Exchange core', () => {
expect(initialOwnerTakerAsset).to.be.bignumber.equal(takerAddress);
// Call Exchange
const takerAssetFillAmount = signedOrder.takerAssetAmount;
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount }),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
it('should throw when takerAssetAmount is greater than 1', async () => {
@@ -815,9 +813,9 @@ describe('Exchange core', () => {
expect(initialOwnerTakerAsset).to.be.bignumber.equal(takerAddress);
// Call Exchange
const takerAssetFillAmount = signedOrder.takerAssetAmount;
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount }),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
it('should throw on partial fill', async () => {
@@ -837,9 +835,9 @@ describe('Exchange core', () => {
expect(initialOwnerTakerAsset).to.be.bignumber.equal(takerAddress);
// Call Exchange
const takerAssetFillAmount = signedOrder.takerAssetAmount;
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount }),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
it('should successfully fill order when makerAsset is ERC721 and takerAsset is ERC20', async () => {
@@ -922,4 +920,6 @@ describe('Exchange core', () => {
);
});
});
-}); // tslint:disable-line:max-file-line-count
+});
+// tslint:disable:max-file-line-count
+// tslint:enable:no-unnecessary-type-assertion
diff --git a/packages/contracts/test/exchange/dispatcher.ts b/packages/contracts/test/exchange/dispatcher.ts
index 287bbfe31..02d43a132 100644
--- a/packages/contracts/test/exchange/dispatcher.ts
+++ b/packages/contracts/test/exchange/dispatcher.ts
@@ -3,13 +3,13 @@ import { assetProxyUtils } from '@0xproject/order-utils';
import { AssetProxyId } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import * as chai from 'chai';
-import * as Web3 from 'web3';
import { DummyERC20TokenContract } from '../../src/generated_contract_wrappers/dummy_e_r_c20_token';
import { ERC20ProxyContract } from '../../src/generated_contract_wrappers/e_r_c20_proxy';
import { ERC721ProxyContract } from '../../src/generated_contract_wrappers/e_r_c721_proxy';
import { TestAssetProxyDispatcherContract } from '../../src/generated_contract_wrappers/test_asset_proxy_dispatcher';
import { artifacts } from '../../src/utils/artifacts';
+import { expectRevertOrAlwaysFailingTransactionAsync } from '../../src/utils/assertions';
import { chaiSetup } from '../../src/utils/chai_setup';
import { constants } from '../../src/utils/constants';
import { ERC20Wrapper } from '../../src/utils/erc20_wrapper';
@@ -23,7 +23,6 @@ const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
describe('AssetProxyDispatcher', () => {
let owner: string;
let notOwner: string;
- let notAuthorized: string;
let makerAddress: string;
let takerAddress: string;
@@ -45,7 +44,6 @@ describe('AssetProxyDispatcher', () => {
// Setup accounts & addresses
const accounts = await web3Wrapper.getAvailableAddressesAsync();
const usedAddresses = ([owner, notOwner, makerAddress, takerAddress] = accounts);
- notAuthorized = notOwner;
erc20Wrapper = new ERC20Wrapper(provider, usedAddresses, owner);
erc721Wrapper = new ERC721Wrapper(provider, usedAddresses, owner);
@@ -177,14 +175,14 @@ describe('AssetProxyDispatcher', () => {
const proxyAddress = await assetProxyDispatcher.getAssetProxy.callAsync(AssetProxyId.ERC20);
expect(proxyAddress).to.be.equal(erc20Proxy.address);
// The following transaction will throw because the currentAddress is no longer constants.NULL_ADDRESS
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
assetProxyDispatcher.registerAssetProxy.sendTransactionAsync(
AssetProxyId.ERC20,
erc20Proxy.address,
constants.NULL_ADDRESS,
{ from: owner },
),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
it('should be able to reset proxy address to NULL', async () => {
@@ -218,26 +216,26 @@ describe('AssetProxyDispatcher', () => {
it('should throw if requesting address is not owner', async () => {
const prevProxyAddress = constants.NULL_ADDRESS;
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
assetProxyDispatcher.registerAssetProxy.sendTransactionAsync(
AssetProxyId.ERC20,
erc20Proxy.address,
prevProxyAddress,
{ from: notOwner },
),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
it('should throw if attempting to register a proxy to the incorrect id', async () => {
const prevProxyAddress = constants.NULL_ADDRESS;
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
assetProxyDispatcher.registerAssetProxy.sendTransactionAsync(
AssetProxyId.ERC721,
erc20Proxy.address,
prevProxyAddress,
{ from: owner },
),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
});
@@ -305,9 +303,8 @@ describe('AssetProxyDispatcher', () => {
// 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);
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
assetProxyDispatcher.publicDispatchTransferFrom.sendTransactionAsync(
encodedProxyMetadata,
makerAddress,
@@ -315,7 +312,7 @@ describe('AssetProxyDispatcher', () => {
amount,
{ from: owner },
),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
});
});
diff --git a/packages/contracts/test/exchange/libs.ts b/packages/contracts/test/exchange/libs.ts
index 176ccb87d..b12934014 100644
--- a/packages/contracts/test/exchange/libs.ts
+++ b/packages/contracts/test/exchange/libs.ts
@@ -3,7 +3,6 @@ import { assetProxyUtils, orderHashUtils } from '@0xproject/order-utils';
import { SignedOrder } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import * as chai from 'chai';
-import ethUtil = require('ethereumjs-util');
import { TestLibsContract } from '../../src/generated_contract_wrappers/test_libs';
import { addressUtils } from '../../src/utils/address_utils';
diff --git a/packages/contracts/test/exchange/match_orders.ts b/packages/contracts/test/exchange/match_orders.ts
index db757c393..39e11fd46 100644
--- a/packages/contracts/test/exchange/match_orders.ts
+++ b/packages/contracts/test/exchange/match_orders.ts
@@ -1,23 +1,18 @@
import { BlockchainLifecycle } from '@0xproject/dev-utils';
-import { assetProxyUtils, crypto } from '@0xproject/order-utils';
-import { AssetProxyId, SignedOrder } from '@0xproject/types';
+import { assetProxyUtils } from '@0xproject/order-utils';
+import { AssetProxyId } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as chai from 'chai';
-import { LogWithDecodedArgs } from 'ethereum-types';
-import ethUtil = require('ethereumjs-util');
import * as _ from 'lodash';
-import { DummyERC20TokenContract } from '../../src/generated_contract_wrappers/dummy_e_r_c20_token';
-import { DummyERC721TokenContract } from '../../src/generated_contract_wrappers/dummy_e_r_c721_token';
-import { ERC20ProxyContract } from '../../src/generated_contract_wrappers/e_r_c20_proxy';
-import { ERC721ProxyContract } from '../../src/generated_contract_wrappers/e_r_c721_proxy';
-import {
- CancelContractEventArgs,
- ExchangeContract,
- FillContractEventArgs,
-} from '../../src/generated_contract_wrappers/exchange';
+import { DummyERC20TokenContract } from '../../src/generated_contract_wrappers/generated/dummy_e_r_c20_token';
+import { DummyERC721TokenContract } from '../../src/generated_contract_wrappers/generated/dummy_e_r_c721_token';
+import { ERC20ProxyContract } from '../../src/generated_contract_wrappers/generated/e_r_c20_proxy';
+import { ERC721ProxyContract } from '../../src/generated_contract_wrappers/generated/e_r_c721_proxy';
+import { ExchangeContract } from '../../src/generated_contract_wrappers/generated/exchange';
import { artifacts } from '../../src/utils/artifacts';
+import { expectRevertOrAlwaysFailingTransactionAsync } from '../../src/utils/assertions';
import { chaiSetup } from '../../src/utils/chai_setup';
import { constants } from '../../src/utils/constants';
import { ERC20Wrapper } from '../../src/utils/erc20_wrapper';
@@ -25,13 +20,7 @@ import { ERC721Wrapper } from '../../src/utils/erc721_wrapper';
import { ExchangeWrapper } from '../../src/utils/exchange_wrapper';
import { MatchOrderTester } from '../../src/utils/match_order_tester';
import { OrderFactory } from '../../src/utils/order_factory';
-import {
- ContractName,
- ERC20BalancesByOwner,
- ERC721TokenIdsByOwner,
- OrderInfo,
- OrderStatus,
-} from '../../src/utils/types';
+import { ERC20BalancesByOwner, ERC721TokenIdsByOwner, OrderInfo, OrderStatus } from '../../src/utils/types';
import { provider, txDefaults, web3Wrapper } from '../../src/utils/web3_wrapper';
chaiSetup.configure();
@@ -64,7 +53,6 @@ describe('matchOrders', () => {
let erc721LeftMakerAssetIds: BigNumber[];
let erc721RightMakerAssetIds: BigNumber[];
- let erc721TakerAssetIds: BigNumber[];
let defaultERC20MakerAssetAddress: string;
let defaultERC20TakerAssetAddress: string;
@@ -103,7 +91,6 @@ describe('matchOrders', () => {
const erc721Balances = await erc721Wrapper.getBalancesAsync();
erc721LeftMakerAssetIds = erc721Balances[makerAddressLeft][erc721Token.address];
erc721RightMakerAssetIds = erc721Balances[makerAddressRight][erc721Token.address];
- erc721TakerAssetIds = erc721Balances[takerAddress][erc721Token.address];
// Depoy exchange
exchange = await ExchangeContract.deployFrom0xArtifactAsync(
artifacts.Exchange,
@@ -639,9 +626,9 @@ describe('matchOrders', () => {
// Cancel left order
await exchangeWrapper.cancelOrderAsync(signedOrderLeft, signedOrderLeft.makerAddress);
// Match orders
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
exchangeWrapper.matchOrdersAsync(signedOrderLeft, signedOrderRight, takerAddress),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
it('Should throw if right order is not fillable', async () => {
@@ -665,9 +652,9 @@ describe('matchOrders', () => {
// Cancel right order
await exchangeWrapper.cancelOrderAsync(signedOrderRight, signedOrderRight.makerAddress);
// Match orders
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
exchangeWrapper.matchOrdersAsync(signedOrderLeft, signedOrderRight, takerAddress),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
it('should throw if there is not a positive spread', async () => {
@@ -689,7 +676,7 @@ describe('matchOrders', () => {
feeRecipientAddress: feeRecipientAddressRight,
});
// Match orders
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
matchOrderTester.matchOrdersAndVerifyBalancesAsync(
signedOrderLeft,
signedOrderRight,
@@ -697,7 +684,7 @@ describe('matchOrders', () => {
erc20BalancesByOwner,
erc721TokenIdsByOwner,
),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
it('should throw if the left maker asset is not equal to the right taker asset ', async () => {
@@ -719,7 +706,7 @@ describe('matchOrders', () => {
feeRecipientAddress: feeRecipientAddressRight,
});
// Match orders
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
matchOrderTester.matchOrdersAndVerifyBalancesAsync(
signedOrderLeft,
signedOrderRight,
@@ -727,7 +714,7 @@ describe('matchOrders', () => {
erc20BalancesByOwner,
erc721TokenIdsByOwner,
),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
it('should throw if the right maker asset is not equal to the left taker asset', async () => {
@@ -749,7 +736,7 @@ describe('matchOrders', () => {
feeRecipientAddress: feeRecipientAddressRight,
});
// Match orders
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
matchOrderTester.matchOrdersAndVerifyBalancesAsync(
signedOrderLeft,
signedOrderRight,
@@ -757,7 +744,7 @@ describe('matchOrders', () => {
erc20BalancesByOwner,
erc721TokenIdsByOwner,
),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
it('should transfer correct amounts when left order maker asset is an ERC721 token', async () => {
diff --git a/packages/contracts/test/exchange/signature_validator.ts b/packages/contracts/test/exchange/signature_validator.ts
index 5232d1486..79db620b4 100644
--- a/packages/contracts/test/exchange/signature_validator.ts
+++ b/packages/contracts/test/exchange/signature_validator.ts
@@ -1,7 +1,6 @@
import { BlockchainLifecycle } from '@0xproject/dev-utils';
import { assetProxyUtils, orderHashUtils } from '@0xproject/order-utils';
import { SignedOrder } from '@0xproject/types';
-import { BigNumber } from '@0xproject/utils';
import * as chai from 'chai';
import ethUtil = require('ethereumjs-util');
diff --git a/packages/contracts/test/exchange/transactions.ts b/packages/contracts/test/exchange/transactions.ts
index 749412658..60e674a95 100644
--- a/packages/contracts/test/exchange/transactions.ts
+++ b/packages/contracts/test/exchange/transactions.ts
@@ -1,16 +1,15 @@
import { BlockchainLifecycle } from '@0xproject/dev-utils';
import { assetProxyUtils, generatePseudoRandomSalt } from '@0xproject/order-utils';
-import { AssetProxyId, Order, OrderWithoutExchangeAddress, SignedOrder } from '@0xproject/types';
+import { AssetProxyId, OrderWithoutExchangeAddress, SignedOrder } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import * as chai from 'chai';
-import * as ethUtil from 'ethereumjs-util';
-import * as Web3 from 'web3';
import { DummyERC20TokenContract } from '../../src/generated_contract_wrappers/dummy_e_r_c20_token';
import { ERC20ProxyContract } from '../../src/generated_contract_wrappers/e_r_c20_proxy';
import { ExchangeContract } from '../../src/generated_contract_wrappers/exchange';
import { WhitelistContract } from '../../src/generated_contract_wrappers/whitelist';
import { artifacts } from '../../src/utils/artifacts';
+import { expectRevertOrAlwaysFailingTransactionAsync } from '../../src/utils/assertions';
import { chaiSetup } from '../../src/utils/chai_setup';
import { constants } from '../../src/utils/constants';
import { ERC20Wrapper } from '../../src/utils/erc20_wrapper';
@@ -18,7 +17,7 @@ import { ExchangeWrapper } from '../../src/utils/exchange_wrapper';
import { OrderFactory } from '../../src/utils/order_factory';
import { orderUtils } from '../../src/utils/order_utils';
import { TransactionFactory } from '../../src/utils/transaction_factory';
-import { ERC20BalancesByOwner, OrderStatus, SignedTransaction } from '../../src/utils/types';
+import { ERC20BalancesByOwner, SignedTransaction } from '../../src/utils/types';
import { provider, txDefaults, web3Wrapper } from '../../src/utils/web3_wrapper';
chaiSetup.configure();
@@ -126,8 +125,8 @@ describe('Exchange transactions', () => {
});
it('should throw if not called by specified sender', async () => {
- return expect(exchangeWrapper.executeTransactionAsync(signedTx, takerAddress)).to.be.rejectedWith(
- constants.REVERT,
+ return expectRevertOrAlwaysFailingTransactionAsync(
+ exchangeWrapper.executeTransactionAsync(signedTx, takerAddress),
);
});
@@ -168,8 +167,8 @@ describe('Exchange transactions', () => {
it('should throw if the a 0x transaction with the same transactionHash has already been executed', async () => {
await exchangeWrapper.executeTransactionAsync(signedTx, senderAddress);
- return expect(exchangeWrapper.executeTransactionAsync(signedTx, senderAddress)).to.be.rejectedWith(
- constants.REVERT,
+ return expectRevertOrAlwaysFailingTransactionAsync(
+ exchangeWrapper.executeTransactionAsync(signedTx, senderAddress),
);
});
@@ -187,15 +186,15 @@ describe('Exchange transactions', () => {
});
it('should throw if not called by specified sender', async () => {
- return expect(exchangeWrapper.executeTransactionAsync(signedTx, makerAddress)).to.be.rejectedWith(
- constants.REVERT,
+ return expectRevertOrAlwaysFailingTransactionAsync(
+ exchangeWrapper.executeTransactionAsync(signedTx, makerAddress),
);
});
it('should cancel the order when signed by maker and called by sender', async () => {
await exchangeWrapper.executeTransactionAsync(signedTx, senderAddress);
- return expect(exchangeWrapper.fillOrderAsync(signedOrder, senderAddress)).to.be.rejectedWith(
- constants.REVERT,
+ return expectRevertOrAlwaysFailingTransactionAsync(
+ exchangeWrapper.fillOrderAsync(signedOrder, senderAddress),
);
});
});
@@ -244,7 +243,7 @@ describe('Exchange transactions', () => {
orderWithoutExchangeAddress = orderUtils.getOrderWithoutExchangeAddress(signedOrder);
const takerAssetFillAmount = signedOrder.takerAssetAmount;
const salt = generatePseudoRandomSalt();
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
whitelist.fillOrderIfWhitelisted.sendTransactionAsync(
orderWithoutExchangeAddress,
takerAssetFillAmount,
@@ -252,7 +251,7 @@ describe('Exchange transactions', () => {
signedOrder.signature,
{ from: takerAddress },
),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
it('should revert if taker has not been whitelisted', async () => {
@@ -264,7 +263,7 @@ describe('Exchange transactions', () => {
orderWithoutExchangeAddress = orderUtils.getOrderWithoutExchangeAddress(signedOrder);
const takerAssetFillAmount = signedOrder.takerAssetAmount;
const salt = generatePseudoRandomSalt();
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
whitelist.fillOrderIfWhitelisted.sendTransactionAsync(
orderWithoutExchangeAddress,
takerAssetFillAmount,
@@ -272,7 +271,7 @@ describe('Exchange transactions', () => {
signedOrder.signature,
{ from: takerAddress },
),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
it('should fill the order if maker and taker have been whitelisted', async () => {
diff --git a/packages/contracts/test/exchange/wrapper.ts b/packages/contracts/test/exchange/wrapper.ts
index 330c0ba3f..b5e8b4125 100644
--- a/packages/contracts/test/exchange/wrapper.ts
+++ b/packages/contracts/test/exchange/wrapper.ts
@@ -1,4 +1,4 @@
-import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils';
+import { BlockchainLifecycle } from '@0xproject/dev-utils';
import { assetProxyUtils } from '@0xproject/order-utils';
import { AssetProxyId, SignedOrder } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
@@ -6,15 +6,14 @@ import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as chai from 'chai';
import * as _ from 'lodash';
import 'make-promises-safe';
-import * as Web3 from 'web3';
-
-import { DummyERC20TokenContract } from '../../src/generated_contract_wrappers/dummy_e_r_c20_token';
-import { DummyERC721TokenContract } from '../../src/generated_contract_wrappers/dummy_e_r_c721_token';
-import { ERC20ProxyContract } from '../../src/generated_contract_wrappers/e_r_c20_proxy';
-import { ERC721ProxyContract } from '../../src/generated_contract_wrappers/e_r_c721_proxy';
-import { ExchangeContract } from '../../src/generated_contract_wrappers/exchange';
-import { TokenRegistryContract } from '../../src/generated_contract_wrappers/token_registry';
+
+import { DummyERC20TokenContract } from '../../src/generated_contract_wrappers/generated/dummy_e_r_c20_token';
+import { DummyERC721TokenContract } from '../../src/generated_contract_wrappers/generated/dummy_e_r_c721_token';
+import { ERC20ProxyContract } from '../../src/generated_contract_wrappers/generated/e_r_c20_proxy';
+import { ERC721ProxyContract } from '../../src/generated_contract_wrappers/generated/e_r_c721_proxy';
+import { ExchangeContract } from '../../src/generated_contract_wrappers/generated/exchange';
import { artifacts } from '../../src/utils/artifacts';
+import { expectRevertOrAlwaysFailingTransactionAsync } from '../../src/utils/assertions';
import { chaiSetup } from '../../src/utils/chai_setup';
import { constants } from '../../src/utils/constants';
import { ERC20Wrapper } from '../../src/utils/erc20_wrapper';
@@ -172,8 +171,8 @@ describe('Exchange wrappers', () => {
expirationTimeSeconds: new BigNumber(Math.floor((Date.now() - 10000) / 1000)),
});
- return expect(exchangeWrapper.fillOrKillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(
- constants.REVERT,
+ return expectRevertOrAlwaysFailingTransactionAsync(
+ exchangeWrapper.fillOrKillOrderAsync(signedOrder, takerAddress),
);
});
@@ -184,8 +183,8 @@ describe('Exchange wrappers', () => {
takerAssetFillAmount: signedOrder.takerAssetAmount.div(2),
});
- return expect(exchangeWrapper.fillOrKillOrderAsync(signedOrder, takerAddress)).to.be.rejectedWith(
- constants.REVERT,
+ return expectRevertOrAlwaysFailingTransactionAsync(
+ exchangeWrapper.fillOrKillOrderAsync(signedOrder, takerAddress),
);
});
});
@@ -197,12 +196,16 @@ describe('Exchange wrappers', () => {
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(200), 18),
});
const takerAssetFillAmount = signedOrder.takerAssetAmount.div(2);
+
await exchangeWrapper.fillOrderNoThrowAsync(signedOrder, takerAddress, {
takerAssetFillAmount,
+ // HACK(albrow): We need to hardcode the gas estimate here because
+ // the Geth gas estimator doesn't work with the way we use
+ // delegatecall and swallow errors.
+ gas: 250000,
});
const newBalances = await erc20Wrapper.getBalancesAsync();
-
const makerAssetFilledAmount = takerAssetFillAmount
.times(signedOrder.makerAssetAmount)
.dividedToIntegerBy(signedOrder.takerAssetAmount);
@@ -212,6 +215,7 @@ describe('Exchange wrappers', () => {
const takerFee = signedOrder.takerFee
.times(makerAssetFilledAmount)
.dividedToIntegerBy(signedOrder.makerAssetAmount);
+
expect(newBalances[makerAddress][defaultMakerAssetAddress]).to.be.bignumber.equal(
erc20Balances[makerAddress][defaultMakerAssetAddress].minus(makerAssetFilledAmount),
);
@@ -360,7 +364,13 @@ describe('Exchange wrappers', () => {
expect(initialOwnerTakerAsset).to.be.bignumber.equal(takerAddress);
// Call Exchange
const takerAssetFillAmount = signedOrder.takerAssetAmount;
- await exchangeWrapper.fillOrderNoThrowAsync(signedOrder, takerAddress, { takerAssetFillAmount });
+ await exchangeWrapper.fillOrderNoThrowAsync(signedOrder, takerAddress, {
+ takerAssetFillAmount,
+ // HACK(albrow): We need to hardcode the gas estimate here because
+ // the Geth gas estimator doesn't work with the way we use
+ // delegatecall and swallow errors.
+ gas: 270000,
+ });
// Verify post-conditions
const newOwnerMakerAsset = await erc721Token.ownerOf.callAsync(makerAssetId);
expect(newOwnerMakerAsset).to.be.bignumber.equal(takerAddress);
@@ -485,11 +495,11 @@ describe('Exchange wrappers', () => {
await exchangeWrapper.fillOrKillOrderAsync(signedOrders[0], takerAddress);
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
exchangeWrapper.batchFillOrKillOrdersAsync(signedOrders, takerAddress, {
takerAssetFillAmounts,
}),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
});
@@ -535,6 +545,10 @@ describe('Exchange wrappers', () => {
await exchangeWrapper.batchFillOrdersNoThrowAsync(signedOrders, takerAddress, {
takerAssetFillAmounts,
+ // HACK(albrow): We need to hardcode the gas estimate here because
+ // the Geth gas estimator doesn't work with the way we use
+ // delegatecall and swallow errors.
+ gas: 600000,
});
const newBalances = await erc20Wrapper.getBalancesAsync();
@@ -591,6 +605,10 @@ describe('Exchange wrappers', () => {
const newOrders = [invalidOrder, ...validOrders];
await exchangeWrapper.batchFillOrdersNoThrowAsync(newOrders, takerAddress, {
takerAssetFillAmounts,
+ // HACK(albrow): We need to hardcode the gas estimate here because
+ // the Geth gas estimator doesn't work with the way we use
+ // delegatecall and swallow errors.
+ gas: 450000,
});
const newBalances = await erc20Wrapper.getBalancesAsync();
@@ -679,11 +697,11 @@ describe('Exchange wrappers', () => {
orderFactory.newSignedOrder(),
];
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
exchangeWrapper.marketSellOrdersAsync(signedOrders, takerAddress, {
takerAssetFillAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(1000), 18),
}),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
});
@@ -753,6 +771,10 @@ describe('Exchange wrappers', () => {
});
await exchangeWrapper.marketSellOrdersNoThrowAsync(signedOrders, takerAddress, {
takerAssetFillAmount,
+ // HACK(albrow): We need to hardcode the gas estimate here because
+ // the Geth gas estimator doesn't work with the way we use
+ // delegatecall and swallow errors.
+ gas: 600000,
});
const newBalances = await erc20Wrapper.getBalancesAsync();
@@ -768,11 +790,11 @@ describe('Exchange wrappers', () => {
orderFactory.newSignedOrder(),
];
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
exchangeWrapper.marketSellOrdersNoThrowAsync(signedOrders, takerAddress, {
takerAssetFillAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(1000), 18),
}),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
});
@@ -857,11 +879,11 @@ describe('Exchange wrappers', () => {
orderFactory.newSignedOrder(),
];
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
exchangeWrapper.marketBuyOrdersAsync(signedOrders, takerAddress, {
makerAssetFillAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(1000), 18),
}),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
});
@@ -931,6 +953,10 @@ describe('Exchange wrappers', () => {
});
await exchangeWrapper.marketSellOrdersNoThrowAsync(signedOrders, takerAddress, {
takerAssetFillAmount,
+ // HACK(albrow): We need to hardcode the gas estimate here because
+ // the Geth gas estimator doesn't work with the way we use
+ // delegatecall and swallow errors.
+ gas: 600000,
});
const newBalances = await erc20Wrapper.getBalancesAsync();
@@ -946,11 +972,11 @@ describe('Exchange wrappers', () => {
orderFactory.newSignedOrder(),
];
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
exchangeWrapper.marketBuyOrdersNoThrowAsync(signedOrders, takerAddress, {
makerAssetFillAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(1000), 18),
}),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
});
diff --git a/packages/contracts/test/libraries/lib_bytes.ts b/packages/contracts/test/libraries/lib_bytes.ts
index c8aecea90..355e3603c 100644
--- a/packages/contracts/test/libraries/lib_bytes.ts
+++ b/packages/contracts/test/libraries/lib_bytes.ts
@@ -1,15 +1,12 @@
-import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils';
-import { AssetProxyId } from '@0xproject/types';
+import { BlockchainLifecycle } from '@0xproject/dev-utils';
import { BigNumber } from '@0xproject/utils';
-import { Web3Wrapper } from '@0xproject/web3-wrapper';
import BN = require('bn.js');
import * as chai from 'chai';
-import { LogWithDecodedArgs, TransactionReceiptWithDecodedLogs } from 'ethereum-types';
import ethUtil = require('ethereumjs-util');
-import * as Web3 from 'web3';
import { TestLibBytesContract } from '../../src/generated_contract_wrappers/test_lib_bytes';
import { artifacts } from '../../src/utils/artifacts';
+import { expectRevertOrAlwaysFailingTransactionAsync, expectRevertOrOtherErrorAsync } from '../../src/utils/assertions';
import { chaiSetup } from '../../src/utils/chai_setup';
import { constants } from '../../src/utils/constants';
import { provider, txDefaults, web3Wrapper } from '../../src/utils/web3_wrapper';
@@ -19,7 +16,6 @@ const expect = chai.expect;
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
describe('LibBytes', () => {
- let owner: string;
let libBytes: TestLibBytesContract;
const byteArrayShorterThan32Bytes = '0x012345';
const byteArrayShorterThan20Bytes = byteArrayShorterThan32Bytes;
@@ -42,7 +38,6 @@ describe('LibBytes', () => {
before(async () => {
// Setup accounts & addresses
const accounts = await web3Wrapper.getAvailableAddressesAsync();
- owner = accounts[0];
testAddress = accounts[1];
// Deploy LibBytes
libBytes = await TestLibBytesContract.deployFrom0xArtifactAsync(artifacts.TestLibBytes, provider, txDefaults);
@@ -63,7 +58,10 @@ describe('LibBytes', () => {
describe('popByte', () => {
it('should revert if length is 0', async () => {
- return expect(libBytes.publicPopByte.callAsync(constants.NULL_BYTES)).to.be.rejectedWith(constants.REVERT);
+ return expectRevertOrOtherErrorAsync(
+ libBytes.publicPopByte.callAsync(constants.NULL_BYTES),
+ constants.LIB_BYTES_GT_ZERO_LENGTH_REQUIRED,
+ );
});
it('should pop the last byte from the input and return it', async () => {
@@ -77,8 +75,9 @@ describe('LibBytes', () => {
describe('popAddress', () => {
it('should revert if length is less than 20', async () => {
- return expect(libBytes.publicPopAddress.callAsync(byteArrayShorterThan20Bytes)).to.be.rejectedWith(
- constants.REVERT,
+ return expectRevertOrOtherErrorAsync(
+ libBytes.publicPopAddress.callAsync(byteArrayShorterThan20Bytes),
+ constants.LIB_BYTES_GTE_20_LENGTH_REQUIRED,
);
});
@@ -162,16 +161,18 @@ describe('LibBytes', () => {
it('should fail if the byte array is too short to hold an address)', async () => {
const shortByteArray = '0xabcdef';
const offset = new BigNumber(0);
- return expect(libBytes.publicReadAddress.callAsync(shortByteArray, offset)).to.be.rejectedWith(
- constants.REVERT,
+ return expectRevertOrOtherErrorAsync(
+ libBytes.publicReadAddress.callAsync(shortByteArray, offset),
+ constants.LIB_BYTES_GTE_20_LENGTH_REQUIRED,
);
});
it('should fail if the length between the offset and end of the byte array is too short to hold an address)', async () => {
const byteArray = ethUtil.addHexPrefix(testAddress);
const badOffset = new BigNumber(ethUtil.toBuffer(byteArray).byteLength);
- return expect(libBytes.publicReadAddress.callAsync(byteArray, badOffset)).to.be.rejectedWith(
- constants.REVERT,
+ return expectRevertOrOtherErrorAsync(
+ libBytes.publicReadAddress.callAsync(byteArray, badOffset),
+ constants.LIB_BYTES_GTE_20_LENGTH_REQUIRED,
);
});
});
@@ -206,15 +207,17 @@ describe('LibBytes', () => {
it('should fail if the byte array is too short to hold a bytes32)', async () => {
const offset = new BigNumber(0);
- return expect(libBytes.publicReadBytes32.callAsync(byteArrayShorterThan32Bytes, offset)).to.be.rejectedWith(
- constants.REVERT,
+ return expectRevertOrOtherErrorAsync(
+ libBytes.publicReadBytes32.callAsync(byteArrayShorterThan32Bytes, offset),
+ constants.LIB_BYTES_GTE_32_LENGTH_REQUIRED,
);
});
it('should fail if the length between the offset and end of the byte array is too short to hold a bytes32)', async () => {
const badOffset = new BigNumber(ethUtil.toBuffer(testBytes32).byteLength);
- return expect(libBytes.publicReadBytes32.callAsync(testBytes32, badOffset)).to.be.rejectedWith(
- constants.REVERT,
+ return expectRevertOrOtherErrorAsync(
+ libBytes.publicReadBytes32.callAsync(testBytes32, badOffset),
+ constants.LIB_BYTES_GTE_32_LENGTH_REQUIRED,
);
});
});
@@ -253,8 +256,9 @@ describe('LibBytes', () => {
it('should fail if the byte array is too short to hold a uint256)', async () => {
const offset = new BigNumber(0);
- return expect(libBytes.publicReadUint256.callAsync(byteArrayShorterThan32Bytes, offset)).to.be.rejectedWith(
- constants.REVERT,
+ return expectRevertOrOtherErrorAsync(
+ libBytes.publicReadUint256.callAsync(byteArrayShorterThan32Bytes, offset),
+ constants.LIB_BYTES_GTE_32_LENGTH_REQUIRED,
);
});
@@ -263,8 +267,9 @@ describe('LibBytes', () => {
const testUint256AsBuffer = ethUtil.toBuffer(formattedTestUint256);
const byteArray = ethUtil.bufferToHex(testUint256AsBuffer);
const badOffset = new BigNumber(testUint256AsBuffer.byteLength);
- return expect(libBytes.publicReadUint256.callAsync(byteArray, badOffset)).to.be.rejectedWith(
- constants.REVERT,
+ return expectRevertOrOtherErrorAsync(
+ libBytes.publicReadUint256.callAsync(byteArray, badOffset),
+ constants.LIB_BYTES_GTE_32_LENGTH_REQUIRED,
);
});
});
@@ -281,10 +286,12 @@ describe('LibBytes', () => {
*/
describe('readFirst4', () => {
+ // AssertionError: expected promise to be rejected with an error including 'revert' but it was fulfilled with '0x08c379a0'
it('should revert if byte array has a length < 4', async () => {
const byteArrayLessThan4Bytes = '0x010101';
- return expect(libBytes.publicReadFirst4.callAsync(byteArrayLessThan4Bytes)).to.be.rejectedWith(
- constants.REVERT,
+ return expectRevertOrOtherErrorAsync(
+ libBytes.publicReadFirst4.callAsync(byteArrayLessThan4Bytes),
+ constants.LIB_BYTES_GTE_4_LENGTH_REQUIRED,
);
});
it('should return the first 4 bytes of a byte array of arbitrary length', async () => {
diff --git a/packages/contracts/test/multi_sig_with_time_lock.ts b/packages/contracts/test/multi_sig_with_time_lock.ts
index 930ff485a..f630743e1 100644
--- a/packages/contracts/test/multi_sig_with_time_lock.ts
+++ b/packages/contracts/test/multi_sig_with_time_lock.ts
@@ -1,26 +1,25 @@
-import { BlockchainLifecycle, web3Factory } from '@0xproject/dev-utils';
+import { BlockchainLifecycle } from '@0xproject/dev-utils';
import { BigNumber } from '@0xproject/utils';
-import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as chai from 'chai';
import { LogWithDecodedArgs } from 'ethereum-types';
-import * as _ from 'lodash';
import 'make-promises-safe';
-import * as Web3 from 'web3';
import {
MultiSigWalletWithTimeLockContract,
SubmissionContractEventArgs,
} from '../src/generated_contract_wrappers/multi_sig_wallet_with_time_lock';
import { artifacts } from '../src/utils/artifacts';
+import { expectRevertOrAlwaysFailingTransactionAsync } from '../src/utils/assertions';
import { chaiSetup } from '../src/utils/chai_setup';
import { constants } from '../src/utils/constants';
+import { increaseTimeAndMineBlockAsync } from '../src/utils/increase_time';
import { MultiSigWrapper } from '../src/utils/multi_sig_wrapper';
import { provider, txDefaults, web3Wrapper } from '../src/utils/web3_wrapper';
chaiSetup.configure();
const expect = chai.expect;
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
-
+// tslint:disable:no-unnecessary-type-assertion
describe('MultiSigWalletWithTimeLock', () => {
let owners: string[];
const REQUIRED_APPROVALS = new BigNumber(2);
@@ -69,9 +68,9 @@ describe('MultiSigWalletWithTimeLock', () => {
});
it('should throw when not called by wallet', async () => {
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
multiSig.changeTimeLock.sendTransactionAsync(SECONDS_TIME_LOCKED, { from: owners[0] }),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
it('should throw without enough confirmations', async () => {
@@ -80,10 +79,9 @@ describe('MultiSigWalletWithTimeLock', () => {
const res = await multiSigWrapper.submitTransactionAsync(destination, changeTimeLockData, owners[0]);
const log = res.logs[0] as LogWithDecodedArgs<SubmissionContractEventArgs>;
const txId = log.args.transactionId;
-
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
multiSig.executeTransaction.sendTransactionAsync(txId, { from: owners[0] }),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
it('should set confirmation time with enough confirmations', async () => {
@@ -148,14 +146,15 @@ describe('MultiSigWalletWithTimeLock', () => {
txId = log.args.transactionId;
await multiSigWrapper.confirmTransactionAsync(txId, owners[1]);
});
+
it('should throw if it has enough confirmations but is not past the time lock', async () => {
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
multiSig.executeTransaction.sendTransactionAsync(txId, { from: owners[0] }),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
it('should execute if it has enough confirmations and is past the time lock', async () => {
- await web3Wrapper.increaseTimeAsync(SECONDS_TIME_LOCKED.toNumber());
+ await increaseTimeAndMineBlockAsync(SECONDS_TIME_LOCKED.toNumber());
await web3Wrapper.awaitTransactionSuccessAsync(
await multiSig.executeTransaction.sendTransactionAsync(txId, { from: owners[0] }),
constants.AWAIT_TRANSACTION_MINED_MS,
@@ -167,3 +166,4 @@ describe('MultiSigWalletWithTimeLock', () => {
});
});
});
+// tslint:enable:no-unnecessary-type-assertion
diff --git a/packages/contracts/test/token_registry.ts b/packages/contracts/test/token_registry.ts
index e996f4478..f368fd73d 100644
--- a/packages/contracts/test/token_registry.ts
+++ b/packages/contracts/test/token_registry.ts
@@ -1,14 +1,13 @@
-import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils';
+import { BlockchainLifecycle } from '@0xproject/dev-utils';
import { BigNumber, NULL_BYTES } from '@0xproject/utils';
-import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as chai from 'chai';
import ethUtil = require('ethereumjs-util');
import * as _ from 'lodash';
import 'make-promises-safe';
-import * as Web3 from 'web3';
import { TokenRegistryContract } from '../src/generated_contract_wrappers/token_registry';
import { artifacts } from '../src/utils/artifacts';
+import { expectRevertOrAlwaysFailingTransactionAsync } from '../src/utils/assertions';
import { chaiSetup } from '../src/utils/chai_setup';
import { constants } from '../src/utils/constants';
import { TokenRegWrapper } from '../src/utils/token_registry_wrapper';
@@ -76,7 +75,7 @@ describe('TokenRegistry', () => {
describe('addToken', () => {
it('should throw when not called by owner', async () => {
- return expect(tokenRegWrapper.addTokenAsync(token1, notOwner)).to.be.rejectedWith(constants.REVERT);
+ return expectRevertOrAlwaysFailingTransactionAsync(tokenRegWrapper.addTokenAsync(token1, notOwner));
});
it('should add token metadata when called by owner', async () => {
@@ -88,19 +87,19 @@ describe('TokenRegistry', () => {
it('should throw if token already exists', async () => {
await tokenRegWrapper.addTokenAsync(token1, owner);
- return expect(tokenRegWrapper.addTokenAsync(token1, owner)).to.be.rejectedWith(constants.REVERT);
+ return expectRevertOrAlwaysFailingTransactionAsync(tokenRegWrapper.addTokenAsync(token1, owner));
});
it('should throw if token address is null', async () => {
- return expect(tokenRegWrapper.addTokenAsync(nullToken, owner)).to.be.rejectedWith(constants.REVERT);
+ return expectRevertOrAlwaysFailingTransactionAsync(tokenRegWrapper.addTokenAsync(nullToken, owner));
});
it('should throw if name already exists', async () => {
await tokenRegWrapper.addTokenAsync(token1, owner);
const duplicateNameToken = _.assign({}, token2, { name: token1.name });
- return expect(tokenRegWrapper.addTokenAsync(duplicateNameToken, owner)).to.be.rejectedWith(
- constants.REVERT,
+ return expectRevertOrAlwaysFailingTransactionAsync(
+ tokenRegWrapper.addTokenAsync(duplicateNameToken, owner),
);
});
@@ -110,8 +109,8 @@ describe('TokenRegistry', () => {
symbol: token1.symbol,
});
- return expect(tokenRegWrapper.addTokenAsync(duplicateSymbolToken, owner)).to.be.rejectedWith(
- constants.REVERT,
+ return expectRevertOrAlwaysFailingTransactionAsync(
+ tokenRegWrapper.addTokenAsync(duplicateSymbolToken, owner),
);
});
});
@@ -137,9 +136,9 @@ describe('TokenRegistry', () => {
describe('setTokenName', () => {
it('should throw when not called by owner', async () => {
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
tokenReg.setTokenName.sendTransactionAsync(token1.address, token2.name, { from: notOwner }),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
it('should change the token name when called by owner', async () => {
@@ -163,25 +162,25 @@ describe('TokenRegistry', () => {
it('should throw if the name already exists', async () => {
await tokenRegWrapper.addTokenAsync(token2, owner);
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
tokenReg.setTokenName.sendTransactionAsync(token1.address, token2.name, { from: owner }),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
it('should throw if token does not exist', async () => {
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
tokenReg.setTokenName.sendTransactionAsync(nullToken.address, token2.name, { from: owner }),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
});
describe('setTokenSymbol', () => {
it('should throw when not called by owner', async () => {
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
tokenReg.setTokenSymbol.sendTransactionAsync(token1.address, token2.symbol, {
from: notOwner,
}),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
it('should change the token symbol when called by owner', async () => {
@@ -203,28 +202,28 @@ describe('TokenRegistry', () => {
it('should throw if the symbol already exists', async () => {
await tokenRegWrapper.addTokenAsync(token2, owner);
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
tokenReg.setTokenSymbol.sendTransactionAsync(token1.address, token2.symbol, {
from: owner,
}),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
it('should throw if token does not exist', async () => {
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
tokenReg.setTokenSymbol.sendTransactionAsync(nullToken.address, token2.symbol, {
from: owner,
}),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
});
describe('removeToken', () => {
it('should throw if not called by owner', async () => {
const index = new BigNumber(0);
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
tokenReg.removeToken.sendTransactionAsync(token1.address, index, { from: notOwner }),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
it('should remove token metadata when called by owner', async () => {
@@ -241,17 +240,17 @@ describe('TokenRegistry', () => {
it('should throw if token does not exist', async () => {
const index = new BigNumber(0);
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
tokenReg.removeToken.sendTransactionAsync(nullToken.address, index, { from: owner }),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
it('should throw if token at given index does not match address', async () => {
await tokenRegWrapper.addTokenAsync(token2, owner);
const incorrectIndex = new BigNumber(0);
- return expect(
+ return expectRevertOrAlwaysFailingTransactionAsync(
tokenReg.removeToken.sendTransactionAsync(token2.address, incorrectIndex, { from: owner }),
- ).to.be.rejectedWith(constants.REVERT);
+ );
});
});
});
diff --git a/packages/contracts/test/unlimited_allowance_token.ts b/packages/contracts/test/unlimited_allowance_token.ts
index 92e9fc216..35315090b 100644
--- a/packages/contracts/test/unlimited_allowance_token.ts
+++ b/packages/contracts/test/unlimited_allowance_token.ts
@@ -1,12 +1,11 @@
-import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils';
+import { BlockchainLifecycle } from '@0xproject/dev-utils';
import { BigNumber } from '@0xproject/utils';
-import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as chai from 'chai';
import 'make-promises-safe';
-import * as Web3 from 'web3';
import { DummyERC20TokenContract } from '../src/generated_contract_wrappers/dummy_e_r_c20_token';
import { artifacts } from '../src/utils/artifacts';
+import { expectRevertOrAlwaysFailingTransactionAsync, expectRevertOrOtherErrorAsync } from '../src/utils/assertions';
import { chaiSetup } from '../src/utils/chai_setup';
import { constants } from '../src/utils/constants';
import { provider, txDefaults, web3Wrapper } from '../src/utils/web3_wrapper';
@@ -55,8 +54,9 @@ describe('UnlimitedAllowanceToken', () => {
it('should throw if owner has insufficient balance', async () => {
const ownerBalance = await token.balanceOf.callAsync(owner);
const amountToTransfer = ownerBalance.plus(1);
- return expect(token.transfer.callAsync(spender, amountToTransfer, { from: owner })).to.be.rejectedWith(
- constants.REVERT,
+ return expectRevertOrOtherErrorAsync(
+ token.transfer.callAsync(spender, amountToTransfer, { from: owner }),
+ constants.ERC20_INSUFFICIENT_BALANCE,
);
});
@@ -93,11 +93,12 @@ describe('UnlimitedAllowanceToken', () => {
await token.approve.sendTransactionAsync(spender, amountToTransfer, { from: owner }),
constants.AWAIT_TRANSACTION_MINED_MS,
);
- return expect(
+ return expectRevertOrOtherErrorAsync(
token.transferFrom.callAsync(owner, spender, amountToTransfer, {
from: spender,
}),
- ).to.be.rejectedWith(constants.REVERT);
+ constants.ERC20_INSUFFICIENT_BALANCE,
+ );
});
it('should throw if spender has insufficient allowance', async () => {
@@ -108,11 +109,12 @@ describe('UnlimitedAllowanceToken', () => {
const isSpenderAllowanceInsufficient = spenderAllowance.cmp(amountToTransfer) < 0;
expect(isSpenderAllowanceInsufficient).to.be.true();
- return expect(
+ return expectRevertOrOtherErrorAsync(
token.transferFrom.callAsync(owner, spender, amountToTransfer, {
from: spender,
}),
- ).to.be.rejectedWith(constants.REVERT);
+ constants.ERC20_INSUFFICIENT_ALLOWANCE,
+ );
});
it('should return true on a 0 value transfer', async () => {
diff --git a/packages/contracts/test/zrx_token.ts b/packages/contracts/test/zrx_token.ts
index 4493ff7a1..996030000 100644
--- a/packages/contracts/test/zrx_token.ts
+++ b/packages/contracts/test/zrx_token.ts
@@ -1,9 +1,8 @@
-import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils';
+import { BlockchainLifecycle } from '@0xproject/dev-utils';
import { BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as chai from 'chai';
import 'make-promises-safe';
-import * as Web3 from 'web3';
import { ZRXTokenContract } from '../src/generated_contract_wrappers/zrx_token';
import { artifacts } from '../src/utils/artifacts';