git.delta.rocks / unique-network / refs/commits / c466f2a28bc7

difftreelog

test fix build and style

Yaroslav Bolyukin2023-08-30parent: #66f7f7d.patch.diff
in: master

18 files changed

modifiedpallets/common/src/benchmarking.rsdiffbeforeafterboth
63 }63 }
64 let bytes = id.to_string();64 let bytes = id.to_string();
65 let len = data.len();65 let len = data.len();
66 data[len - bytes.len()..].copy_from_slice(&bytes.as_bytes());66 data[len - bytes.len()..].copy_from_slice(bytes.as_bytes());
67 data67 data
68}68}
69pub fn property_value() -> PropertyValue {69pub fn property_value() -> PropertyValue {
80 cast: impl FnOnce(CollectionHandle<T>) -> R,80 cast: impl FnOnce(CollectionHandle<T>) -> R,
81) -> Result<R, DispatchError> {81) -> Result<R, DispatchError> {
82 let imbalance = <T as Config>::Currency::deposit(82 let imbalance = <T as Config>::Currency::deposit(
83 &owner.as_sub(),83 owner.as_sub(),
84 T::CollectionCreationPrice::get(),84 T::CollectionCreationPrice::get(),
85 Precision::Exact,85 Precision::Exact,
86 )?;86 )?;
modifiedpallets/common/src/lib.rsdiffbeforeafterboth
2420 }2420 }
2421}2421}
24222422
2423#[cfg(feature = "tests")]2423#[cfg(any(feature = "tests", test))]
2424#[allow(missing_docs)]
2424pub mod tests {2425pub mod tests {
2425 use crate::{DispatchResult, DispatchError, LazyValue, Config};2426 use crate::{DispatchResult, DispatchError, LazyValue, Config};
24262427
2456 }2457 }
24572458
2458 #[rustfmt::skip]2459 #[rustfmt::skip]
2459 pub const table: [TestCase; 16] = [2460 pub const TABLE: [TestCase; 16] = [
2460 // ┌╴collection_admin2461 // ┌╴collection_admin
2461 // │ ┌╴is_collection_admin2462 // │ ┌╴is_collection_admin
2462 // │ │ ┌╴token_owner2463 // │ │ ┌╴token_owner
modifiedpallets/evm-coder-substrate/src/lib.rsdiffbeforeafterboth
336 ERC165Call(ERC165Call, PhantomData<fn() -> T>),336 ERC165Call(ERC165Call, PhantomData<fn() -> T>),
337 OtherCall(ERC165Call),337 OtherCall(ERC165Call),
338338
339 #[weight(Weight::from_ref_time(a + b))]339 #[weight(Weight::from_parts(a + b, 0))]
340 Example {340 Example {
341 a: u64,341 a: u64,
342 b: u64,342 b: u64,
modifiedpallets/fungible/src/benchmarking.rsdiffbeforeafterboth
53 let data = (0..b).map(|i| {53 let data = (0..b).map(|i| {
54 bench_init!(to: cross_sub(i););54 bench_init!(to: cross_sub(i););
55 (to, 200)55 (to, 200)
56 }).collect::<BTreeMap<_, _>>().try_into().unwrap();56 }).collect::<BTreeMap<_, _>>();
57 }: {<Pallet<T>>::create_multiple_items(&collection, &sender, data, &Unlimited)?}57 }: {<Pallet<T>>::create_multiple_items(&collection, &sender, data, &Unlimited)?}
5858
59 burn_item {59 burn_item {
modifiedpallets/identity/src/benchmarking.rsdiffbeforeafterboth
35//! Identity pallet benchmarking.35//! Identity pallet benchmarking.
3636
37#![cfg(feature = "runtime-benchmarks")]37#![cfg(feature = "runtime-benchmarks")]
38#![allow(clippy::no_effect)]
3839
39use super::*;40use super::*;
4041
modifiedpallets/identity/src/tests.rsdiffbeforeafterboth
6767
68parameter_types! {68parameter_types! {
69 pub BlockWeights: frame_system::limits::BlockWeights =69 pub BlockWeights: frame_system::limits::BlockWeights =
70 frame_system::limits::BlockWeights::simple_max(frame_support::weights::Weight::from_ref_time(1024));70 frame_system::limits::BlockWeights::simple_max(frame_support::weights::Weight::from_parts(1024, 0));
71}71}
72impl frame_system::Config for Test {72impl frame_system::Config for Test {
73 type BaseCallFilter = frame_support::traits::Everything;73 type BaseCallFilter = frame_support::traits::Everything;
modifiedpallets/identity/src/types.rsdiffbeforeafterboth
481 let mut registry = scale_info::Registry::new();481 let mut registry = scale_info::Registry::new();
482 let type_id = registry.register_type(&scale_info::meta_type::<Data>());482 let type_id = registry.register_type(&scale_info::meta_type::<Data>());
483 let registry: scale_info::PortableRegistry = registry.into();483 let registry: scale_info::PortableRegistry = registry.into();
484 let type_info = registry.resolve(type_id.id()).unwrap();484 let type_info = registry.resolve(type_id.id).unwrap();
485485
486 let check_type_info = |data: &Data| {486 let check_type_info = |data: &Data| {
487 let variant_name = match data {487 let variant_name = match data {
492 Data::ShaThree256(_) => "ShaThree256".to_string(),492 Data::ShaThree256(_) => "ShaThree256".to_string(),
493 Data::Raw(bytes) => format!("Raw{}", bytes.len()),493 Data::Raw(bytes) => format!("Raw{}", bytes.len()),
494 };494 };
495 if let scale_info::TypeDef::Variant(variant) = type_info.type_def() {495 if let scale_info::TypeDef::Variant(variant) = &type_info.type_def {
496 let variant = variant496 let variant = variant
497 .variants()497 .variants
498 .iter()498 .iter()
499 .find(|v| v.name() == &variant_name)499 .find(|v| v.name == variant_name)
500 .expect(&format!("Expected to find variant {}", variant_name));500 .expect(&format!("Expected to find variant {}", variant_name));
501501
502 let field_arr_len = variant502 let field_arr_len = variant
503 .fields()503 .fields
504 .first()504 .first()
505 .and_then(|f| registry.resolve(f.ty().id()))505 .and_then(|f| registry.resolve(f.ty.id))
506 .map(|ty| {506 .map(|ty| {
507 if let scale_info::TypeDef::Array(arr) = ty.type_def() {507 if let scale_info::TypeDef::Array(arr) = &ty.type_def {
508 arr.len()508 arr.len
509 } else {509 } else {
510 panic!("Should be an array type")510 panic!("Should be an array type")
511 }511 }
512 })512 })
513 .unwrap_or(0);513 .unwrap_or(0);
514514
515 let encoded = data.encode();515 let encoded = data.encode();
516 assert_eq!(encoded[0], variant.index());516 assert_eq!(encoded[0], variant.index);
517 assert_eq!(encoded.len() as u32 - 1, field_arr_len);517 assert_eq!(encoded.len() as u32 - 1, field_arr_len);
518 } else {518 } else {
519 panic!("Should be a variant type")519 panic!("Should be a variant type")
modifiedpallets/inflation/src/tests.rsdiffbeforeafterboth
78parameter_types! {78parameter_types! {
79 pub const BlockHashCount: u64 = 250;79 pub const BlockHashCount: u64 = 250;
80 pub BlockWeights: frame_system::limits::BlockWeights =80 pub BlockWeights: frame_system::limits::BlockWeights =
81 frame_system::limits::BlockWeights::simple_max(Weight::from_ref_time(1024));81 frame_system::limits::BlockWeights::simple_max(Weight::from_parts(1024, 0));
82 pub const SS58Prefix: u8 = 42;82 pub const SS58Prefix: u8 = 42;
83}83}
8484
modifiedpallets/nonfungible/src/benchmarking.rsdiffbeforeafterboth
43 owner: T::CrossAccountId,43 owner: T::CrossAccountId,
44) -> Result<TokenId, DispatchError> {44) -> Result<TokenId, DispatchError> {
45 <Pallet<T>>::create_item(45 <Pallet<T>>::create_item(
46 &collection,46 collection,
47 sender,47 sender,
48 create_max_item_data::<T>(owner),48 create_max_item_data::<T>(owner),
49 &Unlimited,49 &Unlimited,
50 )?;50 )?;
51 Ok(TokenId(<TokensMinted<T>>::get(&collection.id)))51 Ok(TokenId(<TokensMinted<T>>::get(collection.id)))
52}52}
5353
54fn create_collection<T: Config>(54fn create_collection<T: Config>(
modifiedpallets/refungible/src/benchmarking.rsdiffbeforeafterboth
51 users: impl IntoIterator<Item = (T::CrossAccountId, u128)>,51 users: impl IntoIterator<Item = (T::CrossAccountId, u128)>,
52) -> Result<TokenId, DispatchError> {52) -> Result<TokenId, DispatchError> {
53 let data: CreateItemData<T> = create_max_item_data::<T>(users);53 let data: CreateItemData<T> = create_max_item_data::<T>(users);
54 <Pallet<T>>::create_item(&collection, sender, data, &Unlimited)?;54 <Pallet<T>>::create_item(collection, sender, data, &Unlimited)?;
55 Ok(TokenId(<TokensMinted<T>>::get(&collection.id)))55 Ok(TokenId(<TokensMinted<T>>::get(collection.id)))
56}56}
5757
58fn create_collection<T: Config>(58fn create_collection<T: Config>(
104 let data = vec![create_max_item_data::<T>((0..b).map(|u| {104 let data = vec![create_max_item_data::<T>((0..b).map(|u| {
105 bench_init!(to: cross_sub(u););105 bench_init!(to: cross_sub(u););
106 (to, 200)106 (to, 200)
107 }))].try_into().unwrap();107 }))];
108 }: {<Pallet<T>>::create_multiple_items(&collection, &sender, data, &Unlimited)?}108 }: {<Pallet<T>>::create_multiple_items(&collection, &sender, data, &Unlimited)?}
109109
110 // Other user left, token data is kept110 // Other user left, token data is kept
modifiedpallets/scheduler-v2/src/benchmarking.rsdiffbeforeafterboth
83///83///
84/// # Arguments84/// # Arguments
85/// * `periodic` - makes the task periodic.85/// * `periodic` - makes the task periodic.
86/// Sets the task's period and repetition count to `100`.86/// Sets the task's period and repetition count to `100`.
87/// * `named` - gives a name to the task: `u32_to_name(0)`.87/// * `named` - gives a name to the task: `u32_to_name(0)`.
88/// * `signed` - determines the origin of the task.88/// * `signed` - determines the origin of the task.
89/// If true, it will have the Signed origin. Otherwise it will have the Root origin.89/// If true, it will have the Signed origin. Otherwise it will have the Root origin.
90/// See [`make_origin`] for details.90/// See [`make_origin`] for details.
91/// * maybe_lookup_len - sets optional lookup length. It is used to benchmark task fetching from the `Preimages` store.91/// * maybe_lookup_len - sets optional lookup length. It is used to benchmark task fetching from the `Preimages` store.
92/// * priority - the task's priority.92/// * priority - the task's priority.
93fn make_task<T: Config>(93fn make_task<T: Config>(
155 }155 }
156 if maybe_lookup_len.is_some() {156 if maybe_lookup_len.is_some() {
157 len += 1;157 len += 1;
158 } else {158 } else if len > 0 {
159 if len > 0 {
160 len -= 1;159 len -= 1;
161 } else {160 } else {
162 break c;161 break c;
163 }162 }
164 }
165 }163 }
166}164}
167165
modifiedpallets/scheduler-v2/src/mock.rsdiffbeforeafterboth
33// limitations under the License.33// limitations under the License.
3434
35//! # Scheduler test environment.35//! # Scheduler test environment.
36#![allow(deprecated)]
3637
37use super::*;38use super::*;
3839
229 r => Err(O::from(r)),230 r => Err(O::from(r)),
230 })231 })
231 }232 }
233 #[cfg(feature = "runtime-benchmarks")]
234 fn try_successful_origin() -> Result<O, ()> {
235 Ok(O::from(RawOrigin::Root))
236 }
232}237}
233238
234pub struct Executor;239pub struct Executor;
modifiedpallets/scheduler-v2/src/tests.rsdiffbeforeafterboth
33// limitations under the License.33// limitations under the License.
3434
35//! # Scheduler tests.35//! # Scheduler tests.
36#![allow(deprecated)]
3637
37use super::*;38use super::*;
38use crate::mock::{39use crate::mock::{
modifiedpallets/structure/src/benchmarking.rsdiffbeforeafterboth
19use frame_benchmarking::{benchmarks, account};19use frame_benchmarking::{benchmarks, account};
20use frame_support::traits::{fungible::Balanced, Get, tokens::Precision};20use frame_support::traits::{fungible::Balanced, Get, tokens::Precision};
21use up_data_structs::{21use up_data_structs::{
22 CreateCollectionData, CollectionMode, CreateItemData, CollectionFlags, CreateNftData,22 CreateCollectionData, CollectionMode, CreateItemData, CreateNftData, budget::Unlimited,
23 budget::Unlimited,
24};23};
25use pallet_common::Config as CommonConfig;24use pallet_common::Config as CommonConfig;
modifiedruntime/common/tests/mod.rsdiffbeforeafterboth
1616
17use sp_runtime::{BuildStorage, Storage};17use sp_runtime::{BuildStorage, Storage};
18use sp_core::{Public, Pair};18use sp_core::{Public, Pair};
19use sp_std::vec;
20use up_common::types::AuraId;19use up_common::types::AuraId;
21use crate::{Runtime, GenesisConfig, ParachainInfoConfig, RuntimeEvent, System};20use crate::{Runtime, GenesisConfig, ParachainInfoConfig, RuntimeEvent, System};
2221
76 AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()75 AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()
77 }76 }
7877
79 let accounts = vec!["Alice", "Bob"];78 let accounts = ["Alice", "Bob"];
80 let keys = accounts79 let keys = accounts
81 .iter()80 .iter()
82 .map(|&acc| {81 .map(|&acc| {
104 ..GenesisConfig::default()103 ..GenesisConfig::default()
105 };104 };
106105
107 cfg.build_storage().unwrap().into()106 cfg.build_storage().unwrap()
108}107}
109108
110#[cfg(not(feature = "collator-selection"))]109#[cfg(not(feature = "collator-selection"))]
modifiedruntime/common/tests/xcm.rsdiffbeforeafterboth
26const ALICE: AccountId = AccountId::new([0u8; 32]);26const ALICE: AccountId = AccountId::new([0u8; 32]);
27const BOB: AccountId = AccountId::new([1u8; 32]);27const BOB: AccountId = AccountId::new([1u8; 32]);
2828
29const INITIAL_BALANCE: u128 = 1000000000000000000_0000; // 1000 UNQ29const INITIAL_BALANCE: u128 = 10_000_000_000_000_000_000_000; // 10_000 UNQ
3030
31#[test]31#[test]
32pub fn xcm_transact_is_forbidden() {32pub fn xcm_transact_is_forbidden() {
modifiedruntime/tests/Cargo.tomldiffbeforeafterboth
55
6[features]6[features]
7default = ['refungible']7default = ['refungible']
8tests = ['pallet-common/tests']
98
10refungible = []9refungible = []
1110
45up-sponsorship = { workspace = true }44up-sponsorship = { workspace = true }
46xcm = { workspace = true }45xcm = { workspace = true }
46
47[dev-dependencies]
48pallet-common = { workspace = true, features = ["tests"] }
4749
modifiedruntime/tests/src/tests.rsdiffbeforeafterboth
99 .try_into()99 .try_into()
100 .unwrap();100 .unwrap();
101101
102 let data: CreateCollectionData<u64> = CreateCollectionData {102 let data = CreateCollectionData {
103 name: col_name1.try_into().unwrap(),103 name: col_name1.try_into().unwrap(),
104 description: col_desc1.try_into().unwrap(),104 description: col_desc1.try_into().unwrap(),
105 token_prefix: token_prefix1.try_into().unwrap(),105 token_prefix: token_prefix1.try_into().unwrap(),
204 let description: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();204 let description: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();
205 let token_prefix: Vec<u8> = b"token_prefix1\0".to_vec();205 let token_prefix: Vec<u8> = b"token_prefix1\0".to_vec();
206206
207 let data: CreateCollectionData<<Test as frame_system::Config>::AccountId> =207 let data = CreateCollectionData {
208 CreateCollectionData {
209 name: name.try_into().unwrap(),208 name: name.try_into().unwrap(),
210 description: description.try_into().unwrap(),209 description: description.try_into().unwrap(),
225 let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();224 let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();
226 let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();225 let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();
227226
228 let data: CreateCollectionData<u64> = CreateCollectionData {227 let data = CreateCollectionData {
229 name: col_name1.try_into().unwrap(),228 name: col_name1.try_into().unwrap(),
230 description: col_desc1.try_into().unwrap(),229 description: col_desc1.try_into().unwrap(),
231 token_prefix: token_prefix1.try_into().unwrap(),230 token_prefix: token_prefix1.try_into().unwrap(),
2364 let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();2363 let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();
2365 let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();2364 let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();
23662365
2367 let data: CreateCollectionData<u64> = CreateCollectionData {2366 let data = CreateCollectionData {
2368 name: col_name1.try_into().unwrap(),2367 name: col_name1.try_into().unwrap(),
2369 description: col_desc1.try_into().unwrap(),2368 description: col_desc1.try_into().unwrap(),
2370 token_prefix: token_prefix1.try_into().unwrap(),2369 token_prefix: token_prefix1.try_into().unwrap(),
26182617
2619mod check_token_permissions {2618mod check_token_permissions {
2620 use super::*;2619 use super::*;
2621 use frame_support::once_cell::sync::Lazy;
2622 use pallet_common::LazyValue;2620 use pallet_common::LazyValue;
2623 use sp_runtime::DispatchError;
26242621
2625 fn test<FTE: FnOnce() -> bool>(2622 fn test<FTE: FnOnce() -> bool>(
2626 i: usize,2623 i: usize,
2662 fn no_permission_only() {2659 fn no_permission_only() {
2663 new_test_ext().execute_with(|| {2660 new_test_ext().execute_with(|| {
2664 let mut check_token_existence = LazyValue::new(|| true);2661 let mut check_token_existence = LazyValue::new(|| true);
2665 for (i, row) in pallet_common::tests::table.iter().enumerate() {2662 for (i, row) in pallet_common::tests::TABLE.iter().enumerate() {
2666 test(i, row, &mut check_token_existence);2663 test(i, row, &mut check_token_existence);
2667 }2664 }
2668 });2665 });
2671 #[test]2668 #[test]
2672 fn no_permission_and_token_not_found() {2669 fn no_permission_and_token_not_found() {
2673 new_test_ext().execute_with(|| {2670 new_test_ext().execute_with(|| {
2674 for (i, row) in pallet_common::tests::table.iter().enumerate() {2671 for (i, row) in pallet_common::tests::TABLE.iter().enumerate() {
2675 // This is inside the loop to keep track of whether the lambda was called2672 // This is inside the loop to keep track of whether the lambda was called
2676 let mut check_token_existence = LazyValue::new(|| false);2673 let mut check_token_existence = LazyValue::new(|| false);
2677 test(i, row, &mut check_token_existence);2674 test(i, row, &mut check_token_existence);