Skip to content

Commit c00fa4b

Browse files
committed
chore: calc prog size deviation via percentage
1 parent 1cacaf8 commit c00fa4b

File tree

1 file changed

+12
-10
lines changed
  • magicblock-chainlink/src/testing

1 file changed

+12
-10
lines changed

magicblock-chainlink/src/testing/mod.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -317,12 +317,7 @@ macro_rules! assert_loaded_program_with_size {
317317
$loader,
318318
$loader_status
319319
);
320-
// Program size may vary a bit
321-
// especially across differnt solana versions + OSes
322-
const DEVIATION: usize = 500;
323-
let actual_size = loaded_program.program_data.len();
324-
let min = $size - DEVIATION;
325-
let max = $size + DEVIATION;
320+
let (min, max) = $crate::min_max_with_deviation_percent($size, 5.0);
326321
assert!(
327322
actual_size >= min && actual_size <= max,
328323
"Expected program {} to have size around {}, got {}",
@@ -339,10 +334,7 @@ macro_rules! assert_data_has_size {
339334
($data:expr, $size:expr) => {{
340335
// Program size may vary a bit
341336
// especially across differnt solana versions + OSes
342-
const DEVIATION: usize = 500;
343-
let actual_size = $data.len();
344-
let min = $size - DEVIATION;
345-
let max = $size + DEVIATION;
337+
let (min, max) = $crate::min_max_with_deviation_percent($size, 5.0);
346338
assert!(
347339
actual_size >= min && actual_size <= max,
348340
"Expected data to have size around {}, got {}",
@@ -352,6 +344,16 @@ macro_rules! assert_data_has_size {
352344
}};
353345
}
354346

347+
#[allow(unused)]
348+
fn min_max_with_deviation_percent(size: usize, percent: f64) -> (usize, usize) {
349+
// Program size may vary a bit
350+
// especially across differnt solana versions + OSes
351+
let deviation = (size as f64 * percent / 100.0).ceil() as usize;
352+
let min = size.saturating_sub(deviation);
353+
let max = size + deviation;
354+
(min, max)
355+
}
356+
355357
#[macro_export]
356358
macro_rules! assert_loaded_program_with_min_size {
357359
($cloner:expr, $program_id:expr, $auth:expr, $loader:expr, $loader_status:expr, $size:expr) => {{

0 commit comments

Comments
 (0)