0

Im creating a NFTMARKETPLACE that accepts user metadata and mint it as NFT, Ikeep failing at my test. this is my code

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.7;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/utils/Counters.sol";

//defining our storage

contract NFT is ERC721URIStorage {
    //using the counter utility
    using Counters for Counters.Counter;
    //for incrementing value of tokens
    Counters.Counter private _tokenIds;

    //the nft interacts with this contract address for txn
    address contractAddress;
uint256 newItemId;
    constructor(address marketPlaceAddress) ERC721("Metaverse Tokens", "METT") {
        contractAddress = marketPlaceAddress;
    }

    function createToken() public {
        //increment the count the nFT
        _tokenIds.increment();
        _safeMint(msg.sender, newItemId);

        //Get the current value of the token
        newItemId = _tokenIds.current();
        //minting the NFT
    }
        
        function tokenURI (uint256 tokenId ) public view override returns (string memory TOKEN_URI){
        // _setTokenURI(newItemId, tokenURI);
        require(_exists(tokenId),"ERC721Metadata: URI query for nonexistent token");
        return TOKEN_URI;
        }
function getTokenCounter() public view returns (uint256){

        //given the marketPlace permission to transact
        // setApprovalForAll(contractAddress, true);
        return newItemId;
}
}

This is my testing script

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

!developmentChains.includes(network.name)
    ? describe.skip
    : describe("Nft Marketplace Unit Tests", function () {
          let nftMarketplace, nftMarketplaceContract, nftContractAddressConnect, nftContractAddress
          const PRICE = ethers.utils.parseEther("0.1")
          const TOKEN_ID = 0

          beforeEach(async () => {
              accounts = await ethers.getSigners() // could also do with getNamedAccounts
              deployer = accounts[0]
              user = accounts[1]
              await deployments.fixture(["all"])
              nftMarketplaceContract = await ethers.getContract("NftMarketplace")
              nftMarketplace = nftMarketplaceContract.connect(deployer)
              nftContractAddress = await ethers.getContract("NFT")
              nftContractAddressConnect = await nftContractAddress.connect(deployer)
              await nftContractAddressConnect.mint("https://www.mytokenlocation.com")
              await nftContractAddressConnect.approve(nftMarketplaceContract.address, TOKEN_ID)
          })

          describe("listItem", function () {
              it("emits an event after listing an item", async function () {
                  expect(await nftMarketplace.listItem(nftContractAddressConnect.address, TOKEN_ID, PRICE)).to.emit(
                      "ItemListed"
                  )
              })
              it("exclusively items that haven't been listed", async function () {
                  await nftMarketplace.listItem(nftContractAddressConnect.address, TOKEN_ID, PRICE)
                  const error = `AlreadyListed("${nftContractAddressConnect.address}", ${TOKEN_ID})`
                  //   await expect(
                  //       nftMarketplace.listItem(nftContractAddressConnect.address, TOKEN_ID, PRICE)
                  //   ).to.be.revertedWith("AlreadyListed")
                  await expect(
                      nftMarketplace.listItem(nftContractAddressConnect.address, TOKEN_ID, PRICE)
                  ).to.be.revertedWith(error)
              })
              it("exclusively allows owners to list", async function () {
                  nftMarketplace = nftMarketplaceContract.connect(user)
                  await nftContractAddressConnect.approve(user.address, TOKEN_ID)
                  await expect(
                      nftMarketplace.listItem(nftContractAddressConnect.address, TOKEN_ID, PRICE)
                  ).to.be.revertedWith("NotOwner")
              })
              it("needs approvals to list item", async function () {
                  await nftContractAddressConnect.approve(ethers.constants.AddressZero, TOKEN_ID)
                  await expect(
                      nftMarketplace.listItem(nftContractAddressConnect.address, TOKEN_ID, PRICE)
                  ).to.be.revertedWith("NotApprovedForMarketplace")
              })
              it("Updates listing with seller and price", async function () {
                  await nftMarketplace.listItem(nftContractAddressConnect.address, TOKEN_ID, PRICE)
                  const listing = await nftMarketplace.getListing(nftContractAddressConnect.address, TOKEN_ID)
                  assert(listing.price.toString() == PRICE.toString())
                  assert(listing.seller.toString() == deployer.address)
              })
          })

This is my error Error: invalid BigNumber string (argument="value", value="https://www.mytokenlocation.com", code=INVALID_ARGUMENT, version=bignumber/5.6.0)

3
  • Obviously the error is when calling nftContractAddressConnect.mint("https://www.mytokenlocation.com"). Can you include the mint function code in the question?
    – Ismael
    Commented Aug 14, 2022 at 18:11
  • function mintNft( string memory tokenURI) public returns (uint256){ _safeMint(msg.sender, s_tokenCounter); emit cardMinted(s_tokenCounter); s_tokenCounter = s_tokenCounter + 1; } Im trying to accept files from the front end and mint it as nft
    – Santos
    Commented Aug 14, 2022 at 22:25
  • The test calls mint() and not mintNft(), so you should fix the test to call the correct function instead.
    – Ismael
    Commented Aug 15, 2022 at 4:14

1 Answer 1

0

You could consider converting the string to its bytes32 representation using ethers.utils.formatBytes32String (string yourShortString) as specified in the docs

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.