I have a very simple function in my Solidity contract, that I'm trying to test its return value with Hardhat.
function mintNFT(address _recipient) public returns (uint256)
{
uint256 tokenId = calculateTokenID();
return tokenId;
}
where tokenId has some logic to generate a uint256. I've added a console.log(tokenId)
in the Smart Contract which correctly prints out the tokenId, however, when returned and attempted to test, it comes back as undefined
const { expect } = require('chai');
// Import utilities from Test Helpers
const { BN, expectEvent, expectRevert } = require('@openzeppelin/test-helpers');
// Load compiled artifacts
const CONTRACT = artifacts.require('MyContract');
// Start test block
contract('CONTRACT', function ([ owner, other ]) {
beforeEach(async function () {
this.contract = await CONTRACT.new();
await this.contract.initialize();
});
it("mintNFT generated a valid token ID", async function () {
const tokendID = await this.contract.mintNFT();
expect(tokendID.to.equal(1));
});
Error:
1) Contract: DPC
mintNFT generated a valid token ID:
TypeError: Cannot read properties of undefined (reading 'equal')
at Context.<anonymous> (test/DPC_NFT.js:29:24)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
I've even tried hard-coding the function return to a number, and the test still comes back as undefined. Would greately appreciate your help