0

I keep getting this TypeError(0, ethers_1.getAddress) is not a function while running my test for my smart contract and I am very confused on how to solve it. On top of that, for my create listing test I am getting a cannot read properties of undefined reading(approve). I am new to testing so excuse my ignorance.

    import { loadFixture } from "@nomicfoundation/hardhat-network-helpers";
    import { expect } from "chai";
    import { ethers } from "hardhat";

    let tokenId;
    let listingPrice;
    let owner;
    let horizonsMarketplace;
    let tokenIdSupply;
    let listToken;
    let token;
    let minter;

    describe("HorizonsMarketplace Initiation", function () {
    // We define a fixture to reuse the same setup in every test.
    // We use loadFixture to run this setup once, snapshot that state,
    // and reset Hardhat Network to that snapshot in every test.
    async function deployContractAndSetVariables() {
     const HorizonsMarketplace = await ethers.getContractFactory(
    "HorizonsMarketplace"
    );
    const horizonsMarketplace = await HorizonsMarketplace.deploy();

    const [owner] = await ethers.getSigners();

    return { horizonsMarketplace, owner };
   }

   it("should deploy and set the owner correctly", async function () {
     const { horizonsMarketplace, owner } = await loadFixture(
     deployContractAndSetVariables
     );

      expect(await horizonsMarketplace.owner()).to.equal(owner.getAddress);
     });

    describe("HorizonsMarketplace listing functionality", function () {
     it("Should create a new listing", async function () {
      await tokenId.approve(
      horizonsMarketplace.getAddress,
      listingPrice,
      owner
      );

      const tx = await horizonsMarketplace.listToken(
       token.address,
       tokenId,
       listingPrice,
       { from: minter }
       );
       expect(tokenId).to.equal(owner);
       expect(listingPrice).to.equal(1);
      expect(tokenIdSupply).to.increase(1);
      });
     });
   });

I might be missing a package instillation however I checked and updated my packages and everything should up to date. Not only am I getting this error for my specified contract but also getting it for the lock test script. So I am confused. Thank you in advance!

1 Answer 1

0

getAddress was used in v5 of ethers. From v6 onwards, you can simply use

horizonsMarketplace.address  
owner.address

About the second issue, you are calling the approve function on tokenId, which I belive is not a contract instance, instead you should be calling token.approve. Also make sure token contract is deployed, because I don't see any deployment for token in the test file itself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.