我在youtube "https://www.youtube.com/watch?v=7QsqElEaWBQ“上学习这个教程。
我已经检查了两次,以确保我的代码匹配,但我被困在41:00分钟的标记,我正在测试的项目。它始终显示"0传球“。没有失败的消息,我在教程视频中看到。这让我相信他们甚至没有接受测试。我已经安装了开始所需的所有依赖项,检查以确保我的文件名匹配,但仍然没有运气。这个测试使用的是硬帽子-华夫饼。
这是我的"Testing.js“文件代码=>
const { expect } = require("chai");
const { ethers } = require("ethers");
const {
isCallTrace,
} = require("hardhat/internal/hardhat-network/stack-traces/message-trace");
describe("Staking", function () {
beforeEach(async function () {
[signer1, signers2] = await ethers.getSigners();
Staking = await ethers.getContractFactory("Staking", signer1);
staking = await Staking.deploy({
value: ethers.utils.parseEther("10"),
});
});
describe("deploy", function () {
it("should set owner", async function () {
expect(await staking.owner()).to.equal(signer1.address);
});
it("sets up tiers and lockPeriods", async function () {
expect(await staking.lockPeriods(0)).to.equal(30);
expect(await staking.lockPeriods(1)).to.equal(90);
expect(await staking.lockPeriods(2)).to.equal(180);
expect(await staking.tiers(3)).to.equal(700);
expect(await staking.tiers(3)).to.equal(1000);
expect(await staking.tiers(3)).to.equal(1200);
});
});
describe("stakeEther", function () {
it("transfers ether", async function () {
const provider = waffle.provider;
let contractBalance;
let signerBalance;
const transferAmount = ethers.utils.parseEther("2.0");
contractBalance = await provider.getBalance(staking.address);
signerBalance = await signer1.getBalance();
const data = { value: transferAmount };
const transaction = await staking.connect(signer1).stakeEther(30, data);
const receipt = await transaction.wait();
const gasUsed = receipt.gasUsed.mul(receipt.effectiveGasPrice);
//test the change in signer1's ether balance
expect(await signer1.getBalance()).to.equal(
signerBalance.sub(transferAmount).sub(gasUsed)
);
// test the change in contract's ether balance
expect(await provider.getBalance(staking.address)).to.equal(
contractBalance.add(transferAmount)
);
});
});
});如果你知道如何解决我的问题,请告诉我。那会对我有很大帮助的!
发布于 2022-10-15 11:14:54
请确保Testing.js放在test文件夹中,而文件夹test放在package.json旁边
https://stackoverflow.com/questions/73408487
复制相似问题