Contracting testing: get NFT token id

Trying to get the NFT id for writing a simple contract test

Having a similar issue like here:

Where I’m not able to get the token ID for an NFT Contract:


Using the ERC721PresetMinterPauserAutoIdUpgradeable.sol contract

the CountersUpgradeable.Counter does assign a _tokenIdTracker to the minted NFT

as suggested from @abcoathup tried to get the NFT with balanceOf method.

console.log(‘balance of’, await this.DEPLOYED_CONTRACT_INSTANCE.balanceOf(accounts[0]));

Getting either balance of BN { negative: 0, words: [ 0, <1 empty item> ], length: 1, red: null }
or with .toString() method 0

:computer: Environment
@openzeppelin/contracts-upgradeable”: “^4.0.0”,
“truffle”: “^5.3.1”

:1234: Code to reproduce

1 Like

Hi @intoverq,

Please note, when using an upgradeable contract you need to initialize it.

You don’t have an initialize function yet, see:

Thanks for the information, updated the code.

Found a test implementation from openzepplin and that is passing without the “initialize” function.

it('deployer can mint tokens', async function () {
  const tokenId = new BN('0');

  const receipt = await, { from: deployer });
  expectEvent(receipt, 'Transfer', { from: ZERO_ADDRESS, to: other, tokenId });

  expect(await this.token.balanceOf(other))'1');
  expect(await this.token.ownerOf(tokenId)).to.equal(other);

  expect(await this.token.tokenURI(tokenId)).to.equal(baseURI + tokenId);
1 Like