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
before · tests/src/eth/fungible.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 {expect, itEth, usingEthPlaygrounds} from './util';18import {IKeyringPair} from '@polkadot/types/types';1920describe('Fungible: Information getting', () => {21  let donor: IKeyringPair;22  let alice: IKeyringPair;2324  before(async function() {25    await usingEthPlaygrounds(async (helper, privateKey) => {26      donor = await privateKey({filename: __filename});27      [alice] = await helper.arrange.createAccounts([20n], donor);28    });29  });3031  itEth('totalSupply', async ({helper}) => {32    const caller = await helper.eth.createAccountWithBalance(donor);33    const collection = await helper.ft.mintCollection(alice);34    await collection.mint(alice, 200n);3536    const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'ft', caller);37    const totalSupply = await contract.methods.totalSupply().call();38    expect(totalSupply).to.equal('200');39  });4041  itEth('balanceOf', async ({helper}) => {42    const caller = await helper.eth.createAccountWithBalance(donor);43    const collection = await helper.ft.mintCollection(alice);44    await collection.mint(alice, 200n, {Ethereum: caller});4546    const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'ft', caller);47    const balance = await contract.methods.balanceOf(caller).call();48    expect(balance).to.equal('200');49  });50});5152describe('Fungible: Plain calls', () => {53  let donor: IKeyringPair;54  let alice: IKeyringPair;55  let owner: IKeyringPair;5657  before(async function() {58    await usingEthPlaygrounds(async (helper, privateKey) => {59      donor = await privateKey({filename: __filename});60      [alice, owner] = await helper.arrange.createAccounts([20n, 20n], donor);61    });62  });6364  itEth('Can perform mint()', async ({helper}) => {65    const owner = await helper.eth.createAccountWithBalance(donor);66    const receiver = helper.eth.createAccount();67    const collection = await helper.ft.mintCollection(alice);68    await collection.addAdmin(alice, {Ethereum: owner});6970    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);71    const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);7273    const result = await contract.methods.mint(receiver, 100).send();74    75    const event = result.events.Transfer;76    expect(event.address).to.equal(collectionAddress);77    expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');78    expect(event.returnValues.to).to.equal(receiver);79    expect(event.returnValues.value).to.equal('100');80  });8182  itEth('Can perform mintBulk()', async ({helper}) => {83    const owner = await helper.eth.createAccountWithBalance(donor);84    const bulkSize = 3;85    const receivers = [...new Array(bulkSize)].map(() => helper.eth.createAccount());86    const collection = await helper.ft.mintCollection(alice);87    await collection.addAdmin(alice, {Ethereum: owner});8889    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);90    const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);9192    const result = await contract.methods.mintBulk(Array.from({length: bulkSize}, (_, i) => (93      [receivers[i], (i + 1) * 10]94    ))).send();95    const events = result.events.Transfer.sort((a: any, b: any) => +a.returnValues.value - b.returnValues.value);96    for (let i = 0; i < bulkSize; i++) {97      const event = events[i];98      expect(event.address).to.equal(collectionAddress);99      expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');100      expect(event.returnValues.to).to.equal(receivers[i]);101      expect(event.returnValues.value).to.equal(String(10 * (i + 1)));102    }103  });104105  // Soft-deprecated106  itEth('Can perform burn()', async ({helper}) => {107    const owner = await helper.eth.createAccountWithBalance(donor);108    const receiver = await helper.eth.createAccountWithBalance(donor);109    const collection = await helper.ft.mintCollection(alice);110    await collection.addAdmin(alice, {Ethereum: owner});111112    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);113    const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', owner, true);114    await contract.methods.mint(receiver, 100).send();115116    const result = await contract.methods.burnFrom(receiver, 49).send({from: receiver});117    118    const event = result.events.Transfer;119    expect(event.address).to.equal(collectionAddress);120    expect(event.returnValues.from).to.equal(receiver);121    expect(event.returnValues.to).to.equal('0x0000000000000000000000000000000000000000');122    expect(event.returnValues.value).to.equal('49');123124    const balance = await contract.methods.balanceOf(receiver).call();125    expect(balance).to.equal('51');126  });127128  itEth('Can perform approve()', async ({helper}) => {129    const owner = await helper.eth.createAccountWithBalance(donor);130    const spender = helper.eth.createAccount();131    const collection = await helper.ft.mintCollection(alice);132    await collection.mint(alice, 200n, {Ethereum: owner});133134    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);135    const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);136137    {138      const result = await contract.methods.approve(spender, 100).send({from: owner});139140      const event = result.events.Approval;141      expect(event.address).to.be.equal(collectionAddress);142      expect(event.returnValues.owner).to.be.equal(owner);143      expect(event.returnValues.spender).to.be.equal(spender);144      expect(event.returnValues.value).to.be.equal('100');145    }146147    {148      const allowance = await contract.methods.allowance(owner, spender).call();149      expect(+allowance).to.equal(100);150    }151  });152153  itEth('Can perform burnFromCross()', async ({helper}) => {154    const sender = await helper.eth.createAccountWithBalance(donor, 100n);155156    const collection = await helper.ft.mintCollection(owner, {name: 'A', description: 'B', tokenPrefix: 'C'}, 0);157158    await collection.mint(owner, 200n, {Substrate: owner.address});159    await collection.approveTokens(owner, {Ethereum: sender}, 100n);160161    const address = helper.ethAddress.fromCollectionId(collection.collectionId);162    const contract = helper.ethNativeContract.collection(address, 'ft');163164    const fromBalanceBefore = await collection.getBalance({Substrate: owner.address});165    166    const ownerCross = helper.ethCrossAccount.fromKeyringPair(owner);167    const result = await contract.methods.burnFromCross(ownerCross, 49).send({from: sender});168    const events = result.events;169170    expect(events).to.be.like({171      Transfer: {172        address: helper.ethAddress.fromCollectionId(collection.collectionId),173        event: 'Transfer',174        returnValues: {175          from: helper.address.substrateToEth(owner.address),176          to: '0x0000000000000000000000000000000000000000',177          value: '49',178        },179      },180      Approval: {181        address: helper.ethAddress.fromCollectionId(collection.collectionId),182        returnValues: {183          owner: helper.address.substrateToEth(owner.address),184          spender: sender,185          value: '51',186        },187        event: 'Approval',188      },189    });190191    const fromBalanceAfter = await collection.getBalance({Substrate: owner.address});192    expect(fromBalanceBefore - fromBalanceAfter).to.be.eq(49n);193  });194195  itEth('Can perform transferFrom()', async ({helper}) => {196    const owner = await helper.eth.createAccountWithBalance(donor);197    const spender = await helper.eth.createAccountWithBalance(donor);198    const receiver = helper.eth.createAccount();199    const collection = await helper.ft.mintCollection(alice);200    await collection.mint(alice, 200n, {Ethereum: owner});201202    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);203    const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);204205    await contract.methods.approve(spender, 100).send();206207    {208      const result = await contract.methods.transferFrom(owner, receiver, 49).send({from: spender});209      210      let event = result.events.Transfer;211      expect(event.address).to.be.equal(collectionAddress);212      expect(event.returnValues.from).to.be.equal(owner);213      expect(event.returnValues.to).to.be.equal(receiver);214      expect(event.returnValues.value).to.be.equal('49');215216      event = result.events.Approval;217      expect(event.address).to.be.equal(collectionAddress);218      expect(event.returnValues.owner).to.be.equal(owner);219      expect(event.returnValues.spender).to.be.equal(spender);220      expect(event.returnValues.value).to.be.equal('51');221    }222223    {224      const balance = await contract.methods.balanceOf(receiver).call();225      expect(+balance).to.equal(49);226    }227228    {229      const balance = await contract.methods.balanceOf(owner).call();230      expect(+balance).to.equal(151);231    }232  });233234  itEth('Can perform transferCross()', async ({helper}) => {235    const sender = await helper.eth.createAccountWithBalance(donor);236    const receiverEth = await helper.eth.createAccountWithBalance(donor);237    const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);238    const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(donor);239    const collection = await helper.ft.mintCollection(alice);240    await collection.mint(alice, 200n, {Ethereum: sender});241242    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);243    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'ft', sender);244245    {246      // Can transferCross to ethereum address:247      const result = await collectionEvm.methods.transferCross(receiverCrossEth, 50).send({from: sender});248      // Check events:249      const event = result.events.Transfer;250      expect(event.address).to.be.equal(collectionAddress);251      expect(event.returnValues.from).to.be.equal(sender);252      expect(event.returnValues.to).to.be.equal(receiverEth);253      expect(event.returnValues.value).to.be.equal('50');254      // Sender's balance decreased:255      const ownerBalance = await collectionEvm.methods.balanceOf(sender).call();256      expect(+ownerBalance).to.equal(150);257      // Receiver's balance increased:258      const receiverBalance = await collectionEvm.methods.balanceOf(receiverEth).call();259      expect(+receiverBalance).to.equal(50);260    }261    262    {263      // Can transferCross to substrate address:264      const result = await collectionEvm.methods.transferCross(receiverCrossSub, 50).send({from: sender});265      // Check events:266      const event = result.events.Transfer;267      expect(event.address).to.be.equal(collectionAddress);268      expect(event.returnValues.from).to.be.equal(sender);269      expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(donor.address));270      expect(event.returnValues.value).to.be.equal('50');271      // Sender's balance decreased:272      const senderBalance = await collection.getBalance({Ethereum: sender});273      expect(senderBalance).to.equal(100n);274      // Receiver's balance increased:275      const balance = await collection.getBalance({Substrate: donor.address});276      expect(balance).to.equal(50n);277    }278  });279280  itEth('Cannot transferCross() more than have', async ({helper}) => {281    const sender = await helper.eth.createAccountWithBalance(donor);282    const receiverEth = await helper.eth.createAccountWithBalance(donor);283    const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);284    const BALANCE = 200n;285    const BALANCE_TO_TRANSFER = BALANCE + 100n;286287    const collection = await helper.ft.mintCollection(alice);288    await collection.mint(alice, BALANCE, {Ethereum: sender});289    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);290    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'ft', sender);291292    await expect(collectionEvm.methods.transferCross(receiverCrossEth, BALANCE_TO_TRANSFER).send({from: sender})).to.be.rejected;293  });294  295  itEth('Can perform transfer()', async ({helper}) => {296    const owner = await helper.eth.createAccountWithBalance(donor);297    const receiver = await helper.eth.createAccountWithBalance(donor);298    const collection = await helper.ft.mintCollection(alice);299    await collection.mint(alice, 200n, {Ethereum: owner});300301    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);302    const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);303304    {305      const result = await contract.methods.transfer(receiver, 50).send({from: owner});306      307      const event = result.events.Transfer;308      expect(event.address).to.be.equal(collectionAddress);309      expect(event.returnValues.from).to.be.equal(owner);310      expect(event.returnValues.to).to.be.equal(receiver);311      expect(event.returnValues.value).to.be.equal('50');312    }313314    {315      const balance = await contract.methods.balanceOf(owner).call();316      expect(+balance).to.equal(150);317    }318319    {320      const balance = await contract.methods.balanceOf(receiver).call();321      expect(+balance).to.equal(50);322    }323  });324325  itEth('Can perform transferFromCross()', async ({helper}) => {326    const sender = await helper.eth.createAccountWithBalance(donor, 100n);327328    const collection = await helper.ft.mintCollection(owner, {name: 'A', description: 'B', tokenPrefix: 'C'}, 0);329330    const receiver = helper.eth.createAccount();331332    await collection.mint(owner, 200n, {Substrate: owner.address});333    await collection.approveTokens(owner, {Ethereum: sender}, 100n);334335    const address = helper.ethAddress.fromCollectionId(collection.collectionId);336    const contract = helper.ethNativeContract.collection(address, 'ft');337338    const from = helper.ethCrossAccount.fromKeyringPair(owner);339    const to = helper.ethCrossAccount.fromAddress(receiver);340341    const fromBalanceBefore = await collection.getBalance({Substrate: owner.address});342    const toBalanceBefore = await collection.getBalance({Ethereum: receiver});343    344    const result = await contract.methods.transferFromCross(from, to, 51).send({from: sender});345346    expect(result.events).to.be.like({347      Transfer: {348        address,349        event: 'Transfer',350        returnValues: {351          from: helper.address.substrateToEth(owner.address),352          to: receiver,353          value: '51',354        },355      },356      Approval: {357        address,358        event: 'Approval',359        returnValues: {360          owner: helper.address.substrateToEth(owner.address),361          spender: sender,362          value: '49',363        },364      }});365366    const fromBalanceAfter = await collection.getBalance({Substrate: owner.address});367    expect(fromBalanceBefore - fromBalanceAfter).to.be.eq(51n);368    const toBalanceAfter = await collection.getBalance({Ethereum: receiver});369    expect(toBalanceAfter - toBalanceBefore).to.be.eq(51n);370  });371});372373describe('Fungible: Fees', () => {374  let donor: IKeyringPair;375  let alice: IKeyringPair;376377  before(async function() {378    await usingEthPlaygrounds(async (helper, privateKey) => {379      donor = await privateKey({filename: __filename});380      [alice] = await helper.arrange.createAccounts([20n], donor);381    });382  });383  384  itEth('approve() call fee is less than 0.2UNQ', async ({helper}) => {385    const owner = await helper.eth.createAccountWithBalance(donor);386    const spender = helper.eth.createAccount();387    const collection = await helper.ft.mintCollection(alice);388    await collection.mint(alice, 200n, {Ethereum: owner});389390    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);391    const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);392393    const cost = await helper.eth.recordCallFee(owner, () => contract.methods.approve(spender, 100).send({from: owner}));394    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));395  });396397  itEth('transferFrom() call fee is less than 0.2UNQ', async ({helper}) => {398    const owner = await helper.eth.createAccountWithBalance(donor);399    const spender = await helper.eth.createAccountWithBalance(donor);400    const collection = await helper.ft.mintCollection(alice);401    await collection.mint(alice, 200n, {Ethereum: owner});402403    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);404    const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);405406    await contract.methods.approve(spender, 100).send({from: owner});407408    const cost = await helper.eth.recordCallFee(spender, () => contract.methods.transferFrom(owner, spender, 100).send({from: spender}));409    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));410  });411412  itEth('transfer() call fee is less than 0.2UNQ', async ({helper}) => {413    const owner = await helper.eth.createAccountWithBalance(donor);414    const receiver = helper.eth.createAccount();415    const collection = await helper.ft.mintCollection(alice);416    await collection.mint(alice, 200n, {Ethereum: owner});417418    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);419    const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);420421    const cost = await helper.eth.recordCallFee(owner, () => contract.methods.transfer(receiver, 100).send({from: owner}));422    expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));423  });424});425426describe('Fungible: Substrate calls', () => {427  let donor: IKeyringPair;428  let alice: IKeyringPair;429  let owner: IKeyringPair;430431  before(async function() {432    await usingEthPlaygrounds(async (helper, privateKey) => {433      donor = await privateKey({filename: __filename});434      [alice, owner] = await helper.arrange.createAccounts([20n, 20n], donor);435    });436  });437438  itEth('Events emitted for approve()', async ({helper}) => {439    const receiver = helper.eth.createAccount();440    const collection = await helper.ft.mintCollection(alice);441    await collection.mint(alice, 200n);442443    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);444    const contract = helper.ethNativeContract.collection(collectionAddress, 'ft');445446    const events: any = [];447    contract.events.allEvents((_: any, event: any) => {448      events.push(event);449    });450    451    await collection.approveTokens(alice, {Ethereum: receiver}, 100n);452    if (events.length == 0) await helper.wait.newBlocks(1);453    const event = events[0];454455    expect(event.event).to.be.equal('Approval');456    expect(event.address).to.be.equal(collectionAddress);457    expect(event.returnValues.owner).to.be.equal(helper.address.substrateToEth(alice.address));458    expect(event.returnValues.spender).to.be.equal(receiver);459    expect(event.returnValues.value).to.be.equal('100');460  });461462  itEth('Events emitted for transferFrom()', async ({helper}) => {463    const [bob] = await helper.arrange.createAccounts([10n], donor);464    const receiver = helper.eth.createAccount();465    const collection = await helper.ft.mintCollection(alice);466    await collection.mint(alice, 200n);467    await collection.approveTokens(alice, {Substrate: bob.address}, 100n);468469    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);470    const contract = helper.ethNativeContract.collection(collectionAddress, 'ft');471472    const events: any = [];473    contract.events.allEvents((_: any, event: any) => {474      events.push(event);475    });476477    await collection.transferFrom(bob, {Substrate: alice.address}, {Ethereum: receiver}, 51n);478    if (events.length == 0) await helper.wait.newBlocks(1);479    let event = events[0];480481    expect(event.event).to.be.equal('Transfer');482    expect(event.address).to.be.equal(collectionAddress);483    expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));484    expect(event.returnValues.to).to.be.equal(receiver);485    expect(event.returnValues.value).to.be.equal('51');486487    event = events[1];488    expect(event.event).to.be.equal('Approval');489    expect(event.address).to.be.equal(collectionAddress);490    expect(event.returnValues.owner).to.be.equal(helper.address.substrateToEth(alice.address));491    expect(event.returnValues.spender).to.be.equal(helper.address.substrateToEth(bob.address));492    expect(event.returnValues.value).to.be.equal('49');493  });494495  itEth('Events emitted for transfer()', async ({helper}) => {496    const receiver = helper.eth.createAccount();497    const collection = await helper.ft.mintCollection(alice);498    await collection.mint(alice, 200n);499500    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);501    const contract = helper.ethNativeContract.collection(collectionAddress, 'ft');502503    const events: any = [];504    contract.events.allEvents((_: any, event: any) => {505      events.push(event);506    });507    508    await collection.transfer(alice, {Ethereum:receiver}, 51n);509    if (events.length == 0) await helper.wait.newBlocks(1);510    const event = events[0];511512    expect(event.event).to.be.equal('Transfer');513    expect(event.address).to.be.equal(collectionAddress);514    expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));515    expect(event.returnValues.to).to.be.equal(receiver);516    expect(event.returnValues.value).to.be.equal('51');517  });518519  itEth('Events emitted for transferFromCross()', async ({helper}) => {520    const sender = await helper.eth.createAccountWithBalance(donor, 100n);521522    const collection = await helper.ft.mintCollection(owner, {name: 'A', description: 'B', tokenPrefix: 'C'}, 0);523524    const receiver = helper.eth.createAccount();525526    await collection.mint(owner, 200n, {Substrate: owner.address});527    await collection.approveTokens(owner, {Ethereum: sender}, 100n);528529    const address = helper.ethAddress.fromCollectionId(collection.collectionId);530    const contract = helper.ethNativeContract.collection(address, 'ft');531532    const from = helper.ethCrossAccount.fromKeyringPair(owner);533    const to = helper.ethCrossAccount.fromAddress(receiver);534    535    const result = await contract.methods.transferFromCross(from, to, 51).send({from: sender});536537    expect(result.events).to.be.like({538      Transfer: {539        address,540        event: 'Transfer',541        returnValues: {542          from: helper.address.substrateToEth(owner.address),543          to: receiver,544          value: '51',545        },546      },547      Approval: {548        address,549        event: 'Approval',550        returnValues: {551          owner: helper.address.substrateToEth(owner.address),552          spender: sender,553          value: '49',554        },555      }});556  });557});
modifiedtests/src/eth/nonFungible.test.tsdiffbeforeafterboth
--- a/tests/src/eth/nonFungible.test.ts
+++ b/tests/src/eth/nonFungible.test.ts
@@ -517,6 +517,26 @@
       expect(receiverBalance).to.contain(tokenId);
     }
   });
+
+  ['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.nft.mintCollection(minter, {});
+    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', sender);
+
+    await collection.mintToken(minter, {Ethereum: sender});
+    const nonSendersToken = await collection.mintToken(minter, {Ethereum: tokenOwner});
+
+    // Cannot transferCross someone else's token:
+    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;
+  }));
 });
 
 describe('NFT: Fees', () => {
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});
+  });
 });