Skip to content

Commit

Permalink
fix test of rebalance
Browse files Browse the repository at this point in the history
  • Loading branch information
esteblock committed Nov 11, 2024
1 parent d796ce7 commit 65b6f9c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 20 deletions.
4 changes: 2 additions & 2 deletions apps/contracts/vault/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,5 +172,5 @@ mod deposit;
mod admin;
mod invest;
mod withdraw;
// mod emergency_withdraw;
// mod rebalance;
mod emergency_withdraw;
mod rebalance;
32 changes: 21 additions & 11 deletions apps/contracts/vault/src/test/emergency_withdraw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use soroban_sdk::{vec as sorobanvec, String, Vec};

use crate::test::{
create_strategy_params_token0,
defindex_vault::{AssetStrategySet, Investment},
defindex_vault::{AssetStrategySet,
AssetInvestmentAllocation,
StrategyInvestment
},
DeFindexVaultTest,
};

Expand Down Expand Up @@ -30,7 +33,7 @@ fn test_emergency_withdraw_success() {
&String::from_str(&test.env, "dfToken"),
&String::from_str(&test.env, "DFT"),
);
let amount = 1000i128;
let amount = 987654321i128;

let users = DeFindexVaultTest::generate_random_users(&test.env, 1);

Expand All @@ -49,27 +52,34 @@ fn test_emergency_withdraw_success() {
);

let df_balance = test.defindex_contract.balance(&users[0]);
assert_eq!(df_balance, amount);
assert_eq!(df_balance, amount - 1000);

// Balance of the token0 on the vault should be `amount` since it is deposited into the vault first
let vault_balance_of_token = test.token0.balance(&test.defindex_contract.address);
assert_eq!(vault_balance_of_token, amount);

// Should invest the funds

let investments = sorobanvec![
&test.env,
Investment {
amount: amount.clone(),
strategy: strategy_params_token0.first().unwrap().address.clone()
}
Some(AssetInvestmentAllocation {
asset: test.token0.address.clone(),
strategy_investments: sorobanvec![
&test.env,
Some(StrategyInvestment {
strategy: test.strategy_client_token0.address.clone(),
amount: amount,
}),
],
}),
];


test.defindex_contract.invest(&investments);

// Balance of the token0 on the vault should be 0
let vault_balance_of_token = test.token0.balance(&test.defindex_contract.address);
assert_eq!(vault_balance_of_token, 0);

// Balance of the strategy should be `amount`
// Balance of the vault on the strategy contract should be `amount`
let strategy_balance = test
.strategy_client_token0
.balance(&test.defindex_contract.address);
Expand All @@ -80,7 +90,7 @@ fn test_emergency_withdraw_success() {
&test.emergency_manager,
);

// Balance of the strategy should be 0
// Balance of the vault on the strategy should be 0
let strategy_balance = test
.strategy_client_token0
.balance(&test.defindex_contract.address);
Expand Down
25 changes: 18 additions & 7 deletions apps/contracts/vault/src/test/rebalance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ use soroban_sdk::{vec as sorobanvec, String, Vec};
use crate::test::{
create_strategy_params_token0,
defindex_vault::{
ActionType, AssetStrategySet, Instruction, Investment, OptionalSwapDetailsExactIn,
ActionType,
AssetStrategySet,
Instruction,
AssetInvestmentAllocation,
StrategyInvestment,
OptionalSwapDetailsExactIn,
OptionalSwapDetailsExactOut,
},
DeFindexVaultTest,
Expand Down Expand Up @@ -33,7 +38,7 @@ fn rebalance() {
&String::from_str(&test.env, "dfToken"),
&String::from_str(&test.env, "DFT"),
);
let amount = 1000i128;
let amount = 987654321i128;

let users = DeFindexVaultTest::generate_random_users(&test.env, 1);

Expand All @@ -51,14 +56,20 @@ fn rebalance() {
);

let df_balance = test.defindex_contract.balance(&users[0]);
assert_eq!(df_balance, amount);
assert_eq!(df_balance, amount - 1000);

let investments = sorobanvec![
&test.env,
Investment {
amount: amount,
strategy: test.strategy_client_token0.address.clone()
}
Some(AssetInvestmentAllocation {
asset: test.token0.address.clone(),
strategy_investments: sorobanvec![
&test.env,
Some(StrategyInvestment {
strategy: test.strategy_client_token0.address.clone(),
amount: amount,
}),
],
}),
];

test.defindex_contract.invest(&investments);
Expand Down

0 comments on commit 65b6f9c

Please sign in to comment.