@@ -54,7 +54,8 @@ describe('syncCommand', () => {
5454 await runSync ( { config : '/tmp/abi.config.json' } ) ;
5555
5656 expect ( mkdir ) . toHaveBeenCalledWith ( resolve ( './abis' ) , { recursive : true } ) ;
57- expect ( writeFile ) . toHaveBeenCalledTimes ( 2 ) ;
57+ // 2 ABI files + 1 barrel index.ts
58+ expect ( writeFile ) . toHaveBeenCalledTimes ( 3 ) ;
5859 expect ( writeFile ) . toHaveBeenCalledWith (
5960 join ( resolve ( './abis' ) , 'token-a.ts' ) ,
6061 expect . stringContaining ( 'export const abi =' ) ,
@@ -152,8 +153,8 @@ describe('syncCommand', () => {
152153 'Failed to sync: SP2.token-b' ,
153154 ) ;
154155
155- // Still wrote 2 successful contracts
156- expect ( writeFile ) . toHaveBeenCalledTimes ( 2 ) ;
156+ // 2 successful ABI files + 1 barrel
157+ expect ( writeFile ) . toHaveBeenCalledTimes ( 3 ) ;
157158 } ) ;
158159
159160 it ( 'throws when config not found' , async ( ) => {
@@ -192,4 +193,70 @@ describe('syncCommand', () => {
192193 'utf-8' ,
193194 ) ;
194195 } ) ;
196+
197+ it ( 'generates barrel index.ts for ts format' , async ( ) => {
198+ mockConfig ( {
199+ outDir : './abis' ,
200+ contracts : [ { id : 'SP1.amm-pool' } , { id : 'SP2.nft-trait' } ] ,
201+ } ) ;
202+ mockFetchSuccess ( 2 ) ;
203+
204+ await runSync ( { config : '/tmp/abi.config.json' } ) ;
205+
206+ // 2 ABI files + 1 barrel
207+ expect ( writeFile ) . toHaveBeenCalledTimes ( 3 ) ;
208+ expect ( writeFile ) . toHaveBeenCalledWith (
209+ join ( resolve ( './abis' ) , 'index.ts' ) ,
210+ expect . stringContaining ( "export { abi as ammPoolAbi } from './amm-pool.js';" ) ,
211+ 'utf-8' ,
212+ ) ;
213+ expect ( writeFile ) . toHaveBeenCalledWith (
214+ join ( resolve ( './abis' ) , 'index.ts' ) ,
215+ expect . stringContaining ( "export { abi as nftTraitAbi } from './nft-trait.js';" ) ,
216+ 'utf-8' ,
217+ ) ;
218+ } ) ;
219+
220+ it ( 'does NOT generate barrel for json format' , async ( ) => {
221+ mockConfig ( {
222+ outDir : './abis' ,
223+ format : 'json' ,
224+ contracts : [ { id : 'SP1.token-a' } , { id : 'SP2.token-b' } ] ,
225+ } ) ;
226+ mockFetchSuccess ( 2 ) ;
227+
228+ await runSync ( { config : '/tmp/abi.config.json' } ) ;
229+
230+ // Only 2 ABI files, no barrel
231+ expect ( writeFile ) . toHaveBeenCalledTimes ( 2 ) ;
232+ expect ( writeFile ) . not . toHaveBeenCalledWith (
233+ join ( resolve ( './abis' ) , 'index.ts' ) ,
234+ expect . any ( String ) ,
235+ 'utf-8' ,
236+ ) ;
237+ } ) ;
238+
239+ it ( 'barrel uses name alias when available' , async ( ) => {
240+ mockConfig ( {
241+ outDir : './abis' ,
242+ contracts : [
243+ { id : 'SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.amm-pool-v2-01' , name : 'amm-pool' } ,
244+ { id : 'SP2.nft-trait' } ,
245+ ] ,
246+ } ) ;
247+ mockFetchSuccess ( 2 ) ;
248+
249+ await runSync ( { config : '/tmp/abi.config.json' } ) ;
250+
251+ expect ( writeFile ) . toHaveBeenCalledWith (
252+ join ( resolve ( './abis' ) , 'index.ts' ) ,
253+ expect . stringContaining ( "export { abi as ammPoolAbi } from './amm-pool.js';" ) ,
254+ 'utf-8' ,
255+ ) ;
256+ expect ( writeFile ) . toHaveBeenCalledWith (
257+ join ( resolve ( './abis' ) , 'index.ts' ) ,
258+ expect . stringContaining ( "export { abi as nftTraitAbi } from './nft-trait.js';" ) ,
259+ 'utf-8' ,
260+ ) ;
261+ } ) ;
195262} ) ;
0 commit comments