git.delta.rocks / unique-network / refs/commits / 90b12dae5069

difftreelog

misk: Remove some warnings. Add over_max_size test

Trubnikov Sergey2022-10-28parent: #0257bf0.patch.diff
in: master

12 files changed

modifiedCargo.lockdiffbeforeafterboth
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2347,6 +2347,7 @@
  "sha3-const",
  "similar-asserts",
  "sp-std",
+ "trybuild",
 ]
 
 [[package]]
@@ -12671,6 +12672,21 @@
 ]
 
 [[package]]
+name = "trybuild"
+version = "1.0.71"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ea496675d71016e9bc76aa42d87f16aefd95447cc5818e671e12b2d7e269075d"
+dependencies = [
+ "glob",
+ "once_cell",
+ "serde",
+ "serde_derive",
+ "serde_json",
+ "termcolor",
+ "toml",
+]
+
+[[package]]
 name = "tt-call"
 version = "1.0.8"
 source = "registry+https://github.com/rust-lang/crates.io-index"
modifiedcrates/evm-coder/Cargo.tomldiffbeforeafterboth
--- a/crates/evm-coder/Cargo.toml
+++ b/crates/evm-coder/Cargo.toml
@@ -29,6 +29,7 @@
 hex-literal = "0.3.4"
 similar-asserts = "1.4.2"
 concat-idents = "1.1.3"
+trybuild = "1.0"
 
 [features]
 default = ["std"]
modifiedcrates/evm-coder/src/custom_signature.rsdiffbeforeafterboth
--- a/crates/evm-coder/src/custom_signature.rs
+++ b/crates/evm-coder/src/custom_signature.rs
@@ -423,15 +423,6 @@
 		assert_eq!(<MaxSize>::name(), "!".repeat(SIGNATURE_SIZE_LIMIT));
 	}
 
-	// This test must NOT compile with "index out of bounds"!
-	// #[test]
-	// fn over_max_size() {
-	// 	assert_eq!(
-	// 		<Vec<MaxSize>>::name(),
-	// 		"!".repeat(SIGNATURE_SIZE_LIMIT) + "[]"
-	// 	);
-	// }
-
 	#[test]
 	fn make_func_without_args() {
 		const SIG: FunctionSignature = make_signature!(
@@ -498,4 +489,10 @@
 	fn shift() {
 		assert_eq!(<(u32,)>::name(), "(uint32)");
 	}
+
+	#[test]
+	fn over_max_size() {
+		let t = trybuild::TestCases::new();
+		t.compile_fail("tests/build_failed/custom_signature_over_max_size.rs");
+	}
 }
addedcrates/evm-coder/tests/build_failed/custom_signature_over_max_size.rsdiffbeforeafterboth
--- /dev/null
+++ b/crates/evm-coder/tests/build_failed/custom_signature_over_max_size.rs
@@ -0,0 +1,33 @@
+#![allow(dead_code)]
+use std::str::from_utf8;
+
+use evm_coder::{
+	make_signature,
+	custom_signature::{SignatureUnit, SIGNATURE_SIZE_LIMIT},
+};
+
+trait Name {
+	const SIGNATURE: SignatureUnit;
+
+	fn name() -> &'static str {
+		from_utf8(&Self::SIGNATURE.data[..Self::SIGNATURE.len]).expect("bad utf-8")
+	}
+}
+
+impl<T: Name> Name for Vec<T> {
+	evm_coder::make_signature!(new nameof(T) fixed("[]"));
+}
+
+struct MaxSize();
+impl Name for MaxSize {
+	const SIGNATURE: SignatureUnit = SignatureUnit {
+		data: [b'!'; SIGNATURE_SIZE_LIMIT],
+		len: SIGNATURE_SIZE_LIMIT,
+	};
+}
+
+const NAME: SignatureUnit = <Vec<MaxSize>>::SIGNATURE;
+
+fn main() {
+	assert!(false);
+}
addedcrates/evm-coder/tests/build_failed/custom_signature_over_max_size.stderrdiffbeforeafterboth
--- /dev/null
+++ b/crates/evm-coder/tests/build_failed/custom_signature_over_max_size.stderr
@@ -0,0 +1,19 @@
+error: any use of this value will cause an error
+  --> tests/build_failed/custom_signature_over_max_size.rs:18:2
+   |
+18 |     evm_coder::make_signature!(new nameof(T) fixed("[]"));
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ index out of bounds: the length is 256 but the index is 256
+   |
+   = note: `#[deny(const_err)]` on by default
+   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+   = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+   = note: this error originates in the macro `make_signature` which comes from the expansion of the macro `evm_coder::make_signature` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: any use of this value will cause an error
+  --> tests/build_failed/custom_signature_over_max_size.rs:29:29
+   |
+29 | const NAME: SignatureUnit = <Vec<MaxSize>>::SIGNATURE;
+   | -------------------------   ^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
+   |
+   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+   = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
modifiedpallets/common/src/erc.rsdiffbeforeafterboth
--- a/pallets/common/src/erc.rs
+++ b/pallets/common/src/erc.rs
@@ -35,10 +35,7 @@
 
 use crate::{
 	Pallet, CollectionHandle, Config, CollectionProperties, SelfWeightOf,
-	eth::{
-		convert_cross_account_to_uint256, convert_cross_account_to_tuple,
-		convert_tuple_to_cross_account,
-	},
+	eth::{convert_cross_account_to_uint256, convert_tuple_to_cross_account},
 	weights::WeightInfo,
 };
 
modifiedpallets/evm-contract-helpers/src/eth.rsdiffbeforeafterboth
--- a/pallets/evm-contract-helpers/src/eth.rs
+++ b/pallets/evm-contract-helpers/src/eth.rs
@@ -17,7 +17,6 @@
 //! Implementation of magic contract
 
 extern crate alloc;
-use alloc::string::ToString;
 use core::marker::PhantomData;
 use evm_coder::{
 	abi::AbiWriter,
modifiedpallets/fungible/src/erc.rsdiffbeforeafterboth
--- a/pallets/fungible/src/erc.rs
+++ b/pallets/fungible/src/erc.rs
@@ -28,7 +28,6 @@
 	custom_signature::{SignatureUnit, FunctionSignature, SignaturePreferences},
 	make_signature,
 };
-use pallet_common::eth::convert_tuple_to_cross_account;
 use up_data_structs::CollectionMode;
 use pallet_common::erc::{CommonEvmHandler, PrecompileResult};
 use sp_std::vec::Vec;
modifiedpallets/refungible/src/erc.rsdiffbeforeafterboth
--- a/pallets/refungible/src/erc.rs
+++ b/pallets/refungible/src/erc.rs
@@ -21,7 +21,6 @@
 
 extern crate alloc;
 
-use alloc::string::ToString;
 use core::{
 	char::{REPLACEMENT_CHARACTER, decode_utf16},
 	convert::TryInto,
@@ -39,7 +38,6 @@
 use pallet_common::{
 	CollectionHandle, CollectionPropertyPermissions,
 	erc::{CommonEvmHandler, CollectionCall, static_property::key},
-	eth::convert_tuple_to_cross_account,
 };
 use pallet_evm::{account::CrossAccountId, PrecompileHandle};
 use pallet_evm_coder_substrate::{call, dispatch_to_evm};
modifiedpallets/unique/src/eth/mod.rsdiffbeforeafterboth
--- a/pallets/unique/src/eth/mod.rs
+++ b/pallets/unique/src/eth/mod.rs
@@ -42,10 +42,7 @@
 	CreateCollectionData,
 };
 
-use crate::{
-	weights::WeightInfo, Config, SelfWeightOf, NftTransferBasket, FungibleTransferBasket,
-	ReFungibleTransferBasket, NftApproveBasket, FungibleApproveBasket, RefungibleApproveBasket,
-};
+use crate::{weights::WeightInfo, Config, SelfWeightOf};
 
 use alloc::format;
 use sp_std::vec::Vec;
