From e4b3a97a506ada5b273266e2ec5182f8e9a06825 Mon Sep 17 00:00:00 2001 From: nikolay Date: Thu, 18 Jul 2024 13:50:00 +0300 Subject: [PATCH] chore: return logs bloom Signed-off-by: nikolay --- packages/relay/src/lib/eth.ts | 2 +- packages/relay/tests/helpers.ts | 2 ++ .../tests/lib/eth/eth_getBlockByHash.spec.ts | 25 ++++++++++++++++++- .../lib/eth/eth_getBlockByNumber.spec.ts | 23 ++++++++++++++++- 4 files changed, 49 insertions(+), 3 deletions(-) diff --git a/packages/relay/src/lib/eth.ts b/packages/relay/src/lib/eth.ts index 3bb6fa69cc..5312af40b6 100644 --- a/packages/relay/src/lib/eth.ts +++ b/packages/relay/src/lib/eth.ts @@ -2240,7 +2240,7 @@ export class EthImpl implements Eth { gasLimit: numberTo0x(maxGasLimit), gasUsed: numberTo0x(gasUsed), hash: blockHash, - logsBloom: EthImpl.emptyBloom, //TODO calculate full block boom in mirror node + logsBloom: blockResponse.logs_bloom === EthImpl.emptyHex ? EthImpl.emptyBloom : blockResponse.logs_bloom, miner: EthImpl.zeroAddressHex, mixHash: EthImpl.zeroHex32Byte, nonce: EthImpl.zeroHex8Byte, diff --git a/packages/relay/tests/helpers.ts b/packages/relay/tests/helpers.ts index d70761570d..5bba8e7c6f 100644 --- a/packages/relay/tests/helpers.ts +++ b/packages/relay/tests/helpers.ts @@ -508,6 +508,8 @@ export const defaultLogTopics = [ '0x0000000000000000000000000000000000000000000000000000000000000005', ]; +export const blockLogsBloom = + '0x00000000000000000000000000000000000000000000000080010000000000100000000000080000000000000000000000000000000000000000000000000000000000000000000000000080008000000000000000000000000000000000000000000080000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000480000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000'; export const logBloom1 = '0x1111'; export const logBloom2 = '0x2222'; export const logBloom3 = '0x3333'; diff --git a/packages/relay/tests/lib/eth/eth_getBlockByHash.spec.ts b/packages/relay/tests/lib/eth/eth_getBlockByHash.spec.ts index 8db48aa5b7..e66dc44b93 100644 --- a/packages/relay/tests/lib/eth/eth_getBlockByHash.spec.ts +++ b/packages/relay/tests/lib/eth/eth_getBlockByHash.spec.ts @@ -25,7 +25,7 @@ import chaiAsPromised from 'chai-as-promised'; import { predefined } from '../../../src/lib/errors/JsonRpcError'; import { EthImpl } from '../../../src/lib/eth'; -import { defaultContractResults, defaultDetailedContractResults } from '../../helpers'; +import { blockLogsBloom, defaultContractResults, defaultDetailedContractResults } from '../../helpers'; import { SDKClient } from '../../../src/lib/clients'; import RelayAssertions from '../../assertions'; import { numberTo0x } from '../../../dist/formatters'; @@ -112,6 +112,29 @@ describe('@ethGetBlockByHash using MirrorNode', async function () { }); }); + it('eth_getBlockByHash with match and valid logsBloom field', async function () { + // mirror node request mocks + restMock.onGet(`blocks/${BLOCK_HASH}`).reply(200, { + ...DEFAULT_BLOCK, + logs_bloom: blockLogsBloom, + }); + restMock.onGet(CONTRACT_RESULTS_WITH_FILTER_URL).reply(200, defaultContractResults); + restMock.onGet('network/fees').reply(200, DEFAULT_NETWORK_FEES); + restMock.onGet(CONTRACT_RESULTS_LOGS_WITH_FILTER_URL).reply(200, DEFAULT_ETH_GET_BLOCK_BY_LOGS); + + const result = await ethImpl.getBlockByHash(BLOCK_HASH, false); + RelayAssertions.assertBlock(result, { + hash: BLOCK_HASH_TRIMMED, + gasUsed: TOTAL_GAS_USED, + number: BLOCK_NUMBER_HEX, + parentHash: BLOCK_HASH_PREV_TRIMMED, + timestamp: BLOCK_TIMESTAMP_HEX, + transactions: [CONTRACT_HASH_1, CONTRACT_HASH_2], + }); + + expect(result?.logsBloom).equal(blockLogsBloom); + }); + it('eth_getBlockByHash with match paginated', async function () { // mirror node request mocks restMock.onGet(`blocks/${BLOCK_HASH}`).reply(200, DEFAULT_BLOCK); diff --git a/packages/relay/tests/lib/eth/eth_getBlockByNumber.spec.ts b/packages/relay/tests/lib/eth/eth_getBlockByNumber.spec.ts index 455c832449..d15d8ca24b 100644 --- a/packages/relay/tests/lib/eth/eth_getBlockByNumber.spec.ts +++ b/packages/relay/tests/lib/eth/eth_getBlockByNumber.spec.ts @@ -25,7 +25,7 @@ import chaiAsPromised from 'chai-as-promised'; import { predefined } from '../../../src/lib/errors/JsonRpcError'; import { EthImpl } from '../../../src/lib/eth'; -import { defaultContractResults, defaultDetailedContractResults } from '../../helpers'; +import { blockLogsBloom, defaultContractResults, defaultDetailedContractResults } from '../../helpers'; import { Block, Transaction } from '../../../src/lib/model'; import { SDKClient } from '../../../src/lib/clients'; import RelayAssertions from '../../assertions'; @@ -226,6 +226,27 @@ describe('@ethGetBlockByNumber using MirrorNode', async function () { }); }); + it('eth_getBlockByNumber with match and valid logsBloom field', async function () { + restMock.onGet(`blocks/${BLOCK_NUMBER}`).reply(200, { + ...DEFAULT_BLOCK, + logs_bloom: blockLogsBloom, + }); + restMock.onGet(CONTRACT_RESULTS_WITH_FILTER_URL).reply(200, defaultContractResults); + + const result = await ethImpl.getBlockByNumber(numberTo0x(BLOCK_NUMBER), false); + + RelayAssertions.assertBlock(result, { + hash: BLOCK_HASH_TRIMMED, + gasUsed: TOTAL_GAS_USED, + number: BLOCK_NUMBER_HEX, + parentHash: BLOCK_HASH_PREV_TRIMMED, + timestamp: BLOCK_TIMESTAMP_HEX, + transactions: [CONTRACT_HASH_1, CONTRACT_HASH_2], + }); + + expect(result?.logsBloom).equal(blockLogsBloom); + }); + it('eth_getBlockByNumber with match paginated', async function () { restMock.onGet(CONTRACT_RESULTS_WITH_FILTER_URL).reply(200, LINKS_NEXT_RES); restMock.onGet(CONTRACTS_RESULTS_NEXT_URL).reply(200, defaultContractResults);