difftreelog
refactor Generalization some operations.
in: master
13 files changed
pallets/common/src/erc.rsdiffbeforeafterboth--- a/pallets/common/src/erc.rs
+++ b/pallets/common/src/erc.rs
@@ -222,12 +222,11 @@
fn set_collection_sponsor(&mut self, caller: caller, sponsor: address) -> Result<void> {
self.consume_store_reads_and_writes(1, 1)?;
- check_is_owner_or_admin(caller, self)?;
+ let caller = T::CrossAccountId::from_eth(caller);
let sponsor = T::CrossAccountId::from_eth(sponsor);
- self.set_sponsor(sponsor.as_sub().clone())
- .map_err(dispatch_to_evm::<T>)?;
- save(self)
+ self.set_sponsor(&caller, sponsor.as_sub().clone())
+ .map_err(dispatch_to_evm::<T>)
}
/// Set the sponsor of the collection.
@@ -242,12 +241,11 @@
) -> Result<void> {
self.consume_store_reads_and_writes(1, 1)?;
- check_is_owner_or_admin(caller, self)?;
+ let caller = T::CrossAccountId::from_eth(caller);
let sponsor = sponsor.into_sub_cross_account::<T>()?;
- self.set_sponsor(sponsor.as_sub().clone())
- .map_err(dispatch_to_evm::<T>)?;
- save(self)
+ self.set_sponsor(&caller, sponsor.as_sub().clone())
+ .map_err(dispatch_to_evm::<T>)
}
/// Whether there is a pending sponsor.
@@ -265,21 +263,15 @@
self.consume_store_writes(1)?;
let caller = T::CrossAccountId::from_eth(caller);
- if !self
- .confirm_sponsorship(caller.as_sub())
- .map_err(dispatch_to_evm::<T>)?
- {
- return Err("caller is not set as sponsor".into());
- }
- save(self)
+ self.confirm_sponsorship(caller.as_sub())
+ .map_err(dispatch_to_evm::<T>)
}
/// Remove collection sponsor.
fn remove_collection_sponsor(&mut self, caller: caller) -> Result<void> {
self.consume_store_reads_and_writes(1, 1)?;
- check_is_owner_or_admin(caller, self)?;
- self.remove_sponsor().map_err(dispatch_to_evm::<T>)?;
- save(self)
+ let caller = T::CrossAccountId::from_eth(caller);
+ self.remove_sponsor(&caller).map_err(dispatch_to_evm::<T>)
}
/// Get current sponsor.
@@ -333,7 +325,6 @@
}
};
- check_is_owner_or_admin(caller, self)?;
let mut limits = self.limits.clone();
match limit.as_str() {
@@ -366,9 +357,9 @@
}
_ => return Err(Error::Revert(format!("unknown limit \"{}\"", limit))),
}
- self.limits = <Pallet<T>>::clamp_limits(self.mode.clone(), &self.limits, limits)
- .map_err(dispatch_to_evm::<T>)?;
- save(self)
+
+ let caller = T::CrossAccountId::from_eth(caller);
+ <Pallet<T>>::update_limits(&caller, self, limits).map_err(dispatch_to_evm::<T>)
}
/// Get contract address.
@@ -383,7 +374,7 @@
caller: caller,
new_admin: EthCrossAccount,
) -> Result<void> {
- self.consume_store_writes(2)?;
+ self.consume_store_reads_and_writes(2, 2)?;
let caller = T::CrossAccountId::from_eth(caller);
let new_admin = new_admin.into_sub_cross_account::<T>()?;
@@ -398,7 +389,7 @@
caller: caller,
admin: EthCrossAccount,
) -> Result<void> {
- self.consume_store_writes(2)?;
+ self.consume_store_reads_and_writes(2, 2)?;
let caller = T::CrossAccountId::from_eth(caller);
let admin = admin.into_sub_cross_account::<T>()?;
@@ -410,7 +401,7 @@
/// @param newAdmin Address of the added administrator.
#[solidity(hide)]
fn add_collection_admin(&mut self, caller: caller, new_admin: address) -> Result<void> {
- self.consume_store_writes(2)?;
+ self.consume_store_reads_and_writes(2, 2)?;
let caller = T::CrossAccountId::from_eth(caller);
let new_admin = T::CrossAccountId::from_eth(new_admin);
@@ -423,7 +414,7 @@
/// @param admin Address of the removed administrator.
#[solidity(hide)]
fn remove_collection_admin(&mut self, caller: caller, admin: address) -> Result<void> {
- self.consume_store_writes(2)?;
+ self.consume_store_reads_and_writes(2, 2)?;
let caller = T::CrossAccountId::from_eth(caller);
let admin = T::CrossAccountId::from_eth(admin);
@@ -438,7 +429,7 @@
fn set_nesting_bool(&mut self, caller: caller, enable: bool) -> Result<void> {
self.consume_store_reads_and_writes(1, 1)?;
- check_is_owner_or_admin(caller, self)?;
+ let caller = T::CrossAccountId::from_eth(caller);
let mut permissions = self.collection.permissions.clone();
let mut nesting = permissions.nesting().clone();
@@ -446,14 +437,7 @@
nesting.restricted = None;
permissions.nesting = Some(nesting);
- self.collection.permissions = <Pallet<T>>::clamp_permissions(
- self.collection.mode.clone(),
- &self.collection.permissions,
- permissions,
- )
- .map_err(dispatch_to_evm::<T>)?;
-
- save(self)
+ <Pallet<T>>::update_permissions(&caller, self, permissions).map_err(dispatch_to_evm::<T>)
}
/// Toggle accessibility of collection nesting.
@@ -472,7 +456,7 @@
if collections.is_empty() {
return Err("no addresses provided".into());
}
- check_is_owner_or_admin(caller, self)?;
+ let caller = T::CrossAccountId::from_eth(caller);
let mut permissions = self.collection.permissions.clone();
match enable {
@@ -497,14 +481,7 @@
}
};
- self.collection.permissions = <Pallet<T>>::clamp_permissions(
- self.collection.mode.clone(),
- &self.collection.permissions,
- permissions,
- )
- .map_err(dispatch_to_evm::<T>)?;
-
- save(self)
+ <Pallet<T>>::update_permissions(&caller, self, permissions).map_err(dispatch_to_evm::<T>)
}
/// Set the collection access method.
@@ -514,7 +491,7 @@
fn set_collection_access(&mut self, caller: caller, mode: uint8) -> Result<void> {
self.consume_store_reads_and_writes(1, 1)?;
- check_is_owner_or_admin(caller, self)?;
+ let caller = T::CrossAccountId::from_eth(caller);
let permissions = CollectionPermissions {
access: Some(match mode {
0 => AccessMode::Normal,
@@ -523,14 +500,7 @@
}),
..Default::default()
};
- self.collection.permissions = <Pallet<T>>::clamp_permissions(
- self.collection.mode.clone(),
- &self.collection.permissions,
- permissions,
- )
- .map_err(dispatch_to_evm::<T>)?;
-
- save(self)
+ <Pallet<T>>::update_permissions(&caller, self, permissions).map_err(dispatch_to_evm::<T>)
}
/// Checks that user allowed to operate with collection.
@@ -605,19 +575,12 @@
fn set_collection_mint_mode(&mut self, caller: caller, mode: bool) -> Result<void> {
self.consume_store_reads_and_writes(1, 1)?;
- check_is_owner_or_admin(caller, self)?;
+ let caller = T::CrossAccountId::from_eth(caller);
let permissions = CollectionPermissions {
mint_mode: Some(mode),
..Default::default()
};
- self.collection.permissions = <Pallet<T>>::clamp_permissions(
- self.collection.mode.clone(),
- &self.collection.permissions,
- permissions,
- )
- .map_err(dispatch_to_evm::<T>)?;
-
- save(self)
+ <Pallet<T>>::update_permissions(&caller, self, permissions).map_err(dispatch_to_evm::<T>)
}
/// Check that account is the owner or admin of the collection
@@ -671,7 +634,7 @@
let caller = T::CrossAccountId::from_eth(caller);
let new_owner = T::CrossAccountId::from_eth(new_owner);
- self.set_owner_internal(caller, new_owner)
+ self.change_owner(caller, new_owner)
.map_err(dispatch_to_evm::<T>)
}
@@ -699,7 +662,7 @@
let caller = T::CrossAccountId::from_eth(caller);
let new_owner = new_owner.into_sub_cross_account::<T>()?;
- self.set_owner_internal(caller, new_owner)
+ self.change_owner(caller, new_owner)
.map_err(dispatch_to_evm::<T>)
}
}
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -229,28 +229,111 @@
/// Unique collections allows sponsoring for certain actions.
/// This method allows you to set the sponsor of the collection.
/// In order for sponsorship to become active, it must be confirmed through [`Self::confirm_sponsorship`].
- pub fn set_sponsor(&mut self, sponsor: T::AccountId) -> DispatchResult {
- self.collection.sponsorship = SponsorshipState::Unconfirmed(sponsor);
- Ok(())
+ pub fn set_sponsor(
+ &mut self,
+ sender: &T::CrossAccountId,
+ sponsor: T::AccountId,
+ ) -> DispatchResult {
+ self.check_is_internal()?;
+ self.check_is_owner_or_admin(sender)?;
+
+ self.collection.sponsorship = SponsorshipState::Unconfirmed(sponsor.clone());
+
+ <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorSet(self.id, sponsor));
+ <PalletEvm<T>>::deposit_log(
+ erc::CollectionHelpersEvents::CollectionChanged {
+ collection_id: eth::collection_id_to_address(self.id),
+ }
+ .to_log(T::ContractAddress::get()),
+ );
+
+ self.save()
+ }
+
+ /// Force set `sponsor`.
+ ///
+ /// Differs from [`set_sponsor`][`Self::set_sponsor`] in that confirmation
+ /// from the `sponsor` is not required.
+ ///
+ /// # Arguments
+ ///
+ /// * `sender`: Caller's account.
+ /// * `sponsor`: ID of the account of the sponsor-to-be.
+ pub fn force_set_sponsor(&mut self, sponsor: T::AccountId) -> DispatchResult {
+ self.check_is_internal()?;
+
+ self.collection.sponsorship = SponsorshipState::Confirmed(sponsor.clone());
+
+ <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorSet(self.id, sponsor.clone()));
+ <Pallet<T>>::deposit_event(Event::<T>::SponsorshipConfirmed(self.id, sponsor));
+ <PalletEvm<T>>::deposit_log(
+ erc::CollectionHelpersEvents::CollectionChanged {
+ collection_id: eth::collection_id_to_address(self.id),
+ }
+ .to_log(T::ContractAddress::get()),
+ );
+
+ self.save()
}
/// Confirm sponsorship
///
/// In order for the sponsorship to become active, the user set as the sponsor must confirm their participation.
/// Before confirming sponsorship, the user must be specified as the sponsor of the collection via [`Self::set_sponsor`].
- pub fn confirm_sponsorship(&mut self, sender: &T::AccountId) -> Result<bool, DispatchError> {
- if self.collection.sponsorship.pending_sponsor() != Some(sender) {
- return Ok(false);
- }
+ pub fn confirm_sponsorship(&mut self, sender: &T::AccountId) -> DispatchResult {
+ self.check_is_internal()?;
+ ensure!(
+ self.collection.sponsorship.pending_sponsor() == Some(sender),
+ Error::<T>::ConfirmUnsetSponsorFail
+ );
self.collection.sponsorship = SponsorshipState::Confirmed(sender.clone());
- Ok(true)
+
+ <Pallet<T>>::deposit_event(Event::<T>::SponsorshipConfirmed(self.id, sender.clone()));
+ <PalletEvm<T>>::deposit_log(
+ erc::CollectionHelpersEvents::CollectionChanged {
+ collection_id: eth::collection_id_to_address(self.id),
+ }
+ .to_log(T::ContractAddress::get()),
+ );
+
+ self.save()
}
/// Remove collection sponsor.
- pub fn remove_sponsor(&mut self) -> DispatchResult {
+ pub fn remove_sponsor(&mut self, sender: &T::CrossAccountId) -> DispatchResult {
+ self.check_is_internal()?;
+ self.check_is_owner(sender)?;
+
+ self.collection.sponsorship = SponsorshipState::Disabled;
+
+ <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorRemoved(self.id));
+ <PalletEvm<T>>::deposit_log(
+ erc::CollectionHelpersEvents::CollectionChanged {
+ collection_id: eth::collection_id_to_address(self.id),
+ }
+ .to_log(T::ContractAddress::get()),
+ );
+ self.save()
+ }
+
+ /// Force remove `sponsor`.
+ ///
+ /// Differs from `remove_sponsor` in that
+ /// it doesn't require consent from the `owner` of the collection.
+ pub fn force_remove_sponsor(&mut self) -> DispatchResult {
+ self.check_is_internal()?;
+
self.collection.sponsorship = SponsorshipState::Disabled;
- Ok(())
+
+ <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorRemoved(self.id));
+ <PalletEvm<T>>::deposit_log(
+ erc::CollectionHelpersEvents::CollectionChanged {
+ collection_id: eth::collection_id_to_address(self.id),
+ }
+ .to_log(T::ContractAddress::get()),
+ );
+ self.save()
}
/// Checks that the collection was created with, and must be operated upon through **Unique API**.
@@ -328,13 +411,26 @@
/// Changes collection owner to another account
/// #### Store read/writes
/// 1 writes
- fn set_owner_internal(
+ pub fn change_owner(
&mut self,
caller: T::CrossAccountId,
new_owner: T::CrossAccountId,
) -> DispatchResult {
+ self.check_is_internal()?;
self.check_is_owner(&caller)?;
self.collection.owner = new_owner.as_sub().clone();
+
+ <Pallet<T>>::deposit_event(Event::<T>::CollectionOwnedChanged(
+ self.id,
+ new_owner.as_sub().clone(),
+ ));
+ <PalletEvm<T>>::deposit_log(
+ erc::CollectionHelpersEvents::CollectionChanged {
+ collection_id: eth::collection_id_to_address(self.id),
+ }
+ .to_log(T::ContractAddress::get()),
+ );
+
self.save()
}
}
@@ -527,6 +623,80 @@
/// The property permission that was set.
PropertyKey,
),
+
+ /// Address was added to the allow list.
+ AllowListAddressAdded(
+ /// ID of the affected collection.
+ CollectionId,
+ /// Address of the added account.
+ T::CrossAccountId,
+ ),
+
+ /// Address was removed from the allow list.
+ AllowListAddressRemoved(
+ /// ID of the affected collection.
+ CollectionId,
+ /// Address of the removed account.
+ T::CrossAccountId,
+ ),
+
+ /// Collection admin was added.
+ CollectionAdminAdded(
+ /// ID of the affected collection.
+ CollectionId,
+ /// Admin address.
+ T::CrossAccountId,
+ ),
+
+ /// Collection admin was removed.
+ CollectionAdminRemoved(
+ /// ID of the affected collection.
+ CollectionId,
+ /// Removed admin address.
+ T::CrossAccountId,
+ ),
+
+ /// Collection limits were set.
+ CollectionLimitSet(
+ /// ID of the affected collection.
+ CollectionId,
+ ),
+
+ /// Collection owned was changed.
+ CollectionOwnedChanged(
+ /// ID of the affected collection.
+ CollectionId,
+ /// New owner address.
+ T::AccountId,
+ ),
+
+ /// Collection permissions were set.
+ CollectionPermissionSet(
+ /// ID of the affected collection.
+ CollectionId,
+ ),
+
+ /// Collection sponsor was set.
+ CollectionSponsorSet(
+ /// ID of the affected collection.
+ CollectionId,
+ /// New sponsor address.
+ T::AccountId,
+ ),
+
+ /// New sponsor was confirm.
+ SponsorshipConfirmed(
+ /// ID of the affected collection.
+ CollectionId,
+ /// New sponsor address.
+ T::AccountId,
+ ),
+
+ /// Collection sponsor was removed.
+ CollectionSponsorRemoved(
+ /// ID of the affected collection.
+ CollectionId,
+ ),
}
#[pallet::error]
@@ -613,6 +783,12 @@
/// Tried to access an internal collection with an external API
CollectionIsInternal,
+
+ /// This address is not set as sponsor, use setCollectionSponsor first.
+ ConfirmUnsetSponsorFail,
+
+ /// The user is not an administrator.
+ UserIsNotAdmin,
}
/// Storage of the count of created collections. Essentially contains the last collection ID.
@@ -1363,27 +1539,47 @@
if allowed {
<Allowlist<T>>::insert((collection.id, user), true);
+ Self::deposit_event(Event::<T>::AllowListAddressAdded(
+ collection.id,
+ user.clone(),
+ ));
} else {
<Allowlist<T>>::remove((collection.id, user));
+ Self::deposit_event(Event::<T>::AllowListAddressRemoved(
+ collection.id,
+ user.clone(),
+ ));
}
+ <PalletEvm<T>>::deposit_log(
+ erc::CollectionHelpersEvents::CollectionChanged {
+ collection_id: eth::collection_id_to_address(collection.id),
+ }
+ .to_log(T::ContractAddress::get()),
+ );
+
Ok(())
}
/// Toggle `user` participation in the `collection`'s admin list.
/// #### Store read/writes
- /// 2 writes
+ /// 2 reads, 2 writes
pub fn toggle_admin(
collection: &CollectionHandle<T>,
sender: &T::CrossAccountId,
user: &T::CrossAccountId,
admin: bool,
) -> DispatchResult {
+ collection.check_is_internal()?;
collection.check_is_owner(sender)?;
- let was_admin = <IsAdmin<T>>::get((collection.id, user));
- if was_admin == admin {
- return Ok(());
+ let is_admin = <IsAdmin<T>>::get((collection.id, user));
+ if is_admin == admin {
+ if admin {
+ return Ok(());
+ } else {
+ ensure!(false, Error::<T>::UserIsNotAdmin);
+ }
}
let amount = <AdminAmount<T>>::get(collection.id);
@@ -1400,16 +1596,56 @@
<AdminAmount<T>>::insert(collection.id, amount);
<IsAdmin<T>>::insert((collection.id, user), true);
+
+ Self::deposit_event(Event::<T>::CollectionAdminAdded(
+ collection.id,
+ user.clone(),
+ ));
} else {
<AdminAmount<T>>::insert(collection.id, amount.saturating_sub(1));
<IsAdmin<T>>::remove((collection.id, user));
+
+ Self::deposit_event(Event::<T>::CollectionAdminRemoved(
+ collection.id,
+ user.clone(),
+ ));
}
+ <PalletEvm<T>>::deposit_log(
+ erc::CollectionHelpersEvents::CollectionChanged {
+ collection_id: eth::collection_id_to_address(collection.id),
+ }
+ .to_log(T::ContractAddress::get()),
+ );
+
Ok(())
}
+ /// Update collection limits.
+ pub fn update_limits(
+ user: &T::CrossAccountId,
+ collection: &mut CollectionHandle<T>,
+ new_limit: CollectionLimits,
+ ) -> DispatchResult {
+ collection.check_is_internal()?;
+ collection.check_is_owner_or_admin(user)?;
+
+ collection.limits =
+ Self::clamp_limits(collection.mode.clone(), &collection.limits, new_limit)?;
+
+ Self::deposit_event(Event::<T>::CollectionLimitSet(collection.id));
+ <PalletEvm<T>>::deposit_log(
+ erc::CollectionHelpersEvents::CollectionChanged {
+ collection_id: eth::collection_id_to_address(collection.id),
+ }
+ .to_log(T::ContractAddress::get()),
+ );
+
+ collection.save()
+ }
+
/// Merge set fields from `new_limit` to `old_limit`.
- pub fn clamp_limits(
+ fn clamp_limits(
mode: CollectionMode,
old_limit: &CollectionLimits,
mut new_limit: CollectionLimits,
@@ -1454,8 +1690,33 @@
Ok(new_limit)
}
+ /// Update collection permissions.
+ pub fn update_permissions(
+ user: &T::CrossAccountId,
+ collection: &mut CollectionHandle<T>,
+ new_permission: CollectionPermissions,
+ ) -> DispatchResult {
+ collection.check_is_internal()?;
+ collection.check_is_owner_or_admin(user)?;
+ collection.permissions = Self::clamp_permissions(
+ collection.mode.clone(),
+ &collection.permissions,
+ new_permission,
+ )?;
+
+ Self::deposit_event(Event::<T>::CollectionPermissionSet(collection.id));
+ <PalletEvm<T>>::deposit_log(
+ erc::CollectionHelpersEvents::CollectionChanged {
+ collection_id: eth::collection_id_to_address(collection.id),
+ }
+ .to_log(T::ContractAddress::get()),
+ );
+
+ collection.save()
+ }
+
/// Merge set fields from `new_permission` to `old_permission`.
- pub fn clamp_permissions(
+ fn clamp_permissions(
_mode: CollectionMode,
old_permission: &CollectionPermissions,
mut new_permission: CollectionPermissions,
pallets/unique/src/lib.rsdiffbeforeafterboth--- a/pallets/unique/src/lib.rs
+++ b/pallets/unique/src/lib.rs
@@ -89,10 +89,9 @@
MAX_PROPERTIES_PER_ITEM, MAX_PROPERTY_KEY_LENGTH, MAX_PROPERTY_VALUE_LENGTH,
MAX_COLLECTION_PROPERTIES_SIZE, COLLECTION_ADMINS_LIMIT, MAX_TOKEN_PROPERTIES_SIZE,
CreateItemData, CollectionLimits, CollectionPermissions, CollectionId, CollectionMode, TokenId,
- SponsorshipState, CreateCollectionData, CreateItemExData, budget, Property, PropertyKey,
- PropertyKeyPermission,
+ CreateCollectionData, CreateItemExData, budget, Property, PropertyKey, PropertyKeyPermission,
};
-use pallet_evm::account::CrossAccountId;
+use pallet_evm::{account::CrossAccountId};
use pallet_common::{
CollectionHandle, Pallet as PalletCommon, CommonWeightInfo, dispatch::dispatch_tx,
dispatch::CollectionDispatch, RefungibleExtensionsWeightInfo,
@@ -112,8 +111,6 @@
pub enum Error for Module<T: Config> {
/// Decimal_points parameter must be lower than [`up_data_structs::MAX_DECIMAL_POINTS`].
CollectionDecimalPointLimitExceeded,
- /// This address is not set as sponsor, use setCollectionSponsor first.
- ConfirmUnsetSponsorFail,
/// Length of items properties must be greater than 0.
EmptyArgument,
/// Repertition is only supported by refungible collection.
@@ -140,27 +137,12 @@
pub enum Event<T>
where
<T as frame_system::Config>::AccountId,
- <T as pallet_evm::Config>::CrossAccountId,
{
/// Collection sponsor was removed
///
/// # Arguments
/// * collection_id: ID of the affected collection.
CollectionSponsorRemoved(CollectionId),
-
- /// Collection admin was added
- ///
- /// # Arguments
- /// * collection_id: ID of the affected collection.
- /// * admin: Admin address.
- CollectionAdminAdded(CollectionId, CrossAccountId),
-
- /// Collection owned was changed
- ///
- /// # Arguments
- /// * collection_id: ID of the affected collection.
- /// * owner: New owner address.
- CollectionOwnedChanged(CollectionId, AccountId),
/// Collection sponsor was set
///
@@ -168,46 +150,7 @@
/// * collection_id: ID of the affected collection.
/// * owner: New sponsor address.
CollectionSponsorSet(CollectionId, AccountId),
-
- /// New sponsor was confirm
- ///
- /// # Arguments
- /// * collection_id: ID of the affected collection.
- /// * sponsor: New sponsor address.
- SponsorshipConfirmed(CollectionId, AccountId),
-
- /// Collection admin was removed
- ///
- /// # Arguments
- /// * collection_id: ID of the affected collection.
- /// * admin: Removed admin address.
- CollectionAdminRemoved(CollectionId, CrossAccountId),
- /// Address was removed from the allow list
- ///
- /// # Arguments
- /// * collection_id: ID of the affected collection.
- /// * user: Address of the removed account.
- AllowListAddressRemoved(CollectionId, CrossAccountId),
-
- /// Address was added to the allow list
- ///
- /// # Arguments
- /// * collection_id: ID of the affected collection.
- /// * user: Address of the added account.
- AllowListAddressAdded(CollectionId, CrossAccountId),
-
- /// Collection limits were set
- ///
- /// # Arguments
- /// * collection_id: ID of the affected collection.
- CollectionLimitSet(CollectionId),
-
- /// Collection permissions were set
- ///
- /// # Arguments
- /// * collection_id: ID of the affected collection.
- CollectionPermissionSet(CollectionId),
}
}
@@ -432,11 +375,6 @@
&address,
true,
)?;
-
- Self::deposit_event(Event::<T>::AllowListAddressAdded(
- collection_id,
- address
- ));
Ok(())
}
@@ -466,11 +404,6 @@
false,
)?;
- <Pallet<T>>::deposit_event(Event::<T>::AllowListAddressRemoved(
- collection_id,
- address
- ));
-
Ok(())
}
@@ -486,20 +419,10 @@
/// * `new_owner`: ID of the account that will become the owner.
#[weight = <SelfWeightOf<T>>::change_collection_owner()]
pub fn change_collection_owner(origin, collection_id: CollectionId, new_owner: T::AccountId) -> DispatchResult {
-
let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
-
+ let new_owner = T::CrossAccountId::from_sub(new_owner);
let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;
- target_collection.check_is_internal()?;
- target_collection.check_is_owner(&sender)?;
-
- target_collection.owner = new_owner.clone();
- <Pallet<T>>::deposit_event(Event::<T>::CollectionOwnedChanged(
- collection_id,
- new_owner
- ));
-
- target_collection.save()
+ target_collection.change_owner(sender, new_owner.clone())
}
/// Add an admin to a collection.
@@ -522,13 +445,6 @@
pub fn add_collection_admin(origin, collection_id: CollectionId, new_admin_id: T::CrossAccountId) -> DispatchResult {
let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
let collection = <CollectionHandle<T>>::try_get(collection_id)?;
- collection.check_is_internal()?;
-
- <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminAdded(
- collection_id,
- new_admin_id.clone()
- ));
-
<PalletCommon<T>>::toggle_admin(&collection, &sender, &new_admin_id, true)
}
@@ -550,13 +466,6 @@
pub fn remove_collection_admin(origin, collection_id: CollectionId, account_id: T::CrossAccountId) -> DispatchResult {
let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
let collection = <CollectionHandle<T>>::try_get(collection_id)?;
- collection.check_is_internal()?;
-
- <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminRemoved(
- collection_id,
- account_id.clone()
- ));
-
<PalletCommon<T>>::toggle_admin(&collection, &sender, &account_id, false)
}
@@ -576,19 +485,8 @@
#[weight = <SelfWeightOf<T>>::set_collection_sponsor()]
pub fn set_collection_sponsor(origin, collection_id: CollectionId, new_sponsor: T::AccountId) -> DispatchResult {
let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
-
let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;
- target_collection.check_is_owner_or_admin(&sender)?;
- target_collection.check_is_internal()?;
-
- target_collection.set_sponsor(new_sponsor.clone())?;
-
- <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorSet(
- collection_id,
- new_sponsor
- ));
-
- target_collection.save()
+ target_collection.set_sponsor(&sender, new_sponsor.clone())
}
/// Confirm own sponsorship of a collection, becoming the sponsor.
@@ -607,20 +505,8 @@
#[weight = <SelfWeightOf<T>>::confirm_sponsorship()]
pub fn confirm_sponsorship(origin, collection_id: CollectionId) -> DispatchResult {
let sender = ensure_signed(origin)?;
-
let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;
- target_collection.check_is_internal()?;
- ensure!(
- target_collection.confirm_sponsorship(&sender)?,
- Error::<T>::ConfirmUnsetSponsorFail
- );
-
- <Pallet<T>>::deposit_event(Event::<T>::SponsorshipConfirmed(
- collection_id,
- sender
- ));
-
- target_collection.save()
+ target_collection.confirm_sponsorship(&sender)
}
/// Remove a collection's a sponsor, making everyone pay for their own transactions.
@@ -635,17 +521,8 @@
#[weight = <SelfWeightOf<T>>::remove_collection_sponsor()]
pub fn remove_collection_sponsor(origin, collection_id: CollectionId) -> DispatchResult {
let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
-
let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;
- target_collection.check_is_internal()?;
- target_collection.check_is_owner(&sender)?;
-
- target_collection.sponsorship = SponsorshipState::Disabled;
-
- <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorRemoved(
- collection_id
- ));
- target_collection.save()
+ target_collection.remove_sponsor(&sender)
}
/// Mint an item within a collection.
@@ -1053,17 +930,7 @@
) -> DispatchResult {
let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;
- target_collection.check_is_internal()?;
- target_collection.check_is_owner_or_admin(&sender)?;
- let old_limit = &target_collection.limits;
-
- target_collection.limits = <PalletCommon<T>>::clamp_limits(target_collection.mode.clone(), &old_limit, new_limit)?;
-
- <Pallet<T>>::deposit_event(Event::<T>::CollectionLimitSet(
- collection_id
- ));
-
- target_collection.save()
+ <PalletCommon<T>>::update_limits(&sender, &mut target_collection, new_limit)
}
/// Set specific permissions of a collection. Empty, or None fields mean chain default.
@@ -1086,17 +953,11 @@
) -> DispatchResult {
let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;
- target_collection.check_is_internal()?;
- target_collection.check_is_owner_or_admin(&sender)?;
- let old_limit = &target_collection.permissions;
-
- target_collection.permissions = <PalletCommon<T>>::clamp_permissions(target_collection.mode.clone(), &old_limit, new_permission)?;
-
- <Pallet<T>>::deposit_event(Event::<T>::CollectionPermissionSet(
- collection_id
- ));
-
- target_collection.save()
+ <PalletCommon<T>>::update_permissions(
+ &sender,
+ &mut target_collection,
+ new_permission
+ )
}
/// Re-partition a refungible token, while owning all of its parts/pieces.
@@ -1163,22 +1024,7 @@
/// * `collection_id`: ID of the modified collection.
pub fn force_set_sponsor(sponsor: T::AccountId, collection_id: CollectionId) -> DispatchResult {
let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;
- target_collection.check_is_internal()?;
- target_collection.set_sponsor(sponsor.clone())?;
-
- Self::deposit_event(Event::<T>::CollectionSponsorSet(
- collection_id,
- sponsor.clone(),
- ));
-
- ensure!(
- target_collection.confirm_sponsorship(&sponsor)?,
- Error::<T>::ConfirmUnsetSponsorFail
- );
-
- Self::deposit_event(Event::<T>::SponsorshipConfirmed(collection_id, sponsor));
-
- target_collection.save()
+ target_collection.force_set_sponsor(sponsor.clone())
}
/// Force remove `sponsor` for `collection`.
@@ -1191,12 +1037,7 @@
/// * `collection_id`: ID of the modified collection.
pub fn force_remove_collection_sponsor(collection_id: CollectionId) -> DispatchResult {
let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;
- target_collection.check_is_internal()?;
- target_collection.sponsorship = SponsorshipState::Disabled;
-
- Self::deposit_event(Event::<T>::CollectionSponsorRemoved(collection_id));
-
- target_collection.save()
+ target_collection.force_remove_sponsor()
}
#[inline(always)]
tests/src/change-collection-owner.test.tsdiffbeforeafterboth--- a/tests/src/change-collection-owner.test.ts
+++ b/tests/src/change-collection-owner.test.ts
@@ -146,7 +146,7 @@
const confirmSponsorshipTx = () => collection.confirmSponsorship(alice);
const removeSponsorTx = () => collection.removeSponsor(alice);
await expect(setSponsorTx()).to.be.rejectedWith(/common\.NoPermission/);
- await expect(confirmSponsorshipTx()).to.be.rejectedWith(/unique\.ConfirmUnsetSponsorFail/);
+ await expect(confirmSponsorshipTx()).to.be.rejectedWith(/common\.ConfirmUnsetSponsorFail/);
await expect(removeSponsorTx()).to.be.rejectedWith(/common\.NoPermission/);
const limits = {
tests/src/confirmSponsorship.test.tsdiffbeforeafterboth--- a/tests/src/confirmSponsorship.test.ts
+++ b/tests/src/confirmSponsorship.test.ts
@@ -207,14 +207,14 @@
const collection = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
await collection.setSponsor(alice, bob.address);
const confirmSponsorshipTx = () => collection.confirmSponsorship(charlie);
- await expect(confirmSponsorshipTx()).to.be.rejectedWith(/unique\.ConfirmUnsetSponsorFail/);
+ await expect(confirmSponsorshipTx()).to.be.rejectedWith(/common\.ConfirmUnsetSponsorFail/);
});
itSub('(!negative test!) Confirm sponsorship using owner address', async ({helper}) => {
const collection = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
await collection.setSponsor(alice, bob.address);
const confirmSponsorshipTx = () => collection.confirmSponsorship(alice);
- await expect(confirmSponsorshipTx()).to.be.rejectedWith(/unique\.ConfirmUnsetSponsorFail/);
+ await expect(confirmSponsorshipTx()).to.be.rejectedWith(/common\.ConfirmUnsetSponsorFail/);
});
itSub('(!negative test!) Confirm sponsorship by collection admin', async ({helper}) => {
@@ -222,13 +222,13 @@
await collection.setSponsor(alice, bob.address);
await collection.addAdmin(alice, {Substrate: charlie.address});
const confirmSponsorshipTx = () => collection.confirmSponsorship(charlie);
- await expect(confirmSponsorshipTx()).to.be.rejectedWith(/unique\.ConfirmUnsetSponsorFail/);
+ await expect(confirmSponsorshipTx()).to.be.rejectedWith(/common\.ConfirmUnsetSponsorFail/);
});
itSub('(!negative test!) Confirm sponsorship without sponsor being set with setCollectionSponsor', async ({helper}) => {
const collection = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
const confirmSponsorshipTx = () => collection.confirmSponsorship(charlie);
- await expect(confirmSponsorshipTx()).to.be.rejectedWith(/unique\.ConfirmUnsetSponsorFail/);
+ await expect(confirmSponsorshipTx()).to.be.rejectedWith(/common\.ConfirmUnsetSponsorFail/);
});
itSub('(!negative test!) Confirm sponsorship in a collection that was destroyed', async ({helper}) => {
tests/src/eth/collectionSponsoring.test.tsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {IKeyringPair} from '@polkadot/types/types';18import {usingPlaygrounds} from '../util/index';19import {itEth, expect} from './util';2021describe('evm collection sponsoring', () => {22 let donor: IKeyringPair;23 let alice: IKeyringPair;24 let nominal: bigint;2526 before(async () => {27 await usingPlaygrounds(async (helper, privateKey) => {28 donor = await privateKey({filename: __filename});29 [alice] = await helper.arrange.createAccounts([100n], donor);30 nominal = helper.balance.getOneTokenNominal();31 });32 });33 34 // TODO: move to substrate tests35 itEth('sponsors mint transactions', async ({helper}) => {36 const collection = await helper.nft.mintCollection(alice, {tokenPrefix: 'spnr', permissions: {mintMode: true}});37 await collection.setSponsor(alice, alice.address);38 await collection.confirmSponsorship(alice);3940 const minter = helper.eth.createAccount();41 expect(await helper.balance.getEthereum(minter)).to.equal(0n);4243 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);44 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', minter);4546 await collection.addToAllowList(alice, {Ethereum: minter});4748 const result = await contract.methods.mint(minter).send();4950 const events = helper.eth.normalizeEvents(result.events);51 expect(events).to.be.deep.equal([52 {53 address: collectionAddress,54 event: 'Transfer',55 args: {56 from: '0x0000000000000000000000000000000000000000',57 to: minter,58 tokenId: '1',59 },60 },61 ]);62 });6364 // TODO: Temprorary off. Need refactor65 // itWeb3('Set substrate sponsor', async ({api, web3, privateKeyWrapper}) => {66 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);67 // const collectionHelpers = evmCollectionHelpers(web3, owner);68 // let result = await collectionHelpers.methods.createNFTCollection('Sponsor collection', '1', '1').send();69 // const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);70 // const sponsor = privateKeyWrapper('//Alice');71 // const collectionEvm = evmCollection(web3, owner, collectionIdAddress);7273 // expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.false;74 // result = await collectionEvm.methods.setCollectionSponsorSubstrate(sponsor.addressRaw).send({from: owner});75 // expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.true;7677 // const confirmTx = await api.tx.unique.confirmSponsorship(collectionId);78 // await submitTransactionAsync(sponsor, confirmTx);79 // expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.false;8081 // const sponsorTuple = await collectionEvm.methods.collectionSponsor().call({from: owner});82 // expect(bigIntToSub(api, BigInt(sponsorTuple[1]))).to.be.eq(sponsor.address);83 // });8485 [86 'setCollectionSponsorCross',87 'setCollectionSponsor', // Soft-deprecated88 ].map(testCase => 89 itEth(`[${testCase}] can remove collection sponsor`, async ({helper}) => {90 const owner = await helper.eth.createAccountWithBalance(donor);91 const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);92 93 let result = await collectionHelpers.methods.createNFTCollection('Sponsor collection', '1', '1').send({value: Number(2n * nominal)});94 const collectionIdAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);95 const sponsor = await helper.eth.createAccountWithBalance(donor);96 const sponsorCross = helper.ethCrossAccount.fromAddress(sponsor);97 const collectionEvm = helper.ethNativeContract.collection(collectionIdAddress, 'nft', owner, testCase === 'setCollectionSponsor');98 99 expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.false;100 result = await collectionEvm.methods[testCase](testCase === 'setCollectionSponsor' ? sponsor : sponsorCross).send({from: owner});101 expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.true;102 103 await collectionEvm.methods.confirmCollectionSponsorship().send({from: sponsor});104 expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.false;105 106 await collectionEvm.methods.removeCollectionSponsor().send({from: owner});107 108 const sponsorTuple = await collectionEvm.methods.collectionSponsor().call({from: owner});109 expect(sponsorTuple.field_0).to.be.eq('0x0000000000000000000000000000000000000000');110 }));111112 [113 'setCollectionSponsorCross',114 'setCollectionSponsor', // Soft-deprecated115 ].map(testCase => 116 itEth(`[${testCase}] Can sponsor from evm address via access list`, async ({helper}) => {117 const owner = await helper.eth.createAccountWithBalance(donor);118 const sponsorEth = await helper.eth.createAccountWithBalance(donor);119 const sponsorCrossEth = helper.ethCrossAccount.fromAddress(sponsorEth);120 121 const {collectionId, collectionAddress} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'Sponsor collection', '1', '1', '');122 123 const collectionSub = helper.nft.getCollectionObject(collectionId);124 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, testCase === 'setCollectionSponsor');125 126 // Set collection sponsor:127 await collectionEvm.methods[testCase](testCase === 'setCollectionSponsor' ? sponsorEth : sponsorCrossEth).send({from: owner});128 let sponsorship = (await collectionSub.getData())!.raw.sponsorship;129 expect(sponsorship.Unconfirmed).to.be.eq(helper.address.ethToSubstrate(sponsorEth, true));130 // Account cannot confirm sponsorship if it is not set as a sponsor131 await expect(collectionEvm.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('caller is not set as sponsor');132 133 // Sponsor can confirm sponsorship:134 await collectionEvm.methods.confirmCollectionSponsorship().send({from: sponsorEth});135 sponsorship = (await collectionSub.getData())!.raw.sponsorship;136 expect(sponsorship.Confirmed).to.be.eq(helper.address.ethToSubstrate(sponsorEth, true));137 138 // Create user with no balance:139 const user = helper.eth.createAccount();140 const userCross = helper.ethCrossAccount.fromAddress(user);141 const nextTokenId = await collectionEvm.methods.nextTokenId().call();142 expect(nextTokenId).to.be.equal('1');143 144 // Set collection permissions:145 const oldPermissions = (await collectionSub.getData())!.raw.permissions; // (await getDetailedCollectionInfo(api, collectionId))!.permissions.toHuman();146 expect(oldPermissions.mintMode).to.be.false;147 expect(oldPermissions.access).to.be.equal('Normal');148149 await collectionEvm.methods.setCollectionAccess(1 /*'AllowList'*/).send({from: owner});150 await collectionEvm.methods.addToCollectionAllowListCross(userCross).send({from: owner});151 await collectionEvm.methods.setCollectionMintMode(true).send({from: owner});152 153 const newPermissions = (await collectionSub.getData())!.raw.permissions; // (await getDetailedCollectionInfo(api, collectionId))!.permissions.toHuman();154 expect(newPermissions.mintMode).to.be.true;155 expect(newPermissions.access).to.be.equal('AllowList');156 157 const ownerBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(owner));158 const sponsorBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsorEth));159160 // User can mint token without balance:161 {162 const result = await collectionEvm.methods.mintWithTokenURI(user, 'Test URI').send({from: user});163 const events = helper.eth.normalizeEvents(result.events);164 165 expect(events).to.be.deep.equal([166 {167 address: collectionAddress,168 event: 'Transfer',169 args: {170 from: '0x0000000000000000000000000000000000000000',171 to: user,172 tokenId: '1',173 },174 },175 ]);176 177 const ownerBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(owner));178 const sponsorBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsorEth));179 const userBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(user));180 181 expect(await collectionEvm.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');182 expect(ownerBalanceBefore).to.be.eq(ownerBalanceAfter);183 expect(userBalanceAfter).to.be.eq(0n);184 expect(sponsorBalanceBefore > sponsorBalanceAfter).to.be.true;185 }186 }));187188 // TODO: Temprorary off. Need refactor189 // itWeb3('Sponsoring collection from substrate address via access list', async ({api, web3, privateKeyWrapper}) => {190 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);191 // const collectionHelpers = evmCollectionHelpers(web3, owner);192 // const result = await collectionHelpers.methods.createERC721MetadataCompatibleNFTCollection('Sponsor collection', '1', '1', '').send();193 // const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);194 // const sponsor = privateKeyWrapper('//Alice');195 // const collectionEvm = evmCollection(web3, owner, collectionIdAddress);196197 // await collectionEvm.methods.setCollectionSponsorSubstrate(sponsor.addressRaw).send({from: owner});198199 // const confirmTx = await api.tx.unique.confirmSponsorship(collectionId);200 // await submitTransactionAsync(sponsor, confirmTx);201202 // const user = createEthAccount(web3);203 // const nextTokenId = await collectionEvm.methods.nextTokenId().call();204 // expect(nextTokenId).to.be.equal('1');205206 // await collectionEvm.methods.setCollectionAccess(1 /*'AllowList'*/).send({from: owner});207 // await collectionEvm.methods.addToCollectionAllowList(user).send({from: owner});208 // await collectionEvm.methods.setCollectionMintMode(true).send({from: owner});209210 // const ownerBalanceBefore = await ethBalanceViaSub(api, owner);211 // const sponsorBalanceBefore = (await getBalance(api, [sponsor.address]))[0];212213 // {214 // const nextTokenId = await collectionEvm.methods.nextTokenId().call();215 // expect(nextTokenId).to.be.equal('1');216 // const result = await collectionEvm.methods.mintWithTokenURI(217 // user,218 // nextTokenId,219 // 'Test URI',220 // ).send({from: user});221 // const events = normalizeEvents(result.events);222223 // expect(events).to.be.deep.equal([224 // {225 // address: collectionIdAddress,226 // event: 'Transfer',227 // args: {228 // from: '0x0000000000000000000000000000000000000000',229 // to: user,230 // tokenId: nextTokenId,231 // },232 // },233 // ]);234235 // const ownerBalanceAfter = await ethBalanceViaSub(api, owner);236 // const sponsorBalanceAfter = (await getBalance(api, [sponsor.address]))[0];237238 // expect(await collectionEvm.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');239 // expect(ownerBalanceBefore).to.be.eq(ownerBalanceAfter);240 // expect(sponsorBalanceBefore > sponsorBalanceAfter).to.be.true;241 // }242 // });243244 [245 'setCollectionSponsorCross',246 'setCollectionSponsor', // Soft-deprecated247 ].map(testCase => 248 itEth(`[${testCase}] Check that transaction via EVM spend money from sponsor address`, async ({helper}) => {249 const owner = await helper.eth.createAccountWithBalance(donor);250 const sponsor = await helper.eth.createAccountWithBalance(donor);251 const sponsorCross = helper.ethCrossAccount.fromAddress(sponsor);252 253 const {collectionAddress, collectionId} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner,'Sponsor collection', '1', '1', '');254255 const collectionSub = helper.nft.getCollectionObject(collectionId);256 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, testCase === 'setCollectionSponsor');257 // Set collection sponsor:258 await collectionEvm.methods[testCase](testCase === 'setCollectionSponsor' ? sponsor : sponsorCross).send();259 let collectionData = (await collectionSub.getData())!;260 expect(collectionData.raw.sponsorship.Unconfirmed).to.be.eq(helper.address.ethToSubstrate(sponsor, true));261 await expect(collectionEvm.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('caller is not set as sponsor');262 263 await collectionEvm.methods.confirmCollectionSponsorship().send({from: sponsor});264 collectionData = (await collectionSub.getData())!;265 expect(collectionData.raw.sponsorship.Confirmed).to.be.eq(helper.address.ethToSubstrate(sponsor, true));266 267 const user = helper.eth.createAccount();268 const userCross = helper.ethCrossAccount.fromAddress(user);269 await collectionEvm.methods.addCollectionAdminCross(userCross).send();270 271 const ownerBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(owner));272 const sponsorBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));273 274 const mintingResult = await collectionEvm.methods.mintWithTokenURI(user, 'Test URI').send({from: user});275 const tokenId = mintingResult.events.Transfer.returnValues.tokenId;276 277 const events = helper.eth.normalizeEvents(mintingResult.events);278 const address = helper.ethAddress.fromCollectionId(collectionId);279 280 expect(events).to.be.deep.equal([281 {282 address,283 event: 'Transfer',284 args: {285 from: '0x0000000000000000000000000000000000000000',286 to: user,287 tokenId: '1',288 },289 },290 ]);291 expect(await collectionEvm.methods.tokenURI(tokenId).call({from: user})).to.be.equal('Test URI');292 293 const ownerBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(owner));294 expect(ownerBalanceAfter).to.be.eq(ownerBalanceBefore);295 const sponsorBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));296 expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;297 }));298299 itEth('Can reassign collection sponsor', async ({helper}) => {300 const owner = await helper.eth.createAccountWithBalance(donor);301 const sponsorEth = await helper.eth.createAccountWithBalance(donor);302 const sponsorCrossEth = helper.ethCrossAccount.fromAddress(sponsorEth);303 const [sponsorSub] = await helper.arrange.createAccounts([100n], donor);304 const sponsorCrossSub = helper.ethCrossAccount.fromKeyringPair(sponsorSub);305306 const {collectionAddress, collectionId} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner,'Sponsor collection', '1', '1', '');307 const collectionSub = helper.nft.getCollectionObject(collectionId);308 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);309310 // Set and confirm sponsor:311 await collectionEvm.methods.setCollectionSponsorCross(sponsorCrossEth).send({from: owner});312 await collectionEvm.methods.confirmCollectionSponsorship().send({from: sponsorEth});313314 // Can reassign sponsor:315 await collectionEvm.methods.setCollectionSponsorCross(sponsorCrossSub).send({from: owner});316 const collectionSponsor = (await collectionSub.getData())?.raw.sponsorship;317 expect(collectionSponsor).to.deep.eq({Unconfirmed: sponsorSub.address});318 });319});1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {IKeyringPair} from '@polkadot/types/types';18import {usingPlaygrounds} from '../util/index';19import {itEth, expect} from './util';2021describe('evm collection sponsoring', () => {22 let donor: IKeyringPair;23 let alice: IKeyringPair;24 let nominal: bigint;2526 before(async () => {27 await usingPlaygrounds(async (helper, privateKey) => {28 donor = await privateKey({filename: __filename});29 [alice] = await helper.arrange.createAccounts([100n], donor);30 nominal = helper.balance.getOneTokenNominal();31 });32 });33 34 // TODO: move to substrate tests35 itEth('sponsors mint transactions', async ({helper}) => {36 const collection = await helper.nft.mintCollection(alice, {tokenPrefix: 'spnr', permissions: {mintMode: true}});37 await collection.setSponsor(alice, alice.address);38 await collection.confirmSponsorship(alice);3940 const minter = helper.eth.createAccount();41 expect(await helper.balance.getEthereum(minter)).to.equal(0n);4243 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);44 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', minter);4546 await collection.addToAllowList(alice, {Ethereum: minter});4748 const result = await contract.methods.mint(minter).send();4950 const events = helper.eth.normalizeEvents(result.events);51 expect(events).to.be.deep.equal([52 {53 address: collectionAddress,54 event: 'Transfer',55 args: {56 from: '0x0000000000000000000000000000000000000000',57 to: minter,58 tokenId: '1',59 },60 },61 ]);62 });6364 // TODO: Temprorary off. Need refactor65 // itWeb3('Set substrate sponsor', async ({api, web3, privateKeyWrapper}) => {66 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);67 // const collectionHelpers = evmCollectionHelpers(web3, owner);68 // let result = await collectionHelpers.methods.createNFTCollection('Sponsor collection', '1', '1').send();69 // const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);70 // const sponsor = privateKeyWrapper('//Alice');71 // const collectionEvm = evmCollection(web3, owner, collectionIdAddress);7273 // expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.false;74 // result = await collectionEvm.methods.setCollectionSponsorSubstrate(sponsor.addressRaw).send({from: owner});75 // expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.true;7677 // const confirmTx = await api.tx.unique.confirmSponsorship(collectionId);78 // await submitTransactionAsync(sponsor, confirmTx);79 // expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.false;8081 // const sponsorTuple = await collectionEvm.methods.collectionSponsor().call({from: owner});82 // expect(bigIntToSub(api, BigInt(sponsorTuple[1]))).to.be.eq(sponsor.address);83 // });8485 [86 'setCollectionSponsorCross',87 'setCollectionSponsor', // Soft-deprecated88 ].map(testCase => 89 itEth(`[${testCase}] can remove collection sponsor`, async ({helper}) => {90 const owner = await helper.eth.createAccountWithBalance(donor);91 const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);92 93 let result = await collectionHelpers.methods.createNFTCollection('Sponsor collection', '1', '1').send({value: Number(2n * nominal)});94 const collectionIdAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);95 const sponsor = await helper.eth.createAccountWithBalance(donor);96 const sponsorCross = helper.ethCrossAccount.fromAddress(sponsor);97 const collectionEvm = helper.ethNativeContract.collection(collectionIdAddress, 'nft', owner, testCase === 'setCollectionSponsor');98 99 expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.false;100 result = await collectionEvm.methods[testCase](testCase === 'setCollectionSponsor' ? sponsor : sponsorCross).send({from: owner});101 expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.true;102 103 await collectionEvm.methods.confirmCollectionSponsorship().send({from: sponsor});104 expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.false;105 106 await collectionEvm.methods.removeCollectionSponsor().send({from: owner});107 108 const sponsorTuple = await collectionEvm.methods.collectionSponsor().call({from: owner});109 expect(sponsorTuple.field_0).to.be.eq('0x0000000000000000000000000000000000000000');110 }));111112 [113 'setCollectionSponsorCross',114 'setCollectionSponsor', // Soft-deprecated115 ].map(testCase => 116 itEth(`[${testCase}] Can sponsor from evm address via access list`, async ({helper}) => {117 const owner = await helper.eth.createAccountWithBalance(donor);118 const sponsorEth = await helper.eth.createAccountWithBalance(donor);119 const sponsorCrossEth = helper.ethCrossAccount.fromAddress(sponsorEth);120 121 const {collectionId, collectionAddress} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'Sponsor collection', '1', '1', '');122 123 const collectionSub = helper.nft.getCollectionObject(collectionId);124 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, testCase === 'setCollectionSponsor');125 126 // Set collection sponsor:127 await collectionEvm.methods[testCase](testCase === 'setCollectionSponsor' ? sponsorEth : sponsorCrossEth).send({from: owner});128 let sponsorship = (await collectionSub.getData())!.raw.sponsorship;129 expect(sponsorship.Unconfirmed).to.be.eq(helper.address.ethToSubstrate(sponsorEth, true));130 // Account cannot confirm sponsorship if it is not set as a sponsor131 await expect(collectionEvm.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('caller is not set as sponsor');132 133 // Sponsor can confirm sponsorship:134 await collectionEvm.methods.confirmCollectionSponsorship().send({from: sponsorEth});135 sponsorship = (await collectionSub.getData())!.raw.sponsorship;136 expect(sponsorship.Confirmed).to.be.eq(helper.address.ethToSubstrate(sponsorEth, true));137 138 // Create user with no balance:139 const user = helper.eth.createAccount();140 const userCross = helper.ethCrossAccount.fromAddress(user);141 const nextTokenId = await collectionEvm.methods.nextTokenId().call();142 expect(nextTokenId).to.be.equal('1');143 144 // Set collection permissions:145 const oldPermissions = (await collectionSub.getData())!.raw.permissions; // (await getDetailedCollectionInfo(api, collectionId))!.permissions.toHuman();146 expect(oldPermissions.mintMode).to.be.false;147 expect(oldPermissions.access).to.be.equal('Normal');148149 await collectionEvm.methods.setCollectionAccess(1 /*'AllowList'*/).send({from: owner});150 await collectionEvm.methods.addToCollectionAllowListCross(userCross).send({from: owner});151 await collectionEvm.methods.setCollectionMintMode(true).send({from: owner});152 153 const newPermissions = (await collectionSub.getData())!.raw.permissions; // (await getDetailedCollectionInfo(api, collectionId))!.permissions.toHuman();154 expect(newPermissions.mintMode).to.be.true;155 expect(newPermissions.access).to.be.equal('AllowList');156 157 const ownerBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(owner));158 const sponsorBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsorEth));159160 // User can mint token without balance:161 {162 const result = await collectionEvm.methods.mintWithTokenURI(user, 'Test URI').send({from: user});163 const events = helper.eth.normalizeEvents(result.events);164 165 expect(events).to.be.deep.equal([166 {167 address: collectionAddress,168 event: 'Transfer',169 args: {170 from: '0x0000000000000000000000000000000000000000',171 to: user,172 tokenId: '1',173 },174 },175 ]);176 177 const ownerBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(owner));178 const sponsorBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsorEth));179 const userBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(user));180 181 expect(await collectionEvm.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');182 expect(ownerBalanceBefore).to.be.eq(ownerBalanceAfter);183 expect(userBalanceAfter).to.be.eq(0n);184 expect(sponsorBalanceBefore > sponsorBalanceAfter).to.be.true;185 }186 }));187188 // TODO: Temprorary off. Need refactor189 // itWeb3('Sponsoring collection from substrate address via access list', async ({api, web3, privateKeyWrapper}) => {190 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);191 // const collectionHelpers = evmCollectionHelpers(web3, owner);192 // const result = await collectionHelpers.methods.createERC721MetadataCompatibleNFTCollection('Sponsor collection', '1', '1', '').send();193 // const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);194 // const sponsor = privateKeyWrapper('//Alice');195 // const collectionEvm = evmCollection(web3, owner, collectionIdAddress);196197 // await collectionEvm.methods.setCollectionSponsorSubstrate(sponsor.addressRaw).send({from: owner});198199 // const confirmTx = await api.tx.unique.confirmSponsorship(collectionId);200 // await submitTransactionAsync(sponsor, confirmTx);201202 // const user = createEthAccount(web3);203 // const nextTokenId = await collectionEvm.methods.nextTokenId().call();204 // expect(nextTokenId).to.be.equal('1');205206 // await collectionEvm.methods.setCollectionAccess(1 /*'AllowList'*/).send({from: owner});207 // await collectionEvm.methods.addToCollectionAllowList(user).send({from: owner});208 // await collectionEvm.methods.setCollectionMintMode(true).send({from: owner});209210 // const ownerBalanceBefore = await ethBalanceViaSub(api, owner);211 // const sponsorBalanceBefore = (await getBalance(api, [sponsor.address]))[0];212213 // {214 // const nextTokenId = await collectionEvm.methods.nextTokenId().call();215 // expect(nextTokenId).to.be.equal('1');216 // const result = await collectionEvm.methods.mintWithTokenURI(217 // user,218 // nextTokenId,219 // 'Test URI',220 // ).send({from: user});221 // const events = normalizeEvents(result.events);222223 // expect(events).to.be.deep.equal([224 // {225 // address: collectionIdAddress,226 // event: 'Transfer',227 // args: {228 // from: '0x0000000000000000000000000000000000000000',229 // to: user,230 // tokenId: nextTokenId,231 // },232 // },233 // ]);234235 // const ownerBalanceAfter = await ethBalanceViaSub(api, owner);236 // const sponsorBalanceAfter = (await getBalance(api, [sponsor.address]))[0];237238 // expect(await collectionEvm.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');239 // expect(ownerBalanceBefore).to.be.eq(ownerBalanceAfter);240 // expect(sponsorBalanceBefore > sponsorBalanceAfter).to.be.true;241 // }242 // });243244 [245 'setCollectionSponsorCross',246 'setCollectionSponsor', // Soft-deprecated247 ].map(testCase => 248 itEth(`[${testCase}] Check that transaction via EVM spend money from sponsor address`, async ({helper}) => {249 const owner = await helper.eth.createAccountWithBalance(donor);250 const sponsor = await helper.eth.createAccountWithBalance(donor);251 const sponsorCross = helper.ethCrossAccount.fromAddress(sponsor);252 253 const {collectionAddress, collectionId} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner,'Sponsor collection', '1', '1', '');254255 const collectionSub = helper.nft.getCollectionObject(collectionId);256 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, testCase === 'setCollectionSponsor');257 // Set collection sponsor:258 await collectionEvm.methods[testCase](testCase === 'setCollectionSponsor' ? sponsor : sponsorCross).send();259 let collectionData = (await collectionSub.getData())!;260 expect(collectionData.raw.sponsorship.Unconfirmed).to.be.eq(helper.address.ethToSubstrate(sponsor, true));261 await expect(collectionEvm.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('ConfirmUnsetSponsorFail');262 263 await collectionEvm.methods.confirmCollectionSponsorship().send({from: sponsor});264 collectionData = (await collectionSub.getData())!;265 expect(collectionData.raw.sponsorship.Confirmed).to.be.eq(helper.address.ethToSubstrate(sponsor, true));266 267 const user = helper.eth.createAccount();268 const userCross = helper.ethCrossAccount.fromAddress(user);269 await collectionEvm.methods.addCollectionAdminCross(userCross).send();270 271 const ownerBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(owner));272 const sponsorBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));273 274 const mintingResult = await collectionEvm.methods.mintWithTokenURI(user, 'Test URI').send({from: user});275 const tokenId = mintingResult.events.Transfer.returnValues.tokenId;276 277 const events = helper.eth.normalizeEvents(mintingResult.events);278 const address = helper.ethAddress.fromCollectionId(collectionId);279 280 expect(events).to.be.deep.equal([281 {282 address,283 event: 'Transfer',284 args: {285 from: '0x0000000000000000000000000000000000000000',286 to: user,287 tokenId: '1',288 },289 },290 ]);291 expect(await collectionEvm.methods.tokenURI(tokenId).call({from: user})).to.be.equal('Test URI');292 293 const ownerBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(owner));294 expect(ownerBalanceAfter).to.be.eq(ownerBalanceBefore);295 const sponsorBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));296 expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;297 }));298299 itEth('Can reassign collection sponsor', async ({helper}) => {300 const owner = await helper.eth.createAccountWithBalance(donor);301 const sponsorEth = await helper.eth.createAccountWithBalance(donor);302 const sponsorCrossEth = helper.ethCrossAccount.fromAddress(sponsorEth);303 const [sponsorSub] = await helper.arrange.createAccounts([100n], donor);304 const sponsorCrossSub = helper.ethCrossAccount.fromKeyringPair(sponsorSub);305306 const {collectionAddress, collectionId} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner,'Sponsor collection', '1', '1', '');307 const collectionSub = helper.nft.getCollectionObject(collectionId);308 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);309310 // Set and confirm sponsor:311 await collectionEvm.methods.setCollectionSponsorCross(sponsorCrossEth).send({from: owner});312 await collectionEvm.methods.confirmCollectionSponsorship().send({from: sponsorEth});313314 // Can reassign sponsor:315 await collectionEvm.methods.setCollectionSponsorCross(sponsorCrossSub).send({from: owner});316 const collectionSponsor = (await collectionSub.getData())?.raw.sponsorship;317 expect(collectionSponsor).to.deep.eq({Unconfirmed: sponsorSub.address});318 });319});tests/src/eth/createFTCollection.test.tsdiffbeforeafterboth--- a/tests/src/eth/createFTCollection.test.ts
+++ b/tests/src/eth/createFTCollection.test.ts
@@ -46,7 +46,7 @@
let data = (await helper.rft.getData(collectionId))!;
expect(data.raw.sponsorship.Unconfirmed).to.be.equal(evmToAddress(sponsor, Number(ss58Format)));
- await expect(collection.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('caller is not set as sponsor');
+ await expect(collection.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('ConfirmUnsetSponsorFail');
const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'rft', sponsor, true);
await sponsorCollection.methods.confirmCollectionSponsorship().send();
@@ -69,7 +69,7 @@
let data = (await helper.rft.getData(collectionId))!;
expect(data.raw.sponsorship.Unconfirmed).to.be.equal(evmToAddress(sponsor, Number(ss58Format)));
- await expect(collection.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('caller is not set as sponsor');
+ await expect(collection.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('ConfirmUnsetSponsorFail');
const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'rft', sponsor);
await sponsorCollection.methods.confirmCollectionSponsorship().send();
@@ -192,11 +192,11 @@
const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'ft', sponsor, true);
await expect(sponsorCollection.methods
.confirmCollectionSponsorship()
- .call()).to.be.rejectedWith('caller is not set as sponsor');
+ .call()).to.be.rejectedWith('ConfirmUnsetSponsorFail');
}
{
await expect(peasantCollection.methods
- .setCollectionLimit('account_token_ownership_limit', '1000')
+ .setCollectionLimit('accountTokenOwnershipLimit', '1000')
.call()).to.be.rejectedWith(EXPECTED_ERROR);
}
});
@@ -217,11 +217,11 @@
const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'ft', sponsor);
await expect(sponsorCollection.methods
.confirmCollectionSponsorship()
- .call()).to.be.rejectedWith('caller is not set as sponsor');
+ .call()).to.be.rejectedWith('ConfirmUnsetSponsorFail');
}
{
await expect(peasantCollection.methods
- .setCollectionLimit('account_token_ownership_limit', '1000')
+ .setCollectionLimit('accountTokenOwnershipLimit', '1000')
.call()).to.be.rejectedWith(EXPECTED_ERROR);
}
});
tests/src/eth/createNFTCollection.test.tsdiffbeforeafterboth--- a/tests/src/eth/createNFTCollection.test.ts
+++ b/tests/src/eth/createNFTCollection.test.ts
@@ -86,7 +86,7 @@
let data = (await helper.nft.getData(collectionId))!;
expect(data.raw.sponsorship.Unconfirmed).to.be.equal(evmToAddress(sponsor, Number(ss58Format)));
- await expect(collection.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('caller is not set as sponsor');
+ await expect(collection.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('ConfirmUnsetSponsorFail');
const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'nft', sponsor, true);
await sponsorCollection.methods.confirmCollectionSponsorship().send();
@@ -109,7 +109,7 @@
let data = (await helper.nft.getData(collectionId))!;
expect(data.raw.sponsorship.Unconfirmed).to.be.equal(evmToAddress(sponsor, Number(ss58Format)));
- await expect(collection.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('caller is not set as sponsor');
+ await expect(collection.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('ConfirmUnsetSponsorFail');
const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'nft', sponsor);
await sponsorCollection.methods.confirmCollectionSponsorship().send();
@@ -203,11 +203,11 @@
const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'nft', sponsor, true);
await expect(sponsorCollection.methods
.confirmCollectionSponsorship()
- .call()).to.be.rejectedWith('caller is not set as sponsor');
+ .call()).to.be.rejectedWith('ConfirmUnsetSponsorFail');
}
{
await expect(malfeasantCollection.methods
- .setCollectionLimit('account_token_ownership_limit', '1000')
+ .setCollectionLimit('accountTokenOwnershipLimit', '1000')
.call()).to.be.rejectedWith(EXPECTED_ERROR);
}
});
@@ -228,11 +228,11 @@
const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'nft', sponsor);
await expect(sponsorCollection.methods
.confirmCollectionSponsorship()
- .call()).to.be.rejectedWith('caller is not set as sponsor');
+ .call()).to.be.rejectedWith('ConfirmUnsetSponsorFail');
}
{
await expect(malfeasantCollection.methods
- .setCollectionLimit('account_token_ownership_limit', '1000')
+ .setCollectionLimit('accountTokenOwnershipLimit', '1000')
.call()).to.be.rejectedWith(EXPECTED_ERROR);
}
});
tests/src/eth/createRFTCollection.test.tsdiffbeforeafterboth--- a/tests/src/eth/createRFTCollection.test.ts
+++ b/tests/src/eth/createRFTCollection.test.ts
@@ -121,7 +121,7 @@
let data = (await helper.rft.getData(collectionId))!;
expect(data.raw.sponsorship.Unconfirmed).to.be.equal(evmToAddress(sponsor, Number(ss58Format)));
- await expect(collection.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('caller is not set as sponsor');
+ await expect(collection.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('ConfirmUnsetSponsorFail');
const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'rft', sponsor, true);
await sponsorCollection.methods.confirmCollectionSponsorship().send();
@@ -143,7 +143,7 @@
let data = (await helper.rft.getData(collectionId))!;
expect(data.raw.sponsorship.Unconfirmed).to.be.equal(evmToAddress(sponsor, Number(ss58Format)));
- await expect(collection.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('caller is not set as sponsor');
+ await expect(collection.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('ConfirmUnsetSponsorFail');
const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'rft', sponsor);
await sponsorCollection.methods.confirmCollectionSponsorship().send();
@@ -235,11 +235,11 @@
const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'rft', sponsor, true);
await expect(sponsorCollection.methods
.confirmCollectionSponsorship()
- .call()).to.be.rejectedWith('caller is not set as sponsor');
+ .call()).to.be.rejectedWith('ConfirmUnsetSponsorFail');
}
{
await expect(peasantCollection.methods
- .setCollectionLimit('account_token_ownership_limit', '1000')
+ .setCollectionLimit('accountTokenOwnershipLimit', '1000')
.call()).to.be.rejectedWith(EXPECTED_ERROR);
}
});
@@ -260,11 +260,11 @@
const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'rft', sponsor);
await expect(sponsorCollection.methods
.confirmCollectionSponsorship()
- .call()).to.be.rejectedWith('caller is not set as sponsor');
+ .call()).to.be.rejectedWith('ConfirmUnsetSponsorFail');
}
{
await expect(peasantCollection.methods
- .setCollectionLimit('account_token_ownership_limit', '1000')
+ .setCollectionLimit('accountTokenOwnershipLimit', '1000')
.call()).to.be.rejectedWith(EXPECTED_ERROR);
}
});
tests/src/eth/events.test.tsdiffbeforeafterboth--- a/tests/src/eth/events.test.ts
+++ b/tests/src/eth/events.test.ts
@@ -14,11 +14,11 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+import { expect } from 'chai';
import {IKeyringPair} from '@polkadot/types/types';
-import { expect } from 'chai';
import { itEth, usingEthPlaygrounds } from './util';
-describe.only('NFT events', () => {
+describe('NFT events', () => {
let donor: IKeyringPair;
before(async function () {
@@ -29,8 +29,9 @@
itEth('Create event', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
- const {collectionAddress, events} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C');
- expect(events).to.be.like([
+ const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionCreated']}]);
+ const {collectionAddress, events: ethEvents} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C');
+ expect(ethEvents).to.be.like([
{
event: 'CollectionCreated',
args: {
@@ -39,20 +40,25 @@
}
}
]);
+ expect(subEvents).to.be.like([{method: 'CollectionCreated'}]);
+ unsubscribe();
});
itEth('Destroy event', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C');
const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
- let resutl = await collectionHelper.methods.destroyCollection(collectionAddress).send({from:owner});
- expect(resutl.events).to.be.like({
+ const {unsubscribe, collectedEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionDestroyed']}]);
+ let result = await collectionHelper.methods.destroyCollection(collectionAddress).send({from:owner});
+ expect(result.events).to.be.like({
CollectionDestroyed: {
returnValues: {
collectionId: collectionAddress
}
}
});
+ expect(collectedEvents).to.be.like([{method: 'CollectionDestroyed'}]);
+ unsubscribe();
});
itEth('CollectionChanged event for CollectionPropertySet and CollectionPropertyDeleted', async ({helper}) => {
@@ -61,13 +67,14 @@
const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
+ let {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionPropertySet', 'CollectionPropertyDeleted']}]);
{
- const events: any = [];
+ const ethEvents: any = [];
collectionHelper.events.allEvents((_: any, event: any) => {
- events.push(event);
+ ethEvents.push(event);
});
await collection.methods.setCollectionProperties([{key: 'A', value: [0,1,2,3]}]).send({from:owner});
- expect(events).to.be.like([
+ expect(ethEvents).to.be.like([
{
event: 'CollectionChanged',
returnValues: {
@@ -75,14 +82,16 @@
}
}
]);
+ expect(subEvents).to.be.like([{method: 'CollectionPropertySet'}]);
+ subEvents.pop();
}
{
- const events: any = [];
+ const ethEvents: any = [];
collectionHelper.events.allEvents((_: any, event: any) => {
- events.push(event);
+ ethEvents.push(event);
});
await collection.methods.deleteCollectionProperties(['A']).send({from:owner});
- expect(events).to.be.like([
+ expect(ethEvents).to.be.like([
{
event: 'CollectionChanged',
returnValues: {
@@ -90,8 +99,9 @@
}
}
]);
+ expect(subEvents).to.be.like([{method: 'CollectionPropertyDeleted'}]);
}
-
+ unsubscribe();
});
itEth('CollectionChanged event for PropertyPermissionSet', async ({helper}) => {
@@ -99,12 +109,13 @@
const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C');
const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
- const events: any = [];
+ const eethEvents: any = [];
collectionHelper.events.allEvents((_: any, event: any) => {
- events.push(event);
+ eethEvents.push(event);
});
+ const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['PropertyPermissionSet']}]);
await collection.methods.setTokenPropertyPermission('testKey', true, true, true).send({from: owner});
- expect(events).to.be.like([
+ expect(eethEvents).to.be.like([
{
event: 'CollectionChanged',
returnValues: {
@@ -112,28 +123,236 @@
}
}
]);
+ expect(subEvents).to.be.like([{method: 'PropertyPermissionSet'}]);
+ unsubscribe();
+ });
+
+ itEth('CollectionChanged event for AllowListAddressAdded, AllowListAddressRemoved', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const user = helper.ethCrossAccount.createAccount();
+ const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C');
+ const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
+ const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
+ const ethEvents: any[] = [];
+ collectionHelper.events.allEvents((_: any, event: any) => {
+ ethEvents.push(event);
+ });
+
+ const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['AllowListAddressAdded', 'AllowListAddressRemoved']}]);
+ {
+ await collection.methods.addToCollectionAllowListCross(user).send({from: owner});
+ expect(ethEvents).to.be.like([
+ {
+ event: 'CollectionChanged',
+ returnValues: {
+ collectionId: collectionAddress
+ }
+ }
+ ]);
+ expect(subEvents).to.be.like([{method: 'AllowListAddressAdded'}]);
+ ethEvents.pop();
+ subEvents.pop();
+ }
+ {
+ await collection.methods.removeFromCollectionAllowListCross(user).send({from: owner});
+ expect(ethEvents.length).to.be.eq(1);
+ expect(ethEvents).to.be.like([
+ {
+ event: 'CollectionChanged',
+ returnValues: {
+ collectionId: collectionAddress
+ }
+ }
+ ]);
+ expect(subEvents).to.be.like([{method: 'AllowListAddressRemoved'}]);
+ }
+ unsubscribe();
});
- // itEth('CollectionChanged event for AllowListAddressAdded', async ({helper}) => {
- // const owner = await helper.eth.createAccountWithBalance(donor);
- // const user = await helper.eth.createAccount();
- // const userCross = helper.ethCrossAccount.fromAddress(user);
- // const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
- // // allow list does not need to be enabled to add someone in advance
- // const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
- // const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
- // const events: any = [];
- // collectionHelper.events.allEvents((_: any, event: any) => {
- // events.push(event);
- // });
- // await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});
- // expect(events).to.be.like([
- // {
- // event: 'CollectionChanged',
- // returnValues: {
- // collectionId: collectionAddress
- // }
- // }
- // ]);
- // });
+ itEth('CollectionChanged event for CollectionAdminAdded, CollectionAdminRemoved', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const user = helper.ethCrossAccount.createAccount();
+ const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C');
+ const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
+ const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
+ const ethEvents: any = [];
+ collectionHelper.events.allEvents((_: any, event: any) => {
+ ethEvents.push(event);
+ });
+ const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionAdminAdded', 'CollectionAdminRemoved']}]);
+ {
+ await collection.methods.addCollectionAdminCross(user).send({from: owner});
+ expect(ethEvents).to.be.like([
+ {
+ event: 'CollectionChanged',
+ returnValues: {
+ collectionId: collectionAddress
+ }
+ }
+ ]);
+ expect(subEvents).to.be.like([{method: 'CollectionAdminAdded'}]);
+ ethEvents.pop();
+ subEvents.pop();
+ }
+ {
+ await collection.methods.removeCollectionAdminCross(user).send({from: owner});
+ expect(ethEvents).to.be.like([
+ {
+ event: 'CollectionChanged',
+ returnValues: {
+ collectionId: collectionAddress
+ }
+ }
+ ]);
+ expect(subEvents).to.be.like([{method: 'CollectionAdminRemoved'}]);
+ }
+ unsubscribe();
+ });
+
+ itEth('CollectionChanged event for CollectionLimitSet', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C');
+ const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
+ const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
+ const ethEvents: any = [];
+ collectionHelper.events.allEvents((_: any, event: any) => {
+ ethEvents.push(event);
+ });
+ const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionLimitSet']}]);
+ {
+ await collection.methods.setCollectionLimit('ownerCanTransfer', 0n).send({from: owner});
+ expect(ethEvents).to.be.like([
+ {
+ event: 'CollectionChanged',
+ returnValues: {
+ collectionId: collectionAddress
+ }
+ }
+ ]);
+ expect(subEvents).to.be.like([{method: 'CollectionLimitSet'}]);
+ }
+ unsubscribe();
+ });
+
+ itEth('CollectionChanged event for CollectionOwnedChanged', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const new_owner = helper.ethCrossAccount.createAccount();
+ const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C');
+ const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
+ const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
+ const ethEvents: any = [];
+ collectionHelper.events.allEvents((_: any, event: any) => {
+ ethEvents.push(event);
+ });
+ const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionOwnedChanged']}]);
+ {
+ await collection.methods.changeCollectionOwnerCross(new_owner).send({from: owner});
+ expect(ethEvents).to.be.like([
+ {
+ event: 'CollectionChanged',
+ returnValues: {
+ collectionId: collectionAddress
+ }
+ }
+ ]);
+ expect(subEvents).to.be.like([{method: 'CollectionOwnedChanged'}]);
+ }
+ unsubscribe();
+ });
+
+ itEth('CollectionChanged event for CollectionPermissionSet', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C');
+ const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
+ const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
+ const ethEvents: any = [];
+ collectionHelper.events.allEvents((_: any, event: any) => {
+ ethEvents.push(event);
+ });
+ const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionPermissionSet']}]);
+ {
+ await collection.methods.setCollectionMintMode(true).send({from: owner});
+ expect(ethEvents).to.be.like([
+ {
+ event: 'CollectionChanged',
+ returnValues: {
+ collectionId: collectionAddress
+ }
+ }
+ ]);
+ expect(subEvents).to.be.like([{method: 'CollectionPermissionSet'}]);
+ ethEvents.pop();
+ subEvents.pop();
+ }
+ {
+ await collection.methods.setCollectionAccess(1).send({from: owner});
+ expect(ethEvents).to.be.like([
+ {
+ event: 'CollectionChanged',
+ returnValues: {
+ collectionId: collectionAddress
+ }
+ }
+ ]);
+ expect(subEvents).to.be.like([{method: 'CollectionPermissionSet'}]);
+ }
+ unsubscribe();
+ });
+
+ itEth('CollectionChanged event for CollectionSponsorSet, SponsorshipConfirmed, CollectionSponsorRemoved', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const sponsor = await helper.ethCrossAccount.createAccountWithBalance(donor);
+ const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C');
+ const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
+ const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
+ const ethEvents: any = [];
+ collectionHelper.events.allEvents((_: any, event: any) => {
+ ethEvents.push(event);
+ });
+ const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{
+ section: 'common', names: ['CollectionSponsorSet', 'SponsorshipConfirmed', 'CollectionSponsorRemoved'
+ ]}]);
+ {
+ await collection.methods.setCollectionSponsorCross(sponsor).send({from: owner});
+ expect(ethEvents).to.be.like([
+ {
+ event: 'CollectionChanged',
+ returnValues: {
+ collectionId: collectionAddress
+ }
+ }
+ ]);
+ expect(subEvents).to.be.like([{method: 'CollectionSponsorSet'}]);
+ ethEvents.pop();
+ subEvents.pop();
+ }
+ {
+ await collection.methods.confirmCollectionSponsorship().send({from: sponsor.eth});
+ expect(ethEvents).to.be.like([
+ {
+ event: 'CollectionChanged',
+ returnValues: {
+ collectionId: collectionAddress
+ }
+ }
+ ]);
+ expect(subEvents).to.be.like([{method: 'SponsorshipConfirmed'}]);
+ ethEvents.pop();
+ subEvents.pop();
+ }
+ {
+ await collection.methods.removeCollectionSponsor().send({from: owner});
+ expect(ethEvents).to.be.like([
+ {
+ event: 'CollectionChanged',
+ returnValues: {
+ collectionId: collectionAddress
+ }
+ }
+ ]);
+ expect(subEvents).to.be.like([{method: 'CollectionSponsorRemoved'}]);
+ }
+ unsubscribe();
+ });
+
});
\ No newline at end of file
tests/src/removeCollectionAdmin.test.tsdiffbeforeafterboth--- a/tests/src/removeCollectionAdmin.test.ts
+++ b/tests/src/removeCollectionAdmin.test.ts
@@ -51,7 +51,7 @@
const adminListBeforeAddAdmin = await collection.getAdmins();
expect(adminListBeforeAddAdmin).to.have.lengthOf(0);
- await collection.removeAdmin(alice, {Substrate: alice.address});
+ await expect(collection.removeAdmin(alice, {Substrate: alice.address})).to.be.rejectedWith('common.UserIsNotAdmin');
});
});
tests/src/removeCollectionSponsor.test.tsdiffbeforeafterboth--- a/tests/src/removeCollectionSponsor.test.ts
+++ b/tests/src/removeCollectionSponsor.test.ts
@@ -112,7 +112,7 @@
const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-Neg-4', tokenPrefix: 'RCS'});
await collection.setSponsor(alice, bob.address);
await collection.removeSponsor(alice);
- await expect(collection.confirmSponsorship(bob)).to.be.rejectedWith(/unique\.ConfirmUnsetSponsorFail/);
+ await expect(collection.confirmSponsorship(bob)).to.be.rejectedWith(/common\.ConfirmUnsetSponsorFail/);
});
itSub('Set - confirm - remove - confirm: Sponsor cannot come back', async ({helper}) => {
@@ -120,6 +120,6 @@
await collection.setSponsor(alice, bob.address);
await collection.confirmSponsorship(bob);
await collection.removeSponsor(alice);
- await expect(collection.confirmSponsorship(bob)).to.be.rejectedWith(/unique\.ConfirmUnsetSponsorFail/);
+ await expect(collection.confirmSponsorship(bob)).to.be.rejectedWith(/common\.ConfirmUnsetSponsorFail/);
});
});
tests/src/util/playgrounds/unique.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/unique.ts
+++ b/tests/src/util/playgrounds/unique.ts
@@ -43,6 +43,8 @@
IEthCrossAccountId,
} from './types';
import {RuntimeDispatchInfo} from '@polkadot/types/interfaces';
+import type {Vec} from '@polkadot/types-codec';
+import { FrameSystemEventRecord } from '@polkadot/types/lookup';
export class CrossAccountId implements ICrossAccountId {
Substrate?: TSubstrateAccount;
@@ -404,6 +406,21 @@
return this.api;
}
+ async subscribeEvents(expectedEvents: {section: string, names: string[]}[]) {
+ const collectedEvents: IEvent[] = [];
+ const unsubscribe = await this.getApi().query.system.events((events: Vec<FrameSystemEventRecord>) => {
+ const ievents = this.eventHelper.extractEvents(events);
+ ievents.forEach((event) => {
+ expectedEvents.forEach((e => {
+ if (event.section === e.section && e.names.includes(event.method)) {
+ collectedEvents.push(event);
+ }
+ }))
+ });
+ });
+ return {unsubscribe: unsubscribe as any, collectedEvents};
+}
+
clearChainLog(): void {
this.chainLog = [];
}
@@ -834,7 +851,7 @@
true,
);
- return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionSponsorSet');
+ return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'CollectionSponsorSet');
}
/**
@@ -852,7 +869,7 @@
true,
);
- return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'SponsorshipConfirmed');
+ return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'SponsorshipConfirmed');
}
/**
@@ -870,7 +887,7 @@
true,
);
- return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionSponsorRemoved');
+ return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'CollectionSponsorRemoved');
}
/**
@@ -897,7 +914,7 @@
true,
);
- return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionLimitSet');
+ return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'CollectionLimitSet');
}
/**
@@ -916,7 +933,7 @@
true,
);
- return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionOwnedChanged');
+ return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'CollectionOwnedChanged');
}
/**
@@ -935,7 +952,7 @@
true,
);
- return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionAdminAdded');
+ return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'CollectionAdminAdded');
}
/**
@@ -954,7 +971,7 @@
true,
);
- return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionAdminRemoved');
+ return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'CollectionAdminRemoved');
}
/**
@@ -983,7 +1000,7 @@
true,
);
- return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'AllowListAddressAdded');
+ return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'AllowListAddressAdded');
}
/**
@@ -1001,7 +1018,7 @@
true,
);
- return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'AllowListAddressRemoved');
+ return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'AllowListAddressRemoved');
}
/**
@@ -1020,7 +1037,7 @@
true,
);
- return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionPermissionSet');
+ return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'CollectionPermissionSet');
}
/**