Remove truffle from tests
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { schemas, SchemaValidator } from '@0xproject/json-schemas';
|
||||
import { BigNumber, intervalUtils } from '@0xproject/utils';
|
||||
import { TransactionReceiptWithDecodedLogs } from '@0xproject/types';
|
||||
import { AbiDecoder, BigNumber, intervalUtils } from '@0xproject/utils';
|
||||
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
||||
import * as ethUtil from 'ethereumjs-util';
|
||||
import * as _ from 'lodash';
|
||||
@@ -12,16 +13,7 @@ import { TokenTransferProxyWrapper } from './contract_wrappers/token_transfer_pr
|
||||
import { TokenWrapper } from './contract_wrappers/token_wrapper';
|
||||
import { OrderStateWatcher } from './order_watcher/order_state_watcher';
|
||||
import { zeroExConfigSchema } from './schemas/zero_ex_config_schema';
|
||||
import {
|
||||
ECSignature,
|
||||
Order,
|
||||
SignedOrder,
|
||||
TransactionReceiptWithDecodedLogs,
|
||||
Web3Provider,
|
||||
ZeroExConfig,
|
||||
ZeroExError,
|
||||
} from './types';
|
||||
import { AbiDecoder } from './utils/abi_decoder';
|
||||
import { ECSignature, Order, SignedOrder, Web3Provider, ZeroExConfig, ZeroExError } from './types';
|
||||
import { assert } from './utils/assert';
|
||||
import { constants } from './utils/constants';
|
||||
import { decorators } from './utils/decorators';
|
||||
@@ -293,18 +285,18 @@ export class ZeroEx {
|
||||
* @param timeoutMs How long (in ms) to poll for transaction mined until aborting.
|
||||
* @return Transaction receipt with decoded log args.
|
||||
*/
|
||||
public async awaitTransactionMinedAsync(
|
||||
public async awaitTransactionMinedAsync<ArgsType>(
|
||||
txHash: string,
|
||||
pollingIntervalMs = 1000,
|
||||
timeoutMs?: number,
|
||||
): Promise<TransactionReceiptWithDecodedLogs> {
|
||||
): Promise<TransactionReceiptWithDecodedLogs<ArgsType>> {
|
||||
let timeoutExceeded = false;
|
||||
if (timeoutMs) {
|
||||
setTimeout(() => (timeoutExceeded = true), timeoutMs);
|
||||
}
|
||||
|
||||
const txReceiptPromise = new Promise(
|
||||
(resolve: (receipt: TransactionReceiptWithDecodedLogs) => void, reject) => {
|
||||
(resolve: (receipt: TransactionReceiptWithDecodedLogs<ArgsType>) => void, reject) => {
|
||||
const intervalId = intervalUtils.setAsyncExcludingInterval(
|
||||
async () => {
|
||||
if (timeoutExceeded) {
|
||||
@@ -319,7 +311,7 @@ export class ZeroEx {
|
||||
transactionReceipt.logs,
|
||||
this._abiDecoder.tryToDecodeLogOrNoop.bind(this._abiDecoder),
|
||||
);
|
||||
const transactionReceiptWithDecodedLogArgs: TransactionReceiptWithDecodedLogs = {
|
||||
const transactionReceiptWithDecodedLogArgs: TransactionReceiptWithDecodedLogs<ArgsType> = {
|
||||
...transactionReceipt,
|
||||
logs: logsWithDecodedArgs,
|
||||
};
|
||||
@@ -334,8 +326,8 @@ export class ZeroEx {
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
return txReceiptPromise;
|
||||
const txReceipt = await txReceiptPromise;
|
||||
return txReceipt;
|
||||
}
|
||||
/*
|
||||
* HACK: `TokenWrapper` needs a token transfer proxy address. `TokenTransferProxy` address is fetched from
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import { intervalUtils } from '@0xproject/utils';
|
||||
import { LogWithDecodedArgs, RawLog } from '@0xproject/types';
|
||||
import { AbiDecoder, intervalUtils } from '@0xproject/utils';
|
||||
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
||||
import { Block, BlockAndLogStreamer } from 'ethereumjs-blockstream';
|
||||
import * as _ from 'lodash';
|
||||
@@ -13,11 +14,8 @@ import {
|
||||
EventCallback,
|
||||
IndexedFilterValues,
|
||||
InternalZeroExError,
|
||||
LogWithDecodedArgs,
|
||||
RawLog,
|
||||
ZeroExError,
|
||||
} from '../types';
|
||||
import { AbiDecoder } from '../utils/abi_decoder';
|
||||
import { constants } from '../utils/constants';
|
||||
import { filterUtils } from '../utils/filter_utils';
|
||||
|
||||
|
@@ -1,5 +1,6 @@
|
||||
import { schemas } from '@0xproject/json-schemas';
|
||||
import { BigNumber } from '@0xproject/utils';
|
||||
import { LogWithDecodedArgs } from '@0xproject/types';
|
||||
import { AbiDecoder, BigNumber } from '@0xproject/utils';
|
||||
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
@@ -10,11 +11,9 @@ import {
|
||||
EtherTokenEvents,
|
||||
EventCallback,
|
||||
IndexedFilterValues,
|
||||
LogWithDecodedArgs,
|
||||
TransactionOpts,
|
||||
ZeroExError,
|
||||
} from '../types';
|
||||
import { AbiDecoder } from '../utils/abi_decoder';
|
||||
import { assert } from '../utils/assert';
|
||||
|
||||
import { ContractWrapper } from './contract_wrapper';
|
||||
|
@@ -1,5 +1,6 @@
|
||||
import { schemas } from '@0xproject/json-schemas';
|
||||
import { BigNumber } from '@0xproject/utils';
|
||||
import { DecodedLogArgs, LogWithDecodedArgs } from '@0xproject/types';
|
||||
import { AbiDecoder, BigNumber } from '@0xproject/utils';
|
||||
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
||||
import * as _ from 'lodash';
|
||||
import * as Web3 from 'web3';
|
||||
@@ -8,7 +9,6 @@ import { artifacts } from '../artifacts';
|
||||
import {
|
||||
BlockParamLiteral,
|
||||
BlockRange,
|
||||
DecodedLogArgs,
|
||||
ECSignature,
|
||||
EventCallback,
|
||||
ExchangeContractErrCodes,
|
||||
@@ -17,7 +17,6 @@ import {
|
||||
ExchangeEvents,
|
||||
IndexedFilterValues,
|
||||
LogErrorContractEventArgs,
|
||||
LogWithDecodedArgs,
|
||||
MethodOpts,
|
||||
Order,
|
||||
OrderAddresses,
|
||||
@@ -28,7 +27,6 @@ import {
|
||||
SignedOrder,
|
||||
ValidateOrderFillableOpts,
|
||||
} from '../types';
|
||||
import { AbiDecoder } from '../utils/abi_decoder';
|
||||
import { assert } from '../utils/assert';
|
||||
import { decorators } from '../utils/decorators';
|
||||
import { ExchangeTransferSimulator } from '../utils/exchange_transfer_simulator';
|
||||
|
@@ -1,5 +1,6 @@
|
||||
import { schemas } from '@0xproject/json-schemas';
|
||||
import { BigNumber } from '@0xproject/utils';
|
||||
import { AbiDecoder, BigNumber } from '@0xproject/utils';
|
||||
import { LogWithDecodedArgs } from '@0xproject/types';
|
||||
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
@@ -8,14 +9,12 @@ import {
|
||||
BlockRange,
|
||||
EventCallback,
|
||||
IndexedFilterValues,
|
||||
LogWithDecodedArgs,
|
||||
MethodOpts,
|
||||
TokenContractEventArgs,
|
||||
TokenEvents,
|
||||
TransactionOpts,
|
||||
ZeroExError,
|
||||
} from '../types';
|
||||
import { AbiDecoder } from '../utils/abi_decoder';
|
||||
import { assert } from '../utils/assert';
|
||||
import { constants } from '../utils/constants';
|
||||
|
||||
|
16
packages/0x.js/src/globals.d.ts
vendored
16
packages/0x.js/src/globals.d.ts
vendored
@@ -41,19 +41,3 @@ declare module 'truffle-hdwallet-provider' {
|
||||
}
|
||||
export = HDWalletProvider;
|
||||
}
|
||||
|
||||
// abi-decoder declarations
|
||||
interface DecodedLogArg {}
|
||||
interface DecodedLog {
|
||||
name: string;
|
||||
events: DecodedLogArg[];
|
||||
}
|
||||
declare module 'abi-decoder' {
|
||||
import * as Web3 from 'web3';
|
||||
const addABI: (abi: Web3.AbiDefinition) => void;
|
||||
const decodeLogs: (logs: Web3.LogEntry[]) => DecodedLog[];
|
||||
}
|
||||
|
||||
declare module 'web3/lib/solidity/coder' {
|
||||
const decodeParams: (types: string[], data: string) => any[];
|
||||
}
|
||||
|
@@ -28,12 +28,9 @@ export {
|
||||
WithdrawalContractEventArgs,
|
||||
DepositContractEventArgs,
|
||||
ContractEventArgs,
|
||||
ContractEventArg,
|
||||
Web3Provider,
|
||||
ZeroExConfig,
|
||||
EtherTokenEvents,
|
||||
TransactionReceiptWithDecodedLogs,
|
||||
LogWithDecodedArgs,
|
||||
MethodOpts,
|
||||
OrderTransactionOpts,
|
||||
TransactionOpts,
|
||||
@@ -47,4 +44,6 @@ export {
|
||||
OrderState,
|
||||
} from './types';
|
||||
|
||||
export { ContractEventArg, LogWithDecodedArgs, TransactionReceiptWithDecodedLogs } from '@0xproject/types';
|
||||
|
||||
export { TransactionReceipt } from '@0xproject/types';
|
||||
|
@@ -1,5 +1,6 @@
|
||||
import { schemas } from '@0xproject/json-schemas';
|
||||
import { intervalUtils } from '@0xproject/utils';
|
||||
import { LogWithDecodedArgs } from '@0xproject/types';
|
||||
import { AbiDecoder, intervalUtils } from '@0xproject/utils';
|
||||
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
@@ -19,7 +20,6 @@ import {
|
||||
LogCancelContractEventArgs,
|
||||
LogEvent,
|
||||
LogFillContractEventArgs,
|
||||
LogWithDecodedArgs,
|
||||
OnOrderStateChangeCallback,
|
||||
OrderState,
|
||||
OrderStateWatcherConfig,
|
||||
@@ -29,7 +29,6 @@ import {
|
||||
WithdrawalContractEventArgs,
|
||||
ZeroExError,
|
||||
} from '../types';
|
||||
import { AbiDecoder } from '../utils/abi_decoder';
|
||||
import { assert } from '../utils/assert';
|
||||
import { OrderStateUtils } from '../utils/order_state_utils';
|
||||
import { utils } from '../utils/utils';
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { TransactionReceipt } from '@0xproject/types';
|
||||
import { ContractEventArg, DecodedLogArgs, LogWithDecodedArgs, TransactionReceipt } from '@0xproject/types';
|
||||
import { BigNumber } from '@0xproject/utils';
|
||||
import * as Web3 from 'web3';
|
||||
|
||||
@@ -53,13 +53,6 @@ export interface DecodedLogEvent<ArgsType> {
|
||||
export type EventCallback<ArgsType> = (err: null | Error, log?: DecodedLogEvent<ArgsType>) => void;
|
||||
export type EventWatcherCallback = (err: null | Error, log?: LogEvent) => void;
|
||||
|
||||
export enum SolidityTypes {
|
||||
Address = 'address',
|
||||
Uint256 = 'uint256',
|
||||
Uint8 = 'uint8',
|
||||
Uint = 'uint',
|
||||
}
|
||||
|
||||
export enum ExchangeContractErrCodes {
|
||||
ERROR_FILL_EXPIRED, // Order has already expired
|
||||
ERROR_FILL_NO_VALUE, // Order has already been fully filled or cancelled
|
||||
@@ -94,8 +87,6 @@ export enum ExchangeContractErrs {
|
||||
BatchOrdersMustHaveAtLeastOneItem = 'BATCH_ORDERS_MUST_HAVE_AT_LEAST_ONE_ITEM',
|
||||
}
|
||||
|
||||
export type RawLog = Web3.LogEntry;
|
||||
|
||||
export interface ContractEvent {
|
||||
logIndex: number;
|
||||
transactionIndex: number;
|
||||
@@ -163,7 +154,6 @@ export type EtherTokenContractEventArgs =
|
||||
| DepositContractEventArgs
|
||||
| WithdrawalContractEventArgs;
|
||||
export type ContractEventArgs = ExchangeContractEventArgs | TokenContractEventArgs | EtherTokenContractEventArgs;
|
||||
export type ContractEventArg = string | BigNumber;
|
||||
|
||||
export interface Order {
|
||||
maker: string;
|
||||
@@ -300,23 +290,6 @@ export interface ZeroExConfig {
|
||||
orderWatcherConfig?: OrderStateWatcherConfig;
|
||||
}
|
||||
|
||||
export enum AbiType {
|
||||
Function = 'function',
|
||||
Constructor = 'constructor',
|
||||
Event = 'event',
|
||||
Fallback = 'fallback',
|
||||
}
|
||||
|
||||
export interface DecodedLogArgs {
|
||||
[argName: string]: ContractEventArg;
|
||||
}
|
||||
|
||||
export interface LogWithDecodedArgs<ArgsType> extends Web3.DecodedLogEntry<ArgsType> {}
|
||||
|
||||
export interface TransactionReceiptWithDecodedLogs extends TransactionReceipt {
|
||||
logs: Array<LogWithDecodedArgs<DecodedLogArgs> | Web3.LogEntry>;
|
||||
}
|
||||
|
||||
export type ArtifactContractName = 'ZRX' | 'TokenTransferProxy' | 'TokenRegistry' | 'Token' | 'Exchange' | 'EtherToken';
|
||||
|
||||
export interface Artifact {
|
||||
|
@@ -1,72 +0,0 @@
|
||||
import { BigNumber } from '@0xproject/utils';
|
||||
import * as _ from 'lodash';
|
||||
import * as Web3 from 'web3';
|
||||
import * as SolidityCoder from 'web3/lib/solidity/coder';
|
||||
|
||||
import { AbiType, ContractEventArgs, DecodedLogArgs, LogWithDecodedArgs, RawLog, SolidityTypes } from '../types';
|
||||
|
||||
export class AbiDecoder {
|
||||
private _savedABIs: Web3.AbiDefinition[] = [];
|
||||
private _methodIds: { [signatureHash: string]: Web3.EventAbi } = {};
|
||||
private static _padZeros(address: string) {
|
||||
let formatted = address;
|
||||
if (_.startsWith(formatted, '0x')) {
|
||||
formatted = formatted.slice(2);
|
||||
}
|
||||
|
||||
formatted = _.padStart(formatted, 40, '0');
|
||||
return `0x${formatted}`;
|
||||
}
|
||||
constructor(abiArrays: Web3.AbiDefinition[][]) {
|
||||
_.map(abiArrays, this._addABI.bind(this));
|
||||
}
|
||||
// This method can only decode logs from the 0x & ERC20 smart contracts
|
||||
public tryToDecodeLogOrNoop<ArgsType extends ContractEventArgs>(
|
||||
log: Web3.LogEntry,
|
||||
): LogWithDecodedArgs<ArgsType> | RawLog {
|
||||
const methodId = log.topics[0];
|
||||
const event = this._methodIds[methodId];
|
||||
if (_.isUndefined(event)) {
|
||||
return log;
|
||||
}
|
||||
const logData = log.data;
|
||||
const decodedParams: DecodedLogArgs = {};
|
||||
let dataIndex = 0;
|
||||
let topicsIndex = 1;
|
||||
|
||||
const nonIndexedInputs = _.filter(event.inputs, input => !input.indexed);
|
||||
const dataTypes = _.map(nonIndexedInputs, input => input.type);
|
||||
const decodedData = SolidityCoder.decodeParams(dataTypes, logData.slice('0x'.length));
|
||||
|
||||
_.map(event.inputs, (param: Web3.EventParameter) => {
|
||||
// Indexed parameters are stored in topics. Non-indexed ones in decodedData
|
||||
let value = param.indexed ? log.topics[topicsIndex++] : decodedData[dataIndex++];
|
||||
if (param.type === SolidityTypes.Address) {
|
||||
value = AbiDecoder._padZeros(new BigNumber(value).toString(16));
|
||||
} else if (
|
||||
param.type === SolidityTypes.Uint256 ||
|
||||
param.type === SolidityTypes.Uint8 ||
|
||||
param.type === SolidityTypes.Uint
|
||||
) {
|
||||
value = new BigNumber(value);
|
||||
}
|
||||
decodedParams[param.name] = value;
|
||||
});
|
||||
|
||||
return {
|
||||
...log,
|
||||
event: event.name,
|
||||
args: decodedParams,
|
||||
};
|
||||
}
|
||||
private _addABI(abiArray: Web3.AbiDefinition[]): void {
|
||||
_.map(abiArray, (abi: Web3.AbiDefinition) => {
|
||||
if (abi.type === AbiType.Event) {
|
||||
const signature = `${abi.name}(${_.map(abi.inputs, input => input.type).join(',')})`;
|
||||
const signatureHash = new Web3().sha3(signature);
|
||||
this._methodIds[signatureHash] = abi;
|
||||
}
|
||||
});
|
||||
this._savedABIs = this._savedABIs.concat(abiArray);
|
||||
}
|
||||
}
|
@@ -1,10 +1,11 @@
|
||||
import { SolidityTypes } from '@0xproject/types';
|
||||
import { BigNumber } from '@0xproject/utils';
|
||||
import BN = require('bn.js');
|
||||
import * as ethABI from 'ethereumjs-abi';
|
||||
import * as ethUtil from 'ethereumjs-util';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import { Order, SignedOrder, SolidityTypes } from '../types';
|
||||
import { Order, SignedOrder } from '../types';
|
||||
|
||||
export const utils = {
|
||||
/**
|
||||
|
Reference in New Issue
Block a user