ERC6909ContentURI.test.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. const { ethers } = require('hardhat');
  2. const { expect } = require('chai');
  3. const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
  4. async function fixture() {
  5. const token = await ethers.deployContract('$ERC6909ContentURI');
  6. return { token };
  7. }
  8. describe('ERC6909ContentURI', function () {
  9. beforeEach(async function () {
  10. Object.assign(this, await loadFixture(fixture));
  11. });
  12. describe('contractURI', function () {
  13. it('is empty string by default', async function () {
  14. await expect(this.token.contractURI()).to.eventually.equal('');
  15. });
  16. it('is settable by internal setter', async function () {
  17. await this.token.$_setContractURI('https://example.com');
  18. await expect(this.token.contractURI()).to.eventually.equal('https://example.com');
  19. });
  20. it('emits an event when set', async function () {
  21. await expect(this.token.$_setContractURI('https://example.com')).to.emit(this.token, 'ContractURIUpdated');
  22. });
  23. });
  24. describe('tokenURI', function () {
  25. it('is empty string by default', async function () {
  26. await expect(this.token.tokenURI(1n)).to.eventually.equal('');
  27. });
  28. it('can be set by dedicated setter', async function () {
  29. await this.token.$_setTokenURI(1n, 'https://example.com/1');
  30. await expect(this.token.tokenURI(1n)).to.eventually.equal('https://example.com/1');
  31. // Only set for the specified token ID
  32. await expect(this.token.tokenURI(2n)).to.eventually.equal('');
  33. });
  34. it('emits an event when set', async function () {
  35. await expect(this.token.$_setTokenURI(1n, 'https://example.com/1'))
  36. .to.emit(this.token, 'URI')
  37. .withArgs('https://example.com/1', 1n);
  38. });
  39. });
  40. });