Skip to content

Commit 8f3a02b

Browse files
committed
modified test
1 parent fcfeca1 commit 8f3a02b

File tree

1 file changed

+15
-24
lines changed

1 file changed

+15
-24
lines changed
Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,32 @@
1-
import { Base58EncodedAddress } from '@solana/addresses';
21
import { createHttpTransport, createJsonRpc } from '@solana/rpc-transport';
32
import type { Rpc } from '@solana/rpc-transport/dist/types/json-rpc-types';
3+
import fs from 'fs';
44
import fetchMock from 'jest-fetch-mock-fork';
5+
import path from 'path';
56

67
import { createSolanaRpcApi, SolanaRpcMethods } from '../index';
78

8-
// TODO: We may want to replace the higher clusters with just the local
9-
// validator, since this is within the live test suite anyhow.
10-
// Also, with further manipulation capabilities over the local validator,
11-
// we can explore error testing as well
12-
const genesisHashMap: [string, Base58EncodedAddress][] = [
13-
['https://api.devnet.solana.com', 'EtWTRABZaYq6iMfeYKouRu166VU2xqa1wcaWoxPkrZBG' as Base58EncodedAddress],
14-
['https://api.testnet.solana.com', '4uhcVJyU9pJkvQyS88uRDiswHXSCkY3zQawwpjk2NsNY' as Base58EncodedAddress],
15-
['https://api.mainnet-beta.solana.com', '5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d' as Base58EncodedAddress],
16-
];
9+
const logFilePath = path.resolve(__dirname, '../../../../../test-ledger/validator.log');
10+
const genesisHashPattern = /genesis hash: ([\d\w]{44})/;
1711

1812
describe('getGenesisHash', () => {
1913
let rpc: Rpc<SolanaRpcMethods>;
20-
const createRpcForTest = (url: string) => {
21-
rpc = createJsonRpc<SolanaRpcMethods>({
22-
api: createSolanaRpcApi(),
23-
transport: createHttpTransport({ url }),
24-
});
25-
};
2614
beforeEach(() => {
2715
fetchMock.resetMocks();
2816
fetchMock.dontMock();
17+
rpc = createJsonRpc<SolanaRpcMethods>({
18+
api: createSolanaRpcApi(),
19+
transport: createHttpTransport({ url: 'http://127.0.0.1:8899' }),
20+
});
2921
});
3022

31-
genesisHashMap.forEach(([url, expectedGenesisHash]) => {
32-
describe(`when sent to ${url}`, () => {
33-
it(`returns ${expectedGenesisHash}`, async () => {
34-
expect.assertions(1);
35-
createRpcForTest(url);
36-
const genesisHashPromise = rpc.getGenesisHash().send();
37-
await expect(genesisHashPromise).resolves.toBe(expectedGenesisHash);
38-
});
23+
describe('when sent to a local validator', () => {
24+
it('returns the genesis hash', async () => {
25+
expect.assertions(1);
26+
const logFile = fs.readFileSync(logFilePath, 'utf-8');
27+
const expectedGenesisHash = logFile.match(genesisHashPattern)?.[1];
28+
const genesisHashPromise = rpc.getGenesisHash().send();
29+
await expect(genesisHashPromise).resolves.toBe(expectedGenesisHash);
3930
});
4031
});
4132
});

0 commit comments

Comments
 (0)