Skip to content

Commit 592de62

Browse files
committed
test benchmarking
1 parent ff5c446 commit 592de62

File tree

1 file changed

+33
-7
lines changed

1 file changed

+33
-7
lines changed

substrate/frame/indices/src/benchmarking.rs

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,17 +207,43 @@ mod benchmarks {
207207

208208
#[benchmark]
209209
fn migrate_account_step() -> Result<(), BenchmarkError> {
210-
let account = account("account", 0, SEED);
211-
let index = T::AccountIndex::from(SEED);
212-
let frozen = false;
213-
let old_deposit = T::Deposit::get();
210+
use crate::migration::v1::v0;
211+
212+
// Setup: Create an account in the OLD currency system that needs migration
213+
let account_index = T::AccountIndex::from(SEED);
214+
let caller: T::AccountId = whitelisted_caller();
215+
let deposit = T::Deposit::get();
216+
217+
// Give the account some balance (enough for deposit + existential deposit)
218+
T::NativeBalance::set_balance(
219+
&caller,
220+
T::NativeBalance::minimum_balance() + deposit + deposit,
221+
);
222+
223+
// Reserve funds using the old Currency system
224+
<pallet_balances::Pallet<T> as ReservableCurrency<T::AccountId>>::reserve(&caller, deposit)?;
225+
226+
// Insert into the OLD storage (v0) to simulate pre-migration state
227+
v0::OldAccounts::<T>::insert(account_index, (caller.clone(), deposit, false));
228+
214229
#[block]
215230
{
216231
let _ = MigrateCurrencyToFungibles::<T, pallet_balances::Pallet<T>>::step(None, &mut WeightMeter::new());
217232
}
218-
assert_eq!(Accounts::<T>::get(index).unwrap().0, account);
219-
assert_eq!(Accounts::<T>::get(index).unwrap().1, old_deposit);
220-
assert_eq!(Accounts::<T>::get(index).unwrap().2, frozen);
233+
234+
// Verify the account was migrated to the new storage
235+
assert!(Accounts::<T>::contains_key(account_index));
236+
let (migrated_account, migrated_deposit, frozen) = Accounts::<T>::get(account_index).unwrap();
237+
assert_eq!(migrated_account, caller);
238+
assert_eq!(migrated_deposit, deposit);
239+
assert_eq!(frozen, false);
240+
241+
// Verify the hold was created in the new fungible system
242+
assert_eq!(
243+
T::NativeBalance::balance_on_hold(&HoldReason::DepositForIndex.into(), &caller),
244+
deposit
245+
);
246+
221247
Ok(())
222248
}
223249

0 commit comments

Comments
 (0)