Skip to content
This repository was archived by the owner on Apr 11, 2024. It is now read-only.

Commit 46471d2

Browse files
multiple changes
- Add AdminProxy and TransparentUpgradeableProxy - Improve/fix all deployment and test scripts - Add addressBook.saveContract() to deployment scripts - Inject networks in hardhat network - Improve readme - Roll back version number to start < 1 - Improve mock contracts
1 parent 05d6284 commit 46471d2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+887
-89
lines changed

README.md

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[![license](https://img.shields.io/github/license/jamesisaac/react-native-background-task.svg)](https://opensource.org/licenses/MIT)
22

33
# 👷 hardhat-awesome-cli
4-
Hardhat made awesome with a flexible CLI to help run test, deploy and more.
4+
Hardhat made awesome with a flexible CLI to help run tests, deploy and more.
55

66
## How to install this package
77
### 1. Install this package
@@ -37,33 +37,35 @@ cd hardhat-awesome-cli
3737
npm link
3838
```
3939

40-
in the hardhat project you want to use this plugin
40+
in the hardhat project, you want to use this plugin
4141

4242
```
4343
npm link hardhat-awesome-cli
4444
```
4545
</details>
4646

4747
## CLI features
48-
- Run tests (Allow you yo run test on all files or specific files in test/)
49-
- Run scripts (Allow you yo run script on specific files in scripts/)
50-
- Select scripts and tests to run (Allow you to select a script to execure and all or one test to perform afterward)
48+
- Run tests (Allow you you to run tests on all files or specific files in test/)
49+
- Run scripts (Allow you you to run scripts on specific files in scripts/)
50+
- Select scripts and tests to run (Allow you to select a script to execute and all or one test to perform afterward)
5151
- Run coverage tests (Available only if solidity-coverage is installed and available as a task)
5252
- Setup chains, RPC and accounts
5353
- Add/Remove chains from the chain selection
5454
- Set RPC Url, private key or mnemonic for all or one chain
55-
- Add a custom chain to the current chain selection)
55+
- Add a custom chain to the current chain selection (currently these custom chains are not getting injected into hardhat networks)
5656
- More settings
57-
- Exclude test file from the tests selection list
58-
- Exclude script file from the scripts selection list
57+
- Exclude the test file from the tests selection list
58+
- Exclude the script file from the scripts selection list
5959
- Install/Uninstall other Hardhat plugins (Still not very stable)
60-
- Create Mock contracts + (Deployment scripts and tests scripts (currently only for MockERC20))
60+
- Create Mock contracts + (Deployment scripts and tests scripts (Missing test for MockProxyAdmin and MockTransparentUpgradeableProxy))
6161
- MockERC20
6262
- MockERC721
6363
- MockERC1155
6464
- MockERC20Upgradeable
6565
- MockERC721Upgradeable
6666
- MockERC1155Upgradeable
67+
- MockProxyAdmin
68+
- MockTransparentUpgradeableProxy
6769
- Get account balance
6870

6971
### Current chain support
@@ -75,18 +77,24 @@ npm link hardhat-awesome-cli
7577
- Polygon - Mainnet (chainId 137)
7678
- Polygon - Mumbai (chainId 80001)
7779

78-
In 'More settings' you can also add custom chain, or create a issue or pull request to add other chains.
80+
In 'More settings' you can also add a custom chain, create an issue or pull request to add other chains.
7981

8082
## Helper tools
8183
Tools that you can use in your scripts and tests to make your life easier
8284

8385
### Address Book
8486

87+
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.
88+
89+
You can then retrieve your contract address in your tests scripts to run test on deployed contracts on live chains for example.
90+
8591
Import:
86-
js```
92+
javascript
93+
```
8794
const { addressBook } = require('hardhat')
8895
```
89-
typescript```
96+
typescript
97+
```
9098
import { addressBook } from 'hardhat'
9199
```
92100

@@ -99,41 +107,49 @@ addressBook.retrieveContract(contractName: string, deployedNetwork: string)
99107

100108
Example:
101109
```
102-
await addressBook.saveContract('MockERC20', MockERC20.address, 'ethereum', deployer.address)
110+
await addressBook.saveContract('MockERC20', mockERC20.address, 'ethereum', deployer.address)
103111
104112
await addressBook.retrieveContract('MockERC20', 'ethereum')
105113
```
106114

107115
## 💪 Done
108116
- Run test on all or single test file (from all your file in test/)
109117
- Run scripts on all or single scripts file (from all your file in scripts/)
118+
- Inject chain activated in settings, rpc and accounts in hardhat.config
110119
- Setup chains, RPC and accounts:
111120
- Activate/Disable chain to show on test/scripts options
112121
- Build .env file with rpc url and private key (or mnemonic)
113122
- Add ".env.hardhat-awesome-cli" to .gitignore amd .npmignore (create .gitignore if do detected)
114123
- More settings
115124
- Exclude files from, tests and scripts selection (useful for config and share helper file)
116125
- Add other hardhat plugins
117-
- Create Mock contracts (ERC20, ERC721, ERC1155 + Upgradeable version) + (Deployment scripts and tests scripts (currently only for MockERC20))
126+
- Create Mock contracts (ERC20, ERC721, ERC1155 + Upgradeable version, AdminProxy and TransparentUpgradeableProxy)
118127
- Add @openzeppelin/contracts || @openzeppelin/contracts-upgradeable if not already installed
128+
- Offer to create deployment scripts (use addressBook.saveContract() to save the deployed contract in contractsAddressDeployed.json and contractsAddressDeployedHistory.json)
129+
- Offer to create test scripts
119130
- Tool to log all contracts deploy on each chain (1 unique contractName/chain + full log) and retrieve them (not tested yet)
120131
- hre.addressBook.{ saveContract, retrieveContract }
121132

122133

123134
## 🏗️ To do:
124135
- Start working on documentation
125-
- Inject chain settings, rpc and accounts in hardhat.config
126-
- Create deployment and test scripts for all Mock contracts
127136
- Deployment contract generator
128-
- Make 'Run coverage tests' available only if task is exported by hardhat
137+
- Make 'Run coverage tests' available only if the task is exported by hardhat
138+
- Inject custom chain in hardhat networks
129139
- Setup chains, RPC and accounts:
130-
- See list of .env config and chains setup in a table
140+
- See the list of .env config and chains setup in a table
131141
- More Settings:
132-
- Create github workflows file to run test and coverage test
142+
- Create Github workflows file to run test and coverage test
133143
- Setup slack API or email report to receive a copy of test result and contracts list deployed
134144
- Add/Remove other hardhat plugins (need to add/remove in hardhat.config)
135-
- Need to import plugin added in hardhat.config
136-
- Need to list plugin installed to mark them as "check" in the plugin list
137-
- Need to allow to remove plugin, uninstall package via npm/yarn and remove them in hardhat config
138-
- Create custom command
139-
- Add option to create Admin Proxy and Transparent proxy w/ appropriate deployment scripts
145+
- Need to import the plugin added in hardhat.config
146+
- Need to list plugins installed to mark them as "check" in the plugin list
147+
- Need to allow to remove a plugin, uninstall package via npm/yarn and remove them in hardhat config
148+
- Create a custom command
149+
- Improve all the tests, to test transfer, mint, burn (all basic ERC20, ERC721, ERC1155 functions)
150+
- Add test for AdminProxy and TransparentUpgradeableProxy
151+
- Offer to rename the Mock contract and set all constructor input (or initialize input) via cli
152+
- Verify that the input name does not conflict with inheritance
153+
- Rename the Mock file, contract name, deployment script, test scripts (and the test values)
154+
- Add a flatten options (All contracts, or specific contracts) save in contractsFlatten/
155+
- Write some test on the package using mocha

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hardhat-awesome-cli",
3-
"version": "1.0.7",
3+
"version": "0.0.2",
44
"description": "Hardhat made awesome with a flexible CLI to help run test, deploy and more.",
55
"repository": "https://github.com/marc-aurele-besner/hardhat-awesome-cli.git",
66
"author": "Marc-Aurele Besner <82244926+marc-aurele-besner@users.noreply.github.com>",

src/config.ts

Lines changed: 72 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,45 +5,110 @@ export const DefaultChainList: IChain[] = [
55
name: 'Hardhat local',
66
chainName: 'hardhat',
77
chainId: 31337,
8-
gas: 'auto'
8+
gas: 'auto',
9+
currency: 'ETH'
910
},
1011
{
1112
name: 'Ethereum - Mainnet',
1213
chainName: 'ethereum',
1314
chainId: 1,
14-
gas: 'auto'
15+
gas: 'auto',
16+
currency: 'ETH',
17+
defaultBlockExplorer: 'https://etherscan.io/'
1518
},
1619
{
1720
name: 'Ethereum - Ropstein',
1821
chainName: 'ropsten',
1922
chainId: 3,
20-
gas: 'auto'
23+
gas: 'auto',
24+
currency: 'ETH',
25+
defaultBlockExplorer: 'https://ropsten.etherscan.io/'
2126
},
2227
{
2328
name: 'Ethereum - Rinkeby',
2429
chainName: 'rinkeby',
2530
chainId: 4,
26-
gas: 'auto'
31+
gas: 'auto',
32+
currency: 'ETH',
33+
defaultBlockExplorer: 'https://rinkeby.etherscan.io/'
2734
},
2835
{
2936
name: 'Ethereum - Kovan',
3037
chainName: 'kovan',
3138
chainId: 42,
32-
gas: 'auto'
39+
gas: 'auto',
40+
currency: 'ETH',
41+
defaultBlockExplorer: 'https://kovan.etherscan.io/'
42+
},
43+
{
44+
name: 'Ethereum - Goerli',
45+
chainName: 'goerli',
46+
chainId: 5,
47+
gas: 'auto',
48+
currency: 'ETH',
49+
defaultBlockExplorer: 'https://goerli.etherscan.io/'
3350
},
3451
{
3552
name: 'Polygon - Mainnet',
3653
chainName: 'polygon',
3754
chainId: 137,
3855
gas: 'auto',
39-
defaultRpcUrl: 'https://polygon-rpc.com'
56+
currency: 'MATIC',
57+
defaultRpcUrl: 'https://polygon-rpc.com',
58+
defaultBlockExplorer: 'https://polygonscan.com/'
4059
},
4160
{
4261
name: 'Polygon - Mumbai',
4362
chainName: 'mumbai',
4463
chainId: 80001,
4564
gas: 'auto',
46-
defaultRpcUrl: 'https://rpc-mumbai.maticvigil.com'
65+
currency: 'MATIC',
66+
defaultRpcUrl: 'https://rpc-mumbai.maticvigil.com',
67+
defaultBlockExplorer: 'https://mumbai.polygonscan.com/'
68+
},
69+
{
70+
name: 'Binance Smart Chain - Mainnet',
71+
chainName: 'binance',
72+
chainId: 56,
73+
gas: 'auto',
74+
currency: 'BNB',
75+
defaultRpcUrl: 'https://bsc-dataseed.binance.org',
76+
defaultBlockExplorer: 'https://bscscan.com'
77+
},
78+
{
79+
name: 'Binance Smart Chain - Tesnet',
80+
chainName: 'binanceTestnet',
81+
chainId: 97,
82+
gas: 'auto',
83+
currency: 'BNB',
84+
defaultRpcUrl: 'https://rpc-mainnet.matic.network',
85+
defaultBlockExplorer: 'https://explorer.binance.org/smart-testnet'
86+
},
87+
{
88+
name: 'Optimism - Mainnet',
89+
chainName: 'optimism',
90+
chainId: 10,
91+
gas: 'auto',
92+
currency: 'ETH',
93+
defaultRpcUrl: 'https://mainnet.optimism.io',
94+
defaultBlockExplorer: 'https://optimistic.etherscan.io/'
95+
},
96+
{
97+
name: 'Optimism - Testnet Kovan',
98+
chainName: 'optimismTestnetKovan',
99+
chainId: 56,
100+
gas: 'auto',
101+
currency: 'ETH',
102+
defaultRpcUrl: 'https://bsc-dataseed1.binance.org'
103+
},
104+
{
105+
name: 'Avalanche - Mainnet',
106+
chainName: 'optimismTestnetKovan',
107+
chainId: 43114,
108+
gas: 'auto',
109+
currency: 'AVAX',
110+
defaultRpcUrl: 'https://api.avax.network/ext/bc/C/rpc',
111+
defaultBlockExplorer: 'https://snowtrace.io/'
47112
}
48113
]
49114

src/index.ts

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

33
import { spawn } from 'child_process'
44
import fs from 'fs'
5-
import { TASK_TEST_RUN_MOCHA_TESTS } from 'hardhat/builtin-tasks/task-names'
6-
import { extendConfig, extendEnvironment, subtask, task } from 'hardhat/config'
5+
import { extendConfig, extendEnvironment, task } from 'hardhat/config'
76
import { lazyObject } from 'hardhat/plugins'
8-
import { HardhatConfig, HardhatUserConfig, HttpNetworkConfig } from 'hardhat/types'
7+
import { HardhatConfig, HardhatUserConfig, NetworksUserConfig } from 'hardhat/types'
98
import inquirer from 'inquirer'
109
import path from 'path'
11-
import { exit, hrtime } from 'process'
10+
import { exit } from 'process'
1211

1312
import { AwesomeAddressBook } from './AwesomeAddressBook'
1413
import { DefaultChainList, DefaultHardhatPluginsList } from './config'
@@ -87,7 +86,7 @@ const buildFullChainList = async () => {
8786
return chainList
8887
}
8988

90-
const buildActivatedChainNetworkConfig = async () => {
89+
const buildActivatedChainNetworkConfig = () => {
9190
let chainConfig: string = ''
9291
let fileSetting: any = []
9392
if (fs.existsSync(fileHardhatAwesomeCLI)) {
@@ -96,10 +95,10 @@ const buildActivatedChainNetworkConfig = async () => {
9695
}
9796
if (fileSetting && fileSetting.activatedChain) {
9897
if (fileSetting.activatedChain.length > 0) {
99-
await fileSetting.activatedChain.forEach(async (chain: IChain) => {
100-
const defaultRpcUrl = await getEnvValue('rpcUrl'.toUpperCase() + '_' + chain.chainName.toUpperCase())
101-
const defaultPrivateKey = await getEnvValue('privateKey'.toUpperCase() + '_' + chain.chainName.toUpperCase())
102-
const defaultMnemonic = await getEnvValue('mnemonic'.toUpperCase() + '_' + chain.chainName.toUpperCase())
98+
fileSetting.activatedChain.forEach((chain: IChain) => {
99+
const defaultRpcUrl = getEnvValue('rpcUrl'.toUpperCase() + '_' + chain.chainName.toUpperCase())
100+
const defaultPrivateKey = getEnvValue('privateKey'.toUpperCase() + '_' + chain.chainName.toUpperCase())
101+
const defaultMnemonic = getEnvValue('mnemonic'.toUpperCase() + '_' + chain.chainName.toUpperCase())
103102
let buildAccounts = ''
104103
if (defaultPrivateKey) {
105104
buildAccounts = `"accounts": ["${defaultPrivateKey}"]`
@@ -171,7 +170,7 @@ const buildActivatedChainNetworkConfig = async () => {
171170
}
172171
return chainConfig
173172
})
174-
await sleep(100)
173+
// await sleep(100)
175174
const fihainConfig = `${chainConfig.slice(0, -1)}`
176175
return fihainConfig
177176
}
@@ -663,7 +662,7 @@ import '${packageName}'`
663662
}
664663
}
665664

