Testing Smart Contracts
1
Write test definitions
Write test definitions inside the
/test
directory, for example, test/HelloWorld.t.sol
.2
Run tests
Run the tests by running the following command:
Cheatcodes
Cheatcodes allow you to manipulate the state of the blockchain during testing, allowing you to change the block number, your identity, and more.Foundry Cheatcode Reference
Reference for all cheatcodes available in Foundry.
Cheatcode Limitations
When testing on Abstract, cheatcodes have important limitations due to how the underlying ZKsync VM executes transactions. Cheatcodes can only be used at the root level of your test contract - they cannot be accessed from within any contract being tested.ZKsync VM Cheatcodes
Abstract’s underlying ZKsync VM provides additional cheatcodes for testing Abstract-specific functionality:Cheatcode | Description |
---|---|
zkVm | Enables/disables ZKsync context for transactions. Switches between EVM and zkEVM execution environments. |
zkVmSkip | When running in zkEVM context, skips the next CREATE or CALL , executing it on the EVM instead. |
zkRegisterContract | Registers bytecodes for ZK-VM for transact/call and create instructions. Useful for testing with contracts already deployed on-chain. |
zkUsePaymaster | Configures a paymaster for the next transaction. Enables testing paymasters for gasless transactions. |
zkUseFactoryDep | Registers a factory dependency for the next transaction. Useful for testing complex contract deployments. |