all the unit tests are failing #6415
Closed
khushbusandhu
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
hey, here is my solidity code ofFundMeTest.js
const { deployments, ethers, getNamedAccounts } = require("hardhat"); const { assert, expect } = require("chai"); require("@nomiclabs/hardhat-ethers"); const { developmentChains } = require("../../helper-hardhat-config"); describe("FundMe", async function () { let fundMe; let deployer; let mockV3Aggregator; const sendValue = ethers.parseEther("1"); beforeEach(async function () { deployer = (await getNamedAccounts()).deployer; await deployments.fixture(["all"]); fundMe = await ethers.getContractAt("FundMe", deployer); mockV3Aggregator = await ethers.getContractAt("MockV3Aggregator", deployer); }); describe("constructor", function () { it("sets the aggregator addresses correctly", async () => { const response = await fundMe.target; assert.equal(response, mockV3Aggregator.target); }); }); describe("fundme", function () { it("Fails if you don't send enough ETH", async () => { await expect(fundMe.fund()).to.be.revertedWith( "You need to spend more ETH!" ); }); it("Updates the amount funded data structure", async () => { await fundMe.fund({ value: sendValue }); const response = await fundMe.getAddressToAmountFunded(deployer); assert.equal(response.toString(), sendValue.toString()); }); it("Adds funder to funders array", async () => { await fundMe.fund({ value: sendValue }); const funder = await fundMe.getFunder(0); assert.equal(funder, deployer); }); }); describe("withdraw", function () { beforeEach(async () => { await fundMe.fund({ value: sendValue }); }); it("withdraws ETH from a single funder", async () => { // Arrange const startingFundMeBalance = await ethers.provider.getBalance( fundMe.target ); console.log(startingFundMeBalance); const startingDeployerBalance = await ethers.provider.getBalance( deployer ); console.log(startingDeployerBalance); // Act const transactionResponse = await fundMe.withdraw(); const transactionReceipt = await transactionResponse.wait(1); console.log(transactionReceipt); const { gasUsed, gasPrice } = transactionReceipt; const gasCost = gasUsed * gasPrice; const endingFundMeBalance = await ethers.provider.getBalance( fundMe.target ); console.log(endingFundMeBalance); const endingDeployerBalance = await ethers.provider.getBalance(deployer); console.log(endingDeployerBalance); // Assert // Maybe clean up to understand the testing assert.equal(endingFundMeBalance, 0); assert.equal( startingFundMeBalance + startingDeployerBalance, endingDeployerBalance + gasCost ); }); it("is allows us to withdraw with multiple funders", async () => { // Arrange const accounts = await ethers.getSigners(); for (i = 1; i < 6; i++) { const fundMeConnectedContract = await fundMe.connect(accounts[i]); await fundMeConnectedContract.fund({ value: sendValue }); } const startingFundMeBalance = await ethers.provider.getBalance( fundMe.address ); const startingDeployerBalance = await ethers.provider.getBalance( deployer ); // Act const transactionResponse = await fundMe.cheaperWithdraw(); // Let's comapre gas costs :) // const transactionResponse = await fundMe.withdraw() const transactionReceipt = await transactionResponse.wait(); const { gasUsed, effectiveGasPrice } = transactionReceipt; const withdrawGasCost = gasUsed.mul(effectiveGasPrice); console.log(`GasCost: ${withdrawGasCost}`); console.log(`GasUsed: ${gasUsed}`); console.log(`GasPrice: ${effectiveGasPrice}`); const endingFundMeBalance = await ethers.provider.getBalance( fundMe.address ); const endingDeployerBalance = await ethers.provider.getBalance(deployer); // Assert assert.equal( startingFundMeBalance.add(startingDeployerBalance).toString(), endingDeployerBalance.add(withdrawGasCost).toString() ); // Make a getter for storage variables await expect(fundMe.getFunder(0)).to.be.reverted; for (i = 1; i < 6; i++) { assert.equal( await fundMe.getAddressToAmountFunded(accounts[i].address), 0 ); } }); it("Only allows the owner to withdraw", async function () { const accounts = await ethers.getSigners(); const fundMeConnectedContract = await fundMe.connect(accounts[1]); await expect(fundMeConnectedContract.withdraw()).to.be.revertedWith( "FundMe__NotOwner" ); }); }); });and these are the errors i am getting
Beta Was this translation helpful? Give feedback.
All reactions