1

Plugin and tools used: hardhat-chai-matcher, chai, mocha

Issue:

prompted error on .owner() and .connect()

Was wonder if its my environment setup wrong, so i ran other test but theyre passing just alright:

enter image description here

This is my test script written

const { expect } = require("chai");
const { ethers } = require("hardhat");

describe("VolcanoNFT Test", function () {
 let owner, user1, VolcanoNFTFactory, volcanoNFT;

beforeEach(async () => {
    [owner, user1] = await ethers.getSigners();
    VolcanoNFTFactory = await ethers.getContractFactory("VolcanoNFT", owner.address);
    volcanoNFT = await VolcanoNFTFactory.deploy();
    await volcanoNFT.deployed();
    console.log("Deployed with:", owner.address);
    console.log("Contract Deployed to:", volcanoNFT.address);
});

describe("Deployment:", function () {
    it("Should be symbol - VOL", async function () {
        expect(await volcanoNFT.symbol()).to.equal("VOL");
    });

    it("Should be name - VolcanoNFT", async function () {
        expect(await volcanoNFT.name()).to.equal("Volcano");
    });
    
    it("Should deploy by owner address", async function () {
        expect(await volcanoNFT.owner()).to.equal(owner.address);
    });
});

describe("Minting:", function () {
    it("Should add balance of NFT for user", async function () {
        const minting = await volcanoNFT.connect(user1).mint();
        expect(await volcanoNFT.balanceOf(user1.address)).to.equal(1);
    });
});
});

This is my solidity:

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

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

contract VolcanoNFT is ERC721("Volcano", "VOL") {
 uint256 tokenId;
 constructor() {

}

function mint() public {
    _safeMint(msg.sender, tokenId);
    tokenId++;
}

function transfer() public {
}
}

What could be the problem?

1 Answer 1

1

your VolcanoNFT does not have an owner function

add the following import:

import '@openzeppelin/contracts/access/Ownable.sol';

and then inherit your contract from Ownable

contract VolcanoNFT is ..., Ownable {

read more here

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.