Fix test and first part of optionality.

This commit is contained in:
Gav Wood 2016-03-19 08:31:19 +01:00
parent bd338a5741
commit d6f94c4ad7
2 changed files with 12 additions and 10 deletions

View File

@ -264,7 +264,7 @@ impl<'a> Executive<'a> {
trace!("exec: sstore-clears={}\n", unconfirmed_substate.sstore_clears_count);
trace!("exec: substate={:?}; unconfirmed_substate={:?}\n", substate, unconfirmed_substate);
self.enact_result(&res, substate, unconfirmed_substate, action);
self.enact_result(&res, substate, unconfirmed_substate, Some(action));
trace!("exec: new substate={:?}\n", substate);
res
} else {
@ -304,7 +304,7 @@ impl<'a> Executive<'a> {
c.result = res.as_ref().ok().map(|gas_left| (c.gas - *gas_left, created));
}
self.enact_result(&res, substate, unconfirmed_substate, action);
self.enact_result(&res, substate, unconfirmed_substate, Some(action));
res
}
@ -367,7 +367,7 @@ impl<'a> Executive<'a> {
}
}
fn enact_result(&mut self, result: &evm::Result, substate: &mut Substate, un_substate: Substate, action: TraceAction) {
fn enact_result(&mut self, result: &evm::Result, substate: &mut Substate, un_substate: Substate, maybe_action: Option<TraceAction>) {
match *result {
Err(evm::Error::OutOfGas)
| Err(evm::Error::BadJumpDestination {..})
@ -378,7 +378,7 @@ impl<'a> Executive<'a> {
},
Ok(_) | Err(evm::Error::Internal) => {
self.state.clear_snapshot();
substate.accrue(un_substate, action)
substate.accrue(un_substate, maybe_action)
}
}
}

View File

@ -87,16 +87,18 @@ impl Substate {
}
/// Merge secondary substate `s` into self, accruing each element correspondingly.
pub fn accrue(&mut self, s: Substate, action: TraceAction) {
pub fn accrue(&mut self, s: Substate, maybe_action: Option<TraceAction>) {
self.suicides.extend(s.suicides.into_iter());
self.logs.extend(s.logs.into_iter());
self.sstore_clears_count = self.sstore_clears_count + s.sstore_clears_count;
self.contracts_created.extend(s.contracts_created.into_iter());
if let Some(action) = maybe_action {
self.trace.push(TraceItem {
action: action,
subs: s.trace,
});
}
}
}
@ -156,7 +158,7 @@ mod tests {
});
sub_state_2.sstore_clears_count = x!(7);
sub_state.accrue(sub_state_2);
sub_state.accrue(sub_state_2, None);
assert_eq!(sub_state.contracts_created.len(), 2);
assert_eq!(sub_state.sstore_clears_count, x!(12));
assert_eq!(sub_state.suicides.len(), 1);