Lesson 7 Unable to run test for withdraw function at 11:36:09 #1692
-
After running the Even after testing the whole thing using My FundMe.testjs file const { assert, expect } = require("chai")
const {deployments, ethers, getNamedAccounts} = require("hardhat")
describe("FundMe", async function(){
let fundMe
let deployer
let mockV3Aggregator
const sendValue = ethers.utils.parseEther("1") //it converts this 1 to that 1 with 18 zeroes
beforeEach(async function (){
//deploy are fundme contract
//using hardhat deploy
deployer = (await getNamedAccounts()).deployer
/* const accounts = await ethers.getSigners()
const accountZero = accounts[0]
//getSigners will return whatever is in the accounts in the networks section
*/
//fixture allows us to run entire deploy folder with as many tags as we want
await deployments.fixture(["all"])
//getContract will get info of the latest contract that we deployed
//by adding deployer whenever we call a function with fundme it will automatically be from that deployer
fundMe = await ethers.getContract("FundMe", deployer)
mockV3Aggregator = await ethers.getContract("MockV3Aggregator",deployer)
})
describe("constructor", async function() {
it("Sets the Aggregator address correctly", async function () {
const response = await fundMe.priceFeed()
assert.equal(response, mockV3Aggregator.address)
})
})
describe("fund", async function () {
it("Fails When you not send enough eth",async function (){
await expect(fundMe.fund()).to.be.revertedWith("You need to spend more ETH!")
})
it("Updated the amount funded data stucture", async function (){
await fundMe.fund({value: sendValue})
const response = await fundMe.addressToAmountFunded(deployer)
assert.equal(response.toString(), sendValue.toString())
})
it("Adds funder to array of funders",async function (){
await fundMe.fund({value: sendValue})
const funder = await fundMe.funders(0)
assert.equal(funder, deployer)
})
})
descrive("withdraw", async function (){
//need to send some eth before withdrawing therefore the below beforeEach
beforeEach(async function (){
await fundMe.fund({value: sendValue})
})
it("Withdraw ETH from single founder", async function () {
//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) //.mul function used as both are big numbers
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).to(), endingDeployerBalance.add(gasCost).toString())
})
})
}) |
Beta Was this translation helpful? Give feedback.
Answered by
alymurtazamemon
Aug 11, 2022
Replies: 1 comment 1 reply
-
@yash-2138 correct the spelling mistake |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
yash-2138
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@yash-2138 correct the spelling mistake
descrive
todescribe