Lesson 14 Assertion and Reference Errors #2742
-
After I addressed the issue on .env file I proceeded to test my BasicNft.sol file (yarn hardhat test). The compilation results are 12 passed and 2 failed. Please see details of items that failed below: 1) Random IPFS NFT Unit Tests
requestNft
fails if payment isn't sent with the request:
AssertionError: Expected transaction to be reverted with RandomIpfsNft__NeedMoreETHSent, but other exception was thrown: Error: VM Exception while processing transaction: reverted with custom error 'NeedMoreETHSent()'
2) Random IPFS NFT Unit Tests
requestNft
reverts if payment amount is less than the mint fee:
ReferenceError: mintFee is not defined Will somebody be able to help me address the errors. And what to do. Thanks in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
Repo please |
Beta Was this translation helpful? Give feedback.
-
Hi @krakxn I've cloned the repo of Patrick and as requested, please see details below: 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;
}
} BasicNft.test.js 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.getContract("BasicNft")
})
describe("Construtor", () => {
it("Initilizes 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", () => {
it("Allows users to mint an NFT, and updates appropriately", async function () {
const txResponse = await basicNft.mintNft()
await txResponse.wait(1)
const tokenURI = await basicNft.tokenURI(0)
const tokenCounter = await basicNft.getTokenCounter()
assert.equal(tokenCounter.toString(), "1")
assert.equal(tokenURI, await basicNft.TOKEN_URI())
})
})
}) Thanks in advance. |
Beta Was this translation helpful? Give feedback.
-
@Vic7Eugene The issues are in your Random Ipfs Nft test file, In your requestNFT describe await expect(randomIpfsNft.requestNFT()).to.be.revertedWithCustomError(randomIpfsNft,
"NeedMoreETHSent"
); Make sure spelling, this is mine so your spelling could be change.
If you still have query, you should send your Random Ipfs Nft test full code as well. |
Beta Was this translation helpful? Give feedback.
@Vic7Eugene The issues are in your Random Ipfs Nft test file, In your requestNFT describe
Make sure spelling, this is mine so your spelling could be change.
mintFee
it is not getting correctly, you should check the scope of it.If you still have query, you should send your Random Ipfs Nft test full code as well.