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

Commit afbb022

Browse files
Merge pull request #16 from marc-aurele-besner/dev
Add new features 💪
2 parents 97aa72d + 05d6284 commit afbb022

File tree

9 files changed

+162
-12
lines changed

9 files changed

+162
-12
lines changed

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ npm link hardhat-awesome-cli
5656
- More settings
5757
- Exclude test file from the tests selection list
5858
- Exclude script file from the scripts selection list
59-
- Create Mock contracts
59+
- Install/Uninstall other Hardhat plugins (Still not very stable)
60+
- Create Mock contracts + (Deployment scripts and tests scripts (currently only for MockERC20))
6061
- MockERC20
6162
- MockERC721
6263
- MockERC1155
@@ -113,7 +114,7 @@ await addressBook.retrieveContract('MockERC20', 'ethereum')
113114
- More settings
114115
- Exclude files from, tests and scripts selection (useful for config and share helper file)
115116
- Add other hardhat plugins
116-
- Create Mock contracts (ERC20, ERC721, ERC1155 + Upgradeable version)
117+
- Create Mock contracts (ERC20, ERC721, ERC1155 + Upgradeable version) + (Deployment scripts and tests scripts (currently only for MockERC20))
117118
- Add @openzeppelin/contracts || @openzeppelin/contracts-upgradeable if not already installed
118119
- Tool to log all contracts deploy on each chain (1 unique contractName/chain + full log) and retrieve them (not tested yet)
119120
- hre.addressBook.{ saveContract, retrieveContract }
@@ -122,12 +123,10 @@ await addressBook.retrieveContract('MockERC20', 'ethereum')
122123
## 🏗️ To do:
123124
- Start working on documentation
124125
- Inject chain settings, rpc and accounts in hardhat.config
125-
- Offer to generate deployment script and test script for Mock contract created
126+
- Create deployment and test scripts for all Mock contracts
126127
- Deployment contract generator
127128
- Make 'Run coverage tests' available only if task is exported by hardhat
128-
- Run coverage test (if solidity-coverage is installed)
129129
- Setup chains, RPC and accounts:
130-
- Disabling chains seams to be broken
131130
- See list of .env config and chains setup in a table
132131
- More Settings:
133132
- Create github workflows file to run test and coverage test

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
{
22
"name": "hardhat-awesome-cli",
3-
"version": "1.0.6",
3+
"version": "1.0.7",
44
"description": "Hardhat made awesome with a flexible CLI to help run test, deploy and more.",
5-
"repository": "https://github.com/marc-aurele-besner/hardhat-easy-cli.git",
5+
"repository": "https://github.com/marc-aurele-besner/hardhat-awesome-cli.git",
66
"author": "Marc-Aurele Besner <82244926+marc-aurele-besner@users.noreply.github.com>",
77
"license": "MIT",
88
"main": "dist/index.js",
99
"bin": {
10-
"hardhat-easy-cli": "./src/index-cli.ts"
10+
"hardhat-awesome-cli": "./src/index-cli.ts"
1111
},
1212
"bugs": {
13-
"url": "https://github.com/marc-aurele-besner/hardhat-easy-cli/issues"
13+
"url": "https://github.com/marc-aurele-besner/hardhat-awesome-cli/issues"
1414
},
1515
"types": "dist/src/index.d.ts",
1616
"keywords": [

src/index.ts

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,51 @@ const buildMockContract = async (contractName: string) => {
314314
}
315315
}
316316

317+
const buildMockDeploymentScriptOrTest = async (contractName: string, type: string) => {
318+
if (require && require.main) {
319+
const packageRootPath = path.join(path.dirname(require.main.filename), '../../../hardhat-awesome-cli/src/mockContracts')
320+
if (fs.existsSync(packageRootPath)) {
321+
if (fs.existsSync('contracts')) {
322+
if (MockContractsList) {
323+
let deploymentScriptOrTestPath: string = ''
324+
const contractToMock: IMockContractsList[] = MockContractsList.filter((contract) => contract.name === contractName)
325+
if (contractToMock && type === 'deployment') {
326+
if (fs.existsSync('hardhat.config.js')) {
327+
if (contractToMock[0].deploymentScriptJs !== undefined) deploymentScriptOrTestPath = contractToMock[0].deploymentScriptJs
328+
} else if (fs.existsSync('hardhat.config.ts')) {
329+
if (contractToMock[0].deploymentScriptTs !== undefined) deploymentScriptOrTestPath = contractToMock[0].deploymentScriptTs
330+
else if (contractToMock[0].deploymentScriptJs !== undefined) deploymentScriptOrTestPath = contractToMock[0].deploymentScriptJs
331+
}
332+
}
333+
if (contractToMock && type === 'test') {
334+
if (fs.existsSync('hardhat.config.js')) {
335+
if (contractToMock[0].testScriptJs !== undefined) deploymentScriptOrTestPath = contractToMock[0].testScriptJs
336+
} else if (fs.existsSync('hardhat.config.ts')) {
337+
if (contractToMock[0].testScriptTs !== undefined) deploymentScriptOrTestPath = contractToMock[0].testScriptTs
338+
else if (contractToMock[0].testScriptJs !== undefined) deploymentScriptOrTestPath = contractToMock[0].testScriptJs
339+
}
340+
}
341+
if (contractToMock && deploymentScriptOrTestPath) {
342+
if (fs.existsSync(deploymentScriptOrTestPath)) {
343+
console.log('\x1b[33m%s\x1b[0m', 'The ' + type + ' scripts already exists')
344+
} else {
345+
if (fs.existsSync(deploymentScriptOrTestPath)) {
346+
console.log('\x1b[33m%s\x1b[0m', "Can't locate the " + type + ' script')
347+
} else {
348+
console.log('\x1b[32m%s\x1b[0m', 'Creating ' + type + ' for ', contractName, ' in scripts/')
349+
const rawdata: any = fs.readFileSync(packageRootPath + '/' + deploymentScriptOrTestPath)
350+
const scriptsTestRawdataModify = rawdata.toString().slice(2).replace(/\*\//g, '').trim()
351+
await sleep(500)
352+
fs.writeFileSync(deploymentScriptOrTestPath, `${scriptsTestRawdataModify}`)
353+
}
354+
}
355+
}
356+
}
357+
} else console.log('\x1b[33m%s\x1b[0m', 'Error creating ' + type + ' script')
358+
}
359+
}
360+
}
361+
317362
const buildExcludedFile = async () => {
318363
let fileSetting: any = []
319364
if (fs.existsSync(fileHardhatAwesomeCLI)) {
@@ -1147,7 +1192,7 @@ const servePackageUninstaller = async () => {
11471192
}
11481193
})
11491194
})
1150-
await sleep(1000)
1195+
await sleep(1000)
11511196
}
11521197

