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

difftreelog

Merge pull request #747 from UniqueNetwork/tests/refungible

ut-akuznetsov2022-12-07parents: #c07446f #38774eb.patch.diff
in: master
Transfer tests

14 files changed

modifiedpallets/fungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/fungible/src/lib.rs
+++ b/pallets/fungible/src/lib.rs
@@ -379,7 +379,7 @@
 		let balance_from = <Balance<T>>::get((collection.id, from))
 			.checked_sub(amount)
 			.ok_or(<CommonError<T>>::TokenValueTooLow)?;
-		let balance_to = if from != to {
+		let balance_to = if from != to && amount != 0 {
 			Some(
 				<Balance<T>>::get((collection.id, to))
 					.checked_add(amount)
@@ -391,16 +391,17 @@
 
 		// =========
 
-		<PalletStructure<T>>::nest_if_sent_to_token(
-			from.clone(),
-			to,
-			collection.id,
-			TokenId::default(),
-			nesting_budget,
-		)?;
-
 		if let Some(balance_to) = balance_to {
-			// from != to
+			// from != to && amount != 0
+
+			<PalletStructure<T>>::nest_if_sent_to_token(
+				from.clone(),
+				to,
+				collection.id,
+				TokenId::default(),
+				nesting_budget,
+			)?;
+
 			if balance_from == 0 {
 				<Balance<T>>::remove((collection.id, from));
 				<PalletStructure<T>>::unnest_if_nested(from, collection.id, TokenId::default());
modifiedpallets/nonfungible/src/common.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/common.rs
+++ b/pallets/nonfungible/src/common.rs
@@ -291,6 +291,7 @@
 				<CommonWeights<T>>::burn_item(),
 			)
 		} else {
+			<Pallet<T>>::check_token_immediate_ownership(self, token, &sender)?;
 			Ok(().into())
 		}
 	}
@@ -320,6 +321,7 @@
 				<CommonWeights<T>>::transfer(),
 			)
 		} else {
+			<Pallet<T>>::check_token_immediate_ownership(self, token, &from)?;
 			Ok(().into())
 		}
 	}
@@ -360,6 +362,8 @@
 				<CommonWeights<T>>::transfer_from(),
 			)
 		} else {
+			<Pallet<T>>::check_allowed(self, &sender, &from, token, nesting_budget)?;
+
 			Ok(().into())
 		}
 	}
@@ -380,6 +384,8 @@
 				<CommonWeights<T>>::burn_from(),
 			)
 		} else {
+			<Pallet<T>>::check_allowed(self, &sender, &from, token, nesting_budget)?;
+
 			Ok(().into())
 		}
 	}
modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -814,6 +814,20 @@
 		<PalletCommon<T>>::set_property_permission(collection, sender, permission)
 	}
 
+	pub fn check_token_immediate_ownership(
+		collection: &NonfungibleHandle<T>,
+		token: TokenId,
+		possible_owner: &T::CrossAccountId,
+	) -> DispatchResult {
+		let token_data =
+			<TokenData<T>>::get((collection.id, token)).ok_or(<CommonError<T>>::TokenNotFound)?;
+		ensure!(
+			&token_data.owner == possible_owner,
+			<CommonError<T>>::NoPermission
+		);
+		Ok(())
+	}
+
 	/// Transfer NFT token from one account to another.
 	///
 	/// `from` account stops being the owner and `to` account becomes the owner of the token.
modifiedpallets/refungible/src/erc.rsdiffbeforeafterboth
--- a/pallets/refungible/src/erc.rs
+++ b/pallets/refungible/src/erc.rs
@@ -34,6 +34,7 @@
 	CollectionHandle, CollectionPropertyPermissions, CommonCollectionOperations,
 	erc::{CommonEvmHandler, CollectionCall, static_property::key},
 	eth::EthCrossAccount,
+	Error as CommonError,
 };
 use pallet_evm::{account::CrossAccountId, PrecompileHandle};
 use pallet_evm_coder_substrate::{call, dispatch_to_evm};
