From ee6fe93b261bea742369c07eb33298d5839459a7 Mon Sep 17 00:00:00 2001 From: microwavedcola1 Date: Fri, 13 May 2022 15:01:52 +0200 Subject: [PATCH] Fix tests Signed-off-by: microwavedcola1 --- programs/mango-v4/tests/test_liq_tokens.rs | 3 +- .../mango-v4/tests/test_position_lifetime.rs | 38 +++++++++++++------ 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/programs/mango-v4/tests/test_liq_tokens.rs b/programs/mango-v4/tests/test_liq_tokens.rs index 8b49cd07d..47534d1d8 100644 --- a/programs/mango-v4/tests/test_liq_tokens.rs +++ b/programs/mango-v4/tests/test_liq_tokens.rs @@ -462,13 +462,14 @@ async fn test_liq_tokens_with_token() -> Result<(), BanksClientError> { // health after borrow2 liquidation was (1000-32) * 0.6 - 350 * 2 * 1.4 = -399.2 // borrow1 needed 399.2 / (1.4*2 - 0.6*2*1.04) = 257.2 // asset cost = 257.2 * 2 * 1.04 = 535 + // loan orignation fee = 1 assert_eq!( account_position(solana, account, borrow_token1.bank).await, -350 + 257 ); assert_eq!( account_position(solana, account, collateral_token1.bank).await, - 1000 - 32 - 535 + 1000 - 32 - 535 - 1 ); let liqee: MangoAccount = solana.get_account(account).await; assert_eq!(liqee.being_liquidated, 0); diff --git a/programs/mango-v4/tests/test_position_lifetime.rs b/programs/mango-v4/tests/test_position_lifetime.rs index 555f7c1b6..892617e51 100644 --- a/programs/mango-v4/tests/test_position_lifetime.rs +++ b/programs/mango-v4/tests/test_position_lifetime.rs @@ -171,17 +171,33 @@ async fn test_position_lifetime() -> Result<()> { ); // give it back, closing the position - send_tx( - solana, - DepositInstruction { - amount: borrow_amount, - account, - token_account: payer_mint_accounts[1], - token_authority: payer, - }, - ) - .await - .unwrap(); + { + send_tx( + solana, + DepositInstruction { + // deposit withdraw amount + some more to cover loan origination fees + amount: borrow_amount + 2, + account, + token_account: payer_mint_accounts[1], + token_authority: payer, + }, + ) + .await + .unwrap(); + send_tx( + solana, + WithdrawInstruction { + // withdraw residual amount left + amount: u64::MAX, + allow_borrow: false, + account, + owner, + token_account: payer_mint_accounts[1], + }, + ) + .await + .unwrap(); + } // withdraw the collateral, closing the position send_tx(