Lesson 9: ReferenceError: deployer is not defined #1457
Answered
by
ironcladmerc
ironcladmerc
asked this question in
Q&A
-
I'm getting the error "ReferenceError: deployer is not defined" in my Raffle.test.js script after adding the "records players when entering" test, the deployer is available in the beforeEach as I am able to console.log it correctly. Any idea what's wrong? hh test output:
minimal Raffle.test.js: const { assert, expect } = require("chai")
const { getNamedAccounts, deployments, ethers } = require("hardhat")
const { developmentChains, networkConfig } = require("../../hardhat-helper-config")
console.log("Raffle.test.js")
console.log(`Testing on network: ${network.name}`)
!developmentChains.includes(network.name)
? describe.skip
: describe("Raffle", async function () {
let raffle, vrfCoordinatorV2Mock, raffleEntranceFee
const chainId = network.config.chainId
console.log(`Chain: ${chainId}`)
beforeEach(async function () {
const { deployer } = await getNamedAccounts()
await deployments.fixture(["all"])
raffle = await ethers.getContract("Raffle", deployer)
vrfCoordinatorV2Mock = await ethers.getContract("VRFCoordinatorV2Mock", deployer)
raffleEntranceFee = await raffle.getEntranceFee()
console.log(`Deployer: ${deployer}`)
})
describe("Enter raffle", async function () {
it("records players when entering", async function () {
await raffle.enterRaffle({ value: raffleEntranceFee })
const playerFromContract = await raffle.getPlayer(0)
assert.equal(playerFromContract, deployer)
})
})
}) hardhat.config.js require("@nomicfoundation/hardhat-toolbox")
require("@nomiclabs/hardhat-etherscan")
require("hardhat-deploy")
require("solidity-coverage")
require("hardhat-gas-reporter")
require("hardhat-contract-sizer")
require("dotenv").config()
const RINKEBY_PRIVATE_KEY = process.env.RINKEBY_PRIVATE_KEY
const RINKEBY_RPC_URL = process.env.RINKEBY_RPC_URL
const LOCALHOST_PRIVATE_KEY = process.env.LOCALHOST_PRIVATE_KEY
const LOCALHOST_RPC_URL = process.env.LOCALHOST_RPC_URL
const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY
const COINMARKETCAP_API_KEY = process.env.COINMARKETCAP_API_KEY
/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
solidity: "0.8.9",
defaultNetwork: "hardhat",
networks: {
hardhat: {
chainId: 31337,
blockConfirmations: 1,
},
rinkeby: {
url: RINKEBY_RPC_URL,
accounts: [RINKEBY_PRIVATE_KEY],
chainId: 4,
blockConfirmations: 6,
},
localhost: {
url: LOCALHOST_RPC_URL,
accounts: [LOCALHOST_PRIVATE_KEY],
chainId: 31337,
blockConfirmations: 1,
},
},
namedAccounts: {
deployer: {
default: 0, // here this will by default take the first account as deployer
1: 0, // similarly on mainnet it will take the first account as deployer. Note though that depending on how hardhat network are configured, the account 0 on one network can be different than on another
},
player: {
default: 1,
},
},
gasReporter: {
enabled: false,
currency: "USD",
outputFile: "gas-report.txt",
noColors: true,
coinmarketcap: COINMARKETCAP_API_KEY,
},
} hardhat-helper-config.js: const { ethers } = require("hardhat")
const networkConfig = {
4: {
name: "rinkeby",
vrfCoordinator: "0x6168499c0cFfCaCD319c818142124B7A15E857ab",
entranceFee: ethers.utils.parseEther("0.01"),
gasLane: "0xd89b2bf150e3b9e13446986e571fb9cab24b13cea0a43ea20a6049a85cc807cc",
subscriptionId: "0",
callbackGasLimit: "500000",
interval: "30",
},
31337: {
name: "hardhat",
entranceFee: ethers.utils.parseEther("0.01"),
gasLane: "0xd89b2bf150e3b9e13446986e571fb9cab24b13cea0a43ea20a6049a85cc807cc",
callbackGasLimit: "500000",
interval: "30",
},
}
const developmentChains = ["hardhat", "localhost"]
module.exports = { networkConfig, developmentChains } |
Beta Was this translation helpful? Give feedback.
Answered by
ironcladmerc
Aug 1, 2022
Replies: 1 comment
-
oops, I should have kept watching first, Patrick got the same error, need to define the deployer as a global variable |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
ironcladmerc
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
oops, I should have kept watching first, Patrick got the same error, need to define the deployer as a global variable