Skip to content

Commit 11211c5

Browse files
committed
refactor: change resolvers to use handler for storing data
1 parent 22e0cd7 commit 11211c5

File tree

43 files changed

+944
-353
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+944
-353
lines changed

.changeset/dull-suits-act.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@pubkey-cache/resolver': patch
3+
'@pubkey-cache/core': patch
4+
'@pubkey-cache/react': patch
5+
'@pubkey-cache/server': patch
6+
---
7+
8+
change resolvers to use handler for storing data

packages/resolver/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@
7474
"maintained node versions"
7575
],
7676
"dependencies": {
77-
"@solana/kit": "^2.1.0"
77+
"@solana/kit": "^2.1.0",
78+
"gill": "^0.9.0",
79+
"zod": "^3.24.3"
7880
},
7981
"devDependencies": {
8082
"helius-sdk": "^1.4.2",
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { createSolanaClient } from 'gill';
2+
import { Helius } from 'helius-sdk';
3+
4+
import { createResolverContextHelius } from '../resolvers/helius/create-resolver-context-helius';
5+
import { ResolverContextHeliusInstance } from '../resolvers/helius/types/resolver-context-helius-instance';
6+
7+
export function createMockHeliusInstance(helius: unknown): ResolverContextHeliusInstance {
8+
return {
9+
context: createResolverContextHelius({ heliusApiKey: '00000000-0000-0000-0000-000000000000' }),
10+
helius: helius as Helius,
11+
solanaClient: createSolanaClient({ urlOrMoniker: 'localnet' }),
12+
};
13+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Helius } from 'helius-sdk';
2+
3+
import { createResolverContextHelius } from '../resolvers/helius/create-resolver-context-helius';
4+
import { createResolverContextHeliusInstance } from '../resolvers/helius/create-resolver-context-helius-instance';
5+
import { ResolverContextHelius } from '../resolvers/helius/types/resolver-context-helius';
6+
7+
describe('create-resolver-context-helius-instance', () => {
8+
const heliusApiKey = '00000000-0000-0000-0000-000000000000';
9+
10+
describe('expected usage', () => {
11+
it('should create an instance with minimal config', () => {
12+
expect.assertions(3);
13+
// ARRANGE
14+
const context: ResolverContextHelius = createResolverContextHelius({
15+
heliusApiKey,
16+
});
17+
// ACT
18+
const instance = createResolverContextHeliusInstance(context);
19+
// ASSERT
20+
expect(instance.context).toEqual(context);
21+
expect(instance.helius).toBeInstanceOf(Helius);
22+
expect(Object.keys(instance)).toEqual(['context', 'helius', 'solanaClient']);
23+
});
24+
});
25+
});
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import { createResolverContextHelius } from '../resolvers/helius/create-resolver-context-helius';
2+
import { ResolverConfigHeliusInput } from '../resolvers/helius/types/resolver-config-helius-input';
3+
4+
describe('create-resolver-context-helius', () => {
5+
const heliusApiKey = '00000000-0000-0000-0000-000000000000';
6+
7+
describe('expected usage', () => {
8+
it('should create a minimal config', () => {
9+
expect.assertions(1);
10+
// ARRANGE
11+
const config: ResolverConfigHeliusInput = { heliusApiKey };
12+
// ACT
13+
const resolver = createResolverContextHelius(config);
14+
// ASSERT
15+
expect(resolver).toMatchInlineSnapshot(`
16+
{
17+
"clusters": [
18+
"SolanaMainnet",
19+
"SolanaDevnet",
20+
],
21+
"config": {
22+
"heliusApiKey": "00000000-0000-0000-0000-000000000000",
23+
"heliusCluster": "mainnet-beta",
24+
"type": "Helius",
25+
},
26+
"provides": [
27+
"Helius",
28+
"SolanaClient",
29+
],
30+
}
31+
`);
32+
});
33+
34+
it('should create a minimal config with custom cluster', () => {
35+
expect.assertions(1);
36+
// ARRANGE
37+
const config: ResolverConfigHeliusInput = {
38+
heliusApiKey,
39+
heliusCluster: 'devnet',
40+
};
41+
// ACT
42+
const resolver = createResolverContextHelius(config);
43+
// ASSERT
44+
expect(resolver).toMatchInlineSnapshot(`
45+
{
46+
"clusters": [
47+
"SolanaMainnet",
48+
"SolanaDevnet",
49+
],
50+
"config": {
51+
"heliusApiKey": "00000000-0000-0000-0000-000000000000",
52+
"heliusCluster": "devnet",
53+
"type": "Helius",
54+
},
55+
"provides": [
56+
"Helius",
57+
"SolanaClient",
58+
],
59+
}
60+
`);
61+
});
62+
});
63+
64+
describe('unexpected usage', () => {
65+
it('should thrown an error with an invalid api key', () => {
66+
expect.assertions(1);
67+
// ARRANGE
68+
const config: ResolverConfigHeliusInput = { heliusApiKey: '00000000000000000000000000000000' };
69+
70+
// ASSERT
71+
expect(() => createResolverContextHelius(config)).toThrowErrorMatchingInlineSnapshot(`
72+
"[
73+
{
74+
"validation": "uuid",
75+
"code": "invalid_string",
76+
"message": "Invalid uuid",
77+
"path": [
78+
"heliusApiKey"
79+
]
80+
}
81+
]"
82+
`);
83+
});
84+
85+
it('should thrown an error with an invalid cluster', () => {
86+
expect.assertions(1);
87+
// ARRANGE
88+
const config: ResolverConfigHeliusInput = {
89+
heliusApiKey,
90+
// @ts-expect-error we are passing in corrupt data
91+
heliusCluster: 'testnet',
92+
};
93+
94+
// ASSERT
95+
expect(() => createResolverContextHelius(config)).toThrowErrorMatchingInlineSnapshot(`
96+
"[
97+
{
98+
"received": "testnet",
99+
"code": "invalid_enum_value",
100+
"options": [
101+
"mainnet-beta",
102+
"devnet"
103+
],
104+
"path": [
105+
"heliusCluster"
106+
],
107+
"message": "Invalid enum value. Expected 'mainnet-beta' | 'devnet', received 'testnet'"
108+
}
109+
]"
110+
`);
111+
});
112+
});
113+
});
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { createResolverContextSolanaClient } from '../resolvers/solana-client/create-resolver-context-solana-client';
2+
import { createResolverContextSolanaClientInstance } from '../resolvers/solana-client/create-resolver-context-solana-client-instance';
3+
import { ResolverContextSolanaClient } from '../resolvers/solana-client/types/resolver-context-solana-client';
4+
5+
describe('create-resolver-context-solana-client-instance', () => {
6+
const endpoint = 'http://localhost:8899';
7+
8+
describe('expected usage', () => {
9+
it('should create an instance with minimal config', () => {
10+
expect.assertions(2);
11+
// ARRANGE
12+
const context: ResolverContextSolanaClient = createResolverContextSolanaClient({
13+
endpoint,
14+
});
15+
// ACT
16+
const instance = createResolverContextSolanaClientInstance(context);
17+
// ASSERT
18+
expect(instance.context).toEqual(context);
19+
expect(Object.keys(instance)).toEqual(['context', 'solanaClient']);
20+
});
21+
});
22+
});
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
import { createResolverContextSolanaClient } from '../resolvers/solana-client/create-resolver-context-solana-client';
2+
import { ResolverConfigSolanaClientInput } from '../resolvers/solana-client/types/resolver-config-solana-client-input';
3+
4+
describe('create-resolver-context-solana-client', () => {
5+
const endpoint = 'https://api.mainnet-beta.solana.com';
6+
7+
describe('expected usage', () => {
8+
it('should create a minimal context', () => {
9+
expect.assertions(1);
10+
// ARRANGE
11+
const config: ResolverConfigSolanaClientInput = { endpoint };
12+
// ACT
13+
const context = createResolverContextSolanaClient(config);
14+
// ASSERT
15+
expect(context).toMatchInlineSnapshot(`
16+
{
17+
"clusters": [
18+
"SolanaCustom",
19+
"SolanaDevnet",
20+
"SolanaMainnet",
21+
"SolanaTestnet",
22+
],
23+
"config": {
24+
"cluster": "mainnet",
25+
"endpoint": "https://api.mainnet-beta.solana.com",
26+
"endpointWs": "wss://api.mainnet-beta.solana.com",
27+
"type": "SolanaClient",
28+
},
29+
"provides": [
30+
"SolanaClient",
31+
],
32+
}
33+
`);
34+
});
35+
36+
it('should create a minimal context with custom cluster', () => {
37+
expect.assertions(1);
38+
// ARRANGE
39+
const config: ResolverConfigSolanaClientInput = { cluster: 'localnet', endpoint: 'http://localhost:8899' };
40+
// ACT
41+
const context = createResolverContextSolanaClient(config);
42+
// ASSERT
43+
expect(context).toMatchInlineSnapshot(`
44+
{
45+
"clusters": [
46+
"SolanaCustom",
47+
"SolanaDevnet",
48+
"SolanaMainnet",
49+
"SolanaTestnet",
50+
],
51+
"config": {
52+
"cluster": "localnet",
53+
"endpoint": "http://localhost:8899",
54+
"endpointWs": "ws://localhost:8899",
55+
"type": "SolanaClient",
56+
},
57+
"provides": [
58+
"SolanaClient",
59+
],
60+
}
61+
`);
62+
});
63+
});
64+
65+
describe('unexpected usage', () => {
66+
it('should thrown an error with an invalid endpoint', () => {
67+
expect.assertions(1);
68+
// ARRANGE
69+
const config: ResolverConfigSolanaClientInput = { endpoint: 'this is not a url' };
70+
71+
// ASSERT
72+
expect(() => createResolverContextSolanaClient(config)).toThrowErrorMatchingInlineSnapshot(`
73+
"[
74+
{
75+
"validation": "url",
76+
"code": "invalid_string",
77+
"message": "Invalid url",
78+
"path": [
79+
"endpoint"
80+
]
81+
},
82+
{
83+
"validation": "url",
84+
"code": "invalid_string",
85+
"message": "Invalid url",
86+
"path": [
87+
"endpointWs"
88+
]
89+
}
90+
]"
91+
`);
92+
});
93+
it('should thrown an error with an invalid endpointWs', () => {
94+
expect.assertions(1);
95+
// ARRANGE
96+
const config: ResolverConfigSolanaClientInput = { endpoint, endpointWs: 'not a ws endpoint' };
97+
98+
// ASSERT
99+
expect(() => createResolverContextSolanaClient(config)).toThrowErrorMatchingInlineSnapshot(`
100+
"[
101+
{
102+
"validation": "url",
103+
"code": "invalid_string",
104+
"message": "Invalid url",
105+
"path": [
106+
"endpointWs"
107+
]
108+
}
109+
]"
110+
`);
111+
});
112+
113+
it('should thrown an error with an invalid cluster', () => {
114+
expect.assertions(1);
115+
// ARRANGE
116+
const config: ResolverConfigSolanaClientInput = {
117+
// @ts-expect-error we are passing in corrupt data
118+
cluster: 'random',
119+
endpoint,
120+
};
121+
122+
// ASSERT
123+
expect(() => createResolverContextSolanaClient(config)).toThrowErrorMatchingInlineSnapshot(`
124+
"[
125+
{
126+
"received": "random",
127+
"code": "invalid_enum_value",
128+
"options": [
129+
"mainnet",
130+
"devnet",
131+
"testnet",
132+
"localnet"
133+
],
134+
"path": [
135+
"cluster"
136+
],
137+
"message": "Invalid enum value. Expected 'mainnet' | 'devnet' | 'testnet' | 'localnet', received 'random'"
138+
}
139+
]"
140+
`);
141+
});
142+
});
143+
});

0 commit comments

Comments
 (0)