-
Notifications
You must be signed in to change notification settings - Fork 0
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
Test refactoring for new-arc
#29
Conversation
contracts/PirexFees.sol
Outdated
uint8 public immutable PERCENT_DENOMINATOR = 100; | ||
bytes32 public immutable FEE_DISTRIBUTOR_ROLE = | ||
uint8 public constant PERCENT_DENOMINATOR = 100; | ||
bytes32 public constant FEE_DISTRIBUTOR_ROLE = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the other non-32 byte variables to constants, but for FEE_DISTRIBUTOR_ROLE
, we should keep it as an immutable variable even if we don't set it in the constructor:
For a constant variable, the expression assigned to it is copied to all the places where it is accessed and also re-evaluated each time. This allows for local optimizations. Immutable variables are evaluated once at construction time and their value is copied to all the places in the code where they are accessed. For these values, 32 bytes are reserved, even if they would fit in fewer bytes. Due to this, constant values can sometimes be cheaper than immutable values.
It seems that constants may be more efficient in cases where the variable does not need 32 bytes allocated (would not be the case here).
Also, since constants are re-evaluated every time, wouldn't that increase runtime costs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both constant
and immutable
vars are replaced by their values at execution, so usual expensive gas cost from reading state vars won't apply here. Did some test run with gas reporter and I can confirm that immutable
does cost a bit less gas than constant
for bytes32
, but more a bit more expensive for those smaller than bytes32
size. Good find 👍
6062b19
to
0b12116
Compare
Related Issues
Changes
new-arc
branch:solidity-coverage
package to help identifying possible missing (and important) test scenariosvalidateEvent
) and apply it to all existing event testsimmutable
state variables toconstant
instead (ie. they already are assigned on declaration)constant
state variables in testsPirexCvx
unit tests into 3 smaller groups based on action flow (base, main, reward)before
hook to setup required variables commonly used for all testsNotes
npm i
for the first time testing the PR due to new packages