read_storage panics (#3589)

* Add a failing test case

* Actual fix

* read_child_storage, fix wasm side

* Bump the impl version.

* Alternative (#3597)

* Update with_std.rs

* Update with_std.rs

* Update wasm_executor.rs

* Update wasm_executor.rs

* Update with_std.rs

* Update wasm_executor.rs
This commit is contained in:
Sergei Pepyakin
2019-09-11 19:37:19 +02:00
committed by Gavin Wood
parent d136b8eb81
commit 098d880cf9
4 changed files with 79 additions and 14 deletions
+65
View File
@@ -280,6 +280,8 @@ cfg_if! {
///
/// Returns the signature generated for the message `sr25519`.
fn test_sr25519_crypto() -> (sr25519::AppSignature, sr25519::AppPublic);
/// Run various tests against storage.
fn test_storage();
}
}
} else {
@@ -322,6 +324,8 @@ cfg_if! {
///
/// Returns the signature generated for the message `sr25519`.
fn test_sr25519_crypto() -> (sr25519::AppSignature, sr25519::AppPublic);
/// Run various tests against storage.
fn test_storage();
}
}
}
@@ -590,6 +594,11 @@ cfg_if! {
fn test_sr25519_crypto() -> (sr25519::AppSignature, sr25519::AppPublic) {
test_sr25519_crypto()
}
fn test_storage() {
test_read_storage();
test_read_child_storage();
}
}
impl aura_primitives::AuraApi<Block, AuraId> for Runtime {
@@ -805,6 +814,11 @@ cfg_if! {
fn test_sr25519_crypto() -> (sr25519::AppSignature, sr25519::AppPublic) {
test_sr25519_crypto()
}
fn test_storage() {
test_read_storage();
test_read_child_storage();
}
}
impl aura_primitives::AuraApi<Block, AuraId> for Runtime {
@@ -887,6 +901,46 @@ fn test_sr25519_crypto() -> (sr25519::AppSignature, sr25519::AppPublic) {
(signature, public0)
}
fn test_read_storage() {
const KEY: &[u8] = b":read_storage";
runtime_io::set_storage(KEY, b"test");
let mut v = [0u8; 4];
let r = runtime_io::read_storage(
KEY,
&mut v,
0
);
assert_eq!(r, Some(4));
assert_eq!(&v, b"test");
let mut v = [0u8; 4];
let r = runtime_io::read_storage(KEY, &mut v, 8);
assert_eq!(r, Some(4));
assert_eq!(&v, &[0, 0, 0, 0]);
}
fn test_read_child_storage() {
const CHILD_KEY: &[u8] = b":child_storage:default:read_child_storage";
const KEY: &[u8] = b":read_child_storage";
runtime_io::set_child_storage(CHILD_KEY, KEY, b"test");
let mut v = [0u8; 4];
let r = runtime_io::read_child_storage(
CHILD_KEY,
KEY,
&mut v,
0
);
assert_eq!(r, Some(4));
assert_eq!(&v, b"test");
let mut v = [0u8; 4];
let r = runtime_io::read_child_storage(CHILD_KEY, KEY, &mut v, 8);
assert_eq!(r, Some(4));
assert_eq!(&v, &[0, 0, 0, 0]);
}
#[cfg(test)]
mod tests {
use substrate_test_runtime_client::{
@@ -981,4 +1035,15 @@ mod tests {
let ret = runtime_api.vec_with_capacity(&new_block_id, 1048576);
assert!(ret.is_ok());
}
#[test]
fn test_storage() {
let client = TestClientBuilder::new()
.set_execution_strategy(ExecutionStrategy::Both)
.build();
let runtime_api = client.runtime_api();
let block_id = BlockId::Number(client.info().chain.best_number);
runtime_api.test_storage(&block_id).unwrap();
}
}