PatrickAlphaC / hardhat-fund-me-fcc

82 stars 183 forks source link

Failed to hardhat-deploy mocks with tags #108

Closed michaelclubman515 closed 1 year ago

michaelclubman515 commented 1 year ago

At the section hardhat fundme / Mocking / tags in hardhat I typed yarn hardhat deploy --tags mocks the terminal give me message like under , no message about the deploying mocks, I think maybe something wrong with config

yarn run v1.22.19 warning ../package.json: No license field $ /Users/liwei/hardhat-fund-me/node_modules/.bin/hardhat deploy --tags mocks Nothing to compile ✨ Done in 1.69s.

hadhat-config.js `require("@nomicfoundation/hardhat-toolbox") require("hardhat-deploy") require("dotenv").config() const GOERLI_RPC_URL = process.env.GOERLI_RPC_URL const PRIVATE_KEY = process.env.PRIVATE_KEY module.exports = { // solidity: "0.8.17", solidity: { compilers: [{ version: "0.8.8" }, { version: "0.6.6" }], }, defaultNetwork: "hardhat", networks: { hardhat: { chainId: 31337, // gasPrice: 130000000000, }, goerli: { url: GOERLI_RPC_URL, accounts: [PRIVATE_KEY], chainId: 5, blockConfirmations: 6, }, },

namedAccounts: {
    deployer: {
        default: 0, // 这样会默认把第一个账户作为部署合约的账户
        1: 0, //在主网上也会把第一个账户作为部署账户,不管conifg怎么配置,不同网络上的account 0 并不一样
    },
},

} `

helper-hardhat-config.js

`const networkConfig = { 31337: { name: "localhost", },

5: {
    name: "goerli",
    ethUsdPriceFeed: "0xD4a33860578De61DBAbDc8BFdb98FD742fA7028e",
},

} // 声明develomentChains

const developmentChains = ["localhost", "hardhat"] // export config可以让其他文件来交互 module.exports = { networkConfig, developmentChains, } `

00--deploy-mock.js

`const { network } = require("hardhat") const { developmentChains } = require("../helper-hardhat-config")

//声明chainId,MockV3Aggregator的构造函数参数

const DECIMALS = "8" const INITIAL_PRICE = "200000000"

module.exports = async ({ getNamedAccounts, deployments }) => { //console.log(chainId is ${chainId}) const { deploy, log } = deployments // The deployments field itself contains the deploy function.字段本身包含部署功能。 const { deployer } = await getNamedAccounts() // Fetch the accounts.获取账户 These can be configured in hardhat.config.ts as explained above. const chainId = network.config.chainId

/*
是否在本地或hardhat网络上,chainId.name pull from hardhat config,
developmentChains pull from helper-hardhat-config
includes关键字:看哪些变量是否在数组中
*/
if (developmentChains.includes(chainId.name)) {
    log("Local network detected! Deploying mocks ...")
    await deploy("MockV3Aggregator", {
        contract: "MockV3Aggregator",
        from: deployer,
        log: true,
        args: [DECIMALS, INITIAL_PRICE],
    })
    log("Mocks deployed!")
    log("----------------------------------------------")
}

} // 如何只部署deploy mock文件 module.exports.tags = ["all", "mocks"] `

michaelclubman515 commented 1 year ago

Also when I run "yarn hardhat deploy --tags mocks",It seems didn't deploy the mockV3Aggregator terminal 's information like this yarn run v1.22.19 warning ../package.json: No license field $ /Users/liwei/hardhat-fund-me/node_modules/.bin/hardhat deploy --tags mocks Nothing to compile ✨ Done in 2.34s.

possiblyapossum commented 1 year ago

Hey there. Having the same issues here. Hoping that someone can help.

viczhangge commented 1 year ago

When I use the command line like

 yarn  hardhat console

It works well.

but when I use the command line

yarn hardhat  deploy --tags mocks.

some question pops up like this.

  An unexpected error occurred:
  cannot get the transaction for MockV3Aggregator's previous deployment, please check your node synced status

Hoping someone can help

viczhangge commented 1 year ago

resolve this by delete the deployments's files, it works well

viczhangge commented 1 year ago

just the line

npx hardhat deploy --tags mocks.

or

yarn hardhat deploy --tags mocks
michaelclubman515 commented 1 year ago

Update

just fixed in script 00-deploy-mock.js

when identify the network should be "network.name" not "chainId.name",cause in config file describe by network.name

if (developmentChains.includes(network.name)) {

possiblyapossum commented 1 year ago

Managed to fix too. Seems like mine was caused by a simple typo.

Should be

module.exports.tags = ["all", "mocks"];

Instead of

module.exports.tag = ["all, mocks"];

Notice the "tags" vs "tag" and the quotations on all, mocks.