realloc test added
This commit is contained in:
		
							parent
							
								
									e84f308264
								
							
						
					
					
						commit
						e234b7fdbf
					
				@ -115,5 +115,40 @@ pub const SIGNATURES: &'static [UserFunctionDescriptor] = &[
 | 
			
		||||
		"_emscripten_memcpy_big",
 | 
			
		||||
		&[I32; 3],
 | 
			
		||||
		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
 | 
			
		||||
	),
 | 
			
		||||
];
 | 
			
		||||
 | 
			
		||||
@ -272,3 +272,27 @@ fn create() {
 | 
			
		||||
	));
 | 
			
		||||
	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]);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user