difftreelog
CORE-302 Add test for tokenURI
in: master
1 file changed
tests/src/eth/createCollection.test.tsdiffbeforeafterboth14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.161617import nonFungibleAbi from './nonFungibleAbi.json';17import {ApiPromise} from '@polkadot/api';18import {ApiPromise} from '@polkadot/api';18import {evmToAddress} from '@polkadot/util-crypto';19import {evmToAddress} from '@polkadot/util-crypto';19import {expect} from 'chai';20import {expect} from 'chai';20import {getCreatedCollectionCount, getDetailedCollectionInfo} from '../util/helpers';21import {getCreatedCollectionCount, getDetailedCollectionInfo} from '../util/helpers';21import {collectionHelper, collectionIdFromAddress, createEthAccount, createEthAccountWithBalance, itWeb3, normalizeAddress} from './util/helpers';22import {23 collectionHelper,24 collectionIdFromAddress,25 collectionIdToAddress,26 createEthAccount,27 createEthAccountWithBalance,28 GAS_ARGS,29 itWeb3,30 normalizeAddress,31 normalizeEvents,32} from './util/helpers';223323async function getCollectionAddressFromResult(api: ApiPromise, result: any) {34async function getCollectionAddressFromResult(api: ApiPromise, result: any) {104 itWeb3('Set limits', async ({api, web3}) => {115 itWeb3('Set limits', async ({api, web3}) => {105 const owner = await createEthAccountWithBalance(api, web3);116 const owner = await createEthAccountWithBalance(api, web3);106 const helper = collectionHelper(web3, owner);117 const helper = collectionHelper(web3, owner);107 const result = await helper.methods.create721Collection('Const collection', '4', '4').send();118 const result = await helper.methods.create721Collection('Const collection', '5', '5').send();108 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);119 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);109 const limits = {120 const limits = {110 accountTokenOwnershipLimit: 1000,121 accountTokenOwnershipLimit: 1000,133 expect(collection.limits.transfersEnabled.toHuman()).to.be.eq(limits.transfersEnabled);144 expect(collection.limits.transfersEnabled.toHuman()).to.be.eq(limits.transfersEnabled);134 });145 });146147 itWeb3('Check tokenURI', async ({web3, api}) => {148 const owner = await createEthAccountWithBalance(api, web3);149 const helper = collectionHelper(web3, owner);150 let result = await helper.methods.create721Collection('Mint collection', '6', '6').send();151 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);152 const receiver = createEthAccount(web3);153 const contract = new web3.eth.Contract(nonFungibleAbi as any, collectionIdAddress.toLowerCase(), {from: owner, ...GAS_ARGS});154 const nextTokenId = await contract.methods.nextTokenId().call();155156 expect(nextTokenId).to.be.equal('1');157 result = await contract.methods.mintWithTokenURI(158 receiver,159 nextTokenId,160 'Test URI',161 ).send();162163 const events = normalizeEvents(result.events);164 const address = collectionIdToAddress(collectionId);165166 expect(events).to.be.deep.equal([167 {168 address,169 event: 'Transfer',170 args: {171 from: '0x0000000000000000000000000000000000000000',172 to: receiver,173 tokenId: nextTokenId,174 },175 },176 ]);177178 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');179180 // TODO: this wont work right now, need release 919000 first181 // await helper.methods.setOffchainShema(collectionIdAddress, 'https://offchain-service.local/token-info/{id}').send();182 // const tokenUri = await contract.methods.tokenURI(nextTokenId).call();183 // expect(tokenUri).to.be.equal(`https://offchain-service.local/token-info/${nextTokenId}`);184 });135});185});136186137describe('(!negative tests!) Create collection from EVM', () => {187describe('(!negative tests!) Create collection from EVM', () => {