cleanup
This commit is contained in:
parent
4e321eb20f
commit
0d686b2327
@ -34,7 +34,7 @@ impl Ext for FakeExt {
|
|||||||
self.store.insert(key, value);
|
self.store.insert(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn exists(&self, address: &Address) -> bool {
|
fn exists(&self, _address: &Address) -> bool {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,21 +17,11 @@ pub enum OutputPolicy<'a> {
|
|||||||
|
|
||||||
/// Implementation of evm Externalities.
|
/// Implementation of evm Externalities.
|
||||||
pub struct Externalities<'a> {
|
pub struct Externalities<'a> {
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
pub state: &'a mut State,
|
|
||||||
#[cfg(not(test))]
|
|
||||||
state: &'a mut State,
|
state: &'a mut State,
|
||||||
|
|
||||||
info: &'a EnvInfo,
|
info: &'a EnvInfo,
|
||||||
engine: &'a Engine,
|
engine: &'a Engine,
|
||||||
depth: usize,
|
depth: usize,
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
pub params: &'a ActionParams,
|
|
||||||
#[cfg(not(test))]
|
|
||||||
params: &'a ActionParams,
|
params: &'a ActionParams,
|
||||||
|
|
||||||
substate: &'a mut Substate,
|
substate: &'a mut Substate,
|
||||||
schedule: Schedule,
|
schedule: Schedule,
|
||||||
output: OutputPolicy<'a>
|
output: OutputPolicy<'a>
|
||||||
|
@ -44,13 +44,21 @@ struct CallCreate {
|
|||||||
/// Stores callcreates.
|
/// Stores callcreates.
|
||||||
struct TestExt<'a> {
|
struct TestExt<'a> {
|
||||||
ext: Externalities<'a>,
|
ext: Externalities<'a>,
|
||||||
callcreates: Vec<CallCreate>
|
callcreates: Vec<CallCreate>,
|
||||||
|
contract_address: Address
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> TestExt<'a> {
|
impl<'a> TestExt<'a> {
|
||||||
fn new(ext: Externalities<'a>) -> TestExt {
|
fn new(state: &'a mut State,
|
||||||
|
info: &'a EnvInfo,
|
||||||
|
engine: &'a Engine,
|
||||||
|
depth: usize,
|
||||||
|
params: &'a ActionParams,
|
||||||
|
substate: &'a mut Substate,
|
||||||
|
output: OutputPolicy<'a>) -> Self {
|
||||||
TestExt {
|
TestExt {
|
||||||
ext: ext,
|
contract_address: contract_address(¶ms.address, &state.nonce(¶ms.address)),
|
||||||
|
ext: Externalities::new(state, info, engine, depth, params, substate, output),
|
||||||
callcreates: vec![]
|
callcreates: vec![]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -78,14 +86,13 @@ impl<'a> Ext for TestExt<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn create(&mut self, gas: &U256, value: &U256, code: &[u8]) -> ContractCreateResult {
|
fn create(&mut self, gas: &U256, value: &U256, code: &[u8]) -> ContractCreateResult {
|
||||||
let address = contract_address(&self.ext.params.address, &self.ext.state.nonce(&self.ext.params.address));
|
|
||||||
self.callcreates.push(CallCreate {
|
self.callcreates.push(CallCreate {
|
||||||
data: code.to_vec(),
|
data: code.to_vec(),
|
||||||
destination: None,
|
destination: None,
|
||||||
_gas_limit: *gas,
|
_gas_limit: *gas,
|
||||||
value: *value
|
value: *value
|
||||||
});
|
});
|
||||||
ContractCreateResult::Created(address, *gas)
|
ContractCreateResult::Created(self.contract_address.clone(), *gas)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn call(&mut self,
|
fn call(&mut self,
|
||||||
@ -93,8 +100,8 @@ impl<'a> Ext for TestExt<'a> {
|
|||||||
receive_address: &Address,
|
receive_address: &Address,
|
||||||
value: &U256,
|
value: &U256,
|
||||||
data: &[u8],
|
data: &[u8],
|
||||||
code_address: &Address,
|
_code_address: &Address,
|
||||||
output: &mut [u8]) -> MessageCallResult {
|
_output: &mut [u8]) -> MessageCallResult {
|
||||||
self.callcreates.push(CallCreate {
|
self.callcreates.push(CallCreate {
|
||||||
data: data.to_vec(),
|
data: data.to_vec(),
|
||||||
destination: Some(receive_address.clone()),
|
destination: Some(receive_address.clone()),
|
||||||
@ -198,11 +205,10 @@ fn do_json_test(json_data: &[u8]) -> Vec<String> {
|
|||||||
|
|
||||||
// execute
|
// execute
|
||||||
let (res, callcreates) = {
|
let (res, callcreates) = {
|
||||||
let ex = Externalities::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::Return(BytesRef::Flexible(&mut output)));
|
let mut ex = TestExt::new(&mut state, &info, &engine, 0, ¶ms, &mut substate, OutputPolicy::Return(BytesRef::Flexible(&mut output)));
|
||||||
let mut test_ext = TestExt::new(ex);
|
|
||||||
let evm = Factory::create();
|
let evm = Factory::create();
|
||||||
let res = evm.exec(¶ms, &mut test_ext);
|
let res = evm.exec(¶ms, &mut ex);
|
||||||
(res, test_ext.callcreates)
|
(res, ex.callcreates)
|
||||||
};
|
};
|
||||||
|
|
||||||
// then validate
|
// then validate
|
||||||
|
Loading…
Reference in New Issue
Block a user