-
Notifications
You must be signed in to change notification settings - Fork 22
/
spv.test.ts
28 lines (21 loc) · 966 Bytes
/
spv.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
jest.mock('cross-fetch');
import type { SPVResponse } from '@kadena/types';
import { spv } from '../spv';
import { mockFetch } from './mockdata/mockFetch';
import { testSPVProof, testSPVRequest } from './mockdata/Pact';
import fetch, { Response } from 'cross-fetch';
const mockedFunctionFetch = fetch as jest.MockedFunction<typeof fetch>;
mockedFunctionFetch.mockImplementation(
mockFetch as jest.MockedFunction<typeof fetch>,
);
test('/spv returns SPV proof', async () => {
const actual: string | Response = await spv(testSPVRequest, '');
const expected: SPVResponse = testSPVProof;
expect(actual).toEqual(expected);
});
test('/spv returns error message when proof is young', () => {
const actual: Promise<string | Response> = spv(testSPVRequest, '/tooyoung');
const expectedErrorMsg =
'SPV target not reachable: target chain not reachable. Chainweb instance is too young';
return expect(actual).rejects.toThrowError(expectedErrorMsg);
});