difftreelog
test remove ChainLimits leftovers
in: master
8 files changed
pallets/nft/Cargo.tomldiffbeforeafterboth--- a/pallets/nft/Cargo.toml
+++ b/pallets/nft/Cargo.toml
@@ -41,6 +41,7 @@
'evm-coder/std',
'pallet-evm-coder-substrate/std',
]
+limit-testing = ["nft-data-structs/limit-testing"]
################################################################################
# Substrate Dependencies
pallets/nft/src/default_weights.rsdiffbeforeafterboth--- a/pallets/nft/src/default_weights.rs
+++ b/pallets/nft/src/default_weights.rs
@@ -117,11 +117,6 @@
.saturating_add(DbWeight::get().reads(2_u64))
.saturating_add(DbWeight::get().writes(1_u64))
}
- fn set_chain_limits() -> Weight {
- 1_300_000_u64
- .saturating_add(DbWeight::get().reads(0_u64))
- .saturating_add(DbWeight::get().writes(1_u64))
- }
fn set_contract_sponsoring_rate_limit() -> Weight {
3_500_000_u64
.saturating_add(DbWeight::get().reads(0_u64))
pallets/nft/src/lib.rsdiffbeforeafterboth--- a/pallets/nft/src/lib.rs
+++ b/pallets/nft/src/lib.rs
@@ -88,7 +88,6 @@
fn set_variable_meta_data() -> Weight;
fn enable_contract_sponsoring() -> Weight;
fn set_schema_version() -> Weight;
- fn set_chain_limits() -> Weight;
fn set_contract_sponsoring_rate_limit() -> Weight;
fn set_variable_meta_data_sponsoring_rate_limit() -> Weight;
fn toggle_contract_white_list() -> Weight;
@@ -1596,38 +1595,17 @@
) -> DispatchResult {
match target_collection.mode {
CollectionMode::NFT => {
- if let CreateItemData::NFT(data) = data {
- // check sizes
- ensure!(
- CUSTOM_DATA_LIMIT >= data.const_data.len() as u32,
- Error::<T>::TokenConstDataLimitExceeded
- );
- ensure!(
- CUSTOM_DATA_LIMIT >= data.variable_data.len() as u32,
- Error::<T>::TokenVariableDataLimitExceeded
- );
- } else {
+ if !matches!(data, CreateItemData::NFT(_)) {
fail!(Error::<T>::NotNftDataUsedToMintNftCollectionToken);
}
}
CollectionMode::Fungible(_) => {
- if let CreateItemData::Fungible(_) = data {
- } else {
+ if !matches!(data, CreateItemData::Fungible(_)) {
fail!(Error::<T>::NotFungibleDataUsedToMintFungibleCollectionToken);
}
}
CollectionMode::ReFungible => {
if let CreateItemData::ReFungible(data) = data {
- // check sizes
- ensure!(
- CUSTOM_DATA_LIMIT >= data.const_data.len() as u32,
- Error::<T>::TokenConstDataLimitExceeded
- );
- ensure!(
- CUSTOM_DATA_LIMIT >= data.variable_data.len() as u32,
- Error::<T>::TokenVariableDataLimitExceeded
- );
-
// Check refungibility limits
ensure!(
data.pieces <= MAX_REFUNGIBLE_PIECES,
pallets/nft/src/tests.rsdiffbeforeafterboth--- a/pallets/nft/src/tests.rs
+++ b/pallets/nft/src/tests.rs
@@ -1,40 +1,18 @@
// Tests to be written here
use super::*;
use crate::mock::*;
-use crate::{AccessMode, CollectionMode, Ownership, ChainLimits, CreateItemData};
+use crate::{AccessMode, CollectionMode, Ownership, CreateItemData};
use nft_data_structs::{
CreateNftData, CreateFungibleData, CreateReFungibleData, CollectionId, TokenId,
MAX_DECIMAL_POINTS,
};
use frame_support::{assert_noop, assert_ok};
-use frame_system::{RawOrigin};
-
-fn default_collection_numbers_limit() -> u32 {
- 10
-}
-
-fn default_limits() {
- assert_ok!(TemplateModule::set_chain_limits(
- RawOrigin::Root.into(),
- ChainLimits {
- collection_numbers_limit: default_collection_numbers_limit(),
- account_token_ownership_limit: 10,
- collections_admins_limit: 5,
- custom_data_limit: 2048,
- nft_sponsor_transfer_timeout: 15,
- fungible_sponsor_transfer_timeout: 15,
- refungible_sponsor_transfer_timeout: 15,
- const_on_chain_schema_limit: 1024,
- offchain_schema_limit: 1024,
- variable_on_chain_schema_limit: 1024,
- }
- ));
-}
+use sp_std::convert::TryInto;
fn default_nft_data() -> CreateNftData {
CreateNftData {
- const_data: vec![1, 2, 3],
- variable_data: vec![3, 2, 1],
+ const_data: vec![1, 2, 3].try_into().unwrap(),
+ variable_data: vec![3, 2, 1].try_into().unwrap(),
}
}
@@ -44,8 +22,8 @@
fn default_re_fungible_data() -> CreateReFungibleData {
CreateReFungibleData {
- const_data: vec![1, 2, 3],
- variable_data: vec![3, 2, 1],
+ const_data: vec![1, 2, 3].try_into().unwrap(),
+ variable_data: vec![3, 2, 1].try_into().unwrap(),
pieces: 1023,
}
}
@@ -112,7 +90,6 @@
#[test]
fn set_version_schema() {
new_test_ext().execute_with(|| {
- default_limits();
let origin1 = Origin::signed(1);
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
@@ -133,8 +110,6 @@
#[test]
fn create_fungible_collection_fails_with_large_decimal_numbers() {
new_test_ext().execute_with(|| {
- default_limits();
-
let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();
let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();
let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();
@@ -156,14 +131,13 @@
#[test]
fn create_nft_item() {
new_test_ext().execute_with(|| {
- default_limits();
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let data = default_nft_data();
create_test_item(collection_id, &data.clone().into());
let item = TemplateModule::nft_item_id(collection_id, 1).unwrap();
- assert_eq!(item.const_data, data.const_data);
- assert_eq!(item.variable_data, data.variable_data);
+ assert_eq!(item.const_data, data.const_data.into_inner());
+ assert_eq!(item.variable_data, data.variable_data.into_inner());
});
}
@@ -172,8 +146,6 @@
#[test]
fn create_nft_multiple_items() {
new_test_ext().execute_with(|| {
- default_limits();
-
create_test_collection(&CollectionMode::NFT, 1);
let origin1 = Origin::signed(1);
@@ -190,10 +162,10 @@
.map(|d| { d.into() })
.collect()
));
- for (index, data) in items_data.iter().enumerate() {
+ for (index, data) in items_data.into_iter().enumerate() {
let item = TemplateModule::nft_item_id(1, (index + 1) as TokenId).unwrap();
- assert_eq!(item.const_data.to_vec(), data.const_data);
- assert_eq!(item.variable_data.to_vec(), data.variable_data);
+ assert_eq!(item.const_data.to_vec(), data.const_data.into_inner());
+ assert_eq!(item.variable_data.to_vec(), data.variable_data.into_inner());
}
});
}
@@ -201,14 +173,13 @@
#[test]
fn create_refungible_item() {
new_test_ext().execute_with(|| {
- default_limits();
let collection_id = create_test_collection(&CollectionMode::ReFungible, 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();
- assert_eq!(item.const_data, data.const_data);
- assert_eq!(item.variable_data, data.variable_data);
+ assert_eq!(item.const_data, data.const_data.into_inner());
+ assert_eq!(item.variable_data, data.variable_data.into_inner());
assert_eq!(
item.owner[0],
Ownership {
@@ -222,8 +193,6 @@
#[test]
fn create_multiple_refungible_items() {
new_test_ext().execute_with(|| {
- default_limits();
-
create_test_collection(&CollectionMode::ReFungible, 1);
let origin1 = Origin::signed(1);
@@ -244,10 +213,10 @@
.map(|d| { d.into() })
.collect()
));
- for (index, data) in items_data.iter().enumerate() {
+ for (index, data) in items_data.into_iter().enumerate() {
let item = TemplateModule::refungible_item_id(1, (index + 1) as TokenId).unwrap();
- assert_eq!(item.const_data.to_vec(), data.const_data);
- assert_eq!(item.variable_data.to_vec(), data.variable_data);
+ 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!(
item.owner[0],
Ownership {
@@ -262,8 +231,6 @@
#[test]
fn create_fungible_item() {
new_test_ext().execute_with(|| {
- default_limits();
-
let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);
let data = default_fungible_data();
@@ -302,8 +269,6 @@
#[test]
fn transfer_fungible_item() {
new_test_ext().execute_with(|| {
- default_limits();
-
let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);
let origin1 = Origin::signed(1);
@@ -344,8 +309,6 @@
#[test]
fn transfer_refungible_item() {
new_test_ext().execute_with(|| {
- default_limits();
-
let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);
let data = default_re_fungible_data();
@@ -355,8 +318,8 @@
let origin2 = Origin::signed(2);
{
let item = TemplateModule::refungible_item_id(collection_id, 1).unwrap();
- assert_eq!(item.const_data, data.const_data);
- assert_eq!(item.variable_data, data.variable_data);
+ assert_eq!(item.const_data, data.const_data.into_inner());
+ assert_eq!(item.variable_data, data.variable_data.into_inner());
assert_eq!(
item.owner[0],
Ownership {
@@ -441,8 +404,6 @@
#[test]
fn transfer_nft_item() {
new_test_ext().execute_with(|| {
- default_limits();
-
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let data = default_nft_data();
@@ -464,8 +425,6 @@
#[test]
fn nft_approve_and_transfer_from() {
new_test_ext().execute_with(|| {
- default_limits();
-
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let data = default_nft_data();
@@ -503,8 +462,6 @@
#[test]
fn nft_approve_and_transfer_from_white_list() {
new_test_ext().execute_with(|| {
- default_limits();
-
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let origin1 = Origin::signed(1);
@@ -514,8 +471,8 @@
create_test_item(collection_id, &data.clone().into());
assert_eq!(
- TemplateModule::nft_item_id(1, 1).unwrap().const_data,
- data.const_data
+ &TemplateModule::nft_item_id(1, 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]);
@@ -573,8 +530,6 @@
#[test]
fn refungible_approve_and_transfer_from() {
new_test_ext().execute_with(|| {
- default_limits();
-
let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);
let origin1 = Origin::signed(1);
@@ -636,8 +591,6 @@
#[test]
fn fungible_approve_and_transfer_from() {
new_test_ext().execute_with(|| {
- default_limits();
-
let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);
let data = default_fungible_data();
@@ -710,8 +663,6 @@
#[test]
fn change_collection_owner() {
new_test_ext().execute_with(|| {
- default_limits();
-
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let origin1 = Origin::signed(1);
@@ -730,8 +681,6 @@
#[test]
fn destroy_collection() {
new_test_ext().execute_with(|| {
- default_limits();
-
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let origin1 = Origin::signed(1);
@@ -742,8 +691,6 @@
#[test]
fn burn_nft_item() {
new_test_ext().execute_with(|| {
- default_limits();
-
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let origin1 = Origin::signed(1);
@@ -773,8 +720,6 @@
#[test]
fn burn_fungible_item() {
new_test_ext().execute_with(|| {
- default_limits();
-
let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);
let origin1 = Origin::signed(1);
@@ -804,8 +749,6 @@
#[test]
fn burn_refungible_item() {
new_test_ext().execute_with(|| {
- default_limits();
-
let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);
let origin1 = Origin::signed(1);
@@ -851,8 +794,6 @@
#[test]
fn add_collection_admin() {
new_test_ext().execute_with(|| {
- default_limits();
-
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);
@@ -879,8 +820,6 @@
#[test]
fn remove_collection_admin() {
new_test_ext().execute_with(|| {
- default_limits();
-
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);
@@ -916,8 +855,6 @@
#[test]
fn balance_of() {
new_test_ext().execute_with(|| {
- default_limits();
-
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);
@@ -969,8 +906,6 @@
#[test]
fn approve() {
new_test_ext().execute_with(|| {
- default_limits();
-
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let data = default_nft_data();
@@ -987,8 +922,6 @@
#[test]
fn transfer_from() {
new_test_ext().execute_with(|| {
- default_limits();
-
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
@@ -1051,8 +984,6 @@
#[test]
fn owner_can_add_address_to_white_list() {
new_test_ext().execute_with(|| {
- default_limits();
-
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let origin1 = Origin::signed(1);
@@ -1068,8 +999,6 @@
#[test]
fn admin_can_add_address_to_white_list() {
new_test_ext().execute_with(|| {
- default_limits();
-
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
@@ -1091,8 +1020,6 @@
#[test]
fn nonprivileged_user_cannot_add_address_to_white_list() {
new_test_ext().execute_with(|| {
- default_limits();
-
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let origin2 = Origin::signed(2);
@@ -1106,8 +1033,6 @@
#[test]
fn nobody_can_add_address_to_white_list_of_nonexisting_collection() {
new_test_ext().execute_with(|| {
- default_limits();
-
let origin1 = Origin::signed(1);
assert_noop!(
@@ -1120,8 +1045,6 @@
#[test]
fn nobody_can_add_address_to_white_list_of_deleted_collection() {
new_test_ext().execute_with(|| {
- default_limits();
-
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let origin1 = Origin::signed(1);
@@ -1140,8 +1063,6 @@
#[test]
fn address_is_already_added_to_white_list() {
new_test_ext().execute_with(|| {
- default_limits();
-
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let origin1 = Origin::signed(1);
@@ -1162,8 +1083,6 @@
#[test]
fn owner_can_remove_address_from_white_list() {
new_test_ext().execute_with(|| {
- default_limits();
-
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let origin1 = Origin::signed(1);
@@ -1184,8 +1103,6 @@
#[test]
fn admin_can_remove_address_from_white_list() {
new_test_ext().execute_with(|| {
- default_limits();
-
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
@@ -1213,8 +1130,6 @@
#[test]
fn nonprivileged_user_cannot_remove_address_from_white_list() {
new_test_ext().execute_with(|| {
- default_limits();
-
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
@@ -1235,7 +1150,6 @@
#[test]
fn nobody_can_remove_address_from_white_list_of_nonexisting_collection() {
new_test_ext().execute_with(|| {
- default_limits();
let origin1 = Origin::signed(1);
assert_noop!(
@@ -1248,8 +1162,6 @@
#[test]
fn nobody_can_remove_address_from_white_list_of_deleted_collection() {
new_test_ext().execute_with(|| {
- default_limits();
-
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let origin1 = Origin::signed(1);
let origin2 = Origin::signed(2);
@@ -1272,8 +1184,6 @@
#[test]
fn address_is_already_removed_from_white_list() {
new_test_ext().execute_with(|| {
- default_limits();
-
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let origin1 = Origin::signed(1);
@@ -1300,8 +1210,6 @@
#[test]
fn white_list_test_1() {
new_test_ext().execute_with(|| {
- default_limits();
-
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let origin1 = Origin::signed(1);
@@ -1330,8 +1238,6 @@
#[test]
fn white_list_test_2() {
new_test_ext().execute_with(|| {
- default_limits();
-
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let origin1 = Origin::signed(1);
@@ -1381,8 +1287,6 @@
#[test]
fn white_list_test_3() {
new_test_ext().execute_with(|| {
- default_limits();
-
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let origin1 = Origin::signed(1);
@@ -1411,8 +1315,6 @@
#[test]
fn white_list_test_4() {
new_test_ext().execute_with(|| {
- default_limits();
-
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let origin1 = Origin::signed(1);
@@ -1463,8 +1365,6 @@
#[test]
fn white_list_test_5() {
new_test_ext().execute_with(|| {
- default_limits();
-
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let origin1 = Origin::signed(1);
@@ -1488,8 +1388,6 @@
#[test]
fn white_list_test_6() {
new_test_ext().execute_with(|| {
- default_limits();
-
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let origin1 = Origin::signed(1);
@@ -1516,8 +1414,6 @@
#[test]
fn white_list_test_7() {
new_test_ext().execute_with(|| {
- default_limits();
-
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let data = default_nft_data();
@@ -1548,8 +1444,6 @@
#[test]
fn white_list_test_8() {
new_test_ext().execute_with(|| {
- default_limits();
-
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let data = default_nft_data();
@@ -1598,8 +1492,6 @@
#[test]
fn white_list_test_9() {
new_test_ext().execute_with(|| {
- default_limits();
-
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let origin1 = Origin::signed(1);
@@ -1623,8 +1515,6 @@
#[test]
fn white_list_test_10() {
new_test_ext().execute_with(|| {
- default_limits();
-
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let origin1 = Origin::signed(1);
@@ -1660,8 +1550,6 @@
#[test]
fn white_list_test_11() {
new_test_ext().execute_with(|| {
- default_limits();
-
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let origin1 = Origin::signed(1);
@@ -1694,8 +1582,6 @@
#[test]
fn white_list_test_12() {
new_test_ext().execute_with(|| {
- default_limits();
-
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let origin1 = Origin::signed(1);
@@ -1723,8 +1609,6 @@
#[test]
fn white_list_test_13() {
new_test_ext().execute_with(|| {
- default_limits();
-
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let origin1 = Origin::signed(1);
@@ -1749,8 +1633,6 @@
#[test]
fn white_list_test_14() {
new_test_ext().execute_with(|| {
- default_limits();
-
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let origin1 = Origin::signed(1);
@@ -1786,8 +1668,6 @@
#[test]
fn white_list_test_15() {
new_test_ext().execute_with(|| {
- default_limits();
-
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let origin1 = Origin::signed(1);
@@ -1815,8 +1695,6 @@
#[test]
fn white_list_test_16() {
new_test_ext().execute_with(|| {
- default_limits();
-
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let origin1 = Origin::signed(1);
@@ -1851,8 +1729,6 @@
#[test]
fn total_number_collections_bound() {
new_test_ext().execute_with(|| {
- default_limits();
-
create_test_collection(&CollectionMode::NFT, 1);
});
}
@@ -1861,11 +1737,9 @@
#[test]
fn total_number_collections_bound_neg() {
new_test_ext().execute_with(|| {
- default_limits();
-
let origin1 = Origin::signed(1);
- for i in 0..default_collection_numbers_limit() {
+ for i in 0..COLLECTION_NUMBER_LIMIT {
create_test_collection(&CollectionMode::NFT, i + 1);
}
@@ -1891,8 +1765,6 @@
#[test]
fn owned_tokens_bound() {
new_test_ext().execute_with(|| {
- default_limits();
-
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let data = default_nft_data();
@@ -1905,28 +1777,16 @@
#[test]
fn owned_tokens_bound_neg() {
new_test_ext().execute_with(|| {
- assert_ok!(TemplateModule::set_chain_limits(
- RawOrigin::Root.into(),
- ChainLimits {
- collection_numbers_limit: 10,
- account_token_ownership_limit: 1,
- collections_admins_limit: 5,
- custom_data_limit: 2048,
- nft_sponsor_transfer_timeout: 15,
- fungible_sponsor_transfer_timeout: 15,
- refungible_sponsor_transfer_timeout: 15,
- const_on_chain_schema_limit: 1024,
- offchain_schema_limit: 1024,
- variable_on_chain_schema_limit: 1024,
- }
- ));
-
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let origin1 = Origin::signed(1);
- let data = default_nft_data();
- create_test_item(collection_id, &data.clone().into());
+ for _ in 0..ACCOUNT_TOKEN_OWNERSHIP_LIMIT {
+ 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>::AddressOwnershipLimitExceeded
@@ -1938,22 +1798,6 @@
#[test]
fn collection_admins_bound() {
new_test_ext().execute_with(|| {
- assert_ok!(TemplateModule::set_chain_limits(
- RawOrigin::Root.into(),
- ChainLimits {
- collection_numbers_limit: 10,
- account_token_ownership_limit: 10,
- collections_admins_limit: 2,
- custom_data_limit: 2048,
- nft_sponsor_transfer_timeout: 15,
- fungible_sponsor_transfer_timeout: 15,
- refungible_sponsor_transfer_timeout: 15,
- const_on_chain_schema_limit: 1024,
- offchain_schema_limit: 1024,
- variable_on_chain_schema_limit: 1024,
- }
- ));
-
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let origin1 = Origin::signed(1);
@@ -1975,174 +1819,20 @@
#[test]
fn collection_admins_bound_neg() {
new_test_ext().execute_with(|| {
- assert_ok!(TemplateModule::set_chain_limits(
- RawOrigin::Root.into(),
- ChainLimits {
- collection_numbers_limit: 10,
- account_token_ownership_limit: 1,
- collections_admins_limit: 1,
- custom_data_limit: 2048,
- nft_sponsor_transfer_timeout: 15,
- fungible_sponsor_transfer_timeout: 15,
- refungible_sponsor_transfer_timeout: 15,
- const_on_chain_schema_limit: 1024,
- offchain_schema_limit: 1024,
- variable_on_chain_schema_limit: 1024,
- }
- ));
-
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let origin1 = Origin::signed(1);
- assert_ok!(TemplateModule::add_collection_admin(
- origin1.clone(),
- collection_id,
- account(2)
- ));
+ for i in 0..COLLECTION_ADMINS_LIMIT {
+ assert_ok!(TemplateModule::add_collection_admin(
+ origin1.clone(),
+ collection_id,
+ account(2 + i)
+ ));
+ }
assert_noop!(
- TemplateModule::add_collection_admin(origin1, collection_id, account(3)),
+ TemplateModule::add_collection_admin(origin1, collection_id, account(3 + COLLECTION_ADMINS_LIMIT)),
Error::<Test>::CollectionAdminsLimitExceeded
- );
- });
-}
-
-// NFT custom data size. Negative test const_data.
-#[test]
-fn custom_data_size_nft_const_data_bound_neg() {
- new_test_ext().execute_with(|| {
- assert_ok!(TemplateModule::set_chain_limits(
- RawOrigin::Root.into(),
- ChainLimits {
- collection_numbers_limit: 10,
- account_token_ownership_limit: 10,
- collections_admins_limit: 5,
- custom_data_limit: 2,
- nft_sponsor_transfer_timeout: 15,
- fungible_sponsor_transfer_timeout: 15,
- refungible_sponsor_transfer_timeout: 15,
- const_on_chain_schema_limit: 1024,
- offchain_schema_limit: 1024,
- variable_on_chain_schema_limit: 1024,
- }
- ));
-
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
-
- let origin1 = Origin::signed(1);
- let too_big_const_data = CreateItemData::NFT(CreateNftData {
- const_data: vec![1, 2, 3, 4],
- variable_data: vec![],
- });
-
- assert_noop!(
- TemplateModule::create_item(origin1, collection_id, account(1), too_big_const_data),
- Error::<Test>::TokenConstDataLimitExceeded
- );
- });
-}
-
-// NFT custom data size. Negative test variable_data.
-#[test]
-fn custom_data_size_nft_variable_data_bound_neg() {
- new_test_ext().execute_with(|| {
- assert_ok!(TemplateModule::set_chain_limits(
- RawOrigin::Root.into(),
- ChainLimits {
- collection_numbers_limit: 10,
- account_token_ownership_limit: 10,
- collections_admins_limit: 5,
- custom_data_limit: 2,
- nft_sponsor_transfer_timeout: 15,
- fungible_sponsor_transfer_timeout: 15,
- refungible_sponsor_transfer_timeout: 15,
- const_on_chain_schema_limit: 1024,
- offchain_schema_limit: 1024,
- variable_on_chain_schema_limit: 1024,
- }
- ));
-
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
-
- let origin1 = Origin::signed(1);
- let too_big_const_data = CreateItemData::NFT(CreateNftData {
- const_data: vec![],
- variable_data: vec![1, 2, 3, 4],
- });
-
- assert_noop!(
- TemplateModule::create_item(origin1, collection_id, account(1), too_big_const_data),
- Error::<Test>::TokenVariableDataLimitExceeded
- );
- });
-}
-
-// Re fungible custom data size. Negative test const_data.
-#[test]
-fn custom_data_size_re_fungible_const_data_bound_neg() {
- new_test_ext().execute_with(|| {
- assert_ok!(TemplateModule::set_chain_limits(
- RawOrigin::Root.into(),
- ChainLimits {
- collection_numbers_limit: 10,
- account_token_ownership_limit: 10,
- collections_admins_limit: 5,
- custom_data_limit: 2,
- nft_sponsor_transfer_timeout: 15,
- fungible_sponsor_transfer_timeout: 15,
- refungible_sponsor_transfer_timeout: 15,
- const_on_chain_schema_limit: 1024,
- offchain_schema_limit: 1024,
- variable_on_chain_schema_limit: 1024,
- }
- ));
-
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
-
- let origin1 = Origin::signed(1);
- let too_big_const_data = CreateItemData::NFT(CreateNftData {
- const_data: vec![1, 2, 3, 4],
- variable_data: vec![],
- });
-
- assert_noop!(
- TemplateModule::create_item(origin1, collection_id, account(1), too_big_const_data),
- Error::<Test>::TokenConstDataLimitExceeded
- );
- });
-}
-
-// Re fungible custom data size. Negative test variable_data.
-#[test]
-fn custom_data_size_re_fungible_variable_data_bound_neg() {
- new_test_ext().execute_with(|| {
- assert_ok!(TemplateModule::set_chain_limits(
- RawOrigin::Root.into(),
- ChainLimits {
- collection_numbers_limit: 10,
- account_token_ownership_limit: 10,
- collections_admins_limit: 5,
- custom_data_limit: 2,
- nft_sponsor_transfer_timeout: 15,
- fungible_sponsor_transfer_timeout: 15,
- refungible_sponsor_transfer_timeout: 15,
- const_on_chain_schema_limit: 1024,
- offchain_schema_limit: 1024,
- variable_on_chain_schema_limit: 1024,
- }
- ));
-
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
-
- let origin1 = Origin::signed(1);
- let too_big_const_data = CreateItemData::NFT(CreateNftData {
- const_data: vec![],
- variable_data: vec![1, 2, 3, 4],
- });
-
- assert_noop!(
- TemplateModule::create_item(origin1, collection_id, account(1), too_big_const_data),
- Error::<Test>::TokenVariableDataLimitExceeded
);
});
}
@@ -2151,8 +1841,6 @@
#[test]
fn set_const_on_chain_schema() {
new_test_ext().execute_with(|| {
- default_limits();
-
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let origin1 = Origin::signed(1);
@@ -2180,8 +1868,6 @@
#[test]
fn set_variable_on_chain_schema() {
new_test_ext().execute_with(|| {
- default_limits();
-
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let origin1 = Origin::signed(1);
@@ -2209,8 +1895,6 @@
#[test]
fn set_variable_meta_data_on_nft_token_stores_variable_meta_data() {
new_test_ext().execute_with(|| {
- default_limits();
-
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let origin1 = Origin::signed(1);
@@ -2218,7 +1902,7 @@
let data = default_nft_data();
create_test_item(1, &data.into());
- let variable_data = b"test set_variable_meta_data method.".to_vec();
+ let variable_data = b"test data".to_vec();
assert_ok!(TemplateModule::set_variable_meta_data(
origin1,
collection_id,
@@ -2238,8 +1922,6 @@
#[test]
fn set_variable_meta_data_on_re_fungible_token_stores_variable_meta_data() {
new_test_ext().execute_with(|| {
- default_limits();
-
let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);
let origin1 = Origin::signed(1);
@@ -2247,7 +1929,7 @@
let data = default_re_fungible_data();
create_test_item(1, &data.into());
- let variable_data = b"test set_variable_meta_data method.".to_vec();
+ let variable_data = b"test data".to_vec();
assert_ok!(TemplateModule::set_variable_meta_data(
origin1,
collection_id,
@@ -2267,8 +1949,6 @@
#[test]
fn set_variable_meta_data_on_fungible_token_fails() {
new_test_ext().execute_with(|| {
- default_limits();
-
let collection_id = create_test_collection(&CollectionMode::Fungible(3), 1);
let origin1 = Origin::signed(1);
@@ -2276,7 +1956,7 @@
let data = default_fungible_data();
create_test_item(1, &data.into());
- let variable_data = b"test set_variable_meta_data method.".to_vec();
+ let variable_data = b"test data".to_vec();
assert_noop!(
TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data),
Error::<Test>::CantStoreMetadataInFungibleTokens
@@ -2287,22 +1967,6 @@
#[test]
fn set_variable_meta_data_on_nft_token_fails_for_big_data() {
new_test_ext().execute_with(|| {
- assert_ok!(TemplateModule::set_chain_limits(
- RawOrigin::Root.into(),
- ChainLimits {
- collection_numbers_limit: default_collection_numbers_limit(),
- account_token_ownership_limit: 10,
- collections_admins_limit: 5,
- custom_data_limit: 10,
- nft_sponsor_transfer_timeout: 15,
- fungible_sponsor_transfer_timeout: 15,
- refungible_sponsor_transfer_timeout: 15,
- const_on_chain_schema_limit: 1024,
- offchain_schema_limit: 1024,
- variable_on_chain_schema_limit: 1024,
- }
- ));
-
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
let origin1 = Origin::signed(1);
@@ -2321,22 +1985,6 @@
#[test]
fn set_variable_meta_data_on_re_fungible_token_fails_for_big_data() {
new_test_ext().execute_with(|| {
- assert_ok!(TemplateModule::set_chain_limits(
- RawOrigin::Root.into(),
- ChainLimits {
- collection_numbers_limit: default_collection_numbers_limit(),
- account_token_ownership_limit: 10,
- collections_admins_limit: 5,
- custom_data_limit: 10,
- nft_sponsor_transfer_timeout: 15,
- fungible_sponsor_transfer_timeout: 15,
- refungible_sponsor_transfer_timeout: 15,
- const_on_chain_schema_limit: 1024,
- offchain_schema_limit: 1024,
- variable_on_chain_schema_limit: 1024,
- }
- ));
-
let collection_id = create_test_collection(&CollectionMode::ReFungible, 1);
let origin1 = Origin::signed(1);
@@ -2355,8 +2003,6 @@
#[test]
fn collection_transfer_flag_works() {
new_test_ext().execute_with(|| {
- default_limits();
-
let origin1 = Origin::signed(1);
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
@@ -2382,8 +2028,6 @@
#[test]
fn collection_transfer_flag_works_neg() {
new_test_ext().execute_with(|| {
- default_limits();
-
let origin1 = Origin::signed(1);
let collection_id = create_test_collection(&CollectionMode::NFT, 1);
primitives/nft/Cargo.tomldiffbeforeafterboth--- a/primitives/nft/Cargo.toml
+++ b/primitives/nft/Cargo.toml
@@ -32,4 +32,5 @@
"sp-core/std",
"sp-std/std",
]
-serde1 = ["serde"]
\ No newline at end of file
+serde1 = ["serde"]
+limit-testing = []
\ No newline at end of file
primitives/nft/src/lib.rsdiffbeforeafterboth1#![cfg_attr(not(feature = "std"), no_std)]23#[cfg(feature = "serde")]4pub use serde::{Serialize, Deserialize};56use sp_runtime::sp_std::prelude::Vec;7use codec::{Decode, Encode};8use max_encoded_len::MaxEncodedLen;9pub use frame_support::{10 BoundedVec, construct_runtime, decl_event, decl_module, decl_storage, decl_error,11 dispatch::DispatchResult,12 ensure, fail, parameter_types,13 traits::{14 Currency, ExistenceRequirement, Get, Imbalance, KeyOwnerProofSystem, OnUnbalanced,15 Randomness, IsSubType, WithdrawReasons,16 },17 weights::{18 constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},19 DispatchInfo, GetDispatchInfo, IdentityFee, Pays, PostDispatchInfo, Weight,20 WeightToFeePolynomial, DispatchClass,21 },22 StorageValue, transactional,23};24use derivative::Derivative;2526pub const MAX_DECIMAL_POINTS: DecimalPoints = 30;27pub const MAX_REFUNGIBLE_PIECES: u128 = 1_000_000_000_000_000_000_000;28pub const MAX_SPONSOR_TIMEOUT: u32 = 10_368_000;29pub const MAX_TOKEN_OWNERSHIP: u32 = 10_000_000;3031pub const COLLECTION_NUMBER_LIMIT: u32 = 100000;32pub const CUSTOM_DATA_LIMIT: u32 = 2048;33pub const COLLECTION_ADMINS_LIMIT: u64 = 5;34pub const ACCOUNT_TOKEN_OWNERSHIP_LIMIT: u32 = 1000000;3536// Timeouts for item types in passed blocks37pub const NFT_SPONSOR_TRANSFER_TIMEOUT: u32 = 5;38pub const FUNGIBLE_SPONSOR_TRANSFER_TIMEOUT: u32 = 5;39pub const REFUNGIBLE_SPONSOR_TRANSFER_TIMEOUT: u32 = 5;4041// Schema limits42pub const OFFCHAIN_SCHEMA_LIMIT: u32 = 1024;43pub const VARIABLE_ON_CHAIN_SCHEMA_LIMIT: u32 = 1024;44pub const CONST_ON_CHAIN_SCHEMA_LIMIT: u32 = 1024;4546/// How much items can be created per single47/// create_many call48pub const MAX_ITEMS_PER_BATCH: u32 = 200;4950parameter_types! {51 pub const CustomDataLimit: u32 = CUSTOM_DATA_LIMIT;52}5354pub type CollectionId = u32;55pub type TokenId = u32;56pub type DecimalPoints = u8;5758#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq)]59#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]60pub enum CollectionMode {61 Invalid,62 NFT,63 // decimal points64 Fungible(DecimalPoints),65 ReFungible,66}6768impl Default for CollectionMode {69 fn default() -> Self {70 Self::Invalid71 }72}7374impl CollectionMode {75 pub fn id(&self) -> u8 {76 match self {77 CollectionMode::Invalid => 0,78 CollectionMode::NFT => 1,79 CollectionMode::Fungible(_) => 2,80 CollectionMode::ReFungible => 3,81 }82 }83}8485pub trait SponsoringResolve<AccountId, Call> {86 fn resolve(who: &AccountId, call: &Call) -> Option<AccountId>;87}8889#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq)]90#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]91pub enum AccessMode {92 Normal,93 WhiteList,94}95impl Default for AccessMode {96 fn default() -> Self {97 Self::Normal98 }99}100101#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq)]102#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]103pub enum SchemaVersion {104 ImageURL,105 Unique,106}107impl Default for SchemaVersion {108 fn default() -> Self {109 Self::ImageURL110 }111}112113#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]114#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]115pub struct Ownership<AccountId> {116 pub owner: AccountId,117 pub fraction: u128,118}119120#[derive(Encode, Decode, Debug, Clone, PartialEq)]121#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]122pub enum SponsorshipState<AccountId> {123 /// The fees are applied to the transaction sender124 Disabled,125 Unconfirmed(AccountId),126 /// Transactions are sponsored by specified account127 Confirmed(AccountId),128}129130impl<AccountId> SponsorshipState<AccountId> {131 pub fn sponsor(&self) -> Option<&AccountId> {132 match self {133 Self::Confirmed(sponsor) => Some(sponsor),134 _ => None,135 }136 }137138 pub fn pending_sponsor(&self) -> Option<&AccountId> {139 match self {140 Self::Unconfirmed(sponsor) | Self::Confirmed(sponsor) => Some(sponsor),141 _ => None,142 }143 }144145 pub fn confirmed(&self) -> bool {146 matches!(self, Self::Confirmed(_))147 }148}149150impl<T> Default for SponsorshipState<T> {151 fn default() -> Self {152 Self::Disabled153 }154}155156#[derive(Encode, Decode, Clone, PartialEq)]157#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]158pub struct Collection<T: frame_system::Config> {159 pub owner: T::AccountId,160 pub mode: CollectionMode,161 pub access: AccessMode,162 pub decimal_points: DecimalPoints,163 pub name: Vec<u16>, // 64 include null escape char164 pub description: Vec<u16>, // 256 include null escape char165 pub token_prefix: Vec<u8>, // 16 include null escape char166 pub mint_mode: bool,167 pub offchain_schema: Vec<u8>,168 pub schema_version: SchemaVersion,169 pub sponsorship: SponsorshipState<T::AccountId>,170 pub limits: CollectionLimits<T::BlockNumber>, // Collection private restrictions171 pub variable_on_chain_schema: Vec<u8>, //172 pub const_on_chain_schema: Vec<u8>, //173 pub transfers_enabled: bool,174}175176#[derive(Encode, Decode, Debug, Clone, PartialEq)]177#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]178pub struct NftItemType<AccountId> {179 pub owner: AccountId,180 pub const_data: Vec<u8>,181 pub variable_data: Vec<u8>,182}183184#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]185#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]186pub struct FungibleItemType {187 pub value: u128,188}189190#[derive(Encode, Decode, Debug, Clone, PartialEq)]191#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]192pub struct ReFungibleItemType<AccountId> {193 pub owner: Vec<Ownership<AccountId>>,194 pub const_data: Vec<u8>,195 pub variable_data: Vec<u8>,196}197198#[derive(Encode, Decode, Debug, Clone, PartialEq)]199#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]200pub struct CollectionLimits<BlockNumber: Encode + Decode> {201 pub account_token_ownership_limit: u32,202 pub sponsored_data_size: u32,203 /// None - setVariableMetadata is not sponsored204 /// Some(v) - setVariableMetadata is sponsored205 /// if there is v block between txs206 pub sponsored_data_rate_limit: Option<BlockNumber>,207 pub token_limit: u32,208209 // Timeouts for item types in passed blocks210 pub sponsor_transfer_timeout: u32,211 pub owner_can_transfer: bool,212 pub owner_can_destroy: bool,213}214215impl<BlockNumber: Encode + Decode> Default for CollectionLimits<BlockNumber> {216 fn default() -> Self {217 Self {218 account_token_ownership_limit: 10_000_000,219 token_limit: u32::max_value(),220 sponsored_data_size: u32::MAX,221 sponsored_data_rate_limit: None,222 sponsor_transfer_timeout: 14400,223 owner_can_transfer: true,224 owner_can_destroy: true,225 }226 }227}228229/// BoundedVec doesn't supports serde230#[cfg(feature = "serde1")]231mod bounded_serde {232 use core::convert::TryFrom;233 use frame_support::{BoundedVec, traits::Get};234 use serde::{235 ser::{self, Serialize},236 de::{self, Deserialize, Error},237 };238 use sp_std::vec::Vec;239240 pub fn serialize<D, V, S>(value: &BoundedVec<V, S>, serializer: D) -> Result<D::Ok, D::Error>241 where242 D: ser::Serializer,243 V: Serialize,244 {245 let vec: &Vec<_> = &value;246 vec.serialize(serializer)247 }248249 pub fn deserialize<'de, D, V, S>(deserializer: D) -> Result<BoundedVec<V, S>, D::Error>250 where251 D: de::Deserializer<'de>,252 V: de::Deserialize<'de>,253 S: Get<u32>,254 {255 // TODO: Implement custom visitor, which will limit vec size at parse time? Will serde only be used by chainspec?256 let vec = <Vec<V>>::deserialize(deserializer)?;257 let len = vec.len();258 TryFrom::try_from(vec).map_err(|_| D::Error::invalid_length(len, &"lesser size"))259 }260}261262#[derive(Encode, Decode, MaxEncodedLen, Default, PartialEq, Clone, Derivative)]263#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]264#[derivative(Debug)]265pub struct CreateNftData {266 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]267 #[derivative(Debug = "ignore")]268 pub const_data: BoundedVec<u8, CustomDataLimit>,269 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]270 #[derivative(Debug = "ignore")]271 pub variable_data: BoundedVec<u8, CustomDataLimit>,272}273274#[derive(Encode, Decode, MaxEncodedLen, Default, Debug, Clone, PartialEq)]275#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]276pub struct CreateFungibleData {277 pub value: u128,278}279280#[derive(Encode, Decode, MaxEncodedLen, Default, PartialEq, Clone, Derivative)]281#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]282#[derivative(Debug)]283pub struct CreateReFungibleData {284 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]285 #[derivative(Debug = "ignore")]286 pub const_data: BoundedVec<u8, CustomDataLimit>,287 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]288 #[derivative(Debug = "ignore")]289 pub variable_data: BoundedVec<u8, CustomDataLimit>,290 pub pieces: u128,291}292293#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, Debug)]294#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]295pub enum CreateItemData {296 NFT(CreateNftData),297 Fungible(CreateFungibleData),298 ReFungible(CreateReFungibleData),299}300301impl CreateItemData {302 pub fn data_size(&self) -> usize {303 match self {304 CreateItemData::NFT(data) => data.variable_data.len() + data.const_data.len(),305 CreateItemData::ReFungible(data) => data.variable_data.len() + data.const_data.len(),306 _ => 0,307 }308 }309}310311impl From<CreateNftData> for CreateItemData {312 fn from(item: CreateNftData) -> Self {313 CreateItemData::NFT(item)314 }315}316317impl From<CreateReFungibleData> for CreateItemData {318 fn from(item: CreateReFungibleData) -> Self {319 CreateItemData::ReFungible(item)320 }321}322323impl From<CreateFungibleData> for CreateItemData {324 fn from(item: CreateFungibleData) -> Self {325 CreateItemData::Fungible(item)326 }327}1#![cfg_attr(not(feature = "std"), no_std)]23#[cfg(feature = "serde")]4pub use serde::{Serialize, Deserialize};56use sp_runtime::sp_std::prelude::Vec;7use codec::{Decode, Encode};8use max_encoded_len::MaxEncodedLen;9pub use frame_support::{10 BoundedVec, construct_runtime, decl_event, decl_module, decl_storage, decl_error,11 dispatch::DispatchResult,12 ensure, fail, parameter_types,13 traits::{14 Currency, ExistenceRequirement, Get, Imbalance, KeyOwnerProofSystem, OnUnbalanced,15 Randomness, IsSubType, WithdrawReasons,16 },17 weights::{18 constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},19 DispatchInfo, GetDispatchInfo, IdentityFee, Pays, PostDispatchInfo, Weight,20 WeightToFeePolynomial, DispatchClass,21 },22 StorageValue, transactional,23};24use derivative::Derivative;2526pub const MAX_DECIMAL_POINTS: DecimalPoints = 30;27pub const MAX_REFUNGIBLE_PIECES: u128 = 1_000_000_000_000_000_000_000;28pub const MAX_SPONSOR_TIMEOUT: u32 = 10_368_000;29pub const MAX_TOKEN_OWNERSHIP: u32 = 10_000_000;3031pub const COLLECTION_NUMBER_LIMIT: u32 = if cfg!(not(feature = "limit-testing")) { 100000 } else { 10 };32pub const CUSTOM_DATA_LIMIT: u32 = if cfg!(not(feature = "limit-testing")) { 2048 } else { 10 };33pub const COLLECTION_ADMINS_LIMIT: u64 = 5;34pub const ACCOUNT_TOKEN_OWNERSHIP_LIMIT: u32 = if cfg!(not(feature = "limit-testing")) { 1000000 } else { 10 };3536// Timeouts for item types in passed blocks37pub const NFT_SPONSOR_TRANSFER_TIMEOUT: u32 = 5;38pub const FUNGIBLE_SPONSOR_TRANSFER_TIMEOUT: u32 = 5;39pub const REFUNGIBLE_SPONSOR_TRANSFER_TIMEOUT: u32 = 5;4041// Schema limits42pub const OFFCHAIN_SCHEMA_LIMIT: u32 = 1024;43pub const VARIABLE_ON_CHAIN_SCHEMA_LIMIT: u32 = 1024;44pub const CONST_ON_CHAIN_SCHEMA_LIMIT: u32 = 1024;4546/// How much items can be created per single47/// create_many call48pub const MAX_ITEMS_PER_BATCH: u32 = 200;4950parameter_types! {51 pub const CustomDataLimit: u32 = CUSTOM_DATA_LIMIT;52}5354pub type CollectionId = u32;55pub type TokenId = u32;56pub type DecimalPoints = u8;5758#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq)]59#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]60pub enum CollectionMode {61 Invalid,62 NFT,63 // decimal points64 Fungible(DecimalPoints),65 ReFungible,66}6768impl Default for CollectionMode {69 fn default() -> Self {70 Self::Invalid71 }72}7374impl CollectionMode {75 pub fn id(&self) -> u8 {76 match self {77 CollectionMode::Invalid => 0,78 CollectionMode::NFT => 1,79 CollectionMode::Fungible(_) => 2,80 CollectionMode::ReFungible => 3,81 }82 }83}8485pub trait SponsoringResolve<AccountId, Call> {86 fn resolve(who: &AccountId, call: &Call) -> Option<AccountId>;87}8889#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq)]90#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]91pub enum AccessMode {92 Normal,93 WhiteList,94}95impl Default for AccessMode {96 fn default() -> Self {97 Self::Normal98 }99}100101#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq)]102#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]103pub enum SchemaVersion {104 ImageURL,105 Unique,106}107impl Default for SchemaVersion {108 fn default() -> Self {109 Self::ImageURL110 }111}112113#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]114#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]115pub struct Ownership<AccountId> {116 pub owner: AccountId,117 pub fraction: u128,118}119120#[derive(Encode, Decode, Debug, Clone, PartialEq)]121#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]122pub enum SponsorshipState<AccountId> {123 /// The fees are applied to the transaction sender124 Disabled,125 Unconfirmed(AccountId),126 /// Transactions are sponsored by specified account127 Confirmed(AccountId),128}129130impl<AccountId> SponsorshipState<AccountId> {131 pub fn sponsor(&self) -> Option<&AccountId> {132 match self {133 Self::Confirmed(sponsor) => Some(sponsor),134 _ => None,135 }136 }137138 pub fn pending_sponsor(&self) -> Option<&AccountId> {139 match self {140 Self::Unconfirmed(sponsor) | Self::Confirmed(sponsor) => Some(sponsor),141 _ => None,142 }143 }144145 pub fn confirmed(&self) -> bool {146 matches!(self, Self::Confirmed(_))147 }148}149150impl<T> Default for SponsorshipState<T> {151 fn default() -> Self {152 Self::Disabled153 }154}155156#[derive(Encode, Decode, Clone, PartialEq)]157#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]158pub struct Collection<T: frame_system::Config> {159 pub owner: T::AccountId,160 pub mode: CollectionMode,161 pub access: AccessMode,162 pub decimal_points: DecimalPoints,163 pub name: Vec<u16>, // 64 include null escape char164 pub description: Vec<u16>, // 256 include null escape char165 pub token_prefix: Vec<u8>, // 16 include null escape char166 pub mint_mode: bool,167 pub offchain_schema: Vec<u8>,168 pub schema_version: SchemaVersion,169 pub sponsorship: SponsorshipState<T::AccountId>,170 pub limits: CollectionLimits<T::BlockNumber>, // Collection private restrictions171 pub variable_on_chain_schema: Vec<u8>, //172 pub const_on_chain_schema: Vec<u8>, //173 pub transfers_enabled: bool,174}175176#[derive(Encode, Decode, Debug, Clone, PartialEq)]177#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]178pub struct NftItemType<AccountId> {179 pub owner: AccountId,180 pub const_data: Vec<u8>,181 pub variable_data: Vec<u8>,182}183184#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]185#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]186pub struct FungibleItemType {187 pub value: u128,188}189190#[derive(Encode, Decode, Debug, Clone, PartialEq)]191#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]192pub struct ReFungibleItemType<AccountId> {193 pub owner: Vec<Ownership<AccountId>>,194 pub const_data: Vec<u8>,195 pub variable_data: Vec<u8>,196}197198#[derive(Encode, Decode, Debug, Clone, PartialEq)]199#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]200pub struct CollectionLimits<BlockNumber: Encode + Decode> {201 pub account_token_ownership_limit: u32,202 pub sponsored_data_size: u32,203 /// None - setVariableMetadata is not sponsored204 /// Some(v) - setVariableMetadata is sponsored205 /// if there is v block between txs206 pub sponsored_data_rate_limit: Option<BlockNumber>,207 pub token_limit: u32,208209 // Timeouts for item types in passed blocks210 pub sponsor_transfer_timeout: u32,211 pub owner_can_transfer: bool,212 pub owner_can_destroy: bool,213}214215impl<BlockNumber: Encode + Decode> Default for CollectionLimits<BlockNumber> {216 fn default() -> Self {217 Self {218 account_token_ownership_limit: 10_000_000,219 token_limit: u32::max_value(),220 sponsored_data_size: u32::MAX,221 sponsored_data_rate_limit: None,222 sponsor_transfer_timeout: 14400,223 owner_can_transfer: true,224 owner_can_destroy: true,225 }226 }227}228229/// BoundedVec doesn't supports serde230#[cfg(feature = "serde1")]231mod bounded_serde {232 use core::convert::TryFrom;233 use frame_support::{BoundedVec, traits::Get};234 use serde::{235 ser::{self, Serialize},236 de::{self, Deserialize, Error},237 };238 use sp_std::vec::Vec;239240 pub fn serialize<D, V, S>(value: &BoundedVec<V, S>, serializer: D) -> Result<D::Ok, D::Error>241 where242 D: ser::Serializer,243 V: Serialize,244 {245 let vec: &Vec<_> = &value;246 vec.serialize(serializer)247 }248249 pub fn deserialize<'de, D, V, S>(deserializer: D) -> Result<BoundedVec<V, S>, D::Error>250 where251 D: de::Deserializer<'de>,252 V: de::Deserialize<'de>,253 S: Get<u32>,254 {255 // TODO: Implement custom visitor, which will limit vec size at parse time? Will serde only be used by chainspec?256 let vec = <Vec<V>>::deserialize(deserializer)?;257 let len = vec.len();258 TryFrom::try_from(vec).map_err(|_| D::Error::invalid_length(len, &"lesser size"))259 }260}261262#[derive(Encode, Decode, MaxEncodedLen, Default, PartialEq, Clone, Derivative)]263#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]264#[derivative(Debug)]265pub struct CreateNftData {266 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]267 #[derivative(Debug = "ignore")]268 pub const_data: BoundedVec<u8, CustomDataLimit>,269 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]270 #[derivative(Debug = "ignore")]271 pub variable_data: BoundedVec<u8, CustomDataLimit>,272}273274#[derive(Encode, Decode, MaxEncodedLen, Default, Debug, Clone, PartialEq)]275#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]276pub struct CreateFungibleData {277 pub value: u128,278}279280#[derive(Encode, Decode, MaxEncodedLen, Default, PartialEq, Clone, Derivative)]281#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]282#[derivative(Debug)]283pub struct CreateReFungibleData {284 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]285 #[derivative(Debug = "ignore")]286 pub const_data: BoundedVec<u8, CustomDataLimit>,287 #[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]288 #[derivative(Debug = "ignore")]289 pub variable_data: BoundedVec<u8, CustomDataLimit>,290 pub pieces: u128,291}292293#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, Debug)]294#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]295pub enum CreateItemData {296 NFT(CreateNftData),297 Fungible(CreateFungibleData),298 ReFungible(CreateReFungibleData),299}300301impl CreateItemData {302 pub fn data_size(&self) -> usize {303 match self {304 CreateItemData::NFT(data) => data.variable_data.len() + data.const_data.len(),305 CreateItemData::ReFungible(data) => data.variable_data.len() + data.const_data.len(),306 _ => 0,307 }308 }309}310311impl From<CreateNftData> for CreateItemData {312 fn from(item: CreateNftData) -> Self {313 CreateItemData::NFT(item)314 }315}316317impl From<CreateReFungibleData> for CreateItemData {318 fn from(item: CreateReFungibleData) -> Self {319 CreateItemData::ReFungible(item)320 }321}322323impl From<CreateFungibleData> for CreateItemData {324 fn from(item: CreateFungibleData) -> Self {325 CreateItemData::Fungible(item)326 }327}runtime/Cargo.tomldiffbeforeafterboth--- a/runtime/Cargo.toml
+++ b/runtime/Cargo.toml
@@ -85,6 +85,10 @@
'xcm-builder/std',
'xcm-executor/std',
]
+limit-testing = [
+ 'pallet-nft/limit-testing',
+ 'nft-data-structs/limit-testing',
+]
################################################################################
# Substrate Dependencies
runtime/src/nft_weights.rsdiffbeforeafterboth--- a/runtime/src/nft_weights.rs
+++ b/runtime/src/nft_weights.rs
@@ -123,11 +123,6 @@
.saturating_add(DbWeight::get().reads(2_u64))
.saturating_add(DbWeight::get().writes(1_u64))
}
- fn set_chain_limits() -> Weight {
- 1_300_000_u64
- .saturating_add(DbWeight::get().reads(0_u64))
- .saturating_add(DbWeight::get().writes(1_u64))
- }
fn set_contract_sponsoring_rate_limit() -> Weight {
3_500_000_u64
.saturating_add(DbWeight::get().reads(0_u64))