- 使用插件
hardhat-gas-reporter
,参考 - 安装
yarn add hardhat-gas-reporter --dev
- 在
hardhat.config.js
配置
require("hardhat-gas-reporter")
module.exports = {
...
gasReporter: {
enabled: true
}
};
- 执行
yarn hardhat test
,默认会执行获取gas报表的数据
> yarn hardhat test
yarn run v1.22.19
..\node_modules\.bin\hardhat test
SimpleStorage
✔ Should start with a favorite number of 0
✔ Should update when we call store
·----------------------------|----------------------------|-------------|-----------------------------·
| Solc version: 0.8.19 · Optimizer enabled: false · Runs: 200 · Block limit: 30000000 gas │
·····························|····························|·············|······························
| Methods │
··················|··········|··············|·············|·············|···············|··············
| Contract · Method · Min · Max · Avg ·
··················|··········|··············|·············|·············|···············|··············
| SimpleStorage · store · - · - · 43724 · 2 · - │
··················|··········|··············|·············|·············|···············|··············
| Deployments · · % of limit · │
·····························|··············|·············|·············|···············|··············
| SimpleStorage · - · - · 562691 · 1.9 % · - │
·----------------------------|--------------|-------------|-------------|---------------|-------------·
2 passing (1s)
Done in 2.85s.
- 插件
solidity-coverage
使用,检测还有哪些行没有参与测试的,参考