git.delta.rocks / unique-network / refs/commits / 088ceb16caa8

difftreelog

source

tests/src/eth/collectionProperties.test.ts4.7 KiBsourcehistory
1import {itEth, usingEthPlaygrounds, expect} from './util/playgrounds';2import {IKeyringPair} from '@polkadot/types/types';3import {Pallets} from '../util/playgrounds';45describe('EVM collection properties', () => {6  let donor: IKeyringPair;7  let alice: IKeyringPair;89  before(async function() {10    await usingEthPlaygrounds(async (_helper, privateKey) => {11      donor = privateKey('//Alice');12      [alice] = await _helper.arrange.createAccounts([10n], donor);13    });14  });1516  itEth('Can be set', async({helper}) => {17    const caller = await helper.eth.createAccountWithBalance(donor);18    const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties: []});19    await collection.addAdmin(alice, {Ethereum: caller});2021    const address = helper.ethAddress.fromCollectionId(collection.collectionId);22    const contract = helper.ethNativeContract.collection(address, 'nft', caller);2324    await contract.methods.setCollectionProperty('testKey', Buffer.from('testValue')).send({from: caller});2526    const raw = (await collection.getData())?.raw;2728    expect(raw.properties[0].value).to.equal('testValue');29  });3031  itEth('Can be deleted', async({helper}) => {32    const caller = await helper.eth.createAccountWithBalance(donor);33    const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties: [{key: 'testKey', value: 'testValue'}]});3435    await collection.addAdmin(alice, {Ethereum: caller});3637    const address = helper.ethAddress.fromCollectionId(collection.collectionId);38    const contract = helper.ethNativeContract.collection(address, 'nft', caller);3940    await contract.methods.deleteCollectionProperty('testKey').send({from: caller});4142    const raw = (await collection.getData())?.raw;4344    expect(raw.properties.length).to.equal(0);45  });4647  itEth('Can be read', async({helper}) => {48    const caller = helper.eth.createAccount();49    const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties: [{key: 'testKey', value: 'testValue'}]});5051    const address = helper.ethAddress.fromCollectionId(collection.collectionId);52    const contract = helper.ethNativeContract.collection(address, 'nft', caller);5354    const value = await contract.methods.collectionProperty('testKey').call();55    expect(value).to.equal(helper.getWeb3().utils.toHex('testValue'));56  });57});5859describe('Supports ERC721Metadata', () => {60  let donor: IKeyringPair;6162  before(async function() {63    await usingEthPlaygrounds(async (_helper, privateKey) => {64      donor = privateKey('//Alice');65    });66  });6768  itEth('ERC721Metadata property can be set for NFT collection', async({helper}) => {69    const caller = await helper.eth.createAccountWithBalance(donor);70    const tokenPropertyPermissions = [{71      key: 'URI',72      permission: {73        mutable: true,74        collectionAdmin: true,75        tokenOwner: false,76      },77    }];78    const collection = await helper.nft.mintCollection(donor, {name: 'col', description: 'descr', tokenPrefix: 'COL', tokenPropertyPermissions});7980    await collection.addAdmin(donor, {Ethereum: caller});81    const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);8283    await contract.methods.setCollectionProperty('ERC721Metadata', Buffer.from('1')).send({from: caller});8485    expect(await contract.methods.supportsInterface('0x5b5e139f').call()).to.be.true;8687    await contract.methods.setCollectionProperty('ERC721Metadata', Buffer.from('0')).send({from: caller});8889    expect(await contract.methods.supportsInterface('0x5b5e139f').call()).to.be.false;90  });9192  itEth.ifWithPallets('ERC721Metadata property can be set for RFT collection', [Pallets.ReFungible], async({helper}) => {93    const caller = await helper.eth.createAccountWithBalance(donor);94    const tokenPropertyPermissions = [{95      key: 'URI',96      permission: {97        mutable: true,98        collectionAdmin: true,99        tokenOwner: false,100      },101    }];102    const collection = await helper.rft.mintCollection(donor, {name: 'col', description: 'descr', tokenPrefix: 'COL', tokenPropertyPermissions});103104    await collection.addAdmin(donor, {Ethereum: caller});105106    const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);107108    await contract.methods.setCollectionProperty('ERC721Metadata', Buffer.from('1')).send({from: caller});109110    expect(await contract.methods.supportsInterface('0x5b5e139f').call()).to.be.true;111112    await contract.methods.setCollectionProperty('ERC721Metadata', Buffer.from('0')).send({from: caller});113114    expect(await contract.methods.supportsInterface('0x5b5e139f').call()).to.be.false;115  });116});