Cyfrin Updraft.

Bài viết

Chia sẻ kiến thức của bạn.

Cyfrin Moderator Pst.
Mar 29, 2024
Hỏi đáp Chuyên Gia

What's the Role of MockV3Aggregator in FundMe Contrct?

In our project, we have utilized the code from the Foundry fund me project on GitHub, specifically involving the MockV3Aggregator. When testing the PriceFeedVersionIsAccurate() function in the test script, it seems to be calling the getVersion() function in FundMe.sol, which in turn references s_priceFeed. s_priceFeed is defined as AggregatorV3Interface private s_priceFeed; and is imported from AggregatorV3Interface.sol using import {AggregatorV3Interface} from '@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol';.

My question pertains to how HelperConfig.s.sol resolves the issue and whether s_priceFeed is actually MockV3Aggregator instead of AggregatorV3Interface when working with Anvil. Any insights or clarifications on this matter would be greatly appreciated. Thank you for your attention to this query.

When we test with the PriceFeedVersionIsAccurate() function in the test script.

function testPriceFeedVersionIsAccurate() public {
    // This is a unit test
    uint256 version = fundMe.getVersion();
    assertEq(version, 4);
}

As of my understanding, it is actually call the following function in FundMe.sol

function getVersion() public view returns (uint256) {
    return s_priceFeed.version();
}
  • Foundry
  • Solidity
0
1
Chia sẻ
Bình luận
.

Câu trả lời

1
Cyfrin Moderator Ans.
Mar 29 2024, 09:16

The s_price_feed storage variable is initialized within the constructor function at line 48 in the FundMe.sol contract.

constructor(address priceFeed) {
    s_priceFeed = AggregatorV3Interface(priceFeed);
    i_owner = msg.sender;
}

The constructor function expects the priceFeed address, which, in the case of Anvil (deploying locally), corresponds to the address of the MockV3Aggregator.

Subsequently, the HelperConfig.s.sol file plays a crucial role by both deploying and providing the address for the MockV3Aggregator when deploying the FundMe contract using the DeployScript.s.sol.

0
Câu trả lời chính thức
Bình luận
.

Bạn có biết câu trả lời không?

Hãy đăng nhập và chia sẻ nó.

Cyfrin Updraft is an education platform specializing on teaching the next generation of smart contract developers

200Bài viết201Câu trả lời
Sui.X.Peera.

Kiếm phần của bạn từ 1000 Sui

Tích lũy điểm danh tiếng và nhận phần thưởng khi giúp cộng đồng Sui phát triển.