clean up account fmt::Debug (#7983)
This commit is contained in:
parent
e32b600530
commit
9fec2142ae
@ -76,7 +76,12 @@ impl fmt::Display for PodState {
|
|||||||
|
|
||||||
/// Calculate and return diff between `pre` state and `post` state.
|
/// Calculate and return diff between `pre` state and `post` state.
|
||||||
pub fn diff_pod(pre: &PodState, post: &PodState) -> StateDiff {
|
pub fn diff_pod(pre: &PodState, post: &PodState) -> StateDiff {
|
||||||
StateDiff { raw: pre.get().keys().merge(post.get().keys()).filter_map(|acc| pod_account::diff_pod(pre.get().get(acc), post.get().get(acc)).map(|d|(acc.clone(), d))).collect() }
|
StateDiff {
|
||||||
|
raw: pre.get().keys()
|
||||||
|
.merge(post.get().keys())
|
||||||
|
.filter_map(|acc| pod_account::diff_pod(pre.get().get(acc), post.get().get(acc)).map(|d| (acc.clone(), d)))
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@ -89,12 +94,14 @@ mod test {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn create_delete() {
|
fn create_delete() {
|
||||||
let a = PodState::from(map![ 1.into() => PodAccount {
|
let a = PodState::from(map![
|
||||||
|
1.into() => PodAccount {
|
||||||
balance: 69.into(),
|
balance: 69.into(),
|
||||||
nonce: 0.into(),
|
nonce: 0.into(),
|
||||||
code: Some(Vec::new()),
|
code: Some(Vec::new()),
|
||||||
storage: map![],
|
storage: map![],
|
||||||
}]);
|
}
|
||||||
|
]);
|
||||||
assert_eq!(super::diff_pod(&a, &PodState::new()), StateDiff { raw: map![
|
assert_eq!(super::diff_pod(&a, &PodState::new()), StateDiff { raw: map![
|
||||||
1.into() => AccountDiff{
|
1.into() => AccountDiff{
|
||||||
balance: Diff::Died(69.into()),
|
balance: Diff::Died(69.into()),
|
||||||
@ -115,12 +122,14 @@ mod test {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn create_delete_with_unchanged() {
|
fn create_delete_with_unchanged() {
|
||||||
let a = PodState::from(map![ 1.into() => PodAccount {
|
let a = PodState::from(map![
|
||||||
|
1.into() => PodAccount {
|
||||||
balance: 69.into(),
|
balance: 69.into(),
|
||||||
nonce: 0.into(),
|
nonce: 0.into(),
|
||||||
code: Some(Vec::new()),
|
code: Some(Vec::new()),
|
||||||
storage: map![],
|
storage: map![],
|
||||||
}]);
|
}
|
||||||
|
]);
|
||||||
let b = PodState::from(map![
|
let b = PodState::from(map![
|
||||||
1.into() => PodAccount {
|
1.into() => PodAccount {
|
||||||
balance: 69.into(),
|
balance: 69.into(),
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::collections::HashMap;
|
use std::collections::{HashMap, BTreeMap};
|
||||||
use hash::{KECCAK_EMPTY, KECCAK_NULL_RLP, keccak};
|
use hash::{KECCAK_EMPTY, KECCAK_NULL_RLP, keccak};
|
||||||
use ethereum_types::{H256, U256, Address};
|
use ethereum_types::{H256, U256, Address};
|
||||||
use hashdb::HashDB;
|
use hashdb::HashDB;
|
||||||
@ -479,7 +479,12 @@ impl Account {
|
|||||||
|
|
||||||
impl fmt::Debug for Account {
|
impl fmt::Debug for Account {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(f, "{:?}", PodAccount::from_account(self))
|
f.debug_struct("Account")
|
||||||
|
.field("balance", &self.balance)
|
||||||
|
.field("nonce", &self.nonce)
|
||||||
|
.field("code", &self.code())
|
||||||
|
.field("storage", &self.storage_changes.iter().collect::<BTreeMap<_, _>>())
|
||||||
|
.finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user