-
Hi guys I am stuck at 11:28, everything was working on deployment stage, however test show error:
This is my FundMe.test.js const { assert } = require("chai")
const { deployments, ethers, getNamedAccounts } = require("hardhat")
describe("FundMe", async function () {
let fundMe
let deployer
let mockV3Aggregator
beforeEach(async function () {
//deploy our fundMe contract using Hardhat deploy
const accounts = await ethers.getSigners()
// const accountZero = accounts[0]
deployer = (await getNamedAccounts()).deployer
await deployments.fixture(["all"]) //lets us run our entire deploy folder with tags
console.log(`Your deployer is: ${deployer}`)
fundMe = await ethers.getContractAt("FundMe", deployer)
mockV3Aggregator = await ethers.getContractAt(
"MockV3Aggregator",
deployer
)
})
describe("constructor", async function () {
it("sets the aggregator addresses correctly", async function () {
const response = await fundMe.getPriceFeed() //this will run locally the priceFeed variable of the smartcontract
assert.equal(response, mockV3Aggregator.address)
})
})
}) Here is my FundMe.sol: // SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
import "./PriceConverter.sol";
//error Codes
error FundMe__NotOwner();
//interface,librarire, contracts
/** @title A contract for crowd funding
* @author Patrick Collins
* @notice This contract is to demo a sample funding contract
* @dev This implements price feeds as our library
*/
contract FundMe {
//Type Declarations
using PriceConverter for uint256;
//state variables
mapping(address => uint256) public addressToAmountFunded;
address[] public funders;
// Could we make this constant? /* hint: no! We should make it immutable! */
address public immutable i_owner;
uint256 public constant MINIMUM_USD = 50 * 10 ** 18;
AggregatorV3Interface public priceFeed;
modifier onlyOwner() {
// require(msg.sender == owner);
if (msg.sender != i_owner) revert FundMe__NotOwner();
_;
}
constructor(address priceFeedAddress) {
i_owner = msg.sender;
priceFeed = AggregatorV3Interface(priceFeedAddress);
}
receive() external payable {
fund();
}
fallback() external payable {
fund();
}
/**
* @notice This contract funds this contract
* @dev This implements price feeds as our library
*
*/
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);
}
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");
}
function getPriceFeed() public view returns (AggregatorV3Interface) {
return priceFeed;
}
} You can get access to my repo on: my_github_directory |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hello , the problem seems to be that you're implementing The
Currently you're passing the I'm not sure if it's your intention to use this method or if the autocomplete messed with you, but probably what you want to use is |
Beta Was this translation helpful? Give feedback.
Hello , the problem seems to be that you're implementing
getContractAt()
as if it were thegetContract()
method.The
getContractAt()
method takes three arguments:getContractAt(x, y, z)
, Where:Currently you're passing the
deployer
as the address of the deployed contract, which is incorrect. So no contracts are stored in thefundMe
andmockV3Aggregator
variables.I'm not sure if it's your intention to use this method or if the autocomplete messed with you, but probably what you want to use is
getContract()
, which you're basically implementing.