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.rsdiffbeforeafterboth231 /// In order for sponsorship to become active, it must be confirmed through [`Self::confirm_sponsorship`].231 /// In order for sponsorship to become active, it must be confirmed through [`Self::confirm_sponsorship`].232 pub fn set_sponsor(&mut self, sponsor: T::AccountId) -> DispatchResult {232 pub fn set_sponsor(233 &mut self,234 sender: &T::CrossAccountId,235 sponsor: T::AccountId,236 ) -> DispatchResult {237 self.check_is_internal()?;238 self.check_is_owner_or_admin(sender)?;239233 self.collection.sponsorship = SponsorshipState::Unconfirmed(sponsor);240 self.collection.sponsorship = SponsorshipState::Unconfirmed(sponsor.clone());241242 <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorSet(self.id, sponsor));234 Ok(())243 <PalletEvm<T>>::deposit_log(244 erc::CollectionHelpersEvents::CollectionChanged {245 collection_id: eth::collection_id_to_address(self.id),246 }247 .to_log(T::ContractAddress::get()),248 );249250 self.save()235 }251 }252253 /// Force set `sponsor`.254 ///255 /// Differs from [`set_sponsor`][`Self::set_sponsor`] in that confirmation256 /// from the `sponsor` is not required.257 ///258 /// # Arguments259 ///260 /// * `sender`: Caller's account.261 /// * `sponsor`: ID of the account of the sponsor-to-be.262 pub fn force_set_sponsor(&mut self, sponsor: T::AccountId) -> DispatchResult {263 self.check_is_internal()?;264265 self.collection.sponsorship = SponsorshipState::Confirmed(sponsor.clone());266267 <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorSet(self.id, sponsor.clone()));268 <Pallet<T>>::deposit_event(Event::<T>::SponsorshipConfirmed(self.id, sponsor));269 <PalletEvm<T>>::deposit_log(270 erc::CollectionHelpersEvents::CollectionChanged {271 collection_id: eth::collection_id_to_address(self.id),272 }273 .to_log(T::ContractAddress::get()),274 );275276 self.save()277 }236278237 /// Confirm sponsorship279 /// Confirm sponsorship238 ///280 ///239 /// In order for the sponsorship to become active, the user set as the sponsor must confirm their participation.281 /// In order for the sponsorship to become active, the user set as the sponsor must confirm their participation.240 /// Before confirming sponsorship, the user must be specified as the sponsor of the collection via [`Self::set_sponsor`].282 /// Before confirming sponsorship, the user must be specified as the sponsor of the collection via [`Self::set_sponsor`].241 pub fn confirm_sponsorship(&mut self, sender: &T::AccountId) -> Result<bool, DispatchError> {283 pub fn confirm_sponsorship(&mut self, sender: &T::AccountId) -> DispatchResult {284 self.check_is_internal()?;285 ensure!(242 if self.collection.sponsorship.pending_sponsor() != Some(sender) {286 self.collection.sponsorship.pending_sponsor() == Some(sender),287 Error::<T>::ConfirmUnsetSponsorFail243 return Ok(false);288 );244 }245289246 self.collection.sponsorship = SponsorshipState::Confirmed(sender.clone());290 self.collection.sponsorship = SponsorshipState::Confirmed(sender.clone());291292 <Pallet<T>>::deposit_event(Event::<T>::SponsorshipConfirmed(self.id, sender.clone()));293 <PalletEvm<T>>::deposit_log(294 erc::CollectionHelpersEvents::CollectionChanged {295 collection_id: eth::collection_id_to_address(self.id),296 }297 .to_log(T::ContractAddress::get()),298 );299247 Ok(true)300 self.save()248 }301 }249302250 /// Remove collection sponsor.303 /// Remove collection sponsor.251 pub fn remove_sponsor(&mut self) -> DispatchResult {304 pub fn remove_sponsor(&mut self, sender: &T::CrossAccountId) -> DispatchResult {305 self.check_is_internal()?;306 self.check_is_owner(sender)?;307252 self.collection.sponsorship = SponsorshipState::Disabled;308 self.collection.sponsorship = SponsorshipState::Disabled;309310 <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorRemoved(self.id));253 Ok(())311 <PalletEvm<T>>::deposit_log(312 erc::CollectionHelpersEvents::CollectionChanged {313 collection_id: eth::collection_id_to_address(self.id),314 }315 .to_log(T::ContractAddress::get()),316 );317 self.save()254 }318 }319320 /// Force remove `sponsor`.321 ///322 /// Differs from `remove_sponsor` in that323 /// it doesn't require consent from the `owner` of the collection.324 pub fn force_remove_sponsor(&mut self) -> DispatchResult {325 self.check_is_internal()?;326327 self.collection.sponsorship = SponsorshipState::Disabled;328329 <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorRemoved(self.id));330 <PalletEvm<T>>::deposit_log(331 erc::CollectionHelpersEvents::CollectionChanged {332 collection_id: eth::collection_id_to_address(self.id),333 }334 .to_log(T::ContractAddress::get()),335 );336 self.save()337 }255338256 /// Checks that the collection was created with, and must be operated upon through **Unique API**.339 /// Checks that the collection was created with, and must be operated upon through **Unique API**.257 /// Now check only the `external` flag and if it's **true**, then return [`Error::CollectionIsExternal`] error.340 /// Now check only the `external` flag and if it's **true**, then return [`Error::CollectionIsExternal`] error.328 /// Changes collection owner to another account411 /// Changes collection owner to another account329 /// #### Store read/writes412 /// #### Store read/writes330 /// 1 writes413 /// 1 writes331 fn set_owner_internal(414 pub fn change_owner(332 &mut self,415 &mut self,333 caller: T::CrossAccountId,416 caller: T::CrossAccountId,334 new_owner: T::CrossAccountId,417 new_owner: T::CrossAccountId,335 ) -> DispatchResult {418 ) -> DispatchResult {419 self.check_is_internal()?;336 self.check_is_owner(&caller)?;420 self.check_is_owner(&caller)?;337 self.collection.owner = new_owner.as_sub().clone();421 self.collection.owner = new_owner.as_sub().clone();422423 <Pallet<T>>::deposit_event(Event::<T>::CollectionOwnedChanged(424 self.id,425 new_owner.as_sub().clone(),426 ));427 <PalletEvm<T>>::deposit_log(428 erc::CollectionHelpersEvents::CollectionChanged {429 collection_id: eth::collection_id_to_address(self.id),430 }431 .to_log(T::ContractAddress::get()),432 );433338 self.save()434 self.save()339 }435 }528 PropertyKey,624 PropertyKey,529 ),625 ),626627 /// Address was added to the allow list.628 AllowListAddressAdded(629 /// ID of the affected collection.630 CollectionId,631 /// Address of the added account.632 T::CrossAccountId,633 ),634635 /// Address was removed from the allow list.636 AllowListAddressRemoved(637 /// ID of the affected collection.638 CollectionId,639 /// Address of the removed account.640 T::CrossAccountId,641 ),642643 /// Collection admin was added.644 CollectionAdminAdded(645 /// ID of the affected collection.646 CollectionId,647 /// Admin address.648 T::CrossAccountId,649 ),650651 /// Collection admin was removed.652 CollectionAdminRemoved(653 /// ID of the affected collection.654 CollectionId,655 /// Removed admin address.656 T::CrossAccountId,657 ),658659 /// Collection limits were set.660 CollectionLimitSet(661 /// ID of the affected collection.662 CollectionId,663 ),664665 /// Collection owned was changed.666 CollectionOwnedChanged(667 /// ID of the affected collection.668 CollectionId,669 /// New owner address.670 T::AccountId,671 ),672673 /// Collection permissions were set.674 CollectionPermissionSet(675 /// ID of the affected collection.676 CollectionId,677 ),678679 /// Collection sponsor was set.680 CollectionSponsorSet(681 /// ID of the affected collection.682 CollectionId,683 /// New sponsor address.684 T::AccountId,685 ),686687 /// New sponsor was confirm.688 SponsorshipConfirmed(689 /// ID of the affected collection.690 CollectionId,691 /// New sponsor address.692 T::AccountId,693 ),694695 /// Collection sponsor was removed.696 CollectionSponsorRemoved(697 /// ID of the affected collection.698 CollectionId,699 ),530 }700 }531701532 #[pallet::error]702 #[pallet::error]614 /// Tried to access an internal collection with an external API784 /// Tried to access an internal collection with an external API615 CollectionIsInternal,785 CollectionIsInternal,786787 /// This address is not set as sponsor, use setCollectionSponsor first.788 ConfirmUnsetSponsorFail,789790 /// The user is not an administrator.791 UserIsNotAdmin,616 }792 }617793618 /// Storage of the count of created collections. Essentially contains the last collection ID.794 /// Storage of the count of created collections. Essentially contains the last collection ID.136315391364 if allowed {1540 if allowed {1365 <Allowlist<T>>::insert((collection.id, user), true);1541 <Allowlist<T>>::insert((collection.id, user), true);1542 Self::deposit_event(Event::<T>::AllowListAddressAdded(1543 collection.id,1544 user.clone(),1545 ));1366 } else {1546 } else {1367 <Allowlist<T>>::remove((collection.id, user));1547 <Allowlist<T>>::remove((collection.id, user));1548 Self::deposit_event(Event::<T>::AllowListAddressRemoved(1549 collection.id,1550 user.clone(),1551 ));1368 }1552 }15531554 <PalletEvm<T>>::deposit_log(1555 erc::CollectionHelpersEvents::CollectionChanged {1556 collection_id: eth::collection_id_to_address(collection.id),1557 }1558 .to_log(T::ContractAddress::get()),1559 );136915601370 Ok(())1561 Ok(())1371 }1562 }137215631373 /// Toggle `user` participation in the `collection`'s admin list.1564 /// Toggle `user` participation in the `collection`'s admin list.1374 /// #### Store read/writes1565 /// #### Store read/writes1375 /// 2 writes1566 /// 2 reads, 2 writes1376 pub fn toggle_admin(1567 pub fn toggle_admin(1377 collection: &CollectionHandle<T>,1568 collection: &CollectionHandle<T>,1378 sender: &T::CrossAccountId,1569 sender: &T::CrossAccountId,1379 user: &T::CrossAccountId,1570 user: &T::CrossAccountId,1380 admin: bool,1571 admin: bool,1381 ) -> DispatchResult {1572 ) -> DispatchResult {1573 collection.check_is_internal()?;1382 collection.check_is_owner(sender)?;1574 collection.check_is_owner(sender)?;138315751384 let was_admin = <IsAdmin<T>>::get((collection.id, user));1576 let is_admin = <IsAdmin<T>>::get((collection.id, user));1385 if was_admin == admin {1577 if is_admin == admin {1578 if admin {1386 return Ok(());1579 return Ok(());1387 }1580 } else {1581 ensure!(false, Error::<T>::UserIsNotAdmin);1582 }1583 }1388 let amount = <AdminAmount<T>>::get(collection.id);1584 let amount = <AdminAmount<T>>::get(collection.id);138915851401 <AdminAmount<T>>::insert(collection.id, amount);1597 <AdminAmount<T>>::insert(collection.id, amount);1402 <IsAdmin<T>>::insert((collection.id, user), true);1598 <IsAdmin<T>>::insert((collection.id, user), true);15991600 Self::deposit_event(Event::<T>::CollectionAdminAdded(1601 collection.id,1602 user.clone(),1603 ));1403 } else {1604 } else {1404 <AdminAmount<T>>::insert(collection.id, amount.saturating_sub(1));1605 <AdminAmount<T>>::insert(collection.id, amount.saturating_sub(1));1405 <IsAdmin<T>>::remove((collection.id, user));1606 <IsAdmin<T>>::remove((collection.id, user));16071608 Self::deposit_event(Event::<T>::CollectionAdminRemoved(1609 collection.id,1610 user.clone(),1611 ));1406 }1612 }16131614 <PalletEvm<T>>::deposit_log(1615 erc::CollectionHelpersEvents::CollectionChanged {1616 collection_id: eth::collection_id_to_address(collection.id),1617 }1618 .to_log(T::ContractAddress::get()),1619 );140716201408 Ok(())1621 Ok(())1409 }1622 }16231624 /// Update collection limits.1625 pub fn update_limits(1626 user: &T::CrossAccountId,1627 collection: &mut CollectionHandle<T>,1628 new_limit: CollectionLimits,1629 ) -> DispatchResult {1630 collection.check_is_internal()?;1631 collection.check_is_owner_or_admin(user)?;16321633 collection.limits =1634 Self::clamp_limits(collection.mode.clone(), &collection.limits, new_limit)?;16351636 Self::deposit_event(Event::<T>::CollectionLimitSet(collection.id));1637 <PalletEvm<T>>::deposit_log(1638 erc::CollectionHelpersEvents::CollectionChanged {1639 collection_id: eth::collection_id_to_address(collection.id),1640 }1641 .to_log(T::ContractAddress::get()),1642 );16431644 collection.save()1645 }141016461411 /// Merge set fields from `new_limit` to `old_limit`.1647 /// Merge set fields from `new_limit` to `old_limit`.1412 pub fn clamp_limits(1648 fn clamp_limits(1413 mode: CollectionMode,1649 mode: CollectionMode,1414 old_limit: &CollectionLimits,1650 old_limit: &CollectionLimits,1415 mut new_limit: CollectionLimits,1651 mut new_limit: CollectionLimits,1454 Ok(new_limit)1690 Ok(new_limit)1455 }1691 }16921693 /// Update collection permissions.1694 pub fn update_permissions(1695 user: &T::CrossAccountId,1696 collection: &mut CollectionHandle<T>,1697 new_permission: CollectionPermissions,1698 ) -> DispatchResult {1699 collection.check_is_internal()?;1700 collection.check_is_owner_or_admin(user)?;1701 collection.permissions = Self::clamp_permissions(1702 collection.mode.clone(),1703 &collection.permissions,1704 new_permission,1705 )?;17061707 Self::deposit_event(Event::<T>::CollectionPermissionSet(collection.id));1708 <PalletEvm<T>>::deposit_log(1709 erc::CollectionHelpersEvents::CollectionChanged {1710 collection_id: eth::collection_id_to_address(collection.id),1711 }1712 .to_log(T::ContractAddress::get()),1713 );17141715 collection.save()1716 }145617171457 /// Merge set fields from `new_permission` to `old_permission`.1718 /// Merge set fields from `new_permission` to `old_permission`.1458 pub fn clamp_permissions(1719 fn clamp_permissions(1459 _mode: CollectionMode,1720 _mode: CollectionMode,1460 old_permission: &CollectionPermissions,1721 old_permission: &CollectionPermissions,1461 mut new_permission: CollectionPermissions,1722 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.tsdiffbeforeafterboth--- a/tests/src/eth/collectionSponsoring.test.ts
+++ b/tests/src/eth/collectionSponsoring.test.ts
@@ -258,7 +258,7 @@
await collectionEvm.methods[testCase](testCase === 'setCollectionSponsor' ? sponsor : sponsorCross).send();
let collectionData = (await collectionSub.getData())!;
expect(collectionData.raw.sponsorship.Unconfirmed).to.be.eq(helper.address.ethToSubstrate(sponsor, true));
- await expect(collectionEvm.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('caller is not set as sponsor');
+ await expect(collectionEvm.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('ConfirmUnsetSponsorFail');
await collectionEvm.methods.confirmCollectionSponsorship().send({from: sponsor});
collectionData = (await collectionSub.getData())!;
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');
}
/**