-
Couldn't load subscription status.
- Fork 3.3k
-
why did not Patrick use mockV3aggregator for version 0.8 of solidity and uses 0.6? there is another file in :
@chainlink/contracts/src/v0.8/tests/MockV3Aggregator.sol
but he uses this:
@chainlink/contracts/src/v0.6/tests/MockV3Aggregator.sol
why not 0.7 ?!
Also:
when I use version 0.8, it returns an error :
Error HH404: File @chainlink/contracts/src/v0.8/tests/MockV3Aggregator.sol, imported from contracts/test/MockV3Aggregator.sol, not found.
why this happens, although the file exists on GitHub?!
thank you!
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 9 comments 6 replies
-
Could you push your directory to a repo and link it here? Thank you. I will look into it
Beta Was this translation helpful? Give feedback.
All reactions
-
yarn hardhat compile,
it returns this error :
Beta Was this translation helpful? Give feedback.
All reactions
-
Could you push your directory to a repo and link it here? Thank you. I will look into it
^
Beta Was this translation helpful? Give feedback.
All reactions
-
Beta Was this translation helpful? Give feedback.
All reactions
-
Yup got the same error today.
Beta Was this translation helpful? Give feedback.
All reactions
-
hardcoded way to pass this issue for now is create interface directory and there make 3 files: AggregatorInterface.sol, AggregatorV3Interface.sol and AggregatorV2V3Interface.sol. copy content of them from https://github.com/smartcontractkit/chainlink/tree/develop/contracts/src/v0.8/interfaces
then in your MockV3Aggregator.sol import from your local environment. That work for me.
image
Beta Was this translation helpful? Give feedback.
All reactions
-
I had this same issue. I just kept toying with it and fortunately it worked.
Beta Was this translation helpful? Give feedback.
All reactions
-
Well, Patrick is using Chainlink v0.4.0 package and it does not have MockV3Aggregator in v0.8 contracts and that's why you are getting the error that the MockV3Aggregator is not found. If you want to use MockV3Aggregator in v0.8 then you need to upgrade your Chainlink packages to v0.4.2 by yarn add @chainlink/contracts@0.4.2 or simply changing the version in your package.json and run yarn install. v0.4.2 contains MockV3Aggregator in v0.8 contracts.
I think I will create PR for this tomorrow.
Beta Was this translation helpful? Give feedback.
All reactions
-
Change import path to :
import @chainlink/contracts/src/v0.8/tests/MockV3Aggregator.sol
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 3 -
🚀 2
-
hey it works thanks bro...
Beta Was this translation helpful? Give feedback.
All reactions
-
it works for me too thanks shah
Beta Was this translation helpful? Give feedback.
All reactions
-
The MockV3Aggregator is a mock contract often used for testing in decentralized finance (DeFi) projects, specifically when working with Chainlink price feeds. It allows developers to simulate price feed data without interacting with the actual Chainlink oracles. In Solidity version 0.8, you can use this mock to test your contracts without relying on live price feeds.
Here is a basic example of how to set up the MockV3Aggregator in Solidity 0.8:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@chainlink/contracts/src/v0.8/tests/MockV3Aggregator.sol";
contract MyContract {
MockV3Aggregator public priceFeed;
constructor(uint8 _decimals, int256 _initialAnswer) {
// Initialize the mock aggregator with decimals and an initial price
priceFeed = new MockV3Aggregator(_decimals, _initialAnswer);
}
function getLatestPrice() public view returns (int256) {
// Fetch the latest price from the mock price feed
return priceFeed.latestAnswer();
}
}
Key Elements:
MockV3Aggregator: The mock contract imported from Chainlink's tests folder, used for simulating price feed data.
Decimals and Initial Answer: You can set the decimals and initial price data for your mock feed in the constructor.
This is useful for unit testing your smart contracts that rely on Chainlink price feeds. You can easily adjust the price and simulate different scenarios without using live oracles...
Beta Was this translation helpful? Give feedback.
All reactions
-
For anyone reading in 2025 or later, chainlink has updated its repo (I guess? because the paths in the comments above me don't exist anymore), and the mocks have been moved from tests to mocks folder inside the shared directory.
This is the final path that worked for me:
@chainlink/contracts/src/v0.8/shared/mocks/MockV3Aggregator.sol
Here is the link to their github repo.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 2
-
Thank you. You saved a lot of time
I’d love to be friends on Discord ID:- aziz_oxm
Beta Was this translation helpful? Give feedback.
All reactions
-
感恩的心~,感谢有你~
Beta Was this translation helpful? Give feedback.