Skip to content

Commit

Permalink
fix: redeem test cases + add back
Browse files Browse the repository at this point in the history
  • Loading branch information
nakul1010 committed Dec 21, 2023
1 parent 0f67fd9 commit 339bfa7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
3 changes: 3 additions & 0 deletions crates/redeem/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,8 @@ mod spec_based_tests {
assert_eq!(tokens, &burned_tokens);
MockResult::Return(Ok((wrapped(0), griefing(0))))
});
ext::vault_registry::get_vault_max_premium_redeem::<Test>
.mock_safe(|_| MockResult::Return(Ok(collateral(0))));

// The returned `replaceCollateral` MUST be released
currency::Amount::unlock_on.mock_safe(move |collateral_amount, vault_id| {
Expand Down Expand Up @@ -919,6 +921,7 @@ mod spec_based_tests {
assert_eq!(vault, &VAULT);
MockResult::Return(Ok(()))
});
ext::vault_registry::is_vault_below_secure_threshold::<Test>.mock_safe(|_| MockResult::Return(Ok(false)));
Amount::<Test>::unlock_on.mock_safe(|_, _| MockResult::Return(Ok(())));
Amount::<Test>::transfer.mock_safe(|_, _, _| MockResult::Return(Ok(())));
ext::vault_registry::transfer_funds_saturated::<Test>
Expand Down
6 changes: 4 additions & 2 deletions crates/vault-registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1563,7 +1563,6 @@ impl<T: Config> Pallet<T> {
Ok(Self::get_vault_from_id(&vault_id)?.is_liquidated())
}

#[cfg(feature = "integration-tests")]
// note: unlike `is_vault_below_secure_threshold` and `is_vault_below_liquidation_threshold`,
// this function uses to_be_backed tokens
pub fn will_be_below_premium_threshold(vault_id: &DefaultVaultId<T>) -> Result<bool, DispatchError> {
Expand Down Expand Up @@ -1707,7 +1706,10 @@ impl<T: Config> Pallet<T> {

let request_redeem_tokens_for_max_premium = vault_to_burn_tokens.checked_div(&amount_wrapped).ok()?;

if Self::ensure_not_banned(&vault_id).is_ok() && !request_redeem_tokens_for_max_premium.is_zero() {
if Self::ensure_not_banned(&vault_id).is_ok() && !request_redeem_tokens_for_max_premium.is_zero()
// need the check as `inclusion_fee` will be a non zero amount, hence `request_redeem_tokens_for_max_premium` will also be a non zero amount
&& Self::will_be_below_premium_threshold(&vault_id).unwrap_or(false)
{
Some((vault_id, request_redeem_tokens_for_max_premium))
} else {
None
Expand Down
14 changes: 14 additions & 0 deletions parachain/runtime/runtime-tests/src/parachain/redeem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,20 @@ mod premium_redeem_tests {
});
}

#[test]
fn integration_test_try_get_premium_vaults_which_is_sufficiently_collateralized_then_under_collateralized() {
test_setup_for_premium_redeem(|vault_id| {
assert_noop!(
RedeemPallet::get_premium_redeem_vaults(),
VaultRegistryError::NoVaultUnderThePremiumRedeemThreshold
);

// put vault under premium redeem threshold
setup_vault_below_premium_threshold(vault_id.clone());
assert_eq!(RedeemPallet::get_premium_redeem_vaults().unwrap().len(), 1);
});
}

#[test]
fn integration_test_redeem_max_premium_redeemable_token() {
test_setup_for_premium_redeem(|vault_id| {
Expand Down

0 comments on commit 339bfa7

Please sign in to comment.