Skip to content

Commit 1573c49

Browse files
authored
feat: nonfungibles testnet (#588)
* feat(testnet): nonfungibles * fmt * fmt * revert: remove dao contract
1 parent 6de3909 commit 1573c49

File tree

7 files changed

+245
-54
lines changed

7 files changed

+245
-54
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pop-api/integration-tests/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ use utils::*;
1818

1919
mod fungibles;
2020
#[cfg(feature = "testnet")]
21-
mod messaging;
22-
#[cfg(feature = "devnet")]
23-
mod nonfungibles;
21+
pub mod messaging;
22+
pub mod nonfungibles;
2423
mod utils;
2524

2625
type Balance = u128;

runtime/testnet/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ pallet-message-queue.workspace = true
4949
pallet-migrations.workspace = true
5050
pallet-multisig.workspace = true
5151
pallet-nft-fractionalization.workspace = true
52+
pallet-nfts.workspace = true
5253
pallet-nfts-runtime-api.workspace = true
53-
pallet-nfts-sdk.workspace = true
5454
pallet-preimage.workspace = true
5555
pallet-proxy.workspace = true
5656
pallet-revive.workspace = true
@@ -154,7 +154,7 @@ std = [
154154
"pallet-multisig/std",
155155
"pallet-nft-fractionalization/std",
156156
"pallet-nfts-runtime-api/std",
157-
"pallet-nfts-sdk/std",
157+
"pallet-nfts/std",
158158
"pallet-preimage/std",
159159
"pallet-proxy/std",
160160
"pallet-revive/std",
@@ -217,7 +217,7 @@ runtime-benchmarks = [
217217
"pallet-motion/runtime-benchmarks",
218218
"pallet-multisig/runtime-benchmarks",
219219
"pallet-nft-fractionalization/runtime-benchmarks",
220-
"pallet-nfts-sdk/runtime-benchmarks",
220+
"pallet-nfts/runtime-benchmarks",
221221
"pallet-preimage/runtime-benchmarks",
222222
"pallet-proxy/runtime-benchmarks",
223223
"pallet-revive/runtime-benchmarks",
@@ -263,7 +263,7 @@ try-runtime = [
263263
"pallet-motion/try-runtime",
264264
"pallet-multisig/try-runtime",
265265
"pallet-nft-fractionalization/try-runtime",
266-
"pallet-nfts-sdk/try-runtime",
266+
"pallet-nfts/try-runtime",
267267
"pallet-preimage/try-runtime",
268268
"pallet-proxy/try-runtime",
269269
"pallet-revive/try-runtime",

runtime/testnet/src/config/api/mod.rs

Lines changed: 149 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ use xcm::prelude::Location;
1818

1919
use crate::{
2020
config::{
21-
assets::TrustBackedAssetsInstance, monetary::TransactionByteFee, xcm::LocalOriginToLocation,
21+
assets::{TrustBackedAssetsInstance, TrustBackedNftsInstance},
22+
monetary::TransactionByteFee,
23+
xcm::LocalOriginToLocation,
2224
},
23-
fungibles, AccountId, Balances, BlockNumber, Contracts, Ismp, PolkadotXcm, Runtime,
24-
RuntimeCall, RuntimeHoldReason,
25+
fungibles, nonfungibles, AccountId, Balances, BlockNumber, Contracts, Ismp, PolkadotXcm,
26+
Runtime, RuntimeCall, RuntimeHoldReason,
2527
};
2628

2729
mod versioning;
@@ -42,6 +44,9 @@ pub enum RuntimeRead {
4244
/// Fungible token queries.
4345
#[codec(index = 150)]
4446
Fungibles(fungibles::Read<Runtime>),
47+
/// Non-fungible token queries.
48+
#[codec(index = 151)]
49+
NonFungibles(nonfungibles::Read<Runtime>),
4550
/// Messaging state queries.
4651
#[codec(index = 152)]
4752
Messaging(messaging::Read<Runtime>),
@@ -57,6 +62,7 @@ impl Readable for RuntimeRead {
5762
match self {
5863
RuntimeRead::Fungibles(key) => fungibles::Pallet::weight(key),
5964
RuntimeRead::Messaging(key) => messaging::Pallet::weight(key),
65+
RuntimeRead::NonFungibles(key) => nonfungibles::Pallet::weight(key),
6066
}
6167
}
6268

@@ -65,6 +71,8 @@ impl Readable for RuntimeRead {
6571
match self {
6672
RuntimeRead::Fungibles(key) => RuntimeResult::Fungibles(fungibles::Pallet::read(key)),
6773
RuntimeRead::Messaging(key) => RuntimeResult::Messaging(messaging::Pallet::read(key)),
74+
RuntimeRead::NonFungibles(key) =>
75+
RuntimeResult::NonFungibles(nonfungibles::Pallet::read(key)),
6876
}
6977
}
7078
}
@@ -77,6 +85,8 @@ pub enum RuntimeResult {
7785
Fungibles(fungibles::ReadResult<Runtime>),
7886
/// Messaging state read results.
7987
Messaging(messaging::ReadResult),
88+
/// Non-fungible token read results.
89+
NonFungibles(nonfungibles::ReadResult<Runtime>),
8090
}
8191

8292
impl RuntimeResult {
@@ -85,6 +95,7 @@ impl RuntimeResult {
8595
match self {
8696
RuntimeResult::Fungibles(result) => result.encode(),
8797
RuntimeResult::Messaging(result) => result.encode(),
98+
RuntimeResult::NonFungibles(result) => result.encode(),
8899
}
89100
}
90101
}
@@ -99,7 +110,7 @@ impl messaging::Config for Runtime {
99110
type IsmpDispatcher = Ismp;
100111
type MaxContextLen = ConstU32<64>;
101112
type MaxDataLen = ConstU32<1024>;
102-
type MaxKeyLen = ConstU32<32>;
113+
type MaxKeyLen = ConstU32<1000>;
103114
type MaxKeys = ConstU32<10>;
104115
// TODO: size appropriately
105116
type MaxRemovals = ConstU32<1024>;
@@ -193,6 +204,11 @@ impl fungibles::Config for Runtime {
193204
type WeightInfo = fungibles::weights::SubstrateWeight<Runtime>;
194205
}
195206

207+
impl nonfungibles::Config for Runtime {
208+
type NftsInstance = TrustBackedNftsInstance;
209+
type WeightInfo = ();
210+
}
211+
196212
#[derive(Default)]
197213
pub struct Config;
198214
impl pallet_api::extension::Config for Config {
@@ -276,7 +292,28 @@ impl<T: frame_system::Config<RuntimeCall = RuntimeCall>> Contains<RuntimeCall> f
276292
)
277293
};
278294

279-
T::BaseCallFilter::contains(c) && contain_fungibles | contain_messaging
295+
let contain_nonfungibles: bool =
296+
{
297+
use nonfungibles::Call::*;
298+
matches!(
299+
c,
300+
RuntimeCall::NonFungibles(
301+
approve { .. } |
302+
transfer { .. } | create { .. } |
303+
destroy { .. } | set_metadata { .. } |
304+
clear_metadata { .. } | set_attribute { .. } |
305+
clear_attribute { .. } |
306+
set_max_supply { .. } | approve_item_attributes { .. } |
307+
cancel_item_attributes_approval { .. } |
308+
clear_all_transfer_approvals { .. } |
309+
clear_collection_approvals { .. } |
310+
mint { .. } | burn { .. },
311+
)
312+
)
313+
};
314+
315+
T::BaseCallFilter::contains(c) &&
316+
(contain_fungibles | contain_messaging | contain_nonfungibles)
280317
}
281318
}
282319

@@ -300,16 +337,30 @@ impl<T: frame_system::Config> Contains<RuntimeRead> for Filter<T> {
300337
matches!(r, RuntimeRead::Messaging(Poll(..) | Get(..) | QueryId(..)))
301338
};
302339

303-
contain_fungibles | contain_messaging
340+
let contain_nonfungibles: bool = {
341+
use nonfungibles::Read::*;
342+
matches!(
343+
r,
344+
RuntimeRead::NonFungibles(
345+
BalanceOf { .. } |
346+
OwnerOf { .. } | Allowance { .. } |
347+
TotalSupply(..) | GetAttribute { .. } |
348+
ItemMetadata { .. } |
349+
NextCollectionId,
350+
)
351+
)
352+
};
353+
354+
contain_fungibles | contain_messaging | contain_nonfungibles
304355
}
305356
}
306357

