Unit tests for tracing reward added

This commit is contained in:
Anton Gavrilov 2017-07-27 17:54:17 +02:00
parent 53c3b772dd
commit af1fbb39ca
4 changed files with 68 additions and 4 deletions

View File

@ -142,7 +142,8 @@ mod tests {
use util::Address; use util::Address;
use util::sha3::Hashable; use util::sha3::Hashable;
use util::bloom::Bloomable; use util::bloom::Bloomable;
use trace::trace::{Action, Call, Res, Create, CreateResult, Suicide}; use trace::trace::{Action, Call, Res, Create, CreateResult, Suicide, Reward};
use types::trace_types::trace::RewardType;
use trace::flat::FlatTrace; use trace::flat::FlatTrace;
use trace::{Filter, AddressesFilter, TraceError}; use trace::{Filter, AddressesFilter, TraceError};
use evm::CallType; use evm::CallType;
@ -345,5 +346,24 @@ mod tests {
assert!(f4.matches(&trace)); assert!(f4.matches(&trace));
assert!(f5.matches(&trace)); assert!(f5.matches(&trace));
assert!(!f6.matches(&trace)); assert!(!f6.matches(&trace));
let trace = FlatTrace {
action: Action::Reward(Reward {
miner: 2.into(),
value: 100.into(),
reward_type: RewardType::Block,
}),
result: Res::None,
trace_address: vec![].into_iter().collect(),
subtraces: 0
};
assert!(f0.matches(&trace));
assert!(f1.matches(&trace));
assert!(f2.matches(&trace));
assert!(f3.matches(&trace));
assert!(f4.matches(&trace));
assert!(f5.matches(&trace));
assert!(!f6.matches(&trace));
} }
} }

View File

@ -162,8 +162,9 @@ impl Into<Vec<FlatTransactionTraces>> for FlatBlockTraces {
mod tests { mod tests {
use rlp::*; use rlp::*;
use super::{FlatBlockTraces, FlatTransactionTraces, FlatTrace}; use super::{FlatBlockTraces, FlatTransactionTraces, FlatTrace};
use trace::trace::{Action, Res, CallResult, Call, Suicide}; use trace::trace::{Action, Res, CallResult, Call, Suicide, Reward};
use evm::CallType; use evm::CallType;
use types::trace_types::trace::RewardType;
#[test] #[test]
fn encode_flat_transaction_traces() { fn encode_flat_transaction_traces() {
@ -238,9 +239,32 @@ mod tests {
subtraces: 0, subtraces: 0,
}; };
let flat_trace3 = FlatTrace {
action: Action::Reward(Reward {
miner: "412fda7643b37d436cb40628f6dbbb80a07267ed".parse().unwrap(),
value: 10.into(),
reward_type: RewardType::Uncle,
}),
result: Res::None,
trace_address: vec![0].into_iter().collect(),
subtraces: 0,
};
let flat_trace4 = FlatTrace {
action: Action::Reward(Reward {
miner: "412fda7643b37d436cb40628f6dbbb80a07267ed".parse().unwrap(),
value: 10.into(),
reward_type: RewardType::Block,
}),
result: Res::None,
trace_address: vec![0].into_iter().collect(),
subtraces: 0,
};
let block_traces = FlatBlockTraces(vec![ let block_traces = FlatBlockTraces(vec![
FlatTransactionTraces(vec![flat_trace]), FlatTransactionTraces(vec![flat_trace]),
FlatTransactionTraces(vec![flat_trace1, flat_trace2]) FlatTransactionTraces(vec![flat_trace1, flat_trace2]),
FlatTransactionTraces(vec![flat_trace3, flat_trace4])
]); ]);
let encoded = ::rlp::encode(&block_traces); let encoded = ::rlp::encode(&block_traces);

View File

@ -273,7 +273,7 @@ impl Reward {
impl Encodable for Reward { impl Encodable for Reward {
fn rlp_append(&self, s: &mut RlpStream) { fn rlp_append(&self, s: &mut RlpStream) {
s.begin_list(2); s.begin_list(3);
s.append(&self.miner); s.append(&self.miner);
s.append(&self.value); s.append(&self.value);
s.append(&self.reward_type); s.append(&self.reward_type);

View File

@ -763,6 +763,26 @@ mod tests {
assert_eq!(serialized, r#"{"type":"suicide","action":{"address":"0x0000000000000000000000000000000000000004","refundAddress":"0x0000000000000000000000000000000000000006","balance":"0x7"},"result":null,"traceAddress":[10],"subtraces":1,"transactionPosition":11,"transactionHash":"0x000000000000000000000000000000000000000000000000000000000000000c","blockNumber":13,"blockHash":"0x000000000000000000000000000000000000000000000000000000000000000e"}"#); assert_eq!(serialized, r#"{"type":"suicide","action":{"address":"0x0000000000000000000000000000000000000004","refundAddress":"0x0000000000000000000000000000000000000006","balance":"0x7"},"result":null,"traceAddress":[10],"subtraces":1,"transactionPosition":11,"transactionHash":"0x000000000000000000000000000000000000000000000000000000000000000c","blockNumber":13,"blockHash":"0x000000000000000000000000000000000000000000000000000000000000000e"}"#);
} }
#[test]
fn test_trace_reward_serialize() {
let t = LocalizedTrace {
action: Action::Reward(Reward {
miner: 4.into(),
value: 6.into(),
reward_type: RewardType::Block,
}),
result: Res::None,
trace_address: vec![10],
subtraces: 1,
transaction_position: 11,
transaction_hash: 12.into(),
block_number: 13,
block_hash: 14.into(),
};
let serialized = serde_json::to_string(&t).unwrap();
assert_eq!(serialized, r#"{"type":"reward","action":{"miner":"0x0000000000000000000000000000000000000004","value":"0x0000000000000000000000000000000000000006","rewardType":"block"},"result":null,"traceAddress":[10],"subtraces":1,"transactionPosition":11,"transactionHash":"0x000000000000000000000000000000000000000000000000000000000000000c","blockNumber":13,"blockHash":"0x000000000000000000000000000000000000000000000000000000000000000e"}"#);
}
#[test] #[test]
fn test_vmtrace_serialize() { fn test_vmtrace_serialize() {
let t = VMTrace { let t = VMTrace {