0

Right now, when using hardhat, I have a different config for testing and deployment. Currently I am changing the file name depending on whether I am testing or deploying. This does not seem optimal/correct.

Does anyone know a way I can specify which to use? Or even better, a way to specify in the config testing vs deployment?

Testing config:

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

Deployment config:

 * @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"
  },
};

I guess really I just want to ignore the "networks" field when testing...

1 Answer 1

2

I realized the only difference between these configs was the network flag, for testing I wanted to use the hardhat network, and deployment, rinkeby.

Changing the default network param to:

defaultNetwork: "Hardhat"

allowed me to run tests on the hardhat network using the npx hardhat test command.

Then deploying I can use:

npx hardhat run --network rinkeby scripts/deploy.js
Sign up to request clarification or add additional context in comments.

2 Comments

hi @Lucas is it work? because when I did this it gives me the same error while running npx hardhat test
Yes this works. What error are you getting?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.