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

Update coverage of test #14326

Open
wants to merge 95 commits into
base: master
Choose a base branch
from
Open

Conversation

deepsea514
Copy link
Contributor

@deepsea514 deepsea514 commented Jul 29, 2024

Description

Update tests to increase coverage.
Some cases, coverage is not 100% because there are mainnet features with static addresses and duplicated and private functions are not used.

Issues

Fixes #13831
Refs #13831

Checklist:

  • 1 PR, 1 purpose: my Pull Request applies to a single purpose
  • I have commented my code, particularly in hard-to-understand areas
  • I have updated the docs to reflect my changes if applicable
  • I have added tests (and stories for frontend components) that prove my fix is effective or that my feature works
  • I have performed a self-review of my own code
  • If my code involves visual changes, I am adding applicable screenshots to this thread

Release Note Draft Snippet

Copy link

cla-bot bot commented Jul 29, 2024

Thank you for your pull request and welcome to Unlock! We require contributors to sign our Contributor License Agreement, and we don't seem to have the users @deepsea514 on file.
In order for us to review and merge your code, please open another pull request with a single modification: your github username added to the file .clabot.
Thank you!

Copy link

cla-bot bot commented Jul 29, 2024

Thank you for your pull request and welcome to Unlock! We require contributors to sign our Contributor License Agreement, and we don't seem to have the users @deepsea514 on file.
In order for us to review and merge your code, please open another pull request with a single modification: your github username added to the file .clabot.
Thank you!

@SVell
Copy link
Contributor

SVell commented Jul 29, 2024

@deepsea514 You need to submit a separate pr with .calbot file changes

@deepsea514
Copy link
Contributor Author

#14327

Copy link

cla-bot bot commented Jul 30, 2024

Thank you for your pull request and welcome to Unlock! We require contributors to sign our Contributor License Agreement, and we don't seem to have the users @deepsea514 on file.
In order for us to review and merge your code, please open another pull request with a single modification: your github username added to the file .clabot.
Thank you!

@cla-bot cla-bot bot added the cla-signed label Jul 31, 2024
@julien51 julien51 requested review from clemsos and julien51 and removed request for clemsos August 5, 2024 13:37
@deepsea514
Copy link
Contributor Author

@julien51 , @clemsos
Could you please review?

Copy link
Member

@clemsos clemsos left a comment

Choose a reason for hiding this comment

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

Hello ! So far so good. I left some minor text edits and a few tests that seems to be missing.

Looking at the coverage results below, it seems that CardPurchaser.sol is still lacking tests. Also I will remove all *.flatten.sol. It is a mistake and the flattened files should not be commited to the repo.

Thanks!

------------------------------|----------|----------|----------|----------|----------------|
File                          |  % Stmts | % Branch |  % Funcs |  % Lines |Uncovered Lines |
------------------------------|----------|----------|----------|----------|----------------|
 contracts/                   |    53.76 |       50 |    66.07 |    54.94 |                |
  CardPurchaser.sol           |        0 |        0 |        0 |        0 |... 170,196,197 |
  KeyManager.sol              |      100 |       90 |      100 |      100 |                |
  Kickback.flatten.sol        |        0 |        0 |        0 |        0 |... 935,937,939 |
  PublicLock.sol              |      100 |      100 |      100 |      100 |                |
  Unlock.sol                  |    94.12 |    81.08 |    93.75 |    91.27 |... 643,644,650 |
 contracts/hooks/             |    95.35 |      100 |    89.47 |    96.34 |                |
  CaptchaHook.sol             |      100 |      100 |      100 |      100 |                |
  DiscountCodeHook.sol        |      100 |      100 |      100 |      100 |                |
  ERC1155BalanceOfHook.sol    |      100 |      100 |      100 |      100 |                |
  ERC20BalanceOfHook.sol      |      100 |      100 |      100 |      100 |                |
  ERC721BalanceOfHook.sol     |      100 |      100 |      100 |      100 |                |
  GitcoinHook.sol             |     87.5 |      100 |       80 |    90.91 |          60,64 |
  GuildHook.sol               |    88.24 |      100 |       80 |     91.3 |          61,65 |
  PasswordRequiredHook.sol    |    86.67 |      100 |    77.78 |     91.3 |          69,73 |
  TokenUriHook.sol            |      100 |      100 |      100 |      100 |                |
 contracts/interfaces/        |      100 |      100 |      100 |      100 |                |
  IMintableERC20.sol          |      100 |      100 |      100 |      100 |                |
  IPermit2.sol                |      100 |      100 |      100 |      100 |                |
  IPublicLock.sol             |      100 |      100 |      100 |      100 |                |
  ISwapBurner.sol             |      100 |      100 |      100 |      100 |                |
  IUSDC.sol                   |      100 |      100 |      100 |      100 |                |
  IUniswapOracleV3.sol        |      100 |      100 |      100 |      100 |                |
  IUniversalRouter.sol        |      100 |      100 |      100 |      100 |                |
  IUnlock.sol                 |      100 |      100 |      100 |      100 |                |
  IWETH.sol                   |      100 |      100 |      100 |      100 |                |
 contracts/interfaces/hooks/  |      100 |      100 |      100 |      100 |                |
  ILockKeyCancelHook.sol      |      100 |      100 |      100 |      100 |                |
  ILockKeyExtendHook.sol      |      100 |      100 |      100 |      100 |                |
  ILockKeyGrantHook.sol       |      100 |      100 |      100 |      100 |                |
  ILockKeyPurchaseHook.sol    |      100 |      100 |      100 |      100 |                |
  ILockKeyTransferHook.sol    |      100 |      100 |      100 |      100 |                |
  ILockTokenURIHook.sol       |      100 |      100 |      100 |      100 |                |
  ILockValidKeyHook.sol       |      100 |      100 |      100 |      100 |                |
 contracts/mixins/            |    98.78 |    92.73 |    98.92 |     97.5 |                |
  MixinConvenienceOwnable.sol |      100 |      100 |      100 |      100 |                |
  MixinDisable.sol            |      100 |      100 |      100 |      100 |                |
  MixinERC721Enumerable.sol   |      100 |      100 |      100 |      100 |                |
  MixinErrors.sol             |      100 |      100 |      100 |      100 |                |
  MixinFunds.sol              |      100 |    66.67 |      100 |    88.89 |             32 |
  MixinGrantKeys.sol          |      100 |      100 |      100 |      100 |                |
  MixinKeys.sol               |    96.34 |    95.31 |    96.67 |     96.3 |... 147,159,160 |
  MixinLockCore.sol           |      100 |    95.83 |      100 |    98.11 |            121 |
  MixinLockMetadata.sol       |      100 |      100 |      100 |      100 |                |
  MixinPurchase.sol           |      100 |    98.15 |      100 |      100 |                |
  MixinRefunds.sol            |      100 |      100 |      100 |      100 |                |
  MixinRoles.sol              |      100 |    66.67 |      100 |      100 |                |
  MixinTransfer.sol           |    98.28 |    79.41 |      100 |     93.9 |... 202,299,328 |
 contracts/tokens/UDT/        |       20 |       15 |    13.33 |    15.15 |                |
  UnlockDiscountTokenV3.sol   |      100 |     37.5 |      100 |    71.43 |          34,39 |
  UnlockProtocolGovernor.sol  |        0 |        0 |        0 |        0 |... 109,118,129 |
  UnlockProtocolTimelock.sol  |        0 |        0 |        0 |        0 |             12 |
 contracts/tokens/UP/         |    97.73 |    66.67 |       96 |    88.46 |                |
  UPGovernor.sol              |    94.12 |       50 |    91.67 |    94.12 |            142 |
  UPSwap.sol                  |      100 |    57.14 |      100 |    78.26 | 64,73,83,89,95 |
  UPTimelock.sol              |      100 |       50 |      100 |      100 |                |
  UPToken.sol                 |      100 |      100 |      100 |      100 |                |
