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

Test/swap #193

Open
wants to merge 41 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
5c22293
Feat: Pool0 fully tested
uri-99 Nov 8, 2023
6b3474d
Feat: pool 9 with same error as pool 8
uri-99 Nov 13, 2023
026ce72
Fix: obtain_swap_cases
Nov 22, 2023
f26362c
WIP: price to x96 format
uri-99 Nov 22, 2023
058a04b
migrate round price (wip)
dubzn Nov 24, 2023
2cbc7d5
add methods for precision
dubzn Nov 24, 2023
d268048
add presicion param for tests
dubzn Nov 27, 2023
81dc316
adding amounts params for setup
dubzn Nov 29, 2023
704136f
fix add amounts to approve req
dubzn Nov 29, 2023
2541397
Revert "add presicion param for tests"
dubzn Nov 29, 2023
48996aa
Merge branch 'test/swap' into pool-9
Nov 30, 2023
a2d00a1
fix exec price dividing by 0 bug (#184)
uri-99 Nov 30, 2023
a0550ae
Merge branch 'test/swap' into pool-9
Nov 30, 2023
18ed3dd
wip swap_amt=0 test fix
Nov 30, 2023
70ec219
Merge branch 'pool-9' into test/swap
Dec 1, 2023
5f6441a
Revert "Merge branch 'pool-9' into test/swap"
Dec 1, 2023
68f57df
Fix CI Test & Katana (#192)
dpinones Dec 1, 2023
a792eab
make fmt
Dec 1, 2023
e51cd04
add swap() tests for Pool 0 (#158)
uri-99 Dec 1, 2023
973836e
Add swap() tests for Pool 2 (#179)
dubzn Dec 1, 2023
978415c
add swap() tests for Pool 5 (#160)
uri-99 Dec 5, 2023
8a6728c
Fix pool2 error from merge
Dec 5, 2023
7a1ebbf
use Zeroable::zero() in panic cases
Dec 6, 2023
73b0cd8
Merge branch 'main' into test/swap
dubzn Dec 7, 2023
b47faaf
add swap() tests for Pool 9 (#197)
uri-99 Dec 11, 2023
e67656e
add swap() tests for Pool 6 (#177)
uri-99 Dec 11, 2023
022d096
Add usage of swap(-x) in test (#194)
uri-99 Dec 11, 2023
5723427
Add -Inf case (#196)
uri-99 Dec 11, 2023
21e4245
Refactor swap tests (#200)
dubzn Dec 15, 2023
9183529
Add swap() tests for Pool 3 (#181)
dubzn Dec 28, 2023
0a1ec61
Add swap() tests for Pool 14 (#182)
dpinones Dec 28, 2023
2e403ce
Add swap() tests for Pool 13 (#185)
dubzn Dec 28, 2023
360f8eb
add swap() tests for Pool 7 (#186)
uri-99 Dec 28, 2023
b4a7727
add swap() tests for Pool 8 (#187)
uri-99 Dec 28, 2023
e80624f
add swap() tests for Pool 10 (#189)
uri-99 Dec 28, 2023
8257776
add swap() tests for Pool 12 (#191)
uri-99 Dec 28, 2023
6dc62de
Test/fix pool bug (#204)
uri-99 Dec 29, 2023
6bd7cd2
Add swap() tests for Pool 4 (#159)
uri-99 Jan 2, 2024
3b82940
add swap() tests for Pool 11 (#190)
uri-99 Jan 2, 2024
2c2c06e
trigger CI
uri-99 Jan 5, 2024
3689197
Revert "trigger CI"
uri-99 Jan 5, 2024
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
7 changes: 3 additions & 4 deletions .github/workflows/katana.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
name: Run Katana

on:
merge_group:
push:
branches: [main]
pull_request:
branches: ["*"]
types: [opened, synchronize, reopened]

jobs:
katana:
runs-on: ubuntu-latest
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/security.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
name: Security

on:
merge_group:
push:
branches: [main]
pull_request:
types: [opened, synchronize, reopened]
branches: ["*"]

jobs:
check:
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
name: Tests

on:
merge_group:
push:
branches: [main]
pull_request:
branches: ["*"]
types: [opened, synchronize, reopened]

jobs:
check:
runs-on: ubuntu-latest
Expand Down
27 changes: 27 additions & 0 deletions Scarb.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Code generated by scarb DO NOT EDIT.
version = 1

[[package]]
name = "openzeppelin"
version = "0.7.0"
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.7.0#61a2505fe0c0f19b5de2b3f8dedf421ba2cff657"

[[package]]
name = "yas_core"
version = "0.1.0"

[[package]]
name = "yas_faucet"
version = "0.1.0"
dependencies = [
"openzeppelin",
"yas_core",
]

[[package]]
name = "yas_periphery"
version = "0.1.0"
dependencies = [
"openzeppelin",
"yas_core",
]
30 changes: 30 additions & 0 deletions crates/yas_core/src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@ mod tests {
mod test_contracts {
mod test_yas_factory;
mod test_yas_pool;
mod test_swap_pool_0;
mod test_swap_pool_1;
mod test_swap_pool_2;
mod test_swap_pool_3;
mod test_swap_pool_4;
mod test_swap_pool_5;
mod test_swap_pool_6;
mod test_swap_pool_7;
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;
}

mod test_libraries {
Expand All @@ -62,7 +77,22 @@ mod tests {

mod utils {
mod constants;
mod swap_helper;
mod swap_cases;
mod pool_0;
mod pool_1;
mod pool_2;
mod pool_3;
mod pool_4;
mod pool_5;
mod pool_6;
mod pool_7;
mod pool_8;
mod pool_9;
mod pool_10;
mod pool_11;
mod pool_12;
mod pool_13;
mod pool_14;
}
}
14 changes: 9 additions & 5 deletions crates/yas_core/src/libraries/tick_bitmap.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,18 @@ mod TickBitmap {
let divisor = IntegerTrait::<i32>::new(256, false);
let negative_lower_bound = IntegerTrait::<i32>::new(256, true);

let result = if tick >= zero && tick <= upper_bound {
let result = if tick >= zero && tick <= upper_bound { //tick: [0, 255]
zero
} else if tick > upper_bound {
} else if tick > upper_bound { //tick: [256, 887272]
tick / divisor
} else if tick >= negative_lower_bound {
} else if tick >= negative_lower_bound { //tick: [-256, -1]
one_negative
} else {
tick / divisor + one_negative
} else { //tick: [-887272, -257]
if (mod_i32(tick, divisor) != zero) {
IntegerTrait::<i32>::new((tick.mag / divisor.mag) + 1, true)
} else {
IntegerTrait::<i32>::new((tick.mag / divisor.mag), true)
}
};
result.try_into().expect('calculate_word')
}
Expand Down
48 changes: 48 additions & 0 deletions crates/yas_core/src/tests/test_contracts/test_swap_pool_0.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
mod PoolCase0 {
use yas_core::tests::utils::swap_helper::SwapTestHelper::test_pool;
use yas_core::tests::utils::pool_0::{SWAP_CASES_POOL_0, SWAP_EXPECTED_RESULTS_POOL_0};
use yas_core::tests::utils::swap_cases::SwapTestHelper::POOL_CASES;

const PRECISION: u256 = 5;

#[test]
#[available_gas(200000000000)]
fn test_pool_0_success_cases() {
let pool_case = POOL_CASES()[0];
let expected_cases = SWAP_EXPECTED_RESULTS_POOL_0();
let (success_swap_cases, _) = SWAP_CASES_POOL_0();
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_0_panics_0() {
let PANIC_CASE = 0;
let pool_case = POOL_CASES()[0];
let (success_swap_cases, panic_swap_cases) = SWAP_CASES_POOL_0();
let expected_cases = SWAP_EXPECTED_RESULTS_POOL_0();
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_0_panics_1() {
let PANIC_CASE = 1;
let pool_case = POOL_CASES()[0];
let (success_swap_cases, panic_swap_cases) = SWAP_CASES_POOL_0();
let expected_cases = SWAP_EXPECTED_RESULTS_POOL_0();
test_pool(
pool_case,
array![*expected_cases[PANIC_CASE]],
array![*panic_swap_cases[PANIC_CASE]],
Zeroable::zero()
);
}
}
48 changes: 48 additions & 0 deletions crates/yas_core/src/tests/test_contracts/test_swap_pool_1.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
mod PoolCase1 {
use yas_core::tests::utils::swap_helper::SwapTestHelper::test_pool;
use yas_core::tests::utils::pool_1::{SWAP_CASES_POOL_1, SWAP_EXPECTED_RESULTS_POOL_1};
use yas_core::tests::utils::swap_cases::SwapTestHelper::POOL_CASES;

const PRECISION: u256 = 5;

#[test]
#[available_gas(200000000000)]
fn test_pool_1_success_cases() {
let pool_case = POOL_CASES()[1];
let expected_cases = SWAP_EXPECTED_RESULTS_POOL_1();
let (success_swap_cases, _) = SWAP_CASES_POOL_1();
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_1_panics_0() {
let PANIC_CASE = 0;
let pool_case = POOL_CASES()[1];
let (success_swap_cases, panic_swap_cases) = SWAP_CASES_POOL_1();
let expected_cases = SWAP_EXPECTED_RESULTS_POOL_1();
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_1_panics_1() {
let PANIC_CASE = 1;
let pool_case = POOL_CASES()[1];
let (success_swap_cases, panic_swap_cases) = SWAP_CASES_POOL_1();
let expected_cases = SWAP_EXPECTED_RESULTS_POOL_1();
test_pool(
pool_case,
array![*expected_cases[PANIC_CASE]],
array![*panic_swap_cases[PANIC_CASE]],
Zeroable::zero()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
mod PoolCase10 {
use yas_core::tests::utils::swap_helper::SwapTestHelper::test_pool;
use yas_core::tests::utils::pool_10::{SWAP_CASES_POOL_10, SWAP_EXPECTED_RESULTS_POOL_10};
use yas_core::tests::utils::swap_cases::SwapTestHelper::POOL_CASES;

const PRECISION: u256 = 5;

#[test]
#[available_gas(200000000000)]
fn test_pool_10_success_cases() {
let pool_case = POOL_CASES()[10];
let expected_cases = SWAP_EXPECTED_RESULTS_POOL_10();
let (success_swap_cases, _) = SWAP_CASES_POOL_10();
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_10_panics_0() {
let PANIC_CASE = 0;
let pool_case = POOL_CASES()[10];
let (success_swap_cases, panic_swap_cases) = SWAP_CASES_POOL_10();
let expected_cases = SWAP_EXPECTED_RESULTS_POOL_10();
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_10_panics_1() {
let PANIC_CASE = 1;
let pool_case = POOL_CASES()[10];
let (success_swap_cases, panic_swap_cases) = SWAP_CASES_POOL_10();
let expected_cases = SWAP_EXPECTED_RESULTS_POOL_10();
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_10_panics_2() {
let PANIC_CASE = 2;
let pool_case = POOL_CASES()[10];
let (success_swap_cases, panic_swap_cases) = SWAP_CASES_POOL_10();
let expected_cases = SWAP_EXPECTED_RESULTS_POOL_10();
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_10_panics_3() {
let PANIC_CASE = 3;
let pool_case = POOL_CASES()[10];
let (success_swap_cases, panic_swap_cases) = SWAP_CASES_POOL_10();
let expected_cases = SWAP_EXPECTED_RESULTS_POOL_10();
test_pool(
pool_case,
array![*expected_cases[PANIC_CASE]],
array![*panic_swap_cases[PANIC_CASE]],
Zeroable::zero()
);
}
}
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()
);
}
}
Loading
Loading