Skip to content

Commit

Permalink
Add result test to checked cross_tick to invariant-type module
Browse files Browse the repository at this point in the history
  • Loading branch information
wojciech-cichocki committed Apr 3, 2024
1 parent 0aeba7a commit 33af9ed
Showing 1 changed file with 110 additions and 140 deletions.
250 changes: 110 additions & 140 deletions programs/invariant/invariant-types/src/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1823,145 +1823,115 @@ mod tests {
assert_eq!(*refmut_tick, result_tick);
assert_eq!(pool, result_pool);
}
// {
// let mut pool = Pool {
// fee_growth_global_x: FeeGrowth::new(68),
// fee_growth_global_y: FeeGrowth::new(59),
// liquidity: Liquidity::new(0),
// last_timestamp: 9,
// start_timestamp: 34,
// seconds_per_liquidity_global: FixedPoint::new(32),
// current_tick_index: 4,
// ..Default::default()
// };
// let tick = Tick {
// fee_growth_outside_x: FeeGrowth::new(42),
// fee_growth_outside_y: FeeGrowth::new(14),
// index: 9,
// seconds_outside: 41,
// seconds_per_liquidity_outside: FixedPoint::new(23),
// liquidity_change: Liquidity::new(0),
// ..Default::default()
// };
// let result_pool = Pool {
// fee_growth_global_x: FeeGrowth::new(68),
// fee_growth_global_y: FeeGrowth::new(59),
// liquidity: Liquidity::new(0),
// last_timestamp: 1844674407370,
// start_timestamp: 34,
// seconds_per_liquidity_global: FixedPoint::new(32),
// current_tick_index: 4,
// ..Default::default()
// };
// let result_tick = Tick {
// fee_growth_outside_x: FeeGrowth::new(26),
// fee_growth_outside_y: FeeGrowth::new(45),
// index: 9,
// seconds_outside: 1844674407295,
// seconds_per_liquidity_outside: FixedPoint::new(9),
// liquidity_change: Liquidity::from_integer(0),
// ..Default::default()
// };

// let fef_tick = RefCell::new(tick);
// let mut refmut_tick = fef_tick.borrow_mut();
// cross_tick(&mut refmut_tick, &mut pool, 1844674407370).ok();
// assert_eq!(*refmut_tick, result_tick);
// assert_eq!(pool, result_pool);
// }
// // fee_growth_outside should underflow
// {
// let mut pool = Pool {
// fee_growth_global_x: FeeGrowth::new(3402),
// fee_growth_global_y: FeeGrowth::new(3401),
// liquidity: Liquidity::new(14),
// last_timestamp: 9,
// start_timestamp: 15,
// seconds_per_liquidity_global: FixedPoint::new(22),
// current_tick_index: 9,
// ..Default::default()
// };
// let tick = Tick {
// fee_growth_outside_x: FeeGrowth::new(26584),
// fee_growth_outside_y: FeeGrowth::new(1256588),
// index: 45,
// seconds_outside: 74,
// seconds_per_liquidity_outside: FixedPoint::new(23),
// liquidity_change: Liquidity::new(10),
// ..Default::default()
// };
// let result_pool = Pool {
// fee_growth_global_x: FeeGrowth::new(3402),
// fee_growth_global_y: FeeGrowth::new(3401),
// liquidity: Liquidity::new(4),
// last_timestamp: 1844674407370953,
// start_timestamp: 15,
// seconds_per_liquidity_global: FixedPoint::new(131762457669353142857142857142879),
// current_tick_index: 9,
// ..Default::default()
// };
// let result_tick = Tick {
// fee_growth_outside_x: FeeGrowth::new(340282366920938463463374607431768188274),
// fee_growth_outside_y: FeeGrowth::new(340282366920938463463374607431766958269),
// index: 45,
// seconds_outside: 1844674407370864,
// seconds_per_liquidity_outside: FixedPoint::new(131762457669353142857142857142856),
// liquidity_change: Liquidity::new(10),
// ..Default::default()
// };

// let fef_tick = RefCell::new(tick);
// let mut refmut_tick = fef_tick.borrow_mut();
// cross_tick(&mut refmut_tick, &mut pool, 1844674407370953).ok();
// assert_eq!(*refmut_tick, result_tick);
// assert_eq!(pool, result_pool);
// }
// // seconds_per_liquidity_outside should underflow
// {
// let mut pool = Pool {
// fee_growth_global_x: FeeGrowth::new(145),
// fee_growth_global_y: FeeGrowth::new(364),
// liquidity: Liquidity::new(14),
// last_timestamp: 16,
// start_timestamp: 15,
// seconds_per_liquidity_global: FixedPoint::new(354),
// current_tick_index: 9,
// ..Default::default()
// };
// let tick = Tick {
// fee_growth_outside_x: FeeGrowth::new(99),
// fee_growth_outside_y: FeeGrowth::new(256),
// index: 45,
// seconds_outside: 74,
// seconds_per_liquidity_outside: FixedPoint::new(35),
// liquidity_change: Liquidity::new(10),
// ..Default::default()
// };
// let result_pool = Pool {
// fee_growth_global_x: FeeGrowth::new(145),
// fee_growth_global_y: FeeGrowth::new(364),
// liquidity: Liquidity::new(4),
// last_timestamp: 1844674407370953,
// start_timestamp: 15,
// seconds_per_liquidity_global: FixedPoint::new(131762457669352642857142857143211),
// current_tick_index: 9,
// ..Default::default()
// };
// let result_tick = Tick {
// fee_growth_outside_x: FeeGrowth::new(46),
// fee_growth_outside_y: FeeGrowth::new(108),
// index: 45,
// seconds_outside: 1844674407370864,
// seconds_per_liquidity_outside: FixedPoint::new(131762457669352642857142857143176),
// liquidity_change: Liquidity::new(10),
// ..Default::default()
// };

