Skip to content

Commit

Permalink
feat(sub0): nonfungibles pop-api + pallet implementation (#353)
Browse files Browse the repository at this point in the history
Co-authored-by: Daanvdplas <[email protected]>
  • Loading branch information
chungquantin and Daanvdplas authored Nov 1, 2024
1 parent 11977d1 commit 3fa6003
Show file tree
Hide file tree
Showing 38 changed files with 3,989 additions and 481 deletions.
54 changes: 33 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions pallets/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ frame-benchmarking.workspace = true
frame-support.workspace = true
frame-system.workspace = true
pallet-assets.workspace = true
pallet-nfts.workspace = true
sp-core.workspace = true
sp-runtime.workspace = true
sp-std.workspace = true
Expand All @@ -43,6 +44,7 @@ runtime-benchmarks = [
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"pallet-assets/runtime-benchmarks",
"pallet-nfts/runtime-benchmarks",
"pop-chain-extension/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
Expand All @@ -55,6 +57,7 @@ std = [
"pallet-assets/std",
"pallet-balances/std",
"pallet-ismp/std",
"pallet-nfts/std",
"pop-chain-extension/std",
"scale-info/std",
"sp-core/std",
Expand All @@ -65,5 +68,6 @@ std = [
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"pallet-nfts/try-runtime",
"sp-runtime/try-runtime",
]
1 change: 1 addition & 0 deletions pallets/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub mod fungibles;
pub mod messaging;
#[cfg(test)]
mod mock;
pub mod nonfungibles;

/// Trait for performing reads of runtime state.
pub trait Read {
Expand Down
71 changes: 68 additions & 3 deletions pallets/api/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use codec::{Decode, Encode};
use frame_support::{
derive_impl, parameter_types,
traits::{AsEnsureOriginWithArg, ConstU128, ConstU32, Everything},
traits::{AsEnsureOriginWithArg, ConstU128, ConstU32, ConstU64, Everything},
};
use frame_system::{EnsureRoot, EnsureSigned};
use pallet_nfts::PalletFeatures;
use scale_info::TypeInfo;
use sp_core::H256;
use sp_runtime::{
traits::{BlakeTwo256, IdentityLookup},
traits::{BlakeTwo256, IdentifyAccount, IdentityLookup, Lazy, Verify},
BuildStorage,
};

Expand All @@ -29,6 +32,8 @@ frame_support::construct_runtime!(
Assets: pallet_assets::<Instance1>,
Balances: pallet_balances,
Fungibles: crate::fungibles,
Nfts: pallet_nfts,
NonFungibles: crate::nonfungibles
}
);

Expand Down Expand Up @@ -91,7 +96,7 @@ impl pallet_assets::Config<AssetsInstance> for Test {
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
type CallbackHandle = ();
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<u64>>;
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<Self::AccountId>>;
type Currency = Balances;
type Extra = ();
type ForceOrigin = EnsureRoot<u64>;
Expand All @@ -110,6 +115,66 @@ impl crate::fungibles::Config for Test {
type WeightInfo = ();
}

parameter_types! {
pub storage Features: PalletFeatures = PalletFeatures::all_enabled();
}

#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode, TypeInfo)]
pub struct Noop;

impl IdentifyAccount for Noop {
type AccountId = AccountId;

fn into_account(self) -> Self::AccountId {
0
}
}

impl Verify for Noop {
type Signer = Noop;

fn verify<L: Lazy<[u8]>>(
&self,
_msg: L,
_signer: &<Self::Signer as IdentifyAccount>::AccountId,
) -> bool {
false
}
}

impl pallet_nfts::Config for Test {
type ApprovalsLimit = ConstU32<10>;
type AttributeDepositBase = ConstU128<1>;
type CollectionDeposit = ConstU128<2>;
type CollectionId = u32;
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<u64>>;
type Currency = Balances;
type DepositPerByte = ConstU128<1>;
type Features = Features;
type ForceOrigin = frame_system::EnsureRoot<Self::AccountId>;
#[cfg(feature = "runtime-benchmarks")]
type Helper = ();
type ItemAttributesApprovalsLimit = ConstU32<2>;
type ItemDeposit = ConstU128<1>;
type ItemId = u32;
type KeyLimit = ConstU32<50>;
type Locker = ();
type MaxAttributesPerCall = ConstU32<2>;
type MaxDeadlineDuration = ConstU64<10000>;
type MaxTips = ConstU32<10>;
type MetadataDepositBase = ConstU128<1>;
type OffchainPublic = Noop;
type OffchainSignature = Noop;
type RuntimeEvent = RuntimeEvent;
type StringLimit = ConstU32<50>;
type ValueLimit = ConstU32<50>;
type WeightInfo = ();
}

impl crate::nonfungibles::Config for Test {
type RuntimeEvent = RuntimeEvent;
}

pub(crate) fn new_test_ext() -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::<Test>::default()
.build_storage()
Expand Down
Loading

0 comments on commit 3fa6003

Please sign in to comment.