在控制台中使用
npx hardhat test
运行 Hardhat 测试后,我决定能够设置断点将帮助我更快地迭代。
如何让 Webstorm 运行由
npx hardhat test
启动的底层函数,以便我可以使用内置的调试器?
从那以后,我发现安全帽在引擎盖下运行摩卡咖啡。
要在 WebStorm 中调试,您可以:
--timeout 10000
因为mocha的默认超时只是2000ms
const {ethers} = require('hardhat');
添加到您的测试文件中,因为它在运行时不再被 hardhat 注入。此时我可以在我的测试文件中成功设置断点,但不能在 MyContract.sol 文件中设置。这并不奇怪,因为合约是在运行之前编译的。
package.json
文件。test
NPM 运行脚本并保存文件。你的 package.json 应该看起来像这样。{
"name": "hardhat-project",
"scripts": {
"test": "hardhat test"
},
"devDependencies": {
"@nomiclabs/hardhat-ethers": "2.0.2",
"@nomiclabs/hardhat-waffle": "2.0.1",
"chai": "4.3.4",
"ethereum-waffle": "3.4.0",
"ethers": "5.4.4",
"hardhat": "2.6.0"
}
}
Debug "test"
。我在这里更详细地阅读了说明,但这是一般的想法。 https://allendefibank.medium.com/how-to-debug-solidity-contracts-in-webstorm-hardhat-2ea0d3c4d582
如果你使用打字稿,你需要导入 ts-mocha 而不是 mocha
webstorm 是否显示像 uint a = "a" 这样的错误?我已经安装了 solidity,hardhat 插件,但什么也没有。