difftreelog
feat add ApproveFrom eth mirror
in: master
26 files changed
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -746,6 +746,8 @@
ApprovedValueTooLow,
/// Tried to approve more than owned
CantApproveMoreThanOwned,
+ /// Only spending from eth mirror could be approved
+ AddressIsNotEthMirror,
/// Can't transfer tokens to ethereum zero address
AddressIsZero,
@@ -1797,6 +1799,9 @@
/// The price of setting the permission of the operation from another user.
fn approve() -> Weight;
+ /// The price of setting the permission of the operation from another user for eth mirror.
+ fn approve_from() -> Weight;
+
/// Transfer price from another user.
fn transfer_from() -> Weight;
@@ -2008,6 +2013,22 @@
amount: u128,
) -> DispatchResultWithPostInfo;
+ /// Grant access to another account to transfer parts of the token owned by the calling user's eth mirror via [Self::transfer_from].
+ ///
+ /// * `sender` - The user who grants access to the token.
+ /// * `from` - Spender's eth mirror.
+ /// * `to` - The user to whom the rights are granted.
+ /// * `token` - The token to which access is granted.
+ /// * `amount` - The amount of pieces that another user can dispose of.
+ fn approve_from(
+ &self,
+ sender: T::CrossAccountId,
+ from: T::CrossAccountId,
+ to: T::CrossAccountId,
+ token: TokenId,
+ amount: u128,
+ ) -> DispatchResultWithPostInfo;
+
/// Send parts of a token owned by another user.
///
/// Before calling this method, you must grant rights to the calling user via [`Self::approve`].
pallets/evm-contract-helpers/src/stubs/ContractHelpers.rawdiffbeforeafterbothbinary blob — no preview
pallets/evm-contract-helpers/src/stubs/ContractHelpers.soldiffbeforeafterboth--- a/pallets/evm-contract-helpers/src/stubs/ContractHelpers.sol
+++ b/pallets/evm-contract-helpers/src/stubs/ContractHelpers.sol
@@ -283,8 +283,8 @@
/// Ethereum representation of Optional value with CrossAddress.
struct OptionCrossAddress {
- /// TODO: field description
+ /// Whether or not this CrossAdress is valid and has meaning.
bool status;
- /// TODO: field description
+ /// The underlying CrossAddress value. If the status is false, can be set to whatever.
CrossAddress value;
}
pallets/fungible/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/fungible/src/benchmarking.rs
+++ b/pallets/fungible/src/benchmarking.rs
@@ -82,6 +82,16 @@
<Pallet<T>>::create_item(&collection, &owner, (sender.clone(), 200), &Unlimited)?;
}: {<Pallet<T>>::set_allowance(&collection, &sender, &spender, 100)?}
+ approve_from {
+ bench_init!{
+ owner: sub; collection: collection(owner);
+ owner: cross_from_sub; sender: cross_sub; spender: cross_sub;
+
+ };
+ let owner_eth = T::CrossAccountId::from_eth(*sender.as_eth());
+ <Pallet<T>>::create_item(&collection, &owner, (owner_eth.clone(), 200), &Unlimited)?;
+ }: {<Pallet<T>>::set_allowance_for(&collection, &sender, &owner_eth, &spender, 100)?}
+
transfer_from {
bench_init!{
owner: sub; collection: collection(owner);
pallets/fungible/src/common.rsdiffbeforeafterboth--- a/pallets/fungible/src/common.rs
+++ b/pallets/fungible/src/common.rs
@@ -87,6 +87,10 @@
<SelfWeightOf<T>>::approve()
}
+ fn approve_from() -> Weight {
+ <SelfWeightOf<T>>::approve_from()
+ }
+
fn transfer_from() -> Weight {
<SelfWeightOf<T>>::transfer_from()
}
@@ -254,6 +258,25 @@
)
}
+ fn approve_from(
+ &self,
+ sender: T::CrossAccountId,
+ from: T::CrossAccountId,
+ to: T::CrossAccountId,
+ token: TokenId,
+ amount: u128,
+ ) -> DispatchResultWithPostInfo {
+ ensure!(
+ token == TokenId::default(),
+ <Error<T>>::FungibleItemsHaveNoId
+ );
+
+ with_weight(
+ <Pallet<T>>::set_allowance_for(self, &sender, &from, &to, amount),
+ <CommonWeights<T>>::approve_from(),
+ )
+ }
+
fn transfer_from(
&self,
sender: T::CrossAccountId,
pallets/fungible/src/lib.rsdiffbeforeafterboth--- a/pallets/fungible/src/lib.rs
+++ b/pallets/fungible/src/lib.rs
@@ -613,6 +613,45 @@
Ok(())
}
+ /// Set allowance for the spender to `transfer` or `burn` owner's tokens from eth mirror.
+ ///
+ /// - `collection`: Collection that contains the token
+ /// - `sender`: Owner of tokens that sets the allowance.
+ /// - `from`: Owner's eth mirror.
+ /// - `to`: Recipient of the allowance rights.
+ /// - `amount`: Amount of tokens the spender is allowed to `transfer` or `burn`.
+ pub fn set_allowance_for(
+ collection: &FungibleHandle<T>,
+ sender: &T::CrossAccountId,
+ from: &T::CrossAccountId,
+ to: &T::CrossAccountId,
+ amount: u128,
+ ) -> DispatchResult {
+ if collection.permissions.access() == AccessMode::AllowList {
+ collection.check_allowlist(sender)?;
+ collection.check_allowlist(from)?;
+ collection.check_allowlist(to)?;
+ }
+
+ ensure!(
+ *sender.as_eth() == *from.as_eth(),
+ <CommonError<T>>::AddressIsNotEthMirror
+ );
+
+ if <Balance<T>>::get((collection.id, from)) < amount {
+ ensure!(
+ collection.limits.owner_can_transfer()
+ && (collection.is_owner_or_admin(sender) || collection.is_owner_or_admin(from)),
+ <CommonError<T>>::CantApproveMoreThanOwned
+ );
+ }
+
+ // =========
+
+ Self::set_allowance_unchecked(collection, from, to, amount);
+ Ok(())
+ }
+
/// Checks if a non-owner has (enough) allowance from the owner to perform operations on the tokens.
/// Returns the expected remaining allowance - it should be set manually if the transaction proceeds.
///
pallets/fungible/src/weights.rsdiffbeforeafterboth--- a/pallets/fungible/src/weights.rs
+++ b/pallets/fungible/src/weights.rs
@@ -39,6 +39,7 @@
fn burn_item() -> Weight;
fn transfer() -> Weight;
fn approve() -> Weight;
+ fn approve_from() -> Weight;
fn transfer_from() -> Weight;
fn burn_from() -> Weight;
}
@@ -84,6 +85,13 @@
.saturating_add(T::DbWeight::get().reads(1 as u64))
.saturating_add(T::DbWeight::get().writes(1 as u64))
}
+ // Storage: Fungible Balance (r:1 w:0)
+ // Storage: Fungible Allowance (r:0 w:1)
+ fn approve_from() -> Weight {
+ Weight::from_ref_time(19_817_000 as u64)
+ .saturating_add(T::DbWeight::get().reads(1 as u64))
+ .saturating_add(T::DbWeight::get().writes(1 as u64))
+ }
// Storage: Fungible Allowance (r:1 w:1)
// Storage: Fungible Balance (r:2 w:2)
fn transfer_from() -> Weight {
@@ -141,6 +149,13 @@
.saturating_add(RocksDbWeight::get().reads(1 as u64))
.saturating_add(RocksDbWeight::get().writes(1 as u64))
}
+ // Storage: Fungible Balance (r:1 w:0)
+ // Storage: Fungible Allowance (r:0 w:1)
+ fn approve_from() -> Weight {
+ Weight::from_ref_time(19_817_000 as u64)
+ .saturating_add(RocksDbWeight::get().reads(1 as u64))
+ .saturating_add(RocksDbWeight::get().writes(1 as u64))
+ }
// Storage: Fungible Allowance (r:1 w:1)
// Storage: Fungible Balance (r:2 w:2)
fn transfer_from() -> Weight {
pallets/nonfungible/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/benchmarking.rs
+++ b/pallets/nonfungible/src/benchmarking.rs
@@ -134,6 +134,15 @@
let item = create_max_item(&collection, &owner, sender.clone())?;
}: {<Pallet<T>>::set_allowance(&collection, &sender, item, Some(&spender))?}
+ approve_from {
+ bench_init!{
+ owner: sub; collection: collection(owner);
+ owner: cross_from_sub; sender: cross_sub; spender: cross_sub;
+ };
+ let owner_eth = T::CrossAccountId::from_eth(*sender.as_eth());
+ let item = create_max_item(&collection, &owner, owner_eth.clone())?;
+ }: {<Pallet<T>>::set_allowance_for(&collection, &sender, &owner_eth, item, Some(&spender))?}
+
transfer_from {
bench_init!{
owner: sub; collection: collection(owner);
pallets/nonfungible/src/common.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/common.rs
+++ b/pallets/nonfungible/src/common.rs
@@ -102,6 +102,10 @@
<SelfWeightOf<T>>::approve()
}
+ fn approve_from() -> Weight {
+ <SelfWeightOf<T>>::approve_from()
+ }
+
fn transfer_from() -> Weight {
<SelfWeightOf<T>>::transfer_from()
}
@@ -353,6 +357,26 @@
)
}
+ fn approve_from(
+ &self,
+ sender: T::CrossAccountId,
+ from: T::CrossAccountId,
+ to: T::CrossAccountId,
+ token: TokenId,
+ amount: u128,
+ ) -> DispatchResultWithPostInfo {
+ ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);
+
+ with_weight(
+ if amount == 1 {
+ <Pallet<T>>::set_allowance_for(self, &sender, &from, token, Some(&to))
+ } else {
+ <Pallet<T>>::set_allowance_for(self, &sender, &from, token, None)
+ },
+ <CommonWeights<T>>::approve_from(),
+ )
+ }
+
fn transfer_from(
&self,
sender: T::CrossAccountId,
pallets/nonfungible/src/lib.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -1171,6 +1171,51 @@
Ok(())
}
+ /// Set allowance for the spender to `transfer` or `burn` sender's token from eth mirror.
+ ///
+ /// - `from`: Address of sender's eth mirror.
+ /// - `to`: Adress of spender.
+ /// - `token`: Token the spender is allowed to `transfer` or `burn`.
+ pub fn set_allowance_for(
+ collection: &NonfungibleHandle<T>,
+ sender: &T::CrossAccountId,
+ from: &T::CrossAccountId,
+ token: TokenId,
+ to: Option<&T::CrossAccountId>,
+ ) -> DispatchResult {
+ if collection.permissions.access() == AccessMode::AllowList {
+ collection.check_allowlist(sender)?;
+ collection.check_allowlist(from)?;
+ if let Some(to) = to {
+ collection.check_allowlist(to)?;
+ }
+ }
+
+ if let Some(to) = to {
+ <PalletCommon<T>>::ensure_correct_receiver(to)?;
+ }
+
+ ensure!(
+ *sender.as_eth() == *from.as_eth(),
+ <CommonError<T>>::AddressIsNotEthMirror
+ );
+
+ let token_data =
+ <TokenData<T>>::get((collection.id, token)).ok_or(<CommonError<T>>::TokenNotFound)?;
+ if token_data.owner != *from {
+ ensure!(
+ collection.limits.owner_can_transfer()
+ && (collection.is_owner_or_admin(sender) || collection.is_owner_or_admin(from)),
+ <CommonError<T>>::CantApproveMoreThanOwned
+ );
+ }
+
+ // =========
+
+ Self::set_allowance_unchecked(collection, from, token, to, false);
+ Ok(())
+ }
+
/// Checks allowance for the spender to use the token.
fn check_allowed(
collection: &NonfungibleHandle<T>,
pallets/nonfungible/src/weights.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/weights.rs
+++ b/pallets/nonfungible/src/weights.rs
@@ -42,6 +42,7 @@
fn burn_recursively_breadth_plus_self_plus_self_per_each_raw(b: u32, ) -> Weight;
fn transfer() -> Weight;
fn approve() -> Weight;
+ fn approve_from() -> Weight;
fn transfer_from() -> Weight;
fn burn_from() -> Weight;
fn set_token_property_permissions(b: u32, ) -> Weight;
@@ -147,6 +148,13 @@
.saturating_add(T::DbWeight::get().reads(2 as u64))
.saturating_add(T::DbWeight::get().writes(1 as u64))
}
+ // Storage: Nonfungible TokenData (r:1 w:0)
+ // Storage: Nonfungible Allowance (r:1 w:1)
+ fn approve_from() -> Weight {
+ Weight::from_ref_time(18_965_000 as u64)
+ .saturating_add(T::DbWeight::get().reads(2 as u64))
+ .saturating_add(T::DbWeight::get().writes(1 as u64))
+ }
// Storage: Nonfungible Allowance (r:1 w:1)
// Storage: Nonfungible TokenData (r:1 w:1)
// Storage: Nonfungible AccountBalance (r:2 w:2)
@@ -310,6 +318,13 @@
.saturating_add(RocksDbWeight::get().reads(2 as u64))
.saturating_add(RocksDbWeight::get().writes(1 as u64))
}
+ // Storage: Nonfungible TokenData (r:1 w:0)
+ // Storage: Nonfungible Allowance (r:1 w:1)
+ fn approve_from() -> Weight {
+ Weight::from_ref_time(18_965_000 as u64)
+ .saturating_add(RocksDbWeight::get().reads(2 as u64))
+ .saturating_add(RocksDbWeight::get().writes(1 as u64))
+ }
// Storage: Nonfungible Allowance (r:1 w:1)
// Storage: Nonfungible TokenData (r:1 w:1)
// Storage: Nonfungible AccountBalance (r:2 w:2)
pallets/refungible/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/refungible/src/benchmarking.rs
+++ b/pallets/refungible/src/benchmarking.rs
@@ -163,6 +163,15 @@
let item = create_max_item(&collection, &owner, [(sender.clone(), 200)])?;
}: {<Pallet<T>>::set_allowance(&collection, &sender, &spender, item, 100)?}
+ approve_from {
+ bench_init!{
+ owner: sub; collection: collection(owner);
+ owner: cross_from_sub; sender: cross_sub; spender: cross_sub;
+ };
+ let owner_eth = T::CrossAccountId::from_eth(*sender.as_eth());
+ let item = create_max_item(&collection, &owner, [(owner_eth.clone(), 200)])?;
+ }: {<Pallet<T>>::set_allowance_for(&collection, &sender, &owner_eth, &spender, item, 100)?}
+
transfer_from_normal {
bench_init!{
owner: sub; collection: collection(owner);
pallets/refungible/src/common.rsdiffbeforeafterboth--- a/pallets/refungible/src/common.rs
+++ b/pallets/refungible/src/common.rs
@@ -127,6 +127,10 @@
<SelfWeightOf<T>>::approve()
}
+ fn approve_from() -> Weight {
+ <SelfWeightOf<T>>::approve_from()
+ }
+
fn transfer_from() -> Weight {
max_weight_of!(
transfer_from_normal(),
@@ -314,6 +318,20 @@
)
}
+ fn approve_from(
+ &self,
+ sender: T::CrossAccountId,
+ from: T::CrossAccountId,
+ to: T::CrossAccountId,
+ token_id: TokenId,
+ amount: u128,
+ ) -> DispatchResultWithPostInfo {
+ with_weight(
+ <Pallet<T>>::set_allowance_for(self, &sender, &from, &to, token_id, amount),
+ <CommonWeights<T>>::approve_from(),
+ )
+ }
+
fn transfer_from(
&self,
sender: T::CrossAccountId,
pallets/refungible/src/lib.rsdiffbeforeafterboth--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -1102,6 +1102,47 @@
Ok(())
}
+ /// Set allowance to spend from sender's eth mirror
+ ///
+ /// - `from`: Address of sender's eth mirror.
+ /// - `to`: Adress of spender.
+ /// - `amount`: Amount of token pieces the spender is allowed to `transfer` or `burn.
+ pub fn set_allowance_for(
+ collection: &RefungibleHandle<T>,
+ sender: &T::CrossAccountId,
+ from: &T::CrossAccountId,
+ to: &T::CrossAccountId,
+ token_id: TokenId,
+ amount: u128,
+ ) -> DispatchResult {
+ if collection.permissions.access() == AccessMode::AllowList {
+ collection.check_allowlist(sender)?;
+ collection.check_allowlist(from)?;
+ collection.check_allowlist(to)?;
+ }
+
+ <PalletCommon<T>>::ensure_correct_receiver(to)?;
+
+ ensure!(
+ *sender.as_eth() == *from.as_eth(),
+ <CommonError<T>>::AddressIsNotEthMirror
+ );
+
+ if <Balance<T>>::get((collection.id, token_id, from)) < amount {
+ ensure!(
+ collection.limits.owner_can_transfer()
+ && (collection.is_owner_or_admin(sender) || collection.is_owner_or_admin(from))
+ && Self::token_exists(collection, token_id),
+ <CommonError<T>>::CantApproveMoreThanOwned
+ );
+ }
+
+ // =========
+
+ Self::set_allowance_unchecked(collection, from, to, token_id, amount);
+ Ok(())
+ }
+
/// Returns allowance, which should be set after transaction
fn check_allowed(
collection: &RefungibleHandle<T>,
pallets/refungible/src/weights.rsdiffbeforeafterboth1// Template adopted from https://github.com/paritytech/substrate/blob/master/.maintain/frame-weight-template.hbs23//! Autogenerated weights for pallet_refungible4//!5//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev6//! DATE: 2022-12-26, STEPS: `50`, REPEAT: 80, LOW RANGE: `[]`, HIGH RANGE: `[]`7//! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 102489// Executed Command:10// target/release/unique-collator11// benchmark12// pallet13// --pallet14// pallet-refungible15// --wasm-execution16// compiled17// --extrinsic18// *19// --template20// .maintain/frame-weight-template.hbs21// --steps=5022// --repeat=8023// --heap-pages=409624// --output=./pallets/refungible/src/weights.rs2526#![cfg_attr(rustfmt, rustfmt_skip)]27#![allow(unused_parens)]28#![allow(unused_imports)]29#![allow(missing_docs)]30#![allow(clippy::unnecessary_cast)]3132use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};33use sp_std::marker::PhantomData;3435/// Weight functions needed for pallet_refungible.36pub trait WeightInfo {37 fn create_item() -> Weight;38 fn create_multiple_items(b: u32, ) -> Weight;39 fn create_multiple_items_ex_multiple_items(b: u32, ) -> Weight;40 fn create_multiple_items_ex_multiple_owners(b: u32, ) -> Weight;41 fn burn_item_partial() -> Weight;42 fn burn_item_fully() -> Weight;43 fn transfer_normal() -> Weight;44 fn transfer_creating() -> Weight;45 fn transfer_removing() -> Weight;46 fn transfer_creating_removing() -> Weight;47 fn approve() -> Weight;48 fn transfer_from_normal() -> Weight;49 fn transfer_from_creating() -> Weight;50 fn transfer_from_removing() -> Weight;51 fn transfer_from_creating_removing() -> Weight;52 fn burn_from() -> Weight;53 fn set_token_property_permissions(b: u32, ) -> Weight;54 fn set_token_properties(b: u32, ) -> Weight;55 fn delete_token_properties(b: u32, ) -> Weight;56 fn repartition_item() -> Weight;57 fn token_owner() -> Weight;58 fn set_allowance_for_all() -> Weight;59 fn allowance_for_all() -> Weight;60 fn repair_item() -> Weight;61}6263/// Weights for pallet_refungible using the Substrate node and recommended hardware.64pub struct SubstrateWeight<T>(PhantomData<T>);65impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {66 // Storage: Refungible TokensMinted (r:1 w:1)67 // Storage: Refungible AccountBalance (r:1 w:1)68 // Storage: Refungible Balance (r:0 w:1)69 // Storage: Refungible TotalSupply (r:0 w:1)70 // Storage: Refungible Owned (r:0 w:1)71 fn create_item() -> Weight {72 Weight::from_ref_time(32_864_000 as u64)73 .saturating_add(T::DbWeight::get().reads(2 as u64))74 .saturating_add(T::DbWeight::get().writes(5 as u64))75 }76 // Storage: Refungible TokensMinted (r:1 w:1)77 // Storage: Refungible AccountBalance (r:1 w:1)78 // Storage: Refungible Balance (r:0 w:4)79 // Storage: Refungible TotalSupply (r:0 w:4)80 // Storage: Refungible Owned (r:0 w:4)81 fn create_multiple_items(b: u32, ) -> Weight {82 Weight::from_ref_time(11_880_472 as u64)83 // Standard Error: 5_24084 .saturating_add(Weight::from_ref_time(6_556_575 as u64).saturating_mul(b as u64))85 .saturating_add(T::DbWeight::get().reads(2 as u64))86 .saturating_add(T::DbWeight::get().writes(2 as u64))87 .saturating_add(T::DbWeight::get().writes((3 as u64).saturating_mul(b as u64)))88 }89 // Storage: Refungible TokensMinted (r:1 w:1)90 // Storage: Refungible AccountBalance (r:4 w:4)91 // Storage: Refungible Balance (r:0 w:4)92 // Storage: Refungible TotalSupply (r:0 w:4)93 // Storage: Refungible Owned (r:0 w:4)94 fn create_multiple_items_ex_multiple_items(b: u32, ) -> Weight {95 Weight::from_ref_time(11_644_173 as u64)96 // Standard Error: 5_87697 .saturating_add(Weight::from_ref_time(8_214_607 as u64).saturating_mul(b as u64))98 .saturating_add(T::DbWeight::get().reads(1 as u64))99 .saturating_add(T::DbWeight::get().reads((1 as u64).saturating_mul(b as u64)))100 .saturating_add(T::DbWeight::get().writes(1 as u64))101 .saturating_add(T::DbWeight::get().writes((4 as u64).saturating_mul(b as u64)))102 }103 // Storage: Refungible TokensMinted (r:1 w:1)104 // Storage: Refungible TotalSupply (r:0 w:1)105 // Storage: Refungible AccountBalance (r:4 w:4)106 // Storage: Refungible Balance (r:0 w:4)107 // Storage: Refungible Owned (r:0 w:4)108 fn create_multiple_items_ex_multiple_owners(b: u32, ) -> Weight {109 Weight::from_ref_time(21_817_067 as u64)110 // Standard Error: 5_215111 .saturating_add(Weight::from_ref_time(6_084_938 as u64).saturating_mul(b as u64))112 .saturating_add(T::DbWeight::get().reads(1 as u64))113 .saturating_add(T::DbWeight::get().reads((1 as u64).saturating_mul(b as u64)))114 .saturating_add(T::DbWeight::get().writes(2 as u64))115 .saturating_add(T::DbWeight::get().writes((3 as u64).saturating_mul(b as u64)))116 }117 // Storage: Refungible Balance (r:3 w:1)118 // Storage: Refungible TotalSupply (r:1 w:1)119 // Storage: Refungible AccountBalance (r:1 w:1)120 // Storage: Refungible Owned (r:0 w:1)121 fn burn_item_partial() -> Weight {122 Weight::from_ref_time(47_087_000 as u64)123 .saturating_add(T::DbWeight::get().reads(5 as u64))124 .saturating_add(T::DbWeight::get().writes(4 as u64))125 }126 // Storage: Refungible Balance (r:1 w:1)127 // Storage: Refungible TotalSupply (r:1 w:1)128 // Storage: Refungible AccountBalance (r:1 w:1)129 // Storage: Refungible TokensBurnt (r:1 w:1)130 // Storage: Refungible Owned (r:0 w:1)131 // Storage: Refungible TokenProperties (r:0 w:1)132 fn burn_item_fully() -> Weight {133 Weight::from_ref_time(40_135_000 as u64)134 .saturating_add(T::DbWeight::get().reads(4 as u64))135 .saturating_add(T::DbWeight::get().writes(6 as u64))136 }137 // Storage: Refungible Balance (r:2 w:2)138 // Storage: Refungible TotalSupply (r:1 w:0)139 fn transfer_normal() -> Weight {140 Weight::from_ref_time(30_749_000 as u64)141 .saturating_add(T::DbWeight::get().reads(3 as u64))142 .saturating_add(T::DbWeight::get().writes(2 as u64))143 }144 // Storage: Refungible Balance (r:2 w:2)145 // Storage: Refungible AccountBalance (r:1 w:1)146 // Storage: Refungible TotalSupply (r:1 w:0)147 // Storage: Refungible Owned (r:0 w:1)148 fn transfer_creating() -> Weight {149 Weight::from_ref_time(33_565_000 as u64)150 .saturating_add(T::DbWeight::get().reads(4 as u64))151 .saturating_add(T::DbWeight::get().writes(4 as u64))152 }153 // Storage: Refungible Balance (r:2 w:2)154 // Storage: Refungible AccountBalance (r:1 w:1)155 // Storage: Refungible TotalSupply (r:1 w:0)156 // Storage: Refungible Owned (r:0 w:1)157 fn transfer_removing() -> Weight {158 Weight::from_ref_time(37_406_000 as u64)159 .saturating_add(T::DbWeight::get().reads(4 as u64))160 .saturating_add(T::DbWeight::get().writes(4 as u64))161 }162 // Storage: Refungible Balance (r:2 w:2)163 // Storage: Refungible AccountBalance (r:2 w:2)164 // Storage: Refungible TotalSupply (r:1 w:0)165 // Storage: Refungible Owned (r:0 w:2)166 fn transfer_creating_removing() -> Weight {167 Weight::from_ref_time(36_689_000 as u64)168 .saturating_add(T::DbWeight::get().reads(5 as u64))169 .saturating_add(T::DbWeight::get().writes(6 as u64))170 }171 // Storage: Refungible Balance (r:1 w:0)172 // Storage: Refungible Allowance (r:0 w:1)173 fn approve() -> Weight {174 Weight::from_ref_time(23_177_000 as u64)175 .saturating_add(T::DbWeight::get().reads(1 as u64))176 .saturating_add(T::DbWeight::get().writes(1 as u64))177 }178 // Storage: Refungible Allowance (r:1 w:1)179 // Storage: Refungible CollectionAllowance (r:1 w:0)180 // Storage: Refungible Balance (r:2 w:2)181 // Storage: Refungible TotalSupply (r:1 w:0)182 fn transfer_from_normal() -> Weight {183 Weight::from_ref_time(41_288_000 as u64)184 .saturating_add(T::DbWeight::get().reads(5 as u64))185 .saturating_add(T::DbWeight::get().writes(3 as u64))186 }187 // Storage: Refungible Allowance (r:1 w:1)188 // Storage: Refungible CollectionAllowance (r:1 w:0)189 // Storage: Refungible Balance (r:2 w:2)190 // Storage: Refungible AccountBalance (r:1 w:1)191 // Storage: Refungible TotalSupply (r:1 w:0)192 // Storage: Refungible Owned (r:0 w:1)193 fn transfer_from_creating() -> Weight {194 Weight::from_ref_time(44_807_000 as u64)195 .saturating_add(T::DbWeight::get().reads(6 as u64))196 .saturating_add(T::DbWeight::get().writes(5 as u64))197 }198 // Storage: Refungible Allowance (r:1 w:1)199 // Storage: Refungible CollectionAllowance (r:1 w:0)200 // Storage: Refungible Balance (r:2 w:2)201 // Storage: Refungible AccountBalance (r:1 w:1)202 // Storage: Refungible TotalSupply (r:1 w:0)203 // Storage: Refungible Owned (r:0 w:1)204 fn transfer_from_removing() -> Weight {205 Weight::from_ref_time(47_297_000 as u64)206 .saturating_add(T::DbWeight::get().reads(6 as u64))207 .saturating_add(T::DbWeight::get().writes(5 as u64))208 }209 // Storage: Refungible Allowance (r:1 w:1)210 // Storage: Refungible CollectionAllowance (r:1 w:0)211 // Storage: Refungible Balance (r:2 w:2)212 // Storage: Refungible AccountBalance (r:2 w:2)213 // Storage: Refungible TotalSupply (r:1 w:0)214 // Storage: Refungible Owned (r:0 w:2)215 fn transfer_from_creating_removing() -> Weight {216 Weight::from_ref_time(47_566_000 as u64)217 .saturating_add(T::DbWeight::get().reads(7 as u64))218 .saturating_add(T::DbWeight::get().writes(7 as u64))219 }220 // Storage: Refungible Allowance (r:1 w:1)221 // Storage: Refungible CollectionAllowance (r:1 w:0)222 // Storage: Refungible Balance (r:1 w:1)223 // Storage: Refungible TotalSupply (r:1 w:1)224 // Storage: Refungible AccountBalance (r:1 w:1)225 // Storage: Refungible TokensBurnt (r:1 w:1)226 // Storage: Refungible Owned (r:0 w:1)227 // Storage: Refungible TokenProperties (r:0 w:1)228 fn burn_from() -> Weight {229 Weight::from_ref_time(53_074_000 as u64)230 .saturating_add(T::DbWeight::get().reads(6 as u64))231 .saturating_add(T::DbWeight::get().writes(7 as u64))232 }233 // Storage: Common CollectionPropertyPermissions (r:1 w:1)234 fn set_token_property_permissions(b: u32, ) -> Weight {235 Weight::from_ref_time(5_170_000 as u64)236 // Standard Error: 40_532237 .saturating_add(Weight::from_ref_time(11_948_016 as u64).saturating_mul(b as u64))238 .saturating_add(T::DbWeight::get().reads(1 as u64))239 .saturating_add(T::DbWeight::get().writes(1 as u64))240 }241 // Storage: Common CollectionPropertyPermissions (r:1 w:0)242 // Storage: Refungible TokenProperties (r:1 w:1)243 fn set_token_properties(b: u32, ) -> Weight {244 Weight::from_ref_time(4_578_000 as u64)245 // Standard Error: 5_396_287246 .saturating_add(Weight::from_ref_time(633_314_546 as u64).saturating_mul(b as u64))247 .saturating_add(T::DbWeight::get().reads(2 as u64))248 .saturating_add(T::DbWeight::get().writes(1 as u64))249 }250 // Storage: Common CollectionPropertyPermissions (r:1 w:0)251 // Storage: Refungible TokenProperties (r:1 w:1)252 fn delete_token_properties(b: u32, ) -> Weight {253 Weight::from_ref_time(4_583_000 as u64)254 // Standard Error: 5_762_380255 .saturating_add(Weight::from_ref_time(696_007_076 as u64).saturating_mul(b as u64))256 .saturating_add(T::DbWeight::get().reads(2 as u64))257 .saturating_add(T::DbWeight::get().writes(1 as u64))258 }259 // Storage: Refungible TotalSupply (r:1 w:1)260 // Storage: Refungible Balance (r:1 w:1)261 fn repartition_item() -> Weight {262 Weight::from_ref_time(25_574_000 as u64)263 .saturating_add(T::DbWeight::get().reads(2 as u64))264 .saturating_add(T::DbWeight::get().writes(2 as u64))265 }266 // Storage: Refungible Balance (r:2 w:0)267 fn token_owner() -> Weight {268 Weight::from_ref_time(9_819_000 as u64)269 .saturating_add(T::DbWeight::get().reads(2 as u64))270 }271 // Storage: Refungible CollectionAllowance (r:0 w:1)272 fn set_allowance_for_all() -> Weight {273 Weight::from_ref_time(16_228_000 as u64)274 .saturating_add(T::DbWeight::get().writes(1 as u64))275 }276 // Storage: Refungible CollectionAllowance (r:1 w:0)277 fn allowance_for_all() -> Weight {278 Weight::from_ref_time(5_374_000 as u64)279 .saturating_add(T::DbWeight::get().reads(1 as u64))280 }281 // Storage: Refungible TokenProperties (r:1 w:1)282 fn repair_item() -> Weight {283 Weight::from_ref_time(5_624_000 as u64)284 .saturating_add(T::DbWeight::get().reads(1 as u64))285 .saturating_add(T::DbWeight::get().writes(1 as u64))286 }287}288289// For backwards compatibility and tests290impl WeightInfo for () {291 // Storage: Refungible TokensMinted (r:1 w:1)292 // Storage: Refungible AccountBalance (r:1 w:1)293 // Storage: Refungible Balance (r:0 w:1)294 // Storage: Refungible TotalSupply (r:0 w:1)295 // Storage: Refungible Owned (r:0 w:1)296 fn create_item() -> Weight {297 Weight::from_ref_time(32_864_000 as u64)298 .saturating_add(RocksDbWeight::get().reads(2 as u64))299 .saturating_add(RocksDbWeight::get().writes(5 as u64))300 }301 // Storage: Refungible TokensMinted (r:1 w:1)302 // Storage: Refungible AccountBalance (r:1 w:1)303 // Storage: Refungible Balance (r:0 w:4)304 // Storage: Refungible TotalSupply (r:0 w:4)305 // Storage: Refungible Owned (r:0 w:4)306 fn create_multiple_items(b: u32, ) -> Weight {307 Weight::from_ref_time(11_880_472 as u64)308 // Standard Error: 5_240309 .saturating_add(Weight::from_ref_time(6_556_575 as u64).saturating_mul(b as u64))310 .saturating_add(RocksDbWeight::get().reads(2 as u64))311 .saturating_add(RocksDbWeight::get().writes(2 as u64))312 .saturating_add(RocksDbWeight::get().writes((3 as u64).saturating_mul(b as u64)))313 }314 // Storage: Refungible TokensMinted (r:1 w:1)315 // Storage: Refungible AccountBalance (r:4 w:4)316 // Storage: Refungible Balance (r:0 w:4)317 // Storage: Refungible TotalSupply (r:0 w:4)318 // Storage: Refungible Owned (r:0 w:4)319 fn create_multiple_items_ex_multiple_items(b: u32, ) -> Weight {320 Weight::from_ref_time(11_644_173 as u64)321 // Standard Error: 5_876322 .saturating_add(Weight::from_ref_time(8_214_607 as u64).saturating_mul(b as u64))323 .saturating_add(RocksDbWeight::get().reads(1 as u64))324 .saturating_add(RocksDbWeight::get().reads((1 as u64).saturating_mul(b as u64)))325 .saturating_add(RocksDbWeight::get().writes(1 as u64))326 .saturating_add(RocksDbWeight::get().writes((4 as u64).saturating_mul(b as u64)))327 }328 // Storage: Refungible TokensMinted (r:1 w:1)329 // Storage: Refungible TotalSupply (r:0 w:1)330 // Storage: Refungible AccountBalance (r:4 w:4)331 // Storage: Refungible Balance (r:0 w:4)332 // Storage: Refungible Owned (r:0 w:4)333 fn create_multiple_items_ex_multiple_owners(b: u32, ) -> Weight {334 Weight::from_ref_time(21_817_067 as u64)335 // Standard Error: 5_215336 .saturating_add(Weight::from_ref_time(6_084_938 as u64).saturating_mul(b as u64))337 .saturating_add(RocksDbWeight::get().reads(1 as u64))338 .saturating_add(RocksDbWeight::get().reads((1 as u64).saturating_mul(b as u64)))339 .saturating_add(RocksDbWeight::get().writes(2 as u64))340 .saturating_add(RocksDbWeight::get().writes((3 as u64).saturating_mul(b as u64)))341 }342 // Storage: Refungible Balance (r:3 w:1)343 // Storage: Refungible TotalSupply (r:1 w:1)344 // Storage: Refungible AccountBalance (r:1 w:1)345 // Storage: Refungible Owned (r:0 w:1)346 fn burn_item_partial() -> Weight {347 Weight::from_ref_time(47_087_000 as u64)348 .saturating_add(RocksDbWeight::get().reads(5 as u64))349 .saturating_add(RocksDbWeight::get().writes(4 as u64))350 }351 // Storage: Refungible Balance (r:1 w:1)352 // Storage: Refungible TotalSupply (r:1 w:1)353 // Storage: Refungible AccountBalance (r:1 w:1)354 // Storage: Refungible TokensBurnt (r:1 w:1)355 // Storage: Refungible Owned (r:0 w:1)356 // Storage: Refungible TokenProperties (r:0 w:1)357 fn burn_item_fully() -> Weight {358 Weight::from_ref_time(40_135_000 as u64)359 .saturating_add(RocksDbWeight::get().reads(4 as u64))360 .saturating_add(RocksDbWeight::get().writes(6 as u64))361 }362 // Storage: Refungible Balance (r:2 w:2)363 // Storage: Refungible TotalSupply (r:1 w:0)364 fn transfer_normal() -> Weight {365 Weight::from_ref_time(30_749_000 as u64)366 .saturating_add(RocksDbWeight::get().reads(3 as u64))367 .saturating_add(RocksDbWeight::get().writes(2 as u64))368 }369 // Storage: Refungible Balance (r:2 w:2)370 // Storage: Refungible AccountBalance (r:1 w:1)371 // Storage: Refungible TotalSupply (r:1 w:0)372 // Storage: Refungible Owned (r:0 w:1)373 fn transfer_creating() -> Weight {374 Weight::from_ref_time(33_565_000 as u64)375 .saturating_add(RocksDbWeight::get().reads(4 as u64))376 .saturating_add(RocksDbWeight::get().writes(4 as u64))377 }378 // Storage: Refungible Balance (r:2 w:2)379 // Storage: Refungible AccountBalance (r:1 w:1)380 // Storage: Refungible TotalSupply (r:1 w:0)381 // Storage: Refungible Owned (r:0 w:1)382 fn transfer_removing() -> Weight {383 Weight::from_ref_time(37_406_000 as u64)384 .saturating_add(RocksDbWeight::get().reads(4 as u64))385 .saturating_add(RocksDbWeight::get().writes(4 as u64))386 }387 // Storage: Refungible Balance (r:2 w:2)388 // Storage: Refungible AccountBalance (r:2 w:2)389 // Storage: Refungible TotalSupply (r:1 w:0)390 // Storage: Refungible Owned (r:0 w:2)391 fn transfer_creating_removing() -> Weight {392 Weight::from_ref_time(36_689_000 as u64)393 .saturating_add(RocksDbWeight::get().reads(5 as u64))394 .saturating_add(RocksDbWeight::get().writes(6 as u64))395 }396 // Storage: Refungible Balance (r:1 w:0)397 // Storage: Refungible Allowance (r:0 w:1)398 fn approve() -> Weight {399 Weight::from_ref_time(23_177_000 as u64)400 .saturating_add(RocksDbWeight::get().reads(1 as u64))401 .saturating_add(RocksDbWeight::get().writes(1 as u64))402 }403 // Storage: Refungible Allowance (r:1 w:1)404 // Storage: Refungible CollectionAllowance (r:1 w:0)405 // Storage: Refungible Balance (r:2 w:2)406 // Storage: Refungible TotalSupply (r:1 w:0)407 fn transfer_from_normal() -> Weight {408 Weight::from_ref_time(41_288_000 as u64)409 .saturating_add(RocksDbWeight::get().reads(5 as u64))410 .saturating_add(RocksDbWeight::get().writes(3 as u64))411 }412 // Storage: Refungible Allowance (r:1 w:1)413 // Storage: Refungible CollectionAllowance (r:1 w:0)414 // Storage: Refungible Balance (r:2 w:2)415 // Storage: Refungible AccountBalance (r:1 w:1)416 // Storage: Refungible TotalSupply (r:1 w:0)417 // Storage: Refungible Owned (r:0 w:1)418 fn transfer_from_creating() -> Weight {419 Weight::from_ref_time(44_807_000 as u64)420 .saturating_add(RocksDbWeight::get().reads(6 as u64))421 .saturating_add(RocksDbWeight::get().writes(5 as u64))422 }423 // Storage: Refungible Allowance (r:1 w:1)424 // Storage: Refungible CollectionAllowance (r:1 w:0)425 // Storage: Refungible Balance (r:2 w:2)426 // Storage: Refungible AccountBalance (r:1 w:1)427 // Storage: Refungible TotalSupply (r:1 w:0)428 // Storage: Refungible Owned (r:0 w:1)429 fn transfer_from_removing() -> Weight {430 Weight::from_ref_time(47_297_000 as u64)431 .saturating_add(RocksDbWeight::get().reads(6 as u64))432 .saturating_add(RocksDbWeight::get().writes(5 as u64))433 }434 // Storage: Refungible Allowance (r:1 w:1)435 // Storage: Refungible CollectionAllowance (r:1 w:0)436 // Storage: Refungible Balance (r:2 w:2)437 // Storage: Refungible AccountBalance (r:2 w:2)438 // Storage: Refungible TotalSupply (r:1 w:0)439 // Storage: Refungible Owned (r:0 w:2)440 fn transfer_from_creating_removing() -> Weight {441 Weight::from_ref_time(47_566_000 as u64)442 .saturating_add(RocksDbWeight::get().reads(7 as u64))443 .saturating_add(RocksDbWeight::get().writes(7 as u64))444 }445 // Storage: Refungible Allowance (r:1 w:1)446 // Storage: Refungible CollectionAllowance (r:1 w:0)447 // Storage: Refungible Balance (r:1 w:1)448 // Storage: Refungible TotalSupply (r:1 w:1)449 // Storage: Refungible AccountBalance (r:1 w:1)450 // Storage: Refungible TokensBurnt (r:1 w:1)451 // Storage: Refungible Owned (r:0 w:1)452 // Storage: Refungible TokenProperties (r:0 w:1)453 fn burn_from() -> Weight {454 Weight::from_ref_time(53_074_000 as u64)455 .saturating_add(RocksDbWeight::get().reads(6 as u64))456 .saturating_add(RocksDbWeight::get().writes(7 as u64))457 }458 // Storage: Common CollectionPropertyPermissions (r:1 w:1)459 fn set_token_property_permissions(b: u32, ) -> Weight {460 Weight::from_ref_time(5_170_000 as u64)461 // Standard Error: 40_532462 .saturating_add(Weight::from_ref_time(11_948_016 as u64).saturating_mul(b as u64))463 .saturating_add(RocksDbWeight::get().reads(1 as u64))464 .saturating_add(RocksDbWeight::get().writes(1 as u64))465 }466 // Storage: Common CollectionPropertyPermissions (r:1 w:0)467 // Storage: Refungible TokenProperties (r:1 w:1)468 fn set_token_properties(b: u32, ) -> Weight {469 Weight::from_ref_time(4_578_000 as u64)470 // Standard Error: 5_396_287471 .saturating_add(Weight::from_ref_time(633_314_546 as u64).saturating_mul(b as u64))472 .saturating_add(RocksDbWeight::get().reads(2 as u64))473 .saturating_add(RocksDbWeight::get().writes(1 as u64))474 }475 // Storage: Common CollectionPropertyPermissions (r:1 w:0)476 // Storage: Refungible TokenProperties (r:1 w:1)477 fn delete_token_properties(b: u32, ) -> Weight {478 Weight::from_ref_time(4_583_000 as u64)479 // Standard Error: 5_762_380480 .saturating_add(Weight::from_ref_time(696_007_076 as u64).saturating_mul(b as u64))481 .saturating_add(RocksDbWeight::get().reads(2 as u64))482 .saturating_add(RocksDbWeight::get().writes(1 as u64))483 }484 // Storage: Refungible TotalSupply (r:1 w:1)485 // Storage: Refungible Balance (r:1 w:1)486 fn repartition_item() -> Weight {487 Weight::from_ref_time(25_574_000 as u64)488 .saturating_add(RocksDbWeight::get().reads(2 as u64))489 .saturating_add(RocksDbWeight::get().writes(2 as u64))490 }491 // Storage: Refungible Balance (r:2 w:0)492 fn token_owner() -> Weight {493 Weight::from_ref_time(9_819_000 as u64)494 .saturating_add(RocksDbWeight::get().reads(2 as u64))495 }496 // Storage: Refungible CollectionAllowance (r:0 w:1)497 fn set_allowance_for_all() -> Weight {498 Weight::from_ref_time(16_228_000 as u64)499 .saturating_add(RocksDbWeight::get().writes(1 as u64))500 }501 // Storage: Refungible CollectionAllowance (r:1 w:0)502 fn allowance_for_all() -> Weight {503 Weight::from_ref_time(5_374_000 as u64)504 .saturating_add(RocksDbWeight::get().reads(1 as u64))505 }506 // Storage: Refungible TokenProperties (r:1 w:1)507 fn repair_item() -> Weight {508 Weight::from_ref_time(5_624_000 as u64)509 .saturating_add(RocksDbWeight::get().reads(1 as u64))510 .saturating_add(RocksDbWeight::get().writes(1 as u64))511 }512}1// Template adopted from https://github.com/paritytech/substrate/blob/master/.maintain/frame-weight-template.hbs23//! Autogenerated weights for pallet_refungible4//!5//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev6//! DATE: 2022-12-26, STEPS: `50`, REPEAT: 80, LOW RANGE: `[]`, HIGH RANGE: `[]`7//! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 102489// Executed Command:10// target/release/unique-collator11// benchmark12// pallet13// --pallet14// pallet-refungible15// --wasm-execution16// compiled17// --extrinsic18// *19// --template20// .maintain/frame-weight-template.hbs21// --steps=5022// --repeat=8023// --heap-pages=409624// --output=./pallets/refungible/src/weights.rs2526#![cfg_attr(rustfmt, rustfmt_skip)]27#![allow(unused_parens)]28#![allow(unused_imports)]29#![allow(missing_docs)]30#![allow(clippy::unnecessary_cast)]3132use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};33use sp_std::marker::PhantomData;3435/// Weight functions needed for pallet_refungible.36pub trait WeightInfo {37 fn create_item() -> Weight;38 fn create_multiple_items(b: u32, ) -> Weight;39 fn create_multiple_items_ex_multiple_items(b: u32, ) -> Weight;40 fn create_multiple_items_ex_multiple_owners(b: u32, ) -> Weight;41 fn burn_item_partial() -> Weight;42 fn burn_item_fully() -> Weight;43 fn transfer_normal() -> Weight;44 fn transfer_creating() -> Weight;45 fn transfer_removing() -> Weight;46 fn transfer_creating_removing() -> Weight;47 fn approve() -> Weight;48 fn approve_from() -> Weight;49 fn transfer_from_normal() -> Weight;50 fn transfer_from_creating() -> Weight;51 fn transfer_from_removing() -> Weight;52 fn transfer_from_creating_removing() -> Weight;53 fn burn_from() -> Weight;54 fn set_token_property_permissions(b: u32, ) -> Weight;55 fn set_token_properties(b: u32, ) -> Weight;56 fn delete_token_properties(b: u32, ) -> Weight;57 fn repartition_item() -> Weight;58 fn token_owner() -> Weight;59 fn set_allowance_for_all() -> Weight;60 fn allowance_for_all() -> Weight;61 fn repair_item() -> Weight;62}6364/// Weights for pallet_refungible using the Substrate node and recommended hardware.65pub struct SubstrateWeight<T>(PhantomData<T>);66impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {67 // Storage: Refungible TokensMinted (r:1 w:1)68 // Storage: Refungible AccountBalance (r:1 w:1)69 // Storage: Refungible Balance (r:0 w:1)70 // Storage: Refungible TotalSupply (r:0 w:1)71 // Storage: Refungible Owned (r:0 w:1)72 fn create_item() -> Weight {73 Weight::from_ref_time(32_864_000 as u64)74 .saturating_add(T::DbWeight::get().reads(2 as u64))75 .saturating_add(T::DbWeight::get().writes(5 as u64))76 }77 // Storage: Refungible TokensMinted (r:1 w:1)78 // Storage: Refungible AccountBalance (r:1 w:1)79 // Storage: Refungible Balance (r:0 w:4)80 // Storage: Refungible TotalSupply (r:0 w:4)81 // Storage: Refungible Owned (r:0 w:4)82 fn create_multiple_items(b: u32, ) -> Weight {83 Weight::from_ref_time(11_880_472 as u64)84 // Standard Error: 5_24085 .saturating_add(Weight::from_ref_time(6_556_575 as u64).saturating_mul(b as u64))86 .saturating_add(T::DbWeight::get().reads(2 as u64))87 .saturating_add(T::DbWeight::get().writes(2 as u64))88 .saturating_add(T::DbWeight::get().writes((3 as u64).saturating_mul(b as u64)))89 }90 // Storage: Refungible TokensMinted (r:1 w:1)91 // Storage: Refungible AccountBalance (r:4 w:4)92 // Storage: Refungible Balance (r:0 w:4)93 // Storage: Refungible TotalSupply (r:0 w:4)94 // Storage: Refungible Owned (r:0 w:4)95 fn create_multiple_items_ex_multiple_items(b: u32, ) -> Weight {96 Weight::from_ref_time(11_644_173 as u64)97 // Standard Error: 5_87698 .saturating_add(Weight::from_ref_time(8_214_607 as u64).saturating_mul(b as u64))99 .saturating_add(T::DbWeight::get().reads(1 as u64))100 .saturating_add(T::DbWeight::get().reads((1 as u64).saturating_mul(b as u64)))101 .saturating_add(T::DbWeight::get().writes(1 as u64))102 .saturating_add(T::DbWeight::get().writes((4 as u64).saturating_mul(b as u64)))103 }104 // Storage: Refungible TokensMinted (r:1 w:1)105 // Storage: Refungible TotalSupply (r:0 w:1)106 // Storage: Refungible AccountBalance (r:4 w:4)107 // Storage: Refungible Balance (r:0 w:4)108 // Storage: Refungible Owned (r:0 w:4)109 fn create_multiple_items_ex_multiple_owners(b: u32, ) -> Weight {110 Weight::from_ref_time(21_817_067 as u64)111 // Standard Error: 5_215112 .saturating_add(Weight::from_ref_time(6_084_938 as u64).saturating_mul(b as u64))113 .saturating_add(T::DbWeight::get().reads(1 as u64))114 .saturating_add(T::DbWeight::get().reads((1 as u64).saturating_mul(b as u64)))115 .saturating_add(T::DbWeight::get().writes(2 as u64))116 .saturating_add(T::DbWeight::get().writes((3 as u64).saturating_mul(b as u64)))117 }118 // Storage: Refungible Balance (r:3 w:1)119 // Storage: Refungible TotalSupply (r:1 w:1)120 // Storage: Refungible AccountBalance (r:1 w:1)121 // Storage: Refungible Owned (r:0 w:1)122 fn burn_item_partial() -> Weight {123 Weight::from_ref_time(47_087_000 as u64)124 .saturating_add(T::DbWeight::get().reads(5 as u64))125 .saturating_add(T::DbWeight::get().writes(4 as u64))126 }127 // Storage: Refungible Balance (r:1 w:1)128 // Storage: Refungible TotalSupply (r:1 w:1)129 // Storage: Refungible AccountBalance (r:1 w:1)130 // Storage: Refungible TokensBurnt (r:1 w:1)131 // Storage: Refungible Owned (r:0 w:1)132 // Storage: Refungible TokenProperties (r:0 w:1)133 fn burn_item_fully() -> Weight {134 Weight::from_ref_time(40_135_000 as u64)135 .saturating_add(T::DbWeight::get().reads(4 as u64))136 .saturating_add(T::DbWeight::get().writes(6 as u64))137 }138 // Storage: Refungible Balance (r:2 w:2)139 // Storage: Refungible TotalSupply (r:1 w:0)140 fn transfer_normal() -> Weight {141 Weight::from_ref_time(30_749_000 as u64)142 .saturating_add(T::DbWeight::get().reads(3 as u64))143 .saturating_add(T::DbWeight::get().writes(2 as u64))144 }145 // Storage: Refungible Balance (r:2 w:2)146 // Storage: Refungible AccountBalance (r:1 w:1)147 // Storage: Refungible TotalSupply (r:1 w:0)148 // Storage: Refungible Owned (r:0 w:1)149 fn transfer_creating() -> Weight {150 Weight::from_ref_time(33_565_000 as u64)151 .saturating_add(T::DbWeight::get().reads(4 as u64))152 .saturating_add(T::DbWeight::get().writes(4 as u64))153 }154 // Storage: Refungible Balance (r:2 w:2)155 // Storage: Refungible AccountBalance (r:1 w:1)156 // Storage: Refungible TotalSupply (r:1 w:0)157 // Storage: Refungible Owned (r:0 w:1)158 fn transfer_removing() -> Weight {159 Weight::from_ref_time(37_406_000 as u64)160 .saturating_add(T::DbWeight::get().reads(4 as u64))161 .saturating_add(T::DbWeight::get().writes(4 as u64))162 }163 // Storage: Refungible Balance (r:2 w:2)164 // Storage: Refungible AccountBalance (r:2 w:2)165 // Storage: Refungible TotalSupply (r:1 w:0)166 // Storage: Refungible Owned (r:0 w:2)167 fn transfer_creating_removing() -> Weight {168 Weight::from_ref_time(36_689_000 as u64)169 .saturating_add(T::DbWeight::get().reads(5 as u64))170 .saturating_add(T::DbWeight::get().writes(6 as u64))171 }172 // Storage: Refungible Balance (r:1 w:0)173 // Storage: Refungible Allowance (r:0 w:1)174 fn approve() -> Weight {175 Weight::from_ref_time(23_177_000 as u64)176 .saturating_add(T::DbWeight::get().reads(1 as u64))177 .saturating_add(T::DbWeight::get().writes(1 as u64))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 }186 // Storage: Refungible Allowance (r:1 w:1)187 // Storage: Refungible CollectionAllowance (r:1 w:0)188 // Storage: Refungible Balance (r:2 w:2)189 // Storage: Refungible TotalSupply (r:1 w:0)190 fn transfer_from_normal() -> Weight {191 Weight::from_ref_time(41_288_000 as u64)192 .saturating_add(T::DbWeight::get().reads(5 as u64))193 .saturating_add(T::DbWeight::get().writes(3 as u64))194 }195 // Storage: Refungible Allowance (r:1 w:1)196 // Storage: Refungible CollectionAllowance (r:1 w:0)197 // Storage: Refungible Balance (r:2 w:2)198 // Storage: Refungible AccountBalance (r:1 w:1)199 // Storage: Refungible TotalSupply (r:1 w:0)200 // Storage: Refungible Owned (r:0 w:1)201 fn transfer_from_creating() -> Weight {202 Weight::from_ref_time(44_807_000 as u64)203 .saturating_add(T::DbWeight::get().reads(6 as u64))204 .saturating_add(T::DbWeight::get().writes(5 as u64))205 }206 // Storage: Refungible Allowance (r:1 w:1)207 // Storage: Refungible CollectionAllowance (r:1 w:0)208 // Storage: Refungible Balance (r:2 w:2)209 // Storage: Refungible AccountBalance (r:1 w:1)210 // Storage: Refungible TotalSupply (r:1 w:0)211 // Storage: Refungible Owned (r:0 w:1)212 fn transfer_from_removing() -> Weight {213 Weight::from_ref_time(47_297_000 as u64)214 .saturating_add(T::DbWeight::get().reads(6 as u64))215 .saturating_add(T::DbWeight::get().writes(5 as u64))216 }217 // Storage: Refungible Allowance (r:1 w:1)218 // Storage: Refungible CollectionAllowance (r:1 w:0)219 // Storage: Refungible Balance (r:2 w:2)220 // Storage: Refungible AccountBalance (r:2 w:2)221 // Storage: Refungible TotalSupply (r:1 w:0)222 // Storage: Refungible Owned (r:0 w:2)223 fn transfer_from_creating_removing() -> Weight {224 Weight::from_ref_time(47_566_000 as u64)225 .saturating_add(T::DbWeight::get().reads(7 as u64))226 .saturating_add(T::DbWeight::get().writes(7 as u64))227 }228 // Storage: Refungible Allowance (r:1 w:1)229 // Storage: Refungible CollectionAllowance (r:1 w:0)230 // Storage: Refungible Balance (r:1 w:1)231 // Storage: Refungible TotalSupply (r:1 w:1)232 // Storage: Refungible AccountBalance (r:1 w:1)233 // Storage: Refungible TokensBurnt (r:1 w:1)234 // Storage: Refungible Owned (r:0 w:1)235 // Storage: Refungible TokenProperties (r:0 w:1)236 fn burn_from() -> Weight {237 Weight::from_ref_time(53_074_000 as u64)238 .saturating_add(T::DbWeight::get().reads(6 as u64))239 .saturating_add(T::DbWeight::get().writes(7 as u64))240 }241 // Storage: Common CollectionPropertyPermissions (r:1 w:1)242 fn set_token_property_permissions(b: u32, ) -> Weight {243 Weight::from_ref_time(5_170_000 as u64)244 // Standard Error: 40_532245 .saturating_add(Weight::from_ref_time(11_948_016 as u64).saturating_mul(b as u64))246 .saturating_add(T::DbWeight::get().reads(1 as u64))247 .saturating_add(T::DbWeight::get().writes(1 as u64))248 }249 // Storage: Common CollectionPropertyPermissions (r:1 w:0)250 // Storage: Refungible TokenProperties (r:1 w:1)251 fn set_token_properties(b: u32, ) -> Weight {252 Weight::from_ref_time(4_578_000 as u64)253 // Standard Error: 5_396_287254 .saturating_add(Weight::from_ref_time(633_314_546 as u64).saturating_mul(b as u64))255 .saturating_add(T::DbWeight::get().reads(2 as u64))256 .saturating_add(T::DbWeight::get().writes(1 as u64))257 }258 // Storage: Common CollectionPropertyPermissions (r:1 w:0)259 // Storage: Refungible TokenProperties (r:1 w:1)260 fn delete_token_properties(b: u32, ) -> Weight {261 Weight::from_ref_time(4_583_000 as u64)262 // Standard Error: 5_762_380263 .saturating_add(Weight::from_ref_time(696_007_076 as u64).saturating_mul(b as u64))264 .saturating_add(T::DbWeight::get().reads(2 as u64))265 .saturating_add(T::DbWeight::get().writes(1 as u64))266 }267 // Storage: Refungible TotalSupply (r:1 w:1)268 // Storage: Refungible Balance (r:1 w:1)269 fn repartition_item() -> Weight {270 Weight::from_ref_time(25_574_000 as u64)271 .saturating_add(T::DbWeight::get().reads(2 as u64))272 .saturating_add(T::DbWeight::get().writes(2 as u64))273 }274 // Storage: Refungible Balance (r:2 w:0)275 fn token_owner() -> Weight {276 Weight::from_ref_time(9_819_000 as u64)277 .saturating_add(T::DbWeight::get().reads(2 as u64))278 }279 // Storage: Refungible CollectionAllowance (r:0 w:1)280 fn set_allowance_for_all() -> Weight {281 Weight::from_ref_time(16_228_000 as u64)282 .saturating_add(T::DbWeight::get().writes(1 as u64))283 }284 // Storage: Refungible CollectionAllowance (r:1 w:0)285 fn allowance_for_all() -> Weight {286 Weight::from_ref_time(5_374_000 as u64)287 .saturating_add(T::DbWeight::get().reads(1 as u64))288 }289 // Storage: Refungible TokenProperties (r:1 w:1)290 fn repair_item() -> Weight {291 Weight::from_ref_time(5_624_000 as u64)292 .saturating_add(T::DbWeight::get().reads(1 as u64))293 .saturating_add(T::DbWeight::get().writes(1 as u64))294 }295}296297// For backwards compatibility and tests298impl WeightInfo for () {299 // Storage: Refungible TokensMinted (r:1 w:1)300 // Storage: Refungible AccountBalance (r:1 w:1)301 // Storage: Refungible Balance (r:0 w:1)302 // Storage: Refungible TotalSupply (r:0 w:1)303 // Storage: Refungible Owned (r:0 w:1)304 fn create_item() -> Weight {305 Weight::from_ref_time(32_864_000 as u64)306 .saturating_add(RocksDbWeight::get().reads(2 as u64))307 .saturating_add(RocksDbWeight::get().writes(5 as u64))308 }309 // Storage: Refungible TokensMinted (r:1 w:1)310 // Storage: Refungible AccountBalance (r:1 w:1)311 // Storage: Refungible Balance (r:0 w:4)312 // Storage: Refungible TotalSupply (r:0 w:4)313 // Storage: Refungible Owned (r:0 w:4)314 fn create_multiple_items(b: u32, ) -> Weight {315 Weight::from_ref_time(11_880_472 as u64)316 // Standard Error: 5_240317 .saturating_add(Weight::from_ref_time(6_556_575 as u64).saturating_mul(b as u64))318 .saturating_add(RocksDbWeight::get().reads(2 as u64))319 .saturating_add(RocksDbWeight::get().writes(2 as u64))320 .saturating_add(RocksDbWeight::get().writes((3 as u64).saturating_mul(b as u64)))321 }322 // Storage: Refungible TokensMinted (r:1 w:1)323 // Storage: Refungible AccountBalance (r:4 w:4)324 // Storage: Refungible Balance (r:0 w:4)325 // Storage: Refungible TotalSupply (r:0 w:4)326 // Storage: Refungible Owned (r:0 w:4)327 fn create_multiple_items_ex_multiple_items(b: u32, ) -> Weight {328 Weight::from_ref_time(11_644_173 as u64)329 // Standard Error: 5_876330 .saturating_add(Weight::from_ref_time(8_214_607 as u64).saturating_mul(b as u64))331 .saturating_add(RocksDbWeight::get().reads(1 as u64))332 .saturating_add(RocksDbWeight::get().reads((1 as u64).saturating_mul(b as u64)))333 .saturating_add(RocksDbWeight::get().writes(1 as u64))334 .saturating_add(RocksDbWeight::get().writes((4 as u64).saturating_mul(b as u64)))335 }336 // Storage: Refungible TokensMinted (r:1 w:1)337 // Storage: Refungible TotalSupply (r:0 w:1)338 // Storage: Refungible AccountBalance (r:4 w:4)339 // Storage: Refungible Balance (r:0 w:4)340 // Storage: Refungible Owned (r:0 w:4)341 fn create_multiple_items_ex_multiple_owners(b: u32, ) -> Weight {342 Weight::from_ref_time(21_817_067 as u64)343 // Standard Error: 5_215344 .saturating_add(Weight::from_ref_time(6_084_938 as u64).saturating_mul(b as u64))345 .saturating_add(RocksDbWeight::get().reads(1 as u64))346 .saturating_add(RocksDbWeight::get().reads((1 as u64).saturating_mul(b as u64)))347 .saturating_add(RocksDbWeight::get().writes(2 as u64))348 .saturating_add(RocksDbWeight::get().writes((3 as u64).saturating_mul(b as u64)))349 }350 // Storage: Refungible Balance (r:3 w:1)351 // Storage: Refungible TotalSupply (r:1 w:1)352 // Storage: Refungible AccountBalance (r:1 w:1)353 // Storage: Refungible Owned (r:0 w:1)354 fn burn_item_partial() -> Weight {355 Weight::from_ref_time(47_087_000 as u64)356 .saturating_add(RocksDbWeight::get().reads(5 as u64))357 .saturating_add(RocksDbWeight::get().writes(4 as u64))358 }359 // Storage: Refungible Balance (r:1 w:1)360 // Storage: Refungible TotalSupply (r:1 w:1)361 // Storage: Refungible AccountBalance (r:1 w:1)362 // Storage: Refungible TokensBurnt (r:1 w:1)363 // Storage: Refungible Owned (r:0 w:1)364 // Storage: Refungible TokenProperties (r:0 w:1)365 fn burn_item_fully() -> Weight {366 Weight::from_ref_time(40_135_000 as u64)367 .saturating_add(RocksDbWeight::get().reads(4 as u64))368 .saturating_add(RocksDbWeight::get().writes(6 as u64))369 }370 // Storage: Refungible Balance (r:2 w:2)371 // Storage: Refungible TotalSupply (r:1 w:0)372 fn transfer_normal() -> Weight {373 Weight::from_ref_time(30_749_000 as u64)374 .saturating_add(RocksDbWeight::get().reads(3 as u64))375 .saturating_add(RocksDbWeight::get().writes(2 as u64))376 }377 // Storage: Refungible Balance (r:2 w:2)378 // Storage: Refungible AccountBalance (r:1 w:1)379 // Storage: Refungible TotalSupply (r:1 w:0)380 // Storage: Refungible Owned (r:0 w:1)381 fn transfer_creating() -> Weight {382 Weight::from_ref_time(33_565_000 as u64)383 .saturating_add(RocksDbWeight::get().reads(4 as u64))384 .saturating_add(RocksDbWeight::get().writes(4 as u64))385 }386 // Storage: Refungible Balance (r:2 w:2)387 // Storage: Refungible AccountBalance (r:1 w:1)388 // Storage: Refungible TotalSupply (r:1 w:0)389 // Storage: Refungible Owned (r:0 w:1)390 fn transfer_removing() -> Weight {391 Weight::from_ref_time(37_406_000 as u64)392 .saturating_add(RocksDbWeight::get().reads(4 as u64))393 .saturating_add(RocksDbWeight::get().writes(4 as u64))394 }395 // Storage: Refungible Balance (r:2 w:2)396 // Storage: Refungible AccountBalance (r:2 w:2)397 // Storage: Refungible TotalSupply (r:1 w:0)398 // Storage: Refungible Owned (r:0 w:2)399 fn transfer_creating_removing() -> Weight {400 Weight::from_ref_time(36_689_000 as u64)401 .saturating_add(RocksDbWeight::get().reads(5 as u64))402 .saturating_add(RocksDbWeight::get().writes(6 as u64))403 }404 // Storage: Refungible Balance (r:1 w:0)405 // Storage: Refungible Allowance (r:0 w:1)406 fn approve() -> Weight {407 Weight::from_ref_time(23_177_000 as u64)408 .saturating_add(RocksDbWeight::get().reads(1 as u64))409 .saturating_add(RocksDbWeight::get().writes(1 as u64))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 }418 // Storage: Refungible Allowance (r:1 w:1)419 // Storage: Refungible CollectionAllowance (r:1 w:0)420 // Storage: Refungible Balance (r:2 w:2)421 // Storage: Refungible TotalSupply (r:1 w:0)422 fn transfer_from_normal() -> Weight {423 Weight::from_ref_time(41_288_000 as u64)424 .saturating_add(RocksDbWeight::get().reads(5 as u64))425 .saturating_add(RocksDbWeight::get().writes(3 as u64))426 }427 // Storage: Refungible Allowance (r:1 w:1)428 // Storage: Refungible CollectionAllowance (r:1 w:0)429 // Storage: Refungible Balance (r:2 w:2)430 // Storage: Refungible AccountBalance (r:1 w:1)431 // Storage: Refungible TotalSupply (r:1 w:0)432 // Storage: Refungible Owned (r:0 w:1)433 fn transfer_from_creating() -> Weight {434 Weight::from_ref_time(44_807_000 as u64)435 .saturating_add(RocksDbWeight::get().reads(6 as u64))436 .saturating_add(RocksDbWeight::get().writes(5 as u64))437 }438 // Storage: Refungible Allowance (r:1 w:1)439 // Storage: Refungible CollectionAllowance (r:1 w:0)440 // Storage: Refungible Balance (r:2 w:2)441 // Storage: Refungible AccountBalance (r:1 w:1)442 // Storage: Refungible TotalSupply (r:1 w:0)443 // Storage: Refungible Owned (r:0 w:1)444 fn transfer_from_removing() -> Weight {445 Weight::from_ref_time(47_297_000 as u64)446 .saturating_add(RocksDbWeight::get().reads(6 as u64))447 .saturating_add(RocksDbWeight::get().writes(5 as u64))448 }449 // Storage: Refungible Allowance (r:1 w:1)450 // Storage: Refungible CollectionAllowance (r:1 w:0)451 // Storage: Refungible Balance (r:2 w:2)452 // Storage: Refungible AccountBalance (r:2 w:2)453 // Storage: Refungible TotalSupply (r:1 w:0)454 // Storage: Refungible Owned (r:0 w:2)455 fn transfer_from_creating_removing() -> Weight {456 Weight::from_ref_time(47_566_000 as u64)457 .saturating_add(RocksDbWeight::get().reads(7 as u64))458 .saturating_add(RocksDbWeight::get().writes(7 as u64))459 }460 // Storage: Refungible Allowance (r:1 w:1)461 // Storage: Refungible CollectionAllowance (r:1 w:0)462 // Storage: Refungible Balance (r:1 w:1)463 // Storage: Refungible TotalSupply (r:1 w:1)464 // Storage: Refungible AccountBalance (r:1 w:1)465 // Storage: Refungible TokensBurnt (r:1 w:1)466 // Storage: Refungible Owned (r:0 w:1)467 // Storage: Refungible TokenProperties (r:0 w:1)468 fn burn_from() -> Weight {469 Weight::from_ref_time(53_074_000 as u64)470 .saturating_add(RocksDbWeight::get().reads(6 as u64))471 .saturating_add(RocksDbWeight::get().writes(7 as u64))472 }473 // Storage: Common CollectionPropertyPermissions (r:1 w:1)474 fn set_token_property_permissions(b: u32, ) -> Weight {475 Weight::from_ref_time(5_170_000 as u64)476 // Standard Error: 40_532477 .saturating_add(Weight::from_ref_time(11_948_016 as u64).saturating_mul(b as u64))478 .saturating_add(RocksDbWeight::get().reads(1 as u64))479 .saturating_add(RocksDbWeight::get().writes(1 as u64))480 }481 // Storage: Common CollectionPropertyPermissions (r:1 w:0)482 // Storage: Refungible TokenProperties (r:1 w:1)483 fn set_token_properties(b: u32, ) -> Weight {484 Weight::from_ref_time(4_578_000 as u64)485 // Standard Error: 5_396_287486 .saturating_add(Weight::from_ref_time(633_314_546 as u64).saturating_mul(b as u64))487 .saturating_add(RocksDbWeight::get().reads(2 as u64))488 .saturating_add(RocksDbWeight::get().writes(1 as u64))489 }490 // Storage: Common CollectionPropertyPermissions (r:1 w:0)491 // Storage: Refungible TokenProperties (r:1 w:1)492 fn delete_token_properties(b: u32, ) -> Weight {493 Weight::from_ref_time(4_583_000 as u64)494 // Standard Error: 5_762_380495 .saturating_add(Weight::from_ref_time(696_007_076 as u64).saturating_mul(b as u64))496 .saturating_add(RocksDbWeight::get().reads(2 as u64))497 .saturating_add(RocksDbWeight::get().writes(1 as u64))498 }499 // Storage: Refungible TotalSupply (r:1 w:1)500 // Storage: Refungible Balance (r:1 w:1)501 fn repartition_item() -> Weight {502 Weight::from_ref_time(25_574_000 as u64)503 .saturating_add(RocksDbWeight::get().reads(2 as u64))504 .saturating_add(RocksDbWeight::get().writes(2 as u64))505 }506 // Storage: Refungible Balance (r:2 w:0)507 fn token_owner() -> Weight {508 Weight::from_ref_time(9_819_000 as u64)509 .saturating_add(RocksDbWeight::get().reads(2 as u64))510 }511 // Storage: Refungible CollectionAllowance (r:0 w:1)512 fn set_allowance_for_all() -> Weight {513 Weight::from_ref_time(16_228_000 as u64)514 .saturating_add(RocksDbWeight::get().writes(1 as u64))515 }516 // Storage: Refungible CollectionAllowance (r:1 w:0)517 fn allowance_for_all() -> Weight {518 Weight::from_ref_time(5_374_000 as u64)519 .saturating_add(RocksDbWeight::get().reads(1 as u64))520 }521 // Storage: Refungible TokenProperties (r:1 w:1)522 fn repair_item() -> Weight {523 Weight::from_ref_time(5_624_000 as u64)524 .saturating_add(RocksDbWeight::get().reads(1 as u64))525 .saturating_add(RocksDbWeight::get().writes(1 as u64))526 }527}pallets/unique/src/lib.rsdiffbeforeafterboth--- a/pallets/unique/src/lib.rs
+++ b/pallets/unique/src/lib.rs
@@ -851,6 +851,29 @@
dispatch_tx::<T, _>(collection_id, |d| d.approve(sender, spender, item_id, amount))
}
+ /// Allow a non-permissioned address to transfer or burn an item from owner's eth mirror.
+ ///
+ /// # Permissions
+ ///
+ /// * Collection owner
+ /// * Collection admin
+ /// * Current item owner
+ ///
+ /// # Arguments
+ ///
+ /// * `from`: Owner's account eth mirror
+ /// * `to`: Account to be approved to make specific transactions on non-owned tokens.
+ /// * `collection_id`: ID of the collection the item belongs to.
+ /// * `item_id`: ID of the item transactions on which are now approved.
+ /// * `amount`: Number of pieces of the item approved for a transaction (maximum of 1 for NFTs).
+ /// Set to 0 to revoke the approval.
+ #[weight = T::CommonWeightInfo::approve_from()]
+ pub fn approve_from(origin, from:T::CrossAccountId, to: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, amount: u128) -> DispatchResultWithPostInfo {
+ let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
+
+ dispatch_tx::<T, _>(collection_id, |d| d.approve_from(sender, from, to, item_id, amount))
+ }
+
/// Change ownership of an item on behalf of the owner as a non-owner account.
///
/// See the [`approve`][`Pallet::approve`] method for additional information.
runtime/common/identity.rsdiffbeforeafterboth--- a/runtime/common/identity.rs
+++ b/runtime/common/identity.rs
@@ -21,9 +21,7 @@
use sp_runtime::{
traits::{DispatchInfoOf, SignedExtension},
- transaction_validity::{
- TransactionValidity, ValidTransaction, InvalidTransaction, TransactionValidityError,
- },
+ transaction_validity::{TransactionValidity, ValidTransaction, TransactionValidityError},
};
#[derive(Debug, Encode, Decode, PartialEq, Eq, Clone, TypeInfo)]
runtime/common/weights.rsdiffbeforeafterboth--- a/runtime/common/weights.rs
+++ b/runtime/common/weights.rs
@@ -101,6 +101,10 @@
dispatch_weight::<T>() + max_weight_of!(approve())
}
+ fn approve_from() -> Weight {
+ dispatch_weight::<T>() + max_weight_of!(approve_from())
+ }
+
fn transfer_from() -> Weight {
dispatch_weight::<T>() + max_weight_of!(transfer_from())
}
tests/src/approve.test.tsdiffbeforeafterboth--- a/tests/src/approve.test.ts
+++ b/tests/src/approve.test.ts
@@ -16,336 +16,521 @@
import {IKeyringPair} from '@polkadot/types/types';
import {expect, itSub, Pallets, usingPlaygrounds} from './util';
+import {CrossAccountId} from './util/playgrounds/unique';
+
-describe('Integration Test approve(spender, collection_id, item_id, amount):', () => {
- let alice: IKeyringPair;
- let bob: IKeyringPair;
- let charlie: IKeyringPair;
+[
+ {method: 'approveToken', account: (account: IKeyringPair) => CrossAccountId.fromKeyring(account)},
+ {method: 'approveTokenFromEth', account: (account: IKeyringPair) => CrossAccountId.fromKeyring(account).toEthereum()},
+].map(testCase => {
+ describe(`Integration Test ${testCase.method}(spender, collection_id, item_id, amount):`, () => {
+ let alice: IKeyringPair;
+ let bob: IKeyringPair;
+ let charlie: IKeyringPair;
- before(async () => {
- await usingPlaygrounds(async (helper, privateKey) => {
- const donor = await privateKey({filename: __filename});
- [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
+ before(async () => {
+ await usingPlaygrounds(async (helper, privateKey) => {
+ const donor = await privateKey({filename: __filename});
+ [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
+ });
});
- });
- itSub('[nft] Execute the extrinsic and check approvedList', async ({helper}) => {
- const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
- const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
- await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});
- expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.true;
- });
+ itSub('[nft] Execute the extrinsic and check approvedList', async ({helper}) => {
+ const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(alice)});
+ await (helper.nft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address});
+ expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.true;
+ });
+
+ itSub('[fungible] Execute the extrinsic and check approvedList', async ({helper}) => {
+ const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);
+ await helper.ft.mintTokens(alice, collectionId, 10n, testCase.account(alice));
+ const tokenId = await helper.ft.getLastTokenId(collectionId);
+ await (helper.ft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address});
+ const amount = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, testCase.account(alice));
+ expect(amount).to.be.equal(BigInt(1));
+ });
+
+ itSub.ifWithPallets('[refungible] Execute the extrinsic and check approvedList', [Pallets.ReFungible], async ({helper}) => {
+ const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(alice), pieces: 100n});
+ await (helper.rft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address});
+ const amount = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, testCase.account(alice));
+ expect(amount).to.be.equal(BigInt(1));
+ });
+
+ itSub('[nft] Remove approval by using 0 amount', async ({helper}) => {
+ const collection = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const collectionId = collection.collectionId;
+ const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(alice)});
+ await (helper.nft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address});
+ expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.true;
+ await (helper.nft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address}, 0n);
+ expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.false;
+ });
- itSub('[fungible] Execute the extrinsic and check approvedList', async ({helper}) => {
- const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);
- await helper.ft.mintTokens(alice, collectionId, 10n, {Substrate: alice.address});
- const tokenId = await helper.ft.getLastTokenId(collectionId);
- await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});
- const amount = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});
- expect(amount).to.be.equal(BigInt(1));
- });
+ itSub('[fungible] Remove approval by using 0 amount', async ({helper}) => {
+ const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);
+ await helper.ft.mintTokens(alice, collectionId, 10n, testCase.account(alice));
+ const tokenId = await helper.ft.getLastTokenId(collectionId);
+ await (helper.ft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address});
+ const amountBefore = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, testCase.account(alice));
+ expect(amountBefore).to.be.equal(BigInt(1));
- itSub.ifWithPallets('[refungible] Execute the extrinsic and check approvedList', [Pallets.ReFungible], async ({helper}) => {
- const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
- const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n});
- await helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});
- const amount = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});
- expect(amount).to.be.equal(BigInt(1));
- });
+ await (helper.ft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address}, 0n);
+ const amountAfter = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, testCase.account(alice));
+ expect(amountAfter).to.be.equal(BigInt(0));
+ });
- itSub('[nft] Remove approval by using 0 amount', async ({helper}) => {
- const collection = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
- const collectionId = collection.collectionId;
- const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
- await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});
- expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.true;
- await helper.signTransaction(alice, helper.constructApiCall('api.tx.unique.approve', [{Substrate: bob.address}, collectionId, tokenId, 0]));
- expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.false;
- });
+ itSub.ifWithPallets('[refungible] Remove approval by using 0 amount', [Pallets.ReFungible], async ({helper}) => {
+ const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(alice), pieces: 100n});
+ await (helper.rft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address});
+ const amountBefore = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, testCase.account(alice));
+ expect(amountBefore).to.be.equal(BigInt(1));
- itSub('[fungible] Remove approval by using 0 amount', async ({helper}) => {
- const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);
- await helper.ft.mintTokens(alice, collectionId, 10n, {Substrate: alice.address});
- const tokenId = await helper.ft.getLastTokenId(collectionId);
- await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});
- const amountBefore = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});
- expect(amountBefore).to.be.equal(BigInt(1));
+ await (helper.rft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address}, 0n);
+ const amountAfter = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, testCase.account(alice));
+ expect(amountAfter).to.be.equal(BigInt(0));
+ });
- await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 0n);
- const amountAfter = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});
- expect(amountAfter).to.be.equal(BigInt(0));
+ itSub('can`t be called by collection owner on non-owned item when OwnerCanTransfer == false', async ({helper}) => {
+ const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(bob)});
+ const result = (helper.nft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: charlie.address});
+ await expect(result).to.be.rejected;
+ });
});
- itSub.ifWithPallets('[refungible] Remove approval by using 0 amount', [Pallets.ReFungible], async ({helper}) => {
- const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
- const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n});
- await helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});
- const amountBefore = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});
- expect(amountBefore).to.be.equal(BigInt(1));
+ describe(`[${testCase.method}] Normal user can approve other users to transfer:`, () => {
+ let alice: IKeyringPair;
+ let bob: IKeyringPair;
+ let charlie: IKeyringPair;
- await helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 0n);
- const amountAfter = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});
- expect(amountAfter).to.be.equal(BigInt(0));
- });
+ before(async () => {
+ await usingPlaygrounds(async (helper, privateKey) => {
+ const donor = await privateKey({filename: __filename});
+ [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
+ });
+ });
- itSub('can`t be called by collection owner on non-owned item when OwnerCanTransfer == false', async ({helper}) => {
- const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
- const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});
- const approveTokenTx = () => helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});
- await expect(approveTokenTx()).to.be.rejected;
- });
-});
+ itSub('NFT', async ({helper}) => {
+ const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(bob)});
+ await (helper.nft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: charlie.address});
+ expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: charlie.address})).to.be.true;
+ });
-describe('Normal user can approve other users to transfer:', () => {
- let alice: IKeyringPair;
- let bob: IKeyringPair;
- let charlie: IKeyringPair;
+ itSub('Fungible up to an approved amount', async ({helper}) => {
+ const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);
+ await helper.ft.mintTokens(alice, collectionId, 10n, testCase.account(bob));
+ const tokenId = await helper.ft.getLastTokenId(collectionId);
+ await (helper.ft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: charlie.address});
+ const amount = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: charlie.address}, testCase.account(bob));
+ expect(amount).to.be.equal(BigInt(1));
+ });
- before(async () => {
- await usingPlaygrounds(async (helper, privateKey) => {
- const donor = await privateKey({filename: __filename});
- [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
+ itSub.ifWithPallets('ReFungible up to an approved amount', [Pallets.ReFungible], async ({helper}) => {
+ const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(bob), pieces: 100n});
+ await (helper.rft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: charlie.address}, 100n);
+ const amount = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: charlie.address}, testCase.account(bob));
+ expect(amount).to.be.equal(BigInt(100n));
});
});
- itSub('NFT', async ({helper}) => {
- const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
- const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});
- await helper.nft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});
- expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: charlie.address})).to.be.true;
- });
+ describe(`[${testCase.method}] Approved users can transferFrom up to approved amount:`, () => {
+ let alice: IKeyringPair;
+ let bob: IKeyringPair;
+ let charlie: IKeyringPair;
- itSub('Fungible up to an approved amount', async ({helper}) => {
- const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);
- await helper.ft.mintTokens(alice, collectionId, 10n, bob.address);
- const tokenId = await helper.ft.getLastTokenId(collectionId);
- await helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});
- const amount = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: charlie.address}, {Substrate: bob.address});
- expect(amount).to.be.equal(BigInt(1));
- });
+ before(async () => {
+ await usingPlaygrounds(async (helper, privateKey) => {
+ const donor = await privateKey({filename: __filename});
+ [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
+ });
+ });
- itSub.ifWithPallets('ReFungible up to an approved amount', [Pallets.ReFungible], async ({helper}) => {
- const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
- const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: bob.address, pieces: 100n});
- await helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address}, 100n);
- const amount = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: charlie.address}, {Substrate: bob.address});
- expect(amount).to.be.equal(BigInt(100n));
+ itSub('NFT', async ({helper}) => {
+ const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(bob)});
+ await (helper.nft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: charlie.address});
+ await helper.nft.transferTokenFrom(charlie, collectionId, tokenId, testCase.account(bob), {Substrate: alice.address});
+ const owner = await helper.nft.getTokenOwner(collectionId, tokenId);
+ expect(owner.Substrate).to.be.equal(alice.address);
+ });
+
+ itSub('Fungible up to an approved amount', async ({helper}) => {
+ const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);
+ await helper.ft.mintTokens(alice, collectionId, 10n, testCase.account(bob));
+ const tokenId = await helper.ft.getLastTokenId(collectionId);
+ await (helper.ft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: charlie.address});
+ const before = await helper.ft.getBalance(collectionId, {Substrate: alice.address});
+ await helper.ft.transferTokenFrom(charlie, collectionId, tokenId, testCase.account(bob), {Substrate: alice.address}, 1n);
+ const after = await helper.ft.getBalance(collectionId, {Substrate: alice.address});
+ expect(after - before).to.be.equal(BigInt(1));
+ });
+
+ itSub.ifWithPallets('ReFungible up to an approved amount', [Pallets.ReFungible], async ({helper}) => {
+ const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(bob), pieces: 100n});
+ await (helper.rft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: charlie.address});
+ const before = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});
+ await helper.rft.transferTokenFrom(charlie, collectionId, tokenId, testCase.account(bob), {Substrate: alice.address}, 1n);
+ const after = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});
+ expect(after - before).to.be.equal(BigInt(1));
+ });
});
-});
-describe('Approved users can transferFrom up to approved amount:', () => {
- let alice: IKeyringPair;
- let bob: IKeyringPair;
- let charlie: IKeyringPair;
+ describe(`[${testCase.method}] Approved users cannot use transferFrom to repeat transfers if approved amount was already transferred:`, () => {
+ let alice: IKeyringPair;
+ let bob: IKeyringPair;
+ let charlie: IKeyringPair;
+
+ before(async () => {
+ await usingPlaygrounds(async (helper, privateKey) => {
+ const donor = await privateKey({filename: __filename});
+ [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
+ });
+ });
+
+ itSub('NFT', async ({helper}) => {
+ const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(bob)});
+ await (helper.nft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: charlie.address});
+ await helper.nft.transferTokenFrom(charlie, collectionId, tokenId, testCase.account(bob), {Substrate: alice.address});
+ const owner = await helper.nft.getTokenOwner(collectionId, tokenId);
+ expect(owner.Substrate).to.be.equal(alice.address);
+ const transferTokenFromTx = () => helper.nft.transferTokenFrom(charlie, collectionId, tokenId, testCase.account(bob), {Substrate: alice.address});
+ await expect(transferTokenFromTx()).to.be.rejected;
+ });
+
+ itSub('Fungible up to an approved amount', async ({helper}) => {
+ const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);
+ await helper.ft.mintTokens(alice, collectionId, 10n, testCase.account(bob));
+ const tokenId = await helper.ft.getLastTokenId(collectionId);
+ await (helper.ft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: charlie.address});
+ const before = await helper.ft.getBalance(collectionId, {Substrate: alice.address});
+ await helper.ft.transferTokenFrom(charlie, collectionId, tokenId, testCase.account(bob), {Substrate: alice.address}, 1n);
+ const after = await helper.ft.getBalance(collectionId, {Substrate: alice.address});
+ expect(after - before).to.be.equal(BigInt(1));
+
+ const transferTokenFromTx = () => helper.ft.transferTokenFrom(charlie, collectionId, tokenId, testCase.account(bob), {Substrate: alice.address}, 1n);
+ await expect(transferTokenFromTx()).to.be.rejected;
+ });
- before(async () => {
- await usingPlaygrounds(async (helper, privateKey) => {
- const donor = await privateKey({filename: __filename});
- [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
+ itSub.ifWithPallets('ReFungible up to an approved amount', [Pallets.ReFungible], async ({helper}) => {
+ const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(bob), pieces: 100n});
+ await (helper.ft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: charlie.address}, 100n);
+ const before = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});
+ await helper.rft.transferTokenFrom(charlie, collectionId, tokenId, testCase.account(bob), {Substrate: alice.address}, 100n);
+ const after = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});
+ expect(after - before).to.be.equal(BigInt(100));
+ const transferTokenFromTx = () => helper.rft.transferTokenFrom(charlie, collectionId, tokenId, testCase.account(bob), {Substrate: alice.address}, 100n);
+ await expect(transferTokenFromTx()).to.be.rejected;
});
});
- itSub('NFT', async ({helper}) => {
- const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
- const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});
- await helper.nft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});
- await helper.nft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});
- const owner = await helper.nft.getTokenOwner(collectionId, tokenId);
- expect(owner.Substrate).to.be.equal(alice.address);
+ describe(`[${testCase.method}] Approved amount decreases by the transferred amount:`, () => {
+ let alice: IKeyringPair;
+ let bob: IKeyringPair;
+ let charlie: IKeyringPair;
+ let dave: IKeyringPair;
+
+ before(async () => {
+ await usingPlaygrounds(async (helper, privateKey) => {
+ const donor = await privateKey({filename: __filename});
+ [alice, bob, charlie, dave] = await helper.arrange.createAccounts([100n, 100n, 100n, 100n], donor);
+ });
+ });
+
+ 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}) => {
+ const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);
+ await helper.ft.mintTokens(alice, collectionId, 10n, testCase.account(alice));
+ const tokenId = await helper.ft.getLastTokenId(collectionId);
+ await (helper.ft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address}, 10n);
+
+ const charlieBefore = await helper.ft.getBalance(collectionId, {Substrate: charlie.address});
+ await helper.ft.transferTokenFrom(bob, collectionId, tokenId, testCase.account(alice), {Substrate: charlie.address}, 2n);
+ const charlieAfter = await helper.ft.getBalance(collectionId, {Substrate: charlie.address});
+ expect(charlieAfter - charlieBefore).to.be.equal(BigInt(2));
+
+ const daveBefore = await helper.ft.getBalance(collectionId, {Substrate: dave.address});
+ await helper.ft.transferTokenFrom(bob, collectionId, tokenId, testCase.account(alice), {Substrate: dave.address}, 8n);
+ const daveAfter = await helper.ft.getBalance(collectionId, {Substrate: dave.address});
+ expect(daveAfter - daveBefore).to.be.equal(BigInt(8));
+ });
});
- itSub('Fungible up to an approved amount', async ({helper}) => {
- const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);
- await helper.ft.mintTokens(alice, collectionId, 10n, bob.address);
- const tokenId = await helper.ft.getLastTokenId(collectionId);
- await helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});
- const before = await helper.ft.getBalance(collectionId, {Substrate: alice.address});
- await helper.ft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 1n);
- const after = await helper.ft.getBalance(collectionId, {Substrate: alice.address});
- expect(after - before).to.be.equal(BigInt(1));
+ describe(`[${testCase.method}] User may clear the approvals to approving for 0 amount:`, () => {
+ let alice: IKeyringPair;
+ let bob: IKeyringPair;
+ let charlie: IKeyringPair;
+
+ before(async () => {
+ await usingPlaygrounds(async (helper, privateKey) => {
+ const donor = await privateKey({filename: __filename});
+ [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
+ });
+ });
+
+ itSub('NFT', async ({helper}) => {
+ const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(alice)});
+ await (helper.nft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address});
+ expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.true;
+ await (helper.nft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address}, 0n);
+ expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.false;
+ const transferTokenFromTx = () => helper.nft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: bob.address}, {Substrate: bob.address});
+ await expect(transferTokenFromTx()).to.be.rejected;
+ });
+
+ itSub('Fungible', async ({helper}) => {
+ const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);
+ await helper.ft.mintTokens(alice, collectionId, 10n, testCase.account(alice));
+ const tokenId = await helper.ft.getLastTokenId(collectionId);
+ await (helper.ft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address});
+ const amountBefore = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, testCase.account(alice));
+ expect(amountBefore).to.be.equal(BigInt(1));
+
+ await (helper.ft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address}, 0n);
+ const amountAfter = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, testCase.account(alice));
+ expect(amountAfter).to.be.equal(BigInt(0));
+
+ const transferTokenFromTx = () => helper.ft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: bob.address}, {Substrate: charlie.address}, 1n);
+ await expect(transferTokenFromTx()).to.be.rejected;
+ });
+
+ itSub.ifWithPallets('ReFungible', [Pallets.ReFungible], async ({helper}) => {
+ const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(alice), pieces: 100n});
+ await (helper.rft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address});
+ const amountBefore = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, testCase.account(alice));
+ expect(amountBefore).to.be.equal(BigInt(1));
+
+ await (helper.rft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address}, 0n);
+ const amountAfter = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, testCase.account(alice));
+ expect(amountAfter).to.be.equal(BigInt(0));
+
+ const transferTokenFromTx = () => helper.rft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: bob.address}, {Substrate: charlie.address}, 100n);
+ await expect(transferTokenFromTx()).to.be.rejected;
+ });
});
- itSub.ifWithPallets('ReFungible up to an approved amount', [Pallets.ReFungible], async ({helper}) => {
- const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
- const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: bob.address, pieces: 100n});
- await helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});
- const before = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});
- await helper.rft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 1n);
- const after = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});
- expect(after - before).to.be.equal(BigInt(1));
+ describe(`[${testCase.method}] User cannot approve for the amount greater than they own:`, () => {
+ let alice: IKeyringPair;
+ let bob: IKeyringPair;
+ let charlie: IKeyringPair;
+
+ before(async () => {
+ await usingPlaygrounds(async (helper, privateKey) => {
+ const donor = await privateKey({filename: __filename});
+ [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
+ });
+ });
+
+ itSub('1 for NFT', async ({helper}) => {
+ const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(bob)});
+ const result = (helper.nft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: charlie.address}, 2n);
+ await expect(result).to.be.rejected;
+ expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: charlie.address})).to.be.false;
+ });
+
+ itSub('Fungible', async ({helper}) => {
+ const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);
+ await helper.ft.mintTokens(alice, collectionId, 10n, testCase.account(alice));
+ const tokenId = await helper.ft.getLastTokenId(collectionId);
+ const result = (helper.ft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address}, 11n);
+ await expect(result).to.be.rejected;
+ });
+
+ itSub.ifWithPallets('ReFungible', [Pallets.ReFungible], async ({helper}) => {
+ const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(alice), pieces: 100n});
+ const result = (helper.rft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: bob.address}, 101n);
+ await expect(result).to.be.rejected;
+ });
});
-});
-describe('Approved users cannot use transferFrom to repeat transfers if approved amount was already transferred:', () => {
- let alice: IKeyringPair;
- let bob: IKeyringPair;
- let charlie: IKeyringPair;
+ describe(`[${testCase.method}] Integration Test approve(spender, collection_id, item_id, amount) with collection admin permissions:`, () => {
+ let alice: IKeyringPair;
+ let bob: IKeyringPair;
+ let charlie: IKeyringPair;
+
+ before(async () => {
+ await usingPlaygrounds(async (helper, privateKey) => {
+ const donor = await privateKey({filename: __filename});
+ [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
+ });
+ });
- before(async () => {
- await usingPlaygrounds(async (helper, privateKey) => {
- const donor = await privateKey({filename: __filename});
- [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
+ itSub('can be called by collection admin on non-owned item', async ({helper}) => {
+ const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(alice)});
+ await helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address});
+ const result = (helper.nft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: charlie.address});
+ await expect(result).to.be.rejected;
});
});
- itSub('NFT', async ({helper}) => {
- const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
- const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});
- await helper.nft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});
- await helper.nft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});
- const owner = await helper.nft.getTokenOwner(collectionId, tokenId);
- expect(owner.Substrate).to.be.equal(alice.address);
- const transferTokenFromTx = () => helper.nft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});
- await expect(transferTokenFromTx()).to.be.rejected;
- });
+ describe(`[${testCase.method}] Negative Integration Test approve(spender, collection_id, item_id, amount):`, () => {
+ let alice: IKeyringPair;
+ let bob: IKeyringPair;
+ let charlie: IKeyringPair;
- itSub('Fungible up to an approved amount', async ({helper}) => {
- const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);
- await helper.ft.mintTokens(alice, collectionId, 10n, bob.address);
- const tokenId = await helper.ft.getLastTokenId(collectionId);
- await helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});
- const before = await helper.ft.getBalance(collectionId, {Substrate: alice.address});
- await helper.ft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 1n);
- const after = await helper.ft.getBalance(collectionId, {Substrate: alice.address});
- expect(after - before).to.be.equal(BigInt(1));
+ before(async () => {
+ await usingPlaygrounds(async (helper, privateKey) => {
+ const donor = await privateKey({filename: __filename});
+ [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
+ });
+ });
- const transferTokenFromTx = () => helper.ft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 1n);
- await expect(transferTokenFromTx()).to.be.rejected;
- });
+ itSub('[nft] Approve for a collection that does not exist', async ({helper}) => {
+ const collectionId = 1 << 32 - 1;
+ await expect((helper.nft as any)[testCase.method](bob, collectionId, 1, {Substrate: charlie.address})).to.be.rejected;
+ });
+
+ itSub('[fungible] Approve for a collection that does not exist', async ({helper}) => {
+ const collectionId = 1 << 32 - 1;
+ const approveTx = () => (helper.ft as any)[testCase.method](bob, collectionId, 1, {Substrate: charlie.address});
+ await expect(approveTx()).to.be.rejected;
+ });
- itSub.ifWithPallets('ReFungible up to an approved amount', [Pallets.ReFungible], async ({helper}) => {
- const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
- const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: bob.address, pieces: 100n});
- await helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address}, 100n);
- const before = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});
- await helper.rft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 100n);
- const after = await helper.rft.getTokenBalance(collectionId, tokenId, {Substrate: alice.address});
- expect(after - before).to.be.equal(BigInt(100));
- const transferTokenFromTx = () => helper.rft.transferTokenFrom(charlie, collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address}, 100n);
- await expect(transferTokenFromTx()).to.be.rejected;
- });
-});
+ itSub.ifWithPallets('[refungible] Approve for a collection that does not exist', [Pallets.ReFungible], async ({helper}) => {
+ const collectionId = 1 << 32 - 1;
+ const approveTx = () => (helper.rft as any)[testCase.method](bob, collectionId, 1, {Substrate: charlie.address});
+ await expect(approveTx()).to.be.rejected;
+ });
-describe('Approved amount decreases by the transferred amount:', () => {
- let alice: IKeyringPair;
- let bob: IKeyringPair;
- let charlie: IKeyringPair;
- let dave: IKeyringPair;
+ itSub('[nft] Approve for a collection that was destroyed', async ({helper}) => {
+ const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ await helper.nft.burn(alice, collectionId);
+ const approveTx = () => (helper.nft as any)[testCase.method](alice, collectionId, 1, {Substrate: bob.address});
+ await expect(approveTx()).to.be.rejected;
+ });
- before(async () => {
- await usingPlaygrounds(async (helper, privateKey) => {
- const donor = await privateKey({filename: __filename});
- [alice, bob, charlie, dave] = await helper.arrange.createAccounts([100n, 100n, 100n, 100n], donor);
+ itSub('[fungible] Approve for a collection that was destroyed', async ({helper}) => {
+ const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ await helper.ft.burn(alice, collectionId);
+ const approveTx = () => (helper.ft as any)[testCase.method](alice, collectionId, 1, {Substrate: bob.address});
+ await expect(approveTx()).to.be.rejected;
});
- });
- 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}) => {
- const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);
- await helper.ft.mintTokens(alice, collectionId, 10n, alice.address);
- const tokenId = await helper.ft.getLastTokenId(collectionId);
- await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 10n);
+ itSub.ifWithPallets('[refungible] Approve for a collection that was destroyed', [Pallets.ReFungible], async ({helper}) => {
+ const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ await helper.rft.burn(alice, collectionId);
+ const approveTx = () => (helper.rft as any)[testCase.method](alice, collectionId, 1, {Substrate: bob.address});
+ await expect(approveTx()).to.be.rejected;
+ });
- const charlieBefore = await helper.ft.getBalance(collectionId, {Substrate: charlie.address});
- await helper.ft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: alice.address}, {Substrate: charlie.address}, 2n);
- const charlieAfter = await helper.ft.getBalance(collectionId, {Substrate: charlie.address});
- expect(charlieAfter - charlieBefore).to.be.equal(BigInt(2));
+ itSub('[nft] Approve transfer of a token that does not exist', async ({helper}) => {
+ const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const approveTx = () => (helper.nft as any)[testCase.method](alice, collectionId, 2, {Substrate: bob.address});
+ await expect(approveTx()).to.be.rejected;
+ });
- const daveBefore = await helper.ft.getBalance(collectionId, {Substrate: dave.address});
- await helper.ft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: alice.address}, {Substrate: dave.address}, 8n);
- const daveAfter = await helper.ft.getBalance(collectionId, {Substrate: dave.address});
- expect(daveAfter - daveBefore).to.be.equal(BigInt(8));
- });
-});
+ itSub.ifWithPallets('[refungible] Approve transfer of a token that does not exist', [Pallets.ReFungible], async ({helper}) => {
+ const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const approveTx = () => (helper.rft as any)[testCase.method](alice, collectionId, 2, {Substrate: bob.address});
+ await expect(approveTx()).to.be.rejected;
+ });
-describe('User may clear the approvals to approving for 0 amount:', () => {
- let alice: IKeyringPair;
- let bob: IKeyringPair;
- let charlie: IKeyringPair;
+ itSub('[nft] Approve using the address that does not own the approved token', async ({helper}) => {
+ const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(alice)});
+ const approveTx = () => (helper.nft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: alice.address});
+ await expect(approveTx()).to.be.rejected;
+ });
- before(async () => {
- await usingPlaygrounds(async (helper, privateKey) => {
- const donor = await privateKey({filename: __filename});
- [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
+ itSub('[fungible] Approve using the address that does not own the approved token', async ({helper}) => {
+ const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ await helper.ft.mintTokens(alice, collectionId, 10n, testCase.account(alice));
+ const tokenId = await helper.ft.getLastTokenId(collectionId);
+ const approveTx = () => (helper.ft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: alice.address});
+ await expect(approveTx()).to.be.rejected;
});
- });
- itSub('NFT', async ({helper}) => {
- const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
- const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
- await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});
- expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.true;
- await helper.signTransaction(alice, helper.constructApiCall('api.tx.unique.approve', [{Substrate: bob.address}, collectionId, tokenId, 0]));
- expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.false;
- const transferTokenFromTx = () => helper.nft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: bob.address}, {Substrate: bob.address});
- await expect(transferTokenFromTx()).to.be.rejected;
- });
+ itSub.ifWithPallets('[refungible] Approve using the address that does not own the approved token', [Pallets.ReFungible], async ({helper}) => {
+ const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(alice), pieces: 100n});
+ const approveTx = () => (helper.rft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: alice.address});
+ await expect(approveTx()).to.be.rejected;
+ });
- itSub('Fungible', async ({helper}) => {
- const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);
- await helper.ft.mintTokens(alice, collectionId, 10n, alice.address);
- const tokenId = await helper.ft.getLastTokenId(collectionId);
- await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});
- const amountBefore = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});
- expect(amountBefore).to.be.equal(BigInt(1));
+ itSub.ifWithPallets('should fail if approved more ReFungibles than owned', [Pallets.ReFungible], async ({helper}) => {
+ const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n});
+ await helper.rft.transferToken(alice, collectionId, tokenId, testCase.account(bob), 100n);
+ await (helper.rft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: alice.address}, 100n);
- await helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 0n);
- const amountAfter = await helper.ft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});
- expect(amountAfter).to.be.equal(BigInt(0));
+ const approveTx = () => (helper.rft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: alice.address}, 101n);
+ await expect(approveTx()).to.be.rejected;
+ });
- const transferTokenFromTx = () => helper.ft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: bob.address}, {Substrate: charlie.address}, 1n);
- await expect(transferTokenFromTx()).to.be.rejected;
- });
+ itSub('should fail if approved more Fungibles than owned', async ({helper}) => {
+ const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ await helper.ft.mintTokens(alice, collectionId, 10n, alice.address);
+ const tokenId = await helper.ft.getLastTokenId(collectionId);
- itSub.ifWithPallets('ReFungible', [Pallets.ReFungible], async ({helper}) => {
- const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
- const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n});
- await helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});
- const amountBefore = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});
- expect(amountBefore).to.be.equal(BigInt(1));
+ await helper.ft.transferToken(alice, collectionId, tokenId, testCase.account(bob), 10n);
+ await (helper.ft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: alice.address}, 10n);
+ const approveTx = () => (helper.ft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: alice.address}, 11n);
+ await expect(approveTx()).to.be.rejected;
+ });
- await helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 0n);
- const amountAfter = await helper.rft.getTokenApprovedPieces(collectionId, tokenId, {Substrate: bob.address}, {Substrate: alice.address});
- expect(amountAfter).to.be.equal(BigInt(0));
+ itSub('fails when called by collection owner on non-owned item when OwnerCanTransfer == false', async ({helper}) => {
+ const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: testCase.account(bob)});
+ await helper.collection.setLimits(alice, collectionId, {ownerCanTransfer: false});
- const transferTokenFromTx = () => helper.rft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: bob.address}, {Substrate: charlie.address}, 100n);
- await expect(transferTokenFromTx()).to.be.rejected;
+ const approveTx = () => (helper.nft as any)[testCase.method](alice, collectionId, tokenId, {Substrate: charlie.address});
+ await expect(approveTx()).to.be.rejected;
+ });
});
});
-describe('User cannot approve for the amount greater than they own:', () => {
+describe('Normal user can approve other users to be wallet operator:', () => {
let alice: IKeyringPair;
let bob: IKeyringPair;
- let charlie: IKeyringPair;
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
const donor = await privateKey({filename: __filename});
- [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
+ [alice, bob] = await helper.arrange.createAccounts([100n, 100n], donor);
});
});
- itSub('1 for NFT', async ({helper}) => {
+ itSub('[nft] Enable and disable approval', async ({helper}) => {
const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
- const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});
- const approveTx = () => helper.signTransaction(bob, helper.constructApiCall('api.tx.unique.approve', [{Substrate: charlie.address}, collectionId, tokenId, 2]));
- await expect(approveTx()).to.be.rejected;
- expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: charlie.address})).to.be.false;
- });
- itSub('Fungible', async ({helper}) => {
- const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);
- await helper.ft.mintTokens(alice, collectionId, 10n, alice.address);
- const tokenId = await helper.ft.getLastTokenId(collectionId);
- const approveTx = () => helper.ft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 11n);
- await expect(approveTx()).to.be.rejected;
+ const checkBeforeApproval = await helper.nft.allowanceForAll(collectionId, {Substrate: alice.address}, {Substrate: bob.address});
+ expect(checkBeforeApproval).to.be.false;
+
+ await helper.nft.setAllowanceForAll(alice, collectionId, {Substrate: bob.address}, true);
+ const checkAfterApproval = await helper.nft.allowanceForAll(collectionId, {Substrate: alice.address}, {Substrate: bob.address});
+ expect(checkAfterApproval).to.be.true;
+
+ await helper.nft.setAllowanceForAll(alice, collectionId, {Substrate: bob.address}, false);
+ const checkAfterDisapproval = await helper.nft.allowanceForAll(collectionId, {Substrate: alice.address}, {Substrate: bob.address});
+ expect(checkAfterDisapproval).to.be.false;
});
- itSub.ifWithPallets('ReFungible', [Pallets.ReFungible], async ({helper}) => {
+ itSub.ifWithPallets('[rft] Enable and disable approval', [Pallets.ReFungible], async ({helper}) => {
const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
- const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n});
- const approveTx = () => helper.rft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, 101n);
- await expect(approveTx()).to.be.rejected;
+
+ const checkBeforeApproval = await helper.rft.allowanceForAll(collectionId, {Substrate: alice.address}, {Substrate: bob.address});
+ expect(checkBeforeApproval).to.be.false;
+
+ await helper.rft.setAllowanceForAll(alice, collectionId, {Substrate: bob.address}, true);
+ const checkAfterApproval = await helper.rft.allowanceForAll(collectionId, {Substrate: alice.address}, {Substrate: bob.address});
+ expect(checkAfterApproval).to.be.true;
+
+ await helper.rft.setAllowanceForAll(alice, collectionId, {Substrate: bob.address}, false);
+ const checkAfterDisapproval = await helper.rft.allowanceForAll(collectionId, {Substrate: alice.address}, {Substrate: bob.address});
+ expect(checkAfterDisapproval).to.be.false;
});
});
@@ -464,184 +649,5 @@
await token.approve(dave, {Substrate: bob.address}, 50n);
await expect(token.approve(dave, {Substrate: charlie.address}, 51n))
.to.be.rejectedWith('this test would fail (since it is skipped), replace this expecting message with what would have been received');
- });
-});
-
-describe('Integration Test approve(spender, collection_id, item_id, amount) with collection admin permissions:', () => {
- let alice: IKeyringPair;
- let bob: IKeyringPair;
- let charlie: IKeyringPair;
-
- before(async () => {
- await usingPlaygrounds(async (helper, privateKey) => {
- const donor = await privateKey({filename: __filename});
- [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
- });
- });
-
- itSub('can be called by collection admin on non-owned item', async ({helper}) => {
- const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
- const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
- await helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address});
- const approveTx = () => helper.nft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address});
- await expect(approveTx()).to.be.rejected;
- });
-});
-
-describe('Negative Integration Test approve(spender, collection_id, item_id, amount):', () => {
- let alice: IKeyringPair;
- let bob: IKeyringPair;
- let charlie: IKeyringPair;
-
- before(async () => {
- await usingPlaygrounds(async (helper, privateKey) => {
- const donor = await privateKey({filename: __filename});
- [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
- });
- });
-
- itSub('[nft] Approve for a collection that does not exist', async ({helper}) => {
- const collectionId = 1 << 32 - 1;
- const approveTx = () => helper.nft.approveToken(bob, collectionId, 1, {Substrate: charlie.address});
- await expect(approveTx()).to.be.rejected;
- });
-
- itSub('[fungible] Approve for a collection that does not exist', async ({helper}) => {
- const collectionId = 1 << 32 - 1;
- const approveTx = () => helper.ft.approveToken(bob, collectionId, 1, {Substrate: charlie.address});
- await expect(approveTx()).to.be.rejected;
- });
-
- itSub.ifWithPallets('[refungible] Approve for a collection that does not exist', [Pallets.ReFungible], async ({helper}) => {
- const collectionId = 1 << 32 - 1;
- const approveTx = () => helper.rft.approveToken(bob, collectionId, 1, {Substrate: charlie.address});
- await expect(approveTx()).to.be.rejected;
- });
-
- itSub('[nft] Approve for a collection that was destroyed', async ({helper}) => {
- const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
- await helper.nft.burn(alice, collectionId);
- const approveTx = () => helper.nft.approveToken(alice, collectionId, 1, {Substrate: bob.address});
- await expect(approveTx()).to.be.rejected;
- });
-
- itSub('[fungible] Approve for a collection that was destroyed', async ({helper}) => {
- const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
- await helper.ft.burn(alice, collectionId);
- const approveTx = () => helper.ft.approveToken(alice, collectionId, 1, {Substrate: bob.address});
- await expect(approveTx()).to.be.rejected;
- });
-
- itSub.ifWithPallets('[refungible] Approve for a collection that was destroyed', [Pallets.ReFungible], async ({helper}) => {
- const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
- await helper.rft.burn(alice, collectionId);
- const approveTx = () => helper.rft.approveToken(alice, collectionId, 1, {Substrate: bob.address});
- await expect(approveTx()).to.be.rejected;
- });
-
- itSub('[nft] Approve transfer of a token that does not exist', async ({helper}) => {
- const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
- const approveTx = () => helper.nft.approveToken(alice, collectionId, 2, {Substrate: bob.address});
- await expect(approveTx()).to.be.rejected;
- });
-
- itSub.ifWithPallets('[refungible] Approve transfer of a token that does not exist', [Pallets.ReFungible], async ({helper}) => {
- const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
- const approveTx = () => helper.rft.approveToken(alice, collectionId, 2, {Substrate: bob.address});
- await expect(approveTx()).to.be.rejected;
- });
-
- itSub('[nft] Approve using the address that does not own the approved token', async ({helper}) => {
- const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
- const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
- const approveTx = () => helper.nft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address});
- await expect(approveTx()).to.be.rejected;
- });
-
- itSub('[fungible] Approve using the address that does not own the approved token', async ({helper}) => {
- const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
- await helper.ft.mintTokens(alice, collectionId, 10n, alice.address);
- const tokenId = await helper.ft.getLastTokenId(collectionId);
- const approveTx = () => helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address});
- await expect(approveTx()).to.be.rejected;
- });
-
- itSub.ifWithPallets('[refungible] Approve using the address that does not own the approved token', [Pallets.ReFungible], async ({helper}) => {
- const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
- const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n});
- const approveTx = () => helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address});
- await expect(approveTx()).to.be.rejected;
- });
-
- itSub.ifWithPallets('should fail if approved more ReFungibles than owned', [Pallets.ReFungible], async ({helper}) => {
- const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
- const {tokenId} = await helper.rft.mintToken(alice, {collectionId: collectionId, owner: alice.address, pieces: 100n});
- await helper.rft.transferToken(alice, collectionId, tokenId, {Substrate: bob.address}, 100n);
- await helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address}, 100n);
-
- const approveTx = () => helper.rft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address}, 101n);
- await expect(approveTx()).to.be.rejected;
- });
-
- itSub('should fail if approved more Fungibles than owned', async ({helper}) => {
- const {collectionId} = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
- await helper.ft.mintTokens(alice, collectionId, 10n, alice.address);
- const tokenId = await helper.ft.getLastTokenId(collectionId);
-
- await helper.ft.transferToken(alice, collectionId, tokenId, {Substrate: bob.address}, 10n);
- await helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address}, 10n);
- const approveTx = () => helper.ft.approveToken(bob, collectionId, tokenId, {Substrate: alice.address}, 11n);
- await expect(approveTx()).to.be.rejected;
- });
-
- itSub('fails when called by collection owner on non-owned item when OwnerCanTransfer == false', async ({helper}) => {
- const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
- const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});
- await helper.collection.setLimits(alice, collectionId, {ownerCanTransfer: false});
-
- const approveTx = () => helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: charlie.address});
- await expect(approveTx()).to.be.rejected;
- });
-});
-
-describe('Normal user can approve other users to be wallet operator:', () => {
- let alice: IKeyringPair;
- let bob: IKeyringPair;
-
- before(async () => {
- await usingPlaygrounds(async (helper, privateKey) => {
- const donor = await privateKey({filename: __filename});
- [alice, bob] = await helper.arrange.createAccounts([100n, 100n], donor);
- });
- });
-
- itSub('[nft] Enable and disable approval', async ({helper}) => {
- const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
-
- const checkBeforeApproval = await helper.nft.allowanceForAll(collectionId, {Substrate: alice.address}, {Substrate: bob.address});
- expect(checkBeforeApproval).to.be.false;
-
- await helper.nft.setAllowanceForAll(alice, collectionId, {Substrate: bob.address}, true);
- const checkAfterApproval = await helper.nft.allowanceForAll(collectionId, {Substrate: alice.address}, {Substrate: bob.address});
- expect(checkAfterApproval).to.be.true;
-
- await helper.nft.setAllowanceForAll(alice, collectionId, {Substrate: bob.address}, false);
- const checkAfterDisapproval = await helper.nft.allowanceForAll(collectionId, {Substrate: alice.address}, {Substrate: bob.address});
- expect(checkAfterDisapproval).to.be.false;
- });
-
- itSub.ifWithPallets('[rft] Enable and disable approval', [Pallets.ReFungible], async ({helper}) => {
- const {collectionId} = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
-
- const checkBeforeApproval = await helper.rft.allowanceForAll(collectionId, {Substrate: alice.address}, {Substrate: bob.address});
- expect(checkBeforeApproval).to.be.false;
-
- await helper.rft.setAllowanceForAll(alice, collectionId, {Substrate: bob.address}, true);
- const checkAfterApproval = await helper.rft.allowanceForAll(collectionId, {Substrate: alice.address}, {Substrate: bob.address});
- expect(checkAfterApproval).to.be.true;
-
- await helper.rft.setAllowanceForAll(alice, collectionId, {Substrate: bob.address}, false);
- const checkAfterDisapproval = await helper.rft.allowanceForAll(collectionId, {Substrate: alice.address}, {Substrate: bob.address});
- expect(checkAfterDisapproval).to.be.false;
});
});
tests/src/eth/api/ContractHelpers.soldiffbeforeafterboth--- a/tests/src/eth/api/ContractHelpers.sol
+++ b/tests/src/eth/api/ContractHelpers.sol
@@ -183,9 +183,9 @@
/// Ethereum representation of Optional value with CrossAddress.
struct OptionCrossAddress {
- /// TODO: field description
+ /// Whether or not this CrossAdress is valid and has meaning.
bool status;
- /// TODO: field description
+ /// The underlying CrossAddress value. If the status is false, can be set to whatever.
CrossAddress value;
}
tests/src/interfaces/augment-api-errors.tsdiffbeforeafterboth--- a/tests/src/interfaces/augment-api-errors.ts
+++ b/tests/src/interfaces/augment-api-errors.ts
@@ -85,6 +85,10 @@
**/
AccountTokenLimitExceeded: AugmentedError<ApiType>;
/**
+ * Only spending from eth mirror could be approved
+ **/
+ AddressIsNotEthMirror: AugmentedError<ApiType>;
+ /**
* Can't transfer tokens to ethereum zero address
**/
AddressIsZero: AugmentedError<ApiType>;
tests/src/interfaces/augment-api-tx.tsdiffbeforeafterboth--- a/tests/src/interfaces/augment-api-tx.ts
+++ b/tests/src/interfaces/augment-api-tx.ts
@@ -1214,6 +1214,25 @@
**/
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]>;
/**
+ * Allow a non-permissioned address to transfer or burn an item from owner's eth mirror.
+ *
+ * # Permissions
+ *
+ * * Collection owner
+ * * Collection admin
+ * * Current item owner
+ *
+ * # Arguments
+ *
+ * * `from`: Owner's account eth mirror
+ * * `to`: Account to be approved to make specific transactions on non-owned tokens.
+ * * `collection_id`: ID of the collection the item belongs to.
+ * * `item_id`: ID of the item transactions on which are now approved.
+ * * `amount`: Number of pieces of the item approved for a transaction (maximum of 1 for NFTs).
+ * Set to 0 to revoke the approval.
+ **/
+ 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]>;
+ /**
* Destroy a token on behalf of the owner as a non-owner account.
*
* See also: [`approve`][`Pallet::approve`].
tests/src/interfaces/default/types.tsdiffbeforeafterboth--- a/tests/src/interfaces/default/types.ts
+++ b/tests/src/interfaces/default/types.ts
@@ -1216,6 +1216,7 @@
readonly isTokenValueTooLow: boolean;
readonly isApprovedValueTooLow: boolean;
readonly isCantApproveMoreThanOwned: boolean;
+ readonly isAddressIsNotEthMirror: boolean;
readonly isAddressIsZero: boolean;
readonly isUnsupportedOperation: boolean;
readonly isNotSufficientFounds: boolean;
@@ -1231,7 +1232,7 @@
readonly isCollectionIsInternal: boolean;
readonly isConfirmSponsorshipFail: boolean;
readonly isUserIsNotCollectionAdmin: boolean;
- 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';
+ 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';
}
/** @name PalletCommonEvent */
@@ -2306,6 +2307,14 @@
readonly itemId: u32;
readonly amount: u128;
} & Struct;
+ readonly isApproveFrom: boolean;
+ readonly asApproveFrom: {
+ readonly from: PalletEvmAccountBasicCrossAccountIdRepr;
+ readonly to: PalletEvmAccountBasicCrossAccountIdRepr;
+ readonly collectionId: u32;
+ readonly itemId: u32;
+ readonly amount: u128;
+ } & Struct;
readonly isTransferFrom: boolean;
readonly asTransferFrom: {
readonly from: PalletEvmAccountBasicCrossAccountIdRepr;
@@ -2345,7 +2354,7 @@
readonly collectionId: u32;
readonly itemId: u32;
} & Struct;
- 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';
+ 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';
}
/** @name PalletUniqueError */
tests/src/interfaces/lookup.tsdiffbeforeafterboth--- a/tests/src/interfaces/lookup.ts
+++ b/tests/src/interfaces/lookup.ts
@@ -2264,6 +2264,13 @@
itemId: 'u32',
amount: 'u128',
},
+ approve_from: {
+ from: 'PalletEvmAccountBasicCrossAccountIdRepr',
+ to: 'PalletEvmAccountBasicCrossAccountIdRepr',
+ collectionId: 'u32',
+ itemId: 'u32',
+ amount: 'u128',
+ },
transfer_from: {
from: 'PalletEvmAccountBasicCrossAccountIdRepr',
recipient: 'PalletEvmAccountBasicCrossAccountIdRepr',
@@ -3280,7 +3287,7 @@
* Lookup423: pallet_common::pallet::Error<T>
**/
PalletCommonError: {
- _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']
+ _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']
},
/**
* Lookup425: pallet_fungible::pallet::Error<T>
tests/src/interfaces/types-lookup.tsdiffbeforeafterboth--- a/tests/src/interfaces/types-lookup.ts
+++ b/tests/src/interfaces/types-lookup.ts
@@ -2493,6 +2493,14 @@
readonly itemId: u32;
readonly amount: u128;
} & Struct;
+ readonly isApproveFrom: boolean;
+ readonly asApproveFrom: {
+ readonly from: PalletEvmAccountBasicCrossAccountIdRepr;
+ readonly to: PalletEvmAccountBasicCrossAccountIdRepr;
+ readonly collectionId: u32;
+ readonly itemId: u32;
+ readonly amount: u128;
+ } & Struct;
readonly isTransferFrom: boolean;
readonly asTransferFrom: {
readonly from: PalletEvmAccountBasicCrossAccountIdRepr;
@@ -2532,7 +2540,7 @@
readonly collectionId: u32;
readonly itemId: u32;
} & Struct;
- 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';
+ 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';
}
/** @name UpDataStructsCollectionMode (236) */
@@ -3564,6 +3572,7 @@
readonly isTokenValueTooLow: boolean;
readonly isApprovedValueTooLow: boolean;
readonly isCantApproveMoreThanOwned: boolean;
+ readonly isAddressIsNotEthMirror: boolean;
readonly isAddressIsZero: boolean;
readonly isUnsupportedOperation: boolean;
readonly isNotSufficientFounds: boolean;
@@ -3579,7 +3588,7 @@
readonly isCollectionIsInternal: boolean;
readonly isConfirmSponsorshipFail: boolean;
readonly isUserIsNotCollectionAdmin: boolean;
- 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';
+ 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';
}
/** @name PalletFungibleError (425) */
tests/src/util/playgrounds/unique.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/unique.ts
+++ b/tests/src/util/playgrounds/unique.ts
@@ -633,6 +633,10 @@
let call = this.getApi() as any;
for(const part of apiCall.slice(4).split('.')) {
call = call[part];
+ if (!call) {
+ const advice = part.includes('_') ? ' Looks like it needs to be converted to camel case.' : '';
+ throw Error(`Function ${part} of api call ${apiCall} not found.${advice}`);
+ }
}
return call(...params);
}
@@ -1259,6 +1263,42 @@
}
/**
+ * Set, change, or remove approved address to transfer the ownership of the NFT from eth mirror.
+ *
+ * @param signer keyring of signer
+ * @param collectionId ID of collection
+ * @param tokenId ID of token
+ * @param fromAddressObj Signer's Ethereum address containing her tokens
+ * @param toAddressObj Substrate or Ethereum address which gets approved use of the signer's tokens
+ * @param amount amount of token to be approved. For NFT must be set to 1n
+ * @returns ```true``` if extrinsic success, otherwise ```false```
+ */
+ async approveTokenFrom(signer: IKeyringPair, collectionId: number, tokenId: number, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId, amount=1n) {
+ const approveResult = await this.helper.executeExtrinsic(
+ signer,
+ 'api.tx.unique.approveFrom', [fromAddressObj, toAddressObj, collectionId, tokenId, amount],
+ true, // `Unable to approve token for ${label}`,
+ );
+
+ return this.helper.util.findCollectionInEvents(approveResult.result.events, collectionId, 'common', 'Approved');
+ }
+
+ /**
+ * Set, change, or remove approved address to transfer the ownership of the NFT from eth mirror.
+ *
+ * @param signer keyring of signer
+ * @param collectionId ID of collection
+ * @param tokenId ID of token
+ * @param toAddressObj Substrate or Ethereum address which gets approved use of the signer's tokens
+ * @param amount amount of token to be approved. For NFT must be set to 1n
+ * @returns ```true``` if extrinsic success, otherwise ```false```
+ */
+ async approveTokenFromEth(signer: IKeyringPair, collectionId: number, tokenId: number, toAddressObj: ICrossAccountId, amount=1n) {
+ const ethMirror = CrossAccountId.fromKeyring(signer).toEthereum();
+ return await this.approveTokenFrom(signer, collectionId, tokenId, ethMirror, toAddressObj, amount);
+ }
+
+ /**
* Get the amount of token pieces approved to transfer or burn. Normally 0.
*
* @param collectionId ID of collection
@@ -1756,8 +1796,8 @@
* @example approveToken(aliceKeyring, 10, 5, {Substrate: "5DyN4Y92vZCjv38fg..."})
* @returns ```true``` if extrinsic success, otherwise ```false```
*/
- approveToken(signer: IKeyringPair, collectionId: number, tokenId: number, toAddressObj: ICrossAccountId) {
- return super.approveToken(signer, collectionId, tokenId, toAddressObj, 1n);
+ approveToken(signer: IKeyringPair, collectionId: number, tokenId: number, toAddressObj: ICrossAccountId, amount=1n) {
+ return super.approveToken(signer, collectionId, tokenId, toAddressObj, amount);
}
}