Skip to content

Commit

Permalink
🩹Fix deposit function calls on tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MattPoblete committed Dec 2, 2024
1 parent a347942 commit 8073940
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fn test_fixed_apr_deposit_success() {
]
},
}])
.deposit(&svec![&setup.env, deposit_amount], &svec![&setup.env, deposit_amount], &user);
.deposit(&svec![&setup.env, deposit_amount], &svec![&setup.env, deposit_amount], &user, &false);

let vault_balance = enviroment.token.balance(&enviroment.vault_contract.address);
assert_eq!(vault_balance, deposit_amount);
Expand Down Expand Up @@ -113,7 +113,7 @@ fn test_fixed_apr_deposit_insufficient_balance() {
]
},
}])
.deposit(&svec![&setup.env, deposit_amount], &svec![&setup.env, deposit_amount], &user);
.deposit(&svec![&setup.env, deposit_amount], &svec![&setup.env, deposit_amount], &user, &false);
}

#[test]
Expand Down Expand Up @@ -177,7 +177,7 @@ fn test_fixed_apr_deposit_multiple_users() {
]
},
}])
.deposit(&svec![&setup.env, deposit_amount], &svec![&setup.env, deposit_amount], &user1);
.deposit(&svec![&setup.env, deposit_amount], &svec![&setup.env, deposit_amount], &user1, &false);

enviroment.vault_contract
.mock_auths(&[MockAuth {
Expand All @@ -204,7 +204,7 @@ fn test_fixed_apr_deposit_multiple_users() {
]
},
}])
.deposit(&svec![&setup.env, deposit_amount], &svec![&setup.env, deposit_amount], &user2);
.deposit(&svec![&setup.env, deposit_amount], &svec![&setup.env, deposit_amount], &user2, &false);

let vault_balance = enviroment.token.balance(&enviroment.vault_contract.address);
assert_eq!(vault_balance, deposit_amount * 2);
Expand Down Expand Up @@ -250,6 +250,7 @@ fn test_fixed_apr_deposit_zero_amount() {
&svec![&setup.env, deposit_amount],
&svec![&setup.env, deposit_amount],
&user,
&false
);

assert_eq!(result, Err(Ok(VaultContractError::InsufficientAmount)));
Expand Down Expand Up @@ -282,6 +283,7 @@ fn test_fixed_apr_deposit_negative_amount() {
&svec![&setup.env, deposit_amount],
&svec![&setup.env, deposit_amount],
&user,
&false
);

assert_eq!(result, Err(Ok(VaultContractError::NegativeNotAllowed)));
Expand Down Expand Up @@ -314,6 +316,7 @@ fn test_fixed_apr_deposit_insufficient_minimum_liquidity() {
&svec![&setup.env, deposit_amount],
&svec![&setup.env, deposit_amount],
&user,
&false
);

assert_eq!(result, Err(Ok(VaultContractError::InsufficientAmount)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fn test_fixed_apr_no_invest_withdraw_success() {
]
},
}])
.deposit(&svec![&setup.env, deposit_amount], &svec![&setup.env, deposit_amount], &user);
.deposit(&svec![&setup.env, deposit_amount], &svec![&setup.env, deposit_amount], &user, &false);

setup.env.ledger().set_timestamp(setup.env.ledger().timestamp() + ONE_YEAR_IN_SECONDS);

Expand Down Expand Up @@ -128,7 +128,7 @@ fn test_fixed_apr_invest_withdraw_success() {
]
},
}])
.deposit(&svec![&setup.env, deposit_amount], &svec![&setup.env, deposit_amount], &user);
.deposit(&svec![&setup.env, deposit_amount], &svec![&setup.env, deposit_amount], &user, &false);

let investments = svec![
&setup.env,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fn test_deposit_success() {
]
},
}])
.deposit(&svec![&setup.env, deposit_amount], &svec![&setup.env, deposit_amount], &user);
.deposit(&svec![&setup.env, deposit_amount], &svec![&setup.env, deposit_amount], &user, &false);

let vault_balance = enviroment.token.balance(&enviroment.vault_contract.address);
assert_eq!(vault_balance, deposit_amount);
Expand Down Expand Up @@ -113,7 +113,7 @@ fn test_deposit_insufficient_balance() {
]
},
}])
.deposit(&svec![&setup.env, deposit_amount], &svec![&setup.env, deposit_amount], &user);
.deposit(&svec![&setup.env, deposit_amount], &svec![&setup.env, deposit_amount], &user, &false);
}

#[test]
Expand Down Expand Up @@ -177,7 +177,7 @@ fn test_deposit_multiple_users() {
]
},
}])
.deposit(&svec![&setup.env, deposit_amount], &svec![&setup.env, deposit_amount], &user1);
.deposit(&svec![&setup.env, deposit_amount], &svec![&setup.env, deposit_amount], &user1, &false);

enviroment.vault_contract
.mock_auths(&[MockAuth {
Expand All @@ -204,7 +204,7 @@ fn test_deposit_multiple_users() {
]
},
}])
.deposit(&svec![&setup.env, deposit_amount], &svec![&setup.env, deposit_amount], &user2);
.deposit(&svec![&setup.env, deposit_amount], &svec![&setup.env, deposit_amount], &user2, &false);

let vault_balance = enviroment.token.balance(&enviroment.vault_contract.address);
assert_eq!(vault_balance, deposit_amount * 2);
Expand Down Expand Up @@ -250,6 +250,7 @@ fn test_deposit_zero_amount() {
&svec![&setup.env, deposit_amount],
&svec![&setup.env, deposit_amount],
&user,
&false
);

assert_eq!(result, Err(Ok(VaultContractError::InsufficientAmount)));
Expand Down Expand Up @@ -282,6 +283,7 @@ fn test_deposit_negative_amount() {
&svec![&setup.env, deposit_amount],
&svec![&setup.env, deposit_amount],
&user,
&false
);

assert_eq!(result, Err(Ok(VaultContractError::NegativeNotAllowed)));
Expand Down Expand Up @@ -314,6 +316,7 @@ fn test_deposit_insufficient_minimum_liquidity() {
&svec![&setup.env, deposit_amount],
&svec![&setup.env, deposit_amount],
&user,
&false
);

assert_eq!(result, Err(Ok(VaultContractError::InsufficientAmount)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fn test_invest_success() {
]
},
}])
.deposit(&svec![&setup.env, deposit_amount], &svec![&setup.env, deposit_amount], &user);
.deposit(&svec![&setup.env, deposit_amount], &svec![&setup.env, deposit_amount], &user, &false);

let df_balance = enviroment.vault_contract.balance(&user);
assert_eq!(df_balance, deposit_amount - MINIMUM_LIQUIDITY);
Expand Down Expand Up @@ -153,7 +153,7 @@ fn test_invest_exceeding_investing_lenght() {
]
},
}])
.deposit(&svec![&setup.env, deposit_amount], &svec![&setup.env, deposit_amount], &user);
.deposit(&svec![&setup.env, deposit_amount], &svec![&setup.env, deposit_amount], &user, &false);

let df_balance = enviroment.vault_contract.balance(&user);
assert_eq!(df_balance, deposit_amount - MINIMUM_LIQUIDITY);
Expand Down Expand Up @@ -276,7 +276,7 @@ fn test_invest_insufficient_balance() {
]
},
}])
.deposit(&svec![&setup.env, deposit_amount], &svec![&setup.env, deposit_amount], &user);
.deposit(&svec![&setup.env, deposit_amount], &svec![&setup.env, deposit_amount], &user, &false);
}

#[test]
Expand Down Expand Up @@ -340,7 +340,7 @@ fn test_invest_multiple_users() {
]
},
}])
.deposit(&svec![&setup.env, deposit_amount], &svec![&setup.env, deposit_amount], &user1);
.deposit(&svec![&setup.env, deposit_amount], &svec![&setup.env, deposit_amount], &user1, &false);

enviroment.vault_contract
.mock_auths(&[MockAuth {
Expand All @@ -367,7 +367,7 @@ fn test_invest_multiple_users() {
]
},
}])
.deposit(&svec![&setup.env, deposit_amount], &svec![&setup.env, deposit_amount], &user2);
.deposit(&svec![&setup.env, deposit_amount], &svec![&setup.env, deposit_amount], &user2, &false);

let df_balance_user1 = enviroment.vault_contract.balance(&user1);
let df_balance_user2 = enviroment.vault_contract.balance(&user2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fn test_withdraw_no_invest_success() {
]
},
}])
.deposit(&svec![&setup.env, deposit_amount], &svec![&setup.env, deposit_amount], &user);
.deposit(&svec![&setup.env, deposit_amount], &svec![&setup.env, deposit_amount], &user, &false);

let df_balance = enviroment.vault_contract.balance(&user);
assert_eq!(df_balance, deposit_amount - MINIMUM_LIQUIDITY);
Expand Down Expand Up @@ -133,7 +133,7 @@ fn test_withdraw_partial_success() {
]
},
}])
.deposit(&svec![&setup.env, deposit_amount], &svec![&setup.env, deposit_amount], &user);
.deposit(&svec![&setup.env, deposit_amount], &svec![&setup.env, deposit_amount], &user, &false);

let df_balance = enviroment.vault_contract.balance(&user);
assert_eq!(df_balance, deposit_amount - MINIMUM_LIQUIDITY);
Expand Down Expand Up @@ -212,7 +212,7 @@ fn test_withdraw_insufficient_balance() {
]
},
}])
.deposit(&svec![&setup.env, deposit_amount], &svec![&setup.env, deposit_amount], &user);
.deposit(&svec![&setup.env, deposit_amount], &svec![&setup.env, deposit_amount], &user, &false);

let df_balance = enviroment.vault_contract.balance(&user);
assert_eq!(df_balance, deposit_amount - MINIMUM_LIQUIDITY);
Expand Down Expand Up @@ -292,7 +292,7 @@ fn test_withdraw_after_invest() {
]
},
}])
.deposit(&svec![&setup.env, deposit_amount], &svec![&setup.env, deposit_amount], &user);
.deposit(&svec![&setup.env, deposit_amount], &svec![&setup.env, deposit_amount], &user, &false);

let user_balance_after_deposit = enviroment.token.balance(user);
assert_eq!(user_balance_after_deposit, 0);
Expand Down Expand Up @@ -445,7 +445,7 @@ fn test_withdraw_multiple_users() {
]
},
}])
.deposit(&svec![&setup.env, deposit_amount], &svec![&setup.env, deposit_amount], &user1);
.deposit(&svec![&setup.env, deposit_amount], &svec![&setup.env, deposit_amount], &user1, &false);

enviroment.vault_contract
.mock_auths(&[MockAuth {
Expand All @@ -472,7 +472,7 @@ fn test_withdraw_multiple_users() {
]
},
}])
.deposit(&svec![&setup.env, deposit_amount], &svec![&setup.env, deposit_amount], &user2);
.deposit(&svec![&setup.env, deposit_amount], &svec![&setup.env, deposit_amount], &user2, &false);

let df_balance_user1 = enviroment.vault_contract.balance(&user1);
let df_balance_user2 = enviroment.vault_contract.balance(&user2);
Expand Down Expand Up @@ -587,7 +587,7 @@ fn test_withdraw_after_invest_multiple_users() {
]
},
}])
.deposit(&svec![&setup.env, deposit_amount], &svec![&setup.env, deposit_amount], &user1);
.deposit(&svec![&setup.env, deposit_amount], &svec![&setup.env, deposit_amount], &user1, &false);

