hidden private fields of evm/executive
This commit is contained in:
parent
27f6d6a99c
commit
d809ee53d6
640
src/evm/jit.rs
640
src/evm/jit.rs
@ -4,24 +4,24 @@ use evmjit;
|
||||
use evm;
|
||||
|
||||
/// Ethcore representation of evmjit runtime data.
|
||||
pub struct RuntimeData {
|
||||
pub gas: U256,
|
||||
pub gas_price: U256,
|
||||
pub call_data: Vec<u8>,
|
||||
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>
|
||||
struct RuntimeData {
|
||||
gas: U256,
|
||||
gas_price: U256,
|
||||
call_data: Vec<u8>,
|
||||
address: Address,
|
||||
caller: Address,
|
||||
origin: Address,
|
||||
call_value: U256,
|
||||
coinbase: Address,
|
||||
difficulty: U256,
|
||||
gas_limit: U256,
|
||||
number: u64,
|
||||
timestamp: u64,
|
||||
code: Vec<u8>
|
||||
}
|
||||
|
||||
impl RuntimeData {
|
||||
pub fn new() -> RuntimeData {
|
||||
fn new() -> RuntimeData {
|
||||
RuntimeData {
|
||||
gas: U256::zero(),
|
||||
gas_price: U256::zero(),
|
||||
@ -357,359 +357,359 @@ impl evm::Evm for JitEvm {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use common::*;
|
||||
use evm::jit::{FromJit, IntoJit};
|
||||
use evm::{Evm,Schedule};
|
||||
use executive::*;
|
||||
use state::*;
|
||||
use engine::*;
|
||||
use spec::*;
|
||||
//#[cfg(test)]
|
||||
//mod tests {
|
||||
//use super::*;
|
||||
//use common::*;
|
||||
//use evm::jit::{FromJit, IntoJit};
|
||||
//use evm::{Evm,Schedule};
|
||||
//use executive::*;
|
||||
//use state::*;
|
||||
//use engine::*;
|
||||
//use spec::*;
|
||||
|
||||
struct TestEngine;
|
||||
//struct TestEngine;
|
||||
|
||||
impl TestEngine {
|
||||
fn new() -> Self { TestEngine }
|
||||
}
|
||||
//impl TestEngine {
|
||||
//fn new() -> Self { TestEngine }
|
||||
//}
|
||||
|
||||
impl Engine for TestEngine {
|
||||
fn name(&self) -> &str { "TestEngine" }
|
||||
fn spec(&self) -> &Spec { unimplemented!() }
|
||||
fn schedule(&self, _env_info: &EnvInfo) -> Schedule { Schedule::new_frontier() }
|
||||
}
|
||||
//impl Engine for TestEngine {
|
||||
//fn name(&self) -> &str { "TestEngine" }
|
||||
//fn spec(&self) -> &Spec { unimplemented!() }
|
||||
//fn schedule(&self, _env_info: &EnvInfo) -> Schedule { Schedule::new_frontier() }
|
||||
//}
|
||||
|
||||
#[test]
|
||||
fn test_to_and_from_u256() {
|
||||
use std::str::FromStr;
|
||||
//#[test]
|
||||
//fn test_to_and_from_u256() {
|
||||
//use std::str::FromStr;
|
||||
|
||||
let u = U256::from_str("d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3").unwrap();
|
||||
let j = u.into_jit();
|
||||
let u2 = U256::from_jit(&j);
|
||||
assert_eq!(u, u2);
|
||||
}
|
||||
//let u = U256::from_str("d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3").unwrap();
|
||||
//let j = u.into_jit();
|
||||
//let u2 = U256::from_jit(&j);
|
||||
//assert_eq!(u, u2);
|
||||
//}
|
||||
|
||||
#[test]
|
||||
fn test_to_and_from_h256() {
|
||||
use std::str::FromStr;
|
||||
//#[test]
|
||||
//fn test_to_and_from_h256() {
|
||||
//use std::str::FromStr;
|
||||
|
||||
let h = H256::from_str("d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3").unwrap();
|
||||
let j: ::evmjit::I256 = h.clone().into_jit();
|
||||
let h2 = H256::from_jit(&j);
|
||||
assert_eq!(h, h2);
|
||||
}
|
||||
//let h = H256::from_str("d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3").unwrap();
|
||||
//let j: ::evmjit::I256 = h.clone().into_jit();
|
||||
//let h2 = H256::from_jit(&j);
|
||||
//assert_eq!(h, h2);
|
||||
//}
|
||||
|
||||
#[test]
|
||||
fn test_to_and_from_address() {
|
||||
use std::str::FromStr;
|
||||
//#[test]
|
||||
//fn test_to_and_from_address() {
|
||||
//use std::str::FromStr;
|
||||
|
||||
let a = Address::from_str("2adc25665018aa1fe0e6bc666dac8fc2697ff9ba").unwrap();
|
||||
let j: ::evmjit::I256 = a.clone().into_jit();
|
||||
let a2 = Address::from_jit(&j);
|
||||
assert_eq!(a, a2);
|
||||
}
|
||||
//let a = Address::from_str("2adc25665018aa1fe0e6bc666dac8fc2697ff9ba").unwrap();
|
||||
//let j: ::evmjit::I256 = a.clone().into_jit();
|
||||
//let a2 = Address::from_jit(&j);
|
||||
//assert_eq!(a, a2);
|
||||
//}
|
||||
|
||||
#[test]
|
||||
fn test_ext_add() {
|
||||
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
||||
let mut params = ActionParams::new();
|
||||
params.address = address.clone();
|
||||
params.gas = U256::from(0x174876e800u64);
|
||||
params.code = "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01600055".from_hex().unwrap();
|
||||
//#[test]
|
||||
//fn test_ext_add() {
|
||||
//let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
||||
//let mut params = ActionParams::new();
|
||||
//params.address = address.clone();
|
||||
//params.gas = U256::from(0x174876e800u64);
|
||||
//params.code = "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01600055".from_hex().unwrap();
|
||||
|
||||
let mut state = State::new_temp();
|
||||
let info = EnvInfo::new();
|
||||
let engine = TestEngine::new();
|
||||
let mut substate = Substate::new();
|
||||
//let mut state = State::new_temp();
|
||||
//let info = EnvInfo::new();
|
||||
//let engine = TestEngine::new();
|
||||
//let mut substate = Substate::new();
|
||||
|
||||
{
|
||||
let mut ext = Externalities::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::InitContract);
|
||||
let evm = JitEvm;
|
||||
let _res = evm.exec(¶ms, &mut ext);
|
||||
//assert_eq!(evm.exec(¶ms, &mut ext), Result::Stop);
|
||||
}
|
||||
//{
|
||||
//let mut ext = Externalities::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::InitContract);
|
||||
//let evm = JitEvm;
|
||||
//let _res = evm.exec(¶ms, &mut ext);
|
||||
////assert_eq!(evm.exec(¶ms, &mut ext), Result::Stop);
|
||||
//}
|
||||
|
||||
assert_eq!(state.storage_at(&address, &H256::new()),
|
||||
H256::from_str("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe").unwrap());
|
||||
}
|
||||
//assert_eq!(state.storage_at(&address, &H256::new()),
|
||||
//H256::from_str("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe").unwrap());
|
||||
//}
|
||||
|
||||
#[test]
|
||||
fn test_ext_sha3_0() {
|
||||
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
||||
let mut params = ActionParams::new();
|
||||
params.address = address.clone();
|
||||
params.gas = U256::from(0x174876e800u64);
|
||||
params.code = "6000600020600055".from_hex().unwrap();
|
||||
//#[test]
|
||||
//fn test_ext_sha3_0() {
|
||||
//let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
||||
//let mut params = ActionParams::new();
|
||||
//params.address = address.clone();
|
||||
//params.gas = U256::from(0x174876e800u64);
|
||||
//params.code = "6000600020600055".from_hex().unwrap();
|
||||
|
||||
let mut state = State::new_temp();
|
||||
let info = EnvInfo::new();
|
||||
let engine = TestEngine::new();
|
||||
let mut substate = Substate::new();
|
||||
//let mut state = State::new_temp();
|
||||
//let info = EnvInfo::new();
|
||||
//let engine = TestEngine::new();
|
||||
//let mut substate = Substate::new();
|
||||
|
||||
{
|
||||
let mut ext = Externalities::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::InitContract);
|
||||
let evm = JitEvm;
|
||||
let _res = evm.exec(¶ms, &mut ext);
|
||||
//assert_eq!(evm.exec(¶ms, &mut ext), Result::Stop {});
|
||||
}
|
||||
//{
|
||||
//let mut ext = Externalities::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::InitContract);
|
||||
//let evm = JitEvm;
|
||||
//let _res = evm.exec(¶ms, &mut ext);
|
||||
////assert_eq!(evm.exec(¶ms, &mut ext), Result::Stop {});
|
||||
//}
|
||||
|
||||
assert_eq!(state.storage_at(&address, &H256::new()),
|
||||
H256::from_str("c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470").unwrap());
|
||||
}
|
||||
//assert_eq!(state.storage_at(&address, &H256::new()),
|
||||
//H256::from_str("c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470").unwrap());
|
||||
//}
|
||||
|
||||
#[test]
|
||||
fn test_ext_sha3_1() {
|
||||
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
||||
let mut params = ActionParams::new();
|
||||
params.address = address.clone();
|
||||
params.gas = U256::from(0x174876e800u64);
|
||||
params.code = "6005600420600055".from_hex().unwrap();
|
||||
//#[test]
|
||||
//fn test_ext_sha3_1() {
|
||||
//let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
||||
//let mut params = ActionParams::new();
|
||||
//params.address = address.clone();
|
||||
//params.gas = U256::from(0x174876e800u64);
|
||||
//params.code = "6005600420600055".from_hex().unwrap();
|
||||
|
||||
let mut state = State::new_temp();
|
||||
let info = EnvInfo::new();
|
||||
let engine = TestEngine::new();
|
||||
let mut substate = Substate::new();
|
||||
//let mut state = State::new_temp();
|
||||
//let info = EnvInfo::new();
|
||||
//let engine = TestEngine::new();
|
||||
//let mut substate = Substate::new();
|
||||
|
||||
{
|
||||
let mut ext = Externalities::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::InitContract);
|
||||
let evm = JitEvm;
|
||||
let _res = evm.exec(¶ms, &mut ext);
|
||||
//assert_eq!(evm.exec(¶ms, &mut ext), Result::Stop {});
|
||||
}
|
||||
//{
|
||||
//let mut ext = Externalities::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::InitContract);
|
||||
//let evm = JitEvm;
|
||||
//let _res = evm.exec(¶ms, &mut ext);
|
||||
////assert_eq!(evm.exec(¶ms, &mut ext), Result::Stop {});
|
||||
//}
|
||||
|
||||
assert_eq!(state.storage_at(&address, &H256::new()),
|
||||
H256::from_str("c41589e7559804ea4a2080dad19d876a024ccb05117835447d72ce08c1d020ec").unwrap());
|
||||
}
|
||||
//assert_eq!(state.storage_at(&address, &H256::new()),
|
||||
//H256::from_str("c41589e7559804ea4a2080dad19d876a024ccb05117835447d72ce08c1d020ec").unwrap());
|
||||
//}
|
||||
|
||||
#[test]
|
||||
fn test_origin() {
|
||||
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
||||
let mut params = ActionParams::new();
|
||||
params.address = address.clone();
|
||||
params.origin = address.clone();
|
||||
params.gas = U256::from(0x174876e800u64);
|
||||
params.code = "32600055".from_hex().unwrap();
|
||||
//#[test]
|
||||
//fn test_origin() {
|
||||
//let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
||||
//let mut params = ActionParams::new();
|
||||
//params.address = address.clone();
|
||||
//params.origin = address.clone();
|
||||
//params.gas = U256::from(0x174876e800u64);
|
||||
//params.code = "32600055".from_hex().unwrap();
|
||||
|
||||
let mut state = State::new_temp();
|
||||
let info = EnvInfo::new();
|
||||
let engine = TestEngine::new();
|
||||
let mut substate = Substate::new();
|
||||
//let mut state = State::new_temp();
|
||||
//let info = EnvInfo::new();
|
||||
//let engine = TestEngine::new();
|
||||
//let mut substate = Substate::new();
|
||||
|
||||
{
|
||||
let mut ext = Externalities::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::InitContract);
|
||||
let evm = JitEvm;
|
||||
let _res = evm.exec(¶ms, &mut ext);
|
||||
//assert_eq!(evm.exec(¶ms, &mut ext), Result::Stop {});
|
||||
}
|
||||
//{
|
||||
//let mut ext = Externalities::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::InitContract);
|
||||
//let evm = JitEvm;
|
||||
//let _res = evm.exec(¶ms, &mut ext);
|
||||
////assert_eq!(evm.exec(¶ms, &mut ext), Result::Stop {});
|
||||
//}
|
||||
|
||||
assert_eq!(Address::from(state.storage_at(&address, &H256::new())), address.clone());
|
||||
}
|
||||
//assert_eq!(Address::from(state.storage_at(&address, &H256::new())), address.clone());
|
||||
//}
|
||||
|
||||
#[test]
|
||||
fn test_sender() {
|
||||
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
||||
let mut params = ActionParams::new();
|
||||
params.address = address.clone();
|
||||
params.sender = address.clone();
|
||||
params.gas = U256::from(0x174876e800u64);
|
||||
params.code = "32600055".from_hex().unwrap();
|
||||
params.code = "33600055".from_hex().unwrap();
|
||||
//#[test]
|
||||
//fn test_sender() {
|
||||
//let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
||||
//let mut params = ActionParams::new();
|
||||
//params.address = address.clone();
|
||||
//params.sender = address.clone();
|
||||
//params.gas = U256::from(0x174876e800u64);
|
||||
//params.code = "32600055".from_hex().unwrap();
|
||||
//params.code = "33600055".from_hex().unwrap();
|
||||
|
||||
let mut state = State::new_temp();
|
||||
let info = EnvInfo::new();
|
||||
let engine = TestEngine::new();
|
||||
let mut substate = Substate::new();
|
||||
//let mut state = State::new_temp();
|
||||
//let info = EnvInfo::new();
|
||||
//let engine = TestEngine::new();
|
||||
//let mut substate = Substate::new();
|
||||
|
||||
{
|
||||
let mut ext = Externalities::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::InitContract);
|
||||
let evm = JitEvm;
|
||||
let _res = evm.exec(¶ms, &mut ext);
|
||||
//assert_eq!(evm.exec(¶ms, &mut ext), Result::Stop {});
|
||||
}
|
||||
//{
|
||||
//let mut ext = Externalities::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::InitContract);
|
||||
//let evm = JitEvm;
|
||||
//let _res = evm.exec(¶ms, &mut ext);
|
||||
////assert_eq!(evm.exec(¶ms, &mut ext), Result::Stop {});
|
||||
//}
|
||||
|
||||
assert_eq!(Address::from(state.storage_at(&address, &H256::new())), address.clone());
|
||||
}
|
||||
//assert_eq!(Address::from(state.storage_at(&address, &H256::new())), address.clone());
|
||||
//}
|
||||
|
||||
#[test]
|
||||
fn test_extcode_copy0() {
|
||||
// 33 - sender
|
||||
// 3b - extcodesize
|
||||
// 60 00 - push 0
|
||||
// 60 00 - push 0
|
||||
// 33 - sender
|
||||
// 3c - extcodecopy
|
||||
// 60 00 - push 0
|
||||
// 51 - load word from memory
|
||||
// 60 00 - push 0
|
||||
// 55 - sstore
|
||||
//#[test]
|
||||
//fn test_extcode_copy0() {
|
||||
//// 33 - sender
|
||||
//// 3b - extcodesize
|
||||
//// 60 00 - push 0
|
||||
//// 60 00 - push 0
|
||||
//// 33 - sender
|
||||
//// 3c - extcodecopy
|
||||
//// 60 00 - push 0
|
||||
//// 51 - load word from memory
|
||||
//// 60 00 - push 0
|
||||
//// 55 - sstore
|
||||
|
||||
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
||||
let sender = Address::from_str("cd1722f3947def4cf144679da39c4c32bdc35681").unwrap();
|
||||
let address_code = "333b60006000333c600051600055".from_hex().unwrap();
|
||||
let sender_code = "6005600055".from_hex().unwrap();
|
||||
let mut params = ActionParams::new();
|
||||
params.address = address.clone();
|
||||
params.sender = sender.clone();
|
||||
params.origin = sender.clone();
|
||||
params.gas = U256::from(0x174876e800u64);
|
||||
params.code = address_code.clone();
|
||||
//let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
||||
//let sender = Address::from_str("cd1722f3947def4cf144679da39c4c32bdc35681").unwrap();
|
||||
//let address_code = "333b60006000333c600051600055".from_hex().unwrap();
|
||||
//let sender_code = "6005600055".from_hex().unwrap();
|
||||
//let mut params = ActionParams::new();
|
||||
//params.address = address.clone();
|
||||
//params.sender = sender.clone();
|
||||
//params.origin = sender.clone();
|
||||
//params.gas = U256::from(0x174876e800u64);
|
||||
//params.code = address_code.clone();
|
||||
|
||||
let mut state = State::new_temp();
|
||||
state.init_code(&address, address_code);
|
||||
state.init_code(&sender, sender_code);
|
||||
let info = EnvInfo::new();
|
||||
let engine = TestEngine::new();
|
||||
let mut substate = Substate::new();
|
||||
//let mut state = State::new_temp();
|
||||
//state.init_code(&address, address_code);
|
||||
//state.init_code(&sender, sender_code);
|
||||
//let info = EnvInfo::new();
|
||||
//let engine = TestEngine::new();
|
||||
//let mut substate = Substate::new();
|
||||
|
||||
{
|
||||
let mut ext = Externalities::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::InitContract);
|
||||
let evm = JitEvm;
|
||||
let _res = evm.exec(¶ms, &mut ext);
|
||||
//assert_eq!(evm.exec(¶ms, &mut ext), Result::Stop {});
|
||||
}
|
||||
//{
|
||||
//let mut ext = Externalities::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::InitContract);
|
||||
//let evm = JitEvm;
|
||||
//let _res = evm.exec(¶ms, &mut ext);
|
||||
////assert_eq!(evm.exec(¶ms, &mut ext), Result::Stop {});
|
||||
//}
|
||||
|
||||
assert_eq!(state.storage_at(&address, &H256::new()),
|
||||
H256::from_str("6005600055000000000000000000000000000000000000000000000000000000").unwrap());
|
||||
}
|
||||
//assert_eq!(state.storage_at(&address, &H256::new()),
|
||||
//H256::from_str("6005600055000000000000000000000000000000000000000000000000000000").unwrap());
|
||||
//}
|
||||
|
||||
#[test]
|
||||
fn test_balance() {
|
||||
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
||||
let mut params = ActionParams::new();
|
||||
params.address = address.clone();
|
||||
params.sender = address.clone();
|
||||
params.gas = U256::from(0x174876e800u64);
|
||||
params.code = "3331600055".from_hex().unwrap();
|
||||
//#[test]
|
||||
//fn test_balance() {
|
||||
//let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
||||
//let mut params = ActionParams::new();
|
||||
//params.address = address.clone();
|
||||
//params.sender = address.clone();
|
||||
//params.gas = U256::from(0x174876e800u64);
|
||||
//params.code = "3331600055".from_hex().unwrap();
|
||||
|
||||
let mut state = State::new_temp();
|
||||
state.add_balance(&address, &U256::from(0x10));
|
||||
let info = EnvInfo::new();
|
||||
let engine = TestEngine::new();
|
||||
let mut substate = Substate::new();
|
||||
//let mut state = State::new_temp();
|
||||
//state.add_balance(&address, &U256::from(0x10));
|
||||
//let info = EnvInfo::new();
|
||||
//let engine = TestEngine::new();
|
||||
//let mut substate = Substate::new();
|
||||
|
||||
{
|
||||
let mut ext = Externalities::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::InitContract);
|
||||
let evm = JitEvm;
|
||||
let _res = evm.exec(¶ms, &mut ext);
|
||||
//assert_eq!(evm.exec(¶ms, &mut ext), Result::Stop {});
|
||||
}
|
||||
//{
|
||||
//let mut ext = Externalities::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::InitContract);
|
||||
//let evm = JitEvm;
|
||||
//let _res = evm.exec(¶ms, &mut ext);
|
||||
////assert_eq!(evm.exec(¶ms, &mut ext), Result::Stop {});
|
||||
//}
|
||||
|
||||
assert_eq!(state.storage_at(&address, &H256::new()), H256::from(&U256::from(0x10)));
|
||||
}
|
||||
//assert_eq!(state.storage_at(&address, &H256::new()), H256::from(&U256::from(0x10)));
|
||||
//}
|
||||
|
||||
#[test]
|
||||
fn test_empty_log() {
|
||||
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
||||
let mut params = ActionParams::new();
|
||||
params.address = address.clone();
|
||||
params.gas = U256::from(0x174876e800u64);
|
||||
params.code = "60006000a0".from_hex().unwrap();
|
||||
//#[test]
|
||||
//fn test_empty_log() {
|
||||
//let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
||||
//let mut params = ActionParams::new();
|
||||
//params.address = address.clone();
|
||||
//params.gas = U256::from(0x174876e800u64);
|
||||
//params.code = "60006000a0".from_hex().unwrap();
|
||||
|
||||
let mut state = State::new_temp();
|
||||
let info = EnvInfo::new();
|
||||
let engine = TestEngine::new();
|
||||
let mut substate = Substate::new();
|
||||
{
|
||||
let mut ext = Externalities::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::InitContract);
|
||||
let evm = JitEvm;
|
||||
let _res = evm.exec(¶ms, &mut ext);
|
||||
//assert_eq!(evm.exec(¶ms, &mut ext), Result::Stop {});
|
||||
}
|
||||
let logs = substate.logs();
|
||||
assert_eq!(logs.len(), 1);
|
||||
let log = &logs[0];
|
||||
assert_eq!(log.address(), &address);
|
||||
assert_eq!(log.topics().len(), 0);
|
||||
assert_eq!(log.bloom(), H2048::from_str("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").unwrap());
|
||||
}
|
||||
//let mut state = State::new_temp();
|
||||
//let info = EnvInfo::new();
|
||||
//let engine = TestEngine::new();
|
||||
//let mut substate = Substate::new();
|
||||
//{
|
||||
//let mut ext = Externalities::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::InitContract);
|
||||
//let evm = JitEvm;
|
||||
//let _res = evm.exec(¶ms, &mut ext);
|
||||
////assert_eq!(evm.exec(¶ms, &mut ext), Result::Stop {});
|
||||
//}
|
||||
//let logs = substate.logs();
|
||||
//assert_eq!(logs.len(), 1);
|
||||
//let log = &logs[0];
|
||||
//assert_eq!(log.address(), &address);
|
||||
//assert_eq!(log.topics().len(), 0);
|
||||
//assert_eq!(log.bloom(), H2048::from_str("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").unwrap());
|
||||
//}
|
||||
|
||||
#[test]
|
||||
fn test_log_with_one_topic() {
|
||||
// 60 ff - push ff
|
||||
// 60 00 - push 00
|
||||
// 53 - mstore
|
||||
// 33 - sender
|
||||
// 60 20 - push 20
|
||||
// 60 00 - push 0
|
||||
// a1 - log with 1 topic
|
||||
//#[test]
|
||||
//fn test_log_with_one_topic() {
|
||||
//// 60 ff - push ff
|
||||
//// 60 00 - push 00
|
||||
//// 53 - mstore
|
||||
//// 33 - sender
|
||||
//// 60 20 - push 20
|
||||
//// 60 00 - push 0
|
||||
//// a1 - log with 1 topic
|
||||
|
||||
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
||||
let mut params = ActionParams::new();
|
||||
params.address = address.clone();
|
||||
params.sender = address.clone();
|
||||
params.gas = U256::from(0x174876e800u64);
|
||||
params.code = "60ff6000533360206000a1".from_hex().unwrap();
|
||||
//let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
||||
//let mut params = ActionParams::new();
|
||||
//params.address = address.clone();
|
||||
//params.sender = address.clone();
|
||||
//params.gas = U256::from(0x174876e800u64);
|
||||
//params.code = "60ff6000533360206000a1".from_hex().unwrap();
|
||||
|
||||
let mut state = State::new_temp();
|
||||
let info = EnvInfo::new();
|
||||
let engine = TestEngine::new();
|
||||
let mut substate = Substate::new();
|
||||
{
|
||||
let mut ext = Externalities::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::InitContract);
|
||||
let evm = JitEvm;
|
||||
let _res = evm.exec(¶ms, &mut ext);
|
||||
//assert_eq!(evm.exec(¶ms, &mut ext), Result::Stop {});
|
||||
}
|
||||
let logs = substate.logs();
|
||||
assert_eq!(logs.len(), 1);
|
||||
let log = &logs[0];
|
||||
assert_eq!(log.address(), &address);
|
||||
assert_eq!(log.topics().len(), 1);
|
||||
let topic = &log.topics()[0];
|
||||
assert_eq!(topic, &H256::from_str("0000000000000000000000000f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap());
|
||||
assert_eq!(topic, &H256::from(address.clone()));
|
||||
assert_eq!(log.data(), &"ff00000000000000000000000000000000000000000000000000000000000000".from_hex().unwrap());
|
||||
}
|
||||
//let mut state = State::new_temp();
|
||||
//let info = EnvInfo::new();
|
||||
//let engine = TestEngine::new();
|
||||
//let mut substate = Substate::new();
|
||||
//{
|
||||
//let mut ext = Externalities::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::InitContract);
|
||||
//let evm = JitEvm;
|
||||
//let _res = evm.exec(¶ms, &mut ext);
|
||||
////assert_eq!(evm.exec(¶ms, &mut ext), Result::Stop {});
|
||||
//}
|
||||
//let logs = substate.logs();
|
||||
//assert_eq!(logs.len(), 1);
|
||||
//let log = &logs[0];
|
||||
//assert_eq!(log.address(), &address);
|
||||
//assert_eq!(log.topics().len(), 1);
|
||||
//let topic = &log.topics()[0];
|
||||
//assert_eq!(topic, &H256::from_str("0000000000000000000000000f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap());
|
||||
//assert_eq!(topic, &H256::from(address.clone()));
|
||||
//assert_eq!(log.data(), &"ff00000000000000000000000000000000000000000000000000000000000000".from_hex().unwrap());
|
||||
//}
|
||||
|
||||
#[test]
|
||||
fn test_blockhash() {
|
||||
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
||||
let mut params = ActionParams::new();
|
||||
params.address = address.clone();
|
||||
params.gas = U256::from(0x174876e800u64);
|
||||
params.code = "600040600055".from_hex().unwrap();
|
||||
//#[test]
|
||||
//fn test_blockhash() {
|
||||
//let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
||||
//let mut params = ActionParams::new();
|
||||
//params.address = address.clone();
|
||||
//params.gas = U256::from(0x174876e800u64);
|
||||
//params.code = "600040600055".from_hex().unwrap();
|
||||
|
||||
let mut state = State::new_temp();
|
||||
let mut info = EnvInfo::new();
|
||||
info.number = 1;
|
||||
info.last_hashes.push(H256::from(address.clone()));
|
||||
let engine = TestEngine::new();
|
||||
let mut substate = Substate::new();
|
||||
//let mut state = State::new_temp();
|
||||
//let mut info = EnvInfo::new();
|
||||
//info.number = 1;
|
||||
//info.last_hashes.push(H256::from(address.clone()));
|
||||
//let engine = TestEngine::new();
|
||||
//let mut substate = Substate::new();
|
||||
|
||||
{
|
||||
let mut ext = Externalities::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::InitContract);
|
||||
let evm = JitEvm;
|
||||
let _res = evm.exec(¶ms, &mut ext);
|
||||
//assert_eq!(evm.exec(¶ms, &mut ext), Result::Stop {});
|
||||
}
|
||||
//{
|
||||
//let mut ext = Externalities::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::InitContract);
|
||||
//let evm = JitEvm;
|
||||
//let _res = evm.exec(¶ms, &mut ext);
|
||||
////assert_eq!(evm.exec(¶ms, &mut ext), Result::Stop {});
|
||||
//}
|
||||
|
||||
assert_eq!(state.storage_at(&address, &H256::new()), H256::from(address.clone()));
|
||||
}
|
||||
//assert_eq!(state.storage_at(&address, &H256::new()), H256::from(address.clone()));
|
||||
//}
|
||||
|
||||
#[test]
|
||||
fn test_calldataload() {
|
||||
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
||||
let mut params = ActionParams::new();
|
||||
params.address = address.clone();
|
||||
params.gas = U256::from(0x174876e800u64);
|
||||
params.code = "600135600055".from_hex().unwrap();
|
||||
params.data = "0123ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff23".from_hex().unwrap();
|
||||
//#[test]
|
||||
//fn test_calldataload() {
|
||||
//let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
||||
//let mut params = ActionParams::new();
|
||||
//params.address = address.clone();
|
||||
//params.gas = U256::from(0x174876e800u64);
|
||||
//params.code = "600135600055".from_hex().unwrap();
|
||||
//params.data = "0123ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff23".from_hex().unwrap();
|
||||
|
||||
let mut state = State::new_temp();
|
||||
let mut info = EnvInfo::new();
|
||||
info.number = 1;
|
||||
info.last_hashes.push(H256::from(address.clone()));
|
||||
let engine = TestEngine::new();
|
||||
let mut substate = Substate::new();
|
||||
//let mut state = State::new_temp();
|
||||
//let mut info = EnvInfo::new();
|
||||
//info.number = 1;
|
||||
//info.last_hashes.push(H256::from(address.clone()));
|
||||
//let engine = TestEngine::new();
|
||||
//let mut substate = Substate::new();
|
||||
|
||||
{
|
||||
let mut ext = Externalities::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::InitContract);
|
||||
let evm = JitEvm;
|
||||
let _res = evm.exec(¶ms, &mut ext);
|
||||
//assert_eq!(evm.exec(¶ms, &mut ext), Result::Stop {});
|
||||
}
|
||||
//{
|
||||
//let mut ext = Externalities::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::InitContract);
|
||||
//let evm = JitEvm;
|
||||
//let _res = evm.exec(¶ms, &mut ext);
|
||||
////assert_eq!(evm.exec(¶ms, &mut ext), Result::Stop {});
|
||||
//}
|
||||
|
||||
assert_eq!(state.storage_at(&address, &H256::new()), H256::from_str("23ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff23").unwrap());
|
||||
}
|
||||
}
|
||||
//assert_eq!(state.storage_at(&address, &H256::new()), H256::from_str("23ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff23").unwrap());
|
||||
//}
|
||||
//}
|
||||
|
@ -1,3 +1,5 @@
|
||||
//! Cost schedule and other parameterisations for the EVM.
|
||||
|
||||
/// Definition of the cost schedule and other parameterisations for the EVM.
|
||||
pub struct Schedule {
|
||||
pub exceptional_failed_code_deposit: bool,
|
||||
@ -77,4 +79,4 @@ impl Schedule {
|
||||
copy_gas: 3,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ pub fn contract_address(address: &Address, nonce: &U256) -> Address {
|
||||
|
||||
/// State changes which should be applied in finalize,
|
||||
/// after transaction is fully executed.
|
||||
pub struct Substate {
|
||||
struct Substate {
|
||||
/// Any accounts that have suicided.
|
||||
suicides: HashSet<Address>,
|
||||
/// Any logs.
|
||||
@ -25,21 +25,16 @@ pub struct Substate {
|
||||
|
||||
impl Substate {
|
||||
/// Creates new substate.
|
||||
pub fn new() -> Self {
|
||||
fn new() -> Self {
|
||||
Substate {
|
||||
suicides: HashSet::new(),
|
||||
logs: vec![],
|
||||
refunds_count: U256::zero(),
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: remove
|
||||
pub fn logs(&self) -> &[LogEntry] {
|
||||
&self.logs
|
||||
}
|
||||
}
|
||||
|
||||
/// Transaction execution result.
|
||||
/// Transaction execution receipt.
|
||||
pub struct Executed {
|
||||
/// Gas paid up front for execution of transaction.
|
||||
pub gas: U256,
|
||||
@ -61,9 +56,10 @@ pub struct Executed {
|
||||
pub out_of_gas: bool,
|
||||
}
|
||||
|
||||
/// Transaction execution result.
|
||||
pub type ExecutionResult = Result<Executed, ExecutionError>;
|
||||
|
||||
/// Message-call/contract-creation executor; useful for executing transactions.
|
||||
/// Transaction executor.
|
||||
pub struct Executive<'a> {
|
||||
state: &'a mut State,
|
||||
info: &'a EnvInfo,
|
||||
@ -72,7 +68,7 @@ pub struct Executive<'a> {
|
||||
}
|
||||
|
||||
impl<'a> Executive<'a> {
|
||||
/// Creates new executive with depth equal 0.
|
||||
/// Basic constructor.
|
||||
pub fn new(state: &'a mut State, info: &'a EnvInfo, engine: &'a Engine) -> Self {
|
||||
Executive::new_with_depth(state, info, engine, 0)
|
||||
}
|
||||
@ -93,7 +89,7 @@ impl<'a> Executive<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
/// This funtion should be used to execute transaction.
|
||||
/// Executes transaction.
|
||||
pub fn transact(&mut self, t: &Transaction) -> ExecutionResult {
|
||||
// TODO: validate transaction signature ?/ sender
|
||||
|
||||
@ -259,7 +255,7 @@ impl<'a> Executive<'a> {
|
||||
}
|
||||
|
||||
/// Policy for handling output data on `RETURN` opcode.
|
||||
pub enum OutputPolicy<'a> {
|
||||
enum OutputPolicy<'a> {
|
||||
/// Return reference to fixed sized output.
|
||||
/// Used for message calls.
|
||||
Return(&'a mut [u8]),
|
||||
@ -268,7 +264,7 @@ pub enum OutputPolicy<'a> {
|
||||
}
|
||||
|
||||
/// Implementation of evm Externalities.
|
||||
pub struct Externalities<'a> {
|
||||
struct Externalities<'a> {
|
||||
state: &'a mut State,
|
||||
info: &'a EnvInfo,
|
||||
engine: &'a Engine,
|
||||
@ -281,7 +277,7 @@ pub struct Externalities<'a> {
|
||||
|
||||
impl<'a> Externalities<'a> {
|
||||
/// Basic `Externalities` constructor.
|
||||
pub fn new(state: &'a mut State,
|
||||
fn new(state: &'a mut State,
|
||||
info: &'a EnvInfo,
|
||||
engine: &'a Engine,
|
||||
depth: usize,
|
||||
@ -301,7 +297,7 @@ impl<'a> Externalities<'a> {
|
||||
}
|
||||
|
||||
/// Creates `Externalities` from `Executive`.
|
||||
pub fn from_executive(e: &'a mut Executive, params: &'a ActionParams, substate: &'a mut Substate, output: OutputPolicy<'a>) -> Self {
|
||||
fn from_executive(e: &'a mut Executive, params: &'a ActionParams, substate: &'a mut Substate, output: OutputPolicy<'a>) -> Self {
|
||||
Self::new(e.state, e.info, e.engine, e.depth, params, substate, output)
|
||||
}
|
||||
}
|
||||
@ -452,6 +448,7 @@ mod tests {
|
||||
use state::*;
|
||||
use ethereum;
|
||||
use null_engine::*;
|
||||
use super::Substate;
|
||||
|
||||
#[test]
|
||||
fn test_contract_address() {
|
||||
|
Loading…
Reference in New Issue
Block a user