git.delta.rocks / unique-network / refs/commits / 876ef621bd1e

difftreelog

source

tests/src/eth/collectionProperties.test.ts4.2 KiBsourcehistory
1import {itEth, usingEthPlaygrounds, expect} from './util/playgrounds';2import {IKeyringPair} from '@polkadot/types/types';34describe('EVM collection properties', () => {5  let donor: IKeyringPair;6  let alice: IKeyringPair;78  before(async function() {9    await usingEthPlaygrounds(async (_helper, privateKey) => {10      donor = privateKey('//Alice');11      [alice] = await _helper.arrange.createAccounts([10n], donor);12    });13  });1415  itEth('Can be set', async({helper}) => {16    const caller = await helper.eth.createAccountWithBalance(donor);17    const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test'});18    await collection.addAdmin(alice, {Ethereum: caller});1920    const address = helper.ethAddress.fromCollectionId(collection.collectionId);21    const contract = helper.ethNativeContract.collection(address, 'nft', caller);2223    await contract.methods.setCollectionProperty('testKey', Buffer.from('testValue')).send({from: caller});2425    const raw = (await collection.getData())?.raw;2627    expect(raw.properties[1].value).to.equal('testValue');28  });2930  itEth('Can be deleted', async({helper}) => {31    const caller = await helper.eth.createAccountWithBalance(donor);32    const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties: [{key: 'testKey', value: 'testValue'}]});3334    await collection.addAdmin(alice, {Ethereum: caller});3536    const address = helper.ethAddress.fromCollectionId(collection.collectionId);37    const contract = helper.ethNativeContract.collection(address, 'nft', caller);3839    await contract.methods.deleteCollectionProperty('testKey').send({from: caller});4041    const raw = (await collection.getData())?.raw;4243    expect(raw.properties.length).to.equal(0);44  });4546  itEth('Can be read', async({helper}) => {47    const caller = helper.eth.createAccount();48    const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties: [{key: 'testKey', value: 'testValue'}]});4950    const address = helper.ethAddress.fromCollectionId(collection.collectionId);51    const contract = helper.ethNativeContract.collection(address, 'nft', caller);5253    const value = await contract.methods.collectionProperty('testKey').call();54    expect(value).to.equal(helper.getWeb3().utils.toHex('testValue'));55  });56});5758describe('Supports ERC721Metadata', () => {59  let donor: IKeyringPair;6061  before(async function() {62    await usingEthPlaygrounds(async (_helper, privateKey) => {63      donor = privateKey('//Alice');64    });65  });6667  itEth('ERC721Metadata property can be set for NFT collection', async({helper}) => {68    const caller = await helper.eth.createAccountWithBalance(donor);69    const collection = await helper.nft.mintCollection(donor, {name: 'col', description: 'descr', tokenPrefix: 'COL'});7071    await collection.addAdmin(donor, {Ethereum: caller});72    const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);7374    await contract.methods.setCollectionProperty('ERC721Metadata', Buffer.from('1')).send({from: caller});7576    expect(await contract.methods.supportsInterface('0x5b5e139f').call()).to.be.true;7778    await contract.methods.setCollectionProperty('ERC721Metadata', Buffer.from('0')).send({from: caller});7980    expect(await contract.methods.supportsInterface('0x5b5e139f').call()).to.be.false;81  });8283  itEth('ERC721Metadata property can be set for RFT collection', async({helper}) => {84    const caller = await helper.eth.createAccountWithBalance(donor);85    const collection = await helper.rft.mintCollection(donor, {name: 'col', description: 'descr', tokenPrefix: 'COL'});8687    await collection.addAdmin(donor, {Ethereum: caller});8889    const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);9091    await contract.methods.setCollectionProperty('ERC721Metadata', Buffer.from('1')).send({from: caller});9293    expect(await contract.methods.supportsInterface('0x5b5e139f').call()).to.be.true;9495    await contract.methods.setCollectionProperty('ERC721Metadata', Buffer.from('0')).send({from: caller});9697    expect(await contract.methods.supportsInterface('0x5b5e139f').call()).to.be.false;98  });99});