@@ -508,6 +509,13 @@
 ) -> Result<()> {
 	collection.consume_store_reads(1)?;
 	let total_supply = <TotalSupply<T>>::get((collection.id, token));
+
+	if owner_balance == 0 {
+		return Err(dispatch_to_evm::<T>(
+			<CommonError<T>>::MustBeTokenOwner.into(),
+		));
+	}
+
 	if total_supply != owner_balance {
 		return Err("token has multiple owners".into());
 	}
modifiedpallets/refungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -452,6 +452,10 @@
 		token: TokenId,
 		amount: u128,
 	) -> DispatchResult {
+		if <Balance<T>>::get((collection.id, token, owner)) == 0 {
+			return Err(<CommonError<T>>::TokenValueTooLow.into());
+		}
+
 		let total_supply = <TotalSupply<T>>::get((collection.id, token))
 			.checked_sub(amount)
 			.ok_or(<CommonError<T>>::TokenValueTooLow)?;
@@ -739,12 +743,17 @@
 		<PalletCommon<T>>::ensure_correct_receiver(to)?;
 
 		let initial_balance_from = <Balance<T>>::get((collection.id, token, from));
+
+		if initial_balance_from == 0 {
+			return Err(<CommonError<T>>::TokenValueTooLow.into());
+		}
+
 		let updated_balance_from = initial_balance_from
 			.checked_sub(amount)
 			.ok_or(<CommonError<T>>::TokenValueTooLow)?;
 		let mut create_target = false;
 		let from_to_differ = from != to;
-		let updated_balance_to = if from != to {
+		let updated_balance_to = if from != to && amount != 0 {
 			let old_balance = <Balance<T>>::get((collection.id, token, to));
 			if old_balance == 0 {
 				create_target = true;
@@ -786,16 +795,17 @@
 
 		// =========
 
-		<PalletStructure<T>>::nest_if_sent_to_token(
-			from.clone(),
-			to,
-			collection.id,
-			token,
-			nesting_budget,
-		)?;
+		if let Some(updated_balance_to) = updated_balance_to {
+			// from != to && amount != 0
+
+			<PalletStructure<T>>::nest_if_sent_to_token(
+				from.clone(),
+				to,
+				collection.id,
+				token,
+				nesting_budget,
+			)?;
 
-		if let Some(updated_balance_to) = updated_balance_to {
-			// from != to
 			if updated_balance_from == 0 {
 				<Balance<T>>::remove((collection.id, token, from));
 				<PalletStructure<T>>::unnest_if_nested(from, collection.id, token);
modifiedtests/src/burnItem.test.tsdiffbeforeafterboth
--- a/tests/src/burnItem.test.ts
+++ b/tests/src/burnItem.test.ts
@@ -140,6 +140,31 @@
     await expect(token.burn(bob)).to.be.rejectedWith('common.NoPermission');
   });
 
+  itSub.ifWithPallets('RFT: cannot burn non-owned token pieces', [Pallets.ReFungible], async ({helper}) => {
+    const collection = await helper.rft.mintCollection(alice);
+    const aliceToken = await collection.mintToken(alice, 10n, {Substrate: alice.address});
+    const bobToken = await collection.mintToken(alice, 10n, {Substrate: bob.address});
+
+    // 1. Cannot burn non-owned token:
+    await expect(bobToken.burn(alice, 0n)).to.be.rejectedWith('common.TokenValueTooLow');
+    await expect(bobToken.burn(alice, 5n)).to.be.rejectedWith('common.TokenValueTooLow');
+    // 2. Cannot burn non-existing token:
+    await expect(helper.rft.burnToken(alice, 99999, 10)).to.be.rejectedWith('common.CollectionNotFound');
+    await expect(helper.rft.burnToken(alice, collection.collectionId, 99999)).to.be.rejectedWith('common.TokenValueTooLow');
+    // 3. Can burn zero amount of owned tokens (EIP-20)
+    await aliceToken.burn(alice, 0n);
+
+    // 4. Storage is not corrupted:
+    expect(await aliceToken.getTop10Owners()).to.deep.eq([{Substrate: alice.address}]);
+    expect(await bobToken.getTop10Owners()).to.deep.eq([{Substrate: bob.address}]);
+
+    // 4.1 Tokens can be transfered:
+    await aliceToken.transfer(alice, {Substrate: bob.address}, 10n);
+    await bobToken.transfer(bob, {Substrate: alice.address}, 10n);
+    expect(await aliceToken.getTop10Owners()).to.deep.eq([{Substrate: bob.address}]);
+    expect(await bobToken.getTop10Owners()).to.deep.eq([{Substrate: alice.address}]);
+  });
+
   itSub('Transfer a burned token', async ({helper}) => {
     const collection = await helper.nft.mintCollection(alice);
     const token = await collection.mintToken(alice);
@@ -155,4 +180,48 @@
     await expect(collection.burnTokens(alice, 11n)).to.be.rejectedWith('common.TokenValueTooLow');
     expect(await collection.getBalance({Substrate: alice.address})).to.eq(10n);
   });
+
+  itSub('Zero burn NFT', async ({helper}) => {
+    const collection = await helper.nft.mintCollection(alice, {name: 'Coll', description: 'Desc', tokenPrefix: 'T'});
+    const tokenAlice = await collection.mintToken(alice, {Substrate: alice.address});
+    const tokenBob = await collection.mintToken(alice, {Substrate: bob.address});
+    
+    // 1. Zero burn of own tokens allowed:
+    await helper.executeExtrinsic(alice, 'api.tx.unique.burnItem', [collection.collectionId, tokenAlice.tokenId, 0]);
+    // 2. Zero burn of non-owned tokens not allowed:
+    await expect(helper.executeExtrinsic(alice, 'api.tx.unique.burnItem', [collection.collectionId, tokenBob.tokenId, 0])).to.be.rejectedWith('common.NoPermission');
+    // 3. Zero burn of non-existing tokens not allowed:
+    await expect(helper.executeExtrinsic(alice, 'api.tx.unique.burnItem', [collection.collectionId, 9999, 0])).to.be.rejectedWith('common.TokenNotFound');
+    expect(await tokenAlice.doesExist()).to.be.true;
+    expect(await tokenAlice.getOwner()).to.deep.eq({Substrate: alice.address});
+    expect(await tokenBob.getOwner()).to.deep.eq({Substrate: bob.address});
+    // 4. Storage is not corrupted:
+    await tokenAlice.transfer(alice, {Substrate: bob.address});
+    await tokenBob.transfer(bob, {Substrate: alice.address});
+    expect(await tokenAlice.getOwner()).to.deep.eq({Substrate: bob.address});
+    expect(await tokenBob.getOwner()).to.deep.eq({Substrate: alice.address});
+  });
+
+  itSub('zero burnFrom NFT', async ({helper}) => {
+    const collection = await helper.nft.mintCollection(alice, {name: 'Zero', description: 'Zero transfer', tokenPrefix: 'TF'});
+    const notApprovedNft = await collection.mintToken(alice, {Substrate: bob.address});
+    const approvedNft = await collection.mintToken(alice, {Substrate: bob.address});
+    await approvedNft.approve(bob, {Substrate: alice.address});
+
+    // 1. Zero burnFrom of non-existing tokens not allowed:
+    await expect(helper.executeExtrinsic(alice, 'api.tx.unique.burnFrom', [collection.collectionId, {Substrate: bob.address}, 9999, 0])).to.be.rejectedWith('common.ApprovedValueTooLow');
+    // 2. Zero burnFrom of not approved tokens not allowed:
+    await expect(helper.executeExtrinsic(alice, 'api.tx.unique.burnFrom', [collection.collectionId, {Substrate: bob.address}, notApprovedNft.tokenId, 0])).to.be.rejectedWith('common.ApprovedValueTooLow');
+    // 3. Zero burnFrom of approved tokens allowed:
+    await helper.executeExtrinsic(alice, 'api.tx.unique.burnFrom', [collection.collectionId, {Substrate: bob.address}, approvedNft.tokenId, 0]);
+
+    // 4.1 approvedNft still approved:
+    expect(await approvedNft.isApproved({Substrate: alice.address})).to.be.true;
+    // 4.2 bob is still the owner:
+    expect(await approvedNft.getOwner()).to.deep.eq({Substrate: bob.address});
+    expect(await notApprovedNft.getOwner()).to.deep.eq({Substrate: bob.address});
+    // 4.3 Alice can burn approved nft:
+    await approvedNft.burnFrom(alice, {Substrate: bob.address});
+    expect(await approvedNft.doesExist()).to.be.false;
+  });
 });
modifiedtests/src/eth/fungible.test.tsdiffbeforeafterboth
--- a/tests/src/eth/fungible.test.ts
+++ b/tests/src/eth/fungible.test.ts
@@ -277,7 +277,7 @@
     }
   });
 
-  itEth('Cannot transferCross() more than have', async ({helper}) => {
+  ['transfer', 'transferCross'].map(testCase => itEth(`Cannot ${testCase} incorrect amount`, async ({helper}) => {
     const sender = await helper.eth.createAccountWithBalance(donor);
     const receiverEth = await helper.eth.createAccountWithBalance(donor);
     const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);
@@ -289,8 +289,13 @@
     const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
     const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'ft', sender);
 
-    await expect(collectionEvm.methods.transferCross(receiverCrossEth, BALANCE_TO_TRANSFER).send({from: sender})).to.be.rejected;
-  });
+    // 1. Cannot transfer more than have
+    const receiver = testCase === 'transfer' ? receiverEth : receiverCrossEth;
+    await expect(collectionEvm.methods[testCase](receiver, BALANCE_TO_TRANSFER).send({from: sender})).to.be.rejected;
+    // 2. Zero transfer allowed (EIP-20):
+    await collectionEvm.methods[testCase](receiver, 0n).send({from: sender});
+  }));
+  
   
   itEth('Can perform transfer()', async ({helper}) => {
     const owner = await helper.eth.createAccountWithBalance(donor);
modifiedtests/src/eth/nonFungible.test.tsdiffbeforeafterboth
before · tests/src/eth/nonFungible.test.ts
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {itEth, usingEthPlaygrounds, expect, EthUniqueHelper} from './util';18import {IKeyringPair} from '@polkadot/types/types';19import {Contract} from 'web3-eth-contract';202122describe('NFT: Information getting', () => {23  let donor: IKeyringPair;24  let alice: IKeyringPair;2526  before(async function() {27    await usingEthPlaygrounds(async (helper, privateKey) => {28      donor = await privateKey({filename: __filename});29      [alice] = await helper.arrange.createAccounts([10n], donor);30    });31  });3233  itEth('totalSupply', async ({helper}) => {34    const collection = await helper.nft.mintCollection(alice, {});35    await collection.mintToken(alice);3637    const caller = await helper.eth.createAccountWithBalance(donor);3839    const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);40    const totalSupply = await contract.methods.totalSupply().call();4142    expect(totalSupply).to.equal('1');43  });4445  itEth('balanceOf', async ({helper}) => {46    const collection = await helper.nft.mintCollection(alice, {});47    const caller = await helper.eth.createAccountWithBalance(donor);4849    await collection.mintToken(alice, {Ethereum: caller});50    await collection.mintToken(alice, {Ethereum: caller});51    await collection.mintToken(alice, {Ethereum: caller});5253    const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);54    const balance = await contract.methods.balanceOf(caller).call();5556    expect(balance).to.equal('3');57  });5859  itEth('ownerOf', async ({helper}) => {60    const collection = await helper.nft.mintCollection(alice, {});61    const caller = await helper.eth.createAccountWithBalance(donor);6263    const token = await collection.mintToken(alice, {Ethereum: caller});6465    const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);6667    const owner = await contract.methods.ownerOf(token.tokenId).call();6869    expect(owner).to.equal(caller);70  });7172  itEth('name/symbol is available regardless of ERC721Metadata support', async ({helper}) => {73    const collection = await helper.nft.mintCollection(alice, {name: 'test', tokenPrefix: 'TEST'});74    const caller = helper.eth.createAccount();7576    const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);7778    expect(await contract.methods.name().call()).to.equal('test');79    expect(await contract.methods.symbol().call()).to.equal('TEST');80  });81});8283describe('Check ERC721 token URI for NFT', () => {84  let donor: IKeyringPair;8586  before(async function() {87    await usingEthPlaygrounds(async (_helper, privateKey) => {88      donor = await privateKey({filename: __filename});89    });90  });9192  async function setup(helper: EthUniqueHelper, baseUri: string, propertyKey?: string, propertyValue?: string): Promise<{contract: Contract, nextTokenId: string}> {93    const owner = await helper.eth.createAccountWithBalance(donor);94    const receiver = helper.eth.createAccount();9596    const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'Mint collection', 'a', 'b', baseUri);97    const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);9899    const result = await contract.methods.mint(receiver).send();100    const tokenId = result.events.Transfer.returnValues.tokenId;101    expect(tokenId).to.be.equal('1');102103    if (propertyKey && propertyValue) {104      // Set URL or suffix105      await contract.methods.setProperties(tokenId, [{key: propertyKey, value: Buffer.from(propertyValue)}]).send();106    }107108    const event = result.events.Transfer;109    expect(event.address).to.be.equal(collectionAddress);110    expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');111    expect(event.returnValues.to).to.be.equal(receiver);112    expect(event.returnValues.tokenId).to.be.equal(tokenId);113114    return {contract, nextTokenId: tokenId};115  }116117  itEth('Empty tokenURI', async ({helper}) => {118    const {contract, nextTokenId} = await setup(helper, '');119    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('');120  });121122  itEth('TokenURI from url', async ({helper}) => {123    const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'URI', 'Token URI');124    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Token URI');125  });126127  itEth('TokenURI from baseURI', async ({helper}) => {128    const {contract, nextTokenId} = await setup(helper, 'BaseURI_');129    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_');130  });131132  itEth('TokenURI from baseURI + suffix', async ({helper}) => {133    const suffix = '/some/suffix';134    const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'URISuffix', suffix);135    expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_' + suffix);136  });137});138139describe('NFT: Plain calls', () => {140  let donor: IKeyringPair;141  let minter: IKeyringPair;142  let bob: IKeyringPair;143  let charlie: IKeyringPair;144145  before(async function() {146    await usingEthPlaygrounds(async (helper, privateKey) => {147      donor = await privateKey({filename: __filename});148      [minter, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);149    });150  });151152  itEth('Can perform mint() & get crossOwner()', async ({helper}) => {153    const owner = await helper.eth.createAccountWithBalance(donor);154    const receiver = helper.eth.createAccount();155156    const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'Mint collection', '6', '6', '');157    const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);158159    const result = await contract.methods.mintWithTokenURI(receiver, 'Test URI').send();160    const tokenId = result.events.Transfer.returnValues.tokenId;161    expect(tokenId).to.be.equal('1');162163    const event = result.events.Transfer;164    expect(event.address).to.be.equal(collectionAddress);165    expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');166    expect(event.returnValues.to).to.be.equal(receiver);167168    expect(await contract.methods.tokenURI(tokenId).call()).to.be.equal('Test URI');169    console.log(await contract.methods.crossOwnerOf(tokenId).call());170    expect(await contract.methods.crossOwnerOf(tokenId).call()).to.be.like([receiver, '0']);171    // TODO: this wont work right now, need release 919000 first172    // await helper.methods.setOffchainSchema(collectionIdAddress, 'https://offchain-service.local/token-info/{id}').send();173    // const tokenUri = await contract.methods.tokenURI(nextTokenId).call();174    // expect(tokenUri).to.be.equal(`https://offchain-service.local/token-info/${nextTokenId}`);175  });176177  //TODO: CORE-302 add eth methods178  itEth.skip('Can perform mintBulk()', async ({helper}) => {179    const caller = await helper.eth.createAccountWithBalance(donor);180    const receiver = helper.eth.createAccount();181182    const collection = await helper.nft.mintCollection(minter);183    await collection.addAdmin(minter, {Ethereum: caller});184185    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);186    const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', caller);187    {188      const bulkSize = 3;189      const nextTokenId = await contract.methods.nextTokenId().call();190      expect(nextTokenId).to.be.equal('1');191      const result = await contract.methods.mintBulkWithTokenURI(192        receiver,193        Array.from({length: bulkSize}, (_, i) => (194          [+nextTokenId + i, `Test URI ${i}`]195        )),196      ).send({from: caller});197198      const events = result.events.Transfer.sort((a: any, b: any) => +a.returnValues.tokenId - b.returnValues.tokenId);199      for (let i = 0; i < bulkSize; i++) {200        const event = events[i];201        expect(event.address).to.equal(collectionAddress);202        expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');203        expect(event.returnValues.to).to.equal(receiver);204        expect(event.returnValues.tokenId).to.equal(`${+nextTokenId + i}`);205206        expect(await contract.methods.tokenURI(+nextTokenId + i).call()).to.be.equal(`Test URI ${i}`);207      }208    }209  });210211  itEth('Can perform burn()', async ({helper}) => {212    const caller = await helper.eth.createAccountWithBalance(donor);213214    const collection = await helper.nft.mintCollection(minter, {});215    const {tokenId} = await collection.mintToken(minter, {Ethereum: caller});216217    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);218    const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', caller);219220    {221      const result = await contract.methods.burn(tokenId).send({from: caller});222223      const event = result.events.Transfer;224      expect(event.address).to.be.equal(collectionAddress);225      expect(event.returnValues.from).to.be.equal(caller);226      expect(event.returnValues.to).to.be.equal('0x0000000000000000000000000000000000000000');227      expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);228    }229  });230231  itEth('Can perform approve()', async ({helper}) => {232    const owner = await helper.eth.createAccountWithBalance(donor);233    const spender = helper.eth.createAccount();234235    const collection = await helper.nft.mintCollection(minter, {});236    const {tokenId} = await collection.mintToken(minter, {Ethereum: owner});237238    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);239    const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);240241    {242      const result = await contract.methods.approve(spender, tokenId).send({from: owner});243244      const event = result.events.Approval;245      expect(event.address).to.be.equal(collectionAddress);246      expect(event.returnValues.owner).to.be.equal(owner);247      expect(event.returnValues.approved).to.be.equal(spender);248      expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);249    }250  });251252  itEth('Can perform burnFromCross()', async ({helper}) => {253    const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});254    const ownerSub = bob;255    const ownerCrossSub = helper.ethCrossAccount.fromKeyringPair(ownerSub);256    const ownerEth = await helper.eth.createAccountWithBalance(donor, 100n);257    const ownerCrossEth = helper.ethCrossAccount.fromAddress(ownerEth);258259    const burnerEth = await helper.eth.createAccountWithBalance(donor, 100n);260    const burnerCrossEth = helper.ethCrossAccount.fromAddress(burnerEth);261262    const token1 = await collection.mintToken(minter, {Substrate: ownerSub.address});263    const token2 = await collection.mintToken(minter, {Ethereum: ownerEth});264265    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);266    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft');267268    // Approve tokens from substrate and ethereum:269    await token1.approve(ownerSub, {Ethereum: burnerEth});270    await collectionEvm.methods.approveCross(burnerCrossEth, token2.tokenId).send({from: ownerEth});271272    // can burnFromCross:273    const result1 = await collectionEvm.methods.burnFromCross(ownerCrossSub, token1.tokenId).send({from: burnerEth});274    const result2 = await collectionEvm.methods.burnFromCross(ownerCrossEth, token2.tokenId).send({from: burnerEth});275    const events1 = result1.events.Transfer;276    const events2 = result2.events.Transfer;277278    // Check events for burnFromCross (substrate and ethereum):279    [280      [events1, token1, helper.address.substrateToEth(ownerSub.address)], 281      [events2, token2, ownerEth],282    ].map(burnData => {283      expect(burnData[0]).to.be.like({284        address: collectionAddress,285        event: 'Transfer',286        returnValues: {287          from: burnData[2],288          to: '0x0000000000000000000000000000000000000000',289          tokenId: burnData[1].tokenId.toString(),290        },291      });292    });293294    expect(await token1.doesExist()).to.be.false;295    expect(await token2.doesExist()).to.be.false;296  });297298  itEth('Can perform approveCross()', async ({helper}) => {299    // arrange: create accounts300    const owner = await helper.eth.createAccountWithBalance(donor, 100n);301    const ownerCross = helper.ethCrossAccount.fromAddress(owner);302    const receiverSub = charlie;303    const recieverCrossSub = helper.ethCrossAccount.fromKeyringPair(receiverSub);304    const receiverEth = await helper.eth.createAccountWithBalance(donor, 100n);305    const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);306307    // arrange: create collection and tokens:308    const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});309    const token1 = await collection.mintToken(minter, {Ethereum: owner});310    const token2 = await collection.mintToken(minter, {Ethereum: owner});311312    const collectionEvm = helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(collection.collectionId), 'nft');313314    // Can approveCross substrate and ethereum address:315    const resultSub = await collectionEvm.methods.approveCross(recieverCrossSub, token1.tokenId).send({from: owner});316    const resultEth = await collectionEvm.methods.approveCross(receiverCrossEth, token2.tokenId).send({from: owner});317    const eventSub = resultSub.events.Approval;318    const eventEth = resultEth.events.Approval;319    expect(eventSub).to.be.like({320      address: helper.ethAddress.fromCollectionId(collection.collectionId),321      event: 'Approval',322      returnValues: {323        owner,324        approved: helper.address.substrateToEth(receiverSub.address),325        tokenId: token1.tokenId.toString(),326      },327    });328    expect(eventEth).to.be.like({329      address: helper.ethAddress.fromCollectionId(collection.collectionId),330      event: 'Approval',331      returnValues: {332        owner,333        approved: receiverEth,334        tokenId: token2.tokenId.toString(),335      },336    });337338    // Substrate address can transferFrom approved tokens:339    await helper.nft.transferTokenFrom(receiverSub, collection.collectionId, token1.tokenId, {Ethereum: owner}, {Substrate: receiverSub.address});340    expect(await helper.nft.getTokenOwner(collection.collectionId, token1.tokenId)).to.deep.eq({Substrate: receiverSub.address});341    // Ethereum address can transferFromCross approved tokens:342    await collectionEvm.methods.transferFromCross(ownerCross, receiverCrossEth, token2.tokenId).send({from: receiverEth});343    expect(await helper.nft.getTokenOwner(collection.collectionId, token2.tokenId)).to.deep.eq({Ethereum: receiverEth.toLowerCase()});344  });345346  itEth('Can reaffirm approved address', async ({helper}) => {347    const owner = await helper.eth.createAccountWithBalance(donor, 100n);348    const ownerCrossEth = helper.ethCrossAccount.fromAddress(owner);349    const [receiver1, receiver2] = await helper.arrange.createAccounts([100n, 100n], donor);350    const receiver1Cross = helper.ethCrossAccount.fromKeyringPair(receiver1);351    const receiver2Cross = helper.ethCrossAccount.fromKeyringPair(receiver2);352    const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});353    const token1 = await collection.mintToken(minter, {Ethereum: owner});354    const token2 = await collection.mintToken(minter, {Ethereum: owner});355    const collectionEvm = helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(collection.collectionId), 'nft');356357    // Can approve and reaffirm approved address:358    await collectionEvm.methods.approveCross(receiver1Cross, token1.tokenId).send({from: owner});359    await collectionEvm.methods.approveCross(receiver2Cross, token1.tokenId).send({from: owner});360361    // receiver1 cannot transferFrom:362    await expect(helper.nft.transferTokenFrom(receiver1, collection.collectionId, token1.tokenId, {Ethereum: owner}, {Substrate: receiver1.address})).to.be.rejected;363    // receiver2 can transferFrom:364    await helper.nft.transferTokenFrom(receiver2, collection.collectionId, token1.tokenId, {Ethereum: owner}, {Substrate: receiver2.address});365366    // can set approved address to self address to remove approval:367    await collectionEvm.methods.approveCross(receiver1Cross, token2.tokenId).send({from: owner});368    await collectionEvm.methods.approveCross(ownerCrossEth, token2.tokenId).send({from: owner});369370    // receiver1 cannot transfer token anymore:371    await expect(helper.nft.transferTokenFrom(receiver1, collection.collectionId, token2.tokenId, {Ethereum: owner}, {Substrate: receiver1.address})).to.be.rejected;372  });373374  itEth('Can perform transferFrom()', async ({helper}) => {375    const owner = await helper.eth.createAccountWithBalance(donor);376    const spender = await helper.eth.createAccountWithBalance(donor);377    const receiver = helper.eth.createAccount();378379    const collection = await helper.nft.mintCollection(minter, {});380    const {tokenId} = await collection.mintToken(minter, {Ethereum: owner});381382    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);383    const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);384385    await contract.methods.approve(spender, tokenId).send({from: owner});386387    {388      const result = await contract.methods.transferFrom(owner, receiver, tokenId).send({from: spender});389390      const event = result.events.Transfer;391      expect(event.address).to.be.equal(collectionAddress);392      expect(event.returnValues.from).to.be.equal(owner);393      expect(event.returnValues.to).to.be.equal(receiver);394      expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);395    }396397    {398      const balance = await contract.methods.balanceOf(receiver).call();399      expect(+balance).to.equal(1);400    }401402    {403      const balance = await contract.methods.balanceOf(owner).call();404      expect(+balance).to.equal(0);405    }406  });407408  itEth('Can perform transferFromCross()', async ({helper}) => {409    const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});410411    const [owner, receiver] = await helper.arrange.createAccounts([100n, 100n], donor);412    const spender = await helper.eth.createAccountWithBalance(donor);413414    const token = await collection.mintToken(minter, {Substrate: owner.address});415416    const address = helper.ethAddress.fromCollectionId(collection.collectionId);417    const contract = helper.ethNativeContract.collection(address, 'nft');418419    await token.approve(owner, {Ethereum: spender});420421    {422      const ownerCross = helper.ethCrossAccount.fromKeyringPair(owner);423      const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);424      const result = await contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender});425      const event = result.events.Transfer;426      expect(event).to.be.like({427        address: helper.ethAddress.fromCollectionId(collection.collectionId),428        event: 'Transfer',429        returnValues: {430          from: helper.address.substrateToEth(owner.address),431          to: helper.address.substrateToEth(receiver.address),432          tokenId: token.tokenId.toString(),433        },434      });435    }436437    expect(await token.getOwner()).to.be.like({Substrate: receiver.address});438  });439440  itEth('Can perform transfer()', async ({helper}) => {441    const collection = await helper.nft.mintCollection(minter, {});442    const owner = await helper.eth.createAccountWithBalance(donor);443    const receiver = helper.eth.createAccount();444445    const {tokenId} = await collection.mintToken(minter, {Ethereum: owner});446447    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);448    const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);449450    {451      const result = await contract.methods.transfer(receiver, tokenId).send({from: owner});452453      const event = result.events.Transfer;454      expect(event.address).to.be.equal(collectionAddress);455      expect(event.returnValues.from).to.be.equal(owner);456      expect(event.returnValues.to).to.be.equal(receiver);457      expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);458    }459460    {461      const balance = await contract.methods.balanceOf(owner).call();462      expect(+balance).to.equal(0);463    }464465    {466      const balance = await contract.methods.balanceOf(receiver).call();467      expect(+balance).to.equal(1);468    }469  });470  471  itEth('Can perform transferCross()', async ({helper}) => {472    const collection = await helper.nft.mintCollection(minter, {});473    const owner = await helper.eth.createAccountWithBalance(donor);474    const receiverEth = await helper.eth.createAccountWithBalance(donor);475    const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);476    const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(minter);477    478    const {tokenId} = await collection.mintToken(minter, {Ethereum: owner});479480    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);481    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);482483    {484      // Can transferCross to ethereum address:485      const result = await collectionEvm.methods.transferCross(receiverCrossEth, tokenId).send({from: owner});486      // Check events:487      const event = result.events.Transfer;488      expect(event.address).to.be.equal(collectionAddress);489      expect(event.returnValues.from).to.be.equal(owner);490      expect(event.returnValues.to).to.be.equal(receiverEth);491      expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);492      493      // owner has balance = 0:494      const ownerBalance = await collectionEvm.methods.balanceOf(owner).call();495      expect(+ownerBalance).to.equal(0);496      // receiver owns token:497      const receiverBalance = await collectionEvm.methods.balanceOf(receiverEth).call();498      expect(+receiverBalance).to.equal(1);499      expect(await helper.nft.getTokenOwner(collection.collectionId, tokenId)).to.deep.eq({Ethereum: receiverEth.toLowerCase()});500    }501    502    {503      // Can transferCross to substrate address:504      const substrateResult = await collectionEvm.methods.transferCross(receiverCrossSub, tokenId).send({from: receiverEth});505      // Check events:506      const event = substrateResult.events.Transfer;507      expect(event.address).to.be.equal(collectionAddress);508      expect(event.returnValues.from).to.be.equal(receiverEth);509      expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(minter.address));510      expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);511      512      // owner has balance = 0:513      const ownerBalance = await collectionEvm.methods.balanceOf(receiverEth).call();514      expect(+ownerBalance).to.equal(0);515      // receiver owns token:516      const receiverBalance = await helper.nft.getTokensByAddress(collection.collectionId, {Substrate: minter.address});517      expect(receiverBalance).to.contain(tokenId);518    }519  });520});521522describe('NFT: Fees', () => {523  let donor: IKeyringPair;524  let alice: IKeyringPair;525  let bob: IKeyringPair;526  let charlie: IKeyringPair;527528  before(async function() {529    await usingEthPlaygrounds(async (helper, privateKey) => {530      donor = await privateKey({filename: __filename});531      [alice, bob, charlie] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);532    });533  });534535  itEth('approve() call fee is less than 0.2UNQ', async ({helper}) => {536    const owner = await helper.eth.createAccountWithBalance(donor);537    const spender = helper.eth.createAccount();538539    const collection = await helper.nft.mintCollection(alice, {});540    const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});541542    const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', owner);543544    const cost = await helper.eth.recordCallFee(owner, () => contract.methods.approve(spender, tokenId).send({from: owner}));545    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));546  });547548  itEth('transferFrom() call fee is less than 0.2UNQ', async ({helper}) => {549    const owner = await helper.eth.createAccountWithBalance(donor);550    const spender = await helper.eth.createAccountWithBalance(donor);551552    const collection = await helper.nft.mintCollection(alice, {});553    const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});554555    const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', owner);556557    await contract.methods.approve(spender, tokenId).send({from: owner});558559    const cost = await helper.eth.recordCallFee(spender, () => contract.methods.transferFrom(owner, spender, tokenId).send({from: spender}));560    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));561  });562563  itEth('Can perform transferFromCross()', async ({helper}) => {564    const collectionMinter = alice;565    const owner = bob;566    const receiver = charlie;567    const collection = await helper.nft.mintCollection(collectionMinter, {name: 'A', description: 'B', tokenPrefix: 'C'});568569    const spender = await helper.eth.createAccountWithBalance(donor, 100n);570571    const token = await collection.mintToken(collectionMinter, {Substrate: owner.address});572573    const address = helper.ethAddress.fromCollectionId(collection.collectionId);574    const contract = helper.ethNativeContract.collection(address, 'nft');575576    await token.approve(owner, {Ethereum: spender});577578    {579      const ownerCross = helper.ethCrossAccount.fromKeyringPair(owner);580      const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);581      const result = await contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender});582      const event = result.events.Transfer;583      expect(event).to.be.like({584        address: helper.ethAddress.fromCollectionId(collection.collectionId),585        event: 'Transfer',586        returnValues: {587          from: helper.address.substrateToEth(owner.address),588          to: helper.address.substrateToEth(receiver.address),589          tokenId: token.tokenId.toString(),590        },591      });592    }593594    expect(await token.getOwner()).to.be.like({Substrate: receiver.address});595  });596597  itEth('transfer() call fee is less than 0.2UNQ', async ({helper}) => {598    const owner = await helper.eth.createAccountWithBalance(donor);599    const receiver = helper.eth.createAccount();600601    const collection = await helper.nft.mintCollection(alice, {});602    const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});603604    const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', owner);605606    const cost = await helper.eth.recordCallFee(owner, () => contract.methods.transfer(receiver, tokenId).send({from: owner}));607    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));608  });609});610611describe('NFT: Substrate calls', () => {612  let donor: IKeyringPair;613  let alice: IKeyringPair;614615  before(async function() {616    await usingEthPlaygrounds(async (helper, privateKey) => {617      donor = await privateKey({filename: __filename});618      [alice] = await helper.arrange.createAccounts([20n], donor);619    });620  });621622  itEth('Events emitted for mint()', async ({helper}) => {623    const collection = await helper.nft.mintCollection(alice, {});624    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);625    const contract = helper.ethNativeContract.collection(collectionAddress, 'nft');626627    const events: any = [];628    contract.events.allEvents((_: any, event: any) => {629      events.push(event);630    });631632    const {tokenId} = await collection.mintToken(alice);633    if (events.length == 0) await helper.wait.newBlocks(1);634    const event = events[0];635636    expect(event.event).to.be.equal('Transfer');637    expect(event.address).to.be.equal(collectionAddress);638    expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');639    expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(alice.address));640    expect(event.returnValues.tokenId).to.be.equal(tokenId.toString());641  });642643  itEth('Events emitted for burn()', async ({helper}) => {644    const collection = await helper.nft.mintCollection(alice, {});645    const token = await collection.mintToken(alice);646647    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);648    const contract = helper.ethNativeContract.collection(collectionAddress, 'nft');649650    const events: any = [];651    contract.events.allEvents((_: any, event: any) => {652      events.push(event);653    });654655    await token.burn(alice);656    if (events.length == 0) await helper.wait.newBlocks(1);657    const event = events[0];658659    expect(event.event).to.be.equal('Transfer');660    expect(event.address).to.be.equal(collectionAddress);661    expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));662    expect(event.returnValues.to).to.be.equal('0x0000000000000000000000000000000000000000');663    expect(event.returnValues.tokenId).to.be.equal(token.tokenId.toString());664  });665666  itEth('Events emitted for approve()', async ({helper}) => {667    const receiver = helper.eth.createAccount();668669    const collection = await helper.nft.mintCollection(alice, {});670    const token = await collection.mintToken(alice);671672    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);673    const contract = helper.ethNativeContract.collection(collectionAddress, 'nft');674675    const events: any = [];676    contract.events.allEvents((_: any, event: any) => {677      events.push(event);678    });679680    await token.approve(alice, {Ethereum: receiver});681    if (events.length == 0) await helper.wait.newBlocks(1);682    const event = events[0];683684    expect(event.event).to.be.equal('Approval');685    expect(event.address).to.be.equal(collectionAddress);686    expect(event.returnValues.owner).to.be.equal(helper.address.substrateToEth(alice.address));687    expect(event.returnValues.approved).to.be.equal(receiver);688    expect(event.returnValues.tokenId).to.be.equal(token.tokenId.toString());689  });690691  itEth('Events emitted for transferFrom()', async ({helper}) => {692    const [bob] = await helper.arrange.createAccounts([10n], donor);693    const receiver = helper.eth.createAccount();694695    const collection = await helper.nft.mintCollection(alice, {});696    const token = await collection.mintToken(alice);697    await token.approve(alice, {Substrate: bob.address});698699    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);700    const contract = helper.ethNativeContract.collection(collectionAddress, 'nft');701702    const events: any = [];703    contract.events.allEvents((_: any, event: any) => {704      events.push(event);705    });706707    await token.transferFrom(bob, {Substrate: alice.address}, {Ethereum: receiver});708709    if (events.length == 0) await helper.wait.newBlocks(1);710    const event = events[0];711712    expect(event.address).to.be.equal(collectionAddress);713    expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));714    expect(event.returnValues.to).to.be.equal(receiver);715    expect(event.returnValues.tokenId).to.be.equal(`${token.tokenId}`);716  });717718  itEth('Events emitted for transfer()', async ({helper}) => {719    const receiver = helper.eth.createAccount();720721    const collection = await helper.nft.mintCollection(alice, {});722    const token = await collection.mintToken(alice);723724    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);725    const contract = helper.ethNativeContract.collection(collectionAddress, 'nft');726727    const events: any = [];728    contract.events.allEvents((_: any, event: any) => {729      events.push(event);730    });731732    await token.transfer(alice, {Ethereum: receiver});733734    if (events.length == 0) await helper.wait.newBlocks(1);735    const event = events[0];736737    expect(event.address).to.be.equal(collectionAddress);738    expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));739    expect(event.returnValues.to).to.be.equal(receiver);740    expect(event.returnValues.tokenId).to.be.equal(`${token.tokenId}`);741  });742});743744describe('Common metadata', () => {745  let donor: IKeyringPair;746  let alice: IKeyringPair;747748  before(async function() {749    await usingEthPlaygrounds(async (helper, privateKey) => {750      donor = await privateKey({filename: __filename});751      [alice] = await helper.arrange.createAccounts([20n], donor);752    });753  });754755  itEth('Returns collection name', async ({helper}) => {756    const caller = await helper.eth.createAccountWithBalance(donor);757    const tokenPropertyPermissions = [{758      key: 'URI',759      permission: {760        mutable: true,761        collectionAdmin: true,762        tokenOwner: false,763      },764    }];765    const collection = await helper.nft.mintCollection(766      alice,767      {768        name: 'oh River',769        tokenPrefix: 'CHANGE',770        properties: [{key: 'ERC721Metadata', value: '1'}],771        tokenPropertyPermissions,772      },773    );774775    const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);776    const name = await contract.methods.name().call();777    expect(name).to.equal('oh River');778  });779780  itEth('Returns symbol name', async ({helper}) => {781    const caller = await helper.eth.createAccountWithBalance(donor);782    const tokenPropertyPermissions = [{783      key: 'URI',784      permission: {785        mutable: true,786        collectionAdmin: true,787        tokenOwner: false,788      },789    }];790    const collection = await helper.nft.mintCollection(791      alice,792      {793        name: 'oh River',794        tokenPrefix: 'CHANGE',795        properties: [{key: 'ERC721Metadata', value: '1'}],796        tokenPropertyPermissions,797      },798    );799800    const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);801    const symbol = await contract.methods.symbol().call();802    expect(symbol).to.equal('CHANGE');803  });804});
modifiedtests/src/eth/reFungible.test.tsdiffbeforeafterboth
--- a/tests/src/eth/reFungible.test.ts
+++ b/tests/src/eth/reFungible.test.ts
@@ -413,9 +413,10 @@
     }
   });
 
