Skip to content

Commit 74fa289

Browse files
committed
test: get genesis hash from logfile with readLines API
1 parent bfb1537 commit 74fa289

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

packages/rpc-core/src/rpc-methods/__tests__/get-genesis-hash-test.ts

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import { open } from 'node:fs/promises';
2+
13
import { createHttpTransport, createJsonRpc } from '@solana/rpc-transport';
24
import type { Rpc } from '@solana/rpc-transport/dist/types/json-rpc-types';
3-
import fs from 'fs';
45
import fetchMock from 'jest-fetch-mock-fork';
56
import path from 'path';
67

@@ -10,21 +11,13 @@ const logFilePath = path.resolve(__dirname, '../../../../../test-ledger/validato
1011
const genesisHashPattern = /genesis hash: ([\d\w]{32,})/;
1112

1213
async function getGenesisHashFromLogFile() {
13-
return new Promise<string | undefined>((resolve, reject) => {
14-
const logFileStream = fs.createReadStream(logFilePath, { end: 64 * 1024 });
15-
logFileStream.on('error', e => reject(e));
16-
17-
logFileStream.on('data', data => {
18-
const chunk = data.toString('utf-8');
19-
const expectedGenesisHash = chunk.match(genesisHashPattern)?.[1];
20-
if (expectedGenesisHash) {
21-
logFileStream.destroy();
22-
resolve(expectedGenesisHash);
23-
}
24-
});
25-
26-
logFileStream.on('end', () => resolve(undefined));
27-
});
14+
const file = await open(logFilePath);
15+
for await (const line of file.readLines({ encoding: 'utf-8' })) {
16+
const match = line.match(genesisHashPattern);
17+
if (match) {
18+
return match[1];
19+
}
20+
}
2821
}
2922

3023
describe('getGenesisHash', () => {

0 commit comments

Comments
 (0)