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

Option to display total in table #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,11 @@ Mock contracts are used to improve the testing of smart contracts. As they are o
```bash
truffle run contract-size --ignoreMocks
```

### Show total size

You can show the total size of all the contracts specified by running

```bash
truffle run contract-size --showTotal
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "truffle-contract-size",
"version": "2.0.1",
"version": "2.0.2",
"description": "Displays the size of a truffle contracts in kilobytes",
"main": "src/index.js",
"scripts": {
Expand Down
17 changes: 16 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = async (config, done) => {
yargs.parse(process.argv.slice(3))

const contractNames = yargs.argv.contracts
const { checkMaxSize, ignoreMocks } = yargs.argv
const { checkMaxSize, ignoreMocks, showTotal } = yargs.argv

if (!isValidCheckMaxSize(checkMaxSize)) {
done(`--checkMaxSize: invalid value ${checkMaxSize}`)
Expand All @@ -35,6 +35,8 @@ module.exports = async (config, done) => {
// array of objects of {file: path to file, name: name of the contract}
const contracts = await getContracts(config, contractNames, ignoreMocks, done)

let total = 0

const contractPromises = contracts.map(async (contract) => {
await checkFile(contract.file, done)

Expand All @@ -43,6 +45,7 @@ module.exports = async (config, done) => {
if (!('deployedBytecode' in contractFile)) {
done(`Error: deployedBytecode not found in ${contract.file} (it is not a contract json file)`)
}
total += computeByteCodeSizeInKiB(contractFile.deployedBytecode)

const byteCodeSize = computeByteCodeSizeInKiB(contractFile.deployedBytecode)

Expand All @@ -54,6 +57,18 @@ module.exports = async (config, done) => {

await Promise.all(contractPromises)

if (showTotal) {
table.push([
'-',
'-'
])

table.push([
'Total',
formatByteCodeSize(total)
])
}

console.log(table.toString())

if (checkMaxSize) {
Expand Down