Skip to content

Commit d9595c0

Browse files
Add more test cases
1 parent b8d32ee commit d9595c0

File tree

1 file changed

+33
-6
lines changed
  • aggregation_mode/src/backend

1 file changed

+33
-6
lines changed

aggregation_mode/src/backend/mod.rs

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,13 @@ impl ProofAggregator {
208208
monthly_eth_budget: f64,
209209
gas_price_in_wei: U256,
210210
) -> bool {
211+
// We assume a fixed gas cost of 300,000 for each of the 2 transactions
211212
const ON_CHAIN_COST_IN_GAS_UNITS: u64 = 600_000u64;
212213

213214
let on_chain_cost_in_gas: U256 = U256::from(ON_CHAIN_COST_IN_GAS_UNITS);
214215
let max_to_spend_in_wei = Self::max_to_spend_in_wei(time_elapsed, monthly_eth_budget);
215216

216-
let expected_cost_in_wei = gas_price_in_wei * on_chain_cost_in_gas; // assuming 300,000 gas units per transaction
217+
let expected_cost_in_wei = gas_price_in_wei * on_chain_cost_in_gas;
217218

218219
expected_cost_in_wei <= max_to_spend_in_wei
219220
}
@@ -400,41 +401,67 @@ mod tests {
400401

401402
let gas_price_20gwei: U256 = U256::from(20_000_000_000u64);
402403

404+
// With 0 seconds elapsed and 1 ETH budget, we cannot send the proof
403405
assert!(!aggregator.should_send_proof_to_verify_on_chain(
404-
Duration::from_secs(24 * 60 * 60), // 1 day
406+
Duration::from_secs(0),
405407
1.0,
406408
gas_price_20gwei,
407409
));
408410

411+
// After 24 hours and 1 ETH monthly budget, we can send the proof
409412
assert!(aggregator.should_send_proof_to_verify_on_chain(
410413
Duration::from_secs(24 * 3600),
411414
1.0,
412415
gas_price_20gwei,
413416
));
414417

418+
// After 24 hours and a very low budget, we cannot send the proof
419+
assert!(!aggregator.should_send_proof_to_verify_on_chain(
420+
Duration::from_secs(24 * 3600),
421+
0.00325,
422+
U256::from(0_200_000_000u64),
423+
));
424+
425+
// After 27 hours with the same budget as before, we can send the proof
426+
assert!(aggregator.should_send_proof_to_verify_on_chain(
427+
Duration::from_secs(27 * 3600),
428+
0.00325,
429+
U256::from(0_200_000_000u64),
430+
));
431+
432+
// After 30 days but with a very low budget, we cannot send the proof
415433
assert!(!aggregator.should_send_proof_to_verify_on_chain(
416434
Duration::from_secs(30 * 24 * 3600),
417435
0.001,
418436
gas_price_20gwei,
419437
));
420438

421-
let gas_price_high: U256 = U256::from(2_000_000_000_000u64); // 2e12 wei (~2,000 gwei)
422-
assert!(!aggregator.should_send_proof_to_verify_on_chain(
439+
// After 15 days, a moderate budget and a high gas price, we can still send the proof
440+
assert!(aggregator.should_send_proof_to_verify_on_chain(
423441
Duration::from_secs(15 * 24 * 3600),
424442
10.0,
425-
gas_price_high,
443+
U256::from(2_000_000_000_000u64),
426444
));
427445

428-
assert!(aggregator.should_send_proof_to_verify_on_chain(
446+
// After 30 days and a medium budget, we cannot send the proof
447+
assert!(!aggregator.should_send_proof_to_verify_on_chain(
429448
Duration::from_secs(30 * 24 * 3600),
430449
0.012,
431450
gas_price_20gwei,
432451
));
433452

453+
// After 2 days and a reasonable budget, we can send the proof
434454
assert!(aggregator.should_send_proof_to_verify_on_chain(
435455
Duration::from_secs(2 * 24 * 3600),
436456
5.0,
437457
gas_price_20gwei,
438458
));
459+
460+
// After 10 days and a medium budget with a very high gas price, we cannot send the proof
461+
assert!(!aggregator.should_send_proof_to_verify_on_chain(
462+
Duration::from_secs(10 * 24 * 3600),
463+
2.0,
464+
U256::from(100_000_000_000_000u64),
465+
));
439466
}
440467
}

0 commit comments

Comments
 (0)