Skip to content

Commit 109a084

Browse files
committed
fix: renamed COULD_NOT_ESTIMATE_GAS_PRICE to COULD_NOT_SIMULATE_TRANSACTION
Signed-off-by: Logan Nguyen <[email protected]>
1 parent 09adb23 commit 109a084

File tree

6 files changed

+37
-33
lines changed

6 files changed

+37
-33
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,10 @@ export const predefined = {
196196
message: message,
197197
});
198198
},
199-
COULD_NOT_ESTIMATE_GAS_PRICE: (errMessage: string) => {
199+
COULD_NOT_SIMULATE_TRANSACTION: (errMessage: string) => {
200200
return new JsonRpcError({
201201
code: -32000,
202-
message: `Error occurred during gas price estimation: ${errMessage}`,
202+
message: `Error occurred during transaction simulation: ${errMessage}`,
203203
});
204204
},
205205
COULD_NOT_RETRIEVE_LATEST_BLOCK: new JsonRpcError({

packages/relay/src/lib/services/ethService/contractService/ContractService.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,12 @@ export class ContractService implements IContractService {
180180
if (e.isContractRevert()) {
181181
throw predefined.CONTRACT_REVERT(e.detail || e.message, e.data);
182182
} else if (e.statusCode === 400) {
183-
throw predefined.COULD_NOT_ESTIMATE_GAS_PRICE(e.detail || e.message);
183+
throw predefined.COULD_NOT_SIMULATE_TRANSACTION(e.detail || e.message);
184184
}
185185
}
186186

187-
// for any other errors, preserve and re-throw to the upper layer as more mapping logic may be applied there
187+
// for any other error or Mirror Node upstream server errors (429, 500, 502, 503, 504, etc.),
188+
// preserve the original error and re-throw to the upper layer for further handling logic
188189
throw e;
189190
}
190191
}

packages/relay/src/lib/services/ethService/ethCommonService/CommonService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ export class CommonService implements ICommonService {
458458
}
459459
}
460460

461-
throw predefined.COULD_NOT_ESTIMATE_GAS_PRICE('Failed to retrieve gas price from network fees');
461+
throw predefined.COULD_NOT_SIMULATE_TRANSACTION('Failed to retrieve gas price from network fees');
462462
}
463463

