From 08b08ef1d0fbff2da8b64524704cf1bc50f77f30 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 21 May 2018 16:56:00 -0700 Subject: Match class names with file names --- packages/sol-cov/src/artifact_adapters/0x.ts | 41 --------------------- packages/sol-cov/src/artifact_adapters/abstract.ts | 5 --- .../artifact_adapters/abstract_artifact_adapter.ts | 5 +++ .../sol_compiler_artifact_adapter.ts | 41 +++++++++++++++++++++ packages/sol-cov/src/artifact_adapters/truffle.ts | 43 ---------------------- .../artifact_adapters/truffle_artifact_adapter.ts | 43 ++++++++++++++++++++++ packages/sol-cov/src/index.ts | 6 +-- 7 files changed, 92 insertions(+), 92 deletions(-) delete mode 100644 packages/sol-cov/src/artifact_adapters/0x.ts delete mode 100644 packages/sol-cov/src/artifact_adapters/abstract.ts create mode 100644 packages/sol-cov/src/artifact_adapters/abstract_artifact_adapter.ts create mode 100644 packages/sol-cov/src/artifact_adapters/sol_compiler_artifact_adapter.ts delete mode 100644 packages/sol-cov/src/artifact_adapters/truffle.ts create mode 100644 packages/sol-cov/src/artifact_adapters/truffle_artifact_adapter.ts (limited to 'packages/sol-cov/src') diff --git a/packages/sol-cov/src/artifact_adapters/0x.ts b/packages/sol-cov/src/artifact_adapters/0x.ts deleted file mode 100644 index f61364df6..000000000 --- a/packages/sol-cov/src/artifact_adapters/0x.ts +++ /dev/null @@ -1,41 +0,0 @@ -import * as fs from 'fs'; -import * as glob from 'glob'; -import * as _ from 'lodash'; -import * as path from 'path'; - -import { ContractData } from '../types'; - -import { AbstractArtifactAdapter } from './abstract'; - -export class SolCompilerArtifactAdapter extends AbstractArtifactAdapter { - private _artifactsPath: string; - private _sourcesPath: string; - constructor(artifactsPath: string, sourcesPath: string) { - super(); - this._artifactsPath = artifactsPath; - this._sourcesPath = sourcesPath; - } - public async collectContractsDataAsync(): Promise { - const artifactsGlob = `${this._artifactsPath}/**/*.json`; - const artifactFileNames = glob.sync(artifactsGlob, { absolute: true }); - const contractsData: ContractData[] = []; - for (const artifactFileName of artifactFileNames) { - const artifact = JSON.parse(fs.readFileSync(artifactFileName).toString()); - let sources = _.keys(artifact.sources); - sources = _.map(sources, relativeFilePath => path.resolve(this._sourcesPath, relativeFilePath)); - const contractName = artifact.contractName; - // We don't compute coverage for dependencies - const sourceCodes = _.map(sources, (source: string) => fs.readFileSync(source).toString()); - const contractData = { - sourceCodes, - sources, - bytecode: artifact.compilerOutput.evm.bytecode.object, - sourceMap: artifact.compilerOutput.evm.bytecode.sourceMap, - runtimeBytecode: artifact.compilerOutput.evm.deployedBytecode.object, - sourceMapRuntime: artifact.compilerOutput.evm.deployedBytecode.sourceMap, - }; - contractsData.push(contractData); - } - return contractsData; - } -} diff --git a/packages/sol-cov/src/artifact_adapters/abstract.ts b/packages/sol-cov/src/artifact_adapters/abstract.ts deleted file mode 100644 index fcc6562ad..000000000 --- a/packages/sol-cov/src/artifact_adapters/abstract.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { ContractData } from '../types'; - -export abstract class AbstractArtifactAdapter { - public abstract async collectContractsDataAsync(): Promise; -} diff --git a/packages/sol-cov/src/artifact_adapters/abstract_artifact_adapter.ts b/packages/sol-cov/src/artifact_adapters/abstract_artifact_adapter.ts new file mode 100644 index 000000000..fcc6562ad --- /dev/null +++ b/packages/sol-cov/src/artifact_adapters/abstract_artifact_adapter.ts @@ -0,0 +1,5 @@ +import { ContractData } from '../types'; + +export abstract class AbstractArtifactAdapter { + public abstract async collectContractsDataAsync(): Promise; +} diff --git a/packages/sol-cov/src/artifact_adapters/sol_compiler_artifact_adapter.ts b/packages/sol-cov/src/artifact_adapters/sol_compiler_artifact_adapter.ts new file mode 100644 index 000000000..f61364df6 --- /dev/null +++ b/packages/sol-cov/src/artifact_adapters/sol_compiler_artifact_adapter.ts @@ -0,0 +1,41 @@ +import * as fs from 'fs'; +import * as glob from 'glob'; +import * as _ from 'lodash'; +import * as path from 'path'; + +import { ContractData } from '../types'; + +import { AbstractArtifactAdapter } from './abstract'; + +export class SolCompilerArtifactAdapter extends AbstractArtifactAdapter { + private _artifactsPath: string; + private _sourcesPath: string; + constructor(artifactsPath: string, sourcesPath: string) { + super(); + this._artifactsPath = artifactsPath; + this._sourcesPath = sourcesPath; + } + public async collectContractsDataAsync(): Promise { + const artifactsGlob = `${this._artifactsPath}/**/*.json`; + const artifactFileNames = glob.sync(artifactsGlob, { absolute: true }); + const contractsData: ContractData[] = []; + for (const artifactFileName of artifactFileNames) { + const artifact = JSON.parse(fs.readFileSync(artifactFileName).toString()); + let sources = _.keys(artifact.sources); + sources = _.map(sources, relativeFilePath => path.resolve(this._sourcesPath, relativeFilePath)); + const contractName = artifact.contractName; + // We don't compute coverage for dependencies + const sourceCodes = _.map(sources, (source: string) => fs.readFileSync(source).toString()); + const contractData = { + sourceCodes, + sources, + bytecode: artifact.compilerOutput.evm.bytecode.object, + sourceMap: artifact.compilerOutput.evm.bytecode.sourceMap, + runtimeBytecode: artifact.compilerOutput.evm.deployedBytecode.object, + sourceMapRuntime: artifact.compilerOutput.evm.deployedBytecode.sourceMap, + }; + contractsData.push(contractData); + } + return contractsData; + } +} diff --git a/packages/sol-cov/src/artifact_adapters/truffle.ts b/packages/sol-cov/src/artifact_adapters/truffle.ts deleted file mode 100644 index b9c9c4d42..000000000 --- a/packages/sol-cov/src/artifact_adapters/truffle.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { Compiler, CompilerOptions } from '@0xproject/sol-compiler'; -import * as fs from 'fs'; -import * as glob from 'glob'; -import * as _ from 'lodash'; -import * as path from 'path'; -import * as rimraf from 'rimraf'; - -import { ContractData } from '../types'; - -import { SolCompilerArtifactAdapter } from './0x'; -import { AbstractArtifactAdapter } from './abstract'; - -export class TruffleArtifactAdapter extends AbstractArtifactAdapter { - private _solcVersion: string; - private _sourcesPath: string; - constructor(sourcesPath: string, solcVersion: string) { - super(); - this._solcVersion = solcVersion; - this._sourcesPath = sourcesPath; - } - public async collectContractsDataAsync(): Promise { - const artifactsDir = '0x-artifacts'; - const compilerOptions: CompilerOptions = { - contractsDir: this._sourcesPath, - artifactsDir, - compilerSettings: { - outputSelection: { - ['*']: { - ['*']: ['abi', 'evm.bytecode.object', 'evm.deployedBytecode.object'], - }, - }, - }, - contracts: '*', - solcVersion: this._solcVersion, - }; - const compiler = new Compiler(compilerOptions); - await compiler.compileAsync(); - const solCompilerArtifactAdapter = new SolCompilerArtifactAdapter(artifactsDir, this._sourcesPath); - const contractsDataFrom0xArtifacts = await solCompilerArtifactAdapter.collectContractsDataAsync(); - rimraf.sync(artifactsDir); - return contractsDataFrom0xArtifacts; - } -} diff --git a/packages/sol-cov/src/artifact_adapters/truffle_artifact_adapter.ts b/packages/sol-cov/src/artifact_adapters/truffle_artifact_adapter.ts new file mode 100644 index 000000000..b9c9c4d42 --- /dev/null +++ b/packages/sol-cov/src/artifact_adapters/truffle_artifact_adapter.ts @@ -0,0 +1,43 @@ +import { Compiler, CompilerOptions } from '@0xproject/sol-compiler'; +import * as fs from 'fs'; +import * as glob from 'glob'; +import * as _ from 'lodash'; +import * as path from 'path'; +import * as rimraf from 'rimraf'; + +import { ContractData } from '../types'; + +import { SolCompilerArtifactAdapter } from './0x'; +import { AbstractArtifactAdapter } from './abstract'; + +export class TruffleArtifactAdapter extends AbstractArtifactAdapter { + private _solcVersion: string; + private _sourcesPath: string; + constructor(sourcesPath: string, solcVersion: string) { + super(); + this._solcVersion = solcVersion; + this._sourcesPath = sourcesPath; + } + public async collectContractsDataAsync(): Promise { + const artifactsDir = '0x-artifacts'; + const compilerOptions: CompilerOptions = { + contractsDir: this._sourcesPath, + artifactsDir, + compilerSettings: { + outputSelection: { + ['*']: { + ['*']: ['abi', 'evm.bytecode.object', 'evm.deployedBytecode.object'], + }, + }, + }, + contracts: '*', + solcVersion: this._solcVersion, + }; + const compiler = new Compiler(compilerOptions); + await compiler.compileAsync(); + const solCompilerArtifactAdapter = new SolCompilerArtifactAdapter(artifactsDir, this._sourcesPath); + const contractsDataFrom0xArtifacts = await solCompilerArtifactAdapter.collectContractsDataAsync(); + rimraf.sync(artifactsDir); + return contractsDataFrom0xArtifacts; + } +} diff --git a/packages/sol-cov/src/index.ts b/packages/sol-cov/src/index.ts index a4d2b027f..7a2afbe80 100644 --- a/packages/sol-cov/src/index.ts +++ b/packages/sol-cov/src/index.ts @@ -1,5 +1,5 @@ export { CoverageSubprovider } from './coverage_subprovider'; -export { SolCompilerArtifactAdapter } from './artifact_adapters/0x'; -export { TruffleArtifactAdapter } from './artifact_adapters/truffle'; -export { AbstractArtifactAdapter } from './artifact_adapters/abstract'; +export { SolCompilerArtifactAdapter } from './artifact_adapters/sol_compiler_artifact_adapter'; +export { TruffleArtifactAdapter } from './artifact_adapters/truffle_artifact_adapter'; +export { AbstractArtifactAdapter } from './artifact_adapters/abstract_artifact_adapter'; export { ContractData } from './types'; -- cgit v1.2.3