fixing all the compilations errors for mock

This commit is contained in:
undercover-cactus 2026-03-24 10:07:39 +01:00
parent b64ee7165f
commit 6605faf245
16 changed files with 106 additions and 19 deletions

1
operator/Cargo.lock generated
View file

@ -8897,6 +8897,7 @@ dependencies = [
"parity-scale-codec",
"precompile-utils",
"scale-info",
"serde",
"sp-core",
"sp-io",
"sp-runtime",

View file

@ -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 {

View file

@ -142,6 +142,8 @@ impl pallet_evm::Config for Runtime {
type GasWeightMapping = pallet_evm::FixedGasWeightMapping<Self>;
type WeightPerGas = WeightPerGas;
type CallOrigin = EnsureAddressRoot<AccountId>;
type CreateOriginFilter = ();
type CreateInnerOriginFilter = ();
type WithdrawOrigin = EnsureAddressNever<AccountId>;
type AddressMapping = AccountId;
type Currency = Balances;

View file

@ -126,6 +126,8 @@ impl pallet_evm::Config for Runtime {
type GasWeightMapping = pallet_evm::FixedGasWeightMapping<Self>;
type WeightPerGas = WeightPerGas;
type CallOrigin = EnsureAddressRoot<AccountId>;
type CreateOriginFilter = ();
type CreateInnerOriginFilter = ();
type WithdrawOrigin = EnsureAddressNever<AccountId>;
type AddressMapping = AccountId;
type Currency = Balances;

View file

@ -143,6 +143,8 @@ impl pallet_evm::Config for Runtime {
type GasWeightMapping = pallet_evm::FixedGasWeightMapping<Self>;
type WeightPerGas = WeightPerGas;
type CallOrigin = EnsureAddressRoot<AccountId>;
type CreateOriginFilter = ();
type CreateInnerOriginFilter = ();
type WithdrawOrigin = EnsureAddressNever<AccountId>;
type AddressMapping = AccountId;
type Currency = Balances;

View file

@ -133,6 +133,8 @@ impl pallet_evm::Config for Runtime {
type GasWeightMapping = pallet_evm::FixedGasWeightMapping<Self>;
type WeightPerGas = WeightPerGas;
type CallOrigin = EnsureAddressRoot<AccountId>;
type CreateOriginFilter = ();
type CreateInnerOriginFilter = ();
type WithdrawOrigin = EnsureAddressNever<AccountId>;
type AddressMapping = AccountId;
type Currency = Balances;
@ -266,7 +268,7 @@ impl pallet_conviction_voting::Config for Runtime {
type WeightInfo = ();
type MaxTurnout = TotalIssuanceOf<Balances, Self::AccountId>;
type Polls = TestPolls;
type BlockNumberProvider = ();
type BlockNumberProvider = frame_system::Pallet<Runtime>;
type VotingHooks = ();
}

View file

@ -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<Self>;
type WeightPerGas = WeightPerGas;
type CallOrigin = EnsureAddressRoot<AccountId>;
type CreateOriginFilter = ();
type CreateInnerOriginFilter = ();
type WithdrawOrigin = EnsureAddressNever<AccountId>;
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 {

View file

@ -127,6 +127,8 @@ impl pallet_evm::Config for Runtime {
type GasWeightMapping = pallet_evm::FixedGasWeightMapping<Self>;
type WeightPerGas = WeightPerGas;
type CallOrigin = EnsureAddressRoot<AccountId>;
type CreateOriginFilter = ();
type CreateInnerOriginFilter = ();
type WithdrawOrigin = EnsureAddressNever<AccountId>;
type AddressMapping = AccountId;
type Currency = Balances;

View file

@ -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" ] }

View file

@ -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<Runtime>;
// 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<sp_core::ecdsa::Signature> for MockSignature {
fn from(x: sp_core::ecdsa::Signature) -> Self {
MockSignature(x)
}
}
impl From<sp_runtime::MultiSignature> 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<L: sp_runtime::traits::Lazy<[u8]>>(&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<Self>;
type WeightPerGas = WeightPerGas;
type CallOrigin = EnsureAddressRoot<AccountId>;
type CreateOriginFilter = ();
type CreateInnerOriginFilter = ();
type WithdrawOrigin = EnsureAddressNever<AccountId>;
type AddressMapping = AccountId;
type Currency = Balances;

View file

@ -49,6 +49,7 @@ fn evm_call(source: impl Into<H160>, input: Vec<u8>) -> EvmCall<Runtime> {
max_priority_fee_per_gas: Some(U256::zero()),
nonce: None,
access_list: Vec::new(),
authorization_list: Vec::new(),
}
}

View file

@ -127,6 +127,8 @@ impl pallet_evm::Config for Runtime {
type GasWeightMapping = pallet_evm::FixedGasWeightMapping<Self>;
type WeightPerGas = WeightPerGas;
type CallOrigin = EnsureAddressRoot<AccountId>;
type CreateOriginFilter = ();
type CreateInnerOriginFilter = ();
type WithdrawOrigin = EnsureAddressNever<AccountId>;
type AddressMapping = AccountId;
type Currency = Balances;

View file

@ -125,6 +125,8 @@ impl pallet_evm::Config for Runtime {
type GasWeightMapping = pallet_evm::FixedGasWeightMapping<Self>;
type WeightPerGas = WeightPerGas;
type CallOrigin = EnsureAddressRoot<AccountId>;
type CreateOriginFilter = ();
type CreateInnerOriginFilter = ();
type WithdrawOrigin = EnsureAddressNever<AccountId>;
type AddressMapping = AccountId;
type Currency = Balances;

View file

@ -168,6 +168,8 @@ impl pallet_evm::Config for Runtime {
type GasWeightMapping = pallet_evm::FixedGasWeightMapping<Self>;
type WeightPerGas = WeightPerGas;
type CallOrigin = EnsureAddressAlways;
type CreateOriginFilter = ();
type CreateInnerOriginFilter = ();
type WithdrawOrigin = EnsureAddressNever<AccountId>;
type AddressMapping = AccountId;
type Currency = Balances;

View file

@ -166,6 +166,8 @@ impl pallet_evm::Config for Runtime {
type GasWeightMapping = pallet_evm::FixedGasWeightMapping<Self>;
type WeightPerGas = WeightPerGas;
type CallOrigin = EnsureAddressRoot<AccountId>;
type CreateOriginFilter = ();
type CreateInnerOriginFilter = ();
type WithdrawOrigin = EnsureAddressNever<AccountId>;
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<Balance, u32> for TestTracksInfo {
fn tracks() -> impl Iterator<Item = Cow<'static, Track<Self::Id, Balance, u32>>> {
static DATA: [Track<u8, u128, u32>; 2] = [
(
0,
TrackInfo {
Track {
id: 0,
info: TrackInfo {
name: str_array("root"),
max_deciding: 1,
decision_deposit: 10,
@ -349,10 +353,10 @@ impl TracksInfo<Balance, u32> 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<Balance, u32> for TestTracksInfo {
ceil: Perbill::from_percent(50),
},
},
),
},
];
TRACKS
DATA.iter().map(Cow::Borrowed)
}
fn track_for(origin: &Self::RuntimeOrigin) -> Result<Self::Id, ()> {
@ -402,6 +406,7 @@ impl pallet_referenda::Config for Runtime {
type AlarmInterval = ();
type Tracks = TestTracksInfo;
type Preimages = Preimage;
type BlockNumberProvider = ();
}
pub(crate) struct ExtBuilder {

View file

@ -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 = <Runtime as pallet_referenda::Config>::Tracks::tracks().len();
let oob_track_id = <Runtime as pallet_referenda::Config>::Tracks::tracks().count();
// submit with an invalid track_id
let input: Vec<u8> = PCall::submit_at {