use super::*;
use assert_matches::assert_matches;
use tet_core::{Bytes, offchain::storage::InMemOffchainStorage};
#[test]
fn local_storage_should_work() {
let storage = InMemOffchainStorage::default();
let offchain = Offchain::new(storage, DenyUnsafe::No);
let key = Bytes(b"offchain_storage".to_vec());
let value = Bytes(b"offchain_value".to_vec());
assert_matches!(
offchain.set_local_storage(StorageKind::PERSISTENT, key.clone(), value.clone()),
Ok(())
);
assert_matches!(
offchain.get_local_storage(StorageKind::PERSISTENT, key),
Ok(Some(ref v)) if *v == value
);
}
#[test]
fn offchain_calls_considered_unsafe() {
let storage = InMemOffchainStorage::default();
let offchain = Offchain::new(storage, DenyUnsafe::Yes);
let key = Bytes(b"offchain_storage".to_vec());
let value = Bytes(b"offchain_value".to_vec());
assert_matches!(
offchain.set_local_storage(StorageKind::PERSISTENT, key.clone(), value.clone()),
Err(Error::UnsafeRpcCalled(_))
);
assert_matches!(
offchain.get_local_storage(StorageKind::PERSISTENT, key),
Err(Error::UnsafeRpcCalled(_))
);
}