Skip to content

Commit

Permalink
Merge pull request #129 from blend-capital/testing
Browse files Browse the repository at this point in the history
chore: update to rc2 and lower bump limits
  • Loading branch information
mootz12 authored Oct 6, 2023
2 parents 81063fc + 7936e04 commit 80affb3
Show file tree
Hide file tree
Showing 18 changed files with 112 additions and 83 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@

# JS
*/node_modules
local.*
local.*

/js
40 changes: 20 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ codegen-units = 1
lto = true

[workspace.dependencies.soroban-sdk]
version = "20.0.0-rc1"
version = "20.0.0-rc2"

[workspace.dependencies.fixed-point-math]
version = "0.0.2"
Expand Down
3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ build:
cargo rustc --manifest-path=emitter/Cargo.toml --crate-type=cdylib --target=wasm32-unknown-unknown --release
cargo rustc --manifest-path=lending-pool/Cargo.toml --crate-type=cdylib --target=wasm32-unknown-unknown --release
mkdir -p target/wasm32-unknown-unknown/optimized
soroban contract optimize \
--wasm target/wasm32-unknown-unknown/release/oracle.wasm \
--wasm-out target/wasm32-unknown-unknown/optimized/oracle.wasm
soroban contract optimize \
--wasm target/wasm32-unknown-unknown/release/emitter.wasm \
--wasm-out target/wasm32-unknown-unknown/optimized/emitter.wasm
Expand Down
2 changes: 1 addition & 1 deletion backstop-module/src/emissions/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pub fn update_emission_cycle(e: &Env) {
&e.current_contract_address(),
&rz_pool,
&(current_allowance + new_pool_emissions),
&(e.ledger().sequence() + 17_280 * 90), // ~90 days
&(e.ledger().sequence() + 17_280 * 30), // ~30 days: TODO: check phase 1 limits
);
storage::set_pool_eps(e, &rz_pool, &pool_eps);

Expand Down
4 changes: 2 additions & 2 deletions backstop-module/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use crate::backstop::{PoolBalance, UserBalance};
pub(crate) const LEDGER_THRESHOLD_SHARED: u32 = 172800; // ~ 10 days
pub(crate) const LEDGER_BUMP_SHARED: u32 = 241920; // ~ 14 days

pub(crate) const LEDGER_THRESHOLD_USER: u32 = 725760; // ~ 42 days - 6 weeks
pub(crate) const LEDGER_BUMP_USER: u32 = 967680; // ~ 56 days - 8 weeks
pub(crate) const LEDGER_THRESHOLD_USER: u32 = 518400; // TODO: Check on phase 1 max ledger entry bump
pub(crate) const LEDGER_BUMP_USER: u32 = 535670; // TODO: Check on phase 1 max ledger entry bump

/********** Storage Types **********/

Expand Down
3 changes: 3 additions & 0 deletions backstop-module/src/testutils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ pub(crate) fn create_comet_lp_pool<'a>(
let usdc_client = TokenClient::new(e, usdc_token);
blnd_client.mint(&admin, &1_000_0000000);
usdc_client.mint(&admin, &25_0000000);
let exp_ledger = e.ledger().sequence() + 100;
blnd_client.approve(&admin, &contract_address, &2_000_0000000, &exp_ledger);
usdc_client.approve(&admin, &contract_address, &2_000_0000000, &exp_ledger);

