matter-labs / foundry-zksync

Fork of Foundry tailored for zkSync environment
Apache License 2.0
299 stars 130 forks source link

fix(zk): invariant testing #581

Closed Karrq closed 1 month ago

Karrq commented 2 months ago

Motivation

Investigating #565 it was found that invariant tests weren't properly supported, with the handler pattern being usable after #572, but we found that using a non-handler contract as target was still not working as intended, due to a workaround to have the toplevel contract execution not being run in zkVm, to allow tests and script to be run in EVM.

Solution

Adjust the check to only skip if the target address is the (constant) test contract address, so other toplevel calls can be ran in zkVm.

Other changes

Adjusted InvariantDeposit test to be a proper invariant test, asserting that execution of the target contracts happens in zkVm (with new utility contract). Added minimal reproducible test for issue described #565 (and alternative test without handler). Adjusted 1 other test to use the new constant for the test contract address.