Skip to content

Commit

Permalink
update test modules
Browse files Browse the repository at this point in the history
  • Loading branch information
claravanstaden authored and claravanstaden committed Jan 17, 2024
1 parent 87e363d commit 80ab7ce
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 207 deletions.
2 changes: 0 additions & 2 deletions parachain/pallets/ethereum-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,3 @@ try-runtime = [
"pallet-timestamp?/try-runtime",
"sp-runtime/try-runtime",
]
beacon-spec-minimal = []
fast-runtime = ["beacon-spec-minimal"]
19 changes: 2 additions & 17 deletions parachain/pallets/ethereum-client/src/benchmarking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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
);
}
254 changes: 76 additions & 178 deletions parachain/pallets/ethereum-client/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Test>;
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<T>(basename: String) -> Result<T, serde_json::Error>
Expand Down Expand Up @@ -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<Test>;

frame_support::construct_runtime!(
pub enum Test {
System: frame_system::{Pallet, Call, Storage, Event<T>},
Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent},
EthereumBeaconClient: ethereum_beacon_client::{Pallet, Call, Storage, Event<T>},
}
);

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<Self::AccountId>;
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<T>},
Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent},
EthereumBeaconClient: ethereum_beacon_client::{Pallet, Call, Storage, Event<T>},
}
);

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::<Test>::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<Test>;
use sp_runtime::BuildStorage;

frame_support::construct_runtime!(
pub enum Test {
System: frame_system::{Pallet, Call, Storage, Event<T>},
Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent},
EthereumBeaconClient: ethereum_beacon_client::{Pallet, Call, Storage, Event<T>},
}
);

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<Self::AccountId>;
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<Self::AccountId>;
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::<Test>::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::<Test>::default().build_storage().unwrap();
let mut ext = sp_io::TestExternalities::new(t);
let _ = ext.execute_with(|| Timestamp::set(RuntimeOrigin::signed(1), 30_000));
ext
}
11 changes: 2 additions & 9 deletions parachain/pallets/ethereum-client/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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] =
Expand Down
2 changes: 1 addition & 1 deletion polkadot-sdk

0 comments on commit 80ab7ce

Please sign in to comment.