-
Notifications
You must be signed in to change notification settings - Fork 22
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(script): Assert state changes for script tests #79
Conversation
test(script): Assert state changes for script tests
🚨 Report Summary
For more details view the full report in OpenZeppelin Code Inspector |
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.
Looks good few additional points:
- Some of my script tests are failing locally with a mix of errors related to env vars. The errors vary each time (occasionally they all pass). I wonder if my env vars are not getting set up correctly somehow. Are your tests passing locally?
- Could you implement this point you raised:
Merging similar scripts and using branching logic with params (e.g., the AccountHiding scripts, which are 99% identical to the non-hiding versions).
- Could you also replace any hardcoded salts with env values as well?
@benceharomi solved on my end I was accidently running |
Latest changes look good. Only task left is regarding "Merging similar scripts and using branching logic with params". let me know if any issues |
1eaac80
to
b990bcd
Compare
8d29d10
to
830a40f
Compare
@JohnGuilding it's ready for review |
Summary
I focused on improving the tests, but also cleaned up and organised some of the scripts to make them easier to follow.
This PR resolves #65
Approach
Not all scripts store their deployed contract addresses in public variables, so I assumed those addresses weren’t accessible. To handle address checks, I added two functions:
For each test, I followed these steps:
Each test goes through all possible branches in the script and each test case covers the deployment of one contract. I also changed the scripts so they start by loading the required env vars, if an env var is missing, the script will fail right away, before starting deployments.
The test process for each script includes:
For the calldata computation scripts, the success tests basically replicate the implementation logic, but they’re useful to confirm everything works as expected, especially if the code is refactored in the future.
To reduce repeated code, I moved common test cases into the base file so they can be reused. This makes the test files cleaner and easier to read.
This approach helped me achieve 100% code and branch coverage for all tested scripts.

ENV issues
I ran into some strange behaviour with how Foundry handles environment variables. I found a closed GitHub issue explaining this problem. The issue is that if env vars are set in both setUp and the test cases, Foundry doesn’t reload them before every test, even though setUp runs before each test. For example, if one test clears an env var set in setUp, the next test might see it as empty. Since Foundry runs tests in non-deterministic order, this causes unexpected results.
To fix this, I created a separate function that can be used to set env vars at the start of each test case. This ensures that the right env vars are always set before the tests run.
Findings
There is a lot of repeated code in the scripts, as shown by the number of reused test cases. This duplication could be reduced by either:
I also noticed that some deployment scripts use a hardcoded salt value of 0. If this wasn’t intentional, it might need to be addressed. (
DeployEmailRecoveryModule
,DeploySafeRecoveryWithAccountHiding
,DeployUniversalEmailRecoveryModule
)