ERC721Royalty.test.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. const { ethers } = require('hardhat');
  2. const { expect } = require('chai');
  3. const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
  4. const { shouldBehaveLikeERC2981 } = require('../../common/ERC2981.behavior');
  5. const name = 'Non Fungible Token';
  6. const symbol = 'NFT';
  7. const tokenId1 = 1n;
  8. const tokenId2 = 2n;
  9. const royalty = 200n;
  10. const salePrice = 1000n;
  11. async function fixture() {
  12. const [account1, account2, recipient] = await ethers.getSigners();
  13. const token = await ethers.deployContract('$ERC721Royalty', [name, symbol]);
  14. await token.$_mint(account1, tokenId1);
  15. await token.$_mint(account1, tokenId2);
  16. return { account1, account2, recipient, token };
  17. }
  18. describe('ERC721Royalty', function () {
  19. beforeEach(async function () {
  20. Object.assign(
  21. this,
  22. await loadFixture(fixture),
  23. { tokenId1, tokenId2, royalty, salePrice }, // set for behavior tests
  24. );
  25. });
  26. describe('token specific functions', function () {
  27. beforeEach(async function () {
  28. await this.token.$_setTokenRoyalty(tokenId1, this.recipient, royalty);
  29. });
  30. it('royalty information are kept during burn and re-mint', async function () {
  31. await this.token.$_burn(tokenId1);
  32. expect(await this.token.royaltyInfo(tokenId1, salePrice)).to.deep.equal([
  33. this.recipient.address,
  34. (salePrice * royalty) / 10000n,
  35. ]);
  36. await this.token.$_mint(this.account2, tokenId1);
  37. expect(await this.token.royaltyInfo(tokenId1, salePrice)).to.deep.equal([
  38. this.recipient.address,
  39. (salePrice * royalty) / 10000n,
  40. ]);
  41. });
  42. });
  43. shouldBehaveLikeERC2981();
  44. });