git.delta.rocks / unique-network / refs/commits / 29762d93da0e

difftreelog

fix tests

Trubnikov Sergey2023-04-18parent: #9871bd2.patch.diff
in: master

4 files changed

modifiedtests/src/eth/fungible.test.tsdiffbeforeafterboth
--- a/tests/src/eth/fungible.test.ts
+++ b/tests/src/eth/fungible.test.ts
@@ -431,17 +431,28 @@
   itEth('Check balanceOfCross()', async ({helper}) => {
     const collection = await helper.ft.mintCollection(alice, {});
     const owner = await helper.ethCrossAccount.createAccountWithBalance(donor);
+    const other = await helper.ethCrossAccount.createAccountWithBalance(donor);
     const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
     const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner.eth);
 
     expect(BigInt(await collectionEvm.methods.balanceOfCross(owner).call({from: owner.eth})) === 0n).to.be.true;
+    expect(BigInt(await collectionEvm.methods.balanceOfCross(other).call({from: owner.eth})) === 0n).to.be.true;
+
+    await collection.mint(alice, 100n, {Ethereum: owner.eth});
+    expect(BigInt(await collectionEvm.methods.balanceOfCross(owner).call({from: owner.eth})) === 100n).to.be.true;
+    expect(BigInt(await collectionEvm.methods.balanceOfCross(other).call({from: owner.eth})) === 0n).to.be.true;
 
-    let sum = 0n;
-    for (let i = 1n; i < 100n; i++) {
-      await collection.mint(alice, 100n, {Ethereum: owner.eth});
-      sum += 100n;
-      expect(BigInt(await collectionEvm.methods.balanceOfCross(owner).call({from: owner.eth})) === sum).to.be.true;
-    }
+    await collectionEvm.methods.transferCross(other, 50n).send({from: owner.eth});
+    expect(BigInt(await collectionEvm.methods.balanceOfCross(owner).call({from: owner.eth})) === 50n).to.be.true;
+    expect(BigInt(await collectionEvm.methods.balanceOfCross(other).call({from: owner.eth})) === 50n).to.be.true;
+
+    await collectionEvm.methods.transferCross(other, 50n).send({from: owner.eth});
+    expect(BigInt(await collectionEvm.methods.balanceOfCross(owner).call({from: owner.eth})) === 0n).to.be.true;
+    expect(BigInt(await collectionEvm.methods.balanceOfCross(other).call({from: owner.eth})) === 100n).to.be.true;
+
+    await collectionEvm.methods.transferCross(owner, 100n).send({from: other.eth});
+    expect(BigInt(await collectionEvm.methods.balanceOfCross(owner).call({from: owner.eth})) === 100n).to.be.true;
+    expect(BigInt(await collectionEvm.methods.balanceOfCross(other).call({from: owner.eth})) === 0n).to.be.true;
   });
 });
 
modifiedtests/src/eth/nonFungible.test.tsdiffbeforeafterboth
--- a/tests/src/eth/nonFungible.test.ts
+++ b/tests/src/eth/nonFungible.test.ts
@@ -671,7 +671,7 @@
 
     expect(BigInt(await collectionEvm.methods.balanceOfCross(owner).call({from: owner.eth})) === 0n).to.be.true;
 
-    for (let i = 1n; i < 100n; i++) {
+    for (let i = 1n; i < 10n; i++) {
       await collection.mintToken(minter, {Ethereum: owner.eth});
       expect(BigInt(await collectionEvm.methods.balanceOfCross(owner).call({from: owner.eth})) === i).to.be.true;
     }
modifiedtests/src/eth/reFungible.test.tsdiffbeforeafterboth
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';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) => { return {key: `key_${i}`, value: Buffer.from(`value_${i}`)}; });50      const permissions: ITokenPropertyPermission[] = properties.map(p => { return {key: p.key, permission: {51        tokenOwner: false,52        collectionAdmin: true,53        mutable: false}};54      });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 => { return 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 setApprovalForAll()', async ({helper}) => {130    const owner = await helper.eth.createAccountWithBalance(donor);131    const operator = helper.eth.createAccount();132133    const collection = await helper.rft.mintCollection(minter, {});134135    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);136    const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', owner);137138    const approvedBefore = await contract.methods.isApprovedForAll(owner, operator).call();139    expect(approvedBefore).to.be.equal(false);140141    {142      const result = await contract.methods.setApprovalForAll(operator, true).send({from: owner});143144      expect(result.events.ApprovalForAll).to.be.like({145        address: collectionAddress,146        event: 'ApprovalForAll',147        returnValues: {148          owner,149          operator,150          approved: true,151        },152      });153154      const approvedAfter = await contract.methods.isApprovedForAll(owner, operator).call();155      expect(approvedAfter).to.be.equal(true);156    }157158    {159      const result = await contract.methods.setApprovalForAll(operator, false).send({from: owner});160161      expect(result.events.ApprovalForAll).to.be.like({162        address: collectionAddress,163        event: 'ApprovalForAll',164        returnValues: {165          owner,166          operator,167          approved: false,168        },169      });170171      const approvedAfter = await contract.methods.isApprovedForAll(owner, operator).call();172      expect(approvedAfter).to.be.equal(false);173    }174  });175176  itEth('Can perform burn with ApprovalForAll', async ({helper}) => {177    const collection = await helper.rft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});178179    const owner = await helper.eth.createAccountWithBalance(donor);180    const operator = await helper.eth.createAccountWithBalance(donor, 100n);181182    const token = await collection.mintToken(minter, 100n, {Ethereum: owner});183184    const address = helper.ethAddress.fromCollectionId(collection.collectionId);185    const contract = await helper.ethNativeContract.collection(address, 'rft');186187    {188      await contract.methods.setApprovalForAll(operator, true).send({from: owner});189      const ownerCross = helper.ethCrossAccount.fromAddress(owner);190      const result = await contract.methods.burnFromCross(ownerCross, token.tokenId).send({from: operator});191      const events = result.events.Transfer;192193      expect(events).to.be.like({194        address,195        event: 'Transfer',196        returnValues: {197          from: owner,198          to: '0x0000000000000000000000000000000000000000',199          tokenId: token.tokenId.toString(),200        },201      });202    }203  });204205  itEth('Can perform burn with approve and approvalForAll', async ({helper}) => {206    const collection = await helper.rft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});207208    const owner = await helper.eth.createAccountWithBalance(donor);209    const operator = await helper.eth.createAccountWithBalance(donor, 100n);210211    const token = await collection.mintToken(minter, 100n, {Ethereum: owner});212213    const address = helper.ethAddress.fromCollectionId(collection.collectionId);214    const contract = await helper.ethNativeContract.collection(address, 'rft');215216    const rftToken = await helper.ethNativeContract.rftTokenById(token.collectionId, token.tokenId, owner, true);217218    {219      await rftToken.methods.approve(operator, 15n).send({from: owner});220      await contract.methods.setApprovalForAll(operator, true).send({from: owner});221      await rftToken.methods.burnFrom(owner, 10n).send({from: operator});222    }223    {224      const allowance = await rftToken.methods.allowance(owner, operator).call();225      expect(+allowance).to.be.equal(5);226    }227    {228      const ownerCross = helper.ethCrossAccount.fromAddress(owner);229      const operatorCross = helper.ethCrossAccount.fromAddress(operator);230      const allowance = await rftToken.methods.allowanceCross(ownerCross, operatorCross).call();231      expect(+allowance).to.equal(5);232    }233  });234235  itEth('Can perform transfer with ApprovalForAll', async ({helper}) => {236    const collection = await helper.rft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});237238    const owner = await helper.eth.createAccountWithBalance(donor);239    const operator = await helper.eth.createAccountWithBalance(donor);240    const receiver = charlie;241242    const token = await collection.mintToken(minter, 100n, {Ethereum: owner});243244    const address = helper.ethAddress.fromCollectionId(collection.collectionId);245    const contract = await helper.ethNativeContract.collection(address, 'rft');246247    {248      await contract.methods.setApprovalForAll(operator, true).send({from: owner});249      const ownerCross = helper.ethCrossAccount.fromAddress(owner);250      const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);251      const result = await contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: operator});252      const event = result.events.Transfer;253      expect(event).to.be.like({254        address: helper.ethAddress.fromCollectionId(collection.collectionId),255        event: 'Transfer',256        returnValues: {257          from: owner,258          to: helper.address.substrateToEth(receiver.address),259          tokenId: token.tokenId.toString(),260        },261      });262    }263264    expect(await token.getTop10Owners()).to.be.like([{Substrate: receiver.address}]);265  });266267  itEth('Can perform burn()', async ({helper}) => {268    const caller = await helper.eth.createAccountWithBalance(donor);269    const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'Burny', '6', '6');270    const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);271272    const result = await contract.methods.mint(caller).send();273    const tokenId = result.events.Transfer.returnValues.tokenId;274    {275      const result = await contract.methods.burn(tokenId).send();276      const event = result.events.Transfer;277      expect(event.address).to.equal(collectionAddress);278      expect(event.returnValues.from).to.equal(caller);279      expect(event.returnValues.to).to.equal('0x0000000000000000000000000000000000000000');280      expect(event.returnValues.tokenId).to.equal(tokenId.toString());281    }282  });283284  itEth('Can perform transferFrom()', async ({helper}) => {285    const caller = await helper.eth.createAccountWithBalance(donor);286    const receiver = helper.eth.createAccount();287    const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'TransferFromy', '6', '6');288    const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);289290    const result = await contract.methods.mint(caller).send();291    const tokenId = result.events.Transfer.returnValues.tokenId;292293    const tokenAddress = helper.ethAddress.fromTokenId(collectionId, tokenId);294295    const tokenContract = await helper.ethNativeContract.rftToken(tokenAddress, caller);296    await tokenContract.methods.repartition(15).send();297298    {299      const tokenEvents: any = [];300      tokenContract.events.allEvents((_: any, event: any) => {301        tokenEvents.push(event);302      });303      const result = await contract.methods.transferFrom(caller, receiver, tokenId).send();304      if (tokenEvents.length == 0) await helper.wait.newBlocks(1);305306      let event = result.events.Transfer;307      expect(event.address).to.equal(collectionAddress);308      expect(event.returnValues.from).to.equal(caller);309      expect(event.returnValues.to).to.equal(receiver);310      expect(event.returnValues.tokenId).to.equal(tokenId.toString());311312      event = tokenEvents[0];313      expect(event.address).to.equal(tokenAddress);314      expect(event.returnValues.from).to.equal(caller);315      expect(event.returnValues.to).to.equal(receiver);316      expect(event.returnValues.value).to.equal('15');317    }318319    {320      const balance = await contract.methods.balanceOf(receiver).call();321      expect(+balance).to.equal(1);322    }323324    {325      const balance = await contract.methods.balanceOf(caller).call();326      expect(+balance).to.equal(0);327    }328  });329330  // Soft-deprecated331  itEth('Can perform burnFrom()', async ({helper}) => {332    const collection = await helper.rft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});333334    const owner = await helper.eth.createAccountWithBalance(donor, 100n);335    const spender = await helper.eth.createAccountWithBalance(donor, 100n);336337    const token = await collection.mintToken(minter, 100n, {Ethereum: owner});338339    const address = helper.ethAddress.fromCollectionId(collection.collectionId);340    const contract = await helper.ethNativeContract.collection(address, 'rft', spender, true);341342    const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, token.tokenId);343    const tokenContract = await helper.ethNativeContract.rftToken(tokenAddress, owner);344    await tokenContract.methods.repartition(15).send();345    await tokenContract.methods.approve(spender, 15).send();346347    {348      const result = await contract.methods.burnFrom(owner, token.tokenId).send();349      const event = result.events.Transfer;350      expect(event).to.be.like({351        address: helper.ethAddress.fromCollectionId(collection.collectionId),352        event: 'Transfer',353        returnValues: {354          from: owner,355          to: '0x0000000000000000000000000000000000000000',356          tokenId: token.tokenId.toString(),357        },358      });359    }360361    expect(await collection.getTokenBalance(token.tokenId, {Ethereum: owner})).to.be.eq(0n);362  });363364  itEth('Can perform burnFromCross()', async ({helper}) => {365    const collection = await helper.rft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});366367    const owner = bob;368    const spender = await helper.eth.createAccountWithBalance(donor, 100n);369370    const token = await collection.mintToken(minter, 100n, {Substrate: owner.address});371372    const address = helper.ethAddress.fromCollectionId(collection.collectionId);373    const contract = await helper.ethNativeContract.collection(address, 'rft');374375    await token.repartition(owner, 15n);376    await token.approve(owner, {Ethereum: spender}, 15n);377378    {379      const ownerCross = helper.ethCrossAccount.fromKeyringPair(owner);380      const result = await contract.methods.burnFromCross(ownerCross, token.tokenId).send({from: spender});381      const event = result.events.Transfer;382      expect(event).to.be.like({383        address: helper.ethAddress.fromCollectionId(collection.collectionId),384        event: 'Transfer',385        returnValues: {386          from: helper.address.substrateToEth(owner.address),387          to: '0x0000000000000000000000000000000000000000',388          tokenId: token.tokenId.toString(),389        },390      });391    }392393    expect(await collection.getTokenBalance(token.tokenId, {Substrate: owner.address})).to.be.eq(0n);394  });395396  itEth('Can perform transferFromCross()', async ({helper}) => {397    const collection = await helper.rft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});398399    const owner = bob;400    const spender = await helper.eth.createAccountWithBalance(donor, 100n);401    const receiver = charlie;402403    const token = await collection.mintToken(minter, 100n, {Substrate: owner.address});404405    const address = helper.ethAddress.fromCollectionId(collection.collectionId);406    const contract = await helper.ethNativeContract.collection(address, 'rft');407408    await token.repartition(owner, 15n);409    await token.approve(owner, {Ethereum: spender}, 15n);410411    {412      const ownerCross = helper.ethCrossAccount.fromKeyringPair(owner);413      const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);414      const result = await contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender});415      const event = result.events.Transfer;416      expect(event).to.be.like({417        address: helper.ethAddress.fromCollectionId(collection.collectionId),418        event: 'Transfer',419        returnValues: {420          from: helper.address.substrateToEth(owner.address),421          to: helper.address.substrateToEth(receiver.address),422          tokenId: token.tokenId.toString(),423        },424      });425    }426427    expect(await token.getTop10Owners()).to.be.like([{Substrate: receiver.address}]);428  });429430  itEth('Can perform transfer()', async ({helper}) => {431    const caller = await helper.eth.createAccountWithBalance(donor);432    const receiver = helper.eth.createAccount();433    const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'Transferry', '6', '6');434    const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);435436    const result = await contract.methods.mint(caller).send();437    const tokenId = result.events.Transfer.returnValues.tokenId;438439    {440      const result = await contract.methods.transfer(receiver, tokenId).send();441442      const event = result.events.Transfer;443      expect(event.address).to.equal(collectionAddress);444      expect(event.returnValues.from).to.equal(caller);445      expect(event.returnValues.to).to.equal(receiver);446      expect(event.returnValues.tokenId).to.equal(tokenId.toString());447    }448449    {450      const balance = await contract.methods.balanceOf(caller).call();451      expect(+balance).to.equal(0);452    }453454    {455      const balance = await contract.methods.balanceOf(receiver).call();456      expect(+balance).to.equal(1);457    }458  });459460  itEth('Can perform transferCross()', async ({helper}) => {461    const sender = await helper.eth.createAccountWithBalance(donor);462    const receiverEth = await helper.eth.createAccountWithBalance(donor);463    const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);464    const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(minter);465466    const collection = await helper.rft.mintCollection(minter, {});467    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);468    const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'rft', sender);469470    const token = await collection.mintToken(minter, 50n, {Ethereum: sender});471472    {473      // Can transferCross to ethereum address:474      const result = await collectionEvm.methods.transferCross(receiverCrossEth, token.tokenId).send({from: sender});475      // Check events:476      const event = result.events.Transfer;477      expect(event.address).to.equal(collectionAddress);478      expect(event.returnValues.from).to.equal(sender);479      expect(event.returnValues.to).to.equal(receiverEth);480      expect(event.returnValues.tokenId).to.equal(token.tokenId.toString());481      // Sender's balance decreased:482      const senderBalance = await collectionEvm.methods.balanceOf(sender).call();483      expect(+senderBalance).to.equal(0);484      expect(await token.getBalance({Ethereum: sender})).to.eq(0n);485      // Receiver's balance increased:486      const receiverBalance = await collectionEvm.methods.balanceOf(receiverEth).call();487      expect(+receiverBalance).to.equal(1);488      expect(await token.getBalance({Ethereum: receiverEth})).to.eq(50n);489    }490491    {492      // Can transferCross to substrate address:493      const substrateResult = await collectionEvm.methods.transferCross(receiverCrossSub, token.tokenId).send({from: receiverEth});494      // Check events:495      const event = substrateResult.events.Transfer;496      expect(event.address).to.be.equal(collectionAddress);497      expect(event.returnValues.from).to.be.equal(receiverEth);498      expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(minter.address));499      expect(event.returnValues.tokenId).to.be.equal(`${token.tokenId}`);500      // Sender's balance decreased:501      const senderBalance = await collectionEvm.methods.balanceOf(receiverEth).call();502      expect(+senderBalance).to.equal(0);503      expect(await token.getBalance({Ethereum: receiverEth})).to.eq(0n);504      // Receiver's balance increased:505      const receiverBalance = await helper.nft.getTokensByAddress(collection.collectionId, {Substrate: minter.address});506      expect(receiverBalance).to.contain(token.tokenId);507      expect(await token.getBalance({Substrate: minter.address})).to.eq(50n);508    }509  });510511  ['transfer', 'transferCross'].map(testCase => itEth(`Cannot ${testCase} non-owned token`, async ({helper}) => {512    const sender = await helper.eth.createAccountWithBalance(donor);513    const tokenOwner = await helper.eth.createAccountWithBalance(donor);514    const receiverSub = minter;515    const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(minter);516517    const collection = await helper.rft.mintCollection(minter, {});518    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);519    const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'rft', sender);520521    await collection.mintToken(minter, 50n, {Ethereum: sender});522    const nonSendersToken = await collection.mintToken(minter, 50n, {Ethereum: tokenOwner});523524    // Cannot transferCross someone else's token:525    const receiver = testCase === 'transfer' ? helper.address.substrateToEth(receiverSub.address) : receiverCrossSub;526    await expect(collectionEvm.methods[testCase](receiver, nonSendersToken.tokenId).send({from: sender})).to.be.rejected;527    // Cannot transfer token if it does not exist:528    await expect(collectionEvm.methods[testCase](receiver, 999999).send({from: sender})).to.be.rejected;529  }));530531  itEth('transfer event on transfer from partial ownership to full ownership', async ({helper}) => {532    const caller = await helper.eth.createAccountWithBalance(donor);533    const receiver = helper.eth.createAccount();534    const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'Transferry-Partial-to-Full', '6', '6');535    const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);536537    const result = await contract.methods.mint(caller).send();538    const tokenId = result.events.Transfer.returnValues.tokenId;539540    const tokenContract = await helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);541542    await tokenContract.methods.repartition(2).send();543    await tokenContract.methods.transfer(receiver, 1).send();544545    const events: any = [];546    contract.events.allEvents((_: any, event: any) => {547      events.push(event);548    });549550    await tokenContract.methods.transfer(receiver, 1).send();551    if (events.length == 0) await helper.wait.newBlocks(1);552    const event = events[0];553554    expect(event.address).to.equal(collectionAddress);555    expect(event.returnValues.from).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');556    expect(event.returnValues.to).to.equal(receiver);557    expect(event.returnValues.tokenId).to.equal(tokenId.toString());558  });559560  itEth('transfer event on transfer from full ownership to partial ownership', async ({helper}) => {561    const caller = await helper.eth.createAccountWithBalance(donor);562    const receiver = helper.eth.createAccount();563    const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'Transferry-Full-to-Partial', '6', '6');564    const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);565566    const result = await contract.methods.mint(caller).send();567    const tokenId = result.events.Transfer.returnValues.tokenId;568569    const tokenContract = await helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);570571    await tokenContract.methods.repartition(2).send();572573    const events: any = [];574    contract.events.allEvents((_: any, event: any) => {575      events.push(event);576    });577578    await tokenContract.methods.transfer(receiver, 1).send();579    if (events.length == 0) await helper.wait.newBlocks(1);580    const event = events[0];581582    expect(event.address).to.equal(collectionAddress);583    expect(event.returnValues.from).to.equal(caller);584    expect(event.returnValues.to).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');585    expect(event.returnValues.tokenId).to.equal(tokenId.toString());586  });587588  itEth('Check balanceOfCross()', async ({helper}) => {589    const collection = await helper.rft.mintCollection(minter, {});590    const owner = await helper.ethCrossAccount.createAccountWithBalance(donor);591    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);592    const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner.eth);593594    expect(BigInt(await collectionEvm.methods.balanceOfCross(owner).call({from: owner.eth})) === 0n).to.be.true;595596    for (let i = 1n; i < 10n; i++) {597      await collection.mintToken(minter, 100n, {Ethereum: owner.eth});598      expect(BigInt(await collectionEvm.methods.balanceOfCross(owner).call({from: owner.eth})) === i).to.be.true;599    }600  });601602  itEth('Check ownerOfCross()', async ({helper}) => {603    const collection = await helper.rft.mintCollection(minter, {});604    let owner = await helper.ethCrossAccount.createAccountWithBalance(donor);605    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);606    const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner.eth);607    const {tokenId} = await collection.mintToken(minter, 100n,{Ethereum: owner.eth});608609    for (let i = 1n; i < 100n; i++) {610      const ownerCross = await collectionEvm.methods.ownerOfCross(tokenId).call({from: owner.eth});611      expect(ownerCross.eth).to.be.eq(owner.eth);612      expect(ownerCross.sub).to.be.eq(owner.sub);613614      const newOwner = await helper.ethCrossAccount.createAccountWithBalance(donor);615      await collectionEvm.methods.transferCross(newOwner, tokenId).send({from: owner.eth});616      owner = newOwner;617    }618619    const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);620    const tokenContract = await helper.ethNativeContract.rftToken(tokenAddress, owner.eth, true);621    const newOwner = await helper.ethCrossAccount.createAccountWithBalance(donor);622    await tokenContract.methods.transferCross(newOwner, 50).send({from: owner.eth});623    const ownerCross = await collectionEvm.methods.ownerOfCross(tokenId).call({from: owner.eth});624    expect(ownerCross.eth.toUpperCase()).to.be.eq('0XFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF');625    expect(ownerCross.sub).to.be.eq('0');626  });627});628629describe('RFT: Fees', () => {630  let donor: IKeyringPair;631632  before(async function() {633    await usingEthPlaygrounds(async (helper, privateKey) => {634      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);635636      donor = await privateKey({url: import.meta.url});637    });638  });639640  itEth('transferFrom() call fee is less than 0.2UNQ', async ({helper}) => {641    const caller = await helper.eth.createAccountWithBalance(donor);642    const receiver = helper.eth.createAccount();643    const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'Feeful-Transfer-From', '6', '6');644    const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);645646    const result = await contract.methods.mint(caller).send();647    const tokenId = result.events.Transfer.returnValues.tokenId;648649    const cost = await helper.eth.recordCallFee(caller, () => contract.methods.transferFrom(caller, receiver, tokenId).send());650    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));651    expect(cost > 0n);652  });653654  itEth('transfer() call fee is less than 0.2UNQ', async ({helper}) => {655    const caller = await helper.eth.createAccountWithBalance(donor);656    const receiver = helper.eth.createAccount();657    const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'Feeful-Transfer', '6', '6');658    const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);659660    const result = await contract.methods.mint(caller).send();661    const tokenId = result.events.Transfer.returnValues.tokenId;662663    const cost = await helper.eth.recordCallFee(caller, () => contract.methods.transfer(receiver, tokenId).send());664    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));665    expect(cost > 0n);666  });667});668669describe('Common metadata', () => {670  let donor: IKeyringPair;671  let alice: IKeyringPair;672673  before(async function() {674    await usingEthPlaygrounds(async (helper, privateKey) => {675      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);676677      donor = await privateKey({url: import.meta.url});678      [alice] = await helper.arrange.createAccounts([20n], donor);679    });680  });681682  itEth('Returns collection name', async ({helper}) => {683    const caller = helper.eth.createAccount();684    const tokenPropertyPermissions = [{685      key: 'URI',686      permission: {687        mutable: true,688        collectionAdmin: true,689        tokenOwner: false,690      },691    }];692    const collection = await helper.rft.mintCollection(693      alice,694      {695        name: 'Leviathan',696        tokenPrefix: '11',697        properties: [{key: 'ERC721Metadata', value: '1'}],698        tokenPropertyPermissions,699      },700    );701702    const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'rft', caller);703    const name = await contract.methods.name().call();704    expect(name).to.equal('Leviathan');705  });706707  itEth('Returns symbol name', async ({helper}) => {708    const caller = await helper.eth.createAccountWithBalance(donor);709    const tokenPropertyPermissions = [{710      key: 'URI',711      permission: {712        mutable: true,713        collectionAdmin: true,714        tokenOwner: false,715      },716    }];717    const {collectionId} = await helper.rft.mintCollection(718      alice,719      {720        name: 'Leviathan',721        tokenPrefix: '12',722        properties: [{key: 'ERC721Metadata', value: '1'}],723        tokenPropertyPermissions,724      },725    );726727    const contract = await helper.ethNativeContract.collectionById(collectionId, 'rft', caller);728    const symbol = await contract.methods.symbol().call();729    expect(symbol).to.equal('12');730  });731});732733describe('Negative tests', () => {734  let donor: IKeyringPair;735  let minter: IKeyringPair;736  let alice: IKeyringPair;737738  before(async function() {739    await usingEthPlaygrounds(async (helper, privateKey) => {740      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);741742      donor = await privateKey({url: import.meta.url});743      [minter, alice] = await helper.arrange.createAccounts([100n, 100n], donor);744    });745  });746747  itEth('[negative] Cant perform burn without approval', async ({helper}) => {748    const collection = await helper.rft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});749750    const owner = await helper.eth.createAccountWithBalance(donor, 100n);751    const spender = await helper.eth.createAccountWithBalance(donor, 100n);752753    const token = await collection.mintToken(minter, 100n, {Ethereum: owner});754755    const address = helper.ethAddress.fromCollectionId(collection.collectionId);756    const contract = await helper.ethNativeContract.collection(address, 'rft');757758    const ownerCross = helper.ethCrossAccount.fromAddress(owner);759760    await expect(contract.methods.burnFromCross(ownerCross, token.tokenId).send({from: spender})).to.be.rejected;761762    await contract.methods.setApprovalForAll(spender, true).send({from: owner});763    await contract.methods.setApprovalForAll(spender, false).send({from: owner});764765    await expect(contract.methods.burnFromCross(ownerCross, token.tokenId).send({from: spender})).to.be.rejected;766  });767768  itEth('[negative] Cant perform transfer without approval', async ({helper}) => {769    const collection = await helper.rft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});770    const owner = await helper.eth.createAccountWithBalance(donor, 100n);771    const receiver = alice;772773    const spender = await helper.eth.createAccountWithBalance(donor, 100n);774775    const token = await collection.mintToken(minter, 100n, {Ethereum: owner});776777    const address = helper.ethAddress.fromCollectionId(collection.collectionId);778    const contract = await helper.ethNativeContract.collection(address, 'rft');779780    const ownerCross = helper.ethCrossAccount.fromAddress(owner);781    const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);782783    await expect(contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender})).to.be.rejected;784785    await contract.methods.setApprovalForAll(spender, true).send({from: owner});786    await contract.methods.setApprovalForAll(spender, false).send({from: owner});787788    await expect(contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender})).to.be.rejected;789  });790});
modifiedtests/src/eth/reFungibleToken.test.tsdiffbeforeafterboth
--- a/tests/src/eth/reFungibleToken.test.ts
+++ b/tests/src/eth/reFungibleToken.test.ts
@@ -470,16 +470,30 @@
   itEth('Check balanceOfCross()', async ({helper}) => {
     const collection = await helper.rft.mintCollection(alice, {});
     const owner = await helper.ethCrossAccount.createAccountWithBalance(donor);
+    const other = await helper.ethCrossAccount.createAccountWithBalance(donor);
     const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: owner.eth});
     const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);
     const tokenContract = await helper.ethNativeContract.rftToken(tokenAddress, owner.eth);
 
     expect(BigInt(await tokenContract.methods.balanceOfCross(owner).call({from: owner.eth})) === 200n).to.be.true;
