PatrickAlphaC / hardhat-fund-me-fcc

82 stars 184 forks source link

LESSON 7: yarn hardhat test "Error: could not decode result data" #167

Closed pirqqs closed 1 year ago

pirqqs commented 1 year ago

Hello I am running into this error when trying to test the contructor function . It seems that the program is unable to read the result variable from fundMe.priceFeed() I am at 11:18:51 of the course. Here is the ERROR:

     Error: could not decode result data (value="0x", info={ "method": "getPriceFeed", "signature": "getPriceFeed()" }, code=BAD_DATA, version=6.6.0)
      at makeError (node_modules/ethers/src.ts/utils/errors.ts:677:21)
      at assert (node_modules/ethers/src.ts/utils/errors.ts:694:25)
      at Interface.decodeFunctionResult (node_modules/ethers/src.ts/abi/interface.ts:916:15)
      at staticCallResult (node_modules/ethers/src.ts/contract/contract.ts:324:35)
      at processTicksAndRejections (node:internal/process/task_queues:95:5)
      at staticCall (node_modules/ethers/src.ts/contract/contract.ts:281:24)
      at Proxy.getPriceFeed (node_modules/ethers/src.ts/contract/contract.ts:329:41)
      at Context.<anonymous> (test/unit/FundMe.test.js:27:30)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Here is the code that i am running for my test

const { assert } = require("chai")
const { deployments, ethers, getNamedAccounts } = require("hardhat")

describe("FundMe", function () {
    let fundMe
    let mockV3Aggregator
    let deployer

    beforeEach(async () => {

        deployer = (await getNamedAccounts()).deployer
        await deployments.fixture(["all"])
        fundMe = await ethers.getContractAt("FundMe", deployer)
        mockV3Aggregator = await ethers.getContractAt(
            "MockV3Aggregator",
            deployer
        )
    })

    //Test for our constructor
    describe("contructor", () => {
        it("sets the aggregator address correctly", async function () {
            const response = await fundMe.priceFeed()
            assert.equal(
                response,
                mockV3Aggregator.address
            )
        })
    })
})

I think that the error comes from the lines :

fundMe = await ethers.getContractAt("FundMe", deployer) 

or/and

const response = await fundMe.priceFeed()

The FundMe contract code:

 AggregatorV3Interface public priceFeed;
  constructor(address priceFeedAddress) {
        i_owner = msg.sender;
        priceFeed = AggregatorV3Interface(priceFeedAddress);
        //priceFeedAddress is now variable depending on what chain we're on
    }

function getPriceFeed() public view returns (AggregatorV3Interface) {
        return priceFeed;
    }

Any help would be extremly appreciated! Let me know if you need me to provide you anything else

pirqqs commented 1 year ago

I have found the issues to be with the versions of my dependencies if someone runs into to the same error as me i advice them to go to the discussions tabs you will find the answers there

PatrickAlphaC commented 1 year ago

Thank you!