Block: 54

Timestamp: 01:13:41

AuditProfile

Security blog

How to write tests for Proxy contracts with Foundry?

I know there are so many articles of how to test / deploy proxy contracts with Hardhat, but do you know you can do it with Foundry?

Here is how it works:

First, create a new project, run `forge init` and the next commands:

Right after create a 'remappings.txt' and provide new paths:

Then open up the foundry.toml file and add the following code to your file:

Now lets write two versions of token contract:

Pay attention to the next line:

@custom
:oz-upgrades-from MyToken. It is necessary to run an upgrade in a right way!

Now we can write a test! Also note some new import files and Upgrades from "openzeppelin-foundry-upgrades/Upgrades.sol"

Here is a test contract:

Now you can run `forge test --ffi` to test your proxy!

Later you can deploy it to the required blockchain with a simple script:

Now you know how to work with proxy contracts in Foundry!

Like, comment and share!

For more info visit Open Zeppelin repo:

Link: https://github.com/OpenZeppelin/openzeppelin-foundry-upgrades

#foundry

#proxy

#test

Connent with me:

Регистрация прошла успешно! Спасибо за внимание!

loader