use crate::{
ids::IntentResourceKey, ops::storage::intent::IntentStoreOps,
storage::stable::intent::IntentStore,
};
#[doc(hidden)]
pub(crate) use crate::storage::stable::intent::{
IntentId, IntentPendingEntryRecord, IntentRecord, IntentResourceTotalsRecord,
IntentStoreMetaRecord,
};
pub struct IntentTestOps;
impl IntentTestOps {
#[must_use]
pub fn now() -> u64 {
crate::ops::ic::IcOps::now_secs()
}
pub fn allocate_intent_id() -> Result<IntentId, String> {
IntentStoreOps::allocate_intent_id().map_err(|e| e.to_string())
}
pub fn try_reserve(
intent_id: IntentId,
resource_key: IntentResourceKey,
quantity: u64,
created_at: u64,
ttl_secs: Option<u64>,
now_secs: u64,
) -> Result<IntentRecord, String> {
IntentStoreOps::try_reserve(
intent_id,
resource_key,
quantity,
created_at,
ttl_secs,
now_secs,
)
.map_err(|e| e.to_string())
}
pub fn commit_at(intent_id: IntentId, now: u64) -> Result<IntentRecord, String> {
IntentStoreOps::commit_at(intent_id, now).map_err(|e| e.to_string())
}
pub fn abort(intent_id: IntentId) -> Result<IntentRecord, String> {
IntentStoreOps::abort(intent_id).map_err(|e| e.to_string())
}
#[must_use]
pub fn totals_at(resource_key: &IntentResourceKey, now: u64) -> IntentResourceTotalsRecord {
IntentStoreOps::totals_at(resource_key, now)
}
#[must_use]
pub fn pending_entries_at(now: u64) -> Vec<(IntentId, IntentPendingEntryRecord)> {
IntentStoreOps::pending_entries_at(now)
}
#[must_use]
pub fn expired_pending_ids(now: u64) -> Vec<IntentId> {
IntentStoreOps::list_expired_pending_intents(now)
}
#[must_use]
pub fn meta() -> IntentStoreMetaRecord {
IntentStore::meta()
}
#[must_use]
pub fn record(intent_id: IntentId) -> Option<IntentRecord> {
IntentStore::get_record(intent_id)
}
}