From 709026bf1a49d468850b4ebed845c8598fa4fd75 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 19 Jan 2018 15:34:28 +0100 Subject: Refactor contracts tests to not use injected web3 instance --- packages/0x.js/src/types.ts | 5 --- packages/0x.js/test/0x.js_test.ts | 5 ++- packages/0x.js/test/assert_test.ts | 2 +- packages/0x.js/test/ether_token_wrapper_test.ts | 5 ++- packages/0x.js/test/event_watcher_test.ts | 2 +- .../0x.js/test/exchange_transfer_simulator_test.ts | 5 ++- packages/0x.js/test/exchange_wrapper_test.ts | 5 ++- packages/0x.js/test/expiration_watcher_test.ts | 6 ++-- packages/0x.js/test/order_state_watcher_test.ts | 5 ++- packages/0x.js/test/order_validation_test.ts | 5 ++- packages/0x.js/test/subscription_test.ts | 5 ++- packages/0x.js/test/token_registry_wrapper_test.ts | 5 ++- .../test/token_transfer_proxy_wrapper_test.ts | 2 +- packages/0x.js/test/token_wrapper_test.ts | 5 ++- packages/0x.js/test/utils/constants.ts | 2 -- .../utils/subproviders/empty_wallet_subprovider.ts | 27 -------------- .../subproviders/fake_gas_estimate_subprovider.ts | 34 ------------------ packages/0x.js/test/utils/web3_factory.ts | 42 ---------------------- 18 files changed, 23 insertions(+), 144 deletions(-) delete mode 100644 packages/0x.js/test/utils/subproviders/empty_wallet_subprovider.ts delete mode 100644 packages/0x.js/test/utils/subproviders/fake_gas_estimate_subprovider.ts delete mode 100644 packages/0x.js/test/utils/web3_factory.ts (limited to 'packages/0x.js') diff --git a/packages/0x.js/src/types.ts b/packages/0x.js/src/types.ts index 3c93910e9..55f7bb7d3 100644 --- a/packages/0x.js/src/types.ts +++ b/packages/0x.js/src/types.ts @@ -267,11 +267,6 @@ export type SyncMethod = (...args: any[]) => any; */ export type Web3Provider = Web3.Provider; -export interface JSONRPCPayload { - params: any[]; - method: string; -} - /* * orderExpirationCheckingIntervalMs: How often to check for expired orders. Default: 50 * eventPollingIntervalMs: How often to poll the Ethereum node for new events. Defaults: 200 diff --git a/packages/0x.js/test/0x.js_test.ts b/packages/0x.js/test/0x.js_test.ts index 927fe20be..6f8c4139a 100644 --- a/packages/0x.js/test/0x.js_test.ts +++ b/packages/0x.js/test/0x.js_test.ts @@ -1,4 +1,4 @@ -import { BlockchainLifecycle } from '@0xproject/dev-utils'; +import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils'; import { BigNumber } from '@0xproject/utils'; import * as chai from 'chai'; import * as _ from 'lodash'; @@ -10,9 +10,8 @@ import { ApprovalContractEventArgs, LogWithDecodedArgs, Order, TokenEvents, Zero import { chaiSetup } from './utils/chai_setup'; import { constants } from './utils/constants'; import { TokenUtils } from './utils/token_utils'; -import { web3Factory } from './utils/web3_factory'; -const blockchainLifecycle = new BlockchainLifecycle(constants.RPC_URL); +const blockchainLifecycle = new BlockchainLifecycle(devConstants.RPC_URL); chaiSetup.configure(); const expect = chai.expect; diff --git a/packages/0x.js/test/assert_test.ts b/packages/0x.js/test/assert_test.ts index 1f2820070..c4451742f 100644 --- a/packages/0x.js/test/assert_test.ts +++ b/packages/0x.js/test/assert_test.ts @@ -1,3 +1,4 @@ +import { web3Factory } from '@0xproject/dev-utils'; import * as chai from 'chai'; import 'mocha'; @@ -5,7 +6,6 @@ import { ZeroEx } from '../src'; import { assert } from '../src/utils/assert'; import { constants } from './utils/constants'; -import { web3Factory } from './utils/web3_factory'; const expect = chai.expect; diff --git a/packages/0x.js/test/ether_token_wrapper_test.ts b/packages/0x.js/test/ether_token_wrapper_test.ts index b810fc9f1..e0f18f26f 100644 --- a/packages/0x.js/test/ether_token_wrapper_test.ts +++ b/packages/0x.js/test/ether_token_wrapper_test.ts @@ -1,4 +1,4 @@ -import { BlockchainLifecycle } from '@0xproject/dev-utils'; +import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils'; import { BigNumber } from '@0xproject/utils'; import * as chai from 'chai'; import 'mocha'; @@ -24,11 +24,10 @@ import { chaiSetup } from './utils/chai_setup'; import { constants } from './utils/constants'; import { reportNodeCallbackErrors } from './utils/report_callback_errors'; import { TokenUtils } from './utils/token_utils'; -import { web3Factory } from './utils/web3_factory'; chaiSetup.configure(); const expect = chai.expect; -const blockchainLifecycle = new BlockchainLifecycle(constants.RPC_URL); +const blockchainLifecycle = new BlockchainLifecycle(devConstants.RPC_URL); // Since the address depositing/withdrawing ETH/WETH also needs to pay gas costs for the transaction, // a small amount of ETH will be used to pay this gas cost. We therefore check that the difference between diff --git a/packages/0x.js/test/event_watcher_test.ts b/packages/0x.js/test/event_watcher_test.ts index f92fb2b02..93ee9cd1c 100644 --- a/packages/0x.js/test/event_watcher_test.ts +++ b/packages/0x.js/test/event_watcher_test.ts @@ -1,3 +1,4 @@ +import { web3Factory } from '@0xproject/dev-utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as chai from 'chai'; import * as _ from 'lodash'; @@ -11,7 +12,6 @@ import { DoneCallback } from '../src/types'; import { chaiSetup } from './utils/chai_setup'; import { reportNodeCallbackErrors } from './utils/report_callback_errors'; -import { web3Factory } from './utils/web3_factory'; chaiSetup.configure(); const expect = chai.expect; diff --git a/packages/0x.js/test/exchange_transfer_simulator_test.ts b/packages/0x.js/test/exchange_transfer_simulator_test.ts index 20b4a05ca..4bbdecb60 100644 --- a/packages/0x.js/test/exchange_transfer_simulator_test.ts +++ b/packages/0x.js/test/exchange_transfer_simulator_test.ts @@ -1,4 +1,4 @@ -import { BlockchainLifecycle } from '@0xproject/dev-utils'; +import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils'; import { BigNumber } from '@0xproject/utils'; import * as chai from 'chai'; @@ -8,11 +8,10 @@ import { ExchangeTransferSimulator } from '../src/utils/exchange_transfer_simula import { chaiSetup } from './utils/chai_setup'; import { constants } from './utils/constants'; -import { web3Factory } from './utils/web3_factory'; chaiSetup.configure(); const expect = chai.expect; -const blockchainLifecycle = new BlockchainLifecycle(constants.RPC_URL); +const blockchainLifecycle = new BlockchainLifecycle(devConstants.RPC_URL); describe('ExchangeTransferSimulator', () => { const web3 = web3Factory.create(); diff --git a/packages/0x.js/test/exchange_wrapper_test.ts b/packages/0x.js/test/exchange_wrapper_test.ts index 7e0ffd818..016ef08ce 100644 --- a/packages/0x.js/test/exchange_wrapper_test.ts +++ b/packages/0x.js/test/exchange_wrapper_test.ts @@ -1,4 +1,4 @@ -import { BlockchainLifecycle } from '@0xproject/dev-utils'; +import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils'; import { BigNumber } from '@0xproject/utils'; import * as chai from 'chai'; import * as _ from 'lodash'; @@ -25,11 +25,10 @@ import { constants } from './utils/constants'; import { FillScenarios } from './utils/fill_scenarios'; import { reportNodeCallbackErrors } from './utils/report_callback_errors'; import { TokenUtils } from './utils/token_utils'; -import { web3Factory } from './utils/web3_factory'; chaiSetup.configure(); const expect = chai.expect; -const blockchainLifecycle = new BlockchainLifecycle(constants.RPC_URL); +const blockchainLifecycle = new BlockchainLifecycle(devConstants.RPC_URL); const NON_EXISTENT_ORDER_HASH = '0x79370342234e7acd6bbeac335bd3bb1d368383294b64b8160a00f4060e4d3777'; diff --git a/packages/0x.js/test/expiration_watcher_test.ts b/packages/0x.js/test/expiration_watcher_test.ts index 770615f88..90fb20a52 100644 --- a/packages/0x.js/test/expiration_watcher_test.ts +++ b/packages/0x.js/test/expiration_watcher_test.ts @@ -1,4 +1,4 @@ -import { BlockchainLifecycle } from '@0xproject/dev-utils'; +import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils'; import { BigNumber } from '@0xproject/utils'; import * as chai from 'chai'; import * as _ from 'lodash'; @@ -13,15 +13,13 @@ import { constants } from '../src/utils/constants'; import { utils } from '../src/utils/utils'; import { chaiSetup } from './utils/chai_setup'; -import { constants as testConstants } from './utils/constants'; import { FillScenarios } from './utils/fill_scenarios'; import { reportNoErrorCallbackErrors } from './utils/report_callback_errors'; import { TokenUtils } from './utils/token_utils'; -import { web3Factory } from './utils/web3_factory'; chaiSetup.configure(); const expect = chai.expect; -const blockchainLifecycle = new BlockchainLifecycle(testConstants.RPC_URL); +const blockchainLifecycle = new BlockchainLifecycle(devConstants.RPC_URL); describe('ExpirationWatcher', () => { let web3: Web3; diff --git a/packages/0x.js/test/order_state_watcher_test.ts b/packages/0x.js/test/order_state_watcher_test.ts index 2e9202fe2..79b43f433 100644 --- a/packages/0x.js/test/order_state_watcher_test.ts +++ b/packages/0x.js/test/order_state_watcher_test.ts @@ -1,4 +1,4 @@ -import { BlockchainLifecycle } from '@0xproject/dev-utils'; +import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils'; import { BigNumber } from '@0xproject/utils'; import * as chai from 'chai'; import * as _ from 'lodash'; @@ -22,13 +22,12 @@ import { constants } from './utils/constants'; import { FillScenarios } from './utils/fill_scenarios'; import { reportNodeCallbackErrors } from './utils/report_callback_errors'; import { TokenUtils } from './utils/token_utils'; -import { web3Factory } from './utils/web3_factory'; const TIMEOUT_MS = 150; chaiSetup.configure(); const expect = chai.expect; -const blockchainLifecycle = new BlockchainLifecycle(constants.RPC_URL); +const blockchainLifecycle = new BlockchainLifecycle(devConstants.RPC_URL); describe('OrderStateWatcher', () => { let web3: Web3; diff --git a/packages/0x.js/test/order_validation_test.ts b/packages/0x.js/test/order_validation_test.ts index be3e0590c..23fe957fe 100644 --- a/packages/0x.js/test/order_validation_test.ts +++ b/packages/0x.js/test/order_validation_test.ts @@ -1,4 +1,4 @@ -import { BlockchainLifecycle } from '@0xproject/dev-utils'; +import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils'; import { BigNumber } from '@0xproject/utils'; import * as chai from 'chai'; import * as Sinon from 'sinon'; @@ -13,11 +13,10 @@ import { chaiSetup } from './utils/chai_setup'; import { constants } from './utils/constants'; import { FillScenarios } from './utils/fill_scenarios'; import { TokenUtils } from './utils/token_utils'; -import { web3Factory } from './utils/web3_factory'; chaiSetup.configure(); const expect = chai.expect; -const blockchainLifecycle = new BlockchainLifecycle(constants.RPC_URL); +const blockchainLifecycle = new BlockchainLifecycle(devConstants.RPC_URL); describe('OrderValidation', () => { let web3: Web3; diff --git a/packages/0x.js/test/subscription_test.ts b/packages/0x.js/test/subscription_test.ts index f4c6f748f..60a4f7ec9 100644 --- a/packages/0x.js/test/subscription_test.ts +++ b/packages/0x.js/test/subscription_test.ts @@ -1,4 +1,4 @@ -import { BlockchainLifecycle } from '@0xproject/dev-utils'; +import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils'; import { BigNumber } from '@0xproject/utils'; import * as _ from 'lodash'; import 'mocha'; @@ -11,10 +11,9 @@ import { DoneCallback } from '../src/types'; import { chaiSetup } from './utils/chai_setup'; import { constants } from './utils/constants'; import { assertNodeCallbackError } from './utils/report_callback_errors'; -import { web3Factory } from './utils/web3_factory'; chaiSetup.configure(); -const blockchainLifecycle = new BlockchainLifecycle(constants.RPC_URL); +const blockchainLifecycle = new BlockchainLifecycle(devConstants.RPC_URL); describe('SubscriptionTest', () => { let web3: Web3; diff --git a/packages/0x.js/test/token_registry_wrapper_test.ts b/packages/0x.js/test/token_registry_wrapper_test.ts index 0a170db8f..396de5193 100644 --- a/packages/0x.js/test/token_registry_wrapper_test.ts +++ b/packages/0x.js/test/token_registry_wrapper_test.ts @@ -1,4 +1,4 @@ -import { BlockchainLifecycle } from '@0xproject/dev-utils'; +import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils'; import { schemas, SchemaValidator } from '@0xproject/json-schemas'; import * as chai from 'chai'; import * as _ from 'lodash'; @@ -8,11 +8,10 @@ import { Token, ZeroEx } from '../src'; import { chaiSetup } from './utils/chai_setup'; import { constants } from './utils/constants'; -import { web3Factory } from './utils/web3_factory'; chaiSetup.configure(); const expect = chai.expect; -const blockchainLifecycle = new BlockchainLifecycle(constants.RPC_URL); +const blockchainLifecycle = new BlockchainLifecycle(devConstants.RPC_URL); const TOKEN_REGISTRY_SIZE_AFTER_MIGRATION = 7; diff --git a/packages/0x.js/test/token_transfer_proxy_wrapper_test.ts b/packages/0x.js/test/token_transfer_proxy_wrapper_test.ts index 15bd7a8ba..dc9ec2064 100644 --- a/packages/0x.js/test/token_transfer_proxy_wrapper_test.ts +++ b/packages/0x.js/test/token_transfer_proxy_wrapper_test.ts @@ -1,10 +1,10 @@ +import { web3Factory } from '@0xproject/dev-utils'; import * as chai from 'chai'; import { ZeroEx } from '../src'; import { chaiSetup } from './utils/chai_setup'; import { constants } from './utils/constants'; -import { web3Factory } from './utils/web3_factory'; chaiSetup.configure(); const expect = chai.expect; diff --git a/packages/0x.js/test/token_wrapper_test.ts b/packages/0x.js/test/token_wrapper_test.ts index 4ba1f07c5..8b8f19297 100644 --- a/packages/0x.js/test/token_wrapper_test.ts +++ b/packages/0x.js/test/token_wrapper_test.ts @@ -1,4 +1,4 @@ -import { BlockchainLifecycle } from '@0xproject/dev-utils'; +import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils'; import { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as chai from 'chai'; @@ -22,11 +22,10 @@ import { chaiSetup } from './utils/chai_setup'; import { constants } from './utils/constants'; import { reportNodeCallbackErrors } from './utils/report_callback_errors'; import { TokenUtils } from './utils/token_utils'; -import { web3Factory } from './utils/web3_factory'; chaiSetup.configure(); const expect = chai.expect; -const blockchainLifecycle = new BlockchainLifecycle(constants.RPC_URL); +const blockchainLifecycle = new BlockchainLifecycle(devConstants.RPC_URL); describe('TokenWrapper', () => { let web3: Web3; diff --git a/packages/0x.js/test/utils/constants.ts b/packages/0x.js/test/utils/constants.ts index a9e665c25..cf030259c 100644 --- a/packages/0x.js/test/utils/constants.ts +++ b/packages/0x.js/test/utils/constants.ts @@ -1,11 +1,9 @@ export const constants = { NULL_ADDRESS: '0x0000000000000000000000000000000000000000', - RPC_URL: 'http://localhost:8545', ROPSTEN_NETWORK_ID: 3, KOVAN_NETWORK_ID: 42, TESTRPC_NETWORK_ID: 50, KOVAN_RPC_URL: 'https://kovan.infura.io/', ROPSTEN_RPC_URL: 'https://ropsten.infura.io/', ZRX_DECIMALS: 18, - GAS_ESTIMATE: 500000, }; diff --git a/packages/0x.js/test/utils/subproviders/empty_wallet_subprovider.ts b/packages/0x.js/test/utils/subproviders/empty_wallet_subprovider.ts deleted file mode 100644 index 53f2be83d..000000000 --- a/packages/0x.js/test/utils/subproviders/empty_wallet_subprovider.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { JSONRPCPayload } from '../../../src/types'; - -/* - * This class implements the web3-provider-engine subprovider interface and returns - * that the provider has no addresses when queried. - * Source: https://github.com/MetaMask/provider-engine/blob/master/subproviders/subprovider.js - */ -export class EmptyWalletSubprovider { - // This method needs to be here to satisfy the interface but linter wants it to be static. - // tslint:disable-next-line:prefer-function-over-method - public handleRequest(payload: JSONRPCPayload, next: () => void, end: (err: Error | null, result: any) => void) { - switch (payload.method) { - case 'eth_accounts': - end(null, []); - return; - - default: - next(); - return; - } - } - // Required to implement this method despite not needing it for this subprovider - // tslint:disable-next-line:prefer-function-over-method - public setEngine(engine: any) { - // noop - } -} diff --git a/packages/0x.js/test/utils/subproviders/fake_gas_estimate_subprovider.ts b/packages/0x.js/test/utils/subproviders/fake_gas_estimate_subprovider.ts deleted file mode 100644 index e1113a851..000000000 --- a/packages/0x.js/test/utils/subproviders/fake_gas_estimate_subprovider.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { JSONRPCPayload } from '../../../src/types'; - -/* - * This class implements the web3-provider-engine subprovider interface and returns - * the constant gas estimate when queried. - * HACK: We need this so that our tests don't use testrpc gas estimation which sometimes kills the node. - * Source: https://github.com/trufflesuite/ganache-cli/issues/417 - * Source: https://github.com/trufflesuite/ganache-cli/issues/437 - * Source: https://github.com/MetaMask/provider-engine/blob/master/subproviders/subprovider.js - */ -export class FakeGasEstimateSubprovider { - private _constantGasAmount: number; - constructor(constantGasAmount: number) { - this._constantGasAmount = constantGasAmount; - } - // This method needs to be here to satisfy the interface but linter wants it to be static. - // tslint:disable-next-line:prefer-function-over-method - public handleRequest(payload: JSONRPCPayload, next: () => void, end: (err: Error | null, result: any) => void) { - switch (payload.method) { - case 'eth_estimateGas': - end(null, this._constantGasAmount); - return; - - default: - next(); - return; - } - } - // Required to implement this method despite not needing it for this subprovider - // tslint:disable-next-line:prefer-function-over-method - public setEngine(engine: any) { - // noop - } -} diff --git a/packages/0x.js/test/utils/web3_factory.ts b/packages/0x.js/test/utils/web3_factory.ts deleted file mode 100644 index 26c26e03d..000000000 --- a/packages/0x.js/test/utils/web3_factory.ts +++ /dev/null @@ -1,42 +0,0 @@ -// HACK: web3 injects XMLHttpRequest into the global scope and ProviderEngine checks XMLHttpRequest -// to know whether it is running in a browser or node environment. We need it to be undefined since -// we are not running in a browser env. -// Filed issue: https://github.com/ethereum/web3.js/issues/844 -(global as any).XMLHttpRequest = undefined; -import ProviderEngine = require('web3-provider-engine'); -import RpcSubprovider = require('web3-provider-engine/subproviders/rpc'); - -import { EmptyWalletSubprovider } from './subproviders/empty_wallet_subprovider'; -import { FakeGasEstimateSubprovider } from './subproviders/fake_gas_estimate_subprovider'; - -import { constants } from './constants'; - -// HACK: web3 leaks XMLHttpRequest into the global scope and causes requests to hang -// because they are using the wrong XHR package. -// importing web3 after subproviders fixes this issue -// Filed issue: https://github.com/ethereum/web3.js/issues/844 -// tslint:disable-next-line:ordered-imports -import * as Web3 from 'web3'; - -export const web3Factory = { - create(hasAddresses: boolean = true): Web3 { - const provider = this.getRpcProvider(hasAddresses); - const web3 = new Web3(); - web3.setProvider(provider); - return web3; - }, - getRpcProvider(hasAddresses: boolean = true): Web3.Provider { - const provider = new ProviderEngine(); - if (!hasAddresses) { - provider.addProvider(new EmptyWalletSubprovider()); - } - provider.addProvider(new FakeGasEstimateSubprovider(constants.GAS_ESTIMATE)); - provider.addProvider( - new RpcSubprovider({ - rpcUrl: constants.RPC_URL, - }), - ); - provider.start(); - return provider; - }, -}; -- cgit From 387363283ca03ac1d6c9be5b7be2107790bbf79d Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 22 Jan 2018 21:53:32 +0100 Subject: Remove truffle from tests --- packages/0x.js/src/0x.ts | 26 +++----- .../src/contract_wrappers/contract_wrapper.ts | 6 +- .../src/contract_wrappers/ether_token_wrapper.ts | 5 +- .../src/contract_wrappers/exchange_wrapper.ts | 6 +- .../0x.js/src/contract_wrappers/token_wrapper.ts | 5 +- packages/0x.js/src/globals.d.ts | 16 ----- packages/0x.js/src/index.ts | 5 +- .../0x.js/src/order_watcher/order_state_watcher.ts | 5 +- packages/0x.js/src/types.ts | 29 +-------- packages/0x.js/src/utils/abi_decoder.ts | 72 ---------------------- packages/0x.js/src/utils/utils.ts | 3 +- 11 files changed, 24 insertions(+), 154 deletions(-) delete mode 100644 packages/0x.js/src/utils/abi_decoder.ts (limited to 'packages/0x.js') diff --git a/packages/0x.js/src/0x.ts b/packages/0x.js/src/0x.ts index f8a484c5d..8eb8cdd9a 100644 --- a/packages/0x.js/src/0x.ts +++ b/packages/0x.js/src/0x.ts @@ -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( txHash: string, pollingIntervalMs = 1000, timeoutMs?: number, - ): Promise { + ): Promise> { let timeoutExceeded = false; if (timeoutMs) { setTimeout(() => (timeoutExceeded = true), timeoutMs); } const txReceiptPromise = new Promise( - (resolve: (receipt: TransactionReceiptWithDecodedLogs) => void, reject) => { + (resolve: (receipt: TransactionReceiptWithDecodedLogs) => 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 = { ...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 diff --git a/packages/0x.js/src/contract_wrappers/contract_wrapper.ts b/packages/0x.js/src/contract_wrappers/contract_wrapper.ts index 27551c01d..5f11d810a 100644 --- a/packages/0x.js/src/contract_wrappers/contract_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/contract_wrapper.ts @@ -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'; diff --git a/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts b/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts index b03571636..8fa7aa78b 100644 --- a/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts @@ -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'; diff --git a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts index 2b6117729..5672f0360 100644 --- a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts @@ -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'; diff --git a/packages/0x.js/src/contract_wrappers/token_wrapper.ts b/packages/0x.js/src/contract_wrappers/token_wrapper.ts index 7943f4a60..a3a8074a8 100644 --- a/packages/0x.js/src/contract_wrappers/token_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/token_wrapper.ts @@ -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'; diff --git a/packages/0x.js/src/globals.d.ts b/packages/0x.js/src/globals.d.ts index 4f4932b6e..0e103d057 100644 --- a/packages/0x.js/src/globals.d.ts +++ b/packages/0x.js/src/globals.d.ts @@ -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[]; -} diff --git a/packages/0x.js/src/index.ts b/packages/0x.js/src/index.ts index 599c3a2b0..41e67e177 100644 --- a/packages/0x.js/src/index.ts +++ b/packages/0x.js/src/index.ts @@ -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'; diff --git a/packages/0x.js/src/order_watcher/order_state_watcher.ts b/packages/0x.js/src/order_watcher/order_state_watcher.ts index 12ac60960..446fab676 100644 --- a/packages/0x.js/src/order_watcher/order_state_watcher.ts +++ b/packages/0x.js/src/order_watcher/order_state_watcher.ts @@ -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'; diff --git a/packages/0x.js/src/types.ts b/packages/0x.js/src/types.ts index 55f7bb7d3..fcbb9e5f3 100644 --- a/packages/0x.js/src/types.ts +++ b/packages/0x.js/src/types.ts @@ -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 { export type EventCallback = (err: null | Error, log?: DecodedLogEvent) => 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 extends Web3.DecodedLogEntry {} - -export interface TransactionReceiptWithDecodedLogs extends TransactionReceipt { - logs: Array | Web3.LogEntry>; -} - export type ArtifactContractName = 'ZRX' | 'TokenTransferProxy' | 'TokenRegistry' | 'Token' | 'Exchange' | 'EtherToken'; export interface Artifact { diff --git a/packages/0x.js/src/utils/abi_decoder.ts b/packages/0x.js/src/utils/abi_decoder.ts deleted file mode 100644 index bbd2a0b1d..000000000 --- a/packages/0x.js/src/utils/abi_decoder.ts +++ /dev/null @@ -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( - log: Web3.LogEntry, - ): LogWithDecodedArgs | 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); - } -} diff --git a/packages/0x.js/src/utils/utils.ts b/packages/0x.js/src/utils/utils.ts index 42cf5d956..74f2c5995 100644 --- a/packages/0x.js/src/utils/utils.ts +++ b/packages/0x.js/src/utils/utils.ts @@ -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 = { /** -- cgit From a17091b394400ae13b7f85632b2c4a2e20935442 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 22 Jan 2018 22:19:29 +0100 Subject: Make awaitTransactionMinedAsync non-generic again --- packages/0x.js/src/0x.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'packages/0x.js') diff --git a/packages/0x.js/src/0x.ts b/packages/0x.js/src/0x.ts index 8eb8cdd9a..6cfa65cc2 100644 --- a/packages/0x.js/src/0x.ts +++ b/packages/0x.js/src/0x.ts @@ -285,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( txHash: string, pollingIntervalMs = 1000, timeoutMs?: number, - ): Promise> { + ): Promise { let timeoutExceeded = false; if (timeoutMs) { setTimeout(() => (timeoutExceeded = true), timeoutMs); } const txReceiptPromise = new Promise( - (resolve: (receipt: TransactionReceiptWithDecodedLogs) => void, reject) => { + (resolve: (receipt: TransactionReceiptWithDecodedLogs) => void, reject) => { const intervalId = intervalUtils.setAsyncExcludingInterval( async () => { if (timeoutExceeded) { @@ -311,7 +311,7 @@ export class ZeroEx { transactionReceipt.logs, this._abiDecoder.tryToDecodeLogOrNoop.bind(this._abiDecoder), ); - const transactionReceiptWithDecodedLogArgs: TransactionReceiptWithDecodedLogs = { + const transactionReceiptWithDecodedLogArgs: TransactionReceiptWithDecodedLogs = { ...transactionReceipt, logs: logsWithDecodedArgs, }; -- cgit From 1e9147b8bb45a251eefdead23573a9e8d68fc34b Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 25 Jan 2018 15:12:46 +0100 Subject: Normalize the dependencies --- packages/0x.js/package.json | 21 +++++++++------------ .../0x.js/src/contract_wrappers/token_wrapper.ts | 2 +- packages/0x.js/src/types.ts | 2 +- 3 files changed, 11 insertions(+), 14 deletions(-) (limited to 'packages/0x.js') diff --git a/packages/0x.js/package.json b/packages/0x.js/package.json index 2942e5001..9cce372a5 100644 --- a/packages/0x.js/package.json +++ b/packages/0x.js/package.json @@ -2,27 +2,24 @@ "name": "0x.js", "version": "0.31.0", "description": "A javascript library for interacting with the 0x protocol", - "keywords": [ - "0x.js", - "0xproject", - "ethereum", - "tokens", - "exchange" - ], + "keywords": ["0x.js", "0xproject", "ethereum", "tokens", "exchange"], "main": "lib/src/index.js", "types": "lib/src/index.d.ts", "scripts": { "prebuild": "run-s clean generate_contract_wrappers", "build": "run-p build:umd:prod build:commonjs; exit 0;", "docs:json": "typedoc --excludePrivate --excludeExternals --target ES5 --json $JSON_FILE_PATH $PROJECT_DIR", - "upload_docs_json": "aws s3 cp generated_docs/index.json $S3_URL --profile 0xproject --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers --content-type application/json", - "generate_contract_wrappers": "node ../abi-gen/lib/index.js --abiGlob 'src/artifacts/@(Exchange|Token|TokenTransferProxy|EtherToken|TokenRegistry|DummyToken).json' --templates contract_templates --output src/contract_wrappers/generated", + "upload_docs_json": + "aws s3 cp generated_docs/index.json $S3_URL --profile 0xproject --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers --content-type application/json", + "generate_contract_wrappers": + "node ../abi-gen/lib/index.js --abiGlob 'src/artifacts/@(Exchange|Token|TokenTransferProxy|EtherToken|TokenRegistry|DummyToken).json' --templates contract_templates --output src/contract_wrappers/generated", "lint": "tslint --project . 'src/**/*.ts' 'test/**/*.ts'", "test:circleci": "run-s test:coverage report_test_coverage", "test": "run-s clean test:commonjs", "test:coverage": "nyc npm run test --all", "report_test_coverage": "nyc report --reporter=text-lcov | coveralls", - "update_contracts": "for i in ${npm_package_config_artifacts}; do copyfiles -u 4 ../contracts/build/contracts/$i.json ../0x.js/src/artifacts; done;", + "update_contracts": + "for i in ${npm_package_config_artifacts}; do copyfiles -u 4 ../contracts/build/contracts/$i.json ../0x.js/src/artifacts; done;", "clean": "shx rm -rf _bundles lib test_temp", "build:umd:prod": "NODE_ENV=production webpack", "build:commonjs": "tsc && copyfiles -u 2 './src/artifacts/**/*.json' ./lib/src/artifacts;", @@ -66,7 +63,7 @@ "nyc": "^11.0.1", "opn-cli": "^3.1.0", "request": "^2.81.0", - "request-promise-native": "^1.0.4", + "request-promise-native": "^1.0.5", "shx": "^0.2.2", "sinon": "^4.0.0", "source-map-support": "^0.5.0", @@ -89,7 +86,7 @@ "ethereumjs-abi": "^0.6.4", "ethereumjs-blockstream": "^2.0.6", "ethereumjs-util": "^5.1.1", - "js-sha3": "^0.6.1", + "js-sha3": "^0.7.0", "lodash": "^4.17.4", "uuid": "^3.1.0", "web3": "^0.20.0" diff --git a/packages/0x.js/src/contract_wrappers/token_wrapper.ts b/packages/0x.js/src/contract_wrappers/token_wrapper.ts index a3a8074a8..4216ff462 100644 --- a/packages/0x.js/src/contract_wrappers/token_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/token_wrapper.ts @@ -1,6 +1,6 @@ import { schemas } from '@0xproject/json-schemas'; -import { AbiDecoder, 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'; diff --git a/packages/0x.js/src/types.ts b/packages/0x.js/src/types.ts index fcbb9e5f3..a0deb91c9 100644 --- a/packages/0x.js/src/types.ts +++ b/packages/0x.js/src/types.ts @@ -1,4 +1,4 @@ -import { ContractEventArg, DecodedLogArgs, LogWithDecodedArgs, TransactionReceipt } from '@0xproject/types'; +import { ContractEventArg, LogWithDecodedArgs } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import * as Web3 from 'web3'; -- cgit From c02dfc4fb1bf39ceaaf80ec68fb8907a4a11e0df Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 26 Jan 2018 12:57:51 +0100 Subject: Fix tslint issues --- packages/0x.js/src/contract_wrappers/exchange_wrapper.ts | 4 ++-- packages/0x.js/src/order_watcher/order_state_watcher.ts | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'packages/0x.js') diff --git a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts index 5672f0360..fceab851a 100644 --- a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts @@ -844,9 +844,9 @@ export class ExchangeWrapper extends ContractWrapper { public throwLogErrorsAsErrors(logs: Array | Web3.LogEntry>): void { const errLog = _.find(logs, { event: ExchangeEvents.LogError, - }) as LogWithDecodedArgs | undefined; + }); if (!_.isUndefined(errLog)) { - const logArgs = errLog.args; + const logArgs = (errLog as LogWithDecodedArgs).args; const errCode = logArgs.errorId.toNumber(); const errMessage = this._exchangeContractErrCodesToMsg[errCode]; throw new Error(errMessage); diff --git a/packages/0x.js/src/order_watcher/order_state_watcher.ts b/packages/0x.js/src/order_watcher/order_state_watcher.ts index 446fab676..576be00c8 100644 --- a/packages/0x.js/src/order_watcher/order_state_watcher.ts +++ b/packages/0x.js/src/order_watcher/order_state_watcher.ts @@ -223,12 +223,12 @@ export class OrderStateWatcher { return; } const log = logIfExists as LogEvent; // At this moment we are sure that no error occured and log is defined. - const maybeDecodedLog = this._abiDecoder.tryToDecodeLogOrNoop(log); - const isLogDecoded = !_.isUndefined((maybeDecodedLog as LogWithDecodedArgs).event); + const maybeDecodedLog = this._abiDecoder.tryToDecodeLogOrNoop(log); + const isLogDecoded = !_.isUndefined(((maybeDecodedLog as any) as LogWithDecodedArgs).event); if (!isLogDecoded) { return; // noop } - const decodedLog = maybeDecodedLog as LogWithDecodedArgs; + const decodedLog = (maybeDecodedLog as any) as LogWithDecodedArgs; let makerToken: string; let makerAddress: string; switch (decodedLog.event) { -- cgit From 6205209fbbb5dbebbf225e1cef76c3e86117d356 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 30 Jan 2018 14:03:54 +0100 Subject: Make an RPC constructor param implicit --- packages/0x.js/test/0x.js_test.ts | 2 +- packages/0x.js/test/ether_token_wrapper_test.ts | 2 +- packages/0x.js/test/exchange_transfer_simulator_test.ts | 2 +- packages/0x.js/test/exchange_wrapper_test.ts | 2 +- packages/0x.js/test/expiration_watcher_test.ts | 2 +- packages/0x.js/test/order_state_watcher_test.ts | 2 +- packages/0x.js/test/order_validation_test.ts | 2 +- packages/0x.js/test/subscription_test.ts | 2 +- packages/0x.js/test/token_registry_wrapper_test.ts | 2 +- packages/0x.js/test/token_wrapper_test.ts | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) (limited to 'packages/0x.js') diff --git a/packages/0x.js/test/0x.js_test.ts b/packages/0x.js/test/0x.js_test.ts index 6f8c4139a..5ebb68c8c 100644 --- a/packages/0x.js/test/0x.js_test.ts +++ b/packages/0x.js/test/0x.js_test.ts @@ -11,7 +11,7 @@ import { chaiSetup } from './utils/chai_setup'; import { constants } from './utils/constants'; import { TokenUtils } from './utils/token_utils'; -const blockchainLifecycle = new BlockchainLifecycle(devConstants.RPC_URL); +const blockchainLifecycle = new BlockchainLifecycle(); chaiSetup.configure(); const expect = chai.expect; diff --git a/packages/0x.js/test/ether_token_wrapper_test.ts b/packages/0x.js/test/ether_token_wrapper_test.ts index e0f18f26f..6069b42bf 100644 --- a/packages/0x.js/test/ether_token_wrapper_test.ts +++ b/packages/0x.js/test/ether_token_wrapper_test.ts @@ -27,7 +27,7 @@ import { TokenUtils } from './utils/token_utils'; chaiSetup.configure(); const expect = chai.expect; -const blockchainLifecycle = new BlockchainLifecycle(devConstants.RPC_URL); +const blockchainLifecycle = new BlockchainLifecycle(); // Since the address depositing/withdrawing ETH/WETH also needs to pay gas costs for the transaction, // a small amount of ETH will be used to pay this gas cost. We therefore check that the difference between diff --git a/packages/0x.js/test/exchange_transfer_simulator_test.ts b/packages/0x.js/test/exchange_transfer_simulator_test.ts index 4bbdecb60..e85a1640f 100644 --- a/packages/0x.js/test/exchange_transfer_simulator_test.ts +++ b/packages/0x.js/test/exchange_transfer_simulator_test.ts @@ -11,7 +11,7 @@ import { constants } from './utils/constants'; chaiSetup.configure(); const expect = chai.expect; -const blockchainLifecycle = new BlockchainLifecycle(devConstants.RPC_URL); +const blockchainLifecycle = new BlockchainLifecycle(); describe('ExchangeTransferSimulator', () => { const web3 = web3Factory.create(); diff --git a/packages/0x.js/test/exchange_wrapper_test.ts b/packages/0x.js/test/exchange_wrapper_test.ts index 016ef08ce..c15cd65a9 100644 --- a/packages/0x.js/test/exchange_wrapper_test.ts +++ b/packages/0x.js/test/exchange_wrapper_test.ts @@ -28,7 +28,7 @@ import { TokenUtils } from './utils/token_utils'; chaiSetup.configure(); const expect = chai.expect; -const blockchainLifecycle = new BlockchainLifecycle(devConstants.RPC_URL); +const blockchainLifecycle = new BlockchainLifecycle(); const NON_EXISTENT_ORDER_HASH = '0x79370342234e7acd6bbeac335bd3bb1d368383294b64b8160a00f4060e4d3777'; diff --git a/packages/0x.js/test/expiration_watcher_test.ts b/packages/0x.js/test/expiration_watcher_test.ts index 90fb20a52..b49dee8e5 100644 --- a/packages/0x.js/test/expiration_watcher_test.ts +++ b/packages/0x.js/test/expiration_watcher_test.ts @@ -19,7 +19,7 @@ import { TokenUtils } from './utils/token_utils'; chaiSetup.configure(); const expect = chai.expect; -const blockchainLifecycle = new BlockchainLifecycle(devConstants.RPC_URL); +const blockchainLifecycle = new BlockchainLifecycle(); describe('ExpirationWatcher', () => { let web3: Web3; diff --git a/packages/0x.js/test/order_state_watcher_test.ts b/packages/0x.js/test/order_state_watcher_test.ts index 79b43f433..9e2ad89e1 100644 --- a/packages/0x.js/test/order_state_watcher_test.ts +++ b/packages/0x.js/test/order_state_watcher_test.ts @@ -27,7 +27,7 @@ const TIMEOUT_MS = 150; chaiSetup.configure(); const expect = chai.expect; -const blockchainLifecycle = new BlockchainLifecycle(devConstants.RPC_URL); +const blockchainLifecycle = new BlockchainLifecycle(); describe('OrderStateWatcher', () => { let web3: Web3; diff --git a/packages/0x.js/test/order_validation_test.ts b/packages/0x.js/test/order_validation_test.ts index 23fe957fe..934e2e51f 100644 --- a/packages/0x.js/test/order_validation_test.ts +++ b/packages/0x.js/test/order_validation_test.ts @@ -16,7 +16,7 @@ import { TokenUtils } from './utils/token_utils'; chaiSetup.configure(); const expect = chai.expect; -const blockchainLifecycle = new BlockchainLifecycle(devConstants.RPC_URL); +const blockchainLifecycle = new BlockchainLifecycle(); describe('OrderValidation', () => { let web3: Web3; diff --git a/packages/0x.js/test/subscription_test.ts b/packages/0x.js/test/subscription_test.ts index 60a4f7ec9..f485bf84b 100644 --- a/packages/0x.js/test/subscription_test.ts +++ b/packages/0x.js/test/subscription_test.ts @@ -13,7 +13,7 @@ import { constants } from './utils/constants'; import { assertNodeCallbackError } from './utils/report_callback_errors'; chaiSetup.configure(); -const blockchainLifecycle = new BlockchainLifecycle(devConstants.RPC_URL); +const blockchainLifecycle = new BlockchainLifecycle(); describe('SubscriptionTest', () => { let web3: Web3; diff --git a/packages/0x.js/test/token_registry_wrapper_test.ts b/packages/0x.js/test/token_registry_wrapper_test.ts index 396de5193..fefb99b16 100644 --- a/packages/0x.js/test/token_registry_wrapper_test.ts +++ b/packages/0x.js/test/token_registry_wrapper_test.ts @@ -11,7 +11,7 @@ import { constants } from './utils/constants'; chaiSetup.configure(); const expect = chai.expect; -const blockchainLifecycle = new BlockchainLifecycle(devConstants.RPC_URL); +const blockchainLifecycle = new BlockchainLifecycle(); const TOKEN_REGISTRY_SIZE_AFTER_MIGRATION = 7; diff --git a/packages/0x.js/test/token_wrapper_test.ts b/packages/0x.js/test/token_wrapper_test.ts index 8b8f19297..070d6ec47 100644 --- a/packages/0x.js/test/token_wrapper_test.ts +++ b/packages/0x.js/test/token_wrapper_test.ts @@ -25,7 +25,7 @@ import { TokenUtils } from './utils/token_utils'; chaiSetup.configure(); const expect = chai.expect; -const blockchainLifecycle = new BlockchainLifecycle(devConstants.RPC_URL); +const blockchainLifecycle = new BlockchainLifecycle(); describe('TokenWrapper', () => { let web3: Web3; -- cgit From 7cc4a8f5cebb41ee5b9a37a1732d7f2af5d16d4a Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Tue, 30 Jan 2018 16:26:42 -0800 Subject: Fix lint errors --- packages/0x.js/contract_templates/contract.mustache | 2 +- packages/0x.js/contract_templates/partials/call.mustache | 4 ++-- packages/0x.js/contract_templates/partials/tx.mustache | 10 +++++----- packages/0x.js/src/contract_wrappers/contract_wrapper.ts | 2 +- packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts | 6 +++--- packages/0x.js/src/contract_wrappers/exchange_wrapper.ts | 6 +++--- .../0x.js/src/contract_wrappers/generated/base_contract.ts | 12 ++++++------ packages/0x.js/src/contract_wrappers/token_wrapper.ts | 6 +++--- packages/0x.js/test/ether_token_wrapper_test.ts | 2 +- packages/0x.js/test/exchange_wrapper_test.ts | 2 +- packages/0x.js/test/subscription_test.ts | 4 ++-- packages/0x.js/test/token_wrapper_test.ts | 2 +- 12 files changed, 29 insertions(+), 29 deletions(-) (limited to 'packages/0x.js') diff --git a/packages/0x.js/contract_templates/contract.mustache b/packages/0x.js/contract_templates/contract.mustache index 3e501cce6..d3fe1b8cc 100644 --- a/packages/0x.js/contract_templates/contract.mustache +++ b/packages/0x.js/contract_templates/contract.mustache @@ -20,6 +20,6 @@ export class {{contractName}}Contract extends BaseContract { {{/each}} constructor(web3ContractInstance: Web3.ContractInstance, defaults: Partial) { super(web3ContractInstance, defaults); - classUtils.bindAll(this, ['web3ContractInstance', 'defaults']); + classUtils.bindAll(this, ['_web3ContractInstance', '_defaults']); } } // tslint:disable:max-file-line-count diff --git a/packages/0x.js/contract_templates/partials/call.mustache b/packages/0x.js/contract_templates/partials/call.mustache index ef4bda724..0475136f0 100644 --- a/packages/0x.js/contract_templates/partials/call.mustache +++ b/packages/0x.js/contract_templates/partials/call.mustache @@ -5,8 +5,8 @@ public {{this.name}} = { ): Promise<{{> return_type outputs=outputs}}> { const self = this as {{contractName}}Contract; const result = await promisify<{{> return_type outputs=outputs}}>( - self.web3ContractInstance.{{this.name}}.call, - self.web3ContractInstance, + self._web3ContractInstance.{{this.name}}.call, + self._web3ContractInstance, )( {{> params inputs=inputs}} ); diff --git a/packages/0x.js/contract_templates/partials/tx.mustache b/packages/0x.js/contract_templates/partials/tx.mustache index 8a43e5319..9df83266a 100644 --- a/packages/0x.js/contract_templates/partials/tx.mustache +++ b/packages/0x.js/contract_templates/partials/tx.mustache @@ -9,7 +9,7 @@ public {{this.name}} = { {{/this.payable}} ): Promise { const self = this as {{contractName}}Contract; - const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( txData, self.{{this.name}}.estimateGasAsync.bind( self, @@ -17,7 +17,7 @@ public {{this.name}} = { ), ); const txHash = await promisify( - self.web3ContractInstance.{{this.name}}, self.web3ContractInstance, + self._web3ContractInstance.{{this.name}}, self._web3ContractInstance, )( {{> params inputs=inputs}} txDataWithDefaults, @@ -29,11 +29,11 @@ public {{this.name}} = { txData: TxData = {}, ): Promise { const self = this as {{contractName}}Contract; - const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( txData, ); const gas = await promisify( - self.web3ContractInstance.{{this.name}}.estimateGas, self.web3ContractInstance, + self._web3ContractInstance.{{this.name}}.estimateGas, self._web3ContractInstance, )( {{> params inputs=inputs}} txDataWithDefaults, @@ -45,7 +45,7 @@ public {{this.name}} = { txData: TxData = {}, ): string { const self = this as {{contractName}}Contract; - const abiEncodedTransactionData = self.web3ContractInstance.{{this.name}}.getData(); + const abiEncodedTransactionData = self._web3ContractInstance.{{this.name}}.getData(); return abiEncodedTransactionData; }, }; diff --git a/packages/0x.js/src/contract_wrappers/contract_wrapper.ts b/packages/0x.js/src/contract_wrappers/contract_wrapper.ts index 5f11d810a..873489dc9 100644 --- a/packages/0x.js/src/contract_wrappers/contract_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/contract_wrapper.ts @@ -52,7 +52,7 @@ export class ContractWrapper { this._onLogAddedSubscriptionToken = undefined; this._onLogRemovedSubscriptionToken = undefined; } - protected unsubscribeAll(): void { + protected _unsubscribeAll(): void { const filterTokens = _.keys(this._filterCallbacks); _.each(filterTokens, filterToken => { this._unsubscribe(filterToken); diff --git a/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts b/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts index 8fa7aa78b..cbafcfe94 100644 --- a/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts @@ -159,11 +159,11 @@ export class EtherTokenWrapper extends ContractWrapper { /** * Cancels all existing subscriptions */ - public unsubscribeAll(): void { - super.unsubscribeAll(); + public _unsubscribeAll(): void { + super._unsubscribeAll(); } private _invalidateContractInstance(): void { - this.unsubscribeAll(); + this._unsubscribeAll(); this._etherTokenContractsByAddress = {}; } private async _getEtherTokenContractAsync(etherTokenAddress: string): Promise { diff --git a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts index fceab851a..63c0d073a 100644 --- a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts @@ -678,8 +678,8 @@ export class ExchangeWrapper extends ContractWrapper { /** * Cancels all existing subscriptions */ - public unsubscribeAll(): void { - super.unsubscribeAll(); + public _unsubscribeAll(): void { + super._unsubscribeAll(); } /** * Gets historical logs without creating a subscription @@ -861,7 +861,7 @@ export class ExchangeWrapper extends ContractWrapper { return contractAddress; } private _invalidateContractInstances(): void { - this.unsubscribeAll(); + this._unsubscribeAll(); delete this._exchangeContractIfExists; } private async _isValidSignatureUsingContractCallAsync( diff --git a/packages/0x.js/src/contract_wrappers/generated/base_contract.ts b/packages/0x.js/src/contract_wrappers/generated/base_contract.ts index 28a7e2f52..d8fac7eea 100644 --- a/packages/0x.js/src/contract_wrappers/generated/base_contract.ts +++ b/packages/0x.js/src/contract_wrappers/generated/base_contract.ts @@ -3,9 +3,9 @@ import * as _ from 'lodash'; import * as Web3 from 'web3'; export class BaseContract { - protected web3ContractInstance: Web3.ContractInstance; - protected defaults: Partial; - protected async applyDefaultsToTxDataAsync( + protected _web3ContractInstance: Web3.ContractInstance; + protected _defaults: Partial; + protected async _applyDefaultsToTxDataAsync( txData: T, estimateGasAsync?: (txData: T) => Promise, ): Promise { @@ -15,7 +15,7 @@ export class BaseContract { // 3. Gas estimate calculation + safety margin const removeUndefinedProperties = _.pickBy; const txDataWithDefaults = { - ...removeUndefinedProperties(this.defaults), + ...removeUndefinedProperties(this._defaults), ...removeUndefinedProperties(txData as any), // HACK: TS can't prove that T is spreadable. // Awaiting https://github.com/Microsoft/TypeScript/pull/13288 to be merged @@ -27,7 +27,7 @@ export class BaseContract { return txDataWithDefaults; } constructor(web3ContractInstance: Web3.ContractInstance, defaults: Partial) { - this.web3ContractInstance = web3ContractInstance; - this.defaults = defaults; + this._web3ContractInstance = web3ContractInstance; + this._defaults = defaults; } } diff --git a/packages/0x.js/src/contract_wrappers/token_wrapper.ts b/packages/0x.js/src/contract_wrappers/token_wrapper.ts index 4216ff462..98c24d059 100644 --- a/packages/0x.js/src/contract_wrappers/token_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/token_wrapper.ts @@ -342,8 +342,8 @@ export class TokenWrapper extends ContractWrapper { /** * Cancels all existing subscriptions */ - public unsubscribeAll(): void { - super.unsubscribeAll(); + public _unsubscribeAll(): void { + super._unsubscribeAll(); } /** * Gets historical logs without creating a subscription @@ -374,7 +374,7 @@ export class TokenWrapper extends ContractWrapper { return logs; } private _invalidateContractInstances(): void { - this.unsubscribeAll(); + this._unsubscribeAll(); this._tokenContractsByAddress = {}; } private async _getTokenContractAsync(tokenAddress: string): Promise { diff --git a/packages/0x.js/test/ether_token_wrapper_test.ts b/packages/0x.js/test/ether_token_wrapper_test.ts index 6069b42bf..9716abab8 100644 --- a/packages/0x.js/test/ether_token_wrapper_test.ts +++ b/packages/0x.js/test/ether_token_wrapper_test.ts @@ -144,7 +144,7 @@ describe('EtherTokenWrapper', () => { etherTokenAddress = etherToken.address; }); afterEach(() => { - zeroEx.etherToken.unsubscribeAll(); + zeroEx.etherToken._unsubscribeAll(); }); // Hack: Mocha does not allow a test to be both async and have a `done` callback // Since we need to await the receipt of the event in the `subscribe` callback, diff --git a/packages/0x.js/test/exchange_wrapper_test.ts b/packages/0x.js/test/exchange_wrapper_test.ts index c15cd65a9..044298601 100644 --- a/packages/0x.js/test/exchange_wrapper_test.ts +++ b/packages/0x.js/test/exchange_wrapper_test.ts @@ -921,7 +921,7 @@ describe('ExchangeWrapper', () => { ); }); afterEach(async () => { - zeroEx.exchange.unsubscribeAll(); + zeroEx.exchange._unsubscribeAll(); }); // Hack: Mocha does not allow a test to be both async and have a `done` callback // Since we need to await the receipt of the event in the `subscribe` callback, diff --git a/packages/0x.js/test/subscription_test.ts b/packages/0x.js/test/subscription_test.ts index f485bf84b..337e2effa 100644 --- a/packages/0x.js/test/subscription_test.ts +++ b/packages/0x.js/test/subscription_test.ts @@ -49,7 +49,7 @@ describe('SubscriptionTest', () => { tokenAddress = token.address; }); afterEach(() => { - zeroEx.token.unsubscribeAll(); + zeroEx.token._unsubscribeAll(); _.each(stubs, s => s.restore()); stubs = []; }); @@ -76,7 +76,7 @@ describe('SubscriptionTest', () => { const callback = (err: Error | null, logEvent?: DecodedLogEvent) => _.noop; zeroEx.token.subscribe(tokenAddress, TokenEvents.Approval, indexFilterValues, callback); stubs = [Sinon.stub((zeroEx as any)._web3Wrapper, 'getBlockAsync').throws(new Error('JSON RPC error'))]; - zeroEx.token.unsubscribeAll(); + zeroEx.token._unsubscribeAll(); done(); })().catch(done); }); diff --git a/packages/0x.js/test/token_wrapper_test.ts b/packages/0x.js/test/token_wrapper_test.ts index 070d6ec47..34ebe30c2 100644 --- a/packages/0x.js/test/token_wrapper_test.ts +++ b/packages/0x.js/test/token_wrapper_test.ts @@ -377,7 +377,7 @@ describe('TokenWrapper', () => { tokenAddress = token.address; }); afterEach(() => { - zeroEx.token.unsubscribeAll(); + zeroEx.token._unsubscribeAll(); }); // Hack: Mocha does not allow a test to be both async and have a `done` callback // Since we need to await the receipt of the event in the `subscribe` callback, -- cgit From eaeb715e56bbb3243268ee5fd863cfd1f1211c39 Mon Sep 17 00:00:00 2001 From: Olaf Tomalka Date: Wed, 31 Jan 2018 14:24:20 +0100 Subject: Updated contract generation in 0x to new abi-gen CLI --- .../0x.js/contract_templates/contract.handlebars | 25 +++++++++++ .../0x.js/contract_templates/contract.mustache | 25 ----------- .../contract_templates/partials/call.handlebars | 15 +++++++ .../contract_templates/partials/call.mustache | 15 ------- .../contract_templates/partials/params.handlebars | 3 ++ .../contract_templates/partials/params.mustache | 3 -- .../partials/return_type.handlebars | 6 +++ .../partials/return_type.mustache | 6 --- .../contract_templates/partials/tx.handlebars | 51 ++++++++++++++++++++++ .../0x.js/contract_templates/partials/tx.mustache | 51 ---------------------- .../partials/typed_params.handlebars | 3 ++ .../partials/typed_params.mustache | 3 -- packages/0x.js/package.json | 2 +- 13 files changed, 104 insertions(+), 104 deletions(-) create mode 100644 packages/0x.js/contract_templates/contract.handlebars delete mode 100644 packages/0x.js/contract_templates/contract.mustache create mode 100644 packages/0x.js/contract_templates/partials/call.handlebars delete mode 100644 packages/0x.js/contract_templates/partials/call.mustache create mode 100644 packages/0x.js/contract_templates/partials/params.handlebars delete mode 100644 packages/0x.js/contract_templates/partials/params.mustache create mode 100644 packages/0x.js/contract_templates/partials/return_type.handlebars delete mode 100644 packages/0x.js/contract_templates/partials/return_type.mustache create mode 100644 packages/0x.js/contract_templates/partials/tx.handlebars delete mode 100644 packages/0x.js/contract_templates/partials/tx.mustache create mode 100644 packages/0x.js/contract_templates/partials/typed_params.handlebars delete mode 100644 packages/0x.js/contract_templates/partials/typed_params.mustache (limited to 'packages/0x.js') diff --git a/packages/0x.js/contract_templates/contract.handlebars b/packages/0x.js/contract_templates/contract.handlebars new file mode 100644 index 000000000..3e501cce6 --- /dev/null +++ b/packages/0x.js/contract_templates/contract.handlebars @@ -0,0 +1,25 @@ +/** + * This file is auto-generated using abi-gen. Don't edit directly. + * Templates can be found at https://github.com/0xProject/0x.js/tree/development/packages/abi-gen-templates. + */ +// tslint:disable-next-line:no-unused-variable +import { TxData, TxDataPayable } from '@0xproject/types'; +import { BigNumber, classUtils, promisify } from '@0xproject/utils'; +import * as Web3 from 'web3'; + +import {BaseContract} from './base_contract'; + +export class {{contractName}}Contract extends BaseContract { +{{#each methods}} + {{#this.constant}} + {{> call contractName=../contractName}} + {{/this.constant}} + {{^this.constant}} + {{> tx contractName=../contractName}} + {{/this.constant}} +{{/each}} + constructor(web3ContractInstance: Web3.ContractInstance, defaults: Partial) { + super(web3ContractInstance, defaults); + classUtils.bindAll(this, ['web3ContractInstance', 'defaults']); + } +} // tslint:disable:max-file-line-count diff --git a/packages/0x.js/contract_templates/contract.mustache b/packages/0x.js/contract_templates/contract.mustache deleted file mode 100644 index 3e501cce6..000000000 --- a/packages/0x.js/contract_templates/contract.mustache +++ /dev/null @@ -1,25 +0,0 @@ -/** - * This file is auto-generated using abi-gen. Don't edit directly. - * Templates can be found at https://github.com/0xProject/0x.js/tree/development/packages/abi-gen-templates. - */ -// tslint:disable-next-line:no-unused-variable -import { TxData, TxDataPayable } from '@0xproject/types'; -import { BigNumber, classUtils, promisify } from '@0xproject/utils'; -import * as Web3 from 'web3'; - -import {BaseContract} from './base_contract'; - -export class {{contractName}}Contract extends BaseContract { -{{#each methods}} - {{#this.constant}} - {{> call contractName=../contractName}} - {{/this.constant}} - {{^this.constant}} - {{> tx contractName=../contractName}} - {{/this.constant}} -{{/each}} - constructor(web3ContractInstance: Web3.ContractInstance, defaults: Partial) { - super(web3ContractInstance, defaults); - classUtils.bindAll(this, ['web3ContractInstance', 'defaults']); - } -} // tslint:disable:max-file-line-count diff --git a/packages/0x.js/contract_templates/partials/call.handlebars b/packages/0x.js/contract_templates/partials/call.handlebars new file mode 100644 index 000000000..ef4bda724 --- /dev/null +++ b/packages/0x.js/contract_templates/partials/call.handlebars @@ -0,0 +1,15 @@ +public {{this.name}} = { + async callAsync( + {{> typed_params inputs=inputs}} + defaultBlock?: Web3.BlockParam, + ): Promise<{{> return_type outputs=outputs}}> { + const self = this as {{contractName}}Contract; + const result = await promisify<{{> return_type outputs=outputs}}>( + self.web3ContractInstance.{{this.name}}.call, + self.web3ContractInstance, + )( + {{> params inputs=inputs}} + ); + return result; + }, +}; diff --git a/packages/0x.js/contract_templates/partials/call.mustache b/packages/0x.js/contract_templates/partials/call.mustache deleted file mode 100644 index ef4bda724..000000000 --- a/packages/0x.js/contract_templates/partials/call.mustache +++ /dev/null @@ -1,15 +0,0 @@ -public {{this.name}} = { - async callAsync( - {{> typed_params inputs=inputs}} - defaultBlock?: Web3.BlockParam, - ): Promise<{{> return_type outputs=outputs}}> { - const self = this as {{contractName}}Contract; - const result = await promisify<{{> return_type outputs=outputs}}>( - self.web3ContractInstance.{{this.name}}.call, - self.web3ContractInstance, - )( - {{> params inputs=inputs}} - ); - return result; - }, -}; diff --git a/packages/0x.js/contract_templates/partials/params.handlebars b/packages/0x.js/contract_templates/partials/params.handlebars new file mode 100644 index 000000000..ac5d4ae85 --- /dev/null +++ b/packages/0x.js/contract_templates/partials/params.handlebars @@ -0,0 +1,3 @@ +{{#each inputs}} +{{name}}, +{{/each}} diff --git a/packages/0x.js/contract_templates/partials/params.mustache b/packages/0x.js/contract_templates/partials/params.mustache deleted file mode 100644 index ac5d4ae85..000000000 --- a/packages/0x.js/contract_templates/partials/params.mustache +++ /dev/null @@ -1,3 +0,0 @@ -{{#each inputs}} -{{name}}, -{{/each}} diff --git a/packages/0x.js/contract_templates/partials/return_type.handlebars b/packages/0x.js/contract_templates/partials/return_type.handlebars new file mode 100644 index 000000000..383961a40 --- /dev/null +++ b/packages/0x.js/contract_templates/partials/return_type.handlebars @@ -0,0 +1,6 @@ +{{#singleReturnValue}} +{{#returnType outputs.0.type}}{{/returnType}} +{{/singleReturnValue}} +{{^singleReturnValue}} +[{{#each outputs}}{{#returnType type}}{{/returnType}}{{#unless @last}}, {{/unless}}{{/each}}] +{{/singleReturnValue}} diff --git a/packages/0x.js/contract_templates/partials/return_type.mustache b/packages/0x.js/contract_templates/partials/return_type.mustache deleted file mode 100644 index 383961a40..000000000 --- a/packages/0x.js/contract_templates/partials/return_type.mustache +++ /dev/null @@ -1,6 +0,0 @@ -{{#singleReturnValue}} -{{#returnType outputs.0.type}}{{/returnType}} -{{/singleReturnValue}} -{{^singleReturnValue}} -[{{#each outputs}}{{#returnType type}}{{/returnType}}{{#unless @last}}, {{/unless}}{{/each}}] -{{/singleReturnValue}} diff --git a/packages/0x.js/contract_templates/partials/tx.handlebars b/packages/0x.js/contract_templates/partials/tx.handlebars new file mode 100644 index 000000000..8a43e5319 --- /dev/null +++ b/packages/0x.js/contract_templates/partials/tx.handlebars @@ -0,0 +1,51 @@ +public {{this.name}} = { + async sendTransactionAsync( + {{> typed_params inputs=inputs}} + {{#this.payable}} + txData: TxDataPayable = {}, + {{/this.payable}} + {{^this.payable}} + txData: TxData = {}, + {{/this.payable}} + ): Promise { + const self = this as {{contractName}}Contract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + self.{{this.name}}.estimateGasAsync.bind( + self, + {{> params inputs=inputs}} + ), + ); + const txHash = await promisify( + self.web3ContractInstance.{{this.name}}, self.web3ContractInstance, + )( + {{> params inputs=inputs}} + txDataWithDefaults, + ); + return txHash; + }, + async estimateGasAsync( + {{> typed_params inputs=inputs}} + txData: TxData = {}, + ): Promise { + const self = this as {{contractName}}Contract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + ); + const gas = await promisify( + self.web3ContractInstance.{{this.name}}.estimateGas, self.web3ContractInstance, + )( + {{> params inputs=inputs}} + txDataWithDefaults, + ); + return gas; + }, + getABIEncodedTransactionData( + {{> typed_params inputs=inputs}} + txData: TxData = {}, + ): string { + const self = this as {{contractName}}Contract; + const abiEncodedTransactionData = self.web3ContractInstance.{{this.name}}.getData(); + return abiEncodedTransactionData; + }, +}; diff --git a/packages/0x.js/contract_templates/partials/tx.mustache b/packages/0x.js/contract_templates/partials/tx.mustache deleted file mode 100644 index 8a43e5319..000000000 --- a/packages/0x.js/contract_templates/partials/tx.mustache +++ /dev/null @@ -1,51 +0,0 @@ -public {{this.name}} = { - async sendTransactionAsync( - {{> typed_params inputs=inputs}} - {{#this.payable}} - txData: TxDataPayable = {}, - {{/this.payable}} - {{^this.payable}} - txData: TxData = {}, - {{/this.payable}} - ): Promise { - const self = this as {{contractName}}Contract; - const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( - txData, - self.{{this.name}}.estimateGasAsync.bind( - self, - {{> params inputs=inputs}} - ), - ); - const txHash = await promisify( - self.web3ContractInstance.{{this.name}}, self.web3ContractInstance, - )( - {{> params inputs=inputs}} - txDataWithDefaults, - ); - return txHash; - }, - async estimateGasAsync( - {{> typed_params inputs=inputs}} - txData: TxData = {}, - ): Promise { - const self = this as {{contractName}}Contract; - const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( - txData, - ); - const gas = await promisify( - self.web3ContractInstance.{{this.name}}.estimateGas, self.web3ContractInstance, - )( - {{> params inputs=inputs}} - txDataWithDefaults, - ); - return gas; - }, - getABIEncodedTransactionData( - {{> typed_params inputs=inputs}} - txData: TxData = {}, - ): string { - const self = this as {{contractName}}Contract; - const abiEncodedTransactionData = self.web3ContractInstance.{{this.name}}.getData(); - return abiEncodedTransactionData; - }, -}; diff --git a/packages/0x.js/contract_templates/partials/typed_params.handlebars b/packages/0x.js/contract_templates/partials/typed_params.handlebars new file mode 100644 index 000000000..3ea4b2e95 --- /dev/null +++ b/packages/0x.js/contract_templates/partials/typed_params.handlebars @@ -0,0 +1,3 @@ +{{#each inputs}} + {{name}}: {{#parameterType type}}{{/parameterType}}, +{{/each}} diff --git a/packages/0x.js/contract_templates/partials/typed_params.mustache b/packages/0x.js/contract_templates/partials/typed_params.mustache deleted file mode 100644 index 3ea4b2e95..000000000 --- a/packages/0x.js/contract_templates/partials/typed_params.mustache +++ /dev/null @@ -1,3 +0,0 @@ -{{#each inputs}} - {{name}}: {{#parameterType type}}{{/parameterType}}, -{{/each}} diff --git a/packages/0x.js/package.json b/packages/0x.js/package.json index fc0334dd0..22ccbbc2d 100644 --- a/packages/0x.js/package.json +++ b/packages/0x.js/package.json @@ -12,7 +12,7 @@ "upload_docs_json": "aws s3 cp generated_docs/index.json $S3_URL --profile 0xproject --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers --content-type application/json", "generate_contract_wrappers": - "node ../abi-gen/lib/index.js --abiGlob 'src/artifacts/@(Exchange|Token|TokenTransferProxy|EtherToken|TokenRegistry|DummyToken).json' --templates contract_templates --output src/contract_wrappers/generated", + "node ../abi-gen/lib/index.js --abis 'src/artifacts/@(Exchange|Token|TokenTransferProxy|EtherToken|TokenRegistry|DummyToken).json' --template contract_templates/contract.handlebars --partials 'contract_templates/partials/**/*.handlebars' --output src/contract_wrappers/generated", "lint": "tslint --project . 'src/**/*.ts' 'test/**/*.ts'", "test:circleci": "run-s test:coverage report_test_coverage", "test": "run-s clean test:commonjs", -- cgit From 6811bdec404fccb9dcf10e6802671317159b6533 Mon Sep 17 00:00:00 2001 From: Luke Autry Date: Wed, 31 Jan 2018 22:56:05 -0500 Subject: don't remove maker/zrx order from cache twice --- packages/0x.js/src/order_watcher/order_state_watcher.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'packages/0x.js') diff --git a/packages/0x.js/src/order_watcher/order_state_watcher.ts b/packages/0x.js/src/order_watcher/order_state_watcher.ts index 576be00c8..c425c98ee 100644 --- a/packages/0x.js/src/order_watcher/order_state_watcher.ts +++ b/packages/0x.js/src/order_watcher/order_state_watcher.ts @@ -133,8 +133,12 @@ export class OrderStateWatcher { delete this._orderStateByOrderHashCache[orderHash]; const exchange = (this._orderFilledCancelledLazyStore as any)._exchange as ExchangeWrapper; const zrxTokenAddress = exchange.getZRXTokenAddress(); + this._removeFromDependentOrderHashes(signedOrder.maker, zrxTokenAddress, orderHash); - this._removeFromDependentOrderHashes(signedOrder.maker, signedOrder.makerTokenAddress, orderHash); + if (zrxTokenAddress !== signedOrder.makerTokenAddress) { + this.removeFromDependentOrderHashes(signedOrder.maker, signedOrder.makerTokenAddress, orderHash); + } + this._expirationWatcher.removeOrder(orderHash); } /** -- cgit From 09659cc3041e8662e64beab2728477f3437c1ced Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 1 Feb 2018 12:30:41 +0100 Subject: Add build:watch command to all TS packages --- packages/0x.js/package.json | 1 + 1 file changed, 1 insertion(+) (limited to 'packages/0x.js') diff --git a/packages/0x.js/package.json b/packages/0x.js/package.json index 32063aab2..93ffef376 100644 --- a/packages/0x.js/package.json +++ b/packages/0x.js/package.json @@ -6,6 +6,7 @@ "main": "lib/src/index.js", "types": "lib/src/index.d.ts", "scripts": { + "build:watch": "tsc -w", "prebuild": "run-s clean generate_contract_wrappers", "build": "run-p build:umd:prod build:commonjs; exit 0;", "docs:json": "typedoc --excludePrivate --excludeExternals --target ES5 --json $JSON_FILE_PATH $PROJECT_DIR", -- cgit From 39e3733be4b2a8bb6f163c0aa02fbe57db213e61 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 1 Feb 2018 12:50:55 +0100 Subject: Upgrade TS to the newest version --- packages/0x.js/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/0x.js') diff --git a/packages/0x.js/package.json b/packages/0x.js/package.json index 93ffef376..150d823ff 100644 --- a/packages/0x.js/package.json +++ b/packages/0x.js/package.json @@ -71,7 +71,7 @@ "truffle-hdwallet-provider": "^0.0.3", "tslint": "5.8.0", "typedoc": "~0.8.0", - "typescript": "~2.6.1", + "typescript": "2.7.1", "web3-provider-engine": "^13.0.1", "web3-typescript-typings": "^0.9.7", "webpack": "^3.1.0" -- cgit From f6d963d45ac1e07e3cd56cdd47f7f1576dd7ac96 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 1 Feb 2018 12:51:04 +0100 Subject: Fix errors after TS upgrade --- packages/0x.js/src/contract_wrappers/contract_wrapper.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'packages/0x.js') diff --git a/packages/0x.js/src/contract_wrappers/contract_wrapper.ts b/packages/0x.js/src/contract_wrappers/contract_wrapper.ts index 873489dc9..2d5818618 100644 --- a/packages/0x.js/src/contract_wrappers/contract_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/contract_wrapper.ts @@ -34,8 +34,8 @@ export class ContractWrapper { protected _web3Wrapper: Web3Wrapper; private _networkId: number; private _abiDecoder?: AbiDecoder; - private _blockAndLogStreamerIfExists: BlockAndLogStreamer | undefined; - private _blockAndLogStreamInterval: NodeJS.Timer; + private _blockAndLogStreamerIfExists?: BlockAndLogStreamer; + private _blockAndLogStreamIntervalIfExists?: NodeJS.Timer; private _filters: { [filterToken: string]: Web3.FilterObject }; private _filterCallbacks: { [filterToken: string]: EventCallback; @@ -162,7 +162,7 @@ export class ContractWrapper { ); const catchAllLogFilter = {}; this._blockAndLogStreamerIfExists.addLogFilter(catchAllLogFilter); - this._blockAndLogStreamInterval = intervalUtils.setAsyncExcludingInterval( + this._blockAndLogStreamIntervalIfExists = intervalUtils.setAsyncExcludingInterval( this._reconcileBlockAsync.bind(this), constants.DEFAULT_BLOCK_POLLING_INTERVAL, this._onReconcileBlockError.bind(this), @@ -191,7 +191,7 @@ export class ContractWrapper { } this._blockAndLogStreamerIfExists.unsubscribeFromOnLogAdded(this._onLogAddedSubscriptionToken as string); this._blockAndLogStreamerIfExists.unsubscribeFromOnLogRemoved(this._onLogRemovedSubscriptionToken as string); - intervalUtils.clearAsyncExcludingInterval(this._blockAndLogStreamInterval); + intervalUtils.clearAsyncExcludingInterval(this._blockAndLogStreamIntervalIfExists as NodeJS.Timer); delete this._blockAndLogStreamerIfExists; } private async _reconcileBlockAsync(): Promise { -- cgit From 8e0e9c7d3a0a3e84f81f6180a6168917e11f1096 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 1 Feb 2018 16:27:12 +0100 Subject: Update changelog --- packages/0x.js/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'packages/0x.js') diff --git a/packages/0x.js/CHANGELOG.md b/packages/0x.js/CHANGELOG.md index 83c33ee1c..5250402c6 100644 --- a/packages/0x.js/CHANGELOG.md +++ b/packages/0x.js/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## v0.31.1 - _February 1, 2018_ + + * Fix the bug causing order watcher to throw is makerToken === zrx (#357) + ## v0.31.0 - _January 30, 2018_ * Add the `shouldAddPersonalMessagePrefix` parameter to `signOrderHashAsync` so that the -- cgit From 8df2cc103e0f8b0a1455e18ff81334c9bf066165 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 1 Feb 2018 16:29:16 +0100 Subject: Fix linter errors --- packages/0x.js/src/order_watcher/order_state_watcher.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'packages/0x.js') diff --git a/packages/0x.js/src/order_watcher/order_state_watcher.ts b/packages/0x.js/src/order_watcher/order_state_watcher.ts index c425c98ee..1ad1a90b1 100644 --- a/packages/0x.js/src/order_watcher/order_state_watcher.ts +++ b/packages/0x.js/src/order_watcher/order_state_watcher.ts @@ -133,10 +133,10 @@ export class OrderStateWatcher { delete this._orderStateByOrderHashCache[orderHash]; const exchange = (this._orderFilledCancelledLazyStore as any)._exchange as ExchangeWrapper; const zrxTokenAddress = exchange.getZRXTokenAddress(); - + this._removeFromDependentOrderHashes(signedOrder.maker, zrxTokenAddress, orderHash); if (zrxTokenAddress !== signedOrder.makerTokenAddress) { - this.removeFromDependentOrderHashes(signedOrder.maker, signedOrder.makerTokenAddress, orderHash); + this._removeFromDependentOrderHashes(signedOrder.maker, signedOrder.makerTokenAddress, orderHash); } this._expirationWatcher.removeOrder(orderHash); -- cgit From d4631e14b2203bfd95b995d25819d8d9cb834336 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 1 Feb 2018 16:39:06 +0100 Subject: Publish - 0x.js@0.31.1 - @0xproject/abi-gen@0.1.6 - @0xproject/assert@0.0.15 - chai-as-promised-typescript-typings@0.0.8 - @0xproject/connect@0.5.4 - contracts@2.1.8 - @0xproject/deployer@0.0.5 - @0xproject/dev-utils@0.0.9 - @0xproject/json-schemas@0.7.7 - @0xproject/monorepo-scripts@0.1.8 - @0xproject/subproviders@0.3.5 - @0xproject/testnet-faucets@1.0.9 - @0xproject/tslint-config@0.4.6 - @0xproject/types@0.1.8 - @0xproject/utils@0.2.4 - web3-typescript-typings@0.9.8 - @0xproject/web3-wrapper@0.1.9 - @0xproject/website@0.0.11 --- packages/0x.js/package.json | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) (limited to 'packages/0x.js') diff --git a/packages/0x.js/package.json b/packages/0x.js/package.json index 32063aab2..e56c9963e 100644 --- a/packages/0x.js/package.json +++ b/packages/0x.js/package.json @@ -1,25 +1,28 @@ { "name": "0x.js", - "version": "0.31.0", + "version": "0.31.1", "description": "A javascript library for interacting with the 0x protocol", - "keywords": ["0x.js", "0xproject", "ethereum", "tokens", "exchange"], + "keywords": [ + "0x.js", + "0xproject", + "ethereum", + "tokens", + "exchange" + ], "main": "lib/src/index.js", "types": "lib/src/index.d.ts", "scripts": { "prebuild": "run-s clean generate_contract_wrappers", "build": "run-p build:umd:prod build:commonjs; exit 0;", "docs:json": "typedoc --excludePrivate --excludeExternals --target ES5 --json $JSON_FILE_PATH $PROJECT_DIR", - "upload_docs_json": - "aws s3 cp generated_docs/index.json $S3_URL --profile 0xproject --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers --content-type application/json", - "generate_contract_wrappers": - "node ../abi-gen/lib/index.js --abis 'src/artifacts/@(Exchange|Token|TokenTransferProxy|EtherToken|TokenRegistry|DummyToken).json' --template contract_templates/contract.handlebars --partials 'contract_templates/partials/**/*.handlebars' --output src/contract_wrappers/generated", + "upload_docs_json": "aws s3 cp generated_docs/index.json $S3_URL --profile 0xproject --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers --content-type application/json", + "generate_contract_wrappers": "node ../abi-gen/lib/index.js --abis 'src/artifacts/@(Exchange|Token|TokenTransferProxy|EtherToken|TokenRegistry|DummyToken).json' --template contract_templates/contract.handlebars --partials 'contract_templates/partials/**/*.handlebars' --output src/contract_wrappers/generated", "lint": "tslint --project . 'src/**/*.ts' 'test/**/*.ts'", "test:circleci": "run-s test:coverage report_test_coverage", "test": "run-s clean test:commonjs", "test:coverage": "nyc npm run test --all", "report_test_coverage": "nyc report --reporter=text-lcov | coveralls", - "update_contracts": - "for i in ${npm_package_config_artifacts}; do copyfiles -u 4 ../contracts/build/contracts/$i.json ../0x.js/src/artifacts; done;", + "update_contracts": "for i in ${npm_package_config_artifacts}; do copyfiles -u 4 ../contracts/build/contracts/$i.json ../0x.js/src/artifacts; done;", "clean": "shx rm -rf _bundles lib test_temp", "build:umd:prod": "NODE_ENV=production webpack", "build:commonjs": "tsc && copyfiles -u 2 './src/artifacts/**/*.json' ./lib/src/artifacts;", @@ -38,9 +41,9 @@ "node": ">=6.0.0" }, "devDependencies": { - "@0xproject/abi-gen": "^0.1.5", - "@0xproject/dev-utils": "^0.0.8", - "@0xproject/tslint-config": "^0.4.5", + "@0xproject/abi-gen": "^0.1.6", + "@0xproject/dev-utils": "^0.0.9", + "@0xproject/tslint-config": "^0.4.6", "@types/bintrees": "^1.0.2", "@types/jsonschema": "^1.1.1", "@types/lodash": "^4.14.86", @@ -51,7 +54,7 @@ "awesome-typescript-loader": "^3.1.3", "chai": "^4.0.1", "chai-as-promised": "^7.1.0", - "chai-as-promised-typescript-typings": "^0.0.7", + "chai-as-promised-typescript-typings": "^0.0.8", "chai-bignumber": "^2.0.1", "chai-typescript-typings": "^0.0.2", "copyfiles": "^1.2.0", @@ -72,15 +75,15 @@ "typedoc": "~0.8.0", "typescript": "~2.6.1", "web3-provider-engine": "^13.0.1", - "web3-typescript-typings": "^0.9.7", + "web3-typescript-typings": "^0.9.8", "webpack": "^3.1.0" }, "dependencies": { - "@0xproject/assert": "^0.0.14", - "@0xproject/json-schemas": "^0.7.6", - "@0xproject/types": "^0.1.7", - "@0xproject/utils": "^0.2.3", - "@0xproject/web3-wrapper": "^0.1.8", + "@0xproject/assert": "^0.0.15", + "@0xproject/json-schemas": "^0.7.7", + "@0xproject/types": "^0.1.8", + "@0xproject/utils": "^0.2.4", + "@0xproject/web3-wrapper": "^0.1.9", "bintrees": "^1.0.2", "bn.js": "^4.11.8", "ethereumjs-abi": "^0.6.4", -- cgit