Skip to content

Commit 3efdcad

Browse files
authored
fix: eth_getTransactionByHash correct response parsing (#4331)
Signed-off-by: Stanimir Stoyanov <[email protected]>
1 parent e3a961b commit 3efdcad

File tree

16 files changed

+27
-20
lines changed

16 files changed

+27
-20
lines changed

packages/relay/src/formatters.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ const tinybarsToWeibars = (value: number | null, allowNegativeValues: boolean =
258258
if (value && value > constants.TOTAL_SUPPLY_TINYBARS)
259259
throw new Error('Value cannot be more than the total supply of tinybars in the blockchain');
260260

261-
return value == null ? null : value * constants.TINYBAR_TO_WEIBAR_COEF;
261+
return value == null ? null : BigInt(value) * BigInt(constants.TINYBAR_TO_WEIBAR_COEF);
262262
};
263263

264264
export {

packages/relay/src/lib/factories/transactionFactory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export const createTransactionFromContractResult = (cr: any): Transaction | null
101101
blockHash: toHash32(cr.block_hash),
102102
blockNumber: nullableNumberTo0x(cr.block_number),
103103
from: cr.from.substring(0, 42),
104-
gas: nanOrNumberTo0x(cr.gas_used),
104+
gas: nanOrNumberTo0x(cr.gas_limit),
105105
gasPrice,
106106
hash: cr.hash.substring(0, 66),
107107
input: cr.function_parameters,

packages/relay/tests/helpers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ export const blockTransactionCount = 77;
367367
export const gasUsed1 = 200000;
368368
export const gasUsed2 = 800000;
369369
export const maxGasLimit = 250000;
370+
export const maxGasLimit2 = maxGasLimit - 1000;
370371
export const firstTransactionTimestampSeconds = '1653077541';
371372
export const contractAddress1 = '0x000000000000000000000000000000000000055f';
372373
export const contractTimestamp1 = `${firstTransactionTimestampSeconds}.983983199`;
@@ -466,7 +467,7 @@ export const defaultContractResults = {
466467
from: LONG_ZERO_ADDRESS,
467468
function_parameters:
468469
'0x2b6adf430000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000084865792c204d6121000000000000000000000000000000000000000000000000',
469-
gas_limit: maxGasLimit - 1000,
470+
gas_limit: maxGasLimit2,
470471
gas_used: gasUsed2,
471472
hash: contractHash2,
472473
timestamp: `${contractTimestamp2}`,

packages/relay/tests/lib/eth/eth-config.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
export const BLOCK_TRANSACTION_COUNT = 77;
1919
export const GAS_USED_1 = 200000;
2020
export const GAS_USED_2 = 800000;
21+
export const GAS_LIMIT = 1_000_000;
2122
export const GAS_USED_RATIO = 0.5;
2223
export const BLOCK_NUMBER = 3;
2324
export const BLOCK_NUMBER_2 = 4;
@@ -106,7 +107,9 @@ export const ETH_FEE_HISTORY_VALUE = ConfigService.get('ETH_FEE_HISTORY_FIXED');
106107
export const BLOCK_HASH_PREV_TRIMMED = '0xf7d6481f659c866c35391ee230c374f163642ebf13a5e604e04a95a9ca48a298';
107108
export const BLOCK_NUMBER_HEX = `0x${BLOCK_NUMBER.toString(16)}`;
108109
export const MAX_GAS_LIMIT = 250000;
110+
export const MAX_GAS_LIMIT2 = MAX_GAS_LIMIT - 1000;
109111
export const MAX_GAS_LIMIT_HEX = numberTo0x(MAX_GAS_LIMIT);
112+
export const MAX_GAS_LIMIT2_HEX = numberTo0x(MAX_GAS_LIMIT2);
110113
export const BLOCK_TIMESTAMP_HEX = numberTo0x(Number(BLOCK_TIMESTAMP));
111114
export const NO_TRANSACTIONS = '?transactions=false';
112115
export const FIRST_TRX_TIMESTAMP_SEC = '1653077541';
@@ -596,7 +599,7 @@ export const DEFAULT_TRANSACTION = {
596599
blockNumber: '0x11',
597600
chainId: '0x12a',
598601
from: `${defaultEvmAddress}`,
599-
gas: '0x7b',
602+
gas: '0xf4240',
600603
gasPrice: '0xad78ebc5ac620000',
601604
hash: DEFAULT_TX_HASH,
602605
input: '0x0707',

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,13 @@ import {
5454
DEFAULT_LOGS,
5555
DEFAULT_NETWORK_FEES,
5656
GAS_USED_1,
57-
GAS_USED_2,
5857
LATEST_BLOCK_QUERY,
5958
LATEST_BLOCK_RESPONSE,
6059
LINKS_NEXT_RES,
6160
LOG_QUERY,
6261
LOGS_RESPONSE_MOCK,
62+
MAX_GAS_LIMIT_HEX,
63+
MAX_GAS_LIMIT2_HEX,
6364
MOST_RECENT_BLOCK,
6465
NO_SUCH_BLOCK_EXISTS_RES,
6566
NOT_FOUND_RES,
@@ -107,8 +108,9 @@ describe('@ethGetBlockByNumber using MirrorNode', async function () {
107108
function verifyTransactions(transactions: Array<Transaction>) {
108109
expect(transactions.length).equal(2);
109110
expect(transactions[0].hash).equal(CONTRACT_HASH_1);
111+
expect(transactions[0].gas).equal(MAX_GAS_LIMIT_HEX);
110112
expect(transactions[1].hash).equal(CONTRACT_HASH_2);
111-
expect(transactions[1].gas).equal(hashNumber(GAS_USED_2));
113+
expect(transactions[1].gas).equal(MAX_GAS_LIMIT2_HEX);
112114
}
113115

114116
overrideEnvsInMochaDescribe({ ETH_GET_TRANSACTION_COUNT_MAX_BLOCK_RANGE: 1 });

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ describe('@ethGetTransactionByHash eth_getTransactionByHash tests', async functi
234234
it('handles transactions with null gas_used', async function () {
235235
const detailedResultsWithNullNullableValues = {
236236
...defaultDetailedContractResultByHash,
237-
gas_used: null,
237+
gas_limit: null,
238238
};
239239
const uniqueTxHash = '0x14aad7b827375d12d73af57b6a3e84353645fd31305ea58ff52dda53ec640533';
240240

packages/relay/tests/lib/factories/transactionFactory.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('TransactionFactory', () => {
3030
);
3131
expect(formattedResult.chainId).to.equal('0x12a');
3232
expect(formattedResult.from).to.equal('0x05fba803be258049a27b820088bab1cad2058871');
33-
expect(formattedResult.gas).to.equal(expectedValues.gas ?? '0x61a80');
33+
expect(formattedResult.gas).to.equal(expectedValues.gas ?? '0x7a120');
3434
expect(formattedResult.gasPrice).to.equal(expectedValues.gasPrice ?? '0x0');
3535
expect(formattedResult.hash).to.equal('0xfc4ab7133197016293d2e14e8cf9c5227b07357e6385184f1cd1cb40d783cfbd');
3636
expect(formattedResult.input).to.equal('0x08090033');
@@ -57,6 +57,7 @@ describe('TransactionFactory', () => {
5757
from: '0x05fba803be258049a27b820088bab1cad2058871',
5858
function_parameters: '0x08090033',
5959
gas_used: 400000,
60+
gas_limit: 500_000,
6061
to: '0x0000000000000000000000000000000000000409',
6162
hash: '0xfc4ab7133197016293d2e14e8cf9c5227b07357e6385184f1cd1cb40d783cfbd',
6263
block_hash: '0xb0f10139fa0bf9e66402c8c0e5ed364e07cf83b3726c8045fabf86a07f4887130e4650cb5cf48a9f6139a805b78f0312',
@@ -100,7 +101,7 @@ describe('TransactionFactory', () => {
100101
const formattedResult: any = createTransactionFromContractResult({
101102
...contractResult,
102103
block_number: null,
103-
gas_used: null,
104+
gas_limit: null,
104105
gas_price: '0x',
105106
max_priority_fee_per_gas: '0x',
106107
max_fee_per_gas: '0x',

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -660,15 +660,15 @@ describe('Formatters', () => {
660660
describe('tinybarsToWeibars', () => {
661661
for (const allowNegativeValues of [true, false]) {
662662
it(`should convert tinybars to weibars allowNegativeValues = ${allowNegativeValues}`, () => {
663-
expect(tinybarsToWeibars(10, allowNegativeValues)).to.eql(100000000000);
663+
expect(tinybarsToWeibars(10, allowNegativeValues)).to.eql(BigInt(100000000000));
664664
});
665665

666666
it(`should return null if null is passed allowNegativeValues = ${allowNegativeValues}`, () => {
667667
expect(tinybarsToWeibars(null, allowNegativeValues)).to.eql(null);
668668
});
669669

670670
it(`should return 0 for 0 input allowNegativeValues = ${allowNegativeValues}`, () => {
671-
expect(tinybarsToWeibars(0, allowNegativeValues)).to.eql(0);
671+
expect(tinybarsToWeibars(0, allowNegativeValues)).to.eql(BigInt(0));
672672
});
673673

674674
it(`should throw an error when value is larger than the total supply of tinybars allowNegativeValues = ${allowNegativeValues}`, () => {
@@ -706,7 +706,7 @@ describe('Formatters', () => {
706706

707707
it('should handle edge case values correctly', () => {
708708
expect(tinybarsToWeibars(constants.TOTAL_SUPPLY_TINYBARS, false)).to.eql(
709-
constants.TOTAL_SUPPLY_TINYBARS * constants.TINYBAR_TO_WEIBAR_COEF,
709+
BigInt(constants.TOTAL_SUPPLY_TINYBARS) * BigInt(constants.TINYBAR_TO_WEIBAR_COEF),
710710
);
711711
});
712712
});

packages/server/tests/acceptance/data/conformity/overwrites/eth_getTransactionByBlockHashAndIndex/get-block-n.io

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
## wildcard: result.blockHash, result.blockNumber, result.transactionIndex
1515

1616
>> {"jsonrpc":"2.0","id":1,"method":"eth_getTransactionByBlockHashAndIndex","params":["0xbb198addc8a129024ed75dbe52a8c89a6baa97980c855241790439db182a210b","0x0"]}
17-
<< {"jsonrpc":"2.0","id":1,"result":{"blockHash":"0xed7ad3f8312a90317566aa1d6bc64b237658d3c5d5b6364de912c8735be650a1","blockNumber":"0x5d","chainId":"0x12a","from":"0xc37f417fa09933335240fca72dd257bfbde9c275","gas":"0x30d40","gasPrice":"0x2c68af0bb14000","hash":"0xce8bfc3ea57c50a185e2fe61fc8d680a16b5a18dad9d6f05afdbdeb3c3a4516e","input":"0x","nonce":"0x0","r":"0xa685541e887688a4e3f0dbd00e58313f3a466fc0f012bfd4845497b4b16b575e","s":"0x7b300e3c6b327a9c878f1d4476587f8ed8f5303853500b6594f096c945602","to":"0x67d8d32e9bf1a9968a5ff53b87d777aa8ebbee69","transactionIndex":"0x6","type":"0x0","v":"0x278","value":"0x2e90edd000"}}
17+
<< {"jsonrpc":"2.0","id":1,"result":{"blockHash":"0xed7ad3f8312a90317566aa1d6bc64b237658d3c5d5b6364de912c8735be650a1","blockNumber":"0x5d","chainId":"0x12a","from":"0xc37f417fa09933335240fca72dd257bfbde9c275","gas":"0x3d090","gasPrice":"0x2c68af0bb14000","hash":"0xce8bfc3ea57c50a185e2fe61fc8d680a16b5a18dad9d6f05afdbdeb3c3a4516e","input":"0x","nonce":"0x0","r":"0xa685541e887688a4e3f0dbd00e58313f3a466fc0f012bfd4845497b4b16b575e","s":"0x7b300e3c6b327a9c878f1d4476587f8ed8f5303853500b6594f096c945602","to":"0x67d8d32e9bf1a9968a5ff53b87d777aa8ebbee69","transactionIndex":"0x6","type":"0x0","v":"0x278","value":"0x2e90edd000"}}

packages/server/tests/acceptance/data/conformity/overwrites/eth_getTransactionByBlockNumberAndIndex/get-block-n.io

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
## wildcard: result.blockHash, result.blockNumber, result.transactionIndex
1515

1616
>> {"jsonrpc":"2.0","id":1,"method":"eth_getTransactionByBlockNumberAndIndex","params":["0x1","0x0"]}
17-
<< {"jsonrpc":"2.0","id":1,"result":{"blockHash":"0xed7ad3f8312a90317566aa1d6bc64b237658d3c5d5b6364de912c8735be650a1","blockNumber":"0x5d","chainId":"0x12a","from":"0xc37f417fa09933335240fca72dd257bfbde9c275","gas":"0x30d40","gasPrice":"0x2c68af0bb14000","hash":"0xce8bfc3ea57c50a185e2fe61fc8d680a16b5a18dad9d6f05afdbdeb3c3a4516e","input":"0x","nonce":"0x0","r":"0xa685541e887688a4e3f0dbd00e58313f3a466fc0f012bfd4845497b4b16b575e","s":"0x7b300e3c6b327a9c878f1d4476587f8ed8f5303853500b6594f096c945602","to":"0x67d8d32e9bf1a9968a5ff53b87d777aa8ebbee69","transactionIndex":"0x6","type":"0x0","v":"0x278","value":"0x2e90edd000"}}
17+
<< {"jsonrpc":"2.0","id":1,"result":{"blockHash":"0xed7ad3f8312a90317566aa1d6bc64b237658d3c5d5b6364de912c8735be650a1","blockNumber":"0x5d","chainId":"0x12a","from":"0xc37f417fa09933335240fca72dd257bfbde9c275","gas":"0x3d090","gasPrice":"0x2c68af0bb14000","hash":"0xce8bfc3ea57c50a185e2fe61fc8d680a16b5a18dad9d6f05afdbdeb3c3a4516e","input":"0x","nonce":"0x0","r":"0xa685541e887688a4e3f0dbd00e58313f3a466fc0f012bfd4845497b4b16b575e","s":"0x7b300e3c6b327a9c878f1d4476587f8ed8f5303853500b6594f096c945602","to":"0x67d8d32e9bf1a9968a5ff53b87d777aa8ebbee69","transactionIndex":"0x6","type":"0x0","v":"0x278","value":"0x2e90edd000"}}

0 commit comments

Comments
 (0)