From af40733f973f5b2ed48230b9815b8c31bde35136 Mon Sep 17 00:00:00 2001 From: claravanstaden Date: Wed, 17 Jan 2024 15:26:53 +0200 Subject: [PATCH] update test modules --- parachain/pallets/ethereum-client/Cargo.toml | 2 - .../ethereum-client/src/benchmarking/mod.rs | 19 +- parachain/pallets/ethereum-client/src/mock.rs | 254 ++++++------------ .../pallets/ethereum-client/src/tests.rs | 11 +- 4 files changed, 80 insertions(+), 206 deletions(-) diff --git a/parachain/pallets/ethereum-client/Cargo.toml b/parachain/pallets/ethereum-client/Cargo.toml index 6eb0e8b767..400efaee70 100644 --- a/parachain/pallets/ethereum-client/Cargo.toml +++ b/parachain/pallets/ethereum-client/Cargo.toml @@ -95,5 +95,3 @@ try-runtime = [ "pallet-timestamp?/try-runtime", "sp-runtime/try-runtime", ] -beacon-spec-minimal = [] -fast-runtime = ["beacon-spec-minimal"] diff --git a/parachain/pallets/ethereum-client/src/benchmarking/mod.rs b/parachain/pallets/ethereum-client/src/benchmarking/mod.rs index 807d4de14e..493855f33f 100644 --- a/parachain/pallets/ethereum-client/src/benchmarking/mod.rs +++ b/parachain/pallets/ethereum-client/src/benchmarking/mod.rs @@ -7,14 +7,6 @@ use crate::Pallet as EthereumBeaconClient; use frame_benchmarking::v2::*; use frame_system::RawOrigin; -#[cfg(feature = "beacon-spec-minimal")] -mod fixtures_minimal; -#[cfg(feature = "beacon-spec-minimal")] -use fixtures_minimal::*; - -#[cfg(not(feature = "beacon-spec-minimal"))] -mod fixtures_mainnet; -#[cfg(not(feature = "beacon-spec-minimal"))] use fixtures_mainnet::*; use primitives::{ @@ -151,16 +143,9 @@ mod benchmarks { Ok(()) } - #[cfg(feature = "beacon-spec-minimal")] impl_benchmark_test_suite!( EthereumBeaconClient, - crate::mock::minimal::new_tester(), - crate::mock::minimal::Test - ); - #[cfg(not(feature = "beacon-spec-minimal"))] - impl_benchmark_test_suite!( - EthereumBeaconClient, - crate::mock::mainnet::new_tester(), - crate::mock::mainnet::Test + crate::mock::new_tester(), + crate::mock:::Test ); } diff --git a/parachain/pallets/ethereum-client/src/mock.rs b/parachain/pallets/ethereum-client/src/mock.rs index 217d37db8d..8828eadec8 100644 --- a/parachain/pallets/ethereum-client/src/mock.rs +++ b/parachain/pallets/ethereum-client/src/mock.rs @@ -10,10 +10,9 @@ use snowbridge_core::inbound::{Log, Proof}; use sp_core::H256; use sp_runtime::traits::{BlakeTwo256, IdentityLookup}; use std::{fs::File, path::PathBuf}; +type Block = frame_system::mocking::MockBlock; +use sp_runtime::BuildStorage; -#[cfg(feature = "beacon-spec-minimal")] -const SPEC: &str = "minimal"; -#[cfg(not(feature = "beacon-spec-minimal"))] const SPEC: &str = "mainnet"; fn load_fixture(basename: String) -> Result @@ -98,187 +97,86 @@ pub fn get_message_verification_header() -> CompactExecutionHeader { } } -#[cfg(feature = "beacon-spec-minimal")] -pub mod minimal { - use super::*; - - use sp_runtime::BuildStorage; - - type Block = frame_system::mocking::MockBlock; - - frame_support::construct_runtime!( - pub enum Test { - System: frame_system::{Pallet, Call, Storage, Event}, - Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent}, - EthereumBeaconClient: ethereum_beacon_client::{Pallet, Call, Storage, Event}, - } - ); - - parameter_types! { - pub const BlockHashCount: u64 = 250; - pub const SS58Prefix: u8 = 42; - } - - impl frame_system::Config for Test { - type BaseCallFilter = frame_support::traits::Everything; - type OnSetCode = (); - type BlockWeights = (); - type BlockLength = (); - type DbWeight = (); - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; - type Hash = H256; - type Hashing = BlakeTwo256; - type AccountId = u64; - type Lookup = IdentityLookup; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = BlockHashCount; - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = (); - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = SS58Prefix; - type MaxConsumers = frame_support::traits::ConstU32<16>; - type Nonce = u64; - type Block = Block; - } - - impl pallet_timestamp::Config for Test { - type Moment = u64; - type OnTimestampSet = (); - type MinimumPeriod = (); - type WeightInfo = (); +frame_support::construct_runtime!( + pub enum Test { + System: frame_system::{Pallet, Call, Storage, Event}, + Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent}, + EthereumBeaconClient: ethereum_beacon_client::{Pallet, Call, Storage, Event}, } +); - parameter_types! { - pub const ExecutionHeadersPruneThreshold: u32 = 10; - pub const ChainForkVersions: ForkVersions = ForkVersions{ - genesis: Fork { - version: [0, 0, 0, 1], // 0x00000001 - epoch: 0, - }, - altair: Fork { - version: [1, 0, 0, 1], // 0x01000001 - epoch: 0, - }, - bellatrix: Fork { - version: [2, 0, 0, 1], // 0x02000001 - epoch: 0, - }, - capella: Fork { - version: [3, 0, 0, 1], // 0x03000001 - epoch: 0, - }, - }; - } - - impl ethereum_beacon_client::Config for Test { - type RuntimeEvent = RuntimeEvent; - type ForkVersions = ChainForkVersions; - type MaxExecutionHeadersToKeep = ExecutionHeadersPruneThreshold; - type WeightInfo = (); - } - - // Build genesis storage according to the mock runtime. - pub fn new_tester() -> sp_io::TestExternalities { - let t = frame_system::GenesisConfig::::default().build_storage().unwrap(); - let mut ext = sp_io::TestExternalities::new(t); - let _ = ext.execute_with(|| Timestamp::set(RuntimeOrigin::signed(1), 30_000)); - ext - } +parameter_types! { + pub const BlockHashCount: u64 = 250; + pub const SS58Prefix: u8 = 42; } -#[cfg(not(feature = "beacon-spec-minimal"))] -pub mod mainnet { - use super::*; - - type Block = frame_system::mocking::MockBlock; - use sp_runtime::BuildStorage; - - frame_support::construct_runtime!( - pub enum Test { - System: frame_system::{Pallet, Call, Storage, Event}, - Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent}, - EthereumBeaconClient: ethereum_beacon_client::{Pallet, Call, Storage, Event}, - } - ); - - parameter_types! { - pub const BlockHashCount: u64 = 250; - pub const SS58Prefix: u8 = 42; - } - - impl frame_system::Config for Test { - type BaseCallFilter = frame_support::traits::Everything; - type OnSetCode = (); - type BlockWeights = (); - type BlockLength = (); - type DbWeight = (); - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; - type RuntimeTask = RuntimeTask; - type Hash = H256; - type Hashing = BlakeTwo256; - type AccountId = u64; - type Lookup = IdentityLookup; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = BlockHashCount; - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = (); - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = SS58Prefix; - type MaxConsumers = frame_support::traits::ConstU32<16>; - type Nonce = u64; - type Block = Block; - } +impl frame_system::Config for Test { + type BaseCallFilter = frame_support::traits::Everything; + type OnSetCode = (); + type BlockWeights = (); + type BlockLength = (); + type DbWeight = (); + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; + type Hash = H256; + type Hashing = BlakeTwo256; + type AccountId = u64; + type Lookup = IdentityLookup; + type RuntimeEvent = RuntimeEvent; + type BlockHashCount = BlockHashCount; + type Version = (); + type PalletInfo = PalletInfo; + type AccountData = (); + type OnNewAccount = (); + type OnKilledAccount = (); + type SystemWeightInfo = (); + type SS58Prefix = SS58Prefix; + type MaxConsumers = frame_support::traits::ConstU32<16>; + type Nonce = u64; + type Block = Block; +} - impl pallet_timestamp::Config for Test { - type Moment = u64; - type OnTimestampSet = (); - type MinimumPeriod = (); - type WeightInfo = (); - } +impl pallet_timestamp::Config for Test { + type Moment = u64; + type OnTimestampSet = (); + type MinimumPeriod = (); + type WeightInfo = (); +} - parameter_types! { - pub const ChainForkVersions: ForkVersions = ForkVersions { - genesis: Fork { - version: [144, 0, 0, 111], // 0x90000069 - epoch: 0, - }, - altair: Fork { - version: [144, 0, 0, 112], // 0x90000070 - epoch: 50, - }, - bellatrix: Fork { - version: [144, 0, 0, 113], // 0x90000071 - epoch: 100, - }, - capella: Fork { - version: [144, 0, 0, 114], // 0x90000072 - epoch: 56832, - }, - }; - pub const ExecutionHeadersPruneThreshold: u32 = 8192; - } +parameter_types! { + pub const ChainForkVersions: ForkVersions = ForkVersions { + genesis: Fork { + version: [144, 0, 0, 111], // 0x90000069 + epoch: 0, + }, + altair: Fork { + version: [144, 0, 0, 112], // 0x90000070 + epoch: 50, + }, + bellatrix: Fork { + version: [144, 0, 0, 113], // 0x90000071 + epoch: 100, + }, + capella: Fork { + version: [144, 0, 0, 114], // 0x90000072 + epoch: 56832, + }, + }; + pub const ExecutionHeadersPruneThreshold: u32 = 8192; +} - impl ethereum_beacon_client::Config for Test { - type RuntimeEvent = RuntimeEvent; - type ForkVersions = ChainForkVersions; - type MaxExecutionHeadersToKeep = ExecutionHeadersPruneThreshold; - type WeightInfo = (); - } +impl ethereum_beacon_client::Config for Test { + type RuntimeEvent = RuntimeEvent; + type ForkVersions = ChainForkVersions; + type MaxExecutionHeadersToKeep = ExecutionHeadersPruneThreshold; + type WeightInfo = (); +} - // Build genesis storage according to the mock runtime. - pub fn new_tester() -> sp_io::TestExternalities { - let t = frame_system::GenesisConfig::::default().build_storage().unwrap(); - let mut ext = sp_io::TestExternalities::new(t); - let _ = ext.execute_with(|| Timestamp::set(RuntimeOrigin::signed(1), 30_000)); - ext - } +// Build genesis storage according to the mock runtime. +pub fn new_tester() -> sp_io::TestExternalities { + let t = frame_system::GenesisConfig::::default().build_storage().unwrap(); + let mut ext = sp_io::TestExternalities::new(t); + let _ = ext.execute_with(|| Timestamp::set(RuntimeOrigin::signed(1), 30_000)); + ext } diff --git a/parachain/pallets/ethereum-client/src/tests.rs b/parachain/pallets/ethereum-client/src/tests.rs index d6346d3aaf..44c47ccbac 100644 --- a/parachain/pallets/ethereum-client/src/tests.rs +++ b/parachain/pallets/ethereum-client/src/tests.rs @@ -13,15 +13,7 @@ use crate::mock::{ load_next_sync_committee_update_fixture, load_sync_committee_update_fixture, }; -#[cfg(feature = "beacon-spec-minimal")] -pub use crate::config::minimal::*; -#[cfg(feature = "beacon-spec-minimal")] -pub use crate::mock::minimal::*; - -#[cfg(not(feature = "beacon-spec-minimal"))] -pub use crate::config::mainnet::*; -#[cfg(not(feature = "beacon-spec-minimal"))] -pub use crate::mock::mainnet::*; +pub use crate::mock::*; use frame_support::{assert_err, assert_noop, assert_ok}; use hex_literal::hex; @@ -35,6 +27,7 @@ use snowbridge_core::{ }; use sp_core::H256; use sp_runtime::DispatchError; +use crate::config::{EPOCHS_PER_SYNC_COMMITTEE_PERIOD, SLOTS_PER_EPOCH}; /// Arbitrary hash used for tests and invalid hashes. const TEST_HASH: [u8; 32] =