From 0a73bbe279ccc0f39363f0bb700c5f581ec5f654 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 30 Jan 2018 14:35:04 +0100 Subject: Add zeroEx.etherToken.getContractAddressifExists --- packages/0x.js/src/contract_wrappers/contract_wrapper.ts | 2 +- packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts | 9 +++++++++ packages/0x.js/test/ether_token_wrapper_test.ts | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/src/contract_wrappers/contract_wrapper.ts b/packages/0x.js/src/contract_wrappers/contract_wrapper.ts index 27551c01d..09de77452 100644 --- a/packages/0x.js/src/contract_wrappers/contract_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/contract_wrapper.ts @@ -34,7 +34,7 @@ const CONTRACT_NAME_TO_NOT_FOUND_ERROR: { export class ContractWrapper { protected _web3Wrapper: Web3Wrapper; - private _networkId: number; + protected _networkId: number; private _abiDecoder?: AbiDecoder; private _blockAndLogStreamerIfExists: BlockAndLogStreamer | undefined; private _blockAndLogStreamInterval: NodeJS.Timer; diff --git a/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts b/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts index b03571636..1373e7baf 100644 --- a/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts @@ -163,6 +163,15 @@ export class EtherTokenWrapper extends ContractWrapper { public unsubscribeAll(): void { super.unsubscribeAll(); } + /** + * Retrieves the Ethereum address of the EtherToken contract deployed on the network + * that the user-passed web3 provider is connected to. If it's an unknown private network - undefined is returned. + * @returns The Ethereum address of the EtherToken contract or undefined. + */ + public getContractAddressIfExists(): string | undefined { + const contractAddress = artifacts.EtherTokenArtifact.networks[this._networkId].address; + return contractAddress; + } private _invalidateContractInstance(): void { this.unsubscribeAll(); this._etherTokenContractsByAddress = {}; diff --git a/packages/0x.js/test/ether_token_wrapper_test.ts b/packages/0x.js/test/ether_token_wrapper_test.ts index b810fc9f1..6d7d953a8 100644 --- a/packages/0x.js/test/ether_token_wrapper_test.ts +++ b/packages/0x.js/test/ether_token_wrapper_test.ts @@ -61,7 +61,7 @@ describe('EtherTokenWrapper', () => { tokens = await zeroEx.tokenRegistry.getTokensAsync(); userAddresses = await zeroEx.getAvailableAddressesAsync(); addressWithETH = userAddresses[0]; - wethContractAddress = (zeroEx.etherToken as any)._getContractAddress(artifacts.EtherTokenArtifact); + wethContractAddress = zeroEx.etherToken.getContractAddressIfExists() as string; depositWeiAmount = (zeroEx as any)._web3Wrapper.toWei(new BigNumber(5)); decimalPlaces = 7; addressWithoutFunds = userAddresses[1]; -- cgit From 4671999ea0a1085ede347c44881ede2600facdbf Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 30 Jan 2018 14:54:10 +0100 Subject: Fix linter errors --- packages/0x.js/test/ether_token_wrapper_test.ts | 1 - 1 file changed, 1 deletion(-) (limited to 'packages') diff --git a/packages/0x.js/test/ether_token_wrapper_test.ts b/packages/0x.js/test/ether_token_wrapper_test.ts index 6d7d953a8..98e6981fd 100644 --- a/packages/0x.js/test/ether_token_wrapper_test.ts +++ b/packages/0x.js/test/ether_token_wrapper_test.ts @@ -17,7 +17,6 @@ import { ZeroEx, ZeroExError, } from '../src'; -import { artifacts } from '../src/artifacts'; import { DoneCallback } from '../src/types'; import { chaiSetup } from './utils/chai_setup'; -- cgit From 4fa774f866292406ec21e29aee4919c7f73cd505 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 30 Jan 2018 15:04:42 +0100 Subject: Update CHANGELOG --- packages/0x.js/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'packages') diff --git a/packages/0x.js/CHANGELOG.md b/packages/0x.js/CHANGELOG.md index 83c33ee1c..2dd1bbaaa 100644 --- a/packages/0x.js/CHANGELOG.md +++ b/packages/0x.js/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## v0.x.0 - _TBD, 2018_ + + * Add `zeroEx.etherToken.getContractAddressIfExists` (#350) + ## v0.31.0 - _January 30, 2018_ * Add the `shouldAddPersonalMessagePrefix` parameter to `signOrderHashAsync` so that the -- cgit From a816fb5958116127b1fffb78f5fca07624b5b0a5 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 5 Feb 2018 12:28:27 +0100 Subject: Improve the comment and fix an exception --- packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts b/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts index 1373e7baf..ead6fe9d1 100644 --- a/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts @@ -165,12 +165,16 @@ export class EtherTokenWrapper extends ContractWrapper { } /** * Retrieves the Ethereum address of the EtherToken contract deployed on the network - * that the user-passed web3 provider is connected to. If it's an unknown private network - undefined is returned. + * that the user-passed web3 provider is connected to. If it's not Kovan, Ropsten, Rinkeby, Mainnet or TestRPC + * (networkId: 50), it will return undefined (e.g a private network). * @returns The Ethereum address of the EtherToken contract or undefined. */ public getContractAddressIfExists(): string | undefined { - const contractAddress = artifacts.EtherTokenArtifact.networks[this._networkId].address; - return contractAddress; + const networkSpecificArtifact = artifacts.EtherTokenArtifact.networks[this._networkId]; + const contractAddressIfExists = _.isUndefined(networkSpecificArtifact) + ? undefined + : networkSpecificArtifact.address; + return contractAddressIfExists; } private _invalidateContractInstance(): void { this.unsubscribeAll(); -- cgit From 400a97e7a8f76d894d47368425bbe1e33fa5b255 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 5 Feb 2018 12:32:59 +0100 Subject: Add regression tests --- packages/0x.js/test/ether_token_wrapper_test.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'packages') diff --git a/packages/0x.js/test/ether_token_wrapper_test.ts b/packages/0x.js/test/ether_token_wrapper_test.ts index 98e6981fd..145f11bd1 100644 --- a/packages/0x.js/test/ether_token_wrapper_test.ts +++ b/packages/0x.js/test/ether_token_wrapper_test.ts @@ -71,6 +71,18 @@ describe('EtherTokenWrapper', () => { afterEach(async () => { await blockchainLifecycle.revertAsync(); }); + describe('#getContractAddressIfExists', async () => { + it('should return contract address if connected to a known network', () => { + const contractAddressIfExists = zeroEx.etherToken.getContractAddressIfExists(); + expect(contractAddressIfExists).to.not.be.undefined(); + }); + it('should return undefined if connected to an unknown network', () => { + const UNKNOWN_NETWORK_NETWORK_ID = 10; + const unknownNetworkZeroEx = new ZeroEx(web3.currentProvider, { networkId: UNKNOWN_NETWORK_NETWORK_ID }); + const contractAddressIfExists = unknownNetworkZeroEx.etherToken.getContractAddressIfExists(); + expect(contractAddressIfExists).to.be.undefined(); + }); + }); describe('#depositAsync', () => { it('should successfully deposit ETH and issue Wrapped ETH tokens', async () => { const preETHBalance = await (zeroEx as any)._web3Wrapper.getBalanceInWeiAsync(addressWithETH); -- cgit From fa98450754280e5b40cc017566b740032ee33dbe Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 5 Feb 2018 12:49:57 +0100 Subject: Fix prettier --- packages/0x.js/CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) (limited to 'packages') diff --git a/packages/0x.js/CHANGELOG.md b/packages/0x.js/CHANGELOG.md index 0202471e7..1cb51ca9f 100644 --- a/packages/0x.js/CHANGELOG.md +++ b/packages/0x.js/CHANGELOG.md @@ -1,6 +1,5 @@ # CHANGELOG - ## v0.x.0 - _TBD, 2018_ * Add `zeroEx.etherToken.getContractAddressIfExists` (#350) -- cgit From 5324dfa5a70a32f9cc2c51b8252a5310439d3a86 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 5 Feb 2018 19:13:09 +0100 Subject: Fix a typo --- packages/0x.js/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages') diff --git a/packages/0x.js/CHANGELOG.md b/packages/0x.js/CHANGELOG.md index 1cb51ca9f..06b11cba8 100644 --- a/packages/0x.js/CHANGELOG.md +++ b/packages/0x.js/CHANGELOG.md @@ -6,7 +6,7 @@ ## v0.31.1 - _February 1, 2018_ - * Fix the bug causing order watcher to throw is makerToken === zrx (#357) + * Fix the bug causing order watcher to throw if makerToken === zrx (#357) ## v0.31.0 - _January 30, 2018_ -- cgit