git.delta.rocks / unique-network / refs/commits / a3eb5c564fa0

difftreelog

test add tests

Grigoriy Simonov2023-09-22parent: #17ea847.patch.diff
in: master

2 files changed

modifiedtests/src/eth/nonFungible.test.tsdiffbeforeafterboth
--- a/tests/src/eth/nonFungible.test.ts
+++ b/tests/src/eth/nonFungible.test.ts
@@ -18,6 +18,7 @@
 import {IKeyringPair} from '@polkadot/types/types';
 import {Contract} from 'web3-eth-contract';
 import {ITokenPropertyPermission} from '../util/playgrounds/types';
+import { CREATE_COLLECTION_DATA_DEFAULTS, CollectionMode, CreateCollectionData, TokenPermissionField } from './util/playgrounds/types';
 
 describe('Check ERC721 token URI for NFT', () => {
   let donor: IKeyringPair;
@@ -197,6 +198,96 @@
     }
   });
 
+  itEth('Can perform mintBulkCross()', async ({helper}) => {
+    const caller = await helper.eth.createAccountWithBalance(donor);
+    const callerCross = helper.ethCrossAccount.fromAddress(caller);
+    const receiver = helper.eth.createAccount();
+    const receiverCross = helper.ethCrossAccount.fromAddress(receiver);
+
+    const permissions = [
+      {code: TokenPermissionField.Mutable, value: true},
+      {code: TokenPermissionField.TokenOwner, value: true},
+      {code: TokenPermissionField.CollectionAdmin, value: true},
+    ];
+    const {collectionAddress} = await helper.eth.createCollection(
+      caller,
+      {
+        ...CREATE_COLLECTION_DATA_DEFAULTS,
+        name: 'A',
+        description: 'B',
+        tokenPrefix: 'C',
+        collectionMode: 'rft',
+        adminList: [callerCross],
+        tokenPropertyPermissions: [
+          {key: 'key_0_0', permissions},
+          {key: 'key_1_0', permissions},
+          {key: 'key_1_1', permissions},
+          {key: 'key_2_0', permissions},
+          {key: 'key_2_1', permissions},
+          {key: 'key_2_2', permissions},
+        ],
+      },
+    ).send();
+
+    const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', caller);
+    {
+      const nextTokenId = await contract.methods.nextTokenId().call();
+      expect(nextTokenId).to.be.equal('1');
+      const result = await contract.methods.mintBulkCross([
+        {
+          owner: receiverCross,
+          properties: [
+            {key: 'key_0_0', value: Buffer.from('value_0_0')},
+          ],
+        },
+        {
+          owner: receiverCross,
+          properties: [
+            {key: 'key_1_0', value: Buffer.from('value_1_0')},
+            {key: 'key_1_1', value: Buffer.from('value_1_1')},
+          ],
+        },
+        {
+          owner: receiverCross,
+          properties: [
+            {key: 'key_2_0', value: Buffer.from('value_2_0')},
+            {key: 'key_2_1', value: Buffer.from('value_2_1')},
+            {key: 'key_2_2', value: Buffer.from('value_2_2')},
+          ],
+        },
+      ]).send({from: caller});
+      const events = result.events.Transfer.sort((a: any, b: any) => +a.returnValues.tokenId - b.returnValues.tokenId);
+      const bulkSize = 3;
+      for(let i = 0; i < bulkSize; i++) {
+        const event = events[i];
+        expect(event.address).to.equal(collectionAddress);
+        expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');
+        expect(event.returnValues.to).to.equal(receiver);
+        expect(event.returnValues.tokenId).to.equal(`${+nextTokenId + i}`);
+      }
+
+      const properties = [
+        await contract.methods.properties(+nextTokenId, []).call(),
+        await contract.methods.properties(+nextTokenId + 1, []).call(),
+        await contract.methods.properties(+nextTokenId + 2, []).call(),
+      ];
+      expect(properties).to.be.deep.equal([
+        [
+          ['key_0_0', helper.getWeb3().utils.toHex('value_0_0')],
+        ],
+        [
+          ['key_1_0', helper.getWeb3().utils.toHex('value_1_0')],
+          ['key_1_1', helper.getWeb3().utils.toHex('value_1_1')],
+        ],
+        [
+          ['key_2_0', helper.getWeb3().utils.toHex('value_2_0')],
+          ['key_2_1', helper.getWeb3().utils.toHex('value_2_1')],
+          ['key_2_2', helper.getWeb3().utils.toHex('value_2_2')],
+        ],
+      ]);
+    }
+  });
+
   itEth('Can perform burn()', async ({helper}) => {
     const caller = await helper.eth.createAccountWithBalance(donor);
 
modifiedtests/src/eth/reFungible.test.tsdiffbeforeafterboth
before · tests/src/eth/reFungible.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 {Pallets, requirePalletsOrSkip} from '../util';18import {expect, itEth, usingEthPlaygrounds} from './util';19import {IKeyringPair} from '@polkadot/types/types';20import {ITokenPropertyPermission} from '../util/playgrounds/types';2122describe('Refungible: Plain calls', () => {23  let donor: IKeyringPair;24  let minter: IKeyringPair;25  let bob: IKeyringPair;26  let charlie: IKeyringPair;2728  before(async function() {29    await usingEthPlaygrounds(async (helper, privateKey) => {30      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);3132      donor = await privateKey({url: import.meta.url});33      [minter, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);34    });35  });3637  [38    'substrate' as const,39    'ethereum' as const,40  ].map(testCase => {41    itEth(`Can perform mintCross() for ${testCase} address`, async ({helper}) => {42      const collectionAdmin = await helper.eth.createAccountWithBalance(donor);4344      const receiverEth = helper.eth.createAccount();45      const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);46      const receiverSub = bob;47      const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(receiverSub);4849      const properties = Array(5).fill(0).map((_, i) => ({key: `key_${i}`, value: Buffer.from(`value_${i}`)}));50      const permissions: ITokenPropertyPermission[] = properties.map(p => ({key: p.key, permission: {51        tokenOwner: false,52        collectionAdmin: true,53        mutable: false}}));545556      const collection = await helper.rft.mintCollection(minter, {57        tokenPrefix: 'ethp',58        tokenPropertyPermissions: permissions,59      });60      await collection.addAdmin(minter, {Ethereum: collectionAdmin});6162      const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);63      const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', collectionAdmin, true);64      let expectedTokenId = await contract.methods.nextTokenId().call();65      let result = await contract.methods.mintCross(testCase === 'ethereum' ? receiverCrossEth : receiverCrossSub, []).send();66      let tokenId = result.events.Transfer.returnValues.tokenId;67      expect(tokenId).to.be.equal(expectedTokenId);6869      let event = result.events.Transfer;70      expect(event.address).to.be.equal(collectionAddress);71      expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');72      expect(event.returnValues.to).to.be.equal(testCase === 'ethereum' ? receiverEth : helper.address.substrateToEth(bob.address));73      expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);7475      expectedTokenId = await contract.methods.nextTokenId().call();76      result = await contract.methods.mintCross(testCase === 'ethereum' ? receiverCrossEth : receiverCrossSub, properties).send();77      event = result.events.Transfer;78      expect(event.address).to.be.equal(collectionAddress);79      expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');80      expect(event.returnValues.to).to.be.equal(testCase === 'ethereum' ? receiverEth : helper.address.substrateToEth(bob.address));81      expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);8283      tokenId = result.events.Transfer.returnValues.tokenId;8485      expect(tokenId).to.be.equal(expectedTokenId);8687      expect(await contract.methods.properties(tokenId, []).call()).to.be.like(properties88        .map(p => helper.ethProperty.property(p.key, p.value.toString())));8990      expect(await helper.nft.getTokenOwner(collection.collectionId, tokenId))91        .to.deep.eq(testCase === 'ethereum' ? {Ethereum: receiverEth.toLowerCase()} : {Substrate: receiverSub.address});92    });93  });9495  itEth.skip('Can perform mintBulk()', async ({helper}) => {96    const owner = await helper.eth.createAccountWithBalance(donor);97    const receiver = helper.eth.createAccount();98    const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleRFTCollection(owner, 'MintBulky', '6', '6', '');99    const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', owner);100101    {102      const nextTokenId = await contract.methods.nextTokenId().call();103      expect(nextTokenId).to.be.equal('1');104      const result = await contract.methods.mintBulkWithTokenURI(105        receiver,106        [107          [nextTokenId, 'Test URI 0'],108          [+nextTokenId + 1, 'Test URI 1'],109          [+nextTokenId + 2, 'Test URI 2'],110        ],111      ).send();112113      const events = result.events.Transfer;114      for(let i = 0; i < 2; i++) {115        const event = events[i];116        expect(event.address).to.equal(collectionAddress);117        expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');118        expect(event.returnValues.to).to.equal(receiver);119        expect(event.returnValues.tokenId).to.equal(String(+nextTokenId + i));120      }121122      expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI 0');123      expect(await contract.methods.tokenURI(+nextTokenId + 1).call()).to.be.equal('Test URI 1');124      expect(await contract.methods.tokenURI(+nextTokenId + 2).call()).to.be.equal('Test URI 2');125    }126  });127128  itEth('Can perform setApprovalForAll()', async ({helper}) => {129    const owner = await helper.eth.createAccountWithBalance(donor);130    const operator = helper.eth.createAccount();131132    const collection = await helper.rft.mintCollection(minter, {});133134    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);135    const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', owner);136137    const approvedBefore = await contract.methods.isApprovedForAll(owner, operator).call();138    expect(approvedBefore).to.be.equal(false);139140    {141      const result = await contract.methods.setApprovalForAll(operator, true).send({from: owner});142143      expect(result.events.ApprovalForAll).to.be.like({144        address: collectionAddress,145        event: 'ApprovalForAll',146        returnValues: {147          owner,148          operator,149          approved: true,150        },151      });152153      const approvedAfter = await contract.methods.isApprovedForAll(owner, operator).call();154      expect(approvedAfter).to.be.equal(true);155    }156157    {158      const result = await contract.methods.setApprovalForAll(operator, false).send({from: owner});159160      expect(result.events.ApprovalForAll).to.be.like({161        address: collectionAddress,162        event: 'ApprovalForAll',163        returnValues: {164          owner,165          operator,166          approved: false,167        },168      });169170      const approvedAfter = await contract.methods.isApprovedForAll(owner, operator).call();171      expect(approvedAfter).to.be.equal(false);172    }173  });174175  itEth('Can perform burn with ApprovalForAll', async ({helper}) => {176    const collection = await helper.rft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});177178    const owner = await helper.eth.createAccountWithBalance(donor);179    const operator = await helper.eth.createAccountWithBalance(donor);180181    const token = await collection.mintToken(minter, 100n, {Ethereum: owner});182183    const address = helper.ethAddress.fromCollectionId(collection.collectionId);184    const contract = await helper.ethNativeContract.collection(address, 'rft');185186    {187      await contract.methods.setApprovalForAll(operator, true).send({from: owner});188      const ownerCross = helper.ethCrossAccount.fromAddress(owner);189      const result = await contract.methods.burnFromCross(ownerCross, token.tokenId).send({from: operator});190      const events = result.events.Transfer;191192      expect(events).to.be.like({193        address,194        event: 'Transfer',195        returnValues: {196          from: owner,197          to: '0x0000000000000000000000000000000000000000',198          tokenId: token.tokenId.toString(),199        },200      });201    }202  });203204  itEth('Can perform burn with approve and approvalForAll', async ({helper}) => {205    const collection = await helper.rft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});206207    const owner = await helper.eth.createAccountWithBalance(donor);208    const operator = await helper.eth.createAccountWithBalance(donor);209210    const token = await collection.mintToken(minter, 100n, {Ethereum: owner});211212    const address = helper.ethAddress.fromCollectionId(collection.collectionId);213    const contract = await helper.ethNativeContract.collection(address, 'rft');214215    const rftToken = await helper.ethNativeContract.rftTokenById(token.collectionId, token.tokenId, owner, true);216217    {218      await rftToken.methods.approve(operator, 15n).send({from: owner});219      await contract.methods.setApprovalForAll(operator, true).send({from: owner});220      await rftToken.methods.burnFrom(owner, 10n).send({from: operator});221    }222    {223      const allowance = await rftToken.methods.allowance(owner, operator).call();224      expect(+allowance).to.be.equal(5);225    }226    {227      const ownerCross = helper.ethCrossAccount.fromAddress(owner);228      const operatorCross = helper.ethCrossAccount.fromAddress(operator);229      const allowance = await rftToken.methods.allowanceCross(ownerCross, operatorCross).call();230      expect(+allowance).to.equal(5);231    }232  });233234  itEth('Can perform transfer with ApprovalForAll', async ({helper}) => {235    const collection = await helper.rft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});236237    const owner = await helper.eth.createAccountWithBalance(donor);238    const operator = await helper.eth.createAccountWithBalance(donor);239    const receiver = charlie;240241    const token = await collection.mintToken(minter, 100n, {Ethereum: owner});242243    const address = helper.ethAddress.fromCollectionId(collection.collectionId);244    const contract = await helper.ethNativeContract.collection(address, 'rft');245246    {247      await contract.methods.setApprovalForAll(operator, true).send({from: owner});248      const ownerCross = helper.ethCrossAccount.fromAddress(owner);249      const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);250      const result = await contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: operator});251      const event = result.events.Transfer;252      expect(event).to.be.like({253        address: helper.ethAddress.fromCollectionId(collection.collectionId),254        event: 'Transfer',255        returnValues: {256          from: owner,257          to: helper.address.substrateToEth(receiver.address),258          tokenId: token.tokenId.toString(),259        },260      });261    }262263    expect(await token.getTop10Owners()).to.be.like([{Substrate: receiver.address}]);264  });265266  itEth('Can perform burn()', async ({helper}) => {267    const caller = await helper.eth.createAccountWithBalance(donor);268    const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'Burny', '6', '6');269    const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);270271    const result = await contract.methods.mint(caller).send();272    const tokenId = result.events.Transfer.returnValues.tokenId;273    {274      const result = await contract.methods.burn(tokenId).send();275      const event = result.events.Transfer;276      expect(event.address).to.equal(collectionAddress);277      expect(event.returnValues.from).to.equal(caller);278      expect(event.returnValues.to).to.equal('0x0000000000000000000000000000000000000000');279      expect(event.returnValues.tokenId).to.equal(tokenId.toString());280    }281  });282283  itEth('Can perform transferFrom()', async ({helper}) => {284    const caller = await helper.eth.createAccountWithBalance(donor);285    const receiver = helper.eth.createAccount();286    const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'TransferFromy', '6', '6');287    const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);288289    const result = await contract.methods.mint(caller).send();290    const tokenId = result.events.Transfer.returnValues.tokenId;291292    const tokenAddress = helper.ethAddress.fromTokenId(collectionId, tokenId);293294    const tokenContract = await helper.ethNativeContract.rftToken(tokenAddress, caller);295    await tokenContract.methods.repartition(15).send();296297    {298      const tokenEvents: any = [];299      tokenContract.events.allEvents((_: any, event: any) => {300        tokenEvents.push(event);301      });302      const result = await contract.methods.transferFrom(caller, receiver, tokenId).send();303      if(tokenEvents.length == 0) await helper.wait.newBlocks(1);304305      let event = result.events.Transfer;306      expect(event.address).to.equal(collectionAddress);307      expect(event.returnValues.from).to.equal(caller);308      expect(event.returnValues.to).to.equal(receiver);309      expect(event.returnValues.tokenId).to.equal(tokenId.toString());310311      event = tokenEvents[0];312      expect(event.address).to.equal(tokenAddress);313      expect(event.returnValues.from).to.equal(caller);314      expect(event.returnValues.to).to.equal(receiver);315      expect(event.returnValues.value).to.equal('15');316    }317318    {319      const balance = await contract.methods.balanceOf(receiver).call();320      expect(+balance).to.equal(1);321    }322323    {324      const balance = await contract.methods.balanceOf(caller).call();325      expect(+balance).to.equal(0);326    }327  });328329  // Soft-deprecated330  itEth('Can perform burnFrom()', async ({helper}) => {331    const collection = await helper.rft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});332333    const owner = await helper.eth.createAccountWithBalance(donor);334    const spender = await helper.eth.createAccountWithBalance(donor);335336    const token = await collection.mintToken(minter, 100n, {Ethereum: owner});337338    const address = helper.ethAddress.fromCollectionId(collection.collectionId);339    const contract = await helper.ethNativeContract.collection(address, 'rft', spender, true);340341    const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, token.tokenId);342    const tokenContract = await helper.ethNativeContract.rftToken(tokenAddress, owner);343    await tokenContract.methods.repartition(15).send();344    await tokenContract.methods.approve(spender, 15).send();345346    {347      const result = await contract.methods.burnFrom(owner, token.tokenId).send();348      const event = result.events.Transfer;349      expect(event).to.be.like({350        address: helper.ethAddress.fromCollectionId(collection.collectionId),351        event: 'Transfer',352        returnValues: {353          from: owner,354          to: '0x0000000000000000000000000000000000000000',355          tokenId: token.tokenId.toString(),356        },357      });358    }359360    expect(await collection.getTokenBalance(token.tokenId, {Ethereum: owner})).to.be.eq(0n);361  });362363  itEth('Can perform burnFromCross()', async ({helper}) => {364    const collection = await helper.rft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});365366    const owner = bob;367    const spender = await helper.eth.createAccountWithBalance(donor);368369    const token = await collection.mintToken(minter, 100n, {Substrate: owner.address});370371    const address = helper.ethAddress.fromCollectionId(collection.collectionId);372    const contract = await helper.ethNativeContract.collection(address, 'rft');373374    await token.repartition(owner, 15n);375    await token.approve(owner, {Ethereum: spender}, 15n);376377    {378      const ownerCross = helper.ethCrossAccount.fromKeyringPair(owner);379      const result = await contract.methods.burnFromCross(ownerCross, token.tokenId).send({from: spender});380      const event = result.events.Transfer;381      expect(event).to.be.like({382        address: helper.ethAddress.fromCollectionId(collection.collectionId),383        event: 'Transfer',384        returnValues: {385          from: helper.address.substrateToEth(owner.address),386          to: '0x0000000000000000000000000000000000000000',387          tokenId: token.tokenId.toString(),388        },389      });390    }391392    expect(await collection.getTokenBalance(token.tokenId, {Substrate: owner.address})).to.be.eq(0n);393  });394395  itEth('Can perform transferFromCross()', async ({helper}) => {396    const collection = await helper.rft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});397398    const owner = bob;399    const spender = await helper.eth.createAccountWithBalance(donor);400    const receiver = charlie;401402    const token = await collection.mintToken(minter, 100n, {Substrate: owner.address});403404    const address = helper.ethAddress.fromCollectionId(collection.collectionId);405    const contract = await helper.ethNativeContract.collection(address, 'rft');406407    await token.repartition(owner, 15n);408    await token.approve(owner, {Ethereum: spender}, 15n);409410    {411      const ownerCross = helper.ethCrossAccount.fromKeyringPair(owner);412      const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);413      const result = await contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender});414      const event = result.events.Transfer;415      expect(event).to.be.like({416        address: helper.ethAddress.fromCollectionId(collection.collectionId),417        event: 'Transfer',418        returnValues: {419          from: helper.address.substrateToEth(owner.address),420          to: helper.address.substrateToEth(receiver.address),421          tokenId: token.tokenId.toString(),422        },423      });424    }425426    expect(await token.getTop10Owners()).to.be.like([{Substrate: receiver.address}]);427  });428429  itEth('Can perform transfer()', async ({helper}) => {430    const caller = await helper.eth.createAccountWithBalance(donor);431    const receiver = helper.eth.createAccount();432    const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'Transferry', '6', '6');433    const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);434435    const result = await contract.methods.mint(caller).send();436    const tokenId = result.events.Transfer.returnValues.tokenId;437438    {439      const result = await contract.methods.transfer(receiver, tokenId).send();440441      const event = result.events.Transfer;442      expect(event.address).to.equal(collectionAddress);443      expect(event.returnValues.from).to.equal(caller);444      expect(event.returnValues.to).to.equal(receiver);445      expect(event.returnValues.tokenId).to.equal(tokenId.toString());446    }447448    {449      const balance = await contract.methods.balanceOf(caller).call();450      expect(+balance).to.equal(0);451    }452453    {454      const balance = await contract.methods.balanceOf(receiver).call();455      expect(+balance).to.equal(1);456    }457  });458459  itEth('Can perform transferCross()', async ({helper}) => {460    const sender = await helper.eth.createAccountWithBalance(donor);461    const receiverEth = await helper.eth.createAccountWithBalance(donor);462    const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);463    const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(minter);464465    const collection = await helper.rft.mintCollection(minter, {});466    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);467    const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'rft', sender);468469    const token = await collection.mintToken(minter, 50n, {Ethereum: sender});470471    {472      // Can transferCross to ethereum address:473      const result = await collectionEvm.methods.transferCross(receiverCrossEth, token.tokenId).send({from: sender});474      // Check events:475      const event = result.events.Transfer;476      expect(event.address).to.equal(collectionAddress);477      expect(event.returnValues.from).to.equal(sender);478      expect(event.returnValues.to).to.equal(receiverEth);479      expect(event.returnValues.tokenId).to.equal(token.tokenId.toString());480      // Sender's balance decreased:481      const senderBalance = await collectionEvm.methods.balanceOf(sender).call();482      expect(+senderBalance).to.equal(0);483      expect(await token.getBalance({Ethereum: sender})).to.eq(0n);484      // Receiver's balance increased:485      const receiverBalance = await collectionEvm.methods.balanceOf(receiverEth).call();486      expect(+receiverBalance).to.equal(1);487      expect(await token.getBalance({Ethereum: receiverEth})).to.eq(50n);488    }489490    {491      // Can transferCross to substrate address:492      const substrateResult = await collectionEvm.methods.transferCross(receiverCrossSub, token.tokenId).send({from: receiverEth});493      // Check events:494      const event = substrateResult.events.Transfer;495      expect(event.address).to.be.equal(collectionAddress);496      expect(event.returnValues.from).to.be.equal(receiverEth);497      expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(minter.address));498      expect(event.returnValues.tokenId).to.be.equal(`${token.tokenId}`);499      // Sender's balance decreased:500      const senderBalance = await collectionEvm.methods.balanceOf(receiverEth).call();501      expect(+senderBalance).to.equal(0);502      expect(await token.getBalance({Ethereum: receiverEth})).to.eq(0n);503      // Receiver's balance increased:504      const receiverBalance = await helper.nft.getTokensByAddress(collection.collectionId, {Substrate: minter.address});505      expect(receiverBalance).to.contain(token.tokenId);506      expect(await token.getBalance({Substrate: minter.address})).to.eq(50n);507    }508  });509510  ['transfer', 'transferCross'].map(testCase => itEth(`Cannot ${testCase} non-owned token`, async ({helper}) => {511    const sender = await helper.eth.createAccountWithBalance(donor);512    const tokenOwner = await helper.eth.createAccountWithBalance(donor);513    const receiverSub = minter;514    const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(minter);515516    const collection = await helper.rft.mintCollection(minter, {});517    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);518    const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'rft', sender);519520    await collection.mintToken(minter, 50n, {Ethereum: sender});521    const nonSendersToken = await collection.mintToken(minter, 50n, {Ethereum: tokenOwner});522523    // Cannot transferCross someone else's token:524    const receiver = testCase === 'transfer' ? helper.address.substrateToEth(receiverSub.address) : receiverCrossSub;525    await expect(collectionEvm.methods[testCase](receiver, nonSendersToken.tokenId).send({from: sender})).to.be.rejected;526    // Cannot transfer token if it does not exist:527    await expect(collectionEvm.methods[testCase](receiver, 999999).send({from: sender})).to.be.rejected;528  }));529530  itEth('transfer event on transfer from partial ownership to full ownership', async ({helper}) => {531    const caller = await helper.eth.createAccountWithBalance(donor);532    const receiver = helper.eth.createAccount();533    const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'Transferry-Partial-to-Full', '6', '6');534    const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);535536    const result = await contract.methods.mint(caller).send();537    const tokenId = result.events.Transfer.returnValues.tokenId;538539    const tokenContract = await helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);540541    await tokenContract.methods.repartition(2).send();542    await tokenContract.methods.transfer(receiver, 1).send();543544    const events: any = [];545    contract.events.allEvents((_: any, event: any) => {546      events.push(event);547    });548549    await tokenContract.methods.transfer(receiver, 1).send();550    if(events.length == 0) await helper.wait.newBlocks(1);551    const event = events[0];552553    expect(event.address).to.equal(collectionAddress);554    expect(event.returnValues.from).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');555    expect(event.returnValues.to).to.equal(receiver);556    expect(event.returnValues.tokenId).to.equal(tokenId.toString());557  });558559  itEth('transfer event on transfer from full ownership to partial ownership', async ({helper}) => {560    const caller = await helper.eth.createAccountWithBalance(donor);561    const receiver = helper.eth.createAccount();562    const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'Transferry-Full-to-Partial', '6', '6');563    const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);564565    const result = await contract.methods.mint(caller).send();566    const tokenId = result.events.Transfer.returnValues.tokenId;567568    const tokenContract = await helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);569570    await tokenContract.methods.repartition(2).send();571572    const events: any = [];573    contract.events.allEvents((_: any, event: any) => {574      events.push(event);575    });576577    await tokenContract.methods.transfer(receiver, 1).send();578    if(events.length == 0) await helper.wait.newBlocks(1);579    const event = events[0];580581    expect(event.address).to.equal(collectionAddress);582    expect(event.returnValues.from).to.equal(caller);583    expect(event.returnValues.to).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');584    expect(event.returnValues.tokenId).to.equal(tokenId.toString());585  });586587  itEth('Check balanceOfCross()', async ({helper}) => {588    const collection = await helper.rft.mintCollection(minter, {});589    const owner = await helper.ethCrossAccount.createAccountWithBalance(donor);590    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);591    const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner.eth);592593    expect(await collectionEvm.methods.balanceOfCross(owner).call({from: owner.eth})).to.be.eq('0');594595    for(let i = 1n; i < 10n; i++) {596      await collection.mintToken(minter, 100n, {Ethereum: owner.eth});597      expect(await collectionEvm.methods.balanceOfCross(owner).call({from: owner.eth})).to.be.eq(i.toString());598    }599  });600601  itEth('Check ownerOfCross()', async ({helper}) => {602    const collection = await helper.rft.mintCollection(minter, {});603    let owner = await helper.ethCrossAccount.createAccountWithBalance(donor);604    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);605    const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner.eth);606    const {tokenId} = await collection.mintToken(minter, 100n,{Ethereum: owner.eth});607608    for(let i = 1n; i < 10n; i++) {609      const ownerCross = await collectionEvm.methods.ownerOfCross(tokenId).call({from: owner.eth});610      expect(ownerCross.eth).to.be.eq(owner.eth);611      expect(ownerCross.sub).to.be.eq(owner.sub);612613      const newOwner = await helper.ethCrossAccount.createAccountWithBalance(donor);614      await collectionEvm.methods.transferCross(newOwner, tokenId).send({from: owner.eth});615      owner = newOwner;616    }617618    const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);619    const tokenContract = await helper.ethNativeContract.rftToken(tokenAddress, owner.eth, true);620    const newOwner = await helper.ethCrossAccount.createAccountWithBalance(donor);621    await tokenContract.methods.transferCross(newOwner, 50).send({from: owner.eth});622    const ownerCross = await collectionEvm.methods.ownerOfCross(tokenId).call({from: owner.eth});623    expect(ownerCross.eth.toUpperCase()).to.be.eq('0XFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF');624    expect(ownerCross.sub).to.be.eq('0');625  });626});627628describe('RFT: Fees', () => {629  let donor: IKeyringPair;630631  before(async function() {632    await usingEthPlaygrounds(async (helper, privateKey) => {633      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);634635      donor = await privateKey({url: import.meta.url});636    });637  });638639  itEth('transferFrom() call fee is less than 0.2UNQ', async ({helper}) => {640    const caller = await helper.eth.createAccountWithBalance(donor);641    const receiver = helper.eth.createAccount();642    const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'Feeful-Transfer-From', '6', '6');643    const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);644645    const result = await contract.methods.mint(caller).send();646    const tokenId = result.events.Transfer.returnValues.tokenId;647648    const cost = await helper.eth.recordCallFee(caller, () => contract.methods.transferFrom(caller, receiver, tokenId).send());649    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));650    expect(cost > 0n);651  });652653  itEth('transfer() call fee is less than 0.2UNQ', async ({helper}) => {654    const caller = await helper.eth.createAccountWithBalance(donor);655    const receiver = helper.eth.createAccount();656    const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'Feeful-Transfer', '6', '6');657    const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);658659    const result = await contract.methods.mint(caller).send();660    const tokenId = result.events.Transfer.returnValues.tokenId;661662    const cost = await helper.eth.recordCallFee(caller, () => contract.methods.transfer(receiver, tokenId).send());663    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));664    expect(cost > 0n);665  });666});667668describe('Common metadata', () => {669  let donor: IKeyringPair;670  let alice: IKeyringPair;671672  before(async function() {673    await usingEthPlaygrounds(async (helper, privateKey) => {674      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);675676      donor = await privateKey({url: import.meta.url});677      [alice] = await helper.arrange.createAccounts([1000n], donor);678    });679  });680681  itEth('Returns collection name', async ({helper}) => {682    const caller = helper.eth.createAccount();683    const tokenPropertyPermissions = [{684      key: 'URI',685      permission: {686        mutable: true,687        collectionAdmin: true,688        tokenOwner: false,689      },690    }];691    const collection = await helper.rft.mintCollection(692      alice,693      {694        name: 'Leviathan',695        tokenPrefix: '11',696        properties: [{key: 'ERC721Metadata', value: '1'}],697        tokenPropertyPermissions,698      },699    );700701    const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'rft', caller);702    const name = await contract.methods.name().call();703    expect(name).to.equal('Leviathan');704  });705706  itEth('Returns symbol name', async ({helper}) => {707    const caller = await helper.eth.createAccountWithBalance(donor);708    const tokenPropertyPermissions = [{709      key: 'URI',710      permission: {711        mutable: true,712        collectionAdmin: true,713        tokenOwner: false,714      },715    }];716    const {collectionId} = await helper.rft.mintCollection(717      alice,718      {719        name: 'Leviathan',720        tokenPrefix: '12',721        properties: [{key: 'ERC721Metadata', value: '1'}],722        tokenPropertyPermissions,723      },724    );725726    const contract = await helper.ethNativeContract.collectionById(collectionId, 'rft', caller);727    const symbol = await contract.methods.symbol().call();728    expect(symbol).to.equal('12');729  });730});731732describe('Negative tests', () => {733  let donor: IKeyringPair;734  let minter: IKeyringPair;735  let alice: IKeyringPair;736737  before(async function() {738    await usingEthPlaygrounds(async (helper, privateKey) => {739      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);740741      donor = await privateKey({url: import.meta.url});742      [minter, alice] = await helper.arrange.createAccounts([100n, 100n], donor);743    });744  });745746  itEth('[negative] Cant perform burn without approval', async ({helper}) => {747    const collection = await helper.rft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});748749    const owner = await helper.eth.createAccountWithBalance(donor);750    const spender = await helper.eth.createAccountWithBalance(donor);751752    const token = await collection.mintToken(minter, 100n, {Ethereum: owner});753754    const address = helper.ethAddress.fromCollectionId(collection.collectionId);755    const contract = await helper.ethNativeContract.collection(address, 'rft');756757    const ownerCross = helper.ethCrossAccount.fromAddress(owner);758759    await expect(contract.methods.burnFromCross(ownerCross, token.tokenId).send({from: spender})).to.be.rejected;760761    await contract.methods.setApprovalForAll(spender, true).send({from: owner});762    await contract.methods.setApprovalForAll(spender, false).send({from: owner});763764    await expect(contract.methods.burnFromCross(ownerCross, token.tokenId).send({from: spender})).to.be.rejected;765  });766767  itEth('[negative] Cant perform transfer without approval', async ({helper}) => {768    const collection = await helper.rft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});769    const owner = await helper.eth.createAccountWithBalance(donor);770    const receiver = alice;771772    const spender = await helper.eth.createAccountWithBalance(donor);773774    const token = await collection.mintToken(minter, 100n, {Ethereum: owner});775776    const address = helper.ethAddress.fromCollectionId(collection.collectionId);777    const contract = await helper.ethNativeContract.collection(address, 'rft');778779    const ownerCross = helper.ethCrossAccount.fromAddress(owner);780    const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);781782    await expect(contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender})).to.be.rejected;783784    await contract.methods.setApprovalForAll(spender, true).send({from: owner});785    await contract.methods.setApprovalForAll(spender, false).send({from: owner});786787    await expect(contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender})).to.be.rejected;788  });789});
after · tests/src/eth/reFungible.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 {Pallets, requirePalletsOrSkip} from '../util';18import {expect, itEth, usingEthPlaygrounds} from './util';19import {IKeyringPair} from '@polkadot/types/types';20import {ITokenPropertyPermission} from '../util/playgrounds/types';21import { CREATE_COLLECTION_DATA_DEFAULTS, TokenPermissionField } from './util/playgrounds/types';2223describe('Refungible: Plain calls', () => {24  let donor: IKeyringPair;25  let minter: IKeyringPair;26  let bob: IKeyringPair;27  let charlie: IKeyringPair;2829  before(async function() {30    await usingEthPlaygrounds(async (helper, privateKey) => {31      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);3233      donor = await privateKey({url: import.meta.url});34      [minter, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);35    });36  });3738  [39    'substrate' as const,40    'ethereum' as const,41  ].map(testCase => {42    itEth(`Can perform mintCross() for ${testCase} address`, async ({helper}) => {43      const collectionAdmin = await helper.eth.createAccountWithBalance(donor);4445      const receiverEth = helper.eth.createAccount();46      const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);47      const receiverSub = bob;48      const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(receiverSub);4950      const properties = Array(5).fill(0).map((_, i) => ({key: `key_${i}`, value: Buffer.from(`value_${i}`)}));51      const permissions: ITokenPropertyPermission[] = properties.map(p => ({key: p.key, permission: {52        tokenOwner: false,53        collectionAdmin: true,54        mutable: false}}));555657      const collection = await helper.rft.mintCollection(minter, {58        tokenPrefix: 'ethp',59        tokenPropertyPermissions: permissions,60      });61      await collection.addAdmin(minter, {Ethereum: collectionAdmin});6263      const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);64      const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', collectionAdmin, true);65      let expectedTokenId = await contract.methods.nextTokenId().call();66      let result = await contract.methods.mintCross(testCase === 'ethereum' ? receiverCrossEth : receiverCrossSub, []).send();67      let tokenId = result.events.Transfer.returnValues.tokenId;68      expect(tokenId).to.be.equal(expectedTokenId);6970      let event = result.events.Transfer;71      expect(event.address).to.be.equal(collectionAddress);72      expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');73      expect(event.returnValues.to).to.be.equal(testCase === 'ethereum' ? receiverEth : helper.address.substrateToEth(bob.address));74      expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);7576      expectedTokenId = await contract.methods.nextTokenId().call();77      result = await contract.methods.mintCross(testCase === 'ethereum' ? receiverCrossEth : receiverCrossSub, properties).send();78      event = result.events.Transfer;79      expect(event.address).to.be.equal(collectionAddress);80      expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');81      expect(event.returnValues.to).to.be.equal(testCase === 'ethereum' ? receiverEth : helper.address.substrateToEth(bob.address));82      expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);8384      tokenId = result.events.Transfer.returnValues.tokenId;8586      expect(tokenId).to.be.equal(expectedTokenId);8788      expect(await contract.methods.properties(tokenId, []).call()).to.be.like(properties89        .map(p => helper.ethProperty.property(p.key, p.value.toString())));9091      expect(await helper.nft.getTokenOwner(collection.collectionId, tokenId))92        .to.deep.eq(testCase === 'ethereum' ? {Ethereum: receiverEth.toLowerCase()} : {Substrate: receiverSub.address});93    });94  });9596  itEth.skip('Can perform mintBulk()', async ({helper}) => {97    const owner = await helper.eth.createAccountWithBalance(donor);98    const receiver = helper.eth.createAccount();99    const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleRFTCollection(owner, 'MintBulky', '6', '6', '');100    const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', owner);101102    {103      const nextTokenId = await contract.methods.nextTokenId().call();104      expect(nextTokenId).to.be.equal('1');105      const result = await contract.methods.mintBulkWithTokenURI(106        receiver,107        [108          [nextTokenId, 'Test URI 0'],109          [+nextTokenId + 1, 'Test URI 1'],110          [+nextTokenId + 2, 'Test URI 2'],111        ],112      ).send();113114      const events = result.events.Transfer;115      for(let i = 0; i < 2; i++) {116        const event = events[i];117        expect(event.address).to.equal(collectionAddress);118        expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');119        expect(event.returnValues.to).to.equal(receiver);120        expect(event.returnValues.tokenId).to.equal(String(+nextTokenId + i));121      }122123      expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI 0');124      expect(await contract.methods.tokenURI(+nextTokenId + 1).call()).to.be.equal('Test URI 1');125      expect(await contract.methods.tokenURI(+nextTokenId + 2).call()).to.be.equal('Test URI 2');126    }127  });128129  itEth('Can perform mintBulkCross()', async ({helper}) => {130    const caller = await helper.eth.createAccountWithBalance(donor);131    const callerCross = helper.ethCrossAccount.fromAddress(caller);132    const receiver = helper.eth.createAccount();133    const receiverCross = helper.ethCrossAccount.fromAddress(receiver);134135    const permissions = [136      {code: TokenPermissionField.Mutable, value: true},137      {code: TokenPermissionField.TokenOwner, value: true},138      {code: TokenPermissionField.CollectionAdmin, value: true},139    ];140    const {collectionAddress} = await helper.eth.createCollection(141      caller,142      {143        ...CREATE_COLLECTION_DATA_DEFAULTS,144        name: 'A',145        description: 'B',146        tokenPrefix: 'C',147        collectionMode: 'rft',148        adminList: [callerCross],149        tokenPropertyPermissions: [150          {key: 'key_0_0', permissions},151          {key: 'key_1_0', permissions},152          {key: 'key_1_1', permissions},153          {key: 'key_2_0', permissions},154          {key: 'key_2_1', permissions},155          {key: 'key_2_2', permissions},156        ],157      },158    ).send();159160    const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', caller);161    {162      const nextTokenId = await contract.methods.nextTokenId().call();163      expect(nextTokenId).to.be.equal('1');164      const result = await contract.methods.mintBulkCross([165        {166          owner: receiverCross,167          properties: [168            {key: 'key_0_0', value: Buffer.from('value_0_0')},169          ],170        },171        {172          owner: receiverCross,173          properties: [174            {key: 'key_1_0', value: Buffer.from('value_1_0')},175            {key: 'key_1_1', value: Buffer.from('value_1_1')},176          ],177        },178        {179          owner: receiverCross,180          properties: [181            {key: 'key_2_0', value: Buffer.from('value_2_0')},182            {key: 'key_2_1', value: Buffer.from('value_2_1')},183            {key: 'key_2_2', value: Buffer.from('value_2_2')},184          ],185        },186      ]).send({from: caller});187      const events = result.events.Transfer.sort((a: any, b: any) => +a.returnValues.tokenId - b.returnValues.tokenId);188      const bulkSize = 3;189      for(let i = 0; i < bulkSize; i++) {190        const event = events[i];191        expect(event.address).to.equal(collectionAddress);192        expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');193        expect(event.returnValues.to).to.equal(receiver);194        expect(event.returnValues.tokenId).to.equal(`${+nextTokenId + i}`);195      }196197      const properties = [198        await contract.methods.properties(+nextTokenId, []).call(),199        await contract.methods.properties(+nextTokenId + 1, []).call(),200        await contract.methods.properties(+nextTokenId + 2, []).call(),201      ];202      expect(properties).to.be.deep.equal([203        [204          ['key_0_0', helper.getWeb3().utils.toHex('value_0_0')],205        ],206        [207          ['key_1_0', helper.getWeb3().utils.toHex('value_1_0')],208          ['key_1_1', helper.getWeb3().utils.toHex('value_1_1')],209        ],210        [211          ['key_2_0', helper.getWeb3().utils.toHex('value_2_0')],212          ['key_2_1', helper.getWeb3().utils.toHex('value_2_1')],213          ['key_2_2', helper.getWeb3().utils.toHex('value_2_2')],214        ],215      ]);216    }217  });218219  itEth('Can perform setApprovalForAll()', async ({helper}) => {220    const owner = await helper.eth.createAccountWithBalance(donor);221    const operator = helper.eth.createAccount();222223    const collection = await helper.rft.mintCollection(minter, {});224225    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);226    const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', owner);227228    const approvedBefore = await contract.methods.isApprovedForAll(owner, operator).call();229    expect(approvedBefore).to.be.equal(false);230231    {232      const result = await contract.methods.setApprovalForAll(operator, true).send({from: owner});233234      expect(result.events.ApprovalForAll).to.be.like({235        address: collectionAddress,236        event: 'ApprovalForAll',237        returnValues: {238          owner,239          operator,240          approved: true,241        },242      });243244      const approvedAfter = await contract.methods.isApprovedForAll(owner, operator).call();245      expect(approvedAfter).to.be.equal(true);246    }247248    {249      const result = await contract.methods.setApprovalForAll(operator, false).send({from: owner});250251      expect(result.events.ApprovalForAll).to.be.like({252        address: collectionAddress,253        event: 'ApprovalForAll',254        returnValues: {255          owner,256          operator,257          approved: false,258        },259      });260261      const approvedAfter = await contract.methods.isApprovedForAll(owner, operator).call();262      expect(approvedAfter).to.be.equal(false);263    }264  });265266  itEth('Can perform burn with ApprovalForAll', async ({helper}) => {267    const collection = await helper.rft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});268269    const owner = await helper.eth.createAccountWithBalance(donor);270    const operator = await helper.eth.createAccountWithBalance(donor);271272    const token = await collection.mintToken(minter, 100n, {Ethereum: owner});273274    const address = helper.ethAddress.fromCollectionId(collection.collectionId);275    const contract = await helper.ethNativeContract.collection(address, 'rft');276277    {278      await contract.methods.setApprovalForAll(operator, true).send({from: owner});279      const ownerCross = helper.ethCrossAccount.fromAddress(owner);280      const result = await contract.methods.burnFromCross(ownerCross, token.tokenId).send({from: operator});281      const events = result.events.Transfer;282283      expect(events).to.be.like({284        address,285        event: 'Transfer',286        returnValues: {287          from: owner,288          to: '0x0000000000000000000000000000000000000000',289          tokenId: token.tokenId.toString(),290        },291      });292    }293  });294295  itEth('Can perform burn with approve and approvalForAll', async ({helper}) => {296    const collection = await helper.rft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});297298    const owner = await helper.eth.createAccountWithBalance(donor);299    const operator = await helper.eth.createAccountWithBalance(donor);300301    const token = await collection.mintToken(minter, 100n, {Ethereum: owner});302303    const address = helper.ethAddress.fromCollectionId(collection.collectionId);304    const contract = await helper.ethNativeContract.collection(address, 'rft');305306    const rftToken = await helper.ethNativeContract.rftTokenById(token.collectionId, token.tokenId, owner, true);307308    {309      await rftToken.methods.approve(operator, 15n).send({from: owner});310      await contract.methods.setApprovalForAll(operator, true).send({from: owner});311      await rftToken.methods.burnFrom(owner, 10n).send({from: operator});312    }313    {314      const allowance = await rftToken.methods.allowance(owner, operator).call();315      expect(+allowance).to.be.equal(5);316    }317    {318      const ownerCross = helper.ethCrossAccount.fromAddress(owner);319      const operatorCross = helper.ethCrossAccount.fromAddress(operator);320      const allowance = await rftToken.methods.allowanceCross(ownerCross, operatorCross).call();321      expect(+allowance).to.equal(5);322    }323  });324325  itEth('Can perform transfer with ApprovalForAll', async ({helper}) => {326    const collection = await helper.rft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});327328    const owner = await helper.eth.createAccountWithBalance(donor);329    const operator = await helper.eth.createAccountWithBalance(donor);330    const receiver = charlie;331332    const token = await collection.mintToken(minter, 100n, {Ethereum: owner});333334    const address = helper.ethAddress.fromCollectionId(collection.collectionId);335    const contract = await helper.ethNativeContract.collection(address, 'rft');336337    {338      await contract.methods.setApprovalForAll(operator, true).send({from: owner});339      const ownerCross = helper.ethCrossAccount.fromAddress(owner);340      const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);341      const result = await contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: operator});342      const event = result.events.Transfer;343      expect(event).to.be.like({344        address: helper.ethAddress.fromCollectionId(collection.collectionId),345        event: 'Transfer',346        returnValues: {347          from: owner,348          to: helper.address.substrateToEth(receiver.address),349          tokenId: token.tokenId.toString(),350        },351      });352    }353354    expect(await token.getTop10Owners()).to.be.like([{Substrate: receiver.address}]);355  });356357  itEth('Can perform burn()', async ({helper}) => {358    const caller = await helper.eth.createAccountWithBalance(donor);359    const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'Burny', '6', '6');360    const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);361362    const result = await contract.methods.mint(caller).send();363    const tokenId = result.events.Transfer.returnValues.tokenId;364    {365      const result = await contract.methods.burn(tokenId).send();366      const event = result.events.Transfer;367      expect(event.address).to.equal(collectionAddress);368      expect(event.returnValues.from).to.equal(caller);369      expect(event.returnValues.to).to.equal('0x0000000000000000000000000000000000000000');370      expect(event.returnValues.tokenId).to.equal(tokenId.toString());371    }372  });373374  itEth('Can perform transferFrom()', async ({helper}) => {375    const caller = await helper.eth.createAccountWithBalance(donor);376    const receiver = helper.eth.createAccount();377    const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'TransferFromy', '6', '6');378    const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);379380    const result = await contract.methods.mint(caller).send();381    const tokenId = result.events.Transfer.returnValues.tokenId;382383    const tokenAddress = helper.ethAddress.fromTokenId(collectionId, tokenId);384385    const tokenContract = await helper.ethNativeContract.rftToken(tokenAddress, caller);386    await tokenContract.methods.repartition(15).send();387388    {389      const tokenEvents: any = [];390      tokenContract.events.allEvents((_: any, event: any) => {391        tokenEvents.push(event);392      });393      const result = await contract.methods.transferFrom(caller, receiver, tokenId).send();394      if(tokenEvents.length == 0) await helper.wait.newBlocks(1);395396      let event = result.events.Transfer;397      expect(event.address).to.equal(collectionAddress);398      expect(event.returnValues.from).to.equal(caller);399      expect(event.returnValues.to).to.equal(receiver);400      expect(event.returnValues.tokenId).to.equal(tokenId.toString());401402      event = tokenEvents[0];403      expect(event.address).to.equal(tokenAddress);404      expect(event.returnValues.from).to.equal(caller);405      expect(event.returnValues.to).to.equal(receiver);406      expect(event.returnValues.value).to.equal('15');407    }408409    {410      const balance = await contract.methods.balanceOf(receiver).call();411      expect(+balance).to.equal(1);412    }413414    {415      const balance = await contract.methods.balanceOf(caller).call();416      expect(+balance).to.equal(0);417    }418  });419420  // Soft-deprecated421  itEth('Can perform burnFrom()', async ({helper}) => {422    const collection = await helper.rft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});423424    const owner = await helper.eth.createAccountWithBalance(donor);425    const spender = await helper.eth.createAccountWithBalance(donor);426427    const token = await collection.mintToken(minter, 100n, {Ethereum: owner});428429    const address = helper.ethAddress.fromCollectionId(collection.collectionId);430    const contract = await helper.ethNativeContract.collection(address, 'rft', spender, true);431432    const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, token.tokenId);433    const tokenContract = await helper.ethNativeContract.rftToken(tokenAddress, owner);434    await tokenContract.methods.repartition(15).send();435    await tokenContract.methods.approve(spender, 15).send();436437    {438      const result = await contract.methods.burnFrom(owner, token.tokenId).send();439      const event = result.events.Transfer;440      expect(event).to.be.like({441        address: helper.ethAddress.fromCollectionId(collection.collectionId),442        event: 'Transfer',443        returnValues: {444          from: owner,445          to: '0x0000000000000000000000000000000000000000',446          tokenId: token.tokenId.toString(),447        },448      });449    }450451    expect(await collection.getTokenBalance(token.tokenId, {Ethereum: owner})).to.be.eq(0n);452  });453454  itEth('Can perform burnFromCross()', async ({helper}) => {455    const collection = await helper.rft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});456457    const owner = bob;458    const spender = await helper.eth.createAccountWithBalance(donor);459460    const token = await collection.mintToken(minter, 100n, {Substrate: owner.address});461462    const address = helper.ethAddress.fromCollectionId(collection.collectionId);463    const contract = await helper.ethNativeContract.collection(address, 'rft');464465    await token.repartition(owner, 15n);466    await token.approve(owner, {Ethereum: spender}, 15n);467468    {469      const ownerCross = helper.ethCrossAccount.fromKeyringPair(owner);470      const result = await contract.methods.burnFromCross(ownerCross, token.tokenId).send({from: spender});471      const event = result.events.Transfer;472      expect(event).to.be.like({473        address: helper.ethAddress.fromCollectionId(collection.collectionId),474        event: 'Transfer',475        returnValues: {476          from: helper.address.substrateToEth(owner.address),477          to: '0x0000000000000000000000000000000000000000',478          tokenId: token.tokenId.toString(),479        },480      });481    }482483    expect(await collection.getTokenBalance(token.tokenId, {Substrate: owner.address})).to.be.eq(0n);484  });485486  itEth('Can perform transferFromCross()', async ({helper}) => {487    const collection = await helper.rft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});488489    const owner = bob;490    const spender = await helper.eth.createAccountWithBalance(donor);491    const receiver = charlie;492493    const token = await collection.mintToken(minter, 100n, {Substrate: owner.address});494495    const address = helper.ethAddress.fromCollectionId(collection.collectionId);496    const contract = await helper.ethNativeContract.collection(address, 'rft');497498    await token.repartition(owner, 15n);499    await token.approve(owner, {Ethereum: spender}, 15n);500501    {502      const ownerCross = helper.ethCrossAccount.fromKeyringPair(owner);503      const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);504      const result = await contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender});505      const event = result.events.Transfer;506      expect(event).to.be.like({507        address: helper.ethAddress.fromCollectionId(collection.collectionId),508        event: 'Transfer',509        returnValues: {510          from: helper.address.substrateToEth(owner.address),511          to: helper.address.substrateToEth(receiver.address),512          tokenId: token.tokenId.toString(),513        },514      });515    }516517    expect(await token.getTop10Owners()).to.be.like([{Substrate: receiver.address}]);518  });519520  itEth('Can perform transfer()', async ({helper}) => {521    const caller = await helper.eth.createAccountWithBalance(donor);522    const receiver = helper.eth.createAccount();523    const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'Transferry', '6', '6');524    const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);525526    const result = await contract.methods.mint(caller).send();527    const tokenId = result.events.Transfer.returnValues.tokenId;528529    {530      const result = await contract.methods.transfer(receiver, tokenId).send();531532      const event = result.events.Transfer;533      expect(event.address).to.equal(collectionAddress);534      expect(event.returnValues.from).to.equal(caller);535      expect(event.returnValues.to).to.equal(receiver);536      expect(event.returnValues.tokenId).to.equal(tokenId.toString());537    }538539    {540      const balance = await contract.methods.balanceOf(caller).call();541      expect(+balance).to.equal(0);542    }543544    {545      const balance = await contract.methods.balanceOf(receiver).call();546      expect(+balance).to.equal(1);547    }548  });549550  itEth('Can perform transferCross()', async ({helper}) => {551    const sender = await helper.eth.createAccountWithBalance(donor);552    const receiverEth = await helper.eth.createAccountWithBalance(donor);553    const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);554    const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(minter);555556    const collection = await helper.rft.mintCollection(minter, {});557    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);558    const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'rft', sender);559560    const token = await collection.mintToken(minter, 50n, {Ethereum: sender});561562    {563      // Can transferCross to ethereum address:564      const result = await collectionEvm.methods.transferCross(receiverCrossEth, token.tokenId).send({from: sender});565      // Check events:566      const event = result.events.Transfer;567      expect(event.address).to.equal(collectionAddress);568      expect(event.returnValues.from).to.equal(sender);569      expect(event.returnValues.to).to.equal(receiverEth);570      expect(event.returnValues.tokenId).to.equal(token.tokenId.toString());571      // Sender's balance decreased:572      const senderBalance = await collectionEvm.methods.balanceOf(sender).call();573      expect(+senderBalance).to.equal(0);574      expect(await token.getBalance({Ethereum: sender})).to.eq(0n);575      // Receiver's balance increased:576      const receiverBalance = await collectionEvm.methods.balanceOf(receiverEth).call();577      expect(+receiverBalance).to.equal(1);578      expect(await token.getBalance({Ethereum: receiverEth})).to.eq(50n);579    }580581    {582      // Can transferCross to substrate address:583      const substrateResult = await collectionEvm.methods.transferCross(receiverCrossSub, token.tokenId).send({from: receiverEth});584      // Check events:585      const event = substrateResult.events.Transfer;586      expect(event.address).to.be.equal(collectionAddress);587      expect(event.returnValues.from).to.be.equal(receiverEth);588      expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(minter.address));589      expect(event.returnValues.tokenId).to.be.equal(`${token.tokenId}`);590      // Sender's balance decreased:591      const senderBalance = await collectionEvm.methods.balanceOf(receiverEth).call();592      expect(+senderBalance).to.equal(0);593      expect(await token.getBalance({Ethereum: receiverEth})).to.eq(0n);594      // Receiver's balance increased:595      const receiverBalance = await helper.nft.getTokensByAddress(collection.collectionId, {Substrate: minter.address});596      expect(receiverBalance).to.contain(token.tokenId);597      expect(await token.getBalance({Substrate: minter.address})).to.eq(50n);598    }599  });600601  ['transfer', 'transferCross'].map(testCase => itEth(`Cannot ${testCase} non-owned token`, async ({helper}) => {602    const sender = await helper.eth.createAccountWithBalance(donor);603    const tokenOwner = await helper.eth.createAccountWithBalance(donor);604    const receiverSub = minter;605    const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(minter);606607    const collection = await helper.rft.mintCollection(minter, {});608    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);609    const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'rft', sender);610611    await collection.mintToken(minter, 50n, {Ethereum: sender});612    const nonSendersToken = await collection.mintToken(minter, 50n, {Ethereum: tokenOwner});613614    // Cannot transferCross someone else's token:615    const receiver = testCase === 'transfer' ? helper.address.substrateToEth(receiverSub.address) : receiverCrossSub;616    await expect(collectionEvm.methods[testCase](receiver, nonSendersToken.tokenId).send({from: sender})).to.be.rejected;617    // Cannot transfer token if it does not exist:618    await expect(collectionEvm.methods[testCase](receiver, 999999).send({from: sender})).to.be.rejected;619  }));620621  itEth('transfer event on transfer from partial ownership to full ownership', async ({helper}) => {622    const caller = await helper.eth.createAccountWithBalance(donor);623    const receiver = helper.eth.createAccount();624    const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'Transferry-Partial-to-Full', '6', '6');625    const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);626627    const result = await contract.methods.mint(caller).send();628    const tokenId = result.events.Transfer.returnValues.tokenId;629630    const tokenContract = await helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);631632    await tokenContract.methods.repartition(2).send();633    await tokenContract.methods.transfer(receiver, 1).send();634635    const events: any = [];636    contract.events.allEvents((_: any, event: any) => {637      events.push(event);638    });639640    await tokenContract.methods.transfer(receiver, 1).send();641    if(events.length == 0) await helper.wait.newBlocks(1);642    const event = events[0];643644    expect(event.address).to.equal(collectionAddress);645    expect(event.returnValues.from).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');646    expect(event.returnValues.to).to.equal(receiver);647    expect(event.returnValues.tokenId).to.equal(tokenId.toString());648  });649650  itEth('transfer event on transfer from full ownership to partial ownership', async ({helper}) => {651    const caller = await helper.eth.createAccountWithBalance(donor);652    const receiver = helper.eth.createAccount();653    const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'Transferry-Full-to-Partial', '6', '6');654    const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);655656    const result = await contract.methods.mint(caller).send();657    const tokenId = result.events.Transfer.returnValues.tokenId;658659    const tokenContract = await helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);660661    await tokenContract.methods.repartition(2).send();662663    const events: any = [];664    contract.events.allEvents((_: any, event: any) => {665      events.push(event);666    });667668    await tokenContract.methods.transfer(receiver, 1).send();669    if(events.length == 0) await helper.wait.newBlocks(1);670    const event = events[0];671672    expect(event.address).to.equal(collectionAddress);673    expect(event.returnValues.from).to.equal(caller);674    expect(event.returnValues.to).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');675    expect(event.returnValues.tokenId).to.equal(tokenId.toString());676  });677678  itEth('Check balanceOfCross()', async ({helper}) => {679    const collection = await helper.rft.mintCollection(minter, {});680    const owner = await helper.ethCrossAccount.createAccountWithBalance(donor);681    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);682    const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner.eth);683684    expect(await collectionEvm.methods.balanceOfCross(owner).call({from: owner.eth})).to.be.eq('0');685686    for(let i = 1n; i < 10n; i++) {687      await collection.mintToken(minter, 100n, {Ethereum: owner.eth});688      expect(await collectionEvm.methods.balanceOfCross(owner).call({from: owner.eth})).to.be.eq(i.toString());689    }690  });691692  itEth('Check ownerOfCross()', async ({helper}) => {693    const collection = await helper.rft.mintCollection(minter, {});694    let owner = await helper.ethCrossAccount.createAccountWithBalance(donor);695    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);696    const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner.eth);697    const {tokenId} = await collection.mintToken(minter, 100n,{Ethereum: owner.eth});698699    for(let i = 1n; i < 10n; i++) {700      const ownerCross = await collectionEvm.methods.ownerOfCross(tokenId).call({from: owner.eth});701      expect(ownerCross.eth).to.be.eq(owner.eth);702      expect(ownerCross.sub).to.be.eq(owner.sub);703704      const newOwner = await helper.ethCrossAccount.createAccountWithBalance(donor);705      await collectionEvm.methods.transferCross(newOwner, tokenId).send({from: owner.eth});706      owner = newOwner;707    }708709    const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);710    const tokenContract = await helper.ethNativeContract.rftToken(tokenAddress, owner.eth, true);711    const newOwner = await helper.ethCrossAccount.createAccountWithBalance(donor);712    await tokenContract.methods.transferCross(newOwner, 50).send({from: owner.eth});713    const ownerCross = await collectionEvm.methods.ownerOfCross(tokenId).call({from: owner.eth});714    expect(ownerCross.eth.toUpperCase()).to.be.eq('0XFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF');715    expect(ownerCross.sub).to.be.eq('0');716  });717});718719describe('RFT: Fees', () => {720  let donor: IKeyringPair;721722  before(async function() {723    await usingEthPlaygrounds(async (helper, privateKey) => {724      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);725726      donor = await privateKey({url: import.meta.url});727    });728  });729730  itEth('transferFrom() call fee is less than 0.2UNQ', async ({helper}) => {731    const caller = await helper.eth.createAccountWithBalance(donor);732    const receiver = helper.eth.createAccount();733    const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'Feeful-Transfer-From', '6', '6');734    const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);735736    const result = await contract.methods.mint(caller).send();737    const tokenId = result.events.Transfer.returnValues.tokenId;738739    const cost = await helper.eth.recordCallFee(caller, () => contract.methods.transferFrom(caller, receiver, tokenId).send());740    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));741    expect(cost > 0n);742  });743744  itEth('transfer() call fee is less than 0.2UNQ', async ({helper}) => {745    const caller = await helper.eth.createAccountWithBalance(donor);746    const receiver = helper.eth.createAccount();747    const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'Feeful-Transfer', '6', '6');748    const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);749750    const result = await contract.methods.mint(caller).send();751    const tokenId = result.events.Transfer.returnValues.tokenId;752753    const cost = await helper.eth.recordCallFee(caller, () => contract.methods.transfer(receiver, tokenId).send());754    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));755    expect(cost > 0n);756  });757});758759describe('Common metadata', () => {760  let donor: IKeyringPair;761  let alice: IKeyringPair;762763  before(async function() {764    await usingEthPlaygrounds(async (helper, privateKey) => {765      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);766767      donor = await privateKey({url: import.meta.url});768      [alice] = await helper.arrange.createAccounts([1000n], donor);769    });770  });771772  itEth('Returns collection name', async ({helper}) => {773    const caller = helper.eth.createAccount();774    const tokenPropertyPermissions = [{775      key: 'URI',776      permission: {777        mutable: true,778        collectionAdmin: true,779        tokenOwner: false,780      },781    }];782    const collection = await helper.rft.mintCollection(783      alice,784      {785        name: 'Leviathan',786        tokenPrefix: '11',787        properties: [{key: 'ERC721Metadata', value: '1'}],788        tokenPropertyPermissions,789      },790    );791792    const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'rft', caller);793    const name = await contract.methods.name().call();794    expect(name).to.equal('Leviathan');795  });796797  itEth('Returns symbol name', async ({helper}) => {798    const caller = await helper.eth.createAccountWithBalance(donor);799    const tokenPropertyPermissions = [{800      key: 'URI',801      permission: {802        mutable: true,803        collectionAdmin: true,804        tokenOwner: false,805      },806    }];807    const {collectionId} = await helper.rft.mintCollection(808      alice,809      {810        name: 'Leviathan',811        tokenPrefix: '12',812        properties: [{key: 'ERC721Metadata', value: '1'}],813        tokenPropertyPermissions,814      },815    );816817    const contract = await helper.ethNativeContract.collectionById(collectionId, 'rft', caller);818    const symbol = await contract.methods.symbol().call();819    expect(symbol).to.equal('12');820  });821});822823describe('Negative tests', () => {824  let donor: IKeyringPair;825  let minter: IKeyringPair;826  let alice: IKeyringPair;827828  before(async function() {829    await usingEthPlaygrounds(async (helper, privateKey) => {830      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);831832      donor = await privateKey({url: import.meta.url});833      [minter, alice] = await helper.arrange.createAccounts([100n, 100n], donor);834    });835  });836837  itEth('[negative] Cant perform burn without approval', async ({helper}) => {838    const collection = await helper.rft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});839840    const owner = await helper.eth.createAccountWithBalance(donor);841    const spender = await helper.eth.createAccountWithBalance(donor);842843    const token = await collection.mintToken(minter, 100n, {Ethereum: owner});844845    const address = helper.ethAddress.fromCollectionId(collection.collectionId);846    const contract = await helper.ethNativeContract.collection(address, 'rft');847848    const ownerCross = helper.ethCrossAccount.fromAddress(owner);849850    await expect(contract.methods.burnFromCross(ownerCross, token.tokenId).send({from: spender})).to.be.rejected;851852    await contract.methods.setApprovalForAll(spender, true).send({from: owner});853    await contract.methods.setApprovalForAll(spender, false).send({from: owner});854855    await expect(contract.methods.burnFromCross(ownerCross, token.tokenId).send({from: spender})).to.be.rejected;856  });857858  itEth('[negative] Cant perform transfer without approval', async ({helper}) => {859    const collection = await helper.rft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});860    const owner = await helper.eth.createAccountWithBalance(donor);861    const receiver = alice;862863    const spender = await helper.eth.createAccountWithBalance(donor);864865    const token = await collection.mintToken(minter, 100n, {Ethereum: owner});866867    const address = helper.ethAddress.fromCollectionId(collection.collectionId);868    const contract = await helper.ethNativeContract.collection(address, 'rft');869870    const ownerCross = helper.ethCrossAccount.fromAddress(owner);871    const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);872873    await expect(contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender})).to.be.rejected;874875    await contract.methods.setApprovalForAll(spender, true).send({from: owner});876    await contract.methods.setApprovalForAll(spender, false).send({from: owner});877878    await expect(contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender})).to.be.rejected;879  });880});