Commit ae34aeb1 authored by Andrew Jones's avatar Andrew Jones

Implement test env accessor for chain storage

parent a3ad0f9c
Pipeline #69611 failed with stages
in 16 minutes and 44 seconds
......@@ -509,11 +509,21 @@ where
println!("{}", content)
}
fn get_runtime_storage<I, R>(_buffer: &mut I, _key: &[u8]) -> Result<R>
fn get_runtime_storage<I, R>(_buffer: &mut I, key: &[u8]) -> Result<R>
where
I: AsMut<[u8]> + EnlargeTo,
R: scale::Decode,
{
unimplemented!()
INSTANCE.with(|instance| {
let storage = &instance.borrow().state.storage;
// raw runtime storage keys can be of any length, so hash to fit 32 byte Key size
let key = Key(ink_utils::hash::keccak256(key));
let encoded = storage
.read(key)
.map(|entry| entry.data())
.ok_or(Error::InvalidStorageRead)?;
Ok(scale::Decode::decode(&mut &encoded[..])
.map_err(|_| Error::InvalidStorageRead)?)
})
}
}
......@@ -61,14 +61,15 @@ mod runtime {
}
}
// #[cfg(all(test))]
// mod tests {
// use super::*;
//
// #[test]
// fn it_works() {
// let contract = RuntimeStorage::new();
// assert_eq!(contract.get_balance(), false);
// }
// }
#[cfg(all(test))]
mod tests {
use super::*;
#[test]
fn non_existent_account_returns_zero() {
let contract = RuntimeStorage::new();
let account: AccountId = [0u8; 32].into();
assert_eq!(contract.get_balance(account), 0);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment