use crate::ids::CanisterRole;
use serde::{Deserialize, Serialize};
const IMPLICIT_WASM_STORE_ROLE: CanisterRole = CanisterRole::WASM_STORE;
#[cfg(canic_test_small_wasm_store)]
const IMPLICIT_WASM_STORE_MAX_STORE_BYTES: u64 = 8_000_000;
#[cfg(not(canic_test_small_wasm_store))]
const IMPLICIT_WASM_STORE_MAX_STORE_BYTES: u64 = 40_000_000;
#[cfg(canic_test_small_wasm_store)]
const IMPLICIT_WASM_STORE_HEADROOM_BYTES: u64 = 1_000_000;
#[cfg(not(canic_test_small_wasm_store))]
const IMPLICIT_WASM_STORE_HEADROOM_BYTES: u64 = 4_000_000;
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
pub struct WasmStoreConfig {
pub canister_role: CanisterRole,
#[serde(default)]
pub policy: WasmStorePolicy,
}
impl WasmStoreConfig {
#[must_use]
#[allow(clippy::missing_const_for_fn)]
pub fn implicit() -> Self {
Self {
canister_role: IMPLICIT_WASM_STORE_ROLE,
policy: WasmStorePolicy {
max_store_bytes: IMPLICIT_WASM_STORE_MAX_STORE_BYTES,
headroom_bytes: Some(IMPLICIT_WASM_STORE_HEADROOM_BYTES),
max_templates: None,
max_template_versions_per_template: None,
},
}
}
#[must_use]
pub const fn max_store_bytes(&self) -> u64 {
self.policy.max_store_bytes
}
#[must_use]
pub const fn max_templates(&self) -> Option<u32> {
self.policy.max_templates
}
#[must_use]
pub const fn headroom_bytes(&self) -> Option<u64> {
self.policy.headroom_bytes
}
#[must_use]
pub const fn max_template_versions_per_template(&self) -> Option<u16> {
self.policy.max_template_versions_per_template
}
}
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
pub struct WasmStorePolicy {
pub max_store_bytes: u64,
#[serde(default)]
pub headroom_bytes: Option<u64>,
#[serde(default)]
pub max_templates: Option<u32>,
#[serde(default)]
pub max_template_versions_per_template: Option<u16>,
}
#[cfg(test)]
mod tests {
use super::WasmStoreConfig;
use crate::ids::CanisterRole;
#[test]
fn wasm_store_policy_is_the_implicit_ic_preset() {
let store = WasmStoreConfig::implicit();
assert_eq!(store.canister_role, CanisterRole::WASM_STORE);
assert_eq!(store.max_store_bytes(), 40_000_000);
assert_eq!(store.headroom_bytes(), Some(4_000_000));
assert_eq!(store.max_templates(), None);
assert_eq!(store.max_template_versions_per_template(), None);
}
}