Skip to content

Commit c6608dc

Browse files
committed
fix: add extra test for batch2
Signed-off-by: Logan Nguyen <[email protected]>
1 parent 88f7efc commit c6608dc

File tree

1 file changed

+57
-3
lines changed

1 file changed

+57
-3
lines changed

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

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ describe('@api-batch-2 RPC Server Acceptance Tests', function () {
6363
const ONE_WEIBAR = Utils.add0xPrefix(Utils.toHex(ethers.parseUnits('1', 18)));
6464

6565
const BASIC_CONTRACT_PING_CALL_DATA = '0x5c36b186';
66+
const NON_EXISTENT_ACCOUNT = '0x114f60009ee6b84861c0cdae8829751e517bc4d7';
6667
const PING_CALL_ESTIMATED_GAS = '0x6122';
6768
const EXCHANGE_RATE_FILE_ID = '0.0.112';
6869
const EXCHANGE_RATE_FILE_CONTENT_DEFAULT = '0a1008b0ea0110f9bb1b1a0608f0cccf9306121008b0ea0110e9c81a1a060880e9cf9306';
@@ -286,7 +287,7 @@ describe('@api-batch-2 RPC Server Acceptance Tests', function () {
286287
'eth_estimateGas',
287288
[
288289
{
289-
from: '0x114f60009ee6b84861c0cdae8829751e517bc4d7',
290+
from: NON_EXISTENT_ACCOUNT,
290291
to: '0xae410f34f7487e2cd03396499cebb09b79f45',
291292
value: '0xa688906bd8b00000',
292293
gas: '0xd97010',
@@ -305,7 +306,7 @@ describe('@api-batch-2 RPC Server Acceptance Tests', function () {
305306
'eth_estimateGas',
306307
[
307308
{
308-
from: '0x114f60009ee6b84861c0cdae8829751e517bc4d7',
309+
from: NON_EXISTENT_ACCOUNT,
309310
to: '0xae410f34f7487e2cd03396499cebb09b79f45d6e',
310311
value: '123',
311312
gas: '0xd97010',
@@ -324,7 +325,7 @@ describe('@api-batch-2 RPC Server Acceptance Tests', function () {
324325
'eth_estimateGas',
325326
[
326327
{
327-
from: '0x114f60009ee6b84861c0cdae8829751e517bc4d7',
328+
from: NON_EXISTENT_ACCOUNT,
328329
to: '0xae410f34f7487e2cd03396499cebb09b79f45d6e',
329330
value: '0xa688906bd8b00000',
330331
gas: '123',
@@ -460,6 +461,59 @@ describe('@api-batch-2 RPC Server Acceptance Tests', function () {
460461
);
461462
});
462463
});
464+
465+
describe('Gas estimation errors (non-contract revert)', async function () {
466+
it('should throw COULD_NOT_ESTIMATE_GAS_PRICE error when sender account does not exist', async function () {
467+
const promise = relay.call(RelayCalls.ETH_ENDPOINTS.ETH_ESTIMATE_GAS, [
468+
{
469+
from: NON_EXISTENT_ACCOUNT,
470+
to: basicContractAddress,
471+
data: BASIC_CONTRACT_PING_CALL_DATA,
472+
},
473+
]);
474+
475+
await expect(promise).to.eventually.be.rejected.and.satisfy((error: any) => {
476+
const errorBody = error?.response?.bodyJson?.error;
477+
return (
478+
errorBody &&
479+
errorBody.code === -32000 &&
480+
errorBody.message.includes('Error occurred during gas price estimation') &&
481+
errorBody.message.includes('Sender account not found')
482+
);
483+
});
484+
});
485+
486+
it('should throw COULD_NOT_ESTIMATE_GAS_PRICE error when "to" field is empty for contract call', async function () {
487+
const promise = relay.call(RelayCalls.ETH_ENDPOINTS.ETH_ESTIMATE_GAS, [
488+
{
489+
from: accounts[0].address,
490+
data: BASIC_CONTRACT_PING_CALL_DATA,
491+
},
492+
]);
493+
494+
await expect(promise).to.eventually.be.rejected.and.satisfy((error: any) => {
495+
const errorBody = error?.response?.bodyJson?.error;
496+
return (
497+
errorBody &&
498+
errorBody.code === -32000 &&
499+
errorBody.message.includes('Error occurred during gas price estimation')
500+
);
501+
});
502+
});
503+
504+
it('should throw error when gas estimation fails with invalid transaction value', async function () {
505+
// Using a string that can't be converted to a valid hex value
506+
const promise = relay.call(RelayCalls.ETH_ENDPOINTS.ETH_ESTIMATE_GAS, [
507+
{
508+
from: accounts[0].address,
509+
to: accounts[1].address,
510+
value: 'invalid_value',
511+
},
512+
]);
513+
514+
await expect(promise).to.eventually.be.rejected;
515+
});
516+
});
463517
});
464518

465519
describe('eth_gasPrice', async function () {

0 commit comments

Comments
 (0)