@@ -113,33 +113,54 @@ const TEST_SOURCIFY_CONTRACT_INFO = {
113113 } ,
114114} ;
115115
116- describe ( 'getStartBlockForContract' , { sequential : true } , async ( ) => {
116+ // Retry helper with configurable number of retries
117+ async function retry < T > ( operation : ( ) => Promise < T > , maxRetries = 3 , sleepMs = 5000 ) : Promise < T > {
118+ let lastError : Error | undefined ;
119+ for ( let attempt = 0 ; attempt < maxRetries ; attempt ++ ) {
120+ try {
121+ return await operation ( ) ;
122+ } catch ( error ) {
123+ lastError = error as Error ;
124+ if ( attempt < maxRetries - 1 ) {
125+ await new Promise ( resolve => setTimeout ( resolve , sleepMs ) ) ;
126+ }
127+ }
128+ }
129+ throw lastError ;
130+ }
131+
132+ describe ( 'getStartBlockForContract' , { concurrent : true } , async ( ) => {
117133 const registry = await loadRegistry ( ) ;
118134 const contractService = new ContractService ( registry ) ;
119135 for ( const [ network , contracts ] of Object . entries ( TEST_CONTRACT_START_BLOCKS ) ) {
120136 for ( const [ contract , startBlockExp ] of Object . entries ( contracts ) ) {
121137 test (
122138 `Returns the start block ${ network } ${ contract } ${ startBlockExp } ` ,
123- async ( ) => {
124- //loop through the TEST_CONTRACT_START_BLOCKS object and test each network
125- const startBlock = await contractService . getStartBlock ( network , contract ) ;
139+ { timeout : 50_000 } ,
140+ async ( { expect } ) => {
141+ const startBlock = await retry (
142+ ( ) => contractService . getStartBlock ( network , contract ) ,
143+ 10 ,
144+ ) ;
126145 expect ( parseInt ( startBlock ) ) . toBe ( startBlockExp ) ;
127146 } ,
128- { timeout : 10_000 } ,
129147 ) ;
130148 }
131149 }
132150} ) ;
133151
134- describe ( 'getFromSourcifyForContract' , { sequential : true } , async ( ) => {
152+ describe ( 'getFromSourcifyForContract' , { concurrent : true } , async ( ) => {
135153 const registry = await loadRegistry ( ) ;
136154 const contractService = new ContractService ( registry ) ;
137155 for ( const [ networkId , contractInfo ] of Object . entries ( TEST_SOURCIFY_CONTRACT_INFO ) ) {
138156 for ( const [ contract , t ] of Object . entries ( contractInfo ) ) {
139157 test (
140158 `Returns contract information ${ networkId } ${ contract } ${ t . name } ${ t . startBlock } ` ,
159+ { timeout : 50_000 } ,
141160 async ( ) => {
142- const result = await contractService . getFromSourcify ( EthereumABI , networkId , contract ) ;
161+ const result = await retry ( ( ) =>
162+ contractService . getFromSourcify ( EthereumABI , networkId , contract ) ,
163+ ) ;
143164 if ( t . name === null && t . startBlock === null ) {
144165 expect ( result ) . toBeNull ( ) ;
145166 } else {
@@ -148,7 +169,6 @@ describe('getFromSourcifyForContract', { sequential: true }, async () => {
148169 expect ( t ) . toEqual ( { name, startBlock : parseInt ( startBlock ) } ) ;
149170 }
150171 } ,
151- { timeout : 10_000 } ,
152172 ) ;
153173 }
154174 }
0 commit comments