Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | 1x 1x 1x 1x 1x 1x 1x 5x 5x 6x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 40x 36x 3x 3x 1x 1x 2x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 32x 31x 38x 38x 38x 38x 38x 38x 38x 38x 1x | const shell = require('shelljs'); const globby = require('globby'); const pluginUtils = require("./plugin.utils"); const path = require('path'); const DataCollector = require("./../../lib/collector") const semver = require("semver") const util = require('util') // ============================= // Nomiclabs Plugin Utils // ============================= /** * Returns a list of test files to pass to mocha. * @param {String} files file or glob * @return {String[]} list of files to pass to mocha */ function getTestFilePaths(files){ const target = globby.sync([files]) // Hardhat supports js & ts const testregex = /.*\.(js|ts)$/; return target.filter(f => f.match(testregex) != null); } /** * Normalizes Hardhat paths / logging for use by the plugin utilities and * attaches them to the config * @param {HardhatConfig} config * @return {HardhatConfig} updated config */ function normalizeConfig(config, args={}){ let sources; (args.sources) ? sources = path.join(config.paths.sources, args.sources) : sources = config.paths.sources; Iif (!path.isAbsolute(sources)) { sources = path.join(config.paths.root, sources); } Eif (config.solidity && config.solidity.compilers.length) { config.viaIR = isUsingViaIR(config.solidity); } config.workingDir = config.paths.root; config.contractsDir = sources; config.testDir = config.paths.tests; config.artifactsDir = config.paths.artifacts; config.logger = config.logger ? config.logger : {log: null}; config.solcoverjs = args.solcoverjs config.gasReporter = { enabled: false } config.matrix = args.matrix; try { const hardhatPackage = require('hardhat/package.json'); Eif (semver.gt(hardhatPackage.version, '2.0.3')){ config.useHardhatDefaultPaths = true; } } catch(e){ /* ignore */ } return config; } function isUsingViaIR(solidity) { for (compiler of solidity.compilers) { if (compiler.settings && compiler.settings.viaIR) { return true; } } Eif (solidity.overrides) { for (key of Object.keys(solidity.overrides)){ Eif (solidity.overrides[key].settings && solidity.overrides[key].settings.viaIR) { return true; } } } return false; } async function setupHardhatNetwork(env, api, ui){ const hardhatPackage = require('hardhat/package.json'); const { createProvider } = require("hardhat/internal/core/providers/construction"); const { HARDHAT_NETWORK_NAME } = require("hardhat/plugins") // after 2.15.0, the internal createProvider function has a different signature const newCreateProviderSignature = semver.satisfies(hardhatPackage.version, "^2.15.0"); let provider, networkName, networkConfig; // HardhatEVM networkConfig = env.network.config; configureHardhatEVMGas(networkConfig, api); Eif (newCreateProviderSignature) { provider = await createProvider( env.config, HARDHAT_NETWORK_NAME, env.artifacts, ) } else { provider = createProvider( HARDHAT_NETWORK_NAME, networkConfig, env.config.paths, env.artifacts, ) } return configureNetworkEnv( env, HARDHAT_NETWORK_NAME, networkConfig, provider ) } function configureHardhatEVMGas(networkConfig, api){ networkConfig.allowUnlimitedContractSize = true; networkConfig.blockGasLimit = api.gasLimitNumber; networkConfig.gas = api.gasLimit; networkConfig.gasPrice = api.gasPrice; networkConfig.initialBaseFeePerGas = 0; } function configureNetworkEnv(env, networkName, networkConfig, provider){ env.config.networks[networkName] = networkConfig; env.config.defaultNetwork = networkName; env.network = Object.assign(env.network, { name: networkName, config: networkConfig, provider: provider, isHardhatEVM: true }); env.ethereum = provider; // Return a reference so we can set the from account return env.network; } /** * Configures mocha to generate a json object which maps which tests * hit which lines of code. */ function collectTestMatrixData(args, env, api){ if (args.matrix){ mochaConfig = env.config.mocha || {}; mochaConfig.reporter = api.matrixReporterPath; mochaConfig.reporterOptions = { collectTestMatrixData: api.collectTestMatrixData.bind(api), saveMochaJsonOutput: api.saveMochaJsonOutput.bind(api), cwd: api.cwd } env.config.mocha = mochaConfig; } } /** * Returns all Hardhat artifacts. * @param {HRE} env * @return {Artifact[]} */ async function getAllArtifacts(env){ const all = []; const qualifiedNames = await env.artifacts.getArtifactPaths(); for (const name of qualifiedNames){ all.push(require(name)); } return all; } /** * Compiles project * Collects all artifacts from Hardhat project, * Converts them to a format that can be consumed by api.abiUtils.diff * Saves them to `api.abiOutputPath` * @param {HRE} env * @param {SolidityCoverageAPI} api */ async function generateHumanReadableAbiList(env, api, TASK_COMPILE){ await env.run(TASK_COMPILE); const _artifacts = await getAllArtifacts(env); const list = api.abiUtils.generateHumanReadableAbiList(_artifacts) api.saveHumanReadableAbis(list); } /** * Sets the default `from` account field in the network that will be used. * This needs to be done after accounts are fetched from the launched client. * @param {env} config * @param {Array} accounts */ function setNetworkFrom(networkConfig, accounts){ if (!networkConfig.from){ networkConfig.from = accounts[0]; } } // TODO: Hardhat cacheing?? /** * Generates a path to a temporary compilation cache directory * @param {HardhatConfig} config * @return {String} .../.coverage_cache */ function tempCacheDir(config){ return path.join(config.paths.root, '.coverage_cache'); } /** * Silently removes temporary folders and calls api.finish to shut server down * @param {HardhatConfig} config * @param {SolidityCoverage} api * @return {Promise} */ async function finish(config, api, shouldKill){ const { tempContractsDir, tempArtifactsDir } = pluginUtils.getTempLocations(config); shell.config.silent = true; shell.rm('-Rf', tempContractsDir); shell.rm('-Rf', tempArtifactsDir); shell.rm('-Rf', path.join(config.paths.root, '.coverage_cache')); shell.config.silent = false; if (api) await api.finish(); Iif (shouldKill) process.exit(1) } module.exports = { normalizeConfig, finish, tempCacheDir, setupHardhatNetwork, getTestFilePaths, setNetworkFrom, collectTestMatrixData, getAllArtifacts, generateHumanReadableAbiList } |