307358
#[cfg(test)]
308359
mod tests {
309360
use codec::Encode;
310361
use pallet_api::fungibles::Call::*;
311-
use sp_core::crypto::AccountId32;
312-
use RuntimeCall::{Balances, Fungibles};
362+
use sp_core::{bounded_vec, crypto::AccountId32};
363+
use RuntimeCall::{Balances, Fungibles, NonFungibles};
313364

314365
use super::*;
315366

@@ -384,4 +435,94 @@ mod tests {
384435
assert!(Filter::<Runtime>::contains(&read))
385436
}
386437
}
438+
#[test]
439+
fn filter_allows_nonfungibles_calls() {
440+
use pallet_api::nonfungibles::{
441+
Call::*, CancelAttributesApprovalWitness, CollectionConfig, CollectionSettings,
442+
DestroyWitness, MintSettings,
443+
};
444+
445+
for call in vec![
446+
NonFungibles(approve {
447+
collection: 0,
448+
item: Some(0),
449+
operator: ACCOUNT,
450+
approved: false,
451+
deadline: None,
452+
}),
453+
NonFungibles(transfer { collection: 0, item: 0, to: ACCOUNT }),
454+
NonFungibles(create {
455+
admin: ACCOUNT,
456+
config: CollectionConfig {
457+
max_supply: Some(0),
458+
mint_settings: MintSettings::default(),
459+
settings: CollectionSettings::all_enabled(),
460+
},
461+
}),
462+
NonFungibles(destroy {
463+
collection: 0,
464+
witness: DestroyWitness { attributes: 0, item_configs: 0, item_metadatas: 0 },
465+
}),
466+
NonFungibles(set_attribute {
467+
collection: 0,
468+
item: Some(0),
469+
namespace: pallet_nfts::AttributeNamespace::Pallet,
470+
key: bounded_vec![],
471+
value: bounded_vec![],
472+
}),
473+
NonFungibles(clear_attribute {
474+
collection: 0,
475+
item: Some(0),
476+
namespace: pallet_nfts::AttributeNamespace::Pallet,
477+
key: bounded_vec![],
478+
}),
479+
NonFungibles(set_metadata { collection: 0, item: 0, data: bounded_vec![] }),
480+
NonFungibles(clear_metadata { collection: 0, item: 0 }),
481+
NonFungibles(set_max_supply { collection: 0, max_supply: 0 }),
482+
NonFungibles(approve_item_attributes { collection: 0, item: 0, delegate: ACCOUNT }),
483+
NonFungibles(cancel_item_attributes_approval {
484+
collection: 0,
485+
item: 0,
486+
delegate: ACCOUNT,
487+
witness: CancelAttributesApprovalWitness { account_attributes: 0 },
488+
}),
489+
NonFungibles(clear_all_transfer_approvals { collection: 0, item: 0 }),
490+
NonFungibles(clear_collection_approvals { collection: 0, limit: 0 }),
491+
NonFungibles(mint { to: ACCOUNT, collection: 0, item: 0, witness: None }),
492+
NonFungibles(burn { collection: 0, item: 0 }),
493+
]
494+
.iter()
495+
{
496+
assert!(Filter::<Runtime>::contains(call))
497+
}
498+
}
499+
500+
#[test]
501+
fn filter_allows_nonfungibles_reads() {
502+
use super::{nonfungibles::Read::*, RuntimeRead::*};
503+
504+
for read in vec![
505+
NonFungibles(BalanceOf { collection: 1, owner: ACCOUNT }),
506+
NonFungibles(OwnerOf { collection: 1, item: 1 }),
507+
NonFungibles(Allowance {
508+
collection: 1,
509+
owner: ACCOUNT,
510+
operator: ACCOUNT,
511+
item: None,
512+
}),
513+
NonFungibles(TotalSupply(1)),
514+
NonFungibles(GetAttribute {
515+
collection: 1,
516+
item: Some(1),
517+
namespace: pallet_nfts::AttributeNamespace::CollectionOwner,
518+
key: bounded_vec![],
519+
}),
520+
NonFungibles(NextCollectionId),
521+
NonFungibles(ItemMetadata { collection: 1, item: 1 }),
522+
]
523+
.iter()
524+
{
525+
assert!(Filter::<Runtime>::contains(read))
526+
}
527+
}
387528
}

0 commit comments

Comments
 (0)