1import {itEth, usingEthPlaygrounds, expect, EthUniqueHelper} from './util/playgrounds';2import {IKeyringPair} from '@polkadot/types/types';3import {Pallets} from '../util/playgrounds';4import {IProperty, ITokenPropertyPermission} from "../util/playgrounds/types";56describe('EVM collection properties', () => {7 let donor: IKeyringPair;8 let alice: IKeyringPair;910 before(async function() {11 await usingEthPlaygrounds(async (_helper, privateKey) => {12 donor = privateKey('//Alice');13 [alice] = await _helper.arrange.createAccounts([10n], donor);14 });15 });1617 itEth('Can be set', async({helper}) => {18 const caller = await helper.eth.createAccountWithBalance(donor);19 const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties: []});20 await collection.addAdmin(alice, {Ethereum: caller});2122 const address = helper.ethAddress.fromCollectionId(collection.collectionId);23 const contract = helper.ethNativeContract.collection(address, 'nft', caller);2425 await contract.methods.setCollectionProperty('testKey', Buffer.from('testValue')).send({from: caller});2627 const raw = (await collection.getData())?.raw;2829 expect(raw.properties[0].value).to.equal('testValue');30 });3132 itEth('Can be deleted', async({helper}) => {33 const caller = await helper.eth.createAccountWithBalance(donor);34 const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties: [{key: 'testKey', value: 'testValue'}]});3536 await collection.addAdmin(alice, {Ethereum: caller});3738 const address = helper.ethAddress.fromCollectionId(collection.collectionId);39 const contract = helper.ethNativeContract.collection(address, 'nft', caller);4041 await contract.methods.deleteCollectionProperty('testKey').send({from: caller});4243 const raw = (await collection.getData())?.raw;4445 expect(raw.properties.length).to.equal(0);46 });4748 itEth('Can be read', async({helper}) => {49 const caller = helper.eth.createAccount();50 const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties: [{key: 'testKey', value: 'testValue'}]});5152 const address = helper.ethAddress.fromCollectionId(collection.collectionId);53 const contract = helper.ethNativeContract.collection(address, 'nft', caller);5455 const value = await contract.methods.collectionProperty('testKey').call();56 expect(value).to.equal(helper.getWeb3().utils.toHex('testValue'));57 });58});5960describe('Supports ERC721Metadata', () => {61 let donor: IKeyringPair;6263 before(async function() {64 await usingEthPlaygrounds(async (_helper, privateKey) => {65 donor = privateKey('//Alice');66 });67 });6869 const checkERC721Metadata = async (helper: EthUniqueHelper, mode: 'nft' | 'rft') => {70 const caller = await helper.eth.createAccountWithBalance(donor);71 const bruh = await helper.eth.createAccountWithBalance(donor);7273 const BASE_URI = 'base/'74 const SUFFIX = 'suffix1'75 const URI = 'uri1'7677 const collectionHelpers = helper.ethNativeContract.collectionHelpers(caller);78 const creatorMethod = mode === 'rft' ? 'createRFTCollection' : 'createNFTCollection'7980 const {collectionId, collectionAddress} = await helper.eth[creatorMethod](caller, 'n', 'd', 'p')8182 const contract = helper.ethNativeContract.collectionById(collectionId, mode, caller);83 await contract.methods.addCollectionAdmin(bruh).send(); 8485 const collection1 = await helper.nft.getCollectionObject(collectionId);86 const data1 = await collection1.getData()87 expect(data1?.raw.flags.erc721metadata).to.be.false;88 expect(await contract.methods.supportsInterface('0x5b5e139f').call()).to.be.false;8990 await collectionHelpers.methods.makeCollectionERC721MetadataCompatible(collectionAddress, BASE_URI)91 .send({from: bruh});9293 expect(await contract.methods.supportsInterface('0x5b5e139f').call()).to.be.true;9495 const collection2 = await helper.nft.getCollectionObject(collectionId);96 const data2 = await collection2.getData()97 expect(data2?.raw.flags.erc721metadata).to.be.true;9899 const TPPs = data2?.raw.tokenPropertyPermissions100 expect(TPPs?.length).to.equal(2);101102 expect(TPPs.find((tpp: ITokenPropertyPermission) => {103 return tpp.key === "URI" && tpp.permission.mutable && tpp.permission.collectionAdmin && !tpp.permission.tokenOwner104 })).to.be.not.null105106 expect(TPPs.find((tpp: ITokenPropertyPermission) => {107 return tpp.key === "URISuffix" && tpp.permission.mutable && tpp.permission.collectionAdmin && !tpp.permission.tokenOwner108 })).to.be.not.null109110 expect(data2?.raw.properties?.find((property: IProperty) => {111 return property.key === "baseURI" && property.value === BASE_URI112 })).to.be.not.null113114 const token1Result = await contract.methods.mint(bruh).send();115 const tokenId1 = token1Result.events.Transfer.returnValues.tokenId;116117 expect(await contract.methods.tokenURI(tokenId1).call()).to.equal(BASE_URI);118119 await contract.methods.setProperty(tokenId1, "URISuffix", Buffer.from(SUFFIX)).send();120 expect(await contract.methods.tokenURI(tokenId1).call()).to.equal(BASE_URI + SUFFIX);121122 await contract.methods.setProperty(tokenId1, "URI", Buffer.from(URI)).send();123 expect(await contract.methods.tokenURI(tokenId1).call()).to.equal(URI);124125 await contract.methods.deleteProperty(tokenId1, "URI").send();126 expect(await contract.methods.tokenURI(tokenId1).call()).to.equal(BASE_URI + SUFFIX);127128 const token2Result = await contract.methods.mintWithTokenURI(bruh, URI).send();129 const tokenId2 = token2Result.events.Transfer.returnValues.tokenId;130131 expect(await contract.methods.tokenURI(tokenId2).call()).to.equal(URI);132133 await contract.methods.deleteProperty(tokenId2, "URI").send();134 expect(await contract.methods.tokenURI(tokenId2).call()).to.equal(BASE_URI);135136 await contract.methods.setProperty(tokenId2, "URISuffix", Buffer.from(SUFFIX)).send();137 expect(await contract.methods.tokenURI(tokenId2).call()).to.equal(BASE_URI + SUFFIX);138 }139140 itEth('ERC721Metadata property can be set for NFT collection', async({helper}) => {141 await checkERC721Metadata(helper, 'nft');142 });143144 itEth.ifWithPallets('ERC721Metadata property can be set for RFT collection', [Pallets.ReFungible], async({helper}) => {145 await checkERC721Metadata(helper, 'rft');146 });147});