Skip to content

Commit

Permalink
fix call return data format
Browse files Browse the repository at this point in the history
  • Loading branch information
shunjizhan committed Oct 24, 2024
1 parent d0ae77a commit 0653048
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
14 changes: 7 additions & 7 deletions packages/eth-providers/src/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,14 +447,14 @@ describe('eth call error handling', () => {

describe('checkEvmExecutionError', () => {
const commonData = {
used_gas: '0x0',
used_storage: 0,
usedGas: '0x0',
usedStorage: 0,
logs: [],
};

it('when should throw - reverted', () => {
const data = {
exit_reason: { revert: 'Reverted' as const },
exitReason: { revert: 'Reverted' as const },
value: invalidCurrencyIdHex,
...commonData,
};
Expand All @@ -464,7 +464,7 @@ describe('eth call error handling', () => {

it('when should throw - outOfFund', () => {
const data = {
exit_reason: {
exitReason: {
error: { outOfFund: null },
},
value: invalidCurrencyIdHex,
Expand All @@ -476,7 +476,7 @@ describe('eth call error handling', () => {

it('when should throw - ExistentialDeposit', () => {
const data = {
exit_reason: {
exitReason: {
error: { other: 'ExistentialDeposit' },
},
value: invalidCurrencyIdHex,
Expand All @@ -489,7 +489,7 @@ describe('eth call error handling', () => {
it('when should not throw', () => {
{
const data = {
exit_reason: { succeed: 'Returned' as const },
exitReason: { succeed: 'Returned' as const },
value: '0x123456789',
...commonData,
};
Expand All @@ -498,7 +498,7 @@ describe('eth call error handling', () => {

{
const data = {
exit_reason: { succeed: 'Stopped' as const },
exitReason: { succeed: 'Stopped' as const },
value: '0x',
...commonData,
};
Expand Down
21 changes: 12 additions & 9 deletions packages/eth-providers/src/base-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,15 +266,15 @@ export interface PollFilters {
}

export interface CallReturnInfo {
exit_reason: {
exitReason: {
succeed?: 'Stopped' | 'Returned' | 'Suicided';
error?: any;
revert?: 'Reverted';
fatal?: any;
};
value: string;
used_gas: string;
used_storage: number;
usedGas: string;
usedStorage: number;
logs: Log[];
}

Expand Down Expand Up @@ -839,18 +839,21 @@ export abstract class BaseProvider extends AbstractProvider {
return res.value;
};

_ethCall = async (callRequest: SubstrateEvmCallRequest, at?: string) => {
_ethCall = async (
callRequest: SubstrateEvmCallRequest,
at?: string,
): Promise<CallReturnInfo> => {
const api = at ? await this.api.at(at) : this.api;

// call evm rpc when `state_call` is not supported yet
if (!api.call.evmRuntimeRPCApi) {
const data = await this.api.rpc.evm.call(callRequest);

return {
exit_reason: { succeed: 'Returned' },
exitReason: { succeed: 'Returned' },
value: data.toHex(),
used_gas: '0',
used_storage: 0,
usedGas: '0',
usedStorage: 0,
logs: [],
};
}
Expand Down Expand Up @@ -1120,8 +1123,8 @@ export abstract class BaseProvider extends AbstractProvider {
};

const gasInfo = await this._ethCall(txRequest, blockHash);
const usedGas = BigNumber.from(gasInfo.used_gas).toNumber();
const usedStorage = gasInfo.used_storage;
const usedGas = BigNumber.from(gasInfo.usedGas).toNumber();
const usedStorage = gasInfo.usedStorage;

/* ----------
try using a gasLimit slightly more than actual used gas
Expand Down
2 changes: 1 addition & 1 deletion packages/eth-providers/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ export const decodeRevertMsg = (hexMsg: string) => {
export const checkEvmExecutionError = (data: CallReturnInfo): void => {
if (!data) return;

const { exit_reason: exitReason, value: returnData } = data;
const { exitReason, value: returnData } = data;
if (!exitReason.succeed) {
let msg: string;
let err: any;
Expand Down

0 comments on commit 0653048

Please sign in to comment.