difftreelog
misk: Remove some warnings. Add over_max_size test
in: master
12 files changed
Cargo.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"
crates/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"]
crates/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");
+ }
}
crates/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);
+}
crates/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>
pallets/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,
};
pallets/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,
pallets/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;
pallets/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};
pallets/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;
runtime/common/config/pallets/scheduler.rsdiffbeforeafterboth--- a/runtime/common/config/pallets/scheduler.rs
+++ b/runtime/common/config/pallets/scheduler.rs
@@ -25,7 +25,7 @@
use codec::Decode;
use crate::{
runtime_common::{scheduler::SchedulerPaymentExecutor, config::substrate::RuntimeBlockWeights},
- Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, OriginCaller, Balances,
+ Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, OriginCaller,
};
use pallet_unique_scheduler_v2::ScheduledEnsureOriginSuccess;
use up_common::types::AccountId;
runtime/common/scheduler.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/>.1617use frame_support::{18 traits::NamedReservableCurrency,19 dispatch::{GetDispatchInfo, PostDispatchInfo, DispatchInfo},20};21use sp_runtime::{22 traits::{Dispatchable, Applyable, Member},23 generic::Era,24 transaction_validity::TransactionValidityError,25 DispatchErrorWithPostInfo, DispatchError,26};27use codec::Encode;28use crate::{Runtime, RuntimeCall, RuntimeOrigin, Balances};29use up_common::types::{AccountId, Balance};30use fp_self_contained::SelfContainedCall;31use pallet_unique_scheduler_v2::DispatchCall;32use pallet_transaction_payment::ChargeTransactionPayment;3334// type SponsorshipChargeTransactionPayment =35// pallet_charge_transaction::ChargeTransactionPayment<Runtime>;3637/// The SignedExtension to the basic transaction logic.38pub type SignedExtraScheduler = (39 frame_system::CheckSpecVersion<Runtime>,40 frame_system::CheckGenesis<Runtime>,41 frame_system::CheckEra<Runtime>,42 frame_system::CheckNonce<Runtime>,43 frame_system::CheckWeight<Runtime>,44 ChargeTransactionPayment<Runtime>,45);4647fn get_signed_extras(from: <Runtime as frame_system::Config>::AccountId) -> SignedExtraScheduler {48 (49 frame_system::CheckSpecVersion::<Runtime>::new(),50 frame_system::CheckGenesis::<Runtime>::new(),51 frame_system::CheckEra::<Runtime>::from(Era::Immortal),52 frame_system::CheckNonce::<Runtime>::from(frame_system::Pallet::<Runtime>::account_nonce(53 from,54 )),55 frame_system::CheckWeight::<Runtime>::new(),56 ChargeTransactionPayment::<Runtime>::from(0),57 )58}5960pub struct SchedulerPaymentExecutor;6162impl<T: frame_system::Config + pallet_unique_scheduler_v2::Config, SelfContainedSignedInfo>63 DispatchCall<T, SelfContainedSignedInfo> for SchedulerPaymentExecutor64where65 <T as frame_system::Config>::RuntimeCall: Member66 + Dispatchable<RuntimeOrigin = RuntimeOrigin, Info = DispatchInfo>67 + SelfContainedCall<SignedInfo = SelfContainedSignedInfo>68 + GetDispatchInfo69 + From<frame_system::Call<Runtime>>,70 SelfContainedSignedInfo: Send + Sync + 'static,71 RuntimeCall: From<<T as frame_system::Config>::RuntimeCall>72 + From<<T as pallet_unique_scheduler_v2::Config>::RuntimeCall>73 + SelfContainedCall<SignedInfo = SelfContainedSignedInfo>,74 sp_runtime::AccountId32: From<<T as frame_system::Config>::AccountId>,75{76 fn dispatch_call(77 signer: Option<<T as frame_system::Config>::AccountId>,78 call: <T as pallet_unique_scheduler_v2::Config>::RuntimeCall,79 ) -> Result<80 Result<PostDispatchInfo, DispatchErrorWithPostInfo<PostDispatchInfo>>,81 TransactionValidityError,82 > {83 let dispatch_info = call.get_dispatch_info();84 let len = call.encoded_size();8586 let signed = match signer {87 Some(signer) => fp_self_contained::CheckedSignature::Signed(88 signer.clone().into(),89 get_signed_extras(signer.into()),90 ),91 None => fp_self_contained::CheckedSignature::Unsigned,92 };9394 let extrinsic = fp_self_contained::CheckedExtrinsic::<95 AccountId,96 RuntimeCall,97 SignedExtraScheduler,98 SelfContainedSignedInfo,99 > {100 signed,101 function: call.into(),102 };103104 extrinsic.apply::<Runtime>(&dispatch_info, len)105 }106}107108// impl<T: frame_system::Config + pallet_unique_scheduler::Config, SelfContainedSignedInfo>109// DispatchCall<T, SelfContainedSignedInfo> for SchedulerPaymentExecutor110// where111// <T as frame_system::Config>::Call: Member112// + Dispatchable<Origin = Origin, Info = DispatchInfo>113// + SelfContainedCall<SignedInfo = SelfContainedSignedInfo>114// + GetDispatchInfo115// + From<frame_system::Call<Runtime>>,116// SelfContainedSignedInfo: Send + Sync + 'static,117// Call: From<<T as frame_system::Config>::Call>118// + From<<T as pallet_unique_scheduler::Config>::Call>119// + SelfContainedCall<SignedInfo = SelfContainedSignedInfo>,120// sp_runtime::AccountId32: From<<T as frame_system::Config>::AccountId>,121// {122// fn dispatch_call(123// signer: Option<<T as frame_system::Config>::AccountId>,124// call: <T as pallet_unique_scheduler::Config>::Call,125// ) -> Result<126// Result<PostDispatchInfo, DispatchErrorWithPostInfo<PostDispatchInfo>>,127// TransactionValidityError,128// > {129// let dispatch_info = call.get_dispatch_info();130// let len = call.encoded_size();131132// let signed = match signer {133// Some(signer) => fp_self_contained::CheckedSignature::Signed(134// signer.clone().into(),135// get_signed_extras(signer.into()),136// ),137// None => fp_self_contained::CheckedSignature::Unsigned,138// };139140// let extrinsic = fp_self_contained::CheckedExtrinsic::<141// AccountId,142// Call,143// SignedExtraScheduler,144// SelfContainedSignedInfo,145// > {146// signed,147// function: call.into(),148// };149150// extrinsic.apply::<Runtime>(&dispatch_info, len)151// }152153// fn reserve_balance(154// id: [u8; 16],155// sponsor: <T as frame_system::Config>::AccountId,156// call: <T as pallet_unique_scheduler::Config>::Call,157// count: u32,158// ) -> Result<(), DispatchError> {159// let dispatch_info = call.get_dispatch_info();160// let weight: Balance =161// SponsorshipChargeTransactionPayment::traditional_fee(0, &dispatch_info, 0)162// .saturating_mul(count.into());163164// <Balances as NamedReservableCurrency<AccountId>>::reserve_named(165// &id,166// &(sponsor.into()),167// weight,168// )169// }170171// fn pay_for_call(172// id: [u8; 16],173// sponsor: <T as frame_system::Config>::AccountId,174// call: <T as pallet_unique_scheduler::Config>::Call,175// ) -> Result<u128, DispatchError> {176// let dispatch_info = call.get_dispatch_info();177// let weight: Balance =178// SponsorshipChargeTransactionPayment::traditional_fee(0, &dispatch_info, 0);179// Ok(180// <Balances as NamedReservableCurrency<AccountId>>::unreserve_named(181// &id,182// &(sponsor.into()),183// weight,184// ),185// )186// }187188// fn cancel_reserve(189// id: [u8; 16],190// sponsor: <T as frame_system::Config>::AccountId,191// ) -> Result<u128, DispatchError> {192// Ok(193// <Balances as NamedReservableCurrency<AccountId>>::unreserve_named(194// &id,195// &(sponsor.into()),196// u128::MAX,197// ),198// )199// }200// }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::dispatch::{GetDispatchInfo, PostDispatchInfo, DispatchInfo};18use sp_runtime::{19 traits::{Dispatchable, Applyable, Member},20 generic::Era,21 transaction_validity::TransactionValidityError,22 DispatchErrorWithPostInfo,23};24use codec::Encode;25use crate::{Runtime, RuntimeCall, RuntimeOrigin};26use up_common::types::AccountId;27use fp_self_contained::SelfContainedCall;28use pallet_unique_scheduler_v2::DispatchCall;29use pallet_transaction_payment::ChargeTransactionPayment;3031// type SponsorshipChargeTransactionPayment =32// pallet_charge_transaction::ChargeTransactionPayment<Runtime>;3334/// The SignedExtension to the basic transaction logic.35pub type SignedExtraScheduler = (36 frame_system::CheckSpecVersion<Runtime>,37 frame_system::CheckGenesis<Runtime>,38 frame_system::CheckEra<Runtime>,39 frame_system::CheckNonce<Runtime>,40 frame_system::CheckWeight<Runtime>,41 ChargeTransactionPayment<Runtime>,42);4344fn get_signed_extras(from: <Runtime as frame_system::Config>::AccountId) -> SignedExtraScheduler {45 (46 frame_system::CheckSpecVersion::<Runtime>::new(),47 frame_system::CheckGenesis::<Runtime>::new(),48 frame_system::CheckEra::<Runtime>::from(Era::Immortal),49 frame_system::CheckNonce::<Runtime>::from(frame_system::Pallet::<Runtime>::account_nonce(50 from,51 )),52 frame_system::CheckWeight::<Runtime>::new(),53 ChargeTransactionPayment::<Runtime>::from(0),54 )55}5657pub struct SchedulerPaymentExecutor;5859impl<T: frame_system::Config + pallet_unique_scheduler_v2::Config, SelfContainedSignedInfo>60 DispatchCall<T, SelfContainedSignedInfo> for SchedulerPaymentExecutor61where62 <T as frame_system::Config>::RuntimeCall: Member63 + Dispatchable<RuntimeOrigin = RuntimeOrigin, Info = DispatchInfo>64 + SelfContainedCall<SignedInfo = SelfContainedSignedInfo>65 + GetDispatchInfo66 + From<frame_system::Call<Runtime>>,67 SelfContainedSignedInfo: Send + Sync + 'static,68 RuntimeCall: From<<T as frame_system::Config>::RuntimeCall>69 + From<<T as pallet_unique_scheduler_v2::Config>::RuntimeCall>70 + SelfContainedCall<SignedInfo = SelfContainedSignedInfo>,71 sp_runtime::AccountId32: From<<T as frame_system::Config>::AccountId>,72{73 fn dispatch_call(74 signer: Option<<T as frame_system::Config>::AccountId>,75 call: <T as pallet_unique_scheduler_v2::Config>::RuntimeCall,76 ) -> Result<77 Result<PostDispatchInfo, DispatchErrorWithPostInfo<PostDispatchInfo>>,78 TransactionValidityError,79 > {80 let dispatch_info = call.get_dispatch_info();81 let len = call.encoded_size();8283 let signed = match signer {84 Some(signer) => fp_self_contained::CheckedSignature::Signed(85 signer.clone().into(),86 get_signed_extras(signer.into()),87 ),88 None => fp_self_contained::CheckedSignature::Unsigned,89 };9091 let extrinsic = fp_self_contained::CheckedExtrinsic::<92 AccountId,93 RuntimeCall,94 SignedExtraScheduler,95 SelfContainedSignedInfo,96 > {97 signed,98 function: call.into(),99 };100101 extrinsic.apply::<Runtime>(&dispatch_info, len)102 }103}104105// impl<T: frame_system::Config + pallet_unique_scheduler::Config, SelfContainedSignedInfo>106// DispatchCall<T, SelfContainedSignedInfo> for SchedulerPaymentExecutor107// where108// <T as frame_system::Config>::Call: Member109// + Dispatchable<Origin = Origin, Info = DispatchInfo>110// + SelfContainedCall<SignedInfo = SelfContainedSignedInfo>111// + GetDispatchInfo112// + From<frame_system::Call<Runtime>>,113// SelfContainedSignedInfo: Send + Sync + 'static,114// Call: From<<T as frame_system::Config>::Call>115// + From<<T as pallet_unique_scheduler::Config>::Call>116// + SelfContainedCall<SignedInfo = SelfContainedSignedInfo>,117// sp_runtime::AccountId32: From<<T as frame_system::Config>::AccountId>,118// {119// fn dispatch_call(120// signer: Option<<T as frame_system::Config>::AccountId>,121// call: <T as pallet_unique_scheduler::Config>::Call,122// ) -> Result<123// Result<PostDispatchInfo, DispatchErrorWithPostInfo<PostDispatchInfo>>,124// TransactionValidityError,125// > {126// let dispatch_info = call.get_dispatch_info();127// let len = call.encoded_size();128129// let signed = match signer {130// Some(signer) => fp_self_contained::CheckedSignature::Signed(131// signer.clone().into(),132// get_signed_extras(signer.into()),133// ),134// None => fp_self_contained::CheckedSignature::Unsigned,135// };136137// let extrinsic = fp_self_contained::CheckedExtrinsic::<138// AccountId,139// Call,140// SignedExtraScheduler,141// SelfContainedSignedInfo,142// > {143// signed,144// function: call.into(),145// };146147// extrinsic.apply::<Runtime>(&dispatch_info, len)148// }149150// fn reserve_balance(151// id: [u8; 16],152// sponsor: <T as frame_system::Config>::AccountId,153// call: <T as pallet_unique_scheduler::Config>::Call,154// count: u32,155// ) -> Result<(), DispatchError> {156// let dispatch_info = call.get_dispatch_info();157// let weight: Balance =158// SponsorshipChargeTransactionPayment::traditional_fee(0, &dispatch_info, 0)159// .saturating_mul(count.into());160161// <Balances as NamedReservableCurrency<AccountId>>::reserve_named(162// &id,163// &(sponsor.into()),164// weight,165// )166// }167168// fn pay_for_call(169// id: [u8; 16],170// sponsor: <T as frame_system::Config>::AccountId,171// call: <T as pallet_unique_scheduler::Config>::Call,172// ) -> Result<u128, DispatchError> {173// let dispatch_info = call.get_dispatch_info();174// let weight: Balance =175// SponsorshipChargeTransactionPayment::traditional_fee(0, &dispatch_info, 0);176// Ok(177// <Balances as NamedReservableCurrency<AccountId>>::unreserve_named(178// &id,179// &(sponsor.into()),180// weight,181// ),182// )183// }184185// fn cancel_reserve(186// id: [u8; 16],187// sponsor: <T as frame_system::Config>::AccountId,188// ) -> Result<u128, DispatchError> {189// Ok(190// <Balances as NamedReservableCurrency<AccountId>>::unreserve_named(191// &id,192// &(sponsor.into()),193// u128::MAX,194// ),195// )196// }197// }