difftreelog
Fix unit test building
in: master
8 files changed
Cargo.lockdiffbeforeafterboth--- a/Cargo.lock
+++ b/Cargo.lock
@@ -5097,6 +5097,7 @@
"frame-system-rpc-runtime-api",
"hex-literal",
"nft-data-structs",
+ "orml-vesting",
"pallet-aura",
"pallet-balances",
"pallet-common",
@@ -5120,7 +5121,6 @@
"pallet-transaction-payment-rpc-runtime-api",
"pallet-treasury",
"pallet-unq-scheduler",
- "pallet-vesting",
"pallet-xcm",
"parachain-info",
"parity-scale-codec",
@@ -5308,6 +5308,21 @@
]
[[package]]
+name = "orml-vesting"
+version = "0.4.1-dev"
+source = "git+https://github.com/UniqueNetwork/open-runtime-module-library#d69f226e332ae29b7b33d53d2f06f309d2986ea0"
+dependencies = [
+ "frame-support",
+ "frame-system",
+ "parity-scale-codec",
+ "scale-info",
+ "serde",
+ "sp-io",
+ "sp-runtime",
+ "sp-std",
+]
+
+[[package]]
name = "owning_ref"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
pallets/common/src/lib.rsdiffbeforeafterboth1#![cfg_attr(not(feature = "std"), no_std)]23use core::ops::{Deref, DerefMut};4use sp_std::vec::Vec;5use account::CrossAccountId;6use frame_support::{7 dispatch::{DispatchErrorWithPostInfo, DispatchResultWithPostInfo},8 ensure, fail,9 traits::{Imbalance, Get, Currency},10};11use nft_data_structs::{12 COLLECTION_NUMBER_LIMIT, Collection, CollectionId, CreateItemData, ExistenceRequirement,13 MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_COLLECTION_NAME_LENGTH, MAX_TOKEN_PREFIX_LENGTH,14 COLLECTION_ADMINS_LIMIT, MetaUpdatePermission, Pays, PostDispatchInfo, TokenId, Weight,15 WithdrawReasons,16};17pub use pallet::*;18use sp_core::H160;19use sp_runtime::{ArithmeticError, DispatchError, DispatchResult};20pub mod account;21#[cfg(feature = "runtime-benchmarks")]22pub mod benchmarking;23pub mod erc;24pub mod eth;2526#[must_use = "Should call submit_logs or save, otherwise some data will be lost for evm side"]27pub struct CollectionHandle<T: Config> {28 pub id: CollectionId,29 collection: Collection<T>,30 pub recorder: pallet_evm_coder_substrate::SubstrateRecorder<T>,31}32impl<T: Config> CollectionHandle<T> {33 pub fn new_with_gas_limit(id: CollectionId, gas_limit: u64) -> Option<Self> {34 <CollectionById<T>>::get(id).map(|collection| Self {35 id,36 collection,37 recorder: pallet_evm_coder_substrate::SubstrateRecorder::new(38 eth::collection_id_to_address(id),39 gas_limit,40 ),41 })42 }43 pub fn new(id: CollectionId) -> Option<Self> {44 Self::new_with_gas_limit(id, u64::MAX)45 }46 pub fn try_get(id: CollectionId) -> Result<Self, DispatchError> {47 Ok(Self::new(id).ok_or_else(|| <Error<T>>::CollectionNotFound)?)48 }49 pub fn log(&self, log: impl evm_coder::ToLog) -> DispatchResult {50 self.recorder.log_sub(log)51 }52 pub fn log_infallible(&self, log: impl evm_coder::ToLog) {53 self.recorder.log_infallible(log)54 }55 #[allow(dead_code)]56 fn consume_gas(&self, gas: u64) -> DispatchResult {57 self.recorder.consume_gas_sub(gas)58 }59 pub fn consume_sload(&self) -> DispatchResult {60 self.recorder.consume_sload_sub()61 }62 pub fn consume_sstores(&self, amount: usize) -> DispatchResult {63 self.recorder.consume_sstores_sub(amount)64 }65 pub fn consume_sstore(&self) -> DispatchResult {66 self.recorder.consume_sstore_sub()67 }68 pub fn consume_log(&self, topics: usize, data: usize) -> DispatchResult {69 self.recorder.consume_log_sub(topics, data)70 }71 pub fn submit_logs(self) -> DispatchResult {72 self.recorder.submit_logs()73 }74 pub fn save(self) -> DispatchResult {75 self.recorder.submit_logs()?;76 <CollectionById<T>>::insert(self.id, self.collection);77 Ok(())78 }79}80impl<T: Config> Deref for CollectionHandle<T> {81 type Target = Collection<T>;8283 fn deref(&self) -> &Self::Target {84 &self.collection85 }86}8788impl<T: Config> DerefMut for CollectionHandle<T> {89 fn deref_mut(&mut self) -> &mut Self::Target {90 &mut self.collection91 }92}9394impl<T: Config> CollectionHandle<T> {95 pub fn check_is_owner(&self, subject: &T::CrossAccountId) -> DispatchResult {96 ensure!(*subject.as_sub() == self.owner, <Error<T>>::NoPermission);97 Ok(())98 }99 pub fn is_owner_or_admin(&self, subject: &T::CrossAccountId) -> Result<bool, DispatchError> {100 self.consume_sload()?;101102 Ok(*subject.as_sub() == self.owner || <IsAdmin<T>>::get((self.id, subject)))103 }104 pub fn check_is_owner_or_admin(&self, subject: &T::CrossAccountId) -> DispatchResult {105 ensure!(self.is_owner_or_admin(subject)?, <Error<T>>::NoPermission);106 Ok(())107 }108 pub fn ignores_allowance(&self, user: &T::CrossAccountId) -> Result<bool, DispatchError> {109 Ok(self.limits.owner_can_transfer() && self.is_owner_or_admin(user)?)110 }111 pub fn ignores_owned_amount(&self, user: &T::CrossAccountId) -> Result<bool, DispatchError> {112 Ok(self.limits.owner_can_transfer() && self.is_owner_or_admin(user)?)113 }114 pub fn check_allowlist(&self, user: &T::CrossAccountId) -> DispatchResult {115 self.consume_sload()?;116117 ensure!(118 <Allowlist<T>>::get((self.id, user)),119 <Error<T>>::AddressNotInAllowlist120 );121 Ok(())122 }123124 pub fn check_can_update_meta(125 &self,126 subject: &T::CrossAccountId,127 item_owner: &T::CrossAccountId,128 ) -> DispatchResult {129 match self.meta_update_permission {130 MetaUpdatePermission::ItemOwner => {131 ensure!(subject == item_owner, <Error<T>>::NoPermission);132 Ok(())133 }134 MetaUpdatePermission::Admin => self.check_is_owner_or_admin(subject),135 MetaUpdatePermission::None => fail!(<Error<T>>::NoPermission),136 }137 }138}139140#[frame_support::pallet]141pub mod pallet {142 use super::*;143 use frame_support::{Blake2_128Concat, pallet_prelude::*, storage::Key};144 use account::{EvmBackwardsAddressMapping, CrossAccountId};145 use frame_support::traits::Currency;146 use nft_data_structs::TokenId;147 use scale_info::TypeInfo;148149 #[pallet::config]150 pub trait Config: frame_system::Config + pallet_evm_coder_substrate::Config + TypeInfo {151 type Event: IsType<<Self as frame_system::Config>::Event> + From<Event<Self>>;152153 type CrossAccountId: CrossAccountId<Self::AccountId>;154155 type EvmAddressMapping: pallet_evm::AddressMapping<Self::AccountId>;156 type EvmBackwardsAddressMapping: EvmBackwardsAddressMapping<Self::AccountId>;157158 type Currency: Currency<Self::AccountId>;159 type CollectionCreationPrice: Get<160 <<Self as Config>::Currency as Currency<Self::AccountId>>::Balance,161 >;162 type TreasuryAccountId: Get<Self::AccountId>;163 }164165 #[pallet::pallet]166 #[pallet::generate_store(pub(super) trait Store)]167 pub struct Pallet<T>(_);168169 #[pallet::extra_constants]170 impl<T: Config> Pallet<T> {171 pub fn collection_admins_limit() -> u32 {172 COLLECTION_ADMINS_LIMIT173 }174 }175176 #[pallet::event]177 #[pallet::generate_deposit(pub fn deposit_event)]178 pub enum Event<T: Config> {179 /// New collection was created180 ///181 /// # Arguments182 ///183 /// * collection_id: Globally unique identifier of newly created collection.184 ///185 /// * mode: [CollectionMode] converted into u8.186 ///187 /// * account_id: Collection owner.188 CollectionCreated(CollectionId, u8, T::AccountId),189190 /// New item was created.191 ///192 /// # Arguments193 ///194 /// * collection_id: Id of the collection where item was created.195 ///196 /// * item_id: Id of an item. Unique within the collection.197 ///198 /// * recipient: Owner of newly created item199 ///200 /// * amount: Always 1 for NFT201 ItemCreated(CollectionId, TokenId, T::CrossAccountId, u128),202203 /// Collection item was burned.204 ///205 /// # Arguments206 ///207 /// * collection_id.208 ///209 /// * item_id: Identifier of burned NFT.210 ///211 /// * owner: which user has destroyed its tokens212 ///213 /// * amount: Always 1 for NFT214 ItemDestroyed(CollectionId, TokenId, T::CrossAccountId, u128),215216 /// Item was transferred217 ///218 /// * collection_id: Id of collection to which item is belong219 ///220 /// * item_id: Id of an item221 ///222 /// * sender: Original owner of item223 ///224 /// * recipient: New owner of item225 ///226 /// * amount: Always 1 for NFT227 Transfer(228 CollectionId,229 TokenId,230 T::CrossAccountId,231 T::CrossAccountId,232 u128,233 ),234235 /// * collection_id236 ///237 /// * item_id238 ///239 /// * sender240 ///241 /// * spender242 ///243 /// * amount244 Approved(245 CollectionId,246 TokenId,247 T::CrossAccountId,248 T::CrossAccountId,249 u128,250 ),251 }252253 #[pallet::error]254 pub enum Error<T> {255 /// This collection does not exist.256 CollectionNotFound,257 /// Sender parameter and item owner must be equal.258 MustBeTokenOwner,259 /// No permission to perform action260 NoPermission,261 /// Collection is not in mint mode.262 PublicMintingNotAllowed,263 /// Address is not in allow list.264 AddressNotInAllowlist,265266 /// Collection name can not be longer than 63 char.267 CollectionNameLimitExceeded,268 /// Collection description can not be longer than 255 char.269 CollectionDescriptionLimitExceeded,270 /// Token prefix can not be longer than 15 char.271 CollectionTokenPrefixLimitExceeded,272 /// Total collections bound exceeded.273 TotalCollectionsLimitExceeded,274 /// variable_data exceeded data limit.275 TokenVariableDataLimitExceeded,276 /// Exceeded max admin amount277 CollectionAdminAmountExceeded,278279 /// Collection settings not allowing items transferring280 TransferNotAllowed,281 /// Account token limit exceeded per collection282 AccountTokenLimitExceeded,283 /// Collection token limit exceeded284 CollectionTokenLimitExceeded,285 /// Metadata flag frozen286 MetadataFlagFrozen,287288 /// Item not exists.289 TokenNotFound,290 /// Item balance not enough.291 TokenValueTooLow,292 /// Requested value more than approved.293 TokenValueNotEnough,294 /// Tried to approve more than owned295 CantApproveMoreThanOwned,296297 /// Can't transfer tokens to ethereum zero address298 AddressIsZero,299 /// Target collection doesn't supports this operation300 UnsupportedOperation,301 }302303 #[pallet::storage]304 pub type CreatedCollectionCount<T> = StorageValue<Value = CollectionId, QueryKind = ValueQuery>;305 #[pallet::storage]306 pub type DestroyedCollectionCount<T> =307 StorageValue<Value = CollectionId, QueryKind = ValueQuery>;308309 /// Collection info310 #[pallet::storage]311 pub type CollectionById<T> = StorageMap<312 Hasher = Blake2_128Concat,313 Key = CollectionId,314 Value = Collection<T>,315 QueryKind = OptionQuery,316 >;317318 #[pallet::storage]319 pub type AdminAmount<T> = StorageMap<320 Hasher = Blake2_128Concat,321 Key = CollectionId,322 Value = u32,323 QueryKind = ValueQuery,324 >;325326 /// List of collection admins327 #[pallet::storage]328 pub type IsAdmin<T: Config> = StorageNMap<329 Key = (330 Key<Blake2_128Concat, CollectionId>,331 Key<Blake2_128Concat, T::CrossAccountId>,332 ),333 Value = bool,334 QueryKind = ValueQuery,335 >;336337 /// Allowlisted collection users338 #[pallet::storage]339 pub type Allowlist<T: Config> = StorageNMap<340 Key = (341 Key<Blake2_128Concat, CollectionId>,342 Key<Blake2_128Concat, T::CrossAccountId>,343 ),344 Value = bool,345 QueryKind = ValueQuery,346 >;347}348349impl<T: Config> Pallet<T> {350 /// Ethereum receiver 0x0000000000000000000000000000000000000000 is reserved, and shouldn't own tokens351 pub fn ensure_correct_receiver(receiver: &T::CrossAccountId) -> DispatchResult {352 ensure!(353 &T::CrossAccountId::from_eth(H160([0; 20])) != receiver,354 <Error<T>>::AddressIsZero355 );356 Ok(())357 }358}359360impl<T: Config> Pallet<T> {361 pub fn init_collection(data: Collection<T>) -> Result<CollectionId, DispatchError> {362 {363 ensure!(364 data.name.len() <= MAX_COLLECTION_NAME_LENGTH,365 Error::<T>::CollectionNameLimitExceeded366 );367 ensure!(368 data.description.len() <= MAX_COLLECTION_DESCRIPTION_LENGTH,369 Error::<T>::CollectionDescriptionLimitExceeded370 );371 ensure!(372 data.token_prefix.len() <= MAX_TOKEN_PREFIX_LENGTH,373 Error::<T>::CollectionTokenPrefixLimitExceeded374 );375 }376377 let created_count = <CreatedCollectionCount<T>>::get()378 .0379 .checked_add(1)380 .ok_or(ArithmeticError::Overflow)?;381 let destroyed_count = <DestroyedCollectionCount<T>>::get().0;382 let id = CollectionId(created_count);383384 // bound Total number of collections385 ensure!(386 created_count - destroyed_count < COLLECTION_NUMBER_LIMIT,387 <Error<T>>::TotalCollectionsLimitExceeded388 );389390 // =========391392 // Take a (non-refundable) deposit of collection creation393 {394 let mut imbalance =395 <<<T as Config>::Currency as Currency<T::AccountId>>::PositiveImbalance>::zero();396 imbalance.subsume(397 <<T as Config>::Currency as Currency<T::AccountId>>::deposit_creating(398 &T::TreasuryAccountId::get(),399 T::CollectionCreationPrice::get(),400 ),401 );402 <T as Config>::Currency::settle(403 &data.owner,404 imbalance,405 WithdrawReasons::TRANSFER,406 ExistenceRequirement::KeepAlive,407 )408 .map_err(|_| Error::<T>::NoPermission)?;409 }410411 <CreatedCollectionCount<T>>::put(created_count);412 <Pallet<T>>::deposit_event(Event::CollectionCreated(413 id,414 data.mode.id(),415 data.owner.clone(),416 ));417 <CollectionById<T>>::insert(id, data);418 Ok(id)419 }420421 pub fn destroy_collection(422 collection: CollectionHandle<T>,423 sender: &T::CrossAccountId,424 ) -> DispatchResult {425 ensure!(426 collection.limits.owner_can_destroy(),427 <Error<T>>::NoPermission,428 );429 collection.check_is_owner(&sender)?;430431 let destroyed_collections = <DestroyedCollectionCount<T>>::get()432 .0433 .checked_add(1)434 .ok_or(ArithmeticError::Overflow)?;435436 // =========437438 <DestroyedCollectionCount<T>>::put(destroyed_collections);439 <CollectionById<T>>::remove(collection.id);440 <AdminAmount<T>>::remove(collection.id);441 <IsAdmin<T>>::remove_prefix((collection.id,), None);442 <Allowlist<T>>::remove_prefix((collection.id,), None);443 Ok(())444 }445446 pub fn toggle_allowlist(447 collection: &CollectionHandle<T>,448 sender: &T::CrossAccountId,449 user: &T::CrossAccountId,450 allowed: bool,451 ) -> DispatchResult {452 collection.check_is_owner_or_admin(&sender)?;453454 // =========455456 if allowed {457 <Allowlist<T>>::insert((collection.id, user), true);458 } else {459 <Allowlist<T>>::remove((collection.id, user));460 }461462 Ok(())463 }464465 pub fn toggle_admin(466 collection: &CollectionHandle<T>,467 sender: &T::CrossAccountId,468 user: &T::CrossAccountId,469 admin: bool,470 ) -> DispatchResult {471 collection.check_is_owner_or_admin(&sender)?;472473 let was_admin = <IsAdmin<T>>::get((collection.id, user));474 if was_admin == admin {475 return Ok(());476 }477 let amount = <AdminAmount<T>>::get(collection.id);478479 if admin {480 let amount = amount481 .checked_add(1)482 .ok_or(<Error<T>>::CollectionAdminAmountExceeded)?;483 ensure!(484 amount <= Self::collection_admins_limit(),485 <Error<T>>::CollectionAdminAmountExceeded,486 );487488 // =========489490 <AdminAmount<T>>::insert(collection.id, amount);491 <IsAdmin<T>>::insert((collection.id, user), true);492 } else {493 <AdminAmount<T>>::insert(collection.id, amount.saturating_sub(1));494 <IsAdmin<T>>::remove((collection.id, user));495 }496497 Ok(())498 }499}500501#[macro_export]502macro_rules! unsupported {503 () => {504 Err(<Error<T>>::UnsupportedOperation.into())505 };506}507508/// Worst cases509pub trait CommonWeightInfo {510 fn create_item() -> Weight;511 fn create_multiple_items(amount: u32) -> Weight;512 fn burn_item() -> Weight;513 fn transfer() -> Weight;514 fn approve() -> Weight;515 fn transfer_from() -> Weight;516 fn burn_from() -> Weight;517 fn set_variable_metadata(bytes: u32) -> Weight;518}519520pub trait CommonCollectionOperations<T: Config> {521 fn create_item(522 &self,523 sender: T::CrossAccountId,524 to: T::CrossAccountId,525 data: CreateItemData,526 ) -> DispatchResultWithPostInfo;527 fn create_multiple_items(528 &self,529 sender: T::CrossAccountId,530 to: T::CrossAccountId,531 data: Vec<CreateItemData>,532 ) -> DispatchResultWithPostInfo;533 fn burn_item(534 &self,535 sender: T::CrossAccountId,536 token: TokenId,537 amount: u128,538 ) -> DispatchResultWithPostInfo;539540 fn transfer(541 &self,542 sender: T::CrossAccountId,543 to: T::CrossAccountId,544 token: TokenId,545 amount: u128,546 ) -> DispatchResultWithPostInfo;547 fn approve(548 &self,549 sender: T::CrossAccountId,550 spender: T::CrossAccountId,551 token: TokenId,552 amount: u128,553 ) -> DispatchResultWithPostInfo;554 fn transfer_from(555 &self,556 sender: T::CrossAccountId,557 from: T::CrossAccountId,558 to: T::CrossAccountId,559 token: TokenId,560 amount: u128,561 ) -> DispatchResultWithPostInfo;562 fn burn_from(563 &self,564 sender: T::CrossAccountId,565 from: T::CrossAccountId,566 token: TokenId,567 amount: u128,568 ) -> DispatchResultWithPostInfo;569570 fn set_variable_metadata(571 &self,572 sender: T::CrossAccountId,573 token: TokenId,574 data: Vec<u8>,575 ) -> DispatchResultWithPostInfo;576577 fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId>;578 fn token_exists(&self, token: TokenId) -> bool;579 fn last_token_id(&self) -> TokenId;580581 fn token_owner(&self, token: TokenId) -> T::CrossAccountId;582 fn const_metadata(&self, token: TokenId) -> Vec<u8>;583 fn variable_metadata(&self, token: TokenId) -> Vec<u8>;584585 /// How many tokens collection contains (Applicable to nonfungible/refungible)586 fn collection_tokens(&self) -> u32;587 /// Amount of different tokens account has (Applicable to nonfungible/refungible)588 fn account_balance(&self, account: T::CrossAccountId) -> u32;589 /// Amount of specific token account have (Applicable to fungible/refungible)590 fn balance(&self, account: T::CrossAccountId, token: TokenId) -> u128;591 fn allowance(592 &self,593 sender: T::CrossAccountId,594 spender: T::CrossAccountId,595 token: TokenId,596 ) -> u128;597}598599// Flexible enough for implementing CommonCollectionOperations600pub fn with_weight(res: DispatchResult, weight: Weight) -> DispatchResultWithPostInfo {601 let post_info = PostDispatchInfo {602 actual_weight: Some(weight),603 pays_fee: Pays::Yes,604 };605 match res {606 Ok(()) => Ok(post_info),607 Err(error) => Err(DispatchErrorWithPostInfo { post_info, error }),608 }609}pallets/fungible/src/common.rsdiffbeforeafterboth--- a/pallets/fungible/src/common.rs
+++ b/pallets/fungible/src/common.rs
@@ -182,7 +182,7 @@
_token: TokenId,
_data: Vec<u8>,
) -> DispatchResultWithPostInfo {
- fail!(<Error<T>>::FungibleItemsHaveData)
+ fail!(<Error<T>>::FungibleItemsDontHaveData)
}
fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId> {
pallets/fungible/src/lib.rsdiffbeforeafterboth--- a/pallets/fungible/src/lib.rs
+++ b/pallets/fungible/src/lib.rs
@@ -35,7 +35,7 @@
/// Not default id passed as TokenId argument
FungibleItemsHaveNoId,
/// Tried to set data for fungible item
- FungibleItemsHaveData,
+ FungibleItemsDontHaveData,
}
#[pallet::config]
@@ -44,15 +44,15 @@
}
#[pallet::pallet]
- #[pallet::generate_store(pub(super) trait Store)]
+ #[pallet::generate_store(pub trait Store)]
pub struct Pallet<T>(_);
#[pallet::storage]
- pub(super) type TotalSupply<T: Config> =
+ pub type TotalSupply<T: Config> =
StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u128, QueryKind = ValueQuery>;
#[pallet::storage]
- pub(super) type Balance<T: Config> = StorageNMap<
+ pub type Balance<T: Config> = StorageNMap<
Key = (
Key<Twox64Concat, CollectionId>,
Key<Blake2_128Concat, T::CrossAccountId>,
@@ -62,7 +62,7 @@
>;
#[pallet::storage]
- pub(super) type Allowance<T: Config> = StorageNMap<
+ pub type Allowance<T: Config> = StorageNMap<
Key = (
Key<Twox64Concat, CollectionId>,
Key<Blake2_128, T::CrossAccountId>,
pallets/nft/src/mock.rsdiffbeforeafterboth--- a/pallets/nft/src/mock.rs
+++ b/pallets/nft/src/mock.rs
@@ -124,25 +124,35 @@
#[derive(Encode, Decode, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, TypeInfo)]
pub struct TestCrossAccountId(u64, sp_core::H160);
impl CrossAccountId<u64> for TestCrossAccountId {
+ fn as_sub(&self) -> &u64 {
+ &self.0
+ }
+ fn as_eth(&self) -> &sp_core::H160 {
+ &self.1
+ }
fn from_sub(sub: u64) -> Self {
let mut eth = [0; 20];
eth[12..20].copy_from_slice(&sub.to_be_bytes());
Self(sub, sp_core::H160(eth))
}
- fn as_sub(&self) -> &u64 {
- &self.0
- }
fn from_eth(eth: sp_core::H160) -> Self {
let mut sub_raw = [0; 8];
sub_raw.copy_from_slice(ð.0[0..8]);
let sub = u64::from_be_bytes(sub_raw);
Self(sub, eth)
}
- fn as_eth(&self) -> &sp_core::H160 {
- &self.1
+ fn conv_eq(&self, other: &Self) -> bool {
+ self.as_sub() == other.as_sub()
+ }
+}
+
+impl Default for TestCrossAccountId {
+ fn default() -> Self {
+ Self::from_sub(0)
}
}
+
pub struct TestEtheremTransactionSender;
impl pallet_ethereum::EthereumTransactionSender for TestEtheremTransactionSender {
fn submit_logs_transaction(
@@ -157,6 +167,27 @@
type EthereumTransactionSender = TestEtheremTransactionSender;
}
+impl pallet_common::Config for Test {
+ type Event = ();
+ type EvmBackwardsAddressMapping = TestEvmBackwardsAddressMapping;
+ type EvmAddressMapping = TestEvmAddressMapping;
+ type CrossAccountId = TestCrossAccountId;
+
+ type Currency = Balances;
+ type CollectionCreationPrice = CollectionCreationPrice;
+ type TreasuryAccountId = TreasuryAccountId;
+}
+
+impl pallet_fungible::Config for Test {
+ type WeightInfo = ();
+}
+impl pallet_refungible::Config for Test {
+ type WeightInfo = ();
+}
+impl pallet_nonfungible::Config for Test {
+ type WeightInfo = ();
+}
+
impl pallet_template::Config for Test {
type WeightInfo = ();
}
pallets/nft/src/tests.rsdiffbeforeafterboth--- a/pallets/nft/src/tests.rs
+++ b/pallets/nft/src/tests.rs
@@ -1,11 +1,14 @@
// Tests to be written here
use super::*;
use crate::mock::*;
-use crate::{AccessMode, CollectionMode, CreateItemData};
+use crate::{AccessMode, CollectionMode};
use nft_data_structs::{
- CreateNftData, CreateFungibleData, CreateReFungibleData, CollectionId, TokenId,
- MAX_DECIMAL_POINTS,
+ COLLECTION_NUMBER_LIMIT, Collection, CollectionId, CreateItemData, CreateFungibleData,
+ CreateNftData, CreateReFungibleData, ExistenceRequirement, MAX_COLLECTION_DESCRIPTION_LENGTH,
+ MAX_COLLECTION_NAME_LENGTH, MAX_DECIMAL_POINTS, MAX_TOKEN_PREFIX_LENGTH, COLLECTION_ADMINS_LIMIT,
+ MetaUpdatePermission, Pays, PostDispatchInfo, TokenId, Weight, WithdrawReasons,
};
+
use frame_support::{assert_noop, assert_ok};
use sp_std::convert::TryInto;
@@ -49,18 +52,18 @@
let saved_col_name: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();
let saved_description: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();
let saved_prefix: Vec<u8> = b"token_prefix1\0".to_vec();
- assert_eq!(TemplateModule::collection_id(id).unwrap().owner, owner);
+ assert_eq!(<pallet_common::CollectionById<Test>>::get(id).unwrap().owner, owner);
assert_eq!(
- TemplateModule::collection_id(id).unwrap().name,
+ <pallet_common::CollectionById<Test>>::get(id).unwrap().name,
saved_col_name
);
- assert_eq!(TemplateModule::collection_id(id).unwrap().mode, *mode);
+ assert_eq!(<pallet_common::CollectionById<Test>>::get(id).unwrap().mode, *mode);
assert_eq!(
- TemplateModule::collection_id(id).unwrap().description,
+ <pallet_common::CollectionById<Test>>::get(id).unwrap().description,
saved_description
);
assert_eq!(
- TemplateModule::collection_id(id).unwrap().token_prefix,
+ <pallet_common::CollectionById<Test>>::get(id).unwrap().token_prefix,
saved_prefix
);
id
@@ -91,7 +94,7 @@
fn set_version_schema() {
new_test_ext().execute_with(|| {
let origin1 = Origin::signed(1);
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
assert_ok!(TemplateModule::set_schema_version(
origin1,
@@ -99,7 +102,7 @@
SchemaVersion::Unique
));
assert_eq!(
- TemplateModule::collection_id(collection_id)
+ <pallet_common::CollectionById<Test>>::get(collection_id)
.unwrap()
.schema_version,
SchemaVersion::Unique
@@ -131,11 +134,12 @@
#[test]
fn create_nft_item() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let data = default_nft_data();
create_test_item(collection_id, &data.clone().into());
- let item = TemplateModule::nft_item_id(collection_id, 1).unwrap();
+
+ let item = <pallet_nonfungible::TokenData<Test>>::get((collection_id, 1)).unwrap();
assert_eq!(item.const_data, data.const_data.into_inner());
assert_eq!(item.variable_data, data.variable_data.into_inner());
});
@@ -146,7 +150,7 @@
#[test]
fn create_nft_multiple_items() {
new_test_ext().execute_with(|| {
- create_test_collection(&CollectionMode::NFT, 1);
+ create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
@@ -154,7 +158,7 @@
assert_ok!(TemplateModule::create_multiple_items(
origin1,
- 1,
+ CollectionId(1),
account(1),
items_data
.clone()
@@ -163,7 +167,7 @@
.collect()
));
for (index, data) in items_data.into_iter().enumerate() {
- let item = TemplateModule::nft_item_id(1, (index + 1) as TokenId).unwrap();
+ let item = <pallet_nonfungible::TokenData<Test>>::get((CollectionId(1), TokenId((index + 1) as u32))).unwrap();
assert_eq!(item.const_data.to_vec(), data.const_data.into_inner());
assert_eq!(item.variable_data.to_vec(), data.variable_data.into_inner());
}
@@ -173,12 +177,12 @@
#[test]
fn create_refungible_item() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);
+ let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));
let data = default_re_fungible_data();
create_test_item(collection_id, &data.clone().into());
- let item = TemplateModule::refungible_item_id(collection_id, 1).unwrap();
- let balance = TemplateModule::balance(collection_id, 1, account(1));
+ let item = <pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1)));
+ let balance = <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1)));
assert_eq!(item.const_data, data.const_data.into_inner());
assert_eq!(item.variable_data, data.variable_data.into_inner());
assert_eq!(balance, 1023);
@@ -188,7 +192,7 @@
#[test]
fn create_multiple_refungible_items() {
new_test_ext().execute_with(|| {
- create_test_collection(&CollectionMode::ReFungible, 1);
+ create_test_collection(&CollectionMode::ReFungible, CollectionId(1));
let origin1 = Origin::signed(1);
@@ -200,7 +204,7 @@
assert_ok!(TemplateModule::create_multiple_items(
origin1,
- 1,
+ CollectionId(1),
account(1),
items_data
.clone()
@@ -209,8 +213,8 @@
.collect()
));
for (index, data) in items_data.into_iter().enumerate() {
- let item = TemplateModule::refungible_item_id(1, (index + 1) as TokenId).unwrap();
- let balance = TemplateModule::balance(1, 1, account(1));
+ let item = <pallet_nonfungible::TokenData<Test>>::get((CollectionId(1), TokenId((index + 1) as u32))).unwrap();
+ let balance = <pallet_refungible::Balance<Test>>::get((CollectionId(1), TokenId(1), account(1)));
assert_eq!(item.const_data.to_vec(), data.const_data.into_inner());
assert_eq!(item.variable_data.to_vec(), data.variable_data.into_inner());
assert_eq!(balance, 1023);
@@ -221,12 +225,12 @@
#[test]
fn create_fungible_item() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);
+ let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));
let data = default_fungible_data();
create_test_item(collection_id, &data.into());
- assert_eq!(TemplateModule::fungible_item_id(collection_id, 1).value, 5);
+ assert_eq!(<pallet_fungible::Balance<Test>>::get((collection_id, account(1))), 5);
});
}
@@ -235,7 +239,7 @@
// new_test_ext().execute_with(|| {
// default_limits();
-// create_test_collection(&CollectionMode::Fungible(3), 1);
+// create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));
// let origin1 = Origin::signed(1);
@@ -259,7 +263,7 @@
#[test]
fn transfer_fungible_item() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);
+ let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
@@ -267,39 +271,32 @@
let data = default_fungible_data();
create_test_item(collection_id, &data.into());
- assert_eq!(TemplateModule::fungible_item_id(1, 1).value, 5);
- assert_eq!(TemplateModule::balance_count(1, 1), 5);
+ assert_eq!(<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(1))), 5);
// change owner scenario
- assert_ok!(TemplateModule::transfer(origin1, account(2), 1, 1, 5));
- assert_eq!(TemplateModule::fungible_item_id(1, 1).value, 0);
- assert_eq!(TemplateModule::balance_count(1, 1), 0);
- assert_eq!(TemplateModule::balance_count(1, 2), 5);
+ assert_ok!(TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 5));
+ assert_eq!(<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(1))), 0);
// split item scenario
assert_ok!(TemplateModule::transfer(
origin2.clone(),
account(3),
- 1,
- 1,
+ CollectionId(1),
+ TokenId(1),
3
));
- assert_eq!(TemplateModule::balance_count(1, 2), 2);
- assert_eq!(TemplateModule::balance_count(1, 3), 3);
// split item and new owner has account scenario
- assert_ok!(TemplateModule::transfer(origin2, account(3), 1, 1, 1));
- assert_eq!(TemplateModule::fungible_item_id(1, 2).value, 1);
- assert_eq!(TemplateModule::fungible_item_id(1, 3).value, 4);
- assert_eq!(TemplateModule::balance_count(1, 2), 1);
- assert_eq!(TemplateModule::balance_count(1, 3), 4);
+ assert_ok!(TemplateModule::transfer(origin2, account(3), CollectionId(1), TokenId(1), 1));
+ assert_eq!(<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(2))), 1);
+ assert_eq!(<pallet_fungible::Balance<Test>>::get((CollectionId(1), account(3))), 4);
});
}
#[test]
fn transfer_refungible_item() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);
+ let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));
let data = default_re_fungible_data();
create_test_item(collection_id, &data.clone().into());
@@ -307,86 +304,87 @@
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
{
- let item = TemplateModule::refungible_item_id(collection_id, 1).unwrap();
- let balance = TemplateModule::balance(collection_id, 1, account(1));
+ let item = <pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1)));
+ let balance = <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1)));
assert_eq!(item.const_data, data.const_data.into_inner());
assert_eq!(item.variable_data, data.variable_data.into_inner());
assert_eq!(balance, 1023);
}
- assert_eq!(TemplateModule::balance_count(1, 1), 1023);
- assert_eq!(TemplateModule::address_tokens(1, 1), [1]);
+
+ assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))), 1023);
+ assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), true);
// change owner scenario
- assert_ok!(TemplateModule::transfer(origin1, account(2), 1, 1, 1023));
+ assert_ok!(TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 1023));
- let balance2 = TemplateModule::balance(collection_id, 1, account(2));
+ let balance2 = <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2)));
assert_eq!(balance2, 1023);
- assert_eq!(TemplateModule::balance_count(1, 1), 0);
- assert_eq!(TemplateModule::balance_count(1, 2), 1023);
- // assert_eq!(TemplateModule::address_tokens(1, 1), []);
- assert_eq!(TemplateModule::address_tokens(1, 2), [1]);
+ assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))), 0);
+ assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))), 1023);
+ assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), false);
+ assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))), true);
// split item scenario
assert_ok!(TemplateModule::transfer(
origin2.clone(),
account(3),
- 1,
- 1,
+ CollectionId(1),
+ TokenId(1),
500
));
{
- let item = TemplateModule::refungible_item_id(1, 1).unwrap();
- let balance2 = TemplateModule::balance(collection_id, 1, account(2));
- let balance3 = TemplateModule::balance(collection_id, 1, account(3));
+ let item = <pallet_refungible::TokenData<Test>>::get((CollectionId(1), TokenId(1)));
+ let balance2 = <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2)));
+ let balance3 = <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3)));
assert_eq!(balance2, 523);
assert_eq!(balance3, 500);
}
- assert_eq!(TemplateModule::balance_count(1, 2), 523);
- assert_eq!(TemplateModule::balance_count(1, 3), 500);
- assert_eq!(TemplateModule::address_tokens(1, 2), [1]);
- assert_eq!(TemplateModule::address_tokens(1, 3), [1]);
+ assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))), 523);
+ assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))), 500);
+ assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))), true);
+ assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(3), TokenId(1))), true);
// split item and new owner has account scenario
- assert_ok!(TemplateModule::transfer(origin2, account(3), 1, 1, 200));
+ assert_ok!(TemplateModule::transfer(origin2, account(3), CollectionId(1), TokenId(1), 200));
{
- let item = TemplateModule::refungible_item_id(1, 1).unwrap();
- let balance2 = TemplateModule::balance(collection_id, 1, account(2));
- let balance3 = TemplateModule::balance(collection_id, 1, account(3));
+ let item = <pallet_refungible::TokenData<Test>>::get((CollectionId(1), TokenId(1)));
+ let balance2 = <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(2)));
+ let balance3 = <pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(3)));
assert_eq!(balance2, 323);
assert_eq!(balance3, 700);
}
- assert_eq!(TemplateModule::balance_count(1, 2), 323);
- assert_eq!(TemplateModule::balance_count(1, 3), 700);
- assert_eq!(TemplateModule::address_tokens(1, 2), [1]);
- assert_eq!(TemplateModule::address_tokens(1, 3), [1]);
+ assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(2))), 323);
+ assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))), 700);
+ assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))), true);
+ assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(3), TokenId(1))), true);
});
}
#[test]
fn transfer_nft_item() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let data = default_nft_data();
create_test_item(collection_id, &data.into());
- assert_eq!(TemplateModule::balance_count(1, 1), 1);
- assert_eq!(TemplateModule::address_tokens(1, 1), [1]);
+ assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))), 1);
+ assert_eq!(<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), true);
+
let origin1 = Origin::signed(1);
// default scenario
- assert_ok!(TemplateModule::transfer(origin1, account(2), 1, 1, 1000));
- assert_eq!(TemplateModule::nft_item_id(1, 1).unwrap().owner, account(2));
- assert_eq!(TemplateModule::balance_count(1, 1), 0);
- assert_eq!(TemplateModule::balance_count(1, 2), 1);
- // assert_eq!(TemplateModule::address_tokens(1, 1), []);
- assert_eq!(TemplateModule::address_tokens(1, 2), [1]);
+ assert_ok!(TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 1000));
+ assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))), 0);
+ assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))), 1);
+ assert_eq!(<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), false);
+ assert_eq!(<pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))), true);
});
}
#[test]
fn nft_approve_and_transfer_from() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let data = default_nft_data();
create_test_item(collection_id, &data.into());
@@ -394,36 +392,35 @@
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
- assert_eq!(TemplateModule::balance_count(1, 1), 1);
- assert_eq!(TemplateModule::address_tokens(1, 1), [1]);
+ assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))), 1);
+ assert_eq!(<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), true);
// neg transfer
assert_noop!(
- TemplateModule::transfer_from(origin2.clone(), account(1), account(2), 1, 1, 1),
- Error::<Test>::NoPermission
+ TemplateModule::transfer_from(origin2.clone(), account(1), account(2), CollectionId(1), TokenId(1), 1),
+ CommonError::<Test>::NoPermission
);
// do approve
- assert_ok!(TemplateModule::approve(origin1, account(2), 1, 1, 5));
- assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);
- assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);
+ assert_ok!(TemplateModule::approve(origin1, account(2), CollectionId(1), TokenId(1), 5));
+ assert_eq!(<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(), account(2));
assert_ok!(TemplateModule::transfer_from(
origin2,
account(1),
account(3),
- 1,
- 1,
+ CollectionId(1),
+ TokenId(1),
1
));
- assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 4);
+ assert!(<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).is_none());
});
}
#[test]
fn nft_approve_and_transfer_from_allow_list() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
@@ -432,35 +429,35 @@
create_test_item(collection_id, &data.clone().into());
assert_eq!(
- &TemplateModule::nft_item_id(1, 1).unwrap().const_data,
+ &<pallet_nonfungible::TokenData<Test>>::get((collection_id, TokenId(1))).unwrap().const_data,
&data.const_data.into_inner()
);
- assert_eq!(TemplateModule::balance_count(1, 1), 1);
- assert_eq!(TemplateModule::address_tokens(1, 1), [1]);
+ assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))), 1);
+ assert_eq!(<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), true);
assert_ok!(TemplateModule::set_mint_permission(
origin1.clone(),
- 1,
+ CollectionId(1),
true
));
assert_ok!(TemplateModule::set_public_access_mode(
origin1.clone(),
- 1,
+ CollectionId(1),
AccessMode::AllowList
));
assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
- 1,
+ CollectionId(1),
account(1)
));
assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
- 1,
+ CollectionId(1),
account(2)
));
assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
- 1,
+ CollectionId(1),
account(3)
));
@@ -468,30 +465,30 @@
assert_ok!(TemplateModule::approve(
origin1.clone(),
account(2),
- 1,
- 1,
+ CollectionId(1),
+ TokenId(1),
5
));
- assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);
- assert_ok!(TemplateModule::approve(origin1, account(3), 1, 1, 5));
- assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 5);
+ assert_eq!(<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(), account(2));
+ assert_ok!(TemplateModule::approve(origin1, account(3), CollectionId(1), TokenId(1), 5));
+ assert_eq!(<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(), account(3));
assert_ok!(TemplateModule::transfer_from(
origin2,
account(1),
account(3),
- 1,
- 1,
+ CollectionId(1),
+ TokenId(1),
1
));
- assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 4);
+ assert!(<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).is_none());
});
}
#[test]
fn refungible_approve_and_transfer_from() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);
+ let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
@@ -499,92 +496,89 @@
let data = default_re_fungible_data();
create_test_item(collection_id, &data.into());
- assert_eq!(TemplateModule::balance_count(1, 1), 1023);
- assert_eq!(TemplateModule::address_tokens(1, 1), [1]);
+ assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))), 1023);
+ assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), true);
assert_ok!(TemplateModule::set_mint_permission(
origin1.clone(),
- 1,
+ CollectionId(1),
true
));
assert_ok!(TemplateModule::set_public_access_mode(
origin1.clone(),
- 1,
+ CollectionId(1),
AccessMode::AllowList
));
assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
- 1,
+ CollectionId(1),
account(1)
));
assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
- 1,
+ CollectionId(1),
account(2)
));
assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
- 1,
+ CollectionId(1),
account(3)
));
// do approve
- assert_ok!(TemplateModule::approve(origin1, account(2), 1, 1, 1023));
- assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1023);
+ assert_ok!(TemplateModule::approve(origin1, account(2), CollectionId(1), TokenId(1), 1023));
+ assert_eq!(<pallet_refungible::Allowance<Test>>::get((CollectionId(1), TokenId(1), account(1), account(2))), 1023);
assert_ok!(TemplateModule::transfer_from(
origin2,
account(1),
account(3),
- 1,
- 1,
+ CollectionId(1),
+ TokenId(1),
100
));
- assert_eq!(TemplateModule::balance_count(1, 1), 923);
- assert_eq!(TemplateModule::balance_count(1, 3), 100);
- assert_eq!(TemplateModule::address_tokens(1, 1), [1]);
- assert_eq!(TemplateModule::address_tokens(1, 3), [1]);
-
- assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 923);
+ assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))), 923);
+ assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(3))), 100);
+ assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), true);
+ assert_eq!(<pallet_refungible::Owned<Test>>::get((collection_id, account(1), TokenId(3))), true);
+ assert_eq!(<pallet_refungible::Allowance<Test>>::get((CollectionId(1), TokenId(1), account(1), account(2))), 923);
});
}
#[test]
fn fungible_approve_and_transfer_from() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);
+ let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));
let data = default_fungible_data();
create_test_item(collection_id, &data.into());
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
-
- assert_eq!(TemplateModule::balance_count(1, 1), 5);
assert_ok!(TemplateModule::set_mint_permission(
origin1.clone(),
- 1,
+ CollectionId(1),
true
));
assert_ok!(TemplateModule::set_public_access_mode(
origin1.clone(),
- 1,
+ CollectionId(1),
AccessMode::AllowList
));
assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
- 1,
+ CollectionId(1),
account(1)
));
assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
- 1,
+ CollectionId(1),
account(2)
));
assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
- 1,
+ CollectionId(1),
account(3)
));
@@ -592,31 +586,29 @@
assert_ok!(TemplateModule::approve(
origin1.clone(),
account(2),
- 1,
- 1,
+ CollectionId(1),
+ TokenId(1),
5
));
- assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);
- assert_ok!(TemplateModule::approve(origin1, account(3), 1, 1, 5));
- assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 5);
- assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);
+ assert_eq!(<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))), 5);
+ assert_ok!(TemplateModule::approve(origin1, account(3), CollectionId(1), TokenId(1), 5));
+ assert_eq!(<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))), 5);
+ assert_eq!(<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(3))), 5);
assert_ok!(TemplateModule::transfer_from(
origin2.clone(),
account(1),
account(3),
- 1,
- 1,
+ CollectionId(1),
+ TokenId(1),
4
));
- assert_eq!(TemplateModule::balance_count(1, 1), 1);
- assert_eq!(TemplateModule::balance_count(1, 3), 4);
- assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1);
+ assert_eq!(<pallet_fungible::Allowance<Test>>::get((CollectionId(1), account(1), account(2))), 1);
assert_noop!(
- TemplateModule::transfer_from(origin2, account(1), account(3), 1, 1, 4),
- Error::<Test>::NoPermission
+ TemplateModule::transfer_from(origin2, account(1), account(3), CollectionId(1), TokenId(1), 4),
+ CommonError::<Test>::NoPermission
);
});
}
@@ -624,7 +616,7 @@
#[test]
fn change_collection_owner() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
assert_ok!(TemplateModule::change_collection_owner(
@@ -633,7 +625,7 @@
2
));
assert_eq!(
- TemplateModule::collection_id(collection_id).unwrap().owner,
+ <pallet_common::CollectionById<Test>>::get(collection_id).unwrap().owner,
2
);
});
@@ -642,7 +634,7 @@
#[test]
fn destroy_collection() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
assert_ok!(TemplateModule::destroy_collection(origin1, collection_id));
@@ -652,7 +644,7 @@
#[test]
fn burn_nft_item() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
assert_ok!(TemplateModule::add_collection_admin(
@@ -665,28 +657,28 @@
create_test_item(collection_id, &data.into());
// check balance (collection with id = 1, user id = 1)
- assert_eq!(TemplateModule::balance_count(1, 1), 1);
+ assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))), 1);
// burn item
assert_ok!(TemplateModule::burn_item(
origin1.clone(),
collection_id,
- 1,
+ TokenId(1),
1
));
assert_noop!(
- TemplateModule::burn_item(origin1, collection_id, 1, 1),
- Error::<Test>::TokenNotFound
+ TemplateModule::burn_item(origin1, collection_id, TokenId(1), 1),
+ CommonError::<Test>::TokenNotFound
);
- assert_eq!(TemplateModule::balance_count(1, 1), 0);
+ assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))), 0);
});
}
#[test]
fn burn_fungible_item() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);
+ let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));
let origin1 = Origin::signed(1);
assert_ok!(TemplateModule::add_collection_admin(
@@ -699,23 +691,23 @@
create_test_item(collection_id, &data.into());
// check balance (collection with id = 1, user id = 1)
- assert_eq!(TemplateModule::balance_count(1, 1), 5);
+ assert_eq!(<pallet_fungible::Balance<Test>>::get((collection_id, account(1))), 5);
// burn item
- assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1, 5));
+ assert_ok!(TemplateModule::burn_item(origin1.clone(), CollectionId(1), TokenId(1), 5));
assert_noop!(
- TemplateModule::burn_item(origin1, 1, 1, 5),
- Error::<Test>::TokenValueNotEnough
+ TemplateModule::burn_item(origin1, CollectionId(1), TokenId(1), 5),
+ CommonError::<Test>::TokenValueNotEnough
);
- assert_eq!(TemplateModule::balance_count(1, 1), 0);
+ assert_eq!(<pallet_fungible::Balance<Test>>::get((collection_id, account(1))), 0);
});
}
#[test]
fn burn_refungible_item() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);
+ let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));
let origin1 = Origin::signed(1);
assert_ok!(TemplateModule::set_mint_permission(
@@ -730,13 +722,13 @@
));
assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
- 1,
+ collection_id,
account(1)
));
assert_ok!(TemplateModule::add_collection_admin(
origin1.clone(),
- 1,
+ collection_id,
account(2)
));
@@ -744,25 +736,26 @@
create_test_item(collection_id, &data.into());
// check balance (collection with id = 1, user id = 2)
- assert_eq!(TemplateModule::balance_count(1, 1), 1023);
+ assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((collection_id, account(1))), 1023);
+ assert_eq!(<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))), 1023);
// burn item
- assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1, 1023));
+ assert_ok!(TemplateModule::burn_item(origin1.clone(), collection_id, TokenId(1), 1023));
assert_noop!(
- TemplateModule::burn_item(origin1, 1, 1, 1023),
- Error::<Test>::TokenNotFound
+ TemplateModule::burn_item(origin1, collection_id, TokenId(1), 1023),
+ CommonError::<Test>::TokenNotFound
);
- assert_eq!(TemplateModule::balance_count(1, 1), 0);
+ assert_eq!(<pallet_refungible::Balance<Test>>::get((collection_id, TokenId(1), account(1))), 0);
});
}
#[test]
fn add_collection_admin() {
new_test_ext().execute_with(|| {
- let collection1_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, 1);
- create_test_collection_for_owner(&CollectionMode::NFT, 2, 2);
- create_test_collection_for_owner(&CollectionMode::NFT, 3, 3);
+ let collection1_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));
+ create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(2));
+ create_test_collection_for_owner(&CollectionMode::NFT, 3, CollectionId(3));
let origin1 = Origin::signed(1);
@@ -778,17 +771,18 @@
account(3)
));
- assert!(TemplateModule::admin_list_collection(collection1_id).contains(&account(2)),);
- assert!(TemplateModule::admin_list_collection(collection1_id).contains(&account(3)),);
+ assert!(<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(1))));
+ assert!(<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(2))));
+ assert!(<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(3))));
});
}
#[test]
fn remove_collection_admin() {
new_test_ext().execute_with(|| {
- let collection1_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, 1);
- create_test_collection_for_owner(&CollectionMode::NFT, 2, 2);
- create_test_collection_for_owner(&CollectionMode::NFT, 3, 3);
+ let collection1_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));
+ create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(2));
+ create_test_collection_for_owner(&CollectionMode::NFT, 3, CollectionId(3));
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
@@ -805,33 +799,31 @@
account(3)
));
- assert!(TemplateModule::admin_list_collection(1).contains(&account(2)),);
- assert!(TemplateModule::admin_list_collection(1).contains(&account(3)),);
+ assert!(<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(2))));
+ assert!(<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(3))));
// remove admin
assert_ok!(TemplateModule::remove_collection_admin(
origin2,
- 1,
+ CollectionId(1),
account(3)
));
- assert!(!TemplateModule::admin_list_collection(1).contains(&account(3)),);
+ assert!(<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(3))));
+ assert_eq!(<pallet_common::IsAdmin<Test>>::get((CollectionId(1), account(2))), false);
});
}
#[test]
fn balance_of() {
new_test_ext().execute_with(|| {
- let nft_collection_id = create_test_collection(&CollectionMode::NFT, 1);
- let fungible_collection_id = create_test_collection(&CollectionMode::Fungible(3), 2);
- let re_fungible_collection_id = create_test_collection(&CollectionMode::ReFungible, 3);
+ let nft_collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
+ let fungible_collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(2));
+ let re_fungible_collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(3));
// check balance before
- assert_eq!(TemplateModule::balance_count(nft_collection_id, 1), 0);
- assert_eq!(TemplateModule::balance_count(fungible_collection_id, 1), 0);
- assert_eq!(
- TemplateModule::balance_count(re_fungible_collection_id, 1),
- 0
- );
+ assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((nft_collection_id, account(1))), 0);
+ assert_eq!(<pallet_fungible::Balance<Test>>::get((fungible_collection_id, account(1))), 0);
+ assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((re_fungible_collection_id, account(1))), 0);
let nft_data = default_nft_data();
create_test_item(nft_collection_id, &nft_data.into());
@@ -843,36 +835,19 @@
create_test_item(re_fungible_collection_id, &re_fungible_data.into());
// check balance (collection with id = 1, user id = 1)
- assert_eq!(TemplateModule::balance_count(nft_collection_id, 1), 1);
- assert_eq!(TemplateModule::balance_count(fungible_collection_id, 1), 5);
- assert_eq!(
- TemplateModule::balance_count(re_fungible_collection_id, 1),
- 1023
- );
- assert_eq!(
- TemplateModule::nft_item_id(nft_collection_id, 1)
- .unwrap()
- .owner,
- account(1)
- );
- assert_eq!(
- TemplateModule::fungible_item_id(fungible_collection_id, 1).value,
- 5
- );
- assert_eq!(
- TemplateModule::refungible_item_id(re_fungible_collection_id, 1)
- .unwrap()
- .owner[0]
- .owner,
- account(1)
- );
+ assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((nft_collection_id, account(1))), 1);
+ assert_eq!(<pallet_fungible::Balance<Test>>::get((fungible_collection_id, account(1))), 5);
+ assert_eq!(<pallet_refungible::AccountBalance<Test>>::get((re_fungible_collection_id, account(1))), 1023);
+
+ assert_eq!(<pallet_nonfungible::Owned<Test>>::get((nft_collection_id, account(1), TokenId(1))), true);
+ assert_eq!(<pallet_refungible::Owned<Test>>::get((nft_collection_id, account(1), TokenId(1))), true);
});
}
#[test]
fn approve() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let data = default_nft_data();
create_test_item(collection_id, &data.into());
@@ -880,15 +855,15 @@
let origin1 = Origin::signed(1);
// approve
- assert_ok!(TemplateModule::approve(origin1, account(2), 1, 1, 1));
- assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1);
+ assert_ok!(TemplateModule::approve(origin1, account(2), CollectionId(1), TokenId(1), 1));
+ assert_eq!(<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(), account(2));
});
}
#[test]
fn transfer_from() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
@@ -899,46 +874,46 @@
assert_ok!(TemplateModule::approve(
origin1.clone(),
account(2),
- 1,
- 1,
+ CollectionId(1),
+ TokenId(1),
1
));
- assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1);
+ assert_eq!(<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(), account(2));
assert_ok!(TemplateModule::set_mint_permission(
origin1.clone(),
- 1,
+ CollectionId(1),
true
));
assert_ok!(TemplateModule::set_public_access_mode(
origin1.clone(),
- 1,
+ CollectionId(1),
AccessMode::AllowList
));
assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
- 1,
+ CollectionId(1),
account(1)
));
assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
- 1,
+ CollectionId(1),
account(2)
));
- assert_ok!(TemplateModule::add_to_allow_list(origin1, 1, account(3)));
+ assert_ok!(TemplateModule::add_to_allow_list(origin1, CollectionId(1), account(3)));
assert_ok!(TemplateModule::transfer_from(
origin2,
account(1),
account(2),
- 1,
- 1,
+ CollectionId(1),
+ TokenId(1),
1
));
// after transfer
- assert_eq!(TemplateModule::balance_count(1, 1), 0);
- assert_eq!(TemplateModule::balance_count(1, 2), 1);
+ assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((CollectionId(1), account(1))), 0);
+ assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((CollectionId(1), account(2))), 1);
});
}
@@ -950,7 +925,7 @@
#[test]
fn owner_can_add_address_to_allow_list() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
assert_ok!(TemplateModule::add_to_allow_list(
@@ -958,14 +933,14 @@
collection_id,
account(2)
));
- assert!(TemplateModule::allow_list(collection_id, 2));
+ assert!(<pallet_common::Allowlist<Test>>::get((collection_id, account(2))));
});
}
#[test]
fn admin_can_add_address_to_allow_list() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
@@ -979,19 +954,19 @@
collection_id,
account(3)
));
- assert!(TemplateModule::allow_list(collection_id, 3));
+ assert!(<pallet_common::Allowlist<Test>>::get((collection_id, account(3))));
});
}
#[test]
fn nonprivileged_user_cannot_add_address_to_allow_list() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin2 = Origin::signed(2);
assert_noop!(
TemplateModule::add_to_allow_list(origin2, collection_id, account(3)),
- Error::<Test>::NoPermission
+ CommonError::<Test>::NoPermission
);
});
}
@@ -1002,8 +977,8 @@
let origin1 = Origin::signed(1);
assert_noop!(
- TemplateModule::add_to_allow_list(origin1, 1, account(2)),
- Error::<Test>::CollectionNotFound
+ TemplateModule::add_to_allow_list(origin1, CollectionId(1), account(2)),
+ CommonError::<Test>::CollectionNotFound
);
});
}
@@ -1011,7 +986,7 @@
#[test]
fn nobody_can_add_address_to_allow_list_of_deleted_collection() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
assert_ok!(TemplateModule::destroy_collection(
@@ -1020,7 +995,7 @@
));
assert_noop!(
TemplateModule::add_to_allow_list(origin1, collection_id, account(2)),
- Error::<Test>::CollectionNotFound
+ CommonError::<Test>::CollectionNotFound
);
});
}
@@ -1029,7 +1004,7 @@
#[test]
fn address_is_already_added_to_allow_list() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
assert_ok!(TemplateModule::add_to_allow_list(
@@ -1042,14 +1017,14 @@
collection_id,
account(2)
));
- assert!(TemplateModule::allow_list(collection_id, 2));
+ assert!(<pallet_common::Allowlist<Test>>::get((collection_id, account(2))));
});
}
#[test]
fn owner_can_remove_address_from_allow_list() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
assert_ok!(TemplateModule::add_to_allow_list(
@@ -1062,14 +1037,14 @@
collection_id,
account(2)
));
- assert!(!TemplateModule::allow_list(collection_id, 2));
+ assert!(<pallet_common::Allowlist<Test>>::get((collection_id, account(2))));
});
}
#[test]
fn admin_can_remove_address_from_allow_list() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
@@ -1089,14 +1064,14 @@
collection_id,
account(3)
));
- assert!(!TemplateModule::allow_list(collection_id, 3));
+ assert!(<pallet_common::Allowlist<Test>>::get((collection_id, account(3))));
});
}
#[test]
fn nonprivileged_user_cannot_remove_address_from_allow_list() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
@@ -1107,9 +1082,9 @@
));
assert_noop!(
TemplateModule::remove_from_allow_list(origin2, collection_id, account(2)),
- Error::<Test>::NoPermission
+ CommonError::<Test>::NoPermission
);
- assert!(TemplateModule::allow_list(collection_id, 2));
+ assert!(<pallet_common::Allowlist<Test>>::get((collection_id, account(2))));
});
}
@@ -1119,8 +1094,8 @@
let origin1 = Origin::signed(1);
assert_noop!(
- TemplateModule::remove_from_allow_list(origin1, 1, account(2)),
- Error::<Test>::CollectionNotFound
+ TemplateModule::remove_from_allow_list(origin1, CollectionId(1), account(2)),
+ CommonError::<Test>::CollectionNotFound
);
});
}
@@ -1128,7 +1103,7 @@
#[test]
fn nobody_can_remove_address_from_allow_list_of_deleted_collection() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
@@ -1140,9 +1115,9 @@
assert_ok!(TemplateModule::destroy_collection(origin1, collection_id));
assert_noop!(
TemplateModule::remove_from_allow_list(origin2, collection_id, account(2)),
- Error::<Test>::CollectionNotFound
+ CommonError::<Test>::CollectionNotFound
);
- assert!(!TemplateModule::allow_list(collection_id, 2));
+ assert!(<pallet_common::Allowlist<Test>>::get((collection_id, account(2))));
});
}
@@ -1150,7 +1125,7 @@
#[test]
fn address_is_already_removed_from_allow_list() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
assert_ok!(TemplateModule::add_to_allow_list(
@@ -1168,7 +1143,7 @@
collection_id,
account(2)
));
- assert!(!TemplateModule::allow_list(collection_id, 2));
+ assert!(<pallet_common::Allowlist<Test>>::get((collection_id, account(2))));
});
}
@@ -1176,7 +1151,7 @@
#[test]
fn allow_list_test_1() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
@@ -1195,8 +1170,8 @@
));
assert_noop!(
- TemplateModule::transfer(origin1, account(3), 1, 1, 1),
- Error::<Test>::AddresNotInAllowList
+ TemplateModule::transfer(origin1, account(3), CollectionId(1), TokenId(1), 1),
+ CommonError::<Test>::AddressNotInAllowlist
);
});
}
@@ -1204,7 +1179,7 @@
#[test]
fn allow_list_test_2() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
let data = default_nft_data();
@@ -1217,12 +1192,12 @@
));
assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
- 1,
+ collection_id,
account(1)
));
assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
- 1,
+ collection_id,
account(2)
));
@@ -1230,21 +1205,21 @@
assert_ok!(TemplateModule::approve(
origin1.clone(),
account(1),
- 1,
- 1,
+ collection_id,
+ TokenId(1),
1
));
- assert_eq!(TemplateModule::approved(1, (1, 1, 1)), 1);
+ assert_eq!(<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(), account(1));
assert_ok!(TemplateModule::remove_from_allow_list(
origin1.clone(),
- 1,
+ collection_id,
account(1)
));
assert_noop!(
- TemplateModule::transfer_from(origin1, account(1), account(3), 1, 1, 1),
- Error::<Test>::AddresNotInAllowList
+ TemplateModule::transfer_from(origin1, account(1), account(3), CollectionId(1), TokenId(1), 1),
+ CommonError::<Test>::AddressNotInAllowlist
);
});
}
@@ -1253,7 +1228,7 @@
#[test]
fn allow_list_test_3() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
@@ -1267,13 +1242,13 @@
));
assert_ok!(TemplateModule::add_to_allow_list(
origin1.clone(),
- 1,
+ collection_id,
account(1)
));
assert_noop!(
- TemplateModule::transfer(origin1, account(3), 1, 1, 1),
- Error::<Test>::AddresNotInAllowList
+ TemplateModule::transfer(origin1, account(3), collection_id, TokenId(1), 1),
+ CommonError::<Test>::AddressNotInAllowlist
);
});
}
@@ -1281,7 +1256,7 @@
#[test]
fn allow_list_test_4() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
@@ -1308,11 +1283,11 @@
assert_ok!(TemplateModule::approve(
origin1.clone(),
account(1),
- 1,
- 1,
+ collection_id,
+ TokenId(1),
1
));
- assert_eq!(TemplateModule::approved(1, (1, 1, 1)), 1);
+ assert_eq!(<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(), account(1));
assert_ok!(TemplateModule::remove_from_allow_list(
origin1.clone(),
@@ -1321,8 +1296,8 @@
));
assert_noop!(
- TemplateModule::transfer_from(origin1, account(1), account(3), 1, 1, 1),
- Error::<Test>::AddresNotInAllowList
+ TemplateModule::transfer_from(origin1, account(1), account(3), collection_id, TokenId(1), 1),
+ CommonError::<Test>::AddressNotInAllowlist
);
});
}
@@ -1331,7 +1306,7 @@
#[test]
fn allow_list_test_5() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
@@ -1344,8 +1319,8 @@
AccessMode::AllowList
));
assert_noop!(
- TemplateModule::burn_item(origin1.clone(), 1, 1, 5),
- Error::<Test>::AddresNotInAllowList
+ TemplateModule::burn_item(origin1.clone(), CollectionId(1), TokenId(1), 5),
+ CommonError::<Test>::AddressNotInAllowlist
);
});
}
@@ -1354,7 +1329,7 @@
#[test]
fn allow_list_test_6() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
@@ -1369,8 +1344,8 @@
// do approve
assert_noop!(
- TemplateModule::approve(origin1, account(1), 1, 1, 5),
- Error::<Test>::AddresNotInAllowList
+ TemplateModule::approve(origin1, account(1), CollectionId(1), TokenId(1), 5),
+ CommonError::<Test>::AddressNotInAllowlist
);
});
}
@@ -1380,7 +1355,7 @@
#[test]
fn allow_list_test_7() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let data = default_nft_data();
create_test_item(collection_id, &data.into());
@@ -1403,14 +1378,14 @@
account(2)
));
- assert_ok!(TemplateModule::transfer(origin1, account(2), 1, 1, 1));
+ assert_ok!(TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 1));
});
}
#[test]
fn allow_list_test_8() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let data = default_nft_data();
create_test_item(collection_id, &data.into());
@@ -1437,18 +1412,18 @@
assert_ok!(TemplateModule::approve(
origin1.clone(),
account(1),
- 1,
- 1,
+ CollectionId(1),
+ TokenId(1),
5
));
- assert_eq!(TemplateModule::approved(1, (1, 1, 1)), 5);
+ assert_eq!(<pallet_nonfungible::Allowance<Test>>::get((CollectionId(1), TokenId(1))).unwrap(), account(1));
assert_ok!(TemplateModule::transfer_from(
origin1,
account(1),
account(2),
- 1,
- 1,
+ CollectionId(1),
+ TokenId(1),
1
));
});
@@ -1458,7 +1433,7 @@
#[test]
fn allow_list_test_9() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
assert_ok!(TemplateModule::set_public_access_mode(
@@ -1481,7 +1456,7 @@
#[test]
fn allow_list_test_10() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
@@ -1516,7 +1491,7 @@
#[test]
fn allow_list_test_11() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
@@ -1538,8 +1513,8 @@
));
assert_noop!(
- TemplateModule::create_item(origin2, 1, account(2), default_nft_data().into()),
- Error::<Test>::PublicMintingNotAllowed
+ TemplateModule::create_item(origin2, CollectionId(1), account(2), default_nft_data().into()),
+ CommonError::<Test>::PublicMintingNotAllowed
);
});
}
@@ -1548,7 +1523,7 @@
#[test]
fn allow_list_test_12() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
@@ -1565,8 +1540,8 @@
));
assert_noop!(
- TemplateModule::create_item(origin2, 1, account(2), default_nft_data().into()),
- Error::<Test>::PublicMintingNotAllowed
+ TemplateModule::create_item(origin2, CollectionId(1), account(2), default_nft_data().into()),
+ CommonError::<Test>::PublicMintingNotAllowed
);
});
}
@@ -1575,7 +1550,7 @@
#[test]
fn allow_list_test_13() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
@@ -1599,7 +1574,7 @@
#[test]
fn allow_list_test_14() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
@@ -1623,7 +1598,7 @@
assert_ok!(TemplateModule::create_item(
origin2,
- 1,
+ collection_id,
account(2),
default_nft_data().into()
));
@@ -1634,7 +1609,7 @@
#[test]
fn allow_list_test_15() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
@@ -1651,8 +1626,8 @@
));
assert_noop!(
- TemplateModule::create_item(origin2, 1, account(2), default_nft_data().into()),
- Error::<Test>::AddresNotInAllowList
+ TemplateModule::create_item(origin2, collection_id, account(2), default_nft_data().into()),
+ CommonError::<Test>::AddressNotInAllowlist
);
});
}
@@ -1661,7 +1636,7 @@
#[test]
fn allow_list_test_16() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
@@ -1684,7 +1659,7 @@
assert_ok!(TemplateModule::create_item(
origin2,
- 1,
+ collection_id,
account(2),
default_nft_data().into()
));
@@ -1695,7 +1670,7 @@
#[test]
fn total_number_collections_bound() {
new_test_ext().execute_with(|| {
- create_test_collection(&CollectionMode::NFT, 1);
+ create_test_collection(&CollectionMode::NFT, CollectionId(1));
});
}
@@ -1706,7 +1681,7 @@
let origin1 = Origin::signed(1);
for i in 0..COLLECTION_NUMBER_LIMIT {
- create_test_collection(&CollectionMode::NFT, i + 1);
+ create_test_collection(&CollectionMode::NFT, CollectionId(i + 1));
}
let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();
@@ -1722,7 +1697,7 @@
token_prefix1,
CollectionMode::NFT
),
- Error::<Test>::TotalCollectionsLimitExceeded
+ CommonError::<Test>::TotalCollectionsLimitExceeded
);
});
}
@@ -1731,7 +1706,7 @@
#[test]
fn owned_tokens_bound() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let data = default_nft_data();
create_test_item(collection_id, &data.clone().into());
@@ -1743,19 +1718,19 @@
#[test]
fn owned_tokens_bound_neg() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
- for _ in 0..ACCOUNT_TOKEN_OWNERSHIP_LIMIT {
+ for _ in 0..MAX_TOKEN_OWNERSHIP {
let data = default_nft_data();
create_test_item(collection_id, &data.clone().into());
}
let data = default_nft_data();
assert_noop!(
- TemplateModule::create_item(origin1, 1, account(1), data.into()),
- Error::<Test>::AccountTokenLimitExceeded
+ TemplateModule::create_item(origin1, CollectionId(1), account(1), data.into()),
+ CommonError::<Test>::AccountTokenLimitExceeded
);
});
}
@@ -1764,7 +1739,7 @@
#[test]
fn collection_admins_bound() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
@@ -1785,7 +1760,7 @@
#[test]
fn collection_admins_bound_neg() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
@@ -1793,16 +1768,16 @@
assert_ok!(TemplateModule::add_collection_admin(
origin1.clone(),
collection_id,
- account(2 + i)
+ account((2 + i).into())
));
}
assert_noop!(
TemplateModule::add_collection_admin(
origin1,
collection_id,
- account(3 + COLLECTION_ADMINS_LIMIT)
+ account((3 + COLLECTION_ADMINS_LIMIT).into())
),
- Error::<Test>::CollectionAdminsLimitExceeded
+ CommonError::<Test>::CollectionAdminCountExceeded
);
});
}
@@ -1811,7 +1786,7 @@
#[test]
fn set_const_on_chain_schema() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
assert_ok!(TemplateModule::set_const_on_chain_schema(
@@ -1821,13 +1796,13 @@
));
assert_eq!(
- TemplateModule::collection_id(collection_id)
+ <pallet_common::CollectionById<Test>>::get(collection_id)
.unwrap()
.const_on_chain_schema,
b"test const on chain schema".to_vec()
);
assert_eq!(
- TemplateModule::collection_id(collection_id)
+ <pallet_common::CollectionById<Test>>::get(collection_id)
.unwrap()
.variable_on_chain_schema,
b"".to_vec()
@@ -1838,7 +1813,7 @@
#[test]
fn set_variable_on_chain_schema() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
assert_ok!(TemplateModule::set_variable_on_chain_schema(
@@ -1848,13 +1823,13 @@
));
assert_eq!(
- TemplateModule::collection_id(collection_id)
+ <pallet_common::CollectionById<Test>>::get(collection_id)
.unwrap()
.const_on_chain_schema,
b"".to_vec()
);
assert_eq!(
- TemplateModule::collection_id(collection_id)
+ <pallet_common::CollectionById<Test>>::get(collection_id)
.unwrap()
.variable_on_chain_schema,
b"test variable on chain schema".to_vec()
@@ -1865,23 +1840,23 @@
#[test]
fn set_variable_meta_data_on_nft_token_stores_variable_meta_data() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
let data = default_nft_data();
- create_test_item(1, &data.into());
+ create_test_item(CollectionId(1), &data.into());
let variable_data = b"test data".to_vec();
assert_ok!(TemplateModule::set_variable_meta_data(
origin1,
collection_id,
- 1,
+ TokenId(1),
variable_data.clone()
));
assert_eq!(
- TemplateModule::nft_item_id(collection_id, 1)
+ <pallet_nonfungible::TokenData<Test>>::get((collection_id, 1))
.unwrap()
.variable_data,
variable_data
@@ -1892,24 +1867,23 @@
#[test]
fn set_variable_meta_data_on_re_fungible_token_stores_variable_meta_data() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);
+ let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));
let origin1 = Origin::signed(1);
let data = default_re_fungible_data();
- create_test_item(1, &data.into());
+ create_test_item(collection_id, &data.into());
let variable_data = b"test data".to_vec();
assert_ok!(TemplateModule::set_variable_meta_data(
origin1,
collection_id,
- 1,
+ TokenId(1),
variable_data.clone()
));
assert_eq!(
- TemplateModule::refungible_item_id(collection_id, 1)
- .unwrap()
+ <pallet_refungible::TokenData<Test>>::get((collection_id, TokenId(1)))
.variable_data,
variable_data
);
@@ -1919,17 +1893,17 @@
#[test]
fn set_variable_meta_data_on_fungible_token_fails() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);
+ let collection_id = create_test_collection(&CollectionMode::Fungible(3), CollectionId(1));
let origin1 = Origin::signed(1);
let data = default_fungible_data();
- create_test_item(1, &data.into());
+ create_test_item(collection_id, &data.into());
let variable_data = b"test data".to_vec();
assert_noop!(
- TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data),
- Error::<Test>::CantStoreMetadataInFungibleTokens
+ TemplateModule::set_variable_meta_data(origin1, collection_id, TokenId(1), variable_data),
+ <pallet_fungible::Error<Test>>::FungibleItemsDontHaveData
);
});
}
@@ -1937,17 +1911,17 @@
#[test]
fn set_variable_meta_data_on_nft_token_fails_for_big_data() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
let data = default_nft_data();
- create_test_item(1, &data.into());
+ create_test_item(collection_id, &data.into());
let variable_data = b"test set_variable_meta_data method, bigger than limits.".to_vec();
assert_noop!(
- TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data),
- Error::<Test>::TokenVariableDataLimitExceeded
+ TemplateModule::set_variable_meta_data(origin1, collection_id, TokenId(1), variable_data),
+ CommonError::<Test>::TokenVariableDataLimitExceeded
);
});
}
@@ -1955,17 +1929,17 @@
#[test]
fn set_variable_meta_data_on_re_fungible_token_fails_for_big_data() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);
+ let collection_id = create_test_collection(&CollectionMode::ReFungible, CollectionId(1));
let origin1 = Origin::signed(1);
let data = default_re_fungible_data();
- create_test_item(1, &data.into());
+ create_test_item(collection_id, &data.into());
let variable_data = b"test set_variable_meta_data method, bigger than limits.".to_vec();
assert_noop!(
- TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data),
- Error::<Test>::TokenVariableDataLimitExceeded
+ TemplateModule::set_variable_meta_data(origin1, collection_id, TokenId(1), variable_data),
+ CommonError::<Test>::TokenVariableDataLimitExceeded
);
});
}
@@ -1975,12 +1949,12 @@
new_test_ext().execute_with(|| {
//default_limits();
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
let origin1 = Origin::signed(1);
let data = default_nft_data();
- create_test_item(1, &data.into());
+ create_test_item(collection_id, &data.into());
assert_ok!(TemplateModule::set_meta_update_permission_flag(
origin1.clone(),
@@ -1992,12 +1966,12 @@
assert_ok!(TemplateModule::set_variable_meta_data(
origin1,
collection_id,
- 1,
+ TokenId(1),
variable_data.clone()
));
assert_eq!(
- TemplateModule::nft_item_id(collection_id, 1)
+ <pallet_nonfungible::TokenData<Test>>::get((collection_id, TokenId(1)))
.unwrap()
.variable_data,
variable_data
@@ -2008,7 +1982,7 @@
#[test]
fn set_variable_meta_data_on_nft_with_item_owner_permission_flag_neg() {
new_test_ext().execute_with(|| {
- let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, 1);
+ let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));
let origin1 = Origin::signed(1);
@@ -2024,7 +1998,7 @@
));
let data = default_nft_data();
- create_test_item(1, &data.into());
+ create_test_item(collection_id, &data.into());
assert_ok!(TemplateModule::set_meta_update_permission_flag(
origin1.clone(),
@@ -2037,10 +2011,10 @@
TemplateModule::set_variable_meta_data(
origin1,
collection_id,
- 1,
+ TokenId(1),
variable_data.clone()
),
- Error::<Test>::TokenVariableDataLimitExceeded
+ CommonError::<Test>::TokenVariableDataLimitExceeded
);
})
}
@@ -2050,23 +2024,22 @@
new_test_ext().execute_with(|| {
let origin1 = Origin::signed(1);
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
- assert_ok!(TemplateModule::set_transfers_enabled_flag(origin1, 1, true));
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
+ assert_ok!(TemplateModule::set_transfers_enabled_flag(origin1, collection_id, true));
let data = default_nft_data();
create_test_item(collection_id, &data.into());
- assert_eq!(TemplateModule::balance_count(1, 1), 1);
- assert_eq!(TemplateModule::address_tokens(1, 1), [1]);
+ assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))), 1);
+ assert_eq!(<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), true);
let origin1 = Origin::signed(1);
// default scenario
- assert_ok!(TemplateModule::transfer(origin1, account(2), 1, 1, 1000));
- assert_eq!(TemplateModule::nft_item_id(1, 1).unwrap().owner, account(2));
- assert_eq!(TemplateModule::balance_count(1, 1), 0);
- assert_eq!(TemplateModule::balance_count(1, 2), 1);
-
- assert_eq!(TemplateModule::address_tokens(1, 2), [1]);
+ assert_ok!(TemplateModule::transfer(origin1, account(2), collection_id, TokenId(1), 1000));
+ assert_eq!(<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), false);
+ assert_eq!(<pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))), true);
+ assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))), 0);
+ assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))), 1);
});
}
@@ -2075,7 +2048,7 @@
new_test_ext().execute_with(|| {
// default_limits();
- let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 2, 1);
+ let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(1));
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
@@ -2098,7 +2071,7 @@
));
let data = default_nft_data();
- create_test_item(1, &data.into());
+ create_test_item(collection_id, &data.into());
assert_ok!(TemplateModule::set_meta_update_permission_flag(
origin2.clone(),
@@ -2110,12 +2083,12 @@
assert_ok!(TemplateModule::set_variable_meta_data(
origin1,
collection_id,
- 1,
+ TokenId(1),
variable_data.clone()
));
assert_eq!(
- TemplateModule::nft_item_id(collection_id, 1)
+ <pallet_nonfungible::TokenData<Test>>::get((collection_id, 1))
.unwrap()
.variable_data,
variable_data
@@ -2128,7 +2101,7 @@
new_test_ext().execute_with(|| {
// default_limits();
- let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 2, 1);
+ let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(1));
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
@@ -2145,7 +2118,7 @@
));
let data = default_nft_data();
- create_test_item(1, &data.into());
+ create_test_item(collection_id, &data.into());
assert_ok!(TemplateModule::set_meta_update_permission_flag(
origin2.clone(),
@@ -2158,10 +2131,10 @@
TemplateModule::set_variable_meta_data(
origin1,
collection_id,
- 1,
+ TokenId(1),
variable_data.clone()
),
- Error::<Test>::NoPermission
+ CommonError::<Test>::NoPermission
);
});
}
@@ -2171,7 +2144,7 @@
new_test_ext().execute_with(|| {
// default_limits();
- let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 2, 1);
+ let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 2, CollectionId(1));
let origin2 = Origin::signed(2);
@@ -2186,7 +2159,7 @@
collection_id,
MetaUpdatePermission::Admin
),
- Error::<Test>::MetadataFlagFrozen
+ CommonError::<Test>::MetadataFlagFrozen
);
});
}
@@ -2196,11 +2169,11 @@
new_test_ext().execute_with(|| {
// default_limits();
- let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, 1);
+ let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, CollectionId(1));
let origin1 = Origin::signed(1);
let data = default_nft_data();
- create_test_item(1, &data.into());
+ create_test_item(collection_id, &data.into());
assert_ok!(TemplateModule::set_meta_update_permission_flag(
origin1.clone(),
@@ -2213,10 +2186,10 @@
TemplateModule::set_variable_meta_data(
origin1.clone(),
collection_id,
- 1,
+ TokenId(1),
variable_data.clone()
),
- Error::<Test>::MetadataUpdateDenied
+ CommonError::<Test>::NoPermission
);
});
}
@@ -2226,27 +2199,26 @@
new_test_ext().execute_with(|| {
let origin1 = Origin::signed(1);
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));
assert_ok!(TemplateModule::set_transfers_enabled_flag(
- origin1, 1, false
+ origin1, collection_id, false
));
let data = default_nft_data();
create_test_item(collection_id, &data.into());
- assert_eq!(TemplateModule::balance_count(1, 1), 1);
- assert_eq!(TemplateModule::address_tokens(1, 1), [1]);
+ assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))), 1);
+ assert_eq!(<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), true);
let origin1 = Origin::signed(1);
// default scenario
assert_noop!(
- TemplateModule::transfer(origin1, account(2), 1, 1, 1000),
- Error::<Test>::TransferNotAllowed
+ TemplateModule::transfer(origin1, account(2), CollectionId(1), TokenId(1), 1000),
+ CommonError::<Test>::TransferNotAllowed
);
- assert_eq!(TemplateModule::nft_item_id(1, 1).unwrap().owner, account(1));
- assert_eq!(TemplateModule::balance_count(1, 1), 1);
- assert_eq!(TemplateModule::balance_count(1, 2), 0);
-
- assert_eq!(TemplateModule::address_tokens(1, 1), [1]);
+ assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(1))), 1);
+ assert_eq!(<pallet_nonfungible::AccountBalance<Test>>::get((collection_id, account(2))), 0);
+ assert_eq!(<pallet_nonfungible::Owned<Test>>::get((collection_id, account(1), TokenId(1))), true);
+ assert_eq!(<pallet_nonfungible::Owned<Test>>::get((collection_id, account(2), TokenId(1))), false);
});
}
pallets/nonfungible/src/lib.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -58,18 +58,18 @@
}
#[pallet::pallet]
- #[pallet::generate_store(pub(super) trait Store)]
+ #[pallet::generate_store(pub trait Store)]
pub struct Pallet<T>(_);
#[pallet::storage]
- pub(super) type TokensMinted<T: Config> =
+ pub type TokensMinted<T: Config> =
StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;
#[pallet::storage]
- pub(super) type TokensBurnt<T: Config> =
+ pub type TokensBurnt<T: Config> =
StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;
#[pallet::storage]
- pub(super) type TokenData<T: Config> = StorageNMap<
+ pub type TokenData<T: Config> = StorageNMap<
Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),
Value = ItemData<T>,
QueryKind = OptionQuery,
@@ -77,7 +77,7 @@
/// Used to enumerate tokens owned by account
#[pallet::storage]
- pub(super) type Owned<T: Config> = StorageNMap<
+ pub type Owned<T: Config> = StorageNMap<
Key = (
Key<Twox64Concat, CollectionId>,
Key<Blake2_128Concat, T::CrossAccountId>,
@@ -88,7 +88,7 @@
>;
#[pallet::storage]
- pub(super) type AccountBalance<T: Config> = StorageNMap<
+ pub type AccountBalance<T: Config> = StorageNMap<
Key = (
Key<Twox64Concat, CollectionId>,
Key<Blake2_128Concat, T::CrossAccountId>,
@@ -98,7 +98,7 @@
>;
#[pallet::storage]
- pub(super) type Allowance<T: Config> = StorageNMap<
+ pub type Allowance<T: Config> = StorageNMap<
Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),
Value = T::CrossAccountId,
QueryKind = OptionQuery,
pallets/refungible/src/lib.rsdiffbeforeafterboth--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -54,25 +54,25 @@
}
#[pallet::pallet]
- #[pallet::generate_store(pub(super) trait Store)]
+ #[pallet::generate_store(pub trait Store)]
pub struct Pallet<T>(_);
#[pallet::storage]
- pub(super) type TokensMinted<T: Config> =
+ pub type TokensMinted<T: Config> =
StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;
#[pallet::storage]
- pub(super) type TokensBurnt<T: Config> =
+ pub type TokensBurnt<T: Config> =
StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;
#[pallet::storage]
- pub(super) type TokenData<T: Config> = StorageNMap<
+ pub type TokenData<T: Config> = StorageNMap<
Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),
Value = ItemData,
QueryKind = ValueQuery,
>;
#[pallet::storage]
- pub(super) type TotalSupply<T: Config> = StorageNMap<
+ pub type TotalSupply<T: Config> = StorageNMap<
Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),
Value = u128,
QueryKind = ValueQuery,
@@ -80,7 +80,7 @@
/// Used to enumerate tokens owned by account
#[pallet::storage]
- pub(super) type Owned<T: Config> = StorageNMap<
+ pub type Owned<T: Config> = StorageNMap<
Key = (
Key<Twox64Concat, CollectionId>,
Key<Blake2_128Concat, T::CrossAccountId>,
@@ -91,7 +91,7 @@
>;
#[pallet::storage]
- pub(super) type AccountBalance<T: Config> = StorageNMap<
+ pub type AccountBalance<T: Config> = StorageNMap<
Key = (
Key<Twox64Concat, CollectionId>,
// Owner
@@ -102,7 +102,7 @@
>;
#[pallet::storage]
- pub(super) type Balance<T: Config> = StorageNMap<
+ pub type Balance<T: Config> = StorageNMap<
Key = (
Key<Twox64Concat, CollectionId>,
Key<Twox64Concat, TokenId>,
@@ -114,7 +114,7 @@
>;
#[pallet::storage]
- pub(super) type Allowance<T: Config> = StorageNMap<
+ pub type Allowance<T: Config> = StorageNMap<
Key = (
Key<Twox64Concat, CollectionId>,
Key<Twox64Concat, TokenId>,