difftreelog
Merge pull request #974 from UniqueNetwork/fix/evm-coder-leftovers
in: master
25 files changed
client/rpc/src/lib.rsdiffbeforeafterboth--- a/client/rpc/src/lib.rs
+++ b/client/rpc/src/lib.rs
@@ -528,7 +528,7 @@
|r: sc_service::Result<
up_data_structs::TokenDataVersion1<CrossAccountId>,
sp_runtime::DispatchError,
- >| r.and_then(|value| Ok(value.into())),
+ >| r.map(|value| value.into()),
)
.or_else(|_| {
Ok(api
node/cli/src/chain_spec.rsdiffbeforeafterboth--- a/node/cli/src/chain_spec.rs
+++ b/node/cli/src/chain_spec.rs
@@ -297,7 +297,7 @@
default_runtime,
// Sudo account
get_account_id_from_seed::<sr25519::Public>("Alice"),
- vec![
+ [
(
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_from_seed::<AuraId>("Alice"),
@@ -371,7 +371,7 @@
default_runtime,
// Sudo account
get_account_id_from_seed::<sr25519::Public>("Alice"),
- vec![
+ [
(
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_from_seed::<AuraId>("Alice"),
pallets/common/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/common/src/benchmarking.rs
+++ b/pallets/common/src/benchmarking.rs
@@ -63,7 +63,7 @@
}
let bytes = id.to_string();
let len = data.len();
- data[len - bytes.len()..].copy_from_slice(&bytes.as_bytes());
+ data[len - bytes.len()..].copy_from_slice(bytes.as_bytes());
data
}
pub fn property_value() -> PropertyValue {
@@ -80,7 +80,7 @@
cast: impl FnOnce(CollectionHandle<T>) -> R,
) -> Result<R, DispatchError> {
let imbalance = <T as Config>::Currency::deposit(
- &owner.as_sub(),
+ owner.as_sub(),
T::CollectionCreationPrice::get(),
Precision::Exact,
)?;
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -2420,7 +2420,8 @@
}
}
-#[cfg(feature = "tests")]
+#[cfg(any(feature = "tests", test))]
+#[allow(missing_docs)]
pub mod tests {
use crate::{DispatchResult, DispatchError, LazyValue, Config};
@@ -2456,7 +2457,7 @@
}
#[rustfmt::skip]
- pub const table: [TestCase; 16] = [
+ pub const TABLE: [TestCase; 16] = [
// ┌╴collection_admin
// │ ┌╴is_collection_admin
// │ │ ┌╴token_owner
pallets/evm-coder-substrate/src/lib.rsdiffbeforeafterboth--- a/pallets/evm-coder-substrate/src/lib.rs
+++ b/pallets/evm-coder-substrate/src/lib.rs
@@ -286,7 +286,14 @@
{
let call = C::parse_full(input)?;
if call.is_none() {
- return Err("unrecognized selector".into());
+ let selector = if input.len() >= 4 {
+ let mut selector = [0; 4];
+ selector.copy_from_slice(&input[..4]);
+ u32::from_be_bytes(selector)
+ } else {
+ 0
+ };
+ return Err(format!("unrecognized selector: 0x{selector:0>8x}").into());
}
let call = call.unwrap();
@@ -329,7 +336,7 @@
ERC165Call(ERC165Call, PhantomData<fn() -> T>),
OtherCall(ERC165Call),
- #[weight(Weight::from_ref_time(a + b))]
+ #[weight(Weight::from_parts(a + b, 0))]
Example {
a: u64,
b: u64,
pallets/fungible/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/fungible/src/benchmarking.rs
+++ b/pallets/fungible/src/benchmarking.rs
@@ -53,7 +53,7 @@
let data = (0..b).map(|i| {
bench_init!(to: cross_sub(i););
(to, 200)
- }).collect::<BTreeMap<_, _>>().try_into().unwrap();
+ }).collect::<BTreeMap<_, _>>();
}: {<Pallet<T>>::create_multiple_items(&collection, &sender, data, &Unlimited)?}
burn_item {
pallets/identity/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/identity/src/benchmarking.rs
+++ b/pallets/identity/src/benchmarking.rs
@@ -35,6 +35,7 @@
//! Identity pallet benchmarking.
#![cfg(feature = "runtime-benchmarks")]
+#![allow(clippy::no_effect)]
use super::*;
pallets/identity/src/tests.rsdiffbeforeafterboth--- a/pallets/identity/src/tests.rs
+++ b/pallets/identity/src/tests.rs
@@ -67,7 +67,7 @@
parameter_types! {
pub BlockWeights: frame_system::limits::BlockWeights =
- frame_system::limits::BlockWeights::simple_max(frame_support::weights::Weight::from_ref_time(1024));
+ frame_system::limits::BlockWeights::simple_max(frame_support::weights::Weight::from_parts(1024, 0));
}
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::Everything;
pallets/identity/src/types.rsdiffbeforeafterboth--- a/pallets/identity/src/types.rs
+++ b/pallets/identity/src/types.rs
@@ -481,7 +481,7 @@
let mut registry = scale_info::Registry::new();
let type_id = registry.register_type(&scale_info::meta_type::<Data>());
let registry: scale_info::PortableRegistry = registry.into();
- let type_info = registry.resolve(type_id.id()).unwrap();
+ let type_info = registry.resolve(type_id.id).unwrap();
let check_type_info = |data: &Data| {
let variant_name = match data {
@@ -492,20 +492,20 @@
Data::ShaThree256(_) => "ShaThree256".to_string(),
Data::Raw(bytes) => format!("Raw{}", bytes.len()),
};
- if let scale_info::TypeDef::Variant(variant) = type_info.type_def() {
+ if let scale_info::TypeDef::Variant(variant) = &type_info.type_def {
let variant = variant
- .variants()
+ .variants
.iter()
- .find(|v| v.name() == &variant_name)
+ .find(|v| v.name == variant_name)
.expect(&format!("Expected to find variant {}", variant_name));
let field_arr_len = variant
- .fields()
+ .fields
.first()
- .and_then(|f| registry.resolve(f.ty().id()))
+ .and_then(|f| registry.resolve(f.ty.id))
.map(|ty| {
- if let scale_info::TypeDef::Array(arr) = ty.type_def() {
- arr.len()
+ if let scale_info::TypeDef::Array(arr) = &ty.type_def {
+ arr.len
} else {
panic!("Should be an array type")
}
@@ -513,7 +513,7 @@
.unwrap_or(0);
let encoded = data.encode();
- assert_eq!(encoded[0], variant.index());
+ assert_eq!(encoded[0], variant.index);
assert_eq!(encoded.len() as u32 - 1, field_arr_len);
} else {
panic!("Should be a variant type")
pallets/inflation/src/tests.rsdiffbeforeafterboth--- a/pallets/inflation/src/tests.rs
+++ b/pallets/inflation/src/tests.rs
@@ -78,7 +78,7 @@
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub BlockWeights: frame_system::limits::BlockWeights =
- frame_system::limits::BlockWeights::simple_max(Weight::from_ref_time(1024));
+ frame_system::limits::BlockWeights::simple_max(Weight::from_parts(1024, 0));
pub const SS58Prefix: u8 = 42;
}
pallets/nonfungible/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/benchmarking.rs
+++ b/pallets/nonfungible/src/benchmarking.rs
@@ -43,12 +43,12 @@
owner: T::CrossAccountId,
) -> Result<TokenId, DispatchError> {
<Pallet<T>>::create_item(
- &collection,
+ collection,
sender,
create_max_item_data::<T>(owner),
&Unlimited,
)?;
- Ok(TokenId(<TokensMinted<T>>::get(&collection.id)))
+ Ok(TokenId(<TokensMinted<T>>::get(collection.id)))
}
fn create_collection<T: Config>(
pallets/refungible/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/refungible/src/benchmarking.rs
+++ b/pallets/refungible/src/benchmarking.rs
@@ -51,8 +51,8 @@
users: impl IntoIterator<Item = (T::CrossAccountId, u128)>,
) -> Result<TokenId, DispatchError> {
let data: CreateItemData<T> = create_max_item_data::<T>(users);
- <Pallet<T>>::create_item(&collection, sender, data, &Unlimited)?;
- Ok(TokenId(<TokensMinted<T>>::get(&collection.id)))
+ <Pallet<T>>::create_item(collection, sender, data, &Unlimited)?;
+ Ok(TokenId(<TokensMinted<T>>::get(collection.id)))
}
fn create_collection<T: Config>(
@@ -104,7 +104,7 @@
let data = vec![create_max_item_data::<T>((0..b).map(|u| {
bench_init!(to: cross_sub(u););
(to, 200)
- }))].try_into().unwrap();
+ }))];
}: {<Pallet<T>>::create_multiple_items(&collection, &sender, data, &Unlimited)?}
// Other user left, token data is kept
pallets/scheduler-v2/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/scheduler-v2/src/benchmarking.rs
+++ b/pallets/scheduler-v2/src/benchmarking.rs
@@ -83,11 +83,11 @@
///
/// # Arguments
/// * `periodic` - makes the task periodic.
-/// Sets the task's period and repetition count to `100`.
+/// Sets the task's period and repetition count to `100`.
/// * `named` - gives a name to the task: `u32_to_name(0)`.
/// * `signed` - determines the origin of the task.
-/// If true, it will have the Signed origin. Otherwise it will have the Root origin.
-/// See [`make_origin`] for details.
+/// If true, it will have the Signed origin. Otherwise it will have the Root origin.
+/// See [`make_origin`] for details.
/// * maybe_lookup_len - sets optional lookup length. It is used to benchmark task fetching from the `Preimages` store.
/// * priority - the task's priority.
fn make_task<T: Config>(
@@ -155,12 +155,10 @@
}
if maybe_lookup_len.is_some() {
len += 1;
+ } else if len > 0 {
+ len -= 1;
} else {
- if len > 0 {
- len -= 1;
- } else {
- break c;
- }
+ break c;
}
}
}
pallets/scheduler-v2/src/mock.rsdiffbeforeafterboth--- a/pallets/scheduler-v2/src/mock.rs
+++ b/pallets/scheduler-v2/src/mock.rs
@@ -33,6 +33,7 @@
// limitations under the License.
//! # Scheduler test environment.
+#![allow(deprecated)]
use super::*;
@@ -229,6 +230,10 @@
r => Err(O::from(r)),
})
}
+ #[cfg(feature = "runtime-benchmarks")]
+ fn try_successful_origin() -> Result<O, ()> {
+ Ok(O::from(RawOrigin::Root))
+ }
}
pub struct Executor;
pallets/scheduler-v2/src/tests.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617// Original license:18// This file is part of Substrate.1920// Copyright (C) 2017-2022 Parity Technologies (UK) Ltd.21// SPDX-License-Identifier: Apache-2.02223// Licensed under the Apache License, Version 2.0 (the "License");24// you may not use this file except in compliance with the License.25// You may obtain a copy of the License at26//27// http://www.apache.org/licenses/LICENSE-2.028//29// Unless required by applicable law or agreed to in writing, software30// distributed under the License is distributed on an "AS IS" BASIS,31// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.32// See the License for the specific language governing permissions and33// limitations under the License.3435//! # Scheduler tests.3637use super::*;38use crate::mock::{39 logger, new_test_ext, root, run_to_block, LoggerCall, RuntimeCall, Scheduler, Test, *,40};41use frame_support::{42 assert_noop, assert_ok,43 traits::{Contains, OnInitialize},44 assert_err,45};4647#[test]48fn basic_scheduling_works() {49 new_test_ext().execute_with(|| {50 let call = RuntimeCall::Logger(LoggerCall::log {51 i: 42,52 weight: Weight::from_ref_time(10),53 });54 assert!(!<Test as frame_system::Config>::BaseCallFilter::contains(55 &call56 ));57 assert_ok!(Scheduler::do_schedule(58 DispatchTime::At(4),59 None,60 127,61 root(),62 <ScheduledCall<Test>>::new(call).unwrap(),63 ));64 run_to_block(3);65 assert!(logger::log().is_empty());66 run_to_block(4);67 assert_eq!(logger::log(), vec![(root(), 42u32)]);68 run_to_block(100);69 assert_eq!(logger::log(), vec![(root(), 42u32)]);70 });71}7273#[test]74fn schedule_after_works() {75 new_test_ext().execute_with(|| {76 run_to_block(2);77 let call = RuntimeCall::Logger(LoggerCall::log {78 i: 42,79 weight: Weight::from_ref_time(10),80 });81 assert!(!<Test as frame_system::Config>::BaseCallFilter::contains(82 &call83 ));84 // This will schedule the call 3 blocks after the next block... so block 3 + 3 = 685 assert_ok!(Scheduler::do_schedule(86 DispatchTime::After(3),87 None,88 127,89 root(),90 <ScheduledCall<Test>>::new(call).unwrap(),91 ));92 run_to_block(5);93 assert!(logger::log().is_empty());94 run_to_block(6);95 assert_eq!(logger::log(), vec![(root(), 42u32)]);96 run_to_block(100);97 assert_eq!(logger::log(), vec![(root(), 42u32)]);98 });99}100101#[test]102fn schedule_after_zero_works() {103 new_test_ext().execute_with(|| {104 run_to_block(2);105 let call = RuntimeCall::Logger(LoggerCall::log {106 i: 42,107 weight: Weight::from_ref_time(10),108 });109 assert!(!<Test as frame_system::Config>::BaseCallFilter::contains(110 &call111 ));112 assert_ok!(Scheduler::do_schedule(113 DispatchTime::After(0),114 None,115 127,116 root(),117 <ScheduledCall<Test>>::new(call).unwrap(),118 ));119 // Will trigger on the next block.120 run_to_block(3);121 assert_eq!(logger::log(), vec![(root(), 42u32)]);122 run_to_block(100);123 assert_eq!(logger::log(), vec![(root(), 42u32)]);124 });125}126127#[test]128fn periodic_scheduling_works() {129 new_test_ext().execute_with(|| {130 // at #4, every 3 blocks, 3 times.131 assert_ok!(Scheduler::do_schedule(132 DispatchTime::At(4),133 Some((3, 3)),134 127,135 root(),136 <ScheduledCall<Test>>::new(RuntimeCall::Logger(logger::Call::log {137 i: 42,138 weight: Weight::from_ref_time(10)139 }))140 .unwrap()141 ));142 run_to_block(3);143 assert!(logger::log().is_empty());144 run_to_block(4);145 assert_eq!(logger::log(), vec![(root(), 42u32)]);146 run_to_block(6);147 assert_eq!(logger::log(), vec![(root(), 42u32)]);148 run_to_block(7);149 assert_eq!(logger::log(), vec![(root(), 42u32), (root(), 42u32)]);150 run_to_block(9);151 assert_eq!(logger::log(), vec![(root(), 42u32), (root(), 42u32)]);152 run_to_block(10);153 assert_eq!(154 logger::log(),155 vec![(root(), 42u32), (root(), 42u32), (root(), 42u32)]156 );157 run_to_block(100);158 assert_eq!(159 logger::log(),160 vec![(root(), 42u32), (root(), 42u32), (root(), 42u32)]161 );162 });163}164165#[test]166fn cancel_named_scheduling_works_with_normal_cancel() {167 new_test_ext().execute_with(|| {168 // at #4.169 Scheduler::do_schedule_named(170 [1u8; 32],171 DispatchTime::At(4),172 None,173 127,174 root(),175 <ScheduledCall<Test>>::new(RuntimeCall::Logger(LoggerCall::log {176 i: 69,177 weight: Weight::from_ref_time(10),178 }))179 .unwrap(),180 )181 .unwrap();182 let i = Scheduler::do_schedule(183 DispatchTime::At(4),184 None,185 127,186 root(),187 <ScheduledCall<Test>>::new(RuntimeCall::Logger(LoggerCall::log {188 i: 42,189 weight: Weight::from_ref_time(10),190 }))191 .unwrap(),192 )193 .unwrap();194 run_to_block(3);195 assert!(logger::log().is_empty());196 assert_ok!(Scheduler::do_cancel_named(None, [1u8; 32]));197 assert_ok!(Scheduler::do_cancel(None, i));198 run_to_block(100);199 assert!(logger::log().is_empty());200 });201}202203#[test]204fn cancel_named_periodic_scheduling_works() {205 new_test_ext().execute_with(|| {206 // at #4, every 3 blocks, 3 times.207 Scheduler::do_schedule_named(208 [1u8; 32],209 DispatchTime::At(4),210 Some((3, 3)),211 127,212 root(),213 <ScheduledCall<Test>>::new(RuntimeCall::Logger(LoggerCall::log {214 i: 42,215 weight: Weight::from_ref_time(10),216 }))217 .unwrap(),218 )219 .unwrap();220 // same id results in error.221 assert!(Scheduler::do_schedule_named(222 [1u8; 32],223 DispatchTime::At(4),224 None,225 127,226 root(),227 <ScheduledCall<Test>>::new(RuntimeCall::Logger(LoggerCall::log {228 i: 69,229 weight: Weight::from_ref_time(10)230 }))231 .unwrap(),232 )233 .is_err());234 // different id is ok.235 Scheduler::do_schedule_named(236 [2u8; 32],237 DispatchTime::At(8),238 None,239 127,240 root(),241 <ScheduledCall<Test>>::new(RuntimeCall::Logger(LoggerCall::log {242 i: 69,243 weight: Weight::from_ref_time(10),244 }))245 .unwrap(),246 )247 .unwrap();248 run_to_block(3);249 assert!(logger::log().is_empty());250 run_to_block(4);251 assert_eq!(logger::log(), vec![(root(), 42u32)]);252 run_to_block(6);253 assert_ok!(Scheduler::do_cancel_named(None, [1u8; 32]));254 run_to_block(100);255 assert_eq!(logger::log(), vec![(root(), 42u32), (root(), 69u32)]);256 });257}258259#[test]260fn scheduler_respects_weight_limits() {261 let max_weight: Weight = <Test as Config>::MaximumWeight::get();262 new_test_ext().execute_with(|| {263 let call = RuntimeCall::Logger(LoggerCall::log {264 i: 42,265 weight: max_weight / 3 * 2,266 });267 assert_ok!(Scheduler::do_schedule(268 DispatchTime::At(4),269 None,270 127,271 root(),272 <ScheduledCall<Test>>::new(call).unwrap(),273 ));274 let call = RuntimeCall::Logger(LoggerCall::log {275 i: 69,276 weight: max_weight / 3 * 2,277 });278 assert_ok!(Scheduler::do_schedule(279 DispatchTime::At(4),280 None,281 127,282 root(),283 <ScheduledCall<Test>>::new(call).unwrap(),284 ));285 // 69 and 42 do not fit together286 run_to_block(4);287 assert_eq!(logger::log(), vec![(root(), 42u32)]);288 run_to_block(5);289 assert_eq!(logger::log(), vec![(root(), 42u32), (root(), 69u32)]);290 });291}292293/// Permanently overweight calls are not deleted but also not executed.294#[test]295fn scheduler_does_not_delete_permanently_overweight_call() {296 let max_weight: Weight = <Test as Config>::MaximumWeight::get();297 new_test_ext().execute_with(|| {298 let call = RuntimeCall::Logger(LoggerCall::log {299 i: 42,300 weight: max_weight,301 });302 assert_ok!(Scheduler::do_schedule(303 DispatchTime::At(4),304 None,305 127,306 root(),307 <ScheduledCall<Test>>::new(call).unwrap(),308 ));309 // Never executes.310 run_to_block(100);311 assert_eq!(logger::log(), vec![]);312313 // Assert the `PermanentlyOverweight` event.314 assert_eq!(315 System::events().last().unwrap().event,316 crate::Event::PermanentlyOverweight {317 task: (4, 0),318 id: None319 }320 .into(),321 );322 // The call is still in the agenda.323 assert!(Agenda::<Test>::get(4).agenda[0].is_some());324 });325}326327#[test]328fn scheduler_periodic_tasks_always_find_place() {329 let max_weight: Weight = <Test as Config>::MaximumWeight::get();330 let max_per_block = <Test as Config>::MaxScheduledPerBlock::get();331332 new_test_ext().execute_with(|| {333 let call = RuntimeCall::Logger(LoggerCall::log {334 i: 42,335 weight: (max_weight / 3) * 2,336 });337 let call = <ScheduledCall<Test>>::new(call).unwrap();338339 assert_ok!(Scheduler::do_schedule(340 DispatchTime::At(4),341 Some((4, u32::MAX)),342 127,343 root(),344 call.clone(),345 ));346 // Executes 5 times till block 20.347 run_to_block(20);348 assert_eq!(logger::log().len(), 5);349350 // Block 28 will already be full.351 for _ in 0..max_per_block {352 assert_ok!(Scheduler::do_schedule(353 DispatchTime::At(28),354 None,355 120,356 root(),357 call.clone(),358 ));359 }360361 run_to_block(24);362 assert_eq!(logger::log().len(), 6);363364 // The periodic task should be postponed365 assert_eq!(<Agenda<Test>>::get(29).agenda.len(), 1);366367 run_to_block(27); // will call on_initialize(28)368 assert_eq!(logger::log().len(), 6);369370 run_to_block(28); // will call on_initialize(29)371 assert_eq!(logger::log().len(), 7);372 });373}374375#[test]376fn scheduler_respects_priority_ordering() {377 let max_weight: Weight = <Test as Config>::MaximumWeight::get();378 new_test_ext().execute_with(|| {379 let call = RuntimeCall::Logger(LoggerCall::log {380 i: 42,381 weight: max_weight / 3,382 });383 assert_ok!(Scheduler::do_schedule(384 DispatchTime::At(4),385 None,386 1,387 root(),388 <ScheduledCall<Test>>::new(call).unwrap(),389 ));390 let call = RuntimeCall::Logger(LoggerCall::log {391 i: 69,392 weight: max_weight / 3,393 });394 assert_ok!(Scheduler::do_schedule(395 DispatchTime::At(4),396 None,397 0,398 root(),399 <ScheduledCall<Test>>::new(call).unwrap(),400 ));401 run_to_block(4);402 assert_eq!(logger::log(), vec![(root(), 69u32), (root(), 42u32)]);403 });404}405406#[test]407fn scheduler_respects_priority_ordering_with_soft_deadlines() {408 new_test_ext().execute_with(|| {409 let max_weight: Weight = <Test as Config>::MaximumWeight::get();410 let call = RuntimeCall::Logger(LoggerCall::log {411 i: 42,412 weight: max_weight / 5 * 2,413 });414 assert_ok!(Scheduler::do_schedule(415 DispatchTime::At(4),416 None,417 255,418 root(),419 <ScheduledCall<Test>>::new(call).unwrap(),420 ));421 let call = RuntimeCall::Logger(LoggerCall::log {422 i: 69,423 weight: max_weight / 5 * 2,424 });425 assert_ok!(Scheduler::do_schedule(426 DispatchTime::At(4),427 None,428 127,429 root(),430 <ScheduledCall<Test>>::new(call).unwrap(),431 ));432 let call = RuntimeCall::Logger(LoggerCall::log {433 i: 2600,434 weight: max_weight / 5 * 4,435 });436 assert_ok!(Scheduler::do_schedule(437 DispatchTime::At(4),438 None,439 126,440 root(),441 <ScheduledCall<Test>>::new(call).unwrap(),442 ));443444 // 2600 does not fit with 69 or 42, but has higher priority, so will go through445 run_to_block(4);446 assert_eq!(logger::log(), vec![(root(), 2600u32)]);447 // 69 and 42 fit together448 run_to_block(5);449 assert_eq!(450 logger::log(),451 vec![(root(), 2600u32), (root(), 69u32), (root(), 42u32)]452 );453 });454}455456#[test]457fn on_initialize_weight_is_correct() {458 new_test_ext().execute_with(|| {459 let call_weight = Weight::from_ref_time(25);460461 // Named462 let call = RuntimeCall::Logger(LoggerCall::log {463 i: 3,464 weight: call_weight + Weight::from_ref_time(1),465 });466 assert_ok!(Scheduler::do_schedule_named(467 [1u8; 32],468 DispatchTime::At(3),469 None,470 255,471 root(),472 <ScheduledCall<Test>>::new(call).unwrap(),473 ));474 let call = RuntimeCall::Logger(LoggerCall::log {475 i: 42,476 weight: call_weight + Weight::from_ref_time(2),477 });478 // Anon Periodic479 assert_ok!(Scheduler::do_schedule(480 DispatchTime::At(2),481 Some((1000, 3)),482 128,483 root(),484 <ScheduledCall<Test>>::new(call).unwrap(),485 ));486 let call = RuntimeCall::Logger(LoggerCall::log {487 i: 69,488 weight: call_weight + Weight::from_ref_time(3),489 });490 // Anon491 assert_ok!(Scheduler::do_schedule(492 DispatchTime::At(2),493 None,494 127,495 root(),496 <ScheduledCall<Test>>::new(call).unwrap(),497 ));498 // Named Periodic499 let call = RuntimeCall::Logger(LoggerCall::log {500 i: 2600,501 weight: call_weight + Weight::from_ref_time(4),502 });503 assert_ok!(Scheduler::do_schedule_named(504 [2u8; 32],505 DispatchTime::At(1),506 Some((1000, 3)),507 126,508 root(),509 <ScheduledCall<Test>>::new(call).unwrap(),510 ));511512 // Will include the named periodic only513 assert_eq!(514 Scheduler::on_initialize(1),515 TestWeightInfo::service_agendas_base()516 + TestWeightInfo::service_agenda_base(1)517 + <MarginalWeightInfo<Test>>::service_task(None, true, true)518 + TestWeightInfo::execute_dispatch_unsigned()519 + call_weight + Weight::from_ref_time(4)520 );521 assert_eq!(IncompleteSince::<Test>::get(), None);522 assert_eq!(logger::log(), vec![(root(), 2600u32)]);523524 // Will include anon and anon periodic525 assert_eq!(526 Scheduler::on_initialize(2),527 TestWeightInfo::service_agendas_base()528 + TestWeightInfo::service_agenda_base(2)529 + <MarginalWeightInfo<Test>>::service_task(None, false, true)530 + TestWeightInfo::execute_dispatch_unsigned()531 + call_weight + Weight::from_ref_time(3)532 + <MarginalWeightInfo<Test>>::service_task(None, false, false)533 + TestWeightInfo::execute_dispatch_unsigned()534 + call_weight + Weight::from_ref_time(2)535 );536 assert_eq!(IncompleteSince::<Test>::get(), None);537 assert_eq!(538 logger::log(),539 vec![(root(), 2600u32), (root(), 69u32), (root(), 42u32)]540 );541542 // Will include named only543 assert_eq!(544 Scheduler::on_initialize(3),545 TestWeightInfo::service_agendas_base()546 + TestWeightInfo::service_agenda_base(1)547 + <MarginalWeightInfo<Test>>::service_task(None, true, false)548 + TestWeightInfo::execute_dispatch_unsigned()549 + call_weight + Weight::from_ref_time(1)550 );551 assert_eq!(IncompleteSince::<Test>::get(), None);552 assert_eq!(553 logger::log(),554 vec![555 (root(), 2600u32),556 (root(), 69u32),557 (root(), 42u32),558 (root(), 3u32)559 ]560 );561562 // Will contain none563 let actual_weight = Scheduler::on_initialize(4);564 assert_eq!(565 actual_weight,566 TestWeightInfo::service_agendas_base() + TestWeightInfo::service_agenda_base(0)567 );568 });569}570571#[test]572fn root_calls_works() {573 new_test_ext().execute_with(|| {574 let call = Box::new(RuntimeCall::Logger(LoggerCall::log {575 i: 69,576 weight: Weight::from_ref_time(10),577 }));578 let call2 = Box::new(RuntimeCall::Logger(LoggerCall::log {579 i: 42,580 weight: Weight::from_ref_time(10),581 }));582 assert_ok!(Scheduler::schedule_named(583 RuntimeOrigin::root(),584 [1u8; 32],585 4,586 None,587 Some(127),588 call,589 ));590 assert_ok!(Scheduler::schedule(591 RuntimeOrigin::root(),592 4,593 None,594 Some(127),595 call2596 ));597 run_to_block(3);598 // Scheduled calls are in the agenda.599 assert_eq!(Agenda::<Test>::get(4).agenda.len(), 2);600 assert!(logger::log().is_empty());601 assert_ok!(Scheduler::cancel_named(RuntimeOrigin::root(), [1u8; 32]));602 assert_ok!(Scheduler::cancel(RuntimeOrigin::root(), 4, 1));603 // Scheduled calls are made NONE, so should not effect state604 run_to_block(100);605 assert!(logger::log().is_empty());606 });607}608609#[test]610fn fails_to_schedule_task_in_the_past() {611 new_test_ext().execute_with(|| {612 run_to_block(3);613614 let call1 = Box::new(RuntimeCall::Logger(LoggerCall::log {615 i: 69,616 weight: Weight::from_ref_time(10),617 }));618 let call2 = Box::new(RuntimeCall::Logger(LoggerCall::log {619 i: 42,620 weight: Weight::from_ref_time(10),621 }));622 let call3 = Box::new(RuntimeCall::Logger(LoggerCall::log {623 i: 42,624 weight: Weight::from_ref_time(10),625 }));626627 assert_noop!(628 Scheduler::schedule_named(RuntimeOrigin::root(), [1u8; 32], 2, None, Some(127), call1),629 Error::<Test>::TargetBlockNumberInPast,630 );631632 assert_noop!(633 Scheduler::schedule(RuntimeOrigin::root(), 2, None, Some(127), call2),634 Error::<Test>::TargetBlockNumberInPast,635 );636637 assert_noop!(638 Scheduler::schedule(RuntimeOrigin::root(), 3, None, Some(127), call3),639 Error::<Test>::TargetBlockNumberInPast,640 );641 });642}643644#[test]645fn should_use_origin() {646 new_test_ext().execute_with(|| {647 let call = Box::new(RuntimeCall::Logger(LoggerCall::log {648 i: 69,649 weight: Weight::from_ref_time(10),650 }));651 let call2 = Box::new(RuntimeCall::Logger(LoggerCall::log {652 i: 42,653 weight: Weight::from_ref_time(10),654 }));655 assert_ok!(Scheduler::schedule_named(656 system::RawOrigin::Signed(1).into(),657 [1u8; 32],658 4,659 None,660 None,661 call,662 ));663 assert_ok!(Scheduler::schedule(664 system::RawOrigin::Signed(1).into(),665 4,666 None,667 None,668 call2,669 ));670 run_to_block(3);671 // Scheduled calls are in the agenda.672 assert_eq!(Agenda::<Test>::get(4).agenda.len(), 2);673 assert!(logger::log().is_empty());674 assert_ok!(Scheduler::cancel_named(675 system::RawOrigin::Signed(1).into(),676 [1u8; 32]677 ));678 assert_ok!(Scheduler::cancel(system::RawOrigin::Signed(1).into(), 4, 1));679 // Scheduled calls are made NONE, so should not effect state680 run_to_block(100);681 assert!(logger::log().is_empty());682 });683}684685#[test]686fn should_check_origin() {687 new_test_ext().execute_with(|| {688 let call = Box::new(RuntimeCall::Logger(LoggerCall::log {689 i: 69,690 weight: Weight::from_ref_time(10),691 }));692 let call2 = Box::new(RuntimeCall::Logger(LoggerCall::log {693 i: 42,694 weight: Weight::from_ref_time(10),695 }));696 assert_noop!(697 Scheduler::schedule_named(698 system::RawOrigin::Signed(2).into(),699 [1u8; 32],700 4,701 None,702 None,703 call704 ),705 BadOrigin706 );707 assert_noop!(708 Scheduler::schedule(system::RawOrigin::Signed(2).into(), 4, None, None, call2),709 BadOrigin710 );711 });712}713714#[test]715fn should_check_origin_for_cancel() {716 new_test_ext().execute_with(|| {717 let call = Box::new(RuntimeCall::Logger(LoggerCall::log_without_filter {718 i: 69,719 weight: Weight::from_ref_time(10),720 }));721 let call2 = Box::new(RuntimeCall::Logger(LoggerCall::log_without_filter {722 i: 42,723 weight: Weight::from_ref_time(10),724 }));725 assert_ok!(Scheduler::schedule_named(726 system::RawOrigin::Signed(1).into(),727 [1u8; 32],728 4,729 None,730 None,731 call,732 ));733 assert_ok!(Scheduler::schedule(734 system::RawOrigin::Signed(1).into(),735 4,736 None,737 None,738 call2,739 ));740 run_to_block(3);741 // Scheduled calls are in the agenda.742 assert_eq!(Agenda::<Test>::get(4).agenda.len(), 2);743 assert!(logger::log().is_empty());744 assert_noop!(745 Scheduler::cancel_named(system::RawOrigin::Signed(2).into(), [1u8; 32]),746 BadOrigin747 );748 assert_noop!(749 Scheduler::cancel(system::RawOrigin::Signed(2).into(), 4, 1),750 BadOrigin751 );752 assert_noop!(753 Scheduler::cancel_named(system::RawOrigin::Root.into(), [1u8; 32]),754 BadOrigin755 );756 assert_noop!(757 Scheduler::cancel(system::RawOrigin::Root.into(), 4, 1),758 BadOrigin759 );760 run_to_block(5);761 assert_eq!(762 logger::log(),763 vec![764 (system::RawOrigin::Signed(1).into(), 69u32),765 (system::RawOrigin::Signed(1).into(), 42u32)766 ]767 );768 });769}770771/// Cancelling a call and then scheduling a second call for the same772/// block results in different addresses.773#[test]774fn schedule_does_not_resuse_addr() {775 new_test_ext().execute_with(|| {776 let call = RuntimeCall::Logger(LoggerCall::log {777 i: 42,778 weight: Weight::from_ref_time(10),779 });780781 // Schedule both calls.782 let addr_1 = Scheduler::do_schedule(783 DispatchTime::At(4),784 None,785 127,786 root(),787 <ScheduledCall<Test>>::new(call.clone()).unwrap(),788 )789 .unwrap();790 // Cancel the call.791 assert_ok!(Scheduler::do_cancel(None, addr_1));792 let addr_2 = Scheduler::do_schedule(793 DispatchTime::At(4),794 None,795 127,796 root(),797 <ScheduledCall<Test>>::new(call).unwrap(),798 )799 .unwrap();800801 // Should not re-use the address.802 assert!(addr_1 != addr_2);803 });804}805806#[test]807fn schedule_agenda_overflows() {808 let max: u32 = <Test as Config>::MaxScheduledPerBlock::get();809810 new_test_ext().execute_with(|| {811 let call = RuntimeCall::Logger(LoggerCall::log {812 i: 42,813 weight: Weight::from_ref_time(10),814 });815 let call = <ScheduledCall<Test>>::new(call).unwrap();816817 // Schedule the maximal number allowed per block.818 for _ in 0..max {819 Scheduler::do_schedule(DispatchTime::At(4), None, 127, root(), call.clone()).unwrap();820 }821822 // One more time and it errors.823 assert_noop!(824 Scheduler::do_schedule(DispatchTime::At(4), None, 127, root(), call,),825 <Error<Test>>::AgendaIsExhausted,826 );827828 run_to_block(4);829 // All scheduled calls are executed.830 assert_eq!(logger::log().len() as u32, max);831 });832}833834/// Cancelling and scheduling does not overflow the agenda but fills holes.835#[test]836fn cancel_and_schedule_fills_holes() {837 let max: u32 = <Test as Config>::MaxScheduledPerBlock::get();838 assert!(839 max > 3,840 "This test only makes sense for MaxScheduledPerBlock > 3"841 );842843 new_test_ext().execute_with(|| {844 let call = RuntimeCall::Logger(LoggerCall::log {845 i: 42,846 weight: Weight::from_ref_time(10),847 });848 let call = <ScheduledCall<Test>>::new(call).unwrap();849 let mut addrs = Vec::<_>::default();850851 // Schedule the maximal number allowed per block.852 for _ in 0..max {853 addrs.push(854 Scheduler::do_schedule(DispatchTime::At(4), None, 127, root(), call.clone())855 .unwrap(),856 );857 }858 // Cancel three of them.859 for addr in addrs.into_iter().take(3) {860 Scheduler::do_cancel(None, addr).unwrap();861 }862 // Schedule three new ones.863 for i in 0..3 {864 let (_block, index) =865 Scheduler::do_schedule(DispatchTime::At(4), None, 127, root(), call.clone())866 .unwrap();867 assert_eq!(i, index);868 }869870 run_to_block(4);871 // Maximum number of calls are executed.872 assert_eq!(logger::log().len() as u32, max);873 });874}875876#[test]877fn cannot_schedule_too_big_tasks() {878 new_test_ext().execute_with(|| {879 let call = Box::new(<<Test as Config>::RuntimeCall>::from(SystemCall::remark {880 remark: vec![0; EncodedCall::bound() - 4],881 }));882883 assert_ok!(Scheduler::schedule(884 RuntimeOrigin::root(),885 4,886 None,887 Some(127),888 call889 ));890891 let call = Box::new(<<Test as Config>::RuntimeCall>::from(SystemCall::remark {892 remark: vec![0; EncodedCall::bound() - 3],893 }));894895 assert_err!(896 Scheduler::schedule(RuntimeOrigin::root(), 4, None, Some(127), call),897 <Error<Test>>::TooBigScheduledCall898 );899 });900}pallets/structure/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/structure/src/benchmarking.rs
+++ b/pallets/structure/src/benchmarking.rs
@@ -19,8 +19,7 @@
use frame_benchmarking::{benchmarks, account};
use frame_support::traits::{fungible::Balanced, Get, tokens::Precision};
use up_data_structs::{
- CreateCollectionData, CollectionMode, CreateItemData, CollectionFlags, CreateNftData,
- budget::Unlimited,
+ CreateCollectionData, CollectionMode, CreateItemData, CreateNftData, budget::Unlimited,
};
use pallet_common::Config as CommonConfig;
use pallet_evm::account::CrossAccountId;
runtime/common/config/pallets/mod.rsdiffbeforeafterboth--- a/runtime/common/config/pallets/mod.rs
+++ b/runtime/common/config/pallets/mod.rs
@@ -24,8 +24,7 @@
weights::CommonWeights,
RelayChainBlockNumberProvider,
},
- Runtime, RuntimeEvent, RuntimeCall, RUNTIME_NAME, TOKEN_SYMBOL, DECIMALS,
- Balances,
+ Runtime, RuntimeEvent, RuntimeCall, RUNTIME_NAME, TOKEN_SYMBOL, DECIMALS, Balances,
};
use frame_support::traits::{ConstU32, ConstU64, Currency};
use up_common::{
runtime/common/ethereum/sponsoring.rsdiffbeforeafterboth--- a/runtime/common/ethereum/sponsoring.rs
+++ b/runtime/common/ethereum/sponsoring.rs
@@ -161,7 +161,8 @@
}
}
CollectionMode::ReFungible => {
- let call = <UniqueRefungibleCall<T>>::parse_full(&call_context.input).ok()??;
+ let call =
+ <UniqueRefungibleCall<T>>::parse_full(&call_context.input).ok()??;
refungible::call_sponsor(call, collection, who).map(|()| sponsor)
}
CollectionMode::Fungible(_) => {
runtime/common/tests/mod.rsdiffbeforeafterboth--- a/runtime/common/tests/mod.rs
+++ b/runtime/common/tests/mod.rs
@@ -16,7 +16,6 @@
use sp_runtime::{BuildStorage, Storage};
use sp_core::{Public, Pair};
-use sp_std::vec;
use up_common::types::AuraId;
use crate::{Runtime, GenesisConfig, ParachainInfoConfig, RuntimeEvent, System};
@@ -76,7 +75,7 @@
AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()
}
- let accounts = vec!["Alice", "Bob"];
+ let accounts = ["Alice", "Bob"];
let keys = accounts
.iter()
.map(|&acc| {
@@ -104,7 +103,7 @@
..GenesisConfig::default()
};
- cfg.build_storage().unwrap().into()
+ cfg.build_storage().unwrap()
}
#[cfg(not(feature = "collator-selection"))]
runtime/common/tests/xcm.rsdiffbeforeafterboth--- a/runtime/common/tests/xcm.rs
+++ b/runtime/common/tests/xcm.rs
@@ -26,7 +26,7 @@
const ALICE: AccountId = AccountId::new([0u8; 32]);
const BOB: AccountId = AccountId::new([1u8; 32]);
-const INITIAL_BALANCE: u128 = 1000000000000000000_0000; // 1000 UNQ
+const INITIAL_BALANCE: u128 = 10_000_000_000_000_000_000_000; // 10_000 UNQ
#[test]
pub fn xcm_transact_is_forbidden() {
runtime/tests/Cargo.tomldiffbeforeafterboth--- a/runtime/tests/Cargo.toml
+++ b/runtime/tests/Cargo.toml
@@ -5,7 +5,6 @@
[features]
default = ['refungible']
-tests = ['pallet-common/tests']
refungible = []
@@ -44,3 +43,6 @@
evm-coder = { workspace = true }
up-sponsorship = { workspace = true }
xcm = { workspace = true }
+
+[dev-dependencies]
+pallet-common = { workspace = true, features = ["tests"] }
runtime/tests/src/tests.rsdiffbeforeafterboth--- a/runtime/tests/src/tests.rs
+++ b/runtime/tests/src/tests.rs
@@ -99,7 +99,7 @@
.try_into()
.unwrap();
- let data: CreateCollectionData<u64> = CreateCollectionData {
+ let data = CreateCollectionData {
name: col_name1.try_into().unwrap(),
description: col_desc1.try_into().unwrap(),
token_prefix: token_prefix1.try_into().unwrap(),
@@ -204,14 +204,13 @@
let description: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();
let token_prefix: Vec<u8> = b"token_prefix1\0".to_vec();
- let data: CreateCollectionData<<Test as frame_system::Config>::AccountId> =
- CreateCollectionData {
- name: name.try_into().unwrap(),
- description: description.try_into().unwrap(),
- token_prefix: token_prefix.try_into().unwrap(),
- mode: CollectionMode::NFT,
- ..Default::default()
- };
+ let data = CreateCollectionData {
+ name: name.try_into().unwrap(),
+ description: description.try_into().unwrap(),
+ token_prefix: token_prefix.try_into().unwrap(),
+ mode: CollectionMode::NFT,
+ ..Default::default()
+ };
let result = Unique::create_collection_ex(RuntimeOrigin::signed(acc), data);
assert_err!(result, <CommonError<Test>>::NotSufficientFounds);
@@ -225,7 +224,7 @@
let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();
let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();
- let data: CreateCollectionData<u64> = CreateCollectionData {
+ let data = CreateCollectionData {
name: col_name1.try_into().unwrap(),
description: col_desc1.try_into().unwrap(),
token_prefix: token_prefix1.try_into().unwrap(),
@@ -2364,7 +2363,7 @@
let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();
let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();
- let data: CreateCollectionData<u64> = CreateCollectionData {
+ let data = CreateCollectionData {
name: col_name1.try_into().unwrap(),
description: col_desc1.try_into().unwrap(),
token_prefix: token_prefix1.try_into().unwrap(),
@@ -2618,9 +2617,7 @@
mod check_token_permissions {
use super::*;
- use frame_support::once_cell::sync::Lazy;
use pallet_common::LazyValue;
- use sp_runtime::DispatchError;
fn test<FTE: FnOnce() -> bool>(
i: usize,
@@ -2662,7 +2659,7 @@
fn no_permission_only() {
new_test_ext().execute_with(|| {
let mut check_token_existence = LazyValue::new(|| true);
- for (i, row) in pallet_common::tests::table.iter().enumerate() {
+ for (i, row) in pallet_common::tests::TABLE.iter().enumerate() {
test(i, row, &mut check_token_existence);
}
});
@@ -2671,7 +2668,7 @@
#[test]
fn no_permission_and_token_not_found() {
new_test_ext().execute_with(|| {
- for (i, row) in pallet_common::tests::table.iter().enumerate() {
+ for (i, row) in pallet_common::tests::TABLE.iter().enumerate() {
// This is inside the loop to keep track of whether the lambda was called
let mut check_token_existence = LazyValue::new(|| false);
test(i, row, &mut check_token_existence);
tests/src/createCollection.test.tsdiffbeforeafterboth--- a/tests/src/createCollection.test.ts
+++ b/tests/src/createCollection.test.ts
@@ -106,15 +106,17 @@
flags: [CollectionFlag.Erc721metadata],
}, 'nft');
- await mintCollectionHelper(helper, alice, {
+ // User can not set Foreign flag itself
+
+ await expect(mintCollectionHelper(helper, alice, {
name: 'name', description: 'descr', tokenPrefix: 'COL',
flags: [CollectionFlag.Foreign],
- }, 'nft');
+ }, 'nft')).to.be.rejectedWith(/common.NoPermission/);
- await mintCollectionHelper(helper, alice, {
+ await expect(mintCollectionHelper(helper, alice, {
name: 'name', description: 'descr', tokenPrefix: 'COL',
flags: [CollectionFlag.Erc721metadata, CollectionFlag.Foreign],
- }, 'nft');
+ }, 'nft')).to.be.rejectedWith(/common.NoPermission/);
});
itSub('Create new collection with extra fields', async ({helper}) => {
tests/src/eth/collectionLimits.test.tsdiffbeforeafterboth--- a/tests/src/eth/collectionLimits.test.ts
+++ b/tests/src/eth/collectionLimits.test.ts
@@ -106,7 +106,7 @@
// Cannot disable limits
await expect(collectionEvm.methods
- .setCollectionLimit({field: CollectionLimitField.AccountTokenOwnership, value: {status: false, value: 200}})
+ .setCollectionLimit({field: CollectionLimitField.AccountTokenOwnership, value: {status: false, value: 0}})
.call()).to.be.rejectedWith('user can\'t disable limits');
await expect(collectionEvm.methods
tests/src/util/playgrounds/unique.dev.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/unique.dev.ts
+++ b/tests/src/util/playgrounds/unique.dev.ts
@@ -41,7 +41,7 @@
for(const arg of args) {
if(typeof arg !== 'string')
continue;
- const skippedWarnings = ['1000:: Normal connection closure', 'Not decorating unknown runtime apis:', 'RPC methods not decorated:', 'Not decorating runtime apis'];
+ const skippedWarnings = ['1000:: Normal connection closure', 'Not decorating unknown runtime apis:', 'RPC methods not decorated:', 'Not decorating runtime apis', 'Bad input data provided to validate_transaction', 'account balance too low', '1006:: Abnormal Closure'];
const needToSkip = skippedWarnings.reduce((a, b) => a || arg.includes(b), false);
if(needToSkip || arg === 'Normal connection closure')
return;