Testing Counters.Counter (current, increment, etc) THROUGH minted nft

I am using js to test contracts (hardhat, ethers, etc) and I am returning a uint256 tokenId that was created using

uint256 newItemId = _tokenIds.current();

And after, I increment the counter and return the newItemId from the mint function.

In my test I mint to tokens:

const connectedMinter = await nft.connect(minter);
const tx1 = await connectedMinter.mintCollectable(tokenUri);
const tx2 = await connectedMinter.mintCollectable(tokenUri);

The tx object I get back (which isnt the return of the mint function, which is supposed to return a uint256 tokenId) doesn't have the tokenId.

It has a value, but I am guessing that is the msg.value, ie the ether amount.

How should I test the increment without stubbing or calling directly like you guys do here


I just want to get back the uint256 tokenId so I can use it in sequential tests.. I know I can stub it with

BN("0"), BN("1"), BN("2") because I know it is sequential, but is there a better way?

I LOVE THIS PROJECT and all the hard work done by the team and the contributors. You guys really make smart contracts fun to write.

Thanks in advance!

1 Like

Thank you for your nice comments!

One of the ways in which you can get the tokenId is by looking for the Transfer event in the transaction receipt.

tx1 represents the transaction request, and you can get the receipt with await tx1.wait(). In the receipt you will find a list of events, and you should look for the Transfer event, and you should find the tokenId there!