-  itEth.skip('Cannot transferCross with invalid params', async ({helper}) => {
+  ['transfer', 'transferCross'].map(testCase => itEth(`Cannot ${testCase} non-owned token`, async ({helper}) => {
     const sender = await helper.eth.createAccountWithBalance(donor);
     const tokenOwner = await helper.eth.createAccountWithBalance(donor);
+    const receiverSub = minter;
     const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(minter);
 
     const collection = await helper.rft.mintCollection(minter, {});
@@ -423,12 +424,14 @@
     const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'rft', sender);
 
     await collection.mintToken(minter, 50n, {Ethereum: sender});
-    const notSendersToken = await collection.mintToken(minter, 50n, {Ethereum: tokenOwner});
+    const nonSendersToken = await collection.mintToken(minter, 50n, {Ethereum: tokenOwner});
+
     // Cannot transferCross someone else's token:
-    await expect(collectionEvm.methods.transferCross(receiverCrossSub, notSendersToken.tokenId).send({from: sender})).to.be.rejected;
-    // FIXME: (transaction successful): Cannot transfer token if it does not exist:
-    await expect(collectionEvm.methods.transferCross(receiverCrossSub, 999999).send({from: sender})).to.be.rejected;
-  });
+    const receiver = testCase === 'transfer' ? helper.address.substrateToEth(receiverSub.address) : receiverCrossSub;
+    await expect(collectionEvm.methods[testCase](receiver, nonSendersToken.tokenId).send({from: sender})).to.be.rejected;
+    // Cannot transfer token if it does not exist:
+    await expect(collectionEvm.methods[testCase](receiver, 999999).send({from: sender})).to.be.rejected;
+  }));
 
   itEth('transfer event on transfer from partial ownership to full ownership', async ({helper}) => {
     const caller = await helper.eth.createAccountWithBalance(donor);
modifiedtests/src/eth/reFungibleToken.test.tsdiffbeforeafterboth
--- a/tests/src/eth/reFungibleToken.test.ts
+++ b/tests/src/eth/reFungibleToken.test.ts
@@ -227,6 +227,46 @@
     }
   });
 
