Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

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!

You must be logged in to vote

Replies: 9 comments · 5 replies

Comment options

Could you push your directory to a repo and link it here? Thank you. I will look into it

You must be logged in to vote
2 replies
@hamednasr
Comment options

yarn hardhat compile,
it returns this error :

image

@anannyenaik
Comment options

Could you push your directory to a repo and link it here? Thank you. I will look into it

^

Comment options

@PatrickAlphaC

You must be logged in to vote
0 replies
Comment options

Yup got the same error today.

You must be logged in to vote
0 replies
Comment options

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

You must be logged in to vote
0 replies
Comment options

I had this same issue. I just kept toying with it and fortunately it worked.

You must be logged in to vote
0 replies
Comment options

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.

You must be logged in to vote
0 replies
Comment options

Change import path to :
import @chainlink/contracts/src/v0.8/tests/MockV3Aggregator.sol

You must be logged in to vote
2 replies
@AbhimanyuAjudiya
Comment options

hey it works thanks bro...

@Nikzadkhan
Comment options

it works for me too thanks shah

Comment options

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...

You must be logged in to vote
0 replies
Comment options

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.

You must be logged in to vote
1 reply
@devloperaziz1280
Comment options

Thank you. You saved a lot of time
I’d love to be friends on Discord ID:- aziz_oxm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
Morty Proxy This is a proxified and sanitized view of the page, visit original site.