464464
/**

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

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ describe('@ethEstimateGas Estimate Gas spec', async function () {
6262
};
6363
const id = uuid();
6464
const defaultGasOverride = constants.TX_DEFAULT_GAS_DEFAULT + 1;
65-
const gasPriceErrorMessage = 'Error occurred during gas price estimation';
65+
const simulationFailErrorMessage = 'Error occurred during transaction simulation';
6666

6767
overrideEnvsInMochaDescribe({
6868
ETH_GET_TRANSACTION_COUNT_MAX_BLOCK_RANGE: 1,
@@ -94,7 +94,7 @@ describe('@ethEstimateGas Estimate Gas spec', async function () {
9494

9595
describe('eth_estimateGas with contract call', async function () {});
9696

97-
it('should eth_estimateGas with transaction.data null throws COULD_NOT_ESTIMATE_GAS_PRICE error on 400', async function () {
97+
it('should eth_estimateGas with transaction.data null throws COULD_NOT_SIMULATE_TRANSACTION error on 400', async function () {
9898
const callData: IContractCallRequest = {
9999
from: '0x05fba803be258049a27b820088bab1cad2058871',
100100
value: '0x0',
@@ -105,11 +105,11 @@ describe('@ethEstimateGas Estimate Gas spec', async function () {
105105

106106
await expect(ethImpl.estimateGas(callData, null, requestDetails)).to.be.rejectedWith(
107107
JsonRpcError,
108-
gasPriceErrorMessage,
108+
simulationFailErrorMessage,
109109
);
110110
});
111111

112-
it('should eth_estimateGas to mirror node for contract call returns 400 throws COULD_NOT_ESTIMATE_GAS_PRICE error', async function () {
112+
it('should eth_estimateGas to mirror node for contract call returns 400 throws COULD_NOT_SIMULATE_TRANSACTION error', async function () {
113113
const callData: IContractCallRequest = {
114114
data: '0x608060405234801561001057600080fd5b506040516107893803806107898339818101604052810190610032919061015a565b806000908051906020019061004892919061004f565b50506102f6565b82805461005b90610224565b90600052602060002090601f01602090048101928261007d57600085556100c4565b82601f1061009657805160ff19168380011785556100c4565b828001600101855582156100c4579182015b828111156100c35782518255916020019190600101906100a8565b5b5090506100d191906100d5565b5090565b5b808211156100ee5760008160009055506001016100d6565b5090565b6000610105610100846101c0565b61019b565b90508281526020810184848401111561011d57600080fd5b6101288482856101f1565b509392505050565b600082601f83011261014157600080fd5b81516101518482602086016100f2565b91505092915050565b60006020828403121561016c57600080fd5b600082015167ffffffffffffffff81111561018657600080fd5b61019284828501610130565b91505092915050565b60006101a56101b6565b90506101b18282610256565b919050565b6000604051905090565b600067ffffffffffffffff8211156101db576101da6102b6565b5b6101e4826102e5565b9050602081019050919050565b60005b8381101561020f5780820151818401526020810190506101f4565b8381111561021e576000848401525b50505050565b6000600282049050600182168061023c57607f821691505b602082108114156102505761024f610287565b5b50919050565b61025f826102e5565b810181811067ffffffffffffffff8211171561027e5761027d6102b6565b5b80604052505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000601f19601f8301169050919050565b610484806103056000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c8063a41368621461003b578063cfae321714610057575b600080fd5b6100556004803603810190610050919061022c565b610075565b005b61005f61008f565b60405161006c91906102a6565b60405180910390f35b806000908051906020019061008b929190610121565b5050565b60606000805461009e9061037c565b80601f01602080910402602001604051908101604052809291908181526020018280546100ca9061037c565b80156101175780601f106100ec57610100808354040283529160200191610117565b820191906000526020600020905b8154815290600101906020018083116100fa57829003601f168201915b5050505050905090565b82805461012d9061037c565b90600052602060002090601f01602090048101928261014f5760008555610196565b82601f1061016857805160ff1916838001178555610196565b82800160010185558215610196579182015b8281111561019557825182559160200191906001019061017a565b5b5090506101a391906101a7565b5090565b5b808211156101c05760008160009055506001016101a8565b5090565b60006101d76101d2846102ed565b6102c8565b9050828152602081018484840111156101ef57600080fd5b6101fa84828561033a565b509392505050565b600082601f83011261021357600080fd5b81356102238482602086016101c4565b91505092915050565b60006020828403121561023e57600080fd5b600082013567ffffffffffffffff81111561025857600080fd5b61026484828501610202565b91505092915050565b60006102788261031e565b6102828185610329565b9350610292818560208601610349565b61029b8161043d565b840191505092915050565b600060208201905081810360008301526102c0818461026d565b905092915050565b60006102d26102e3565b90506102de82826103ae565b919050565b6000604051905090565b600067ffffffffffffffff8211156103085761030761040e565b5b6103118261043d565b9050602081019050919050565b600081519050919050565b600082825260208201905092915050565b82818337600083830152505050565b60005b8381101561036757808201518184015260208101905061034c565b83811115610376576000848401525b50505050565b6000600282049050600182168061039457607f821691505b602082108114156103a8576103a76103df565b5b50919050565b6103b78261043d565b810181811067ffffffffffffffff821117156103d6576103d561040e565b5b80604052505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000601f19601f830116905091905056fea264697066735822122070d157c4efbb3fba4a1bde43cbba5b92b69f2fc455a650c0dfb61e9ed3d4bd6364736f6c634300080400330000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000b696e697469616c5f6d7367000000000000000000000000000000000000000000',
115115
from: '0x81cb089c285e5ee3a7353704fb114955037443af',
@@ -119,7 +119,7 @@ describe('@ethEstimateGas Estimate Gas spec', async function () {
119119

120120
await expect(ethImpl.estimateGas(callData, null, requestDetails)).to.be.rejectedWith(
121121
JsonRpcError,
122-
gasPriceErrorMessage,
122+
simulationFailErrorMessage,
123123
);
124124
});
125125

@@ -146,19 +146,19 @@ describe('@ethEstimateGas Estimate Gas spec', async function () {
146146
expect((gas as string).toLowerCase()).to.equal(numberTo0x(constants.TX_DEFAULT_GAS_DEFAULT).toLowerCase());
147147
});
148148

149-
it('should eth_estimateGas for contract deploy throws COULD_NOT_ESTIMATE_GAS_PRICE error on 400', async function () {
149+
it('should eth_estimateGas for contract deploy throws COULD_NOT_SIMULATE_TRANSACTION error on 400', async function () {
150150
const callData: IContractCallRequest = {
151151
data: '0x01',
152152
};
153153
await mockContractCall(callData, true, 400, { errorMessage: '', statusCode: 400 }, requestDetails);
154154

155155
await expect(ethImpl.estimateGas({ data: '0x01' }, null, requestDetails)).to.be.rejectedWith(
156156
JsonRpcError,
157-
gasPriceErrorMessage,
157+
simulationFailErrorMessage,
158158
);
159159
});
160160

161-
it('should eth_estimateGas to mirror node for transfer throws COULD_NOT_ESTIMATE_GAS_PRICE error on 400', async function () {
161+
it('should eth_estimateGas to mirror node for transfer throws COULD_NOT_SIMULATE_TRANSACTION error on 400', async function () {
162162
const callData: IContractCallRequest = {
163163
from: '0x81cb089c285e5ee3a7353704fb114955037443af',
164164
to: RECEIVER_ADDRESS,
@@ -172,11 +172,11 @@ describe('@ethEstimateGas Estimate Gas spec', async function () {
172172

173173
await expect(ethImpl.estimateGas(callData, null, requestDetails)).to.be.rejectedWith(
174174
JsonRpcError,
175-
gasPriceErrorMessage,
175+
simulationFailErrorMessage,
176176
);
177177
});
178178

179-
it('should eth_estimateGas to mirror node for transfer without value throws COULD_NOT_ESTIMATE_GAS_PRICE error on 400', async function () {
179+
it('should eth_estimateGas to mirror node for transfer without value throws COULD_NOT_SIMULATE_TRANSACTION error on 400', async function () {
180180
const callData: IContractCallRequest = {
181181
from: '0x81cb089c285e5ee3a7353704fb114955037443af',
182182
to: RECEIVER_ADDRESS,
@@ -187,7 +187,7 @@ describe('@ethEstimateGas Estimate Gas spec', async function () {
187187

188188
await expect(ethImpl.estimateGas(callData, null, requestDetails)).to.be.rejectedWith(
189189
JsonRpcError,
190-
gasPriceErrorMessage,
190+
simulationFailErrorMessage,
191191
);
192192
});
193193

@@ -306,7 +306,7 @@ describe('@ethEstimateGas Estimate Gas spec', async function () {
306306
expect((gas as string).toLowerCase()).to.equal(numberTo0x(gasEstimation).toLowerCase());
307307
});
308308

309-
it('should eth_estimateGas transfer with invalid value throws COULD_NOT_ESTIMATE_GAS_PRICE error on 400', async function () {
309+
it('should eth_estimateGas transfer with invalid value throws COULD_NOT_SIMULATE_TRANSACTION error on 400', async function () {
310310
const callData: IContractCallRequest = {
311311
to: RECEIVER_ADDRESS,
312312
value: -100_000_000_000, //in tinybars
@@ -325,14 +325,17 @@ describe('@ethEstimateGas Estimate Gas spec', async function () {
325325
null,
326326
requestDetails,
327327
),
328-
).to.be.rejectedWith(JsonRpcError, gasPriceErrorMessage);
328+
).to.be.rejectedWith(JsonRpcError, simulationFailErrorMessage);
329329
});
330330

331-
it('should eth_estimateGas empty call throws COULD_NOT_ESTIMATE_GAS_PRICE error on 400', async function () {
331+
it('should eth_estimateGas empty call throws COULD_NOT_SIMULATE_TRANSACTION error on 400', async function () {
332332
const callData: IContractCallRequest = {};
333333
await mockContractCall(callData, true, 400, { errorMessage: '', statusCode: 400 }, requestDetails);
334334

335-
await expect(ethImpl.estimateGas({}, null, requestDetails)).to.be.rejectedWith(JsonRpcError, gasPriceErrorMessage);
335+
await expect(ethImpl.estimateGas({}, null, requestDetails)).to.be.rejectedWith(
336+
JsonRpcError,
337+
simulationFailErrorMessage,
338+
);
336339
});
337340

338341
it('should eth_estimateGas empty call returns transfer cost with overridden default gas', async function () {
@@ -343,7 +346,7 @@ describe('@ethEstimateGas Estimate Gas spec', async function () {
343346
expect(gas).to.equal(numberTo0x(defaultGasOverride));
344347
});
345348

346-
it('should eth_estimateGas empty input throws COULD_NOT_ESTIMATE_GAS_PRICE error on 400', async function () {
349+
it('should eth_estimateGas empty input throws COULD_NOT_SIMULATE_TRANSACTION error on 400', async function () {
347350
const callData: IContractCallRequest = {
348351
data: '',
349352
estimate: true,
@@ -354,19 +357,19 @@ describe('@ethEstimateGas Estimate Gas spec', async function () {
354357

355358
await expect(ethImpl.estimateGas({ data: '' }, null, requestDetails)).to.be.rejectedWith(
356359
JsonRpcError,
357-
gasPriceErrorMessage,
360+
simulationFailErrorMessage,
358361
);
359362
});
360363

361-
it('should eth_estimateGas empty input throws COULD_NOT_ESTIMATE_GAS_PRICE error on 400 with overridden default gas', async function () {
364+
it('should eth_estimateGas empty input throws COULD_NOT_SIMULATE_TRANSACTION error on 400 with overridden default gas', async function () {
362365
const callData: IContractCallRequest = {
363366
data: '',
364367
};
365368
await mockContractCall(callData, true, 400, { errorMessage: '', statusCode: 400 }, requestDetails);
366369

367370
await expect(ethImplOverridden.estimateGas({ data: '' }, null, requestDetails)).to.be.rejectedWith(
368371
JsonRpcError,
369-
gasPriceErrorMessage,
372+
simulationFailErrorMessage,
370373
);
371374
});
372375

@@ -391,15 +394,15 @@ describe('@ethEstimateGas Estimate Gas spec', async function () {
391394
expect(gas).to.equal(gasTxBaseCost);
392395
});
393396

394-
it('should eth_estimateGas zero input throws COULD_NOT_ESTIMATE_GAS_PRICE error on 400 with overridden default gas', async function () {
397+
it('should eth_estimateGas zero input throws COULD_NOT_SIMULATE_TRANSACTION error on 400 with overridden default gas', async function () {
395398
const callData: IContractCallRequest = {
396399
gas: '0x0',
397400
};
398401
await mockContractCall(callData, true, 400, { errorMessage: '', statusCode: 400 }, requestDetails);
399402

400403
await expect(ethImplOverridden.estimateGas(callData, null, requestDetails)).to.be.rejectedWith(
401404
JsonRpcError,
402-
gasPriceErrorMessage,
405+
simulationFailErrorMessage,
403406
);
404407
});
405408

@@ -419,7 +422,7 @@ describe('@ethEstimateGas Estimate Gas spec', async function () {
419422

420423
await expect(ethImpl.estimateGas(transaction, id, requestDetails)).to.be.rejectedWith(
421424
JsonRpcError,
422-
gasPriceErrorMessage,
425+
simulationFailErrorMessage,
423426
);
424427
});
425428

@@ -519,7 +522,7 @@ describe('@ethEstimateGas Estimate Gas spec', async function () {
519522
});
520523
});
521524

522-
it('should eth_estimateGas handles a 400 response from the mirror node correctly by throwing COULD_NOT_ESTIMATE_GAS_PRICE error', async function () {
525+
it('should eth_estimateGas handles a 400 response from the mirror node correctly by throwing COULD_NOT_SIMULATE_TRANSACTION error', async function () {
523526
const callData: IContractCallRequest = {
524527
from: '0x05fba803be258049a27b820088bab1cad2058871',
525528
value: '0x1',
@@ -545,7 +548,7 @@ describe('@ethEstimateGas Estimate Gas spec', async function () {
545548

546549
await expect(ethImpl.estimateGas(callData, null, requestDetails)).to.be.rejectedWith(
547550
JsonRpcError,
548-
gasPriceErrorMessage,
551+
simulationFailErrorMessage,
549552
);
550553
});
551554

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ describe('@ethGasPrice Gas Price spec', async function () {
8484

8585
restMock.onGet(`network/fees`).reply(200, JSON.stringify(partialNetworkFees));
8686
await RelayAssertions.assertRejection(
87-
predefined.COULD_NOT_ESTIMATE_GAS_PRICE('Failed to retrieve gas price from network fees'),
87+
predefined.COULD_NOT_SIMULATE_TRANSACTION('Failed to retrieve gas price from network fees'),
8888
ethImpl.gasPrice,
8989
true,
9090
ethImpl,
@@ -140,7 +140,7 @@ describe('@ethGasPrice Gas Price spec', async function () {
140140

141141
it('eth_gasPrice with no network fees records found', async function () {
142142
await RelayAssertions.assertRejection(
143-
predefined.COULD_NOT_ESTIMATE_GAS_PRICE('Failed to retrieve gas price from network fees'),
143+
predefined.COULD_NOT_SIMULATE_TRANSACTION('Failed to retrieve gas price from network fees'),
144144
ethImpl.gasPrice,
145145
true,
146146
ethImpl,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ describe('@api-batch-2 RPC Server Acceptance Tests', function () {
463463
});
464464

465465
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 () {
466+
it('should throw COULD_NOT_SIMULATE_TRANSACTION error when sender account does not exist', async function () {
467467
const promise = relay.call(RelayCalls.ETH_ENDPOINTS.ETH_ESTIMATE_GAS, [
468468
{
469469
from: NON_EXISTENT_ACCOUNT,
@@ -483,7 +483,7 @@ describe('@api-batch-2 RPC Server Acceptance Tests', function () {
483483
});
484484
});
485485

486-
it('should throw COULD_NOT_ESTIMATE_GAS_PRICE error when "to" field is empty for contract call', async function () {
486+
it('should throw COULD_NOT_SIMULATE_TRANSACTION error when "to" field is empty for contract call', async function () {
487487
const promise = relay.call(RelayCalls.ETH_ENDPOINTS.ETH_ESTIMATE_GAS, [
488488
{
489489
from: accounts[0].address,

0 commit comments

Comments
 (0)