+  [
+    'transfer',
+    // 'transferCross', // TODO
+  ].map(testCase => 
+    itEth(`Cannot ${testCase}() non-owned token`, async ({helper}) => {
+      const owner = await helper.eth.createAccountWithBalance(donor);
+      const receiver = await helper.eth.createAccountWithBalance(donor);
+      const collection = await helper.rft.mintCollection(alice);
+      const rftOwner = await collection.mintToken(alice, 10n, {Ethereum: owner});
+      const rftReceiver = await collection.mintToken(alice, 10n, {Ethereum: receiver});
+      const tokenIdNonExist = 9999999;
+  
+      const tokenAddress1 = helper.ethAddress.fromTokenId(collection.collectionId, rftOwner.tokenId);
+      const tokenAddress2 = helper.ethAddress.fromTokenId(collection.collectionId, rftReceiver.tokenId);
+      const tokenAddressNonExist = helper.ethAddress.fromTokenId(collection.collectionId, tokenIdNonExist);
+      const tokenEvmOwner = helper.ethNativeContract.rftToken(tokenAddress1, owner);
+      const tokenEvmReceiver = helper.ethNativeContract.rftToken(tokenAddress2, owner);
+      const tokenEvmNonExist = helper.ethNativeContract.rftToken(tokenAddressNonExist, owner);
+      
+      // 1. Can transfer zero amount (EIP-20):
+      await tokenEvmOwner.methods[testCase](receiver, 0).send({from: owner});
+      // 2. Cannot transfer non-owned token:
+      await expect(tokenEvmReceiver.methods[testCase](owner, 0).send({from: owner})).to.be.rejected;
+      await expect(tokenEvmReceiver.methods[testCase](owner, 5).send({from: owner})).to.be.rejected;
+      // 3. Cannot transfer non-existing token:
+      await expect(tokenEvmNonExist.methods[testCase](owner, 0).send({from: owner})).to.be.rejected;
+      await expect(tokenEvmNonExist.methods[testCase](owner, 5).send({from: owner})).to.be.rejected;
+
+      // 4. Storage is not corrupted:
+      expect(await rftOwner.getTop10Owners()).to.deep.eq([{Ethereum: owner.toLowerCase()}]);
+      expect(await rftReceiver.getTop10Owners()).to.deep.eq([{Ethereum: receiver.toLowerCase()}]);
+      expect(await helper.rft.getTokenTop10Owners(collection.collectionId, tokenIdNonExist)).to.deep.eq([]); // TODO
+
+      // 4.1 Tokens can be transferred:
+      await tokenEvmOwner.methods[testCase](receiver, 10).send({from: owner});
+      await tokenEvmReceiver.methods[testCase](owner, 10).send({from: receiver});
+      expect(await rftOwner.getTop10Owners()).to.deep.eq([{Ethereum: receiver.toLowerCase()}]);
+      expect(await rftReceiver.getTop10Owners()).to.deep.eq([{Ethereum: owner.toLowerCase()}]);
+    }));
+
   itEth('Can perform repartition()', async ({helper}) => {
     const owner = await helper.eth.createAccountWithBalance(donor);
     const receiver = await helper.eth.createAccountWithBalance(donor);
modifiedtests/src/fungible.test.tsdiffbeforeafterboth
--- a/tests/src/fungible.test.ts
+++ b/tests/src/fungible.test.ts
@@ -15,7 +15,7 @@
 // along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
 
 import {IKeyringPair} from '@polkadot/types/types';
-import {itSub, usingPlaygrounds, expect} from './util';
+import {itSub, usingPlaygrounds, expect, requirePalletsOrSkip, Pallets} from './util';
 
 const U128_MAX = (1n << 128n) - 1n;
 
@@ -145,3 +145,42 @@
     expect(await collection.getBalance(ethAcc)).to.be.equal(10n);
   });
 });
