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

add swap() tests for Pool 11 #190

Merged
merged 21 commits into from
Jan 2, 2024
Merged
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
2 changes: 2 additions & 0 deletions crates/yas_core/src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ mod tests {
mod test_swap_pool_8;
mod test_swap_pool_9;
mod test_swap_pool_10;
mod test_swap_pool_11;
mod test_swap_pool_12;
mod test_swap_pool_13;
mod test_swap_pool_14;
Expand Down Expand Up @@ -87,6 +88,7 @@ mod tests {
mod pool_8;
mod pool_9;
mod pool_10;
mod pool_11;
mod pool_12;
mod pool_13;
mod pool_14;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
mod PoolCase11 {
use yas_core::tests::utils::swap_helper::SwapTestHelper::test_pool;
use yas_core::tests::utils::pool_11::{SWAP_CASES_POOL_11, SWAP_EXPECTED_RESULTS_POOL_11};
use yas_core::tests::utils::swap_cases::SwapTestHelper::POOL_CASES;

const PRECISION: u256 = 5;

#[test]
#[available_gas(200000000000)]
fn test_pool_11_success_cases() {
let pool_case = POOL_CASES()[11];
let expected_cases = SWAP_EXPECTED_RESULTS_POOL_11();
let (success_swap_cases, _) = SWAP_CASES_POOL_11();
test_pool(pool_case, expected_cases, success_swap_cases, PRECISION);
}

#[test]
#[available_gas(200000000000)]
#[should_panic(expected: ('SPL', 'ENTRYPOINT_FAILED', 'ENTRYPOINT_FAILED'))]
fn test_pool_11_panics_0() {
let PANIC_CASE = 0;
let pool_case = POOL_CASES()[11];
let (success_swap_cases, panic_swap_cases) = SWAP_CASES_POOL_11();
let expected_cases = SWAP_EXPECTED_RESULTS_POOL_11();
test_pool(
pool_case,
array![*expected_cases[PANIC_CASE]],
array![*panic_swap_cases[PANIC_CASE]],
Zeroable::zero()
);
}

#[test]
#[available_gas(200000000000)]
#[should_panic(expected: ('SPL', 'ENTRYPOINT_FAILED', 'ENTRYPOINT_FAILED'))]
fn test_pool_11_panics_1() {
let PANIC_CASE = 1;
let pool_case = POOL_CASES()[11];
let (success_swap_cases, panic_swap_cases) = SWAP_CASES_POOL_11();
let expected_cases = SWAP_EXPECTED_RESULTS_POOL_11();
test_pool(
pool_case,
array![*expected_cases[PANIC_CASE]],
array![*panic_swap_cases[PANIC_CASE]],
Zeroable::zero()
);
}

#[test]
#[available_gas(200000000000)]
#[should_panic(expected: ('SPL', 'ENTRYPOINT_FAILED', 'ENTRYPOINT_FAILED'))]
fn test_pool_11_panics_2() {
let PANIC_CASE = 2;
let pool_case = POOL_CASES()[11];
let (success_swap_cases, panic_swap_cases) = SWAP_CASES_POOL_11();
let expected_cases = SWAP_EXPECTED_RESULTS_POOL_11();
test_pool(
pool_case,
array![*expected_cases[PANIC_CASE]],
array![*panic_swap_cases[PANIC_CASE]],
Zeroable::zero()
);
}

#[test]
#[available_gas(200000000000)]
#[should_panic(expected: ('SPL', 'ENTRYPOINT_FAILED', 'ENTRYPOINT_FAILED'))]
fn test_pool_11_panics_3() {
let PANIC_CASE = 3;
let pool_case = POOL_CASES()[11];
let (success_swap_cases, panic_swap_cases) = SWAP_CASES_POOL_11();
let expected_cases = SWAP_EXPECTED_RESULTS_POOL_11();
test_pool(
pool_case,
array![*expected_cases[PANIC_CASE]],
array![*panic_swap_cases[PANIC_CASE]],
Zeroable::zero()
);
}
}
175 changes: 175 additions & 0 deletions crates/yas_core/src/tests/utils/pool_11.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
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_11() -> (Array<SwapTestCase>, Array<SwapTestCase>) {
obtain_swap_cases(array![4, 6, 13, 14])
}

fn SWAP_EXPECTED_RESULTS_POOL_11() -> Array<SwapExpectedResults> {
array![
SwapExpectedResults {
amount_0_before: 26037782196502120275425782622539039026,
amount_0_delta: IntegerTrait::<i256>::new(1000000000000000000, false),
amount_1_before: 1,
amount_1_delta: IntegerTrait::<i256>::new(0, false),
execution_price: 0,
fee_growth_global_0_X128_delta: 170141183460469231731687303715884105728,
fee_growth_global_1_X128_delta: 0,
pool_price_after: 6085630636,
pool_price_before: 6085630636,
tick_after: IntegerTrait::<i32>::new(880303, true),
tick_before: IntegerTrait::<i32>::new(880303, true),
},
SwapExpectedResults {
amount_0_before: 26037782196502120275425782622539039026,
amount_0_delta: IntegerTrait::<i256>::new(26037782196502120271413746514214063808, true),
amount_1_before: 1,
amount_1_delta: IntegerTrait::<i256>::new(1000000000000000000, false),
execution_price: 3042815318,
fee_growth_global_0_X128_delta: 0,
fee_growth_global_1_X128_delta: 510423550381413820277666488039994629,
pool_price_after: 39495239013360769732380381856,
pool_price_before: 6085630636,
tick_after: IntegerTrait::<i32>::new(13924, true),
tick_before: IntegerTrait::<i32>::new(880303, true),
},
SwapExpectedResults {
amount_0_before: 26037782196502120275425782622539039026,
amount_0_delta: IntegerTrait::<i256>::new(
10790901831095468191587263901270792610, false
),
amount_1_before: 1,
amount_1_delta: IntegerTrait::<i256>::new(0, false),
execution_price: 0,
fee_growth_global_0_X128_delta: 5507930424444982259736347157352787128931407551935325049,
fee_growth_global_1_X128_delta: 0,
pool_price_after: 4295128740,
pool_price_before: 6085630636,
tick_after: IntegerTrait::<i32>::new(887272, true),
tick_before: IntegerTrait::<i32>::new(880303, true),
},
SwapExpectedResults {
amount_0_before: 26037782196502120275425782622539039026,
amount_0_delta: IntegerTrait::<i256>::new(1000000000000000000, true),
amount_1_before: 1,
amount_1_delta: IntegerTrait::<i256>::new(2, false),
execution_price: 158456325028,
fee_growth_global_0_X128_delta: 0,
fee_growth_global_1_X128_delta: 170141183460469231731,
pool_price_after: 6085630637,
pool_price_before: 6085630636,
tick_after: IntegerTrait::<i32>::new(880303, true),
tick_before: IntegerTrait::<i32>::new(880303, true),
},
SwapExpectedResults {
amount_0_before: 26037782196502120275425782622539039026,
amount_0_delta: IntegerTrait::<i256>::new(26037782196502120271413746514214063808, true),
amount_1_before: 1,
amount_1_delta: IntegerTrait::<i256>::new(1000000000000000000, false),
execution_price: 3042815318,
fee_growth_global_0_X128_delta: 0,
fee_growth_global_1_X128_delta: 510423550381413820277666488039994629,
pool_price_after: 39495239013360769732380381856,
pool_price_before: 6085630636,
tick_after: IntegerTrait::<i32>::new(13924, true),
tick_before: IntegerTrait::<i32>::new(880303, true),
},
SwapExpectedResults {
amount_0_before: 26037782196502120275425782622539039026,
amount_0_delta: IntegerTrait::<i256>::new(1000000000000000000, true),
amount_1_before: 1,
amount_1_delta: IntegerTrait::<i256>::new(2, false),
execution_price: 158456325028,
fee_growth_global_0_X128_delta: 0,
fee_growth_global_1_X128_delta: 170141183460469231731,
pool_price_after: 6085630637,
pool_price_before: 6085630636,
tick_after: IntegerTrait::<i32>::new(880303, true),
tick_before: IntegerTrait::<i32>::new(880303, true),
},
SwapExpectedResults {
amount_0_before: 26037782196502120275425782622539039026,
amount_0_delta: IntegerTrait::<i256>::new(1000, false),
amount_1_before: 1,
amount_1_delta: IntegerTrait::<i256>::new(0, false),
execution_price: 0,
fee_growth_global_0_X128_delta: 170141183460469231731687,
fee_growth_global_1_X128_delta: 0,
pool_price_after: 6085630636,
pool_price_before: 6085630636,
tick_after: IntegerTrait::<i32>::new(880303, true),
tick_before: IntegerTrait::<i32>::new(880303, true),
},
SwapExpectedResults {
amount_0_before: 26037782196502120275425782622539039026,
amount_0_delta: IntegerTrait::<i256>::new(26033697540846965126433148994127431276, true),
amount_1_before: 1,
amount_1_delta: IntegerTrait::<i256>::new(1000, false),
execution_price: 0,
fee_growth_global_0_X128_delta: 0,
fee_growth_global_1_X128_delta: 2381976568446569244235,
pool_price_after: 38793068108090,
pool_price_before: 6085630636,
tick_after: IntegerTrait::<i32>::new(705093, true),
tick_before: IntegerTrait::<i32>::new(880303, true),
},
SwapExpectedResults {
amount_0_before: 26037782196502120275425782622539039026,
amount_0_delta: IntegerTrait::<i256>::new(
10790901831095468191587263901270792610, false
),
amount_1_before: 1,
amount_1_delta: IntegerTrait::<i256>::new(0, false),
execution_price: 0,
fee_growth_global_0_X128_delta: 5507930424444982259736347157352787128931407551935325049,
fee_growth_global_1_X128_delta: 0,
pool_price_after: 4295128740,
pool_price_before: 6085630636,
tick_after: IntegerTrait::<i32>::new(887272, true),
tick_before: IntegerTrait::<i32>::new(880303, true),
},
SwapExpectedResults {
amount_0_before: 26037782196502120275425782622539039026,
amount_0_delta: IntegerTrait::<i256>::new(1000, true),
amount_1_before: 1,
amount_1_delta: IntegerTrait::<i256>::new(2, false),
execution_price: 158456325028528675187087900,
fee_growth_global_0_X128_delta: 0,
fee_growth_global_1_X128_delta: 170141183460469231731,
pool_price_after: 6085630637,
pool_price_before: 6085630636,
tick_after: IntegerTrait::<i32>::new(880303, true),
tick_before: IntegerTrait::<i32>::new(880303, true),
},
SwapExpectedResults {
amount_0_before: 26037782196502120275425782622539039026,
amount_0_delta: IntegerTrait::<i256>::new(26037782196502120274160871558471687260, true),
amount_1_before: 1,
amount_1_delta: IntegerTrait::<i256>::new(3171793039286238112, false),
execution_price: 9651180445,
fee_growth_global_0_X128_delta: 0,
fee_growth_global_1_X128_delta: 1618957864187523634078592530170978294,
pool_price_after: 125270724187523965593206900784,
pool_price_before: 6085630636,
tick_after: IntegerTrait::<i32>::new(9163, false),
tick_before: IntegerTrait::<i32>::new(880303, true),
},
SwapExpectedResults {
amount_0_before: 26037782196502120275425782622539039026,
amount_0_delta: IntegerTrait::<i256>::new(26037782196502120272263504962370659661, true),
amount_1_before: 1,
amount_1_delta: IntegerTrait::<i256>::new(1268717215714495283, false),
execution_price: 3860472178,
fee_growth_global_0_X128_delta: 0,
fee_growth_global_1_X128_delta: 647583145675012958539816297734564973,
pool_price_after: 50108289675009586237282760313,
pool_price_before: 6085630636,
tick_after: IntegerTrait::<i32>::new(9164, true),
tick_before: IntegerTrait::<i32>::new(880303, true),
}
]
}
Loading