11531198
const serveMockContractCreatorSelector = async () => {
@@ -1162,10 +1207,28 @@ const serveMockContractCreatorSelector = async () => {
11621207
name: 'mockContract',
11631208
message: 'Select a mock contract',
11641209
choices: mockContractsList
1210+
},
1211+
{
1212+
type: 'list',
1213+
name: 'mockDeploymentScript',
1214+
message: 'Create a deployment script for this mock contract',
1215+
choices: ['yes', 'no']
1216+
},
1217+
{
1218+
type: 'list',
1219+
name: 'mockTestScript',
1220+
message: 'Create a test script for this mock contract',
1221+
choices: ['yes', 'no']
11651222
}
11661223
])
1167-
.then(async (mockContractSelected: { mockContract: string }) => {
1224+
.then(async (mockContractSelected: { mockContract: string; mockDeploymentScript: string; mockTestScript: string }) => {
11681225
await buildMockContract(mockContractSelected.mockContract)
1226+
if (mockContractSelected.mockDeploymentScript === 'yes') {
1227+
await buildMockDeploymentScriptOrTest(mockContractSelected.mockContract, 'deployment')
1228+
}
1229+
if (mockContractSelected.mockTestScript === 'yes') {
1230+
await buildMockDeploymentScriptOrTest(mockContractSelected.mockContract, 'test')
1231+
}
11691232
})
11701233
}
11711234
}

