Lesson 9: Error ... 'InvalidConsumer()' #1565
-
Just outputs 'InvalidConsumer()' even after several corrections . Is this possibly a file issue ? Error:
github repo => https://github.com/paulcoffee85/hh-fcc-harhat-smartcontract-lottery-fcc-TEST
const { getNamedAccounts, deployments, ethers, network } = require("hardhat")
const { developmentChains, networkConfig } = require("../../helper-hardhat-config")
const { assert, expect } = require("chai")
!developmentChains.includes(network.name)
? describe.skip
: describe("Raffle Unit Tests", async function () {
let raffle, vrfCoordinatorV2Mock, raffleEntranceFee, deployer, interval
const chainId = network.config.chainId
beforeEach(async function () {
// const { deployer } = await getNamedAccounts()
// new line to get deployer
deployer = (await getNamedAccounts()).deployer
await deployments.fixture(["all"])
raffle = await ethers.getContract("Raffle", deployer)
vrfCoordinatorV2Mock = await ethers.getContract("VRFCoordinatorV2Mock", deployer)
raffleEntranceFee = await raffle.getEntranceFee()
interval = await raffle.getInterval()
})
describe("constructor", async function () {
it("initalizes the raffle correctly", async function () {
// Ideally we make our tests have just 1 assert per"it"
const raffleState = await raffle.getRaffleState()
// const interval = await raffle.getInterval()
// => changed getInterval() to Global variable in beforeEach() above
assert.equal(raffleState.toString(), 0)
assert.equal(interval.toString(), networkConfig[chainId]["interval"])
})
})
describe("enterRaffle", async function () {
it("reverts when you don't pay enough", async function () {
await expect(raffle.enterRaffle()).to.be.revertedWith(
"Raffle__NotEnoughETHEntered"
)
})
it("records players when they enter", async function () {
await raffle.enterRaffle({ value: raffleEntranceFee })
const playerFromContract = await raffle.getPlayer(0)
assert.equal(playerFromContract, deployer)
})
// Make sure a function emits an event
it("emits event on enter", async function () {
await expect(raffle.enterRaffle({ value: raffleEntranceFee })).to.emit(
raffle,
"RaffleEnter"
)
})
it("doesn't allow entrance when raffle is calculating", async function () {
await raffle.enterRaffle({ value: raffleEntranceFee })
await network.provider.send("evm_increaseTime", [interval.toNumber() + 1])
await network.provider.send("evm_mine", [])
// We pretend to be a Chainlink Keeper
await raffle.performUpkeep([])
await expect(raffle.enterRaffle({ value: raffleEntranceFee })).to.be.revertedWith(
"Raffle__NotOpen"
)
})
})
}) |
Beta Was this translation helpful? Give feedback.
Replies: 11 comments 21 replies
-
Hi @paulcoffee85 |
Beta Was this translation helpful? Give feedback.
-
@paulcoffee85 run |
Beta Was this translation helpful? Give feedback.
-
Thanks , I love this community |
Beta Was this translation helpful? Give feedback.
-
To solve this issue input the code on your CLI / terminal |
Beta Was this translation helpful? Give feedback.
-
Thanks! That worked like a charm. Just want to add for the people in the future, to use (in Raffle.sol)
instead of
|
Beta Was this translation helpful? Give feedback.
-
So as the error suggest, we did not add our Lottery contract as consumer to VRFCoordinator. If you do want to use the latest version of
|
Beta Was this translation helpful? Give feedback.
-
Hello, I cannot seem to access the methods of VRFCoordinatorV2Mock When I try to call createSubscription() it says it is not a function same goes for addConsumer() method Here's the full error message : TypeError: vrfCoordinatorV2Mock.addConsumer is not a function My solidity file:
My deploy script:
I commented out the createSubscription part and hardcoded 0 to the subId to work around like a pro coder XD Please help me out |
Beta Was this translation helpful? Give feedback.
-
: Use 'yarn hardhat test' with the hard-coded 'subId=1'. If you use 'yarn hardhat test --network localhost', it will work correctly. |
Beta Was this translation helpful? Give feedback.
-
write this affter you deploy your contract which is in 01-deploy-raffle.js //Deploying contract |
Beta Was this translation helpful? Give feedback.
-
I found a way to solve it inside solidity itself, you can even have to pass subscription id when deploying the contract. Check out this answer. smartcontractkit/chainlink#7982 (comment) |
Beta Was this translation helpful? Give feedback.
@paulcoffee85 run
npm install --save-dev @chainlink/[email protected]