// let fef_tick = RefCell::new(tick);
// let mut refmut_tick = fef_tick.borrow_mut();
// cross_tick(&mut refmut_tick, &mut pool, 1844674407370953).ok();
// assert_eq!(*refmut_tick, result_tick);
// assert_eq!(pool, result_pool);
// }
{
let mut pool = Pool {
fee_growth_global_x: FeeGrowth::new(68),
fee_growth_global_y: FeeGrowth::new(59),
liquidity: Liquidity::new(0),
current_tick_index: 4,
..Default::default()
};
let tick = Tick {
fee_growth_outside_x: FeeGrowth::new(42),
fee_growth_outside_y: FeeGrowth::new(14),
index: 9,
liquidity_change: Liquidity::new(0),
..Default::default()
};
let result_pool = Pool {
fee_growth_global_x: FeeGrowth::new(68),
fee_growth_global_y: FeeGrowth::new(59),
liquidity: Liquidity::new(0),
current_tick_index: 4,
..Default::default()
};
let result_tick = Tick {
fee_growth_outside_x: FeeGrowth::new(26),
fee_growth_outside_y: FeeGrowth::new(45),
index: 9,
liquidity_change: Liquidity::from_integer(0),
..Default::default()
};

let ref_tick = RefCell::new(tick);
let mut refmut_tick = ref_tick.borrow_mut();
cross_tick(&mut refmut_tick, &mut pool).ok();
assert_eq!(*refmut_tick, result_tick);
assert_eq!(pool, result_pool);
}
// fee_growth_outside should underflow
{
let mut pool = Pool {
fee_growth_global_x: FeeGrowth::new(3402),
fee_growth_global_y: FeeGrowth::new(3401),
liquidity: Liquidity::new(14),
current_tick_index: 9,
..Default::default()
};
let tick = Tick {
fee_growth_outside_x: FeeGrowth::new(26584),
fee_growth_outside_y: FeeGrowth::new(1256588),
index: 45,
liquidity_change: Liquidity::new(10),
..Default::default()
};
let result_pool = Pool {
fee_growth_global_x: FeeGrowth::new(3402),
fee_growth_global_y: FeeGrowth::new(3401),
liquidity: Liquidity::new(4),
current_tick_index: 9,
..Default::default()
};
let result_tick = Tick {
fee_growth_outside_x: FeeGrowth::new(340282366920938463463374607431768188274),
fee_growth_outside_y: FeeGrowth::new(340282366920938463463374607431766958269),
index: 45,
liquidity_change: Liquidity::new(10),
..Default::default()
};

let fef_tick = RefCell::new(tick);
let mut refmut_tick = fef_tick.borrow_mut();
cross_tick(&mut refmut_tick, &mut pool).ok();
assert_eq!(*refmut_tick, result_tick);
assert_eq!(pool, result_pool);
}
// seconds_per_liquidity_outside should underflow
{
let mut pool = Pool {
fee_growth_global_x: FeeGrowth::new(145),
fee_growth_global_y: FeeGrowth::new(364),
liquidity: Liquidity::new(14),
current_tick_index: 9,
..Default::default()
};
let tick = Tick {
fee_growth_outside_x: FeeGrowth::new(99),
fee_growth_outside_y: FeeGrowth::new(256),
index: 45,
liquidity_change: Liquidity::new(10),
..Default::default()
};
let result_pool = Pool {
fee_growth_global_x: FeeGrowth::new(145),
fee_growth_global_y: FeeGrowth::new(364),
liquidity: Liquidity::new(4),
current_tick_index: 9,
..Default::default()
};
let result_tick = Tick {
fee_growth_outside_x: FeeGrowth::new(46),
fee_growth_outside_y: FeeGrowth::new(108),
index: 45,
liquidity_change: Liquidity::new(10),
..Default::default()
};

let fef_tick = RefCell::new(tick);
let mut refmut_tick = fef_tick.borrow_mut();
cross_tick(&mut refmut_tick, &mut pool).ok();
assert_eq!(*refmut_tick, result_tick);
assert_eq!(pool, result_pool);
}
}
}

0 comments on commit 33af9ed

Please sign in to comment.