【问题标题】:How do I use different config for testing vs. deployment hardhat solidity?如何使用不同的配置进行测试与部署安全帽可靠性?
【发布时间】:2021-10-18 17:39:42
【问题描述】:

现在,当使用安全帽时,我有一个不同的配置用于测试和部署。目前我正在根据我是在测试还是部署来更改文件名。这似乎不是最佳/正确的。

有人知道我可以指定使用哪个方法吗?或者更好的是,一种在配置测试与部署中指定的方法?

测试配置:

require("@nomiclabs/hardhat-waffle");
/**
 * @type import('hardhat/config').HardhatUserConfig
 */
module.exports = {
  solidity: "0.8.0",
};

部署配置:

 * @type import('hardhat/config').HardhatUserConfig
 */
require('dotenv').config();
require("@nomiclabs/hardhat-waffle")
const {API_URL, METAMASK_PRIVATE_KEY} = process.env;
module.exports = {
  solidity: "0.8.0",
  defaultNetwork: "rinkeby",
  networks: {
    hardhat: {},
    rinkeby: {
      url: API_URL,
      accounts: [`0x${METAMASK_PRIVATE_KEY}`]
    }
  },
  paths: {
    sources: "./contracts",
    tests: "./test",
    cache: "./cache",
    artifacts: "./artifacts"
  },
};

我想我真的只是想在测试时忽略“网络”字段......

【问题讨论】:

    标签: testing deployment config solidity hardhat


    【解决方案1】:

    我意识到这些配置之间的唯一区别是网络标志,为了测试我想使用安全帽网络和部署,rinkeby。

    将默认网络参数更改为:

    defaultNetwork: "Hardhat"
    

    允许我使用 npx hardhat test 命令在安全帽网络上运行测试。

    然后部署我可以使用:

    npx hardhat run --network rinkeby scripts/deploy.js
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-23
      • 2022-06-16
      • 1970-01-01
      • 2022-01-24
      • 1970-01-01
      • 2022-10-09
      • 1970-01-01
      • 2021-10-01
      相关资源
      最近更新 更多