-
Hi, I have this error trying to test FundMe contract. Error: //
FundMe
constructor
1) sets the aggregator addresses correctly
0 passing (1s)
1 failing
1) FundMe
constructor
sets the aggregator addresses correctly:
Error: could not decode result data (value="0x", info={ "method": "priceFeed", "signature": "priceFeed()" }, code=BAD_DATA, version=6.7.1)
at makeError (node_modules/ethers/src.ts/utils/errors.ts:685:21)
at assert (node_modules/ethers/src.ts/utils/errors.ts:702:25)
at Interface.decodeFunctionResult (node_modules/ethers/src.ts/abi/interface.ts:916:15)
at staticCallResult (node_modules/ethers/src.ts/contract/contract.ts:332:35)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at staticCall (node_modules/ethers/src.ts/contract/contract.ts:289:24)
at Proxy.priceFeed (node_modules/ethers/src.ts/contract/contract.ts:337:41)
at Context.<anonymous> (test/unit/FundMe.test.js:25:30)
error Command failed with exit code 1.
// FundMe.test.js //
const { network, deployments, ethers, getNamedAccounts } = require("hardhat")
const { assert } = require("chai")
const { developmentChains } = require("../../helper-hardhat-config")
describe("FundMe", async function () {
let fundMe
let deployer
let mockV3Aggregator
beforeEach(async () => {
//Deploy FundMe
// using Hardhat-deploy
//const accounts = await ethers.getSigners()
//const acccountZero = accounts[0]
deployer = (await getNamedAccounts()).deployer
await deployments.fixture(["all"])
fundMe = await ethers.getContractAt("FundMe", deployer)
mockV3Aggregator = await ethers.getContractAt(
"MockV3Aggregator",
deployer
)
})
describe("constructor", function () {
it("sets the aggregator addresses correctly", async () => {
const response = await fundMe.priceFeed()
assert.equal(response, mockV3Aggregator.address)
})
})
})
// 01-deploy-fund-me.js //
module.exports.default = deployFunc
/*module.exports = async (hre) => {
const { getNamedAccounts, deployments } = hre
}*/
const { networkConfig, developmentChains } = require("../helper-hardhat-config")
const { network } = require("hardhat")
const { verify } = require("../utils/verify")
require("dotenv").config()
module.exports = async ({ getNamedAccounts, deployments }) => {
const { deploy, log } = deployments
const { deployer } = await getNamedAccounts()
const chainId = network.config.chainId
//const ethUsdPriceFeedAddress = networkConfig[chainId]["ethUsdPriceFeed"]
let ethUsdPriceFeedAddress
if (developmentChains.includes(network.name)) {
const ethUsdPriceFeed = await deployments.get("MockV3Aggregator")
ethUsdPriceFeedAddress = ethUsdPriceFeed.address
} else {
ethUsdPriceFeedAddress = networkConfig[chainId]["ethUsdPriceFeed"]
}
log("----------------------------------------------------")
log("Deploying FundMe and waiting for confirmations...")
const args = [ethUsdPriceFeedAddress]
const fundMe = await deploy("FundMe", {
from: deployer,
args: args,
log: true,
waitConfirmations: network.config.blockConfirmations || 1,
})
log(`FundMe deployed at ${fundMe.address}`)
if (
!developmentChains.includes(network.name) &&
process.env.ETHERSCAN_API_KEY
) {
await verify(fundMe.address, args)
}
module.exports.tags = ["all", "fundme"]
}
// hardhat.config.js //
require("@nomicfoundation/hardhat-toolbox")
//require("solhint")
require("@nomicfoundation/hardhat-chai-matchers")
//require("hardhat-gas-reporter")
//require("@nomiclabs/hardhat-ethers")
require("dotenv").config()
//require("solidity-coverage")
require("hardhat-deploy")
const SEPOLIA_RPC_URL = process.env.SEPOLIA_RPC_URL
const PRIVATE_KEY = process.env.PRIVATE_KEY
const COINMARKETCAP_API_KEY = process.env.COINMARKETCAP_API_KEY
const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY
module.exports = {
//solidity: "0.8.8",
solidity: {
compilers: [{ version: "0.8.8" }, { version: "0.6.6" }],
},
defaultNetworks: "hardhat",
networks: {
sepolia: {
url: SEPOLIA_RPC_URL,
accounts: [PRIVATE_KEY],
chainId: 11155111,
blocksConfirmations: 6,
},
},
gasReporter: {
enabled: false,
outputFile: "gas-report.txt",
noColor: true,
currency: "USD",
coinmarketcap: COINMARKETCAP_API_KEY,
token: "MATIC",
},
etherscan: {
apiKey: process.env.ETHERSCAN_API_KEY,
},
namedAccounts: {
deployer: {
default: 0,
},
user: {
default: 1,
},
},
}
// package.json {
"devDependencies": {
"@chainlink/contracts": "^0.6.1",
"@nomicfoundation/hardhat-chai-matchers": "1",
"@nomicfoundation/hardhat-ethers": "^3.0.0",
"@nomicfoundation/hardhat-network-helpers": "^1.0.9",
"@nomicfoundation/hardhat-toolbox": "^3.0.0",
"@nomicfoundation/hardhat-verify": "^1.0.0",
"@nomiclabs/hardhat-ethers": "^2.2.3",
"@nomiclabs/hardhat-etherscan": "^3.1.7",
"@typechain/ethers-v6": "^0.5.0",
"@typechain/hardhat": "^9.0.0",
"chai": "^4.3.9",
"deploy": "^1.0.3",
"hardhat": "^2.17.3",
"hardhat-deploy": "^0.11.37",
"hardhat-gas-reporter": "^1.0.9",
"solidity-coverage": "^0.8.5",
"typechain": "^8.3.1"
},
"dependencies": {
"dotenv": "^16.3.1",
"ethers": "6.7.1",
"solhint": "^3.6.2"
}
}
// |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
Hello @kotysky The issue you are facing is because you are mixing ethers v5 (course) with ethers v6. Just downgrade your ethers to v5 and you will be good, otherwise fix your code to proper syntax with ethers v6 documentation. best what i can tell you is do following to not mess up even more:
|
Beta Was this translation helpful? Give feedback.
-
I also faced a similar issue and managed to resolve it using #5884, head over and check it out you might find it helpful |
Beta Was this translation helpful? Give feedback.
I also faced a similar issue and managed to resolve it using #5884, head over and check it out you might find it helpful