Skip to content

Commit 6a4e588

Browse files
committed
fixup! feat(cardano-services-client): restore KoraLabsHandleProvider
1 parent 5742bfc commit 6a4e588

File tree

6 files changed

+101
-20
lines changed

6 files changed

+101
-20
lines changed

.github/workflows/continuous-integration-unit-tests.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,6 @@ jobs:
4242
- name: 🔬 Test
4343
run: |
4444
yarn test --forceExit
45+
yarn test:handle
4546
env:
4647
NODE_OPTIONS: '--max_old_space_size=8192'

packages/cardano-services-client/src/HandleProvider/KoraLabsHandleProvider.ts

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,27 +58,31 @@ export class KoraLabsHandleProvider implements HandleProvider {
5858
this.policyId = policyId;
5959
}
6060

61-
async resolveHandles(args: ResolveHandlesArgs): Promise<Array<HandleResolution | null>> {
62-
try {
63-
const results = await Promise.all(
64-
args.handles.map((handle) => this.axiosClient.get<IHandle>(`${paths.handles}/${handle}`))
65-
);
66-
return results.map(({ data: apiResponse }) => toHandleResolution({ apiResponse, policyId: this.policyId }));
67-
} catch (error) {
68-
if (axios.isAxiosError(error)) {
69-
if (error.request) {
70-
throw new ProviderError(ProviderFailure.ConnectionFailure, error, error.code);
71-
}
61+
resolveHandles({ handles }: ResolveHandlesArgs): Promise<Array<HandleResolution | null>> {
62+
// eslint-disable-next-line unicorn/consistent-function-scoping
63+
const resolveHandle = async (handle: string) => {
64+
try {
65+
const { data } = await this.axiosClient.get<IHandle>(`${paths.handles}/${handle}`);
66+
67+
return toHandleResolution({ apiResponse: data, policyId: this.policyId });
68+
} catch (error) {
69+
if (error instanceof ProviderError) throw error;
70+
if (axios.isAxiosError(error)) {
71+
if (error.response?.status === 404) return null;
72+
if (error.request) throw new ProviderError(ProviderFailure.ConnectionFailure, error, error.code);
7273

73-
if (error.response?.status === 404) {
74-
return [null];
74+
throw new ProviderError(
75+
ProviderFailure.Unhealthy,
76+
error,
77+
`Failed to resolve handles due to: ${error.message}`
78+
);
7579
}
7680

77-
throw new ProviderError(ProviderFailure.Unhealthy, error, `Failed to resolve handles due to: ${error.message}`);
81+
throw new ProviderError(ProviderFailure.Unknown, error, 'Failed to resolve handles');
7882
}
79-
if (error instanceof ProviderError) throw error;
80-
throw new ProviderError(ProviderFailure.Unknown, error, 'Failed to resolve handles');
81-
}
83+
};
84+
85+
return Promise.all(handles.map((handle) => resolveHandle(handle)));
8286
}
8387

8488
async healthCheck(): Promise<HealthCheckResponse> {

packages/cardano-services-client/test/HandleProvider/KoraLabsHandleProvider.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe('KoraLabsHandleProvider', () => {
3434
});
3535

3636
describe('resolveHandles', () => {
37-
test('HandlesProvider should resolve a single handle', async () => {
37+
test('HandleProvider should resolve a single handle', async () => {
3838
axiosMock.onGet().replyOnce(200, getAliceHandleAPIResponse);
3939
const args = {
4040
handles: ['alice']
@@ -102,8 +102,9 @@ describe('KoraLabsHandleProvider', () => {
102102
describe('get policy ids', () => {
103103
test('HandleProvider should get handle policy ids', async () => {
104104
const policyIds = await provider.getPolicyIds();
105-
await expect(policyIds.length).toEqual(1);
106-
await expect(policyIds).toEqual([config.policyId]);
105+
106+
expect(policyIds.length).toEqual(1);
107+
expect(policyIds).toEqual([config.policyId]);
107108
});
108109
});
109110
});

packages/e2e/jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ module.exports = {
2727
projects: [
2828
{ ...project('blockfrost'), globalSetup: './test/blockfrost/setup.ts' },
2929
project('blockfrost-providers'),
30+
project('handle'),
3031
project('local-network'),
3132
project('long-running'),
3233
project('ogmios'),

packages/e2e/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"test": "echo 'test' command not implemented yet",
2525
"test:blockfrost": "jest -c jest.config.js --forceExit --selectProjects blockfrost --runInBand --verbose",
2626
"test:utils": "jest -c jest.config.js --forceExit --selectProjects utils --verbose",
27+
"test:handle": "jest -c jest.config.js --forceExit --selectProjects handle --runInBand --verbose",
2728
"test:long-running": "jest -c jest.config.js --forceExit --selectProjects long-running --runInBand --verbose",
2829
"test:local-network": "jest -c jest.config.js --forceExit --selectProjects local-network --runInBand --verbose",
2930
"test:projection": "jest -c jest.config.js --forceExit --selectProjects projection --runInBand --verbose",
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/* eslint-disable no-magic-numbers */
2+
/* eslint-disable camelcase */
3+
import { Cardano, HandleResolution } from '@cardano-sdk/core';
4+
import { KoraLabsHandleProvider } from '@cardano-sdk/cardano-services-client';
5+
6+
const handlePolicyId = 'f0ff48bbb7bbe9d59a40f1ce90e9e9d0ff5002ec48f232b49ca0fb9a';
7+
8+
const config = {
9+
policyId: Cardano.PolicyId(handlePolicyId),
10+
serverUrl: 'https://preprod.api.handle.me/'
11+
};
12+
13+
const checkHandleResolution = (source: string, result: unknown) => {
14+
expect(typeof result).toBe('object');
15+
16+
const { backgroundImage, cardanoAddress, handle, hasDatum, image, policyId, profilePic } = result as HandleResolution;
17+
18+
expect(['string', 'undefined']).toContain(typeof backgroundImage);
19+
expect(typeof cardanoAddress).toBe('string');
20+
expect(cardanoAddress.startsWith('addr_')).toBe(true);
21+
expect(handle).toBe(source);
22+
expect(typeof hasDatum).toBe('boolean');
23+
expect(typeof image).toBe('string');
24+
expect(policyId).toBe(handlePolicyId);
25+
expect(['string', 'undefined']).toContain(typeof profilePic);
26+
};
27+
28+
describe('KoraLabsHandleProvider', () => {
29+
let provider: KoraLabsHandleProvider;
30+
31+
beforeAll(() => {
32+
provider = new KoraLabsHandleProvider(config);
33+
});
34+
35+
describe('resolveHandles', () => {
36+
test('HandleProvider should resolve a single handle', async () => {
37+
const [result] = await provider.resolveHandles({ handles: ['test_handle_1'] });
38+
39+
checkHandleResolution('test_handle_1', result);
40+
});
41+
42+
test('HandleProvider should resolve multiple handles', async () => {
43+
const [result2, result3] = await provider.resolveHandles({ handles: ['test_handle_2', 'test_handle_3'] });
44+
45+
checkHandleResolution('test_handle_2', result2);
46+
checkHandleResolution('test_handle_3', result3);
47+
});
48+
49+
test('HandleProvider should return null for for not found handle', async () => {
50+
const [resultN, result1] = await provider.resolveHandles({ handles: ['does_not_exists', 'test_handle_1'] });
51+
52+
expect(resultN).toBe(null);
53+
checkHandleResolution('test_handle_1', result1);
54+
});
55+
});
56+
57+
describe('health checks', () => {
58+
test('HandleProvider should get ok health check', async () => {
59+
const result = await provider.healthCheck();
60+
61+
expect(result.ok).toEqual(true);
62+
});
63+
});
64+
65+
describe('get policy ids', () => {
66+
test('HandleProvider should get handle policy ids', async () => {
67+
const policyIds = await provider.getPolicyIds();
68+
69+
expect(policyIds.length).toEqual(1);
70+
expect(policyIds).toEqual([config.policyId]);
71+
});
72+
});
73+
});

0 commit comments

Comments
 (0)