This contract was created mainly to understand how I can use Merkle proofs in Solidity and write tests for it using Foundry.
I have inherited a ERC20 template from Openzepplin contracts and created mint and burn functionality which restricts the functions to a certain whitelist of addresses.
The test was written in Forge and for generating root of the Merkle tree and testing its validity I have used Murky repo. I have also used fuzzing approach in the test.
Note that this is not for production and have many vulnerabilities. I just created it for learning purposes.
- git
- You'll know you did it right if you can run
git --version
and you see a response likegit version x.x.x
- You'll know you did it right if you can run
- foundry
- You'll know you did it right if you can run
forge --version
and you see a response likeforge 0.2.0 (816e00b 2023-03-16T00:05:26.396218Z)
- You'll know you did it right if you can run
Install any missing libraries by running:
forge install https://github.com/OpenZeppelin/openzeppelin-contracts.git --no-commit
forge install https://github.com/dmfxyz/murky.git --no-commit
git clone https://github.com/El-Ku/Testing-Merkle-Trees
cd Testing-Merkle-Trees
forge build
Note that I didnt write any tests for the burn
function. As the repo was created only to learn about Merkle trees.
# Test everything without any log messages
forge test
# Test everything with emitted events and console messages
forge test -vv
# Test everything with information printed out on each individual transaction
forge test -vvvv
or
# Only run test functions matching the specified regex pattern.
forge test --match-test testFunctionName
(OR)
forge test --mt testFunctionName
forge coverage
You can estimate how much gas things cost by running:
forge snapshot
And you'll see and output file called .gas-snapshot
To run code formatting:
forge fmt