@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.
This commit is contained in:
F. Eugene Aumson 2019-10-25 21:08:31 -04:00 committed by GitHub
parent 59210f5e5e
commit 0067f10a6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 3 deletions

View File

@ -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.

View File

@ -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('');
});

View File

@ -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": [

View File

@ -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
}
]
},

View File

@ -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));
},