Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
moodysalem committed Oct 23, 2024
1 parent 0f79eda commit e25ff79
Showing 1 changed file with 120 additions and 37 deletions.
157 changes: 120 additions & 37 deletions src/quoting/twamm_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,11 @@ mod tests {
0,
0,
1 << 32,
vec![],
vec![TwammSaleRateDelta {
time: u64::MAX,
sale_rate_delta0: 0,
sale_rate_delta1: -(1 << 32),
}],
);

let result = pool.quote(QuoteParams {
Expand Down Expand Up @@ -707,7 +711,11 @@ mod tests {
0,
1 << 32,
0,
vec![],
vec![TwammSaleRateDelta {
time: u64::MAX,
sale_rate_delta0: -(1 << 32),
sale_rate_delta1: 0,
}],
);

let result = pool.quote(QuoteParams {
Expand Down Expand Up @@ -745,7 +753,11 @@ mod tests {
0,
0,
1 << 32,
vec![],
vec![TwammSaleRateDelta {
time: u64::MAX,
sale_rate_delta0: 0,
sale_rate_delta1: -(1 << 32),
}],
);

let result = pool.quote(QuoteParams {
Expand Down Expand Up @@ -782,11 +794,18 @@ mod tests {
0,
0,
1 << 32,
vec![TwammSaleRateDelta {
sale_rate_delta0: 100_000i128 * (1 << 32),
sale_rate_delta1: 0,
time: 16u64,
}],
vec![
TwammSaleRateDelta {
sale_rate_delta0: 100_000i128 * (1 << 32),
sale_rate_delta1: 0,
time: 16u64,
},
TwammSaleRateDelta {
time: u64::MAX,
sale_rate_delta0: -100_000 * (1 << 32),
sale_rate_delta1: -(1 << 32),
},
],
);

let quote = pool
Expand Down Expand Up @@ -828,11 +847,18 @@ mod tests {
0u64,
1 << 32,
0u128,
vec![TwammSaleRateDelta {
sale_rate_delta0: 0i128,
sale_rate_delta1: 100_000 * (1 << 32),
time: 16u64,
}],
vec![
TwammSaleRateDelta {
sale_rate_delta0: 0i128,
sale_rate_delta1: 100_000 * (1 << 32),
time: 16u64,
},
TwammSaleRateDelta {
time: u64::MAX,
sale_rate_delta0: -(1 << 32),
sale_rate_delta1: -100_000 * (1 << 32),
},
],
);

let result = pool.quote(QuoteParams {
Expand Down Expand Up @@ -874,11 +900,18 @@ mod tests {
0,
0,
1 << 32,
vec![TwammSaleRateDelta {
sale_rate_delta0: 100_000 * (1 << 32),
sale_rate_delta1: 0,
time: 16,
}],
vec![
TwammSaleRateDelta {
sale_rate_delta0: 100_000 * (1 << 32),
sale_rate_delta1: 0,
time: 16,
},
TwammSaleRateDelta {
time: u64::MAX,
sale_rate_delta0: -100_000 * (1 << 32),
sale_rate_delta1: -(1 << 32),
},
],
);

let quote = pool
Expand Down Expand Up @@ -920,11 +953,18 @@ mod tests {
0,
1 << 32,
0,
vec![TwammSaleRateDelta {
sale_rate_delta0: 0i128,
sale_rate_delta1: (100_000u128 * (1 << 32)) as i128,
time: 16u64,
}],
vec![
TwammSaleRateDelta {
sale_rate_delta0: 0i128,
sale_rate_delta1: (100_000u128 * (1 << 32)) as i128,
time: 16u64,
},
TwammSaleRateDelta {
time: u64::MAX,
sale_rate_delta0: -(1 << 32),
sale_rate_delta1: -100_000 * (1 << 32),
},
],
);

let result = pool.quote(QuoteParams {
Expand Down Expand Up @@ -966,7 +1006,11 @@ mod tests {
0u64,
1 << 32u128,
1 << 32u128,
vec![], // No sale rate deltas
vec![TwammSaleRateDelta {
time: u64::MAX,
sale_rate_delta0: -(1 << 32),
sale_rate_delta1: -(1 << 32),
}], // No sale rate deltas
);

let result = pool.quote(QuoteParams {
Expand Down Expand Up @@ -1008,7 +1052,11 @@ mod tests {
0u64,
1 << 32u128,
1 << 32u128,
vec![], // No sale rate deltas
vec![TwammSaleRateDelta {
time: u64::MAX,
sale_rate_delta0: -(1 << 32),
sale_rate_delta1: -(1 << 32),
}], // No sale rate deltas
);

let result = pool.quote(QuoteParams {
Expand Down Expand Up @@ -1050,7 +1098,11 @@ mod tests {
0u64,
10 << 32u128,
1 << 32u128,
vec![], // No sale rate deltas
vec![TwammSaleRateDelta {
time: u64::MAX,
sale_rate_delta0: -(10 << 32),
sale_rate_delta1: -(1 << 32),
}], // No sale rate deltas
);

let result = pool.quote(QuoteParams {
Expand Down Expand Up @@ -1092,7 +1144,11 @@ mod tests {
0u64,
1 << 32u128,
10 << 32u128,
vec![], // No sale rate deltas
vec![TwammSaleRateDelta {
time: u64::MAX,
sale_rate_delta0: -(1 << 32),
sale_rate_delta1: -(10 << 32),
}], // No sale rate deltas
);

let result = pool.quote(QuoteParams {
Expand Down Expand Up @@ -1134,7 +1190,11 @@ mod tests {
0u64,
10 << 32u128,
1 << 32u128,
vec![], // No sale rate deltas
vec![TwammSaleRateDelta {
time: u64::MAX,
sale_rate_delta0: -(10 << 32),
sale_rate_delta1: -(1 << 32),
}], // No sale rate deltas
);

let result = pool.quote(QuoteParams {
Expand Down Expand Up @@ -1176,7 +1236,11 @@ mod tests {
0u64,
1 << 32u128,
10 << 32u128,
vec![], // No sale rate deltas
vec![TwammSaleRateDelta {
time: u64::MAX,
sale_rate_delta0: -(1 << 32),
sale_rate_delta1: -(10 << 32),
}], // No sale rate deltas
);

let result = pool.quote(QuoteParams {
Expand Down Expand Up @@ -1264,11 +1328,18 @@ mod tests {
0u64,
1 << 32u128,
1 << 32u128,
vec![TwammSaleRateDelta {
sale_rate_delta0: 2i128.pow(32),
sale_rate_delta1: 2i128.pow(32),
time: 16u64,
}],
vec![
TwammSaleRateDelta {
sale_rate_delta0: 2i128.pow(32),
sale_rate_delta1: 2i128.pow(32),
time: 16u64,
},
TwammSaleRateDelta {
time: u64::MAX,
sale_rate_delta0: -(1 << 33),
sale_rate_delta1: -(1 << 33),
},
],
);

let result = pool.quote(QuoteParams {
Expand Down Expand Up @@ -1310,7 +1381,11 @@ mod tests {
0,
10_526_880_627_450_980_392_156_862_745,
10_526_880_627_450_980_392_156_862_745,
vec![],
vec![TwammSaleRateDelta {
time: u64::MAX,
sale_rate_delta0: -10_526_880_627_450_980_392_156_862_745,
sale_rate_delta1: -10_526_880_627_450_980_392_156_862_745,
}],
);

// First quote: no swap
Expand Down Expand Up @@ -1477,7 +1552,11 @@ mod tests {
0,
10_526_880_627_450_980_392_156_862_745,
10_526_880_627_450_980_392_156_862_745,
vec![],
vec![TwammSaleRateDelta {
time: u64::MAX,
sale_rate_delta0: -10_526_880_627_450_980_392_156_862_745,
sale_rate_delta1: -10_526_880_627_450_980_392_156_862_745,
}],
);

// First swap
Expand Down Expand Up @@ -1549,7 +1628,11 @@ mod tests {
0,
10_526_880_627_450_980_392_156_862_745,
10_526_880_627_450_980_392_156_862_745,
vec![],
vec![TwammSaleRateDelta {
time: u64::MAX,
sale_rate_delta0: -10_526_880_627_450_980_392_156_862_745,
sale_rate_delta1: -10_526_880_627_450_980_392_156_862_745,
}],
);

// First swap
Expand Down

0 comments on commit e25ff79

Please sign in to comment.