Skip to content
This repository was archived by the owner on Aug 22, 2025. It is now read-only.

Commit f362483

Browse files
committed
test: improve tests
1 parent 10ea55c commit f362483

4 files changed

Lines changed: 278 additions & 309 deletions

File tree

src/utils.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,6 @@ export function getAddressesByProtocol(
185185
});
186186
}
187187

188-
export function validateAddress(address: string): void {
189-
try {
190-
getFormattedAddressesByProtocol([address], ['evm', 'starknet']);
191-
} catch {
192-
throw new Error('invalid address');
193-
}
194-
}
195-
196188
export const {
197189
multicall,
198190
Multicaller,

src/utils/vp.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import {
77
getProvider,
88
getSnapshots,
99
Multicaller,
10-
subgraphRequest,
11-
validateAddress
10+
subgraphRequest
1211
} from '../utils';
1312
import _strategies from '../strategies';
1413
import { Score, Snapshot, VotingPower } from '../types';
@@ -31,10 +30,7 @@ export async function getVp(
3130
space: string,
3231
delegation?: boolean
3332
): Promise<VotingPower> {
34-
if (strategies.some((s) => !_strategies[s.name])) {
35-
throw new Error('invalid strategies');
36-
}
37-
// Ensure that the address is either a valid EVM address or Starknet address
33+
validateStrategies(strategies);
3834
validateAddress(address);
3935

4036
const networks = [...new Set(strategies.map((s) => s.network || network))];
@@ -237,3 +233,22 @@ export async function getDelegations(
237233
out: delegationOut
238234
};
239235
}
236+
237+
// Ensure that the address is either a valid EVM address or Starknet address
238+
function validateAddress(address: string): void {
239+
try {
240+
getFormattedAddressesByProtocol([address], ['evm', 'starknet']);
241+
} catch {
242+
throw new Error('invalid address');
243+
}
244+
}
245+
246+
function validateStrategies(strategies: any[]): void {
247+
const invalidStrategies = strategies
248+
.filter((s) => !_strategies[s.name])
249+
.map((s) => s.name);
250+
251+
if (invalidStrategies.length > 0) {
252+
throw new Error(`invalid strategies: ${invalidStrategies.join(', ')}`);
253+
}
254+
}
Lines changed: 80 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -1,158 +1,84 @@
1-
export const vpTestFixtures = {
2-
withDelegation: {
3-
address: '0xeF8305E140ac520225DAf050e2f71d5fBcC543e7',
4-
space: 'cvx.eth',
5-
network: '1',
6-
snapshot: 15354134,
7-
strategies: [
8-
{
9-
name: 'erc20-balance-of',
10-
params: {
11-
symbol: 'CVX',
12-
address: '0x72a19342e8F1838460eBFCCEf09F6585e32db86E',
13-
decimals: 18
14-
}
15-
},
16-
{
17-
name: 'eth-balance',
18-
network: '100',
19-
params: {}
20-
},
21-
{
22-
name: 'eth-balance',
23-
network: '1',
24-
params: {}
25-
},
26-
{
27-
name: 'eth-balance',
28-
network: '10',
29-
params: {}
30-
}
31-
]
32-
},
33-
evmWithMixedProtocols: {
34-
address: '0xeF8305E140ac520225DAf050e2f71d5fBcC543e7',
35-
space: 'cvx.eth',
36-
network: '1',
37-
snapshot: 15354134,
38-
strategies: [
39-
{
40-
name: 'whitelist',
41-
params: {
42-
addresses: [
43-
'0xeF8305E140ac520225DAf050e2f71d5fBcC543e7',
44-
'0x07f71118e351c02f6EC7099C8CDf93AED66CEd8406E94631cC91637f7D7F203A'
45-
]
46-
}
47-
},
48-
{
49-
name: 'eth-balance',
50-
network: '100',
51-
params: {}
52-
}
53-
]
54-
},
55-
starknetWithMixedProtocols: {
56-
address:
57-
'0x07f71118e351c02f6EC7099C8CDf93AED66CEd8406E94631cC91637f7D7F203A',
58-
space: 'cvx.eth',
59-
network: '1',
60-
snapshot: 15354134,
61-
strategies: [
62-
{
63-
name: 'whitelist',
64-
params: {
65-
addresses: [
66-
'0xeF8305E140ac520225DAf050e2f71d5fBcC543e7',
67-
'0x07f71118e351c02f6EC7099C8CDf93AED66CEd8406E94631cC91637f7D7F203A'
68-
]
69-
}
70-
},
71-
{
72-
name: 'eth-balance',
73-
network: '100',
74-
params: {}
75-
}
76-
]
77-
},
78-
starknetWithEvmProtocol: {
79-
address:
80-
'0x07f71118e351c02f6EC7099C8CDf93AED66CEd8406E94631cC91637f7D7F203A',
81-
space: 'cvx.eth',
82-
network: '1',
83-
snapshot: 15354134,
84-
strategies: [
85-
{
86-
name: 'eth-balance',
87-
network: '100',
88-
params: {}
89-
}
90-
]
91-
},
92-
invalidAddress: {
93-
address: '0xeF8305E140ac520225DAf050e2f71d5fBcC543',
94-
space: 'cvx.eth',
95-
network: '1',
96-
snapshot: 15354134,
97-
strategies: [
98-
{
99-
name: 'whitelist',
100-
params: {
101-
addresses: [
102-
'0xeF8305E140ac520225DAf050e2f71d5fBcC543e7',
103-
'0x07f71118e351c02f6EC7099C8CDf93AED66CEd8406E94631cC91637f7D7F203A'
104-
]
105-
}
106-
},
107-
{
108-
name: 'eth-balance',
109-
network: '100',
110-
params: {}
1+
export const testConfig = {
2+
network: '1',
3+
snapshot: 15354134,
4+
space: 'cvx.eth',
5+
evmAddress: '0xeF8305E140ac520225DAf050e2f71d5fBcC543e7',
6+
starknetAddress:
7+
'0x07f71118e351c02f6EC7099C8CDf93AED66CEd8406E94631cC91637f7D7F203A'
8+
};
9+
10+
export const strategies = {
11+
withDelegation: [
12+
{
13+
name: 'erc20-balance-of',
14+
params: {
15+
symbol: 'CVX',
16+
address: '0x72a19342e8F1838460eBFCCEf09F6585e32db86E',
17+
decimals: 18
11118
}
112-
]
113-
},
114-
invalidEvmLikeAddress: {
115-
address: '0x91Fd2C8d24767Db4eCe7069aA27832FfaF8590F3',
116-
space: 'cvx.eth',
117-
network: '1',
118-
snapshot: 15354134,
119-
strategies: [
120-
{
121-
name: 'whitelist',
122-
params: {
123-
addresses: [
124-
'0xeF8305E140ac520225DAf050e2f71d5fBcC543e7',
125-
'0x07f71118e351c02f6EC7099C8CDf93AED66CEd8406E94631cC91637f7D7F203A'
126-
]
127-
}
128-
},
129-
{
130-
name: 'eth-balance',
131-
network: '100',
132-
params: {}
19+
},
20+
{
21+
name: 'eth-balance',
22+
network: '100',
23+
params: {}
24+
},
25+
{
26+
name: 'eth-balance',
27+
network: '1',
28+
params: {}
29+
},
30+
{
31+
name: 'eth-balance',
32+
network: '10',
33+
params: {}
34+
}
35+
],
36+
mixed: [
37+
{
38+
name: 'whitelist',
39+
params: {
40+
addresses: [testConfig.evmAddress, testConfig.starknetAddress]
13341
}
134-
]
135-
},
136-
invalidStrategies: {
137-
address: '0xeF8305E140ac520225DAf050e2f71d5fBcC543e7',
138-
space: 'cvx.eth',
139-
network: '1',
140-
snapshot: 15354134,
141-
strategies: [
142-
{
143-
name: 'whitelist-invalid',
144-
params: {
145-
addresses: [
146-
'0xeF8305E140ac520225DAf050e2f71d5fBcC543e7',
147-
'0x07f71118e351c02f6EC7099C8CDf93AED66CEd8406E94631cC91637f7D7F203A'
148-
]
149-
}
150-
},
151-
{
152-
name: 'eth-balance',
153-
network: '100',
154-
params: {}
42+
},
43+
{
44+
name: 'eth-balance',
45+
network: '100',
46+
params: {}
47+
}
48+
],
49+
evmOnly: [
50+
{
51+
name: 'eth-balance',
52+
network: '100',
53+
params: {}
54+
}
55+
],
56+
singleInvalid: [
57+
{
58+
name: 'whitelist-invalid',
59+
params: {
60+
addresses: [testConfig.evmAddress, testConfig.starknetAddress]
15561
}
156-
]
157-
}
62+
},
63+
{
64+
name: 'eth-balance',
65+
network: '100',
66+
params: {}
67+
}
68+
],
69+
multipleInvalid: [
70+
{
71+
name: 'strategy-one-invalid',
72+
params: {}
73+
},
74+
{
75+
name: 'strategy-two-invalid',
76+
params: {}
77+
},
78+
{
79+
name: 'eth-balance',
80+
network: '100',
81+
params: {}
82+
}
83+
]
15884
};

0 commit comments

Comments
 (0)