From 6605faf245c723e7bed2f182e815653872dc0c8d Mon Sep 17 00:00:00 2001 From: undercover-cactus Date: Tue, 24 Mar 2026 10:07:39 +0100 Subject: [PATCH] fixing all the compilations errors for mock --- operator/Cargo.lock | 1 + .../proxy-genesis-companion/src/mock.rs | 2 +- operator/precompiles/batch/src/mock.rs | 2 + operator/precompiles/call-permit/src/mock.rs | 2 + operator/precompiles/collective/src/mock.rs | 2 + .../precompiles/conviction-voting/src/mock.rs | 4 +- .../datahaven-native-transfer/src/mock.rs | 6 +- .../precompiles/erc20-balances/src/mock.rs | 2 + operator/precompiles/identity/Cargo.toml | 4 ++ operator/precompiles/identity/src/mock.rs | 66 +++++++++++++++++-- operator/precompiles/identity/src/tests.rs | 1 + .../precompile-registry/src/mock.rs | 2 + operator/precompiles/preimage/src/mock.rs | 2 + operator/precompiles/proxy/src/mock.rs | 2 + operator/precompiles/referenda/src/mock.rs | 25 ++++--- operator/precompiles/referenda/src/tests.rs | 2 +- 16 files changed, 106 insertions(+), 19 deletions(-) diff --git a/operator/Cargo.lock b/operator/Cargo.lock index b8ba7881..cf90f05d 100644 --- a/operator/Cargo.lock +++ b/operator/Cargo.lock @@ -8897,6 +8897,7 @@ dependencies = [ "parity-scale-codec", "precompile-utils", "scale-info", + "serde", "sp-core", "sp-io", "sp-runtime", diff --git a/operator/pallets/proxy-genesis-companion/src/mock.rs b/operator/pallets/proxy-genesis-companion/src/mock.rs index 29734e8e..ef57a1d9 100644 --- a/operator/pallets/proxy-genesis-companion/src/mock.rs +++ b/operator/pallets/proxy-genesis-companion/src/mock.rs @@ -109,7 +109,7 @@ impl pallet_proxy::Config for Test { type CallHasher = BlakeTwo256; type AnnouncementDepositBase = AnnouncementDepositBase; type AnnouncementDepositFactor = AnnouncementDepositFactor; - type BlockNumberProvider = (); + type BlockNumberProvider = System; } impl Config for Test { diff --git a/operator/precompiles/batch/src/mock.rs b/operator/precompiles/batch/src/mock.rs index 7af4c141..85e2ada3 100644 --- a/operator/precompiles/batch/src/mock.rs +++ b/operator/precompiles/batch/src/mock.rs @@ -142,6 +142,8 @@ impl pallet_evm::Config for Runtime { type GasWeightMapping = pallet_evm::FixedGasWeightMapping; type WeightPerGas = WeightPerGas; type CallOrigin = EnsureAddressRoot; + type CreateOriginFilter = (); + type CreateInnerOriginFilter = (); type WithdrawOrigin = EnsureAddressNever; type AddressMapping = AccountId; type Currency = Balances; diff --git a/operator/precompiles/call-permit/src/mock.rs b/operator/precompiles/call-permit/src/mock.rs index 504bc924..4eb53cb4 100644 --- a/operator/precompiles/call-permit/src/mock.rs +++ b/operator/precompiles/call-permit/src/mock.rs @@ -126,6 +126,8 @@ impl pallet_evm::Config for Runtime { type GasWeightMapping = pallet_evm::FixedGasWeightMapping; type WeightPerGas = WeightPerGas; type CallOrigin = EnsureAddressRoot; + type CreateOriginFilter = (); + type CreateInnerOriginFilter = (); type WithdrawOrigin = EnsureAddressNever; type AddressMapping = AccountId; type Currency = Balances; diff --git a/operator/precompiles/collective/src/mock.rs b/operator/precompiles/collective/src/mock.rs index 10614256..bbdf6833 100644 --- a/operator/precompiles/collective/src/mock.rs +++ b/operator/precompiles/collective/src/mock.rs @@ -143,6 +143,8 @@ impl pallet_evm::Config for Runtime { type GasWeightMapping = pallet_evm::FixedGasWeightMapping; type WeightPerGas = WeightPerGas; type CallOrigin = EnsureAddressRoot; + type CreateOriginFilter = (); + type CreateInnerOriginFilter = (); type WithdrawOrigin = EnsureAddressNever; type AddressMapping = AccountId; type Currency = Balances; diff --git a/operator/precompiles/conviction-voting/src/mock.rs b/operator/precompiles/conviction-voting/src/mock.rs index 90ab3458..cdff74bc 100644 --- a/operator/precompiles/conviction-voting/src/mock.rs +++ b/operator/precompiles/conviction-voting/src/mock.rs @@ -133,6 +133,8 @@ impl pallet_evm::Config for Runtime { type GasWeightMapping = pallet_evm::FixedGasWeightMapping; type WeightPerGas = WeightPerGas; type CallOrigin = EnsureAddressRoot; + type CreateOriginFilter = (); + type CreateInnerOriginFilter = (); type WithdrawOrigin = EnsureAddressNever; type AddressMapping = AccountId; type Currency = Balances; @@ -266,7 +268,7 @@ impl pallet_conviction_voting::Config for Runtime { type WeightInfo = (); type MaxTurnout = TotalIssuanceOf; type Polls = TestPolls; - type BlockNumberProvider = (); + type BlockNumberProvider = frame_system::Pallet; type VotingHooks = (); } diff --git a/operator/precompiles/datahaven-native-transfer/src/mock.rs b/operator/precompiles/datahaven-native-transfer/src/mock.rs index f4c7be83..ea2f2624 100644 --- a/operator/precompiles/datahaven-native-transfer/src/mock.rs +++ b/operator/precompiles/datahaven-native-transfer/src/mock.rs @@ -21,7 +21,7 @@ use super::*; use frame_support::traits::Everything; use frame_support::{construct_runtime, parameter_types, weights::Weight}; use pallet_evm::{EnsureAddressNever, EnsureAddressRoot, FrameSystemAccountProvider}; -use parity_scale_codec::{Decode, Encode}; +use parity_scale_codec::{Decode, DecodeWithMemTracking, Encode}; use precompile_utils::{mock_account, precompile_set::*, testing::MockAccount}; use snowbridge_core::TokenId; use snowbridge_outbound_queue_primitives::v1::Ticket; @@ -146,6 +146,8 @@ impl pallet_evm::Config for Runtime { type GasWeightMapping = pallet_evm::FixedGasWeightMapping; type WeightPerGas = WeightPerGas; type CallOrigin = EnsureAddressRoot; + type CreateOriginFilter = (); + type CreateInnerOriginFilter = (); type WithdrawOrigin = EnsureAddressNever; type AddressMapping = AccountId; type Currency = Balances; @@ -194,7 +196,7 @@ impl SendMessage for MockOutboundQueue { } } -#[derive(Clone, Encode, Decode)] +#[derive(Clone, Encode, Decode, DecodeWithMemTracking)] pub struct MockTicket; impl Ticket for MockTicket { diff --git a/operator/precompiles/erc20-balances/src/mock.rs b/operator/precompiles/erc20-balances/src/mock.rs index f7213ccf..35bc3727 100644 --- a/operator/precompiles/erc20-balances/src/mock.rs +++ b/operator/precompiles/erc20-balances/src/mock.rs @@ -127,6 +127,8 @@ impl pallet_evm::Config for Runtime { type GasWeightMapping = pallet_evm::FixedGasWeightMapping; type WeightPerGas = WeightPerGas; type CallOrigin = EnsureAddressRoot; + type CreateOriginFilter = (); + type CreateInnerOriginFilter = (); type WithdrawOrigin = EnsureAddressNever; type AddressMapping = AccountId; type Currency = Balances; diff --git a/operator/precompiles/identity/Cargo.toml b/operator/precompiles/identity/Cargo.toml index b826ed31..0162614f 100644 --- a/operator/precompiles/identity/Cargo.toml +++ b/operator/precompiles/identity/Cargo.toml @@ -21,6 +21,10 @@ fp-evm = { workspace = true } pallet-evm = { workspace = true, features = [ "forbid-evm-reentrancy" ] } precompile-utils = { workspace = true } +# Temp +## TODO/ remove it once we move to 2506 +serde = { workspace = true } + [dev-dependencies] pallet-balances = { workspace = true, features = [ "std" ] } diff --git a/operator/precompiles/identity/src/mock.rs b/operator/precompiles/identity/src/mock.rs index ebb79c20..e91b7a7b 100644 --- a/operator/precompiles/identity/src/mock.rs +++ b/operator/precompiles/identity/src/mock.rs @@ -25,10 +25,12 @@ use frame_system::{EnsureRoot, EnsureSignedBy}; use pallet_evm::{EnsureAddressNever, EnsureAddressRoot, FrameSystemAccountProvider}; use pallet_identity::legacy::IdentityInfo; use precompile_utils::mock_account; -use precompile_utils::{ - precompile_set::*, - testing::{MockAccount, MockSignature}, -}; +use precompile_utils::testing::MockSigner; +use precompile_utils::{precompile_set::*, testing::MockAccount}; +use scale_info::TypeInfo; +use serde::{Deserialize, Serialize}; +use sp_core::keccak_256; +use sp_core::{Decode, DecodeWithMemTracking, Encode}; use sp_core::{H256, U256}; use sp_runtime::{ traits::{BlakeTwo256, IdentityLookup}, @@ -40,6 +42,60 @@ pub type Balance = u128; type Block = frame_system::mocking::MockBlockU32; +// TODO: remove this chunk once we moved to 2506. `MockSignature` was missing the `DecodeWithMemTracking` trait in frontier 2503. +// We should be able to use the one from frontier when migrating to 2506 +#[derive( + Eq, + PartialEq, + Clone, + Encode, + Decode, + DecodeWithMemTracking, + sp_core::RuntimeDebug, + TypeInfo, + Serialize, + Deserialize, +)] +pub struct MockSignature(sp_core::ecdsa::Signature); + +impl From for MockSignature { + fn from(x: sp_core::ecdsa::Signature) -> Self { + MockSignature(x) + } +} + +impl From for MockSignature { + fn from(signature: sp_runtime::MultiSignature) -> Self { + match signature { + sp_runtime::MultiSignature::Ed25519(_) => { + panic!("Ed25519 not supported for MockSignature") + } + sp_runtime::MultiSignature::Sr25519(_) => { + panic!("Sr25519 not supported for MockSignature") + } + sp_runtime::MultiSignature::Ecdsa(sig) => Self(sig), + } + } +} + +impl sp_runtime::traits::Verify for MockSignature { + type Signer = MockSigner; + fn verify>(&self, mut msg: L, signer: &MockAccount) -> bool { + let mut m = [0u8; 32]; + m.copy_from_slice(keccak_256(msg.get()).as_slice()); + match sp_io::crypto::secp256k1_ecdsa_recover(self.0.as_ref(), &m) { + Ok(pubkey) => { + MockAccount(sp_core::H160::from_slice( + &keccak_256(&pubkey).as_slice()[12..32], + )) == *signer + } + Err(sp_io::EcdsaVerifyError::BadRS) => false, + Err(sp_io::EcdsaVerifyError::BadV) => false, + Err(sp_io::EcdsaVerifyError::BadSignature) => false, + } + } +} + construct_runtime!( pub enum Runtime { System: frame_system, @@ -136,6 +192,8 @@ impl pallet_evm::Config for Runtime { type GasWeightMapping = pallet_evm::FixedGasWeightMapping; type WeightPerGas = WeightPerGas; type CallOrigin = EnsureAddressRoot; + type CreateOriginFilter = (); + type CreateInnerOriginFilter = (); type WithdrawOrigin = EnsureAddressNever; type AddressMapping = AccountId; type Currency = Balances; diff --git a/operator/precompiles/identity/src/tests.rs b/operator/precompiles/identity/src/tests.rs index 7efa1519..e3d25173 100644 --- a/operator/precompiles/identity/src/tests.rs +++ b/operator/precompiles/identity/src/tests.rs @@ -49,6 +49,7 @@ fn evm_call(source: impl Into, input: Vec) -> EvmCall { max_priority_fee_per_gas: Some(U256::zero()), nonce: None, access_list: Vec::new(), + authorization_list: Vec::new(), } } diff --git a/operator/precompiles/precompile-registry/src/mock.rs b/operator/precompiles/precompile-registry/src/mock.rs index c78fda24..c1a66780 100644 --- a/operator/precompiles/precompile-registry/src/mock.rs +++ b/operator/precompiles/precompile-registry/src/mock.rs @@ -127,6 +127,8 @@ impl pallet_evm::Config for Runtime { type GasWeightMapping = pallet_evm::FixedGasWeightMapping; type WeightPerGas = WeightPerGas; type CallOrigin = EnsureAddressRoot; + type CreateOriginFilter = (); + type CreateInnerOriginFilter = (); type WithdrawOrigin = EnsureAddressNever; type AddressMapping = AccountId; type Currency = Balances; diff --git a/operator/precompiles/preimage/src/mock.rs b/operator/precompiles/preimage/src/mock.rs index 1687718c..6bb4279a 100644 --- a/operator/precompiles/preimage/src/mock.rs +++ b/operator/precompiles/preimage/src/mock.rs @@ -125,6 +125,8 @@ impl pallet_evm::Config for Runtime { type GasWeightMapping = pallet_evm::FixedGasWeightMapping; type WeightPerGas = WeightPerGas; type CallOrigin = EnsureAddressRoot; + type CreateOriginFilter = (); + type CreateInnerOriginFilter = (); type WithdrawOrigin = EnsureAddressNever; type AddressMapping = AccountId; type Currency = Balances; diff --git a/operator/precompiles/proxy/src/mock.rs b/operator/precompiles/proxy/src/mock.rs index fbb79b90..394a1787 100644 --- a/operator/precompiles/proxy/src/mock.rs +++ b/operator/precompiles/proxy/src/mock.rs @@ -168,6 +168,8 @@ impl pallet_evm::Config for Runtime { type GasWeightMapping = pallet_evm::FixedGasWeightMapping; type WeightPerGas = WeightPerGas; type CallOrigin = EnsureAddressAlways; + type CreateOriginFilter = (); + type CreateInnerOriginFilter = (); type WithdrawOrigin = EnsureAddressNever; type AddressMapping = AccountId; type Currency = Balances; diff --git a/operator/precompiles/referenda/src/mock.rs b/operator/precompiles/referenda/src/mock.rs index 901adc6f..903f476f 100644 --- a/operator/precompiles/referenda/src/mock.rs +++ b/operator/precompiles/referenda/src/mock.rs @@ -166,6 +166,8 @@ impl pallet_evm::Config for Runtime { type GasWeightMapping = pallet_evm::FixedGasWeightMapping; type WeightPerGas = WeightPerGas; type CallOrigin = EnsureAddressRoot; + type CreateOriginFilter = (); + type CreateInnerOriginFilter = (); type WithdrawOrigin = EnsureAddressNever; type AddressMapping = AccountId; type Currency = Balances; @@ -247,7 +249,9 @@ parameter_types! { pub struct TestTracksInfo; // Simple tally implementation for testing -#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode, TypeInfo, MaxEncodedLen)] +#[derive( + Debug, Clone, PartialEq, Eq, Encode, Decode, DecodeWithMemTracking, TypeInfo, MaxEncodedLen, +)] pub struct Tally { pub ayes: u128, pub nays: u128, @@ -328,9 +332,9 @@ impl TracksInfo for TestTracksInfo { fn tracks() -> impl Iterator>> { static DATA: [Track; 2] = [ - ( - 0, - TrackInfo { + Track { + id: 0, + info: TrackInfo { name: str_array("root"), max_deciding: 1, decision_deposit: 10, @@ -349,10 +353,10 @@ impl TracksInfo for TestTracksInfo { ceil: Perbill::from_percent(50), }, }, - ), - ( - 1, - TrackInfo { + }, + Track { + id: 1, + info: TrackInfo { name: str_array("none"), max_deciding: 1, decision_deposit: 10, @@ -371,9 +375,9 @@ impl TracksInfo for TestTracksInfo { ceil: Perbill::from_percent(50), }, }, - ), + }, ]; - TRACKS + DATA.iter().map(Cow::Borrowed) } fn track_for(origin: &Self::RuntimeOrigin) -> Result { @@ -402,6 +406,7 @@ impl pallet_referenda::Config for Runtime { type AlarmInterval = (); type Tracks = TestTracksInfo; type Preimages = Preimage; + type BlockNumberProvider = (); } pub(crate) struct ExtBuilder { diff --git a/operator/precompiles/referenda/src/tests.rs b/operator/precompiles/referenda/src/tests.rs index f786f4aa..0a9c1862 100644 --- a/operator/precompiles/referenda/src/tests.rs +++ b/operator/precompiles/referenda/src/tests.rs @@ -296,7 +296,7 @@ fn submit_track_id_oob_fails() { .execute_with(|| { let proposal = vec![1, 2, 3]; let proposal_hash = sp_runtime::traits::BlakeTwo256::hash(&proposal); - let oob_track_id = ::Tracks::tracks().len(); + let oob_track_id = ::Tracks::tracks().count(); // submit with an invalid track_id let input: Vec = PCall::submit_at {