initial test setup
This commit is contained in:
parent
1ae4da46b3
commit
cc4206f690
@ -68,12 +68,12 @@ pub struct Externalities<'a> {
|
|||||||
|
|
||||||
impl<'a> Externalities<'a> {
|
impl<'a> Externalities<'a> {
|
||||||
/// Basic `Externalities` constructor.
|
/// Basic `Externalities` constructor.
|
||||||
pub fn new(state: &'a mut State,
|
pub fn new(state: &'a mut State,
|
||||||
env_info: &'a EnvInfo,
|
env_info: &'a EnvInfo,
|
||||||
engine: &'a Engine,
|
engine: &'a Engine,
|
||||||
depth: usize,
|
depth: usize,
|
||||||
origin_info: OriginInfo,
|
origin_info: OriginInfo,
|
||||||
substate: &'a mut Substate,
|
substate: &'a mut Substate,
|
||||||
output: OutputPolicy<'a>) -> Self {
|
output: OutputPolicy<'a>) -> Self {
|
||||||
Externalities {
|
Externalities {
|
||||||
state: state,
|
state: state,
|
||||||
@ -139,7 +139,7 @@ impl<'a> Ext for Externalities<'a> {
|
|||||||
|
|
||||||
self.state.inc_nonce(&self.origin_info.address);
|
self.state.inc_nonce(&self.origin_info.address);
|
||||||
let mut ex = Executive::from_parent(self.state, self.env_info, self.engine, self.depth);
|
let mut ex = Executive::from_parent(self.state, self.env_info, self.engine, self.depth);
|
||||||
|
|
||||||
// TODO: handle internal error separately
|
// TODO: handle internal error separately
|
||||||
match ex.create(params, self.substate) {
|
match ex.create(params, self.substate) {
|
||||||
Ok(gas_left) => {
|
Ok(gas_left) => {
|
||||||
@ -150,18 +150,18 @@ impl<'a> Ext for Externalities<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn call(&mut self,
|
fn call(&mut self,
|
||||||
gas: &U256,
|
gas: &U256,
|
||||||
sender_address: &Address,
|
sender_address: &Address,
|
||||||
receive_address: &Address,
|
receive_address: &Address,
|
||||||
value: Option<U256>,
|
value: Option<U256>,
|
||||||
data: &[u8],
|
data: &[u8],
|
||||||
code_address: &Address,
|
code_address: &Address,
|
||||||
output: &mut [u8]) -> MessageCallResult {
|
output: &mut [u8]) -> MessageCallResult {
|
||||||
|
|
||||||
let mut params = ActionParams {
|
let mut params = ActionParams {
|
||||||
sender: sender_address.clone(),
|
sender: sender_address.clone(),
|
||||||
address: receive_address.clone(),
|
address: receive_address.clone(),
|
||||||
value: ActionValue::Apparent(self.origin_info.value.clone()),
|
value: ActionValue::Apparent(self.origin_info.value.clone()),
|
||||||
code_address: code_address.clone(),
|
code_address: code_address.clone(),
|
||||||
origin: self.origin_info.origin.clone(),
|
origin: self.origin_info.origin.clone(),
|
||||||
@ -257,3 +257,49 @@ impl<'a> Ext for Externalities<'a> {
|
|||||||
self.substate.sstore_clears_count = self.substate.sstore_clears_count + U256::one();
|
self.substate.sstore_clears_count = self.substate.sstore_clears_count + U256::one();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use common::*;
|
||||||
|
use state::*;
|
||||||
|
use engine::*;
|
||||||
|
use executive::*;
|
||||||
|
use evm::{self, Schedule, Ext, ContractCreateResult, MessageCallResult};
|
||||||
|
use substate::*;
|
||||||
|
use tests::helpers::*;
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
fn get_test_origin() -> OriginInfo {
|
||||||
|
OriginInfo {
|
||||||
|
address: Address::zero(),
|
||||||
|
origin: Address::zero(),
|
||||||
|
gas_price: U256::zero(),
|
||||||
|
value: U256::zero()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_test_env_info() -> EnvInfo {
|
||||||
|
EnvInfo {
|
||||||
|
number: 100,
|
||||||
|
author: x!(0),
|
||||||
|
timestamp: 0,
|
||||||
|
difficulty: x!(0),
|
||||||
|
last_hashes: vec![],
|
||||||
|
gas_used: x!(0),
|
||||||
|
gas_limit: x!(0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn can_be_created() {
|
||||||
|
let mut state_result = get_temp_state();
|
||||||
|
let state = state_result.reference_mut();
|
||||||
|
let test_spec = get_test_spec();
|
||||||
|
let test_engine: &Engine = &*test_spec.to_engine().unwrap();
|
||||||
|
let mut test_sub_state = Substate::new();
|
||||||
|
let env_info = get_test_env_info();
|
||||||
|
|
||||||
|
let ext = Externalities::new(state, &env_info, test_engine, 0, get_test_origin(), &mut test_sub_state, OutputPolicy::InitContract);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -56,6 +56,12 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use common::*;
|
use common::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn created() {
|
||||||
|
let mut sub_state = Substate::new();
|
||||||
|
assert_eq!(sub_state.suicides.len(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn accrue() {
|
fn accrue() {
|
||||||
let mut sub_state = Substate::new();
|
let mut sub_state = Substate::new();
|
||||||
|
Loading…
Reference in New Issue
Block a user