Skip to content

Commit c91245f

Browse files
authored
Calls with bad data should return an error response (#390)
* Add truffle-relay compatibility * Add license headers * Edit package.json * Edit tests * Add note * Fix sendRawTransaction * Add test * Remove leftover Signed-off-by: nikolay <[email protected]>
1 parent 4d5c201 commit c91245f

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

packages/relay/src/lib/eth.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -657,9 +657,12 @@ export class EthImpl implements Eth {
657657
try {
658658
const gasPrice = await this.getFeeWeibars(EthImpl.ethSendRawTransaction);
659659
await this.precheck.sendRawTransactionCheck(transaction, gasPrice);
660-
}
661-
catch(e: any) {
662-
return e;
660+
} catch (e: any) {
661+
if (e instanceof JsonRpcError) {
662+
return e;
663+
}
664+
665+
throw predefined.INTERNAL_ERROR;
663666
}
664667

665668
const transactionBuffer = Buffer.from(EthImpl.prune0x(transaction), 'hex');

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,6 +1437,24 @@ describe('Eth calls using MirrorNode', async function () {
14371437
expect(result).to.equal("0x00")
14381438
});
14391439
});
1440+
1441+
describe('eth_sendRawTransaction', async function() {
1442+
it('should return a predefined INTERNAL_ERROR instead of NUMERIC_FAULT as precheck exception', async function() {
1443+
// tx with 'gasLimit: BigNumber { value: "30678687678687676876786786876876876000" }'
1444+
const txHash = '0x02f881820128048459682f0086014fa0186f00901714801554cbe52dd95512bedddf68e09405fba803be258049a27b820088bab1cad205887185174876e80080c080a0cab3f53602000c9989be5787d0db637512acdd2ad187ce15ba83d10d9eae2571a07802515717a5a1c7d6fa7616183eb78307b4657d7462dbb9e9deca820dd28f62';
1445+
1446+
let hasError = false;
1447+
mock.onGet('network/fees').reply(200, defaultNetworkFees);
1448+
try {
1449+
await ethImpl.sendRawTransaction(txHash);
1450+
} catch (e) {
1451+
hasError = true;
1452+
expect(e.code).to.equal(-32603);
1453+
expect(e.name).to.equal('Internal error');
1454+
}
1455+
expect(hasError).to.be.true;
1456+
});
1457+
});
14401458
});
14411459

14421460
describe('Eth', async function () {

0 commit comments

Comments
 (0)