首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >草帽测试不起作用

草帽测试不起作用
EN

Ethereum用户
提问于 2022-07-15 12:29:05
回答 2查看 1.1K关注 0票数 0

我试着在安全帽上运行一个简单的测试,但由于某些原因,它不起作用,它总是返回:

代码语言:javascript
复制
0 passing (1ms)

这是一个考验:

代码语言:javascript
复制
const { ethers } = require("hardhat")
const { expect, assert } = require("chai")

describe("SimpleStorage", async function () {
  let simpleStorageFactory, simpleStorage
  beforEach(async function () {
    simpleStorageFactory = await ethers.getContractFactory("SimpleStorage")
    simpleStorage = await simpleStorageFactory.deploy()
  })

  it("Should start with a favorite number of 0", async function () {
    const currentValue = await simpleStorage.retrieve()
    const expectedValue = "0"

    assert.equal(currentValue.toString(), expectedValue)
  })
})

当我跑步时:

代码语言:javascript
复制
yarn hardhat test

它返回0。好像测试文件是空的。

代码语言:javascript
复制
0 passing (1ms)

这是hardhat.config.js:

代码语言:javascript
复制
require("@nomicfoundation/hardhat-toolbox")
require("dotenv").config()
require("@nomiclabs/hardhat-etherscan")
require("./tasks/block_number")
require("@nomicfoundation/hardhat-chai-matchers")
require("@nomiclabs/hardhat-ethers")
require("@nomiclabs/hardhat-waffle")

const RINKEBY_RPC_URL = process.env.RINKEBY_RPC_URL
const PRIVATE_KEY = process.env.PRIVATE_KEY
const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY

/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
  defaultNetwork: "hardhat",
  networks: {
    rinkeby: {
      url: RINKEBY_RPC_URL,
      accounts: [PRIVATE_KEY],
      chainId: 4,
    },
    localhost: {
      url: "http://127.0.0.1:8545",

      chainId: 31337,
    },
  },
  solidity: "0.8.8",
  etherscan: {
    apiKey: ETHERSCAN_API_KEY,
  },
}

package.json:

代码语言:javascript
复制
{
  "name": "hardhat-simple-ss-2",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "devDependencies": {
    "@ethersproject/abi": "^5.4.7",
    "@ethersproject/providers": "^5.4.7",
    "@nomicfoundation/hardhat-chai-matchers": "^1.0.2",
    "@nomicfoundation/hardhat-network-helpers": "^1.0.0",
    "@nomicfoundation/hardhat-toolbox": "^1.0.1",
    "@nomiclabs/hardhat-ethers": "^2.1.0",
    "@nomiclabs/hardhat-etherscan": "^3.1.0",
    "@nomiclabs/hardhat-waffle": "^2.0.3",
    "@typechain/ethers-v5": "^10.1.0",
    "@typechain/hardhat": "^6.1.2",
    "@types/mocha": "^9.1.1",
    "chai": "^4.3.6",
    "dotenv": "^16.0.1",
    "ethereum-waffle": "^3.4.4",
    "ethers": "^5.6.9",
    "hardhat": "^2.10.1",
    "hardhat-gas-reporter": "^1.0.8",
    "prettier": "^2.7.1",
    "prettier-plugin-solidity": "^1.0.0-dev.23",
    "solidity-coverage": "^0.7.21",
    "ts-node": "^10.9.1",
    "typechain": "^8.1.0",
    "typescript": "^4.7.4"
  }
}

所有的软件包似乎都安装在https://hardhat.org/hardhat-runner/docs/other-guides/waffle-testing中。

有什么问题吗?

EN

回答 2

Ethereum用户

发布于 2022-08-29 13:39:42

您的beforEach(异步函数() )在前面的末尾缺少一个"e“

应该是beforeEach(异步函数() )

票数 1
EN

Ethereum用户

发布于 2022-07-15 14:56:28

我认为问题在于,在顶级描述块中包含了async。删除它应该允许您的测试被执行。将第4行替换为这样可以解决您的问题:

代码语言:javascript
复制
describe("SimpleStorage", function () {
票数 0
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/131814

复制
相关文章

相似问题

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