1+ import { open } from 'node:fs/promises' ;
2+
13import { createHttpTransport , createJsonRpc } from '@solana/rpc-transport' ;
24import type { Rpc } from '@solana/rpc-transport/dist/types/json-rpc-types' ;
3- import fs from 'fs' ;
45import fetchMock from 'jest-fetch-mock-fork' ;
56import path from 'path' ;
67
@@ -10,21 +11,13 @@ const logFilePath = path.resolve(__dirname, '../../../../../test-ledger/validato
1011const genesisHashPattern = / g e n e s i s h a s h : ( [ \d \w ] { 32 , } ) / ;
1112
1213async 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
3023describe ( 'getGenesisHash' , ( ) => {
0 commit comments