Add sha2-256 hash function (#4218)

* Add sha2-256 hash function

Widely used hash function, supported by bitcoin and ethereum

* Add runtime io support

* add test

* add test

* Update hashing.rs

* Update hashing.rs
This commit is contained in:
Weiliang Li
2019-11-28 02:32:35 +09:00
committed by Gavin Wood
parent f8bf17dc49
commit dcaabbaacf
4 changed files with 57 additions and 2 deletions
@@ -230,6 +230,42 @@ fn blake2_128_should_work(wasm_method: WasmExecutionMethod) {
);
}
#[test_case(WasmExecutionMethod::Interpreted)]
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
fn sha2_256_should_work(wasm_method: WasmExecutionMethod) {
let mut ext = TestExternalities::default();
let mut ext = ext.ext();
let test_code = WASM_BINARY;
assert_eq!(
call_in_wasm(
"test_sha2_256",
&[0],
wasm_method,
&mut ext,
&test_code[..],
8,
)
.unwrap(),
hex!("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")
.to_vec()
.encode(),
);
assert_eq!(
call_in_wasm(
"test_sha2_256",
&b"Hello world!".to_vec().encode(),
wasm_method,
&mut ext,
&test_code[..],
8,
)
.unwrap(),
hex!("c0535e4be2b79ffd93291305436bf889314e4a3faec05ecffcbb7df31ad9e51a")
.to_vec()
.encode(),
);
}
#[test_case(WasmExecutionMethod::Interpreted)]
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
fn twox_256_should_work(wasm_method: WasmExecutionMethod) {