Skip to content

Commit 5694531

Browse files
committed
make ci lut checks not shit
1 parent 8685a2c commit 5694531

File tree

2 files changed

+139
-127
lines changed

2 files changed

+139
-127
lines changed

sdk/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"test": "mocha -r ts-node/register tests/**/*.ts",
1919
"test:inspect": "mocha --inspect-brk -r ts-node/register tests/**/*.ts",
2020
"test:bignum": "mocha -r ts-node/register tests/bn/**/*.ts",
21+
"test:ci": "mocha -r ts-node/register tests/ci/**/*.ts",
2122
"patch-and-pub": "npm version patch --force && npm publish",
2223
"prettify": "prettier --check './src/***/*.ts'",
2324
"prettify:fix": "prettier --write './{src,tests}/***/*.ts'",

sdk/tests/ci/verifyConstants.ts

Lines changed: 138 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -80,56 +80,53 @@ describe('Verify Constants', function () {
8080
});
8181

8282
it('has all mainnet markets', async () => {
83+
const errors: string[] = [];
84+
const missingLutAddresses: { type: string; marketIndex: number; address: string; description: string }[] = [];
85+
8386
const spotMarkets = mainnetDriftClient.getSpotMarketAccounts();
8487
spotMarkets.sort((a, b) => a.marketIndex - b.marketIndex);
8588

8689
for (const market of spotMarkets) {
8790
const correspondingConfigMarket = MainnetSpotMarkets.find(
8891
(configMarket) => configMarket.marketIndex === market.marketIndex
8992
);
90-
assert(
91-
correspondingConfigMarket !== undefined,
92-
`Market ${
93-
market.marketIndex
94-
} not found in MainnetSpotMarkets. market: ${market.pubkey.toBase58()}`
95-
);
96-
assert(
97-
correspondingConfigMarket.oracle.toBase58() == market.oracle.toBase58(),
98-
`Oracle mismatch for mainnet spot market ${
99-
market.marketIndex
100-
}, market: ${market.pubkey.toBase58()}, constants: ${correspondingConfigMarket.oracle.toBase58()}, chain: ${market.oracle.toBase58()}`
101-
);
102-
assert(
103-
getVariant(correspondingConfigMarket.oracleSource) ===
104-
getVariant(market.oracleSource),
105-
`Oracle source mismatch for mainnet spot market ${
106-
market.marketIndex
107-
}, market: ${market.pubkey.toBase58()}, constants: ${getVariant(
108-
correspondingConfigMarket.oracleSource
109-
)}, chain: ${getVariant(market.oracleSource)}`
110-
);
111-
assert(
112-
correspondingConfigMarket.mint.toBase58() === market.mint.toBase58(),
113-
`Mint mismatch for mainnet spot market ${
114-
market.marketIndex
115-
}, market: ${market.pubkey.toBase58()}, constants: ${correspondingConfigMarket.mint.toBase58()}, chain: ${market.mint.toBase58()}`
116-
);
93+
94+
if (correspondingConfigMarket === undefined) {
95+
errors.push(`Market ${market.marketIndex} not found in MainnetSpotMarkets. market: ${market.pubkey.toBase58()}`);
96+
continue;
97+
}
98+
99+
if (correspondingConfigMarket.oracle.toBase58() !== market.oracle.toBase58()) {
100+
errors.push(`Oracle mismatch for mainnet spot market ${market.marketIndex}, market: ${market.pubkey.toBase58()}, constants: ${correspondingConfigMarket.oracle.toBase58()}, chain: ${market.oracle.toBase58()}`);
101+
}
102+
103+
if (getVariant(correspondingConfigMarket.oracleSource) !== getVariant(market.oracleSource)) {
104+
errors.push(`Oracle source mismatch for mainnet spot market ${market.marketIndex}, market: ${market.pubkey.toBase58()}, constants: ${getVariant(correspondingConfigMarket.oracleSource)}, chain: ${getVariant(market.oracleSource)}`);
105+
}
106+
107+
if (correspondingConfigMarket.mint.toBase58() !== market.mint.toBase58()) {
108+
errors.push(`Mint mismatch for mainnet spot market ${market.marketIndex}, market: ${market.pubkey.toBase58()}, constants: ${correspondingConfigMarket.mint.toBase58()}, chain: ${market.mint.toBase58()}`);
109+
}
117110

118111
const lutHasMarket = lutAccounts.includes(market.pubkey.toBase58());
119-
assert(
120-
lutHasMarket,
121-
`Mainnet LUT is missing spot market ${
122-
market.marketIndex
123-
} pubkey ${market.pubkey.toBase58()}`
124-
);
112+
if (!lutHasMarket) {
113+
missingLutAddresses.push({
114+
type: 'spot',
115+
marketIndex: market.marketIndex,
116+
address: market.pubkey.toBase58(),
117+
description: 'market'
118+
});
119+
}
125120

126121
const lutHasMarketOracle = lutAccounts.includes(market.oracle.toBase58());
127-
assert(
128-
lutHasMarketOracle,
129-
`Mainnet LUT is missing spot market ${
130-
market.marketIndex
131-
} oracle ${market.oracle.toBase58()}`
132-
);
122+
if (!lutHasMarketOracle) {
123+
missingLutAddresses.push({
124+
type: 'spot',
125+
marketIndex: market.marketIndex,
126+
address: market.oracle.toBase58(),
127+
description: 'oracle'
128+
});
129+
}
133130

134131
if (
135132
isOneOfVariant(market.oracleSource, [
@@ -140,7 +137,7 @@ describe('Verify Constants', function () {
140137
])
141138
) {
142139
if (!correspondingConfigMarket.pythFeedId) {
143-
assert(false, `spot market ${market.marketIndex} missing feed id`);
140+
errors.push(`spot market ${market.marketIndex} missing feed id`);
144141
}
145142
}
146143
}
@@ -152,46 +149,39 @@ describe('Verify Constants', function () {
152149
const correspondingConfigMarket = MainnetPerpMarkets.find(
153150
(configMarket) => configMarket.marketIndex === market.marketIndex
154151
);
155-
assert(
156-
correspondingConfigMarket !== undefined,
157-
`Market ${
158-
market.marketIndex
159-
} not found in MainnetPerpMarkets, market: ${market.pubkey.toBase58()}`
160-
);
161-
assert(
162-
correspondingConfigMarket.oracle.toBase58() ==
163-
market.amm.oracle.toBase58(),
164-
`Oracle mismatch for mainnet perp market ${
165-
market.marketIndex
166-
}, market: ${market.pubkey.toBase58()}, constants: ${correspondingConfigMarket.oracle.toBase58()}, chain: ${market.amm.oracle.toBase58()}`
167-
);
168-
assert(
169-
getVariant(correspondingConfigMarket.oracleSource) ===
170-
getVariant(market.amm.oracleSource),
171-
`Oracle source mismatch for mainnet perp market ${
172-
market.marketIndex
173-
}, market: ${market.pubkey.toBase58()}, constants: ${getVariant(
174-
correspondingConfigMarket.oracleSource
175-
)}, chain: ${getVariant(market.amm.oracleSource)}`
176-
);
152+
153+
if (correspondingConfigMarket === undefined) {
154+
errors.push(`Market ${market.marketIndex} not found in MainnetPerpMarkets, market: ${market.pubkey.toBase58()}`);
155+
continue;
156+
}
157+
158+
if (correspondingConfigMarket.oracle.toBase58() !== market.amm.oracle.toBase58()) {
159+
errors.push(`Oracle mismatch for mainnet perp market ${market.marketIndex}, market: ${market.pubkey.toBase58()}, constants: ${correspondingConfigMarket.oracle.toBase58()}, chain: ${market.amm.oracle.toBase58()}`);
160+
}
161+
162+
if (getVariant(correspondingConfigMarket.oracleSource) !== getVariant(market.amm.oracleSource)) {
163+
errors.push(`Oracle source mismatch for mainnet perp market ${market.marketIndex}, market: ${market.pubkey.toBase58()}, constants: ${getVariant(correspondingConfigMarket.oracleSource)}, chain: ${getVariant(market.amm.oracleSource)}`);
164+
}
177165

178166
const lutHasMarket = lutAccounts.includes(market.pubkey.toBase58());
179-
assert(
180-
lutHasMarket,
181-
`Mainnet LUT is missing perp market ${
182-
market.marketIndex
183-
} pubkey ${market.pubkey.toBase58()}`
184-
);
167+
if (!lutHasMarket) {
168+
missingLutAddresses.push({
169+
type: 'perp',
170+
marketIndex: market.marketIndex,
171+
address: market.pubkey.toBase58(),
172+
description: 'market'
173+
});
174+
}
185175

186-
const lutHasMarketOracle = lutAccounts.includes(
187-
market.amm.oracle.toBase58()
188-
);
189-
assert(
190-
lutHasMarketOracle,
191-
`Mainnet LUT is missing perp market ${
192-
market.marketIndex
193-
} oracle ${market.amm.oracle.toBase58()}`
194-
);
176+
const lutHasMarketOracle = lutAccounts.includes(market.amm.oracle.toBase58());
177+
if (!lutHasMarketOracle) {
178+
missingLutAddresses.push({
179+
type: 'perp',
180+
marketIndex: market.marketIndex,
181+
address: market.amm.oracle.toBase58(),
182+
description: 'oracle'
183+
});
184+
}
195185

196186
if (
197187
isOneOfVariant(market.amm.oracleSource, [
@@ -202,47 +192,63 @@ describe('Verify Constants', function () {
202192
])
203193
) {
204194
if (!correspondingConfigMarket.pythFeedId) {
205-
assert(false, `perp market ${market.marketIndex} missing feed id`);
195+
errors.push(`perp market ${market.marketIndex} missing feed id`);
206196
}
207197
}
208198
}
199+
200+
// Print all missing LUT addresses
201+
if (missingLutAddresses.length > 0) {
202+
console.log('\n=== MISSING LUT ADDRESSES ===');
203+
missingLutAddresses.forEach(({ type, marketIndex, address, description }) => {
204+
console.log(`${type.toUpperCase()} Market ${marketIndex} ${description}: ${address}`);
205+
});
206+
console.log(`\nTotal missing LUT addresses: ${missingLutAddresses.length}`);
207+
}
208+
209+
// Print all errors
210+
if (errors.length > 0) {
211+
console.log('\n=== VALIDATION ERRORS ===');
212+
errors.forEach((error, index) => {
213+
console.log(`${index + 1}. ${error}`);
214+
});
215+
console.log(`\nTotal errors: ${errors.length}`);
216+
}
217+
218+
// Fail if there are any issues
219+
const totalIssues = errors.length + missingLutAddresses.length;
220+
if (totalIssues > 0) {
221+
assert(false, `Found ${totalIssues} issues (${errors.length} validation errors, ${missingLutAddresses.length} missing LUT addresses). See details above.`);
222+
}
209223
});
210224

211225
it('has all devnet markets', async () => {
226+
const errors: string[] = [];
227+
212228
const spotMarkets = devnetDriftClient.getSpotMarketAccounts();
213229
spotMarkets.sort((a, b) => a.marketIndex - b.marketIndex);
214230

215231
for (const market of spotMarkets) {
216232
const correspondingConfigMarket = DevnetSpotMarkets.find(
217233
(configMarket) => configMarket.marketIndex === market.marketIndex
218234
);
219-
assert(
220-
correspondingConfigMarket !== undefined,
221-
`Market ${
222-
market.marketIndex
223-
} not found in DevnetSpotMarkets, market: ${market.pubkey.toBase58()}`
224-
);
225-
assert(
226-
correspondingConfigMarket.oracle.toBase58() == market.oracle.toBase58(),
227-
`Oracle mismatch for devnet spot market ${
228-
market.marketIndex
229-
}, market: ${market.pubkey.toBase58()}, constants: ${correspondingConfigMarket.oracle.toBase58()}, chain: ${market.oracle.toBase58()}`
230-
);
231-
assert(
232-
getVariant(correspondingConfigMarket.oracleSource) ===
233-
getVariant(market.oracleSource),
234-
`Oracle source mismatch for devnet spot market ${
235-
market.marketIndex
236-
}, market: ${market.pubkey.toBase58()}, constants: ${getVariant(
237-
correspondingConfigMarket.oracleSource
238-
)}, chain: ${getVariant(market.oracleSource)}`
239-
);
240-
assert(
241-
correspondingConfigMarket.mint.toBase58() === market.mint.toBase58(),
242-
`Mint mismatch for devnet spot market ${
243-
market.marketIndex
244-
}, market: ${market.pubkey.toBase58()}, constants: ${correspondingConfigMarket.mint.toBase58()}, chain: ${market.mint.toBase58()}`
245-
);
235+
236+
if (correspondingConfigMarket === undefined) {
237+
errors.push(`Market ${market.marketIndex} not found in DevnetSpotMarkets, market: ${market.pubkey.toBase58()}`);
238+
continue;
239+
}
240+
241+
if (correspondingConfigMarket.oracle.toBase58() !== market.oracle.toBase58()) {
242+
errors.push(`Oracle mismatch for devnet spot market ${market.marketIndex}, market: ${market.pubkey.toBase58()}, constants: ${correspondingConfigMarket.oracle.toBase58()}, chain: ${market.oracle.toBase58()}`);
243+
}
244+
245+
if (getVariant(correspondingConfigMarket.oracleSource) !== getVariant(market.oracleSource)) {
246+
errors.push(`Oracle source mismatch for devnet spot market ${market.marketIndex}, market: ${market.pubkey.toBase58()}, constants: ${getVariant(correspondingConfigMarket.oracleSource)}, chain: ${getVariant(market.oracleSource)}`);
247+
}
248+
249+
if (correspondingConfigMarket.mint.toBase58() !== market.mint.toBase58()) {
250+
errors.push(`Mint mismatch for devnet spot market ${market.marketIndex}, market: ${market.pubkey.toBase58()}, constants: ${correspondingConfigMarket.mint.toBase58()}, chain: ${market.mint.toBase58()}`);
251+
}
246252
}
247253

248254
const perpMarkets = devnetDriftClient.getPerpMarketAccounts();
@@ -252,28 +258,33 @@ describe('Verify Constants', function () {
252258
const correspondingConfigMarket = DevnetPerpMarkets.find(
253259
(configMarket) => configMarket.marketIndex === market.marketIndex
254260
);
255-
assert(
256-
correspondingConfigMarket !== undefined,
257-
`Market ${
258-
market.marketIndex
259-
} not found in DevnetPerpMarkets, market: ${market.pubkey.toBase58()}`
260-
);
261-
assert(
262-
correspondingConfigMarket.oracle.toBase58() ==
263-
market.amm.oracle.toBase58(),
264-
`Oracle mismatch for devnet perp market ${
265-
market.marketIndex
266-
}, market: ${market.pubkey.toBase58()}, constants: ${correspondingConfigMarket.oracle.toBase58()}, chain: ${market.amm.oracle.toBase58()}`
267-
);
268-
assert(
269-
getVariant(correspondingConfigMarket.oracleSource) ===
270-
getVariant(market.amm.oracleSource),
271-
`Oracle source mismatch for devnet perp market ${
272-
market.marketIndex
273-
}, market: ${market.pubkey.toBase58()}, constants: ${getVariant(
274-
correspondingConfigMarket.oracleSource
275-
)}, chain: ${getVariant(market.amm.oracleSource)}`
276-
);
261+
262+
if (correspondingConfigMarket === undefined) {
263+
errors.push(`Market ${market.marketIndex} not found in DevnetPerpMarkets, market: ${market.pubkey.toBase58()}`);
264+
continue;
265+
}
266+
267+
if (correspondingConfigMarket.oracle.toBase58() !== market.amm.oracle.toBase58()) {
268+
errors.push(`Oracle mismatch for devnet perp market ${market.marketIndex}, market: ${market.pubkey.toBase58()}, constants: ${correspondingConfigMarket.oracle.toBase58()}, chain: ${market.amm.oracle.toBase58()}`);
269+
}
270+
271+
if (getVariant(correspondingConfigMarket.oracleSource) !== getVariant(market.amm.oracleSource)) {
272+
errors.push(`Oracle source mismatch for devnet perp market ${market.marketIndex}, market: ${market.pubkey.toBase58()}, constants: ${getVariant(correspondingConfigMarket.oracleSource)}, chain: ${getVariant(market.amm.oracleSource)}`);
273+
}
274+
}
275+
276+
// Print all errors
277+
if (errors.length > 0) {
278+
console.log('\n=== DEVNET VALIDATION ERRORS ===');
279+
errors.forEach((error, index) => {
280+
console.log(`${index + 1}. ${error}`);
281+
});
282+
console.log(`\nTotal devnet errors: ${errors.length}`);
283+
}
284+
285+
// Fail if there are any issues
286+
if (errors.length > 0) {
287+
assert(false, `Found ${errors.length} devnet validation errors. See details above.`);
277288
}
278289
});
279290
});

0 commit comments

Comments
 (0)