Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions packages/relay/src/lib/factories/transactionFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,23 @@ export const createTransactionFromContractResult = (cr: any): Transaction | null
chainId: cr.chain_id === constants.EMPTY_HEX ? undefined : cr.chain_id,
};

const maxPriorityFeePerGas =
cr.max_priority_fee_per_gas === null || cr.max_priority_fee_per_gas === constants.EMPTY_HEX
? null
: isHex(cr.max_priority_fee_per_gas)
? numberTo0x(BigInt(cr.max_priority_fee_per_gas) * BigInt(constants.TINYBAR_TO_WEIBAR_COEF))
: nanOrNumberTo0x(cr.max_priority_fee_per_gas);

const maxFeePerGas =
cr.max_fee_per_gas === null || cr.max_fee_per_gas === constants.EMPTY_HEX
? null
: isHex(cr.max_fee_per_gas)
? numberTo0x(BigInt(cr.max_fee_per_gas) * BigInt(constants.TINYBAR_TO_WEIBAR_COEF))
: nanOrNumberTo0x(cr.max_fee_per_gas);

return TransactionFactory.createTransactionByType(cr.type, {
...commonFields,
maxPriorityFeePerGas: cr.max_priority_fee_per_gas,
maxFeePerGas: cr.max_fee_per_gas,
maxPriorityFeePerGas,
maxFeePerGas,
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,10 @@ export async function getBlock(

const receiptsRoot: string = await getRootHash(receipts);

const gasPrice = await commonService.gasPrice(requestDetails);
// Use block-time gas price (not current) so baseFeePerGas matches effectiveGasPrice.
// Mirrors the pattern in getBlockReceipts (line 364).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you consider referencing just the function name here? That approach should require less maintenance while providing the same value.

const blockTimestamp = blockResponse.timestamp?.from?.split('.')[0] ?? '';
const gasPrice = numberTo0x(await commonService.getGasPriceInWeibars(requestDetails, blockTimestamp));

return await BlockFactory.createBlock({
blockResponse,
Expand Down
1 change: 1 addition & 0 deletions packages/relay/tests/lib/eth/eth_getBlockByHash.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ describe('@ethGetBlockByHash using MirrorNode', async function () {
sdkClientStub = sinon.createStubInstance(SDKClient);
getSdkClientStub = sinon.stub(hapiServiceInstance, 'getSDKClient').returns(sdkClientStub);
restMock.onGet('network/fees').reply(200, JSON.stringify(modifiedNetworkFees));
restMock.onGet(/network\/fees\?timestamp=\d+/).reply(200, JSON.stringify(modifiedNetworkFees));
restMock.onGet(ACCOUNT_WITHOUT_TRANSACTIONS).reply(200, JSON.stringify(MOCK_ACCOUNT_WITHOUT_TRANSACTIONS));
restMock
.onGet(contractByEvmAddress(CONTRACT_ADDRESS_1))
Expand Down
9 changes: 6 additions & 3 deletions packages/relay/tests/lib/eth/eth_getBlockByNumber.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
BLOCK_NUMBER,
BLOCK_NUMBER_HEX,
BLOCK_NUMBER_WITH_SYN_TXN,
BLOCK_TIMESTAMP,
BLOCK_TIMESTAMP_HEX,
BLOCK_WITH_SYN_TXN,
BLOCKS_LIMIT_ORDER_URL,
Expand Down Expand Up @@ -128,6 +129,7 @@ describe('@ethGetBlockByNumber using MirrorNode', async function () {
const modifiedNetworkFees = structuredClone(DEFAULT_NETWORK_FEES);
modifiedNetworkFees.fees[2].gas *= 100;
restMock.onGet('network/fees').reply(200, JSON.stringify(modifiedNetworkFees));
restMock.onGet(/network\/fees\?timestamp=\d+/).reply(200, JSON.stringify(modifiedNetworkFees));
restMock.onGet(`accounts/${defaultContractResults.results[0].from}?transactions=false`).reply(200);
restMock.onGet(`accounts/${defaultContractResults.results[1].from}?transactions=false`).reply(200);
restMock.onGet(`accounts/${defaultContractResults.results[0].to}?transactions=false`).reply(200);
Expand Down Expand Up @@ -444,7 +446,7 @@ describe('@ethGetBlockByNumber using MirrorNode', async function () {
expect(restMock.history.get[2].url).equal(
'contracts/results/logs?timestamp=gte:1651560386.060890949&timestamp=lte:1651560389.060890949&limit=100&order=asc',
);
expect(restMock.history.get[TOTAL_GET_CALLS_EXECUTED - 1].url).equal('network/fees');
expect(restMock.history.get[TOTAL_GET_CALLS_EXECUTED - 1].url).equal(`network/fees?timestamp=${BLOCK_TIMESTAMP}`);
confirmResult(result);
});

Expand Down Expand Up @@ -479,7 +481,7 @@ describe('@ethGetBlockByNumber using MirrorNode', async function () {
expect(restMock.history.get[2].url).equal(
'contracts/results/logs?timestamp=gte:1651560386.060890949&timestamp=lte:1651560389.060890949&limit=100&order=asc',
);
expect(restMock.history.get[TOTAL_GET_CALLS_EXECUTED - 1].url).equal('network/fees');
expect(restMock.history.get[TOTAL_GET_CALLS_EXECUTED - 1].url).equal(`network/fees?timestamp=${BLOCK_TIMESTAMP}`);
confirmResult(result);
});

Expand All @@ -494,7 +496,7 @@ describe('@ethGetBlockByNumber using MirrorNode', async function () {
expect(restMock.history.get[2].url).equal(
'contracts/results/logs?timestamp=gte:1651560386.060890949&timestamp=lte:1651560389.060890949&limit=100&order=asc',
);
expect(restMock.history.get[TOTAL_GET_CALLS_EXECUTED - 1].url).equal('network/fees');
expect(restMock.history.get[TOTAL_GET_CALLS_EXECUTED - 1].url).equal(`network/fees?timestamp=${BLOCK_TIMESTAMP}`);
confirmResult(result);
});

Expand Down Expand Up @@ -584,6 +586,7 @@ describe('@ethGetBlockByNumber using MirrorNode', async function () {
restMock.onGet(`blocks/${BLOCK_HASH}`).reply(200, JSON.stringify(DEFAULT_BLOCK));
restMock.onGet(CONTRACT_RESULTS_WITH_FILTER_URL).reply(200, JSON.stringify(defaultContractResults));
restMock.onGet('network/fees').reply(200, JSON.stringify(DEFAULT_NETWORK_FEES));
restMock.onGet(/network\/fees\?timestamp=\d+/).reply(200, JSON.stringify(DEFAULT_NETWORK_FEES));

const nullEntitiedLogs = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ describe('@ethGetTransactionByBlockHashAndIndex using MirrorNode', async functio
requestDetails,
);
expect(result).to.be.an.instanceOf(Transaction1559);
if (result) {
expect((result as Transaction1559).maxFeePerGas).to.equal('0xa54f4c3c00');
expect((result as Transaction1559).maxPriorityFeePerGas).to.equal('0xa54f4c3c00');
}
});

describe('synthetic transaction handling', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Eth } from '../../../src';
import { SDKClient } from '../../../src/lib/clients';
import type { ICacheClient } from '../../../src/lib/clients/cache/ICacheClient';
import { predefined } from '../../../src/lib/errors/JsonRpcError';
import { Transaction } from '../../../src/lib/model';
import { Transaction, Transaction1559 } from '../../../src/lib/model';
import HAPIService from '../../../src/lib/services/hapiService/hapiService';
import { RequestDetails } from '../../../src/lib/types';
import RelayAssertions from '../../assertions';
Expand All @@ -21,6 +21,7 @@ import {
BLOCK_NUMBER_HEX,
CONTRACT_ADDRESS_1,
CONTRACT_HASH_1,
CONTRACT_RESULT_MOCK,
CONTRACT_TIMESTAMP_1,
DEFAULT_BLOCK,
DEFAULT_BLOCKS_RES,
Expand Down Expand Up @@ -273,6 +274,34 @@ describe('@ethGetTransactionByBlockNumberAndIndex using MirrorNode', async funct
verifyAggregatedInfo(result);
});

it('eth_getTransactionByBlockNumberAndIndex returns 1559 transaction for type 2 with converted fee caps', async function () {
restMock.onGet(contractResultsByNumberByIndexURL(DEFAULT_BLOCK.number, DEFAULT_BLOCK.count)).reply(
200,
JSON.stringify({
results: [
{
...CONTRACT_RESULT_MOCK,
type: 2,
access_list: [],
max_fee_per_gas: '0x47',
max_priority_fee_per_gas: '0x47',
},
],
}),
);

const result = await ethImpl.getTransactionByBlockNumberAndIndex(
numberTo0x(DEFAULT_BLOCK.number),
numberTo0x(DEFAULT_BLOCK.count),
requestDetails,
);
expect(result).to.be.an.instanceOf(Transaction1559);
if (result) {
expect((result as Transaction1559).maxFeePerGas).to.equal('0xa54f4c3c00');
expect((result as Transaction1559).maxPriorityFeePerGas).to.equal('0xa54f4c3c00');
}
});

describe('synthetic transaction handling', function () {
it('returns synthetic transaction when contract result is empty but logs exist', async function () {
// Mock contract results returning empty (no EVM transaction)
Expand Down
12 changes: 6 additions & 6 deletions packages/relay/tests/lib/eth/eth_getTransactionByHash.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ describe('@ethGetTransactionByHash eth_getTransactionByHash tests', async functi
const result = await ethImpl.getTransactionByHash(DEFAULT_TX_HASH, requestDetails);
RelayAssertions.assertTransaction(result, {
...DEFAULT_TRANSACTION,
maxFeePerGas: '0x55',
maxPriorityFeePerGas: '0x43',
maxFeePerGas: '0xc5e7f2b400',
maxPriorityFeePerGas: '0x9bff1cac00',
});
});

Expand All @@ -220,8 +220,8 @@ describe('@ethGetTransactionByHash eth_getTransactionByHash tests', async functi
const result = await ethImpl.getTransactionByHash(uniqueTxHash, requestDetails);
RelayAssertions.assertTransaction(result, {
...DEFAULT_TRANSACTION,
maxFeePerGas: '0x55',
maxPriorityFeePerGas: '0x43',
maxFeePerGas: '0xc5e7f2b400',
maxPriorityFeePerGas: '0x9bff1cac00',
r: '0x0',
s: '0x0',
});
Expand Down Expand Up @@ -335,8 +335,8 @@ describe('@ethGetTransactionByHash eth_getTransactionByHash tests', async functi
const result = await ethImpl.getTransactionByHash(DEFAULT_TX_HASH, requestDetails);
RelayAssertions.assertTransaction(result, {
...DEFAULT_TRANSACTION,
maxFeePerGas: '0x55',
maxPriorityFeePerGas: '0x43',
maxFeePerGas: '0xc5e7f2b400',
maxPriorityFeePerGas: '0x9bff1cac00',
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ describe('TransactionFactory', () => {
expect(formattedResult.hash).to.equal('0xfc4ab7133197016293d2e14e8cf9c5227b07357e6385184f1cd1cb40d783cfbd');
expect(formattedResult.input).to.equal('0x08090033');
expect(formattedResult.maxPriorityFeePerGas).to.equal(expectedValues.maxPriorityFeePerGas ?? '0x0');
expect(formattedResult.maxFeePerGas).to.equal(expectedValues.maxFeePerGas ?? '0x59');
expect(formattedResult.maxFeePerGas).to.equal(expectedValues.maxFeePerGas ?? '0xcf38224400');
expect(formattedResult.nonce).to.equal(expectedValues.nonce ?? '0x2');
expect(formattedResult.r).to.equal(
expectedValues.r ?? '0x2af9d41244c702764ed86c5b9f1a734b075b91c4d9c65e78bc584b0e35181e42',
Expand Down
Loading
Loading