+
+describe('Fungible negative tests', () => {
+  let donor: IKeyringPair;
+  let alice: IKeyringPair;
+  let bob: IKeyringPair;
+  let charlie: IKeyringPair;
+
+  before(async function() {
+    await usingPlaygrounds(async (helper, privateKey) => {
+      requirePalletsOrSkip(this, helper, [Pallets.Fungible]);
+
+      donor = await privateKey({filename: __filename});
+      [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
+    });
+  });
+
+  itSub('Cannot transfer incorrect amount of tokens', async ({helper}) => {
+    const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+    const nonExistingCollection = helper.ft.getCollectionObject(99999);
+    await collection.mint(alice, 10n, {Substrate: bob.address});
+
+    // 1. Alice cannot transfer more than 0 tokens if balance low:
+    await expect(collection.transfer(alice, {Substrate: charlie.address}, 1n)).to.be.rejectedWith('common.TokenValueTooLow');
+    await expect(collection.transfer(alice, {Substrate: charlie.address}, 100n)).to.be.rejectedWith('common.TokenValueTooLow');
+    
+    // 2. Alice cannot transfer non-existing token:
+    await expect(nonExistingCollection.transfer(alice, {Substrate: charlie.address}, 0n)).to.be.rejectedWith('common.CollectionNotFound');
+    await expect(nonExistingCollection.transfer(alice, {Substrate: charlie.address}, 1n)).to.be.rejectedWith('common.CollectionNotFound');
+    
+    // 3. Zero transfer allowed (EIP-20):
+    await collection.transfer(bob, {Substrate: charlie.address}, 0n);
+    // 3.1 even if the balance = 0
+    await collection.transfer(alice, {Substrate: charlie.address}, 0n);
+
+    expect(await collection.getBalance({Substrate: alice.address})).to.eq(0n);
+    expect(await collection.getBalance({Substrate: bob.address})).to.eq(10n);
+    expect(await collection.getBalance({Substrate: charlie.address})).to.eq(0n);
+  });
+});
modifiedtests/src/refungible.test.tsdiffbeforeafterboth
--- a/tests/src/refungible.test.ts
+++ b/tests/src/refungible.test.ts
@@ -255,3 +255,43 @@
   });
 });
 
