Skip to content

Commit dc3edfa

Browse files
committed
Edits
1 parent 5a7587b commit dc3edfa

File tree

2 files changed

+36
-28
lines changed

2 files changed

+36
-28
lines changed

dist/truffle.plugin.js

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
Test options override
1515
---------------------
1616
contracts_directory, /users/myPath/to/someProject/.coverageContracts
17-
contracts_build_directory, /users/myPath/to/someProject/.coverageArtifact/contracts
18-
provider ganache.provider (w/ vm resolved)
17+
contracts_build_directory, /users/myPath/to/someProject/.coverageArtifacts/contracts
18+
provider ganache.provider (async b/c vm must be resolved)
1919
logger add filter for unused variables...
2020
2121
Truffle Lib API
@@ -26,62 +26,72 @@
2626
*/
2727

2828
const SolidityCoverage = require('./../lib/app.js');
29+
const req = require('req-cwd');
2930

3031
module.exports = async (config) =>
31-
let truffle;
32+
let error;
3233

3334
try {
34-
truffle = loadTruffleLibrary();
3535

36-
const coverageConfigPath = coveragePaths.config(config)
37-
const coverageConfig = req.silent(coverageConfigPath) || {};
38-
39-
app.contractsDir = coveragePaths.contracts(config, coverageConfig);
36+
// Load truffle lib & coverage config
37+
const truffle = loadTruffleLibrary();
38+
const coverageConfig = req.silent('./.solcover.js') || {};
4039

40+
// Start
4141
const app = new SolidityCoverage(coverageConfig);
42-
app.generateEnvironment();
43-
app.instrument(config.contracts_directory);
4442

45-
// Compile instrumented sources / optimization off
46-
config.contracts_directory = app.contractsDir;
47-
config.build_directory = coveragePaths.artifacts.root(config, coverageConfig);
48-
config.contracts_build_directory = coveragePaths.artifacts.contracts(config, coverageConfig);
43+
// Write instrumented sources to temp folder
44+
app.contractsDirectory = coveragePaths.contracts(config, app);
45+
app.generateEnvironment(config.contracts_directory, app.contractsDirectory);
46+
app.instrument();
47+
48+
// Have truffle use temp folders
49+
config.contracts_directory = app.contractsDirectory;
50+
config.build_directory = coveragePaths.artifacts.root(config, app);
51+
config.contracts_build_directory = coveragePaths.artifacts.contracts(config, app);
52+
53+
// Compile w/out optimization
4954
config.compilers.solc.settings.optimization.enabled = false;
5055
await truffle.contracts.compile(config);
5156

52-
// Test using compiled, instrumented sources
53-
config.provider = await app.getCoverageProvider();
57+
// Launch provider & run tests
58+
config.provider = await app.getCoverageProvider(truffle);
5459
try {
5560
await truffle.test.run(config)
56-
} catch (err) {
61+
} catch (e) {
62+
error = e;
5763
app.testsErrored = true;
5864
}
5965

66+
// Produce report
6067
app.generateCoverage();
6168

62-
} catch(err){
63-
return app.cleanUp(err);
69+
} catch(e){
70+
error = e;
6471
}
6572

66-
return app.cleanUp();
73+
// Finish
74+
return app.cleanUp(error);
6775
}
6876

6977
// -------------------------------------- Helpers --------------------------------------------------
7078
function loadTruffleLibrary(){
7179

7280
try { return require("truffle") } catch(err) {};
73-
try { return require("sc-truffle")} catch(err) {};
81+
try { return require("./truffle.library")} catch(err) {};
7482

7583
throw new Error(utils.errors.NO_TRUFFLE_LIB)
7684
}
7785

7886
const coveragePaths = {
79-
contracts: (t, c) => path.join(path.dirname(t.contracts_directory), c.contractsDirName)),
80-
config: (t) => path.join(t.working_directory, '.solcover.js'),
87+
contracts: (t, c) => path.join(path.dirname(t.contracts_directory), c.contractsDirName)),
8188

8289
artifacts: {
83-
root: (t, c) => path.join(path.dirname(t.build_directory), c.artifactsDirName),
84-
contracts: (c, t) => path.join(c.build_directory, path.basename(t.contracts_build_directory))
90+
root: (t, c) => path.join(path.dirname(t.build_directory), c.artifactsDirName),
91+
contracts: (t, c) => {
92+
const root = path.join(path.dirname(t.build_directory), c.artifactsDirName);
93+
return path.join(root, path.basename(t.contracts_build_directory));
94+
}
8595
}
8696
}
8797

lib/injector.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@ class Injector {
1212
* @param {String} memoryVariable
1313
* @param {String} hash hash key to an instrumentationData entry (see _getHash)
1414
* @param {String} type instrumentation type, e.g. line, statement
15-
* @return {String} ex: _sc_82e0891[0] = bytes32(0xdc08...08ed1); // function
16-
*/
15+
// @return {String} ex: _sc_82e0891[0] = bytes32(0xdc08...08ed1); /* function */
1716
_getInjectable(memoryVariable, hash, type){
1817
return `${memoryVariable}[0] = bytes32(${hash}); /* ${type} */ \n`;
1918
}
2019

21-
2220
_getHash(fileName) {
2321
this.hashCounter++;
2422
return web3Utils.keccak256(`${fileName}:${this.hashCounter}`);

0 commit comments

Comments
 (0)