Merge pull request #6177 from paritytech/wasm-realloc-test

Realloc test added
This commit is contained in:
Marek Kotewicz 2017-08-01 11:04:59 +02:00 committed by GitHub
commit c4025622de
3 changed files with 61 additions and 2 deletions

View File

@ -115,5 +115,40 @@ pub const SIGNATURES: &'static [UserFunctionDescriptor] = &[
"_emscripten_memcpy_big", "_emscripten_memcpy_big",
&[I32; 3], &[I32; 3],
Some(I32), Some(I32),
) ),
Static(
"___syscall140",
&[I32; 2],
Some(I32)
),
Static(
"___syscall146",
&[I32; 2],
Some(I32)
),
Static(
"___syscall54",
&[I32; 2],
Some(I32)
),
Static(
"___syscall6",
&[I32; 2],
Some(I32)
),
Static(
"_llvm_trap",
&[I32; 0],
None
),
Static(
"abortOnCannotGrowMemory",
&[I32; 0],
Some(I32)
),
Static(
"___setErrNo",
&[I32; 1],
None
),
]; ];

View File

@ -272,3 +272,27 @@ fn create() {
)); ));
assert_eq!(gas_left, U256::from(99_768)); assert_eq!(gas_left, U256::from(99_768));
} }
// Realloc test
#[test]
fn realloc() {
let code = load_sample!("realloc.wasm");
let mut params = ActionParams::default();
params.gas = U256::from(100_000);
params.code = Some(Arc::new(code));
params.data = Some(vec![0u8]);
let mut ext = FakeExt::new();
let (gas_left, result) = {
let mut interpreter = wasm_interpreter();
let result = interpreter.exec(params, &mut ext).expect("Interpreter to execute without any errors");
match result {
GasLeft::Known(_) => { panic!("Realloc should return payload"); },
GasLeft::NeedsReturn { gas_left: gas, data: result, apply_state: _apply } => (gas, result.to_vec()),
}
};
assert_eq!(gas_left, U256::from(98326));
assert_eq!(result, vec![0u8; 2]);
}

@ -1 +1 @@
Subproject commit 9ed6304313fa949ed92aa0570fb2bc759fb6dc58 Subproject commit 04c9d84c5fe5c3ad707be58664c7e72b97cc9996