Cyfrin Updraft.

Допис

Діліться своїми знаннями.

Cyfrin Moderator Pst.
Mar 29, 2024
Питання та відповіді експертів

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
Поділитися
Коментарі
.

Відповіді

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
Офіційна відповідь
Коментарі
.

Ви знаєте відповідь?

Будь ласка, увійдіть та поділіться нею.

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

200Пости201Відповіді
Sui.X.Peera.

Зароби свою частку з 1000 Sui

Заробляй бали репутації та отримуй винагороди за допомогу в розвитку спільноти Sui.