create-blaize-audit v1.0.1
Project Documentation
This README provides comprehensive documentation for setting up, developing, testing, and deploying the project. It includes instructions for installation, environment setup, running scripts, and troubleshooting.
Table of Contents
- Installation
- Guide to Set Up
.env
Environments - Testing
- Scripts Running
- Test Coverage Results
- Troubleshooting
Installation
Prerequisites: NodeJS
version 16 or higher, npm
version 7 or higher.
π NodeJS
version v22.5.1
and npm
version 10.8.3
were used for development.
Run the command $ npm install
in the root of the project directory to install all the dependencies specified in package.json
, compile contracts (contracts/
), prepare an ABI (abi/
), documentation (docs/
) for the contracts in the NatSpec format and Husky hooks.
Guide to Set Up .env
Environments
Steps
Create a
.env
File- In the root directory of your project, create a file named
.env
.
- In the root directory of your project, create a file named
Define Environment Variables
- Open the
.env.example
file and copy all variables and then paste them into.env
file and set the values
- Open the
DEVELOPMENT Mode
For the audits it is recommended to not use development mode. Development mode allows to generate docs and abi after each commit to the github.
Development mode is designed to automate certain tasks before committing changes to the repository. It performs the following actions:
- Loads Environment Variables: If a
.env
file exists in the project directory, the script loads the environment variables defined in it. - Checks DEVELOPMENT Environment Variable: The script checks if the
DEVELOPMENT
environment variable is set totrue
. - Conditional Actions Based on DEVELOPMENT:
- If
DEVELOPMENT
istrue
, the script performs the following tasks: a. Rundev:abi
Script: Executes thedev:abi
npm script to generate ABI files and stages any changes in theabi/
directory. b. Rundev:docs
Script: Executes thedev:docs
npm script to generate documentation and stages any changes in thedocs/
directory. c. Runlint-staged
: Executeslint-staged
to lint and format the staged files.
- If
This script ensures that the ABI files and documentation are up-to-date and that the code is properly linted and formatted before committing changes, provided that the DEVELOPMENT
environment variable is set to true
.
Testing
Hardhat
Run $ npm run dev:coverage
to examine how well the developed tests cover the functionality of contracts. The results can also be viewed in a web browser by opening a file coverage/index.html
created by the script.
Perform tests with $ npm test
to run all tests from the test/
directory.
Use $ npm run test-t
to see events and calls when running tests, or $ npm run test-ft
to also see the storage operations.
π Each test case (it()
) of tests/
is independent, a snapshot or beforeEach()
, so the entire specific flow is contained in it()
and a set of before()
and beforeEach()
before it.
Foundry
Run $ forge coverage
to examine how well the developed tests cover the functionality of contracts.
Run $ forge coverage --report lcov
to create lcov file with coverage data.
Run $ forge coverage --report debug
to output uncovered code locations.
Perform tests with $ forge test -vvv
to run all tests from the test/
directory.
π _Each test case is independent function.
Scripts running
Hardhat Scripts
scripts/hardhat/deployment/deploy.js
This script is used to deploy the smart contracts using Hardhat.
Usage:
$ npx hardhat run scripts/hardhat/deployment/deploy.ts --network <network-name>
Description:
- This script deploys the smart contracts to the specified network.
- Replace
<network-name>
with the name of the network you want to deploy to (e.g.,mainnet
,sepolia
).
Example:
$ npx hardhat run scripts/hardhat/deployment/deploy.ts --network sepolia
Foundry Scripts
scripts/foundry/DeployPositiveEvenSetter.s.sol
This script is used to deploy the PositiveEvenSetter
contract using Foundry.
πBefore running script for deployment make sure you set all the values in .env
and then run the following command to load all environment variables.
πPrivate key
must starts with 0xyour_private_key
$ source .env
Usage:
$ forge script scripts/foundry/DeployPositiveEvenSetter.s.sol --broadcast --rpc-url <YOUR_RPC_URL> --verify -vvvv
Description:
- This script deploys the
PositiveEvenSetter
contract to the specified network. - Replace
<YOUR_RPC_URL>
with the RPC URL of the network you want to deploy to (e.g., Infura, Alchemy). - Remove
<--verify>
if ETHERSCAN_API_KEY is not provided
Example:
$ forge script scripts/DeployPositiveEvenSetter.s.sol --broadcast --rpc-url https://mainnet.infura.io/v3/YOUR_INFURA_PROJECT_ID -- verify
Summary
These scripts help automate the deployment of smart contracts using Hardhat and Foundry. Make sure to replace the placeholders with actual values when running the scripts.
Test coverage results
File | % Stmts | % Branch | % Funcs | % Lines |
---|---|---|---|---|
Troubleshooting
Hardhat:
Use $ npm run clean
and try again.
Foundry:
- Use
$ foundryup
- Then
$ forge install