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

Encapsulation of initialization variables and minor refactoring of BaseTest #1191

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

elshan-eth
Copy link
Contributor

Description

A variable that we initialize before setUp, defaultAccountBalance has been encapsulated in a separate method to be able to get a readable error and prevent uncontrolled changes to this variable.

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Dependency changes
  • Code refactor / cleanup
  • Optimization: [ ] gas / [ ] bytecode
  • Documentation or wording changes
  • Other

Checklist:

  • The diff is legible and has no extraneous changes
  • Complex code has been commented, including external interfaces
  • Tests have 100% code coverage
  • The base branch is either main, or there's a description of how to merge

Issue Resolution

Copy link
Contributor

@joaobrunoah joaobrunoah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Collaborator

@EndymionJkb EndymionJkb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

}

function setDefaultAccountBalance(uint256 balance) internal {
if (_initialized) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isInitialized() is never called; could call it here, or we don't need it.

}

function defaultAccountBalance() internal view returns (uint256) {
return _defaultAccountBalance;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

require that it be initialized? Could even lazy initialize it, if there's a reasonable default. Like if it's not initialized, set it to a global default and then set _initialized. If a particular test wants to use a different specific value, it can just be sure to call setDefaultAccountBalance before anything that references it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or make a virtual defaultAccountBalance() that just returns the standard value, and if tests want something different, they can override it?

/**
* @notice Manipulate rates of ERC4626 tokens.
* @dev It's important to not have a 1:1 rate when testing ERC4626 tokens, so we can differentiate between
* wrapped and underlying amounts. For certain tests, we may need to override these rates for simplicity.
*/
function mockERC4626TokenRates() internal virtual {
waDAI.inflateUnderlyingOrWrapped(0, 6 * defaultBalance);
waUSDC.inflateUnderlyingOrWrapped(23 * defaultBalance, 0);
waDAI.inflateUnderlyingOrWrapped(0, 6 * _defaultAccountBalance);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using the function consistently, instead of the variable directly (as it's internal)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants