Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Format code
Source Link
Ismael
  • 30.3k
  • 23
  • 54
  • 97

` Basic NFT Unit Tests Constructor

  Basic NFT Unit Tests
    Constructor

      1) "before each" hook for "Initializes the NFT Correctly."


  0 passing (2s)
  1 failing

  1) Basic NFT Unit Tests
       "before each" hook for "Initializes the NFT Correctly.":
     Error: invalid contract address or ENS name (argument="addressOrName", value=undefined, code=INVALID_ARGUMENT, version=contracts/5.7.0)
      at Logger.makeError (node_modules\@ethersproject\logger\src.ts\index.ts:269:28)
      at Logger.throwError (node_modules\@ethersproject\logger\src.ts\index.ts:281:20)
      at Logger.throwArgumentError (node_modules\@ethersproject\logger\src.ts\index.ts:285:21)
      at Contract.BaseContract (node_modules\@ethersproject\contracts\src.ts\index.ts:712:20)
      at new Contract (node_modules\@ethersproject\contracts\lib\index.js:1053:42)
      at Function.ContractFactory.getContract (node_modules\@ethersproject\contracts\src.ts\index.ts:1297:16)
      at ContractFactory.attach (node_modules\@ethersproject\contracts\src.ts\index.ts:1260:42)
      at getContractAtFromArtifact (node_modules\@nomiclabs\hardhat-ethers\src\internal\helpers.ts:377:26)
      at processTicksAndRejections (node:internal/process/task_queues:95:5)
      at Context.<anonymous> (test\basicNft.test.js:15:26)`

0 passing (2s) 1 failing

  1. Basic NFT Unit Tests "before each" hook for "Initializes the NFT Correctly.": Error: invalid contract address or ENS name (argument="addressOrName", value=undefined, code=INVALID_ARGUMENT, version=contracts/5.7.0) at Logger.makeError (node_modules@ethersproject\logger\src.ts\index.ts:269:28) at Logger.throwError (node_modules@ethersproject\logger\src.ts\index.ts:281:20) at Logger.throwArgumentError (node_modules@ethersproject\logger\src.ts\index.ts:285:21) at Contract.BaseContract (node_modules@ethersproject\contracts\src.ts\index.ts:712:20) at new Contract (node_modules@ethersproject\contracts\lib\index.js:1053:42) at Function.ContractFactory.getContract (node_modules@ethersproject\contracts\src.ts\index.ts:1297:16) at ContractFactory.attach (node_modules@ethersproject\contracts\src.ts\index.ts:1260:42) at getContractAtFromArtifact (node_modules@nomiclabs\hardhat-ethers\src\internal\helpers.ts:377:26) at processTicksAndRejections (node:internal/process/task_queues:95:5) at Context. (test\basicNft.test.js:15:26)`

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

!developmentChains.includes(network.name) ? describe.skip : describe("Basic NFT Unit Tests", function () { let basicNft, deployer

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


!developmentChains.includes(network.name)
    ? describe.skip
    : describe("Basic NFT Unit Tests", function () {
          let basicNft, deployer

          beforeEach(async () => {
              accounts = await ethers.getSigners()
              deployer = accounts[0]
              await deployments.fixture(["basicNft"])
              basicNft = await ethers.getContractAt("BasicNFT")
          })
        
        describe("Constructor", () => {
            it("Initializes the NFT Correctly.", async () => {
                const name = await basicNft.name()
                const symbol = await basicNft.symbol()
                const tokenCounter=await basicNft.getTokenCounter()
                assert.equal(name, "Dogie")
                assert.equal(symbol, "DOG")
                assert.equal(tokenCounter.toString(),"0")
            })
        })

        describe("Mint NFT", () => {
          beforeEach(async () => {
              const txResponse = await basicNft.mintNft()
              await txResponse.wait(1)
          })
          it("Allows users to mint an NFT, and updates appropriately", async function () {
              const tokenURI = await basicNft.tokenURI(0)
              const tokenCounter = await basicNft.getTokenCounter()

              assert.equal(tokenCounter.toString(), "1")
              assert.equal(tokenURI, await basicNft.TOKEN_URI())
          })
          it("Show the correct balance and owner of an NFT", async function () {
              const deployerAddress = deployer.address;
              const deployerBalance = await basicNft.balanceOf(deployerAddress)
              const owner = await basicNft.ownerOf("0")

              assert.equal(deployerBalance.toString(), "1")
              assert.equal(owner, deployerAddress)
          })
        })
    })`

` Basic NFT Unit Tests Constructor

  1) "before each" hook for "Initializes the NFT Correctly."

0 passing (2s) 1 failing

  1. Basic NFT Unit Tests "before each" hook for "Initializes the NFT Correctly.": Error: invalid contract address or ENS name (argument="addressOrName", value=undefined, code=INVALID_ARGUMENT, version=contracts/5.7.0) at Logger.makeError (node_modules@ethersproject\logger\src.ts\index.ts:269:28) at Logger.throwError (node_modules@ethersproject\logger\src.ts\index.ts:281:20) at Logger.throwArgumentError (node_modules@ethersproject\logger\src.ts\index.ts:285:21) at Contract.BaseContract (node_modules@ethersproject\contracts\src.ts\index.ts:712:20) at new Contract (node_modules@ethersproject\contracts\lib\index.js:1053:42) at Function.ContractFactory.getContract (node_modules@ethersproject\contracts\src.ts\index.ts:1297:16) at ContractFactory.attach (node_modules@ethersproject\contracts\src.ts\index.ts:1260:42) at getContractAtFromArtifact (node_modules@nomiclabs\hardhat-ethers\src\internal\helpers.ts:377:26) at processTicksAndRejections (node:internal/process/task_queues:95:5) at Context. (test\basicNft.test.js:15:26)`

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

!developmentChains.includes(network.name) ? describe.skip : describe("Basic NFT Unit Tests", function () { let basicNft, deployer

      beforeEach(async () => {
          accounts = await ethers.getSigners()
          deployer = accounts[0]
          await deployments.fixture(["basicNft"])
          basicNft = await ethers.getContractAt("BasicNFT")
      })
    
    describe("Constructor", () => {
        it("Initializes the NFT Correctly.", async () => {
            const name = await basicNft.name()
            const symbol = await basicNft.symbol()
            const tokenCounter=await basicNft.getTokenCounter()
            assert.equal(name, "Dogie")
            assert.equal(symbol, "DOG")
            assert.equal(tokenCounter.toString(),"0")
        })
    })

    describe("Mint NFT", () => {
      beforeEach(async () => {
          const txResponse = await basicNft.mintNft()
          await txResponse.wait(1)
      })
      it("Allows users to mint an NFT, and updates appropriately", async function () {
          const tokenURI = await basicNft.tokenURI(0)
          const tokenCounter = await basicNft.getTokenCounter()

          assert.equal(tokenCounter.toString(), "1")
          assert.equal(tokenURI, await basicNft.TOKEN_URI())
      })
      it("Show the correct balance and owner of an NFT", async function () {
          const deployerAddress = deployer.address;
          const deployerBalance = await basicNft.balanceOf(deployerAddress)
          const owner = await basicNft.ownerOf("0")

          assert.equal(deployerBalance.toString(), "1")
          assert.equal(owner, deployerAddress)
      })
    })
})`
  Basic NFT Unit Tests
    Constructor

      1) "before each" hook for "Initializes the NFT Correctly."


  0 passing (2s)
  1 failing

  1) Basic NFT Unit Tests
       "before each" hook for "Initializes the NFT Correctly.":
     Error: invalid contract address or ENS name (argument="addressOrName", value=undefined, code=INVALID_ARGUMENT, version=contracts/5.7.0)
      at Logger.makeError (node_modules\@ethersproject\logger\src.ts\index.ts:269:28)
      at Logger.throwError (node_modules\@ethersproject\logger\src.ts\index.ts:281:20)
      at Logger.throwArgumentError (node_modules\@ethersproject\logger\src.ts\index.ts:285:21)
      at Contract.BaseContract (node_modules\@ethersproject\contracts\src.ts\index.ts:712:20)
      at new Contract (node_modules\@ethersproject\contracts\lib\index.js:1053:42)
      at Function.ContractFactory.getContract (node_modules\@ethersproject\contracts\src.ts\index.ts:1297:16)
      at ContractFactory.attach (node_modules\@ethersproject\contracts\src.ts\index.ts:1260:42)
      at getContractAtFromArtifact (node_modules\@nomiclabs\hardhat-ethers\src\internal\helpers.ts:377:26)
      at processTicksAndRejections (node:internal/process/task_queues:95:5)
      at Context.<anonymous> (test\basicNft.test.js:15:26)`

Here, my code

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


!developmentChains.includes(network.name)
    ? describe.skip
    : describe("Basic NFT Unit Tests", function () {
          let basicNft, deployer

          beforeEach(async () => {
              accounts = await ethers.getSigners()
              deployer = accounts[0]
              await deployments.fixture(["basicNft"])
              basicNft = await ethers.getContractAt("BasicNFT")
          })
        
        describe("Constructor", () => {
            it("Initializes the NFT Correctly.", async () => {
                const name = await basicNft.name()
                const symbol = await basicNft.symbol()
                const tokenCounter=await basicNft.getTokenCounter()
                assert.equal(name, "Dogie")
                assert.equal(symbol, "DOG")
                assert.equal(tokenCounter.toString(),"0")
            })
        })

        describe("Mint NFT", () => {
          beforeEach(async () => {
              const txResponse = await basicNft.mintNft()
              await txResponse.wait(1)
          })
          it("Allows users to mint an NFT, and updates appropriately", async function () {
              const tokenURI = await basicNft.tokenURI(0)
              const tokenCounter = await basicNft.getTokenCounter()

              assert.equal(tokenCounter.toString(), "1")
              assert.equal(tokenURI, await basicNft.TOKEN_URI())
          })
          it("Show the correct balance and owner of an NFT", async function () {
              const deployerAddress = deployer.address;
              const deployerBalance = await basicNft.balanceOf(deployerAddress)
              const owner = await basicNft.ownerOf("0")

              assert.equal(deployerBalance.toString(), "1")
              assert.equal(owner, deployerAddress)
          })
        })
    })
Source Link

Error: invalid contract address or ENS name (argument="addressOrName", value=undefined, code=INVALID_ARGUMENT, version=contracts/5.7.0)

I am trying to test the contract but getting error:

` Basic NFT Unit Tests Constructor

  1) "before each" hook for "Initializes the NFT Correctly."

0 passing (2s) 1 failing

  1. Basic NFT Unit Tests "before each" hook for "Initializes the NFT Correctly.": Error: invalid contract address or ENS name (argument="addressOrName", value=undefined, code=INVALID_ARGUMENT, version=contracts/5.7.0) at Logger.makeError (node_modules@ethersproject\logger\src.ts\index.ts:269:28) at Logger.throwError (node_modules@ethersproject\logger\src.ts\index.ts:281:20) at Logger.throwArgumentError (node_modules@ethersproject\logger\src.ts\index.ts:285:21) at Contract.BaseContract (node_modules@ethersproject\contracts\src.ts\index.ts:712:20) at new Contract (node_modules@ethersproject\contracts\lib\index.js:1053:42) at Function.ContractFactory.getContract (node_modules@ethersproject\contracts\src.ts\index.ts:1297:16) at ContractFactory.attach (node_modules@ethersproject\contracts\src.ts\index.ts:1260:42) at getContractAtFromArtifact (node_modules@nomiclabs\hardhat-ethers\src\internal\helpers.ts:377:26) at processTicksAndRejections (node:internal/process/task_queues:95:5) at Context. (test\basicNft.test.js:15:26)`

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

!developmentChains.includes(network.name) ? describe.skip : describe("Basic NFT Unit Tests", function () { let basicNft, deployer

      beforeEach(async () => {
          accounts = await ethers.getSigners()
          deployer = accounts[0]
          await deployments.fixture(["basicNft"])
          basicNft = await ethers.getContractAt("BasicNFT")
      })
    
    describe("Constructor", () => {
        it("Initializes the NFT Correctly.", async () => {
            const name = await basicNft.name()
            const symbol = await basicNft.symbol()
            const tokenCounter=await basicNft.getTokenCounter()
            assert.equal(name, "Dogie")
            assert.equal(symbol, "DOG")
            assert.equal(tokenCounter.toString(),"0")
        })
    })

    describe("Mint NFT", () => {
      beforeEach(async () => {
          const txResponse = await basicNft.mintNft()
          await txResponse.wait(1)
      })
      it("Allows users to mint an NFT, and updates appropriately", async function () {
          const tokenURI = await basicNft.tokenURI(0)
          const tokenCounter = await basicNft.getTokenCounter()

          assert.equal(tokenCounter.toString(), "1")
          assert.equal(tokenURI, await basicNft.TOKEN_URI())
      })
      it("Show the correct balance and owner of an NFT", async function () {
          const deployerAddress = deployer.address;
          const deployerBalance = await basicNft.balanceOf(deployerAddress)
          const owner = await basicNft.ownerOf("0")

          assert.equal(deployerBalance.toString(), "1")
          assert.equal(owner, deployerAddress)
      })
    })
})`