From eceeac080297a2c36f17fff6d48079f9079bc349 Mon Sep 17 00:00:00 2001 From: Brendon Votteler Date: Fri, 1 Mar 2024 13:40:56 +1100 Subject: [PATCH] test: add test for vaultsAPI.withdrawAllCollateral --- .../staging/sequential/vaults.partial.ts | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/integration/parachain/staging/sequential/vaults.partial.ts b/test/integration/parachain/staging/sequential/vaults.partial.ts index 0cbca1fad..5273fb238 100644 --- a/test/integration/parachain/staging/sequential/vaults.partial.ts +++ b/test/integration/parachain/staging/sequential/vaults.partial.ts @@ -143,6 +143,27 @@ export const vaultsTests = () => { } }); + // PRECONDITION: vault_2 must have some collateral in KSM or DOT + it("should be able to withdraw all collateral", async () => { + const interBtcAPI = new DefaultInterBtcApi(api, "regtest", vault_2, ESPLORA_BASE_PATH); + // const currencyTicker = collateralCurrency.ticker; + const collateralCurrency = getCorrespondingCollateralCurrenciesForTests(governanceCurrency)[0]; + const accountId = newAccountId(api, vault_2.address); + + const collateralAmountBefore = await interBtcAPI.vaults.getCollateral(accountId, collateralCurrency); + + // method under test + await submitExtrinsic(interBtcAPI, await interBtcAPI.vaults.withdrawAllCollateral(collateralCurrency)); + + const collateralAmountAfter = await interBtcAPI.vaults.getCollateral(accountId, collateralCurrency); + + const differenceAmount = collateralAmountBefore.sub(collateralAmountAfter); + expect(differenceAmount.toBig().toNumber()).toBeGreaterThan(0); + + // replenish + await submitExtrinsic(interBtcAPI, interBtcAPI.vaults.depositCollateral(differenceAmount)); + }); + it("should getLiquidationCollateralThreshold", async () => { for (const collateralCurrency of collateralCurrencies) { const currencyTicker = collateralCurrency.ticker;