import * as fs from 'fs' ; import { promisify } from 'util' ; import { AbstractArtifactAdapter } from '@compound-finance/sol-coverage' ; export class SaddleArtifactAdapter extends AbstractArtifactAdapter { private readonly _buildDir : string ; private readonly _contractsFile : string ; private readonly _coverageIgnore : string [ ] ; param artifactsPath param sourcesPath constructor ( buildDir , contractsFile , coverageIgnore ) { super ( ) ; this . _buildDir = buildDir ; this . _contractsFile = contractsFile ; this . _coverageIgnore = coverageIgnore ; } public async collectContractsDataAsync ( ) { const contractsFile = `${ this . _buildDir }/${ this . _contractsFile }` ; const json = JSON . parse ( await promisify ( fs . readFile ) ( contractsFile , 'utf8' ) ) ; const contracts = json [ 'contracts' ] ; const sourceList = json [ 'sourceList' ] ; const sourceIndex = sourceList . reduce ( ( acc , el , i ) => ( { ... acc , [ el ] : i } ) , { } ) ; return Object . entries ( contracts ) . reduce ( ( res , [ contractName , contract ] ) => { let metadata = JSON . parse ( contract [ 'metadata' ] ) ; let [ sources , sourceCodes ] = Object . entries ( metadata [ 'sources' ] ) . reduce ( ( [ sources , sourceCodes ] , [ path , source ] ) => { let i = sourceIndex [ path ] ; return [ { ... sources , [ i ] : path } , { ... sourceCodes , [ i ] : ( < any > source ) [ 'content' ] } ] ; } , [ { } , { } ] ) ; const contractData = { name : contractName . split ( ':' ) [ 0 ] , sourceCodes , sources , bytecode : '0x' + contract [ 'bin' ] , sourceMap : contract [ 'srcmap' ] , runtimeBytecode : '0x' + contract [ 'bin-runtime' ] , sourceMapRuntime : contract [ 'srcmap-runtime' ] , } ; const isInterfaceContract = contractData . bytecode === '0x' && contractData . runtimeBytecode === '0x' ; const isIgnored = this . _coverageIgnore . includes ( contractData . name ) ; if ( isInterfaceContract || isIgnored ) { return res ; } else { return [ ... res , contractData ] ; } } , < any [ ] > [ ] ) ; } }