Skip to content

Tooling Performance Upgrades #250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,38 @@ brew install https://raw.githubusercontent.com/ethereum/homebrew-ethereum/06d13a

### Generate TypeChain Typings

`yarn build`
To generate a complete set of types (including for resources in the `external` folder) run:

`yarn typechain`

By default `yarn compile` will incrementally generate types for any recently changed types in the
`contracts` folder


### Run Contract Tests

`yarn test` to run compiled contracts
There are several test commands to support different use cases. It's fastest to specify
the test file you're interested in and skip typescript typechecking using one of the "fast" commands.
(Typechecking is already done continuously by your code editor.)


Invoke the command using `yarn`.

**Example**

```sh
# The fastest way to run a test

$ yarn test:fast test/protocol/modules/v2/perpLeverageModuleV2.spec.ts
```

OR `yarn test:clean` if contracts have been typings need to be updated
| Command | Compiles | Typechecks | Notes |
| ---- | ---- | ---- | ---- |
| `test` | :white_check_mark: | :white_check_mark: | Slowest - used in CI to perform all validations |
| `test:fast` | :x:`| :x: | Fastest |
| `test:fast:compile` | :white_check_mark: | :white_check_mark: | Fast with solidity compilation |
| `test:fork` | :white_check_mark: | :white_check_mark: |Runs any tests with the tag `@forked-mainnet` in its mocha test description |
| `test:fork:fast` | :x: | :x: | Runs `test:fork` without typechecking |

### Run Coverage Report for Tests

Expand Down
22 changes: 17 additions & 5 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@ const mochaConfig = {
timeout: (process.env.FORK) ? 100000 : 40000,
} as Mocha.MochaOptions;

// Compiles new types for contracts & external.
// NOTE: when adding files to the `external` folder, you must run `yarn typechain` to
// generate the necessary types artifacts. By default we only generate types for regular
// `artifacts` to take advantage of typechain's incremental generation feature.
const fullTypechainConfig = {
outDir: "typechain",
target: "ethers-v5",
externalArtifacts: ["external/**/*.json"],
}

// Only re-compiles types for recently changed contracts
const defaultTypechainConfig = {
outDir: "typechain",
target: "ethers-v5",
}

checkForkedProviderEnvironment();

const config: HardhatUserConfig = {
Expand Down Expand Up @@ -66,11 +82,7 @@ const config: HardhatUserConfig = {
},
},
// @ts-ignore
typechain: {
outDir: "typechain",
target: "ethers-v5",
externalArtifacts: ["external/**/*.json"],
},
typechain: (process.env.BUILD) ? fullTypechainConfig : defaultTypechainConfig,
// @ts-ignore
contractSizer: {
runOnCompile: false,
Expand Down
28 changes: 14 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,18 @@
"tsconfig.json"
],
"scripts": {
"build": "yarn clean && yarn compile && yarn build:ts:latest",
"build": "yarn clean && yarn compile:all && yarn build:ts:latest",
"build:npm:latest": "yarn clean && yarn compile:latest && yarn build:ts:latest",
"build:npm:hardhat": "yarn clean && yarn compile && yarn build:ts:hardhat",
"build:ts:latest": "yarn typechain && yarn transpile:dist:latest",
"build:ts:hardhat": "yarn typechain && yarn transpile:dist:hardhat",
"chain": "npx hardhat node",
"build:npm:hardhat": "yarn clean && yarn compile:all && yarn build:ts:hardhat",
"build:ts:latest": "yarn transpile:dist:latest",
"build:ts:hardhat": "yarn transpile:dist:hardhat",
"chain": "TS_NODE_TRANSPILE_ONLY=1 npx hardhat node",
"clean": "./scripts/clean.sh",
"compile": "npx hardhat compile",
"compile:latest": "SKIP_ABI_GAS_MODS=true npx hardhat compile",
"compile:all": "BUILD=true TS_NODE_TRANSPILE_ONLY=1 npx hardhat compile",
"compile": "TS_NODE_TRANSPILE_ONLY=1 npx hardhat compile",
"compile:latest": "SKIP_ABI_GAS_MODS=true BUILD=true TS_NODE_TRANSPILE_ONLY=1 npx hardhat compile",
"coverage": "yarn clean && yarn build && yarn cov:command",
"cov:command": "COVERAGE=true node --max-old-space-size=4096 ./node_modules/.bin/hardhat coverage",
"etherscan:verify": "hardhat --network kovan etherscan-verify --solc-input --license 'None'",
"flatten": "npx waffle flatten",
"cov:command": "COVERAGE=true BUILD=true node --max-old-space-size=4096 ./node_modules/.bin/hardhat coverage",
"lint": "yarn run lint-sol && yarn run lint-ts",
"lint-sol": "solhint 'contracts/**/*.sol'",
"lint-ts": "eslint -c .eslintrc.js --ext .ts test utils tasks --fix",
Expand All @@ -46,7 +45,7 @@
"transpile": "tsc",
"transpile:dist:latest": "tsc --project tsconfig.dist.json",
"transpile:dist:hardhat": "tsc --project tsconfig.hardhat.json",
"typechain": "npx hardhat typechain",
"typechain": "TS_NODE_TRANSPILE_ONLY=1 BUILD=true npx hardhat typechain",
"semantic-release": "semantic-release"
},
"repository": {
Expand All @@ -68,6 +67,7 @@
"@nomiclabs/hardhat-waffle": "^2.0.1",
"@openzeppelin/contracts": "^3.1.0",
"@semantic-release/git": "^10.0.1",
"@swc/core": "^1.2.171",
"@typechain/ethers-v5": "8.0.5",
"@typechain/hardhat": "3.1.0",
"@types/chai": "^4.2.11",
Expand All @@ -86,7 +86,7 @@
"eslint-plugin-jsdoc": "^38.0.6",
"eslint-plugin-no-null": "^1.0.2",
"ethereum-waffle": "^3.4.0",
"hardhat": "^2.6.4",
"hardhat": "^2.9.3",
"hardhat-contract-sizer": "^2.5.0",
"husky": "^4.2.5",
"istanbul-combine-updated": "^0.3.0",
Expand All @@ -95,9 +95,9 @@
"semantic-release": "^19.0.2",
"solc": "^0.6.10",
"solhint": "^3.1.0",
"solidity-coverage": "^0.7.17",
"solidity-coverage": "^0.7.21",
"ts-generator": "^0.1.1",
"ts-node": "^8.10.2",
"ts-node": "^10.7.0",
"tslint": "^6.1.3",
"tslint-eslint-rules": "^5.3.1",
"typechain": "6.1.0",
Expand Down
5 changes: 4 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,8 @@
],
"files": [
"hardhat.config.ts",
]
],
"ts-node": {
"swc": true
}
}
Loading