From f2d12aebef47d9d66cadda63f372b1c451391e34 Mon Sep 17 00:00:00 2001 From: Anton Gavrilov Date: Thu, 27 Jul 2017 17:54:17 +0200 Subject: [PATCH] Unit tests for tracing reward added --- ethcore/src/trace/types/filter.rs | 22 +++++++++++++++++++++- ethcore/src/trace/types/flat.rs | 28 ++++++++++++++++++++++++++-- ethcore/src/trace/types/trace.rs | 2 +- rpc/src/v1/types/trace.rs | 20 ++++++++++++++++++++ 4 files changed, 68 insertions(+), 4 deletions(-) diff --git a/ethcore/src/trace/types/filter.rs b/ethcore/src/trace/types/filter.rs index 35d70f84e..00fff0014 100644 --- a/ethcore/src/trace/types/filter.rs +++ b/ethcore/src/trace/types/filter.rs @@ -142,7 +142,8 @@ mod tests { use util::Address; use util::sha3::Hashable; 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::{Filter, AddressesFilter, TraceError}; use evm::CallType; @@ -345,5 +346,24 @@ mod tests { assert!(f4.matches(&trace)); assert!(f5.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)); } } diff --git a/ethcore/src/trace/types/flat.rs b/ethcore/src/trace/types/flat.rs index da304694d..536ecbef3 100644 --- a/ethcore/src/trace/types/flat.rs +++ b/ethcore/src/trace/types/flat.rs @@ -162,8 +162,9 @@ impl Into> for FlatBlockTraces { mod tests { use rlp::*; 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 types::trace_types::trace::RewardType; #[test] fn encode_flat_transaction_traces() { @@ -238,9 +239,32 @@ mod tests { 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![ 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); diff --git a/ethcore/src/trace/types/trace.rs b/ethcore/src/trace/types/trace.rs index 69e351cbb..faa4ca78f 100644 --- a/ethcore/src/trace/types/trace.rs +++ b/ethcore/src/trace/types/trace.rs @@ -273,7 +273,7 @@ impl Reward { impl Encodable for Reward { fn rlp_append(&self, s: &mut RlpStream) { - s.begin_list(2); + s.begin_list(3); s.append(&self.miner); s.append(&self.value); s.append(&self.reward_type); diff --git a/rpc/src/v1/types/trace.rs b/rpc/src/v1/types/trace.rs index 0fef8ae2b..3de90a75d 100644 --- a/rpc/src/v1/types/trace.rs +++ b/rpc/src/v1/types/trace.rs @@ -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"}"#); } + #[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] fn test_vmtrace_serialize() { let t = VMTrace {