CRYPTO NEWS

Why the first code is showing error but not the second one. What’s happening here?

    address public owner = msg.sender;  //deployer     uint public tokens = 10000;                mapping(address=>uint) balances;    //address=>tokens                  balances[owner] = tokens;          //assigning all tokens                                         // to owner; 

The above code shows error, but when put it into a constructor it does not show any error

address public owner = msg.sender;     uint public tokens = 10000;     mapping(address=>uint) balances;          constructor() {        balances[owner] = tokens;     } 

getting error when testing hardhat fundMe constructor testing in patrick kolin fcc video at timestamp 11.15.00

when i test this code in hardhat enviroment its give me following error // const accounts = await ethers.getSigners() // deployer = accounts[0] const deployer = (await getNamedAccounts()).deployer await deployments.fixture(["all"]) fundMe = await ethers.getContract("FundMe", deployer) mockV3Aggregator = await ethers.getContract( "MockV3Aggregator", deployer ) }) describe("constructor", function () { it("sets the aggregator addresses correctly", async () =>::Listen

when i test this code in hardhat enviroment its give me following error

    // const accounts = await ethers.getSigners()     // deployer = accounts[0]    const deployer = (await getNamedAccounts()).deployer     await deployments.fixture(["all"])     fundMe = await ethers.getContract("FundMe", deployer)     mockV3Aggregator = await ethers.getContract(         "MockV3Aggregator",         deployer     ) }) describe("constructor", function () {     it("sets the aggregator addresses correctly", async () => {         const response = await fundMe.getPriceFeed()         assert.equal(response, mockV3Aggregator.address)     }) })``` 

getting following this error in terminal

    constructor        1) "before each" hook for "sets the aggregator addresses correctly"     0 passing (5s)   1 failing    1) fundMe        "before each" hook for "sets the aggregator addresses correctly":      ERROR processing C:Usersmdisthh-fcc-fundmedeploysample.js: TypeError: fundMe.priceFeed is not a functionhave ```  **anyone have idea?** 

Why the first code is showing error but not the second one. What’s happening here?

Shopping cart
There are no products in the cart!
Continue shopping
0