Skip to content

Commit

Permalink
Update testing environment
Browse files Browse the repository at this point in the history
  • Loading branch information
0xOmarA committed Jan 2, 2024
1 parent 40a66e7 commit 8f7b240
Show file tree
Hide file tree
Showing 5 changed files with 297 additions and 333 deletions.
31 changes: 15 additions & 16 deletions unit-tests/tests/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,25 @@ macro_rules! test_access_rules {
paste::paste! {
#[test]
fn [< can_call_ $method_name _with_ $role _role >]()
-> ::std::result::Result<(), ::scrypto_test::prelude::RuntimeError>
-> ::std::result::Result<
(),
::scrypto_test::prelude::RuntimeError
>
{
// Arrange
let Environment {
environment: ref mut env,
components: Components { mut olympus, .. },
additional_data: OlympusBadges {
protocol_manager: protocol_manager_badge,
protocol_owner: protocol_owner_badge
},
mut protocol,
ociswap,
..
} = Environment::new_create_badges()?;
} = Environment::new()?;
env.enable_auth_module();

let proof = [< $role _badge >].create_proof_of_all(env)?;
let proof = protocol.[< $role _badge >].create_proof_of_all(env)?;
LocalAuthZone::push(proof, env)?;

// Act
let rtn = olympus.$method_name( $( $arg ),* , env);
let rtn = protocol.olympus.$method_name( $( $arg ),* , env);

// Assert
assert!(!matches!(
Expand All @@ -55,16 +56,14 @@ macro_rules! test_access_rules {
// Arrange
let Environment {
environment: ref mut env,
components: Components { mut olympus, .. },
additional_data: OlympusBadges {
protocol_manager: protocol_manager_badge,
protocol_owner: protocol_owner_badge
},
mut protocol,
ociswap,
..
} = Environment::new_create_badges()?;
} = Environment::new()?;
env.enable_auth_module();

// Act
let rtn = olympus.$method_name( $( $arg ),* , env);
let rtn = protocol.olympus.$method_name( $( $arg ),* , env);

// Assert
assert!(matches!(
Expand Down
70 changes: 14 additions & 56 deletions unit-tests/tests/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
mod utils;
use utils::*;

use ociswap_adapter::*;
use olympus::{LockupPeriod, Percent};
use olympus::LockupPeriod;
use radix_engine_interface::prelude::*;
use radix_engine_interface::*;
use scrypto_test::prelude::*;
Expand All @@ -14,15 +13,14 @@ fn cant_add_a_pool_with_no_corresponding_adapter() -> Result<(), RuntimeError> {
// Arrange
let Environment {
environment: ref mut env,
components: Components { mut olympus, .. },
protocol: ProtocolEntities { mut olympus, .. },
..
} = Environment::new()?;

// Act
let rtn = olympus.add_allowed_pool(FAUCET, env);

// Assert
dbg!(&rtn);
assert!(is_wasm_panic(&rtn));

Ok(())
Expand All @@ -33,53 +31,12 @@ fn can_open_position_on_an_ociswap_pool() -> Result<(), RuntimeError> {
// Arrange
let Environment {
environment: ref mut env,
packages,
mut resources,
components:
Components {
mut olympus,
test_oracle: mut oracle,
ociswap_adapter,
},
..
} = Environment::new_create_badges()?;
env.disable_auth_module();

let initial_xrd =
ResourceManager(XRD).mint_fungible(dec!(100_000_000_000), env)?;
olympus.deposit(FungibleBucket(initial_xrd), env)?;
olympus.update_oracle(oracle.0.try_into().unwrap(), env)?;

let bucket1 =
ResourceManager(XRD).mint_fungible(dec!(1_037_305.4202264115), env)?;
let bucket2 = resources.bitcoin.mint_fungible(dec!(1), env)?;

let (ociswap, _, _) =
OciswapPoolInterfaceScryptoTestStub::instantiate_with_liquidity(
bucket1,
bucket2,
dec!(0),
FAUCET,
packages.ociswap_package,
env,
)?;

olympus.add_pool_adapter(
OciswapPoolInterfaceScryptoTestStub::blueprint_id(
packages.ociswap_package,
),
ociswap_adapter.try_into().unwrap(),
env,
)?;
olympus.add_allowed_pool(ociswap.try_into().unwrap(), env)?;
olympus.config_open_liquidity_position(true, env)?;
olympus.add_rewards_rate(
LockupPeriod::from_seconds(10),
Percent::new(dec!(0.5)).unwrap(),
env,
)?;
mut protocol,
ociswap,
} = Environment::new()?;

oracle.set_price(
protocol.oracle.set_price(
resources.bitcoin.0,
XRD,
dec!(1_037_305.4202264115),
Expand All @@ -88,17 +45,18 @@ fn can_open_position_on_an_ociswap_pool() -> Result<(), RuntimeError> {

// Act
let bitcoin_bucket = resources.bitcoin.mint_fungible(dec!(0.1), env)?;
let (_, change, additional_resources) = olympus.open_liquidity_position(
ociswap.try_into().unwrap(),
FungibleBucket(bitcoin_bucket),
LockupPeriod::from_seconds(10),
env,
)?;
let (_, change, additional_resources) =
protocol.olympus.open_liquidity_position(
ociswap.bitcoin_pool.try_into().unwrap(),
FungibleBucket(bitcoin_bucket),
LockupPeriod::from_months(6),
env,
)?;

// Assert
assert_eq!(
change.0.amount(env),
Ok(dec!(0.1) * dec!(1_037_305.4202264115) / dec!(2))
Ok(dec!(0.1) * dec!(1_037_305.4202264115) * dec!(0.1))
);
assert!(additional_resources.is_empty());

Expand Down
Loading

0 comments on commit 8f7b240

Please sign in to comment.