src/mockContracts/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ const MockContractsList: IMockContractsList[] = [
44
{
55
name: 'MockERC20',
66
desc: 'Basic ERC20 Token contract',
7-
dependencies: ['@openzeppelin/contracts']
7+
dependencies: ['@openzeppelin/contracts'],
8+
deploymentScriptJs: 'scripts/deploy-mock-erc20.js',
9+
deploymentScriptTs: 'scripts/deploy-mock-erc20.ts',
10+
testScriptJs: 'test/test-mock-erc20.js',
11+
testScriptTs: 'test/test-mock-erc20.ts'
812
},
913
{
1014
name: 'MockERC721',
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
const hre = require('hardhat')
3+
4+
async function main() {
5+
const MockERC20 = await hre.ethers.getContractFactory('MockERC20')
6+
const mockERC20 = await MockERC20.deploy()
7+
8+
await mockERC20.deployed()
9+
10+
console.log('MockERC20 deployed to:', mockERC20.address)
11+
}
12+
13+
main()
14+
.then(() => process.exit(0))
15+
.catch((error) => {
16+
console.error(error)
17+
process.exit(1)
18+
})
19+
*/
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
import { ethers } from 'hardhat'
3+
4+
async function main() {
5+
const MockERC20 = await ethers.getContractFactory('MockERC20')
6+
const mockERC20 = await MockERC20.deploy()
7+
8+
await mockERC20.deployed()
9+
10+
console.log('MockERC20 deployed to:', mockERC20.address)
11+
}
12+
13+
main().catch((error) => {
14+
console.error(error)
15+
process.exitCode = 1
16+
})
17+
*/
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
const { expect } = require("chai");
3+
const { ethers } = require("hardhat");
4+
5+
describe("MockERC20", function () {
6+
it("Should return the name of the token", async function () {
7+
const MockERC20 = await ethers.getContractFactory("MockERC20");
8+
const mockERC20 = await MockERC20.deploy();
9+
await mockERC20.deployed();
10+
11+
expect(await mockERC20.name()).to.equal("MockERC20");
12+
});
13+
14+
it("Should return the symbol of the token", async function () {
15+
const MockERC20 = await ethers.getContractFactory("MockERC20");
16+
const mockERC20 = await MockERC20.deploy();
17+
await mockERC20.deployed();
18+
19+
expect(await mockERC20.symbol()).to.equal("MOCK");
20+
});
21+
});
22+
*/
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
import { expect } from "chai";
3+
import { ethers } from "hardhat";
4+
5+
describe("MockERC20", function () {
6+
it("Should return the name of the token", async function () {
7+
const MockERC20 = await ethers.getContractFactory("MockERC20");
8+
const mockERC20 = await MockERC20.deploy();
9+
await mockERC20.deployed();
10+
11+
expect(await mockERC20.name()).to.equal("MockERC20");
12+
});
13+
14+
it("Should return the symbol of the token", async function () {
15+
const MockERC20 = await ethers.getContractFactory("MockERC20");
16+
const mockERC20 = await MockERC20.deploy();
17+
await mockERC20.deployed();
18+
19+
expect(await mockERC20.symbol()).to.equal("MOCK");
20+
});
21+
});
22+
*/

src/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ export interface IMockContractsList {
2121
name: string
2222
desc: string
2323
dependencies: string[]
24+
deploymentScriptJs?: string
25+
deploymentScriptTs?: string
26+
testScriptJs?: string
27+
testScriptTs?: string
2428
upgradeable?: boolean
2529
}
2630

0 commit comments

Comments
 (0)