git.delta.rocks / unique-network / refs/commits / 2694afec2e83

difftreelog

source

tests/src/eth/metadata.test.ts6.1 KiBsourcehistory
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {expect} from 'chai';18import {createCollectionExpectSuccess} from '../util/helpers';19import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3, normalizeEvents} from './util/helpers';20import fungibleMetadataAbi from './fungibleMetadataAbi.json';21import privateKey from '../substrate/privateKey';22import {submitTransactionAsync} from '../substrate/substrate-api';23import nonFungibleAbi from './nonFungibleAbi.json';2425describe('Common metadata', () => {26  itWeb3('Returns collection name', async ({api, web3}) => {27    const collection = await createCollectionExpectSuccess({28      name: 'token name',29      mode: {type: 'NFT'},30    });31    const caller = await createEthAccountWithBalance(api, web3);3233    const address = collectionIdToAddress(collection);34    const contract = new web3.eth.Contract(fungibleMetadataAbi as any, address, {from: caller, ...GAS_ARGS});35    const name = await contract.methods.name().call();3637    expect(name).to.equal('token name');38  });3940  itWeb3('Returns symbol name', async ({api, web3}) => {41    const collection = await createCollectionExpectSuccess({42      tokenPrefix: 'TOK',43      mode: {type: 'NFT'},44    });45    const caller = await createEthAccountWithBalance(api, web3);4647    const address = collectionIdToAddress(collection);48    const contract = new web3.eth.Contract(fungibleMetadataAbi as any, address, {from: caller, ...GAS_ARGS});49    const symbol = await contract.methods.symbol().call();5051    expect(symbol).to.equal('TOK');52  });53});5455describe('Fungible metadata', () => {56  itWeb3('Returns fungible decimals', async ({api, web3}) => {57    const collection = await createCollectionExpectSuccess({58      mode: {type: 'Fungible', decimalPoints: 6},59    });60    const caller = await createEthAccountWithBalance(api, web3);6162    const address = collectionIdToAddress(collection);63    const contract = new web3.eth.Contract(fungibleMetadataAbi as any, address, {from: caller, ...GAS_ARGS});64    const decimals = await contract.methods.decimals().call();6566    expect(+decimals).to.equal(6);67  });68});6970describe.only('Support ERC721Metadata', () => {71  itWeb3('Check unsupport ERC721Metadata ShemaVersion::Unique', async ({web3, api}) => {72    const collectionId = await createCollectionExpectSuccess({73      mode: {type: 'NFT'},74      shemaVersion: 'Unique',75    });76    const collection = await api.rpc.unique.collectionById(collectionId);77    expect(collection.isSome).to.be.true;78    expect(collection.unwrap().schemaVersion.toHuman()).to.be.eq('Unique');7980    const alice = privateKey('//Alice');8182    const caller = await createEthAccountWithBalance(api, web3);83    const changeAdminTx = api.tx.unique.addCollectionAdmin(collectionId, {Ethereum: caller});84    await submitTransactionAsync(alice, changeAdminTx);8586    const address = collectionIdToAddress(collectionId);87    const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});8889    await expect(contract.methods.name().call()).to.be.rejectedWith('Unsupported shema version! Support only ImageURL');90    await expect(contract.methods.symbol().call()).to.be.rejectedWith('Unsupported shema version! Support only ImageURL');9192    const receiver = createEthAccount(web3);93    const nextTokenId = await contract.methods.nextTokenId().call();94    expect(nextTokenId).to.be.equal('1');95    await expect(contract.methods.mintWithTokenURI(96      receiver,97      nextTokenId,98      'Test URI',99    ).send({from: caller})).to.be.rejected;100101    await expect(contract.methods.mintBulkWithTokenURI(102      receiver,103      [104        [nextTokenId, 'Test URI 0'],105        [+nextTokenId + 1, 'Test URI 1'],106        [+nextTokenId + 2, 'Test URI 2'],107      ],108    ).send({from: caller})).to.be.rejected;109  });110111  itWeb3('Check support ERC721Metadata for ShemaVersion::ImageURL', async ({web3, api}) => {112    const collectionId = await createCollectionExpectSuccess({113      mode: {type: 'NFT'},114      name: 'some_name',115      tokenPrefix: 'some_prefix',116    });117    const collection = await api.rpc.unique.collectionById(collectionId);118    expect(collection.isSome).to.be.true;119    expect(collection.unwrap().schemaVersion.toHuman()).to.be.eq('ImageURL');120121    const alice = privateKey('//Alice');122123    const caller = await createEthAccountWithBalance(api, web3);124    const changeAdminTx = api.tx.unique.addCollectionAdmin(collectionId, {Ethereum: caller});125    await submitTransactionAsync(alice, changeAdminTx);126127    const address = collectionIdToAddress(collectionId);128    const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});129    130    expect(await contract.methods.name().call()).to.be.eq('some_name');131    expect(await contract.methods.symbol().call()).to.be.eq('some_prefix');132133    const receiver = createEthAccount(web3);134    const nextTokenId = await contract.methods.nextTokenId().call();135    expect(nextTokenId).to.be.equal('1');136    const result = await contract.methods.mintWithTokenURI(137      receiver,138      nextTokenId,139      'Test URI',140    ).send({from: caller});141    const events = normalizeEvents(result.events);142143    expect(events).to.be.deep.equal([144      {145        address,146        event: 'Transfer',147        args: {148          from: '0x0000000000000000000000000000000000000000',149          to: receiver,150          tokenId: nextTokenId,151        },152      },153    ]);154155    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');156  });157});158