Releases: marc-aurele-besner/hardhat-awesome-cli
v0.1.1
👷 hardhat-awesome-cli
# # ## ##### ##### # # ## ##### ## # # ###### #### #### # # ###### #### # #
# # # # # # # # # # # # # # # # # # # # # ## ## # # # # #
###### # # # # # # ###### # # # ##### # # # # ##### #### # # # ## # ##### ##### # # #
# # ###### ##### # # # # ###### # ###### # ## # # # # # # # # # # #
# # # # # # # # # # # # # # # ## ## # # # # # # # # # # # #
# # # # # # ##### # # # # # # # # # ###### #### #### # # ###### #### ###### #
Hardhat made awesome with a flexible CLI to help run tests, deploy and more.
How to install this package
1. Install this package
With NPM
npm install hardhat-awesome-cli
Or with Yarn
yarn add hardhat-awesome-cli
2. Import/Require this package in your hardhat.config.js/.ts
Inside inside hardhat.config.js
require('hardhat-awesome-cli')
or inside hardhat.config.ts (Typescript)
import 'hardhat-awesome-cli'
Other option
Clone this repository and create a symlink
git clone https://github.com/marc-aurele-besner/hardhat-awesome-cli
cd hardhat-awesome-cli
npm install
npm run build
npm link
in the hardhat project, you want to use this plugin
npm link hardhat-awesome-cli
Directories
CLI features
-
Run tests (Allow you you to run tests on all files or specific files in test/)
-
Run scripts (Allow you you to run scripts on specific files in scripts/)
-
Select scripts and tests to run (Allow you to select a script to execute and all or one test to perform afterward)
-
Flatten all your contract or a specific contract (offer to rename SPDX-License-Identifier -> SPDX-License-Flatten-Identifier to avoid multiple license identifier issue)
-
Run Forge test on all or single test contracts if forge setting is detected
-
Run coverage tests (Available only if solidity-coverage is installed and available as a task)
-
Setup chains, RPC and accounts
- Add/Remove chains from the chain selection
- Set RPC Url, private key or mnemonic for all or one chain
- Add a custom chain to the current chain selection (currently these custom chains are not getting injected into hardhat networks)
- See all config for activated chain
-
More settings
-
Exclude test file from the tests selection list
-
Exclude script file from the scripts selection list
-
Exclude script or contract file from the contract selection list
-
Install/Uninstall other Hardhat plugins
-
Create Github test workflows (for NPM and/or Yarn and for Hardhat test&coverage and/or Foundry test)
-
Create Foundry settings, remapping and test utilities
More details on Foundry
[Foundry Documentation](https://book.getfoundry.sh/index.html)Run forge test
forge test
-
-
Create Mock contracts + (Deployment scripts, tests scripts and Foundry(Forge) test contracts (Missing test for MockProxyAdmin and MockTransparentUpgradeableProxy))
- MockERC20
- MockERC721
- MockERC1155
- MockERC20Upgradeable
- MockERC721Upgradeable
- MockERC1155Upgradeable
- MockProxyAdmin
- MockTransparentUpgradeableProxy
-
Get account balance
Current chain support
- Hardhat local (default local network)
- Ethereum - Mainnet (chainId: 1)
- Ethereum - Ropstein (chainId 3)
- Ethereum - Rinkeby (chainId 4)
- Ethereum - Goerli (chainId 5)
- Ethereum - Kovan (chainId 42)
- Polygon - Mainnet (chainId 137)
- Polygon - Mumbai (chainId 80001)
- Binance Smart Chain - Mainnet (chainId 56)
- Binance Smart Chain - Testnet (chainId 97)
- Optimism - Mainnet (chainId 10)
- Optimism - Testnet Kovan (chainId 69)
- Avalanche - Mainnet (chainId 43114)
In 'More settings' you can also add a custom chain, create an issue or pull request to add other chains.
CLI optional flags
- --add-activated-chain Add chains from the chain selection (default: "")
- --add-foundry Create Foundry settings, remapping and test utilities (default: "")
- --add-github-test-workflow Create Github test workflows (default: "")
- --add-hardhat-plugin Add other Hardhat plugins (default: "")
- --exclude-contract-file Exclude contract file from the contract selection list (default: "")
- --exclude-script-file Exclude script file from the scripts selection list (default: "")
- --exclude-test-file Exclude test file from the tests selection list (default: "")
- --get-account-balance Get account balance (default: "")
- --remove-activated-chain Remove chains from the chain selection (default: "")
- --remove-hardhat-plugin Remove other Hardhat plugins (default: "")
Helper tools
Tools that you can use in your scripts and tests to make your life easier
Address Book
Create (if it does not exist) contractsAddressDeployed.json and contractsAddressDeployedHistory.json to store all the contracts you deployed, with the name of the contract, the contract address, the network name, the deployer address and the deployment date. The first file (contractsAddressDeployed.json) stores only the last contract for a given contract name and network name, while the second file (contractsAddressDeployedHistory.json) keeps a log of all the contracts deployed.
You can then retrieve your contract address in your tests scripts to run test on deployed contracts on live chains for example.
Import:
javascript
const { addressBook, network } = require('hardhat')
typescript
import { addressBook, network } from 'hardhat'
Usage:
addressBook.saveContract(
contractName: string,
contractAddress: string,
deployedNetwork: string,
deployedBy: string,
chainId: number = 0,
blockHash?: string,
blockNumber?: number,
tag?: string,
extra?: any
)
addressBook.retrieveContract(contractName: string, deployedNetwork: string)
Example:
await addressBook.saveContract(
'MockERC20',
mockERC20.address,
network.name,
deployer.address,
network.config.chainId,
mockERC20.deployTransaction.blockHash,
mockERC20.deployTransaction.blockNumber,
'Test-MockERC20'
)
await addressBook.retrieveContract('MockERC20', network.name)
Return:
address: string
Retrieve a deployed contract object
Usage:
addressBook.retrieveContractObject(contractName: string, deployedNetwork: string)
Example:
await addressBook.retrieveContractObject('MockERC20', network.name)
Return:
{
name: string
address: string
network: string
deployer: string
deploymentDate: Date
chainId: number
blockHah?: string
blockNumber?: number
tag?: string
extra?: any
}
Retrieve Admin Proxy contract address deployed by @openzeppelin/hardhat-upgrades library
Usage:
addressBook.retrieveOZAdminProxyContract(chainId: number)
Example:
await addressBook.retrieveOZAdminProxyContract(network.config.chainId)
Return:
address: string
Retrieve all contracts deployed for a network name
Usage:
addressBook.retrieveContractHistory(deployedNetwork: string)
Example:
await addressBook.retrieveContractHistory(network.name)
Return:
[
{
name: string
address: string
network: string
deployer: string
deploymentDate: Date
chainId: number
blockHah?: string
blockNumber?: number
tag?: string
extra?: any
}
]
Clean the contractsAddressDeployed files by filtering a field and a value and remove these entry from the file, can be apply to both files or just the primary
Usage:
addressBook.cleanContractDeployed(field: TAddressBookFields, value: any, applyToPrimary: boolean = true, applyToHistory: boolean = true)
Example:
await addressBook.cleanContractDeployed('network', 'hardhat', true, true)
## 💪 Done
- Run test on all or single test file (from all your file in test/) - Run scripts on all or single scripts file (from all your file in scripts/) - Run Forge test on all or single test contracts if forge setting is detected - Inject chain activated in settings, rpc and accounts in hardhat.config - Inject custom chain in hardhat networks - Setup chains, RPC and accounts: - Acti...v0.03
Merge pull request #20 from marc-aurele-besner/dev Add flatten option💪