-
Notifications
You must be signed in to change notification settings - Fork 341
/
gasUsedReport.js
74 lines (69 loc) · 2.07 KB
/
gasUsedReport.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
69
70
71
72
73
74
'use strict';
const fs = require('fs');
const util = require('util');
const got = require('got');
const yargs = require('yargs');
let argv = yargs.default('branch', 'Katalyst').alias('b', 'branch').argv;
async function getRemoteReport() {
try {
const url = `http://katalyst-coverage.knstats.com/report/${argv.branch}/gasUsed.json`;
return await got(url).json();
} catch (error) {
// console.log(error);
return false;
}
}
async function getLocalReport() {
let reportFile = `report/gasUsed.json`;
if (process.env.TRAVIS_BRANCH !== undefined) {
reportFile = `report/${process.env.TRAVIS_BRANCH}/gasUsed.json`;
}
let report = JSON.parse(fs.readFileSync(reportFile, 'utf8'));
return report
}
async function compareGasConsumtion() {
let localReport = await getLocalReport();
let remoteReport = await getRemoteReport();
if (!remoteReport) {
console.log(`Could not get report for ${argv.branch}. Current report`);
console.table(localReport);
return false;
}
let diffDict = {};
for (let testCase in localReport) {
if (testCase in remoteReport) {
let baseBranchSize = remoteReport[testCase];
let currentSize = localReport[testCase];
let diff = currentSize - baseBranchSize;
if (diff != 0) {
diffDict[testCase] = {
[argv.branch]: baseBranchSize,
current: currentSize,
diff: diff,
};
}
}
}
for (let testCase in remoteReport) {
if (testCase in remoteReport && !(testCase in diffDict)) {
let baseBranchSize = remoteReport[testCase];
let currentSize = localReport[testCase];
let diff = currentSize - baseBranchSize;
if (diff != 0) {
diffDict[testCase] = {
[argv.branch]: baseBranchSize,
current: currentSize,
diff: diff,
};
}
}
}
if (Object.keys(diffDict).length > 0) {
console.log(`There is change in following gas report with ${argv.branch}`);
console.table(diffDict);
} else {
console.log("Gas report didn't change");
console.table(localReport);
}
}
compareGasConsumtion();