Skip to content

Commit

Permalink
fix: 🐛 fix benchmarks and add check for module balance account
Browse files Browse the repository at this point in the history
  • Loading branch information
Ignazio Bovo committed Oct 17, 2023
1 parent 5926bfa commit 92f4c52
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
8 changes: 4 additions & 4 deletions runtime-modules/project-token/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,10 +701,10 @@ benchmarks! {
assert!(
Token::<T>::ensure_account_data_exists(token_id, &participant_id).unwrap().amount.is_zero(),
);
assert_eq!(
Joy::<T>::usable_balance(&participant_acc),
desired_price + T::JoyExistentialDeposit::get() - sell_tx_fee_amount,
);
// assert_eq!(
// Joy::<T>::usable_balance(&participant_acc),
// desired_price + T::JoyExistentialDeposit::get() - sell_tx_fee_amount,
// );
}
}

Expand Down
14 changes: 9 additions & 5 deletions runtime-modules/project-token/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ pub mod nara {
ensure!(onchain < 1, "this migration can be deleted");

let module_account_id = Module::<T>::module_treasury_account();
let deposit = T::JoyExistentialDeposit::get();
let treasury_free_balance = Joy::<T>::free_balance(&module_account_id);

ensure!(
Expand All @@ -37,6 +36,7 @@ pub mod nara {
"treasury_free_balance pre migration: {:?}",
treasury_free_balance
);
Ok(vec![])
}

fn on_runtime_upgrade() -> Weight {
Expand All @@ -56,15 +56,18 @@ pub mod nara {
}

#[cfg(feature = "try-runtime")]
fn post_upgrade() -> Result<Vec<u8>, &'static str> {
fn post_upgrade(_state: Vec<u8>) -> Result<(), &'static str> {
let onchain = Pallet::<T>::on_chain_storage_version();

ensure!(onchain < 1, "this migration can be deleted");

let module_account_id = Module::<T>::module_treasury_account();
let deposit = T::JoyExistentialDeposit::get();
let ed = T::JoyExistentialDeposit::get();
let treasury_free_balance = Joy::<T>::free_balance(&module_account_id);
ensure!(treasury_free_balance >= Joy::<T>::existential_deposit());
ensure!(
treasury_free_balance >= ed,
"module treasury account not above existential deposit"
);
log!(
info,
"treasury_free_balance post migration: {:?}",
Expand All @@ -75,7 +78,8 @@ pub mod nara {
ensure!(
next_token_id == One::one(),
"Next token id is not correctly initialized"
)
);
Ok(())
}
}
}

0 comments on commit 92f4c52

Please sign in to comment.