| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
pub const STORAGE_RATE_CENTS_PER_GB: i64 = 3; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
pub const MAX_STORAGE_GB: i64 = 10 * 1024; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
pub const BASE_FLOOR_CENTS: i64 = 31; |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
pub const WARNING_THRESHOLDS_PCT: &[i16] = &[75, 90, 100]; |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
pub fn monthly_price_cents( |
| 53 |
enforcement_mode: crate::db::SyncEnforcementMode, |
| 54 |
storage_gb_cap: Option<u32>, |
| 55 |
key_cap: Option<u32>, |
| 56 |
gb_per_key: Option<u32>, |
| 57 |
) -> i64 { |
| 58 |
use crate::db::SyncEnforcementMode::{Bulk, PerKey}; |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
let gb: i64 = match enforcement_mode { |
| 68 |
Bulk => i64::from(storage_gb_cap.unwrap_or(0)), |
| 69 |
PerKey => { |
| 70 |
let k = i64::from(key_cap.unwrap_or(0)); |
| 71 |
let g = i64::from(gb_per_key.unwrap_or(0)); |
| 72 |
k.saturating_mul(g) |
| 73 |
} |
| 74 |
}; |
| 75 |
let raw = gb.saturating_mul(STORAGE_RATE_CENTS_PER_GB); |
| 76 |
raw.max(BASE_FLOOR_CENTS) |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
pub fn storage_cap_bytes(storage_gb: u32) -> i64 { |
| 81 |
i64::from(storage_gb) * 1024 * 1024 * 1024 |
| 82 |
} |
| 83 |
|
| 84 |
#[cfg(test)] |
| 85 |
mod tests { |
| 86 |
use super::*; |
| 87 |
use crate::db::SyncEnforcementMode::{Bulk, PerKey}; |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
#[test] |
| 94 |
fn developer_storage_ceiling_matches_the_end_user_one() { |
| 95 |
assert_eq!(MAX_STORAGE_GB, 10 * 1024, "10 TiB, in GiB"); |
| 96 |
assert_eq!( |
| 97 |
MAX_STORAGE_GB * 1024 * 1024 * 1024, |
| 98 |
crate::payments::synckit_app_pricing::MAX_CAP_BYTES, |
| 99 |
); |
| 100 |
} |
| 101 |
|
| 102 |
#[test] |
| 103 |
fn bulk_mode_pricing() { |
| 104 |
|
| 105 |
assert_eq!(monthly_price_cents(Bulk, Some(100), None, None), 300); |
| 106 |
|
| 107 |
assert_eq!(monthly_price_cents(Bulk, Some(1000), None, None), 3000); |
| 108 |
} |
| 109 |
|
| 110 |
#[test] |
| 111 |
fn per_key_mode_pricing() { |
| 112 |
|
| 113 |
assert_eq!(monthly_price_cents(PerKey, None, Some(50), Some(2)), 300); |
| 114 |
|
| 115 |
assert_eq!(monthly_price_cents(PerKey, None, Some(1000), Some(1)), 3000); |
| 116 |
} |
| 117 |
|
| 118 |
#[test] |
| 119 |
fn floor_kicks_in_for_small_accounts() { |
| 120 |
|
| 121 |
assert_eq!(monthly_price_cents(Bulk, Some(1), None, None), 31); |
| 122 |
|
| 123 |
assert_eq!(monthly_price_cents(Bulk, Some(10), None, None), 31); |
| 124 |
|
| 125 |
assert_eq!(monthly_price_cents(Bulk, Some(11), None, None), 33); |
| 126 |
|
| 127 |
assert_eq!(monthly_price_cents(PerKey, None, Some(1), Some(1)), 31); |
| 128 |
} |
| 129 |
|
| 130 |
#[test] |
| 131 |
fn heavy_workload_pricing() { |
| 132 |
|
| 133 |
assert_eq!(monthly_price_cents(Bulk, Some(10_240), None, None), 30_720); |
| 134 |
|
| 135 |
assert_eq!( |
| 136 |
monthly_price_cents(PerKey, None, Some(10_000), Some(1)), |
| 137 |
30_000 |
| 138 |
); |
| 139 |
} |
| 140 |
|
| 141 |
#[test] |
| 142 |
fn missing_knobs_drop_to_floor() { |
| 143 |
|
| 144 |
assert_eq!( |
| 145 |
monthly_price_cents(Bulk, None, None, None), |
| 146 |
BASE_FLOOR_CENTS |
| 147 |
); |
| 148 |
assert_eq!( |
| 149 |
monthly_price_cents(PerKey, None, None, None), |
| 150 |
BASE_FLOOR_CENTS |
| 151 |
); |
| 152 |
} |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
#[test] |
| 159 |
fn floor_amount_covers_stripe_fee() { |
| 160 |
|
| 161 |
|
| 162 |
let net = (BASE_FLOOR_CENTS as f64) * 0.971 - 30.0; |
| 163 |
assert!( |
| 164 |
net >= 0.0, |
| 165 |
"floor must net ≥ 0 after Stripe fees, got {net}" |
| 166 |
); |
| 167 |
assert!(net < 1.0, "floor should be tight, not overshoot, got {net}"); |
| 168 |
} |
| 169 |
|
| 170 |
#[test] |
| 171 |
fn storage_cap_in_bytes() { |
| 172 |
assert_eq!(storage_cap_bytes(10), 10 * 1024 * 1024 * 1024); |
| 173 |
} |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
#[test] |
| 178 |
fn pricing_at_u32_max_does_not_panic() { |
| 179 |
|
| 180 |
let p = monthly_price_cents(Bulk, Some(u32::MAX), None, None); |
| 181 |
assert!(p > 0, "huge price should be positive, got {p}"); |
| 182 |
} |
| 183 |
|
| 184 |
#[test] |
| 185 |
fn per_key_pricing_at_u32_max_saturates_cleanly() { |
| 186 |
|
| 187 |
|
| 188 |
let p = monthly_price_cents(PerKey, None, Some(u32::MAX), Some(u32::MAX)); |
| 189 |
assert!(p > 0, "saturated price should still be positive, got {p}"); |
| 190 |
} |
| 191 |
|
| 192 |
#[test] |
| 193 |
fn storage_cap_at_u32_max_fits_in_i64() { |
| 194 |
|
| 195 |
let bytes = storage_cap_bytes(u32::MAX); |
| 196 |
assert!(bytes > 0, "u32::MAX GB should produce a positive i64"); |
| 197 |
assert_eq!(bytes, (u32::MAX as i64) * 1024 * 1024 * 1024); |
| 198 |
} |
| 199 |
|
| 200 |
#[test] |
| 201 |
fn bulk_with_zero_gb_drops_to_floor() { |
| 202 |
|
| 203 |
|
| 204 |
assert_eq!( |
| 205 |
monthly_price_cents(Bulk, Some(0), None, None), |
| 206 |
BASE_FLOOR_CENTS |
| 207 |
); |
| 208 |
} |
| 209 |
|
| 210 |
#[test] |
| 211 |
fn per_key_one_dimension_zero_drops_to_floor() { |
| 212 |
|
| 213 |
assert_eq!( |
| 214 |
monthly_price_cents(PerKey, None, Some(0), Some(10)), |
| 215 |
BASE_FLOOR_CENTS |
| 216 |
); |
| 217 |
assert_eq!( |
| 218 |
monthly_price_cents(PerKey, None, Some(10), Some(0)), |
| 219 |
BASE_FLOOR_CENTS |
| 220 |
); |
| 221 |
} |
| 222 |
} |
| 223 |
|