Skip to content

Commit

Permalink
Merge branch 'pool-9' into test/swap
Browse files Browse the repository at this point in the history
  • Loading branch information
Uriel Mihura committed Dec 1, 2023
2 parents a2d00a1 + 18ed3dd commit 70ec219
Show file tree
Hide file tree
Showing 4 changed files with 354 additions and 110 deletions.
1 change: 1 addition & 0 deletions crates/yas_core/src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,6 @@ mod tests {
mod constants;
mod swap_cases;
mod pool_1;
mod pool_9;
}
}
46 changes: 46 additions & 0 deletions crates/yas_core/src/tests/test_contracts/test_yas_pool.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -1586,6 +1586,46 @@ mod YASPoolTests {
}
}


mod PoolCase9 {
use super::test_pool;
use yas_core::tests::utils::pool_9::{SWAP_CASES_POOL_9, SWAP_EXPECTED_RESULTS_POOL_9};
use yas_core::tests::utils::swap_cases::SwapTestHelper::{
POOL_CASES
};
use debug::PrintTrait;

const PRESICION: u128 = 5;

#[test]
#[available_gas(200000000000)]
fn test_pool_9_success_cases() {
let pool_case = POOL_CASES()[9];
let expected_cases = SWAP_EXPECTED_RESULTS_POOL_9();
let (success_swap_cases, _) = SWAP_CASES_POOL_9();
test_pool(pool_case, expected_cases, success_swap_cases, PRESICION);
}

// #[test]
// #[available_gas(200000000000)]
// #[should_panic(expected: ('SPL', 'ENTRYPOINT_FAILED', 'ENTRYPOINT_FAILED'))]
// fn test_pool_9_panics_0() {
// let PANIC_CASE = 0;
// let pool_case = POOL_CASES()[9];
// let (success_swap_cases, panic_swap_cases) = SWAP_CASES_POOL_9();
// let expected_cases =
// SWAP_EXPECTED_RESULTS_POOL_9(); //get random case, is never executed
// test_pool(
// pool_case,
// array![*expected_cases[PANIC_CASE]],
// array![*panic_swap_cases[PANIC_CASE]]
// );
// }

}



