Skip to content

Commit

Permalink
Merge pull request #554 from PolymathNetwork/calc-size
Browse files Browse the repository at this point in the history
Calculate size script optimized
  • Loading branch information
satyamakgec committed Feb 14, 2019
2 parents 3ca3b9b + ba5c75a commit 32663e2
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1,141 deletions.
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();

0 comments on commit 32663e2

Please sign in to comment.