difftreelog
Merge pull request #818 from UniqueNetwork/feature/approve-from-eth-mirror
in: master
26 files changed
pallets/common/src/lib.rsdiffbeforeafterboth746 ApprovedValueTooLow,746 ApprovedValueTooLow,747 /// Tried to approve more than owned747 /// Tried to approve more than owned748 CantApproveMoreThanOwned,748 CantApproveMoreThanOwned,749 /// Only spending from eth mirror could be approved750 AddressIsNotEthMirror,749751750 /// Can't transfer tokens to ethereum zero address752 /// Can't transfer tokens to ethereum zero address751 AddressIsZero,753 AddressIsZero,1797 /// The price of setting the permission of the operation from another user.1799 /// The price of setting the permission of the operation from another user.1798 fn approve() -> Weight;1800 fn approve() -> Weight;18011802 /// The price of setting the permission of the operation from another user for eth mirror.1803 fn approve_from() -> Weight;179918041800 /// Transfer price from another user.1805 /// Transfer price from another user.1801 fn transfer_from() -> Weight;1806 fn transfer_from() -> Weight;2008 amount: u128,2013 amount: u128,2009 ) -> DispatchResultWithPostInfo;2014 ) -> DispatchResultWithPostInfo;20152016 /// Grant access to another account to transfer parts of the token owned by the calling user's eth mirror via [Self::transfer_from].2017 ///2018 /// * `sender` - The user who grants access to the token.2019 /// * `from` - Spender's eth mirror.2020 /// * `to` - The user to whom the rights are granted.2021 /// * `token` - The token to which access is granted.2022 /// * `amount` - The amount of pieces that another user can dispose of.2023 fn approve_from(2024 &self,2025 sender: T::CrossAccountId,2026 from: T::CrossAccountId,2027 to: T::CrossAccountId,2028 token: TokenId,2029 amount: u128,2030 ) -> DispatchResultWithPostInfo;201020312011 /// Send parts of a token owned by another user.2032 /// Send parts of a token owned by another user.2012 ///2033 ///pallets/evm-contract-helpers/src/stubs/ContractHelpers.rawdiffbeforeafterbothbinary blob — no preview
pallets/evm-contract-helpers/src/stubs/ContractHelpers.soldiffbeforeafterboth283283284/// Ethereum representation of Optional value with CrossAddress.284/// Ethereum representation of Optional value with CrossAddress.285struct OptionCrossAddress {285struct OptionCrossAddress {286 /// TODO: field description286 /// Whether or not this CrossAdress is valid and has meaning.287 bool status;287 bool status;288 /// TODO: field description288 /// The underlying CrossAddress value. If the status is false, can be set to whatever.289 CrossAddress value;289 CrossAddress value;290}290}291291pallets/fungible/src/benchmarking.rsdiffbeforeafterboth82 <Pallet<T>>::create_item(&collection, &owner, (sender.clone(), 200), &Unlimited)?;82 <Pallet<T>>::create_item(&collection, &owner, (sender.clone(), 200), &Unlimited)?;83 }: {<Pallet<T>>::set_allowance(&collection, &sender, &spender, 100)?}83 }: {<Pallet<T>>::set_allowance(&collection, &sender, &spender, 100)?}8485 approve_from {86 bench_init!{87 owner: sub; collection: collection(owner);88 owner: cross_from_sub; sender: cross_sub; spender: cross_sub;8990 };91 let owner_eth = T::CrossAccountId::from_eth(*sender.as_eth());92 <Pallet<T>>::create_item(&collection, &owner, (owner_eth.clone(), 200), &Unlimited)?;93 }: {<Pallet<T>>::set_allowance_from(&collection, &sender, &owner_eth, &spender, 100)?}849485 transfer_from {95 transfer_from {86 bench_init!{96 bench_init!{pallets/fungible/src/common.rsdiffbeforeafterboth87 <SelfWeightOf<T>>::approve()87 <SelfWeightOf<T>>::approve()88 }88 }8990 fn approve_from() -> Weight {91 <SelfWeightOf<T>>::approve_from()92 }899390 fn transfer_from() -> Weight {94 fn transfer_from() -> Weight {91 <SelfWeightOf<T>>::transfer_from()95 <SelfWeightOf<T>>::transfer_from()254 )258 )255 }259 }260261 fn approve_from(262 &self,263 sender: T::CrossAccountId,264 from: T::CrossAccountId,265 to: T::CrossAccountId,266 token: TokenId,267 amount: u128,268 ) -> DispatchResultWithPostInfo {269 ensure!(270 token == TokenId::default(),271 <Error<T>>::FungibleItemsHaveNoId272 );273274 with_weight(275 <Pallet<T>>::set_allowance_from(self, &sender, &from, &to, amount),276 <CommonWeights<T>>::approve_from(),277 )278 }256279257 fn transfer_from(280 fn transfer_from(258 &self,281 &self,pallets/fungible/src/lib.rsdiffbeforeafterboth613 Ok(())613 Ok(())614 }614 }615616 /// Set allowance for the spender to `transfer` or `burn` owner's tokens from eth mirror.617 ///618 /// - `collection`: Collection that contains the token619 /// - `sender`: Owner of tokens that sets the allowance.620 /// - `from`: Owner's eth mirror.621 /// - `to`: Recipient of the allowance rights.622 /// - `amount`: Amount of tokens the spender is allowed to `transfer` or `burn`.623 pub fn set_allowance_from(624 collection: &FungibleHandle<T>,625 sender: &T::CrossAccountId,626 from: &T::CrossAccountId,627 to: &T::CrossAccountId,628 amount: u128,629 ) -> DispatchResult {630 if collection.permissions.access() == AccessMode::AllowList {631 collection.check_allowlist(sender)?;632 collection.check_allowlist(from)?;633 collection.check_allowlist(to)?;634 }635636 ensure!(637 sender.conv_eq(from),638 <CommonError<T>>::AddressIsNotEthMirror639 );640641 if <Balance<T>>::get((collection.id, from)) < amount {642 ensure!(643 collection.limits.owner_can_transfer()644 && (collection.is_owner_or_admin(sender) || collection.is_owner_or_admin(from)),645 <CommonError<T>>::CantApproveMoreThanOwned646 );647 }648649 // =========650651 Self::set_allowance_unchecked(collection, from, to, amount);652 Ok(())653 }615654616 /// Checks if a non-owner has (enough) allowance from the owner to perform operations on the tokens.655 /// Checks if a non-owner has (enough) allowance from the owner to perform operations on the tokens.617 /// Returns the expected remaining allowance - it should be set manually if the transaction proceeds.656 /// Returns the expected remaining allowance - it should be set manually if the transaction proceeds.pallets/fungible/src/weights.rsdiffbeforeafterboth39 fn burn_item() -> Weight;39 fn burn_item() -> Weight;40 fn transfer() -> Weight;40 fn transfer() -> Weight;41 fn approve() -> Weight;41 fn approve() -> Weight;42 fn approve_from() -> Weight;42 fn transfer_from() -> Weight;43 fn transfer_from() -> Weight;43 fn burn_from() -> Weight;44 fn burn_from() -> Weight;44}45}84 .saturating_add(T::DbWeight::get().reads(1 as u64))85 .saturating_add(T::DbWeight::get().reads(1 as u64))85 .saturating_add(T::DbWeight::get().writes(1 as u64))86 .saturating_add(T::DbWeight::get().writes(1 as u64))86 }87 }88 // Storage: Fungible Balance (r:1 w:0)89 // Storage: Fungible Allowance (r:0 w:1)90 fn approve_from() -> Weight {91 Weight::from_ref_time(19_817_000 as u64)92 .saturating_add(T::DbWeight::get().reads(1 as u64))93 .saturating_add(T::DbWeight::get().writes(1 as u64))94 }87 // Storage: Fungible Allowance (r:1 w:1)95 // Storage: Fungible Allowance (r:1 w:1)88 // Storage: Fungible Balance (r:2 w:2)96 // Storage: Fungible Balance (r:2 w:2)89 fn transfer_from() -> Weight {97 fn transfer_from() -> Weight {141 .saturating_add(RocksDbWeight::get().reads(1 as u64))149 .saturating_add(RocksDbWeight::get().reads(1 as u64))142 .saturating_add(RocksDbWeight::get().writes(1 as u64))150 .saturating_add(RocksDbWeight::get().writes(1 as u64))143 }151 }152 // Storage: Fungible Balance (r:1 w:0)153 // Storage: Fungible Allowance (r:0 w:1)154 fn approve_from() -> Weight {155 Weight::from_ref_time(19_817_000 as u64)156 .saturating_add(RocksDbWeight::get().reads(1 as u64))157 .saturating_add(RocksDbWeight::get().writes(1 as u64))158 }144 // Storage: Fungible Allowance (r:1 w:1)159 // Storage: Fungible Allowance (r:1 w:1)145 // Storage: Fungible Balance (r:2 w:2)160 // Storage: Fungible Balance (r:2 w:2)146 fn transfer_from() -> Weight {161 fn transfer_from() -> Weight {pallets/nonfungible/src/benchmarking.rsdiffbeforeafterboth134 let item = create_max_item(&collection, &owner, sender.clone())?;134 let item = create_max_item(&collection, &owner, sender.clone())?;135 }: {<Pallet<T>>::set_allowance(&collection, &sender, item, Some(&spender))?}135 }: {<Pallet<T>>::set_allowance(&collection, &sender, item, Some(&spender))?}136137 approve_from {138 bench_init!{139 owner: sub; collection: collection(owner);140 owner: cross_from_sub; sender: cross_sub; spender: cross_sub;141 };142 let owner_eth = T::CrossAccountId::from_eth(*sender.as_eth());143 let item = create_max_item(&collection, &owner, owner_eth.clone())?;144 }: {<Pallet<T>>::set_allowance_from(&collection, &sender, &owner_eth, item, Some(&spender))?}136145137 transfer_from {146 transfer_from {138 bench_init!{147 bench_init!{pallets/nonfungible/src/common.rsdiffbeforeafterboth102 <SelfWeightOf<T>>::approve()102 <SelfWeightOf<T>>::approve()103 }103 }104105 fn approve_from() -> Weight {106 <SelfWeightOf<T>>::approve_from()107 }104108105 fn transfer_from() -> Weight {109 fn transfer_from() -> Weight {106 <SelfWeightOf<T>>::transfer_from()110 <SelfWeightOf<T>>::transfer_from()353 )357 )354 }358 }359360 fn approve_from(361 &self,362 sender: T::CrossAccountId,363 from: T::CrossAccountId,364 to: T::CrossAccountId,365 token: TokenId,366 amount: u128,367 ) -> DispatchResultWithPostInfo {368 ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);369370 with_weight(371 if amount == 1 {372 <Pallet<T>>::set_allowance_from(self, &sender, &from, token, Some(&to))373 } else {374 <Pallet<T>>::set_allowance_from(self, &sender, &from, token, None)375 },376 <CommonWeights<T>>::approve_from(),377 )378 }355379356 fn transfer_from(380 fn transfer_from(357 &self,381 &self,pallets/nonfungible/src/lib.rsdiffbeforeafterboth1171 Ok(())1171 Ok(())1172 }1172 }11731174 /// Set allowance for the spender to `transfer` or `burn` sender's token from eth mirror.1175 ///1176 /// - `from`: Address of sender's eth mirror.1177 /// - `to`: Adress of spender.1178 /// - `token`: Token the spender is allowed to `transfer` or `burn`.1179 pub fn set_allowance_from(1180 collection: &NonfungibleHandle<T>,1181 sender: &T::CrossAccountId,1182 from: &T::CrossAccountId,1183 token: TokenId,1184 to: Option<&T::CrossAccountId>,1185 ) -> DispatchResult {1186 if collection.permissions.access() == AccessMode::AllowList {1187 collection.check_allowlist(sender)?;1188 collection.check_allowlist(from)?;1189 if let Some(to) = to {1190 collection.check_allowlist(to)?;1191 }1192 }11931194 if let Some(to) = to {1195 <PalletCommon<T>>::ensure_correct_receiver(to)?;1196 }11971198 ensure!(1199 sender.conv_eq(from),1200 <CommonError<T>>::AddressIsNotEthMirror1201 );12021203 let token_data =1204 <TokenData<T>>::get((collection.id, token)).ok_or(<CommonError<T>>::TokenNotFound)?;1205 if token_data.owner != *from {1206 ensure!(1207 collection.limits.owner_can_transfer()1208 && (collection.is_owner_or_admin(sender) || collection.is_owner_or_admin(from)),1209 <CommonError<T>>::CantApproveMoreThanOwned1210 );1211 }12121213 // =========12141215 Self::set_allowance_unchecked(collection, from, token, to, false);1216 Ok(())1217 }117312181174 /// Checks allowance for the spender to use the token.1219 /// Checks allowance for the spender to use the token.1175 fn check_allowed(1220 fn check_allowed(pallets/nonfungible/src/weights.rsdiffbeforeafterboth42 fn burn_recursively_breadth_plus_self_plus_self_per_each_raw(b: u32, ) -> Weight;42 fn burn_recursively_breadth_plus_self_plus_self_per_each_raw(b: u32, ) -> Weight;43 fn transfer() -> Weight;43 fn transfer() -> Weight;44 fn approve() -> Weight;44 fn approve() -> Weight;45 fn approve_from() -> Weight;45 fn transfer_from() -> Weight;46 fn transfer_from() -> Weight;46 fn burn_from() -> Weight;47 fn burn_from() -> Weight;47 fn set_token_property_permissions(b: u32, ) -> Weight;48 fn set_token_property_permissions(b: u32, ) -> Weight;147 .saturating_add(T::DbWeight::get().reads(2 as u64))148 .saturating_add(T::DbWeight::get().reads(2 as u64))148 .saturating_add(T::DbWeight::get().writes(1 as u64))149 .saturating_add(T::DbWeight::get().writes(1 as u64))149 }150 }151 // Storage: Nonfungible TokenData (r:1 w:0)152 // Storage: Nonfungible Allowance (r:1 w:1)153 fn approve_from() -> Weight {154 Weight::from_ref_time(18_965_000 as u64)155 .saturating_add(T::DbWeight::get().reads(2 as u64))156 .saturating_add(T::DbWeight::get().writes(1 as u64))157 }150 // Storage: Nonfungible Allowance (r:1 w:1)158 // Storage: Nonfungible Allowance (r:1 w:1)151 // Storage: Nonfungible TokenData (r:1 w:1)159 // Storage: Nonfungible TokenData (r:1 w:1)152 // Storage: Nonfungible AccountBalance (r:2 w:2)160 // Storage: Nonfungible AccountBalance (r:2 w:2)310 .saturating_add(RocksDbWeight::get().reads(2 as u64))318 .saturating_add(RocksDbWeight::get().reads(2 as u64))311 .saturating_add(RocksDbWeight::get().writes(1 as u64))319 .saturating_add(RocksDbWeight::get().writes(1 as u64))312 }320 }321 // Storage: Nonfungible TokenData (r:1 w:0)322 // Storage: Nonfungible Allowance (r:1 w:1)323 fn approve_from() -> Weight {324 Weight::from_ref_time(18_965_000 as u64)325 .saturating_add(RocksDbWeight::get().reads(2 as u64))326 .saturating_add(RocksDbWeight::get().writes(1 as u64))327 }313 // Storage: Nonfungible Allowance (r:1 w:1)328 // Storage: Nonfungible Allowance (r:1 w:1)314 // Storage: Nonfungible TokenData (r:1 w:1)329 // Storage: Nonfungible TokenData (r:1 w:1)315 // Storage: Nonfungible AccountBalance (r:2 w:2)330 // Storage: Nonfungible AccountBalance (r:2 w:2)pallets/refungible/src/benchmarking.rsdiffbeforeafterboth163 let item = create_max_item(&collection, &owner, [(sender.clone(), 200)])?;163 let item = create_max_item(&collection, &owner, [(sender.clone(), 200)])?;164 }: {<Pallet<T>>::set_allowance(&collection, &sender, &spender, item, 100)?}164 }: {<Pallet<T>>::set_allowance(&collection, &sender, &spender, item, 100)?}165166 approve_from {167 bench_init!{168 owner: sub; collection: collection(owner);169 owner: cross_from_sub; sender: cross_sub; spender: cross_sub;170 };171 let owner_eth = T::CrossAccountId::from_eth(*sender.as_eth());172 let item = create_max_item(&collection, &owner, [(owner_eth.clone(), 200)])?;173 }: {<Pallet<T>>::set_allowance_from(&collection, &sender, &owner_eth, &spender, item, 100)?}165174166 transfer_from_normal {175 transfer_from_normal {167 bench_init!{176 bench_init!{pallets/refungible/src/common.rsdiffbeforeafterboth127 <SelfWeightOf<T>>::approve()127 <SelfWeightOf<T>>::approve()128 }128 }129130 fn approve_from() -> Weight {131 <SelfWeightOf<T>>::approve_from()132 }129133130 fn transfer_from() -> Weight {134 fn transfer_from() -> Weight {131 max_weight_of!(135 max_weight_of!(314 )318 )315 }319 }320321 fn approve_from(322 &self,323 sender: T::CrossAccountId,324 from: T::CrossAccountId,325 to: T::CrossAccountId,326 token_id: TokenId,327 amount: u128,328 ) -> DispatchResultWithPostInfo {329 with_weight(330 <Pallet<T>>::set_allowance_from(self, &sender, &from, &to, token_id, amount),331 <CommonWeights<T>>::approve_from(),332 )333 }316334317 fn transfer_from(335 fn transfer_from(318 &self,336 &self,pallets/refungible/src/lib.rsdiffbeforeafterboth1102 Ok(())1102 Ok(())1103 }1103 }11041105 /// Set allowance to spend from sender's eth mirror1106 ///1107 /// - `from`: Address of sender's eth mirror.1108 /// - `to`: Adress of spender.1109 /// - `amount`: Amount of token pieces the spender is allowed to `transfer` or `burn.1110 pub fn set_allowance_from(1111 collection: &RefungibleHandle<T>,1112 sender: &T::CrossAccountId,1113 from: &T::CrossAccountId,1114 to: &T::CrossAccountId,1115 token_id: TokenId,1116 amount: u128,1117 ) -> DispatchResult {1118 if collection.permissions.access() == AccessMode::AllowList {1119 collection.check_allowlist(sender)?;1120 collection.check_allowlist(from)?;1121 collection.check_allowlist(to)?;1122 }11231124 <PalletCommon<T>>::ensure_correct_receiver(to)?;11251126 ensure!(1127 sender.conv_eq(from),1128 <CommonError<T>>::AddressIsNotEthMirror1129 );11301131 if <Balance<T>>::get((collection.id, token_id, from)) < amount {1132 ensure!(1133 collection.limits.owner_can_transfer()1134 && (collection.is_owner_or_admin(sender) || collection.is_owner_or_admin(from))1135 && Self::token_exists(collection, token_id),1136 <CommonError<T>>::CantApproveMoreThanOwned1137 );1138 }11391140 // =========11411142 Self::set_allowance_unchecked(collection, from, to, token_id, amount);1143 Ok(())1144 }110411451105 /// Returns allowance, which should be set after transaction1146 /// Returns allowance, which should be set after transaction1106 fn check_allowed(1147 fn check_allowed(pallets/refungible/src/weights.rsdiffbeforeafterboth45 fn transfer_removing() -> Weight;45 fn transfer_removing() -> Weight;46 fn transfer_creating_removing() -> Weight;46 fn transfer_creating_removing() -> Weight;47 fn approve() -> Weight;47 fn approve() -> Weight;48 fn approve_from() -> Weight;48 fn transfer_from_normal() -> Weight;49 fn transfer_from_normal() -> Weight;49 fn transfer_from_creating() -> Weight;50 fn transfer_from_creating() -> Weight;50 fn transfer_from_removing() -> Weight;51 fn transfer_from_removing() -> Weight;175 .saturating_add(T::DbWeight::get().reads(1 as u64))176 .saturating_add(T::DbWeight::get().reads(1 as u64))176 .saturating_add(T::DbWeight::get().writes(1 as u64))177 .saturating_add(T::DbWeight::get().writes(1 as u64))177 }178 }179 // Storage: Refungible Balance (r:1 w:0)180 // Storage: Refungible Allowance (r:0 w:1)181 fn approve_from() -> Weight {182 Weight::from_ref_time(20_649_000 as u64)183 .saturating_add(T::DbWeight::get().reads(1 as u64))184 .saturating_add(T::DbWeight::get().writes(1 as u64))185 }178 // Storage: Refungible Allowance (r:1 w:1)186 // Storage: Refungible Allowance (r:1 w:1)179 // Storage: Refungible CollectionAllowance (r:1 w:0)187 // Storage: Refungible CollectionAllowance (r:1 w:0)180 // Storage: Refungible Balance (r:2 w:2)188 // Storage: Refungible Balance (r:2 w:2)400 .saturating_add(RocksDbWeight::get().reads(1 as u64))408 .saturating_add(RocksDbWeight::get().reads(1 as u64))401 .saturating_add(RocksDbWeight::get().writes(1 as u64))409 .saturating_add(RocksDbWeight::get().writes(1 as u64))402 }410 }411 // Storage: Refungible Balance (r:1 w:0)412 // Storage: Refungible Allowance (r:0 w:1)413 fn approve_from() -> Weight {414 Weight::from_ref_time(20_649_000 as u64)415 .saturating_add(RocksDbWeight::get().reads(1 as u64))416 .saturating_add(RocksDbWeight::get().writes(1 as u64))417 }403 // Storage: Refungible Allowance (r:1 w:1)418 // Storage: Refungible Allowance (r:1 w:1)404 // Storage: Refungible CollectionAllowance (r:1 w:0)419 // Storage: Refungible CollectionAllowance (r:1 w:0)405 // Storage: Refungible Balance (r:2 w:2)420 // Storage: Refungible Balance (r:2 w:2)pallets/unique/src/lib.rsdiffbeforeafterboth851 dispatch_tx::<T, _>(collection_id, |d| d.approve(sender, spender, item_id, amount))851 dispatch_tx::<T, _>(collection_id, |d| d.approve(sender, spender, item_id, amount))852 }852 }853854 /// Allow a non-permissioned address to transfer or burn an item from owner's eth mirror.855 ///856 /// # Permissions857 ///858 /// * Collection owner859 /// * Collection admin860 /// * Current item owner861 ///862 /// # Arguments863 ///864 /// * `from`: Owner's account eth mirror865 /// * `to`: Account to be approved to make specific transactions on non-owned tokens.866 /// * `collection_id`: ID of the collection the item belongs to.867 /// * `item_id`: ID of the item transactions on which are now approved.868 /// * `amount`: Number of pieces of the item approved for a transaction (maximum of 1 for NFTs).869 /// Set to 0 to revoke the approval.870 #[weight = T::CommonWeightInfo::approve_from()]871 pub fn approve_from(origin, from:T::CrossAccountId, to: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, amount: u128) -> DispatchResultWithPostInfo {872 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);873874 dispatch_tx::<T, _>(collection_id, |d| d.approve_from(sender, from, to, item_id, amount))875 }853876854 /// Change ownership of an item on behalf of the owner as a non-owner account.877 /// Change ownership of an item on behalf of the owner as a non-owner account.855 ///878 ///runtime/common/identity.rsdiffbeforeafterboth27#[cfg(feature = "collator-selection")]26#[cfg(feature = "collator-selection")]28use sp_runtime::transaction_validity::InvalidTransaction;27use sp_runtime::transaction_validity::InvalidTransaction;2829#[cfg(feature = "collator-selection")]30use sp_runtime::transaction_validity::InvalidTransaction;293130#[derive(Debug, Encode, Decode, PartialEq, Eq, Clone, TypeInfo)]32#[derive(Debug, Encode, Decode, PartialEq, Eq, Clone, TypeInfo)]31pub struct DisableIdentityCalls;33pub struct DisableIdentityCalls;runtime/common/weights.rsdiffbeforeafterboth101 dispatch_weight::<T>() + max_weight_of!(approve())101 dispatch_weight::<T>() + max_weight_of!(approve())102 }102 }103104 fn approve_from() -> Weight {105 dispatch_weight::<T>() + max_weight_of!(approve_from())106 }103107104 fn transfer_from() -> Weight {108 fn transfer_from() -> Weight {105 dispatch_weight::<T>() + max_weight_of!(transfer_from())109 dispatch_weight::<T>() + max_weight_of!(transfer_from())tests/src/approve.test.tsdiffbeforeafterboth161617import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';18import {expect, itSub, Pallets, usingPlaygrounds} from './util';18import {expect, itSub, Pallets, usingPlaygrounds} from './util';19import {CrossAccountId} from './util/playgrounds/unique';1920202121describe('Integration Test approve(spender, collection_id, item_id, amount):', () => {22 let alice: IKeyringPair;23 let bob: IKeyringPair;24 let charlie: IKeyringPair;252223[26 before(async () => {24 {method: 'approveToken', account: (account: IKeyringPair) => CrossAccountId.fromKeyring(account)},25 {method: 'approveTokenFromEth', account: (account: IKeyringPair) => CrossAccountId.fromKeyring(account).toEthereum()},26].map(testCase => {27 describe(`Integration Test ${testCase.method}(spender, collection_id, item_id, amount):`, () => {28 let alice: IKeyringPair;29 let bob: IKeyringPair;30 let charlie: IKeyringPair;3132 before(async () => {27 await usingPlaygrounds(async (helper, privateKey) => {33 await usingPlaygrounds(async (helper, privateKey) => {28 const donor = await privateKey({filename: __filename});34 const donor = await privateKey({filename: __filename});29 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);35 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);36 });30 });37 });31 });323833 itSub('[nft] Execute the extrinsic and check approvedList', async ({helper}) => {39 itSub('[nft] Execute the extrinsic and check approvedList', async ({helper}) => {34 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});40 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});35 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});41 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(alice)});36 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});42 await (helper.nft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address});37 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.true;43 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.true;38 });44 });394540 itSub('[fungible] Execute the extrinsic and check approvedList', async ({helper}) => {46 itSub('[fungible] Execute the extrinsic and check approvedList', async ({helper}) => {41 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);47 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);42 await helper.ft.mintTokens(alice, collectionId, 10n, {Substrate: alice.address});48 await helper.ft.mintTokens(alice, collectionId, 10n, testCase.account(alice));43 const tokenId = await helper.ft.getLastTokenId(collectionId);49 const tokenId = await helper.ft.getLastTokenId(collectionId);44 await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});50 await (helper.ft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address});45 const amount = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});51 const amount = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, testCase.account(alice));46 expect(amount).to.be.equal(BigInt(1));52 expect(amount).to.be.equal(BigInt(1));47 });53 });485449 itSub.ifWithPallets('[refungible] Execute the extrinsic and check approvedList', [Pallets.ReFungible], async ({helper}) => {55 itSub.ifWithPallets('[refungible] Execute the extrinsic and check approvedList', [Pallets.ReFungible], async ({helper}) => {50 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});56 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});51 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n});57 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(alice), pieces: 100n});52 await helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});58 await (helper.rft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address});53 const amount = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});59 const amount = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, testCase.account(alice));54 expect(amount).to.be.equal(BigInt(1));60 expect(amount).to.be.equal(BigInt(1));55 });61 });566257 itSub('[nft] Remove approval by using 0 amount', async ({helper}) => {63 itSub('[nft] Remove approval by using 0 amount', async ({helper}) => {58 const collection = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});64 const collection = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});59 const collectionId = collection.collectionId;65 const collectionId = collection.collectionId;60 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});66 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(alice)});61 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});67 await (helper.nft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address});62 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.true;68 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.true;63 await helper.signTransaction(alice, helper.constructApiCall('api.tx.unique.approve', [{Substrate: bob.address}, collectionId, tokenId, 0]));69 await (helper.nft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address}, 0n);64 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.false;70 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.false;65 });71 });667267 itSub('[fungible] Remove approval by using 0 amount', async ({helper}) => {73 itSub('[fungible] Remove approval by using 0 amount', async ({helper}) => {68 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);74 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);69 await helper.ft.mintTokens(alice, collectionId, 10n, {Substrate: alice.address});75 await helper.ft.mintTokens(alice, collectionId, 10n, testCase.account(alice));70 const tokenId = await helper.ft.getLastTokenId(collectionId);76 const tokenId = await helper.ft.getLastTokenId(collectionId);71 await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});77 await (helper.ft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address});72 const amountBefore = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});78 const amountBefore = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, testCase.account(alice));73 expect(amountBefore).to.be.equal(BigInt(1));79 expect(amountBefore).to.be.equal(BigInt(1));748075 await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 0n);81 await (helper.ft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address}, 0n);76 const amountAfter = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});82 const amountAfter = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, testCase.account(alice));77 expect(amountAfter).to.be.equal(BigInt(0));83 expect(amountAfter).to.be.equal(BigInt(0));78 });84 });798580 itSub.ifWithPallets('[refungible] Remove approval by using 0 amount', [Pallets.ReFungible], async ({helper}) => {86 itSub.ifWithPallets('[refungible] Remove approval by using 0 amount', [Pallets.ReFungible], async ({helper}) => {81 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});87 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});82 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n});88 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(alice), pieces: 100n});83 await helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});89 await (helper.rft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address});84 const amountBefore = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});90 const amountBefore = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, testCase.account(alice));85 expect(amountBefore).to.be.equal(BigInt(1));91 expect(amountBefore).to.be.equal(BigInt(1));869287 await helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 0n);93 await (helper.rft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address}, 0n);88 const amountAfter = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});94 const amountAfter = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, testCase.account(alice));89 expect(amountAfter).to.be.equal(BigInt(0));95 expect(amountAfter).to.be.equal(BigInt(0));90 });96 });919792 itSub('can`t be called by collection owner on non-owned item when OwnerCanTransfer == false', async ({helper}) => {98 itSub('can`t be called by collection owner on non-owned item when OwnerCanTransfer == false', async ({helper}) => {93 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});99 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});94 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});100 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(bob)});95 const approveTokenTx = () => helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});101 const result = (helper.nft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: charlie.address});96 await expect(approveTokenTx()).to.be.rejected;102 await expect(result).to.be.rejected;103 });97 });104 });98});99105100describe('Normal user can approve other users to transfer:', () => {106 describe(`[${testCase.method}] Normal user can approve other users to transfer:`, () => {101 let alice: IKeyringPair;107 let alice: IKeyringPair;102 let bob: IKeyringPair;108 let bob: IKeyringPair;103 let charlie: IKeyringPair;109 let charlie: IKeyringPair;104110105 before(async () => {111 before(async () => {106 await usingPlaygrounds(async (helper, privateKey) => {112 await usingPlaygrounds(async (helper, privateKey) => {107 const donor = await privateKey({filename: __filename});113 const donor = await privateKey({filename: __filename});108 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);114 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);115 });109 });116 });110 });111117112 itSub('NFT', async ({helper}) => {118 itSub('NFT', async ({helper}) => {113 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});119 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});114 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});120 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(bob)});115 await helper.nft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});121 await (helper.nft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: charlie.address});116 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: charlie.address})).to.be.true;122 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: charlie.address})).to.be.true;117 });123 });118124119 itSub('Fungible up to an approved amount', async ({helper}) => {125 itSub('Fungible up to an approved amount', async ({helper}) => {120 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);126 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);121 await helper.ft.mintTokens(alice, collectionId, 10n, bob.address);127 await helper.ft.mintTokens(alice, collectionId, 10n, testCase.account(bob));122 const tokenId = await helper.ft.getLastTokenId(collectionId);128 const tokenId = await helper.ft.getLastTokenId(collectionId);123 await helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});129 await (helper.ft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: charlie.address});124 const amount = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: charlie.address}, {Substrate: bob.address});130 const amount = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: charlie.address}, testCase.account(bob));125 expect(amount).to.be.equal(BigInt(1));131 expect(amount).to.be.equal(BigInt(1));126 });132 });127133128 itSub.ifWithPallets('ReFungible up to an approved amount', [Pallets.ReFungible], async ({helper}) => {134 itSub.ifWithPallets('ReFungible up to an approved amount', [Pallets.ReFungible], async ({helper}) => {129 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});135 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});130 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: bob.address, pieces: 100n});136 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(bob), pieces: 100n});131 await helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address}, 100n);137 await (helper.rft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: charlie.address}, 100n);132 const amount = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: charlie.address}, {Substrate: bob.address});138 const amount = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: charlie.address}, testCase.account(bob));133 expect(amount).to.be.equal(BigInt(100n));139 expect(amount).to.be.equal(BigInt(100n));140 });134 });141 });135});136142137describe('Approved users can transferFrom up to approved amount:', () => {143 describe(`[${testCase.method}] Approved users can transferFrom up to approved amount:`, () => {138 let alice: IKeyringPair;144 let alice: IKeyringPair;139 let bob: IKeyringPair;145 let bob: IKeyringPair;140 let charlie: IKeyringPair;146 let charlie: IKeyringPair;141147142 before(async () => {148 before(async () => {143 await usingPlaygrounds(async (helper, privateKey) => {149 await usingPlaygrounds(async (helper, privateKey) => {144 const donor = await privateKey({filename: __filename});150 const donor = await privateKey({filename: __filename});145 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);151 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);152 });146 });153 });147 });148154149 itSub('NFT', async ({helper}) => {155 itSub('NFT', async ({helper}) => {150 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});156 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});151 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});157 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(bob)});152 await helper.nft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});158 await (helper.nft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: charlie.address});153 await helper.nft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});159 await helper.nft.transferTokenFrom(charlie, collectionId, tokenId, testCase.account(bob), {Substrate: alice.address});154 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);160 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);155 expect(owner.Substrate).to.be.equal(alice.address);161 expect(owner.Substrate).to.be.equal(alice.address);156 });162 });157163158 itSub('Fungible up to an approved amount', async ({helper}) => {164 itSub('Fungible up to an approved amount', async ({helper}) => {159 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);165 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);160 await helper.ft.mintTokens(alice, collectionId, 10n, bob.address);166 await helper.ft.mintTokens(alice, collectionId, 10n, testCase.account(bob));161 const tokenId = await helper.ft.getLastTokenId(collectionId);167 const tokenId = await helper.ft.getLastTokenId(collectionId);162 await helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});168 await (helper.ft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: charlie.address});163 const before = await helper.ft.getBalance(collectionId, {Substrate: alice.address});169 const before = await helper.ft.getBalance(collectionId, {Substrate: alice.address});164 await helper.ft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 1n);170 await helper.ft.transferTokenFrom(charlie, collectionId, tokenId, testCase.account(bob), {Substrate: alice.address}, 1n);165 const after = await helper.ft.getBalance(collectionId, {Substrate: alice.address});171 const after = await helper.ft.getBalance(collectionId, {Substrate: alice.address});166 expect(after - before).to.be.equal(BigInt(1));172 expect(after - before).to.be.equal(BigInt(1));167 });173 });168174169 itSub.ifWithPallets('ReFungible up to an approved amount', [Pallets.ReFungible], async ({helper}) => {175 itSub.ifWithPallets('ReFungible up to an approved amount', [Pallets.ReFungible], async ({helper}) => {170 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});176 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});171 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: bob.address, pieces: 100n});177 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(bob), pieces: 100n});172 await helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});178 await (helper.rft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: charlie.address});173 const before = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});179 const before = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});174 await helper.rft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 1n);180 await helper.rft.transferTokenFrom(charlie, collectionId, tokenId, testCase.account(bob), {Substrate: alice.address}, 1n);175 const after = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});181 const after = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});176 expect(after - before).to.be.equal(BigInt(1));182 expect(after - before).to.be.equal(BigInt(1));183 });177 });184 });178});179185180describe('Approved users cannot use transferFrom to repeat transfers if approved amount was already transferred:', () => {186 describe(`[${testCase.method}] Approved users cannot use transferFrom to repeat transfers if approved amount was already transferred:`, () => {181 let alice: IKeyringPair;187 let alice: IKeyringPair;182 let bob: IKeyringPair;188 let bob: IKeyringPair;183 let charlie: IKeyringPair;189 let charlie: IKeyringPair;184190185 before(async () => {191 before(async () => {186 await usingPlaygrounds(async (helper, privateKey) => {192 await usingPlaygrounds(async (helper, privateKey) => {187 const donor = await privateKey({filename: __filename});193 const donor = await privateKey({filename: __filename});188 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);194 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);195 });189 });196 });190 });191197192 itSub('NFT', async ({helper}) => {198 itSub('NFT', async ({helper}) => {193 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});199 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});194 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});200 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(bob)});195 await helper.nft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});201 await (helper.nft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: charlie.address});196 await helper.nft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});202 await helper.nft.transferTokenFrom(charlie, collectionId, tokenId, testCase.account(bob), {Substrate: alice.address});197 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);203 const owner = await helper.nft.getTokenOwner(collectionId, tokenId);198 expect(owner.Substrate).to.be.equal(alice.address);204 expect(owner.Substrate).to.be.equal(alice.address);199 const transferTokenFromTx = () => helper.nft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});205 const transferTokenFromTx = () => helper.nft.transferTokenFrom(charlie, collectionId, tokenId, testCase.account(bob), {Substrate: alice.address});200 await expect(transferTokenFromTx()).to.be.rejected;206 await expect(transferTokenFromTx()).to.be.rejected;201 });207 });202208203 itSub('Fungible up to an approved amount', async ({helper}) => {209 itSub('Fungible up to an approved amount', async ({helper}) => {204 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);210 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);205 await helper.ft.mintTokens(alice, collectionId, 10n, bob.address);211 await helper.ft.mintTokens(alice, collectionId, 10n, testCase.account(bob));206 const tokenId = await helper.ft.getLastTokenId(collectionId);212 const tokenId = await helper.ft.getLastTokenId(collectionId);207 await helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});213 await (helper.ft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: charlie.address});208 const before = await helper.ft.getBalance(collectionId, {Substrate: alice.address});214 const before = await helper.ft.getBalance(collectionId, {Substrate: alice.address});209 await helper.ft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 1n);215 await helper.ft.transferTokenFrom(charlie, collectionId, tokenId, testCase.account(bob), {Substrate: alice.address}, 1n);210 const after = await helper.ft.getBalance(collectionId, {Substrate: alice.address});216 const after = await helper.ft.getBalance(collectionId, {Substrate: alice.address});211 expect(after - before).to.be.equal(BigInt(1));217 expect(after - before).to.be.equal(BigInt(1));212218213 const transferTokenFromTx = () => helper.ft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 1n);219 const transferTokenFromTx = () => helper.ft.transferTokenFrom(charlie, collectionId, tokenId, testCase.account(bob), {Substrate: alice.address}, 1n);214 await expect(transferTokenFromTx()).to.be.rejected;220 await expect(transferTokenFromTx()).to.be.rejected;215 });221 });216222217 itSub.ifWithPallets('ReFungible up to an approved amount', [Pallets.ReFungible], async ({helper}) => {223 itSub.ifWithPallets('ReFungible up to an approved amount', [Pallets.ReFungible], async ({helper}) => {218 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});224 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});219 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: bob.address, pieces: 100n});225 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(bob), pieces: 100n});220 await helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address}, 100n);226 await (helper.ft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: charlie.address}, 100n);221 const before = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});227 const before = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});222 await helper.rft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 100n);228 await helper.rft.transferTokenFrom(charlie, collectionId, tokenId, testCase.account(bob), {Substrate: alice.address}, 100n);223 const after = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});229 const after = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});224 expect(after - before).to.be.equal(BigInt(100));230 expect(after - before).to.be.equal(BigInt(100));225 const transferTokenFromTx = () => helper.rft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 100n);231 const transferTokenFromTx = () => helper.rft.transferTokenFrom(charlie, collectionId, tokenId, testCase.account(bob), {Substrate: alice.address}, 100n);226 await expect(transferTokenFromTx()).to.be.rejected;232 await expect(transferTokenFromTx()).to.be.rejected;233 });227 });234 });228});229235230describe('Approved amount decreases by the transferred amount:', () => {236 describe(`[${testCase.method}] Approved amount decreases by the transferred amount:`, () => {231 let alice: IKeyringPair;237 let alice: IKeyringPair;232 let bob: IKeyringPair;238 let bob: IKeyringPair;233 let charlie: IKeyringPair;239 let charlie: IKeyringPair;234 let dave: IKeyringPair;240 let dave: IKeyringPair;235241236 before(async () => {242 before(async () => {237 await usingPlaygrounds(async (helper, privateKey) => {243 await usingPlaygrounds(async (helper, privateKey) => {238 const donor = await privateKey({filename: __filename});244 const donor = await privateKey({filename: __filename});239 [alice, bob, charlie, dave] = await helper.arrange.createAccounts([100n, 100n, 100n, 100n], donor);245 [alice, bob, charlie, dave] = await helper.arrange.createAccounts([100n, 100n, 100n, 100n], donor);246 });240 });247 });241 });242248243 itSub('If a user B is approved to transfer 10 Fungible tokens from user A, they can transfer 2 tokens to user C, which will result in decreasing approval from 10 to 8. Then user B can transfer 8 tokens to user D.', async ({helper}) => {249 itSub('If a user B is approved to transfer 10 Fungible tokens from user A, they can transfer 2 tokens to user C, which will result in decreasing approval from 10 to 8. Then user B can transfer 8 tokens to user D.', async ({helper}) => {244 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);250 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);245 await helper.ft.mintTokens(alice, collectionId, 10n, alice.address);251 await helper.ft.mintTokens(alice, collectionId, 10n, testCase.account(alice));246 const tokenId = await helper.ft.getLastTokenId(collectionId);252 const tokenId = await helper.ft.getLastTokenId(collectionId);247 await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 10n);253 await (helper.ft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address}, 10n);248254249 const charlieBefore = await helper.ft.getBalance(collectionId, {Substrate: charlie.address});255 const charlieBefore = await helper.ft.getBalance(collectionId, {Substrate: charlie.address});250 await helper.ft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: alice.address}, {Substrate: charlie.address}, 2n);256 await helper.ft.transferTokenFrom(bob, collectionId, tokenId, testCase.account(alice), {Substrate: charlie.address}, 2n);251 const charlieAfter = await helper.ft.getBalance(collectionId, {Substrate: charlie.address});257 const charlieAfter = await helper.ft.getBalance(collectionId, {Substrate: charlie.address});252 expect(charlieAfter - charlieBefore).to.be.equal(BigInt(2));258 expect(charlieAfter - charlieBefore).to.be.equal(BigInt(2));253259254 const daveBefore = await helper.ft.getBalance(collectionId, {Substrate: dave.address});260 const daveBefore = await helper.ft.getBalance(collectionId, {Substrate: dave.address});255 await helper.ft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: alice.address}, {Substrate: dave.address}, 8n);261 await helper.ft.transferTokenFrom(bob, collectionId, tokenId, testCase.account(alice), {Substrate: dave.address}, 8n);256 const daveAfter = await helper.ft.getBalance(collectionId, {Substrate: dave.address});262 const daveAfter = await helper.ft.getBalance(collectionId, {Substrate: dave.address});257 expect(daveAfter - daveBefore).to.be.equal(BigInt(8));263 expect(daveAfter - daveBefore).to.be.equal(BigInt(8));264 });258 });265 });259});260266261describe('User may clear the approvals to approving for 0 amount:', () => {267 describe(`[${testCase.method}] User may clear the approvals to approving for 0 amount:`, () => {262 let alice: IKeyringPair;268 let alice: IKeyringPair;263 let bob: IKeyringPair;269 let bob: IKeyringPair;264 let charlie: IKeyringPair;270 let charlie: IKeyringPair;265271266 before(async () => {272 before(async () => {267 await usingPlaygrounds(async (helper, privateKey) => {273 await usingPlaygrounds(async (helper, privateKey) => {268 const donor = await privateKey({filename: __filename});274 const donor = await privateKey({filename: __filename});269 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);275 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);276 });270 });277 });278279 itSub('NFT', async ({helper}) => {280 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});281 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(alice)});282 await (helper.nft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address});283 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.true;284 await (helper.nft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address}, 0n);285 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.false;286 const transferTokenFromTx = () => helper.nft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: bob.address}, {Substrate: bob.address});287 await expect(transferTokenFromTx()).to.be.rejected;288 });289290 itSub('Fungible', async ({helper}) => {291 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);292 await helper.ft.mintTokens(alice, collectionId, 10n, testCase.account(alice));293 const tokenId = await helper.ft.getLastTokenId(collectionId);294 await (helper.ft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address});295 const amountBefore = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, testCase.account(alice));296 expect(amountBefore).to.be.equal(BigInt(1));297298 await (helper.ft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address}, 0n);299 const amountAfter = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, testCase.account(alice));300 expect(amountAfter).to.be.equal(BigInt(0));301302 const transferTokenFromTx = () => helper.ft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: bob.address}, {Substrate: charlie.address}, 1n);303 await expect(transferTokenFromTx()).to.be.rejected;304 });305306 itSub.ifWithPallets('ReFungible', [Pallets.ReFungible], async ({helper}) => {307 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});308 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(alice), pieces: 100n});309 await (helper.rft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address});310 const amountBefore = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, testCase.account(alice));311 expect(amountBefore).to.be.equal(BigInt(1));312313 await (helper.rft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address}, 0n);314 const amountAfter = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, testCase.account(alice));315 expect(amountAfter).to.be.equal(BigInt(0));316317 const transferTokenFromTx = () => helper.rft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: bob.address}, {Substrate: charlie.address}, 100n);318 await expect(transferTokenFromTx()).to.be.rejected;319 });271 });320 });272321273 itSub('NFT', async ({helper}) => {322 describe(`[${testCase.method}] User cannot approve for the amount greater than they own:`, () => {323 let alice: IKeyringPair;324 let bob: IKeyringPair;325 let charlie: IKeyringPair;326327 before(async () => {328 await usingPlaygrounds(async (helper, privateKey) => {329 const donor = await privateKey({filename: __filename});330 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);331 });332 });333334 itSub('1 for NFT', async ({helper}) => {274 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});335 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});275 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});336 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(bob)});276 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});337 const result = (helper.nft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: charlie.address}, 2n);277 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.true;338 await expect(result).to.be.rejected;339 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: charlie.address})).to.be.false;278 await helper.signTransaction(alice, helper.constructApiCall('api.tx.unique.approve', [{Substrate: bob.address}, collectionId, tokenId, 0]));340 });341342 itSub('Fungible', async ({helper}) => {343 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);344 await helper.ft.mintTokens(alice, collectionId, 10n, testCase.account(alice));279 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.false;345 const tokenId = await helper.ft.getLastTokenId(collectionId);346 const result = (helper.ft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address}, 11n);347 await expect(result).to.be.rejected;280 const transferTokenFromTx = () => helper.nft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: bob.address}, {Substrate: bob.address});348 });349350 itSub.ifWithPallets('ReFungible', [Pallets.ReFungible], async ({helper}) => {351 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});352 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(alice), pieces: 100n});353 const result = (helper.rft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address}, 101n);281 await expect(transferTokenFromTx()).to.be.rejected;354 await expect(result).to.be.rejected;355 });282 });356 });283357284 itSub('Fungible', async ({helper}) => {358 describe(`[${testCase.method}] Integration Test approve(spender, collection_id, item_id, amount) with collection admin permissions:`, () => {285 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);286 await helper.ft.mintTokens(alice, collectionId, 10n, alice.address);287 const tokenId = await helper.ft.getLastTokenId(collectionId);288 await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});359 let alice: IKeyringPair;289 const amountBefore = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});360 let bob: IKeyringPair;290 expect(amountBefore).to.be.equal(BigInt(1));361 let charlie: IKeyringPair;291362292 await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 0n);363 before(async () => {364 await usingPlaygrounds(async (helper, privateKey) => {365 const donor = await privateKey({filename: __filename});293 const amountAfter = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});366 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);367 });294 expect(amountAfter).to.be.equal(BigInt(0));368 });295369296 const transferTokenFromTx = () => helper.ft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: bob.address}, {Substrate: charlie.address}, 1n);370 itSub('can be called by collection admin on non-owned item', async ({helper}) => {371 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});372 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(alice)});373 await helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address});374 const result = (helper.nft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: charlie.address});297 await expect(transferTokenFromTx()).to.be.rejected;375 await expect(result).to.be.rejected;376 });298 });377 });299378300 itSub.ifWithPallets('ReFungible', [Pallets.ReFungible], async ({helper}) => {379 describe(`[${testCase.method}] Negative Integration Test approve(spender, collection_id, item_id, amount):`, () => {301 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});302 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n});303 await helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});380 let alice: IKeyringPair;304 const amountBefore = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});381 let bob: IKeyringPair;305 expect(amountBefore).to.be.equal(BigInt(1));382 let charlie: IKeyringPair;306383307 await helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 0n);384 before(async () => {385 await usingPlaygrounds(async (helper, privateKey) => {386 const donor = await privateKey({filename: __filename});308 const amountAfter = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});387 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);388 });309 expect(amountAfter).to.be.equal(BigInt(0));389 });310390311 const transferTokenFromTx = () => helper.rft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: bob.address}, {Substrate: charlie.address}, 100n);391 itSub('[nft] Approve for a collection that does not exist', async ({helper}) => {312 await expect(transferTokenFromTx()).to.be.rejected;392 const collectionId = 1 << 32 - 1;393 await expect((helper.nft as any)[testCase.method](bob, collectionId, 1, {Substrate: charlie.address})).to.be.rejected;394 });395396 itSub('[fungible] Approve for a collection that does not exist', async ({helper}) => {397 const collectionId = 1 << 32 - 1;398 const approveTx = () => (helper.ft as any)[testCase.method](bob, collectionId, 1, {Substrate: charlie.address});399 await expect(approveTx()).to.be.rejected;400 });401402 itSub.ifWithPallets('[refungible] Approve for a collection that does not exist', [Pallets.ReFungible], async ({helper}) => {403 const collectionId = 1 << 32 - 1;404 const approveTx = () => (helper.rft as any)[testCase.method](bob, collectionId, 1, {Substrate: charlie.address});405 await expect(approveTx()).to.be.rejected;406 });407408 itSub('[nft] Approve for a collection that was destroyed', async ({helper}) => {409 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});410 await helper.nft.burn(alice, collectionId);411 const approveTx = () => (helper.nft as any)[testCase.method](alice, collectionId, 1, {Substrate: bob.address});412 await expect(approveTx()).to.be.rejected;413 });414415 itSub('[fungible] Approve for a collection that was destroyed', async ({helper}) => {416 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});417 await helper.ft.burn(alice, collectionId);418 const approveTx = () => (helper.ft as any)[testCase.method](alice, collectionId, 1, {Substrate: bob.address});419 await expect(approveTx()).to.be.rejected;420 });421422 itSub.ifWithPallets('[refungible] Approve for a collection that was destroyed', [Pallets.ReFungible], async ({helper}) => {423 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});424 await helper.rft.burn(alice, collectionId);425 const approveTx = () => (helper.rft as any)[testCase.method](alice, collectionId, 1, {Substrate: bob.address});426 await expect(approveTx()).to.be.rejected;427 });428429 itSub('[nft] Approve transfer of a token that does not exist', async ({helper}) => {430 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});431 const approveTx = () => (helper.nft as any)[testCase.method](alice, collectionId, 2, {Substrate: bob.address});432 await expect(approveTx()).to.be.rejected;433 });434435 itSub.ifWithPallets('[refungible] Approve transfer of a token that does not exist', [Pallets.ReFungible], async ({helper}) => {436 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});437 const approveTx = () => (helper.rft as any)[testCase.method](alice, collectionId, 2, {Substrate: bob.address});438 await expect(approveTx()).to.be.rejected;439 });440441 itSub('[nft] Approve using the address that does not own the approved token', async ({helper}) => {442 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});443 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(alice)});444 const approveTx = () => (helper.nft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: alice.address});445 await expect(approveTx()).to.be.rejected;446 });447448 itSub('[fungible] Approve using the address that does not own the approved token', async ({helper}) => {449 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});450 await helper.ft.mintTokens(alice, collectionId, 10n, testCase.account(alice));451 const tokenId = await helper.ft.getLastTokenId(collectionId);452 const approveTx = () => (helper.ft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: alice.address});453 await expect(approveTx()).to.be.rejected;454 });455456 itSub.ifWithPallets('[refungible] Approve using the address that does not own the approved token', [Pallets.ReFungible], async ({helper}) => {457 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});458 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(alice), pieces: 100n});459 const approveTx = () => (helper.rft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: alice.address});460 await expect(approveTx()).to.be.rejected;461 });462463 itSub.ifWithPallets('should fail if approved more ReFungibles than owned', [Pallets.ReFungible], async ({helper}) => {464 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});465 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n});466 await helper.rft.transferToken(alice, collectionId, tokenId, testCase.account(bob), 100n);467 await (helper.rft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: alice.address}, 100n);468469 const approveTx = () => (helper.rft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: alice.address}, 101n);470 await expect(approveTx()).to.be.rejected;471 });472473 itSub('should fail if approved more Fungibles than owned', async ({helper}) => {474 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});475 await helper.ft.mintTokens(alice, collectionId, 10n, alice.address);476 const tokenId = await helper.ft.getLastTokenId(collectionId);477478 await helper.ft.transferToken(alice, collectionId, tokenId, testCase.account(bob), 10n);479 await (helper.ft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: alice.address}, 10n);480 const approveTx = () => (helper.ft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: alice.address}, 11n);481 await expect(approveTx()).to.be.rejected;482 });483484 itSub('fails when called by collection owner on non-owned item when OwnerCanTransfer == false', async ({helper}) => {485 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});486 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(bob)});487 await helper.collection.setLimits(alice, collectionId, {ownerCanTransfer: false});488489 const approveTx = () => (helper.nft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: charlie.address});490 await expect(approveTx()).to.be.rejected;491 });313 });492 });314});493});315494316describe('User cannot approve for the amount greater than they own:', () => {495describe('Normal user can approve other users to be wallet operator:', () => {317 let alice: IKeyringPair;496 let alice: IKeyringPair;318 let bob: IKeyringPair;497 let bob: IKeyringPair;319 let charlie: IKeyringPair;320498321 before(async () => {499 before(async () => {322 await usingPlaygrounds(async (helper, privateKey) => {500 await usingPlaygrounds(async (helper, privateKey) => {323 const donor = await privateKey({filename: __filename});501 const donor = await privateKey({filename: __filename});324 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);502 [alice, bob] = await helper.arrange.createAccounts([100n, 100n], donor);325 });503 });326 });504 });327505328 itSub('1 for NFT', async ({helper}) => {506 itSub('[nft] Enable and disable approval', async ({helper}) => {329 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});507 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});330 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});331 const approveTx = () => helper.signTransaction(bob, helper.constructApiCall('api.tx.unique.approve', [{Substrate: charlie.address}, collectionId, tokenId, 2]));332 await expect(approveTx()).to.be.rejected;333 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: charlie.address})).to.be.false;334 });335508336 itSub('Fungible', async ({helper}) => {509 const checkBeforeApproval = await helper.nft.allowanceForAll(collectionId, {Substrate: alice.address}, {Substrate: bob.address});337 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);510 expect(checkBeforeApproval).to.be.false;511338 await helper.ft.mintTokens(alice, collectionId, 10n, alice.address);512 await helper.nft.setAllowanceForAll(alice, collectionId, {Substrate: bob.address}, true);339 const tokenId = await helper.ft.getLastTokenId(collectionId);513 const checkAfterApproval = await helper.nft.allowanceForAll(collectionId, {Substrate: alice.address}, {Substrate: bob.address});340 const approveTx = () => helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 11n);514 expect(checkAfterApproval).to.be.true;515516 await helper.nft.setAllowanceForAll(alice, collectionId, {Substrate: bob.address}, false);341 await expect(approveTx()).to.be.rejected;517 const checkAfterDisapproval = await helper.nft.allowanceForAll(collectionId, {Substrate: alice.address}, {Substrate: bob.address});518 expect(checkAfterDisapproval).to.be.false;342 });519 });343520344 itSub.ifWithPallets('ReFungible', [Pallets.ReFungible], async ({helper}) => {521 itSub.ifWithPallets('[rft] Enable and disable approval', [Pallets.ReFungible], async ({helper}) => {345 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});522 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});523346 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n});524 const checkBeforeApproval = await helper.rft.allowanceForAll(collectionId, {Substrate: alice.address}, {Substrate: bob.address});525 expect(checkBeforeApproval).to.be.false;526527 await helper.rft.setAllowanceForAll(alice, collectionId, {Substrate: bob.address}, true);347 const approveTx = () => helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 101n);528 const checkAfterApproval = await helper.rft.allowanceForAll(collectionId, {Substrate: alice.address}, {Substrate: bob.address});529 expect(checkAfterApproval).to.be.true;530531 await helper.rft.setAllowanceForAll(alice, collectionId, {Substrate: bob.address}, false);348 await expect(approveTx()).to.be.rejected;532 const checkAfterDisapproval = await helper.rft.allowanceForAll(collectionId, {Substrate: alice.address}, {Substrate: bob.address});533 expect(checkAfterDisapproval).to.be.false;349 });534 });350});535});351536464 await token.approve(dave, {Substrate: bob.address}, 50n);649 await token.approve(dave, {Substrate: bob.address}, 50n);465 await expect(token.approve(dave, {Substrate: charlie.address}, 51n))650 await expect(token.approve(dave, {Substrate: charlie.address}, 51n))466 .to.be.rejectedWith('this test would fail (since it is skipped), replace this expecting message with what would have been received');651 .to.be.rejectedWith('this test would fail (since it is skipped), replace this expecting message with what would have been received');467 });468});469470describe('Integration Test approve(spender, collection_id, item_id, amount) with collection admin permissions:', () => {471 let alice: IKeyringPair;472 let bob: IKeyringPair;473 let charlie: IKeyringPair;474475 before(async () => {476 await usingPlaygrounds(async (helper, privateKey) => {477 const donor = await privateKey({filename: __filename});478 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);479 });480 });481482 itSub('can be called by collection admin on non-owned item', async ({helper}) => {483 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});484 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});485 await helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address});486 const approveTx = () => helper.nft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});487 await expect(approveTx()).to.be.rejected;488 });489});490491describe('Negative Integration Test approve(spender, collection_id, item_id, amount):', () => {492 let alice: IKeyringPair;493 let bob: IKeyringPair;494 let charlie: IKeyringPair;495496 before(async () => {497 await usingPlaygrounds(async (helper, privateKey) => {498 const donor = await privateKey({filename: __filename});499 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);500 });501 });502503 itSub('[nft] Approve for a collection that does not exist', async ({helper}) => {504 const collectionId = 1 << 32 - 1;505 const approveTx = () => helper.nft.approveToken(bob, collectionId, 1, {Substrate: charlie.address});506 await expect(approveTx()).to.be.rejected;507 });508509 itSub('[fungible] Approve for a collection that does not exist', async ({helper}) => {510 const collectionId = 1 << 32 - 1;511 const approveTx = () => helper.ft.approveToken(bob, collectionId, 1, {Substrate: charlie.address});512 await expect(approveTx()).to.be.rejected;513 });514515 itSub.ifWithPallets('[refungible] Approve for a collection that does not exist', [Pallets.ReFungible], async ({helper}) => {516 const collectionId = 1 << 32 - 1;517 const approveTx = () => helper.rft.approveToken(bob, collectionId, 1, {Substrate: charlie.address});518 await expect(approveTx()).to.be.rejected;519 });520521 itSub('[nft] Approve for a collection that was destroyed', async ({helper}) => {522 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});523 await helper.nft.burn(alice, collectionId);524 const approveTx = () => helper.nft.approveToken(alice, collectionId, 1, {Substrate: bob.address});525 await expect(approveTx()).to.be.rejected;526 });527528 itSub('[fungible] Approve for a collection that was destroyed', async ({helper}) => {529 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});530 await helper.ft.burn(alice, collectionId);531 const approveTx = () => helper.ft.approveToken(alice, collectionId, 1, {Substrate: bob.address});532 await expect(approveTx()).to.be.rejected;533 });534535 itSub.ifWithPallets('[refungible] Approve for a collection that was destroyed', [Pallets.ReFungible], async ({helper}) => {536 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});537 await helper.rft.burn(alice, collectionId);538 const approveTx = () => helper.rft.approveToken(alice, collectionId, 1, {Substrate: bob.address});539 await expect(approveTx()).to.be.rejected;540 });541542 itSub('[nft] Approve transfer of a token that does not exist', async ({helper}) => {543 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});544 const approveTx = () => helper.nft.approveToken(alice, collectionId, 2, {Substrate: bob.address});545 await expect(approveTx()).to.be.rejected;546 });547548 itSub.ifWithPallets('[refungible] Approve transfer of a token that does not exist', [Pallets.ReFungible], async ({helper}) => {549 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});550 const approveTx = () => helper.rft.approveToken(alice, collectionId, 2, {Substrate: bob.address});551 await expect(approveTx()).to.be.rejected;552 });553554 itSub('[nft] Approve using the address that does not own the approved token', async ({helper}) => {555 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});556 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});557 const approveTx = () => helper.nft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address});558 await expect(approveTx()).to.be.rejected;559 });560561 itSub('[fungible] Approve using the address that does not own the approved token', async ({helper}) => {562 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});563 await helper.ft.mintTokens(alice, collectionId, 10n, alice.address);564 const tokenId = await helper.ft.getLastTokenId(collectionId);565 const approveTx = () => helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address});566 await expect(approveTx()).to.be.rejected;567 });568569 itSub.ifWithPallets('[refungible] Approve using the address that does not own the approved token', [Pallets.ReFungible], async ({helper}) => {570 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});571 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n});572 const approveTx = () => helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address});573 await expect(approveTx()).to.be.rejected;574 });575576 itSub.ifWithPallets('should fail if approved more ReFungibles than owned', [Pallets.ReFungible], async ({helper}) => {577 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});578 const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n});579 await helper.rft.transferToken(alice, collectionId, tokenId, {Substrate: bob.address}, 100n);580 await helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address}, 100n);581582 const approveTx = () => helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address}, 101n);583 await expect(approveTx()).to.be.rejected;584 });585586 itSub('should fail if approved more Fungibles than owned', async ({helper}) => {587 const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});588 await helper.ft.mintTokens(alice, collectionId, 10n, alice.address);589 const tokenId = await helper.ft.getLastTokenId(collectionId);590591 await helper.ft.transferToken(alice, collectionId, tokenId, {Substrate: bob.address}, 10n);592 await helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address}, 10n);593 const approveTx = () => helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address}, 11n);594 await expect(approveTx()).to.be.rejected;595 });596597 itSub('fails when called by collection owner on non-owned item when OwnerCanTransfer == false', async ({helper}) => {598 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});599 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});600 await helper.collection.setLimits(alice, collectionId, {ownerCanTransfer: false});601602 const approveTx = () => helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});603 await expect(approveTx()).to.be.rejected;604 });605});606607describe('Normal user can approve other users to be wallet operator:', () => {608 let alice: IKeyringPair;609 let bob: IKeyringPair;610611 before(async () => {612 await usingPlaygrounds(async (helper, privateKey) => {613 const donor = await privateKey({filename: __filename});614 [alice, bob] = await helper.arrange.createAccounts([100n, 100n], donor);615 });616 });617618 itSub('[nft] Enable and disable approval', async ({helper}) => {619 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});620621 const checkBeforeApproval = await helper.nft.allowanceForAll(collectionId, {Substrate: alice.address}, {Substrate: bob.address});622 expect(checkBeforeApproval).to.be.false;623624 await helper.nft.setAllowanceForAll(alice, collectionId, {Substrate: bob.address}, true);625 const checkAfterApproval = await helper.nft.allowanceForAll(collectionId, {Substrate: alice.address}, {Substrate: bob.address});626 expect(checkAfterApproval).to.be.true;627628 await helper.nft.setAllowanceForAll(alice, collectionId, {Substrate: bob.address}, false);629 const checkAfterDisapproval = await helper.nft.allowanceForAll(collectionId, {Substrate: alice.address}, {Substrate: bob.address});630 expect(checkAfterDisapproval).to.be.false;631 });632633 itSub.ifWithPallets('[rft] Enable and disable approval', [Pallets.ReFungible], async ({helper}) => {634 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});635636 const checkBeforeApproval = await helper.rft.allowanceForAll(collectionId, {Substrate: alice.address}, {Substrate: bob.address});637 expect(checkBeforeApproval).to.be.false;638639 await helper.rft.setAllowanceForAll(alice, collectionId, {Substrate: bob.address}, true);640 const checkAfterApproval = await helper.rft.allowanceForAll(collectionId, {Substrate: alice.address}, {Substrate: bob.address});641 expect(checkAfterApproval).to.be.true;642643 await helper.rft.setAllowanceForAll(alice, collectionId, {Substrate: bob.address}, false);644 const checkAfterDisapproval = await helper.rft.allowanceForAll(collectionId, {Substrate: alice.address}, {Substrate: bob.address});645 expect(checkAfterDisapproval).to.be.false;646 });652 });647});653});648654tests/src/eth/api/ContractHelpers.soldiffbeforeafterboth183183184/// Ethereum representation of Optional value with CrossAddress.184/// Ethereum representation of Optional value with CrossAddress.185struct OptionCrossAddress {185struct OptionCrossAddress {186 /// TODO: field description186 /// Whether or not this CrossAdress is valid and has meaning.187 bool status;187 bool status;188 /// TODO: field description188 /// The underlying CrossAddress value. If the status is false, can be set to whatever.189 CrossAddress value;189 CrossAddress value;190}190}191191tests/src/interfaces/augment-api-errors.tsdiffbeforeafterboth84 * Account token limit exceeded per collection84 * Account token limit exceeded per collection85 **/85 **/86 AccountTokenLimitExceeded: AugmentedError<ApiType>;86 AccountTokenLimitExceeded: AugmentedError<ApiType>;87 /**88 * Only spending from eth mirror could be approved89 **/90 AddressIsNotEthMirror: AugmentedError<ApiType>;87 /**91 /**88 * Can't transfer tokens to ethereum zero address92 * Can't transfer tokens to ethereum zero address89 **/93 **/tests/src/interfaces/augment-api-tx.tsdiffbeforeafterboth1213 * Set to 0 to revoke the approval.1213 * Set to 0 to revoke the approval.1214 **/1214 **/1215 approve: AugmentedSubmittable<(spender: PalletEvmAccountBasicCrossAccountIdRepr | { Substrate: any } | { Ethereum: any } | string | Uint8Array, collectionId: u32 | AnyNumber | Uint8Array, itemId: u32 | AnyNumber | Uint8Array, amount: u128 | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>, [PalletEvmAccountBasicCrossAccountIdRepr, u32, u32, u128]>;1215 approve: AugmentedSubmittable<(spender: PalletEvmAccountBasicCrossAccountIdRepr | { Substrate: any } | { Ethereum: any } | string | Uint8Array, collectionId: u32 | AnyNumber | Uint8Array, itemId: u32 | AnyNumber | Uint8Array, amount: u128 | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>, [PalletEvmAccountBasicCrossAccountIdRepr, u32, u32, u128]>;1216 /**1217 * Allow a non-permissioned address to transfer or burn an item from owner's eth mirror.1218 * 1219 * # Permissions1220 * 1221 * * Collection owner1222 * * Collection admin1223 * * Current item owner1224 * 1225 * # Arguments1226 * 1227 * * `from`: Owner's account eth mirror1228 * * `to`: Account to be approved to make specific transactions on non-owned tokens.1229 * * `collection_id`: ID of the collection the item belongs to.1230 * * `item_id`: ID of the item transactions on which are now approved.1231 * * `amount`: Number of pieces of the item approved for a transaction (maximum of 1 for NFTs).1232 * Set to 0 to revoke the approval.1233 **/1234 approveFrom: AugmentedSubmittable<(from: PalletEvmAccountBasicCrossAccountIdRepr | { Substrate: any } | { Ethereum: any } | string | Uint8Array, to: PalletEvmAccountBasicCrossAccountIdRepr | { Substrate: any } | { Ethereum: any } | string | Uint8Array, collectionId: u32 | AnyNumber | Uint8Array, itemId: u32 | AnyNumber | Uint8Array, amount: u128 | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>, [PalletEvmAccountBasicCrossAccountIdRepr, PalletEvmAccountBasicCrossAccountIdRepr, u32, u32, u128]>;1216 /**1235 /**1217 * Destroy a token on behalf of the owner as a non-owner account.1236 * Destroy a token on behalf of the owner as a non-owner account.1218 * 1237 * tests/src/interfaces/default/types.tsdiffbeforeafterboth1216 readonly isTokenValueTooLow: boolean;1216 readonly isTokenValueTooLow: boolean;1217 readonly isApprovedValueTooLow: boolean;1217 readonly isApprovedValueTooLow: boolean;1218 readonly isCantApproveMoreThanOwned: boolean;1218 readonly isCantApproveMoreThanOwned: boolean;1219 readonly isAddressIsNotEthMirror: boolean;1219 readonly isAddressIsZero: boolean;1220 readonly isAddressIsZero: boolean;1220 readonly isUnsupportedOperation: boolean;1221 readonly isUnsupportedOperation: boolean;1221 readonly isNotSufficientFounds: boolean;1222 readonly isNotSufficientFounds: boolean;1231 readonly isCollectionIsInternal: boolean;1232 readonly isCollectionIsInternal: boolean;1232 readonly isConfirmSponsorshipFail: boolean;1233 readonly isConfirmSponsorshipFail: boolean;1233 readonly isUserIsNotCollectionAdmin: boolean;1234 readonly isUserIsNotCollectionAdmin: boolean;1234 readonly type: 'CollectionNotFound' | 'MustBeTokenOwner' | 'NoPermission' | 'CantDestroyNotEmptyCollection' | 'PublicMintingNotAllowed' | 'AddressNotInAllowlist' | 'CollectionNameLimitExceeded' | 'CollectionDescriptionLimitExceeded' | 'CollectionTokenPrefixLimitExceeded' | 'TotalCollectionsLimitExceeded' | 'CollectionAdminCountExceeded' | 'CollectionLimitBoundsExceeded' | 'OwnerPermissionsCantBeReverted' | 'TransferNotAllowed' | 'AccountTokenLimitExceeded' | 'CollectionTokenLimitExceeded' | 'MetadataFlagFrozen' | 'TokenNotFound' | 'TokenValueTooLow' | 'ApprovedValueTooLow' | 'CantApproveMoreThanOwned' | 'AddressIsZero' | 'UnsupportedOperation' | 'NotSufficientFounds' | 'UserIsNotAllowedToNest' | 'SourceCollectionIsNotAllowedToNest' | 'CollectionFieldSizeExceeded' | 'NoSpaceForProperty' | 'PropertyLimitReached' | 'PropertyKeyIsTooLong' | 'InvalidCharacterInPropertyKey' | 'EmptyPropertyKey' | 'CollectionIsExternal' | 'CollectionIsInternal' | 'ConfirmSponsorshipFail' | 'UserIsNotCollectionAdmin';1235 readonly type: 'CollectionNotFound' | 'MustBeTokenOwner' | 'NoPermission' | 'CantDestroyNotEmptyCollection' | 'PublicMintingNotAllowed' | 'AddressNotInAllowlist' | 'CollectionNameLimitExceeded' | 'CollectionDescriptionLimitExceeded' | 'CollectionTokenPrefixLimitExceeded' | 'TotalCollectionsLimitExceeded' | 'CollectionAdminCountExceeded' | 'CollectionLimitBoundsExceeded' | 'OwnerPermissionsCantBeReverted' | 'TransferNotAllowed' | 'AccountTokenLimitExceeded' | 'CollectionTokenLimitExceeded' | 'MetadataFlagFrozen' | 'TokenNotFound' | 'TokenValueTooLow' | 'ApprovedValueTooLow' | 'CantApproveMoreThanOwned' | 'AddressIsNotEthMirror' | 'AddressIsZero' | 'UnsupportedOperation' | 'NotSufficientFounds' | 'UserIsNotAllowedToNest' | 'SourceCollectionIsNotAllowedToNest' | 'CollectionFieldSizeExceeded' | 'NoSpaceForProperty' | 'PropertyLimitReached' | 'PropertyKeyIsTooLong' | 'InvalidCharacterInPropertyKey' | 'EmptyPropertyKey' | 'CollectionIsExternal' | 'CollectionIsInternal' | 'ConfirmSponsorshipFail' | 'UserIsNotCollectionAdmin';1235}1236}123612371237/** @name PalletCommonEvent */1238/** @name PalletCommonEvent */2306 readonly itemId: u32;2307 readonly itemId: u32;2307 readonly amount: u128;2308 readonly amount: u128;2308 } & Struct;2309 } & Struct;2310 readonly isApproveFrom: boolean;2311 readonly asApproveFrom: {2312 readonly from: PalletEvmAccountBasicCrossAccountIdRepr;2313 readonly to: PalletEvmAccountBasicCrossAccountIdRepr;2314 readonly collectionId: u32;2315 readonly itemId: u32;2316 readonly amount: u128;2317 } & Struct;2309 readonly isTransferFrom: boolean;2318 readonly isTransferFrom: boolean;2310 readonly asTransferFrom: {2319 readonly asTransferFrom: {2311 readonly from: PalletEvmAccountBasicCrossAccountIdRepr;2320 readonly from: PalletEvmAccountBasicCrossAccountIdRepr;2345 readonly collectionId: u32;2354 readonly collectionId: u32;2346 readonly itemId: u32;2355 readonly itemId: u32;2347 } & Struct;2356 } & Struct;2348 readonly type: 'CreateCollection' | 'CreateCollectionEx' | 'DestroyCollection' | 'AddToAllowList' | 'RemoveFromAllowList' | 'ChangeCollectionOwner' | 'AddCollectionAdmin' | 'RemoveCollectionAdmin' | 'SetCollectionSponsor' | 'ConfirmSponsorship' | 'RemoveCollectionSponsor' | 'CreateItem' | 'CreateMultipleItems' | 'SetCollectionProperties' | 'DeleteCollectionProperties' | 'SetTokenProperties' | 'DeleteTokenProperties' | 'SetTokenPropertyPermissions' | 'CreateMultipleItemsEx' | 'SetTransfersEnabledFlag' | 'BurnItem' | 'BurnFrom' | 'Transfer' | 'Approve' | 'TransferFrom' | 'SetCollectionLimits' | 'SetCollectionPermissions' | 'Repartition' | 'SetAllowanceForAll' | 'ForceRepairCollection' | 'ForceRepairItem';2357 readonly type: 'CreateCollection' | 'CreateCollectionEx' | 'DestroyCollection' | 'AddToAllowList' | 'RemoveFromAllowList' | 'ChangeCollectionOwner' | 'AddCollectionAdmin' | 'RemoveCollectionAdmin' | 'SetCollectionSponsor' | 'ConfirmSponsorship' | 'RemoveCollectionSponsor' | 'CreateItem' | 'CreateMultipleItems' | 'SetCollectionProperties' | 'DeleteCollectionProperties' | 'SetTokenProperties' | 'DeleteTokenProperties' | 'SetTokenPropertyPermissions' | 'CreateMultipleItemsEx' | 'SetTransfersEnabledFlag' | 'BurnItem' | 'BurnFrom' | 'Transfer' | 'Approve' | 'ApproveFrom' | 'TransferFrom' | 'SetCollectionLimits' | 'SetCollectionPermissions' | 'Repartition' | 'SetAllowanceForAll' | 'ForceRepairCollection' | 'ForceRepairItem';2349}2358}235023592351/** @name PalletUniqueError */2360/** @name PalletUniqueError */tests/src/interfaces/lookup.tsdiffbeforeafterboth2264 itemId: 'u32',2264 itemId: 'u32',2265 amount: 'u128',2265 amount: 'u128',2266 },2266 },2267 approve_from: {2268 from: 'PalletEvmAccountBasicCrossAccountIdRepr',2269 to: 'PalletEvmAccountBasicCrossAccountIdRepr',2270 collectionId: 'u32',2271 itemId: 'u32',2272 amount: 'u128',2273 },2267 transfer_from: {2274 transfer_from: {2268 from: 'PalletEvmAccountBasicCrossAccountIdRepr',2275 from: 'PalletEvmAccountBasicCrossAccountIdRepr',2269 recipient: 'PalletEvmAccountBasicCrossAccountIdRepr',2276 recipient: 'PalletEvmAccountBasicCrossAccountIdRepr',3280 * Lookup423: pallet_common::pallet::Error<T>3287 * Lookup423: pallet_common::pallet::Error<T>3281 **/3288 **/3282 PalletCommonError: {3289 PalletCommonError: {3283 _enum: ['CollectionNotFound', 'MustBeTokenOwner', 'NoPermission', 'CantDestroyNotEmptyCollection', 'PublicMintingNotAllowed', 'AddressNotInAllowlist', 'CollectionNameLimitExceeded', 'CollectionDescriptionLimitExceeded', 'CollectionTokenPrefixLimitExceeded', 'TotalCollectionsLimitExceeded', 'CollectionAdminCountExceeded', 'CollectionLimitBoundsExceeded', 'OwnerPermissionsCantBeReverted', 'TransferNotAllowed', 'AccountTokenLimitExceeded', 'CollectionTokenLimitExceeded', 'MetadataFlagFrozen', 'TokenNotFound', 'TokenValueTooLow', 'ApprovedValueTooLow', 'CantApproveMoreThanOwned', 'AddressIsZero', 'UnsupportedOperation', 'NotSufficientFounds', 'UserIsNotAllowedToNest', 'SourceCollectionIsNotAllowedToNest', 'CollectionFieldSizeExceeded', 'NoSpaceForProperty', 'PropertyLimitReached', 'PropertyKeyIsTooLong', 'InvalidCharacterInPropertyKey', 'EmptyPropertyKey', 'CollectionIsExternal', 'CollectionIsInternal', 'ConfirmSponsorshipFail', 'UserIsNotCollectionAdmin']3290 _enum: ['CollectionNotFound', 'MustBeTokenOwner', 'NoPermission', 'CantDestroyNotEmptyCollection', 'PublicMintingNotAllowed', 'AddressNotInAllowlist', 'CollectionNameLimitExceeded', 'CollectionDescriptionLimitExceeded', 'CollectionTokenPrefixLimitExceeded', 'TotalCollectionsLimitExceeded', 'CollectionAdminCountExceeded', 'CollectionLimitBoundsExceeded', 'OwnerPermissionsCantBeReverted', 'TransferNotAllowed', 'AccountTokenLimitExceeded', 'CollectionTokenLimitExceeded', 'MetadataFlagFrozen', 'TokenNotFound', 'TokenValueTooLow', 'ApprovedValueTooLow', 'CantApproveMoreThanOwned', 'AddressIsNotEthMirror', 'AddressIsZero', 'UnsupportedOperation', 'NotSufficientFounds', 'UserIsNotAllowedToNest', 'SourceCollectionIsNotAllowedToNest', 'CollectionFieldSizeExceeded', 'NoSpaceForProperty', 'PropertyLimitReached', 'PropertyKeyIsTooLong', 'InvalidCharacterInPropertyKey', 'EmptyPropertyKey', 'CollectionIsExternal', 'CollectionIsInternal', 'ConfirmSponsorshipFail', 'UserIsNotCollectionAdmin']3284 },3291 },3285 /**3292 /**3286 * Lookup425: pallet_fungible::pallet::Error<T>3293 * Lookup425: pallet_fungible::pallet::Error<T>tests/src/interfaces/types-lookup.tsdiffbeforeafterboth2493 readonly itemId: u32;2493 readonly itemId: u32;2494 readonly amount: u128;2494 readonly amount: u128;2495 } & Struct;2495 } & Struct;2496 readonly isApproveFrom: boolean;2497 readonly asApproveFrom: {2498 readonly from: PalletEvmAccountBasicCrossAccountIdRepr;2499 readonly to: PalletEvmAccountBasicCrossAccountIdRepr;2500 readonly collectionId: u32;2501 readonly itemId: u32;2502 readonly amount: u128;2503 } & Struct;2496 readonly isTransferFrom: boolean;2504 readonly isTransferFrom: boolean;2497 readonly asTransferFrom: {2505 readonly asTransferFrom: {2498 readonly from: PalletEvmAccountBasicCrossAccountIdRepr;2506 readonly from: PalletEvmAccountBasicCrossAccountIdRepr;2532 readonly collectionId: u32;2540 readonly collectionId: u32;2533 readonly itemId: u32;2541 readonly itemId: u32;2534 } & Struct;2542 } & Struct;2535 readonly type: 'CreateCollection' | 'CreateCollectionEx' | 'DestroyCollection' | 'AddToAllowList' | 'RemoveFromAllowList' | 'ChangeCollectionOwner' | 'AddCollectionAdmin' | 'RemoveCollectionAdmin' | 'SetCollectionSponsor' | 'ConfirmSponsorship' | 'RemoveCollectionSponsor' | 'CreateItem' | 'CreateMultipleItems' | 'SetCollectionProperties' | 'DeleteCollectionProperties' | 'SetTokenProperties' | 'DeleteTokenProperties' | 'SetTokenPropertyPermissions' | 'CreateMultipleItemsEx' | 'SetTransfersEnabledFlag' | 'BurnItem' | 'BurnFrom' | 'Transfer' | 'Approve' | 'TransferFrom' | 'SetCollectionLimits' | 'SetCollectionPermissions' | 'Repartition' | 'SetAllowanceForAll' | 'ForceRepairCollection' | 'ForceRepairItem';2543 readonly type: 'CreateCollection' | 'CreateCollectionEx' | 'DestroyCollection' | 'AddToAllowList' | 'RemoveFromAllowList' | 'ChangeCollectionOwner' | 'AddCollectionAdmin' | 'RemoveCollectionAdmin' | 'SetCollectionSponsor' | 'ConfirmSponsorship' | 'RemoveCollectionSponsor' | 'CreateItem' | 'CreateMultipleItems' | 'SetCollectionProperties' | 'DeleteCollectionProperties' | 'SetTokenProperties' | 'DeleteTokenProperties' | 'SetTokenPropertyPermissions' | 'CreateMultipleItemsEx' | 'SetTransfersEnabledFlag' | 'BurnItem' | 'BurnFrom' | 'Transfer' | 'Approve' | 'ApproveFrom' | 'TransferFrom' | 'SetCollectionLimits' | 'SetCollectionPermissions' | 'Repartition' | 'SetAllowanceForAll' | 'ForceRepairCollection' | 'ForceRepairItem';2536 }2544 }253725452538 /** @name UpDataStructsCollectionMode (236) */2546 /** @name UpDataStructsCollectionMode (236) */3564 readonly isTokenValueTooLow: boolean;3572 readonly isTokenValueTooLow: boolean;3565 readonly isApprovedValueTooLow: boolean;3573 readonly isApprovedValueTooLow: boolean;3566 readonly isCantApproveMoreThanOwned: boolean;3574 readonly isCantApproveMoreThanOwned: boolean;3575 readonly isAddressIsNotEthMirror: boolean;3567 readonly isAddressIsZero: boolean;3576 readonly isAddressIsZero: boolean;3568 readonly isUnsupportedOperation: boolean;3577 readonly isUnsupportedOperation: boolean;3569 readonly isNotSufficientFounds: boolean;3578 readonly isNotSufficientFounds: boolean;3579 readonly isCollectionIsInternal: boolean;3588 readonly isCollectionIsInternal: boolean;3580 readonly isConfirmSponsorshipFail: boolean;3589 readonly isConfirmSponsorshipFail: boolean;3581 readonly isUserIsNotCollectionAdmin: boolean;3590 readonly isUserIsNotCollectionAdmin: boolean;3582 readonly type: 'CollectionNotFound' | 'MustBeTokenOwner' | 'NoPermission' | 'CantDestroyNotEmptyCollection' | 'PublicMintingNotAllowed' | 'AddressNotInAllowlist' | 'CollectionNameLimitExceeded' | 'CollectionDescriptionLimitExceeded' | 'CollectionTokenPrefixLimitExceeded' | 'TotalCollectionsLimitExceeded' | 'CollectionAdminCountExceeded' | 'CollectionLimitBoundsExceeded' | 'OwnerPermissionsCantBeReverted' | 'TransferNotAllowed' | 'AccountTokenLimitExceeded' | 'CollectionTokenLimitExceeded' | 'MetadataFlagFrozen' | 'TokenNotFound' | 'TokenValueTooLow' | 'ApprovedValueTooLow' | 'CantApproveMoreThanOwned' | 'AddressIsZero' | 'UnsupportedOperation' | 'NotSufficientFounds' | 'UserIsNotAllowedToNest' | 'SourceCollectionIsNotAllowedToNest' | 'CollectionFieldSizeExceeded' | 'NoSpaceForProperty' | 'PropertyLimitReached' | 'PropertyKeyIsTooLong' | 'InvalidCharacterInPropertyKey' | 'EmptyPropertyKey' | 'CollectionIsExternal' | 'CollectionIsInternal' | 'ConfirmSponsorshipFail' | 'UserIsNotCollectionAdmin';3591 readonly type: 'CollectionNotFound' | 'MustBeTokenOwner' | 'NoPermission' | 'CantDestroyNotEmptyCollection' | 'PublicMintingNotAllowed' | 'AddressNotInAllowlist' | 'CollectionNameLimitExceeded' | 'CollectionDescriptionLimitExceeded' | 'CollectionTokenPrefixLimitExceeded' | 'TotalCollectionsLimitExceeded' | 'CollectionAdminCountExceeded' | 'CollectionLimitBoundsExceeded' | 'OwnerPermissionsCantBeReverted' | 'TransferNotAllowed' | 'AccountTokenLimitExceeded' | 'CollectionTokenLimitExceeded' | 'MetadataFlagFrozen' | 'TokenNotFound' | 'TokenValueTooLow' | 'ApprovedValueTooLow' | 'CantApproveMoreThanOwned' | 'AddressIsNotEthMirror' | 'AddressIsZero' | 'UnsupportedOperation' | 'NotSufficientFounds' | 'UserIsNotAllowedToNest' | 'SourceCollectionIsNotAllowedToNest' | 'CollectionFieldSizeExceeded' | 'NoSpaceForProperty' | 'PropertyLimitReached' | 'PropertyKeyIsTooLong' | 'InvalidCharacterInPropertyKey' | 'EmptyPropertyKey' | 'CollectionIsExternal' | 'CollectionIsInternal' | 'ConfirmSponsorshipFail' | 'UserIsNotCollectionAdmin';3583 }3592 }358435933585 /** @name PalletFungibleError (425) */3594 /** @name PalletFungibleError (425) */tests/src/util/playgrounds/unique.tsdiffbeforeafterboth633 let call = this.getApi() as any;633 let call = this.getApi() as any;634 for(const part of apiCall.slice(4).split('.')) {634 for(const part of apiCall.slice(4).split('.')) {635 call = call[part];635 call = call[part];636 if (!call) {637 const advice = part.includes('_') ? ' Looks like it needs to be converted to camel case.' : '';638 throw Error(`Function ${part} of api call ${apiCall} not found.${advice}`);639 }636 }640 }637 return call(...params);641 return call(...params);638 }642 }1258 return this.helper.util.findCollectionInEvents(approveResult.result.events, collectionId, 'common', 'Approved');1262 return this.helper.util.findCollectionInEvents(approveResult.result.events, collectionId, 'common', 'Approved');1259 }1263 }12641265 /**1266 * Set, change, or remove approved address to transfer the ownership of the NFT from eth mirror.1267 *1268 * @param signer keyring of signer1269 * @param collectionId ID of collection1270 * @param tokenId ID of token1271 * @param fromAddressObj Signer's Ethereum address containing her tokens1272 * @param toAddressObj Substrate or Ethereum address which gets approved use of the signer's tokens1273 * @param amount amount of token to be approved. For NFT must be set to 1n1274 * @returns ```true``` if extrinsic success, otherwise ```false```1275 */1276 async approveTokenFrom(signer: IKeyringPair, collectionId: number, tokenId: number, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId, amount=1n) {1277 const approveResult = await this.helper.executeExtrinsic(1278 signer,1279 'api.tx.unique.approveFrom', [fromAddressObj, toAddressObj, collectionId, tokenId, amount],1280 true, // `Unable to approve token for ${label}`,1281 );12821283 return this.helper.util.findCollectionInEvents(approveResult.result.events, collectionId, 'common', 'Approved');1284 }12851286 /**1287 * Set, change, or remove approved address to transfer the ownership of the NFT from eth mirror.1288 *1289 * @param signer keyring of signer1290 * @param collectionId ID of collection1291 * @param tokenId ID of token1292 * @param toAddressObj Substrate or Ethereum address which gets approved use of the signer's tokens1293 * @param amount amount of token to be approved. For NFT must be set to 1n1294 * @returns ```true``` if extrinsic success, otherwise ```false```1295 */1296 async approveTokenFromEth(signer: IKeyringPair, collectionId: number, tokenId: number, toAddressObj: ICrossAccountId, amount=1n) {1297 const ethMirror = CrossAccountId.fromKeyring(signer).toEthereum();1298 return await this.approveTokenFrom(signer, collectionId, tokenId, ethMirror, toAddressObj, amount);1299 }126013001261 /**1301 /**1262 * Get the amount of token pieces approved to transfer or burn. Normally 0.1302 * Get the amount of token pieces approved to transfer or burn. Normally 0.1756 * @example approveToken(aliceKeyring, 10, 5, {Substrate: "5DyN4Y92vZCjv38fg..."})1796 * @example approveToken(aliceKeyring, 10, 5, {Substrate: "5DyN4Y92vZCjv38fg..."})1757 * @returns ```true``` if extrinsic success, otherwise ```false```1797 * @returns ```true``` if extrinsic success, otherwise ```false```1758 */1798 */1759 approveToken(signer: IKeyringPair, collectionId: number, tokenId: number, toAddressObj: ICrossAccountId) {1799 approveToken(signer: IKeyringPair, collectionId: number, tokenId: number, toAddressObj: ICrossAccountId, amount=1n) {1760 return super.approveToken(signer, collectionId, tokenId, toAddressObj, 1n);1800 return super.approveToken(signer, collectionId, tokenId, toAddressObj, amount);1761 }1801 }1762}1802}17631803