PatrickAlphaC / hardhat-nft-fcc

102 stars 140 forks source link

Error HH702: Invalid artifact path contracts/BasicNft.sol:BasicNft, its correct case-sensitive path is contracts/BasicNFT.sol:BasicNFT #67

Closed sin-blanca closed 1 year ago

sin-blanca commented 1 year ago

BasicNft.sol

` // SPDX-License-Identifier: MIT pragma solidity ^0.8.7;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";

contract BasicNft is ERC721 { string public constant TOKEN_URI = "ipfs://bafybeig37ioir76s7mg5oobetncojcm3c3hxasyd4rvid4jqhy4gkaheg4/?filename=0-PUG.json"; uint256 private s_tokenCounter;

constructor() ERC721("Dogie", "DOG") {
    s_tokenCounter = 0;
}

function mintNft() public {
    s_tokenCounter = s_tokenCounter + 1;
    _safeMint(msg.sender, s_tokenCounter);
}

function tokenURI(uint256 /*tokenId*/) public view override returns (string memory) {
    // require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
    return TOKEN_URI;
}

function getTokenCounter() public view returns (uint256) {
    return s_tokenCounter;
}

} `

01-deploy-basic-nft.js `const { network } = require("hardhat") const { developmentChains } = require("../helper-hardhat-config") const { verify } = require("../utils/verify")

module.exports = async ({ getNamedAccounts, deployments }) => { const { deploy, log } = deployments const { deployer } = await getNamedAccounts()

log("----------------------------------------------------")
arguments = []
const basicNft = await deploy("BasicNft", {
    from: deployer,
    args: arguments,
    log: true,
    waitConfirmations: network.config.blockConfirmations || 1,
})

// Verify the deployment
if (!developmentChains.includes(network.name) && process.env.ETHERSCAN_API_KEY) {
    log("Verifying...")
    await verify(basicNft.address, arguments)
}

}

module.exports.tags = ["all", "basicnft", "main"]`

basicNft.test.js

`// We are going to skip a bit on these tests...

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

//writing the test code from here..

!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.getContract("BasicNft")
      })

    //test01
    describe("Construtor", () => {
        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")
        })
    })

//test02 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("1")

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

hardhat.config.js

`require("@nomiclabs/hardhat-waffle") require("hardhat-gas-reporter") require("@nomiclabs/hardhat-etherscan") require("dotenv").config() require("solidity-coverage") require("hardhat-deploy") // You need to export an object to set up your config // Go to https://hardhat.org/config/ to learn more /**

const MAINNET_RPC_URL = process.env.MAINNET_RPC_URL || process.env.ALCHEMY_MAINNET_RPC_URL || "" const COINMARKETCAP_API_KEY = process.env.COINMARKETCAP_API_KEY || "" const GOERLI_RPC_URL = process.env.GOERLI_RPC_URL || "https://eth-goerli.alchemyapi.io/v2/your-api-key" const PRIVATE_KEY = process.env.PRIVATE_KEY || "0x11ee3108a03081fe260ecdc106554d09d9d1209bcafd46942b10e02943effc4a" const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY || ""

module.exports = { defaultNetwork: "hardhat", networks: { hardhat: { chainId: 31337, forking: { url: MAINNET_RPC_URL, }, }, localhost: { chainId: 31337, }, goerli: { url: GOERLI_RPC_URL, accounts: [PRIVATE_KEY], chainId: 5, blockConfirmations: 6, }, }, solidity: { compilers: [ { version: "0.8.7", }, { version: "0.6.12", }, { version: "0.4.19", }, ], }, etherscan: { apiKey: ETHERSCAN_API_KEY, }, gasReporter: { enabled: true, currency: "USD", outputFile: "gas-report.txt", noColors: true, // coinmarketcap: COINMARKETCAP_API_KEY, }, namedAccounts: { deployer: { default: 0, // here this will by default take the first account as deployer 1: 0, // similarly on mainnet it will take the first account as deployer. Note though that depending on how hardhat network are configured, the account 0 on one network can be different than on another }, }, }`

PatrickAlphaC commented 1 year ago

Can you:

  1. Make this a discusson on the full repo? https://github.com/smartcontractkit/full-blockchain-solidity-course-js/
  2. Follow this section for formatting questions? https://www.youtube.com/watch?t=19846&v=gyMwXuJrbJQ&feature=youtu.be