-
Notifications
You must be signed in to change notification settings - Fork 131
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
Unable to run invariant tests using handler pattern #565
Comments
Hey @brotherlymite, thanks for the report! There's no way for us to determine if the target selectors are handler contracts or not, thus it's not possible to determine whether to run it in EVM or zkVM automatically. We are working on a new feature (#569) which will make calling cheatcodes in external contracts a lot easier to work with, without having to switch zkvm on or off manually. Unfortunately, there's no workaround available to make it work today, but if you wish to maintain this type of test I can suggest migrating to a fuzz test instead, for example: struct SummaryInput {
uint8 tokenIndex;
uint128 amount;
uint8 opIdx;
}
/// forge-config: zksync.fuzz.runs = 25
/// forge-config: zksync.fuzz.show-logs = true
function testFuzz_summary(SummaryInput[1000] memory inputs) external {
address(vm).call(abi.encodeWithSignature("zkVm(bool)", false));
FuzzSelector memory pool = targetSelectors()[0];
for (uint i = 0; i < inputs.length; i++) {
SummaryInput memory input = inputs[i];
uint8 idx = (input.opIdx % uint8(pool.selectors.length));
bytes4 op = pool.selectors[idx];
address(s_poolHandler).call(abi.encodeWithSelector(op, input.tokenIndex, input.amount));
}
s_poolHandler.summary();
} You can tweak the Note that the calls to |
Hey @brotherlymite, upon further review we actually determined the issue to be a bit different. The fix in this case would be to deactivate zkVm before doing the deployment of the handler, which resolves the issue above, and allows invariant tests to run as normal. Additionally, in the version you originally encountered the issue there's still a bug, in particular when the deployment happening in EVM instead of zkVM, it wouldn't be detected for the invariant executor, but this has been resolved as of #572, therefore an upgrade is required to run invariant tests with the handler pattern. There are a few more adjustments that need to be made to make the invariant test to run successfully, but these are relatively easy and are just to account for zkVM specifics:
Please let me know if you have any more questions about this issue! Thank you |
* test(zk): add #565 repro * test(zk:565): fix invariant and use zkVmSkip * fix(zk): use constant test addr for zkvm skip test * test(zk): proper basic invariant test * test(zk:invariant): add direct invariant test * feat: `InZkVm` utility to detect if contract is running in zkVm * chore: lints & formatting * refactor(test:zk): edit runner test opts * fix(test:zk): pre-select target senders for issue565 w/o handler * fix(zk): use `get_test_contract_address` * fix(backend): don't set test contract on each init * chore: lints * fix(executor): set_test_contract even w/o setup * test(zk): filter test to specific contract * refactor(zk): simplify test contract check Co-authored-by: Nisheeth Barthwal <[email protected]> * chore: fmt --------- Co-authored-by: Nisheeth Barthwal <[email protected]>
Hey @brotherlymite! We have fixed the issue with invariant testing as of #581! |
Component
Forge
Have you ensured that all of these are up to date?
What version of Foundry are you on?
forge 0.0.2 (a69c479 2024-09-06T00:32:22.954024000Z)
What command(s) is the bug in?
forge test --zksync
Operating System
macOS (Apple Silicon)
Describe the bug
When running the invariant test, the test seems to be passing but strangely the functions in the handler contract are not being called for some reason.
To replicate, run
forge test --match-contract PoolInvariants -vv --show-progress
on this branch and you would see the following output in the terminal:When the same test is being run in zksync, we see that the handler functions are not being called. To run the same test in zksync and replicate: checkout to this branch, copy
.env.examples
to.env
and runFOUNDRY_PROFILE=zksync forge test --zksync --match-contract PoolInvariants --rpc-url https://mainnet.era.zksync.io -vv --show-progress
.This is the output we are getting when running the same test in zksync:
We see that none of the actions of the invariant test, including
Supply
,Borrow
,Withdraw
,Repay
are being called for some reason but the same test in normal foundry works fine.The text was updated successfully, but these errors were encountered: