Skip to content

Commit

Permalink
fix: rebase & update integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chungquantin committed Nov 18, 2024
1 parent 325e8d3 commit e303439
Show file tree
Hide file tree
Showing 8 changed files with 335 additions and 139 deletions.
38 changes: 8 additions & 30 deletions pallets/api/src/nonfungibles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,17 @@ pub use pallet_nfts::{
CollectionSetting, CollectionSettings, DestroyWitness, ItemDeposit, ItemDetails, ItemMetadata,
ItemSetting, MintSettings, MintType, MintWitness,
};
use sp_runtime::traits::StaticLookup;
use sp_runtime::{traits::StaticLookup, BoundedVec};
use types::*;
use weights::WeightInfo;

#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;
#[cfg(test)]
mod tests;
pub mod types;
pub mod weights;

type AccountIdOf<T> = <T as frame_system::Config>::AccountId;
type NftsOf<T> = pallet_nfts::Pallet<T, NftsInstanceOf<T>>;
type NftsErrorOf<T> = pallet_nfts::Error<T, NftsInstanceOf<T>>;
type NftsWeightInfoOf<T> = <T as pallet_nfts::Config<NftsInstanceOf<T>>>::WeightInfo;
type NftsInstanceOf<T> = <T as Config>::NftsInstance;
type BalanceOf<T> = <<T as pallet_nfts::Config<NftsInstanceOf<T>>>::Currency as Currency<
<T as frame_system::Config>::AccountId,
>>::Balance;
type CollectionIdOf<T> =
<NftsOf<T> as Inspect<<T as frame_system::Config>::AccountId>>::CollectionId;
type ItemIdOf<T> = <NftsOf<T> as Inspect<<T as frame_system::Config>::AccountId>>::ItemId;
type ItemPriceOf<T> = BalanceOf<T>;
type CollectionDetailsFor<T> = CollectionDetails<AccountIdOf<T>, BalanceOf<T>>;
type AttributeNamespaceOf<T> = AttributeNamespace<AccountIdOf<T>>;
type CollectionConfigFor<T> =
CollectionConfig<ItemPriceOf<T>, BlockNumberFor<T>, CollectionIdOf<T>>;
// Type aliases for pallet-nfts storage items.
pub(super) type AccountBalanceOf<T> = pallet_nfts::AccountBalance<T, NftsInstanceOf<T>>;
pub(super) type AttributeOf<T> = pallet_nfts::Attribute<T, NftsInstanceOf<T>>;
pub(super) type NextCollectionIdOf<T> = pallet_nfts::NextCollectionId<T, NftsInstanceOf<T>>;
pub(super) type CollectionOf<T> = pallet_nfts::Collection<T, NftsInstanceOf<T>>;

#[frame_support::pallet]
pub mod pallet {
use frame_support::{
Expand All @@ -50,8 +30,6 @@ pub mod pallet {
traits::Incrementable,
};
use frame_system::pallet_prelude::*;
use pallet_nfts::{CancelAttributesApprovalWitness, DestroyWitness, MintWitness};
use sp_runtime::BoundedVec;
use sp_std::vec::Vec;

use super::*;
Expand Down Expand Up @@ -104,7 +82,7 @@ pub mod pallet {
/// The namespace of the attribute.
namespace: AttributeNamespaceOf<T>,
/// The key of the attribute.
key: BoundedVec<u8, T::KeyLimit>,
key: AttributeKey<T>,
},
/// Details of a specified collection.
#[codec(index = 9)]
Expand Down Expand Up @@ -354,8 +332,8 @@ pub mod pallet {
collection: CollectionIdOf<T>,
item: Option<ItemIdOf<T>>,
namespace: AttributeNamespaceOf<T>,
key: BoundedVec<u8, T::KeyLimit>,
value: BoundedVec<u8, T::ValueLimit>,
key: AttributeKey<T>,
value: AttributeValue<T>,
) -> DispatchResult {
NftsOf::<T>::set_attribute(origin, collection, item, namespace, key, value)
}
Expand All @@ -374,7 +352,7 @@ pub mod pallet {
collection: CollectionIdOf<T>,
item: Option<ItemIdOf<T>>,
namespace: AttributeNamespaceOf<T>,
key: BoundedVec<u8, T::KeyLimit>,
key: AttributeKey<T>,
) -> DispatchResult {
NftsOf::<T>::clear_attribute(origin, collection, item, namespace, key)
}
Expand All @@ -391,7 +369,7 @@ pub mod pallet {
origin: OriginFor<T>,
collection: CollectionIdOf<T>,
item: ItemIdOf<T>,
data: BoundedVec<u8, T::StringLimit>,
data: MetadataData<T>,
) -> DispatchResult {
NftsOf::<T>::set_metadata(origin, collection, item, data)
}
Expand Down
31 changes: 31 additions & 0 deletions pallets/api/src/nonfungibles/types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use super::*;

pub(super) type AccountIdOf<T> = <T as frame_system::Config>::AccountId;
pub(super) type NftsOf<T> = pallet_nfts::Pallet<T, NftsInstanceOf<T>>;
pub(super) type NftsErrorOf<T> = pallet_nfts::Error<T, NftsInstanceOf<T>>;
pub(super) type NftsWeightInfoOf<T> = <T as pallet_nfts::Config<NftsInstanceOf<T>>>::WeightInfo;
pub(super) type NftsInstanceOf<T> = <T as Config>::NftsInstance;
pub(super) type BalanceOf<T> =
<<T as pallet_nfts::Config<NftsInstanceOf<T>>>::Currency as Currency<
<T as frame_system::Config>::AccountId,
>>::Balance;
pub(super) type CollectionIdOf<T> =
<NftsOf<T> as Inspect<<T as frame_system::Config>::AccountId>>::CollectionId;
pub(super) type ItemIdOf<T> =
<NftsOf<T> as Inspect<<T as frame_system::Config>::AccountId>>::ItemId;
pub(super) type ItemPriceOf<T> = BalanceOf<T>;
pub(super) type CollectionDetailsFor<T> = CollectionDetails<AccountIdOf<T>, BalanceOf<T>>;
pub(super) type AttributeNamespaceOf<T> = AttributeNamespace<AccountIdOf<T>>;
pub(super) type CollectionConfigFor<T> =
CollectionConfig<ItemPriceOf<T>, BlockNumberFor<T>, CollectionIdOf<T>>;
// Public due to pop-api integration tests crate.
pub type AccountBalanceOf<T> = pallet_nfts::AccountBalance<T, NftsInstanceOf<T>>;
pub type AttributeOf<T> = pallet_nfts::Attribute<T, NftsInstanceOf<T>>;
pub type AttributeKey<T> = BoundedVec<u8, <T as pallet_nfts::Config<NftsInstanceOf<T>>>::KeyLimit>;
pub type AttributeValue<T> =
BoundedVec<u8, <T as pallet_nfts::Config<NftsInstanceOf<T>>>::ValueLimit>;
pub type CollectionOf<T> = pallet_nfts::Collection<T, NftsInstanceOf<T>>;
pub type CollectionConfigOf<T> = pallet_nfts::CollectionConfigOf<T, NftsInstanceOf<T>>;
pub type NextCollectionIdOf<T> = pallet_nfts::NextCollectionId<T, NftsInstanceOf<T>>;
pub type MetadataData<T> =
BoundedVec<u8, <T as pallet_nfts::Config<NftsInstanceOf<T>>>::StringLimit>;
2 changes: 2 additions & 0 deletions pop-api/integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ frame-support = { version = "36.0.0", default-features = false }
frame-support-procedural = { version = "=30.0.1", default-features = false }
frame-system = { version = "36.1.0", default-features = false }
log = "0.4.22"
pallet-api = { path = "../../pallets/api", default-features = false }
pallet-assets = { version = "37.0.0", default-features = false }
pallet-balances = { version = "37.0.0", default-features = false }
pallet-contracts = { version = "35.0.0", default-features = false }
Expand All @@ -38,6 +39,7 @@ devnet = [ ]
std = [
"frame-support/std",
"frame-system/std",
"pallet-api/std",
"pallet-assets/std",
"pallet-balances/std",
"pallet-contracts/std",
Expand Down
4 changes: 2 additions & 2 deletions pop-api/integration-tests/contracts/nonfungibles/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ mod nonfungibles {
pub fn allowance(
&self,
collection: CollectionId,
item: Option<ItemId>,
owner: AccountId,
operator: AccountId,
item: Option<ItemId>,
) -> Result<bool> {
api::allowance(collection, owner, operator, item)
api::allowance(collection, item, owner, operator)
}

#[ink(message)]
Expand Down
Loading

0 comments on commit e303439

Please sign in to comment.