666-
const getEnvValue = async (envName: string) => {
665+
const getEnvValue = (envName: string) => {
667666
if (fs.existsSync(fileEnvHardhatAwesomeCLI)) {
668667
const allEnv = require('dotenv').config({ path: fileEnvHardhatAwesomeCLI })
669668
const oldEnv = Object.entries(allEnv.parsed)
@@ -1342,6 +1341,30 @@ extendConfig(async (config: HardhatConfig, userConfig: HardhatUserConfig) => {
13421341
}
13431342
}
13441343
config.paths.cli = cli
1344+
1345+
const getNetworkConfig = buildActivatedChainNetworkConfig()
1346+
let buildNetworkConfig: any = {}
1347+
if (getNetworkConfig) {
1348+
buildNetworkConfig = `{
1349+
"networks": [
1350+
{${getNetworkConfig}}
1351+
]
1352+
}`
1353+
buildNetworkConfig = JSON.parse(buildNetworkConfig)
1354+
}
1355+
if (buildNetworkConfig.networks !== undefined) {
1356+
if (buildNetworkConfig.networks[0] !== undefined) {
1357+
if (buildNetworkConfig.networks[0].ethereum !== undefined) config.networks.ethereum = buildNetworkConfig.networks[0].ethereum
1358+
if (buildNetworkConfig.networks[0].ropsten !== undefined) config.networks.ropsten = buildNetworkConfig.networks[0].ropsten
1359+
if (buildNetworkConfig.networks[0].rinkeby !== undefined) config.networks.rinkeby = buildNetworkConfig.networks[0].rinkeby
1360+
if (buildNetworkConfig.networks[0].kovan !== undefined) config.networks.kovan = buildNetworkConfig.networks[0].kovan
1361+
if (buildNetworkConfig.networks[0].polygon !== undefined) config.networks.polygon = buildNetworkConfig.networks[0].polygon
1362+
if (buildNetworkConfig.networks[0].mumbai !== undefined) config.networks.mumbai = buildNetworkConfig.networks[0].mumbai
1363+
if (buildNetworkConfig.networks[0].optimism !== undefined) config.networks.optimism = buildNetworkConfig.networks[0].optimism
1364+
if (buildNetworkConfig.networks[0].optimismTestnetKovan !== undefined)
1365+
config.networks.optimismTestnetKovan = buildNetworkConfig.networks[0].optimismTestnetKovan
1366+
}
1367+
}
13451368
})
13461369

13471370
extendEnvironment(async (hre: any) => {

src/mockContracts/MockERC1155.sol

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT
2-
pragma solidity ^0.8.13;
2+
pragma solidity ^0.8.0;
33

44
/**
55
* @title MockERC1155
@@ -8,9 +8,20 @@ pragma solidity ^0.8.13;
88
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
99

1010
contract MockERC1155 is ERC1155 {
11+
12+
string internal _name = "MockERC1155";
13+
string internal _symbol = "MOCK";
1114
constructor () ERC1155("https://google.com") {
1215

1316
}
17+
18+
function name() public view returns (string memory) {
19+
return _name;
20+
}
21+
22+
function symbol() public view returns (string memory) {
23+
return _symbol;
24+
}
1425

1526
function mint(address _to, uint256 _tokenId, uint256 _amount) public {
1627
require(_to != address(0));
@@ -22,6 +33,4 @@ contract MockERC1155 is ERC1155 {
2233
function burn(uint256 _tokenId, uint256 _amount) public {
2334
_burn(_msgSender(), _tokenId, _amount);
2435
}
25-
26-
uint256[50] private __gap;
2736
}

0 commit comments

Comments
 (0)