aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2018-05-23 07:41:50 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2018-05-23 07:41:50 +0800
commitd49f2c40ae28bde3574907a72c0fdd84196e8303 (patch)
treeaf8145dc6404c08c870d9cb60b122acf7a1d9eb1
parent8c7f0902c044b671ca66c004d9c29e018bcdb20e (diff)
downloaddexon-sol-tools-d49f2c40ae28bde3574907a72c0fdd84196e8303.tar.gz
dexon-sol-tools-d49f2c40ae28bde3574907a72c0fdd84196e8303.tar.zst
dexon-sol-tools-d49f2c40ae28bde3574907a72c0fdd84196e8303.zip
Parse compiler.json in SolCompilerArtifactsAdapter
-rw-r--r--packages/contracts/test/utils/coverage.ts4
-rw-r--r--packages/sol-cov/src/artifact_adapters/sol_compiler_artifact_adapter.ts15
2 files changed, 13 insertions, 6 deletions
diff --git a/packages/contracts/test/utils/coverage.ts b/packages/contracts/test/utils/coverage.ts
index 3b2a8d7b2..a37939464 100644
--- a/packages/contracts/test/utils/coverage.ts
+++ b/packages/contracts/test/utils/coverage.ts
@@ -14,9 +14,7 @@ export const coverage = {
},
_getCoverageSubprovider(): CoverageSubprovider {
const defaultFromAddress = devConstants.TESTRPC_FIRST_ADDRESS;
- const CONFIG_FILE = 'compiler.json';
- const config = JSON.parse(fs.readFileSync(CONFIG_FILE).toString());
- const solCompilerArtifactAdapter = new SolCompilerArtifactAdapter(config.artifactsDir, config.contractsDir);
+ const solCompilerArtifactAdapter = new SolCompilerArtifactAdapter();
const subprovider = new CoverageSubprovider(solCompilerArtifactAdapter, defaultFromAddress);
return subprovider;
},
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
index cb164f769..d08828bf6 100644
--- a/packages/sol-cov/src/artifact_adapters/sol_compiler_artifact_adapter.ts
+++ b/packages/sol-cov/src/artifact_adapters/sol_compiler_artifact_adapter.ts
@@ -7,13 +7,22 @@ import { ContractData } from '../types';
import { AbstractArtifactAdapter } from './abstract_artifact_adapter';
+const CONFIG_FILE = 'compiler.json';
+
export class SolCompilerArtifactAdapter extends AbstractArtifactAdapter {
private _artifactsPath: string;
private _sourcesPath: string;
- constructor(artifactsPath: string, sourcesPath: string) {
+ constructor(artifactsPath?: string, sourcesPath?: string) {
super();
- this._artifactsPath = artifactsPath;
- this._sourcesPath = sourcesPath;
+ const config = JSON.parse(fs.readFileSync(CONFIG_FILE).toString());
+ if (_.isUndefined(artifactsPath) && _.isUndefined(config.artifactsDir)) {
+ throw new Error(`artifactsDir not found in ${CONFIG_FILE}`);
+ }
+ this._artifactsPath = config.artifactsDir;
+ if (_.isUndefined(sourcesPath) && _.isUndefined(config.contractsDir)) {
+ throw new Error(`contractsDir not found in ${CONFIG_FILE}`);
+ }
+ this._sourcesPath = config.contractsDir;
}
public async collectContractsDataAsync(): Promise<ContractData[]> {
const artifactsGlob = `${this._artifactsPath}/**/*.json`;