Tier step price.

This commit is contained in:
Gav Wood 2016-01-13 23:53:00 +01:00
parent 12187b8af7
commit f835990091
3 changed files with 40 additions and 19 deletions

View File

@ -54,13 +54,34 @@ impl AccountDiff {
} }
} }
/*impl Debug for AccountDiff { #[derive(Debug,Clone,PartialEq,Eq)]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { pub struct StateDiff (BTreeMap<Address, AccountDiff>);
write!(f, "{:?}", PodAccount::from_account(self))
}
}*/
pub type StateDiff = BTreeMap<Address, AccountDiff>; impl fmt::Display for AccountDiff {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "...\n")
}
}
impl fmt::Display for Existance {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
&Existance::Born => try!(write!(f, "+++")),
&Existance::Alive => try!(write!(f, "***")),
&Existance::Died => try!(write!(f, "---")),
}
Ok(())
}
}
impl fmt::Display for StateDiff {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
for (add, acc) in self.0.iter() {
try!(write!(f, "{} {}: {}", acc.existance(), add, acc));
}
Ok(())
}
}
pub fn pod_diff(pre: Option<&PodAccount>, post: Option<&PodAccount>) -> Option<AccountDiff> { pub fn pod_diff(pre: Option<&PodAccount>, post: Option<&PodAccount>) -> Option<AccountDiff> {
match (pre, post) { match (pre, post) {
@ -101,7 +122,7 @@ pub fn pod_diff(pre: Option<&PodAccount>, post: Option<&PodAccount>) -> Option<A
} }
pub fn pod_map_diff(pre: &BTreeMap<Address, PodAccount>, post: &BTreeMap<Address, PodAccount>) -> StateDiff { pub fn pod_map_diff(pre: &BTreeMap<Address, PodAccount>, post: &BTreeMap<Address, PodAccount>) -> StateDiff {
pre.keys().merge(post.keys()).filter_map(|acc| pod_diff(pre.get(acc), post.get(acc)).map(|d|(acc.clone(), d))).collect() StateDiff(pre.keys().merge(post.keys()).filter_map(|acc| pod_diff(pre.get(acc), post.get(acc)).map(|d|(acc.clone(), d))).collect())
} }
#[test] #[test]
@ -114,22 +135,22 @@ fn state_diff_create_delete() {
storage: map![] storage: map![]
} }
]; ];
assert_eq!(pod_map_diff(&a, &map![]), map![ assert_eq!(pod_map_diff(&a, &map![]), StateDiff(map![
x!(1) => AccountDiff{ x!(1) => AccountDiff{
balance: Diff::Died(x!(69)), balance: Diff::Died(x!(69)),
nonce: Diff::Died(x!(0)), nonce: Diff::Died(x!(0)),
code: Diff::Died(vec![]), code: Diff::Died(vec![]),
storage: map![], storage: map![],
} }
]); ]));
assert_eq!(pod_map_diff(&map![], &a), map![ assert_eq!(pod_map_diff(&map![], &a), StateDiff(map![
x!(1) => AccountDiff{ x!(1) => AccountDiff{
balance: Diff::Born(x!(69)), balance: Diff::Born(x!(69)),
nonce: Diff::Born(x!(0)), nonce: Diff::Born(x!(0)),
code: Diff::Born(vec![]), code: Diff::Born(vec![]),
storage: map![], storage: map![],
} }
]); ]));
} }
#[test] #[test]
@ -156,22 +177,22 @@ fn state_diff_cretae_delete_with_unchanged() {
storage: map![] storage: map![]
} }
]; ];
assert_eq!(pod_map_diff(&a, &b), map![ assert_eq!(pod_map_diff(&a, &b), StateDiff(map![
x!(2) => AccountDiff{ x!(2) => AccountDiff{
balance: Diff::Born(x!(69)), balance: Diff::Born(x!(69)),
nonce: Diff::Born(x!(0)), nonce: Diff::Born(x!(0)),
code: Diff::Born(vec![]), code: Diff::Born(vec![]),
storage: map![], storage: map![],
} }
]); ]));
assert_eq!(pod_map_diff(&b, &a), map![ assert_eq!(pod_map_diff(&b, &a), StateDiff(map![
x!(2) => AccountDiff{ x!(2) => AccountDiff{
balance: Diff::Died(x!(69)), balance: Diff::Died(x!(69)),
nonce: Diff::Died(x!(0)), nonce: Diff::Died(x!(0)),
code: Diff::Died(vec![]), code: Diff::Died(vec![]),
storage: map![], storage: map![],
} }
]); ]));
} }
#[test] #[test]
@ -204,14 +225,14 @@ fn state_diff_change_with_unchanged() {
storage: map![] storage: map![]
} }
]; ];
assert_eq!(pod_map_diff(&a, &b), map![ assert_eq!(pod_map_diff(&a, &b), StateDiff(map![
x!(1) => AccountDiff{ x!(1) => AccountDiff{
balance: Diff::Same, balance: Diff::Same,
nonce: Diff::Changed(x!(0), x!(1)), nonce: Diff::Changed(x!(0), x!(1)),
code: Diff::Same, code: Diff::Same,
storage: map![], storage: map![],
} }
]); ]));
} }
#[test] #[test]

View File

@ -50,7 +50,7 @@ impl Schedule {
exceptional_failed_code_deposit: efcd, exceptional_failed_code_deposit: efcd,
have_delegate_call: hdc, have_delegate_call: hdc,
stack_limit: 1024, stack_limit: 1024,
tier_step_gas: [0usize, 2, 3, 4, 5, 8, 10, 20], tier_step_gas: [0, 2, 3, 5, 8, 10, 20, 0],
exp_gas: 10, exp_gas: 10,
exp_byte_gas: 10, exp_byte_gas: 10,
sha3_gas: 30, sha3_gas: 30,

View File

@ -56,7 +56,7 @@ fn do_json_test(json_data: &[u8]) -> Vec<String> {
let our_post = s.to_pod_map(); let our_post = s.to_pod_map();
if fail_unless(s.root() == &post_state_root) { if fail_unless(s.root() == &post_state_root) {
println!("DIFF:\n{:?}", pod_map_diff(&post, &our_post)); println!("DIFF:\n{}", pod_map_diff(&post, &our_post));
} }
// TODO: Compare logs. // TODO: Compare logs.