From becf0d97a54803a10cb7b1c864b48d08ff3e650c Mon Sep 17 00:00:00 2001 From: Sander Bosma Date: Mon, 28 Mar 2022 10:41:00 +0200 Subject: [PATCH] refactor!: more explicit error when vault is liquidated --- crates/vault-registry/src/lib.rs | 14 +++++++++----- standalone/runtime/tests/test_redeem.rs | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/crates/vault-registry/src/lib.rs b/crates/vault-registry/src/lib.rs index eae7e9c6b1..22a03ccc55 100644 --- a/crates/vault-registry/src/lib.rs +++ b/crates/vault-registry/src/lib.rs @@ -563,6 +563,10 @@ pub mod pallet { MaxNominationRatioViolation, /// The collateral ceiling would be exceeded for the vault's currency CurrencyCeilingExceeded, + /// Vault is no longer usable as it was liquidated due to theft + VaultCommittedTheft, + /// Vault is no longer usable as it was liquidated due to undercollateralization + VaultLiquidated, // Errors used exclusively in RPC functions /// Collateralization is infinite if no tokens are issued @@ -764,11 +768,11 @@ impl Pallet { /// Like get_vault_from_id, but additionally checks that the vault is active pub fn get_active_vault_from_id(vault_id: &DefaultVaultId) -> Result, DispatchError> { let vault = Self::get_vault_from_id(vault_id)?; - ensure!( - matches!(vault.status, VaultStatus::Active(_)), - Error::::VaultNotFound - ); - Ok(vault) + match vault.status { + VaultStatus::Active(_) => Ok(vault), + VaultStatus::Liquidated => Err(Error::::VaultLiquidated.into()), + VaultStatus::CommittedTheft => Err(Error::::VaultCommittedTheft.into()), + } } /// Deposit an `amount` of collateral to be used for collateral tokens diff --git a/standalone/runtime/tests/test_redeem.rs b/standalone/runtime/tests/test_redeem.rs index 31ecaa791d..90dcd86256 100644 --- a/standalone/runtime/tests/test_redeem.rs +++ b/standalone/runtime/tests/test_redeem.rs @@ -267,7 +267,7 @@ mod spec_based_tests { vault_id: vault_id.clone(), }) .dispatch(origin_of(account_of(ALICE))), - VaultRegistryError::VaultNotFound, + VaultRegistryError::VaultLiquidated, ); }); }