From 0067f10a6a7df2cabe0ea1a411a504e5065f7f77 Mon Sep 17 00:00:00 2001 From: "F. Eugene Aumson" Date: Fri, 25 Oct 2019 21:08:31 -0400 Subject: [PATCH] @0x/utils: fix wrong RPC method in getChainIdAsync() (#2270) It was using net_version, but it should be using the eth_chainId method introduced in EIP-695. I'm not sure whether/how the network ID differs from the chain ID on mainnet and the testnets, but in Ganache in particular, the network ID is 50 while the chain ID is 1337, and this difference was causing problems for Python tests. Specifically, the Web3.py interface `Web3.eth.chainId` invokes the eth_chainId method, and the result feeds into the order hash, which wasn't lining up with the non-Python side of things. --- contracts/test-utils/src/constants.ts | 1 + contracts/test-utils/test/mocha_blockchain.ts | 2 +- packages/migrations/CHANGELOG.json | 9 +++++++++ packages/utils/CHANGELOG.json | 4 ++++ packages/utils/src/provider_utils.ts | 4 ++-- 5 files changed, 17 insertions(+), 3 deletions(-) diff --git a/contracts/test-utils/src/constants.ts b/contracts/test-utils/src/constants.ts index 45bcc6ff72..5e33b32295 100644 --- a/contracts/test-utils/src/constants.ts +++ b/contracts/test-utils/src/constants.ts @@ -32,6 +32,7 @@ export const constants = { BASE_16: 16, INVALID_OPCODE: 'invalid opcode', TESTRPC_NETWORK_ID: 50, + TESTRPC_CHAIN_ID: 1337, // Note(albrow): In practice V8 and most other engines limit the minimum // interval for setInterval to 10ms. We still set it to 0 here in order to // ensure we always use the minimum interval. diff --git a/contracts/test-utils/test/mocha_blockchain.ts b/contracts/test-utils/test/mocha_blockchain.ts index bf21bbe41d..15c4ea43e5 100644 --- a/contracts/test-utils/test/mocha_blockchain.ts +++ b/contracts/test-utils/test/mocha_blockchain.ts @@ -18,7 +18,7 @@ blockchainTests('mocha blockchain extensions', env => { }); it('initializes the test environment', async () => { - expect(await env.getChainIdAsync()).to.eq(constants.TESTRPC_NETWORK_ID); + expect(await env.getChainIdAsync()).to.eq(constants.TESTRPC_CHAIN_ID); expect(await env.getAccountAddressesAsync()).to.be.not.empty(''); }); diff --git a/packages/migrations/CHANGELOG.json b/packages/migrations/CHANGELOG.json index 5056bca91e..04a5829780 100644 --- a/packages/migrations/CHANGELOG.json +++ b/packages/migrations/CHANGELOG.json @@ -1,4 +1,13 @@ [ + { + "version": "4.4.0-beta.1", + "changes": [ + { + "note": "Update all contract deployments to pass the actual chain ID (rather than the network ID) via the newly modified @0x/utils/provider_utils", + "pr": 2270 + } + ] + }, { "version": "4.4.0-beta.0", "changes": [ diff --git a/packages/utils/CHANGELOG.json b/packages/utils/CHANGELOG.json index 356ae9535e..769fd80687 100644 --- a/packages/utils/CHANGELOG.json +++ b/packages/utils/CHANGELOG.json @@ -5,6 +5,10 @@ { "note": "Consolidated FixedMathRevertErrors", "pr": 2255 + }, + { + "note": "Changed provider_utils.providerUtils.getChainIdAsync() to invoke RPC method eth_chainId rather than net_version", + "pr": 2270 } ] }, diff --git a/packages/utils/src/provider_utils.ts b/packages/utils/src/provider_utils.ts index 736d54fae4..0a9849bdb9 100644 --- a/packages/utils/src/provider_utils.ts +++ b/packages/utils/src/provider_utils.ts @@ -111,7 +111,7 @@ export const providerUtils = { { jsonrpc: '2.0', id: _.random(1, RPC_ID_MAX), - method: 'net_version', + method: 'eth_chainId', params: [], }, (err: Error | null, result?: JSONRPCResponsePayload) => { @@ -119,7 +119,7 @@ export const providerUtils = { reject(err); } if (!result) { - throw new Error("Invalid 'net_version' response"); + throw new Error("Invalid 'eth_chainId' response"); } accept(_.toNumber(result.result)); },