Skip to content

Commit 3e047cf

Browse files
committed
Add tests Core tick.rs. Fix bug get_initializable_tick_index for ts1. Fix uncaught overflow issue for mul_shift_96. Add error. Fix test names in program.
1 parent e20268a commit 3e047cf

File tree

5 files changed

+934
-108
lines changed

5 files changed

+934
-108
lines changed

programs/whirlpool/src/math/tick_math.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -341,44 +341,44 @@ mod test_tick_index_from_sqrt_price {
341341
use crate::state::{MAX_TICK_INDEX, MIN_TICK_INDEX};
342342

343343
#[test]
344-
fn test_sqrt_price_from_tick_index_at_max() {
344+
fn test_tick_index_from_sqrt_price_at_max() {
345345
let r = tick_index_from_sqrt_price(&MAX_SQRT_PRICE_X64);
346346
assert_eq!(&r, &MAX_TICK_INDEX);
347347
}
348348

349349
#[test]
350-
fn test_sqrt_price_from_tick_index_at_min() {
350+
fn test_tick_index_from_sqrt_price_at_min() {
351351
let r = tick_index_from_sqrt_price(&MIN_SQRT_PRICE_X64);
352352
assert_eq!(&r, &MIN_TICK_INDEX);
353353
}
354354

355355
#[test]
356-
fn test_sqrt_price_from_tick_index_at_max_add_one() {
356+
fn test_tick_index_from_sqrt_price_at_max_add_one() {
357357
let sqrt_price_x64_max_add_one = MAX_SQRT_PRICE_X64 + 1;
358358
let tick_from_max_add_one = tick_index_from_sqrt_price(&sqrt_price_x64_max_add_one);
359-
let sqrt_price_x64_max = MAX_SQRT_PRICE_X64 + 1;
359+
let sqrt_price_x64_max = MAX_SQRT_PRICE_X64;
360360
let tick_from_max = tick_index_from_sqrt_price(&sqrt_price_x64_max);
361361

362362
// We don't care about accuracy over the limit. We just care about it's equality properties.
363363
assert!(tick_from_max_add_one >= tick_from_max);
364364
}
365365

366366
#[test]
367-
fn test_sqrt_price_from_tick_index_at_min_add_one() {
367+
fn test_tick_index_from_sqrt_price_at_min_add_one() {
368368
let sqrt_price_x64 = MIN_SQRT_PRICE_X64 + 1;
369369
let r = tick_index_from_sqrt_price(&sqrt_price_x64);
370370
assert_eq!(&r, &(MIN_TICK_INDEX));
371371
}
372372

373373
#[test]
374-
fn test_sqrt_price_from_tick_index_at_max_sub_one() {
374+
fn test_tick_index_from_sqrt_price_at_max_sub_one() {
375375
let sqrt_price_x64 = MAX_SQRT_PRICE_X64 - 1;
376376
let r = tick_index_from_sqrt_price(&sqrt_price_x64);
377377
assert_eq!(&r, &(MAX_TICK_INDEX - 1));
378378
}
379379

380380
#[test]
381-
fn test_sqrt_price_from_tick_index_at_min_sub_one() {
381+
fn test_tick_index_from_sqrt_price_at_min_sub_one() {
382382
let sqrt_price_x64_min_sub_one = MIN_SQRT_PRICE_X64 - 1;
383383
let tick_from_min_sub_one = tick_index_from_sqrt_price(&sqrt_price_x64_min_sub_one);
384384
let sqrt_price_x64_min = MIN_SQRT_PRICE_X64 + 1;
@@ -389,21 +389,21 @@ mod test_tick_index_from_sqrt_price {
389389
}
390390

391391
#[test]
392-
fn test_sqrt_price_from_tick_index_at_one() {
392+
fn test_tick_index_from_sqrt_price_at_one() {
393393
let sqrt_price_x64: u128 = u64::MAX as u128 + 1;
394394
let r = tick_index_from_sqrt_price(&sqrt_price_x64);
395395
assert_eq!(r, 0);
396396
}
397397

398398
#[test]
399-
fn test_sqrt_price_from_tick_index_at_one_add_one() {
399+
fn test_tick_index_from_sqrt_price_at_one_add_one() {
400400
let sqrt_price_x64: u128 = u64::MAX as u128 + 2;
401401
let r = tick_index_from_sqrt_price(&sqrt_price_x64);
402402
assert_eq!(r, 0);
403403
}
404404

405405
#[test]
406-
fn test_sqrt_price_from_tick_index_at_one_sub_one() {
406+
fn test_tick_index_from_sqrt_price_at_one_sub_one() {
407407
let sqrt_price_x64: u128 = u64::MAX.into();
408408
let r = tick_index_from_sqrt_price(&sqrt_price_x64);
409409
assert_eq!(r, -1);

0 commit comments

Comments
 (0)