Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculate size script optimized #554

Merged
merged 4 commits into from
Feb 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"babel-preset-stage-3": "6.24.1",
"babel-register": "6.26.0",
"bignumber.js": "5.0.0",
"chalk": "^2.4.1",
"chalk": "^2.4.2",
"coveralls": "^3.0.1",
"ethereumjs-testrpc": "^6.0.3",
"ethers": "^4.0.7",
Expand Down Expand Up @@ -90,7 +90,7 @@
"ganache-cli": "^6.2.4",
"mocha-junit-reporter": "^1.18.0",
"prettier": "^1.15.3",
"prettier-plugin-solidity-refactor": "^1.0.0-alpha.10",
"table": "^5.2.3",
"sol-merger": "^0.1.2",
"solidity-coverage": "^0.5.11",
"solidity-docgen": "^0.1.0",
Expand Down
31 changes: 19 additions & 12 deletions scripts/calculateSize.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,35 @@
const fs = require("fs");
const path = require("path");
var size = new Array();
const exec = require('child_process').execSync;
const chalk = require('chalk');
const { table } = require("table");

function readFiles() {
async function readFiles() {
if (fs.existsSync("./build/contracts/")) {
let files = fs.readdirSync("./build/contracts/");
return files;
return fs.readdirSync("./build/contracts/");
} else {
console.log("Directory doesn't exists");
console.log('Compiling contracts. This may take a while, please wait.');
exec('truffle compile');
return fs.readdirSync("./build/contracts/");
}
}

async function printSize() {
let files = readFiles();
let files = await readFiles();
console.log(`NOTE- Maximum size of contracts allowed to deloyed on the Ethereum mainnet is 24 KB(EIP170)`);
console.log(`---- Size of the contracts ----`);
let dataTable = [['Contracts', 'Size in KB']];
files.forEach(item => {
let content = JSON.parse(fs.readFileSync(`./build/contracts/${item}`).toString()).deployedBytecode;
let sizeInKB = content.toString().length / 2 / 1024;
size.push(sizeInKB);
if (sizeInKB > 24)
dataTable.push([chalk.red(path.basename(item, ".json")),chalk.red(sizeInKB)]);
else if (sizeInKB > 20)
dataTable.push([chalk.yellow(path.basename(item, ".json")),chalk.yellow(sizeInKB)]);
else
dataTable.push([chalk.green(path.basename(item, ".json")),chalk.green(sizeInKB)]);
});
console.log(`NOTE- Maximum size of contracts allowed to deloyed on the Ethereum mainnet is 24 KB(EIP170)`);
console.log(`---- Size of the contracts ----`);
for (let i = 0; i < files.length; i++) {
console.log(`${path.basename(files[i], ".json")} - ${size[i]} KB`);
}
console.log(table(dataTable));
}

printSize();
Loading