Merge branch 'refactor/check-revert-reasons' into feature/combinatorial-testing

* refactor/check-revert-reasons:
  Temporarily switch revert reasons to `TransferFailed`. Should be `InvalidAmount` but because of an oversight in the assembly implementation of `dispatchTransferFrom`, it always throws `TransferFailed`
  Expect RevertReason be passed in, not string
  Rename RevertReasons to RevertReason since singular enum names are more common

# Conflicts:
#	packages/contracts/test/asset_proxy/proxies.ts
#	packages/contracts/test/exchange/core.ts
This commit is contained in:
Fabio Berger
2018-06-26 18:53:44 +02:00
12 changed files with 92 additions and 88 deletions

View File

@@ -1,3 +1,4 @@
import { RevertReason } from '@0xproject/types';
import * as chai from 'chai'; import * as chai from 'chai';
import * as _ from 'lodash'; import * as _ from 'lodash';
@@ -59,7 +60,10 @@ export function expectRevertOrAlwaysFailingTransactionAsync<T>(p: Promise<T>): P
* @returns a new Promise which will reject if the conditions are not met and * @returns a new Promise which will reject if the conditions are not met and
* otherwise resolve with no value. * otherwise resolve with no value.
*/ */
export function expectRevertReasonOrAlwaysFailingTransactionAsync<T>(p: Promise<T>, reason: string): PromiseLike<void> { export function expectRevertReasonOrAlwaysFailingTransactionAsync<T>(
p: Promise<T>,
reason: RevertReason,
): PromiseLike<void> {
return _expectEitherErrorAsync(p, 'always failing transaction', reason); return _expectEitherErrorAsync(p, 'always failing transaction', reason);
} }

View File

@@ -1,5 +1,5 @@
import { BlockchainLifecycle } from '@0xproject/dev-utils'; import { BlockchainLifecycle } from '@0xproject/dev-utils';
import { RevertReasons } from '@0xproject/types'; import { RevertReason } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils'; import { BigNumber } from '@0xproject/utils';
import * as chai from 'chai'; import * as chai from 'chai';
@@ -49,7 +49,7 @@ describe('Authorizable', () => {
it('should throw if not called by owner', async () => { it('should throw if not called by owner', async () => {
return expectRevertReasonOrAlwaysFailingTransactionAsync( return expectRevertReasonOrAlwaysFailingTransactionAsync(
authorizable.addAuthorizedAddress.sendTransactionAsync(notOwner, { from: notOwner }), authorizable.addAuthorizedAddress.sendTransactionAsync(notOwner, { from: notOwner }),
RevertReasons.OnlyContractOwner, RevertReason.OnlyContractOwner,
); );
}); });
it('should allow owner to add an authorized address', async () => { it('should allow owner to add an authorized address', async () => {
@@ -67,7 +67,7 @@ describe('Authorizable', () => {
); );
return expectRevertReasonOrAlwaysFailingTransactionAsync( return expectRevertReasonOrAlwaysFailingTransactionAsync(
authorizable.addAuthorizedAddress.sendTransactionAsync(address, { from: owner }), authorizable.addAuthorizedAddress.sendTransactionAsync(address, { from: owner }),
RevertReasons.TargetAlreadyAuthorized, RevertReason.TargetAlreadyAuthorized,
); );
}); });
}); });
@@ -82,7 +82,7 @@ describe('Authorizable', () => {
authorizable.removeAuthorizedAddress.sendTransactionAsync(address, { authorizable.removeAuthorizedAddress.sendTransactionAsync(address, {
from: notOwner, from: notOwner,
}), }),
RevertReasons.OnlyContractOwner, RevertReason.OnlyContractOwner,
); );
}); });
@@ -106,7 +106,7 @@ describe('Authorizable', () => {
authorizable.removeAuthorizedAddress.sendTransactionAsync(address, { authorizable.removeAuthorizedAddress.sendTransactionAsync(address, {
from: owner, from: owner,
}), }),
RevertReasons.TargetNotAuthorized, RevertReason.TargetNotAuthorized,
); );
}); });
}); });

View File

@@ -1,6 +1,6 @@
import { BlockchainLifecycle } from '@0xproject/dev-utils'; import { BlockchainLifecycle } from '@0xproject/dev-utils';
import { assetProxyUtils, generatePseudoRandomSalt } from '@0xproject/order-utils'; import { assetProxyUtils, generatePseudoRandomSalt } from '@0xproject/order-utils';
import { RevertReasons } from '@0xproject/types'; import { RevertReason } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils'; import { BigNumber } from '@0xproject/utils';
import * as chai from 'chai'; import * as chai from 'chai';
import { LogWithDecodedArgs } from 'ethereum-types'; import { LogWithDecodedArgs } from 'ethereum-types';
@@ -173,7 +173,7 @@ describe('Asset Transfer Proxies', () => {
transferAmount, transferAmount,
{ from: exchangeAddress }, { from: exchangeAddress },
), ),
RevertReasons.TransferFailed, RevertReason.TransferFailed,
); );
}); });
@@ -187,7 +187,7 @@ describe('Asset Transfer Proxies', () => {
erc20Proxy.transferFrom.sendTransactionAsync(encodedAssetData, makerAddress, takerAddress, amount, { erc20Proxy.transferFrom.sendTransactionAsync(encodedAssetData, makerAddress, takerAddress, amount, {
from: notAuthorized, from: notAuthorized,
}), }),
RevertReasons.SenderNotAuthorized, RevertReason.SenderNotAuthorized,
); );
}); });
}); });
@@ -239,7 +239,7 @@ describe('Asset Transfer Proxies', () => {
erc20Proxy.batchTransferFrom.sendTransactionAsync(assetData, fromAddresses, toAddresses, amounts, { erc20Proxy.batchTransferFrom.sendTransactionAsync(assetData, fromAddresses, toAddresses, amounts, {
from: notAuthorized, from: notAuthorized,
}), }),
RevertReasons.SenderNotAuthorized, RevertReason.SenderNotAuthorized,
); );
}); });
}); });
@@ -381,7 +381,7 @@ describe('Asset Transfer Proxies', () => {
amount, amount,
{ from: exchangeAddress }, { from: exchangeAddress },
), ),
RevertReasons.InvalidAmount, RevertReason.InvalidAmount,
); );
}); });
@@ -401,7 +401,7 @@ describe('Asset Transfer Proxies', () => {
amount, amount,
{ from: exchangeAddress }, { from: exchangeAddress },
), ),
RevertReasons.InvalidAmount, RevertReason.InvalidAmount,
); );
}); });
@@ -421,7 +421,7 @@ describe('Asset Transfer Proxies', () => {
erc20Proxy.transferFrom.sendTransactionAsync(encodedAssetData, makerAddress, takerAddress, amount, { erc20Proxy.transferFrom.sendTransactionAsync(encodedAssetData, makerAddress, takerAddress, amount, {
from: exchangeAddress, from: exchangeAddress,
}), }),
RevertReasons.TransferFailed, RevertReason.TransferFailed,
); );
}); });
@@ -438,7 +438,7 @@ describe('Asset Transfer Proxies', () => {
amount, amount,
{ from: notAuthorized }, { from: notAuthorized },
), ),
RevertReasons.SenderNotAuthorized, RevertReason.SenderNotAuthorized,
); );
}); });
}); });
@@ -493,7 +493,7 @@ describe('Asset Transfer Proxies', () => {
erc721Proxy.batchTransferFrom.sendTransactionAsync(assetData, fromAddresses, toAddresses, amounts, { erc721Proxy.batchTransferFrom.sendTransactionAsync(assetData, fromAddresses, toAddresses, amounts, {
from: notAuthorized, from: notAuthorized,
}), }),
RevertReasons.SenderNotAuthorized, RevertReason.SenderNotAuthorized,
); );
}); });
}); });

View File

@@ -1,6 +1,6 @@
import { BlockchainLifecycle } from '@0xproject/dev-utils'; import { BlockchainLifecycle } from '@0xproject/dev-utils';
import { assetProxyUtils, orderHashUtils } from '@0xproject/order-utils'; import { assetProxyUtils, orderHashUtils } from '@0xproject/order-utils';
import { AssetProxyId, RevertReasons, SignedOrder } from '@0xproject/types'; import { AssetProxyId, RevertReason, SignedOrder } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils'; import { BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper'; import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as chai from 'chai'; import * as chai from 'chai';
@@ -147,7 +147,7 @@ describe('Exchange core', () => {
signedOrder.signature = invalidSigHex; signedOrder.signature = invalidSigHex;
return expectRevertReasonOrAlwaysFailingTransactionAsync( return expectRevertReasonOrAlwaysFailingTransactionAsync(
exchangeWrapper.fillOrderAsync(signedOrder, takerAddress), exchangeWrapper.fillOrderAsync(signedOrder, takerAddress),
RevertReasons.InvalidOrderSignature, RevertReason.InvalidOrderSignature,
); );
}); });
@@ -156,7 +156,7 @@ describe('Exchange core', () => {
await exchangeWrapper.fillOrderAsync(signedOrder, takerAddress); await exchangeWrapper.fillOrderAsync(signedOrder, takerAddress);
return expectRevertReasonOrAlwaysFailingTransactionAsync( return expectRevertReasonOrAlwaysFailingTransactionAsync(
exchangeWrapper.fillOrderAsync(signedOrder, takerAddress), exchangeWrapper.fillOrderAsync(signedOrder, takerAddress),
RevertReasons.OrderUnfillable, RevertReason.OrderUnfillable,
); );
}); });
}); });
@@ -170,7 +170,7 @@ describe('Exchange core', () => {
it('should throw if not sent by maker', async () => { it('should throw if not sent by maker', async () => {
return expectRevertReasonOrAlwaysFailingTransactionAsync( return expectRevertReasonOrAlwaysFailingTransactionAsync(
exchangeWrapper.cancelOrderAsync(signedOrder, takerAddress), exchangeWrapper.cancelOrderAsync(signedOrder, takerAddress),
RevertReasons.InvalidMaker, RevertReason.InvalidMaker,
); );
}); });
@@ -181,7 +181,7 @@ describe('Exchange core', () => {
return expectRevertReasonOrAlwaysFailingTransactionAsync( return expectRevertReasonOrAlwaysFailingTransactionAsync(
exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress), exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress),
RevertReasons.OrderUnfillable, RevertReason.OrderUnfillable,
); );
}); });
@@ -192,7 +192,7 @@ describe('Exchange core', () => {
return expectRevertReasonOrAlwaysFailingTransactionAsync( return expectRevertReasonOrAlwaysFailingTransactionAsync(
exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress), exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress),
RevertReasons.OrderUnfillable, RevertReason.OrderUnfillable,
); );
}); });
@@ -202,7 +202,7 @@ describe('Exchange core', () => {
exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, {
takerAssetFillAmount: signedOrder.takerAssetAmount.div(2), takerAssetFillAmount: signedOrder.takerAssetAmount.div(2),
}), }),
RevertReasons.OrderUnfillable, RevertReason.OrderUnfillable,
); );
}); });
@@ -225,7 +225,7 @@ describe('Exchange core', () => {
await exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress); await exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress);
return expectRevertReasonOrAlwaysFailingTransactionAsync( return expectRevertReasonOrAlwaysFailingTransactionAsync(
exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress), exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress),
RevertReasons.OrderUnfillable, RevertReason.OrderUnfillable,
); );
}); });
@@ -235,7 +235,7 @@ describe('Exchange core', () => {
}); });
return expectRevertReasonOrAlwaysFailingTransactionAsync( return expectRevertReasonOrAlwaysFailingTransactionAsync(
exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress), exchangeWrapper.cancelOrderAsync(signedOrder, makerAddress),
RevertReasons.OrderUnfillable, RevertReason.OrderUnfillable,
); );
}); });
@@ -255,7 +255,7 @@ describe('Exchange core', () => {
exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, {
takerAssetFillAmount: fillTakerAssetAmount2, takerAssetFillAmount: fillTakerAssetAmount2,
}), }),
RevertReasons.RoundingError, RevertReason.RoundingError,
); );
}); });
}); });
@@ -267,7 +267,7 @@ describe('Exchange core', () => {
const lesserOrderEpoch = new BigNumber(0); const lesserOrderEpoch = new BigNumber(0);
return expectRevertReasonOrAlwaysFailingTransactionAsync( return expectRevertReasonOrAlwaysFailingTransactionAsync(
exchangeWrapper.cancelOrdersUpToAsync(lesserOrderEpoch, makerAddress), exchangeWrapper.cancelOrdersUpToAsync(lesserOrderEpoch, makerAddress),
RevertReasons.InvalidNewOrderEpoch, RevertReason.InvalidNewOrderEpoch,
); );
}); });
@@ -276,7 +276,7 @@ describe('Exchange core', () => {
await exchangeWrapper.cancelOrdersUpToAsync(orderEpoch, makerAddress); await exchangeWrapper.cancelOrdersUpToAsync(orderEpoch, makerAddress);
return expectRevertReasonOrAlwaysFailingTransactionAsync( return expectRevertReasonOrAlwaysFailingTransactionAsync(
exchangeWrapper.cancelOrdersUpToAsync(orderEpoch, makerAddress), exchangeWrapper.cancelOrdersUpToAsync(orderEpoch, makerAddress),
RevertReasons.InvalidNewOrderEpoch, RevertReason.InvalidNewOrderEpoch,
); );
}); });
@@ -410,7 +410,7 @@ describe('Exchange core', () => {
const takerAssetFillAmount = signedOrder.takerAssetAmount; const takerAssetFillAmount = signedOrder.takerAssetAmount;
return expectRevertReasonOrAlwaysFailingTransactionAsync( return expectRevertReasonOrAlwaysFailingTransactionAsync(
exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount }), exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount }),
RevertReasons.InvalidAmount, RevertReason.TransferFailed,
); );
}); });
@@ -433,7 +433,7 @@ describe('Exchange core', () => {
const takerAssetFillAmount = signedOrder.takerAssetAmount; const takerAssetFillAmount = signedOrder.takerAssetAmount;
return expectRevertReasonOrAlwaysFailingTransactionAsync( return expectRevertReasonOrAlwaysFailingTransactionAsync(
exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount }), exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount }),
RevertReasons.InvalidAmount, RevertReason.TransferFailed,
); );
}); });
@@ -450,7 +450,7 @@ describe('Exchange core', () => {
const takerAssetFillAmount = signedOrder.takerAssetAmount.div(2); const takerAssetFillAmount = signedOrder.takerAssetAmount.div(2);
return expectRevertReasonOrAlwaysFailingTransactionAsync( return expectRevertReasonOrAlwaysFailingTransactionAsync(
exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount }), exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount }),
RevertReasons.RoundingError, RevertReason.RoundingError,
); );
}); });
}); });

View File

@@ -1,6 +1,6 @@
import { BlockchainLifecycle } from '@0xproject/dev-utils'; import { BlockchainLifecycle } from '@0xproject/dev-utils';
import { assetProxyUtils } from '@0xproject/order-utils'; import { assetProxyUtils } from '@0xproject/order-utils';
import { AssetProxyId, RevertReasons } from '@0xproject/types'; import { AssetProxyId, RevertReason } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils'; import { BigNumber } from '@0xproject/utils';
import * as chai from 'chai'; import * as chai from 'chai';
@@ -185,7 +185,7 @@ describe('AssetProxyDispatcher', () => {
constants.NULL_ADDRESS, constants.NULL_ADDRESS,
{ from: owner }, { from: owner },
), ),
RevertReasons.AssetProxyMismatch, RevertReason.AssetProxyMismatch,
); );
}); });
@@ -227,7 +227,7 @@ describe('AssetProxyDispatcher', () => {
prevProxyAddress, prevProxyAddress,
{ from: notOwner }, { from: notOwner },
), ),
RevertReasons.OnlyContractOwner, RevertReason.OnlyContractOwner,
); );
}); });
@@ -240,7 +240,7 @@ describe('AssetProxyDispatcher', () => {
prevProxyAddress, prevProxyAddress,
{ from: owner }, { from: owner },
), ),
RevertReasons.AssetProxyIdMismatch, RevertReason.AssetProxyIdMismatch,
); );
}); });
}); });
@@ -319,7 +319,7 @@ describe('AssetProxyDispatcher', () => {
amount, amount,
{ from: owner }, { from: owner },
), ),
RevertReasons.AssetProxyDoesNotExist, RevertReason.AssetProxyDoesNotExist,
); );
}); });
}); });

View File

@@ -1,6 +1,6 @@
import { BlockchainLifecycle } from '@0xproject/dev-utils'; import { BlockchainLifecycle } from '@0xproject/dev-utils';
import { assetProxyUtils } from '@0xproject/order-utils'; import { assetProxyUtils } from '@0xproject/order-utils';
import { AssetProxyId, RevertReasons } from '@0xproject/types'; import { AssetProxyId, RevertReason } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils'; import { BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper'; import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as chai from 'chai'; import * as chai from 'chai';
@@ -603,7 +603,7 @@ describe('matchOrders', () => {
// Match orders // Match orders
return expectRevertReasonOrAlwaysFailingTransactionAsync( return expectRevertReasonOrAlwaysFailingTransactionAsync(
exchangeWrapper.matchOrdersAsync(signedOrderLeft, signedOrderRight, takerAddress), exchangeWrapper.matchOrdersAsync(signedOrderLeft, signedOrderRight, takerAddress),
RevertReasons.OrderUnfillable, RevertReason.OrderUnfillable,
); );
}); });
@@ -628,7 +628,7 @@ describe('matchOrders', () => {
// Match orders // Match orders
return expectRevertReasonOrAlwaysFailingTransactionAsync( return expectRevertReasonOrAlwaysFailingTransactionAsync(
exchangeWrapper.matchOrdersAsync(signedOrderLeft, signedOrderRight, takerAddress), exchangeWrapper.matchOrdersAsync(signedOrderLeft, signedOrderRight, takerAddress),
RevertReasons.OrderUnfillable, RevertReason.OrderUnfillable,
); );
}); });
@@ -657,7 +657,7 @@ describe('matchOrders', () => {
erc20BalancesByOwner, erc20BalancesByOwner,
erc721TokenIdsByOwner, erc721TokenIdsByOwner,
), ),
RevertReasons.NegativeSpreadRequired, RevertReason.NegativeSpreadRequired,
); );
}); });
@@ -690,7 +690,7 @@ describe('matchOrders', () => {
// reverse of the left order, rather than checking equality. This // reverse of the left order, rather than checking equality. This
// saves a bunch of gas, but as a result if the assetData fields are // saves a bunch of gas, but as a result if the assetData fields are
// off then the failure ends up happening at signature validation // off then the failure ends up happening at signature validation
RevertReasons.InvalidOrderSignature, RevertReason.InvalidOrderSignature,
); );
}); });
@@ -721,7 +721,7 @@ describe('matchOrders', () => {
erc20BalancesByOwner, erc20BalancesByOwner,
erc721TokenIdsByOwner, erc721TokenIdsByOwner,
), ),
RevertReasons.InvalidOrderSignature, RevertReason.InvalidOrderSignature,
); );
}); });

View File

@@ -1,6 +1,6 @@
import { BlockchainLifecycle } from '@0xproject/dev-utils'; import { BlockchainLifecycle } from '@0xproject/dev-utils';
import { addSignedMessagePrefix, assetProxyUtils, MessagePrefixType, orderHashUtils } from '@0xproject/order-utils'; import { addSignedMessagePrefix, assetProxyUtils, MessagePrefixType, orderHashUtils } from '@0xproject/order-utils';
import { RevertReasons, SignatureType, SignedOrder } from '@0xproject/types'; import { RevertReason, SignatureType, SignedOrder } from '@0xproject/types';
import * as chai from 'chai'; import * as chai from 'chai';
import { LogWithDecodedArgs } from 'ethereum-types'; import { LogWithDecodedArgs } from 'ethereum-types';
import ethUtil = require('ethereumjs-util'); import ethUtil = require('ethereumjs-util');
@@ -107,7 +107,7 @@ describe('MixinSignatureValidator', () => {
signedOrder.makerAddress, signedOrder.makerAddress,
emptySignature, emptySignature,
), ),
RevertReasons.LengthGreaterThan0Required, RevertReason.LengthGreaterThan0Required,
); );
}); });
@@ -121,7 +121,7 @@ describe('MixinSignatureValidator', () => {
signedOrder.makerAddress, signedOrder.makerAddress,
unsupportedSignatureHex, unsupportedSignatureHex,
), ),
RevertReasons.SignatureUnsupported, RevertReason.SignatureUnsupported,
); );
}); });
@@ -134,7 +134,7 @@ describe('MixinSignatureValidator', () => {
signedOrder.makerAddress, signedOrder.makerAddress,
unsupportedSignatureHex, unsupportedSignatureHex,
), ),
RevertReasons.SignatureIllegal, RevertReason.SignatureIllegal,
); );
}); });
@@ -161,7 +161,7 @@ describe('MixinSignatureValidator', () => {
signedOrder.makerAddress, signedOrder.makerAddress,
signatureHex, signatureHex,
), ),
RevertReasons.Length0Required, RevertReason.Length0Required,
); );
}); });

View File

@@ -1,6 +1,6 @@
import { BlockchainLifecycle } from '@0xproject/dev-utils'; import { BlockchainLifecycle } from '@0xproject/dev-utils';
import { assetProxyUtils, generatePseudoRandomSalt } from '@0xproject/order-utils'; import { assetProxyUtils, generatePseudoRandomSalt } from '@0xproject/order-utils';
import { AssetProxyId, OrderWithoutExchangeAddress, RevertReasons, SignedOrder } from '@0xproject/types'; import { AssetProxyId, OrderWithoutExchangeAddress, RevertReason, SignedOrder } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils'; import { BigNumber } from '@0xproject/utils';
import * as chai from 'chai'; import * as chai from 'chai';
@@ -130,7 +130,7 @@ describe('Exchange transactions', () => {
it('should throw if not called by specified sender', async () => { it('should throw if not called by specified sender', async () => {
return expectRevertReasonOrAlwaysFailingTransactionAsync( return expectRevertReasonOrAlwaysFailingTransactionAsync(
exchangeWrapper.executeTransactionAsync(signedTx, takerAddress), exchangeWrapper.executeTransactionAsync(signedTx, takerAddress),
RevertReasons.FailedExecution, RevertReason.FailedExecution,
); );
}); });
@@ -173,7 +173,7 @@ describe('Exchange transactions', () => {
await exchangeWrapper.executeTransactionAsync(signedTx, senderAddress); await exchangeWrapper.executeTransactionAsync(signedTx, senderAddress);
return expectRevertReasonOrAlwaysFailingTransactionAsync( return expectRevertReasonOrAlwaysFailingTransactionAsync(
exchangeWrapper.executeTransactionAsync(signedTx, senderAddress), exchangeWrapper.executeTransactionAsync(signedTx, senderAddress),
RevertReasons.InvalidTxHash, RevertReason.InvalidTxHash,
); );
}); });
@@ -193,7 +193,7 @@ describe('Exchange transactions', () => {
it('should throw if not called by specified sender', async () => { it('should throw if not called by specified sender', async () => {
return expectRevertReasonOrAlwaysFailingTransactionAsync( return expectRevertReasonOrAlwaysFailingTransactionAsync(
exchangeWrapper.executeTransactionAsync(signedTx, makerAddress), exchangeWrapper.executeTransactionAsync(signedTx, makerAddress),
RevertReasons.FailedExecution, RevertReason.FailedExecution,
); );
}); });
@@ -201,7 +201,7 @@ describe('Exchange transactions', () => {
await exchangeWrapper.executeTransactionAsync(signedTx, senderAddress); await exchangeWrapper.executeTransactionAsync(signedTx, senderAddress);
return expectRevertReasonOrAlwaysFailingTransactionAsync( return expectRevertReasonOrAlwaysFailingTransactionAsync(
exchangeWrapper.fillOrderAsync(signedOrder, senderAddress), exchangeWrapper.fillOrderAsync(signedOrder, senderAddress),
RevertReasons.OrderUnfillable, RevertReason.OrderUnfillable,
); );
}); });
}); });
@@ -253,7 +253,7 @@ describe('Exchange transactions', () => {
signedFillTx.signature, signedFillTx.signature,
{ from: takerAddress }, { from: takerAddress },
), ),
RevertReasons.FailedExecution, RevertReason.FailedExecution,
); );
}); });
@@ -372,7 +372,7 @@ describe('Exchange transactions', () => {
signedOrder.signature, signedOrder.signature,
{ from: takerAddress }, { from: takerAddress },
), ),
RevertReasons.MakerNotWhitelisted, RevertReason.MakerNotWhitelisted,
); );
}); });
@@ -394,7 +394,7 @@ describe('Exchange transactions', () => {
signedOrder.signature, signedOrder.signature,
{ from: takerAddress }, { from: takerAddress },
), ),
RevertReasons.TakerNotWhitelisted, RevertReason.TakerNotWhitelisted,
); );
}); });

