Skip to content

Commit 048c6ec

Browse files
authored
fix: Handle INVALID_TRANSACTION together with FAIL_INVALID when Contract does not exists (#1990)
* handle INVALID_TRANSACTION together with FAIL_INVALID. restoring disabled tests Signed-off-by: Alfredo Gutierrez <[email protected]> * Add UT for non-existent to address on relay call request, 2 response scenarios: FAIL_INVALID and INVALID_TRANSACTION Signed-off-by: Alfredo Gutierrez <[email protected]> * removing .only Signed-off-by: Alfredo Gutierrez <[email protected]> --------- Signed-off-by: Alfredo Gutierrez <[email protected]>
1 parent 6bfbba0 commit 048c6ec

File tree

7 files changed

+63
-3
lines changed

7 files changed

+63
-3
lines changed

packages/relay/src/lib/errors/MirrorNodeClientError.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,8 @@ export class MirrorNodeClientError extends Error {
8787
isFailInvalid() {
8888
return this.message === 'FAIL_INVALID';
8989
}
90+
91+
isInvalidTransaction() {
92+
return this.message === 'INVALID_TRANSACTION';
93+
}
9094
}

packages/relay/src/lib/eth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1523,7 +1523,7 @@ export class EthImpl implements Eth {
15231523

15241524
if (e instanceof MirrorNodeClientError) {
15251525
// Handles mirror node error for missing contract
1526-
if (e.isFailInvalid()) {
1526+
if (e.isFailInvalid() || e.isInvalidTransaction()) {
15271527
return EthImpl.emptyHex;
15281528
}
15291529

packages/relay/tests/helpers.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,30 @@ const mockData = {
299299
},
300300
},
301301

302+
invalidTransaction: {
303+
_status: {
304+
messages: [
305+
{
306+
message: 'INVALID_TRANSACTION',
307+
detail: '',
308+
data: '',
309+
},
310+
],
311+
},
312+
},
313+
314+
failInvalid: {
315+
_status: {
316+
messages: [
317+
{
318+
message: 'FAIL_INVALID',
319+
detail: '',
320+
data: '',
321+
},
322+
],
323+
},
324+
},
325+
302326
notSuported: {
303327
_status: {
304328
messages: [

packages/relay/tests/lib/eth/eth-config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ export const CONTRACT_ADDRESS_2 = '0x000000000000000000000000000000000000055e';
122122
export const CONTRACT_ADDRESS_3 = '0x000000000000000000000000000000000000255c';
123123
export const HTS_TOKEN_ADDRESS = '0x0000000000000000000000000000000002dca431';
124124
export const ACCOUNT_ADDRESS_1 = '0x13212A14deaf2775a5b3bEcC857806D5c719d3f2';
125+
export const NON_EXISTENT_CONTRACT_ADDRESS = `'0x55555555555555555555555555555555555555'`;
125126
export const DEFAULT_HTS_TOKEN = mockData.token;
126127
export const DEPLOYED_BYTECODE =
127128
'0x608060405234801561001057600080fd5b5060405161078938038061078983398181016040528101906100329190';

packages/relay/tests/lib/eth/eth_call.spec.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {
4040
MAX_GAS_LIMIT,
4141
MAX_GAS_LIMIT_HEX,
4242
NO_TRANSACTIONS,
43+
NON_EXISTENT_CONTRACT_ADDRESS,
4344
WRONG_CONTRACT_ADDRESS,
4445
} from './eth-config';
4546
import { JsonRpcError, predefined } from '../../../src/lib/errors/JsonRpcError';
@@ -820,5 +821,35 @@ describe('@ethCall Eth Call spec', async function () {
820821
args,
821822
);
822823
});
824+
825+
it('eth_call with all fields but mirrorNode throws 400 due to non-existent `to` address (INVALID_TRANSACTION)', async function () {
826+
const callData = {
827+
...defaultCallData,
828+
from: ACCOUNT_ADDRESS_1,
829+
to: NON_EXISTENT_CONTRACT_ADDRESS,
830+
data: CONTRACT_CALL_DATA,
831+
gas: MAX_GAS_LIMIT,
832+
};
833+
834+
web3Mock.onPost('contracts/call', { ...callData, estimate: false }).reply(400, mockData.invalidTransaction);
835+
const result = await ethImpl.call(callData, 'latest');
836+
expect(result).to.be.not.null;
837+
expect(result).to.equal('0x');
838+
});
839+
840+
it('eth_call with all fields but mirrorNode throws 400 due to non-existent `to` address (FAIL_INVALID)', async function () {
841+
const callData = {
842+
...defaultCallData,
843+
from: ACCOUNT_ADDRESS_1,
844+
to: NON_EXISTENT_CONTRACT_ADDRESS,
845+
data: CONTRACT_CALL_DATA,
846+
gas: MAX_GAS_LIMIT,
847+
};
848+
849+
web3Mock.onPost('contracts/call', { ...callData, estimate: false }).reply(400, mockData.failInvalid);
850+
const result = await ethImpl.call(callData, 'latest');
851+
expect(result).to.be.not.null;
852+
expect(result).to.equal('0x');
853+
});
823854
});
824855
});

packages/server/tests/acceptance/htsPrecompile/precompileCalls.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ describe('@precompile-calls Tests for eth_call with HTS', async function () {
614614
const CALLDATA_ALLOWANCE = '0xdd62ed3e';
615615
const NON_EXISTING_ACCOUNT = '123abc123abc123abc123abc123abc123abc123a';
616616

617-
xit('Call to non-existing HTS token returns 0x', async () => {
617+
it('Call to non-existing HTS token returns 0x', async () => {
618618
const callData = {
619619
from: accounts[0].address,
620620
to: '0x' + NON_EXISTING_ACCOUNT,

packages/server/tests/acceptance/rpc_batch3.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ describe('@api-batch-3 RPC Server Acceptance Tests', function () {
149149
expect(res).to.eq('0x'); // confirm no error
150150
});
151151

152-
xit('"eth_call" for non-existing contract address returns 0x', async function () {
152+
it('"eth_call" for non-existing contract address returns 0x', async function () {
153153
const callData = {
154154
from: accounts[0].address,
155155
to: Address.NON_EXISTING_ADDRESS,

0 commit comments

Comments
 (0)