Skip to content

Commit

Permalink
Add color formatting to gas report to point out high gas usage
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeshultz committed Mar 12, 2019
1 parent 9acf020 commit 6e8c744
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions solidbyte/cli/test.py
Expand Up @@ -9,12 +9,43 @@
from ..common.exceptions import DeploymentValidationError
from ..common import store
from ..common.web3 import web3c, remove_0x
from ..common.logging import getLogger
from ..common.logging import ConsoleStyle, getLogger
from ..testing.gas import GasReportStorage

log = getLogger(__name__)


# TODO: Make these configurable?
GAS_WARN = 1e5
GAS_BAD = 1e6
GAS_ERROR = 47e5 # Ropsten is at 4.7m


def highlight_gas(gas):
""" Uses console color highlights to indicate high gas usage """

if gas >= GAS_ERROR:
return '{}{}{}'.format(
ConsoleStyle.CRITICAL,
gas,
ConsoleStyle.END
)
elif gas >= GAS_BAD:
return '{}{}{}'.format(
ConsoleStyle.ERROR,
gas,
ConsoleStyle.END
)
elif gas >= GAS_WARN:
return '{}{}{}'.format(
ConsoleStyle.WARNING,
gas,
ConsoleStyle.END
)

return gas


def add_parser_arguments(parser):
""" Add additional subcommands onto this command """
parser.add_argument('network', metavar="NETWORK", type=str, nargs=1,
Expand Down Expand Up @@ -100,9 +131,9 @@ def main(parser_args):
avg = round(sum(report_data[func]) / len(report_data[func]))
report_table.append([
sigs_resolver.get(func, 'Unknown'),
lo,
hi,
avg,
highlight_gas(lo),
highlight_gas(hi),
highlight_gas(avg),
])

print(tabulate(report_table, headers=['Function', 'Low', 'High', 'Avg']))
Expand Down

0 comments on commit 6e8c744

Please sign in to comment.