Skip to content

Commit bc74d06

Browse files
committed
removed idempotent
1 parent 2b7b273 commit bc74d06

File tree

2 files changed

+0
-81
lines changed

2 files changed

+0
-81
lines changed

substrate/frame/assets/precompiles/src/migration.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ pub enum MigrationState<A> {
7676
///
7777
/// # Safety
7878
///
79-
/// - Idempotent: Skips assets that already have mappings
8079
/// - Non-destructive: Does not modify any asset data, only adds mappings
8180
/// - Sequential indices: Each migrated asset gets the next available index
8281
pub struct MigrateForeignAssetPrecompileMappings<T, I = (), W = ()>(PhantomData<(T, I, W)>);
@@ -254,16 +253,6 @@ where
254253
};
255254

256255
if let Some(asset_id) = iter.next() {
257-
// Check if mapping already exists (idempotent)
258-
if pallet::Pallet::<T>::asset_index_of(&asset_id).is_some() {
259-
log::debug!(
260-
target: "runtime::MigrateForeignAssetPrecompileMappings",
261-
"Skipping asset {:?} - mapping already exists",
262-
asset_id
263-
);
264-
return (MigrationState::Asset(asset_id), W::migrate_asset_step_skip());
265-
}
266-
267256
// Insert the bidirectional mapping with a new sequential index
268257
match pallet::Pallet::<T>::insert_asset_mapping(&asset_id) {
269258
Ok(asset_index) => {

substrate/frame/assets/precompiles/src/migration_tests.rs

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -260,76 +260,6 @@ fn migration_populates_precompile_mappings() {
260260
});
261261
}
262262

263-
/// Test that the migration is idempotent - running it twice produces the same result.
264-
///
265-
/// Idempotency is critical: the second run should not modify any existing mappings.
266-
#[test]
267-
fn migration_is_idempotent() {
268-
new_test_ext().execute_with(|| {
269-
let owner = 1u64;
270-
271-
let asset_location_1 = Location::new(1, [Junction::Parachain(1234)]);
272-
let asset_location_2 = Location::new(1, [Junction::Parachain(5678)]);
273-
274-
pallet_assets::Asset::<Test, ForeignAssetsInstance>::insert(
275-
asset_location_1.clone(),
276-
create_asset_details(owner),
277-
);
278-
pallet_assets::Asset::<Test, ForeignAssetsInstance>::insert(
279-
asset_location_2.clone(),
280-
create_asset_details(owner),
281-
);
282-
283-
// Verify mappings do not exist before migration
284-
assert!(
285-
pallet::Pallet::<Test>::asset_index_of(&asset_location_1).is_none(),
286-
"Mapping 1 should NOT exist before migration"
287-
);
288-
assert!(
289-
pallet::Pallet::<Test>::asset_index_of(&asset_location_2).is_none(),
290-
"Mapping 2 should NOT exist before migration"
291-
);
292-
293-
run_migration_to_completion();
294-
295-
// Get the indices assigned during first run
296-
let index_1 = pallet::Pallet::<Test>::asset_index_of(&asset_location_1).unwrap();
297-
let index_2 = pallet::Pallet::<Test>::asset_index_of(&asset_location_2).unwrap();
298-
299-
// Capture complete state after first run
300-
let state_after_first = (
301-
pallet::Pallet::<Test>::asset_id_of(index_1),
302-
pallet::Pallet::<Test>::asset_id_of(index_2),
303-
pallet::Pallet::<Test>::asset_index_of(&asset_location_1),
304-
pallet::Pallet::<Test>::asset_index_of(&asset_location_2),
305-
pallet::Pallet::<Test>::next_asset_index(),
306-
);
307-
308-
// Verify mappings were created correctly after first run
309-
assert!(state_after_first.0.is_some(), "Forward mapping 1 should exist after first run");
310-
assert!(state_after_first.1.is_some(), "Forward mapping 2 should exist after first run");
311-
assert!(state_after_first.2.is_some(), "Reverse mapping 1 should exist after first run");
312-
assert!(state_after_first.3.is_some(), "Reverse mapping 2 should exist after first run");
313-
314-
run_migration_to_completion();
315-
316-
// Capture complete state after second run
317-
let state_after_second = (
318-
pallet::Pallet::<Test>::asset_id_of(index_1),
319-
pallet::Pallet::<Test>::asset_id_of(index_2),
320-
pallet::Pallet::<Test>::asset_index_of(&asset_location_1),
321-
pallet::Pallet::<Test>::asset_index_of(&asset_location_2),
322-
pallet::Pallet::<Test>::next_asset_index(),
323-
);
324-
325-
// State must be identical after second run
326-
assert_eq!(
327-
state_after_first, state_after_second,
328-
"Idempotency violation: migration modified mappings on second run"
329-
);
330-
});
331-
}
332-
333263
/// Test that the migration handles the case with no foreign assets gracefully.
334264
#[test]
335265
fn migration_handles_empty_foreign_assets() {

0 commit comments

Comments
 (0)