单元测试错误:没有部署名称为Raffle的契约



这是我的单元测试部分…过去几个小时我一直在研究这个问题。然而,我不能……我认为错误在const { deployer } = await getNamedAccounts()这条线。抽奖合同不被认可…(注意-所有的部署工作正常…)

!developmentChains.includes(network.name)
? describe.skip()
: describe("Raffle UNIT test", async () => {
let raffle, vrfCoordinatorV2Mock
const chainId = network.config.chainId
beforeEach(async () => {
const { deployer } = await getNamedAccounts()
await deployments.fixture(["all"])
raffle = await ethers.getContract("Raffle", deployer)
vrfCoordinatorV2Mock = await ethers.getContract("VRFCoordinatorV2Mock", deployer)
})
describe("Constructor function", async () => {
it("Initializes the raffle correctly.", async () => {
const raffleState = await raffle.getRaffleState()
const interval = await raffle.getInterval()

assert.equal(raffleState.toString(), "0")
assert.equal(interval.toString(), networkConfig[chainId]["interval"])
})
})
})

ERROR that I got…

~/b/JSweb3_2/smart-contract_lottery  on main !2  hh test                                                      ✔  took 5s  system    at 07:27:25 am 

Raffle UNIT test
Constructor function
Development chain detected! Deploying mocks
Mocks deployed!!!...
---------------------!--!--!---------------------
1) "before each" hook for "Initializes the raffle correctly."
0 passing (428ms)
1 failing
1) Raffle UNIT test
"before each" hook for "Initializes the raffle correctly.":
Error: No Contract deployed with name Raffle
at Object.getContract (node_modules/@nomiclabs/hardhat-ethers/src/internal/helpers.ts:447:11)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at runNextTicks (node:internal/process/task_queues:65:3)
at listOnTimeout (node:internal/timers:528:9)
at processTimers (node:internal/timers:502:7)
at Context.<anonymous> (test/unit/Raffle.test.js:16:24)

我正在遵循相应的教程。

我相信您正在遵循Patrick的课程,您是否在运行测试之前检查了部署脚本是否正在执行?您可以在脚本中执行控制台日志,并确保它们正在导出标记。例如,

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

最新更新