+describe('Refungible negative tests', () => {
+  let donor: IKeyringPair;
+  let alice: IKeyringPair;
+  let bob: IKeyringPair;
+  let charlie: IKeyringPair;
+
+  before(async function() {
+    await usingPlaygrounds(async (helper, privateKey) => {
+      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
+
+      donor = await privateKey({filename: __filename});
+      [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
+    });
+  });
+
+  itSub('Cannot transfer incorrect amount of token pieces', async ({helper}) => {
+    const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+    const tokenAlice = await collection.mintToken(alice, 10n, {Substrate: alice.address});
+    const tokenBob = await collection.mintToken(alice, 10n, {Substrate: bob.address});
+
+    // 1. Alice cannot transfer Bob's token:
+    await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 0n)).to.be.rejectedWith('common.TokenValueTooLow');
+    await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 1n)).to.be.rejectedWith('common.TokenValueTooLow');
+    await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 10n)).to.be.rejectedWith('common.TokenValueTooLow');
+    await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 100n)).to.be.rejectedWith('common.TokenValueTooLow');
+    
+    // 2. Alice cannot transfer non-existing token:
+    await expect(collection.transferToken(alice, 100, {Substrate: charlie.address}, 0n)).to.be.rejectedWith('common.TokenValueTooLow');
+    await expect(collection.transferToken(alice, 100, {Substrate: charlie.address}, 1n)).to.be.rejectedWith('common.TokenValueTooLow');
+
+    // 3. Zero transfer allowed (EIP-20):
+    await tokenAlice.transfer(alice, {Substrate: charlie.address}, 0n);
+
+    expect(await tokenAlice.getTop10Owners()).to.deep.eq([{Substrate: alice.address}]);
+    expect(await tokenBob.getTop10Owners()).to.deep.eq([{Substrate: bob.address}]);
+    expect(await tokenAlice.getBalance({Substrate: alice.address})).to.eq(10n);
+    expect(await tokenBob.getBalance({Substrate: bob.address})).to.eq(10n);
+    expect(await tokenBob.getBalance({Substrate: charlie.address})).to.eq(0n);
+  });
+});
modifiedtests/src/transfer.test.tsdiffbeforeafterboth
--- a/tests/src/transfer.test.ts
+++ b/tests/src/transfer.test.ts
@@ -122,6 +122,7 @@
     });
   });
 
