forked from NexusMutual/smart-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.solcover.js
68 lines (56 loc) · 2 KB
/
.solcover.js
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
const fs = require('fs');
const path = require('path');
const { artifacts, config } = require('hardhat');
const { keccak256 } = require('ethereum-cryptography/keccak');
const { bytesToHex, hexToBytes } = require('ethereum-cryptography/utils');
const stakingLibraryPath = 'contracts/libraries/StakingPoolLibrary.sol';
function findFiles(dir) {
const results = [];
for (const filename of fs.readdirSync(dir)) {
const filepath = path.join(dir, filename);
const stat = fs.statSync(filepath);
const fileOrContents = stat && stat.isDirectory() ? findFiles(filepath) : [filepath];
results.push(...fileOrContents);
}
return results;
}
async function onCompileComplete() {
const { bytecode } = await artifacts.readArtifact('MinimalBeaconProxy');
const requiredHash = bytesToHex(keccak256(hexToBytes(bytecode.replace(/^0x/i, ''))));
const stakingLibrary = fs.readFileSync(stakingLibraryPath, 'utf8').toString();
const hardcodedHash = stakingLibrary.match(/hex'([0-9a-f]+)' \/\/ init code hash/i)[1];
console.log('Required hash:', requiredHash);
console.log('Hardcoded hash:', hardcodedHash);
if (hardcodedHash === requiredHash) {
console.log('Artifact patching not required');
return;
}
const files = findFiles(config.paths.artifacts);
const foundArtifacts = files.filter(file => file.match(/\.json/));
for (const file of foundArtifacts) {
const contents = fs.readFileSync(file, 'utf8').toString();
if (contents.includes(hardcodedHash)) {
console.log(`Patching ${file}`);
fs.writeFileSync(file, contents.replace(hardcodedHash, requiredHash), 'utf8');
}
}
}
module.exports = {
onCompileComplete,
skipFiles: [
'abstract/',
'external/',
'interfaces/',
'mocks/',
'modules/assessment/AssessmentViews.sol',
'modules/cover/CoverViewer.sol',
'modules/cover/ProductsV1.sol',
'modules/governance/external',
'modules/legacy',
'modules/token/external',
'utils/',
],
providerOptions: {
default_balance_ether: 100000000,
},
};