Lesson 7 Test leads to TypeError: Cannot read properties of undefined (reading 'JsonRpcProvider') #4733
-
I'm stuck on lesson 7 I can use yarn hardhat deploy and it deploys to the network I want, no problem. Now when I try to run a yarn hardhat test I always receive this error message: TypeError: Cannot read properties of undefined (reading 'JsonRpcProvider')
at Object.<anonymous> (/Users/patrickzimmerer/Solidity/freecodecamp/hardhat-fund-me/node_modules/@nomiclabs/hardhat-ethers/src/internal/ethers-provider-wrapper.ts:4:61)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Object.require.extensions.<computed> [as .js] (/Users/patrickzimmerer/Solidity/freecodecamp/hardhat-fund-me/node_modules/ts-node/src/index.ts:1608:43)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/Users/patrickzimmerer/Solidity/freecodecamp/hardhat-fund-me/node_modules/@nomiclabs/hardhat-ethers/src/internal/provider-proxy.ts:9:1)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
error Command failed with exit code 1. Does anyone know where I should start looking? import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import { assert, expect } from "chai";
import { network, deployments, ethers } from "hardhat";
import { developmentChains } from "../../helper-hardhat-config";
import { FundMe, MockV3Aggregator } from "../../typechain-types";
describe("FundMe", function() {
let fundMe: any;
let mockV3Aggregator: any;
let deployer: any;
const sendValue = ethers.utils.parseEther("1");
beforeEach(async () => {
// if you need accounts
// const accounts = await ethers.getSigners();
// const accountOne = accounts[0]
console.log("before each");
const accounts = await ethers.getSigners();
deployer = accounts[0];
await deployments.fixture(["all"]);
fundMe = await ethers.getContract("FundMe");
mockV3Aggregator = await ethers.getContract("MockV3Aggregator");
console.log("went through beforeEach");
});
describe("constructor", function() {
it("sets the aggregator address correctly", async function() {
const response = await fundMe.priceFeed();
assert.equal(response, mockV3Aggregator.address);
});
});
describe("fund", function() {
it("Fails if you don't send enough ETH", async function() {
await expect(fundMe.fund()).to.be.revertedWith(
"You need to spend more ETH!"
);
});
it("Updated the amount funded data structure", async function() {
await fundMe.fund({ value: sendValue });
const response = await fundMe.addressToAmountFunded(deployer);
assert.equal(response.toString(), sendValue.toString());
});
it("Adds fuinder to array of funders", async function() {
await fundMe.fund({ value: sendValue });
const funder = await fundMe.funders(0);
assert.equal(funder, deployer);
});
});
describe("withdraw", function() {
beforeEach(async () => {
await fundMe.fund({ value: sendValue });
});
it("withdraw ETH from a single founder", async () => {
// Arrange
const startingFundMeBalance = await fundMe.provider.getBalance(
fundMe.address
);
const startingDeployerBalance = await fundMe.provider.getBalance(
deployer
);
// Act
const transactionResponse = await fundMe.withdraw();
const transactionReceipt = await transactionResponse.wait(1);
const { gasUsed, effectiveGasPrice } = transactionReceipt;
const gasCost = gasUsed.mul(effectiveGasPrice);
const endingFundMeBalance = await fundMe.provider.getBalance(
fundMe.address
);
const endingDeployerBalance = await fundMe.provider.getBalance(
deployer
);
// Assert
assert.equal(endingFundMeBalance, 0);
assert.equal(
startingFundMeBalance.add(startingDeployerBalance.toString()),
endingDeployerBalance.add(gasCost).toString()
);
});
});
}); and here's my Repo: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
So I fixed this by debugging my testfile and it crashed at setting the const sendValue => so the error would have to be in ethers, to resolve this particular error: yarn add ethers @5.7.2 which should install ethers v 5.7.2 which works just fine. |
Beta Was this translation helpful? Give feedback.
So I fixed this by debugging my testfile and it crashed at setting the const sendValue => so the error would have to be in ethers, to resolve this particular error:
1.Go to your package.json and search for ethers which should be on 6.0.2 if you just did yarn add ethers, then just run
2. Run this command =>
which should install ethers v 5.7.2 which works just fine.