gpt4 book ai didi

testing - Solidity:类型错误:无法通过尝试测试来读取简单 HelloWorld 合约中未定义的属性(读取 'JsonRpcProvider' )

转载 作者:行者123 更新时间:2023-12-03 07:58:13 26 4
gpt4 key购买 nike

我正在尝试测试一个简单的 HelloWorld.sol 文件:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract HelloWorld
{
function hello() public pure returns (string memory)
{
return "Hello, World";
}
}

使用 HelloWorld.ts 测试文件

import "@nomiclabs/hardhat-ethers" ;
import { ethers } from "hardhat";
import { expect } from "chai";


describe("hello world", function()
{
it("should say hello world", async function ()
{
const HelloWorld = await ethers.getContractFactory("HelloWorld");
const hello = await HelloWorld.deploy();

expect(hello).to.equal("Hello, World");

});
});

调用后:npx 安全帽测试

I got result with a error message:

hello world
1) should say hello world


0 passing (78ms)
1 failing

1) hello world
should say hello world:
TypeError: Cannot read properties of undefined (reading 'JsonRpcProvider')
at Object.<anonymous> (node_modules\@nomiclabs\hardhat-ethers\src\internal\ethers-provider-wrapper.ts:4:61)
at Module._compile (node:internal/modules/cjs/loader:1218:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1272:10)
at Object.require.extensions.<computed> [as .js] (node_modules\ts-node\src\index.ts:1608:43)
at Module.load (node:internal/modules/cjs/loader:1081:32)
at Function.Module._load (node:internal/modules/cjs/loader:922:12)
at Module.require (node:internal/modules/cjs/loader:1105:19)
at require (node:internal/modules/cjs/helpers:103:18)
at Object.<anonymous> (node_modules\@nomiclabs\hardhat-ethers\src\internal\provider-proxy.ts:7:1)
at Module._compile (node:internal/modules/cjs/loader:1218:14)

我已经在网上进行了答案/修复研究,但无法找到合适的答案..

所以我不知道如何解决这个问题以及我应该做什么?

提前致谢!

请参阅上文

不知道为什么会出现此错误...

最佳答案

对我来说,将package.json中的ethers版本更改为^5.7.2(我安装了6.2.0)然后删除 node_modules 文件夹并运行 yarn 再次安装软件包清除了错误。

referenced from here

关于testing - Solidity:类型错误:无法通过尝试测试来读取简单 HelloWorld 合约中未定义的属性(读取 'JsonRpcProvider' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75391122/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com