From d727bed6ab6fef90717a45845c544b409657e3c2 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Sat, 10 Jun 2017 15:36:52 +0200 Subject: Prefix private vars with _ --- src/0x.js.ts | 26 ++-- src/contract_wrappers/contract_wrapper.ts | 2 +- src/contract_wrappers/exchange_wrapper.ts | 183 ++++++++++++------------ src/contract_wrappers/token_registry_wrapper.ts | 18 +-- src/contract_wrappers/token_wrapper.ts | 30 ++-- test/0x.js_test.ts | 12 +- test/exchange_wrapper_test.ts | 4 +- 7 files changed, 138 insertions(+), 137 deletions(-) diff --git a/src/0x.js.ts b/src/0x.js.ts index b1e4e25ff..3a149ae6e 100644 --- a/src/0x.js.ts +++ b/src/0x.js.ts @@ -33,7 +33,7 @@ export class ZeroEx { public exchange: ExchangeWrapper; public tokenRegistry: TokenRegistryWrapper; public token: TokenWrapper; - private web3Wrapper: Web3Wrapper; + private _web3Wrapper: Web3Wrapper; /** * Verifies that the elliptic curve signature `signature` was generated * by signing `dataHex` with the private key corresponding to the `signerAddressHex` address. @@ -128,10 +128,10 @@ export class ZeroEx { * @return An instance of the 0x.js ZeroEx class. */ constructor(web3: Web3) { - this.web3Wrapper = new Web3Wrapper(web3); - this.token = new TokenWrapper(this.web3Wrapper); - this.exchange = new ExchangeWrapper(this.web3Wrapper, this.token); - this.tokenRegistry = new TokenRegistryWrapper(this.web3Wrapper); + this._web3Wrapper = new Web3Wrapper(web3); + this.token = new TokenWrapper(this._web3Wrapper); + this.exchange = new ExchangeWrapper(this._web3Wrapper, this.token); + this.tokenRegistry = new TokenRegistryWrapper(this._web3Wrapper); } /** * Sets a new provider for the web3 instance used by 0x.js. Updating the provider will stop all @@ -139,7 +139,7 @@ export class ZeroEx { * @param provider The Web3.Provider you would like the 0x.js library to use from now on. */ public async setProviderAsync(provider: Web3.Provider) { - this.web3Wrapper.setProvider(provider); + this._web3Wrapper.setProvider(provider); await this.exchange.invalidateContractInstanceAsync(); this.tokenRegistry.invalidateContractInstance(); this.token.invalidateContractInstances(); @@ -149,7 +149,7 @@ export class ZeroEx { * @return An array of Ethereum addresses available. */ public async getAvailableAddressesAsync(): Promise { - const availableAddresses = await this.web3Wrapper.getAvailableAddressesAsync(); + const availableAddresses = await this._web3Wrapper.getAvailableAddressesAsync(); return availableAddresses; } /** @@ -160,7 +160,7 @@ export class ZeroEx { public async getOrderHashHexAsync(order: Order|SignedOrder): Promise { assert.doesConformToSchema('order', order, orderSchema); - const exchangeContractAddr = await this.getExchangeAddressAsync(); + const exchangeContractAddr = await this._getExchangeAddressAsync(); const orderHashHex = utils.getOrderHashHex(order, exchangeContractAddr); return orderHashHex; } @@ -174,10 +174,10 @@ export class ZeroEx { */ public async signOrderHashAsync(orderHashHex: string, signerAddress: string): Promise { assert.isHexString('orderHashHex', orderHashHex); - await assert.isSenderAddressAsync('signerAddress', signerAddress, this.web3Wrapper); + await assert.isSenderAddressAsync('signerAddress', signerAddress, this._web3Wrapper); let msgHashHex; - const nodeVersion = await this.web3Wrapper.getNodeVersionAsync(); + const nodeVersion = await this._web3Wrapper.getNodeVersionAsync(); const isParityNode = utils.isParityNode(nodeVersion); if (isParityNode) { // Parity node adds the personalMessage prefix itself @@ -188,7 +188,7 @@ export class ZeroEx { msgHashHex = ethUtil.bufferToHex(msgHashBuff); } - const signature = await this.web3Wrapper.signTransactionAsync(signerAddress, msgHashHex); + const signature = await this._web3Wrapper.signTransactionAsync(signerAddress, msgHashHex); let signatureData; const [nodeVersionNumber] = findVersions(nodeVersion); @@ -224,8 +224,8 @@ export class ZeroEx { } return ecSignature; } - private async getExchangeAddressAsync() { - const networkIdIfExists = await this.web3Wrapper.getNetworkIdIfExistsAsync(); + private async _getExchangeAddressAsync() { + const networkIdIfExists = await this._web3Wrapper.getNetworkIdIfExistsAsync(); const exchangeNetworkConfigsIfExists = _.isUndefined(networkIdIfExists) ? undefined : (ExchangeArtifacts as any).networks[networkIdIfExists]; diff --git a/src/contract_wrappers/contract_wrapper.ts b/src/contract_wrappers/contract_wrapper.ts index c3067f613..99cfd97f0 100644 --- a/src/contract_wrappers/contract_wrapper.ts +++ b/src/contract_wrappers/contract_wrapper.ts @@ -9,7 +9,7 @@ export class ContractWrapper { constructor(web3Wrapper: Web3Wrapper) { this.web3Wrapper = web3Wrapper; } - protected async instantiateContractIfExistsAsync(artifact: Artifact, address?: string): Promise { + protected async _instantiateContractIfExistsAsync(artifact: Artifact, address?: string): Promise { const c = await contract(artifact); const providerObj = this.web3Wrapper.getCurrentProvider(); c.setProvider(providerObj); diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts index 76f86e464..d546a6102 100644 --- a/src/contract_wrappers/exchange_wrapper.ts +++ b/src/contract_wrappers/exchange_wrapper.ts @@ -37,7 +37,7 @@ import {constants} from '../utils/constants'; import {TokenWrapper} from './token_wrapper'; export class ExchangeWrapper extends ContractWrapper { - private exchangeContractErrCodesToMsg = { + private _exchangeContractErrCodesToMsg = { [ExchangeContractErrCodes.ERROR_FILL_EXPIRED]: ExchangeContractErrs.ORDER_FILL_EXPIRED, [ExchangeContractErrCodes.ERROR_CANCEL_EXPIRED]: ExchangeContractErrs.ORDER_FILL_EXPIRED, [ExchangeContractErrCodes.ERROR_FILL_NO_VALUE]: ExchangeContractErrs.ORDER_REMAINING_FILL_AMOUNT_ZERO, @@ -45,10 +45,10 @@ export class ExchangeWrapper extends ContractWrapper { [ExchangeContractErrCodes.ERROR_FILL_TRUNCATION]: ExchangeContractErrs.ORDER_FILL_ROUNDING_ERROR, [ExchangeContractErrCodes.ERROR_FILL_BALANCE_ALLOWANCE]: ExchangeContractErrs.FILL_BALANCE_ALLOWANCE_ERROR, }; - private exchangeContractIfExists?: ExchangeContract; - private exchangeLogEventObjs: ContractEventObj[]; - private tokenWrapper: TokenWrapper; - private static getOrderAddressesAndValues(order: Order): [OrderAddresses, OrderValues] { + private _exchangeContractIfExists?: ExchangeContract; + private _exchangeLogEventObjs: ContractEventObj[]; + private _tokenWrapper: TokenWrapper; + private static _getOrderAddressesAndValues(order: Order): [OrderAddresses, OrderValues] { const orderAddresses: OrderAddresses = [ order.maker, order.taker, @@ -68,12 +68,12 @@ export class ExchangeWrapper extends ContractWrapper { } constructor(web3Wrapper: Web3Wrapper, tokenWrapper: TokenWrapper) { super(web3Wrapper); - this.tokenWrapper = tokenWrapper; - this.exchangeLogEventObjs = []; + this._tokenWrapper = tokenWrapper; + this._exchangeLogEventObjs = []; } public async invalidateContractInstanceAsync(): Promise { - await this.stopWatchingExchangeLogEventsAsync(); - delete this.exchangeContractIfExists; + await this._stopWatchingExchangeLogEventsAsync(); + delete this._exchangeContractIfExists; } /** * Returns the unavailable takerAmount of an order. Unavailable amount is defined as the total @@ -86,7 +86,7 @@ export class ExchangeWrapper extends ContractWrapper { public async getUnavailableTakerAmountAsync(orderHashHex: string): Promise { assert.isValidOrderHash('orderHashHex', orderHashHex); - const exchangeContract = await this.getExchangeContractAsync(); + const exchangeContract = await this._getExchangeContractAsync(); let unavailableAmountInBaseUnits = await exchangeContract.getUnavailableValueT.call(orderHashHex); // Wrap BigNumbers returned from web3 with our own (later) version of BigNumber unavailableAmountInBaseUnits = new BigNumber(unavailableAmountInBaseUnits); @@ -100,7 +100,7 @@ export class ExchangeWrapper extends ContractWrapper { public async getFilledTakerAmountAsync(orderHashHex: string): Promise { assert.isValidOrderHash('orderHashHex', orderHashHex); - const exchangeContract = await this.getExchangeContractAsync(); + const exchangeContract = await this._getExchangeContractAsync(); let fillAmountInBaseUnits = await exchangeContract.filled.call(orderHashHex); // Wrap BigNumbers returned from web3 with our own (later) version of BigNumber fillAmountInBaseUnits = new BigNumber(fillAmountInBaseUnits); @@ -115,7 +115,7 @@ export class ExchangeWrapper extends ContractWrapper { public async getCanceledTakerAmountAsync(orderHashHex: string): Promise { assert.isValidOrderHash('orderHashHex', orderHashHex); - const exchangeContract = await this.getExchangeContractAsync(); + const exchangeContract = await this._getExchangeContractAsync(); let cancelledAmountInBaseUnits = await exchangeContract.cancelled.call(orderHashHex); // Wrap BigNumbers returned from web3 with our own (later) version of BigNumber cancelledAmountInBaseUnits = new BigNumber(cancelledAmountInBaseUnits); @@ -142,10 +142,10 @@ export class ExchangeWrapper extends ContractWrapper { assert.isBoolean('shouldCheckTransfer', shouldCheckTransfer); await assert.isSenderAddressAsync('takerAddress', takerAddress, this.web3Wrapper); - const exchangeInstance = await this.getExchangeContractAsync(); - await this.validateFillOrderAndThrowIfInvalidAsync(signedOrder, takerTokenFillAmount, takerAddress); + const exchangeInstance = await this._getExchangeContractAsync(); + await this._validateFillOrderAndThrowIfInvalidAsync(signedOrder, takerTokenFillAmount, takerAddress); - const [orderAddresses, orderValues] = ExchangeWrapper.getOrderAddressesAndValues(signedOrder); + const [orderAddresses, orderValues] = ExchangeWrapper._getOrderAddressesAndValues(signedOrder); const gas = await exchangeInstance.fill.estimateGas( orderAddresses, @@ -172,7 +172,7 @@ export class ExchangeWrapper extends ContractWrapper { gas, }, ); - this.throwErrorLogsAsErrors(response.logs); + this._throwErrorLogsAsErrors(response.logs); } /** * Sequentially and atomically fills signedOrders up to the specified takerTokenFillAmount. @@ -198,7 +198,7 @@ export class ExchangeWrapper extends ContractWrapper { assert.doesConformToSchema('signedOrders', signedOrders, signedOrdersSchema); await assert.isSenderAddressAsync('takerAddress', takerAddress, this.web3Wrapper); for (const signedOrder of signedOrders) { - await this.validateFillOrderAndThrowIfInvalidAsync( + await this._validateFillOrderAndThrowIfInvalidAsync( signedOrder, takerTokenFillAmount, takerAddress); } if (_.isEmpty(signedOrders)) { @@ -207,7 +207,7 @@ export class ExchangeWrapper extends ContractWrapper { const orderAddressesValuesAndSignatureArray = _.map(signedOrders, signedOrder => { return [ - ...ExchangeWrapper.getOrderAddressesAndValues(signedOrder), + ...ExchangeWrapper._getOrderAddressesAndValues(signedOrder), signedOrder.ecSignature.v, signedOrder.ecSignature.r, signedOrder.ecSignature.s, @@ -218,7 +218,7 @@ export class ExchangeWrapper extends ContractWrapper { orderAddressesValuesAndSignatureArray, ); - const exchangeInstance = await this.getExchangeContractAsync(); + const exchangeInstance = await this._getExchangeContractAsync(); const gas = await exchangeInstance.fillUpTo.estimateGas( orderAddressesArray, orderValuesArray, @@ -244,7 +244,7 @@ export class ExchangeWrapper extends ContractWrapper { gas, }, ); - this.throwErrorLogsAsErrors(response.logs); + this._throwErrorLogsAsErrors(response.logs); } /** * Batch version of fillOrderAsync. @@ -265,7 +265,7 @@ export class ExchangeWrapper extends ContractWrapper { await assert.isSenderAddressAsync('takerAddress', takerAddress, this.web3Wrapper); assert.doesConformToSchema('orderFillRequests', orderFillRequests, orderFillRequestsSchema); for (const orderFillRequest of orderFillRequests) { - await this.validateFillOrderAndThrowIfInvalidAsync( + await this._validateFillOrderAndThrowIfInvalidAsync( orderFillRequest.signedOrder, orderFillRequest.takerTokenFillAmount, takerAddress); } if (_.isEmpty(orderFillRequests)) { @@ -274,7 +274,7 @@ export class ExchangeWrapper extends ContractWrapper { const orderAddressesValuesAmountsAndSignatureArray = _.map(orderFillRequests, orderFillRequest => { return [ - ...ExchangeWrapper.getOrderAddressesAndValues(orderFillRequest.signedOrder), + ...ExchangeWrapper._getOrderAddressesAndValues(orderFillRequest.signedOrder), orderFillRequest.takerTokenFillAmount, orderFillRequest.signedOrder.ecSignature.v, orderFillRequest.signedOrder.ecSignature.r, @@ -286,7 +286,7 @@ export class ExchangeWrapper extends ContractWrapper { orderAddressesValuesAmountsAndSignatureArray, ); - const exchangeInstance = await this.getExchangeContractAsync(); + const exchangeInstance = await this._getExchangeContractAsync(); const gas = await exchangeInstance.batchFill.estimateGas( orderAddressesArray, orderValuesArray, @@ -312,7 +312,7 @@ export class ExchangeWrapper extends ContractWrapper { gas, }, ); - this.throwErrorLogsAsErrors(response.logs); + this._throwErrorLogsAsErrors(response.logs); } /** * Attempts to fill a specific amount of an order. If the entire amount specified cannot be filled, @@ -329,13 +329,13 @@ export class ExchangeWrapper extends ContractWrapper { assert.isBigNumber('takerTokenFillAmount', takerTokenFillAmount); await assert.isSenderAddressAsync('takerAddress', takerAddress, this.web3Wrapper); - const exchangeInstance = await this.getExchangeContractAsync(); - await this.validateFillOrderAndThrowIfInvalidAsync(signedOrder, takerTokenFillAmount, takerAddress); + const exchangeInstance = await this._getExchangeContractAsync(); + await this._validateFillOrderAndThrowIfInvalidAsync(signedOrder, takerTokenFillAmount, takerAddress); - await this.validateFillOrKillOrderAndThrowIfInvalidAsync(signedOrder, exchangeInstance.address, + await this._validateFillOrKillOrderAndThrowIfInvalidAsync(signedOrder, exchangeInstance.address, takerTokenFillAmount); - const [orderAddresses, orderValues] = ExchangeWrapper.getOrderAddressesAndValues(signedOrder); + const [orderAddresses, orderValues] = ExchangeWrapper._getOrderAddressesAndValues(signedOrder); const gas = await exchangeInstance.fillOrKill.estimateGas( orderAddresses, @@ -360,7 +360,7 @@ export class ExchangeWrapper extends ContractWrapper { gas, }, ); - this.throwErrorLogsAsErrors(response.logs); + this._throwErrorLogsAsErrors(response.logs); } /** * Batch version of fillOrKill. Allows a taker to specify a batch of orders that will either be atomically @@ -373,15 +373,15 @@ export class ExchangeWrapper extends ContractWrapper { takerAddress: string): Promise { await assert.isSenderAddressAsync('takerAddress', takerAddress, this.web3Wrapper); assert.doesConformToSchema('orderFillOrKillRequests', orderFillOrKillRequests, orderFillOrKillRequestsSchema); - const exchangeInstance = await this.getExchangeContractAsync(); + const exchangeInstance = await this._getExchangeContractAsync(); for (const request of orderFillOrKillRequests) { - await this.validateFillOrKillOrderAndThrowIfInvalidAsync(request.signedOrder, exchangeInstance.address, + await this._validateFillOrKillOrderAndThrowIfInvalidAsync(request.signedOrder, exchangeInstance.address, request.fillTakerAmount); } const orderAddressesValuesAndTakerTokenFillAmounts = _.map(orderFillOrKillRequests, request => { return [ - ...ExchangeWrapper.getOrderAddressesAndValues(request.signedOrder), + ...ExchangeWrapper._getOrderAddressesAndValues(request.signedOrder), request.fillTakerAmount, request.signedOrder.ecSignature.v, request.signedOrder.ecSignature.r, @@ -416,7 +416,7 @@ export class ExchangeWrapper extends ContractWrapper { gas, }, ); - this.throwErrorLogsAsErrors(response.logs); + this._throwErrorLogsAsErrors(response.logs); } /** * Cancel a given fill amount of an order. Cancellations are cumulative. @@ -430,10 +430,10 @@ export class ExchangeWrapper extends ContractWrapper { assert.isBigNumber('takerTokenCancelAmount', takerTokenCancelAmount); await assert.isSenderAddressAsync('order.maker', order.maker, this.web3Wrapper); - const exchangeInstance = await this.getExchangeContractAsync(); - await this.validateCancelOrderAndThrowIfInvalidAsync(order, takerTokenCancelAmount); + const exchangeInstance = await this._getExchangeContractAsync(); + await this._validateCancelOrderAndThrowIfInvalidAsync(order, takerTokenCancelAmount); - const [orderAddresses, orderValues] = ExchangeWrapper.getOrderAddressesAndValues(order); + const [orderAddresses, orderValues] = ExchangeWrapper._getOrderAddressesAndValues(order); const gas = await exchangeInstance.cancel.estimateGas( orderAddresses, orderValues, @@ -451,7 +451,7 @@ export class ExchangeWrapper extends ContractWrapper { gas, }, ); - this.throwErrorLogsAsErrors(response.logs); + this._throwErrorLogsAsErrors(response.logs); } /** * Batch version of cancelOrderAsync. Atomically cancels multiple orders in a single transaction. @@ -467,17 +467,17 @@ export class ExchangeWrapper extends ContractWrapper { assert.doesConformToSchema('orderCancellationRequests', orderCancellationRequests, orderCancellationRequestsSchema); for (const cancellationRequest of orderCancellationRequests) { - await this.validateCancelOrderAndThrowIfInvalidAsync( + await this._validateCancelOrderAndThrowIfInvalidAsync( cancellationRequest.order, cancellationRequest.takerTokenCancelAmount, ); } if (_.isEmpty(orderCancellationRequests)) { return; // no-op } - const exchangeInstance = await this.getExchangeContractAsync(); + const exchangeInstance = await this._getExchangeContractAsync(); const orderAddressesValuesAndTakerTokenCancelAmounts = _.map(orderCancellationRequests, cancellationRequest => { return [ - ...ExchangeWrapper.getOrderAddressesAndValues(cancellationRequest.order), + ...ExchangeWrapper._getOrderAddressesAndValues(cancellationRequest.order), cancellationRequest.takerTokenCancelAmount, ]; }); @@ -501,7 +501,7 @@ export class ExchangeWrapper extends ContractWrapper { gas, }, ); - this.throwErrorLogsAsErrors(response.logs); + this._throwErrorLogsAsErrors(response.logs); } /** * Subscribe to an event type emitted by the Exchange smart contract @@ -514,7 +514,7 @@ export class ExchangeWrapper extends ContractWrapper { public async subscribeAsync(eventName: ExchangeEvents, subscriptionOpts: SubscriptionOpts, indexFilterValues: IndexFilterValues, callback: EventCallback): Promise { - const exchangeContract = await this.getExchangeContractAsync(); + const exchangeContract = await this._getExchangeContractAsync(); let createLogEvent: CreateContractEvent; switch (eventName) { case ExchangeEvents.LogFill: @@ -533,15 +533,15 @@ export class ExchangeWrapper extends ContractWrapper { const logEventObj: ContractEventObj = createLogEvent(indexFilterValues, subscriptionOpts); logEventObj.watch(callback); - this.exchangeLogEventObjs.push(logEventObj); + this._exchangeLogEventObjs.push(logEventObj); } - private async isValidSignatureUsingContractCallAsync(dataHex: string, ecSignature: ECSignature, - signerAddressHex: string): Promise { + private async _isValidSignatureUsingContractCallAsync(dataHex: string, ecSignature: ECSignature, + signerAddressHex: string): Promise { assert.isHexString('dataHex', dataHex); assert.doesConformToSchema('ecSignature', ecSignature, ecSignatureSchema); assert.isETHAddressHex('signerAddressHex', signerAddressHex); - const exchangeInstance = await this.getExchangeContractAsync(); + const exchangeInstance = await this._getExchangeContractAsync(); const isValidSignature = await exchangeInstance.isValidSignature.call( signerAddressHex, @@ -552,27 +552,27 @@ export class ExchangeWrapper extends ContractWrapper { ); return isValidSignature; } - private async getOrderHashHexAsync(order: Order|SignedOrder): Promise { - const exchangeInstance = await this.getExchangeContractAsync(); + private async _getOrderHashHexAsync(order: Order|SignedOrder): Promise { + const exchangeInstance = await this._getExchangeContractAsync(); const orderHashHex = utils.getOrderHashHex(order, exchangeInstance.address); return orderHashHex; } - private async getOrderHashHexUsingContractCallAsync(order: Order|SignedOrder): Promise { - const exchangeInstance = await this.getExchangeContractAsync(); - const [orderAddresses, orderValues] = ExchangeWrapper.getOrderAddressesAndValues(order); + private async _getOrderHashHexUsingContractCallAsync(order: Order|SignedOrder): Promise { + const exchangeInstance = await this._getExchangeContractAsync(); + const [orderAddresses, orderValues] = ExchangeWrapper._getOrderAddressesAndValues(order); const orderHashHex = await exchangeInstance.getOrderHash.call(orderAddresses, orderValues); return orderHashHex; } - private async stopWatchingExchangeLogEventsAsync() { - const stopWatchingPromises = _.map(this.exchangeLogEventObjs, logEventObj => { + private async _stopWatchingExchangeLogEventsAsync() { + const stopWatchingPromises = _.map(this._exchangeLogEventObjs, logEventObj => { return promisify(logEventObj.stopWatching, logEventObj)(); }); await Promise.all(stopWatchingPromises); - this.exchangeLogEventObjs = []; + this._exchangeLogEventObjs = []; } - private async validateFillOrderAndThrowIfInvalidAsync(signedOrder: SignedOrder, - fillTakerAmount: BigNumber.BigNumber, - senderAddress: string): Promise { + private async _validateFillOrderAndThrowIfInvalidAsync(signedOrder: SignedOrder, + fillTakerAmount: BigNumber.BigNumber, + senderAddress: string): Promise { if (fillTakerAmount.eq(0)) { throw new Error(ExchangeContractErrs.ORDER_REMAINING_FILL_AMOUNT_ZERO); } @@ -583,23 +583,23 @@ export class ExchangeWrapper extends ContractWrapper { if (signedOrder.expirationUnixTimestampSec.lessThan(currentUnixTimestampSec)) { throw new Error(ExchangeContractErrs.ORDER_FILL_EXPIRED); } - const zrxTokenAddress = await this.getZRXTokenAddressAsync(); - await this.validateFillOrderBalancesAndAllowancesAndThrowIfInvalidAsync(signedOrder, fillTakerAmount, + const zrxTokenAddress = await this._getZRXTokenAddressAsync(); + await this._validateFillOrderBalancesAndAllowancesAndThrowIfInvalidAsync(signedOrder, fillTakerAmount, senderAddress, zrxTokenAddress); - const wouldRoundingErrorOccur = await this.isRoundingErrorAsync( + const wouldRoundingErrorOccur = await this._isRoundingErrorAsync( signedOrder.takerTokenAmount, fillTakerAmount, signedOrder.makerTokenAmount, ); if (wouldRoundingErrorOccur) { throw new Error(ExchangeContractErrs.ORDER_FILL_ROUNDING_ERROR); } } - private async validateCancelOrderAndThrowIfInvalidAsync( + private async _validateCancelOrderAndThrowIfInvalidAsync( order: Order, takerTokenCancelAmount: BigNumber.BigNumber): Promise { if (takerTokenCancelAmount.eq(0)) { throw new Error(ExchangeContractErrs.ORDER_CANCEL_AMOUNT_ZERO); } - const orderHash = await this.getOrderHashHexAsync(order); + const orderHash = await this._getOrderHashHexAsync(order); const unavailableAmount = await this.getUnavailableTakerAmountAsync(orderHash); if (order.takerTokenAmount.minus(unavailableAmount).eq(0)) { throw new Error(ExchangeContractErrs.ORDER_ALREADY_CANCELLED_OR_FILLED); @@ -609,9 +609,9 @@ export class ExchangeWrapper extends ContractWrapper { throw new Error(ExchangeContractErrs.ORDER_CANCEL_EXPIRED); } } - private async validateFillOrKillOrderAndThrowIfInvalidAsync(signedOrder: SignedOrder, - exchangeAddress: string, - fillTakerAmount: BigNumber.BigNumber) { + private async _validateFillOrKillOrderAndThrowIfInvalidAsync(signedOrder: SignedOrder, + exchangeAddress: string, + fillTakerAmount: BigNumber.BigNumber) { // Check that fillValue available >= fillTakerAmount const orderHashHex = utils.getOrderHashHex(signedOrder, exchangeAddress); const unavailableTakerAmount = await this.getUnavailableTakerAmountAsync(orderHashHex); @@ -629,17 +629,18 @@ export class ExchangeWrapper extends ContractWrapper { * TODO: Throw errors before calling the smart contract for these edge-cases in order to minimize * the callers gas costs. */ - private async validateFillOrderBalancesAndAllowancesAndThrowIfInvalidAsync(signedOrder: SignedOrder, - fillTakerAmount: BigNumber.BigNumber, - senderAddress: string, - zrxTokenAddress: string): Promise { + private async _validateFillOrderBalancesAndAllowancesAndThrowIfInvalidAsync(signedOrder: SignedOrder, + fillTakerAmount: BigNumber.BigNumber, + senderAddress: string, + zrxTokenAddress: string, + ): Promise { - const makerBalance = await this.tokenWrapper.getBalanceAsync(signedOrder.makerTokenAddress, + const makerBalance = await this._tokenWrapper.getBalanceAsync(signedOrder.makerTokenAddress, signedOrder.maker); - const takerBalance = await this.tokenWrapper.getBalanceAsync(signedOrder.takerTokenAddress, senderAddress); - const makerAllowance = await this.tokenWrapper.getProxyAllowanceAsync(signedOrder.makerTokenAddress, + const takerBalance = await this._tokenWrapper.getBalanceAsync(signedOrder.takerTokenAddress, senderAddress); + const makerAllowance = await this._tokenWrapper.getProxyAllowanceAsync(signedOrder.makerTokenAddress, signedOrder.maker); - const takerAllowance = await this.tokenWrapper.getProxyAllowanceAsync(signedOrder.takerTokenAddress, + const takerAllowance = await this._tokenWrapper.getProxyAllowanceAsync(signedOrder.takerTokenAddress, senderAddress); // exchangeRate is the price of one maker token denominated in taker tokens @@ -659,12 +660,12 @@ export class ExchangeWrapper extends ContractWrapper { throw new Error(ExchangeContractErrs.INSUFFICIENT_MAKER_ALLOWANCE); } - const makerFeeBalance = await this.tokenWrapper.getBalanceAsync(zrxTokenAddress, + const makerFeeBalance = await this._tokenWrapper.getBalanceAsync(zrxTokenAddress, signedOrder.maker); - const takerFeeBalance = await this.tokenWrapper.getBalanceAsync(zrxTokenAddress, senderAddress); - const makerFeeAllowance = await this.tokenWrapper.getProxyAllowanceAsync(zrxTokenAddress, + const takerFeeBalance = await this._tokenWrapper.getBalanceAsync(zrxTokenAddress, senderAddress); + const makerFeeAllowance = await this._tokenWrapper.getProxyAllowanceAsync(zrxTokenAddress, signedOrder.maker); - const takerFeeAllowance = await this.tokenWrapper.getProxyAllowanceAsync(zrxTokenAddress, + const takerFeeAllowance = await this._tokenWrapper.getProxyAllowanceAsync(zrxTokenAddress, senderAddress); if (signedOrder.takerFee.greaterThan(takerFeeBalance)) { @@ -680,34 +681,34 @@ export class ExchangeWrapper extends ContractWrapper { throw new Error(ExchangeContractErrs.INSUFFICIENT_MAKER_FEE_ALLOWANCE); } } - private throwErrorLogsAsErrors(logs: ContractEvent[]): void { + private _throwErrorLogsAsErrors(logs: ContractEvent[]): void { const errEvent = _.find(logs, {event: 'LogError'}); if (!_.isUndefined(errEvent)) { const errCode = errEvent.args.errorId.toNumber(); - const errMessage = this.exchangeContractErrCodesToMsg[errCode]; + const errMessage = this._exchangeContractErrCodesToMsg[errCode]; throw new Error(errMessage); } } - private async isRoundingErrorAsync(takerTokenAmount: BigNumber.BigNumber, - fillTakerAmount: BigNumber.BigNumber, - makerTokenAmount: BigNumber.BigNumber): Promise { + private async _isRoundingErrorAsync(takerTokenAmount: BigNumber.BigNumber, + fillTakerAmount: BigNumber.BigNumber, + makerTokenAmount: BigNumber.BigNumber): Promise { await assert.isUserAddressAvailableAsync(this.web3Wrapper); - const exchangeInstance = await this.getExchangeContractAsync(); + const exchangeInstance = await this._getExchangeContractAsync(); const isRoundingError = await exchangeInstance.isRoundingError.call( takerTokenAmount, fillTakerAmount, makerTokenAmount, ); return isRoundingError; } - private async getExchangeContractAsync(): Promise { - if (!_.isUndefined(this.exchangeContractIfExists)) { - return this.exchangeContractIfExists; + private async _getExchangeContractAsync(): Promise { + if (!_.isUndefined(this._exchangeContractIfExists)) { + return this._exchangeContractIfExists; } - const contractInstance = await this.instantiateContractIfExistsAsync((ExchangeArtifacts as any)); - this.exchangeContractIfExists = contractInstance as ExchangeContract; - return this.exchangeContractIfExists; + const contractInstance = await this._instantiateContractIfExistsAsync((ExchangeArtifacts as any)); + this._exchangeContractIfExists = contractInstance as ExchangeContract; + return this._exchangeContractIfExists; } - private async getZRXTokenAddressAsync(): Promise { - const exchangeInstance = await this.getExchangeContractAsync(); + private async _getZRXTokenAddressAsync(): Promise { + const exchangeInstance = await this._getExchangeContractAsync(); return exchangeInstance.ZRX.call(); } } diff --git a/src/contract_wrappers/token_registry_wrapper.ts b/src/contract_wrappers/token_registry_wrapper.ts index 96346a7a4..ab0218777 100644 --- a/src/contract_wrappers/token_registry_wrapper.ts +++ b/src/contract_wrappers/token_registry_wrapper.ts @@ -6,19 +6,19 @@ import {ContractWrapper} from './contract_wrapper'; import * as TokenRegistryArtifacts from '../artifacts/TokenRegistry.json'; export class TokenRegistryWrapper extends ContractWrapper { - private tokenRegistryContractIfExists?: TokenRegistryContract; + private _tokenRegistryContractIfExists?: TokenRegistryContract; constructor(web3Wrapper: Web3Wrapper) { super(web3Wrapper); } public invalidateContractInstance(): void { - delete this.tokenRegistryContractIfExists; + delete this._tokenRegistryContractIfExists; } /** * Retrieves all the tokens currently listed in the Token Registry smart contract * @return An array of JS objects that conform to the Token interface. */ public async getTokensAsync(): Promise { - const tokenRegistryContract = await this.getTokenRegistryContractAsync(); + const tokenRegistryContract = await this._getTokenRegistryContractAsync(); const addresses = await tokenRegistryContract.getTokenAddresses.call(); const tokenMetadataPromises: Array> = _.map( @@ -37,12 +37,12 @@ export class TokenRegistryWrapper extends ContractWrapper { }); return tokens; } - private async getTokenRegistryContractAsync(): Promise { - if (!_.isUndefined(this.tokenRegistryContractIfExists)) { - return this.tokenRegistryContractIfExists; + private async _getTokenRegistryContractAsync(): Promise { + if (!_.isUndefined(this._tokenRegistryContractIfExists)) { + return this._tokenRegistryContractIfExists; } - const contractInstance = await this.instantiateContractIfExistsAsync((TokenRegistryArtifacts as any)); - this.tokenRegistryContractIfExists = contractInstance as TokenRegistryContract; - return this.tokenRegistryContractIfExists; + const contractInstance = await this._instantiateContractIfExistsAsync((TokenRegistryArtifacts as any)); + this._tokenRegistryContractIfExists = contractInstance as TokenRegistryContract; + return this._tokenRegistryContractIfExists; } } diff --git a/src/contract_wrappers/token_wrapper.ts b/src/contract_wrappers/token_wrapper.ts index bb79cac47..b0101c0da 100644 --- a/src/contract_wrappers/token_wrapper.ts +++ b/src/contract_wrappers/token_wrapper.ts @@ -11,13 +11,13 @@ import {TokenContract, ZeroExError} from '../types'; const ALLOWANCE_TO_ZERO_GAS_AMOUNT = 45730; export class TokenWrapper extends ContractWrapper { - private tokenContractsByAddress: {[address: string]: TokenContract}; + private _tokenContractsByAddress: {[address: string]: TokenContract}; constructor(web3Wrapper: Web3Wrapper) { super(web3Wrapper); - this.tokenContractsByAddress = {}; + this._tokenContractsByAddress = {}; } public invalidateContractInstances() { - this.tokenContractsByAddress = {}; + this._tokenContractsByAddress = {}; } /** * Retrieves an owner's ERC20 token balance. @@ -29,7 +29,7 @@ export class TokenWrapper extends ContractWrapper { assert.isETHAddressHex('tokenAddress', tokenAddress); await assert.isUserAddressAvailableAsync(this.web3Wrapper); - const tokenContract = await this.getTokenContractAsync(tokenAddress); + const tokenContract = await this._getTokenContractAsync(tokenAddress); let balance = await tokenContract.balanceOf.call(ownerAddress); // Wrap BigNumbers returned from web3 with our own (later) version of BigNumber balance = new BigNumber(balance); @@ -51,7 +51,7 @@ export class TokenWrapper extends ContractWrapper { assert.isETHAddressHex('tokenAddress', tokenAddress); assert.isBigNumber('amountInBaseUnits', amountInBaseUnits); - const tokenContract = await this.getTokenContractAsync(tokenAddress); + const tokenContract = await this._getTokenContractAsync(tokenAddress); // Hack: for some reason default estimated gas amount causes `base fee exceeds gas limit` exception // on testrpc. Probably related to https://github.com/ethereumjs/testrpc/issues/294 // TODO: Debug issue in testrpc and submit a PR, then remove this hack @@ -74,7 +74,7 @@ export class TokenWrapper extends ContractWrapper { assert.isETHAddressHex('tokenAddress', tokenAddress); await assert.isUserAddressAvailableAsync(this.web3Wrapper); - const tokenContract = await this.getTokenContractAsync(tokenAddress); + const tokenContract = await this._getTokenContractAsync(tokenAddress); let allowanceInBaseUnits = await tokenContract.allowance.call(ownerAddress, spenderAddress); // Wrap BigNumbers returned from web3 with our own (later) version of BigNumber allowanceInBaseUnits = new BigNumber(allowanceInBaseUnits); @@ -89,7 +89,7 @@ export class TokenWrapper extends ContractWrapper { assert.isETHAddressHex('ownerAddress', ownerAddress); assert.isETHAddressHex('tokenAddress', tokenAddress); - const proxyAddress = await this.getProxyAddressAsync(); + const proxyAddress = await this._getProxyAddressAsync(); const allowanceInBaseUnits = await this.getAllowanceAsync(tokenAddress, ownerAddress, proxyAddress); return allowanceInBaseUnits; } @@ -107,7 +107,7 @@ export class TokenWrapper extends ContractWrapper { assert.isETHAddressHex('tokenAddress', tokenAddress); assert.isBigNumber('amountInBaseUnits', amountInBaseUnits); - const proxyAddress = await this.getProxyAddressAsync(); + const proxyAddress = await this._getProxyAddressAsync(); await this.setAllowanceAsync(tokenAddress, ownerAddress, proxyAddress, amountInBaseUnits); } /** @@ -124,7 +124,7 @@ export class TokenWrapper extends ContractWrapper { assert.isETHAddressHex('toAddress', toAddress); assert.isBigNumber('amountInBaseUnits', amountInBaseUnits); - const tokenContract = await this.getTokenContractAsync(tokenAddress); + const tokenContract = await this._getTokenContractAsync(tokenAddress); const fromAddressBalance = await this.getBalanceAsync(tokenAddress, fromAddress); if (fromAddressBalance.lessThan(amountInBaseUnits)) { @@ -155,7 +155,7 @@ export class TokenWrapper extends ContractWrapper { await assert.isSenderAddressAsync('senderAddress', senderAddress, this.web3Wrapper); assert.isBigNumber('amountInBaseUnits', amountInBaseUnits); - const tokenContract = await this.getTokenContractAsync(tokenAddress); + const tokenContract = await this._getTokenContractAsync(tokenAddress); const fromAddressAllowance = await this.getAllowanceAsync(tokenAddress, fromAddress, senderAddress); if (fromAddressAllowance.lessThan(amountInBaseUnits)) { @@ -171,17 +171,17 @@ export class TokenWrapper extends ContractWrapper { from: senderAddress, }); } - private async getTokenContractAsync(tokenAddress: string): Promise { - let tokenContract = this.tokenContractsByAddress[tokenAddress]; + private async _getTokenContractAsync(tokenAddress: string): Promise { + let tokenContract = this._tokenContractsByAddress[tokenAddress]; if (!_.isUndefined(tokenContract)) { return tokenContract; } - const contractInstance = await this.instantiateContractIfExistsAsync((TokenArtifacts as any), tokenAddress); + const contractInstance = await this._instantiateContractIfExistsAsync((TokenArtifacts as any), tokenAddress); tokenContract = contractInstance as TokenContract; - this.tokenContractsByAddress[tokenAddress] = tokenContract; + this._tokenContractsByAddress[tokenAddress] = tokenContract; return tokenContract; } - private async getProxyAddressAsync() { + private async _getProxyAddressAsync() { const networkIdIfExists = await this.web3Wrapper.getNetworkIdIfExistsAsync(); const proxyNetworkConfigsIfExists = _.isUndefined(networkIdIfExists) ? undefined : diff --git a/test/0x.js_test.ts b/test/0x.js_test.ts index 1349d6360..3a1f8514e 100644 --- a/test/0x.js_test.ts +++ b/test/0x.js_test.ts @@ -19,8 +19,8 @@ describe('ZeroEx library', () => { const web3 = web3Factory.create(); const zeroEx = new ZeroEx(web3); // Instantiate the contract instances with the current provider - await (zeroEx.exchange as any).getExchangeContractAsync(); - await (zeroEx.tokenRegistry as any).getTokenRegistryContractAsync(); + await (zeroEx.exchange as any)._getExchangeContractAsync(); + await (zeroEx.tokenRegistry as any)._getTokenRegistryContractAsync(); expect((zeroEx.exchange as any).exchangeContractIfExists).to.not.be.undefined(); expect((zeroEx.tokenRegistry as any).tokenRegistryContractIfExists).to.not.be.undefined(); @@ -57,14 +57,14 @@ describe('ZeroEx library', () => { it('should return false if the data doesn\'t pertain to the signature & address', async () => { expect(ZeroEx.isValidSignature('0x0', signature, address)).to.be.false(); return expect( - (zeroEx.exchange as any).isValidSignatureUsingContractCallAsync('0x0', signature, address), + (zeroEx.exchange as any)._isValidSignatureUsingContractCallAsync('0x0', signature, address), ).to.become(false); }); it('should return false if the address doesn\'t pertain to the signature & data', async () => { const validUnrelatedAddress = '0x8b0292B11a196601eD2ce54B665CaFEca0347D42'; expect(ZeroEx.isValidSignature(dataHex, signature, validUnrelatedAddress)).to.be.false(); return expect( - (zeroEx.exchange as any).isValidSignatureUsingContractCallAsync(dataHex, signature, + (zeroEx.exchange as any)._isValidSignatureUsingContractCallAsync(dataHex, signature, validUnrelatedAddress), ).to.become(false); }); @@ -72,14 +72,14 @@ describe('ZeroEx library', () => { const wrongSignature = _.assign({}, signature, {v: 28}); expect(ZeroEx.isValidSignature(dataHex, wrongSignature, address)).to.be.false(); return expect( - (zeroEx.exchange as any).isValidSignatureUsingContractCallAsync(dataHex, wrongSignature, address), + (zeroEx.exchange as any)._isValidSignatureUsingContractCallAsync(dataHex, wrongSignature, address), ).to.become(false); }); it('should return true if the signature does pertain to the dataHex & address', async () => { const isValidSignatureLocal = ZeroEx.isValidSignature(dataHex, signature, address); expect(isValidSignatureLocal).to.be.true(); const isValidSignatureOnContract = await (zeroEx.exchange as any) - .isValidSignatureUsingContractCallAsync(dataHex, signature, address); + ._isValidSignatureUsingContractCallAsync(dataHex, signature, address); return expect(isValidSignatureOnContract).to.be.true(); }); }); diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts index 1b97d7b05..633fa3c5d 100644 --- a/test/exchange_wrapper_test.ts +++ b/test/exchange_wrapper_test.ts @@ -618,7 +618,7 @@ describe('ExchangeWrapper', () => { ); }); afterEach(async () => { - await (zeroEx.exchange as any).stopWatchingExchangeLogEventsAsync(); + await (zeroEx.exchange as any)._stopWatchingExchangeLogEventsAsync(); }); // 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 `subscribeAsync` callback, @@ -705,7 +705,7 @@ describe('ExchangeWrapper', () => { ); const orderHash = await zeroEx.getOrderHashHexAsync(signedOrder); const orderHashFromContract = await (zeroEx.exchange as any) - .getOrderHashHexUsingContractCallAsync(signedOrder); + ._getOrderHashHexUsingContractCallAsync(signedOrder); expect(orderHash).to.equal(orderHashFromContract); }); }); -- cgit v1.2.3 From fad23af55e997eea764f1d4e8e698c0ace3c351b Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Sat, 10 Jun 2017 16:07:03 +0200 Subject: Fix some tests --- test/0x.js_test.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/test/0x.js_test.ts b/test/0x.js_test.ts index 3a1f8514e..346ef69f8 100644 --- a/test/0x.js_test.ts +++ b/test/0x.js_test.ts @@ -21,8 +21,8 @@ describe('ZeroEx library', () => { // Instantiate the contract instances with the current provider await (zeroEx.exchange as any)._getExchangeContractAsync(); await (zeroEx.tokenRegistry as any)._getTokenRegistryContractAsync(); - expect((zeroEx.exchange as any).exchangeContractIfExists).to.not.be.undefined(); - expect((zeroEx.tokenRegistry as any).tokenRegistryContractIfExists).to.not.be.undefined(); + expect((zeroEx.exchange as any)._exchangeContractIfExists).to.not.be.undefined(); + expect((zeroEx.tokenRegistry as any)._tokenRegistryContractIfExists).to.not.be.undefined(); const newProvider = web3Factory.getRpcProvider(); // Add property to newProvider so that we can differentiate it from old provider @@ -30,15 +30,15 @@ describe('ZeroEx library', () => { await zeroEx.setProviderAsync(newProvider); // Check that contractInstances with old provider are removed after provider update - expect((zeroEx.exchange as any).exchangeContractIfExists).to.be.undefined(); - expect((zeroEx.tokenRegistry as any).tokenRegistryContractIfExists).to.be.undefined(); + expect((zeroEx.exchange as any)._exchangeContractIfExists).to.be.undefined(); + expect((zeroEx.tokenRegistry as any)._tokenRegistryContractIfExists).to.be.undefined(); // Check that all nested web3 instances return the updated provider - const nestedWeb3WrapperProvider = (zeroEx as any).web3Wrapper.getCurrentProvider(); + const nestedWeb3WrapperProvider = (zeroEx as any)._web3Wrapper.getCurrentProvider(); expect((nestedWeb3WrapperProvider as any).zeroExTestId).to.be.a('number'); - const exchangeWeb3WrapperProvider = (zeroEx.exchange as any).web3Wrapper.getCurrentProvider(); + const exchangeWeb3WrapperProvider = (zeroEx.exchange as any)._web3Wrapper.getCurrentProvider(); expect((exchangeWeb3WrapperProvider as any).zeroExTestId).to.be.a('number'); - const tokenRegistryWeb3WrapperProvider = (zeroEx.tokenRegistry as any).web3Wrapper.getCurrentProvider(); + const tokenRegistryWeb3WrapperProvider = (zeroEx.tokenRegistry as any)._web3Wrapper.getCurrentProvider(); expect((tokenRegistryWeb3WrapperProvider as any).zeroExTestId).to.be.a('number'); }); }); @@ -154,7 +154,7 @@ describe('ZeroEx library', () => { const zeroEx = new ZeroEx(web3); stubs = [ - Sinon.stub((zeroEx as any), 'getExchangeAddressAsync') + Sinon.stub((zeroEx as any), '_getExchangeAddressAsync') .returns(Promise.resolve(exchangeContractAddress)), ]; @@ -197,9 +197,9 @@ describe('ZeroEx library', () => { s: '0x050aa3cc1f2c435e67e114cdce54b9527b4f50548342401bc5d2b77adbdacb02', }; stubs = [ - Sinon.stub((zeroEx as any).web3Wrapper, 'getNodeVersionAsync') + Sinon.stub((zeroEx as any)._web3Wrapper, 'getNodeVersionAsync') .returns(Promise.resolve(newParityNodeVersion)), - Sinon.stub((zeroEx as any).web3Wrapper, 'signTransactionAsync') + Sinon.stub((zeroEx as any)._web3Wrapper, 'signTransactionAsync') .returns(Promise.resolve(signature)), Sinon.stub(ZeroEx, 'isValidSignature').returns(true), ]; @@ -218,9 +218,9 @@ describe('ZeroEx library', () => { s: '0x2dea66f25a608bbae457e020fb6decb763deb8b7192abab624997242da248960', }; stubs = [ - Sinon.stub((zeroEx as any).web3Wrapper, 'getNodeVersionAsync') + Sinon.stub((zeroEx as any)._web3Wrapper, 'getNodeVersionAsync') .returns(Promise.resolve(newParityNodeVersion)), - Sinon.stub((zeroEx as any).web3Wrapper, 'signTransactionAsync') + Sinon.stub((zeroEx as any)._web3Wrapper, 'signTransactionAsync') .returns(Promise.resolve(signature)), Sinon.stub(ZeroEx, 'isValidSignature').returns(true), ]; -- cgit v1.2.3 From 6b152edb985d836c91c6d816c03cc15e77be2c6e Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Sun, 11 Jun 2017 13:14:46 +0200 Subject: Fix last tests --- src/contract_wrappers/contract_wrapper.ts | 10 +++++----- src/contract_wrappers/exchange_wrapper.ts | 16 ++++++++-------- src/contract_wrappers/token_wrapper.ts | 14 +++++++------- test/assert_test.ts | 6 +++--- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/contract_wrappers/contract_wrapper.ts b/src/contract_wrappers/contract_wrapper.ts index 99cfd97f0..b9426849a 100644 --- a/src/contract_wrappers/contract_wrapper.ts +++ b/src/contract_wrappers/contract_wrapper.ts @@ -5,16 +5,16 @@ import {ZeroExError} from '../types'; import {utils} from '../utils/utils'; export class ContractWrapper { - protected web3Wrapper: Web3Wrapper; + protected _web3Wrapper: Web3Wrapper; constructor(web3Wrapper: Web3Wrapper) { - this.web3Wrapper = web3Wrapper; + this._web3Wrapper = web3Wrapper; } protected async _instantiateContractIfExistsAsync(artifact: Artifact, address?: string): Promise { const c = await contract(artifact); - const providerObj = this.web3Wrapper.getCurrentProvider(); + const providerObj = this._web3Wrapper.getCurrentProvider(); c.setProvider(providerObj); - const networkIdIfExists = await this.web3Wrapper.getNetworkIdIfExistsAsync(); + const networkIdIfExists = await this._web3Wrapper.getNetworkIdIfExistsAsync(); const artifactNetworkConfigs = _.isUndefined(networkIdIfExists) ? undefined : artifact.networks[networkIdIfExists]; @@ -26,7 +26,7 @@ export class ContractWrapper { } if (!_.isUndefined(contractAddress)) { - const doesContractExist = await this.web3Wrapper.doesContractExistAtAddressAsync(contractAddress); + const doesContractExist = await this._web3Wrapper.doesContractExistAtAddressAsync(contractAddress); if (!doesContractExist) { throw new Error(ZeroExError.CONTRACT_DOES_NOT_EXIST); } diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts index d546a6102..232d84789 100644 --- a/src/contract_wrappers/exchange_wrapper.ts +++ b/src/contract_wrappers/exchange_wrapper.ts @@ -140,7 +140,7 @@ export class ExchangeWrapper extends ContractWrapper { assert.doesConformToSchema('signedOrder', signedOrder, signedOrderSchema); assert.isBigNumber('takerTokenFillAmount', takerTokenFillAmount); assert.isBoolean('shouldCheckTransfer', shouldCheckTransfer); - await assert.isSenderAddressAsync('takerAddress', takerAddress, this.web3Wrapper); + await assert.isSenderAddressAsync('takerAddress', takerAddress, this._web3Wrapper); const exchangeInstance = await this._getExchangeContractAsync(); await this._validateFillOrderAndThrowIfInvalidAsync(signedOrder, takerTokenFillAmount, takerAddress); @@ -196,7 +196,7 @@ export class ExchangeWrapper extends ContractWrapper { assert.isBigNumber('takerTokenFillAmount', takerTokenFillAmount); assert.isBoolean('shouldCheckTransfer', shouldCheckTransfer); assert.doesConformToSchema('signedOrders', signedOrders, signedOrdersSchema); - await assert.isSenderAddressAsync('takerAddress', takerAddress, this.web3Wrapper); + await assert.isSenderAddressAsync('takerAddress', takerAddress, this._web3Wrapper); for (const signedOrder of signedOrders) { await this._validateFillOrderAndThrowIfInvalidAsync( signedOrder, takerTokenFillAmount, takerAddress); @@ -262,7 +262,7 @@ export class ExchangeWrapper extends ContractWrapper { public async batchFillOrderAsync(orderFillRequests: OrderFillRequest[], shouldCheckTransfer: boolean, takerAddress: string): Promise { assert.isBoolean('shouldCheckTransfer', shouldCheckTransfer); - await assert.isSenderAddressAsync('takerAddress', takerAddress, this.web3Wrapper); + await assert.isSenderAddressAsync('takerAddress', takerAddress, this._web3Wrapper); assert.doesConformToSchema('orderFillRequests', orderFillRequests, orderFillRequestsSchema); for (const orderFillRequest of orderFillRequests) { await this._validateFillOrderAndThrowIfInvalidAsync( @@ -327,7 +327,7 @@ export class ExchangeWrapper extends ContractWrapper { takerAddress: string): Promise { assert.doesConformToSchema('signedOrder', signedOrder, signedOrderSchema); assert.isBigNumber('takerTokenFillAmount', takerTokenFillAmount); - await assert.isSenderAddressAsync('takerAddress', takerAddress, this.web3Wrapper); + await assert.isSenderAddressAsync('takerAddress', takerAddress, this._web3Wrapper); const exchangeInstance = await this._getExchangeContractAsync(); await this._validateFillOrderAndThrowIfInvalidAsync(signedOrder, takerTokenFillAmount, takerAddress); @@ -371,7 +371,7 @@ export class ExchangeWrapper extends ContractWrapper { */ public async batchFillOrKillAsync(orderFillOrKillRequests: OrderFillOrKillRequest[], takerAddress: string): Promise { - await assert.isSenderAddressAsync('takerAddress', takerAddress, this.web3Wrapper); + await assert.isSenderAddressAsync('takerAddress', takerAddress, this._web3Wrapper); assert.doesConformToSchema('orderFillOrKillRequests', orderFillOrKillRequests, orderFillOrKillRequestsSchema); const exchangeInstance = await this._getExchangeContractAsync(); for (const request of orderFillOrKillRequests) { @@ -428,7 +428,7 @@ export class ExchangeWrapper extends ContractWrapper { order: Order|SignedOrder, takerTokenCancelAmount: BigNumber.BigNumber): Promise { assert.doesConformToSchema('order', order, orderSchema); assert.isBigNumber('takerTokenCancelAmount', takerTokenCancelAmount); - await assert.isSenderAddressAsync('order.maker', order.maker, this.web3Wrapper); + await assert.isSenderAddressAsync('order.maker', order.maker, this._web3Wrapper); const exchangeInstance = await this._getExchangeContractAsync(); await this._validateCancelOrderAndThrowIfInvalidAsync(order, takerTokenCancelAmount); @@ -463,7 +463,7 @@ export class ExchangeWrapper extends ContractWrapper { const makers = _.map(orderCancellationRequests, cancellationRequest => cancellationRequest.order.maker); assert.hasAtMostOneUniqueValue(makers, ExchangeContractErrs.MULTIPLE_MAKERS_IN_SINGLE_CANCEL_BATCH_DISALLOWED); const maker = makers[0]; - await assert.isSenderAddressAsync('maker', maker, this.web3Wrapper); + await assert.isSenderAddressAsync('maker', maker, this._web3Wrapper); assert.doesConformToSchema('orderCancellationRequests', orderCancellationRequests, orderCancellationRequestsSchema); for (const cancellationRequest of orderCancellationRequests) { @@ -692,7 +692,7 @@ export class ExchangeWrapper extends ContractWrapper { private async _isRoundingErrorAsync(takerTokenAmount: BigNumber.BigNumber, fillTakerAmount: BigNumber.BigNumber, makerTokenAmount: BigNumber.BigNumber): Promise { - await assert.isUserAddressAvailableAsync(this.web3Wrapper); + await assert.isUserAddressAvailableAsync(this._web3Wrapper); const exchangeInstance = await this._getExchangeContractAsync(); const isRoundingError = await exchangeInstance.isRoundingError.call( takerTokenAmount, fillTakerAmount, makerTokenAmount, diff --git a/src/contract_wrappers/token_wrapper.ts b/src/contract_wrappers/token_wrapper.ts index b0101c0da..98da6c2cd 100644 --- a/src/contract_wrappers/token_wrapper.ts +++ b/src/contract_wrappers/token_wrapper.ts @@ -27,7 +27,7 @@ export class TokenWrapper extends ContractWrapper { public async getBalanceAsync(tokenAddress: string, ownerAddress: string): Promise { assert.isETHAddressHex('ownerAddress', ownerAddress); assert.isETHAddressHex('tokenAddress', tokenAddress); - await assert.isUserAddressAvailableAsync(this.web3Wrapper); + await assert.isUserAddressAvailableAsync(this._web3Wrapper); const tokenContract = await this._getTokenContractAsync(tokenAddress); let balance = await tokenContract.balanceOf.call(ownerAddress); @@ -46,7 +46,7 @@ export class TokenWrapper extends ContractWrapper { */ public async setAllowanceAsync(tokenAddress: string, ownerAddress: string, spenderAddress: string, amountInBaseUnits: BigNumber.BigNumber): Promise { - await assert.isSenderAddressAsync('ownerAddress', ownerAddress, this.web3Wrapper); + await assert.isSenderAddressAsync('ownerAddress', ownerAddress, this._web3Wrapper); assert.isETHAddressHex('spenderAddress', spenderAddress); assert.isETHAddressHex('tokenAddress', tokenAddress); assert.isBigNumber('amountInBaseUnits', amountInBaseUnits); @@ -55,7 +55,7 @@ export class TokenWrapper extends ContractWrapper { // Hack: for some reason default estimated gas amount causes `base fee exceeds gas limit` exception // on testrpc. Probably related to https://github.com/ethereumjs/testrpc/issues/294 // TODO: Debug issue in testrpc and submit a PR, then remove this hack - const networkIdIfExists = await this.web3Wrapper.getNetworkIdIfExistsAsync(); + const networkIdIfExists = await this._web3Wrapper.getNetworkIdIfExistsAsync(); const gas = networkIdIfExists === constants.TESTRPC_NETWORK_ID ? ALLOWANCE_TO_ZERO_GAS_AMOUNT : undefined; await tokenContract.approve(spenderAddress, amountInBaseUnits, { from: ownerAddress, @@ -72,7 +72,7 @@ export class TokenWrapper extends ContractWrapper { public async getAllowanceAsync(tokenAddress: string, ownerAddress: string, spenderAddress: string) { assert.isETHAddressHex('ownerAddress', ownerAddress); assert.isETHAddressHex('tokenAddress', tokenAddress); - await assert.isUserAddressAvailableAsync(this.web3Wrapper); + await assert.isUserAddressAvailableAsync(this._web3Wrapper); const tokenContract = await this._getTokenContractAsync(tokenAddress); let allowanceInBaseUnits = await tokenContract.allowance.call(ownerAddress, spenderAddress); @@ -120,7 +120,7 @@ export class TokenWrapper extends ContractWrapper { public async transferAsync(tokenAddress: string, fromAddress: string, toAddress: string, amountInBaseUnits: BigNumber.BigNumber): Promise { assert.isETHAddressHex('tokenAddress', tokenAddress); - await assert.isSenderAddressAsync('fromAddress', fromAddress, this.web3Wrapper); + await assert.isSenderAddressAsync('fromAddress', fromAddress, this._web3Wrapper); assert.isETHAddressHex('toAddress', toAddress); assert.isBigNumber('amountInBaseUnits', amountInBaseUnits); @@ -152,7 +152,7 @@ export class TokenWrapper extends ContractWrapper { assert.isETHAddressHex('tokenAddress', tokenAddress); assert.isETHAddressHex('fromAddress', fromAddress); assert.isETHAddressHex('toAddress', toAddress); - await assert.isSenderAddressAsync('senderAddress', senderAddress, this.web3Wrapper); + await assert.isSenderAddressAsync('senderAddress', senderAddress, this._web3Wrapper); assert.isBigNumber('amountInBaseUnits', amountInBaseUnits); const tokenContract = await this._getTokenContractAsync(tokenAddress); @@ -182,7 +182,7 @@ export class TokenWrapper extends ContractWrapper { return tokenContract; } private async _getProxyAddressAsync() { - const networkIdIfExists = await this.web3Wrapper.getNetworkIdIfExistsAsync(); + const networkIdIfExists = await this._web3Wrapper.getNetworkIdIfExistsAsync(); const proxyNetworkConfigsIfExists = _.isUndefined(networkIdIfExists) ? undefined : (ProxyArtifacts as any).networks[networkIdIfExists]; diff --git a/test/assert_test.ts b/test/assert_test.ts index 6b623eaad..338027ad3 100644 --- a/test/assert_test.ts +++ b/test/assert_test.ts @@ -13,13 +13,13 @@ describe('Assertion library', () => { it('throws when address is invalid', async () => { const address = '0xdeadbeef'; const varName = 'address'; - return expect(assert.isSenderAddressAsync(varName, address, (zeroEx as any).web3Wrapper)) + return expect(assert.isSenderAddressAsync(varName, address, (zeroEx as any)._web3Wrapper)) .to.be.rejectedWith(`Expected ${varName} to be of type ETHAddressHex, encountered: ${address}`); }); it('throws when address is unavailable', async () => { const validUnrelatedAddress = '0x8b0292b11a196601eddce54b665cafeca0347d42'; const varName = 'address'; - return expect(assert.isSenderAddressAsync(varName, validUnrelatedAddress, (zeroEx as any).web3Wrapper)) + return expect(assert.isSenderAddressAsync(varName, validUnrelatedAddress, (zeroEx as any)._web3Wrapper)) .to.be.rejectedWith( `Specified ${varName} ${validUnrelatedAddress} isn't available through the supplied web3 instance`, ); @@ -27,7 +27,7 @@ describe('Assertion library', () => { it('doesn\'t throw if address is available', async () => { const availableAddress = (await zeroEx.getAvailableAddressesAsync())[0]; const varName = 'address'; - return expect(assert.isSenderAddressAsync(varName, availableAddress, (zeroEx as any).web3Wrapper)) + return expect(assert.isSenderAddressAsync(varName, availableAddress, (zeroEx as any)._web3Wrapper)) .to.become(undefined); }); }); -- cgit v1.2.3