+
   itSub('[nft] Transfer with not existed collection_id', async ({helper}) => {
     const collectionId = (1 << 32) - 1;
     await expect(helper.nft.transferToken(alice, collectionId, 1, {Substrate: bob.address}))
@@ -191,6 +192,25 @@
       .to.be.rejectedWith(/common\.TokenValueTooLow/);
   });
 
+  itSub('Zero transfer NFT', async ({helper}) => {
+    const collection = await helper.nft.mintCollection(alice, {name: 'Transfer-Neg-3-NFT', description: '', tokenPrefix: 'T'});
+    const tokenAlice = await collection.mintToken(alice, {Substrate: alice.address});
+    const tokenBob = await collection.mintToken(alice, {Substrate: bob.address});
+    // 1. Zero transfer of own tokens allowed:
+    await helper.executeExtrinsic(alice, 'api.tx.unique.transfer', [{Substrate: bob.address}, collection.collectionId, tokenAlice.tokenId, 0]);
+    // 2. Zero transfer of non-owned tokens not allowed:
+    await expect(helper.executeExtrinsic(alice, 'api.tx.unique.transfer', [{Substrate: alice.address}, collection.collectionId, tokenBob.tokenId, 0])).to.be.rejectedWith('common.NoPermission');
+    // 3. Zero transfer of non-existing tokens not allowed:
+    await expect(helper.executeExtrinsic(alice, 'api.tx.unique.transfer', [{Substrate: alice.address}, collection.collectionId, 10, 0])).to.be.rejectedWith('common.TokenNotFound');
+    expect(await tokenAlice.getOwner()).to.deep.eq({Substrate: alice.address});
+    expect(await tokenBob.getOwner()).to.deep.eq({Substrate: bob.address});
+    // 4. Storage is not corrupted:
+    await tokenAlice.transfer(alice, {Substrate: bob.address});
+    await tokenBob.transfer(bob, {Substrate: alice.address});
+    expect(await tokenAlice.getOwner()).to.deep.eq({Substrate: bob.address});
+    expect(await tokenBob.getOwner()).to.deep.eq({Substrate: alice.address});
+  });
+
   itSub('[nft] Transfer with deleted item_id', async ({helper}) => {
     const collection = await helper.nft.mintCollection(alice, {name: 'Transfer-Neg-3-NFT', description: '', tokenPrefix: 'T'});
     const nft = await collection.mintToken(alice);
modifiedtests/src/transferFrom.test.tsdiffbeforeafterboth
--- a/tests/src/transferFrom.test.ts
+++ b/tests/src/transferFrom.test.ts
@@ -349,4 +349,27 @@
       {Substrate: charlie.address},
     )).to.be.rejectedWith(/common\.ApprovedValueTooLow/);
   });
+
+  itSub('zero transfer NFT', async ({helper}) => {
+    const collection = await helper.nft.mintCollection(alice, {name: 'Zero', description: 'Zero transfer', tokenPrefix: 'TF'});
+    const notApprovedNft = await collection.mintToken(alice, {Substrate: bob.address});
+    const approvedNft = await collection.mintToken(alice, {Substrate: bob.address});
+    await approvedNft.approve(bob, {Substrate: alice.address});
+
+    // 1. Cannot zero transferFrom (non-existing token)
+    await expect(helper.executeExtrinsic(alice, 'api.tx.unique.transferFrom', [{Substrate: bob.address}, {Substrate: alice.address}, collection.collectionId, 9999, 0])).to.be.rejectedWith('common.ApprovedValueTooLow');
+    // 2. Cannot zero transferFrom (not approved token)
+    await expect(helper.executeExtrinsic(alice, 'api.tx.unique.transferFrom', [{Substrate: bob.address}, {Substrate: alice.address}, collection.collectionId, notApprovedNft.tokenId, 0])).to.be.rejectedWith('common.ApprovedValueTooLow');
+    // 3. Can zero transferFrom (approved token):
+    await helper.executeExtrinsic(alice, 'api.tx.unique.transferFrom', [{Substrate: bob.address}, {Substrate: alice.address}, collection.collectionId, approvedNft.tokenId, 0]);
+
+    // 4.1 approvedNft still approved:
+    expect(await approvedNft.isApproved({Substrate: alice.address})).to.be.true;
+    // 4.2 bob is still the owner:
+    expect(await approvedNft.getOwner()).to.deep.eq({Substrate: bob.address});
+    expect(await notApprovedNft.getOwner()).to.deep.eq({Substrate: bob.address});
+    // 4.3 Alice can transfer approved nft:
+    await approvedNft.transferFrom(alice, {Substrate: bob.address}, {Substrate: alice.address});
+    expect(await approvedNft.getOwner()).to.deep.eq({Substrate: alice.address});
+  });
 });