2

This is code for my unit test scripts, I don't know where I am wrong.

const { deployments, ethers, network } = require("hardhat")
const { assert, expect } = require("chai")
const { developmentChains } = require("../../helper-hardhat-config")

!developmentChains.includes(network.name)
  ? describe.skip
  : describe("NFTMarketplace test", function () {
      4
      let nftMarketplaceContract, basicNftContract, nftMarketplace, basicNft
      const PRICE = ethers.utils.parseEther("1")
      const TOKEN_ID = 0
      beforeEach(async function () {
        accounts = await ethers.getSigners()
        deployer = accounts[0]
        player = accounts[1]
        await deployments.fixture(["all"])
        nftMarketplaceContract = await ethers.getContract("NftMarketplace")
        nftMarketplace = await nftMarketplaceContract.connect(deployer)
        basicNftContract = await ethers.getContract("BasicNft")
        basicNft = await basicNftContract.connect(deployer)
        await basicNft.mintNft()
        await basicNft.approve(nftMarketplaceContract.address, TOKEN_ID, PRICE)
      })
      describe("ListItem", function () {
        it("Lists nft", async function () {})
      })
    })

ERROR:

"before each" hook for "Lists nft":
     Error: cannot override "_hex","_isBigNumber","fromTwos","toTwos","abs","add","sub","div","mul","mod","pow","and","or","xor","mask","shl","shr","eq","lt","lte","gt","gte","isNegative","isZero","toNumber","toBigInt","toString","toHexString","toJSON" (operation="overrides", overrides=["_hex","_isBigNumber","fromTwos","toTwos","abs","add","sub","div","mul","mod","pow","and","or","xor","mask","shl","shr","eq","lt","lte","gt","gte","isNegative","isZero","toNumber","toBigInt","toString","toHexString","toJSON"], code=UNSUPPORTED_OPERATION, version=contracts/5.7.0)

Can someone help me with this error?

1 Answer 1

1

If it is approve() from ERC721 it only takes 2 arguments:

approve(address to, uint256 tokenId)

You need to remove PRICE

await basicNft.approve(nftMarketplaceContract.address, TOKEN_ID)
4
  • It didn't work.
    – Yana Gupta
    Mar 28, 2023 at 2:32
  • What do your mintNft() and approve() functions look like?
    – PSS
    Mar 28, 2023 at 2:37
  • function mintNft() public { _safeMint(msg.sender, s_tokenCounter); s_tokenCounter = s_tokenCounter + 1; } And approve is function from ERC721 contract that is imported in the contract by using @openzeppelin/contract
    – Yana Gupta
    Mar 28, 2023 at 2:41
  • Yes, It worked! thanks
    – Yana Gupta
    Mar 28, 2023 at 2:48

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.