Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add pallet-api/nonfungibles #432

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
0ae0d7b
chore: rebase
chungquantin Jan 22, 2025
b585741
chore: rebase nonfungibles pallet to pallet-nfts
chungquantin Jan 16, 2025
5a272f9
chore: update nonfungibles tests
chungquantin Jan 16, 2025
2fccbcb
refactor: do_approve and do_cancel_approval
chungquantin Jan 16, 2025
3571709
chore: naming
chungquantin Jan 16, 2025
6777440
chore: resolve review comments
chungquantin Jan 20, 2025
9cf8502
chore: resolve review comments & update weights
chungquantin Jan 20, 2025
9f17d66
chore: add tests for nonfungibles api in runtime devnet
chungquantin Jan 20, 2025
010b9cf
fix: integration test & return post dispatch weight for transfer() on…
chungquantin Jan 21, 2025
c185d36
refactor: reorder `Read` impl in nonfungibles
chungquantin Jan 21, 2025
665feea
chore: remove unnecessary clone()
chungquantin Jan 21, 2025
f65dc98
chore: remove description for pallet configure
chungquantin Jan 21, 2025
15df8b3
refactor: approve() tests
chungquantin Jan 21, 2025
0396644
chore: resolve review comments
chungquantin Jan 21, 2025
ea59ba3
feat: add AttributeSet event
chungquantin Jan 21, 2025
728c1df
chore: comments and add test for Collection read
chungquantin Jan 22, 2025
bec6b25
chore: revert changes made to pallet nfts
chungquantin Jan 22, 2025
6a8adaa
chore: fix comment
chungquantin Jan 22, 2025
f70e005
chore: resolve review comments
chungquantin Jan 24, 2025
4bfbafe
chore: update function order
chungquantin Jan 24, 2025
ac68a1f
chore: add release conventions document and refactor CI to run node r…
Daanvdplas Jan 22, 2025
a8b2e7e
refactor: reuse `WeightInfo` in nonfungibles pallet test (#450)
chungquantin Jan 24, 2025
bbf5915
chore: update collection details field to public (#449)
chungquantin Jan 24, 2025
9604472
chore: rebase and remove local collection details type
chungquantin Jan 24, 2025
924e520
chore: remove impls.rs and update burn()
chungquantin Jan 24, 2025
5316da1
Merge branch 'main' into chungquantin/feat-main_pallet_nonfungibles
chungquantin Jan 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 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-runtime.workspace = true
sp-std.workspace = true

Expand All @@ -37,6 +38,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 @@ -48,6 +50,7 @@ std = [
"log/std",
"pallet-assets/std",
"pallet-balances/std",
"pallet-nfts/std",
"pop-chain-extension/std",
"scale-info/std",
"sp-core/std",
Expand All @@ -58,5 +61,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
@@ -1,12 +1,13 @@
#![cfg_attr(not(feature = "std"), no_std)]

pub use extension::Extension;
use frame_support::pallet_prelude::Weight;

pub mod extension;

Check warning on line 6 in pallets/api/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a module

warning: missing documentation for a module --> pallets/api/src/lib.rs:6:1 | 6 | pub mod extension; | ^^^^^^^^^^^^^^^^^
pub mod fungibles;
#[cfg(test)]
mod mock;
pub mod nonfungibles;
chungquantin marked this conversation as resolved.
Show resolved Hide resolved

/// Trait for performing reads of runtime state.
pub trait Read {
Expand Down
98 changes: 94 additions & 4 deletions pallets/api/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
use codec::{Decode, Encode};
use frame_support::{
derive_impl, parameter_types,
traits::{AsEnsureOriginWithArg, ConstU128, ConstU32, Everything},
traits::{AsEnsureOriginWithArg, ConstU128, ConstU32, ConstU64, Everything},
weights::constants::RocksDbWeight,
};
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 +33,8 @@ frame_support::construct_runtime!(
Assets: pallet_assets::<Instance1>,
Balances: pallet_balances,
Fungibles: crate::fungibles,
Nfts: pallet_nfts::<Instance1>,
NonFungibles: crate::nonfungibles
}
);

Expand All @@ -46,7 +52,7 @@ impl frame_system::Config for Test {
type BlockHashCount = BlockHashCount;
type BlockLength = ();
type BlockWeights = ();
type DbWeight = ();
type DbWeight = RocksDbWeight;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requires for testing with <Test as frame_system::Config>::DbWeight::get()::reads(1)

type Hash = H256;
type Hashing = BlakeTwo256;
type Lookup = IdentityLookup<Self::AccountId>;
Expand Down Expand Up @@ -92,7 +98,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 @@ -111,6 +117,90 @@ 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
}
}

#[cfg(feature = "runtime-benchmarks")]
impl pallet_nfts::pallet::BenchmarkHelper<u32, u32, Noop, u64, Noop> for () {
chungquantin marked this conversation as resolved.
Show resolved Hide resolved
fn collection(i: u16) -> u32 {
i.into()
}

fn item(i: u16) -> u32 {
i.into()
}

fn signer() -> (Noop, u64) {
unimplemented!()
}

fn sign(_signer: &Noop, _message: &[u8]) -> Noop {
unimplemented!()
}
}

type NftsInstance = pallet_nfts::Instance1;
impl pallet_nfts::Config<NftsInstance> for Test {
type ApprovalsLimit = ConstU32<10>;
type AttributeDepositBase = ConstU128<1>;
type CollectionApprovalDeposit = ConstU128<1>;
type CollectionBalanceDeposit = 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 NftsInstance = NftsInstance;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
}

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