difftreelog
fix tests and weights
in: master
16 files changed
pallets/balances-adapter/src/erc.rsdiffbeforeafterboth--- a/pallets/balances-adapter/src/erc.rs
+++ b/pallets/balances-adapter/src/erc.rs
@@ -1,6 +1,7 @@
-use crate::{Config, NativeFungibleHandle};
+use crate::{Config, NativeFungibleHandle, SelfWeightOf};
use evm_coder::{abi::AbiType, ToLog, generate_stubgen, solidity_interface, types::*};
use frame_support::traits::{Currency, ExistenceRequirement};
+use pallet_balances::WeightInfo;
use pallet_common::{
erc::{CommonEvmHandler, CrossAccountId, PrecompileHandle, PrecompileResult},
eth::CrossAddress,
@@ -73,7 +74,7 @@
Ok(total.into())
}
- // #[weight(<SelfWeightOf<T>>::transfer())]
+ #[weight(<SelfWeightOf<T>>::transfer())]
fn transfer(&mut self, caller: Caller, to: Address, amount: U256) -> Result<bool> {
let caller = T::CrossAccountId::from_eth(caller);
let to = T::CrossAccountId::from_eth(to);
@@ -93,7 +94,7 @@
Ok(true)
}
- // #[weight(<SelfWeightOf<T>>::transfer_from())]
+ #[weight(<SelfWeightOf<T>>::transfer())]
fn transfer_from(
&mut self,
caller: Caller,
@@ -138,7 +139,7 @@
Ok(balance.into())
}
- // #[weight(<SelfWeightOf<T>>::transfer())]
+ #[weight(<SelfWeightOf<T>>::transfer())]
fn transfer_cross(&mut self, caller: Caller, to: CrossAddress, amount: U256) -> Result<bool> {
let caller = T::CrossAccountId::from_eth(caller);
let to = to.into_sub_cross_account::<T>()?;
@@ -158,7 +159,7 @@
Ok(true)
}
- // #[weight(<SelfWeightOf<T>>::transfer_from())]
+ #[weight(<SelfWeightOf<T>>::transfer())]
fn transfer_from_cross(
&mut self,
caller: Caller,
pallets/balances-adapter/src/lib.rsdiffbeforeafterboth--- a/pallets/balances-adapter/src/lib.rs
+++ b/pallets/balances-adapter/src/lib.rs
@@ -11,6 +11,8 @@
pub mod common;
pub mod erc;
+pub(crate) type SelfWeightOf<T> = <T as Config>::WeightInfo;
+
pub struct NativeFungibleHandle<T: Config>(SubstrateRecorder<T>);
impl<T: Config> NativeFungibleHandle<T> {
pub fn new() -> NativeFungibleHandle<T> {
@@ -34,6 +36,7 @@
pub mod pallet {
use alloc::string::String;
use frame_support::{traits::Get, sp_runtime::DispatchResult};
+ use pallet_balances::WeightInfo;
use sp_core::U256;
#[pallet::config]
@@ -49,6 +52,8 @@
type Decimals: Get<u8>;
type Name: Get<String>;
type Symbol: Get<String>;
+
+ type WeightInfo: WeightInfo;
}
#[pallet::pallet]
pub struct Pallet<T>(_);
runtime/common/config/pallets/mod.rsdiffbeforeafterboth--- a/runtime/common/config/pallets/mod.rs
+++ b/runtime/common/config/pallets/mod.rs
@@ -94,6 +94,7 @@
type Decimals = Decimals;
type Name = Name;
type Symbol = Symbol;
+ type WeightInfo = pallet_balances::weights::SubstrateWeight<Self>;
}
parameter_types! {
tests/src/addCollectionAdmin.test.tsdiffbeforeafterboth--- a/tests/src/addCollectionAdmin.test.ts
+++ b/tests/src/addCollectionAdmin.test.ts
@@ -16,6 +16,7 @@
import {IKeyringPair} from '@polkadot/types/types';
import {itSub, usingPlaygrounds, expect} from './util';
+import {NON_EXISTENT_COLLECTION_ID} from './util/playgrounds/types';
describe('Integration Test addCollectionAdmin(collection_id, new_admin_id):', () => {
let donor: IKeyringPair;
@@ -82,7 +83,7 @@
itSub("Can't add collection admin of not existing collection.", async ({helper}) => {
const [alice, bob] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);
- const collectionId = (1 << 32) - 1;
+ const collectionId = NON_EXISTENT_COLLECTION_ID;
await expect(helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address})).to.be.rejectedWith(/common\.CollectionNotFound/);
tests/src/allowLists.test.tsdiffbeforeafterboth--- a/tests/src/allowLists.test.ts
+++ b/tests/src/allowLists.test.ts
@@ -16,7 +16,7 @@
import {IKeyringPair} from '@polkadot/types/types';
import {usingPlaygrounds, expect, itSub} from './util';
-import {ICollectionPermissions} from './util/playgrounds/types';
+import {ICollectionPermissions, NON_EXISTENT_COLLECTION_ID} from './util/playgrounds/types';
describe('Integration Test ext. Allow list tests', () => {
let alice: IKeyringPair;
@@ -60,7 +60,7 @@
describe('Negative', () => {
itSub('Nobody can add address to allow list of non-existing collection', async ({helper}) => {
- const collectionId = (1<<32) - 1;
+ const collectionId = NON_EXISTENT_COLLECTION_ID;
await expect(helper.nft.addToAllowList(bob, collectionId, {Substrate: charlie.address}))
.to.be.rejectedWith(/common\.CollectionNotFound/);
});
@@ -140,7 +140,7 @@
});
itSub('Nobody can remove address from allow list of non-existing collection', async ({helper}) => {
- const collectionId = (1<<32) - 1;
+ const collectionId = NON_EXISTENT_COLLECTION_ID;
await expect(helper.collection.removeFromAllowList(bob, collectionId, {Substrate: charlie.address}))
.to.be.rejectedWith(/common\.CollectionNotFound/);
});
tests/src/change-collection-owner.test.tsdiffbeforeafterboth--- a/tests/src/change-collection-owner.test.ts
+++ b/tests/src/change-collection-owner.test.ts
@@ -16,6 +16,7 @@
import {IKeyringPair} from '@polkadot/types/types';
import {usingPlaygrounds, expect, itSub} from './util';
+import {NON_EXISTENT_COLLECTION_ID} from './util/playgrounds/types';
describe('Integration Test changeCollectionOwner(collection_id, new_owner):', () => {
let alice: IKeyringPair;
@@ -127,7 +128,7 @@
});
itSub('Can\'t change owner of a non-existing collection.', async ({helper}) => {
- const collectionId = (1 << 32) - 1;
+ const collectionId = NON_EXISTENT_COLLECTION_ID;
const changeOwnerTx = () => helper.collection.changeOwner(bob, collectionId, bob.address);
await expect(changeOwnerTx()).to.be.rejectedWith(/common\.CollectionNotFound/);
});
tests/src/confirmSponsorship.test.tsdiffbeforeafterboth--- a/tests/src/confirmSponsorship.test.ts
+++ b/tests/src/confirmSponsorship.test.ts
@@ -16,6 +16,7 @@
import {IKeyringPair} from '@polkadot/types/types';
import {usingPlaygrounds, expect, itSub, Pallets} from './util';
+import {NON_EXISTENT_COLLECTION_ID} from './util/playgrounds/types';
async function setSponsorHelper(collection: any, signer: IKeyringPair, sponsorAddress: string) {
await collection.setSponsor(signer, sponsorAddress);
@@ -198,7 +199,7 @@
});
itSub('(!negative test!) Confirm sponsorship for a collection that never existed', async ({helper}) => {
- const collectionId = (1 << 32) - 1;
+ const collectionId = NON_EXISTENT_COLLECTION_ID;
const confirmSponsorshipTx = () => helper.collection.confirmSponsorship(bob, collectionId);
await expect(confirmSponsorshipTx()).to.be.rejectedWith(/common\.CollectionNotFound/);
});
tests/src/eth/util/playgrounds/types.tsdiffbeforeafterboth--- a/tests/src/eth/util/playgrounds/types.ts
+++ b/tests/src/eth/util/playgrounds/types.ts
@@ -48,5 +48,3 @@
field: CollectionLimitField,
value: OptionUint,
}
-
-export const NON_EXISTENT_COLLECTION_ID = 4_294_967_295;
\ No newline at end of file
tests/src/removeCollectionAdmin.test.tsdiffbeforeafterboth--- a/tests/src/removeCollectionAdmin.test.ts
+++ b/tests/src/removeCollectionAdmin.test.ts
@@ -16,6 +16,7 @@
import {IKeyringPair} from '@polkadot/types/types';
import {itSub, usingPlaygrounds, expect} from './util';
+import {NON_EXISTENT_COLLECTION_ID} from './util/playgrounds/types';
describe('Integration Test removeCollectionAdmin(collection_id, account_id):', () => {
let alice: IKeyringPair;
@@ -68,7 +69,7 @@
});
itSub('Can\'t remove collection admin from not existing collection', async ({helper}) => {
- const collectionId = (1 << 32) - 1;
+ const collectionId = NON_EXISTENT_COLLECTION_ID;
await expect(helper.collection.removeAdmin(alice, collectionId, {Substrate: bob.address}))
.to.be.rejectedWith(/common\.CollectionNotFound/);
tests/src/removeCollectionSponsor.test.tsdiffbeforeafterboth--- a/tests/src/removeCollectionSponsor.test.ts
+++ b/tests/src/removeCollectionSponsor.test.ts
@@ -16,6 +16,7 @@
import {IKeyringPair} from '@polkadot/types/types';
import {itSub, usingPlaygrounds, expect} from './util';
+import {NON_EXISTENT_COLLECTION_ID} from './util/playgrounds/types';
describe('integration test: ext. removeCollectionSponsor():', () => {
let donor: IKeyringPair;
@@ -91,7 +92,7 @@
});
itSub('(!negative test!) Remove sponsor for a collection that never existed', async ({helper}) => {
- const collectionId = (1 << 32) - 1;
+ const collectionId = NON_EXISTENT_COLLECTION_ID;
await expect(helper.collection.removeSponsor(alice, collectionId)).to.be.rejectedWith(/common\.CollectionNotFound/);
});
tests/src/setCollectionLimits.test.tsdiffbeforeafterboth--- a/tests/src/setCollectionLimits.test.ts
+++ b/tests/src/setCollectionLimits.test.ts
@@ -17,6 +17,7 @@
// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits
import {IKeyringPair} from '@polkadot/types/types';
import {itSub, usingPlaygrounds, expect} from './util';
+import {NON_EXISTENT_COLLECTION_ID} from './util/playgrounds/types';
const accountTokenOwnershipLimit = 0;
const sponsoredDataSize = 0;
@@ -110,7 +111,7 @@
});
itSub('execute setCollectionLimits for not exists collection', async ({helper}) => {
- const nonExistentCollectionId = (1 << 32) - 1;
+ const nonExistentCollectionId = NON_EXISTENT_COLLECTION_ID;
await expect(helper.collection.setLimits(
alice,
nonExistentCollectionId,
tests/src/setCollectionSponsor.test.tsdiffbeforeafterboth--- a/tests/src/setCollectionSponsor.test.ts
+++ b/tests/src/setCollectionSponsor.test.ts
@@ -16,6 +16,7 @@
import {IKeyringPair} from '@polkadot/types/types';
import {itSub, usingPlaygrounds, expect, Pallets} from './util';
+import {NON_EXISTENT_COLLECTION_ID} from './util/playgrounds/types';
describe('integration test: ext. setCollectionSponsor():', () => {
let alice: IKeyringPair;
@@ -105,7 +106,7 @@
});
itSub('(!negative test!) Add sponsor to a collection that never existed', async ({helper}) => {
- const collectionId = (1 << 32) - 1;
+ const collectionId = NON_EXISTENT_COLLECTION_ID;
await expect(helper.collection.setSponsor(alice, collectionId, bob.address))
.to.be.rejectedWith(/common\.CollectionNotFound/);
});
tests/src/setPermissions.test.tsdiffbeforeafterboth--- a/tests/src/setPermissions.test.ts
+++ b/tests/src/setPermissions.test.ts
@@ -16,6 +16,7 @@
import {IKeyringPair} from '@polkadot/types/types';
import {itSub, usingPlaygrounds, expect} from './util';
+import {NON_EXISTENT_COLLECTION_ID} from './util/playgrounds/types';
describe('Integration Test: Set Permissions', () => {
let alice: IKeyringPair;
@@ -85,7 +86,7 @@
});
itSub('fails on not existing collection', async ({helper}) => {
- const collectionId = (1 << 32) - 1;
+ const collectionId = NON_EXISTENT_COLLECTION_ID;
await expect(helper.collection.setPermissions(alice, collectionId, {access: 'AllowList', mintMode: true}))
.to.be.rejectedWith(/common\.CollectionNotFound/);
});
tests/src/transfer.test.tsdiffbeforeafterboth--- a/tests/src/transfer.test.ts
+++ b/tests/src/transfer.test.ts
@@ -17,7 +17,7 @@
import {IKeyringPair} from '@polkadot/types/types';
import {itEth, usingEthPlaygrounds} from './eth/util';
import {itSub, Pallets, usingPlaygrounds, expect} from './util';
-import {NON_EXISTENT_COLLECTION_ID} from './eth/util/playgrounds/types';
+import {NON_EXISTENT_COLLECTION_ID} from './util/playgrounds/types';
describe('Integration Test Transfer(recipient, collection_id, item_id, value)', () => {
let donor: IKeyringPair;
tests/src/transferFrom.test.tsdiffbeforeafterboth1// 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 {IKeyringPair} from '@polkadot/types/types';18import {itSub, Pallets, usingPlaygrounds, expect} from './util';19import {NON_EXISTENT_COLLECTION_ID} from './eth/util/playgrounds/types';2021describe('Integration Test transferFrom(from, recipient, collection_id, item_id, value):', () => {22 let alice: IKeyringPair;23 let bob: IKeyringPair;24 let charlie: IKeyringPair;2526 before(async () => {27 await usingPlaygrounds(async (helper, privateKey) => {28 const donor = await privateKey({url: import.meta.url});29 [alice, bob, charlie] = await helper.arrange.createAccounts([20n, 10n, 10n], donor);30 });31 });3233 itSub('[nft] Execute the extrinsic and check nftItemList - owner of token', async ({helper}) => {34 const collection = await helper.nft.mintCollection(alice, {name: 'TransferFrom-1', description: '', tokenPrefix: 'TF'});35 const nft = await collection.mintToken(alice);36 await nft.approve(alice, {Substrate: bob.address});37 expect(await nft.isApproved({Substrate: bob.address})).to.be.true;3839 await nft.transferFrom(bob, {Substrate: alice.address}, {Substrate: charlie.address});40 expect(await nft.getOwner()).to.be.deep.equal({Substrate: charlie.address});41 });4243 itSub('[fungible] Execute the extrinsic and check nftItemList - owner of token', async ({helper}) => {44 const collection = await helper.ft.mintCollection(alice, {name: 'TransferFrom-2', description: '', tokenPrefix: 'TF'});45 await collection.mint(alice, 10n);46 await collection.approveTokens(alice, {Substrate: bob.address}, 7n);47 expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(7n);4849 await collection.transferFrom(bob, {Substrate: alice.address}, {Substrate: charlie.address}, 6n);50 expect(await collection.getBalance({Substrate: charlie.address})).to.be.equal(6n);51 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(4n);52 expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(1n);53 });5455 itSub.ifWithPallets('[refungible] Execute the extrinsic and check nftItemList - owner of token', [Pallets.ReFungible], async ({helper}) => {56 const collection = await helper.rft.mintCollection(alice, {name: 'TransferFrom-3', description: '', tokenPrefix: 'TF'});57 const rft = await collection.mintToken(alice, 10n);58 await rft.approve(alice, {Substrate: bob.address}, 7n);59 expect(await rft.getApprovedPieces({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(7n);6061 await rft.transferFrom(bob, {Substrate: alice.address}, {Substrate: charlie.address}, 6n);62 expect(await rft.getBalance({Substrate: charlie.address})).to.be.equal(6n);63 expect(await rft.getBalance({Substrate: alice.address})).to.be.equal(4n);64 expect(await rft.getApprovedPieces({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(1n);65 });6667 itSub('Should reduce allowance if value is big', async ({helper}) => {68 // fungible69 const collection = await helper.ft.mintCollection(alice, {name: 'TransferFrom-4', description: '', tokenPrefix: 'TF'});70 await collection.mint(alice, 500000n);7172 await collection.approveTokens(alice, {Substrate: bob.address}, 500000n);73 expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(500000n);74 await collection.transferFrom(bob, {Substrate: alice.address}, {Substrate: charlie.address}, 500000n);75 expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(0n);76 });7778 itSub('can be called by collection owner on non-owned item when OwnerCanTransfer == true', async ({helper}) => {79 const collection = await helper.nft.mintCollection(alice, {name: 'TransferFrom-5', description: '', tokenPrefix: 'TF'});80 await collection.setLimits(alice, {ownerCanTransfer: true});8182 const nft = await collection.mintToken(alice, {Substrate: bob.address});83 await nft.transferFrom(alice, {Substrate: bob.address}, {Substrate: charlie.address});84 expect(await nft.getOwner()).to.be.deep.equal({Substrate: charlie.address});85 });86});8788describe('Negative Integration Test transferFrom(from, recipient, collection_id, item_id, value):', () => {89 let alice: IKeyringPair;90 let bob: IKeyringPair;91 let charlie: IKeyringPair;9293 before(async () => {94 await usingPlaygrounds(async (helper, privateKey) => {95 const donor = await privateKey({url: import.meta.url});96 [alice, bob, charlie] = await helper.arrange.createAccounts([50n, 10n, 10n], donor);97 });98 });99100 itSub('transferFrom for a collection that does not exist', async ({helper}) => {101 await expect(helper.collection.approveToken(alice, NON_EXISTENT_COLLECTION_ID, 0, {Substrate: bob.address}, 1n))102 .to.be.rejectedWith(/common\.CollectionNotFound/);103 await expect(helper.collection.transferTokenFrom(bob, NON_EXISTENT_COLLECTION_ID, 0, {Substrate: alice.address}, {Substrate: bob.address}, 1n))104 .to.be.rejectedWith(/common\.CollectionNotFound/);105 });106107 /* itSub('transferFrom for a collection that was destroyed', async ({helper}) => {108 this test copies approve negative test109 }); */110111 /* itSub('transferFrom a token that does not exist', async ({helper}) => {112 this test copies approve negative test113 }); */114115 /* itSub('transferFrom a token that was deleted', async ({helper}) => {116 this test copies approve negative test117 }); */118119 itSub('[nft] transferFrom for not approved address', async ({helper}) => {120 const collection = await helper.nft.mintCollection(alice, {name: 'TransferFrom-Neg-1', description: '', tokenPrefix: 'TF'});121 const nft = await collection.mintToken(alice);122123 await expect(nft.transferFrom(bob, {Substrate: alice.address}, {Substrate: charlie.address}))124 .to.be.rejectedWith(/common\.ApprovedValueTooLow/);125 expect(await nft.getOwner()).to.be.deep.equal({Substrate: alice.address});126 });127128 itSub('[fungible] transferFrom for not approved address', async ({helper}) => {129 const collection = await helper.ft.mintCollection(alice, {name: 'TransferFrom-Neg-1', description: '', tokenPrefix: 'TF'});130 await collection.mint(alice, 10n);131132 await expect(collection.transferFrom(bob, {Substrate: alice.address}, {Substrate: charlie.address}, 5n))133 .to.be.rejectedWith(/common\.ApprovedValueTooLow/);134 expect(await collection.getBalance({Substrate: alice.address})).to.be.deep.equal(10n);135 expect(await collection.getBalance({Substrate: bob.address})).to.be.deep.equal(0n);136 expect(await collection.getBalance({Substrate: charlie.address})).to.be.deep.equal(0n);137 });138139 itSub.ifWithPallets('[refungible] transferFrom for not approved address', [Pallets.ReFungible], async({helper}) => {140 const collection = await helper.rft.mintCollection(alice, {name: 'TransferFrom-Neg-3', description: '', tokenPrefix: 'TF'});141 const rft = await collection.mintToken(alice, 10n);142143 await expect(rft.transferFrom(bob, {Substrate: alice.address}, {Substrate: charlie.address}))144 .to.be.rejectedWith(/common\.ApprovedValueTooLow/);145 expect(await rft.getBalance({Substrate: alice.address})).to.be.deep.equal(10n);146 expect(await rft.getBalance({Substrate: bob.address})).to.be.deep.equal(0n);147 expect(await rft.getBalance({Substrate: charlie.address})).to.be.deep.equal(0n);148 });149150 itSub('[nft] transferFrom incorrect token count', async ({helper}) => {151 const collection = await helper.nft.mintCollection(alice, {name: 'TransferFrom-Neg-4', description: '', tokenPrefix: 'TF'});152 const nft = await collection.mintToken(alice);153154 await nft.approve(alice, {Substrate: bob.address});155 expect(await nft.isApproved({Substrate: bob.address})).to.be.true;156157 await expect(helper.collection.transferTokenFrom(158 bob,159 collection.collectionId,160 nft.tokenId,161 {Substrate: alice.address},162 {Substrate: charlie.address},163 2n,164 )).to.be.rejectedWith(/nonfungible\.NonfungibleItemsHaveNoAmount/);165 expect(await nft.getOwner()).to.be.deep.equal({Substrate: alice.address});166 });167168 itSub('[fungible] transferFrom incorrect token count', async ({helper}) => {169 const collection = await helper.ft.mintCollection(alice, {name: 'TransferFrom-Neg-5', description: '', tokenPrefix: 'TF'});170 await collection.mint(alice, 10n);171172 await collection.approveTokens(alice, {Substrate: bob.address}, 2n);173 expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.eq(2n);174175 await expect(collection.transferFrom(bob, {Substrate: alice.address}, {Substrate: charlie.address}, 5n))176 .to.be.rejectedWith(/common\.ApprovedValueTooLow/);177 expect(await collection.getBalance({Substrate: alice.address})).to.be.deep.equal(10n);178 expect(await collection.getBalance({Substrate: bob.address})).to.be.deep.equal(0n);179 expect(await collection.getBalance({Substrate: charlie.address})).to.be.deep.equal(0n);180 });181182 itSub.ifWithPallets('[refungible] transferFrom incorrect token count', [Pallets.ReFungible], async ({helper}) => {183 const collection = await helper.rft.mintCollection(alice, {name: 'TransferFrom-Neg-6', description: '', tokenPrefix: 'TF'});184 const rft = await collection.mintToken(alice, 10n);185186 await rft.approve(alice, {Substrate: bob.address}, 5n);187 expect(await rft.getApprovedPieces({Substrate: alice.address}, {Substrate: bob.address})).to.be.eq(5n);188189 await expect(rft.transferFrom(bob, {Substrate: alice.address}, {Substrate: charlie.address}, 7n))190 .to.be.rejectedWith(/common\.ApprovedValueTooLow/);191 expect(await rft.getBalance({Substrate: alice.address})).to.be.deep.equal(10n);192 expect(await rft.getBalance({Substrate: bob.address})).to.be.deep.equal(0n);193 expect(await rft.getBalance({Substrate: charlie.address})).to.be.deep.equal(0n);194 });195196 itSub('[nft] execute transferFrom from account that is not owner of collection', async ({helper}) => {197 const collection = await helper.nft.mintCollection(alice, {name: 'TransferFrom-Neg-7', description: '', tokenPrefix: 'TF'});198 const nft = await collection.mintToken(alice);199200 await expect(nft.approve(charlie, {Substrate: bob.address})).to.be.rejectedWith(/common\.CantApproveMoreThanOwned/);201 expect(await nft.isApproved({Substrate: bob.address})).to.be.false;202203 await expect(nft.transferFrom(204 charlie,205 {Substrate: alice.address},206 {Substrate: charlie.address},207 )).to.be.rejectedWith(/common\.ApprovedValueTooLow/);208 expect(await nft.getOwner()).to.be.deep.equal({Substrate: alice.address});209 });210211 itSub('[fungible] execute transferFrom from account that is not owner of collection', async ({helper}) => {212 const collection = await helper.ft.mintCollection(alice, {name: 'TransferFrom-Neg-8', description: '', tokenPrefix: 'TF'});213 await collection.mint(alice, 10000n);214215 await expect(collection.approveTokens(charlie, {Substrate: bob.address}, 1n)).to.be.rejectedWith(/common\.CantApproveMoreThanOwned/);216 expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.eq(0n);217 expect(await collection.getApprovedTokens({Substrate: charlie.address}, {Substrate: bob.address})).to.be.eq(0n);218219 await expect(collection.transferFrom(220 charlie,221 {Substrate: alice.address},222 {Substrate: charlie.address},223 )).to.be.rejectedWith(/common\.ApprovedValueTooLow/);224 expect(await collection.getBalance({Substrate: alice.address})).to.be.deep.equal(10000n);225 expect(await collection.getBalance({Substrate: bob.address})).to.be.deep.equal(0n);226 expect(await collection.getBalance({Substrate: charlie.address})).to.be.deep.equal(0n);227 });228229 itSub.ifWithPallets('[refungible] execute transferFrom from account that is not owner of collection', [Pallets.ReFungible], async ({helper}) => {230 const collection = await helper.rft.mintCollection(alice, {name: 'TransferFrom-Neg-9', description: '', tokenPrefix: 'TF'});231 const rft = await collection.mintToken(alice, 10000n);232233 await expect(rft.approve(charlie, {Substrate: bob.address}, 1n)).to.be.rejectedWith(/common\.CantApproveMoreThanOwned/);234 expect(await rft.getApprovedPieces({Substrate: alice.address}, {Substrate: bob.address})).to.be.eq(0n);235 expect(await rft.getApprovedPieces({Substrate: charlie.address}, {Substrate: bob.address})).to.be.eq(0n);236237 await expect(rft.transferFrom(238 charlie,239 {Substrate: alice.address},240 {Substrate: charlie.address},241 )).to.be.rejectedWith(/common\.ApprovedValueTooLow/);242 expect(await rft.getBalance({Substrate: alice.address})).to.be.deep.equal(10000n);243 expect(await rft.getBalance({Substrate: bob.address})).to.be.deep.equal(0n);244 expect(await rft.getBalance({Substrate: charlie.address})).to.be.deep.equal(0n);245 });246247 itSub('transferFrom burnt token before approve NFT', async ({helper}) => {248 const collection = await helper.nft.mintCollection(alice, {name: 'TransferFrom-Neg-10', description: '', tokenPrefix: 'TF'});249 await collection.setLimits(alice, {ownerCanTransfer: true});250 const nft = await collection.mintToken(alice);251252 await nft.burn(alice);253 await expect(nft.approve(alice, {Substrate: bob.address})).to.be.rejectedWith(/common\.TokenNotFound/);254255 await expect(nft.transferFrom(256 bob,257 {Substrate: alice.address},258 {Substrate: charlie.address},259 )).to.be.rejectedWith(/common\.ApprovedValueTooLow/);260 });261262 itSub('transferFrom burnt token before approve Fungible', async ({helper}) => {263 const collection = await helper.ft.mintCollection(alice, {name: 'TransferFrom-Neg-11', description: '', tokenPrefix: 'TF'});264 await collection.setLimits(alice, {ownerCanTransfer: true});265 await collection.mint(alice, 10n);266267 await collection.burnTokens(alice, 10n);268 await expect(collection.approveTokens(alice, {Substrate: bob.address})).to.be.not.rejected;269270 await expect(collection.transferFrom(271 alice,272 {Substrate: alice.address},273 {Substrate: charlie.address},274 )).to.be.rejectedWith(/common\.TokenValueTooLow/);275 });276277 itSub.ifWithPallets('transferFrom burnt token before approve ReFungible', [Pallets.ReFungible], async ({helper}) => {278 const collection = await helper.rft.mintCollection(alice, {name: 'TransferFrom-Neg-12', description: '', tokenPrefix: 'TF'});279 await collection.setLimits(alice, {ownerCanTransfer: true});280 const rft = await collection.mintToken(alice, 10n);281282 await rft.burn(alice, 10n);283 await expect(rft.approve(alice, {Substrate: bob.address})).to.be.rejectedWith(/common\.CantApproveMoreThanOwned/);284285 await expect(rft.transferFrom(286 alice,287 {Substrate: alice.address},288 {Substrate: charlie.address},289 )).to.be.rejectedWith(/common\.TokenValueTooLow/);290 });291292 itSub('transferFrom burnt token after approve NFT', async ({helper}) => {293 const collection = await helper.nft.mintCollection(alice, {name: 'TransferFrom-Neg-13', description: '', tokenPrefix: 'TF'});294 const nft = await collection.mintToken(alice);295296 await nft.approve(alice, {Substrate: bob.address});297 expect(await nft.isApproved({Substrate: bob.address})).to.be.true;298299 await nft.burn(alice);300301 await expect(nft.transferFrom(302 bob,303 {Substrate: alice.address},304 {Substrate: charlie.address},305 )).to.be.rejectedWith(/common\.ApprovedValueTooLow/);306 });307308 itSub('transferFrom burnt token after approve Fungible', async ({helper}) => {309 const collection = await helper.ft.mintCollection(alice, {name: 'TransferFrom-Neg-14', description: '', tokenPrefix: 'TF'});310 await collection.mint(alice, 10n);311312 await collection.approveTokens(alice, {Substrate: bob.address});313 expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.eq(1n);314315 await collection.burnTokens(alice, 10n);316317 await expect(collection.transferFrom(318 bob,319 {Substrate: alice.address},320 {Substrate: charlie.address},321 )).to.be.rejectedWith(/common\.TokenValueTooLow/);322 });323324 itSub.ifWithPallets('transferFrom burnt token after approve ReFungible', [Pallets.ReFungible], async ({helper}) => {325 const collection = await helper.rft.mintCollection(alice, {name: 'TransferFrom-Neg-15', description: '', tokenPrefix: 'TF'});326 const rft = await collection.mintToken(alice, 10n);327328 await rft.approve(alice, {Substrate: bob.address}, 10n);329 expect(await rft.getApprovedPieces({Substrate: alice.address}, {Substrate: bob.address})).to.be.eq(10n);330331 await rft.burn(alice, 10n);332333 await expect(rft.transferFrom(334 bob,335 {Substrate: alice.address},336 {Substrate: charlie.address},337 )).to.be.rejectedWith(/common\.ApprovedValueTooLow/);338 });339340 itSub('fails when called by collection owner on non-owned item when OwnerCanTransfer == false', async ({helper}) => {341 const collection = await helper.nft.mintCollection(alice, {name: 'TransferFrom-Neg-16', description: '', tokenPrefix: 'TF'});342 const nft = await collection.mintToken(alice, {Substrate: bob.address});343344 await collection.setLimits(alice, {ownerCanTransfer: false});345346 await expect(nft.transferFrom(347 alice,348 {Substrate: bob.address},349 {Substrate: charlie.address},350 )).to.be.rejectedWith(/common\.ApprovedValueTooLow/);351 });352353 itSub('zero transfer NFT', async ({helper}) => {354 const collection = await helper.nft.mintCollection(alice, {name: 'Zero', description: 'Zero transfer', tokenPrefix: 'TF'});355 const notApprovedNft = await collection.mintToken(alice, {Substrate: bob.address});356 const approvedNft = await collection.mintToken(alice, {Substrate: bob.address});357 await approvedNft.approve(bob, {Substrate: alice.address});358359 // 1. Cannot zero transferFrom (non-existing token)360 await expect(helper.executeExtrinsic(alice, 'api.tx.unique.transferFrom', [{Substrate: bob.address}, {Substrate: alice.address}, collection.collectionId, 9999, 0])).to.be.rejectedWith('common.ApprovedValueTooLow');361 // 2. Cannot zero transferFrom (not approved token)362 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');363 // 3. Can zero transferFrom (approved token):364 await helper.executeExtrinsic(alice, 'api.tx.unique.transferFrom', [{Substrate: bob.address}, {Substrate: alice.address}, collection.collectionId, approvedNft.tokenId, 0]);365366 // 4.1 approvedNft still approved:367 expect(await approvedNft.isApproved({Substrate: alice.address})).to.be.true;368 // 4.2 bob is still the owner:369 expect(await approvedNft.getOwner()).to.deep.eq({Substrate: bob.address});370 expect(await notApprovedNft.getOwner()).to.deep.eq({Substrate: bob.address});371 // 4.3 Alice can transfer approved nft:372 await approvedNft.transferFrom(alice, {Substrate: bob.address}, {Substrate: alice.address});373 expect(await approvedNft.getOwner()).to.deep.eq({Substrate: alice.address});374 });375});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 {IKeyringPair} from '@polkadot/types/types';18import {itSub, Pallets, usingPlaygrounds, expect} from './util';19import {NON_EXISTENT_COLLECTION_ID} from './util/playgrounds/types';2021describe('Integration Test transferFrom(from, recipient, collection_id, item_id, value):', () => {22 let alice: IKeyringPair;23 let bob: IKeyringPair;24 let charlie: IKeyringPair;2526 before(async () => {27 await usingPlaygrounds(async (helper, privateKey) => {28 const donor = await privateKey({url: import.meta.url});29 [alice, bob, charlie] = await helper.arrange.createAccounts([20n, 10n, 10n], donor);30 });31 });3233 itSub('[nft] Execute the extrinsic and check nftItemList - owner of token', async ({helper}) => {34 const collection = await helper.nft.mintCollection(alice, {name: 'TransferFrom-1', description: '', tokenPrefix: 'TF'});35 const nft = await collection.mintToken(alice);36 await nft.approve(alice, {Substrate: bob.address});37 expect(await nft.isApproved({Substrate: bob.address})).to.be.true;3839 await nft.transferFrom(bob, {Substrate: alice.address}, {Substrate: charlie.address});40 expect(await nft.getOwner()).to.be.deep.equal({Substrate: charlie.address});41 });4243 itSub('[fungible] Execute the extrinsic and check nftItemList - owner of token', async ({helper}) => {44 const collection = await helper.ft.mintCollection(alice, {name: 'TransferFrom-2', description: '', tokenPrefix: 'TF'});45 await collection.mint(alice, 10n);46 await collection.approveTokens(alice, {Substrate: bob.address}, 7n);47 expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(7n);4849 await collection.transferFrom(bob, {Substrate: alice.address}, {Substrate: charlie.address}, 6n);50 expect(await collection.getBalance({Substrate: charlie.address})).to.be.equal(6n);51 expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(4n);52 expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(1n);53 });5455 itSub.ifWithPallets('[refungible] Execute the extrinsic and check nftItemList - owner of token', [Pallets.ReFungible], async ({helper}) => {56 const collection = await helper.rft.mintCollection(alice, {name: 'TransferFrom-3', description: '', tokenPrefix: 'TF'});57 const rft = await collection.mintToken(alice, 10n);58 await rft.approve(alice, {Substrate: bob.address}, 7n);59 expect(await rft.getApprovedPieces({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(7n);6061 await rft.transferFrom(bob, {Substrate: alice.address}, {Substrate: charlie.address}, 6n);62 expect(await rft.getBalance({Substrate: charlie.address})).to.be.equal(6n);63 expect(await rft.getBalance({Substrate: alice.address})).to.be.equal(4n);64 expect(await rft.getApprovedPieces({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(1n);65 });6667 itSub('Should reduce allowance if value is big', async ({helper}) => {68 // fungible69 const collection = await helper.ft.mintCollection(alice, {name: 'TransferFrom-4', description: '', tokenPrefix: 'TF'});70 await collection.mint(alice, 500000n);7172 await collection.approveTokens(alice, {Substrate: bob.address}, 500000n);73 expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(500000n);74 await collection.transferFrom(bob, {Substrate: alice.address}, {Substrate: charlie.address}, 500000n);75 expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(0n);76 });7778 itSub('can be called by collection owner on non-owned item when OwnerCanTransfer == true', async ({helper}) => {79 const collection = await helper.nft.mintCollection(alice, {name: 'TransferFrom-5', description: '', tokenPrefix: 'TF'});80 await collection.setLimits(alice, {ownerCanTransfer: true});8182 const nft = await collection.mintToken(alice, {Substrate: bob.address});83 await nft.transferFrom(alice, {Substrate: bob.address}, {Substrate: charlie.address});84 expect(await nft.getOwner()).to.be.deep.equal({Substrate: charlie.address});85 });86});8788describe('Negative Integration Test transferFrom(from, recipient, collection_id, item_id, value):', () => {89 let alice: IKeyringPair;90 let bob: IKeyringPair;91 let charlie: IKeyringPair;9293 before(async () => {94 await usingPlaygrounds(async (helper, privateKey) => {95 const donor = await privateKey({url: import.meta.url});96 [alice, bob, charlie] = await helper.arrange.createAccounts([50n, 10n, 10n], donor);97 });98 });99100 itSub('transferFrom for a collection that does not exist', async ({helper}) => {101 await expect(helper.collection.approveToken(alice, NON_EXISTENT_COLLECTION_ID, 0, {Substrate: bob.address}, 1n))102 .to.be.rejectedWith(/common\.CollectionNotFound/);103 await expect(helper.collection.transferTokenFrom(bob, NON_EXISTENT_COLLECTION_ID, 0, {Substrate: alice.address}, {Substrate: bob.address}, 1n))104 .to.be.rejectedWith(/common\.CollectionNotFound/);105 });106107 /* itSub('transferFrom for a collection that was destroyed', async ({helper}) => {108 this test copies approve negative test109 }); */110111 /* itSub('transferFrom a token that does not exist', async ({helper}) => {112 this test copies approve negative test113 }); */114115 /* itSub('transferFrom a token that was deleted', async ({helper}) => {116 this test copies approve negative test117 }); */118119 itSub('[nft] transferFrom for not approved address', async ({helper}) => {120 const collection = await helper.nft.mintCollection(alice, {name: 'TransferFrom-Neg-1', description: '', tokenPrefix: 'TF'});121 const nft = await collection.mintToken(alice);122123 await expect(nft.transferFrom(bob, {Substrate: alice.address}, {Substrate: charlie.address}))124 .to.be.rejectedWith(/common\.ApprovedValueTooLow/);125 expect(await nft.getOwner()).to.be.deep.equal({Substrate: alice.address});126 });127128 itSub('[fungible] transferFrom for not approved address', async ({helper}) => {129 const collection = await helper.ft.mintCollection(alice, {name: 'TransferFrom-Neg-1', description: '', tokenPrefix: 'TF'});130 await collection.mint(alice, 10n);131132 await expect(collection.transferFrom(bob, {Substrate: alice.address}, {Substrate: charlie.address}, 5n))133 .to.be.rejectedWith(/common\.ApprovedValueTooLow/);134 expect(await collection.getBalance({Substrate: alice.address})).to.be.deep.equal(10n);135 expect(await collection.getBalance({Substrate: bob.address})).to.be.deep.equal(0n);136 expect(await collection.getBalance({Substrate: charlie.address})).to.be.deep.equal(0n);137 });138139 itSub.ifWithPallets('[refungible] transferFrom for not approved address', [Pallets.ReFungible], async({helper}) => {140 const collection = await helper.rft.mintCollection(alice, {name: 'TransferFrom-Neg-3', description: '', tokenPrefix: 'TF'});141 const rft = await collection.mintToken(alice, 10n);142143 await expect(rft.transferFrom(bob, {Substrate: alice.address}, {Substrate: charlie.address}))144 .to.be.rejectedWith(/common\.ApprovedValueTooLow/);145 expect(await rft.getBalance({Substrate: alice.address})).to.be.deep.equal(10n);146 expect(await rft.getBalance({Substrate: bob.address})).to.be.deep.equal(0n);147 expect(await rft.getBalance({Substrate: charlie.address})).to.be.deep.equal(0n);148 });149150 itSub('[nft] transferFrom incorrect token count', async ({helper}) => {151 const collection = await helper.nft.mintCollection(alice, {name: 'TransferFrom-Neg-4', description: '', tokenPrefix: 'TF'});152 const nft = await collection.mintToken(alice);153154 await nft.approve(alice, {Substrate: bob.address});155 expect(await nft.isApproved({Substrate: bob.address})).to.be.true;156157 await expect(helper.collection.transferTokenFrom(158 bob,159 collection.collectionId,160 nft.tokenId,161 {Substrate: alice.address},162 {Substrate: charlie.address},163 2n,164 )).to.be.rejectedWith(/nonfungible\.NonfungibleItemsHaveNoAmount/);165 expect(await nft.getOwner()).to.be.deep.equal({Substrate: alice.address});166 });167168 itSub('[fungible] transferFrom incorrect token count', async ({helper}) => {169 const collection = await helper.ft.mintCollection(alice, {name: 'TransferFrom-Neg-5', description: '', tokenPrefix: 'TF'});170 await collection.mint(alice, 10n);171172 await collection.approveTokens(alice, {Substrate: bob.address}, 2n);173 expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.eq(2n);174175 await expect(collection.transferFrom(bob, {Substrate: alice.address}, {Substrate: charlie.address}, 5n))176 .to.be.rejectedWith(/common\.ApprovedValueTooLow/);177 expect(await collection.getBalance({Substrate: alice.address})).to.be.deep.equal(10n);178 expect(await collection.getBalance({Substrate: bob.address})).to.be.deep.equal(0n);179 expect(await collection.getBalance({Substrate: charlie.address})).to.be.deep.equal(0n);180 });181182 itSub.ifWithPallets('[refungible] transferFrom incorrect token count', [Pallets.ReFungible], async ({helper}) => {183 const collection = await helper.rft.mintCollection(alice, {name: 'TransferFrom-Neg-6', description: '', tokenPrefix: 'TF'});184 const rft = await collection.mintToken(alice, 10n);185186 await rft.approve(alice, {Substrate: bob.address}, 5n);187 expect(await rft.getApprovedPieces({Substrate: alice.address}, {Substrate: bob.address})).to.be.eq(5n);188189 await expect(rft.transferFrom(bob, {Substrate: alice.address}, {Substrate: charlie.address}, 7n))190 .to.be.rejectedWith(/common\.ApprovedValueTooLow/);191 expect(await rft.getBalance({Substrate: alice.address})).to.be.deep.equal(10n);192 expect(await rft.getBalance({Substrate: bob.address})).to.be.deep.equal(0n);193 expect(await rft.getBalance({Substrate: charlie.address})).to.be.deep.equal(0n);194 });195196 itSub('[nft] execute transferFrom from account that is not owner of collection', async ({helper}) => {197 const collection = await helper.nft.mintCollection(alice, {name: 'TransferFrom-Neg-7', description: '', tokenPrefix: 'TF'});198 const nft = await collection.mintToken(alice);199200 await expect(nft.approve(charlie, {Substrate: bob.address})).to.be.rejectedWith(/common\.CantApproveMoreThanOwned/);201 expect(await nft.isApproved({Substrate: bob.address})).to.be.false;202203 await expect(nft.transferFrom(204 charlie,205 {Substrate: alice.address},206 {Substrate: charlie.address},207 )).to.be.rejectedWith(/common\.ApprovedValueTooLow/);208 expect(await nft.getOwner()).to.be.deep.equal({Substrate: alice.address});209 });210211 itSub('[fungible] execute transferFrom from account that is not owner of collection', async ({helper}) => {212 const collection = await helper.ft.mintCollection(alice, {name: 'TransferFrom-Neg-8', description: '', tokenPrefix: 'TF'});213 await collection.mint(alice, 10000n);214215 await expect(collection.approveTokens(charlie, {Substrate: bob.address}, 1n)).to.be.rejectedWith(/common\.CantApproveMoreThanOwned/);216 expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.eq(0n);217 expect(await collection.getApprovedTokens({Substrate: charlie.address}, {Substrate: bob.address})).to.be.eq(0n);218219 await expect(collection.transferFrom(220 charlie,221 {Substrate: alice.address},222 {Substrate: charlie.address},223 )).to.be.rejectedWith(/common\.ApprovedValueTooLow/);224 expect(await collection.getBalance({Substrate: alice.address})).to.be.deep.equal(10000n);225 expect(await collection.getBalance({Substrate: bob.address})).to.be.deep.equal(0n);226 expect(await collection.getBalance({Substrate: charlie.address})).to.be.deep.equal(0n);227 });228229 itSub.ifWithPallets('[refungible] execute transferFrom from account that is not owner of collection', [Pallets.ReFungible], async ({helper}) => {230 const collection = await helper.rft.mintCollection(alice, {name: 'TransferFrom-Neg-9', description: '', tokenPrefix: 'TF'});231 const rft = await collection.mintToken(alice, 10000n);232233 await expect(rft.approve(charlie, {Substrate: bob.address}, 1n)).to.be.rejectedWith(/common\.CantApproveMoreThanOwned/);234 expect(await rft.getApprovedPieces({Substrate: alice.address}, {Substrate: bob.address})).to.be.eq(0n);235 expect(await rft.getApprovedPieces({Substrate: charlie.address}, {Substrate: bob.address})).to.be.eq(0n);236237 await expect(rft.transferFrom(238 charlie,239 {Substrate: alice.address},240 {Substrate: charlie.address},241 )).to.be.rejectedWith(/common\.ApprovedValueTooLow/);242 expect(await rft.getBalance({Substrate: alice.address})).to.be.deep.equal(10000n);243 expect(await rft.getBalance({Substrate: bob.address})).to.be.deep.equal(0n);244 expect(await rft.getBalance({Substrate: charlie.address})).to.be.deep.equal(0n);245 });246247 itSub('transferFrom burnt token before approve NFT', async ({helper}) => {248 const collection = await helper.nft.mintCollection(alice, {name: 'TransferFrom-Neg-10', description: '', tokenPrefix: 'TF'});249 await collection.setLimits(alice, {ownerCanTransfer: true});250 const nft = await collection.mintToken(alice);251252 await nft.burn(alice);253 await expect(nft.approve(alice, {Substrate: bob.address})).to.be.rejectedWith(/common\.TokenNotFound/);254255 await expect(nft.transferFrom(256 bob,257 {Substrate: alice.address},258 {Substrate: charlie.address},259 )).to.be.rejectedWith(/common\.ApprovedValueTooLow/);260 });261262 itSub('transferFrom burnt token before approve Fungible', async ({helper}) => {263 const collection = await helper.ft.mintCollection(alice, {name: 'TransferFrom-Neg-11', description: '', tokenPrefix: 'TF'});264 await collection.setLimits(alice, {ownerCanTransfer: true});265 await collection.mint(alice, 10n);266267 await collection.burnTokens(alice, 10n);268 await expect(collection.approveTokens(alice, {Substrate: bob.address})).to.be.not.rejected;269270 await expect(collection.transferFrom(271 alice,272 {Substrate: alice.address},273 {Substrate: charlie.address},274 )).to.be.rejectedWith(/common\.TokenValueTooLow/);275 });276277 itSub.ifWithPallets('transferFrom burnt token before approve ReFungible', [Pallets.ReFungible], async ({helper}) => {278 const collection = await helper.rft.mintCollection(alice, {name: 'TransferFrom-Neg-12', description: '', tokenPrefix: 'TF'});279 await collection.setLimits(alice, {ownerCanTransfer: true});280 const rft = await collection.mintToken(alice, 10n);281282 await rft.burn(alice, 10n);283 await expect(rft.approve(alice, {Substrate: bob.address})).to.be.rejectedWith(/common\.CantApproveMoreThanOwned/);284285 await expect(rft.transferFrom(286 alice,287 {Substrate: alice.address},288 {Substrate: charlie.address},289 )).to.be.rejectedWith(/common\.TokenValueTooLow/);290 });291292 itSub('transferFrom burnt token after approve NFT', async ({helper}) => {293 const collection = await helper.nft.mintCollection(alice, {name: 'TransferFrom-Neg-13', description: '', tokenPrefix: 'TF'});294 const nft = await collection.mintToken(alice);295296 await nft.approve(alice, {Substrate: bob.address});297 expect(await nft.isApproved({Substrate: bob.address})).to.be.true;298299 await nft.burn(alice);300301 await expect(nft.transferFrom(302 bob,303 {Substrate: alice.address},304 {Substrate: charlie.address},305 )).to.be.rejectedWith(/common\.ApprovedValueTooLow/);306 });307308 itSub('transferFrom burnt token after approve Fungible', async ({helper}) => {309 const collection = await helper.ft.mintCollection(alice, {name: 'TransferFrom-Neg-14', description: '', tokenPrefix: 'TF'});310 await collection.mint(alice, 10n);311312 await collection.approveTokens(alice, {Substrate: bob.address});313 expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.eq(1n);314315 await collection.burnTokens(alice, 10n);316317 await expect(collection.transferFrom(318 bob,319 {Substrate: alice.address},320 {Substrate: charlie.address},321 )).to.be.rejectedWith(/common\.TokenValueTooLow/);322 });323324 itSub.ifWithPallets('transferFrom burnt token after approve ReFungible', [Pallets.ReFungible], async ({helper}) => {325 const collection = await helper.rft.mintCollection(alice, {name: 'TransferFrom-Neg-15', description: '', tokenPrefix: 'TF'});326 const rft = await collection.mintToken(alice, 10n);327328 await rft.approve(alice, {Substrate: bob.address}, 10n);329 expect(await rft.getApprovedPieces({Substrate: alice.address}, {Substrate: bob.address})).to.be.eq(10n);330331 await rft.burn(alice, 10n);332333 await expect(rft.transferFrom(334 bob,335 {Substrate: alice.address},336 {Substrate: charlie.address},337 )).to.be.rejectedWith(/common\.ApprovedValueTooLow/);338 });339340 itSub('fails when called by collection owner on non-owned item when OwnerCanTransfer == false', async ({helper}) => {341 const collection = await helper.nft.mintCollection(alice, {name: 'TransferFrom-Neg-16', description: '', tokenPrefix: 'TF'});342 const nft = await collection.mintToken(alice, {Substrate: bob.address});343344 await collection.setLimits(alice, {ownerCanTransfer: false});345346 await expect(nft.transferFrom(347 alice,348 {Substrate: bob.address},349 {Substrate: charlie.address},350 )).to.be.rejectedWith(/common\.ApprovedValueTooLow/);351 });352353 itSub('zero transfer NFT', async ({helper}) => {354 const collection = await helper.nft.mintCollection(alice, {name: 'Zero', description: 'Zero transfer', tokenPrefix: 'TF'});355 const notApprovedNft = await collection.mintToken(alice, {Substrate: bob.address});356 const approvedNft = await collection.mintToken(alice, {Substrate: bob.address});357 await approvedNft.approve(bob, {Substrate: alice.address});358359 // 1. Cannot zero transferFrom (non-existing token)360 await expect(helper.executeExtrinsic(alice, 'api.tx.unique.transferFrom', [{Substrate: bob.address}, {Substrate: alice.address}, collection.collectionId, 9999, 0])).to.be.rejectedWith('common.ApprovedValueTooLow');361 // 2. Cannot zero transferFrom (not approved token)362 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');363 // 3. Can zero transferFrom (approved token):364 await helper.executeExtrinsic(alice, 'api.tx.unique.transferFrom', [{Substrate: bob.address}, {Substrate: alice.address}, collection.collectionId, approvedNft.tokenId, 0]);365366 // 4.1 approvedNft still approved:367 expect(await approvedNft.isApproved({Substrate: alice.address})).to.be.true;368 // 4.2 bob is still the owner:369 expect(await approvedNft.getOwner()).to.deep.eq({Substrate: bob.address});370 expect(await notApprovedNft.getOwner()).to.deep.eq({Substrate: bob.address});371 // 4.3 Alice can transfer approved nft:372 await approvedNft.transferFrom(alice, {Substrate: bob.address}, {Substrate: alice.address});373 expect(await approvedNft.getOwner()).to.deep.eq({Substrate: alice.address});374 });375});tests/src/util/playgrounds/types.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/types.ts
+++ b/tests/src/util/playgrounds/types.ts
@@ -3,6 +3,8 @@
import {IKeyringPair} from '@polkadot/types/types';
+export const NON_EXISTENT_COLLECTION_ID = 4_294_967_295;
+
export interface IEvent {
section: string;
method: string;