From 578fc45ca0a4c1e3731f203846ab4d79a5661970 Mon Sep 17 00:00:00 2001 From: lukelee-sl <109538178+lukelee-sl@users.noreply.github.com> Date: Thu, 4 Aug 2022 10:05:13 -0700 Subject: [PATCH] =?UTF-8?q?return=200x=20instead=20of=200x0=20for=20non=20?= =?UTF-8?q?existing=20contract=20addresses=20given=20to=E2=80=A6=20(#419)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * return 0x instead of 0x0 for non existing contract addresses given to eth_getCode Signed-off-by: lukelee-sl * update acceptance tests to reflect expectation of 0x vs 0x0 Signed-off-by: lukelee-sl * update values to use predefined constant for 0x Signed-off-by: lukelee-sl --- packages/relay/src/lib/eth.ts | 4 ++-- packages/relay/tests/lib/eth.spec.ts | 4 ++-- packages/server/tests/acceptance/erc20.spec.ts | 3 ++- packages/server/tests/acceptance/rpc.spec.ts | 7 ++++--- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/relay/src/lib/eth.ts b/packages/relay/src/lib/eth.ts index 0ca318340f..e0e81a994c 100644 --- a/packages/relay/src/lib/eth.ts +++ b/packages/relay/src/lib/eth.ts @@ -494,8 +494,8 @@ export class EthImpl implements Eth { // handle INVALID_CONTRACT_ID if (e.isInvalidContractId()) { this.logger.debug('Unable to find code for contract %s in block "%s", returning 0x0, err code: %s', address, blockNumber, e.statusCode); - cache.set(cachedLabel, '0x0', constants.CACHE_TTL.ONE_HOUR); - return '0x0'; + cache.set(cachedLabel, EthImpl.emptyHex, constants.CACHE_TTL.ONE_HOUR); + return EthImpl.emptyHex; } this.logger.error(e, 'Error raised during getCode for address %s, err code: %s', address, e.statusCode); } else { diff --git a/packages/relay/tests/lib/eth.spec.ts b/packages/relay/tests/lib/eth.spec.ts index 0cddedb6c4..8f4d9eba5b 100644 --- a/packages/relay/tests/lib/eth.spec.ts +++ b/packages/relay/tests/lib/eth.spec.ts @@ -958,8 +958,8 @@ describe('Eth calls using MirrorNode', async function () { const resNoCache = await ethImpl.getCode(contractAddress1, null); const resCached = await ethImpl.getCode(contractAddress1, null); sinon.assert.calledOnce(sdkClientStub.getContractByteCode); - expect(resNoCache).to.equal(EthImpl.zeroHex); - expect(resCached).to.equal(EthImpl.zeroHex); + expect(resNoCache).to.equal(EthImpl.emptyHex); + expect(resCached).to.equal(EthImpl.emptyHex); }); it('should return the bytecode', async () => { diff --git a/packages/server/tests/acceptance/erc20.spec.ts b/packages/server/tests/acceptance/erc20.spec.ts index 4fc7dc5f91..07354f0cbc 100644 --- a/packages/server/tests/acceptance/erc20.spec.ts +++ b/packages/server/tests/acceptance/erc20.spec.ts @@ -28,6 +28,7 @@ import { ethers, BigNumber } from 'ethers'; import ERC20MockJson from '../contracts/ERC20Mock.json'; import Assertions from '../helpers/assertions'; import {Utils} from '../helpers/utils'; +import { EthImpl } from "@hashgraph/json-rpc-relay/src/lib/eth"; describe('ERC20 Acceptance Tests', async function () { @@ -50,7 +51,7 @@ describe('ERC20 Acceptance Tests', async function () { const testTitles = [ {testName: ERC20, expectedBytecode: ERC20MockJson.deployedBytecode}, - {testName: HTS, expectedBytecode: '0x0'} + {testName: HTS, expectedBytecode: EthImpl.emptyHex} ]; before(async () => { diff --git a/packages/server/tests/acceptance/rpc.spec.ts b/packages/server/tests/acceptance/rpc.spec.ts index 8d54469e06..76592a3753 100644 --- a/packages/server/tests/acceptance/rpc.spec.ts +++ b/packages/server/tests/acceptance/rpc.spec.ts @@ -31,6 +31,7 @@ import parentContractJson from '../contracts/Parent.json'; import basicContractJson from '../contracts/Basic.json'; import logsContractJson from '../contracts/Logs.json'; import { predefined } from '../../../relay/src/lib/errors/JsonRpcError'; +import { EthImpl } from '@hashgraph/json-rpc-relay/src/lib/eth'; describe('RPC Server Acceptance Tests', function () { this.timeout(240 * 1000); // 240 seconds @@ -989,19 +990,19 @@ describe('RPC Server Acceptance Tests', function () { it('should return 0x0 for non-existing contract on eth_getCode', async function () { const res = await relay.call('eth_getCode', [NON_EXISTING_ADDRESS]); - expect(res).to.eq('0x0'); + expect(res).to.eq(EthImpl.emptyHex); }); it('should return 0x0 for account evm_address on eth_getCode', async function () { const evmAddress = Utils.idToEvmAddress(accounts[2].accountId.toString()); const res = await relay.call('eth_getCode', [evmAddress]); - expect(res).to.eq('0x0'); + expect(res).to.eq(EthImpl.emptyHex); }); it('should return 0x0 for account alias on eth_getCode', async function () { const alias = Utils.idToEvmAddress(accounts[2].accountId.toString()); const res = await relay.call('eth_getCode', [alias]); - expect(res).to.eq('0x0'); + expect(res).to.eq(EthImpl.emptyHex); }); });