2022-04-11 17:14:19 -04:00
var _ _classPrivateFieldSet = ( this && this . _ _classPrivateFieldSet ) || function ( receiver , state , value , kind , f ) {
if ( kind === "m" ) throw new TypeError ( "Private method is not writable" ) ;
if ( kind === "a" && ! f ) throw new TypeError ( "Private accessor was defined without a setter" ) ;
if ( typeof state === "function" ? receiver !== state || ! f : ! state . has ( receiver ) ) throw new TypeError ( "Cannot write private member to an object whose class did not declare it" ) ;
return ( kind === "a" ? f . call ( receiver , value ) : f ? f . value = value : state . set ( receiver , value ) ) , value ;
} ;
var _ _classPrivateFieldGet = ( this && this . _ _classPrivateFieldGet ) || function ( receiver , state , kind , f ) {
if ( kind === "a" && ! f ) throw new TypeError ( "Private accessor was defined without a getter" ) ;
if ( typeof state === "function" ? receiver !== state || ! f : ! state . has ( receiver ) ) throw new TypeError ( "Cannot read private member from an object whose class did not declare it" ) ;
return kind === "m" ? f : kind === "a" ? f . call ( receiver ) : f ? f . value : state . get ( receiver ) ;
} ;
var _Stats _instances , _Stats _stats , _Stats _currentStats ;
import fs from "fs" ;
import path from "path" ;
import zlib from 'zlib' ;
// Find the package root (based on the nyc output/ folder)
const root = ( function ( ) {
let root = process . cwd ( ) ;
while ( true ) {
if ( fs . existsSync ( path . join ( root , "output" ) ) ) {
return root ;
}
const parent = path . join ( root , ".." ) ;
if ( parent === root ) {
break ;
}
root = parent ;
}
throw new Error ( "could not find root" ) ;
} ) ( ) ;
// Load the tests
export function loadTests ( tag ) {
const filename = path . resolve ( root , "testcases" , tag + '.json.gz' ) ;
return JSON . parse ( zlib . gunzipSync ( fs . readFileSync ( filename ) ) . toString ( ) ) ;
}
2022-04-21 01:45:32 -04:00
export function log ( context , text ) {
if ( context && context . test && typeof ( context . test . _ethersLog ) === "function" ) {
context . test . _ethersLog ( text ) ;
}
else {
console . log ( text ) ;
}
}
2022-04-11 17:14:19 -04:00
async function stall ( duration ) {
return new Promise ( ( resolve ) => { setTimeout ( resolve , duration ) ; } ) ;
}
const ATTEMPTS = 5 ;
export async function retryIt ( name , func ) {
it ( name , async function ( ) {
this . timeout ( ATTEMPTS * 5000 ) ;
for ( let i = 0 ; i < ATTEMPTS ; i ++ ) {
try {
await func . call ( this ) ;
return ;
}
catch ( error ) {
if ( error . message === "sync skip; aborting execution" ) {
// Skipping a test; let mocha handle it
throw error ;
}
else if ( error . code === "ERR_ASSERTION" ) {
// Assertion error; let mocha scold us
throw error ;
}
else {
if ( i === ATTEMPTS - 1 ) {
stats . pushRetry ( i , name , error ) ;
}
else {
await stall ( 500 * ( 1 << i ) ) ;
stats . pushRetry ( i , name , null ) ;
}
}
}
}
// All hope is lost.
throw new Error ( ` Failed after ${ ATTEMPTS } attempts; ${ name } ` ) ;
} ) ;
}
const _guard = { } ;
export class Stats {
constructor ( guard ) {
_Stats _instances . add ( this ) ;
_Stats _stats . set ( this , void 0 ) ;
if ( guard !== _guard ) {
throw new Error ( "private constructor" ) ;
}
_ _classPrivateFieldSet ( this , _Stats _stats , [ ] , "f" ) ;
}
pushRetry ( attempt , line , error ) {
const { retries } = _ _classPrivateFieldGet ( this , _Stats _instances , "m" , _Stats _currentStats ) . call ( this ) ;
if ( attempt > 0 ) {
retries . pop ( ) ;
}
if ( retries . length < 100 ) {
retries . push ( {
message : ` ${ attempt + 1 } failures: ${ line } ` ,
error
} ) ;
}
}
start ( name ) {
_ _classPrivateFieldGet ( this , _Stats _stats , "f" ) . push ( { name , retries : [ ] } ) ;
}
2022-04-21 01:45:32 -04:00
end ( context ) {
let log = console . log . bind ( console ) ;
if ( context && typeof ( context . _ethersLog ) === "function" ) {
log = context . _ethersLog ;
}
2022-04-11 17:14:19 -04:00
const { name , retries } = _ _classPrivateFieldGet ( this , _Stats _instances , "m" , _Stats _currentStats ) . call ( this ) ;
if ( retries . length === 0 ) {
return ;
}
2022-04-21 01:45:32 -04:00
log ( ` Warning: The following tests required retries ( ${ name } ) ` ) ;
2022-04-11 17:14:19 -04:00
retries . forEach ( ( { error , message } ) => {
2022-04-21 01:45:32 -04:00
log ( " " + message ) ;
2022-04-11 17:14:19 -04:00
if ( error ) {
2022-04-21 01:45:32 -04:00
log ( error ) ;
2022-04-11 17:14:19 -04:00
}
} ) ;
}
}
_Stats _stats = new WeakMap ( ) , _Stats _instances = new WeakSet ( ) , _Stats _currentStats = function _Stats _currentStats ( ) {
if ( _ _classPrivateFieldGet ( this , _Stats _stats , "f" ) . length === 0 ) {
throw new Error ( "no active stats" ) ;
}
return _ _classPrivateFieldGet ( this , _Stats _stats , "f" ) [ _ _classPrivateFieldGet ( this , _Stats _stats , "f" ) . length - 1 ] ;
} ;
export const stats = new Stats ( _guard ) ;
//# sourceMappingURL=utils.js.map