Fixed delegatecall's from/to (#7568)

* Fixed delegatecall's from/to, closes #7166

* added tests for delegatecall traces, #7167
This commit is contained in:
Marek Kotewicz 2018-01-17 10:44:11 +01:00 committed by GitHub
parent 25b19835e3
commit 7d49dd4727
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 14 deletions

View File

@ -1404,7 +1404,7 @@ mod tests {
} }
#[test] #[test]
fn should_not_trace_delegatecall() { fn should_trace_delegatecall_properly() {
init_log(); init_log();
let mut state = get_temp_state(); let mut state = get_temp_state();
@ -1424,7 +1424,7 @@ mod tests {
}.sign(&secret(), None); }.sign(&secret(), None);
state.init_code(&0xa.into(), FromHex::from_hex("6000600060006000600b618000f4").unwrap()).unwrap(); state.init_code(&0xa.into(), FromHex::from_hex("6000600060006000600b618000f4").unwrap()).unwrap();
state.init_code(&0xb.into(), FromHex::from_hex("6000").unwrap()).unwrap(); state.init_code(&0xb.into(), FromHex::from_hex("60056000526001601ff3").unwrap()).unwrap();
let result = state.apply(&info, &machine, &t, true).unwrap(); let result = state.apply(&info, &machine, &t, true).unwrap();
let expected_trace = vec![FlatTrace { let expected_trace = vec![FlatTrace {
@ -1439,23 +1439,23 @@ mod tests {
call_type: CallType::Call, call_type: CallType::Call,
}), }),
result: trace::Res::Call(trace::CallResult { result: trace::Res::Call(trace::CallResult {
gas_used: U256::from(721), // in post-eip150 gas_used: U256::from(736), // in post-eip150
output: vec![] output: vec![]
}), }),
}, FlatTrace { }, FlatTrace {
trace_address: vec![0].into_iter().collect(), trace_address: vec![0].into_iter().collect(),
subtraces: 0, subtraces: 0,
action: trace::Action::Call(trace::Call { action: trace::Action::Call(trace::Call {
from: "9cce34f7ab185c7aba1b7c8140d620b4bda941d6".into(), from: 0xa.into(),
to: 0xa.into(), to: 0xb.into(),
value: 0.into(), value: 0.into(),
gas: 32768.into(), gas: 32768.into(),
input: vec![], input: vec![],
call_type: CallType::DelegateCall, call_type: CallType::DelegateCall,
}), }),
result: trace::Res::Call(trace::CallResult { result: trace::Res::Call(trace::CallResult {
gas_used: 3.into(), gas_used: 18.into(),
output: vec![], output: vec![5],
}), }),
}]; }];

View File

@ -70,13 +70,23 @@ pub struct Call {
impl From<ActionParams> for Call { impl From<ActionParams> for Call {
fn from(p: ActionParams) -> Self { fn from(p: ActionParams) -> Self {
Call { match p.call_type {
from: p.sender, CallType::DelegateCall => Call {
to: p.address, from: p.address,
value: p.value.value(), to: p.code_address,
gas: p.gas, value: p.value.value(),
input: p.data.unwrap_or_else(Vec::new), gas: p.gas,
call_type: p.call_type, input: p.data.unwrap_or_else(Vec::new),
call_type: p.call_type,
},
_ => Call {
from: p.sender,
to: p.address,
value: p.value.value(),
gas: p.gas,
input: p.data.unwrap_or_else(Vec::new),
call_type: p.call_type,
},
} }
} }
} }