aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
Diffstat (limited to 'packages')
-rw-r--r--packages/contract-wrappers/src/utils/utils.ts3
-rw-r--r--packages/contracts/src/utils/combinatorial_utils.ts213
-rw-r--r--packages/contracts/src/utils/types.ts31
-rw-r--r--packages/order-watcher/src/order_watcher/order_watcher.ts4
-rw-r--r--packages/order-watcher/src/utils/utils.ts3
-rw-r--r--packages/react-docs/src/components/type.tsx4
-rw-r--r--packages/react-docs/src/components/type_definition.tsx4
-rw-r--r--packages/react-docs/src/utils/typedoc_utils.ts4
-rw-r--r--packages/utils/CHANGELOG.json8
-rw-r--r--packages/utils/src/error_utils.ts (renamed from packages/react-docs/src/utils/utils.ts)2
-rw-r--r--packages/utils/src/index.ts1
-rw-r--r--packages/website/ts/components/token_balances.tsx4
-rw-r--r--packages/website/ts/components/ui/lifecycle_raised_button.tsx3
-rw-r--r--packages/website/ts/components/wallet/wallet.tsx4
-rw-r--r--packages/website/ts/utils/utils.ts3
15 files changed, 268 insertions, 23 deletions
diff --git a/packages/contract-wrappers/src/utils/utils.ts b/packages/contract-wrappers/src/utils/utils.ts
index 7cf9450a0..689a7ee0a 100644
--- a/packages/contract-wrappers/src/utils/utils.ts
+++ b/packages/contract-wrappers/src/utils/utils.ts
@@ -1,9 +1,6 @@
import { BigNumber } from '@0xproject/utils';
export const utils = {
- spawnSwitchErr(name: string, value: any): Error {
- return new Error(`Unexpected switch value: ${value} encountered for ${name}`);
- },
getCurrentUnixTimestampSec(): BigNumber {
const milisecondsInSecond = 1000;
return new BigNumber(Date.now() / milisecondsInSecond).round();
diff --git a/packages/contracts/src/utils/combinatorial_utils.ts b/packages/contracts/src/utils/combinatorial_utils.ts
new file mode 100644
index 000000000..c7d48c86d
--- /dev/null
+++ b/packages/contracts/src/utils/combinatorial_utils.ts
@@ -0,0 +1,213 @@
+import { assetProxyUtils, generatePseudoRandomSalt } from '@0xproject/order-utils';
+import { Order } from '@0xproject/types';
+import { BigNumber, errorUtils } from '@0xproject/utils';
+
+import { constants } from './constants';
+import {
+ AssetDataScenario,
+ ERC721Token,
+ ExpirationTimeSecondsScenario,
+ FeeRecipientAddressScenario,
+ OrderAmountScenario,
+} from './types';
+
+const TEN_UNITS_EIGHTEEN_DECIMALS = new BigNumber(10000000000000000000);
+const POINT_ONE_UNITS_EIGHTEEN_DECIMALS = new BigNumber(100000000000000000);
+const TEN_UNITS_FIVE_DECIMALS = new BigNumber(1000000);
+const ONE_NFT_UNIT = new BigNumber(1);
+const TEN_MINUTES_MS = 1000 * 60 * 10;
+
+export const combinatorialUtils = {
+ generateOrder(
+ userAddresses: string[],
+ zrxAddress: string,
+ nonZrxERC20EighteenDecimalTokenAddress: string,
+ erc20FiveDecimalTokenAddress: string,
+ erc721Token: ERC721Token,
+ exchangeAddress: string,
+ feeRecipientScenario: FeeRecipientAddressScenario,
+ makerAssetAmountScenario: OrderAmountScenario,
+ takerAssetAmountScenario: OrderAmountScenario,
+ makerFeeScenario: OrderAmountScenario,
+ takerFeeScenario: OrderAmountScenario,
+ expirationTimeSecondsScenario: ExpirationTimeSecondsScenario,
+ makerAssetDataScenario: AssetDataScenario,
+ takerAssetDataScenario: AssetDataScenario,
+ ): Order {
+ let feeRecipientAddress;
+ let makerAssetAmount;
+ let takerAssetAmount;
+ let makerFee;
+ let takerFee;
+ let expirationTimeSeconds;
+ let makerAssetData;
+ let takerAssetData;
+
+ switch (feeRecipientScenario) {
+ case FeeRecipientAddressScenario.BurnAddress:
+ feeRecipientAddress = constants.NULL_ADDRESS;
+ break;
+ case FeeRecipientAddressScenario.EthUserAddress:
+ feeRecipientAddress = userAddresses[4];
+ break;
+ default:
+ throw errorUtils.spawnSwitchErr('FeeRecipientAddressScenario', feeRecipientScenario);
+ }
+
+ const invalidAssetProxyIdHex = '0A';
+ switch (makerAssetDataScenario) {
+ case AssetDataScenario.ZRXFeeToken:
+ makerAssetData = assetProxyUtils.encodeERC20ProxyData(zrxAddress);
+ break;
+ case AssetDataScenario.ERC20NonZRXEighteenDecimals:
+ makerAssetData = assetProxyUtils.encodeERC20ProxyData(nonZrxERC20EighteenDecimalTokenAddress);
+ break;
+ case AssetDataScenario.ERC20FiveDecimals:
+ makerAssetData = assetProxyUtils.encodeERC20ProxyData(erc20FiveDecimalTokenAddress);
+ break;
+ case AssetDataScenario.ERC20InvalidAssetProxyId: {
+ const validAssetData = assetProxyUtils.encodeERC20ProxyData(nonZrxERC20EighteenDecimalTokenAddress);
+ makerAssetData = `${validAssetData.slice(0, -2)}${invalidAssetProxyIdHex}`;
+ break;
+ }
+ case AssetDataScenario.ERC721ValidAssetProxyId:
+ makerAssetData = assetProxyUtils.encodeERC721ProxyData(erc721Token.address, erc721Token.id);
+ break;
+ case AssetDataScenario.ERC721InvalidAssetProxyId: {
+ const validAssetData = assetProxyUtils.encodeERC721ProxyData(erc721Token.address, erc721Token.id);
+ makerAssetData = `${validAssetData.slice(0, -2)}${invalidAssetProxyIdHex}`;
+ break;
+ }
+ default:
+ throw errorUtils.spawnSwitchErr('AssetDataScenario', makerAssetDataScenario);
+ }
+
+ switch (takerAssetDataScenario) {
+ case AssetDataScenario.ZRXFeeToken:
+ takerAssetData = assetProxyUtils.encodeERC20ProxyData(zrxAddress);
+ break;
+ case AssetDataScenario.ERC20NonZRXEighteenDecimals:
+ takerAssetData = assetProxyUtils.encodeERC20ProxyData(nonZrxERC20EighteenDecimalTokenAddress);
+ break;
+ case AssetDataScenario.ERC20FiveDecimals:
+ takerAssetData = assetProxyUtils.encodeERC20ProxyData(erc20FiveDecimalTokenAddress);
+ break;
+ case AssetDataScenario.ERC20InvalidAssetProxyId: {
+ const validAssetData = assetProxyUtils.encodeERC20ProxyData(nonZrxERC20EighteenDecimalTokenAddress);
+ takerAssetData = `${validAssetData.slice(0, -2)}${invalidAssetProxyIdHex}`;
+ break;
+ }
+ case AssetDataScenario.ERC721ValidAssetProxyId:
+ takerAssetData = assetProxyUtils.encodeERC721ProxyData(erc721Token.address, erc721Token.id);
+ break;
+ case AssetDataScenario.ERC721InvalidAssetProxyId: {
+ const validAssetData = assetProxyUtils.encodeERC721ProxyData(erc721Token.address, erc721Token.id);
+ takerAssetData = `${validAssetData.slice(0, -2)}${invalidAssetProxyIdHex}`;
+ break;
+ }
+ default:
+ throw errorUtils.spawnSwitchErr('AssetDataScenario', takerAssetDataScenario);
+ }
+
+ switch (makerAssetAmountScenario) {
+ case OrderAmountScenario.NonZero:
+ switch (makerAssetDataScenario) {
+ case AssetDataScenario.ERC20NonZRXEighteenDecimals:
+ case AssetDataScenario.ERC20InvalidAssetProxyId:
+ makerAssetAmount = TEN_UNITS_EIGHTEEN_DECIMALS;
+ break;
+ case AssetDataScenario.ERC20FiveDecimals:
+ makerAssetAmount = TEN_UNITS_FIVE_DECIMALS;
+ break;
+ case AssetDataScenario.ERC721ValidAssetProxyId:
+ case AssetDataScenario.ERC721InvalidAssetProxyId:
+ makerAssetAmount = ONE_NFT_UNIT;
+ break;
+ default:
+ throw errorUtils.spawnSwitchErr('AssetDataScenario', makerAssetDataScenario);
+ }
+ break;
+ case OrderAmountScenario.Zero:
+ makerAssetAmount = new BigNumber(0);
+ break;
+ default:
+ throw errorUtils.spawnSwitchErr('OrderAmountScenario', makerAssetAmountScenario);
+ }
+
+ switch (takerAssetAmountScenario) {
+ case OrderAmountScenario.NonZero:
+ switch (takerAssetDataScenario) {
+ case AssetDataScenario.ERC20NonZRXEighteenDecimals:
+ case AssetDataScenario.ERC20InvalidAssetProxyId:
+ takerAssetAmount = TEN_UNITS_EIGHTEEN_DECIMALS;
+ break;
+ case AssetDataScenario.ERC20FiveDecimals:
+ takerAssetAmount = TEN_UNITS_FIVE_DECIMALS;
+ break;
+ case AssetDataScenario.ERC721ValidAssetProxyId:
+ case AssetDataScenario.ERC721InvalidAssetProxyId:
+ takerAssetAmount = ONE_NFT_UNIT;
+ break;
+ default:
+ throw errorUtils.spawnSwitchErr('AssetDataScenario', takerAssetDataScenario);
+ }
+ break;
+ case OrderAmountScenario.Zero:
+ takerAssetAmount = new BigNumber(0);
+ break;
+ default:
+ throw errorUtils.spawnSwitchErr('OrderAmountScenario', takerAssetAmountScenario);
+ }
+
+ switch (makerFeeScenario) {
+ case OrderAmountScenario.NonZero:
+ makerFee = POINT_ONE_UNITS_EIGHTEEN_DECIMALS;
+ break;
+ case OrderAmountScenario.Zero:
+ makerFee = new BigNumber(0);
+ break;
+ default:
+ throw errorUtils.spawnSwitchErr('OrderAmountScenario', makerFeeScenario);
+ }
+
+ switch (takerFeeScenario) {
+ case OrderAmountScenario.NonZero:
+ takerFee = POINT_ONE_UNITS_EIGHTEEN_DECIMALS;
+ break;
+ case OrderAmountScenario.Zero:
+ takerFee = new BigNumber(0);
+ break;
+ default:
+ throw errorUtils.spawnSwitchErr('OrderAmountScenario', takerFeeScenario);
+ }
+
+ switch (expirationTimeSecondsScenario) {
+ case ExpirationTimeSecondsScenario.InFuture:
+ expirationTimeSeconds = new BigNumber(Date.now() + TEN_MINUTES_MS);
+ break;
+ case ExpirationTimeSecondsScenario.InPast:
+ expirationTimeSeconds = new BigNumber(Date.now() - TEN_MINUTES_MS);
+ break;
+ default:
+ throw errorUtils.spawnSwitchErr('ExpirationTimeSecondsScenario', expirationTimeSecondsScenario);
+ }
+
+ const order: Order = {
+ senderAddress: constants.NULL_ADDRESS,
+ makerAddress: userAddresses[1],
+ takerAddress: userAddresses[2],
+ makerFee,
+ takerFee,
+ makerAssetAmount,
+ takerAssetAmount,
+ makerAssetData,
+ takerAssetData,
+ salt: generatePseudoRandomSalt(),
+ exchangeAddress,
+ feeRecipientAddress,
+ expirationTimeSeconds,
+ };
+
+ return order;
+ },
+};
diff --git a/packages/contracts/src/utils/types.ts b/packages/contracts/src/utils/types.ts
index 491890fa1..94c7f627f 100644
--- a/packages/contracts/src/utils/types.ts
+++ b/packages/contracts/src/utils/types.ts
@@ -147,3 +147,34 @@ export interface MatchOrder {
leftSignature: string;
rightSignature: string;
}
+
+export interface ERC721Token {
+ address: string;
+ id: BigNumber;
+}
+
+// Combinatorial testing types
+
+export enum FeeRecipientAddressScenario {
+ BurnAddress = 'BURN_ADDRESS',
+ EthUserAddress = 'ETH_USER_ADDRESS',
+}
+
+export enum OrderAmountScenario {
+ Zero = 'ZERO',
+ NonZero = 'NON_ZERO',
+}
+
+export enum ExpirationTimeSecondsScenario {
+ InPast = 'IN_PAST',
+ InFuture = 'IN_FUTURE',
+}
+
+export enum AssetDataScenario {
+ ERC721ValidAssetProxyId = 'ERC721_VALID_ASSET_PROXY_ID',
+ ERC721InvalidAssetProxyId = 'ERC721_INVALID_ASSET_PROXY_ID',
+ ZRXFeeToken = 'ZRX_FEE_TOKEN',
+ ERC20InvalidAssetProxyId = 'ERC20_INVALID_ASSET_PROXY_ID',
+ ERC20FiveDecimals = 'ERC20_FIVE_DECIMALS',
+ ERC20NonZRXEighteenDecimals = 'ERC20_NON_ZRX_EIGHTEEN_DECIMALS',
+}
diff --git a/packages/order-watcher/src/order_watcher/order_watcher.ts b/packages/order-watcher/src/order_watcher/order_watcher.ts
index c1f6c9230..f25076213 100644
--- a/packages/order-watcher/src/order_watcher/order_watcher.ts
+++ b/packages/order-watcher/src/order_watcher/order_watcher.ts
@@ -14,7 +14,7 @@ import {
Provider,
SignedOrder,
} from '@0xproject/types';
-import { intervalUtils } from '@0xproject/utils';
+import { errorUtils, intervalUtils } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as _ from 'lodash';
@@ -344,7 +344,7 @@ export class OrderWatcher {
return; // noop
default:
- throw utils.spawnSwitchErr('decodedLog.event', decodedLog.event);
+ throw errorUtils.spawnSwitchErr('decodedLog.event', decodedLog.event);
}
}
private async _emitRevalidateOrdersAsync(orderHashes: string[]): Promise<void> {
diff --git a/packages/order-watcher/src/utils/utils.ts b/packages/order-watcher/src/utils/utils.ts
index d34f6b99f..087fc635e 100644
--- a/packages/order-watcher/src/utils/utils.ts
+++ b/packages/order-watcher/src/utils/utils.ts
@@ -1,9 +1,6 @@
import { BigNumber } from '@0xproject/utils';
export const utils = {
- spawnSwitchErr(name: string, value: any): Error {
- return new Error(`Unexpected switch value: ${value} encountered for ${name}`);
- },
getCurrentUnixTimestampSec(): BigNumber {
const milisecondsInASecond = 1000;
return new BigNumber(Date.now() / milisecondsInASecond).round();
diff --git a/packages/react-docs/src/components/type.tsx b/packages/react-docs/src/components/type.tsx
index caf0796ee..e453349ef 100644
--- a/packages/react-docs/src/components/type.tsx
+++ b/packages/react-docs/src/components/type.tsx
@@ -1,4 +1,5 @@
import { colors, constants as sharedConstants, utils as sharedUtils } from '@0xproject/react-shared';
+import { errorUtils } from '@0xproject/utils';
import * as _ from 'lodash';
import * as React from 'react';
import { Link as ScrollLink } from 'react-scroll';
@@ -6,7 +7,6 @@ import * as ReactTooltip from 'react-tooltip';
import { DocsInfo } from '../docs_info';
import { Type as TypeDef, TypeDefinitionByName, TypeDocTypes } from '../types';
-import { utils } from '../utils/utils';
import { Signature } from './signature';
import { TypeDefinition } from './type_definition';
@@ -129,7 +129,7 @@ export function Type(props: TypeProps): any {
break;
default:
- throw utils.spawnSwitchErr('type.typeDocType', type.typeDocType);
+ throw errorUtils.spawnSwitchErr('type.typeDocType', type.typeDocType);
}
// HACK: Normalize BigNumber to simply BigNumber. For some reason the type
// name is unpredictably one or the other.
diff --git a/packages/react-docs/src/components/type_definition.tsx b/packages/react-docs/src/components/type_definition.tsx
index fdaad556b..c4bd7359a 100644
--- a/packages/react-docs/src/components/type_definition.tsx
+++ b/packages/react-docs/src/components/type_definition.tsx
@@ -1,11 +1,11 @@
import { AnchorTitle, colors, HeaderSizes } from '@0xproject/react-shared';
+import { errorUtils } from '@0xproject/utils';
import * as _ from 'lodash';
import * as React from 'react';
import { DocsInfo } from '../docs_info';
import { CustomType, CustomTypeChild, KindString, TypeDocTypes } from '../types';
import { constants } from '../utils/constants';
-import { utils } from '../utils/utils';
import { Comment } from './comment';
import { CustomEnum } from './custom_enum';
@@ -96,7 +96,7 @@ export class TypeDefinition extends React.Component<TypeDefinitionProps, TypeDef
break;
default:
- throw utils.spawnSwitchErr('type.kindString', customType.kindString);
+ throw errorUtils.spawnSwitchErr('type.kindString', customType.kindString);
}
const typeDefinitionAnchorId = `${this.props.sectionName}-${customType.name}`;
diff --git a/packages/react-docs/src/utils/typedoc_utils.ts b/packages/react-docs/src/utils/typedoc_utils.ts
index 5a672f10f..5633d9040 100644
--- a/packages/react-docs/src/utils/typedoc_utils.ts
+++ b/packages/react-docs/src/utils/typedoc_utils.ts
@@ -1,3 +1,4 @@
+import { errorUtils } from '@0xproject/utils';
import * as _ from 'lodash';
import { DocsInfo } from '../docs_info';
@@ -19,7 +20,6 @@ import {
TypescriptFunction,
TypescriptMethod,
} from '../types';
-import { utils } from '../utils/utils';
export const typeDocUtils = {
isType(entity: TypeDocNode): boolean {
@@ -197,7 +197,7 @@ export const typeDocUtils = {
break;
default:
- throw utils.spawnSwitchErr('kindString', entity.kindString);
+ throw errorUtils.spawnSwitchErr('kindString', entity.kindString);
}
});
return docSection;
diff --git a/packages/utils/CHANGELOG.json b/packages/utils/CHANGELOG.json
index 616a17d62..339d73e05 100644
--- a/packages/utils/CHANGELOG.json
+++ b/packages/utils/CHANGELOG.json
@@ -1,5 +1,13 @@
[
{
+ "version": "0.6.3",
+ "changes": [
+ {
+ "note": "Added errorUtils.spawnSwitchErr"
+ }
+ ]
+ },
+ {
"timestamp": 1527009133,
"version": "0.6.2",
"changes": [
diff --git a/packages/react-docs/src/utils/utils.ts b/packages/utils/src/error_utils.ts
index e3dd1fc62..735d3940b 100644
--- a/packages/react-docs/src/utils/utils.ts
+++ b/packages/utils/src/error_utils.ts
@@ -1,4 +1,4 @@
-export const utils = {
+export const errorUtils = {
spawnSwitchErr(name: string, value: any): Error {
return new Error(`Unexpected switch value: ${value} encountered for ${name}`);
},
diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts
index 709ec93b2..fd102cecb 100644
--- a/packages/utils/src/index.ts
+++ b/packages/utils/src/index.ts
@@ -7,3 +7,4 @@ export { AbiDecoder } from './abi_decoder';
export { logUtils } from './log_utils';
export { abiUtils } from './abi_utils';
export { NULL_BYTES } from './constants';
+export { errorUtils } from './error_utils';
diff --git a/packages/website/ts/components/token_balances.tsx b/packages/website/ts/components/token_balances.tsx
index 6f5aa756e..555a59830 100644
--- a/packages/website/ts/components/token_balances.tsx
+++ b/packages/website/ts/components/token_balances.tsx
@@ -5,7 +5,7 @@ import {
Styles,
utils as sharedUtils,
} from '@0xproject/react-shared';
-import { BigNumber, logUtils } from '@0xproject/utils';
+import { BigNumber, errorUtils, logUtils } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as _ from 'lodash';
import Dialog from 'material-ui/Dialog';
@@ -500,7 +500,7 @@ export class TokenBalances extends React.Component<TokenBalancesProps, TokenBala
return null; // No error to show
default:
- throw utils.spawnSwitchErr('errorType', this.state.errorType);
+ throw errorUtils.spawnSwitchErr('errorType', this.state.errorType);
}
}
private _onErrorOccurred(errorType: BalanceErrs): void {
diff --git a/packages/website/ts/components/ui/lifecycle_raised_button.tsx b/packages/website/ts/components/ui/lifecycle_raised_button.tsx
index 0c3ebcc0c..a24de56b7 100644
--- a/packages/website/ts/components/ui/lifecycle_raised_button.tsx
+++ b/packages/website/ts/components/ui/lifecycle_raised_button.tsx
@@ -1,4 +1,5 @@
import { colors } from '@0xproject/react-shared';
+import { errorUtils } from '@0xproject/utils';
import RaisedButton from 'material-ui/RaisedButton';
import * as React from 'react';
import { utils } from 'ts/utils/utils';
@@ -62,7 +63,7 @@ export class LifeCycleRaisedButton extends React.Component<LifeCycleRaisedButton
label = this.props.labelComplete;
break;
default:
- throw utils.spawnSwitchErr('ButtonState', this.state.buttonState);
+ throw errorUtils.spawnSwitchErr('ButtonState', this.state.buttonState);
}
return (
<RaisedButton
diff --git a/packages/website/ts/components/wallet/wallet.tsx b/packages/website/ts/components/wallet/wallet.tsx
index 977902103..bc2ee227d 100644
--- a/packages/website/ts/components/wallet/wallet.tsx
+++ b/packages/website/ts/components/wallet/wallet.tsx
@@ -1,5 +1,5 @@
import { EtherscanLinkSuffixes, Styles, utils as sharedUtils } from '@0xproject/react-shared';
-import { BigNumber } from '@0xproject/utils';
+import { BigNumber, errorUtils } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as _ from 'lodash';
import CircularProgress from 'material-ui/CircularProgress';
@@ -491,7 +491,7 @@ export class Wallet extends React.Component<WalletProps, WalletState> {
buttonIconName = 'zmdi-long-arrow-up';
break;
default:
- throw utils.spawnSwitchErr('wrappedEtherDirection', wrappedEtherDirection);
+ throw errorUtils.spawnSwitchErr('wrappedEtherDirection', wrappedEtherDirection);
}
}
const onClick = isWrappedEtherDirectionOpen
diff --git a/packages/website/ts/utils/utils.ts b/packages/website/ts/utils/utils.ts
index 2c8c06c01..6961784c6 100644
--- a/packages/website/ts/utils/utils.ts
+++ b/packages/website/ts/utils/utils.ts
@@ -33,9 +33,6 @@ export const utils = {
throw new Error(message);
}
},
- spawnSwitchErr(name: string, value: any): Error {
- return new Error(`Unexpected switch value: ${value} encountered for ${name}`);
- },
isNumeric(n: string): boolean {
return !isNaN(parseFloat(n)) && isFinite(Number(n));
},