enviroment.vault_contract
.mock_auths(&[MockAuth {
Expand All @@ -614,7 +614,7 @@ fn test_withdraw_after_invest_multiple_users() {
]
},
}])
.deposit(&svec![&setup.env, deposit_amount], &svec![&setup.env, deposit_amount], &user2);
.deposit(&svec![&setup.env, deposit_amount], &svec![&setup.env, deposit_amount], &user2, &false);

let df_balance_user1 = enviroment.vault_contract.balance(&user1);
let df_balance_user2 = enviroment.vault_contract.balance(&user2);
Expand Down
6 changes: 6 additions & 0 deletions apps/contracts/vault/src/test/deposit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,7 @@ fn deposit_amounts_min_greater_than_amounts_desired(){
&sorobanvec![&test.env, amount0, amount1],
&sorobanvec![&test.env, amount0 + 1, amount1 + 1],
&users[0],
&false
);

// this should fail
Expand Down Expand Up @@ -832,6 +833,7 @@ fn deposit_transfers_tokens_from_user_to_vault(){
&sorobanvec![&test.env, amount0, amount1],
&sorobanvec![&test.env, amount0, amount1],
&users[0],
&false
);

// check balances after deposit
Expand Down Expand Up @@ -888,13 +890,15 @@ fn test_deposit_arithmetic_error() {
&sorobanvec![&test.env, large_amount],
&sorobanvec![&test.env, large_amount],
&users[0],
&false
);

// Try to deposit a large amount
let result = test.defindex_contract.try_deposit(
&sorobanvec![&test.env, large_amount],
&sorobanvec![&test.env, large_amount],
&users[0],
&false
);

// Verify that the returned error is ContractError::ArithmeticError
Expand Down Expand Up @@ -951,6 +955,7 @@ fn deposit_amounts_desired_zero() {
&sorobanvec![&test.env, 0i128],
&sorobanvec![&test.env, 0i128],
&users[0],
&false
);

// Verify that the returned error is ContractError::InsufficientAmount
Expand Down Expand Up @@ -1014,6 +1019,7 @@ fn deposit_insufficient_funds_with_error_message() {
&sorobanvec![&test.env, amount0 + 1, amount1 + 1],
&sorobanvec![&test.env, amount0 + 1, amount1 + 1],
&users[0],
&false
);

if deposit_result == Err(Err(InvokeError::Contract(10))) {
Expand Down
6 changes: 5 additions & 1 deletion apps/contracts/vault/src/test/rebalance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ fn rebalance_one_instruction() {
&sorobanvec![&test.env, amount],
&sorobanvec![&test.env, amount],
&users[0],
&false
);

let df_balance = test.defindex_contract.balance(&users[0]);
Expand Down Expand Up @@ -226,6 +227,7 @@ fn rebalance_empty_instructions(){
&sorobanvec![&test.env, amount],
&sorobanvec![&test.env, amount],
&users[0],
&false
);
let df_balance = test.defindex_contract.balance(&users[0]);
assert_eq!(df_balance, amount - 1000);
Expand Down Expand Up @@ -304,6 +306,7 @@ fn rebalance_no_instructions(){
&sorobanvec![&test.env, amount],
&sorobanvec![&test.env, amount],
&users[0],
&false
);
let df_balance = test.defindex_contract.balance(&users[0]);
assert_eq!(df_balance, amount - 1000);
Expand Down Expand Up @@ -346,8 +349,9 @@ fn rebalance_insufficient_balance(){
&sorobanvec![&test.env, amount],
&sorobanvec![&test.env, amount],
&users[0],
&false
);
let df_balance = test.defindex_contract.balance(&users[0]);
let df_balance: i128 = test.defindex_contract.balance(&users[0]);
assert_eq!(df_balance, amount - 1000);

let withdraw_instructions = sorobanvec![
Expand Down

0 comments on commit 8073940

Please sign in to comment.