runtime_data, tests in progress

This commit is contained in:
debris 2015-12-24 01:07:46 +01:00
parent c695e09bba
commit 000d8fe8d0
3 changed files with 41 additions and 8 deletions

View File

@ -271,12 +271,12 @@ pub mod ffi {
}
#[no_mangle]
pub unsafe extern fn env_sha3(begin: *const u8, size: *const u64, out_hash: *mut JitI256) {
pub unsafe extern fn env_sha3(begin: *const u8, size: u64, out_hash: *mut JitI256) {
// TODO: write tests
// it may be incorrect due to endianess
// if it is, don't use `from_raw_parts`
let out_hash = &mut *out_hash;
let input = slice::from_raw_parts(begin, *size as usize);
let input = slice::from_raw_parts(begin, size as usize);
let outlen = out_hash.words.len() * 8;
let output = slice::from_raw_parts_mut(out_hash.words.as_mut_ptr() as *mut u8, outlen);
let mut sha3 = Keccak::new_sha3_256();

View File

@ -3,6 +3,7 @@ use evmjit;
use util::hash::*;
use util::uint::*;
use util::bytes::*;
use util::sha3::*;
use evm;
/// Should be used to convert jit types to ethcore
@ -56,6 +57,37 @@ impl IntoJit<evmjit::I256> for H256 {
}
}
impl IntoJit<evmjit::I256> for Address {
fn into_jit(self) -> evmjit::I256 {
H256::from(self).into_jit()
}
}
impl IntoJit<evmjit::RuntimeDataHandle> for evm::RuntimeData {
fn into_jit(self) -> evmjit::RuntimeDataHandle {
let mut data = evmjit::RuntimeDataHandle::new();
data.gas = self.gas as i64;
data.gas_price = self.gas_price as i64;
data.call_data = self.call_data.as_ptr();
data.call_data_size = self.call_data.len() as u64;
mem::forget(self.call_data);
data.address = self.address.into_jit();
data.caller = self.caller.into_jit();
data.origin = self.origin.into_jit();
data.call_value = self.call_value.into_jit();
data.coinbase = self.coinbase.into_jit();
data.difficulty = self.difficulty.into_jit();
data.gas_limit = self.gas_limit.into_jit();
data.number = self.number;
data.timestamp = self.timestamp as i64;
data.code = self.code.as_ptr();
data.code_size = self.code.len() as u64;
data.code_hash = self.code.sha3().into_jit();
mem::forget(self.code);
data
}
}
pub struct EnvAdapter {
env: evm::Env
}
@ -158,9 +190,10 @@ mod tests {
#[test]
fn test_env_adapter() {
let data = RuntimeDataHandle::new();
let mut data = RuntimeData::new();
data.code = vec![0x60, 0x00, 0x60, 0x00, 0x20, 0x60, 0x00, 0x55];
let env = EnvAdapter::new();
let mut context = ContextHandle::new(data, EnvHandle::new(env));
let mut context = ContextHandle::new(data.into_jit(), EnvHandle::new(env));
assert_eq!(context.exec(), ReturnCode::Stop);
}

View File

@ -8,13 +8,13 @@ pub struct RuntimeData {
pub address: Address,
pub caller: Address,
pub origin: Address,
pub call_value: U256,
pub coinbase: Address,
pub difficulty: U256,
pub gas_limit: U256,
pub number: u64,
pub timestamp: u64,
pub code: Vec<u8>,
pub code_hash: H256
pub code: Vec<u8>
}
impl RuntimeData {
@ -26,13 +26,13 @@ impl RuntimeData {
address: Address::new(),
caller: Address::new(),
origin: Address::new(),
call_value: U256::from(0),
coinbase: Address::new(),
difficulty: U256::from(0),
gas_limit: U256::from(0),
number: 0,
timestamp: 0,
code: vec![],
code_hash: H256::new()
code: vec![]
}
}
}