Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Commit

Permalink
Merge pull request #2362 from 0xProject/fix/revert-errors-utils
Browse files Browse the repository at this point in the history
Re-export the RevertErrors
  • Loading branch information
dekz authored Nov 27, 2019
2 parents 38dd45c + 389d4d1 commit 6ac5bcc
Show file tree
Hide file tree
Showing 58 changed files with 117 additions and 131 deletions.
2 changes: 1 addition & 1 deletion contracts/coordinator/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export {
LibCoordinatorRichErrorsContract,
LibEIP712CoordinatorDomainContract,
} from './wrappers';
export import CoordinatorRevertErrors = require('./revert_errors');
export { CoordinatorRevertErrors } from '@0x/utils';
export { CoordinatorServerCancellationResponse } from './client/index';
export { ApprovalFactory } from './approval_factory';
export { SignedCoordinatorApproval } from './types';
Expand Down
4 changes: 1 addition & 3 deletions contracts/coordinator/test/mixins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ import {
} from '@0x/contracts-test-utils';
import { LibBytesRevertErrors } from '@0x/contracts-utils';
import { SignatureType, SignedOrder } from '@0x/types';
import { BigNumber } from '@0x/utils';

import CoordinatorRevertErrors = require('../src/revert_errors');
import { BigNumber, CoordinatorRevertErrors } from '@0x/utils';

import { ApprovalFactory } from '../src/approval_factory';

Expand Down
2 changes: 1 addition & 1 deletion contracts/exchange-forwarder/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export { artifacts } from './artifacts';
export { ForwarderContract } from './wrappers';
export import ForwarderRevertErrors = require('./revert_errors');
export { ExchangeForwarderRevertErrors } from '@0x/utils';
export {
ContractArtifact,
ContractChains,
Expand Down
10 changes: 5 additions & 5 deletions contracts/exchange-forwarder/test/asset_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ import {
randomAddress,
verifyEventsFromLogs,
} from '@0x/contracts-test-utils';
import { BigNumber } from '@0x/utils';

import { ForwarderRevertErrors } from '../src';
import { BigNumber, ExchangeForwarderRevertErrors } from '@0x/utils';

import { artifacts } from './artifacts';
import { TestForwarderContract } from './wrappers';
Expand Down Expand Up @@ -159,7 +157,7 @@ blockchainTests('Supported asset type unit tests', env => {
const tx = forwarder
.transferAssetToSender(erc721AssetData, invalidAmount)
.awaitTransactionSuccessAsync({ from: receiver });
const expectedError = new ForwarderRevertErrors.Erc721AmountMustEqualOneError(invalidAmount);
const expectedError = new ExchangeForwarderRevertErrors.Erc721AmountMustEqualOneError(invalidAmount);
return expect(tx).to.revertWith(expectedError);
});
it('transfers an ERC20 token given ERC20Bridge assetData', async () => {
Expand All @@ -177,7 +175,9 @@ blockchainTests('Supported asset type unit tests', env => {
const tx = forwarder
.transferAssetToSender(randomBytes, TRANSFER_AMOUNT)
.awaitTransactionSuccessAsync({ from: receiver });
const expectedError = new ForwarderRevertErrors.UnsupportedAssetProxyError(hexSlice(randomBytes, 0, 4));
const expectedError = new ExchangeForwarderRevertErrors.UnsupportedAssetProxyError(
hexSlice(randomBytes, 0, 4),
);
return expect(tx).to.revertWith(expectedError);
});
});
Expand Down
2 changes: 1 addition & 1 deletion contracts/exchange-libs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export {
LibOrderContract,
LibZeroExTransactionContract,
} from './wrappers';
export import LibMathRevertErrors = require('./lib_math_revert_errors');
export { LibMathRevertErrors } from '@0x/utils';

import * as ReferenceFunctionsToExport from './reference_functions';
export import ReferenceFunctions = ReferenceFunctionsToExport;
Expand Down
4 changes: 1 addition & 3 deletions contracts/exchange-libs/src/reference_functions.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { ReferenceFunctions } from '@0x/contracts-utils';
import { FillResults, Order } from '@0x/types';
import { BigNumber } from '@0x/utils';

import LibMathRevertErrors = require('./lib_math_revert_errors');
import { BigNumber, LibMathRevertErrors } from '@0x/utils';

const { safeAdd, safeSub, safeMul, safeDiv } = ReferenceFunctions;

Expand Down
3 changes: 1 addition & 2 deletions contracts/exchange-libs/test/lib_fill_results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ import {
} from '@0x/contracts-test-utils';
import { SafeMathRevertErrors } from '@0x/contracts-utils';
import { FillResults, MatchedFillResults, Order } from '@0x/types';
import { BigNumber } from '@0x/utils';
import { BigNumber, LibMathRevertErrors } from '@0x/utils';
import { Web3Wrapper } from '@0x/web3-wrapper';
import * as _ from 'lodash';

import LibMathRevertErrors = require('../src/lib_math_revert_errors');
import { addFillResults, calculateFillResults, getPartialAmountFloor } from '../src/reference_functions';

import { artifacts } from './artifacts';
Expand Down
3 changes: 1 addition & 2 deletions contracts/exchange-libs/test/lib_math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import {
uint256Values,
} from '@0x/contracts-test-utils';
import { SafeMathRevertErrors } from '@0x/contracts-utils';
import { BigNumber } from '@0x/utils';
import { BigNumber, LibMathRevertErrors } from '@0x/utils';

import LibMathRevertErrors = require('../src/lib_math_revert_errors');
import {
getPartialAmountCeil,
getPartialAmountFloor,
Expand Down
3 changes: 1 addition & 2 deletions contracts/exchange-libs/test/reference_functions.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { constants, describe, expect } from '@0x/contracts-test-utils';
import { SafeMathRevertErrors } from '@0x/contracts-utils';
import { BigNumber } from '@0x/utils';
import { BigNumber, LibMathRevertErrors } from '@0x/utils';
import * as _ from 'lodash';

import LibMathRevertErrors = require('../src/lib_math_revert_errors');
import {
addFillResults,
getPartialAmountCeil,
Expand Down
2 changes: 1 addition & 1 deletion contracts/exchange/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export {
ExchangeProtocolFeeMultiplierEventArgs,
ExchangeTransactionExecutionEventArgs,
} from './wrappers';
export import ExchangeRevertErrors = require('./revert_errors');
export { ExchangeRevertErrors } from '@0x/utils';
export { exchangeDataEncoder } from './exchange_data_encoder';
export { SignedOrder } from '@0x/types';
export { ExchangeFunctionName } from '@0x/contracts-test-utils';
Expand Down
7 changes: 2 additions & 5 deletions contracts/exchange/test/dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,14 @@ import {
import { OwnableRevertErrors } from '@0x/contracts-utils';
import { BlockchainLifecycle } from '@0x/dev-utils';
import { AssetProxyId, RevertReason } from '@0x/types';
import { BigNumber, StringRevertError } from '@0x/utils';
import { BigNumber, ExchangeRevertErrors, StringRevertError } from '@0x/utils';
import * as chai from 'chai';
import { LogWithDecodedArgs } from 'ethereum-types';
import * as _ from 'lodash';

import ExchangeRevertErrors = require('../src/revert_errors');

import { artifacts } from './artifacts';
import { TestAssetProxyDispatcherAssetProxyRegisteredEventArgs, TestAssetProxyDispatcherContract } from './wrappers';

import { dependencyArtifacts } from './utils/dependency_artifacts';
import { TestAssetProxyDispatcherAssetProxyRegisteredEventArgs, TestAssetProxyDispatcherContract } from './wrappers';

chaiSetup.configure();
const expect = chai.expect;
Expand Down
5 changes: 1 addition & 4 deletions contracts/exchange/test/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,17 @@ import { ReferenceFunctions as LibReferenceFunctions } from '@0x/contracts-excha
import { blockchainTests, constants, expect, hexRandom, orderHashUtils } from '@0x/contracts-test-utils';
import { SafeMathRevertErrors } from '@0x/contracts-utils';
import { Order } from '@0x/types';
import { BigNumber } from '@0x/utils';
import { BigNumber, ExchangeRevertErrors } from '@0x/utils';
import { Web3Wrapper } from '@0x/web3-wrapper';
import { LogWithDecodedArgs } from 'ethereum-types';
import * as _ from 'lodash';

import ExchangeRevertErrors = require('../src/revert_errors');

import { artifacts } from './artifacts';
import {
TestExchangeInternalsContract,
TestExchangeInternalsDispatchTransferFromCalledEventArgs,
TestExchangeInternalsFillEventArgs,
} from './wrappers';

blockchainTests('Exchange core internal functions', env => {
const CHAIN_ID = 1337;
const ONE_ETHER = constants.ONE_ETHER;
Expand Down
4 changes: 1 addition & 3 deletions contracts/exchange/test/isolated_fill_order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import { LibMathRevertErrors, ReferenceFunctions as LibReferenceFunctions } from
import { blockchainTests, constants, expect, hexRandom } from '@0x/contracts-test-utils';
import { SafeMathRevertErrors } from '@0x/contracts-utils';
import { FillResults, OrderInfo, OrderStatus, SignatureType } from '@0x/types';
import { BigNumber } from '@0x/utils';
import { BigNumber, ExchangeRevertErrors } from '@0x/utils';
import * as _ from 'lodash';

import ExchangeRevertErrors = require('../src/revert_errors');

import {
AssetBalances,
createBadAssetData,
Expand Down
4 changes: 1 addition & 3 deletions contracts/exchange/test/lib_exchange_rich_error_decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ import {
randomAddress,
} from '@0x/contracts-test-utils';
import { generatePseudoRandomSalt } from '@0x/order-utils';
import { BigNumber, RevertError } from '@0x/utils';
import { BigNumber, ExchangeRevertErrors, RevertError } from '@0x/utils';
import * as _ from 'lodash';

import ExchangeRevertErrors = require('../src/revert_errors');

import { artifacts } from './artifacts';
import { TestLibExchangeRichErrorDecoderContract } from './wrappers';

Expand Down
4 changes: 1 addition & 3 deletions contracts/exchange/test/signature_validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ import {
transactionHashUtils,
} from '@0x/contracts-test-utils';
import { SignatureType, SignedOrder, SignedZeroExTransaction } from '@0x/types';
import { BigNumber, StringRevertError } from '@0x/utils';
import { BigNumber, ExchangeRevertErrors, StringRevertError } from '@0x/utils';
import { LogWithDecodedArgs } from 'ethereum-types';
import ethUtil = require('ethereumjs-util');

import ExchangeRevertErrors = require('../src/revert_errors');

import { artifacts } from './artifacts';
import {
ExchangeContract,
Expand Down
3 changes: 1 addition & 2 deletions contracts/exchange/test/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ import {
transactionHashUtils,
} from '@0x/contracts-test-utils';
import { FillResults, OrderStatus } from '@0x/types';
import { AbiEncoder, BigNumber } from '@0x/utils';
import { AbiEncoder, BigNumber, ExchangeRevertErrors } from '@0x/utils';
import { LogWithDecodedArgs, MethodAbi } from 'ethereum-types';
import * as ethUtil from 'ethereumjs-util';
import * as _ from 'lodash';

import { exchangeDataEncoder } from '../src/exchange_data_encoder';
import ExchangeRevertErrors = require('../src/revert_errors');

import { artifacts as localArtifacts } from './artifacts';
import { ExchangeWrapper } from './utils/exchange_wrapper';
Expand Down
4 changes: 1 addition & 3 deletions contracts/exchange/test/transactions_unit_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ import {
transactionHashUtils,
} from '@0x/contracts-test-utils';
import { EIP712DomainWithDefaultSchema, ZeroExTransaction } from '@0x/types';
import { BigNumber, StringRevertError } from '@0x/utils';
import { BigNumber, ExchangeRevertErrors, StringRevertError } from '@0x/utils';
import { LogWithDecodedArgs } from 'ethereum-types';
import * as _ from 'lodash';

import ExchangeRevertErrors = require('../src/revert_errors');

import { artifacts } from './artifacts';
import { TestTransactionsContract, TestTransactionsTransactionExecutionEventArgs } from './wrappers';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ import {
import { DevUtilsContract } from '@0x/contracts-dev-utils';
import { constants, expect, LogDecoder, orderHashUtils, orderUtils, signingUtils } from '@0x/contracts-test-utils';
import { FillResults, Order, SignatureType, SignedOrder } from '@0x/types';
import { BigNumber, errorUtils, providerUtils, RevertError, StringRevertError } from '@0x/utils';
import { BigNumber, errorUtils, ExchangeRevertErrors, providerUtils, RevertError, StringRevertError } from '@0x/utils';
import { SupportedProvider, Web3Wrapper } from '@0x/web3-wrapper';
import { LogWithDecodedArgs, TxData } from 'ethereum-types';
import * as _ from 'lodash';
import 'make-promises-safe';

import ExchangeRevertErrors = require('../../src/revert_errors');

import { artifacts } from '../artifacts';

import { ExchangeContract, ExchangeFillEventArgs } from '../wrappers';
Expand Down
4 changes: 1 addition & 3 deletions contracts/exchange/test/wrapper_unit_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ import {
} from '@0x/contracts-test-utils';
import { ReferenceFunctions as UtilReferenceFunctions, SafeMathRevertErrors } from '@0x/contracts-utils';
import { FillResults, Order } from '@0x/types';
import { AnyRevertError, BigNumber, StringRevertError } from '@0x/utils';
import { AnyRevertError, BigNumber, ExchangeRevertErrors, StringRevertError } from '@0x/utils';
import { LogEntry, LogWithDecodedArgs } from 'ethereum-types';
import * as ethjs from 'ethereumjs-util';
import * as _ from 'lodash';

import ExchangeRevertErrors = require('../src/revert_errors');

import { artifacts } from './artifacts';
import {
TestFillRoundingContract,
Expand Down
12 changes: 6 additions & 6 deletions contracts/integrations/test/forwarder/bridge_test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IAssetDataContract } from '@0x/contracts-asset-proxy';
import { DummyERC721TokenContract } from '@0x/contracts-erc721';
import { ForwarderContract, ForwarderRevertErrors } from '@0x/contracts-exchange-forwarder';
import { ForwarderContract } from '@0x/contracts-exchange-forwarder';
import {
blockchainTests,
constants,
Expand All @@ -10,7 +10,7 @@ import {
} from '@0x/contracts-test-utils';
import { generatePseudoRandomSalt } from '@0x/order-utils';
import { SignatureType, SignedOrder } from '@0x/types';
import { AbiEncoder, BigNumber } from '@0x/utils';
import { AbiEncoder, BigNumber, ExchangeForwarderRevertErrors } from '@0x/utils';

import { deployEth2DaiBridgeAsync } from '../bridges/deploy_eth2dai_bridge';
import { deployUniswapBridgeAsync } from '../bridges/deploy_uniswap_bridge';
Expand Down Expand Up @@ -251,7 +251,7 @@ blockchainTests.resets('Forwarder <> ERC20Bridge integration tests', env => {
takerFee: toBaseUnitAmount(0.01),
takerFeeAssetData: makerFeeTokenAssetData,
};
const expectedError = new ForwarderRevertErrors.UnsupportedFeeError(makerFeeTokenAssetData);
const expectedError = new ExchangeForwarderRevertErrors.UnsupportedFeeError(makerFeeTokenAssetData);
await testFactory.marketSellTestAsync([order], 1.23, { revertError: expectedError });
});
});
Expand Down Expand Up @@ -301,7 +301,7 @@ blockchainTests.resets('Forwarder <> ERC20Bridge integration tests', env => {
await testFactory.marketBuyTestAsync(orders, 2.56, { forwarderFeePercentage: 1 });
});
it('should revert if the amount of ETH sent is too low to fill the makerAssetAmount (Eth2Dai)', async () => {
const expectedError = new ForwarderRevertErrors.CompleteBuyFailedError(
const expectedError = new ExchangeForwarderRevertErrors.CompleteBuyFailedError(
eth2DaiBridgeOrder.makerAssetAmount.times(0.5),
constants.ZERO_AMOUNT,
);
Expand Down Expand Up @@ -352,7 +352,7 @@ blockchainTests.resets('Forwarder <> ERC20Bridge integration tests', env => {
await testFactory.marketBuyTestAsync(orders, 2.56, { forwarderFeePercentage: 1 });
});
it('should revert if the amount of ETH sent is too low to fill the makerAssetAmount (Uniswap)', async () => {
const expectedError = new ForwarderRevertErrors.CompleteBuyFailedError(
const expectedError = new ExchangeForwarderRevertErrors.CompleteBuyFailedError(
uniswapBridgeOrder.makerAssetAmount.times(0.5),
constants.ZERO_AMOUNT,
);
Expand All @@ -370,7 +370,7 @@ blockchainTests.resets('Forwarder <> ERC20Bridge integration tests', env => {
takerFee: toBaseUnitAmount(0.01),
takerFeeAssetData: makerFeeTokenAssetData,
};
const expectedError = new ForwarderRevertErrors.UnsupportedFeeError(makerFeeTokenAssetData);
const expectedError = new ExchangeForwarderRevertErrors.UnsupportedFeeError(makerFeeTokenAssetData);
await testFactory.marketBuyTestAsync([order], 1.23, { revertError: expectedError });
});
});
Expand Down
18 changes: 10 additions & 8 deletions contracts/integrations/test/forwarder/forwarder_test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DummyERC20TokenContract } from '@0x/contracts-erc20';
import { DummyERC721TokenContract } from '@0x/contracts-erc721';
import { artifacts as exchangeArtifacts, ExchangeContract } from '@0x/contracts-exchange';
import { artifacts, ForwarderContract, ForwarderRevertErrors } from '@0x/contracts-exchange-forwarder';
import { artifacts, ExchangeForwarderRevertErrors, ForwarderContract } from '@0x/contracts-exchange-forwarder';
import {
blockchainTests,
constants,
Expand Down Expand Up @@ -127,7 +127,9 @@ blockchainTests('Forwarder integration tests', env => {
exchange.address,
deployment.tokens.weth.address,
);
await expect(deployForwarder).to.revertWith(new ForwarderRevertErrors.UnregisteredAssetProxyError());
await expect(deployForwarder).to.revertWith(
new ExchangeForwarderRevertErrors.UnregisteredAssetProxyError(),
);
});
});
blockchainTests.resets('marketSellOrdersWithEth without extra fees', () => {
Expand Down Expand Up @@ -258,7 +260,7 @@ blockchainTests('Forwarder integration tests', env => {
takerFeeAssetData,
takerFee: toBaseUnitAmount(1),
});
const revertError = new ForwarderRevertErrors.UnsupportedFeeError(takerFeeAssetData);
const revertError = new ExchangeForwarderRevertErrors.UnsupportedFeeError(takerFeeAssetData);
await testFactory.marketSellTestAsync([order], 0.5, {
revertError,
});
Expand Down Expand Up @@ -316,7 +318,7 @@ blockchainTests('Forwarder integration tests', env => {
it('should fail if the fee is set too high', async () => {
const order = await maker.signOrderAsync();
const forwarderFeePercentage = new BigNumber(6);
const revertError = new ForwarderRevertErrors.FeePercentageTooLargeError(
const revertError = new ExchangeForwarderRevertErrors.FeePercentageTooLargeError(
getPercentageOfValue(constants.PERCENTAGE_DENOMINATOR, forwarderFeePercentage),
);
await testFactory.marketSellTestAsync([order], 0.5, {
Expand Down Expand Up @@ -383,7 +385,7 @@ blockchainTests('Forwarder integration tests', env => {
});
it('should revert if the amount of ETH sent is too low to fill the makerAssetAmount', async () => {
const order = await maker.signOrderAsync();
const revertError = new ForwarderRevertErrors.CompleteBuyFailedError(
const revertError = new ExchangeForwarderRevertErrors.CompleteBuyFailedError(
order.makerAssetAmount.times(0.5),
constants.ZERO_AMOUNT,
);
Expand Down Expand Up @@ -421,7 +423,7 @@ blockchainTests('Forwarder integration tests', env => {
takerFeeAssetData,
takerFee: toBaseUnitAmount(1),
});
const revertError = new ForwarderRevertErrors.UnsupportedFeeError(takerFeeAssetData);
const revertError = new ExchangeForwarderRevertErrors.UnsupportedFeeError(takerFeeAssetData);
await testFactory.marketBuyTestAsync([order], 0.5, {
revertError,
});
Expand Down Expand Up @@ -608,7 +610,7 @@ blockchainTests('Forwarder integration tests', env => {
});
it('should fail if the fee is set too high', async () => {
const order = await maker.signOrderAsync();
const revertError = new ForwarderRevertErrors.FeePercentageTooLargeError(
const revertError = new ExchangeForwarderRevertErrors.FeePercentageTooLargeError(
getPercentageOfValue(constants.PERCENTAGE_DENOMINATOR, new BigNumber(6)),
);
await testFactory.marketBuyTestAsync([order], 0.5, {
Expand All @@ -623,7 +625,7 @@ blockchainTests('Forwarder integration tests', env => {
order.takerAssetAmount.times(0.5).plus(DeploymentManager.protocolFee),
forwarderFeePercentage,
);
const revertError = new ForwarderRevertErrors.InsufficientEthForFeeError(ethFee, ethFee.minus(1));
const revertError = new ExchangeForwarderRevertErrors.InsufficientEthForFeeError(ethFee, ethFee.minus(1));
await testFactory.marketBuyTestAsync([order], 0.5, {
ethValueAdjustment: -1,
forwarderFeePercentage,
Expand Down
Loading

0 comments on commit 6ac5bcc

Please sign in to comment.