Skip to content

Commit 49cd45a

Browse files
authored
chore: cherry pick PR#2616 (#2618)
fix: fixed unexpected returns for eth_getLog requests with zero address (#2616) Signed-off-by: Logan Nguyen <[email protected]>
1 parent 22b70fa commit 49cd45a

File tree

4 files changed

+56
-2
lines changed

4 files changed

+56
-2
lines changed

packages/relay/src/lib/clients/mirrorNodeClient.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { predefined } from '../errors/JsonRpcError';
2929
import { SDKClientError } from '../errors/SDKClientError';
3030
import { install as betterLookupInstall } from 'better-lookup';
3131
import { CacheService } from '../services/cacheService/cacheService';
32+
import { ethers } from 'ethers';
3233

3334
const http = require('http');
3435
const https = require('https');
@@ -816,6 +817,8 @@ export class MirrorNodeClient {
816817
limitOrderParams?: ILimitOrderParams,
817818
requestIdPrefix?: string,
818819
) {
820+
if (address === ethers.ZeroAddress) return [];
821+
819822
const queryParams = this.prepareLogsParams(contractLogsResultsParams, limitOrderParams);
820823
const apiEndpoint = MirrorNodeClient.GET_CONTRACT_RESULT_LOGS_BY_ADDRESS_ENDPOINT.replace(
821824
MirrorNodeClient.ADDRESS_PLACEHOLDER,

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import {
5656
DEFAULT_NULL_LOG_TOPICS,
5757
NOT_FOUND_RES,
5858
} from './eth-config';
59+
import { ethers } from 'ethers';
5960
import { generateEthTestEnv } from './eth-helpers';
6061

6162
dotenv.config({ path: path.resolve(__dirname, '../../test.env') });
@@ -578,8 +579,16 @@ describe('@ethGetLogs using MirrorNode', async function () {
578579

579580
const result = await ethImpl.getLogs(null, '0x5', '0x10', null, DEFAULT_LOG_TOPICS);
580581

581-
expect(result).to.exist;
582582
expectLogData1(result[0]);
583583
expectLogData2(result[1]);
584584
});
585+
586+
it('Should return empty log if address = ZeroAddress', async () => {
587+
restMock.onGet(BLOCKS_LIMIT_ORDER_URL).reply(200, { blocks: [latestBlock] });
588+
restMock.onGet('blocks/0').reply(200, DEFAULT_BLOCK);
589+
restMock.onGet('blocks/latest').reply(200, DEFAULT_BLOCK);
590+
const result = await ethImpl.getLogs(null, '0x0', 'latest', ethers.ZeroAddress, DEFAULT_LOG_TOPICS);
591+
expect(result.length).to.eq(0);
592+
expect(result).to.deep.equal([]);
593+
});
585594
});

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ import { getRequestId, mockData, random20BytesAddress } from './../helpers';
3131
const registry = new Registry();
3232

3333
import pino from 'pino';
34-
import { SDKClientError } from '../../src/lib/errors/SDKClientError';
34+
import { ethers } from 'ethers';
3535
import { predefined } from '../../src/lib/errors/JsonRpcError';
36+
import { SDKClientError } from '../../src/lib/errors/SDKClientError';
3637
import { CacheService } from '../../src/lib/services/cacheService/cacheService';
3738
const logger = pino();
3839
const noTransactions = '?transactions=false';
@@ -732,6 +733,12 @@ describe('MirrorNodeClient', async function () {
732733
expect(firstResult.contract_id).equal(log.contract_id);
733734
expect(firstResult.index).equal(log.index);
734735
});
736+
it('`getContractResultsLogsByAddress` with ZeroAddress ', async () => {
737+
const results = await mirrorNodeInstance.getContractResultsLogsByAddress(ethers.ZeroAddress);
738+
expect(results).to.exist;
739+
expect(results.length).to.eq(0);
740+
expect(results).to.deep.equal([]);
741+
});
735742

736743
it('`getContractCurrentStateByAddressAndSlot`', async () => {
737744
mock

packages/server/tests/acceptance/rpc_batch1.spec.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,41 @@ describe('@api-batch-1 RPC Server Acceptance Tests', function () {
429429
);
430430
expect(logs.length).to.be.greaterThan(2);
431431
});
432+
433+
it('should return empty logs if address = ZeroAddress', async () => {
434+
const logs = await relay.call(
435+
RelayCalls.ETH_ENDPOINTS.ETH_GET_LOGS,
436+
[
437+
{
438+
fromBlock: '0x0',
439+
toBlock: 'latest',
440+
address: ethers.ZeroAddress,
441+
},
442+
],
443+
requestId,
444+
);
445+
expect(logs.length).to.eq(0);
446+
});
447+
448+
it('should return only logs of non-zero addresses', async () => {
449+
const currentBlock = Number(await relay.call(RelayCalls.ETH_ENDPOINTS.ETH_BLOCK_NUMBER, [], requestId));
450+
let blocksBehindLatest = 0;
451+
if (currentBlock > 10) {
452+
blocksBehindLatest = currentBlock - 10;
453+
}
454+
const logs = await relay.call(
455+
RelayCalls.ETH_ENDPOINTS.ETH_GET_LOGS,
456+
[
457+
{
458+
fromBlock: numberTo0x(blocksBehindLatest),
459+
toBlock: 'latest',
460+
address: [ethers.ZeroAddress, contractAddress2],
461+
},
462+
],
463+
requestId,
464+
);
465+
expect(logs.length).to.eq(1);
466+
});
432467
});
433468

434469
describe('Block related RPC calls', () => {

0 commit comments

Comments
 (0)