Skip to content

Commit 2908d5f

Browse files
authored
fix: Removing name field from RPC Error when returning Execution Revert on eth_call (#2333)
* Removing `name` field from RPC Error when returning Execution Revert error from `eth_call` due to not being compatible with thegraph node, since it does not maps to their RPC Error structure. Signed-off-by: Alfredo Gutierrez <[email protected]> * Fix typo on test Signed-off-by: Alfredo Gutierrez <[email protected]> --------- Signed-off-by: Alfredo Gutierrez <[email protected]>
1 parent 1daf4f5 commit 2908d5f

File tree

4 files changed

+9
-10
lines changed

4 files changed

+9
-10
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ import constants from '../../lib/constants';
2323
export class JsonRpcError {
2424
public code: number;
2525
public message: string;
26-
public name: string;
26+
public name?: string;
2727
public data?: string;
2828

29-
constructor(args: { name: string; code: number; message: string; data?: string }, requestId?: string) {
29+
constructor(args: { name?: string; code: number; message: string; data?: string }, requestId?: string) {
3030
this.code = args.code;
3131
this.name = args.name;
3232
this.message = requestId ? `[${constants.REQUEST_ID_STRING}${requestId}] ` + args.message : args.message;
@@ -37,7 +37,6 @@ export class JsonRpcError {
3737
export const predefined = {
3838
CONTRACT_REVERT: (errorMessage?: string, data: string = '') =>
3939
new JsonRpcError({
40-
name: 'Contract revert executed',
4140
code: -32008,
4241
message: `execution reverted: ${decodeErrorMessage(errorMessage)}`,
4342
data: data,

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ describe('@ethCall Eth Call spec', async function () {
529529

530530
expect(result).to.exist;
531531
expect((result as JsonRpcError).code).to.equal(-32008);
532-
expect((result as JsonRpcError).name).to.equal('Contract revert executed');
532+
expect((result as JsonRpcError).name).to.undefined;
533533
expect((result as JsonRpcError).message).to.equal(`execution reverted: ${defaultErrorMessageText}`);
534534
expect((result as JsonRpcError).data).to.equal(defaultErrorMessageHex);
535535
});
@@ -723,7 +723,7 @@ describe('@ethCall Eth Call spec', async function () {
723723
const result = await ethImpl.call(callData, 'latest');
724724
expect(result).to.be.not.null;
725725
expect((result as JsonRpcError).code).to.eq(-32008);
726-
expect((result as JsonRpcError).name).to.eq('Contract revert executed');
726+
expect((result as JsonRpcError).name).to.undefined;
727727
expect((result as JsonRpcError).message).to.contain(mockData.contractReverted._status.messages[0].message);
728728
});
729729

@@ -774,7 +774,7 @@ describe('@ethCall Eth Call spec', async function () {
774774
sinon.assert.notCalled(sdkClientStub.submitContractCallQueryWithRetry);
775775
expect(result).to.not.be.null;
776776
expect((result as JsonRpcError).code).to.eq(-32008);
777-
expect((result as JsonRpcError).name).to.eq('Contract revert executed');
777+
expect((result as JsonRpcError).name).to.undefined;
778778
expect((result as JsonRpcError).message).to.contain(mockData.contractReverted._status.messages[0].message);
779779
});
780780

@@ -805,7 +805,7 @@ describe('@ethCall Eth Call spec', async function () {
805805

806806
expect(result).to.exist;
807807
expect((result as JsonRpcError).code).to.eq(-32008);
808-
expect((result as JsonRpcError).name).to.eq('Contract revert executed');
808+
expect((result as JsonRpcError).name).to.undefined;
809809
expect((result as JsonRpcError).message).to.equal(`execution reverted: ${defaultErrorMessageText}`);
810810
expect((result as JsonRpcError).data).to.equal(defaultErrorMessageHex);
811811
});

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { Utils } from '../helpers/utils';
2727
// local resources
2828
import reverterContractJson from '../contracts/Reverter.json';
2929
import { EthImpl } from '../../../../packages/relay/src/lib/eth';
30-
import { predefined } from '../../../../packages/relay';
30+
import { JsonRpcError, predefined } from '../../../../packages/relay';
3131
import basicContractJson from '../contracts/Basic.json';
3232
import callerContractJson from '../contracts/Caller.json';
3333
import DeployerContractJson from '../contracts/Deployer.json';
@@ -567,7 +567,7 @@ describe('@api-batch-3 RPC Server Acceptance Tests', function () {
567567
expect(response.data.error).to.exist;
568568
expect(response.data.error.code).to.be.equal(-32008);
569569
expect(response.data.error.message).to.contain('execution reverted: CONTRACT_REVERT_EXECUTED');
570-
expect(response.data.error.name).to.be.equal('Contract revert executed');
570+
expect(response.data.error.name).to.undefined;
571571
});
572572
});
573573

packages/server/tests/clients/relayClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export default class RelayClient {
9494
);
9595
Assertions.expectedError();
9696
} catch (e: any) {
97-
if (expectedRpcError.name === 'Contract revert executed') {
97+
if (expectedRpcError.message.includes('execution reverted')) {
9898
if (e?.info) {
9999
Assertions.jsonRpcError(e.info.error, expectedRpcError);
100100
} else if (e?.error) {

0 commit comments

Comments
 (0)