View File

@@ -1,6 +1,6 @@
import { BlockchainLifecycle } from '@0xproject/dev-utils'; import { BlockchainLifecycle } from '@0xproject/dev-utils';
import { assetProxyUtils } from '@0xproject/order-utils'; import { assetProxyUtils } from '@0xproject/order-utils';
import { AssetProxyId, RevertReasons, SignedOrder } from '@0xproject/types'; import { AssetProxyId, RevertReason, SignedOrder } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils'; import { BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper'; import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as chai from 'chai'; import * as chai from 'chai';
@@ -175,7 +175,7 @@ describe('Exchange wrappers', () => {
return expectRevertReasonOrAlwaysFailingTransactionAsync( return expectRevertReasonOrAlwaysFailingTransactionAsync(
exchangeWrapper.fillOrKillOrderAsync(signedOrder, takerAddress), exchangeWrapper.fillOrKillOrderAsync(signedOrder, takerAddress),
RevertReasons.OrderUnfillable, RevertReason.OrderUnfillable,
); );
}); });
@@ -188,7 +188,7 @@ describe('Exchange wrappers', () => {
return expectRevertReasonOrAlwaysFailingTransactionAsync( return expectRevertReasonOrAlwaysFailingTransactionAsync(
exchangeWrapper.fillOrKillOrderAsync(signedOrder, takerAddress), exchangeWrapper.fillOrKillOrderAsync(signedOrder, takerAddress),
RevertReasons.CompleteFillFailed, RevertReason.CompleteFillFailed,
); );
}); });
}); });
@@ -503,7 +503,7 @@ describe('Exchange wrappers', () => {
exchangeWrapper.batchFillOrKillOrdersAsync(signedOrders, takerAddress, { exchangeWrapper.batchFillOrKillOrdersAsync(signedOrders, takerAddress, {
takerAssetFillAmounts, takerAssetFillAmounts,
}), }),
RevertReasons.OrderUnfillable, RevertReason.OrderUnfillable,
); );
}); });
}); });
@@ -708,7 +708,7 @@ describe('Exchange wrappers', () => {
}), }),
// We simply use the takerAssetData from the first order for all orders. // We simply use the takerAssetData from the first order for all orders.
// If they are not the same, the contract throws when validating the order signature // If they are not the same, the contract throws when validating the order signature
RevertReasons.InvalidOrderSignature, RevertReason.InvalidOrderSignature,
); );
}); });
}); });
@@ -924,7 +924,7 @@ describe('Exchange wrappers', () => {
exchangeWrapper.marketBuyOrdersAsync(signedOrders, takerAddress, { exchangeWrapper.marketBuyOrdersAsync(signedOrders, takerAddress, {
makerAssetFillAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(1000), 18), makerAssetFillAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(1000), 18),
}), }),
RevertReasons.InvalidOrderSignature, RevertReason.InvalidOrderSignature,
); );
}); });
}); });

View File

