Skip to content

Commit

Permalink
fix: Removed the contract revert reason from the eth_getTransactionBy…
Browse files Browse the repository at this point in the history
…Hash. (#1979)

* fix: Removed the contract revert reason from the eth_getTransactionByHash.

Signed-off-by: ebadiere <[email protected]>

* fix: removed test that no longer needed.

Signed-off-by: ebadiere <[email protected]>

* fix: Removed eth_getTransactionByHash test that tested contract revert reasons.

Signed-off-by: ebadiere <[email protected]>

---------

Signed-off-by: ebadiere <[email protected]>
  • Loading branch information
ebadiere authored Dec 14, 2023
1 parent 4ce2a41 commit 25965a2
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 116 deletions.
9 changes: 0 additions & 9 deletions packages/relay/src/lib/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1752,15 +1752,6 @@ export class EthImpl implements Eth {
const fromAddress = await this.resolveEvmAddress(contractResult.from, requestIdPrefix, [constants.TYPE_ACCOUNT]);
const toAddress = await this.resolveEvmAddress(contractResult.to, requestIdPrefix);

if (
process.env.DEV_MODE &&
process.env.DEV_MODE === 'true' &&
contractResult.result === 'CONTRACT_REVERT_EXECUTED'
) {
const err = predefined.CONTRACT_REVERT(contractResult.error_message, contractResult.error_message);
throw err;
}

return formatContractResult({
...contractResult,
from: fromAddress,
Expand Down
19 changes: 0 additions & 19 deletions packages/relay/tests/lib/eth/eth_getTransactionByHash.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,25 +280,6 @@ describe('@ethGetTransactionByHash eth_getTransactionByHash tests', async functi
});
});

it('throws error for reverted transactions when DEV_MODE=true', async function () {
const initialDevModeValue = process.env.DEV_MODE;
process.env.DEV_MODE = 'true';

const uniqueTxHash = '0xa8cad7b827375d12d73af57b6a3f84353645fd31305ea58ff52dda53ec640533';
restMock.onGet(`contracts/results/${uniqueTxHash}`).reply(200, DEFAULT_DETAILED_CONTRACT_RESULT_BY_HASH_REVERTED);
const args = [uniqueTxHash];
const errMessage = DEFAULT_DETAILED_CONTRACT_RESULT_BY_HASH_REVERTED.error_message;
const data = DEFAULT_DETAILED_CONTRACT_RESULT_BY_HASH_REVERTED.error_message;
await RelayAssertions.assertRejection(
predefined.CONTRACT_REVERT(errMessage, data),
ethImpl.getTransactionByHash,
true,
ethImpl,
args,
);
process.env.DEV_MODE = initialDevModeValue;
});

it('returns synthetic transaction when it matches cache', async function () {
// prepare cache with synthetic log
const cacheKeySyntheticLog = `${constants.CACHE_KEY.SYNTHETIC_LOG_TRANSACTION_HASH}${defaultDetailedContractResultByHash.hash}`;
Expand Down
88 changes: 0 additions & 88 deletions packages/server/tests/acceptance/rpc_batch3.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -561,94 +561,6 @@ describe('@api-batch-3 RPC Server Acceptance Tests', function () {
expect(receipt.revertReason).to.eq(PAYABLE_METHOD_ERROR_DATA);
});

describe('eth_getTransactionByHash for reverted payable contract calls', async function () {
const payableMethodsData = [
{
data: '0xfe0a3dd7',
method: 'revertWithNothing',
message: '',
errorData: '0x',
},
{
data: '0x0323d234',
method: 'revertWithString',
message: 'Some revert message',
errorData:
'0x08c379a000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000013536f6d6520726576657274206d65737361676500000000000000000000000000',
},
{
data: '0x46fc4bb1',
method: 'revertWithCustomError',
message: '',
errorData: '0x0bd3d39c',
},
{
data: '0x33fe3fbd',
method: 'revertWithPanic',
message: '',
errorData: '0x4e487b710000000000000000000000000000000000000000000000000000000000000012',
},
];
const hashes: any = [];

beforeEach(async () => {
requestId = Utils.generateRequestId();
});

before(async function () {
for (const element of payableMethodsData) {
const transaction = {
// value: ONE_TINYBAR,
gasLimit: numberTo0x(30000),
chainId: Number(CHAIN_ID),
to: reverterEvmAddress,
nonce: await relay.getAccountNonce(accounts[0].address, requestId),
maxFeePerGas: await relay.gasPrice(requestId),
data: element.data,
};
const signedTx = await accounts[0].wallet.signTransaction(transaction);
const hash = await relay.sendRawTransaction(signedTx, requestId);
hashes.push(hash);

// Wait until receipt is available in mirror node
await mirrorNode.get(`/contracts/results/${hash}`, requestId);
}
});

for (let i = 0; i < payableMethodsData.length; i++) {
it(`Payable method ${payableMethodsData[i].method} returns tx object`, async function () {
const tx = await relay.call(RelayCall.ETH_ENDPOINTS.ETH_GET_TRANSACTION_BY_HASH, [hashes[i]], requestId);
expect(tx).to.exist;
expect(tx.hash).to.exist;
expect(tx.hash).to.eq(hashes[i]);
});
}

// skip this test if using a remote relay since updating the env vars would not affect it
if (global.relayIsLocal) {
describe('DEV_MODE = true', async function () {
before(async () => {
process.env.DEV_MODE = 'true';
});

after(async () => {
process.env.DEV_MODE = 'false';
});

for (let i = 0; i < payableMethodsData.length; i++) {
it(`Payable method ${payableMethodsData[i].method} throws an error`, async function () {
await relay.callFailing(
RelayCall.ETH_ENDPOINTS.ETH_GET_TRANSACTION_BY_HASH,
[hashes[i]],
predefined.CONTRACT_REVERT(payableMethodsData[i].message, payableMethodsData[i].errorData),
requestId,
);
});
}
});
}
});

describe('eth_call for reverted pure contract calls', async function () {
beforeEach(async () => {
requestId = Utils.generateRequestId();
Expand Down

0 comments on commit 25965a2

Please sign in to comment.