Skip to content

Commit

Permalink
merge with main
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquinsoza committed Dec 3, 2024
2 parents 2d117b1 + 5f8c51f commit a56b6e4
Show file tree
Hide file tree
Showing 56 changed files with 2,983 additions and 304 deletions.
1 change: 1 addition & 0 deletions apps/contracts/factory/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ impl FactoryTrait for DeFindexFactory {
deposit_args.push_back(amounts.to_val());
deposit_args.push_back(amounts_min.to_val());
deposit_args.push_back(caller.to_val());
deposit_args.push_back(false.into_val(&e));

e.invoke_contract::<Val>(&defindex_address, &Symbol::new(&e, "deposit"), deposit_args);

Expand Down
4 changes: 1 addition & 3 deletions apps/contracts/factory/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,4 @@ impl<'a> DeFindexFactoryTest<'a> {
}
}

mod admin;
mod initialize;
mod create_defindex;
mod factory;
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use alloc::vec;
use crate::test::DeFindexFactoryTest;

#[test]
fn test_set_new_admin_by_admin() {
fn set_new_admin_by_admin() {

let test = DeFindexFactoryTest::setup();

Expand Down Expand Up @@ -46,7 +46,7 @@ fn test_set_new_admin_by_admin() {

#[test]
#[should_panic(expected = "HostError: Error(Auth, InvalidAction)")] // Unauthorized
fn test_set_new_admin_by_unauthorized() {
fn set_new_admin_by_unauthorized() {
let test = DeFindexFactoryTest::setup();

test.factory_contract.initialize(&test.admin, &test.defindex_receiver, &100u32, &test.defindex_wasm_hash);
Expand All @@ -69,7 +69,7 @@ fn test_set_new_admin_by_unauthorized() {
}

#[test]
fn test_set_defindex_receiver_by_admin() {
fn set_defindex_receiver_by_admin() {
let test = DeFindexFactoryTest::setup();

test.factory_contract.initialize(&test.admin, &test.defindex_receiver, &100u32, &test.defindex_wasm_hash);
Expand Down Expand Up @@ -109,7 +109,7 @@ fn test_set_defindex_receiver_by_admin() {

#[test]
#[should_panic(expected = "HostError: Error(Auth, InvalidAction)")] // Unauthorized
fn test_set_fee_receiver_by_unauthorized() {
fn set_fee_receiver_by_unauthorized() {
let test = DeFindexFactoryTest::setup();

test.factory_contract.initialize(&test.admin, &test.defindex_receiver, &100u32, &test.defindex_wasm_hash);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use soroban_sdk::{vec, BytesN, String, Vec};
use crate::test::{create_asset_params, DeFindexFactoryTest};

#[test]
fn test_create_defindex_success() {
fn create_success() {
let test = DeFindexFactoryTest::setup();

test.factory_contract.initialize(&test.admin, &test.defindex_receiver, &100u32, &test.defindex_wasm_hash);
Expand All @@ -28,7 +28,7 @@ fn test_create_defindex_success() {
}

#[test]
fn test_create_defindex_deposit_success() {
fn create_and_deposit_success() {
let test = DeFindexFactoryTest::setup();
test.env.mock_all_auths();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::error::FactoryError;
use crate::test::{create_asset_params, DeFindexFactoryTest};

#[test]
fn test_initialize_and_get_storage() {
fn initialize_and_get_storage() {
let test = DeFindexFactoryTest::setup();

test.factory_contract.initialize(&test.admin, &test.defindex_receiver, &100u32, &test.defindex_wasm_hash);
Expand All @@ -17,7 +17,7 @@ fn test_initialize_and_get_storage() {
}

#[test]
fn test_get_storage_not_yet_initialized() {
fn get_storage_not_yet_initialized() {
let test = DeFindexFactoryTest::setup();
let factory_admin = test.factory_contract.try_admin();
let factory_defindex_receiver = test.factory_contract.try_defindex_receiver();
Expand All @@ -27,7 +27,7 @@ fn test_get_storage_not_yet_initialized() {
}

#[test]
fn test_initialize_twice() {
fn initialize_twice() {
let test = DeFindexFactoryTest::setup();

test.factory_contract.initialize(&test.admin, &test.defindex_receiver, &100u32, &test.defindex_wasm_hash);
Expand All @@ -40,7 +40,7 @@ fn test_initialize_twice() {
}

#[test]
fn test_create_defindex_not_yet_initialized() {
fn create_defindex_not_yet_initialized() {
let test = DeFindexFactoryTest::setup();

let asset_params = create_asset_params(&test);
Expand Down
3 changes: 3 additions & 0 deletions apps/contracts/factory/src/test/factory/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod admin;
mod create_defindex;
mod initialize;
4 changes: 2 additions & 2 deletions apps/contracts/integration-test/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@ impl<'a> IntegrationTest<'a> {
}

#[cfg(test)]
mod test_vault_one_hodl_strategy;
mod test_vault_one_fixed_strategy;
mod vault_one_hodl_strategy;
mod vault_one_fixed_strategy;
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

This file was deleted.

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
Loading

0 comments on commit a56b6e4

Please sign in to comment.