@@ -1,6 +1,6 @@
import { BlockchainLifecycle } from '@0xproject/dev-utils'; import { BlockchainLifecycle } from '@0xproject/dev-utils';
import { assetProxyUtils, generatePseudoRandomSalt } from '@0xproject/order-utils'; import { assetProxyUtils, generatePseudoRandomSalt } from '@0xproject/order-utils';
import { RevertReasons } from '@0xproject/types'; import { RevertReason } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils'; import { BigNumber } from '@0xproject/utils';
import BN = require('bn.js'); import BN = require('bn.js');
import * as chai from 'chai'; import * as chai from 'chai';
@@ -102,7 +102,7 @@ describe('LibBytes', () => {
it('should revert if length is 0', async () => { it('should revert if length is 0', async () => {
return expectRevertOrOtherErrorAsync( return expectRevertOrOtherErrorAsync(
libBytes.publicPopLastByte.callAsync(constants.NULL_BYTES), libBytes.publicPopLastByte.callAsync(constants.NULL_BYTES),
RevertReasons.LibBytesGreaterThanZeroLengthRequired, RevertReason.LibBytesGreaterThanZeroLengthRequired,
); );
}); });
it('should pop the last byte from the input and return it', async () => { it('should pop the last byte from the input and return it', async () => {
@@ -118,7 +118,7 @@ describe('LibBytes', () => {
it('should revert if length is less than 20', async () => { it('should revert if length is less than 20', async () => {
return expectRevertOrOtherErrorAsync( return expectRevertOrOtherErrorAsync(
libBytes.publicPopLast20Bytes.callAsync(byteArrayShorterThan20Bytes), libBytes.publicPopLast20Bytes.callAsync(byteArrayShorterThan20Bytes),
RevertReasons.LibBytesGreaterOrEqualTo20LengthRequired, RevertReason.LibBytesGreaterOrEqualTo20LengthRequired,
); );
}); });
it('should pop the last 20 bytes from the input and return it', async () => { it('should pop the last 20 bytes from the input and return it', async () => {
@@ -186,7 +186,7 @@ describe('LibBytes', () => {
it('should revert if dest is shorter than source', async () => { it('should revert if dest is shorter than source', async () => {
return expectRevertOrOtherErrorAsync( return expectRevertOrOtherErrorAsync(
libBytes.publicDeepCopyBytes.callAsync(byteArrayShorterThan32Bytes, byteArrayLongerThan32Bytes), libBytes.publicDeepCopyBytes.callAsync(byteArrayShorterThan32Bytes, byteArrayLongerThan32Bytes),
RevertReasons.LibBytesGreaterOrEqualToSourceBytesLengthRequired, RevertReason.LibBytesGreaterOrEqualToSourceBytesLengthRequired,
); );
}); });
it('should overwrite dest with source if source and dest have equal length', async () => { it('should overwrite dest with source if source and dest have equal length', async () => {
@@ -239,7 +239,7 @@ describe('LibBytes', () => {
const offset = new BigNumber(0); const offset = new BigNumber(0);
return expectRevertOrOtherErrorAsync( return expectRevertOrOtherErrorAsync(
libBytes.publicReadAddress.callAsync(shortByteArray, offset), libBytes.publicReadAddress.callAsync(shortByteArray, offset),
RevertReasons.LibBytesGreaterOrEqualTo20LengthRequired, RevertReason.LibBytesGreaterOrEqualTo20LengthRequired,
); );
}); });
it('should fail if the length between the offset and end of the byte array is too short to hold an address', async () => { it('should fail if the length between the offset and end of the byte array is too short to hold an address', async () => {
@@ -247,7 +247,7 @@ describe('LibBytes', () => {
const badOffset = new BigNumber(ethUtil.toBuffer(byteArray).byteLength); const badOffset = new BigNumber(ethUtil.toBuffer(byteArray).byteLength);
return expectRevertOrOtherErrorAsync( return expectRevertOrOtherErrorAsync(
libBytes.publicReadAddress.callAsync(byteArray, badOffset), libBytes.publicReadAddress.callAsync(byteArray, badOffset),
RevertReasons.LibBytesGreaterOrEqualTo20LengthRequired, RevertReason.LibBytesGreaterOrEqualTo20LengthRequired,
); );
}); });
}); });
@@ -283,7 +283,7 @@ describe('LibBytes', () => {
const offset = new BigNumber(0); const offset = new BigNumber(0);
return expectRevertOrOtherErrorAsync( return expectRevertOrOtherErrorAsync(
libBytes.publicWriteAddress.callAsync(byteArrayShorterThan20Bytes, offset, testAddress), libBytes.publicWriteAddress.callAsync(byteArrayShorterThan20Bytes, offset, testAddress),
RevertReasons.LibBytesGreaterOrEqualTo20LengthRequired, RevertReason.LibBytesGreaterOrEqualTo20LengthRequired,
); );
}); });
it('should fail if the length between the offset and end of the byte array is too short to hold an address', async () => { it('should fail if the length between the offset and end of the byte array is too short to hold an address', async () => {
@@ -291,7 +291,7 @@ describe('LibBytes', () => {
const badOffset = new BigNumber(ethUtil.toBuffer(byteArray).byteLength); const badOffset = new BigNumber(ethUtil.toBuffer(byteArray).byteLength);
return expectRevertOrOtherErrorAsync( return expectRevertOrOtherErrorAsync(
libBytes.publicWriteAddress.callAsync(byteArray, badOffset, testAddress), libBytes.publicWriteAddress.callAsync(byteArray, badOffset, testAddress),
RevertReasons.LibBytesGreaterOrEqualTo20LengthRequired, RevertReason.LibBytesGreaterOrEqualTo20LengthRequired,
); );
}); });
}); });
@@ -315,14 +315,14 @@ describe('LibBytes', () => {
const offset = new BigNumber(0); const offset = new BigNumber(0);
return expectRevertOrOtherErrorAsync( return expectRevertOrOtherErrorAsync(
libBytes.publicReadBytes32.callAsync(byteArrayShorterThan32Bytes, offset), libBytes.publicReadBytes32.callAsync(byteArrayShorterThan32Bytes, offset),
RevertReasons.LibBytesGreaterOrEqualTo32LengthRequired, RevertReason.LibBytesGreaterOrEqualTo32LengthRequired,
); );
}); });
it('should fail if the length between the offset and end of the byte array is too short to hold a bytes32', async () => { 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); const badOffset = new BigNumber(ethUtil.toBuffer(testBytes32).byteLength);
return expectRevertOrOtherErrorAsync( return expectRevertOrOtherErrorAsync(
libBytes.publicReadBytes32.callAsync(testBytes32, badOffset), libBytes.publicReadBytes32.callAsync(testBytes32, badOffset),
RevertReasons.LibBytesGreaterOrEqualTo32LengthRequired, RevertReason.LibBytesGreaterOrEqualTo32LengthRequired,
); );
}); });
}); });
@@ -358,7 +358,7 @@ describe('LibBytes', () => {
const offset = new BigNumber(0); const offset = new BigNumber(0);
return expectRevertOrOtherErrorAsync( return expectRevertOrOtherErrorAsync(
libBytes.publicWriteBytes32.callAsync(byteArrayShorterThan32Bytes, offset, testBytes32), libBytes.publicWriteBytes32.callAsync(byteArrayShorterThan32Bytes, offset, testBytes32),
RevertReasons.LibBytesGreaterOrEqualTo32LengthRequired, RevertReason.LibBytesGreaterOrEqualTo32LengthRequired,
); );
}); });
it('should fail if the length between the offset and end of the byte array is too short to hold a bytes32', async () => { it('should fail if the length between the offset and end of the byte array is too short to hold a bytes32', async () => {
@@ -366,7 +366,7 @@ describe('LibBytes', () => {
const badOffset = new BigNumber(ethUtil.toBuffer(byteArray).byteLength); const badOffset = new BigNumber(ethUtil.toBuffer(byteArray).byteLength);
return expectRevertOrOtherErrorAsync( return expectRevertOrOtherErrorAsync(
libBytes.publicWriteBytes32.callAsync(byteArray, badOffset, testBytes32), libBytes.publicWriteBytes32.callAsync(byteArray, badOffset, testBytes32),
RevertReasons.LibBytesGreaterOrEqualTo32LengthRequired, RevertReason.LibBytesGreaterOrEqualTo32LengthRequired,
); );
}); });
}); });
@@ -394,7 +394,7 @@ describe('LibBytes', () => {
const offset = new BigNumber(0); const offset = new BigNumber(0);
return expectRevertOrOtherErrorAsync( return expectRevertOrOtherErrorAsync(
libBytes.publicReadUint256.callAsync(byteArrayShorterThan32Bytes, offset), libBytes.publicReadUint256.callAsync(byteArrayShorterThan32Bytes, offset),
RevertReasons.LibBytesGreaterOrEqualTo32LengthRequired, RevertReason.LibBytesGreaterOrEqualTo32LengthRequired,
); );
}); });
it('should fail if the length between the offset and end of the byte array is too short to hold a uint256', async () => { it('should fail if the length between the offset and end of the byte array is too short to hold a uint256', async () => {
@@ -404,7 +404,7 @@ describe('LibBytes', () => {
const badOffset = new BigNumber(testUint256AsBuffer.byteLength); const badOffset = new BigNumber(testUint256AsBuffer.byteLength);
return expectRevertOrOtherErrorAsync( return expectRevertOrOtherErrorAsync(
libBytes.publicReadUint256.callAsync(byteArray, badOffset), libBytes.publicReadUint256.callAsync(byteArray, badOffset),
RevertReasons.LibBytesGreaterOrEqualTo32LengthRequired, RevertReason.LibBytesGreaterOrEqualTo32LengthRequired,
); );
}); });
}); });
@@ -444,7 +444,7 @@ describe('LibBytes', () => {
const offset = new BigNumber(0); const offset = new BigNumber(0);
return expectRevertOrOtherErrorAsync( return expectRevertOrOtherErrorAsync(
libBytes.publicWriteUint256.callAsync(byteArrayShorterThan32Bytes, offset, testUint256), libBytes.publicWriteUint256.callAsync(byteArrayShorterThan32Bytes, offset, testUint256),
RevertReasons.LibBytesGreaterOrEqualTo32LengthRequired, RevertReason.LibBytesGreaterOrEqualTo32LengthRequired,
); );
}); });
it('should fail if the length between the offset and end of the byte array is too short to hold a uint256', async () => { it('should fail if the length between the offset and end of the byte array is too short to hold a uint256', async () => {
@@ -452,7 +452,7 @@ describe('LibBytes', () => {
const badOffset = new BigNumber(ethUtil.toBuffer(byteArray).byteLength); const badOffset = new BigNumber(ethUtil.toBuffer(byteArray).byteLength);
return expectRevertOrOtherErrorAsync( return expectRevertOrOtherErrorAsync(
libBytes.publicWriteUint256.callAsync(byteArray, badOffset, testUint256), libBytes.publicWriteUint256.callAsync(byteArray, badOffset, testUint256),
RevertReasons.LibBytesGreaterOrEqualTo32LengthRequired, RevertReason.LibBytesGreaterOrEqualTo32LengthRequired,
); );
}); });
}); });
@@ -463,7 +463,7 @@ describe('LibBytes', () => {
const byteArrayLessThan4Bytes = '0x010101'; const byteArrayLessThan4Bytes = '0x010101';
return expectRevertOrOtherErrorAsync( return expectRevertOrOtherErrorAsync(
libBytes.publicReadBytes4.callAsync(byteArrayLessThan4Bytes, new BigNumber(0)), libBytes.publicReadBytes4.callAsync(byteArrayLessThan4Bytes, new BigNumber(0)),
RevertReasons.LibBytesGreaterOrEqualTo4LengthRequired, RevertReason.LibBytesGreaterOrEqualTo4LengthRequired,
); );
}); });
it('should return the first 4 bytes of a byte array of arbitrary length', async () => { it('should return the first 4 bytes of a byte array of arbitrary length', async () => {
@@ -518,28 +518,28 @@ describe('LibBytes', () => {
const offset = new BigNumber(0); const offset = new BigNumber(0);
return expectRevertOrOtherErrorAsync( return expectRevertOrOtherErrorAsync(
libBytes.publicReadBytesWithLength.callAsync(byteArrayShorterThan32Bytes, offset), libBytes.publicReadBytesWithLength.callAsync(byteArrayShorterThan32Bytes, offset),
RevertReasons.LibBytesGreaterOrEqualTo32LengthRequired, RevertReason.LibBytesGreaterOrEqualTo32LengthRequired,
); );
}); });
it('should fail if we store a nested byte array length, without a nested byte array', async () => { it('should fail if we store a nested byte array length, without a nested byte array', async () => {
const offset = new BigNumber(0); const offset = new BigNumber(0);
return expectRevertOrOtherErrorAsync( return expectRevertOrOtherErrorAsync(
libBytes.publicReadBytesWithLength.callAsync(testBytes32, offset), libBytes.publicReadBytesWithLength.callAsync(testBytes32, offset),
RevertReasons.LibBytesGreaterOrEqualToNestedBytesLengthRequired, RevertReason.LibBytesGreaterOrEqualToNestedBytesLengthRequired,
); );
}); });
it('should fail if the length between the offset and end of the byte array is too short to hold the length of a nested byte array', async () => { it('should fail if the length between the offset and end of the byte array is too short to hold the length of a nested byte array', async () => {
const badOffset = new BigNumber(ethUtil.toBuffer(byteArrayShorterThan32Bytes).byteLength); const badOffset = new BigNumber(ethUtil.toBuffer(byteArrayShorterThan32Bytes).byteLength);
return expectRevertOrOtherErrorAsync( return expectRevertOrOtherErrorAsync(
libBytes.publicReadBytesWithLength.callAsync(byteArrayShorterThan32Bytes, badOffset), libBytes.publicReadBytesWithLength.callAsync(byteArrayShorterThan32Bytes, badOffset),
RevertReasons.LibBytesGreaterOrEqualTo32LengthRequired, RevertReason.LibBytesGreaterOrEqualTo32LengthRequired,
); );
}); });
it('should fail if the length between the offset and end of the byte array is too short to hold the nested byte array', async () => { it('should fail if the length between the offset and end of the byte array is too short to hold the nested byte array', async () => {
const badOffset = new BigNumber(ethUtil.toBuffer(testBytes32).byteLength); const badOffset = new BigNumber(ethUtil.toBuffer(testBytes32).byteLength);
return expectRevertOrOtherErrorAsync( return expectRevertOrOtherErrorAsync(
libBytes.publicReadBytesWithLength.callAsync(testBytes32, badOffset), libBytes.publicReadBytesWithLength.callAsync(testBytes32, badOffset),
RevertReasons.LibBytesGreaterOrEqualTo32LengthRequired, RevertReason.LibBytesGreaterOrEqualTo32LengthRequired,
); );
}); });
}); });
@@ -651,7 +651,7 @@ describe('LibBytes', () => {
const emptyByteArray = ethUtil.bufferToHex(new Buffer(1)); const emptyByteArray = ethUtil.bufferToHex(new Buffer(1));
return expectRevertOrOtherErrorAsync( return expectRevertOrOtherErrorAsync(
libBytes.publicWriteBytesWithLength.callAsync(emptyByteArray, offset, longData), libBytes.publicWriteBytesWithLength.callAsync(emptyByteArray, offset, longData),
RevertReasons.LibBytesGreaterOrEqualToNestedBytesLengthRequired, RevertReason.LibBytesGreaterOrEqualToNestedBytesLengthRequired,
); );
}); });
it('should fail if the length between the offset and end of the byte array is too short to hold the length of a nested byte array)', async () => { it('should fail if the length between the offset and end of the byte array is too short to hold the length of a nested byte array)', async () => {
@@ -659,7 +659,7 @@ describe('LibBytes', () => {
const badOffset = new BigNumber(ethUtil.toBuffer(shortTestBytesAsBuffer).byteLength); const badOffset = new BigNumber(ethUtil.toBuffer(shortTestBytesAsBuffer).byteLength);
return expectRevertOrOtherErrorAsync( return expectRevertOrOtherErrorAsync(
libBytes.publicWriteBytesWithLength.callAsync(emptyByteArray, badOffset, shortData), libBytes.publicWriteBytesWithLength.callAsync(emptyByteArray, badOffset, shortData),
RevertReasons.LibBytesGreaterOrEqualToNestedBytesLengthRequired, RevertReason.LibBytesGreaterOrEqualToNestedBytesLengthRequired,
); );
}); });
}); });

