forked from Remitwise-Org/Remitwise-Contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix_all_tests.js
More file actions
47 lines (39 loc) · 1.54 KB
/
Copy pathfix_all_tests.js
File metadata and controls
47 lines (39 loc) · 1.54 KB
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
const fs = require('fs');
const path = require('path');
const projectRoot = process.cwd();
const filesToFix = [
path.join(projectRoot, 'insurance', 'src', 'test.rs')
];
filesToFix.forEach(filePath => {
if (!fs.existsSync(filePath)) return;
let content = fs.readFileSync(filePath, 'utf8');
// Fix set_ledger_time(&env, 1000) -> set_ledger_time(&env, 1, 1000)
content = content.replace(/set_ledger_time\s*\(\s*&env\s*,\s*([0-9a-zA-Z_+\-*/\s]+)\)/g, 'set_ledger_time(&env, 1, $1)');
// Fix any remaining CoverageType issues in create_policy
const enumMap = {
"health": "CoverageType::Health",
"life": "CoverageType::Life",
"auto": "CoverageType::Auto",
"property": "CoverageType::Property",
"emergency": "CoverageType::Health",
"type": "CoverageType::Health"
};
content = content.replace(/client\.(?:try_)?create_policy\s*\(([\s\S]*?)\);/g, (match, p1) => {
let args = p1.split(',').map(s => s.trim());
if (args.length >= 3) {
for (const [key, val] of Object.entries(enumMap)) {
if (args[2].toLowerCase().includes(`"${key}"`) || args[2].toLowerCase().includes(`::${key}`)) {
args[2] = `&${val}`;
break;
}
}
}
if (args.length === 5) {
args.push('&None');
}
return `client.create_policy(${args.join(', ')});`;
});
fs.writeFileSync(filePath, content);
console.log(`Successfully updated ${filePath}`);
});
console.log("Done.");