This project was tested by using foundry. foundry is contract tool for deploy, test by solidity.
foundry use git submodule , submodules don't scale.
- Slow installation times
- Switching between branches produces git diffs when the submodules are different
- Need custom helpers like this "reinit"
So this template uses Node.js packages by yarn.
- Forge: compile, test, fuzz, format, and deploy smart contracts
- Forge Std: collection of helpful contracts and cheatcodes for testing
- DSTest: Forge Std collection of testing assertions and logging utilities
- PRBTest: modern collection of testing assertions and logging utilities
- Solhint: linter for Solidity code
- OpenzeppelinV4.9.5 : Contract code for develop more easier
This template comes with a set of sensible default configurations for you to use. These defaults can be found in the following files:
├── .gitignore
├── .solhint.json
├── foundry.toml
└── remappings.txt
This template is IDE agnostic, but for the best user experience, you may want to use it in VSCode alongside Nomic Foundation's Solidity extension.
For guidance on how to integrate a Foundry project in VSCode, please refer to this guide.
Foundry typically uses git submodules to manage dependencies, but this template uses Node.js packages because
This is how to install dependencies:
- Install the dependency using your preferred package manager, e.g.
bun install dependency-name- Use this syntax to install from GitHub:
bun install github:username/repo-name
- Use this syntax to install from GitHub:
- Add a remapping for the dependency in remappings.txt, e.g.
dependency-name=node_modules/dependency-name
Note that OpenZeppelin Contracts is pre-installed, so you can follow that as an example.
This is a list of the most frequently needed commands.
Build the contracts:
$ forge buildDelete the build artifacts and cache directories:
$ forge cleanCompile the contracts:
$ forge buildGet a test coverage report:
$ forge coverageDeploy to Anvil:
$ forge script script/Deploy.s.sol --broadcast --fork-url http://localhost:8545For this script to work, you need to have a MNEMONIC environment variable set to a valid
BIP39 mnemonic.
For instructions on how to deploy to a testnet or mainnet, check out the Solidity Scripting tutorial.
Format the contracts:
$ forge fmtGet a gas report:
$ forge test --gas-reportLint the contracts:
$ bun run lintRun the tests:
$ forge testMore Detail(console) test:
forge test -vvMore Detail(console and onChain Event):
forge test -vvvIf you want to test contract in env of mainnet:
$ bun run test:fork:mainnetGenerate test coverage and output result to the terminal:
$ bun run test:coverageGenerate test coverage with lcov report (you'll have to open the ./coverage/index.html file in your browser, to do so
simply copy paste the path):
$ bun run test:coverage:report