diff --git a/bridges/snowbridge/pallets/ethereum-client/src/migration/mod.rs b/bridges/snowbridge/pallets/ethereum-client/src/migration/mod.rs index ec5c78f85bd0..d2c5856fb565 100644 --- a/bridges/snowbridge/pallets/ethereum-client/src/migration/mod.rs +++ b/bridges/snowbridge/pallets/ethereum-client/src/migration/mod.rs @@ -6,7 +6,6 @@ use frame_support::{ pallet_prelude::PhantomData, weights::WeightMeter, }; -use scale_info::TypeInfo; use sp_core::Get; mod test; @@ -40,7 +39,7 @@ mod v0 { pub type ExecutionHeaderMapping = StorageMap, 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, @@ -84,6 +83,7 @@ impl> SteppedMigration mut cursor: Option, meter: &mut WeightMeter, ) -> Result, 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 diff --git a/bridges/snowbridge/pallets/ethereum-client/src/migration/test.rs b/bridges/snowbridge/pallets/ethereum-client/src/migration/test.rs index 48e269d2bec6..fe085faf1eba 100644 --- a/bridges/snowbridge/pallets/ethereum-client/src/migration/test.rs +++ b/bridges/snowbridge/pallets/ethereum-client/src/migration/test.rs @@ -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; @@ -32,7 +33,10 @@ fn ethereum_execution_header_migration_works() { }); ExecutionHeaderIndex::::set(5500); - for index in 0..10 { + let execution_header_count = 5500; + + let mut block_roots: Vec = vec![]; + for index in 0..execution_header_count { let block_root = H256::random(); ExecutionHeaders::::insert( block_root, @@ -44,7 +48,7 @@ fn ethereum_execution_header_migration_works() { }, ); ExecutionHeaderMapping::::insert(index as u32, block_root); - println!("block: {}", block_root); + block_roots.push(block_root); } // Give it enough weight to do exactly 16 iterations: @@ -52,15 +56,19 @@ fn ethereum_execution_header_migration_works() { pallet_migrations::Pallet::::exec_migration_max_weight() + SubstrateWeight::::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::::get(index as u32); - assert_eq!(value, H256::zero()) + let block_root_hash = block_roots.get(index as usize).unwrap(); + assert_eq!(ExecutionHeaderMapping::::get(index as u32), H256::zero()); + assert!(ExecutionHeaders::::get(block_root_hash).is_none()); } + assert_eq!(LatestExecutionState::::get(), ExecutionHeaderState::default()); + assert_eq!(ExecutionHeaderIndex::::get(), 0); }); } diff --git a/bridges/snowbridge/pallets/ethereum-client/src/mock.rs b/bridges/snowbridge/pallets/ethereum-client/src/mock.rs index 58b5d5d08945..36ce1dda7bae 100644 --- a/bridges/snowbridge/pallets/ethereum-client/src/mock.rs +++ b/bridges/snowbridge/pallets/ethereum-client/src/mock.rs @@ -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); }