Lesson 9, Error: No Contract deployed with name VRFCoordinatorV2Mock #1237
-
My contract deployed perfectly but when running test i got this error, Raffle Unit Tests
constructor
1) "before each" hook for "Initializes the raffle correctly"
0 passing (2s)
0 passing (2s)
1 failing
1) Raffle Unit Tests
"before each" hook for "Initializes the raffle correctly":
ERROR processing C:\Users\PC\Desktop\DEVELOPEMENT\hardhat-smartcontract-lottery-fcc\deploy\01-deploy-raffle.js:
Error: No Contract deployed with name VRFCoordinatorV2Mock Raffle.test.js const { assert } = require("chai")
const { getNamedAccounts, deployments, ethers } = require("hardhat")
const { developmentChains, networkConfig } = require("../../helper-hardhat-config")
!developmentChains.includes(network.name)
? describe.skip
: describe("Raffle Unit Tests", async function (){
let raffle, vrfCoordinatorV2Mock
const chainId = network.config.chainId
beforeEach(async function () {
const { deployer } = await getNamedAccounts()
await deployments.fixture(["all"])
raffle = await ethers.getContract("Raffle", deployer)
vrfCoordinatorV2Mock = await ethers.getContract("VRFCoordinatorV2Mock", deployer)
})
describe("constructor", async function () {
it("Initializes the raffle correctly", async function (){
const raffleState = await raffle.getRaffleState()
const interval = await raffle.getInterval()
assert.equal(raffleState.toString(), "0")
assert.equal(interval.toString(), networkConfig[chainId])["interval"]
})
})
}) deploy-raffle.js const { network, ethers } = require("hardhat")
const { developmentChains, networkConfig } = require("../helper-hardhat-config")
const { verify } = require("../helper-hardhat-config")
const VRF_FUND_AMOUNT = ethers.utils.parseEther("30")
module.exports = async function ({getNamedAccounts, deployments}){
const { deploy, log } = deployments
const {deployer} = await getNamedAccounts()
const chainId = network.config.chainId
//chainId of vrfco-ordinator
let vrfCoordinatorV2Address
if(developmentChains.includes(network.name)) {
const vrfCoordinatorV2Mock = await ethers.getContract("VRFCoordinatorV2Mock")
vrfCoordinatorV2Address = vrfCoordinatorV2Mock.address
const transactionResponse = await vrfCoordinatorV2Mock.createSubscription()
const transactionReceipt = await transactionResponse.wait(1)
subscriptionId = transactionReceipt.events[0].args.subId
//Fund the sunscription
await vrfCoordinatorV2Mock.fundSubscription(subscriptionId, VRF_FUND_AMOUNT)
//if we are not on a local network
//vrfCoordinator will be derived from networkconfig
//in helper-hardhat-config
//import the networkConfig
} else {
vrfCoordinatorV2Address = networkConfig[chainId]["vrfCoordinatorV2"]
subscriptionId = networkConfig[chainId]["subscription"]
}
const entranceFee = networkConfig[chainId]["entranceFee"]
const gasLane = networkConfig[chainId]["gasLane"]
const callbackGasLimit = networkConfig[chainId]["callbackGasLimit"]
const interval = networkConfig[chainId]["interval"]
const args = [vrfCoordinatorV2Address,
entranceFee,
gasLane,
subscriptionId,
callbackGasLimit,
interval,
]
const raffle = await deploy("Raffle", {
from: deployer,
args: args ,
log: true,
waitConfirmations: network.config.blockConfirmations || 1,
//from args[], pass contructor contracts into it
//create a Helpers config()
})
if (!developmentChains.includes(network.name) && process.env.ETHERSCAN_API_KEY){
log("Verifying......")
await verify(raffle.address, args)
}
log("...........................")
}
module.exports.tags = ["all", "raffle"] |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 34 replies
-
upload your |
Beta Was this translation helpful? Give feedback.
-
Copy this in your unit test file: beforeEach(async () => {
accounts = await ethers.getSigners() // could also do with getNamedAccounts
// deployer = accounts[0]
player = accounts[1]
await deployments.fixture(["mocks", "raffle"]) // Deploys modules with the tags "mocks" and "raffle"
vrfCoordinatorV2Mock = await ethers.getContract("VRFCoordinatorV2Mock") // Returns a new connection to the VRFCoordinatorV2Mock contract
raffleContract = await ethers.getContract("Raffle") // Returns a new connection to the Raffle contract
raffle = raffleContract.connect(player) // Returns a new instance of the Raffle contract connected to player
// If below getter functions are required, uncomment them:
// Uncomment this if needed: raffleEntranceFee = await raffle.getEntranceFee()
// Uncomment this if needed: interval = await raffle.getInterval()
}) Let me know if this fixes your problem |
Beta Was this translation helpful? Give feedback.
-
@Maakai123 Push to GitHub and leave the link here. |
Beta Was this translation helpful? Give feedback.
-
Hello, i've got the same error Error: No Contract deployed with name VRFCoordinatorV2Mock |
Beta Was this translation helpful? Give feedback.
-
https://github.com/ayoubray/hardhat-smartcontract-lottery-fcc
Le ven. 3 févr. 2023 à 10:29, Basudev Bharat Bhushan <
***@***.***> a écrit :
… @alymurtazamemon <https://github.com/alymurtazamemon>
https://github.com/Maakai123/smartcontract-Raffle
Hey man, could you make your repo public so that we can go through the
modification in code.
—
Reply to this email directly, view it on GitHub
<#1237 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AZ4ULXLT2GL2WYFASX2N3BLWVSXVNANCNFSM54NQ5XQQ>
.
You are receiving this because you commented.Message ID:
<smartcontractkit/full-blockchain-solidity-course-js/repo-discussions/1237/comments/4859175
@github.com>
|
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
@Maakai123 Push to GitHub and leave the link here.