Gas Report Contract
Purpose
The gas report is used to determine how individual active rules affect gas consumption of basic token actions.
Overview
The gas report is the output of running the GasReport test file. Run this command to see the gas report output to the console. The output will include baseline gas used by each action. Each test has a tag associated with the action being run for easier readability during console output.
GasHelpers contract
GasHelpers.sol includes a couple helper functions to specify what should be included in the gas report.
startMeasuringGas
This function is run after the rule setup and before the transactions desired for the gas report. Currently, only the basic actions like burn, transfer, and mint are desired and included in the gas report test file. But an arbitrary amount of actions can be done after gas measuring starts.
stopMeasuringGas
This function is run after the desired actions are run. Any actions after this function is run will not be included in the gas report console output.
Adding new rules/actions
To add new rules or reports, simply add a function to apply the desired rule or change. Once the helper is created, create a new test function with the rule helper being the first action run. Next, add the action which is desired using the functions included.
Example
This helper function applies the Token Max Buy Sell Volume rule. When including this function in a new test, it should be run before gas measuring starts.
Gas measuring helpers for individual actions are included for both ERC721 and ERC20. For this example, I want to test how the rule affects the gas used for an ERC721 burn action.
This consists of two functions, one to prep the burn and one to perform a subsequent burn. This is to ensure that the test is not affected by touching cold storage.
This is the helper to start measuring gas consumption, burn an NFT, and stop measuring gas consumption. Once finished, it will output the label and gas used by the burn action.
For this example, this is the full test function.
The output to the console will look like this when running this individual test.