------------------------------|----------|----------|----------|----------|----------------|
All files                     |    83.57 |    76.67 |    83.74 |     83.1 |                |
------------------------------|----------|----------|----------|----------|----------------|

smart-contracts/test/Lock/hooks/CaptchaHook.js Outdated Show resolved Hide resolved
smart-contracts/test/Lock/hooks/CaptchaHook.js Outdated Show resolved Hide resolved
smart-contracts/test/Lock/purchaseWithUnlock.js Outdated Show resolved Hide resolved
smart-contracts/test/Unlock/removeLock.js Outdated Show resolved Hide resolved
smart-contracts/test/Unlock/removeLock.js Outdated Show resolved Hide resolved
smart-contracts/test/Unlock/transferTokens.js Outdated Show resolved Hide resolved
@deepsea514
Copy link
Contributor Author

The test for CardPurchaser.sol has removed by @julien51 .
Should I make it again?

@deepsea514
Copy link
Contributor Author

deepsea514 commented Aug 13, 2024

@clemsos , @julien51
Could you please add testUSDC contract for testing?
In CardPurchaser.sol, it uses IUSDC functions but not able to simulate it with mock ERC20.
The test were designed to work on mainnet only.
I cannot add mock contracts as contracts folder is git ignored.

Copy link
Member

@julien51 julien51 left a comment

Choose a reason for hiding this comment

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

Please uncomment and cleanup a bunch of things.!
Also let's get @clemsos to fo a final check!

@deepsea514
Copy link
Contributor Author

I have cleaned up things you mentioned

Copy link
Member

@clemsos clemsos left a comment

Choose a reason for hiding this comment

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

Thanks for the work ! Most of it LG

Nevertheless, running the entirety of the tests coverage suite on a mainnet fork is a not good practice and we need to avoid it.

If you need to run some of the tests on a fork, please add a coverage:mainnet task with the RUN_FORK=1 flag. That task should run only the tests suffixed with *mainnet.js. All the other unit tests files should run on a clean node, not load state from a fork.

smart-contracts/contracts/test-artifacts/TestERC20.sol Outdated Show resolved Hide resolved
smart-contracts/package.json Outdated Show resolved Hide resolved
smart-contracts/test/Lock/fail.js Show resolved Hide resolved
smart-contracts/test/UPToken/swap.js Outdated Show resolved Hide resolved
smart-contracts/test/Unlock/upgrades.mainnet.js Outdated Show resolved Hide resolved
smart-contracts/test/fixtures/deploy.js Outdated Show resolved Hide resolved
smart-contracts/test/mainnet/udt.js Outdated Show resolved Hide resolved
@deepsea514
Copy link
Contributor Author

Thanks for the work ! Most of it LG

Nevertheless, running the entirety of the tests coverage suite on a mainnet fork is a not good practice and we need to avoid it.

If you need to run some of the tests on a fork, please add a coverage:mainnet task with the RUN_FORK=1 flag. That task should run only the tests suffixed with *mainnet.js. All the other unit tests files should run on a clean node, not load state from a fork.

Yeah, I know that but many functions are designed to run on mainnet only so coverage is falling down.
That's why I have run with RUN_FORK

@deepsea514
Copy link
Contributor Author

@clemsos
I have fixed points you mentioned.

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

Successfully merging this pull request may close these issues.

Get to 100% coverage for smart contracts
4 participants