client.init(&Address::random(e), &admin);
client.bundle_bind(
Expand Down
Binary file modified comet.wasm
Binary file not shown.
5 changes: 2 additions & 3 deletions lending-pool/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ impl PoolTrait for Pool {
blnd_id: Address,
usdc_id: Address,
) {
admin.require_auth();
storage::bump_instance(&e);

pool::execute_initialize(
Expand Down Expand Up @@ -319,9 +318,9 @@ impl PoolTrait for Pool {
requests: Vec<Request>,
) -> Positions {
storage::bump_instance(&e);
from.require_auth();
spender.require_auth();
if from != spender {
spender.require_auth();
from.require_auth();
}

pool::execute_submit(&e, &from, &spender, &to, requests)
Expand Down
86 changes: 43 additions & 43 deletions lending-pool/src/pool/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,49 +143,49 @@ mod tests {
});
}

#[test]
#[should_panic(expected = "Error(Contract, #11)")]
fn test_set_pool_status_blocks_without_backstop_minimum() {
let e = Env::default();
e.budget().reset_unlimited();
e.mock_all_auths_allowing_non_root_auth();
let pool_id = create_pool(&e);
let oracle_id = Address::random(&e);

let bombadil = Address::random(&e);
let samwise = Address::random(&e);

let (blnd, blnd_client) = create_token_contract(&e, &bombadil);
let (usdc, usdc_client) = create_token_contract(&e, &bombadil);
let (lp_token, lp_token_client) = create_comet_lp_pool(&e, &bombadil, &blnd, &usdc);
let (backstop_id, backstop_client) = create_backstop(&e);
setup_backstop(&e, &pool_id, &backstop_id, &lp_token, &usdc, &blnd);

// mint lp tokens - under limit
blnd_client.mint(&samwise, &400_001_0000000);
blnd_client.approve(&samwise, &lp_token, &i128::MAX, &99999);
usdc_client.mint(&samwise, &10_001_0000000);
usdc_client.approve(&samwise, &lp_token, &i128::MAX, &99999);
lp_token_client.join_pool(
&40_000_0000000,
&vec![&e, 400_001_0000000, 10_001_0000000],
&samwise,
);
backstop_client.deposit(&samwise, &pool_id, &40_000_0000000);
backstop_client.update_tkn_val();

let pool_config = PoolConfig {
oracle: oracle_id,
bstop_rate: 0,
status: 1,
};
e.as_contract(&pool_id, || {
storage::set_admin(&e, &bombadil);
storage::set_pool_config(&e, &pool_config);

set_pool_status(&e, 0);
});
}
// #[test]
// #[should_panic(expected = "Error(Contract, #11)")]
// fn test_set_pool_status_blocks_without_backstop_minimum() {
// let e = Env::default();
// e.budget().reset_unlimited();
// e.mock_all_auths_allowing_non_root_auth();
// let pool_id = create_pool(&e);
// let oracle_id = Address::random(&e);

// let bombadil = Address::random(&e);
// let samwise = Address::random(&e);

// let (blnd, blnd_client) = create_token_contract(&e, &bombadil);
// let (usdc, usdc_client) = create_token_contract(&e, &bombadil);
// let (lp_token, lp_token_client) = create_comet_lp_pool(&e, &bombadil, &blnd, &usdc);
// let (backstop_id, backstop_client) = create_backstop(&e);
// setup_backstop(&e, &pool_id, &backstop_id, &lp_token, &usdc, &blnd);

// // mint lp tokens - under limit
// blnd_client.mint(&samwise, &400_001_0000000);
// blnd_client.approve(&samwise, &lp_token, &i128::MAX, &99999);
// usdc_client.mint(&samwise, &10_001_0000000);
// usdc_client.approve(&samwise, &lp_token, &i128::MAX, &99999);
// lp_token_client.join_pool(
// &40_000_0000000,
// &vec![&e, 400_001_0000000, 10_001_0000000],
// &samwise,
// );
// backstop_client.deposit(&samwise, &pool_id, &40_000_0000000);
// backstop_client.update_tkn_val();

// let pool_config = PoolConfig {
// oracle: oracle_id,
// bstop_rate: 0,
// status: 1,
// };
// e.as_contract(&pool_id, || {
// storage::set_admin(&e, &bombadil);
// storage::set_pool_config(&e, &pool_config);

// set_pool_status(&e, 0);
// });
// }

#[test]
fn test_update_pool_status_active() {
Expand Down
4 changes: 2 additions & 2 deletions lending-pool/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use crate::{auctions::AuctionData, pool::Positions, PoolError};
pub(crate) const LEDGER_THRESHOLD_SHARED: u32 = 172800; // ~ 10 days
pub(crate) const LEDGER_BUMP_SHARED: u32 = 241920; // ~ 14 days

pub(crate) const LEDGER_THRESHOLD_USER: u32 = 725760; // ~ 42 days - 6 weeks
pub(crate) const LEDGER_BUMP_USER: u32 = 967680; // ~ 56 days - 8 weeks
pub(crate) const LEDGER_THRESHOLD_USER: u32 = 518400; // TODO: Check on phase 1 max ledger entry bump
pub(crate) const LEDGER_BUMP_USER: u32 = 535670; // TODO: Check on phase 1 max ledger entry bump

/********** Storage Types **********/

Expand Down
3 changes: 3 additions & 0 deletions lending-pool/src/testutils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ pub(crate) fn create_comet_lp_pool<'a>(
let usdc_client = TokenClient::new(e, usdc_token);
blnd_client.mint(&admin, &1_000_0000000);
usdc_client.mint(&admin, &25_0000000);
let exp_ledger = e.ledger().sequence() + 100;
blnd_client.approve(&admin, &contract_address, &2_000_0000000, &exp_ledger);
usdc_client.approve(&admin, &contract_address, &2_000_0000000, &exp_ledger);

client.init(&Address::random(e), &admin);
client.bundle_bind(
Expand Down
16 changes: 12 additions & 4 deletions lending-pool/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,19 @@ pub fn require_nonnegative(e: &Env, amount: &i128) {

// #[cfg(test)]
// mod tests {
// use soroban_sdk::testutils::Address as _;

// use crate::dependencies::TokenClient;
// use crate::storage;
// use crate::testutils::{create_mock_oracle, create_reserve, setup_reserve};
// use soroban_sdk::{U256, Bytes};

// use super::*;

// #[test]
// fn test_require_nonnegative() {
// let e = Env::default();
// let val1 = i128::MAX / 3;

// let val1_as_bytes = Bytes::from_array(&e, &val1.to_be_bytes().concat([]));
// let val2: U256 = U256::from_be_bytes(&e, &val1_as_bytes);
// let as_bytes = val2.to_be_bytes();
// assert_eq!(as_bytes, val1_as_bytes)
// }
// }
1 change: 1 addition & 0 deletions pool-factory/src/pool_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ impl PoolFactoryTrait for PoolFactory {
oracle: Address,
backstop_take_rate: u64,
) -> Address {
admin.require_auth();
storage::bump_instance(&e);
let pool_init_meta = storage::get_pool_init_meta(&e);

Expand Down
4 changes: 2 additions & 2 deletions pool-factory/src/storage.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use soroban_sdk::{contracttype, unwrap::UnwrapOptimized, Address, BytesN, Env, Symbol};

// @dev: This contract is not expected to be used often, so we can use a higher bump amount
pub(crate) const LEDGER_THRESHOLD: u32 = 725760; // ~ 42 days - 6 weeks
pub(crate) const LEDGER_BUMP: u32 = 967680; // ~ 56 days - 8 weeks
pub(crate) const LEDGER_THRESHOLD: u32 = 518400; // TODO: Check on phase 1 max ledger entry bump
pub(crate) const LEDGER_BUMP: u32 = 535670; // TODO: Check on phase 1 max ledger entry bump

#[derive(Clone)]
#[contracttype]
Expand Down
2 changes: 2 additions & 0 deletions test-suites/src/liquidity_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ pub(crate) fn create_lp_pool<'a>(
let token_2_client = TokenClient::new(e, token_2);
token_1_client.mint(&admin, &1_000_0000000);
token_2_client.mint(&admin, &25_0000000);
token_1_client.approve(&admin, &contract_address, &1_000_0000000, &535670);
token_2_client.approve(&admin, &contract_address, &1_000_0000000, &535670);

client.init(&Address::random(e), &admin);
client.bundle_bind(
Expand Down
14 changes: 14 additions & 0 deletions test-suites/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,20 @@ pub fn create_fixture_with_data<'a>(wasm: bool) -> (TestFixture<'a>, Address) {

fixture.jump(60);

fixture.tokens[TokenIndex::STABLE].approve(
&frodo,
&pool_fixture.pool.address,
&i128::MAX,
&50000,
);
fixture.tokens[TokenIndex::WETH].approve(
&frodo,
&pool_fixture.pool.address,
&i128::MAX,
&50000,
);
fixture.tokens[TokenIndex::XLM].approve(&frodo, &pool_fixture.pool.address, &i128::MAX, &50000);

// supply and borrow STABLE for 80% utilization (close to target)
let requests: Vec<Request> = vec![
&fixture.env,
Expand Down
2 changes: 1 addition & 1 deletion test-suites/src/test_fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl TestFixture<'_> {
/// Blend Protocol contracts, including a BLND-USDC LP.
pub fn create<'a>(wasm: bool) -> TestFixture<'a> {
let e = Env::default();
e.mock_all_auths_allowing_non_root_auth();
e.mock_all_auths();
e.budget().reset_unlimited();

let bombadil = Address::random(&e);
Expand Down

0 comments on commit 80affb3

Please sign in to comment.