Skip to content

Commit

Permalink
chore: return logs bloom
Browse files Browse the repository at this point in the history
Signed-off-by: nikolay <n.atanasow94@gmail.com>
  • Loading branch information
natanasow committed Jul 18, 2024
1 parent 9ead77c commit e4b3a97
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/relay/src/lib/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions packages/relay/tests/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,8 @@ export const defaultLogTopics = [
'0x0000000000000000000000000000000000000000000000000000000000000005',
];

export const blockLogsBloom =
'0x00000000000000000000000000000000000000000000000080010000000000100000000000080000000000000000000000000000000000000000000000000000000000000000000000000080008000000000000000000000000000000000000000000080000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000480000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000';
export const logBloom1 = '0x1111';
export const logBloom2 = '0x2222';
export const logBloom3 = '0x3333';
Expand Down
25 changes: 24 additions & 1 deletion packages/relay/tests/lib/eth/eth_getBlockByHash.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down
23 changes: 22 additions & 1 deletion packages/relay/tests/lib/eth/eth_getBlockByNumber.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit e4b3a97

Please sign in to comment.