Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test for wasm_executor
  • Loading branch information
pepyakin committed Jul 3, 2018
commit d14da71ecca4e3113c7227aba3676cf0f1efa63c
23 changes: 23 additions & 0 deletions substrate/executor/src/wasm_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,29 @@ mod tests {
assert_eq!(expected, ext);
}

#[test]
fn clear_prefix_should_work() {
let mut ext = TestExternalities::default();
ext.set_storage(b"aaa".to_vec(), b"1".to_vec());
ext.set_storage(b"aab".to_vec(), b"2".to_vec());
ext.set_storage(b"aba".to_vec(), b"3".to_vec());
ext.set_storage(b"abb".to_vec(), b"4".to_vec());
ext.set_storage(b"bbb".to_vec(), b"5".to_vec());
let test_code = include_bytes!("../wasm/target/wasm32-unknown-unknown/release/runtime_test.compact.wasm");

// This will clear all entries which prefix is "ab".
let output = WasmExecutor.call(&mut ext, &test_code[..], "test_clear_prefix", b"ab").unwrap();

assert_eq!(output, b"all ok!".to_vec());

let expected: HashMap<_, _> = map![
b"aaa".to_vec() => b"1".to_vec(),
b"aab".to_vec() => b"2".to_vec(),
b"bbb".to_vec() => b"5".to_vec()
];
assert_eq!(expected, ext);
}

#[test]
fn blake2_256_should_work() {
let mut ext = TestExternalities::default();
Expand Down
6 changes: 5 additions & 1 deletion substrate/executor/wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extern crate substrate_runtime_io as runtime_io;
extern crate substrate_runtime_sandbox as sandbox;

use runtime_io::{
set_storage, storage, print, blake2_256,
set_storage, storage, clear_prefix, print, blake2_256,
twox_128, twox_256, ed25519_verify, enumerated_trie_root
};

Expand All @@ -29,6 +29,10 @@ impl_stubs!(
print("finished!");
b"all ok!".to_vec()
},
test_clear_prefix NO_DECODE => |input| {
clear_prefix(input);
b"all ok!".to_vec()
},
test_empty_return NO_DECODE => |_| Vec::new(),
test_panic NO_DECODE => |_| panic!("test panic"),
test_conditional_panic NO_DECODE => |input: &[u8]| {
Expand Down