Skip to content

Commit baa1498

Browse files
AlfredoG87ebadiere
andauthored
chore: cherry-pick of: fix: Use Transaction1559 type to create synthetic transactions. (#2405) (#2417)
fix: Use Transaction1559 type to create synthetic transactions. (#2405) * fix: Use Transaction1559 type to create synthetic transactions. * feat: Added test. --------- Signed-off-by: ebadiere <[email protected]> Signed-off-by: Alfredo Gutierrez <[email protected]> Co-authored-by: Eric Badiere <[email protected]>
1 parent e6f86a5 commit baa1498

File tree

3 files changed

+221
-3
lines changed

3 files changed

+221
-3
lines changed

packages/relay/src/lib/eth.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import { Eth } from '../index';
2222
import { Hbar, PrecheckStatusError } from '@hashgraph/sdk';
2323
import { Logger } from 'pino';
24-
import { Block, Transaction, Log } from './model';
24+
import { Block, Transaction, Log, Transaction1559 } from './model';
2525
import { MirrorNodeClient } from './clients';
2626
import { JsonRpcError, predefined } from './errors/JsonRpcError';
2727
import { SDKClientError } from './errors/SDKClientError';
@@ -2164,7 +2164,7 @@ export class EthImpl implements Eth {
21642164
* @returns Transaction Object
21652165
*/
21662166
private createTransactionFromLog(log: Log) {
2167-
return new Transaction({
2167+
return new Transaction1559({
21682168
accessList: undefined, // we don't support access lists for now
21692169
blockHash: log.blockHash,
21702170
blockNumber: log.blockNumber,

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

Lines changed: 191 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*
33
* Hedera JSON RPC Relay
44
*
5-
* Copyright (C) 2023 Hedera Hashgraph, LLC
5+
* Copyright (C) 2023-2024 Hedera Hashgraph, LLC
66
*
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
@@ -28,13 +28,19 @@ export const GAS_USED_RATIO = 0.5;
2828
export const BLOCK_NUMBER = 3;
2929
export const BLOCK_NUMBER_2 = 4;
3030
export const BLOCK_NUMBER_3 = 5;
31+
export const BLOCK_NUMBER_WITH_SYN_TXN = 62970125;
3132
export const BLOCK_TIMESTAMP = '1651560386';
3233
export const BLOCK_HASH_TRIMMED = '0x3c08bbbee74d287b1dcd3f0ca6d1d2cb92c90883c4acf9747de9f3f3162ad25b';
3334
export const BLOCK_HASH = `${BLOCK_HASH_TRIMMED}999fc7e86699f60f2a3fb3ed9a646c6b`;
3435
export const BLOCK_HASH_2 = `${BLOCK_HASH_TRIMMED}999fc7e86699f60f2a3fb3ed9a646c6c`;
3536
export const BLOCK_HASH_3 = `${BLOCK_HASH_TRIMMED}999fc7e86699f60f2a3fb3ed9a646c6d`;
3637
export const RECEIVER_ADDRESS = '0x5b98Ce3a4D1e1AC55F15Da174D5CeFcc5b8FB994';
3738
export const WRONG_CONTRACT_ADDRESS = '0x00000000000000000000000000000000055e';
39+
export const LATEST_BLOCK_QUERY = 'blocks?limit=1&order=desc';
40+
export const CONTRACT_QUERY =
41+
'contracts/results?timestamp=gte:1713966020.010306294&timestamp=lte:1713966021.974483904&limit=100&order=asc';
42+
export const LOG_QUERY =
43+
'contracts/results/logs?timestamp=gte:1713966020.010306294&timestamp=lte:1713966021.974483904&limit=100&order=asc';
3844

3945
export const DEFAULT_BLOCK = {
4046
count: BLOCK_TRANSACTION_COUNT,
@@ -222,6 +228,190 @@ export const MOST_RECENT_BLOCK = {
222228
},
223229
],
224230
};
231+
232+
export const LATEST_BLOCK_RESPONSE = {
233+
blocks: [
234+
{
235+
count: 4224,
236+
hapi_version: '0.47.0',
237+
hash: '0x434a5468a6ca89d9a408d2b2eb20cef19906fdeb77daf849f8faa724bac9ce8b82289e60ec3d23103f4fa5bb70fc326e',
238+
name: '2024-04-24T20_44_10.008148389Z.rcd.gz',
239+
number: 62982840,
240+
previous_hash:
241+
'0x4937f5500de07ef30ce9b58e621d1d97846b9a9df0e6411e22f5693301c1e3c4bc2ccb286fcecca4ac3118121b4198ae',
242+
size: 1028454,
243+
timestamp: {
244+
from: '1713991450.008148389',
245+
to: '1713991451.974699092',
246+
},
247+
gas_used: 0,
248+
logs_bloom: '0x',
249+
},
250+
],
251+
links: {
252+
next: '/api/v1/blocks?limit=1&order=desc&block.number=lt:62982840',
253+
},
254+
};
255+
256+
export const LOGS_RESPONSE_MOCK = {
257+
logs: [
258+
{
259+
address: '0x000000000000000000000000000000000006f89a',
260+
bloom: '0x00',
261+
contract_id: '0.0.456858',
262+
data: '0x0000000000000000000000000000000000000000000000000000000002625929',
263+
index: 0,
264+
topics: [
265+
'0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925',
266+
'0x0000000000000000000000000000000000000000000000000000000000486bd3',
267+
'0x00000000000000000000000000000000000000000000000000000000003ddbb9',
268+
],
269+
block_hash: '0xd7ccab6cdbdaa68815016b4c4e9b1c43a84f312c85db8a34ef22f721f744bc37efab2cc95b7593d182682aa542cbb5fc',
270+
block_number: 62970125,
271+
root_contract_id: '0.0.456858',
272+
timestamp: '1713966020.226506003',
273+
transaction_hash: '0x9de8631f0b7a720d86ea798c544225c93ae22e4b43d6e7aed62b15f98f1a5095',
274+
transaction_index: 377,
275+
},
276+
{
277+
address: '0xf85350598c4e2817d5ce4385c19cc872cbc19cf4',
278+
bloom:
279+
'0x00000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000020000000000000000004000000000000000000000000000000000000000000000000000000000000004000000000000000200000000000000000000000000000000001000000000000000000000200000000000000000000000000000120000000000000000000000000000000000010000000000000000000000000040000000000000000000000020000000000000000000000000080000000000000100000000000000000000000000000000000000000000',
280+
contract_id: '0.0.4601632',
281+
data: '0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
282+
index: 0,
283+
topics: [
284+
'0x0c396cd989a39f4459b5fa1aed6a9a8dcdbc45908acfd67e028cd568da98982c',
285+
'0x00000000000000000000000022ab1cb7e1e7051e505b33bf4c7a34958e43bb15',
286+
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0d08',
287+
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff2158',
288+
],
289+
block_hash: '0xd7ccab6cdbdaa68815016b4c4e9b1c43a84f312c85db8a34ef22f721f744bc37efab2cc95b7593d182682aa542cbb5fc',
290+
block_number: 62970125,
291+
root_contract_id: '0.0.4568290',
292+
timestamp: '1713966021.843572355',
293+
transaction_hash: '0x17bba5b747f392d216e4dd955f09acbf9b78383624a99110b86696c5daba32a1',
294+
transaction_index: 3168,
295+
},
296+
{
297+
address: '0xf85350598c4e2817d5ce4385c19cc872cbc19cf4',
298+
bloom:
299+
'0x00000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000020000000000000000004000000000000000000000000000000000000000000000000000000000000004000000000000000200000000000000000000000000000000001000000000000000000000200000000000000000000000000000120000000000000000000000000000000000010000000000000000000000000040000000000000000000000020000000000000000000000000080000000000000100000000000000000000000000000000000000000000',
300+
contract_id: '0.0.4601632',
301+
data: '0x000000000000000000000000000000000000000000000000000161c96a6d8fa700000000000000000000000000000000000000000000000000001fef6d95b83c00000000000000000000000000000000000000000000000000000494578917e8',
302+
index: 1,
303+
topics: [
304+
'0x0c396cd989a39f4459b5fa1aed6a9a8dcdbc45908acfd67e028cd568da98982c',
305+
'0x00000000000000000000000022ab1cb7e1e7051e505b33bf4c7a34958e43bb15',
306+
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0d08',
307+
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff2158',
308+
],
309+
block_hash: '0xd7ccab6cdbdaa68815016b4c4e9b1c43a84f312c85db8a34ef22f721f744bc37efab2cc95b7593d182682aa542cbb5fc',
310+
block_number: 62970125,
311+
root_contract_id: '0.0.4568290',
312+
timestamp: '1713966021.843572355',
313+
transaction_hash: '0x17bba5b747f392d216e4dd955f09acbf9b78383624a99110b86696c5daba32a1',
314+
transaction_index: 3168,
315+
},
316+
],
317+
links: {
318+
next: null,
319+
},
320+
};
321+
322+
export const CONTRACT_RESPONSE_MOCK = [
323+
{
324+
address: '0x00000000000000000000000000000000002e7a5d',
325+
amount: 0,
326+
bloom: '0x',
327+
call_result: '0x',
328+
contract_id: '0.0.3045981',
329+
created_contract_ids: [],
330+
error_message:
331+
'0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002b556e69737761705632526f757465723a20494e53554646494349454e545f4f55545055545f414d4f554e54000000000000000000000000000000000000000080',
332+
from: '0x0000000000000000000000000000000000428885',
333+
function_parameters:
334+
'0x791ac9470000000000000000000000000000000000000000000000000000006b57e7764800000000000000000000000000000000000000000000000000000002777cb1d800000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000004288850000000000000000000000000000000000000000000000000000018f106838600000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000056c77d0000000000000000000000000000000000000000000000000000000000163b5a',
335+
gas_consumed: 120002,
336+
gas_limit: 1120000,
337+
gas_used: 896000,
338+
timestamp: '1713966020.091151003',
339+
to: '0x00000000000000000000000000000000002e7a5d',
340+
hash: '0x3b913d06f464580c60663158a736f28871bacd819592b06c34faaf89df8d5ec4',
341+
block_hash: '0xd7ccab6cdbdaa68815016b4c4e9b1c43a84f312c85db8a34ef22f721f744bc37efab2cc95b7593d182682aa542cbb5fc',
342+
block_number: 62970125,
343+
result: 'CONTRACT_REVERT_EXECUTED',
344+
transaction_index: 66,
345+
status: '0x0',
346+
failed_initcode: null,
347+
access_list: null,
348+
block_gas_used: 1857802,
349+
chain_id: null,
350+
gas_price: null,
351+
max_fee_per_gas: null,
352+
max_priority_fee_per_gas: null,
353+
r: null,
354+
s: null,
355+
type: null,
356+
v: null,
357+
nonce: null,
358+
},
359+
{
360+
address: '0xf2239961d2e916503fd35315660733b8a323b929',
361+
amount: 0,
362+
bloom:
363+
'0x0000801000001000008010000200000000000000000000014010200000a00000002000000000010000000010000000000000000004080000020000000000408000006000000000000000000802000000000100000000400000000000800000000000000002040000000000000120000000000000000400000000001000020008000040000a000000000920000000001000008000000400000000200000000000404000000000200000120008000000000200000000008000000000010000000000880003000000200040480000000000000200000424000000000420000000000002080000040006001100000100000280000000000042000000000000000000',
364+
call_result:
365+
'0x0000000000000000000000000000000000000000000000000000000003c0d90d000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000e298200000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000',
366+
contract_id: '0.0.4568290',
367+
created_contract_ids: [],
368+
error_message: null,
369+
from: '0x000000000000000000000000000000000045704a',
370+
function_parameters:
371+
'0x1749e1e30000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000003b9ba84e98e560c88337adb459c7a0378eb053a800000000000000000000000000000000000000000000000000000000001194fc000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000444585e33b0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
372+
gas_consumed: 953437,
373+
gas_limit: 1202252,
374+
gas_used: 961802,
375+
timestamp: '1713966021.843572355',
376+
to: '0xf2239961d2e916503fd35315660733b8a323b929',
377+
hash: '0x17bba5b747f392d216e4dd955f09acbf9b78383624a99110b86696c5daba32a1',
378+
block_hash: '0xd7ccab6cdbdaa68815016b4c4e9b1c43a84f312c85db8a34ef22f721f744bc37efab2cc95b7593d182682aa542cbb5fc',
379+
block_number: 62970125,
380+
result: 'SUCCESS',
381+
transaction_index: 3168,
382+
status: '0x1',
383+
failed_initcode: null,
384+
access_list: '0x',
385+
block_gas_used: 1857802,
386+
chain_id: '0x127',
387+
gas_price: '0x',
388+
max_fee_per_gas: '0x55',
389+
max_priority_fee_per_gas: '0x55',
390+
r: '0x34ec3fa5894ccdc88335f5d8a297ec4b0acb5706522db69d0a156b7e31a8596e',
391+
s: '0x1a3079e5e9932ffb052dafbe2dcdeb013edaee4cad34ca6d8fa3ed031b692e1b',
392+
type: 2,
393+
v: 1,
394+
nonce: 7257,
395+
},
396+
];
397+
398+
export const BLOCK_WITH_SYN_TXN = {
399+
count: 3388,
400+
hapi_version: '0.47.0',
401+
hash: '0xd7ccab6cdbdaa68815016b4c4e9b1c43a84f312c85db8a34ef22f721f744bc37efab2cc95b7593d182682aa542cbb5fc',
402+
name: '2024-04-24T13_40_20.010306294Z.rcd.gz',
403+
number: 62970125,
404+
previous_hash: '0xe79421d58727ed78d12e141dfbd3d8bbfa5820ce674e01b5280b07a4ab296ed366232d4e129e1ef2e98870885954f842',
405+
size: 822338,
406+
timestamp: {
407+
from: '1713966020.010306294',
408+
to: '1713966021.974483904',
409+
},
410+
gas_used: 1857802,
411+
logs_bloom:
412+
'0x0000801000001000008010000200000000000000000000014010200000a00000002000000000010000000010000000000000000004080000020000000000408000006000000000000000000802000000000100000000400000000000800000000000000002040000000000000120000000000000000400000000001000020008000040000a000000000920000000001000008000000400000000200000000000404000000000200000120008000000000200000000008000000000010000000000880003000000200040480000000000000200000424000000000420000000000002080000040006001100000100000280000000000042000000000000000000',
413+
};
414+
225415
export const DEFAULT_OLDER_CONTRACT_STATE = {
226416
state: [
227417
{

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,16 @@ import {
3939
BLOCK_NOT_FOUND_RES,
4040
BLOCK_NUMBER,
4141
BLOCK_NUMBER_HEX,
42+
BLOCK_NUMBER_WITH_SYN_TXN,
4243
BLOCK_TIMESTAMP_HEX,
44+
BLOCK_WITH_SYN_TXN,
4345
CONTRACTS_RESULTS_NEXT_URL,
4446
CONTRACT_ADDRESS_1,
4547
CONTRACT_ADDRESS_2,
4648
CONTRACT_HASH_1,
4749
CONTRACT_HASH_2,
50+
CONTRACT_QUERY,
51+
CONTRACT_RESPONSE_MOCK,
4852
CONTRACT_RESULTS_LOGS_WITH_FILTER_URL,
4953
CONTRACT_RESULTS_WITH_FILTER_URL,
5054
CONTRACT_TIMESTAMP_1,
@@ -56,12 +60,17 @@ import {
5660
DEFAULT_NETWORK_FEES,
5761
GAS_USED_1,
5862
GAS_USED_2,
63+
LATEST_BLOCK_QUERY,
64+
LATEST_BLOCK_RESPONSE,
5965
LINKS_NEXT_RES,
66+
LOGS_RESPONSE_MOCK,
67+
LOG_QUERY,
6068
MOST_RECENT_BLOCK,
6169
NOT_FOUND_RES,
6270
NO_SUCH_BLOCK_EXISTS_RES,
6371
} from './eth-config';
6472
import { generateEthTestEnv } from './eth-helpers';
73+
import { fail } from 'assert';
6574

6675
dotenv.config({ path: path.resolve(__dirname, '../test.env') });
6776
use(chaiAsPromised);
@@ -298,6 +307,25 @@ describe('@ethGetBlockByNumber using MirrorNode', async function () {
298307
}
299308
});
300309

310+
it('eth_getBlockByNumber with match and details and sythetic transactions', async function () {
311+
// mirror node request mocks
312+
restMock.onGet(`blocks/${BLOCK_NUMBER_WITH_SYN_TXN}`).reply(200, BLOCK_WITH_SYN_TXN);
313+
314+
restMock.onGet(LATEST_BLOCK_QUERY).reply(200, LATEST_BLOCK_RESPONSE);
315+
restMock.onGet(CONTRACT_QUERY).reply(200, CONTRACT_RESPONSE_MOCK);
316+
restMock.onGet(LOG_QUERY).reply(200, LOGS_RESPONSE_MOCK);
317+
318+
const result = await ethImpl.getBlockByNumber(numberTo0x(BLOCK_NUMBER_WITH_SYN_TXN), true);
319+
if (result) {
320+
result.transactions.forEach((txn) => {
321+
expect(txn.maxFeePerGas).to.exist;
322+
expect(txn.maxPriorityFeePerGas).to.exist;
323+
});
324+
} else {
325+
fail('Result is null');
326+
}
327+
});
328+
301329
it('eth_getBlockByNumber with match and details paginated', async function () {
302330
// mirror node request mocks
303331
restMock.onGet(`blocks/${BLOCK_NUMBER}`).reply(200, DEFAULT_BLOCK);

0 commit comments

Comments
 (0)