git.delta.rocks / unique-network / refs/commits / 994aeb14c5bb

difftreelog

Add checks to mintCross tests

Max Andreev2022-12-21parent: #fce9c8f.patch.diff
in: master

3 files changed

modifiedtests/src/eth/fungible.test.tsdiffbeforeafterboth
--- a/tests/src/eth/fungible.test.ts
+++ b/tests/src/eth/fungible.test.ts
@@ -79,23 +79,40 @@
     expect(event.returnValues.value).to.equal('100');
   });
   
+  [
+    'substrate' as const,
+    'ethereum' as const,
+  ].map(testCase => {
+    itEth(`Can perform mintCross() for ${testCase} address`, async ({helper}) => {
+      // 1. Create receiver depending on the test case:
+      const receiverEth = helper.eth.createAccount();
+      const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);
+      const receiverSub = owner;
+      const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(owner);
+
+      const ethOwner = await helper.eth.createAccountWithBalance(donor);
+      const collection = await helper.ft.mintCollection(alice);
+      await collection.addAdmin(alice, {Ethereum: ethOwner});
   
-  itEth('Can perform mintCross()', async ({helper}) => {
-    const receiverCross = helper.ethCrossAccount.fromKeyringPair(owner);
-    const ethOwner = await helper.eth.createAccountWithBalance(donor);
-    const collection = await helper.ft.mintCollection(alice);
-    await collection.addAdmin(alice, {Ethereum: ethOwner});
-
-    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
-    const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', ethOwner);
+      const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+      const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'ft', ethOwner);
+  
+      // 2. Mint tokens:
+      const result = await collectionEvm.methods.mintCross(testCase === 'ethereum' ? receiverCrossEth : receiverCrossSub, 100).send();
+      
+      const event = result.events.Transfer;
+      expect(event.address).to.equal(collectionAddress);
+      expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');
+      expect(event.returnValues.to).to.equal(testCase === 'ethereum' ? receiverEth : helper.address.substrateToEth(receiverSub.address));
+      expect(event.returnValues.value).to.equal('100');
 
-    const result = await contract.methods.mintCross(receiverCross, 100).send();
-    
-    const event = result.events.Transfer;
-    expect(event.address).to.equal(collectionAddress);
-    expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');
-    expect(event.returnValues.to).to.equal(helper.address.substrateToEth(owner.address));
-    expect(event.returnValues.value).to.equal('100');
+      // 3. Get balance depending on the test case:
+      let balance;
+      if (testCase === 'ethereum') balance = await collection.getBalance({Ethereum: receiverEth});
+      else if (testCase === 'substrate') balance = await collection.getBalance({Substrate: receiverSub.address});
+      // 3.1 Check balance:
+      expect(balance).to.eq(100n);
+    });
   });
 
   itEth('Can perform mintBulk()', async ({helper}) => {
modifiedtests/src/eth/nonFungible.test.tsdiffbeforeafterboth
before · tests/src/eth/nonFungible.test.ts
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 {itEth, usingEthPlaygrounds, expect, EthUniqueHelper} from './util';18import {IKeyringPair} from '@polkadot/types/types';19import {Contract} from 'web3-eth-contract';20import {ITokenPropertyPermission} from '../util/playgrounds/types';212223describe('NFT: Information getting', () => {24  let donor: IKeyringPair;25  let alice: IKeyringPair;2627  before(async function() {28    await usingEthPlaygrounds(async (helper, privateKey) => {29      donor = await privateKey({filename: __filename});30      [alice] = await helper.arrange.createAccounts([10n], donor);31    });32  });3334  itEth('totalSupply', async ({helper}) => {35    const collection = await helper.nft.mintCollection(alice, {});36    await collection.mintToken(alice);3738    const caller = await helper.eth.createAccountWithBalance(donor);3940    const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);41    const totalSupply = await contract.methods.totalSupply().call();4243    expect(totalSupply).to.equal('1');44  });4546  itEth('balanceOf', async ({helper}) => {47    const collection = await helper.nft.mintCollection(alice, {});48    const caller = await helper.eth.createAccountWithBalance(donor);4950    await collection.mintToken(alice, {Ethereum: caller});51    await collection.mintToken(alice, {Ethereum: caller});52    await collection.mintToken(alice, {Ethereum: caller});5354    const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);55    const balance = await contract.methods.balanceOf(caller).call();5657    expect(balance).to.equal('3');58  });5960  itEth('ownerOf', async ({helper}) => {61    const collection = await helper.nft.mintCollection(alice, {});62    const caller = await helper.eth.createAccountWithBalance(donor);6364    const token = await collection.mintToken(alice, {Ethereum: caller});6566    const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);6768    const owner = await contract.methods.ownerOf(token.tokenId).call();6970    expect(owner).to.equal(caller);71  });7273  itEth('name/symbol is available regardless of ERC721Metadata support', async ({helper}) => {74    const collection = await helper.nft.mintCollection(alice, {name: 'test', tokenPrefix: 'TEST'});75    const caller = helper.eth.createAccount();7677    const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);7879    expect(await contract.methods.name().call()).to.equal('test');80    expect(await contract.methods.symbol().call()).to.equal('TEST');81  });82});8384describe('Check ERC721 token URI for NFT', () => {85  let donor: IKeyringPair;8687  before(async function() {88    await usingEthPlaygrounds(async (_helper, privateKey) => {89      donor = await privateKey({filename: __filename});90    });91  });9293  async function setup(helper: EthUniqueHelper, baseUri: string, propertyKey?: string, propertyValue?: string): Promise<{contract: Contract, nextTokenId: string}> {94    const owner = await helper.eth.createAccountWithBalance(donor);95    const receiver = helper.eth.createAccount();9697    const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'Mint collection', 'a', 'b', baseUri);98    const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);99100    const result = await contract.methods.mint(receiver).send();101    const tokenId = result.events.Transfer.returnValues.tokenId;102    expect(tokenId).to.be.equal('1');103104    if (propertyKey && propertyValue) {105      // Set URL or suffix106      await contract.methods.setProperties(tokenId, [{key: propertyKey, value: Buffer.from(propertyValue)}]).send();107    }108109    const event = result.events.Transfer;110    expect(event.address).to.be.equal(collectionAddress);111    expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');112    expect(event.returnValues.to).to.be.equal(receiver);113    expect(event.returnValues.tokenId).to.be.equal(tokenId);114115    return {contract, nextTokenId: tokenId};116  }117118  itEth('Empty tokenURI', async ({helper}) => {119    const {contract, nextTokenId} = await setup(helper, '');120    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('');121  });122123  itEth('TokenURI from url', async ({helper}) => {124    const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'URI', 'Token URI');125    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Token URI');126  });127128  itEth('TokenURI from baseURI', async ({helper}) => {129    const {contract, nextTokenId} = await setup(helper, 'BaseURI_');130    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_');131  });132133  itEth('TokenURI from baseURI + suffix', async ({helper}) => {134    const suffix = '/some/suffix';135    const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'URISuffix', suffix);136    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_' + suffix);137  });138});139140describe('NFT: Plain calls', () => {141  let donor: IKeyringPair;142  let minter: IKeyringPair;143  let bob: IKeyringPair;144  let charlie: IKeyringPair;145146  before(async function() {147    await usingEthPlaygrounds(async (helper, privateKey) => {148      donor = await privateKey({filename: __filename});149      [minter, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);150    });151  });152153  itEth('Can perform mint() & get crossOwner()', async ({helper}) => {154    const owner = await helper.eth.createAccountWithBalance(donor);155    const receiver = helper.eth.createAccount();156157    const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'Mint collection', '6', '6', '');158    const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);159160    const result = await contract.methods.mintWithTokenURI(receiver, 'Test URI').send();161    const tokenId = result.events.Transfer.returnValues.tokenId;162    expect(tokenId).to.be.equal('1');163164    const event = result.events.Transfer;165    expect(event.address).to.be.equal(collectionAddress);166    expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');167    expect(event.returnValues.to).to.be.equal(receiver);168169    expect(await contract.methods.tokenURI(tokenId).call()).to.be.equal('Test URI');170    console.log(await contract.methods.crossOwnerOf(tokenId).call());171    expect(await contract.methods.crossOwnerOf(tokenId).call()).to.be.like([receiver, '0']);172    // TODO: this wont work right now, need release 919000 first173    // await helper.methods.setOffchainSchema(collectionIdAddress, 'https://offchain-service.local/token-info/{id}').send();174    // const tokenUri = await contract.methods.tokenURI(nextTokenId).call();175    // expect(tokenUri).to.be.equal(`https://offchain-service.local/token-info/${nextTokenId}`);176  });177  178  itEth('Can perform mintCross()', async ({helper}) => {179    const caller = await helper.eth.createAccountWithBalance(donor);180    const receiverCross = helper.ethCrossAccount.fromKeyringPair(bob);181    const properties = Array(5).fill(0).map((_, i) => { return {key: `key_${i}`, value: Buffer.from(`value_${i}`)}; });182    const permissions: ITokenPropertyPermission[] = properties183      .map(p => {184        return {185          key: p.key, permission: {186            tokenOwner: true,187            collectionAdmin: true,188            mutable: true,189          },190        };191      });192    193    194    const collection = await helper.nft.mintCollection(minter, {195      tokenPrefix: 'ethp',196      tokenPropertyPermissions: permissions,197    });198    await collection.addAdmin(minter, {Ethereum: caller});199    200    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);201    const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', caller, true);202    let expectedTokenId = await contract.methods.nextTokenId().call();203    let result = await contract.methods.mintCross(receiverCross, []).send();204    let tokenId = result.events.Transfer.returnValues.tokenId;205    expect(tokenId).to.be.equal(expectedTokenId);206207    let event = result.events.Transfer;208    expect(event.address).to.be.equal(collectionAddress);209    expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');210    expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(bob.address));211    expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);212    213    expectedTokenId = await contract.methods.nextTokenId().call();214    result = await contract.methods.mintCross(receiverCross, properties).send();215    event = result.events.Transfer;216    expect(event.address).to.be.equal(collectionAddress);217    expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');218    expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(bob.address));219    expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);220    221    tokenId = result.events.Transfer.returnValues.tokenId;222    223    expect(tokenId).to.be.equal(expectedTokenId);224225    expect(await contract.methods.properties(tokenId, []).call()).to.be.like(properties226      .map(p => { return helper.ethProperty.property(p.key, p.value.toString()); }));227  });228  229  //TODO: CORE-302 add eth methods230  itEth.skip('Can perform mintBulk()', async ({helper}) => {231    const caller = await helper.eth.createAccountWithBalance(donor);232    const receiver = helper.eth.createAccount();233234    const collection = await helper.nft.mintCollection(minter);235    await collection.addAdmin(minter, {Ethereum: caller});236237    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);238    const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', caller);239    {240      const bulkSize = 3;241      const nextTokenId = await contract.methods.nextTokenId().call();242      expect(nextTokenId).to.be.equal('1');243      const result = await contract.methods.mintBulkWithTokenURI(244        receiver,245        Array.from({length: bulkSize}, (_, i) => (246          [+nextTokenId + i, `Test URI ${i}`]247        )),248      ).send({from: caller});249250      const events = result.events.Transfer.sort((a: any, b: any) => +a.returnValues.tokenId - b.returnValues.tokenId);251      for (let i = 0; i < bulkSize; i++) {252        const event = events[i];253        expect(event.address).to.equal(collectionAddress);254        expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');255        expect(event.returnValues.to).to.equal(receiver);256        expect(event.returnValues.tokenId).to.equal(`${+nextTokenId + i}`);257258        expect(await contract.methods.tokenURI(+nextTokenId + i).call()).to.be.equal(`Test URI ${i}`);259      }260    }261  });262263  itEth('Can perform burn()', async ({helper}) => {264    const caller = await helper.eth.createAccountWithBalance(donor);265266    const collection = await helper.nft.mintCollection(minter, {});267    const {tokenId} = await collection.mintToken(minter, {Ethereum: caller});268269    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);270    const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', caller);271272    {273      const result = await contract.methods.burn(tokenId).send({from: caller});274275      const event = result.events.Transfer;276      expect(event.address).to.be.equal(collectionAddress);277      expect(event.returnValues.from).to.be.equal(caller);278      expect(event.returnValues.to).to.be.equal('0x0000000000000000000000000000000000000000');279      expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);280    }281  });282283  itEth('Can perform approve()', async ({helper}) => {284    const owner = await helper.eth.createAccountWithBalance(donor);285    const spender = helper.eth.createAccount();286287    const collection = await helper.nft.mintCollection(minter, {});288    const {tokenId} = await collection.mintToken(minter, {Ethereum: owner});289290    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);291    const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);292293    {294      const result = await contract.methods.approve(spender, tokenId).send({from: owner});295296      const event = result.events.Approval;297      expect(event.address).to.be.equal(collectionAddress);298      expect(event.returnValues.owner).to.be.equal(owner);299      expect(event.returnValues.approved).to.be.equal(spender);300      expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);301    }302  });303304  itEth('Can perform setApprovalForAll()', async ({helper}) => {305    const owner = await helper.eth.createAccountWithBalance(donor);306    const operator = helper.eth.createAccount();307308    const collection = await helper.nft.mintCollection(minter, {});309310    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);311    const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);312313    const approvedBefore = await contract.methods.isApprovedForAll(owner, operator).call();314    expect(approvedBefore).to.be.equal(false);315316    {317      const result = await contract.methods.setApprovalForAll(operator, true).send({from: owner});318319      expect(result.events.ApprovalForAll).to.be.like({320        address: collectionAddress,321        event: 'ApprovalForAll',322        returnValues: {323          owner,324          operator,325          approved: true,326        },327      });328329      const approvedAfter = await contract.methods.isApprovedForAll(owner, operator).call();330      expect(approvedAfter).to.be.equal(true);331    }332333    {334      const result = await contract.methods.setApprovalForAll(operator, false).send({from: owner});335336      expect(result.events.ApprovalForAll).to.be.like({337        address: collectionAddress,338        event: 'ApprovalForAll',339        returnValues: {340          owner,341          operator,342          approved: false,343        },344      });345346      const approvedAfter = await contract.methods.isApprovedForAll(owner, operator).call();347      expect(approvedAfter).to.be.equal(false);348    }349  });350351  itEth('Can perform burn with ApprovalForAll', async ({helper}) => {352    const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});353354    const owner = await helper.eth.createAccountWithBalance(donor);355    const operator = await helper.eth.createAccountWithBalance(donor, 100n);356357    const token = await collection.mintToken(minter, {Ethereum: owner});358359    const address = helper.ethAddress.fromCollectionId(collection.collectionId);360    const contract = helper.ethNativeContract.collection(address, 'nft');361362    {363      await contract.methods.setApprovalForAll(operator, true).send({from: owner});364      const ownerCross = helper.ethCrossAccount.fromAddress(owner);365      const result = await contract.methods.burnFromCross(ownerCross, token.tokenId).send({from: operator});366      const events = result.events.Transfer;367368      expect(events).to.be.like({369        address,370        event: 'Transfer',371        returnValues: {372          from: owner,373          to: '0x0000000000000000000000000000000000000000',374          tokenId: token.tokenId.toString(),375        },376      });377    }378  });379  380  itEth('Can perform transfer with ApprovalForAll', async ({helper}) => {381    const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});382383    const owner = await helper.eth.createAccountWithBalance(donor);384    const operator = await helper.eth.createAccountWithBalance(donor);385    const receiver = charlie;386387    const token = await collection.mintToken(minter, {Ethereum: owner});388389    const address = helper.ethAddress.fromCollectionId(collection.collectionId);390    const contract = helper.ethNativeContract.collection(address, 'nft');391392    {393      await contract.methods.setApprovalForAll(operator, true).send({from: owner});394      const ownerCross = helper.ethCrossAccount.fromAddress(owner);395      const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);396      const result = await contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: operator});397      const event = result.events.Transfer;398      expect(event).to.be.like({399        address: helper.ethAddress.fromCollectionId(collection.collectionId),400        event: 'Transfer',401        returnValues: {402          from: owner,403          to: helper.address.substrateToEth(receiver.address),404          tokenId: token.tokenId.toString(),405        },406      });407    }408409    expect(await token.getOwner()).to.be.like({Substrate: receiver.address});410  });411412  itEth('Can perform burnFromCross()', async ({helper}) => {413    const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});414    const ownerSub = bob;415    const ownerCrossSub = helper.ethCrossAccount.fromKeyringPair(ownerSub);416    const ownerEth = await helper.eth.createAccountWithBalance(donor, 100n);417    const ownerCrossEth = helper.ethCrossAccount.fromAddress(ownerEth);418419    const burnerEth = await helper.eth.createAccountWithBalance(donor, 100n);420    const burnerCrossEth = helper.ethCrossAccount.fromAddress(burnerEth);421422    const token1 = await collection.mintToken(minter, {Substrate: ownerSub.address});423    const token2 = await collection.mintToken(minter, {Ethereum: ownerEth});424425    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);426    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft');427428    // Approve tokens from substrate and ethereum:429    await token1.approve(ownerSub, {Ethereum: burnerEth});430    await collectionEvm.methods.approveCross(burnerCrossEth, token2.tokenId).send({from: ownerEth});431432    // can burnFromCross:433    const result1 = await collectionEvm.methods.burnFromCross(ownerCrossSub, token1.tokenId).send({from: burnerEth});434    const result2 = await collectionEvm.methods.burnFromCross(ownerCrossEth, token2.tokenId).send({from: burnerEth});435    const events1 = result1.events.Transfer;436    const events2 = result2.events.Transfer;437438    // Check events for burnFromCross (substrate and ethereum):439    [440      [events1, token1, helper.address.substrateToEth(ownerSub.address)], 441      [events2, token2, ownerEth],442    ].map(burnData => {443      expect(burnData[0]).to.be.like({444        address: collectionAddress,445        event: 'Transfer',446        returnValues: {447          from: burnData[2],448          to: '0x0000000000000000000000000000000000000000',449          tokenId: burnData[1].tokenId.toString(),450        },451      });452    });453454    expect(await token1.doesExist()).to.be.false;455    expect(await token2.doesExist()).to.be.false;456  });457458  itEth('Can perform approveCross()', async ({helper}) => {459    // arrange: create accounts460    const owner = await helper.eth.createAccountWithBalance(donor, 100n);461    const ownerCross = helper.ethCrossAccount.fromAddress(owner);462    const receiverSub = charlie;463    const recieverCrossSub = helper.ethCrossAccount.fromKeyringPair(receiverSub);464    const receiverEth = await helper.eth.createAccountWithBalance(donor, 100n);465    const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);466467    // arrange: create collection and tokens:468    const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});469    const token1 = await collection.mintToken(minter, {Ethereum: owner});470    const token2 = await collection.mintToken(minter, {Ethereum: owner});471472    const collectionEvm = helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(collection.collectionId), 'nft');473474    // Can approveCross substrate and ethereum address:475    const resultSub = await collectionEvm.methods.approveCross(recieverCrossSub, token1.tokenId).send({from: owner});476    const resultEth = await collectionEvm.methods.approveCross(receiverCrossEth, token2.tokenId).send({from: owner});477    const eventSub = resultSub.events.Approval;478    const eventEth = resultEth.events.Approval;479    expect(eventSub).to.be.like({480      address: helper.ethAddress.fromCollectionId(collection.collectionId),481      event: 'Approval',482      returnValues: {483        owner,484        approved: helper.address.substrateToEth(receiverSub.address),485        tokenId: token1.tokenId.toString(),486      },487    });488    expect(eventEth).to.be.like({489      address: helper.ethAddress.fromCollectionId(collection.collectionId),490      event: 'Approval',491      returnValues: {492        owner,493        approved: receiverEth,494        tokenId: token2.tokenId.toString(),495      },496    });497498    // Substrate address can transferFrom approved tokens:499    await helper.nft.transferTokenFrom(receiverSub, collection.collectionId, token1.tokenId, {Ethereum: owner}, {Substrate: receiverSub.address});500    expect(await helper.nft.getTokenOwner(collection.collectionId, token1.tokenId)).to.deep.eq({Substrate: receiverSub.address});501    // Ethereum address can transferFromCross approved tokens:502    await collectionEvm.methods.transferFromCross(ownerCross, receiverCrossEth, token2.tokenId).send({from: receiverEth});503    expect(await helper.nft.getTokenOwner(collection.collectionId, token2.tokenId)).to.deep.eq({Ethereum: receiverEth.toLowerCase()});504  });505506  itEth('Can reaffirm approved address', async ({helper}) => {507    const owner = await helper.eth.createAccountWithBalance(donor, 100n);508    const ownerCrossEth = helper.ethCrossAccount.fromAddress(owner);509    const [receiver1, receiver2] = await helper.arrange.createAccounts([100n, 100n], donor);510    const receiver1Cross = helper.ethCrossAccount.fromKeyringPair(receiver1);511    const receiver2Cross = helper.ethCrossAccount.fromKeyringPair(receiver2);512    const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});513    const token1 = await collection.mintToken(minter, {Ethereum: owner});514    const token2 = await collection.mintToken(minter, {Ethereum: owner});515    const collectionEvm = helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(collection.collectionId), 'nft');516517    // Can approve and reaffirm approved address:518    await collectionEvm.methods.approveCross(receiver1Cross, token1.tokenId).send({from: owner});519    await collectionEvm.methods.approveCross(receiver2Cross, token1.tokenId).send({from: owner});520521    // receiver1 cannot transferFrom:522    await expect(helper.nft.transferTokenFrom(receiver1, collection.collectionId, token1.tokenId, {Ethereum: owner}, {Substrate: receiver1.address})).to.be.rejected;523    // receiver2 can transferFrom:524    await helper.nft.transferTokenFrom(receiver2, collection.collectionId, token1.tokenId, {Ethereum: owner}, {Substrate: receiver2.address});525526    // can set approved address to self address to remove approval:527    await collectionEvm.methods.approveCross(receiver1Cross, token2.tokenId).send({from: owner});528    await collectionEvm.methods.approveCross(ownerCrossEth, token2.tokenId).send({from: owner});529530    // receiver1 cannot transfer token anymore:531    await expect(helper.nft.transferTokenFrom(receiver1, collection.collectionId, token2.tokenId, {Ethereum: owner}, {Substrate: receiver1.address})).to.be.rejected;532  });533534  itEth('Can perform transferFrom()', async ({helper}) => {535    const owner = await helper.eth.createAccountWithBalance(donor);536    const spender = await helper.eth.createAccountWithBalance(donor);537    const receiver = helper.eth.createAccount();538539    const collection = await helper.nft.mintCollection(minter, {});540    const {tokenId} = await collection.mintToken(minter, {Ethereum: owner});541542    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);543    const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);544545    await contract.methods.approve(spender, tokenId).send({from: owner});546547    {548      const result = await contract.methods.transferFrom(owner, receiver, tokenId).send({from: spender});549550      const event = result.events.Transfer;551      expect(event.address).to.be.equal(collectionAddress);552      expect(event.returnValues.from).to.be.equal(owner);553      expect(event.returnValues.to).to.be.equal(receiver);554      expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);555    }556557    {558      const balance = await contract.methods.balanceOf(receiver).call();559      expect(+balance).to.equal(1);560    }561562    {563      const balance = await contract.methods.balanceOf(owner).call();564      expect(+balance).to.equal(0);565    }566  });567568  itEth('Can perform transferFromCross()', async ({helper}) => {569    const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});570571    const [owner, receiver] = await helper.arrange.createAccounts([100n, 100n], donor);572    const spender = await helper.eth.createAccountWithBalance(donor);573574    const token = await collection.mintToken(minter, {Substrate: owner.address});575576    const address = helper.ethAddress.fromCollectionId(collection.collectionId);577    const contract = helper.ethNativeContract.collection(address, 'nft');578579    await token.approve(owner, {Ethereum: spender});580581    {582      const ownerCross = helper.ethCrossAccount.fromKeyringPair(owner);583      const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);584      const result = await contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender});585      const event = result.events.Transfer;586      expect(event).to.be.like({587        address: helper.ethAddress.fromCollectionId(collection.collectionId),588        event: 'Transfer',589        returnValues: {590          from: helper.address.substrateToEth(owner.address),591          to: helper.address.substrateToEth(receiver.address),592          tokenId: token.tokenId.toString(),593        },594      });595    }596597    expect(await token.getOwner()).to.be.like({Substrate: receiver.address});598  });599600  itEth('Can perform transfer()', async ({helper}) => {601    const collection = await helper.nft.mintCollection(minter, {});602    const owner = await helper.eth.createAccountWithBalance(donor);603    const receiver = helper.eth.createAccount();604605    const {tokenId} = await collection.mintToken(minter, {Ethereum: owner});606607    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);608    const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);609610    {611      const result = await contract.methods.transfer(receiver, tokenId).send({from: owner});612613      const event = result.events.Transfer;614      expect(event.address).to.be.equal(collectionAddress);615      expect(event.returnValues.from).to.be.equal(owner);616      expect(event.returnValues.to).to.be.equal(receiver);617      expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);618    }619620    {621      const balance = await contract.methods.balanceOf(owner).call();622      expect(+balance).to.equal(0);623    }624625    {626      const balance = await contract.methods.balanceOf(receiver).call();627      expect(+balance).to.equal(1);628    }629  });630  631  itEth('Can perform transferCross()', async ({helper}) => {632    const collection = await helper.nft.mintCollection(minter, {});633    const owner = await helper.eth.createAccountWithBalance(donor);634    const receiverEth = await helper.eth.createAccountWithBalance(donor);635    const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);636    const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(minter);637    638    const {tokenId} = await collection.mintToken(minter, {Ethereum: owner});639640    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);641    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);642643    {644      // Can transferCross to ethereum address:645      const result = await collectionEvm.methods.transferCross(receiverCrossEth, tokenId).send({from: owner});646      // Check events:647      const event = result.events.Transfer;648      expect(event.address).to.be.equal(collectionAddress);649      expect(event.returnValues.from).to.be.equal(owner);650      expect(event.returnValues.to).to.be.equal(receiverEth);651      expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);652      653      // owner has balance = 0:654      const ownerBalance = await collectionEvm.methods.balanceOf(owner).call();655      expect(+ownerBalance).to.equal(0);656      // receiver owns token:657      const receiverBalance = await collectionEvm.methods.balanceOf(receiverEth).call();658      expect(+receiverBalance).to.equal(1);659      expect(await helper.nft.getTokenOwner(collection.collectionId, tokenId)).to.deep.eq({Ethereum: receiverEth.toLowerCase()});660    }661    662    {663      // Can transferCross to substrate address:664      const substrateResult = await collectionEvm.methods.transferCross(receiverCrossSub, tokenId).send({from: receiverEth});665      // Check events:666      const event = substrateResult.events.Transfer;667      expect(event.address).to.be.equal(collectionAddress);668      expect(event.returnValues.from).to.be.equal(receiverEth);669      expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(minter.address));670      expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);671      672      // owner has balance = 0:673      const ownerBalance = await collectionEvm.methods.balanceOf(receiverEth).call();674      expect(+ownerBalance).to.equal(0);675      // receiver owns token:676      const receiverBalance = await helper.nft.getTokensByAddress(collection.collectionId, {Substrate: minter.address});677      expect(receiverBalance).to.contain(tokenId);678    }679  });680681  ['transfer', 'transferCross'].map(testCase => itEth(`Cannot ${testCase} non-owned token`, async ({helper}) => {682    const sender = await helper.eth.createAccountWithBalance(donor);683    const tokenOwner = await helper.eth.createAccountWithBalance(donor);684    const receiverSub = minter;685    const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(minter);686687    const collection = await helper.nft.mintCollection(minter, {});688    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);689    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', sender);690691    await collection.mintToken(minter, {Ethereum: sender});692    const nonSendersToken = await collection.mintToken(minter, {Ethereum: tokenOwner});693694    // Cannot transferCross someone else's token:695    const receiver = testCase === 'transfer' ? helper.address.substrateToEth(receiverSub.address) : receiverCrossSub;696    await expect(collectionEvm.methods[testCase](receiver, nonSendersToken.tokenId).send({from: sender})).to.be.rejected;697    // Cannot transfer token if it does not exist:698    await expect(collectionEvm.methods[testCase](receiver, 999999).send({from: sender})).to.be.rejected;699  }));700});701702describe('NFT: Fees', () => {703  let donor: IKeyringPair;704  let alice: IKeyringPair;705  let bob: IKeyringPair;706  let charlie: IKeyringPair;707708  before(async function() {709    await usingEthPlaygrounds(async (helper, privateKey) => {710      donor = await privateKey({filename: __filename});711      [alice, bob, charlie] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);712    });713  });714715  itEth('approve() call fee is less than 0.2UNQ', async ({helper}) => {716    const owner = await helper.eth.createAccountWithBalance(donor);717    const spender = helper.eth.createAccount();718719    const collection = await helper.nft.mintCollection(alice, {});720    const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});721722    const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', owner);723724    const cost = await helper.eth.recordCallFee(owner, () => contract.methods.approve(spender, tokenId).send({from: owner}));725    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));726  });727728  itEth('transferFrom() call fee is less than 0.2UNQ', async ({helper}) => {729    const owner = await helper.eth.createAccountWithBalance(donor);730    const spender = await helper.eth.createAccountWithBalance(donor);731732    const collection = await helper.nft.mintCollection(alice, {});733    const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});734735    const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', owner);736737    await contract.methods.approve(spender, tokenId).send({from: owner});738739    const cost = await helper.eth.recordCallFee(spender, () => contract.methods.transferFrom(owner, spender, tokenId).send({from: spender}));740    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));741  });742743  itEth('Can perform transferFromCross()', async ({helper}) => {744    const collectionMinter = alice;745    const owner = bob;746    const receiver = charlie;747    const collection = await helper.nft.mintCollection(collectionMinter, {name: 'A', description: 'B', tokenPrefix: 'C'});748749    const spender = await helper.eth.createAccountWithBalance(donor, 100n);750751    const token = await collection.mintToken(collectionMinter, {Substrate: owner.address});752753    const address = helper.ethAddress.fromCollectionId(collection.collectionId);754    const contract = helper.ethNativeContract.collection(address, 'nft');755756    await token.approve(owner, {Ethereum: spender});757758    {759      const ownerCross = helper.ethCrossAccount.fromKeyringPair(owner);760      const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);761      const result = await contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender});762      const event = result.events.Transfer;763      expect(event).to.be.like({764        address: helper.ethAddress.fromCollectionId(collection.collectionId),765        event: 'Transfer',766        returnValues: {767          from: helper.address.substrateToEth(owner.address),768          to: helper.address.substrateToEth(receiver.address),769          tokenId: token.tokenId.toString(),770        },771      });772    }773774    expect(await token.getOwner()).to.be.like({Substrate: receiver.address});775  });776777  itEth('transfer() call fee is less than 0.2UNQ', async ({helper}) => {778    const owner = await helper.eth.createAccountWithBalance(donor);779    const receiver = helper.eth.createAccount();780781    const collection = await helper.nft.mintCollection(alice, {});782    const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});783784    const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', owner);785786    const cost = await helper.eth.recordCallFee(owner, () => contract.methods.transfer(receiver, tokenId).send({from: owner}));787    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));788  });789});790791describe('NFT: Substrate calls', () => {792  let donor: IKeyringPair;793  let alice: IKeyringPair;794795  before(async function() {796    await usingEthPlaygrounds(async (helper, privateKey) => {797      donor = await privateKey({filename: __filename});798      [alice] = await helper.arrange.createAccounts([20n], donor);799    });800  });801802  itEth('Events emitted for mint()', async ({helper}) => {803    const collection = await helper.nft.mintCollection(alice, {});804    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);805    const contract = helper.ethNativeContract.collection(collectionAddress, 'nft');806807    const events: any = [];808    contract.events.allEvents((_: any, event: any) => {809      events.push(event);810    });811812    const {tokenId} = await collection.mintToken(alice);813    if (events.length == 0) await helper.wait.newBlocks(1);814    const event = events[0];815816    expect(event.event).to.be.equal('Transfer');817    expect(event.address).to.be.equal(collectionAddress);818    expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');819    expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(alice.address));820    expect(event.returnValues.tokenId).to.be.equal(tokenId.toString());821  });822823  itEth('Events emitted for burn()', async ({helper}) => {824    const collection = await helper.nft.mintCollection(alice, {});825    const token = await collection.mintToken(alice);826827    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);828    const contract = helper.ethNativeContract.collection(collectionAddress, 'nft');829830    const events: any = [];831    contract.events.allEvents((_: any, event: any) => {832      events.push(event);833    });834835    await token.burn(alice);836    if (events.length == 0) await helper.wait.newBlocks(1);837    const event = events[0];838839    expect(event.event).to.be.equal('Transfer');840    expect(event.address).to.be.equal(collectionAddress);841    expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));842    expect(event.returnValues.to).to.be.equal('0x0000000000000000000000000000000000000000');843    expect(event.returnValues.tokenId).to.be.equal(token.tokenId.toString());844  });845846  itEth('Events emitted for approve()', async ({helper}) => {847    const receiver = helper.eth.createAccount();848849    const collection = await helper.nft.mintCollection(alice, {});850    const token = await collection.mintToken(alice);851852    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);853    const contract = helper.ethNativeContract.collection(collectionAddress, 'nft');854855    const events: any = [];856    contract.events.allEvents((_: any, event: any) => {857      events.push(event);858    });859860    await token.approve(alice, {Ethereum: receiver});861    if (events.length == 0) await helper.wait.newBlocks(1);862    const event = events[0];863864    expect(event.event).to.be.equal('Approval');865    expect(event.address).to.be.equal(collectionAddress);866    expect(event.returnValues.owner).to.be.equal(helper.address.substrateToEth(alice.address));867    expect(event.returnValues.approved).to.be.equal(receiver);868    expect(event.returnValues.tokenId).to.be.equal(token.tokenId.toString());869  });870871  itEth('Events emitted for transferFrom()', async ({helper}) => {872    const [bob] = await helper.arrange.createAccounts([10n], donor);873    const receiver = helper.eth.createAccount();874875    const collection = await helper.nft.mintCollection(alice, {});876    const token = await collection.mintToken(alice);877    await token.approve(alice, {Substrate: bob.address});878879    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);880    const contract = helper.ethNativeContract.collection(collectionAddress, 'nft');881882    const events: any = [];883    contract.events.allEvents((_: any, event: any) => {884      events.push(event);885    });886887    await token.transferFrom(bob, {Substrate: alice.address}, {Ethereum: receiver});888889    if (events.length == 0) await helper.wait.newBlocks(1);890    const event = events[0];891892    expect(event.address).to.be.equal(collectionAddress);893    expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));894    expect(event.returnValues.to).to.be.equal(receiver);895    expect(event.returnValues.tokenId).to.be.equal(`${token.tokenId}`);896  });897898  itEth('Events emitted for transfer()', async ({helper}) => {899    const receiver = helper.eth.createAccount();900901    const collection = await helper.nft.mintCollection(alice, {});902    const token = await collection.mintToken(alice);903904    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);905    const contract = helper.ethNativeContract.collection(collectionAddress, 'nft');906907    const events: any = [];908    contract.events.allEvents((_: any, event: any) => {909      events.push(event);910    });911912    await token.transfer(alice, {Ethereum: receiver});913914    if (events.length == 0) await helper.wait.newBlocks(1);915    const event = events[0];916917    expect(event.address).to.be.equal(collectionAddress);918    expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));919    expect(event.returnValues.to).to.be.equal(receiver);920    expect(event.returnValues.tokenId).to.be.equal(`${token.tokenId}`);921  });922});923924describe('Common metadata', () => {925  let donor: IKeyringPair;926  let alice: IKeyringPair;927928  before(async function() {929    await usingEthPlaygrounds(async (helper, privateKey) => {930      donor = await privateKey({filename: __filename});931      [alice] = await helper.arrange.createAccounts([20n], donor);932    });933  });934935  itEth('Returns collection name', async ({helper}) => {936    const caller = await helper.eth.createAccountWithBalance(donor);937    const tokenPropertyPermissions = [{938      key: 'URI',939      permission: {940        mutable: true,941        collectionAdmin: true,942        tokenOwner: false,943      },944    }];945    const collection = await helper.nft.mintCollection(946      alice,947      {948        name: 'oh River',949        tokenPrefix: 'CHANGE',950        properties: [{key: 'ERC721Metadata', value: '1'}],951        tokenPropertyPermissions,952      },953    );954955    const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);956    const name = await contract.methods.name().call();957    expect(name).to.equal('oh River');958  });959960  itEth('Returns symbol name', async ({helper}) => {961    const caller = await helper.eth.createAccountWithBalance(donor);962    const tokenPropertyPermissions = [{963      key: 'URI',964      permission: {965        mutable: true,966        collectionAdmin: true,967        tokenOwner: false,968      },969    }];970    const collection = await helper.nft.mintCollection(971      alice,972      {973        name: 'oh River',974        tokenPrefix: 'CHANGE',975        properties: [{key: 'ERC721Metadata', value: '1'}],976        tokenPropertyPermissions,977      },978    );979980    const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);981    const symbol = await contract.methods.symbol().call();982    expect(symbol).to.equal('CHANGE');983  });984});985986describe('Negative tests', () => {987  let donor: IKeyringPair;988  let minter: IKeyringPair;989  let alice: IKeyringPair;990991  before(async function() {992    await usingEthPlaygrounds(async (helper, privateKey) => {993      donor = await privateKey({filename: __filename});994      [minter, alice] = await helper.arrange.createAccounts([100n, 100n], donor);995    });996  });997998  itEth('[negative] Cant perform burn without approval', async ({helper}) => {999    const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});10001001    const owner = await helper.eth.createAccountWithBalance(donor, 100n);1002    const spender = await helper.eth.createAccountWithBalance(donor, 100n);10031004    const token = await collection.mintToken(minter, {Ethereum: owner});10051006    const address = helper.ethAddress.fromCollectionId(collection.collectionId);1007    const contract = helper.ethNativeContract.collection(address, 'nft');10081009    const ownerCross = helper.ethCrossAccount.fromAddress(owner);1010    await expect(contract.methods.burnFromCross(ownerCross, token.tokenId).send({from: spender})).to.be.rejected;10111012    await contract.methods.setApprovalForAll(spender, true).send({from: owner});1013    await contract.methods.setApprovalForAll(spender, false).send({from: owner});10141015    await expect(contract.methods.burnFromCross(ownerCross, token.tokenId).send({from: spender})).to.be.rejected;1016  });10171018  itEth('[negative] Cant perform transfer without approval', async ({helper}) => {1019    const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});1020    const receiver = alice;10211022    const owner = await helper.eth.createAccountWithBalance(donor, 100n);1023    const spender = await helper.eth.createAccountWithBalance(donor, 100n);10241025    const token = await collection.mintToken(minter, {Ethereum: owner});10261027    const address = helper.ethAddress.fromCollectionId(collection.collectionId);1028    const contract = helper.ethNativeContract.collection(address, 'nft');10291030    const ownerCross = helper.ethCrossAccount.fromAddress(owner);1031    const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);10321033    await expect(contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender})).to.be.rejected;10341035    await contract.methods.setApprovalForAll(spender, true).send({from: owner});1036    await contract.methods.setApprovalForAll(spender, false).send({from: owner});1037    1038    await expect(contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender})).to.be.rejected;1039  });1040});
after · tests/src/eth/nonFungible.test.ts
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 {itEth, usingEthPlaygrounds, expect, EthUniqueHelper} from './util';18import {IKeyringPair} from '@polkadot/types/types';19import {Contract} from 'web3-eth-contract';20import {ITokenPropertyPermission} from '../util/playgrounds/types';212223describe('NFT: Information getting', () => {24  let donor: IKeyringPair;25  let alice: IKeyringPair;2627  before(async function() {28    await usingEthPlaygrounds(async (helper, privateKey) => {29      donor = await privateKey({filename: __filename});30      [alice] = await helper.arrange.createAccounts([10n], donor);31    });32  });3334  itEth('totalSupply', async ({helper}) => {35    const collection = await helper.nft.mintCollection(alice, {});36    await collection.mintToken(alice);3738    const caller = await helper.eth.createAccountWithBalance(donor);3940    const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);41    const totalSupply = await contract.methods.totalSupply().call();4243    expect(totalSupply).to.equal('1');44  });4546  itEth('balanceOf', async ({helper}) => {47    const collection = await helper.nft.mintCollection(alice, {});48    const caller = await helper.eth.createAccountWithBalance(donor);4950    await collection.mintToken(alice, {Ethereum: caller});51    await collection.mintToken(alice, {Ethereum: caller});52    await collection.mintToken(alice, {Ethereum: caller});5354    const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);55    const balance = await contract.methods.balanceOf(caller).call();5657    expect(balance).to.equal('3');58  });5960  itEth('ownerOf', async ({helper}) => {61    const collection = await helper.nft.mintCollection(alice, {});62    const caller = await helper.eth.createAccountWithBalance(donor);6364    const token = await collection.mintToken(alice, {Ethereum: caller});6566    const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);6768    const owner = await contract.methods.ownerOf(token.tokenId).call();6970    expect(owner).to.equal(caller);71  });7273  itEth('name/symbol is available regardless of ERC721Metadata support', async ({helper}) => {74    const collection = await helper.nft.mintCollection(alice, {name: 'test', tokenPrefix: 'TEST'});75    const caller = helper.eth.createAccount();7677    const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);7879    expect(await contract.methods.name().call()).to.equal('test');80    expect(await contract.methods.symbol().call()).to.equal('TEST');81  });82});8384describe('Check ERC721 token URI for NFT', () => {85  let donor: IKeyringPair;8687  before(async function() {88    await usingEthPlaygrounds(async (_helper, privateKey) => {89      donor = await privateKey({filename: __filename});90    });91  });9293  async function setup(helper: EthUniqueHelper, baseUri: string, propertyKey?: string, propertyValue?: string): Promise<{contract: Contract, nextTokenId: string}> {94    const owner = await helper.eth.createAccountWithBalance(donor);95    const receiver = helper.eth.createAccount();9697    const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'Mint collection', 'a', 'b', baseUri);98    const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);99100    const result = await contract.methods.mint(receiver).send();101    const tokenId = result.events.Transfer.returnValues.tokenId;102    expect(tokenId).to.be.equal('1');103104    if (propertyKey && propertyValue) {105      // Set URL or suffix106      await contract.methods.setProperties(tokenId, [{key: propertyKey, value: Buffer.from(propertyValue)}]).send();107    }108109    const event = result.events.Transfer;110    expect(event.address).to.be.equal(collectionAddress);111    expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');112    expect(event.returnValues.to).to.be.equal(receiver);113    expect(event.returnValues.tokenId).to.be.equal(tokenId);114115    return {contract, nextTokenId: tokenId};116  }117118  itEth('Empty tokenURI', async ({helper}) => {119    const {contract, nextTokenId} = await setup(helper, '');120    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('');121  });122123  itEth('TokenURI from url', async ({helper}) => {124    const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'URI', 'Token URI');125    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Token URI');126  });127128  itEth('TokenURI from baseURI', async ({helper}) => {129    const {contract, nextTokenId} = await setup(helper, 'BaseURI_');130    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_');131  });132133  itEth('TokenURI from baseURI + suffix', async ({helper}) => {134    const suffix = '/some/suffix';135    const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'URISuffix', suffix);136    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_' + suffix);137  });138});139140describe('NFT: Plain calls', () => {141  let donor: IKeyringPair;142  let minter: IKeyringPair;143  let bob: IKeyringPair;144  let charlie: IKeyringPair;145146  before(async function() {147    await usingEthPlaygrounds(async (helper, privateKey) => {148      donor = await privateKey({filename: __filename});149      [minter, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);150    });151  });152153  itEth('Can perform mint() & get crossOwner()', async ({helper}) => {154    const owner = await helper.eth.createAccountWithBalance(donor);155    const receiver = helper.eth.createAccount();156157    const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'Mint collection', '6', '6', '');158    const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);159160    const result = await contract.methods.mintWithTokenURI(receiver, 'Test URI').send();161    const tokenId = result.events.Transfer.returnValues.tokenId;162    expect(tokenId).to.be.equal('1');163164    const event = result.events.Transfer;165    expect(event.address).to.be.equal(collectionAddress);166    expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');167    expect(event.returnValues.to).to.be.equal(receiver);168169    expect(await contract.methods.tokenURI(tokenId).call()).to.be.equal('Test URI');170    console.log(await contract.methods.crossOwnerOf(tokenId).call());171    expect(await contract.methods.crossOwnerOf(tokenId).call()).to.be.like([receiver, '0']);172    // TODO: this wont work right now, need release 919000 first173    // await helper.methods.setOffchainSchema(collectionIdAddress, 'https://offchain-service.local/token-info/{id}').send();174    // const tokenUri = await contract.methods.tokenURI(nextTokenId).call();175    // expect(tokenUri).to.be.equal(`https://offchain-service.local/token-info/${nextTokenId}`);176  });177  178  // TODO combine all minting tests in one place179  [180    'substrate' as const,181    'ethereum' as const,182  ].map(testCase => {183    itEth(`Can perform mintCross() for ${testCase} address`, async ({helper}) => {184      const collectionAdmin = await helper.eth.createAccountWithBalance(donor);185186      const receiverEth = helper.eth.createAccount();187      const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);188      const receiverSub = bob;189      const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(receiverSub);190191      // const receiverCross = helper.ethCrossAccount.fromKeyringPair(bob);192      const properties = Array(5).fill(0).map((_, i) => { return {key: `key_${i}`, value: Buffer.from(`value_${i}`)}; });193      const permissions: ITokenPropertyPermission[] = properties194        .map(p => {195          return {196            key: p.key, permission: {197              tokenOwner: true,198              collectionAdmin: true,199              mutable: true,200            },201          };202        });203    204    205      const collection = await helper.nft.mintCollection(minter, {206        tokenPrefix: 'ethp',207        tokenPropertyPermissions: permissions,208      });209      await collection.addAdmin(minter, {Ethereum: collectionAdmin});210    211      const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);212      const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', collectionAdmin, true);213      let expectedTokenId = await contract.methods.nextTokenId().call();214      let result = await contract.methods.mintCross(testCase === 'ethereum' ? receiverCrossEth : receiverCrossSub, []).send();215      let tokenId = result.events.Transfer.returnValues.tokenId;216      expect(tokenId).to.be.equal(expectedTokenId);217218      let event = result.events.Transfer;219      expect(event.address).to.be.equal(collectionAddress);220      expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');221      expect(event.returnValues.to).to.be.equal(testCase === 'ethereum' ? receiverEth : helper.address.substrateToEth(bob.address));222      expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);223    224      expectedTokenId = await contract.methods.nextTokenId().call();225      result = await contract.methods.mintCross(testCase === 'ethereum' ? receiverCrossEth : receiverCrossSub, properties).send();226      event = result.events.Transfer;227      expect(event.address).to.be.equal(collectionAddress);228      expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');229      expect(event.returnValues.to).to.be.equal(testCase === 'ethereum' ? receiverEth : helper.address.substrateToEth(bob.address));230      expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);231    232      tokenId = result.events.Transfer.returnValues.tokenId;233    234      expect(tokenId).to.be.equal(expectedTokenId);235236      expect(await contract.methods.properties(tokenId, []).call()).to.be.like(properties237        .map(p => { return helper.ethProperty.property(p.key, p.value.toString()); }));238      239      expect(await helper.nft.getTokenOwner(collection.collectionId, tokenId))240        .to.deep.eq(testCase === 'ethereum' ? {Ethereum: receiverEth.toLowerCase()} : {Substrate: receiverSub.address});241    });242  });243244  itEth('Non-owner and non admin cannot mintCross', async ({helper}) => {245    const nonOwner = await helper.eth.createAccountWithBalance(donor);246    const nonOwnerCross = helper.ethCrossAccount.fromAddress(nonOwner);247248    const collection = await helper.nft.mintCollection(minter);249    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);250    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft');251252    await expect(collectionEvm.methods.mintCross(nonOwnerCross, []).call({from: nonOwner}))253      .to.be.rejectedWith('PublicMintingNotAllowed');254  });255  256  //TODO: CORE-302 add eth methods257  itEth.skip('Can perform mintBulk()', async ({helper}) => {258    const caller = await helper.eth.createAccountWithBalance(donor);259    const receiver = helper.eth.createAccount();260261    const collection = await helper.nft.mintCollection(minter);262    await collection.addAdmin(minter, {Ethereum: caller});263264    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);265    const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', caller);266    {267      const bulkSize = 3;268      const nextTokenId = await contract.methods.nextTokenId().call();269      expect(nextTokenId).to.be.equal('1');270      const result = await contract.methods.mintBulkWithTokenURI(271        receiver,272        Array.from({length: bulkSize}, (_, i) => (273          [+nextTokenId + i, `Test URI ${i}`]274        )),275      ).send({from: caller});276277      const events = result.events.Transfer.sort((a: any, b: any) => +a.returnValues.tokenId - b.returnValues.tokenId);278      for (let i = 0; i < bulkSize; i++) {279        const event = events[i];280        expect(event.address).to.equal(collectionAddress);281        expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');282        expect(event.returnValues.to).to.equal(receiver);283        expect(event.returnValues.tokenId).to.equal(`${+nextTokenId + i}`);284285        expect(await contract.methods.tokenURI(+nextTokenId + i).call()).to.be.equal(`Test URI ${i}`);286      }287    }288  });289290  itEth('Can perform burn()', async ({helper}) => {291    const caller = await helper.eth.createAccountWithBalance(donor);292293    const collection = await helper.nft.mintCollection(minter, {});294    const {tokenId} = await collection.mintToken(minter, {Ethereum: caller});295296    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);297    const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', caller);298299    {300      const result = await contract.methods.burn(tokenId).send({from: caller});301302      const event = result.events.Transfer;303      expect(event.address).to.be.equal(collectionAddress);304      expect(event.returnValues.from).to.be.equal(caller);305      expect(event.returnValues.to).to.be.equal('0x0000000000000000000000000000000000000000');306      expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);307    }308  });309310  itEth('Can perform approve()', async ({helper}) => {311    const owner = await helper.eth.createAccountWithBalance(donor);312    const spender = helper.eth.createAccount();313314    const collection = await helper.nft.mintCollection(minter, {});315    const {tokenId} = await collection.mintToken(minter, {Ethereum: owner});316317    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);318    const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);319320    {321      const result = await contract.methods.approve(spender, tokenId).send({from: owner});322323      const event = result.events.Approval;324      expect(event.address).to.be.equal(collectionAddress);325      expect(event.returnValues.owner).to.be.equal(owner);326      expect(event.returnValues.approved).to.be.equal(spender);327      expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);328    }329  });330331  itEth('Can perform setApprovalForAll()', async ({helper}) => {332    const owner = await helper.eth.createAccountWithBalance(donor);333    const operator = helper.eth.createAccount();334335    const collection = await helper.nft.mintCollection(minter, {});336337    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);338    const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);339340    const approvedBefore = await contract.methods.isApprovedForAll(owner, operator).call();341    expect(approvedBefore).to.be.equal(false);342343    {344      const result = await contract.methods.setApprovalForAll(operator, true).send({from: owner});345346      expect(result.events.ApprovalForAll).to.be.like({347        address: collectionAddress,348        event: 'ApprovalForAll',349        returnValues: {350          owner,351          operator,352          approved: true,353        },354      });355356      const approvedAfter = await contract.methods.isApprovedForAll(owner, operator).call();357      expect(approvedAfter).to.be.equal(true);358    }359360    {361      const result = await contract.methods.setApprovalForAll(operator, false).send({from: owner});362363      expect(result.events.ApprovalForAll).to.be.like({364        address: collectionAddress,365        event: 'ApprovalForAll',366        returnValues: {367          owner,368          operator,369          approved: false,370        },371      });372373      const approvedAfter = await contract.methods.isApprovedForAll(owner, operator).call();374      expect(approvedAfter).to.be.equal(false);375    }376  });377378  itEth('Can perform burn with ApprovalForAll', async ({helper}) => {379    const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});380381    const owner = await helper.eth.createAccountWithBalance(donor);382    const operator = await helper.eth.createAccountWithBalance(donor, 100n);383384    const token = await collection.mintToken(minter, {Ethereum: owner});385386    const address = helper.ethAddress.fromCollectionId(collection.collectionId);387    const contract = helper.ethNativeContract.collection(address, 'nft');388389    {390      await contract.methods.setApprovalForAll(operator, true).send({from: owner});391      const ownerCross = helper.ethCrossAccount.fromAddress(owner);392      const result = await contract.methods.burnFromCross(ownerCross, token.tokenId).send({from: operator});393      const events = result.events.Transfer;394395      expect(events).to.be.like({396        address,397        event: 'Transfer',398        returnValues: {399          from: owner,400          to: '0x0000000000000000000000000000000000000000',401          tokenId: token.tokenId.toString(),402        },403      });404    }405  });406  407  itEth('Can perform transfer with ApprovalForAll', async ({helper}) => {408    const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});409410    const owner = await helper.eth.createAccountWithBalance(donor);411    const operator = await helper.eth.createAccountWithBalance(donor);412    const receiver = charlie;413414    const token = await collection.mintToken(minter, {Ethereum: owner});415416    const address = helper.ethAddress.fromCollectionId(collection.collectionId);417    const contract = helper.ethNativeContract.collection(address, 'nft');418419    {420      await contract.methods.setApprovalForAll(operator, true).send({from: owner});421      const ownerCross = helper.ethCrossAccount.fromAddress(owner);422      const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);423      const result = await contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: operator});424      const event = result.events.Transfer;425      expect(event).to.be.like({426        address: helper.ethAddress.fromCollectionId(collection.collectionId),427        event: 'Transfer',428        returnValues: {429          from: owner,430          to: helper.address.substrateToEth(receiver.address),431          tokenId: token.tokenId.toString(),432        },433      });434    }435436    expect(await token.getOwner()).to.be.like({Substrate: receiver.address});437  });438439  itEth('Can perform burnFromCross()', async ({helper}) => {440    const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});441    const ownerSub = bob;442    const ownerCrossSub = helper.ethCrossAccount.fromKeyringPair(ownerSub);443    const ownerEth = await helper.eth.createAccountWithBalance(donor, 100n);444    const ownerCrossEth = helper.ethCrossAccount.fromAddress(ownerEth);445446    const burnerEth = await helper.eth.createAccountWithBalance(donor, 100n);447    const burnerCrossEth = helper.ethCrossAccount.fromAddress(burnerEth);448449    const token1 = await collection.mintToken(minter, {Substrate: ownerSub.address});450    const token2 = await collection.mintToken(minter, {Ethereum: ownerEth});451452    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);453    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft');454455    // Approve tokens from substrate and ethereum:456    await token1.approve(ownerSub, {Ethereum: burnerEth});457    await collectionEvm.methods.approveCross(burnerCrossEth, token2.tokenId).send({from: ownerEth});458459    // can burnFromCross:460    const result1 = await collectionEvm.methods.burnFromCross(ownerCrossSub, token1.tokenId).send({from: burnerEth});461    const result2 = await collectionEvm.methods.burnFromCross(ownerCrossEth, token2.tokenId).send({from: burnerEth});462    const events1 = result1.events.Transfer;463    const events2 = result2.events.Transfer;464465    // Check events for burnFromCross (substrate and ethereum):466    [467      [events1, token1, helper.address.substrateToEth(ownerSub.address)], 468      [events2, token2, ownerEth],469    ].map(burnData => {470      expect(burnData[0]).to.be.like({471        address: collectionAddress,472        event: 'Transfer',473        returnValues: {474          from: burnData[2],475          to: '0x0000000000000000000000000000000000000000',476          tokenId: burnData[1].tokenId.toString(),477        },478      });479    });480481    expect(await token1.doesExist()).to.be.false;482    expect(await token2.doesExist()).to.be.false;483  });484485  itEth('Can perform approveCross()', async ({helper}) => {486    // arrange: create accounts487    const owner = await helper.eth.createAccountWithBalance(donor, 100n);488    const ownerCross = helper.ethCrossAccount.fromAddress(owner);489    const receiverSub = charlie;490    const recieverCrossSub = helper.ethCrossAccount.fromKeyringPair(receiverSub);491    const receiverEth = await helper.eth.createAccountWithBalance(donor, 100n);492    const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);493494    // arrange: create collection and tokens:495    const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});496    const token1 = await collection.mintToken(minter, {Ethereum: owner});497    const token2 = await collection.mintToken(minter, {Ethereum: owner});498499    const collectionEvm = helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(collection.collectionId), 'nft');500501    // Can approveCross substrate and ethereum address:502    const resultSub = await collectionEvm.methods.approveCross(recieverCrossSub, token1.tokenId).send({from: owner});503    const resultEth = await collectionEvm.methods.approveCross(receiverCrossEth, token2.tokenId).send({from: owner});504    const eventSub = resultSub.events.Approval;505    const eventEth = resultEth.events.Approval;506    expect(eventSub).to.be.like({507      address: helper.ethAddress.fromCollectionId(collection.collectionId),508      event: 'Approval',509      returnValues: {510        owner,511        approved: helper.address.substrateToEth(receiverSub.address),512        tokenId: token1.tokenId.toString(),513      },514    });515    expect(eventEth).to.be.like({516      address: helper.ethAddress.fromCollectionId(collection.collectionId),517      event: 'Approval',518      returnValues: {519        owner,520        approved: receiverEth,521        tokenId: token2.tokenId.toString(),522      },523    });524525    // Substrate address can transferFrom approved tokens:526    await helper.nft.transferTokenFrom(receiverSub, collection.collectionId, token1.tokenId, {Ethereum: owner}, {Substrate: receiverSub.address});527    expect(await helper.nft.getTokenOwner(collection.collectionId, token1.tokenId)).to.deep.eq({Substrate: receiverSub.address});528    // Ethereum address can transferFromCross approved tokens:529    await collectionEvm.methods.transferFromCross(ownerCross, receiverCrossEth, token2.tokenId).send({from: receiverEth});530    expect(await helper.nft.getTokenOwner(collection.collectionId, token2.tokenId)).to.deep.eq({Ethereum: receiverEth.toLowerCase()});531  });532533  itEth('Can reaffirm approved address', async ({helper}) => {534    const owner = await helper.eth.createAccountWithBalance(donor, 100n);535    const ownerCrossEth = helper.ethCrossAccount.fromAddress(owner);536    const [receiver1, receiver2] = await helper.arrange.createAccounts([100n, 100n], donor);537    const receiver1Cross = helper.ethCrossAccount.fromKeyringPair(receiver1);538    const receiver2Cross = helper.ethCrossAccount.fromKeyringPair(receiver2);539    const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});540    const token1 = await collection.mintToken(minter, {Ethereum: owner});541    const token2 = await collection.mintToken(minter, {Ethereum: owner});542    const collectionEvm = helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(collection.collectionId), 'nft');543544    // Can approve and reaffirm approved address:545    await collectionEvm.methods.approveCross(receiver1Cross, token1.tokenId).send({from: owner});546    await collectionEvm.methods.approveCross(receiver2Cross, token1.tokenId).send({from: owner});547548    // receiver1 cannot transferFrom:549    await expect(helper.nft.transferTokenFrom(receiver1, collection.collectionId, token1.tokenId, {Ethereum: owner}, {Substrate: receiver1.address})).to.be.rejected;550    // receiver2 can transferFrom:551    await helper.nft.transferTokenFrom(receiver2, collection.collectionId, token1.tokenId, {Ethereum: owner}, {Substrate: receiver2.address});552553    // can set approved address to self address to remove approval:554    await collectionEvm.methods.approveCross(receiver1Cross, token2.tokenId).send({from: owner});555    await collectionEvm.methods.approveCross(ownerCrossEth, token2.tokenId).send({from: owner});556557    // receiver1 cannot transfer token anymore:558    await expect(helper.nft.transferTokenFrom(receiver1, collection.collectionId, token2.tokenId, {Ethereum: owner}, {Substrate: receiver1.address})).to.be.rejected;559  });560561  itEth('Can perform transferFrom()', async ({helper}) => {562    const owner = await helper.eth.createAccountWithBalance(donor);563    const spender = await helper.eth.createAccountWithBalance(donor);564    const receiver = helper.eth.createAccount();565566    const collection = await helper.nft.mintCollection(minter, {});567    const {tokenId} = await collection.mintToken(minter, {Ethereum: owner});568569    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);570    const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);571572    await contract.methods.approve(spender, tokenId).send({from: owner});573574    {575      const result = await contract.methods.transferFrom(owner, receiver, tokenId).send({from: spender});576577      const event = result.events.Transfer;578      expect(event.address).to.be.equal(collectionAddress);579      expect(event.returnValues.from).to.be.equal(owner);580      expect(event.returnValues.to).to.be.equal(receiver);581      expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);582    }583584    {585      const balance = await contract.methods.balanceOf(receiver).call();586      expect(+balance).to.equal(1);587    }588589    {590      const balance = await contract.methods.balanceOf(owner).call();591      expect(+balance).to.equal(0);592    }593  });594595  itEth('Can perform transferFromCross()', async ({helper}) => {596    const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});597598    const [owner, receiver] = await helper.arrange.createAccounts([100n, 100n], donor);599    const spender = await helper.eth.createAccountWithBalance(donor);600601    const token = await collection.mintToken(minter, {Substrate: owner.address});602603    const address = helper.ethAddress.fromCollectionId(collection.collectionId);604    const contract = helper.ethNativeContract.collection(address, 'nft');605606    await token.approve(owner, {Ethereum: spender});607608    {609      const ownerCross = helper.ethCrossAccount.fromKeyringPair(owner);610      const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);611      const result = await contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender});612      const event = result.events.Transfer;613      expect(event).to.be.like({614        address: helper.ethAddress.fromCollectionId(collection.collectionId),615        event: 'Transfer',616        returnValues: {617          from: helper.address.substrateToEth(owner.address),618          to: helper.address.substrateToEth(receiver.address),619          tokenId: token.tokenId.toString(),620        },621      });622    }623624    expect(await token.getOwner()).to.be.like({Substrate: receiver.address});625  });626627  itEth('Can perform transfer()', async ({helper}) => {628    const collection = await helper.nft.mintCollection(minter, {});629    const owner = await helper.eth.createAccountWithBalance(donor);630    const receiver = helper.eth.createAccount();631632    const {tokenId} = await collection.mintToken(minter, {Ethereum: owner});633634    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);635    const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);636637    {638      const result = await contract.methods.transfer(receiver, tokenId).send({from: owner});639640      const event = result.events.Transfer;641      expect(event.address).to.be.equal(collectionAddress);642      expect(event.returnValues.from).to.be.equal(owner);643      expect(event.returnValues.to).to.be.equal(receiver);644      expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);645    }646647    {648      const balance = await contract.methods.balanceOf(owner).call();649      expect(+balance).to.equal(0);650    }651652    {653      const balance = await contract.methods.balanceOf(receiver).call();654      expect(+balance).to.equal(1);655    }656  });657  658  itEth('Can perform transferCross()', async ({helper}) => {659    const collection = await helper.nft.mintCollection(minter, {});660    const owner = await helper.eth.createAccountWithBalance(donor);661    const receiverEth = await helper.eth.createAccountWithBalance(donor);662    const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);663    const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(minter);664    665    const {tokenId} = await collection.mintToken(minter, {Ethereum: owner});666667    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);668    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);669670    {671      // Can transferCross to ethereum address:672      const result = await collectionEvm.methods.transferCross(receiverCrossEth, tokenId).send({from: owner});673      // Check events:674      const event = result.events.Transfer;675      expect(event.address).to.be.equal(collectionAddress);676      expect(event.returnValues.from).to.be.equal(owner);677      expect(event.returnValues.to).to.be.equal(receiverEth);678      expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);679      680      // owner has balance = 0:681      const ownerBalance = await collectionEvm.methods.balanceOf(owner).call();682      expect(+ownerBalance).to.equal(0);683      // receiver owns token:684      const receiverBalance = await collectionEvm.methods.balanceOf(receiverEth).call();685      expect(+receiverBalance).to.equal(1);686      expect(await helper.nft.getTokenOwner(collection.collectionId, tokenId)).to.deep.eq({Ethereum: receiverEth.toLowerCase()});687    }688    689    {690      // Can transferCross to substrate address:691      const substrateResult = await collectionEvm.methods.transferCross(receiverCrossSub, tokenId).send({from: receiverEth});692      // Check events:693      const event = substrateResult.events.Transfer;694      expect(event.address).to.be.equal(collectionAddress);695      expect(event.returnValues.from).to.be.equal(receiverEth);696      expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(minter.address));697      expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);698      699      // owner has balance = 0:700      const ownerBalance = await collectionEvm.methods.balanceOf(receiverEth).call();701      expect(+ownerBalance).to.equal(0);702      // receiver owns token:703      const receiverBalance = await helper.nft.getTokensByAddress(collection.collectionId, {Substrate: minter.address});704      expect(receiverBalance).to.contain(tokenId);705    }706  });707708  ['transfer', 'transferCross'].map(testCase => itEth(`Cannot ${testCase} non-owned token`, async ({helper}) => {709    const sender = await helper.eth.createAccountWithBalance(donor);710    const tokenOwner = await helper.eth.createAccountWithBalance(donor);711    const receiverSub = minter;712    const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(minter);713714    const collection = await helper.nft.mintCollection(minter, {});715    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);716    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', sender);717718    await collection.mintToken(minter, {Ethereum: sender});719    const nonSendersToken = await collection.mintToken(minter, {Ethereum: tokenOwner});720721    // Cannot transferCross someone else's token:722    const receiver = testCase === 'transfer' ? helper.address.substrateToEth(receiverSub.address) : receiverCrossSub;723    await expect(collectionEvm.methods[testCase](receiver, nonSendersToken.tokenId).send({from: sender})).to.be.rejected;724    // Cannot transfer token if it does not exist:725    await expect(collectionEvm.methods[testCase](receiver, 999999).send({from: sender})).to.be.rejected;726  }));727});728729describe('NFT: Fees', () => {730  let donor: IKeyringPair;731  let alice: IKeyringPair;732  let bob: IKeyringPair;733  let charlie: IKeyringPair;734735  before(async function() {736    await usingEthPlaygrounds(async (helper, privateKey) => {737      donor = await privateKey({filename: __filename});738      [alice, bob, charlie] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);739    });740  });741742  itEth('approve() call fee is less than 0.2UNQ', async ({helper}) => {743    const owner = await helper.eth.createAccountWithBalance(donor);744    const spender = helper.eth.createAccount();745746    const collection = await helper.nft.mintCollection(alice, {});747    const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});748749    const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', owner);750751    const cost = await helper.eth.recordCallFee(owner, () => contract.methods.approve(spender, tokenId).send({from: owner}));752    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));753  });754755  itEth('transferFrom() call fee is less than 0.2UNQ', async ({helper}) => {756    const owner = await helper.eth.createAccountWithBalance(donor);757    const spender = await helper.eth.createAccountWithBalance(donor);758759    const collection = await helper.nft.mintCollection(alice, {});760    const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});761762    const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', owner);763764    await contract.methods.approve(spender, tokenId).send({from: owner});765766    const cost = await helper.eth.recordCallFee(spender, () => contract.methods.transferFrom(owner, spender, tokenId).send({from: spender}));767    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));768  });769770  itEth('Can perform transferFromCross()', async ({helper}) => {771    const collectionMinter = alice;772    const owner = bob;773    const receiver = charlie;774    const collection = await helper.nft.mintCollection(collectionMinter, {name: 'A', description: 'B', tokenPrefix: 'C'});775776    const spender = await helper.eth.createAccountWithBalance(donor, 100n);777778    const token = await collection.mintToken(collectionMinter, {Substrate: owner.address});779780    const address = helper.ethAddress.fromCollectionId(collection.collectionId);781    const contract = helper.ethNativeContract.collection(address, 'nft');782783    await token.approve(owner, {Ethereum: spender});784785    {786      const ownerCross = helper.ethCrossAccount.fromKeyringPair(owner);787      const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);788      const result = await contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender});789      const event = result.events.Transfer;790      expect(event).to.be.like({791        address: helper.ethAddress.fromCollectionId(collection.collectionId),792        event: 'Transfer',793        returnValues: {794          from: helper.address.substrateToEth(owner.address),795          to: helper.address.substrateToEth(receiver.address),796          tokenId: token.tokenId.toString(),797        },798      });799    }800801    expect(await token.getOwner()).to.be.like({Substrate: receiver.address});802  });803804  itEth('transfer() call fee is less than 0.2UNQ', async ({helper}) => {805    const owner = await helper.eth.createAccountWithBalance(donor);806    const receiver = helper.eth.createAccount();807808    const collection = await helper.nft.mintCollection(alice, {});809    const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});810811    const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', owner);812813    const cost = await helper.eth.recordCallFee(owner, () => contract.methods.transfer(receiver, tokenId).send({from: owner}));814    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));815  });816});817818describe('NFT: Substrate calls', () => {819  let donor: IKeyringPair;820  let alice: IKeyringPair;821822  before(async function() {823    await usingEthPlaygrounds(async (helper, privateKey) => {824      donor = await privateKey({filename: __filename});825      [alice] = await helper.arrange.createAccounts([20n], donor);826    });827  });828829  itEth('Events emitted for mint()', async ({helper}) => {830    const collection = await helper.nft.mintCollection(alice, {});831    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);832    const contract = helper.ethNativeContract.collection(collectionAddress, 'nft');833834    const events: any = [];835    contract.events.allEvents((_: any, event: any) => {836      events.push(event);837    });838839    const {tokenId} = await collection.mintToken(alice);840    if (events.length == 0) await helper.wait.newBlocks(1);841    const event = events[0];842843    expect(event.event).to.be.equal('Transfer');844    expect(event.address).to.be.equal(collectionAddress);845    expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');846    expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(alice.address));847    expect(event.returnValues.tokenId).to.be.equal(tokenId.toString());848  });849850  itEth('Events emitted for burn()', async ({helper}) => {851    const collection = await helper.nft.mintCollection(alice, {});852    const token = await collection.mintToken(alice);853854    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);855    const contract = helper.ethNativeContract.collection(collectionAddress, 'nft');856857    const events: any = [];858    contract.events.allEvents((_: any, event: any) => {859      events.push(event);860    });861862    await token.burn(alice);863    if (events.length == 0) await helper.wait.newBlocks(1);864    const event = events[0];865866    expect(event.event).to.be.equal('Transfer');867    expect(event.address).to.be.equal(collectionAddress);868    expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));869    expect(event.returnValues.to).to.be.equal('0x0000000000000000000000000000000000000000');870    expect(event.returnValues.tokenId).to.be.equal(token.tokenId.toString());871  });872873  itEth('Events emitted for approve()', async ({helper}) => {874    const receiver = helper.eth.createAccount();875876    const collection = await helper.nft.mintCollection(alice, {});877    const token = await collection.mintToken(alice);878879    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);880    const contract = helper.ethNativeContract.collection(collectionAddress, 'nft');881882    const events: any = [];883    contract.events.allEvents((_: any, event: any) => {884      events.push(event);885    });886887    await token.approve(alice, {Ethereum: receiver});888    if (events.length == 0) await helper.wait.newBlocks(1);889    const event = events[0];890891    expect(event.event).to.be.equal('Approval');892    expect(event.address).to.be.equal(collectionAddress);893    expect(event.returnValues.owner).to.be.equal(helper.address.substrateToEth(alice.address));894    expect(event.returnValues.approved).to.be.equal(receiver);895    expect(event.returnValues.tokenId).to.be.equal(token.tokenId.toString());896  });897898  itEth('Events emitted for transferFrom()', async ({helper}) => {899    const [bob] = await helper.arrange.createAccounts([10n], donor);900    const receiver = helper.eth.createAccount();901902    const collection = await helper.nft.mintCollection(alice, {});903    const token = await collection.mintToken(alice);904    await token.approve(alice, {Substrate: bob.address});905906    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);907    const contract = helper.ethNativeContract.collection(collectionAddress, 'nft');908909    const events: any = [];910    contract.events.allEvents((_: any, event: any) => {911      events.push(event);912    });913914    await token.transferFrom(bob, {Substrate: alice.address}, {Ethereum: receiver});915916    if (events.length == 0) await helper.wait.newBlocks(1);917    const event = events[0];918919    expect(event.address).to.be.equal(collectionAddress);920    expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));921    expect(event.returnValues.to).to.be.equal(receiver);922    expect(event.returnValues.tokenId).to.be.equal(`${token.tokenId}`);923  });924925  itEth('Events emitted for transfer()', async ({helper}) => {926    const receiver = helper.eth.createAccount();927928    const collection = await helper.nft.mintCollection(alice, {});929    const token = await collection.mintToken(alice);930931    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);932    const contract = helper.ethNativeContract.collection(collectionAddress, 'nft');933934    const events: any = [];935    contract.events.allEvents((_: any, event: any) => {936      events.push(event);937    });938939    await token.transfer(alice, {Ethereum: receiver});940941    if (events.length == 0) await helper.wait.newBlocks(1);942    const event = events[0];943944    expect(event.address).to.be.equal(collectionAddress);945    expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));946    expect(event.returnValues.to).to.be.equal(receiver);947    expect(event.returnValues.tokenId).to.be.equal(`${token.tokenId}`);948  });949});950951describe('Common metadata', () => {952  let donor: IKeyringPair;953  let alice: IKeyringPair;954955  before(async function() {956    await usingEthPlaygrounds(async (helper, privateKey) => {957      donor = await privateKey({filename: __filename});958      [alice] = await helper.arrange.createAccounts([20n], donor);959    });960  });961962  itEth('Returns collection name', async ({helper}) => {963    const caller = await helper.eth.createAccountWithBalance(donor);964    const tokenPropertyPermissions = [{965      key: 'URI',966      permission: {967        mutable: true,968        collectionAdmin: true,969        tokenOwner: false,970      },971    }];972    const collection = await helper.nft.mintCollection(973      alice,974      {975        name: 'oh River',976        tokenPrefix: 'CHANGE',977        properties: [{key: 'ERC721Metadata', value: '1'}],978        tokenPropertyPermissions,979      },980    );981982    const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);983    const name = await contract.methods.name().call();984    expect(name).to.equal('oh River');985  });986987  itEth('Returns symbol name', async ({helper}) => {988    const caller = await helper.eth.createAccountWithBalance(donor);989    const tokenPropertyPermissions = [{990      key: 'URI',991      permission: {992        mutable: true,993        collectionAdmin: true,994        tokenOwner: false,995      },996    }];997    const collection = await helper.nft.mintCollection(998      alice,999      {1000        name: 'oh River',1001        tokenPrefix: 'CHANGE',1002        properties: [{key: 'ERC721Metadata', value: '1'}],1003        tokenPropertyPermissions,1004      },1005    );10061007    const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);1008    const symbol = await contract.methods.symbol().call();1009    expect(symbol).to.equal('CHANGE');1010  });1011});10121013describe('Negative tests', () => {1014  let donor: IKeyringPair;1015  let minter: IKeyringPair;1016  let alice: IKeyringPair;10171018  before(async function() {1019    await usingEthPlaygrounds(async (helper, privateKey) => {1020      donor = await privateKey({filename: __filename});1021      [minter, alice] = await helper.arrange.createAccounts([100n, 100n], donor);1022    });1023  });10241025  itEth('[negative] Cant perform burn without approval', async ({helper}) => {1026    const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});10271028    const owner = await helper.eth.createAccountWithBalance(donor, 100n);1029    const spender = await helper.eth.createAccountWithBalance(donor, 100n);10301031    const token = await collection.mintToken(minter, {Ethereum: owner});10321033    const address = helper.ethAddress.fromCollectionId(collection.collectionId);1034    const contract = helper.ethNativeContract.collection(address, 'nft');10351036    const ownerCross = helper.ethCrossAccount.fromAddress(owner);1037    await expect(contract.methods.burnFromCross(ownerCross, token.tokenId).send({from: spender})).to.be.rejected;10381039    await contract.methods.setApprovalForAll(spender, true).send({from: owner});1040    await contract.methods.setApprovalForAll(spender, false).send({from: owner});10411042    await expect(contract.methods.burnFromCross(ownerCross, token.tokenId).send({from: spender})).to.be.rejected;1043  });10441045  itEth('[negative] Cant perform transfer without approval', async ({helper}) => {1046    const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});1047    const receiver = alice;10481049    const owner = await helper.eth.createAccountWithBalance(donor, 100n);1050    const spender = await helper.eth.createAccountWithBalance(donor, 100n);10511052    const token = await collection.mintToken(minter, {Ethereum: owner});10531054    const address = helper.ethAddress.fromCollectionId(collection.collectionId);1055    const contract = helper.ethNativeContract.collection(address, 'nft');10561057    const ownerCross = helper.ethCrossAccount.fromAddress(owner);1058    const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);10591060    await expect(contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender})).to.be.rejected;10611062    await contract.methods.setApprovalForAll(spender, true).send({from: owner});1063    await contract.methods.setApprovalForAll(spender, false).send({from: owner});1064    1065    await expect(contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender})).to.be.rejected;1066  });1067});
modifiedtests/src/eth/reFungible.test.tsdiffbeforeafterboth
--- a/tests/src/eth/reFungible.test.ts
+++ b/tests/src/eth/reFungible.test.ts
@@ -137,48 +137,61 @@
     expect(await contract.methods.tokenURI(tokenId).call()).to.be.equal('Test URI');
   });
   
-  itEth('Can perform mintCross()', async ({helper}) => {
-    const caller = await helper.eth.createAccountWithBalance(donor);
-    const receiverCross = helper.ethCrossAccount.fromKeyringPair(bob);
-    const properties = Array(5).fill(0).map((_, i) => { return {key: `key_${i}`, value: Buffer.from(`value_${i}`)}; });
-    const permissions: ITokenPropertyPermission[] = properties.map(p => { return {key: p.key, permission: {tokenOwner: true,
-      collectionAdmin: true,
-      mutable: true}}; });
+  [
+    'substrate' as const,
+    'ethereum' as const,
+  ].map(testCase => {
+    itEth(`Can perform mintCross() for ${testCase} address`, async ({helper}) => {
+      const collectionAdmin = await helper.eth.createAccountWithBalance(donor);
+
+      const receiverEth = helper.eth.createAccount();
+      const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);
+      const receiverSub = bob;
+      const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(receiverSub);
+
+      const properties = Array(5).fill(0).map((_, i) => { return {key: `key_${i}`, value: Buffer.from(`value_${i}`)}; });
+      const permissions: ITokenPropertyPermission[] = properties.map(p => { return {key: p.key, permission: {tokenOwner: true,
+        collectionAdmin: true,
+        mutable: true}}; });
     
     
-    const collection = await helper.rft.mintCollection(minter, {
-      tokenPrefix: 'ethp',
-      tokenPropertyPermissions: permissions,
-    });
-    await collection.addAdmin(minter, {Ethereum: caller});
+      const collection = await helper.rft.mintCollection(minter, {
+        tokenPrefix: 'ethp',
+        tokenPropertyPermissions: permissions,
+      });
+      await collection.addAdmin(minter, {Ethereum: collectionAdmin});
     
-    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
-    const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller, true);
-    let expectedTokenId = await contract.methods.nextTokenId().call();
-    let result = await contract.methods.mintCross(receiverCross, []).send();
-    let tokenId = result.events.Transfer.returnValues.tokenId;
-    expect(tokenId).to.be.equal(expectedTokenId);
+      const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+      const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', collectionAdmin, true);
+      let expectedTokenId = await contract.methods.nextTokenId().call();
+      let result = await contract.methods.mintCross(testCase === 'ethereum' ? receiverCrossEth : receiverCrossSub, []).send();
+      let tokenId = result.events.Transfer.returnValues.tokenId;
+      expect(tokenId).to.be.equal(expectedTokenId);
 
-    let event = result.events.Transfer;
-    expect(event.address).to.be.equal(collectionAddress);
-    expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');
-    expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(bob.address));
-    expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);
+      let event = result.events.Transfer;
+      expect(event.address).to.be.equal(collectionAddress);
+      expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');
+      expect(event.returnValues.to).to.be.equal(testCase === 'ethereum' ? receiverEth : helper.address.substrateToEth(bob.address));
+      expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);
     
-    expectedTokenId = await contract.methods.nextTokenId().call();
-    result = await contract.methods.mintCross(receiverCross, properties).send();
-    event = result.events.Transfer;
-    expect(event.address).to.be.equal(collectionAddress);
-    expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');
-    expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(bob.address));
-    expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);
+      expectedTokenId = await contract.methods.nextTokenId().call();
+      result = await contract.methods.mintCross(testCase === 'ethereum' ? receiverCrossEth : receiverCrossSub, properties).send();
+      event = result.events.Transfer;
+      expect(event.address).to.be.equal(collectionAddress);
+      expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');
+      expect(event.returnValues.to).to.be.equal(testCase === 'ethereum' ? receiverEth : helper.address.substrateToEth(bob.address));
+      expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);
     
-    tokenId = result.events.Transfer.returnValues.tokenId;
+      tokenId = result.events.Transfer.returnValues.tokenId;
 
-    expect(tokenId).to.be.equal(expectedTokenId);
+      expect(tokenId).to.be.equal(expectedTokenId);
     
-    expect(await contract.methods.properties(tokenId, []).call()).to.be.like(properties
-      .map(p => { return helper.ethProperty.property(p.key, p.value.toString()); }));
+      expect(await contract.methods.properties(tokenId, []).call()).to.be.like(properties
+        .map(p => { return helper.ethProperty.property(p.key, p.value.toString()); }));
+
+      expect(await helper.nft.getTokenOwner(collection.collectionId, tokenId))
+        .to.deep.eq(testCase === 'ethereum' ? {Ethereum: receiverEth.toLowerCase()} : {Substrate: receiverSub.address});
+    });
   });
 
   itEth.skip('Can perform mintBulk()', async ({helper}) => {