【发布时间】:2022-09-24 13:38:15
【问题描述】:
我正在 youtube 上关注本教程 \"https://www.youtube.com/watch?v=7QsqElEaWBQ\"
我已经仔细检查以确保我的代码匹配,但我被困在我正在测试项目的 41:00 分钟标记处。它始终显示“0 通过”。我在教程视频中没有看到失败消息。这让我相信他们甚至没有得到测试。我已经安装了开始时所需的所有依赖项,检查以确保我的文件名匹配但仍然没有运气。此测试使用的是 hardhat-waffle。
这是我的 \"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)
);
});
});
});
如果您知道如何解决我的问题,请告诉我。那对我会有很大的帮助!