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.36#![allow(deprecated)]3738use super::*;39use crate::mock::{40 logger, new_test_ext, root, run_to_block, LoggerCall, RuntimeCall, Scheduler, Test, *,41};42use frame_support::{43 assert_noop, assert_ok,44 traits::{Contains, OnInitialize},45 assert_err,46};4748#[test]49fn basic_scheduling_works() {50 new_test_ext().execute_with(|| {51 let call = RuntimeCall::Logger(LoggerCall::log {52 i: 42,53 weight: Weight::from_ref_time(10),54 });55 assert!(!<Test as frame_system::Config>::BaseCallFilter::contains(56 &call57 ));58 assert_ok!(Scheduler::do_schedule(59 DispatchTime::At(4),60 None,61 127,62 root(),63 <ScheduledCall<Test>>::new(call).unwrap(),64 ));65 run_to_block(3);66 assert!(logger::log().is_empty());67 run_to_block(4);68 assert_eq!(logger::log(), vec![(root(), 42u32)]);69 run_to_block(100);70 assert_eq!(logger::log(), vec![(root(), 42u32)]);71 });72}7374#[test]75fn schedule_after_works() {76 new_test_ext().execute_with(|| {77 run_to_block(2);78 let call = RuntimeCall::Logger(LoggerCall::log {79 i: 42,80 weight: Weight::from_ref_time(10),81 });82 assert!(!<Test as frame_system::Config>::BaseCallFilter::contains(83 &call84 ));85 // This will schedule the call 3 blocks after the next block... so block 3 + 3 = 686 assert_ok!(Scheduler::do_schedule(87 DispatchTime::After(3),88 None,89 127,90 root(),91 <ScheduledCall<Test>>::new(call).unwrap(),92 ));93 run_to_block(5);94 assert!(logger::log().is_empty());95 run_to_block(6);96 assert_eq!(logger::log(), vec![(root(), 42u32)]);97 run_to_block(100);98 assert_eq!(logger::log(), vec![(root(), 42u32)]);99 });100}101102#[test]103fn schedule_after_zero_works() {104 new_test_ext().execute_with(|| {105 run_to_block(2);106 let call = RuntimeCall::Logger(LoggerCall::log {107 i: 42,108 weight: Weight::from_ref_time(10),109 });110 assert!(!<Test as frame_system::Config>::BaseCallFilter::contains(111 &call112 ));113 assert_ok!(Scheduler::do_schedule(114 DispatchTime::After(0),115 None,116 127,117 root(),118 <ScheduledCall<Test>>::new(call).unwrap(),119 ));120 // Will trigger on the next block.121 run_to_block(3);122 assert_eq!(logger::log(), vec![(root(), 42u32)]);123 run_to_block(100);124 assert_eq!(logger::log(), vec![(root(), 42u32)]);125 });126}127128#[test]129fn periodic_scheduling_works() {130 new_test_ext().execute_with(|| {131 // at #4, every 3 blocks, 3 times.132 assert_ok!(Scheduler::do_schedule(133 DispatchTime::At(4),134 Some((3, 3)),135 127,136 root(),137 <ScheduledCall<Test>>::new(RuntimeCall::Logger(logger::Call::log {138 i: 42,139 weight: Weight::from_ref_time(10)140 }))141 .unwrap()142 ));143 run_to_block(3);144 assert!(logger::log().is_empty());145 run_to_block(4);146 assert_eq!(logger::log(), vec![(root(), 42u32)]);147 run_to_block(6);148 assert_eq!(logger::log(), vec![(root(), 42u32)]);149 run_to_block(7);150 assert_eq!(logger::log(), vec![(root(), 42u32), (root(), 42u32)]);151 run_to_block(9);152 assert_eq!(logger::log(), vec![(root(), 42u32), (root(), 42u32)]);153 run_to_block(10);154 assert_eq!(155 logger::log(),156 vec![(root(), 42u32), (root(), 42u32), (root(), 42u32)]157 );158 run_to_block(100);159 assert_eq!(160 logger::log(),161 vec![(root(), 42u32), (root(), 42u32), (root(), 42u32)]162 );163 });164}165166#[test]167fn cancel_named_scheduling_works_with_normal_cancel() {168 new_test_ext().execute_with(|| {169 // at #4.170 Scheduler::do_schedule_named(171 [1u8; 32],172 DispatchTime::At(4),173 None,174 127,175 root(),176 <ScheduledCall<Test>>::new(RuntimeCall::Logger(LoggerCall::log {177 i: 69,178 weight: Weight::from_ref_time(10),179 }))180 .unwrap(),181 )182 .unwrap();183 let i = Scheduler::do_schedule(184 DispatchTime::At(4),185 None,186 127,187 root(),188 <ScheduledCall<Test>>::new(RuntimeCall::Logger(LoggerCall::log {189 i: 42,190 weight: Weight::from_ref_time(10),191 }))192 .unwrap(),193 )194 .unwrap();195 run_to_block(3);196 assert!(logger::log().is_empty());197 assert_ok!(Scheduler::do_cancel_named(None, [1u8; 32]));198 assert_ok!(Scheduler::do_cancel(None, i));199 run_to_block(100);200 assert!(logger::log().is_empty());201 });202}203204#[test]205fn cancel_named_periodic_scheduling_works() {206 new_test_ext().execute_with(|| {207 // at #4, every 3 blocks, 3 times.208 Scheduler::do_schedule_named(209 [1u8; 32],210 DispatchTime::At(4),211 Some((3, 3)),212 127,213 root(),214 <ScheduledCall<Test>>::new(RuntimeCall::Logger(LoggerCall::log {215 i: 42,216 weight: Weight::from_ref_time(10),217 }))218 .unwrap(),219 )220 .unwrap();221 // same id results in error.222 assert!(Scheduler::do_schedule_named(223 [1u8; 32],224 DispatchTime::At(4),225 None,226 127,227 root(),228 <ScheduledCall<Test>>::new(RuntimeCall::Logger(LoggerCall::log {229 i: 69,230 weight: Weight::from_ref_time(10)231 }))232 .unwrap(),233 )234 .is_err());235 // different id is ok.236 Scheduler::do_schedule_named(237 [2u8; 32],238 DispatchTime::At(8),239 None,240 127,241 root(),242 <ScheduledCall<Test>>::new(RuntimeCall::Logger(LoggerCall::log {243 i: 69,244 weight: Weight::from_ref_time(10),245 }))246 .unwrap(),247 )248 .unwrap();249 run_to_block(3);250 assert!(logger::log().is_empty());251 run_to_block(4);252 assert_eq!(logger::log(), vec![(root(), 42u32)]);253 run_to_block(6);254 assert_ok!(Scheduler::do_cancel_named(None, [1u8; 32]));255 run_to_block(100);256 assert_eq!(logger::log(), vec![(root(), 42u32), (root(), 69u32)]);257 });258}259260#[test]261fn scheduler_respects_weight_limits() {262 let max_weight: Weight = <Test as Config>::MaximumWeight::get();263 new_test_ext().execute_with(|| {264 let call = RuntimeCall::Logger(LoggerCall::log {265 i: 42,266 weight: max_weight / 3 * 2,267 });268 assert_ok!(Scheduler::do_schedule(269 DispatchTime::At(4),270 None,271 127,272 root(),273 <ScheduledCall<Test>>::new(call).unwrap(),274 ));275 let call = RuntimeCall::Logger(LoggerCall::log {276 i: 69,277 weight: max_weight / 3 * 2,278 });279 assert_ok!(Scheduler::do_schedule(280 DispatchTime::At(4),281 None,282 127,283 root(),284 <ScheduledCall<Test>>::new(call).unwrap(),285 ));286 // 69 and 42 do not fit together287 run_to_block(4);288 assert_eq!(logger::log(), vec![(root(), 42u32)]);289 run_to_block(5);290 assert_eq!(logger::log(), vec![(root(), 42u32), (root(), 69u32)]);291 });292}293294/// Permanently overweight calls are not deleted but also not executed.295#[test]296fn scheduler_does_not_delete_permanently_overweight_call() {297 let max_weight: Weight = <Test as Config>::MaximumWeight::get();298 new_test_ext().execute_with(|| {299 let call = RuntimeCall::Logger(LoggerCall::log {300 i: 42,301 weight: max_weight,302 });303 assert_ok!(Scheduler::do_schedule(304 DispatchTime::At(4),305 None,306 127,307 root(),308 <ScheduledCall<Test>>::new(call).unwrap(),309 ));310 // Never executes.311 run_to_block(100);312 assert_eq!(logger::log(), vec![]);313314 // Assert the `PermanentlyOverweight` event.315 assert_eq!(316 System::events().last().unwrap().event,317 crate::Event::PermanentlyOverweight {318 task: (4, 0),319 id: None320 }321 .into(),322 );323 // The call is still in the agenda.324 assert!(Agenda::<Test>::get(4).agenda[0].is_some());325 });326}327328#[test]329fn scheduler_periodic_tasks_always_find_place() {330 let max_weight: Weight = <Test as Config>::MaximumWeight::get();331 let max_per_block = <Test as Config>::MaxScheduledPerBlock::get();332333 new_test_ext().execute_with(|| {334 let call = RuntimeCall::Logger(LoggerCall::log {335 i: 42,336 weight: (max_weight / 3) * 2,337 });338 let call = <ScheduledCall<Test>>::new(call).unwrap();339340 assert_ok!(Scheduler::do_schedule(341 DispatchTime::At(4),342 Some((4, u32::MAX)),343 127,344 root(),345 call.clone(),346 ));347 // Executes 5 times till block 20.348 run_to_block(20);349 assert_eq!(logger::log().len(), 5);350351 // Block 28 will already be full.352 for _ in 0..max_per_block {353 assert_ok!(Scheduler::do_schedule(354 DispatchTime::At(28),355 None,356 120,357 root(),358 call.clone(),359 ));360 }361362 run_to_block(24);363 assert_eq!(logger::log().len(), 6);364365 // The periodic task should be postponed366 assert_eq!(<Agenda<Test>>::get(29).agenda.len(), 1);367368 run_to_block(27); // will call on_initialize(28)369 assert_eq!(logger::log().len(), 6);370371 run_to_block(28); // will call on_initialize(29)372 assert_eq!(logger::log().len(), 7);373 });374}375376#[test]377fn scheduler_respects_priority_ordering() {378 let max_weight: Weight = <Test as Config>::MaximumWeight::get();379 new_test_ext().execute_with(|| {380 let call = RuntimeCall::Logger(LoggerCall::log {381 i: 42,382 weight: max_weight / 3,383 });384 assert_ok!(Scheduler::do_schedule(385 DispatchTime::At(4),386 None,387 1,388 root(),389 <ScheduledCall<Test>>::new(call).unwrap(),390 ));391 let call = RuntimeCall::Logger(LoggerCall::log {392 i: 69,393 weight: max_weight / 3,394 });395 assert_ok!(Scheduler::do_schedule(396 DispatchTime::At(4),397 None,398 0,399 root(),400 <ScheduledCall<Test>>::new(call).unwrap(),401 ));402 run_to_block(4);403 assert_eq!(logger::log(), vec![(root(), 69u32), (root(), 42u32)]);404 });405}406407#[test]408fn scheduler_respects_priority_ordering_with_soft_deadlines() {409 new_test_ext().execute_with(|| {410 let max_weight: Weight = <Test as Config>::MaximumWeight::get();411 let call = RuntimeCall::Logger(LoggerCall::log {412 i: 42,413 weight: max_weight / 5 * 2,414 });415 assert_ok!(Scheduler::do_schedule(416 DispatchTime::At(4),417 None,418 255,419 root(),420 <ScheduledCall<Test>>::new(call).unwrap(),421 ));422 let call = RuntimeCall::Logger(LoggerCall::log {423 i: 69,424 weight: max_weight / 5 * 2,425 });426 assert_ok!(Scheduler::do_schedule(427 DispatchTime::At(4),428 None,429 127,430 root(),431 <ScheduledCall<Test>>::new(call).unwrap(),432 ));433 let call = RuntimeCall::Logger(LoggerCall::log {434 i: 2600,435 weight: max_weight / 5 * 4,436 });437 assert_ok!(Scheduler::do_schedule(438 DispatchTime::At(4),439 None,440 126,441 root(),442 <ScheduledCall<Test>>::new(call).unwrap(),443 ));444445 // 2600 does not fit with 69 or 42, but has higher priority, so will go through446 run_to_block(4);447 assert_eq!(logger::log(), vec![(root(), 2600u32)]);448 // 69 and 42 fit together449 run_to_block(5);450 assert_eq!(451 logger::log(),452 vec![(root(), 2600u32), (root(), 69u32), (root(), 42u32)]453 );454 });455}456457#[test]458fn on_initialize_weight_is_correct() {459 new_test_ext().execute_with(|| {460 let call_weight = Weight::from_ref_time(25);461462 // Named463 let call = RuntimeCall::Logger(LoggerCall::log {464 i: 3,465 weight: call_weight + Weight::from_ref_time(1),466 });467 assert_ok!(Scheduler::do_schedule_named(468 [1u8; 32],469 DispatchTime::At(3),470 None,471 255,472 root(),473 <ScheduledCall<Test>>::new(call).unwrap(),474 ));475 let call = RuntimeCall::Logger(LoggerCall::log {476 i: 42,477 weight: call_weight + Weight::from_ref_time(2),478 });479 // Anon Periodic480 assert_ok!(Scheduler::do_schedule(481 DispatchTime::At(2),482 Some((1000, 3)),483 128,484 root(),485 <ScheduledCall<Test>>::new(call).unwrap(),486 ));487 let call = RuntimeCall::Logger(LoggerCall::log {488 i: 69,489 weight: call_weight + Weight::from_ref_time(3),490 });491 // Anon492 assert_ok!(Scheduler::do_schedule(493 DispatchTime::At(2),494 None,495 127,496 root(),497 <ScheduledCall<Test>>::new(call).unwrap(),498 ));499 // Named Periodic500 let call = RuntimeCall::Logger(LoggerCall::log {501 i: 2600,502 weight: call_weight + Weight::from_ref_time(4),503 });504 assert_ok!(Scheduler::do_schedule_named(505 [2u8; 32],506 DispatchTime::At(1),507 Some((1000, 3)),508 126,509 root(),510 <ScheduledCall<Test>>::new(call).unwrap(),511 ));512513 // Will include the named periodic only514 assert_eq!(515 Scheduler::on_initialize(1),516 TestWeightInfo::service_agendas_base()517 + TestWeightInfo::service_agenda_base(1)518 + <MarginalWeightInfo<Test>>::service_task(None, true, true)519 + TestWeightInfo::execute_dispatch_unsigned()520 + call_weight + Weight::from_ref_time(4)521 );522 assert_eq!(IncompleteSince::<Test>::get(), None);523 assert_eq!(logger::log(), vec![(root(), 2600u32)]);524525 // Will include anon and anon periodic526 assert_eq!(527 Scheduler::on_initialize(2),528 TestWeightInfo::service_agendas_base()529 + TestWeightInfo::service_agenda_base(2)530 + <MarginalWeightInfo<Test>>::service_task(None, false, true)531 + TestWeightInfo::execute_dispatch_unsigned()532 + call_weight + Weight::from_ref_time(3)533 + <MarginalWeightInfo<Test>>::service_task(None, false, false)534 + TestWeightInfo::execute_dispatch_unsigned()535 + call_weight + Weight::from_ref_time(2)536 );537 assert_eq!(IncompleteSince::<Test>::get(), None);538 assert_eq!(539 logger::log(),540 vec![(root(), 2600u32), (root(), 69u32), (root(), 42u32)]541 );542543 // Will include named only544 assert_eq!(545 Scheduler::on_initialize(3),546 TestWeightInfo::service_agendas_base()547 + TestWeightInfo::service_agenda_base(1)548 + <MarginalWeightInfo<Test>>::service_task(None, true, false)549 + TestWeightInfo::execute_dispatch_unsigned()550 + call_weight + Weight::from_ref_time(1)551 );552 assert_eq!(IncompleteSince::<Test>::get(), None);553 assert_eq!(554 logger::log(),555 vec![556 (root(), 2600u32),557 (root(), 69u32),558 (root(), 42u32),559 (root(), 3u32)560 ]561 );562563 // Will contain none564 let actual_weight = Scheduler::on_initialize(4);565 assert_eq!(566 actual_weight,567 TestWeightInfo::service_agendas_base() + TestWeightInfo::service_agenda_base(0)568 );569 });570}571572#[test]573fn root_calls_works() {574 new_test_ext().execute_with(|| {575 let call = Box::new(RuntimeCall::Logger(LoggerCall::log {576 i: 69,577 weight: Weight::from_ref_time(10),578 }));579 let call2 = Box::new(RuntimeCall::Logger(LoggerCall::log {580 i: 42,581 weight: Weight::from_ref_time(10),582 }));583 assert_ok!(Scheduler::schedule_named(584 RuntimeOrigin::root(),585 [1u8; 32],586 4,587 None,588 Some(127),589 call,590 ));591 assert_ok!(Scheduler::schedule(592 RuntimeOrigin::root(),593 4,594 None,595 Some(127),596 call2597 ));598 run_to_block(3);599 // Scheduled calls are in the agenda.600 assert_eq!(Agenda::<Test>::get(4).agenda.len(), 2);601 assert!(logger::log().is_empty());602 assert_ok!(Scheduler::cancel_named(RuntimeOrigin::root(), [1u8; 32]));603 assert_ok!(Scheduler::cancel(RuntimeOrigin::root(), 4, 1));604 // Scheduled calls are made NONE, so should not effect state605 run_to_block(100);606 assert!(logger::log().is_empty());607 });608}609610#[test]611fn fails_to_schedule_task_in_the_past() {612 new_test_ext().execute_with(|| {613 run_to_block(3);614615 let call1 = Box::new(RuntimeCall::Logger(LoggerCall::log {616 i: 69,617 weight: Weight::from_ref_time(10),618 }));619 let call2 = Box::new(RuntimeCall::Logger(LoggerCall::log {620 i: 42,621 weight: Weight::from_ref_time(10),622 }));623 let call3 = Box::new(RuntimeCall::Logger(LoggerCall::log {624 i: 42,625 weight: Weight::from_ref_time(10),626 }));627628 assert_noop!(629 Scheduler::schedule_named(RuntimeOrigin::root(), [1u8; 32], 2, None, Some(127), call1),630 Error::<Test>::TargetBlockNumberInPast,631 );632633 assert_noop!(634 Scheduler::schedule(RuntimeOrigin::root(), 2, None, Some(127), call2),635 Error::<Test>::TargetBlockNumberInPast,636 );637638 assert_noop!(639 Scheduler::schedule(RuntimeOrigin::root(), 3, None, Some(127), call3),640 Error::<Test>::TargetBlockNumberInPast,641 );642 });643}644645#[test]646fn should_use_origin() {647 new_test_ext().execute_with(|| {648 let call = Box::new(RuntimeCall::Logger(LoggerCall::log {649 i: 69,650 weight: Weight::from_ref_time(10),651 }));652 let call2 = Box::new(RuntimeCall::Logger(LoggerCall::log {653 i: 42,654 weight: Weight::from_ref_time(10),655 }));656 assert_ok!(Scheduler::schedule_named(657 system::RawOrigin::Signed(1).into(),658 [1u8; 32],659 4,660 None,661 None,662 call,663 ));664 assert_ok!(Scheduler::schedule(665 system::RawOrigin::Signed(1).into(),666 4,667 None,668 None,669 call2,670 ));671 run_to_block(3);672 // Scheduled calls are in the agenda.673 assert_eq!(Agenda::<Test>::get(4).agenda.len(), 2);674 assert!(logger::log().is_empty());675 assert_ok!(Scheduler::cancel_named(676 system::RawOrigin::Signed(1).into(),677 [1u8; 32]678 ));679 assert_ok!(Scheduler::cancel(system::RawOrigin::Signed(1).into(), 4, 1));680 // Scheduled calls are made NONE, so should not effect state681 run_to_block(100);682 assert!(logger::log().is_empty());683 });684}685686#[test]687fn should_check_origin() {688 new_test_ext().execute_with(|| {689 let call = Box::new(RuntimeCall::Logger(LoggerCall::log {690 i: 69,691 weight: Weight::from_ref_time(10),692 }));693 let call2 = Box::new(RuntimeCall::Logger(LoggerCall::log {694 i: 42,695 weight: Weight::from_ref_time(10),696 }));697 assert_noop!(698 Scheduler::schedule_named(699 system::RawOrigin::Signed(2).into(),700 [1u8; 32],701 4,702 None,703 None,704 call705 ),706 BadOrigin707 );708 assert_noop!(709 Scheduler::schedule(system::RawOrigin::Signed(2).into(), 4, None, None, call2),710 BadOrigin711 );712 });713}714715#[test]716fn should_check_origin_for_cancel() {717 new_test_ext().execute_with(|| {718 let call = Box::new(RuntimeCall::Logger(LoggerCall::log_without_filter {719 i: 69,720 weight: Weight::from_ref_time(10),721 }));722 let call2 = Box::new(RuntimeCall::Logger(LoggerCall::log_without_filter {723 i: 42,724 weight: Weight::from_ref_time(10),725 }));726 assert_ok!(Scheduler::schedule_named(727 system::RawOrigin::Signed(1).into(),728 [1u8; 32],729 4,730 None,731 None,732 call,733 ));734 assert_ok!(Scheduler::schedule(735 system::RawOrigin::Signed(1).into(),736 4,737 None,738 None,739 call2,740 ));741 run_to_block(3);742 // Scheduled calls are in the agenda.743 assert_eq!(Agenda::<Test>::get(4).agenda.len(), 2);744 assert!(logger::log().is_empty());745 assert_noop!(746 Scheduler::cancel_named(system::RawOrigin::Signed(2).into(), [1u8; 32]),747 BadOrigin748 );749 assert_noop!(750 Scheduler::cancel(system::RawOrigin::Signed(2).into(), 4, 1),751 BadOrigin752 );753 assert_noop!(754 Scheduler::cancel_named(system::RawOrigin::Root.into(), [1u8; 32]),755 BadOrigin756 );757 assert_noop!(758 Scheduler::cancel(system::RawOrigin::Root.into(), 4, 1),759 BadOrigin760 );761 run_to_block(5);762 assert_eq!(763 logger::log(),764 vec![765 (system::RawOrigin::Signed(1).into(), 69u32),766 (system::RawOrigin::Signed(1).into(), 42u32)767 ]768 );769 });770}771772/// Cancelling a call and then scheduling a second call for the same773/// block results in different addresses.774#[test]775fn schedule_does_not_resuse_addr() {776 new_test_ext().execute_with(|| {777 let call = RuntimeCall::Logger(LoggerCall::log {778 i: 42,779 weight: Weight::from_ref_time(10),780 });781782 // Schedule both calls.783 let addr_1 = Scheduler::do_schedule(784 DispatchTime::At(4),785 None,786 127,787 root(),788 <ScheduledCall<Test>>::new(call.clone()).unwrap(),789 )790 .unwrap();791 // Cancel the call.792 assert_ok!(Scheduler::do_cancel(None, addr_1));793 let addr_2 = Scheduler::do_schedule(794 DispatchTime::At(4),795 None,796 127,797 root(),798 <ScheduledCall<Test>>::new(call).unwrap(),799 )800 .unwrap();801802 // Should not re-use the address.803 assert!(addr_1 != addr_2);804 });805}806807#[test]808fn schedule_agenda_overflows() {809 let max: u32 = <Test as Config>::MaxScheduledPerBlock::get();810811 new_test_ext().execute_with(|| {812 let call = RuntimeCall::Logger(LoggerCall::log {813 i: 42,814 weight: Weight::from_ref_time(10),815 });816 let call = <ScheduledCall<Test>>::new(call).unwrap();817818 // Schedule the maximal number allowed per block.819 for _ in 0..max {820 Scheduler::do_schedule(DispatchTime::At(4), None, 127, root(), call.clone()).unwrap();821 }822823 // One more time and it errors.824 assert_noop!(825 Scheduler::do_schedule(DispatchTime::At(4), None, 127, root(), call,),826 <Error<Test>>::AgendaIsExhausted,827 );828829 run_to_block(4);830 // All scheduled calls are executed.831 assert_eq!(logger::log().len() as u32, max);832 });833}834835/// Cancelling and scheduling does not overflow the agenda but fills holes.836#[test]837fn cancel_and_schedule_fills_holes() {838 let max: u32 = <Test as Config>::MaxScheduledPerBlock::get();839 assert!(840 max > 3,841 "This test only makes sense for MaxScheduledPerBlock > 3"842 );843844 new_test_ext().execute_with(|| {845 let call = RuntimeCall::Logger(LoggerCall::log {846 i: 42,847 weight: Weight::from_ref_time(10),848 });849 let call = <ScheduledCall<Test>>::new(call).unwrap();850 let mut addrs = Vec::<_>::default();851852 // Schedule the maximal number allowed per block.853 for _ in 0..max {854 addrs.push(855 Scheduler::do_schedule(DispatchTime::At(4), None, 127, root(), call.clone())856 .unwrap(),857 );858 }859 // Cancel three of them.860 for addr in addrs.into_iter().take(3) {861 Scheduler::do_cancel(None, addr).unwrap();862 }863 // Schedule three new ones.864 for i in 0..3 {865 let (_block, index) =866 Scheduler::do_schedule(DispatchTime::At(4), None, 127, root(), call.clone())867 .unwrap();868 assert_eq!(i, index);869 }870871 run_to_block(4);872 // Maximum number of calls are executed.873 assert_eq!(logger::log().len() as u32, max);874 });875}876877#[test]878fn cannot_schedule_too_big_tasks() {879 new_test_ext().execute_with(|| {880 let call = Box::new(<<Test as Config>::RuntimeCall>::from(SystemCall::remark {881 remark: vec![0; EncodedCall::bound() - 4],882 }));883884 assert_ok!(Scheduler::schedule(885 RuntimeOrigin::root(),886 4,887 None,888 Some(127),889 call890 ));891892 let call = Box::new(<<Test as Config>::RuntimeCall>::from(SystemCall::remark {893 remark: vec![0; EncodedCall::bound() - 3],894 }));895896 assert_err!(897 Scheduler::schedule(RuntimeOrigin::root(), 4, None, Some(127), call),898 <Error<Test>>::TooBigScheduledCall899 );900 });901}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;