modifiedruntime/common/config/pallets/scheduler.rsdiffbeforeafterboth
before · runtime/common/config/pallets/scheduler.rs
1// 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/>.1617use frame_support::{18	traits::{PrivilegeCmp, EnsureOrigin},19	weights::Weight,20	parameter_types,21};22use frame_system::{EnsureRoot, RawOrigin};23use sp_runtime::Perbill;24use core::cmp::Ordering;25use codec::Decode;26use crate::{27	runtime_common::{scheduler::SchedulerPaymentExecutor, config::substrate::RuntimeBlockWeights},28	Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, OriginCaller, Balances,29};30use pallet_unique_scheduler_v2::ScheduledEnsureOriginSuccess;31use up_common::types::AccountId;3233parameter_types! {34	pub MaximumSchedulerWeight: Weight = Perbill::from_percent(50) *35		RuntimeBlockWeights::get().max_block;36	pub const MaxScheduledPerBlock: u32 = 50;3738	pub const NoPreimagePostponement: Option<u32> = Some(10);39	pub const Preimage: Option<u32> = Some(10);40}4142pub struct EnsureSignedOrRoot<AccountId>(sp_std::marker::PhantomData<AccountId>);43impl<O: Into<Result<RawOrigin<AccountId>, O>> + From<RawOrigin<AccountId>>, AccountId: Decode>44	EnsureOrigin<O> for EnsureSignedOrRoot<AccountId>45{46	type Success = ScheduledEnsureOriginSuccess<AccountId>;47	fn try_origin(o: O) -> Result<Self::Success, O> {48		o.into().and_then(|o| match o {49			RawOrigin::Root => Ok(ScheduledEnsureOriginSuccess::Root),50			RawOrigin::Signed(who) => Ok(ScheduledEnsureOriginSuccess::Signed(who)),51			r => Err(O::from(r)),52		})53	}54}5556pub struct EqualOrRootOnly;57impl PrivilegeCmp<OriginCaller> for EqualOrRootOnly {58	fn cmp_privilege(left: &OriginCaller, right: &OriginCaller) -> Option<Ordering> {59		use RawOrigin::*;6061		let left = left.clone().try_into().ok()?;62		let right = right.clone().try_into().ok()?;6364		match (left, right) {65			(Root, Root) => Some(Ordering::Equal),66			(Root, _) => Some(Ordering::Greater),67			(_, Root) => Some(Ordering::Less),68			lr @ _ => (lr.0 == lr.1).then(|| Ordering::Equal),69		}70	}71}7273// impl pallet_unique_scheduler::Config for Runtime {74// 	type RuntimeEvent = RuntimeEvent;75// 	type RuntimeOrigin = RuntimeOrigin;76// 	type Currency = Balances;77// 	type PalletsOrigin = OriginCaller;78// 	type RuntimeCall = RuntimeCall;79// 	type MaximumWeight = MaximumSchedulerWeight;80// 	type ScheduleOrigin = EnsureSignedOrRoot<AccountId>;81// 	type PrioritySetOrigin = EnsureRoot<AccountId>;82// 	type MaxScheduledPerBlock = MaxScheduledPerBlock;83// 	type WeightInfo = ();84// 	type CallExecutor = SchedulerPaymentExecutor;85// 	type OriginPrivilegeCmp = EqualOrRootOnly;86// 	type PreimageProvider = ();87// 	type NoPreimagePostponement = NoPreimagePostponement;88// }8990impl pallet_unique_scheduler_v2::Config for Runtime {91	type RuntimeEvent = RuntimeEvent;92	type RuntimeOrigin = RuntimeOrigin;93	type PalletsOrigin = OriginCaller;94	type RuntimeCall = RuntimeCall;95	type MaximumWeight = MaximumSchedulerWeight;96	type ScheduleOrigin = EnsureSignedOrRoot<AccountId>;97	type OriginPrivilegeCmp = EqualOrRootOnly;98	type MaxScheduledPerBlock = MaxScheduledPerBlock;99	type WeightInfo = ();100	type Preimages = ();101	type CallExecutor = SchedulerPaymentExecutor;102	type PrioritySetOrigin = EnsureRoot<AccountId>;103}
modifiedruntime/common/scheduler.rsdiffbeforeafterboth
--- a/runtime/common/scheduler.rs
+++ b/runtime/common/scheduler.rs
@@ -14,19 +14,16 @@
 // You should have received a copy of the GNU General Public License
 // along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
 
-use frame_support::{
-	traits::NamedReservableCurrency,
-	dispatch::{GetDispatchInfo, PostDispatchInfo, DispatchInfo},
-};
+use frame_support::dispatch::{GetDispatchInfo, PostDispatchInfo, DispatchInfo};
 use sp_runtime::{
 	traits::{Dispatchable, Applyable, Member},
 	generic::Era,
 	transaction_validity::TransactionValidityError,
-	DispatchErrorWithPostInfo, DispatchError,
+	DispatchErrorWithPostInfo,
 };
 use codec::Encode;
-use crate::{Runtime, RuntimeCall, RuntimeOrigin, Balances};
-use up_common::types::{AccountId, Balance};
+use crate::{Runtime, RuntimeCall, RuntimeOrigin};
+use up_common::types::AccountId;
 use fp_self_contained::SelfContainedCall;
 use pallet_unique_scheduler_v2::DispatchCall;
 use pallet_transaction_payment::ChargeTransactionPayment;