-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
237 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use crate::math::percentage::Percentage; | ||
use crate::InvariantDeployer; | ||
use crate::InvariantError; | ||
use crate::{FeeTier, PoolKey}; | ||
use decimal::*; | ||
use odra::test_env; | ||
use odra::types::casper_types::ContractPackageHash; | ||
use odra::types::Address; | ||
use odra::types::U128; | ||
|
||
#[test] | ||
fn test_change_fee_reciever() { | ||
let token_0 = Address::Contract(ContractPackageHash::from([0x01; 32])); | ||
let token_1 = Address::Contract(ContractPackageHash::from([0x02; 32])); | ||
|
||
let deployer = test_env::get_account(0); | ||
test_env::set_caller(deployer); | ||
let mut invariant = InvariantDeployer::init(Percentage::new(U128::from(0))); | ||
|
||
let fee_tier = FeeTier::new(Percentage::from_scale(5, 1), 1).unwrap(); | ||
invariant.add_fee_tier(fee_tier).unwrap(); | ||
|
||
let exist = invariant.fee_tier_exist(fee_tier); | ||
assert!(exist); | ||
|
||
let init_tick = 0; | ||
invariant | ||
.create_pool(token_0, token_1, fee_tier, init_tick) | ||
.unwrap(); | ||
|
||
let new_receiver = test_env::get_account(1); | ||
let pool_key = PoolKey::new(token_0, token_1, fee_tier).unwrap(); | ||
|
||
invariant | ||
.change_fee_receiver(pool_key, new_receiver) | ||
.unwrap(); | ||
|
||
let pool = invariant.get_pool(token_0, token_1, fee_tier).unwrap(); | ||
assert_eq!(pool.fee_receiver, new_receiver); | ||
} | ||
|
||
#[test] | ||
fn test_not_admin_change_fee_reciever() { | ||
let token_0 = Address::Contract(ContractPackageHash::from([0x01; 32])); | ||
let token_1 = Address::Contract(ContractPackageHash::from([0x02; 32])); | ||
|
||
let deployer = test_env::get_account(0); | ||
test_env::set_caller(deployer); | ||
let mut invariant = InvariantDeployer::init(Percentage::new(U128::from(0))); | ||
|
||
let fee_tier = FeeTier::new(Percentage::from_scale(5, 1), 1).unwrap(); | ||
invariant.add_fee_tier(fee_tier).unwrap(); | ||
|
||
let exist = invariant.fee_tier_exist(fee_tier); | ||
assert!(exist); | ||
|
||
let init_tick = 0; | ||
invariant | ||
.create_pool(token_0, token_1, fee_tier, init_tick) | ||
.unwrap(); | ||
|
||
let new_receiver = test_env::get_account(1); | ||
let pool_key = PoolKey::new(token_0, token_1, fee_tier).unwrap(); | ||
test_env::set_caller(new_receiver); | ||
let result = invariant.change_fee_receiver(pool_key, new_receiver); | ||
assert_eq!(result, Err(InvariantError::NotAdmin)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use crate::math::percentage::Percentage; | ||
use crate::InvariantDeployer; | ||
use crate::InvariantError; | ||
use decimal::*; | ||
use odra::test_env; | ||
use odra::types::U128; | ||
|
||
#[test] | ||
fn test_change_protocol_fee() { | ||
let deployer = test_env::get_account(0); | ||
test_env::set_caller(deployer); | ||
let mut invariant = InvariantDeployer::init(Percentage::new(U128::from(0))); | ||
|
||
let protocol_fee = invariant.get_protocol_fee(); | ||
assert_eq!(protocol_fee, Percentage::new(U128::from(0))); | ||
|
||
let new_fee = Percentage::new(U128::from(1)); | ||
invariant.change_protocol_fee(new_fee).unwrap(); | ||
|
||
let protocol_fee = invariant.get_protocol_fee(); | ||
assert_eq!(protocol_fee, new_fee); | ||
} | ||
|
||
#[test] | ||
fn test_change_protocol_fee_not_admin() { | ||
let deployer = test_env::get_account(0); | ||
test_env::set_caller(deployer); | ||
let mut invariant = InvariantDeployer::init(Percentage::new(U128::from(0))); | ||
|
||
let protocol_fee = invariant.get_protocol_fee(); | ||
assert_eq!(protocol_fee, Percentage::new(U128::from(0))); | ||
|
||
let new_fee = Percentage::new(U128::from(1)); | ||
test_env::set_caller(test_env::get_account(1)); | ||
let result = invariant.change_protocol_fee(new_fee); | ||
|
||
assert_eq!(result, Err(InvariantError::NotAdmin)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
pub mod add_fee_tier; | ||
pub mod change_fee_receiver; | ||
pub mod change_protocol_fee; | ||
pub mod constructor; | ||
pub mod create_pool; | ||
pub mod remove_fee_tier; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters