From b9d39e9db7df82c679e34706bf805111fcd49efa Mon Sep 17 00:00:00 2001 From: Ashutosh Varma Date: Mon, 25 Sep 2023 17:29:20 +0530 Subject: [PATCH] feat: remove deprecated pallet --- Cargo.lock | 20 -- Cargo.toml | 1 - pallets/custom-signatures/Cargo.toml | 43 --- pallets/custom-signatures/src/ethereum.rs | 100 ------- pallets/custom-signatures/src/lib.rs | 220 -------------- pallets/custom-signatures/src/tests.rs | 334 ---------------------- 6 files changed, 718 deletions(-) delete mode 100644 pallets/custom-signatures/Cargo.toml delete mode 100644 pallets/custom-signatures/src/ethereum.rs delete mode 100644 pallets/custom-signatures/src/lib.rs delete mode 100644 pallets/custom-signatures/src/tests.rs diff --git a/Cargo.lock b/Cargo.lock index 6045012fe6..117590af56 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7083,26 +7083,6 @@ dependencies = [ "sp-std", ] -[[package]] -name = "pallet-custom-signatures" -version = "4.6.0" -dependencies = [ - "assert_matches", - "frame-support", - "frame-system", - "hex-literal", - "libsecp256k1", - "pallet-balances", - "parity-scale-codec", - "scale-info", - "serde", - "sp-core", - "sp-io", - "sp-keyring", - "sp-runtime", - "sp-std", -] - [[package]] name = "pallet-dapps-staking" version = "3.10.0" diff --git a/Cargo.toml b/Cargo.toml index fd6f3ee412..a6d739f9df 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -272,7 +272,6 @@ orml-xcm-support = { git = "https://github.com/open-web3-stack/open-runtime-modu # (wasm) pallet-block-reward = { path = "./pallets/block-reward", default-features = false } pallet-collator-selection = { path = "./pallets/collator-selection", default-features = false } -pallet-custom-signatures = { path = "./pallets/custom-signatures", default-features = false } pallet-dapps-staking = { path = "./pallets/dapps-staking", default-features = false } pallet-xc-asset-config = { path = "./pallets/xc-asset-config", default-features = false } pallet-xvm = { path = "./pallets/xvm", default-features = false } diff --git a/pallets/custom-signatures/Cargo.toml b/pallets/custom-signatures/Cargo.toml deleted file mode 100644 index 94dc4a7e3a..0000000000 --- a/pallets/custom-signatures/Cargo.toml +++ /dev/null @@ -1,43 +0,0 @@ -[package] -name = "pallet-custom-signatures" -version = "4.6.0" -license = "Apache-2.0" -description = "FRAME pallet for user defined extrinsic signatures" -authors.workspace = true -edition.workspace = true -homepage.workspace = true -repository.workspace = true - -[dependencies] -frame-support = { workspace = true } -frame-system = { workspace = true } -parity-scale-codec = { workspace = true } -scale-info = { workspace = true } -serde = { workspace = true, optional = true } -sp-core = { workspace = true } -sp-io = { workspace = true } -sp-runtime = { workspace = true } -sp-std = { workspace = true } - -[dev-dependencies] -assert_matches = { workspace = true } -hex-literal = { workspace = true } -libsecp256k1 = { workspace = true } -pallet-balances = { workspace = true } -sp-keyring = { workspace = true } - -[features] -default = ["std"] -std = [ - "serde", - "parity-scale-codec/std", - "pallet-balances/std", - "scale-info/std", - "sp-io/std", - "sp-std/std", - "sp-core/std", - "sp-runtime/std", - "frame-support/std", - "frame-system/std", -] -try-runtime = ["frame-support/try-runtime"] diff --git a/pallets/custom-signatures/src/ethereum.rs b/pallets/custom-signatures/src/ethereum.rs deleted file mode 100644 index 0a93d3803b..0000000000 --- a/pallets/custom-signatures/src/ethereum.rs +++ /dev/null @@ -1,100 +0,0 @@ -// This file is part of Astar. - -// Copyright (C) 2019-2023 Stake Technologies Pte.Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//! Ethereum prefixed signatures compatibility instances. - -use parity_scale_codec::{Decode, Encode}; -use sp_core::ecdsa; -use sp_io::{crypto::secp256k1_ecdsa_recover_compressed, hashing::keccak_256}; -use sp_runtime::traits::{IdentifyAccount, Lazy, Verify}; -use sp_runtime::MultiSignature; -use sp_std::prelude::*; - -/// Ethereum-compatible signature type. -#[derive(Encode, Decode, PartialEq, Eq, Clone, scale_info::TypeInfo)] -pub struct EthereumSignature(pub [u8; 65]); - -impl sp_std::fmt::Debug for EthereumSignature { - fn fmt(&self, f: &mut sp_std::fmt::Formatter<'_>) -> sp_std::fmt::Result { - write!(f, "EthereumSignature({:?})", &self.0[..]) - } -} - -impl From for EthereumSignature { - fn from(signature: ecdsa::Signature) -> Self { - Self(signature.into()) - } -} - -impl sp_std::convert::TryFrom> for EthereumSignature { - type Error = (); - - fn try_from(data: Vec) -> Result { - if data.len() == 65 { - let mut inner = [0u8; 65]; - inner.copy_from_slice(&data[..]); - Ok(EthereumSignature(inner)) - } else { - Err(()) - } - } -} - -/// Constructs the message that Ethereum RPC's `personal_sign` and `eth_sign` would sign. -/// -/// Note: sign message hash to escape of message length estimation. -pub fn signable_message(what: &[u8]) -> Vec { - let hash = keccak_256(what); - let mut v = b"\x19Ethereum Signed Message:\n32".to_vec(); - v.extend_from_slice(&hash[..]); - v -} - -/// Attempts to recover the Ethereum public key from a message signature signed by using -/// the Ethereum RPC's `personal_sign` and `eth_sign`. -impl Verify for EthereumSignature { - type Signer = ::Signer; - - fn verify>( - &self, - mut msg: L, - account: &::AccountId, - ) -> bool { - let msg = keccak_256(&signable_message(msg.get())); - match secp256k1_ecdsa_recover_compressed(&self.0, &msg).ok() { - Some(public) => { - let signer = Self::Signer::from(ecdsa::Public::from_raw(public)); - *account == signer.into_account() - } - None => false, - } - } -} - -#[test] -fn verify_should_works() { - use hex_literal::hex; - use sp_core::{ecdsa, Pair}; - - let msg = "test eth signed message"; - let pair = ecdsa::Pair::from_seed(&hex![ - "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" - ]); - let account = ::Signer::from(pair.public()).into_account(); - let signature = EthereumSignature(hex!["f5d5cc953828e3fb0d81f3176d88fa5c73d3ad3dc4bc7a8061b03a6db2cd73337778df75a1443e8c642f6ceae0db39b90c321ac270ad7836695cae76f703f3031c"]); - assert_eq!(signature.verify(msg.as_ref(), &account), true); -} diff --git a/pallets/custom-signatures/src/lib.rs b/pallets/custom-signatures/src/lib.rs deleted file mode 100644 index 530cfd9d02..0000000000 --- a/pallets/custom-signatures/src/lib.rs +++ /dev/null @@ -1,220 +0,0 @@ -// This file is part of Astar. - -// Copyright (C) 2019-2023 Stake Technologies Pte.Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#![cfg_attr(not(feature = "std"), no_std)] - -pub use pallet::*; - -/// Ethereum-compatible signatures (eth_sign API call). -pub mod ethereum; - -#[cfg(test)] -mod tests; - -#[frame_support::pallet] -pub mod pallet { - use frame_support::{ - dispatch::{Dispatchable, GetDispatchInfo}, - pallet_prelude::*, - traits::{Currency, ExistenceRequirement, Get, OnUnbalanced, WithdrawReasons}, - }; - use frame_system::{ensure_none, pallet_prelude::*}; - use sp_runtime::traits::{IdentifyAccount, Verify}; - use sp_std::{convert::TryFrom, prelude::*}; - - #[pallet::pallet] - pub struct Pallet(_); - - /// The balance type of this pallet. - pub type BalanceOf = - <::Currency as Currency<::AccountId>>::Balance; - - #[pallet::config] - pub trait Config: frame_system::Config { - /// The overarching event type. - type RuntimeEvent: From> + IsType<::RuntimeEvent>; - - /// A signable call. - type RuntimeCall: Parameter - + Dispatchable - + GetDispatchInfo; - - /// User defined signature type. - type Signature: Parameter + Verify + TryFrom>; - - /// User defined signer type. - type Signer: IdentifyAccount; - - /// The currency trait. - type Currency: Currency; - - /// The call fee destination. - type OnChargeTransaction: OnUnbalanced< - >::NegativeImbalance, - >; - - /// The call processing fee amount. - #[pallet::constant] - type CallFee: Get>; - - /// The call magic number. - #[pallet::constant] - type CallMagicNumber: Get; - - /// A configuration for base priority of unsigned transactions. - /// - /// This is exposed so that it can be tuned for particular runtime, when - /// multiple pallets send unsigned transactions. - type UnsignedPriority: Get; - } - - #[pallet::error] - pub enum Error { - /// Signature decode fails. - DecodeFailure, - /// Signature and account mismatched. - InvalidSignature, - /// Bad nonce parameter. - BadNonce, - } - - #[pallet::event] - #[pallet::generate_deposit(pub(crate) fn deposit_event)] - pub enum Event { - /// A call just executed. \[result\] - Executed(T::AccountId, DispatchResult), - } - - #[pallet::call] - impl Pallet { - /// # - /// - O(1). - /// - Limited storage reads. - /// - One DB write (event). - /// - Weight of derivative `call` execution + read/write + 10_000. - /// # - #[pallet::call_index(0)] - #[pallet::weight({ - let dispatch_info = call.get_dispatch_info(); - (dispatch_info.weight.saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(1)) - .saturating_add(Weight::from_parts(10_000, 0)), - dispatch_info.class) - })] - pub fn call( - origin: OriginFor, - call: Box<::RuntimeCall>, - signer: T::AccountId, - signature: Vec, - #[pallet::compact] nonce: T::Index, - ) -> DispatchResultWithPostInfo { - ensure_none(origin)?; - - // Ensure that transaction isn't stale - ensure!( - nonce == frame_system::Pallet::::account_nonce(signer.clone()), - Error::::BadNonce, - ); - - let signature = ::Signature::try_from(signature) - .map_err(|_| Error::::DecodeFailure)?; - - // Ensure that transaction signature is valid - ensure!( - Self::valid_signature(&call, &signer, &signature, &nonce), - Error::::InvalidSignature - ); - - // Increment account nonce - frame_system::Pallet::::inc_account_nonce(signer.clone()); - - // Processing fee - let tx_fee = T::Currency::withdraw( - &signer, - T::CallFee::get(), - WithdrawReasons::FEE, - ExistenceRequirement::AllowDeath, - )?; - T::OnChargeTransaction::on_unbalanced(tx_fee); - - // Dispatch call - let new_origin = frame_system::RawOrigin::Signed(signer.clone()).into(); - let res = call.dispatch(new_origin).map(|_| ()); - Self::deposit_event(Event::Executed(signer, res.map_err(|e| e.error))); - - // Fee already charged - Ok(Pays::No.into()) - } - } - - impl Pallet { - /// Verify custom signature and returns `true` if correct. - pub fn valid_signature( - call: &Box<::RuntimeCall>, - signer: &T::AccountId, - signature: &T::Signature, - nonce: &T::Index, - ) -> bool { - let payload = (T::CallMagicNumber::get(), *nonce, call.clone()); - signature.verify(&payload.encode()[..], signer) - } - } - - pub(crate) const SIGNATURE_DECODE_FAILURE: u8 = 1; - - #[pallet::validate_unsigned] - impl frame_support::unsigned::ValidateUnsigned for Pallet { - type Call = Call; - - fn validate_unsigned(_source: TransactionSource, call: &Self::Call) -> TransactionValidity { - // Call decomposition (we have only one possible value here) - let (call, signer, signature, nonce) = match call { - Call::call { - call, - signer, - signature, - nonce, - } => (call, signer, signature, nonce), - _ => return InvalidTransaction::Call.into(), - }; - - // Check that tx isn't stale - if *nonce != frame_system::Pallet::::account_nonce(signer.clone()) { - return InvalidTransaction::Stale.into(); - } - - // Check signature encoding - if let Ok(signature) = ::Signature::try_from(signature.clone()) { - // Verify signature - if Self::valid_signature(call, signer, &signature, nonce) { - ValidTransaction::with_tag_prefix("CustomSignatures") - .priority(T::UnsignedPriority::get()) - .and_provides((call, signer, nonce)) - .longevity(64_u64) - .propagate(true) - .build() - } else { - // Signature mismatched to given signer - InvalidTransaction::BadProof.into() - } - } else { - // Signature encoding broken - InvalidTransaction::Custom(SIGNATURE_DECODE_FAILURE).into() - } - } - } -} diff --git a/pallets/custom-signatures/src/tests.rs b/pallets/custom-signatures/src/tests.rs deleted file mode 100644 index 67ac06eb9b..0000000000 --- a/pallets/custom-signatures/src/tests.rs +++ /dev/null @@ -1,334 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use crate as custom_signatures; -use assert_matches::assert_matches; -use custom_signatures::*; -use frame_support::{ - traits::{ConstU32, Contains}, - {assert_err, assert_ok, parameter_types}, -}; -use hex_literal::hex; -use parity_scale_codec::Encode; -use sp_core::{ecdsa, Pair}; -use sp_io::{hashing::keccak_256, TestExternalities}; -use sp_keyring::AccountKeyring as Keyring; -use sp_runtime::{ - testing::{Header, H256}, - traits::{BlakeTwo256, IdentifyAccount, IdentityLookup, Verify}, - transaction_validity::TransactionPriority, - MultiSignature, MultiSigner, -}; - -pub const ECDSA_SEED: [u8; 32] = - hex_literal::hex!["7e9c7ad85df5cdc88659f53e06fb2eb9bab3ebc59083a3190eaf2c730332529c"]; - -type Balance = u128; -type BlockNumber = u64; -type Signature = MultiSignature; -type AccountId = <::Signer as IdentifyAccount>::AccountId; -type Block = frame_system::mocking::MockBlock; -type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; - -frame_support::construct_runtime!( - pub enum Runtime where - Block = Block, - NodeBlock = Block, - UncheckedExtrinsic = UncheckedExtrinsic, - { - Balances: pallet_balances, - System: frame_system, - CustomSignatures: custom_signatures, - } -); - -parameter_types! { - pub const BlockHashCount: u64 = 250; -} - -pub struct NoRemarkFilter; -impl Contains for NoRemarkFilter { - fn contains(call: &RuntimeCall) -> bool { - match call { - RuntimeCall::System(method) => match method { - frame_system::Call::remark { .. } => false, - _ => true, - }, - _ => true, - } - } -} - -impl frame_system::Config for Runtime { - type RuntimeOrigin = RuntimeOrigin; - type BaseCallFilter = NoRemarkFilter; - type Index = u32; - type BlockNumber = BlockNumber; - type RuntimeCall = RuntimeCall; - type Hash = H256; - type Hashing = BlakeTwo256; - type AccountId = AccountId; - type Lookup = IdentityLookup; - type Header = Header; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = BlockHashCount; - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type DbWeight = (); - type SystemWeightInfo = (); - type BlockWeights = (); - type BlockLength = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; -} - -parameter_types! { - pub const ExistentialDeposit: Balance = 1; -} - -impl pallet_balances::Config for Runtime { - type Balance = Balance; - type RuntimeEvent = RuntimeEvent; - type DustRemoval = (); - type ExistentialDeposit = ExistentialDeposit; - type AccountStore = frame_system::Pallet; - type WeightInfo = (); - type MaxLocks = (); - type MaxReserves = (); - type ReserveIdentifier = (); - type HoldIdentifier = (); - type FreezeIdentifier = (); - type MaxHolds = ConstU32<0>; - type MaxFreezes = ConstU32<0>; -} - -const MAGIC_NUMBER: u16 = 0xff50; -parameter_types! { - pub const Priority: TransactionPriority = TransactionPriority::MAX; - pub const CallFee: Balance = 42; - pub const CallMagicNumber: u16 = MAGIC_NUMBER; -} - -impl Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type RuntimeCall = RuntimeCall; - type Signature = ethereum::EthereumSignature; - type Signer = ::Signer; - type CallMagicNumber = CallMagicNumber; - type Currency = Balances; - type CallFee = CallFee; - type OnChargeTransaction = (); - type UnsignedPriority = Priority; -} - -fn new_test_ext() -> TestExternalities { - let mut storage = frame_system::GenesisConfig::default() - .build_storage::() - .unwrap(); - - let pair = ecdsa::Pair::from_seed(&ECDSA_SEED); - let account = MultiSigner::from(pair.public()).into_account(); - let _ = pallet_balances::GenesisConfig:: { - balances: vec![(account, 1_000_000_000)], - } - .assimilate_storage(&mut storage); - - let mut ext = TestExternalities::from(storage); - ext.execute_with(|| System::set_block_number(1)); - ext -} - -/// Simple `eth_sign` implementation, should be equal to exported by RPC -fn eth_sign(seed: &[u8; 32], data: &[u8]) -> Vec { - let call_msg = ethereum::signable_message(data); - let ecdsa_msg = libsecp256k1::Message::parse(&keccak_256(&call_msg)); - let secret = libsecp256k1::SecretKey::parse(&seed).expect("valid seed"); - let (signature, recovery_id) = libsecp256k1::sign(&ecdsa_msg, &secret); - let mut out = Vec::new(); - out.extend_from_slice(&signature.serialize()[..]); - // Fix recovery ID: Ethereum uses 27/28 notation - out.push(recovery_id.serialize() + 27); - out -} - -#[test] -fn eth_sign_works() { - let seed = hex!["ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"]; - let text = b"Hello Astar"; - let signature = hex!["0cc6d5de6db06727fe43a260e7c9a417be3daab9b0e4e65e276f543e5c2f3de67e9e26d903d5301181e13033f61692db2dca67c1f8992b62476eaf8cb3a597101c"]; - assert_eq!(eth_sign(&seed, &text[..]), signature); -} - -#[test] -fn invalid_signature() { - let bob: ::AccountId = Keyring::Bob.into(); - let alice: ::AccountId = Keyring::Alice.into(); - let call = pallet_balances::Call::::transfer { - dest: alice.clone(), - value: 1_000, - } - .into(); - let signature = Vec::from(&hex!["dd0992d40e5cdf99db76bed162808508ac65acd7ae2fdc8573594f03ed9c939773e813181788fc02c3c68f3fdc592759b35f6354484343e18cb5317d34dab6c61b"][..]); - new_test_ext().execute_with(|| { - assert_err!( - CustomSignatures::call(RuntimeOrigin::none(), Box::new(call), bob, signature, 0), - Error::::InvalidSignature, - ); - }); -} - -#[test] -fn balance_transfer() { - new_test_ext().execute_with(|| { - let pair = ecdsa::Pair::from_seed(&ECDSA_SEED); - let account = MultiSigner::from(pair.public()).into_account(); - - let alice: ::AccountId = Keyring::Alice.into(); - assert_eq!(System::account(alice.clone()).data.free, 0); - - let call: RuntimeCall = pallet_balances::Call::::transfer { - dest: alice.clone(), - value: 1_000, - } - .into(); - let payload = (MAGIC_NUMBER, 0u32, call.clone()); - let signature = eth_sign(&ECDSA_SEED, payload.encode().as_ref()).into(); - - assert_eq!(System::account(account.clone()).nonce, 0); - assert_ok!(CustomSignatures::call( - RuntimeOrigin::none(), - Box::new(call.clone()), - account.clone(), - signature, - 0, - )); - assert_eq!(System::account(alice.clone()).data.free, 1_000); - assert_eq!(System::account(account.clone()).nonce, 1); - assert_eq!(System::account(account.clone()).data.free, 999_998_958); - assert_matches!( - System::events() - .last() - .expect("events expected") - .event - .clone(), - RuntimeEvent::CustomSignatures(Event::Executed(used_account, Ok(..),)) - if used_account == account - ); - - let signature = eth_sign(&ECDSA_SEED, payload.encode().as_ref()).into(); - assert_err!( - CustomSignatures::call( - RuntimeOrigin::none(), - Box::new(call.clone()), - account.clone(), - signature, - 0, - ), - Error::::BadNonce, - ); - - let payload = (MAGIC_NUMBER, 1u32, call.clone()); - let signature = eth_sign(&ECDSA_SEED, payload.encode().as_ref()).into(); - assert_eq!(System::account(account.clone()).nonce, 1); - assert_ok!(CustomSignatures::call( - RuntimeOrigin::none(), - Box::new(call.clone()), - account.clone(), - signature, - 1, - )); - assert_eq!(System::account(alice).data.free, 2_000); - assert_eq!(System::account(account.clone()).nonce, 2); - assert_eq!(System::account(account.clone()).data.free, 999_997_916); - }) -} - -#[test] -fn call_fixtures() { - use sp_core::crypto::Ss58Codec; - - let seed = hex!["ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"]; - let pair = ecdsa::Pair::from_seed(&seed); - assert_eq!( - MultiSigner::from(pair.public()) - .into_account() - .to_ss58check(), - "5EGynCAEvv8NLeHx8vDMvb8hTcEcMYUMWCDQEEncNEfNWB2W", - ); - - let dest = - AccountId::from_ss58check("5GVwcV6EzxxYbXBm7H6dtxc9TCgL4oepMXtgqWYEc3VXJoaf").unwrap(); - let call: RuntimeCall = - pallet_balances::Call::::transfer_allow_death { dest, value: 1000 }.into(); - assert_eq!( - call.encode(), - hex!["0000c4305fb88b6ccb43d6552dc11d18e7b0ee3185247adcc6e885eb284adf6c563da10f"], - ); - - let payload = (MAGIC_NUMBER, 0u32, call.clone()); - assert_eq!( - payload.encode(), - hex![ - "50ff000000000000c4305fb88b6ccb43d6552dc11d18e7b0ee3185247adcc6e885eb284adf6c563da10f" - ], - ); - - let signature = hex!["6ecb474240df46ee5cde8f51cf5ccf4c75d15ac3c1772aea6c8189604263c98b16350883438c4eaa447ebcb6889d516f70351fd704bb3521072cd2fccc7c99dc1c"]; - assert_eq!(eth_sign(&seed, payload.encode().as_ref()), signature) -} - -#[test] -fn not_allowed_call_filtered() { - new_test_ext().execute_with(|| { - let pair = ecdsa::Pair::from_seed(&ECDSA_SEED); - let account = MultiSigner::from(pair.public()).into_account(); - - let alice: ::AccountId = Keyring::Alice.into(); - assert_eq!(System::account(alice.clone()).data.free, 0); - - let call: RuntimeCall = frame_system::Call::::remark { - remark: Vec::<_>::new(), - } - .into(); - // sanity check, call should be filtered out - assert!(!::BaseCallFilter::contains(&call)); - - let payload = (MAGIC_NUMBER, 0u32, call.clone()); - let signature = eth_sign(&ECDSA_SEED, payload.encode().as_ref()).into(); - - assert_eq!(System::account(account.clone()).nonce, 0); - assert_ok!(CustomSignatures::call( - RuntimeOrigin::none(), - Box::new(call.clone()), - account.clone(), - signature, - 0, - )); - assert_eq!(System::account(account.clone()).nonce, 1); - - assert_matches!( - System::events() - .last() - .expect("events expected") - .event - .clone(), - RuntimeEvent::CustomSignatures(Event::Executed(used_account, Err(..),)) - if used_account == account - ); - }) -}