Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,24 @@ import { createSolanaRpcApi, SolanaRpcMethods } from '../index';
const logFilePath = path.resolve(__dirname, '../../../../../test-ledger/validator.log');
const genesisHashPattern = /genesis hash: ([\d\w]{32,})/;

async function getGenesisHashFromLogFile() {
return new Promise<string | undefined>((resolve, reject) => {
const logFileStream = fs.createReadStream(logFilePath, { end: 64 * 1024 });
logFileStream.on('error', e => reject(e))

logFileStream.on('data', data => {
const chunk = data.toString('utf-8');
const expectedGenesisHash = chunk.match(genesisHashPattern)?.[1];
if (expectedGenesisHash) {
logFileStream.destroy();
resolve(expectedGenesisHash)
}
})

logFileStream.on('end', () => resolve(undefined));
})
}

describe('getGenesisHash', () => {
let rpc: Rpc<SolanaRpcMethods>;
beforeEach(() => {
Expand All @@ -23,8 +41,7 @@ describe('getGenesisHash', () => {
describe('when sent to a local validator', () => {
it('returns the genesis hash', async () => {
expect.assertions(1);
const logFile = fs.readFileSync(logFilePath, 'utf-8');
const expectedGenesisHash = logFile.match(genesisHashPattern)?.[1];
const expectedGenesisHash = await getGenesisHashFromLogFile();
const genesisHashPromise = rpc.getGenesisHash().send();
await expect(genesisHashPromise).resolves.toBe(expectedGenesisHash);
});
Expand Down