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

Unit test in github actions: Validations cache not found #623

Closed
developerasun opened this issue Aug 6, 2022 · 5 comments
Closed

Unit test in github actions: Validations cache not found #623

developerasun opened this issue Aug 6, 2022 · 5 comments

Comments

@developerasun
Copy link

developerasun commented Aug 6, 2022

problem

I was working on my personal project using openzeppelin/contracts-upgradeable.

Github actions requires below things for testing upgradeable ERC20(UUPS)

  • artifacts
  • validations cache

screenshot

artifact-not-found

validation-cache-not-found

dependency
"@chainlink/contracts": "^0.4.1",
    "@ethersproject/abi": "^5.0.0",
    "@ethersproject/bytes": "^5.0.0",
    "@ethersproject/providers": "^5.0.0",
    "@nomicfoundation/hardhat-chai-matchers": "^1.0.2",
    "@nomicfoundation/hardhat-network-helpers": "^1.0.3",
    "@nomiclabs/hardhat-ethers": "^2.0.6",
    "@nomiclabs/hardhat-etherscan": "^3.1.0",
    "@openzeppelin/contracts": "^4.6.0",
    "@openzeppelin/contracts-upgradeable": "^4.7.0",
    "@openzeppelin/hardhat-upgrades": "^1.19.0",
    "@typechain/ethers-v5": "^7.2.0",
    "@typechain/hardhat": "^2.3.1",
    "@types/chai": "^4.3.1",
    "@types/mocha": "^9.1.1",
    "@types/node": "^12.20.55",
    "@typescript-eslint/eslint-plugin": "^4.33.0",
    "@typescript-eslint/parser": "^4.33.0",
    "async": "^3.2.4",
    "chai": "^4.3.6",
    "chalk": "4.1.2",
    "dotenv": "^16.0.1",
    "eslint": "^7.32.0",
    "eslint-config-prettier": "^8.5.0",
    "eslint-config-standard": "^16.0.3",
    "eslint-plugin-import": "^2.26.0",
    "eslint-plugin-node": "^11.1.0",
    "eslint-plugin-prettier": "^4.0.0",
    "eslint-plugin-promise": "^4.2.1 || ^5.0.0",
    "ethers": "^5.6.9",
    "hardhat": "^2.9.9",
    "hardhat-contract-sizer": "^2.5.1",
    "hardhat-gas-reporter": "^1.0.8",
    "hardhat-log-remover": "^2.0.2",
    "install": "^0.13.0",
    "lodash": "^4.17.15",
    "mocha": "^10.0.0",
    "nodemon": "^2.0.15",
    "prettier": ">=2.0.0",
    "prettier-plugin-solidity": "1.0.0-beta.19",
    "solhint": "^3.3.7",
    "solidity-coverage": "^0.7.21",
    "ts-node": "^10.8.1",
    "typechain": "^5.2.0",
    "typescript": "^4.7.4"
@developerasun
Copy link
Author

developerasun commented Aug 6, 2022

I have manged to solve these issues by uploading artifacts directory and validations.json.

But I'm not sure if I have to upload the json files every time I refactor upgradeable contracts with some test files. If I understood correctly how testing upgradeable contract in github actions works, I have to.

Do I?

@frangio
Copy link
Contributor

frangio commented Aug 20, 2022

You definitely shouldn't need to add those files to your repository! I don't know why this is happening to you. Can you create a minimal repo that reproduces the issue?

@developerasun
Copy link
Author

developerasun commented Aug 20, 2022

You definitely shouldn't need to add those files to your repository! I don't know why this is happening to you. Can you create a minimal repo that reproduces the issue?

I will try to reproduce the issue and comment again.

That's the point where I felt a bit strange cause I thought like I read Openzeppelin docs saying that you don't have to upload build-info and such directory to git, unlike .openzeppelin directory is recommended to upload to git.

One more question,

Maybe is it because I was using mocha test in CI instead of hardhat test command? I know hardhat already uses mocha but I did that to exploit more flag options, for example slow like below.

The command I was using is,

    "test:unit": "mocha -g \"unit\" --slow 2000  --reporter list",

From Hardhat ver2.9, it can be replaced with,

"test:unit": "pnpm exec hardhat test --grep \"unit\""

Is there difference between executing test for upgradeable contracts by mocha and by hardhat?

@frangio
Copy link
Contributor

frangio commented Aug 22, 2022

Maybe is it because I was using mocha test in CI instead of hardhat test command?

Yes, this is the problem. hardhat test will compile the contracts before running the tests. You can use mocha but you should do hardhat compile && mocha ....

@frangio frangio closed this as completed Aug 22, 2022
@developerasun
Copy link
Author

developerasun commented Aug 22, 2022

Maybe is it because I was using mocha test in CI instead of hardhat test command?

Yes, this is the problem. hardhat test will compile the contracts before running the tests. You can use mocha but you should do hardhat compile && mocha ....

I'll leave a fixed script command below for others.

I solved issue change the script from

    "test:unit": "mocha -g \"unit\" --slow 2000  --reporter list",

to

    "ci:unit": "pnpm exec hardhat test --grep \"unit\"",
    "ci:integ": "pnpm exec hardhat test --grep \"integ\"",
    "ci:tests": "pnpm ci:unit & pnpm ci:integ",

Recommend to split scripts to 1) development (mocha test command with fluent flag options + nodemon ) 2) ci (hardhat test command for generating artifacts and stuff you need).

Check the scripts here: https://github.com/asunlabs/pawcon-monorepo/blob/develop/apps/blockchain/package.json

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

No branches or pull requests

2 participants