-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Open
Description
Discussed in #1257
Originally posted by ritesh798 July 23, 2022
getting this error when i used expect from chai
const { assert, expect } = require("chai");
const { deployments, ethers, getNamedAccounts } = require("hardhat");
describe("FundMe", async () => {
let fundMe;
let deployer;
let mockV3Aggregator;
beforeEach(async () => {
deployer = (await getNamedAccounts()).deployer;
await deployments.fixture(["all"]);
fundMe = ethers.getContract("FundMe", deployer);
mockV3Aggregator = ethers.getContract("MockV3Aggregator", deployer);
});
describe("Constructor", async () => {
it("Sets the aggregator address correctly ", async () => {
const response = await fundMe.priceFeed;
assert.equal(response, mockV3Aggregator.address);
});
});
describe("fund", () => {
it("Fails if you dont send enough eth", async () => {
await expect(fundMe.fund()).to.be.revertedWithCustomError(
"You need to spend more ETH!"
);
});
});
});and I get this error :
FundMe
Constructor
✔ Sets the aggregator address correctly
fund
1) Fails if you dont send enough eth
1 passing (757ms)
1 failing
1) FundMe
fund
Fails if you dont send enough eth:
TypeError: fundMe.fund is not a function
at Context.<anonymous> (test/unit/FundMe.test.js:21:27)
at processImmediate (node:internal/timers:471:21)
error Command failed with exit code 1.
This is my Fundme contract
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
import "./PriceConvertor.sol";
error NotOwner();
/**
* @title A croud funding decentralized platform
* @author Leo Franklin
* @notice This implements price feed as a library and check with the real time value of currrency and able to donate the eth
*/
contract FundMe {
using PriceConverter for uint256;
mapping(address => uint256) public addressToAmountFunded;
address[] public funders;
address public immutable i_owner;
uint256 public constant MINIMUM_USD = 50 * 10 ** 18;
AggregatorV3Interface public priceFeed;
constructor(address priceFeedAddress) {
i_owner = msg.sender;
priceFeed=AggregatorV3Interface(priceFeedAddress);
}
function fund() public payable {
require(msg.value.getConversionRate(priceFeed) >= MINIMUM_USD, "You need to spend more ETH!");
// require(PriceConverter.getConversionRate(msg.value) >= MINIMUM_USD, "You need to spend more ETH!");
addressToAmountFunded[msg.sender] += msg.value;
funders.push(msg.sender);
}
modifier onlyOwner {
// require(msg.sender == owner);
if (msg.sender != i_owner) revert NotOwner();
_;
}
function withdraw() public onlyOwner {
for (uint256 funderIndex=0; funderIndex < funders.length; funderIndex++){
address funder = funders[funderIndex];
addressToAmountFunded[funder] = 0;
}
funders = new address[](0);
(bool callSuccess, ) = payable(msg.sender).call{value: address(this).balance}("");
require(callSuccess, "Call failed");
}
fallback() external payable {
fund();
}
receive() external payable {
fund();
}
}
Metadata
Metadata
Assignees
Labels
No labels