+    expect(BigInt(await tokenContract.methods.balanceOfCross(other).call({from: owner.eth})) === 0n).to.be.true;
+
+    await tokenContract.methods.repartition(100n).send({from: owner.eth});
+    expect(BigInt(await tokenContract.methods.balanceOfCross(owner).call({from: owner.eth})) === 100n).to.be.true;
+    expect(BigInt(await tokenContract.methods.balanceOfCross(other).call({from: owner.eth})) === 0n).to.be.true;
+
+    await tokenContract.methods.transferCross(other, 50n).send({from: owner.eth});
+    expect(BigInt(await tokenContract.methods.balanceOfCross(owner).call({from: owner.eth})) === 50n).to.be.true;
+    expect(BigInt(await tokenContract.methods.balanceOfCross(other).call({from: owner.eth})) === 50n).to.be.true;
+
+    await tokenContract.methods.transferCross(other, 50n).send({from: owner.eth});
+    expect(BigInt(await tokenContract.methods.balanceOfCross(owner).call({from: owner.eth})) === 0n).to.be.true;
+    expect(BigInt(await tokenContract.methods.balanceOfCross(other).call({from: owner.eth})) === 100n).to.be.true;
 
-    for (let i = 1n; i < 100n; i++) {
-      await tokenContract.methods.repartition(i).send({from: owner.eth});
-      expect(BigInt(await tokenContract.methods.balanceOfCross(owner).call({from: owner.eth})) === i).to.be.true;
-    }
+    await tokenContract.methods.repartition(1000n).send({from: other.eth});
+    await tokenContract.methods.transferCross(owner, 500n).send({from: other.eth});
+    expect(BigInt(await tokenContract.methods.balanceOfCross(owner).call({from: owner.eth})) === 500n).to.be.true;
+    expect(BigInt(await tokenContract.methods.balanceOfCross(other).call({from: owner.eth})) === 500n).to.be.true;
   });
 });