Mock Ready

This commit is contained in:
2024-08-05 18:07:29 +08:00
parent 3ab5ee37c6
commit 39c2dd760b
12 changed files with 6904 additions and 1052 deletions
+37 -13
View File
@@ -1,6 +1,9 @@
// import
const { ethers, run, network } = require("hardhat");
const { networkConfig } = require("../helper-hardhat-config");
const {
networkConfig,
developmentChains,
} = require("../helper-hardhat-config");
/* Above same as:
const helperConfig = require("../helper-hardhat-config");
const networkConfig = helperConfig.networkConfig;
@@ -20,23 +23,44 @@ module.exports = async ({ getNamedAccounts, deployments }) => {
const { deploy, log } = deployments;
const { deployer } = await getNamedAccounts(); // Take from hardhat.config.js namedAccounts
const chainId = network.config.chainId;
let ethUsdPriceFeedAddress;
if (networkConfig[chainId] === undefined) {
console.log("Is Not Testnet / Mainnet! No Mock Up...");
console.log(deployments);
const ethUsdAggregator = await deployments.get("MockV3Aggregator");
return;
/*
31337 - Local Hardhat Network
5777 - Local Ganache Network
11155111 - Sepolia Testnet
When going for localhost / hardhat network we want to use a mock
*/
switch (chainId) {
case 31337:
ethUsdAggregator = await deployments.get("MockV3Aggregator");
ethUsdPriceFeedAddress = ethUsdAggregator.address;
break;
case 5777:
ethUsdAggregator = await deployments.get("MockV3Aggregator");
ethUsdPriceFeedAddress = ethUsdAggregator.address;
break;
default:
ethUsdPriceFeedAddress = networkConfig[chainId]["ethUsdPriceFeed"];
}
const ethUsdPriceFeedAddress = networkConfig[chainId]["ethUsdPriceFeed"];
// if contract doest't exist, we deploy a minimal version for our local testing
// When going for localhost / hardhat network we want to use a mock
// Auto Change Chains To Get different Gas
log("----------------------------------------------------");
log("Deploying FundMe Contract and waiting for confirmations...");
const fundMe = await deploy("FundMe", {
from: deployer,
args: [ethUsdPriceFeedAddress], // put price feed address
args: [ethUsdPriceFeedAddress],
log: true,
// we need to wait if on a live network so we can verify properly
waitConfirmations: network.config.blockConfirmations || 1,
});
log(`FundMe deployed at ${fundMe.address}`);
if (
!developmentChains.includes(network.name) &&
process.env.ETHERSCAN_API_KEY
) {
await verify(fundMe.address, [ethUsdPriceFeedAddress]);
}
};
module.exports.tags = ["all", "fundme"];