Skip to content

Commit 3b31892

Browse files
committed
Add a test with price > 1 and alpha limiting
1 parent 6084f49 commit 3b31892

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pallets/swap/src/pallet/tests.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2782,6 +2782,20 @@ fn proportional_when_price_is_one_and_alpha_is_excess() {
27822782
assert_eq!(as_tuple(out), (5, 5, 0, 5));
27832783
}
27842784

2785+
#[test]
2786+
fn proportional_with_higher_price_and_alpha_limiting() {
2787+
// Choose sqrt_price = 2.0 => price = 4.0 (since implementation squares it)
2788+
let sqrt = U64F64::from_num(2u64);
2789+
let amount_tao: TaoCurrency = 85u64.into();
2790+
let amount_alpha: AlphaCurrency = 20u64.into();
2791+
2792+
// tao_equivalent = alpha * price = 20 * 4 = 80 < 85 => alpha limits tao
2793+
// remainders: tao 5, alpha 0
2794+
let out =
2795+
Pallet::<Test>::get_proportional_alpha_tao_and_remainders(sqrt, amount_tao, amount_alpha);
2796+
assert_eq!(as_tuple(out), (80, 20, 5, 0));
2797+
}
2798+
27852799
#[test]
27862800
fn proportional_with_higher_price_and_tao_limiting() {
27872801
// Choose sqrt_price = 2.0 => price = 4.0 (since implementation squares it)

0 commit comments

Comments
 (0)