View File

@@ -1,5 +1,5 @@
import { BlockchainLifecycle } from '@0xproject/dev-utils'; import { BlockchainLifecycle } from '@0xproject/dev-utils';
import { RevertReasons } from '@0xproject/types'; import { RevertReason } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils'; import { BigNumber } from '@0xproject/utils';
import * as chai from 'chai'; import * as chai from 'chai';
@@ -56,7 +56,7 @@ describe('UnlimitedAllowanceToken', () => {
const amountToTransfer = ownerBalance.plus(1); const amountToTransfer = ownerBalance.plus(1);
return expectRevertOrOtherErrorAsync( return expectRevertOrOtherErrorAsync(
token.transfer.callAsync(spender, amountToTransfer, { from: owner }), token.transfer.callAsync(spender, amountToTransfer, { from: owner }),
RevertReasons.Erc20InsufficientBalance, RevertReason.Erc20InsufficientBalance,
); );
}); });
@@ -97,7 +97,7 @@ describe('UnlimitedAllowanceToken', () => {
token.transferFrom.callAsync(owner, spender, amountToTransfer, { token.transferFrom.callAsync(owner, spender, amountToTransfer, {
from: spender, from: spender,
}), }),
RevertReasons.Erc20InsufficientBalance, RevertReason.Erc20InsufficientBalance,
); );
}); });
@@ -113,7 +113,7 @@ describe('UnlimitedAllowanceToken', () => {
token.transferFrom.callAsync(owner, spender, amountToTransfer, { token.transferFrom.callAsync(owner, spender, amountToTransfer, {
from: spender, from: spender,
}), }),
RevertReasons.Erc20InsufficientAllowance, RevertReason.Erc20InsufficientAllowance,
); );
}); });

View File

@@ -169,7 +169,7 @@ export interface ERC721AssetData {
receiverData: string; receiverData: string;
} }
export enum RevertReasons { export enum RevertReason {
OrderUnfillable = 'ORDER_UNFILLABLE', OrderUnfillable = 'ORDER_UNFILLABLE',
InvalidMaker = 'INVALID_MAKER', InvalidMaker = 'INVALID_MAKER',
InvalidTaker = 'INVALID_TAKER', InvalidTaker = 'INVALID_TAKER',