Skip to content

Commit e9ae7e5

Browse files
Use constants for the variables that dont change in the test cases
1 parent ee4cc13 commit e9ae7e5

File tree

1 file changed

+24
-19
lines changed
  • aggregation_mode/proof_aggregator/src/backend

1 file changed

+24
-19
lines changed

aggregation_mode/proof_aggregator/src/backend/mod.rs

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -481,10 +481,15 @@ mod tests {
481481
// Max to spend: 0.000000058 ETH/hour * 24 hours = 0.005 ETH
482482
// Expected cost: 600,000 * 1 Gwei = 0.0006 ETH
483483
// Expected cost < Max to spend, so we can send the proof
484+
485+
const BUDGET_PER_MONTH_IN_ETH: f64 = 0.15;
486+
const ONE_DAY_SECONDS: u64 = 24 * 60 * 60;
487+
let gas_price = U256::from(1_000_000_000u64); // 10 GWEI
488+
484489
assert!(aggregator.should_send_proof_to_verify_on_chain(
485-
Duration::from_secs(24 * 3600), // 24 hours
486-
0.15, // 0.15 ETH monthly budget
487-
U256::from(1_000_000_000u64), // 1 Gwei gas price
490+
Duration::from_secs(ONE_DAY_SECONDS), // 24 hours
491+
BUDGET_PER_MONTH_IN_ETH, // 0.15 ETH monthly budget
492+
gas_price, // 1 Gwei gas price
488493
));
489494

490495
// Case 2: Slightly Increased Gas Price -> should return false
@@ -495,9 +500,9 @@ mod tests {
495500
// Expected cost: 600,000 * 8 Gwei = 0.0048 ETH
496501
// Expected cost < Max to spend, so we can send the proof
497502
assert!(aggregator.should_send_proof_to_verify_on_chain(
498-
Duration::from_secs(24 * 3600), // 24 hours
499-
0.15, // 0.15 ETH monthly budget
500-
U256::from(8_000_000_000u64), // 10 Gwei gas price
503+
Duration::from_secs(ONE_DAY_SECONDS), // 24 hours
504+
BUDGET_PER_MONTH_IN_ETH, // 0.15 ETH monthly budget
505+
U256::from(8_000_000_000u64), // 10 Gwei gas price
501506
));
502507

503508
// Case 3: Increased Gas Price -> should return false
@@ -508,9 +513,9 @@ mod tests {
508513
// Expected cost: 600,000 * 10 Gwei = 0.006 ETH
509514
// Expected cost > Max to spend, so we cannot send the proof
510515
assert!(!aggregator.should_send_proof_to_verify_on_chain(
511-
Duration::from_secs(24 * 3600), // 24 hours
512-
0.15, // 0.15 ETH monthly budget
513-
U256::from(10_000_000_000u64), // 10 Gwei gas price
516+
Duration::from_secs(ONE_DAY_SECONDS), // 24 hours
517+
BUDGET_PER_MONTH_IN_ETH, // 0.15 ETH monthly budget
518+
U256::from(10_000_000_000u64), // 10 Gwei gas price
514519
));
515520

516521
// Case 4: Slightly Reduced Time Elapsed -> should return true
@@ -522,8 +527,8 @@ mod tests {
522527
// Expected cost < Max to spend, so we can send the proof
523528
assert!(aggregator.should_send_proof_to_verify_on_chain(
524529
Duration::from_secs(3 * 3600), // 3 hours
525-
0.15, // 0.15 ETH monthly budget
526-
U256::from(1_000_000_000u64), // 1 Gwei gas price
530+
BUDGET_PER_MONTH_IN_ETH, // 0.15 ETH monthly budget
531+
gas_price, // 1 Gwei gas price
527532
));
528533

529534
// Case 5: Reduced Time Elapsed -> should return false
@@ -535,8 +540,8 @@ mod tests {
535540
// Expected cost > Max to spend, so we cannot send the proof
536541
assert!(!aggregator.should_send_proof_to_verify_on_chain(
537542
Duration::from_secs_f64(1.2 * 3600.0), // 1.2 hours
538-
0.15, // 0.15 ETH monthly budget
539-
U256::from(1_000_000_000u64), // 1 Gwei gas price
543+
BUDGET_PER_MONTH_IN_ETH, // 0.15 ETH monthly budget
544+
gas_price, // 1 Gwei gas price
540545
));
541546

542547
// Case 6: Slightly Reduced Monthly Budget -> should return true
@@ -547,9 +552,9 @@ mod tests {
547552
// Expected cost: 600,000 * 1 Gwei = 0.0006 ETH
548553
// Expected cost < Max to spend, so we can send the proof
549554
assert!(aggregator.should_send_proof_to_verify_on_chain(
550-
Duration::from_secs(24 * 3600), // 24 hours
551-
0.1, // 0.1 ETH monthly budget
552-
U256::from(1_000_000_000u64), // 1 Gwei gas price
555+
Duration::from_secs(ONE_DAY_SECONDS), // 24 hours
556+
0.1, // 0.1 ETH monthly budget
557+
gas_price, // 1 Gwei gas price
553558
));
554559

555560
// Case 7: Decreased Monthly Budget -> should return false
@@ -560,9 +565,9 @@ mod tests {
560565
// Expected cost: 600,000 * 1 Gwei = 0.0006 ETH
561566
// Expected cost > Max to spend, so we cannot send the proof
562567
assert!(!aggregator.should_send_proof_to_verify_on_chain(
563-
Duration::from_secs(24 * 3600), // 24 hours
564-
0.01, // 0.01 ETH monthly budget
565-
U256::from(1_000_000_000u64), // 1 Gwei gas price
568+
Duration::from_secs(ONE_DAY_SECONDS), // 24 hours
569+
0.01, // 0.01 ETH monthly budget
570+
gas_price, // 1 Gwei gas price
566571
));
567572
}
568573
}

0 commit comments

Comments
 (0)