git.delta.rocks / unique-network / refs/commits / 48f959311e08

difftreelog

source

tests/src/eth/collectionProperties.test.ts4.3 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 collection = await helper.nft.mintCollection(donor, {name: 'col', description: 'descr', tokenPrefix: 'COL'});7172    await collection.addAdmin(donor, {Ethereum: caller});73    const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);7475    await contract.methods.setCollectionProperty('ERC721Metadata', Buffer.from('1')).send({from: caller});7677    expect(await contract.methods.supportsInterface('0x5b5e139f').call()).to.be.true;7879    await contract.methods.setCollectionProperty('ERC721Metadata', Buffer.from('0')).send({from: caller});8081    expect(await contract.methods.supportsInterface('0x5b5e139f').call()).to.be.false;82  });8384  itEth.ifWithPallets('ERC721Metadata property can be set for RFT collection', [Pallets.ReFungible], async({helper}) => {85    const caller = await helper.eth.createAccountWithBalance(donor);86    const collection = await helper.rft.mintCollection(donor, {name: 'col', description: 'descr', tokenPrefix: 'COL'});8788    await collection.addAdmin(donor, {Ethereum: caller});8990    const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);9192    await contract.methods.setCollectionProperty('ERC721Metadata', Buffer.from('1')).send({from: caller});9394    expect(await contract.methods.supportsInterface('0x5b5e139f').call()).to.be.true;9596    await contract.methods.setCollectionProperty('ERC721Metadata', Buffer.from('0')).send({from: caller});9798    expect(await contract.methods.supportsInterface('0x5b5e139f').call()).to.be.false;99  });100});