fn test_pool(
pool_case: @PoolTestCase,
expected_cases: Array<SwapExpectedResults>,
Expand Down Expand Up @@ -1633,6 +1673,12 @@ mod YASPoolTests {
} else {
amount_to_swap = IntegerTrait::<i256>::new((BoundedInt::max() / 2) - 1, false);
}
if amount_to_swap == Zeroable::zero() {
amount_to_swap = *swap_case.amount_specified; //maybe same in negative?
// amount_to_swap = IntegerTrait::<i256>::new(1, true);
}


// Execute swap
let (token_0_swapped_amount, token_1_swapped_amount) = swap_test_case(
yas_router,
Expand Down
197 changes: 197 additions & 0 deletions crates/yas_core/src/tests/utils/pool_9.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
use yas_core::numbers::signed_integer::{
i32::i32, i32::i32_div_no_round, i256::i256, integer_trait::IntegerTrait
};
use yas_core::tests::utils::swap_cases::SwapTestHelper::{
SwapExpectedResults, SwapTestCase, PoolTestCase, obtain_swap_cases, POOL_CASES
};

fn SWAP_CASES_POOL_9() -> (Array<SwapTestCase>, Array<SwapTestCase>) {
obtain_swap_cases(array![14, 15])
}

fn SWAP_EXPECTED_RESULTS_POOL_9() -> Array<SwapExpectedResults> {
array![
// SwapExpectedResults { //ok
// amount_0_before: 0,
// amount_0_delta: IntegerTrait::<i256>::new(1000000000000000000, false),
// amount_1_before: 1995041008271423675,
// amount_1_delta: IntegerTrait::<i256>::new(665331998665331998, true),
// execution_price: 52713031716197226894743303609,
// fee_growth_global_0_X128_delta: 510423550381407695195061911147652317,
// fee_growth_global_1_X128_delta: 0,
// pool_price_after: 52871646656165724119815782674,
// pool_price_before: 79228162514264337593543950336,
// tick_after: IntegerTrait::<i32>::new(8090, true),
// tick_before: IntegerTrait::<i32>::new(0, false),
// },
// SwapExpectedResults { //ok
// amount_0_before: 0,
// amount_0_delta: IntegerTrait::<i256>::new(0, false),
// amount_1_before: 1995041008271423675,
// amount_1_delta: IntegerTrait::<i256>::new(0, false),
// execution_price: 0,
// fee_growth_global_0_X128_delta: 0,
// fee_growth_global_1_X128_delta: 0,
// pool_price_after: 1461446703485210103287273052203988822378723970341,
// pool_price_before: 79228162514264337593543950336,
// tick_after: IntegerTrait::<i32>::new(887271, false),
// tick_before: IntegerTrait::<i32>::new(0, false),
// },
// SwapExpectedResults { //ok
// amount_0_before: 0,
// amount_0_delta: IntegerTrait::<i256>::new(2006018054162487463, false),
// amount_1_before: 1995041008271423675,
// amount_1_delta: IntegerTrait::<i256>::new(1000000000000000000, true),
// execution_price: 39495239013360772278497434865,
// fee_growth_global_0_X128_delta: 1023918857334819954209013958517557896,
// fee_growth_global_1_X128_delta: 0,
// pool_price_after: 39614081257132168796771975168,
// pool_price_before: 79228162514264337593543950336,
// tick_after: IntegerTrait::<i32>::new(13864, true),
// tick_before: IntegerTrait::<i32>::new(0, false),
// },
SwapExpectedResults {
amount_0_before: 0,
amount_0_delta: IntegerTrait::<i256>::new(0, false),
amount_1_before: 1995041008271423675,
amount_1_delta: IntegerTrait::<i256>::new(0, false),
execution_price: 0,
fee_growth_global_0_X128_delta: 0,
fee_growth_global_1_X128_delta: 0,
pool_price_after: 1461446703485210103287273052203988822378723970341,
pool_price_before: 79228162514264337593543950336,
tick_after: IntegerTrait::<i32>::new(887271, false),
tick_before: IntegerTrait::<i32>::new(0, false),
},
// SwapExpectedResults {
// amount_0_before: 0,
// amount_0_delta: IntegerTrait::<i256>::new(830919884399388263, false),
// amount_1_before: 1995041008271423675,
// amount_1_delta: IntegerTrait::<i256>::new(585786437626904951, true),
// execution_price: 55854702661861781438949172455,
// fee_growth_global_0_X128_delta: 424121077477644648929101317621422688,
// fee_growth_global_1_X128_delta: 0,
// pool_price_after: 56022770974786139918731938227,
// pool_price_before: 79228162514264337593543950336,
// tick_after: IntegerTrait::<i32>::new(6932, true),
// tick_before: IntegerTrait::<i32>::new(0, false),
// },
// SwapExpectedResults {
// amount_0_before: 0,
// amount_0_delta: IntegerTrait::<i256>::new(0, false),
// amount_1_before: 1995041008271423675,
// amount_1_delta: IntegerTrait::<i256>::new(0, false),
// execution_price: 0,
// fee_growth_global_0_X128_delta: 0,
// fee_growth_global_1_X128_delta: 0,
// pool_price_after: 112045541949572279837463876454,
// pool_price_before: 79228162514264337593543950336,
// tick_after: IntegerTrait::<i32>::new(6931, false),
// tick_before: IntegerTrait::<i32>::new(0, false),
// },
// SwapExpectedResults {
// amount_0_before: 0,
// amount_0_delta: IntegerTrait::<i256>::new(830919884399388263, false),
// amount_1_before: 1995041008271423675,
// amount_1_delta: IntegerTrait::<i256>::new(585786437626904951, true),
// execution_price: 55854702661861781438949172455,
// fee_growth_global_0_X128_delta: 424121077477644648929101317621422688,
// fee_growth_global_1_X128_delta: 0,
// pool_price_after: 56022770974786139918731938227,
// pool_price_before: 79228162514264337593543950336,
// tick_after: IntegerTrait::<i32>::new(6932, true),
// tick_before: IntegerTrait::<i32>::new(0, false),
// },
// SwapExpectedResults {
// amount_0_before: 0,
// amount_0_delta: IntegerTrait::<i256>::new(0, false),
// amount_1_before: 1995041008271423675,
// amount_1_delta: IntegerTrait::<i256>::new(0, false),
// execution_price: 0,
// fee_growth_global_0_X128_delta: 0,
// fee_growth_global_1_X128_delta: 0,
// pool_price_after: 112045541949572279837463876454,
// pool_price_before: 79228162514264337593543950336,
// tick_after: IntegerTrait::<i32>::new(6931, false),
// tick_before: IntegerTrait::<i32>::new(0, false),
// },
// SwapExpectedResults {
// amount_0_before: 0,
// amount_0_delta: IntegerTrait::<i256>::new(1000, false),
// amount_1_before: 1995041008271423675,
// amount_1_delta: IntegerTrait::<i256>::new(996, true),
// execution_price: 78911249864207280243169774534,
// fee_growth_global_0_X128_delta: 510423550381407695195,
// fee_growth_global_1_X128_delta: 0,
// pool_price_after: 79228162514264298098304936976,
// pool_price_before: 79228162514264337593543950336,
// tick_after: IntegerTrait::<i32>::new(1, true),
// tick_before: IntegerTrait::<i32>::new(0, false),
// },
// SwapExpectedResults {
// amount_0_before: 0,
// amount_0_delta: IntegerTrait::<i256>::new(0, false),
// amount_1_before: 1995041008271423675,
// amount_1_delta: IntegerTrait::<i256>::new(0, false),
// execution_price: 0,
// fee_growth_global_0_X128_delta: 0,
// fee_growth_global_1_X128_delta: 0,
// pool_price_after: 1461446703485210103287273052203988822378723970341,
// pool_price_before: 79228162514264337593543950336,
// tick_after: IntegerTrait::<i32>::new(887271, false),
// tick_before: IntegerTrait::<i32>::new(0, false),
// },
// SwapExpectedResults {
// amount_0_before: 0,
// amount_0_delta: IntegerTrait::<i256>::new(1005, false),
// amount_1_before: 1995041008271423675,
// amount_1_delta: IntegerTrait::<i256>::new(1000, true),
// execution_price: 78833992551506803575373936452,
// fee_growth_global_0_X128_delta: 680564733841876926926,
// fee_growth_global_1_X128_delta: 0,
// pool_price_after: 79228162514264297979462693203,
// pool_price_before: 79228162514264337593543950336,
// tick_after: IntegerTrait::<i32>::new(1, true),
// tick_before: IntegerTrait::<i32>::new(0, false),
// },
// SwapExpectedResults {
// amount_0_before: 0,
// amount_0_delta: IntegerTrait::<i256>::new(0, false),
// amount_1_before: 1995041008271423675,
// amount_1_delta: IntegerTrait::<i256>::new(0, false),
// execution_price: 0,
// fee_growth_global_0_X128_delta: 0,
// fee_growth_global_1_X128_delta: 0,
// pool_price_after: 1461446703485210103287273052203988822378723970341,
// pool_price_before: 79228162514264337593543950336,
// tick_after: IntegerTrait::<i32>::new(887271, false),
// tick_before: IntegerTrait::<i32>::new(0, false),
// },
// SwapExpectedResults {
// amount_0_before: 0,
// amount_0_delta: IntegerTrait::<i256>::new(0, false),
// amount_1_before: 1995041008271423675,
// amount_1_delta: IntegerTrait::<i256>::new(0, false),
// execution_price: 0,
// fee_growth_global_0_X128_delta: 0,
// fee_growth_global_1_X128_delta: 0,
// pool_price_after: 125270724187523965593206900784,
// pool_price_before: 79228162514264337593543950336,
// tick_after: IntegerTrait::<i32>::new(9163, false),
// tick_before: IntegerTrait::<i32>::new(0, false),
// },
// SwapExpectedResults {
// amount_0_before: 0,
// amount_0_delta: IntegerTrait::<i256>::new(1165774985123750584, false),
// amount_1_before: 1995041008271423675,
// amount_1_delta: IntegerTrait::<i256>::new(735088935932648267, true),
// execution_price: 49957964805984557453964279014,
// fee_growth_global_0_X128_delta: 595039006852697554786973994761078087,
// fee_growth_global_1_X128_delta: 0,
// pool_price_after: 50108289675009586237282760313,
// pool_price_before: 79228162514264337593543950336,
// tick_after: IntegerTrait::<i32>::new(9164, true),
// tick_before: IntegerTrait::<i32>::new(0, false),
// },
]
}
Loading

0 comments on commit 70ec219

Please sign in to comment.