Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
more test refining
Browse files Browse the repository at this point in the history
  • Loading branch information
claravanstaden committed Jun 4, 2024
1 parent 1d53294 commit f3e569b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use frame_support::{
pallet_prelude::PhantomData,
weights::WeightMeter,
};
use scale_info::TypeInfo;
use sp_core::Get;

mod test;
Expand Down Expand Up @@ -40,7 +39,7 @@ mod v0 {
pub type ExecutionHeaderMapping<T: Config> =
StorageMap<Pallet<T>, Identity, u32, H256, ValueQuery>;

#[derive(Copy, Clone, Default, Encode, Decode, TypeInfo, MaxEncodedLen)]
#[derive(Copy, Clone, Default, Encode, Decode, Debug, TypeInfo, MaxEncodedLen, PartialEq)]
pub struct ExecutionHeaderState {
pub beacon_block_root: H256,
pub beacon_slot: u64,
Expand Down Expand Up @@ -84,6 +83,7 @@ impl<T: Config, W: weights::WeightInfo, M: Get<u32>> SteppedMigration
mut cursor: Option<Self::Cursor>,
meter: &mut WeightMeter,
) -> Result<Option<Self::Cursor>, SteppedMigrationError> {
log::info!(target: LOG_TARGET, "Starting stepped migration iteration.");
let required = W::step();
// If there is not enough weight for a single step, return an error. This case can be
// problematic if it is the first migration that ran in this block. But there is nothing
Expand Down
20 changes: 14 additions & 6 deletions bridges/snowbridge/pallets/ethereum-client/src/migration/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ use crate::{
},
mock::new_tester,
tests::{
run_to_block_with_migrator, AllPalletsWithSystem, MigratorServiceWeight, System, Test,
run_to_block_with_migrator, AllPalletsWithSystem, ExecutionHeaderCount,
MigratorServiceWeight, System, Test,
},
};
use frame_support::traits::OnRuntimeUpgrade;
Expand All @@ -32,7 +33,10 @@ fn ethereum_execution_header_migration_works() {
});
ExecutionHeaderIndex::<Test>::set(5500);

for index in 0..10 {
let execution_header_count = 5500;

let mut block_roots: Vec<H256> = vec![];
for index in 0..execution_header_count {
let block_root = H256::random();
ExecutionHeaders::<Test>::insert(
block_root,
Expand All @@ -44,23 +48,27 @@ fn ethereum_execution_header_migration_works() {
},
);
ExecutionHeaderMapping::<Test>::insert(index as u32, block_root);
println!("block: {}", block_root);
block_roots.push(block_root);
}

// Give it enough weight to do exactly 16 iterations:
let limit = <Test as pallet_migrations::Config>::WeightInfo::progress_mbms_none() +
pallet_migrations::Pallet::<Test>::exec_migration_max_weight() +
SubstrateWeight::<Test>::step() * 16;
MigratorServiceWeight::set(&limit);
ExecutionHeaderCount::set(&(execution_header_count as u32));

System::set_block_number(1);
AllPalletsWithSystem::on_runtime_upgrade(); // onboard MBMs

// Check everything is empty
for index in 0..10 {
for index in 0..execution_header_count {
run_to_block_with_migrator(index + 2);
let value = ExecutionHeaderMapping::<Test>::get(index as u32);
assert_eq!(value, H256::zero())
let block_root_hash = block_roots.get(index as usize).unwrap();
assert_eq!(ExecutionHeaderMapping::<Test>::get(index as u32), H256::zero());
assert!(ExecutionHeaders::<Test>::get(block_root_hash).is_none());
}
assert_eq!(LatestExecutionState::<Test>::get(), ExecutionHeaderState::default());
assert_eq!(ExecutionHeaderIndex::<Test>::get(), 0);
});
}
2 changes: 1 addition & 1 deletion bridges/snowbridge/pallets/ethereum-client/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl ethereum_beacon_client::Config for Test {
}

parameter_types! {
pub const ExecutionHeaderCount: u32 = 10;
pub storage ExecutionHeaderCount: u32 = 100;
pub storage MigratorServiceWeight: Weight = Weight::from_parts(100, 100);
}

Expand Down

0 comments on commit f3e569b

Please sign in to comment.