diff options
-rw-r--r-- | src/0x.js.ts | 26 | ||||
-rw-r--r-- | src/contract_wrappers/contract_wrapper.ts | 12 | ||||
-rw-r--r-- | src/contract_wrappers/exchange_wrapper.ts | 199 | ||||
-rw-r--r-- | src/contract_wrappers/token_registry_wrapper.ts | 18 | ||||
-rw-r--r-- | src/contract_wrappers/token_wrapper.ts | 44 | ||||
-rw-r--r-- | test/0x.js_test.ts | 36 | ||||
-rw-r--r-- | test/assert_test.ts | 6 | ||||
-rw-r--r-- | test/exchange_wrapper_test.ts | 4 |
8 files changed, 173 insertions, 172 deletions
diff --git a/src/0x.js.ts b/src/0x.js.ts index b641739ac..f01c918d6 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 `data` with the private key corresponding to the `signerAddress` 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<string[]> { - 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<string> { 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(orderHash: string, signerAddress: string): Promise<ECSignature> { assert.isHexString('orderHash', orderHash); - 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..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<ContractInstance> { + protected async _instantiateContractIfExistsAsync(artifact: Artifact, address?: string): Promise<ContractInstance> { 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 589dfb1cc..a08901004 100644 --- a/src/contract_wrappers/exchange_wrapper.ts +++ b/src/contract_wrappers/exchange_wrapper.ts @@ -38,7 +38,7 @@ import {TokenWrapper} from './token_wrapper'; import {decorators} from '../utils/decorators'; 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, @@ -46,10 +46,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, @@ -69,12 +69,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<void> { - 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 @@ -87,7 +87,7 @@ export class ExchangeWrapper extends ContractWrapper { public async getUnavailableTakerAmountAsync(orderHash: string): Promise<BigNumber.BigNumber> { assert.isValidOrderHash('orderHash', orderHash); - const exchangeContract = await this.getExchangeContractAsync(); + const exchangeContract = await this._getExchangeContractAsync(); let unavailableAmountInBaseUnits = await exchangeContract.getUnavailableValueT.call(orderHash); // Wrap BigNumbers returned from web3 with our own (later) version of BigNumber unavailableAmountInBaseUnits = new BigNumber(unavailableAmountInBaseUnits); @@ -101,7 +101,7 @@ export class ExchangeWrapper extends ContractWrapper { public async getFilledTakerAmountAsync(orderHash: string): Promise<BigNumber.BigNumber> { assert.isValidOrderHash('orderHash', orderHash); - const exchangeContract = await this.getExchangeContractAsync(); + const exchangeContract = await this._getExchangeContractAsync(); let fillAmountInBaseUnits = await exchangeContract.filled.call(orderHash); // Wrap BigNumbers returned from web3 with our own (later) version of BigNumber fillAmountInBaseUnits = new BigNumber(fillAmountInBaseUnits); @@ -116,7 +116,7 @@ export class ExchangeWrapper extends ContractWrapper { public async getCanceledTakerAmountAsync(orderHash: string): Promise<BigNumber.BigNumber> { assert.isValidOrderHash('orderHash', orderHash); - const exchangeContract = await this.getExchangeContractAsync(); + const exchangeContract = await this._getExchangeContractAsync(); let cancelledAmountInBaseUnits = await exchangeContract.cancelled.call(orderHash); // Wrap BigNumbers returned from web3 with our own (later) version of BigNumber cancelledAmountInBaseUnits = new BigNumber(cancelledAmountInBaseUnits); @@ -142,12 +142,12 @@ 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); + 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, @@ -174,7 +174,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. @@ -199,9 +199,9 @@ 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( + await this._validateFillOrderAndThrowIfInvalidAsync( signedOrder, takerTokenFillAmount, takerAddress); } if (_.isEmpty(signedOrders)) { @@ -210,7 +210,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, @@ -221,7 +221,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, @@ -247,7 +247,7 @@ export class ExchangeWrapper extends ContractWrapper { gas, }, ); - this.throwErrorLogsAsErrors(response.logs); + this._throwErrorLogsAsErrors(response.logs); } /** * Batch version of fillOrderAsync. @@ -266,10 +266,10 @@ export class ExchangeWrapper extends ContractWrapper { public async batchFillOrderAsync(orderFillRequests: OrderFillRequest[], shouldCheckTransfer: boolean, takerAddress: string): Promise<void> { 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( + await this._validateFillOrderAndThrowIfInvalidAsync( orderFillRequest.signedOrder, orderFillRequest.takerTokenFillAmount, takerAddress); } if (_.isEmpty(orderFillRequests)) { @@ -278,7 +278,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, @@ -290,7 +290,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, @@ -316,7 +316,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, @@ -332,15 +332,15 @@ export class ExchangeWrapper extends ContractWrapper { takerAddress: string): Promise<void> { 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); + 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, @@ -365,7 +365,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 @@ -377,17 +377,17 @@ export class ExchangeWrapper extends ContractWrapper { @decorators.contractCallErrorHandler public async batchFillOrKillAsync(orderFillOrKillRequests: OrderFillOrKillRequest[], takerAddress: string): Promise<void> { - await assert.isSenderAddressAsync('takerAddress', takerAddress, this.web3Wrapper); + 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, @@ -422,7 +422,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. @@ -435,12 +435,12 @@ export class ExchangeWrapper extends ContractWrapper { order: Order|SignedOrder, takerTokenCancelAmount: BigNumber.BigNumber): Promise<void> { 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); + 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, @@ -458,7 +458,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. @@ -471,21 +471,21 @@ 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) { - 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, ]; }); @@ -509,7 +509,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 @@ -522,7 +522,7 @@ export class ExchangeWrapper extends ContractWrapper { public async subscribeAsync(eventName: ExchangeEvents, subscriptionOpts: SubscriptionOpts, indexFilterValues: IndexFilterValues, callback: EventCallback): Promise<void> { - const exchangeContract = await this.getExchangeContractAsync(); + const exchangeContract = await this._getExchangeContractAsync(); let createLogEvent: CreateContractEvent; switch (eventName) { case ExchangeEvents.LogFill: @@ -541,15 +541,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<boolean> { + private async _isValidSignatureUsingContractCallAsync(dataHex: string, ecSignature: ECSignature, + signerAddressHex: string): Promise<boolean> { 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, @@ -560,27 +560,27 @@ export class ExchangeWrapper extends ContractWrapper { ); return isValidSignature; } - private async getOrderHashHexAsync(order: Order|SignedOrder): Promise<string> { - const exchangeInstance = await this.getExchangeContractAsync(); + private async _getOrderHashHexAsync(order: Order|SignedOrder): Promise<string> { + const exchangeInstance = await this._getExchangeContractAsync(); const orderHashHex = utils.getOrderHashHex(order, exchangeInstance.address); return orderHashHex; } - private async getOrderHashHexUsingContractCallAsync(order: Order|SignedOrder): Promise<string> { - const exchangeInstance = await this.getExchangeContractAsync(); - const [orderAddresses, orderValues] = ExchangeWrapper.getOrderAddressesAndValues(order); + private async _getOrderHashHexUsingContractCallAsync(order: Order|SignedOrder): Promise<string> { + 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<void> { + private async _validateFillOrderAndThrowIfInvalidAsync(signedOrder: SignedOrder, + fillTakerAmount: BigNumber.BigNumber, + senderAddress: string): Promise<void> { if (fillTakerAmount.eq(0)) { throw new Error(ExchangeContractErrs.ORDER_REMAINING_FILL_AMOUNT_ZERO); } @@ -591,23 +591,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<void> { 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); @@ -617,9 +617,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); @@ -637,17 +637,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<void> { + private async _validateFillOrderBalancesAndAllowancesAndThrowIfInvalidAsync(signedOrder: SignedOrder, + fillTakerAmount: BigNumber.BigNumber, + senderAddress: string, + zrxTokenAddress: string, + ): Promise<void> { - 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 @@ -667,12 +668,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)) { @@ -688,34 +689,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<boolean> { - await assert.isUserAddressAvailableAsync(this.web3Wrapper); - const exchangeInstance = await this.getExchangeContractAsync(); + private async _isRoundingErrorAsync(takerTokenAmount: BigNumber.BigNumber, + fillTakerAmount: BigNumber.BigNumber, + makerTokenAmount: BigNumber.BigNumber): Promise<boolean> { + await assert.isUserAddressAvailableAsync(this._web3Wrapper); + const exchangeInstance = await this._getExchangeContractAsync(); const isRoundingError = await exchangeInstance.isRoundingError.call( takerTokenAmount, fillTakerAmount, makerTokenAmount, ); return isRoundingError; } - private async getExchangeContractAsync(): Promise<ExchangeContract> { - if (!_.isUndefined(this.exchangeContractIfExists)) { - return this.exchangeContractIfExists; + private async _getExchangeContractAsync(): Promise<ExchangeContract> { + 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<string> { - const exchangeInstance = await this.getExchangeContractAsync(); + private async _getZRXTokenAddressAsync(): Promise<string> { + 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<Token[]> { - const tokenRegistryContract = await this.getTokenRegistryContractAsync(); + const tokenRegistryContract = await this._getTokenRegistryContractAsync(); const addresses = await tokenRegistryContract.getTokenAddresses.call(); const tokenMetadataPromises: Array<Promise<TokenMetadata>> = _.map( @@ -37,12 +37,12 @@ export class TokenRegistryWrapper extends ContractWrapper { }); return tokens; } - private async getTokenRegistryContractAsync(): Promise<TokenRegistryContract> { - if (!_.isUndefined(this.tokenRegistryContractIfExists)) { - return this.tokenRegistryContractIfExists; + private async _getTokenRegistryContractAsync(): Promise<TokenRegistryContract> { + 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..98da6c2cd 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. @@ -27,9 +27,9 @@ export class TokenWrapper extends ContractWrapper { public async getBalanceAsync(tokenAddress: string, ownerAddress: string): Promise<BigNumber.BigNumber> { assert.isETHAddressHex('ownerAddress', ownerAddress); assert.isETHAddressHex('tokenAddress', tokenAddress); - await assert.isUserAddressAvailableAsync(this.web3Wrapper); + 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); @@ -46,16 +46,16 @@ export class TokenWrapper extends ContractWrapper { */ public async setAllowanceAsync(tokenAddress: string, ownerAddress: string, spenderAddress: string, amountInBaseUnits: BigNumber.BigNumber): Promise<void> { - 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); - 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 - 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,9 +72,9 @@ 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); + 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); } /** @@ -120,11 +120,11 @@ export class TokenWrapper extends ContractWrapper { public async transferAsync(tokenAddress: string, fromAddress: string, toAddress: string, amountInBaseUnits: BigNumber.BigNumber): Promise<void> { 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); - const tokenContract = await this.getTokenContractAsync(tokenAddress); + const tokenContract = await this._getTokenContractAsync(tokenAddress); const fromAddressBalance = await this.getBalanceAsync(tokenAddress, fromAddress); if (fromAddressBalance.lessThan(amountInBaseUnits)) { @@ -152,10 +152,10 @@ 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); + const tokenContract = await this._getTokenContractAsync(tokenAddress); const fromAddressAllowance = await this.getAllowanceAsync(tokenAddress, fromAddress, senderAddress); if (fromAddressAllowance.lessThan(amountInBaseUnits)) { @@ -171,18 +171,18 @@ export class TokenWrapper extends ContractWrapper { from: senderAddress, }); } - private async getTokenContractAsync(tokenAddress: string): Promise<TokenContract> { - let tokenContract = this.tokenContractsByAddress[tokenAddress]; + private async _getTokenContractAsync(tokenAddress: string): Promise<TokenContract> { + 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() { - const networkIdIfExists = await this.web3Wrapper.getNetworkIdIfExistsAsync(); + private async _getProxyAddressAsync() { + const networkIdIfExists = await this._web3Wrapper.getNetworkIdIfExistsAsync(); const proxyNetworkConfigsIfExists = _.isUndefined(networkIdIfExists) ? undefined : (ProxyArtifacts as any).networks[networkIdIfExists]; diff --git a/test/0x.js_test.ts b/test/0x.js_test.ts index 1349d6360..346ef69f8 100644 --- a/test/0x.js_test.ts +++ b/test/0x.js_test.ts @@ -19,10 +19,10 @@ 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(); - expect((zeroEx.exchange as any).exchangeContractIfExists).to.not.be.undefined(); - expect((zeroEx.tokenRegistry as any).tokenRegistryContractIfExists).to.not.be.undefined(); + 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(); 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'); }); }); @@ -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(); }); }); @@ -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), ]; 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); }); }); 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); }); }); |