Merge pull request #101 from gavofyork/gav

Tier step price.
This commit is contained in:
Marek Kotewicz 2016-01-13 23:56:43 +01:00
commit 5b52b19bb3
3 changed files with 40 additions and 19 deletions

View File

@ -54,13 +54,34 @@ impl AccountDiff {
}
}
/*impl Debug for AccountDiff {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:?}", PodAccount::from_account(self))
}
}*/
#[derive(Debug,Clone,PartialEq,Eq)]
pub struct StateDiff (BTreeMap<Address, AccountDiff>);
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> {
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 {
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]
@ -114,22 +135,22 @@ fn state_diff_create_delete() {
storage: map![]
}
];
assert_eq!(pod_map_diff(&a, &map![]), map![
assert_eq!(pod_map_diff(&a, &map![]), StateDiff(map![
x!(1) => AccountDiff{
balance: Diff::Died(x!(69)),
nonce: Diff::Died(x!(0)),
code: Diff::Died(vec![]),
storage: map![],
}
]);
assert_eq!(pod_map_diff(&map![], &a), map![
]));
assert_eq!(pod_map_diff(&map![], &a), StateDiff(map![
x!(1) => AccountDiff{
balance: Diff::Born(x!(69)),
nonce: Diff::Born(x!(0)),
code: Diff::Born(vec![]),
storage: map![],
}
]);
]));
}
#[test]
@ -156,22 +177,22 @@ fn state_diff_cretae_delete_with_unchanged() {
storage: map![]
}
];
assert_eq!(pod_map_diff(&a, &b), map![
assert_eq!(pod_map_diff(&a, &b), StateDiff(map![
x!(2) => AccountDiff{
balance: Diff::Born(x!(69)),
nonce: Diff::Born(x!(0)),
code: Diff::Born(vec![]),
storage: map![],
}
]);
assert_eq!(pod_map_diff(&b, &a), map![
]));
assert_eq!(pod_map_diff(&b, &a), StateDiff(map![
x!(2) => AccountDiff{
balance: Diff::Died(x!(69)),
nonce: Diff::Died(x!(0)),
code: Diff::Died(vec![]),
storage: map![],
}
]);
]));
}
#[test]
@ -204,14 +225,14 @@ fn state_diff_change_with_unchanged() {
storage: map![]
}
];
assert_eq!(pod_map_diff(&a, &b), map![
assert_eq!(pod_map_diff(&a, &b), StateDiff(map![
x!(1) => AccountDiff{
balance: Diff::Same,
nonce: Diff::Changed(x!(0), x!(1)),
code: Diff::Same,
storage: map![],
}
]);
]));
}
#[test]

View File

@ -50,7 +50,7 @@ impl Schedule {
exceptional_failed_code_deposit: efcd,
have_delegate_call: hdc,
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_byte_gas: 10,
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();
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.