Code coverage for Solidity smart-contracts
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
solidity-coverage/test/util/util.js

40 lines
908 B

const fs = require('fs');
const path = require('path');
8 years ago
/**
* Retrieves code at source/<testType>/<test>.sol
* @param {String} _path path relative to `./source`
* @return {String} contents of a .sol file
*/
module.exports.getCode = function getCode(_path) {
8 years ago
return fs.readFileSync(path.join(__dirname, `./../sources/${_path}`), 'utf8');
};
8 years ago
module.exports.report = function report(errors) {
7 years ago
if (errors) {
errors.forEach(error => {
if (error.severity === 'error') {
throw new Error(`Instrumented solidity invalid: ${JSON.stringify(errors)}`);
7 years ago
}
});
7 years ago
}
};
module.exports.codeToCompilerInput = function codeToCompilerInput(code) {
return JSON.stringify({
language: 'Solidity',
sources: {
'test.sol': {
content: code
}
},
settings: {
outputSelection: {
'*': {
'*': [ '*' ]
}
}
}
});
}