Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Factory, Multihop, Pool, Stake: test to migrate from 21.7.7 to 22.04 #417

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .artifacts/old_phoenix_factory.optimized.wasm
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of those artifacts what we could really use is mostly factory, multihop, pool and staking.
The others plus the optimized variants are redundant.

Binary file not shown.
Binary file added .artifacts/old_phoenix_factory.wasm
Binary file not shown.
Binary file added .artifacts/old_phoenix_multihop.optimized.wasm
Binary file not shown.
Binary file added .artifacts/old_phoenix_multihop.wasm
Binary file not shown.
Binary file added .artifacts/old_phoenix_pool.optimized.wasm
Binary file not shown.
Binary file added .artifacts/old_phoenix_pool.wasm
Binary file not shown.
Binary file added .artifacts/old_phoenix_pool_stable.optimized.wasm
Binary file not shown.
Binary file added .artifacts/old_phoenix_pool_stable.wasm
Binary file not shown.
Binary file added .artifacts/old_phoenix_stake.optimized.wasm
Binary file not shown.
Binary file added .artifacts/old_phoenix_stake.wasm
Binary file not shown.
Binary file not shown.
Binary file added .artifacts/old_phoenix_stake_rewards.wasm
Binary file not shown.
Binary file added .artifacts/old_phoenix_vesting.wasm
Binary file not shown.
Binary file not shown.
Binary file added .artifacts/old_soroban_token_contract.wasm
Binary file not shown.
1 change: 1 addition & 0 deletions contracts/factory/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ crate-type = ["cdylib"]

[features]
testutils = ["soroban-sdk/testutils"]
upgrade = []

[dependencies]
soroban-sdk = { workspace = true }
Expand Down
79 changes: 78 additions & 1 deletion contracts/factory/src/tests/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,42 @@ use crate::{
token_contract,
};
use phoenix::utils::{LiquidityPoolInitInfo, StakeInitInfo, TokenInitInfo};
use soroban_sdk::{testutils::Address as _, vec, Address, BytesN, Env, String};
use soroban_sdk::{
testutils::{arbitrary::std, Address as _},
vec, Address, BytesN, Env, String,
};
pub const ONE_DAY: u64 = 86400;
const TOKEN_WASM: &[u8] =
include_bytes!("../../../../target/wasm32-unknown-unknown/release/soroban_token_contract.wasm");

#[allow(clippy::too_many_arguments)]
pub mod old_factory {
soroban_sdk::contractimport!(file = "../../.artifacts/old_phoenix_factory.wasm");
}

#[allow(clippy::too_many_arguments)]
#[cfg(feature = "upgrade")]
pub fn old_lp_wasm(env: &Env) -> BytesN<32> {
soroban_sdk::contractimport!(file = "../../.artifacts/old_phoenix_pool.wasm");
env.deployer().upload_contract_wasm(WASM)
}

#[allow(clippy::too_many_arguments)]
#[cfg(feature = "upgrade")]
pub fn old_stake_wasm(env: &Env) -> BytesN<32> {
soroban_sdk::contractimport!(file = "../../.artifacts/old_phoenix_stake.wasm");
env.deployer().upload_contract_wasm(WASM)
}

#[allow(clippy::too_many_arguments)]
#[cfg(feature = "upgrade")]
pub fn install_latest_factory(env: &Env) -> BytesN<32> {
soroban_sdk::contractimport!(
file = "../../target/wasm32-unknown-unknown/release/phoenix_factory.wasm"
);
env.deployer().upload_contract_wasm(WASM)
}

#[allow(clippy::too_many_arguments)]
pub mod lp_contract {
soroban_sdk::contractimport!(
Expand Down Expand Up @@ -126,3 +157,49 @@ pub fn install_and_deploy_token_contract<'a>(

token_client
}

#[test]
#[allow(deprecated)]
#[cfg(feature = "upgrade")]
fn update_factory() {
let env = Env::default();
env.mock_all_auths();
env.cost_estimate().budget().reset_unlimited();
let admin = Address::generate(&env);

let factory_addr = env.register_contract_wasm(None, old_factory::WASM);
let old_factory_client = old_factory::Client::new(&env, &factory_addr);

old_factory_client.initialize(
&admin.clone(),
&install_multihop_wasm(&env),
&old_lp_wasm(&env),
&install_stable_lp(&env),
&old_stake_wasm(&env),
&install_token_wasm(&env),
&vec![
&env,
admin.clone(),
Address::generate(&env),
Address::generate(&env),
],
&7u32,
);

assert_eq!(old_factory_client.get_admin(), admin.clone());

let latest_factory_wasm = install_latest_factory(&env);
let stable_wasm = install_stable_lp(&env);

old_factory_client.update(&latest_factory_wasm, &stable_wasm);

let latest_factory_client = FactoryClient::new(&env, &factory_addr);

assert_eq!(latest_factory_client.get_admin(), admin.clone());

latest_factory_client.update_wasm_hashes(
&Some(install_lp_contract(&env)),
&Some(install_stake_wasm(&env)),
&Some(install_token_wasm(&env)),
);
}
1 change: 1 addition & 0 deletions contracts/multihop/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ crate-type = ["cdylib"]

[features]
testutils = ["soroban-sdk/testutils"]
upgrade = []

[dependencies]
soroban-sdk = { workspace = true }
Expand Down
32 changes: 32 additions & 0 deletions contracts/multihop/src/tests/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ use soroban_sdk::{
Address, Bytes, BytesN, Env,
};
use soroban_sdk::{vec, String};

#[allow(clippy::too_many_arguments)]
pub mod old_multihop {
soroban_sdk::contractimport!(file = "../../.artifacts/old_phoenix_multihop.wasm");
}

#[allow(clippy::too_many_arguments)]
pub mod latest_multihop {
soroban_sdk::contractimport!(
file = "../../target/wasm32-unknown-unknown/release/phoenix_multihop.wasm"
);
}

pub fn create_token_contract_with_metadata<'a>(
env: &Env,
admin: &Address,
Expand Down Expand Up @@ -198,3 +211,22 @@ pub fn deploy_and_initialize_pool(
}
}
}

#[test]
#[allow(deprecated)]
#[cfg(feature = "upgrade")]
fn updapte_multihop() {
let env = Env::default();
env.mock_all_auths();
env.cost_estimate().budget().reset_unlimited();

let admin = Address::generate(&env);
let factory = Address::generate(&env);

let old_multhop_addr = env.register_contract_wasm(None, old_multihop::WASM);
let old_multihop_client = old_multihop::Client::new(&env, &old_multhop_addr);

old_multihop_client.initialize(&admin, &factory);
let latest_multihop_wasm = install_multihop_wasm(&env);
old_multihop_client.update(&latest_multihop_wasm);
}
1 change: 1 addition & 0 deletions contracts/pool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ crate-type = ["cdylib"]

[features]
testutils = ["soroban-sdk/testutils"]
upgrade = []

[dependencies]
soroban-decimal = { workspace = true }
Expand Down
70 changes: 6 additions & 64 deletions contracts/pool/src/tests/config.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
extern crate std;
use phoenix::utils::{LiquidityPoolInitInfo, StakeInitInfo, TokenInitInfo};
use soroban_sdk::{testutils::Address as _, Address, Env, String};
use soroban_sdk::{
testutils::{arbitrary::std, Address as _},
Address, Env, String,
};

use super::setup::{
deploy_liquidity_pool_contract, deploy_token_contract, install_new_lp_wasm, install_stake_wasm,
install_token_wasm,
deploy_liquidity_pool_contract, deploy_token_contract, install_stake_wasm, install_token_wasm,
};
use crate::{
contract::{LiquidityPool, LiquidityPoolClient},
storage::{Asset, Config, PairType, PoolResponse},
storage::{Config, PairType},
};

#[should_panic(
Expand Down Expand Up @@ -302,65 +303,6 @@ fn update_config_too_high_fees() {
);
}

#[test]
fn update_liquidity_pool_works() {
let env = Env::default();
env.mock_all_auths();
env.cost_estimate().budget().reset_unlimited();

let mut admin1 = Address::generate(&env);
let mut admin2 = Address::generate(&env);

let mut token1 = deploy_token_contract(&env, &admin1);
let mut token2 = deploy_token_contract(&env, &admin2);
if token2.address < token1.address {
std::mem::swap(&mut token1, &mut token2);
std::mem::swap(&mut admin1, &mut admin2);
}
let user1 = Address::generate(&env);
let stake_manager = Address::generate(&env);
let stake_owner = Address::generate(&env);
let swap_fees = 0i64;
let pool = deploy_liquidity_pool_contract(
&env,
Some(admin1.clone()),
(&token1.address, &token2.address),
swap_fees,
user1.clone(),
500,
200,
stake_manager,
stake_owner,
);

let new_wasm_hash = install_new_lp_wasm(&env);

// no assertions, just check if it goes smooth
pool.upgrade(&new_wasm_hash, &5_000i64);

let result = pool.query_pool_info_for_factory();
// not using result only because we have to take the current contract address, which is not known during the test
assert_eq!(
result.pool_response,
PoolResponse {
asset_a: Asset {
address: token1.address,
amount: 0
},
asset_b: Asset {
address: token2.address,
amount: 0
},
asset_lp_share: Asset {
address: pool.query_share_token_address(),
amount: 0
},
stake_address: pool.query_stake_contract_address(),
}
);
assert_eq!(result.total_fee_bps, 0);
}

#[test]
fn update_configs_all_bps_values_should_work() {
let env = Env::default();
Expand Down
Loading
Loading