soroban_sdk/testutils/
storage.rs

1use crate::{Env, IntoVal, Map, Val};
2
3/// Test utilities for [`Persistent`][crate::storage::Persistent].
4pub trait Persistent {
5    /// Returns all data stored in persistent storage for the contract.
6    fn all(&self) -> Map<Val, Val>;
7
8    /// Gets the TTL for the persistent storage entry corresponding to the provided key.
9    ///
10    /// TTL is the number of ledgers left until the persistent entry is considered
11    /// expired, excluding the current ledger.
12    ///
13    /// Panics if there is no entry corresponding to the key, or if the entry has expired.
14    fn get_ttl<K: IntoVal<Env, Val>>(&self, key: &K) -> u32;
15}
16
17/// Test utilities for [`Temporary`][crate::storage::Temporary].
18pub trait Temporary {
19    /// Returns all data stored in temporary storage for the contract.
20    fn all(&self) -> Map<Val, Val>;
21
22    /// Gets the TTL for the temporary storage entry corresponding to the provided key.
23    ///
24    /// TTL is the number of ledgers left until the temporary entry is considered
25    /// non-existent, excluding the current ledger.
26    ///
27    /// Panics if there is no entry corresponding to the key.
28    fn get_ttl<K: IntoVal<Env, Val>>(&self, key: &K) -> u32;
29}
30
31/// Test utilities for [`Instance`][crate::storage::Instance].
32pub trait Instance {
33    /// Returns all data stored in Instance storage for the contract.
34    fn all(&self) -> Map<Val, Val>;
35
36    /// Gets the TTL for the current contract's instance entry.
37    ///
38    /// TTL is the number of ledgers left until the instance entry is considered
39    /// expired, excluding the current ledger.
40    fn get_ttl(&self) -> u32;
41}