@@ -5,6 +5,10 @@ import { getAddress } from "viem";
55
66interface TokenMetadata {
77 logoURI : string ;
8+ alternativeOracle ?: string ;
9+ alternativeOracles ?: any [ ] ;
10+ alternativeHardcodedOracle ?: string ;
11+ alternativeHardcodedOracles ?: any [ ] ;
812}
913
1014interface Token {
@@ -129,6 +133,36 @@ describe("tokens.json validation", () => {
129133 `Token at index ${ index } (address: ${ token . address } ) has invalid metadata structure: ${ error } `
130134 ) ;
131135 }
136+
137+ // Add validation for oracle arrays in metadata
138+ try {
139+ if ( token . metadata ?. alternativeOracles !== undefined ) {
140+ expect ( Array . isArray ( token . metadata . alternativeOracles ) ) . toBe ( true ) ;
141+ }
142+
143+ if ( token . metadata ?. alternativeHardcodedOracles !== undefined ) {
144+ expect (
145+ Array . isArray ( token . metadata . alternativeHardcodedOracles )
146+ ) . toBe ( true ) ;
147+ }
148+
149+ // Check for incorrect singular forms and suggest the plural version
150+ if ( token . metadata ?. alternativeOracle !== undefined ) {
151+ errors . push (
152+ `Token at index ${ index } (address: ${ token . address } ) has incorrect 'metadata.alternativeOracle' field. Use 'alternativeOracles' (plural) instead.`
153+ ) ;
154+ }
155+
156+ if ( token . metadata ?. alternativeHardcodedOracle !== undefined ) {
157+ errors . push (
158+ `Token at index ${ index } (address: ${ token . address } ) has incorrect 'metadata.alternativeHardcodedOracle' field. Use 'alternativeHardcodedOracles' (plural) instead.`
159+ ) ;
160+ }
161+ } catch ( error ) {
162+ errors . push (
163+ `Token at index ${ index } (address: ${ token . address } ) has invalid oracle fields in metadata: ${ error } `
164+ ) ;
165+ }
132166 } ) ;
133167
134168 // Additional validation for decimal values
@@ -186,4 +220,72 @@ describe("tokens.json validation", () => {
186220 ) ;
187221 }
188222 } ) ;
223+
224+ // Add this new test to explicitly check for singular/plural naming issues
225+ test ( "token fields use correct plural naming conventions" , ( ) => {
226+ const singularFields = [ "alternativeOracle" , "alternativeHardcodedOracle" ] ;
227+ const correctPluralFields = [
228+ "alternativeOracles" ,
229+ "alternativeHardcodedOracles" ,
230+ ] ;
231+ const errors : string [ ] = [ ] ;
232+
233+ tokens . forEach ( ( token , index ) => {
234+ // Check for incorrect singular forms in the token object
235+ for ( const singularField of singularFields ) {
236+ if ( Object . prototype . hasOwnProperty . call ( token , singularField ) ) {
237+ errors . push (
238+ `Token at index ${ index } (address: ${ token . address } , chainId: ${ token . chainId } ) uses incorrect singular field name "${ singularField } ". Use the plural form instead.`
239+ ) ;
240+ }
241+
242+ // Also check inside metadata object
243+ if (
244+ token . metadata &&
245+ Object . prototype . hasOwnProperty . call ( token . metadata , singularField )
246+ ) {
247+ errors . push (
248+ `Token at index ${ index } (address: ${ token . address } , chainId: ${ token . chainId } ) has metadata with incorrect singular field name "${ singularField } ". Use the plural form instead.`
249+ ) ;
250+ }
251+ }
252+
253+ // Verify the correct plural fields when present
254+ for ( const pluralField of correctPluralFields ) {
255+ // Check in token object
256+ if ( Object . prototype . hasOwnProperty . call ( token , pluralField ) ) {
257+ if ( ! Array . isArray ( token [ pluralField as keyof Token ] ) ) {
258+ errors . push (
259+ `Token at index ${ index } (address: ${ token . address } , chainId: ${ token . chainId } ) has ${ pluralField } that is not an array.`
260+ ) ;
261+ }
262+ }
263+
264+ // Also check inside metadata object
265+ if (
266+ token . metadata &&
267+ Object . prototype . hasOwnProperty . call ( token . metadata , pluralField )
268+ ) {
269+ if (
270+ ! Array . isArray (
271+ token . metadata [ pluralField as keyof typeof token . metadata ]
272+ )
273+ ) {
274+ errors . push (
275+ `Token at index ${ index } (address: ${ token . address } , chainId: ${ token . chainId } ) has metadata.${ pluralField } that is not an array.`
276+ ) ;
277+ }
278+ }
279+ }
280+ } ) ;
281+
282+ // If we collected any errors, fail the test with all error messages
283+ if ( errors . length > 0 ) {
284+ throw new Error (
285+ `Found ${ errors . length } naming convention errors:\n\n${ errors . join (
286+ "\n\n"
287+ ) } `
288+ ) ;
289+ }
290+ } ) ;
189291} ) ;
0 commit comments