首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无论我尝试什么,npx硬帽子测试都会返回"0传递“。

无论我尝试什么,npx硬帽子测试都会返回"0传递“。
EN

Stack Overflow用户
提问于 2022-08-18 19:28:15
回答 1查看 261关注 0票数 1

我在youtube "https://www.youtube.com/watch?v=7QsqElEaWBQ“上学习这个教程。

我已经检查了两次,以确保我的代码匹配,但我被困在41:00分钟的标记,我正在测试的项目。它始终显示"0传球“。没有失败的消息,我在教程视频中看到。这让我相信他们甚至没有接受测试。我已经安装了开始所需的所有依赖项,检查以确保我的文件名匹配,但仍然没有运气。这个测试使用的是硬帽子-华夫饼。

这是我的"Testing.js“文件代码=>

代码语言:javascript
复制
    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)
      );
    });
  });
});

如果你知道如何解决我的问题,请告诉我。那会对我有很大帮助的!

EN

回答 1

Stack Overflow用户

发布于 2022-10-15 11:14:54

请确保Testing.js放在test文件夹中,而文件夹test放在package.json旁边

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73408487

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档