Skip to main content
Verify your smart contracts work as intended before you deploy them by writing tests.

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:

Fork Testing

Running your tests against a fork of Abstract testnet or mainnet allows you to test your contracts in a real environment before deploying to Abstract. This is especially useful for testing contracts that interact with other contracts on Abstract such as those listed on the Deployed Contracts page. To run your tests against a fork of Abstract testnet or mainnet, you can use the following command:

Local Node Testing

Anvil-zksync comes installed with Foundry, and is a tool that allows you to instantiate a local node for testing purposes. Run the following command to start the local node:
Then run your tests on the local node by running the following command:
View all available options ↗.

Advanced Testing

View further documentation on advanced testing with Foundry-zksync: