2

I´m new to solidity and wonder how I`m writing a uint test for this contract in hardhat:

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

import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";

contract Web3 is ERC721URIStorage {
    uint256 Web3_Token_ID;

    constructor() ERC721("Web3NFT", "Web3N") {}

    function mintNFT(
        address _userOne,
        address _userTwo,
        string memory tokenURI
    ) public {
        _mint(_userOne, Web3_Token_ID);
        _setTokenURI(Web3_Token_ID, tokenURI);
        Web3_Token_ID++;

        _mint(_userTwo, Web3_Token_ID);
        _setTokenURI(Web_Token_ID, tokenURI);
        Web3_Token_ID++;
    }
}

1 Answer 1

2

When you create a new hardhat project there is a really good example test.

The docs also explain it step by step https://hardhat.org/tutorial/testing-contracts

You can run the test for the default greeter contract in the project by running npx hardhat test

For your specific test first I'd check that Web3_Token_ID is 0, that _userOne and _userTwo balance is 0 (by using balanceOf(_userOne) on the contract), then call your mint() function, and checking the same balances and Web3_Token_ID again to see if they were updated properly

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.