Fix up tests, remove dead state-diff code
This commit is contained in:
parent
0620a03e56
commit
eed7d006f1
@ -14,8 +14,7 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use std::mem;
|
use std::collections::BTreeMap;
|
||||||
use std::collections::{BTreeMap, VecDeque};
|
|
||||||
use util::{U256, Address, H256, H2048, Bytes, Itertools};
|
use util::{U256, Address, H256, H2048, Bytes, Itertools};
|
||||||
use blockchain::TreeRoute;
|
use blockchain::TreeRoute;
|
||||||
use block_queue::BlockQueueInfo;
|
use block_queue::BlockQueueInfo;
|
||||||
|
@ -21,7 +21,6 @@ pub use env_info::*;
|
|||||||
pub use views::*;
|
pub use views::*;
|
||||||
pub use builtin::*;
|
pub use builtin::*;
|
||||||
pub use header::*;
|
pub use header::*;
|
||||||
pub use account::*;
|
|
||||||
pub use transaction::*;
|
pub use transaction::*;
|
||||||
pub use log_entry::*;
|
pub use log_entry::*;
|
||||||
pub use receipt::*;
|
pub use receipt::*;
|
||||||
|
@ -16,12 +16,11 @@
|
|||||||
|
|
||||||
//! Transaction Execution environment.
|
//! Transaction Execution environment.
|
||||||
use common::*;
|
use common::*;
|
||||||
use state::*;
|
use state::{State, Substate};
|
||||||
use engines::Engine;
|
use engines::Engine;
|
||||||
use types::executed::CallType;
|
use types::executed::CallType;
|
||||||
use evm::{self, Ext, Factory, Finalize};
|
use evm::{self, Ext, Factory, Finalize};
|
||||||
use externalities::*;
|
use externalities::*;
|
||||||
use substate::*;
|
|
||||||
use trace::{FlatTrace, Tracer, NoopTracer, ExecutiveTracer, VMTrace, VMTracer, ExecutiveVMTracer, NoopVMTracer};
|
use trace::{FlatTrace, Tracer, NoopTracer, ExecutiveTracer, VMTrace, VMTracer, ExecutiveVMTracer, NoopVMTracer};
|
||||||
use crossbeam;
|
use crossbeam;
|
||||||
pub use types::executed::{Executed, ExecutionResult};
|
pub use types::executed::{Executed, ExecutionResult};
|
||||||
@ -487,7 +486,7 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use common::*;
|
use common::*;
|
||||||
use evm::{Factory, VMType};
|
use evm::{Factory, VMType};
|
||||||
use substate::*;
|
use state::Substate;
|
||||||
use tests::helpers::*;
|
use tests::helpers::*;
|
||||||
use trace::trace;
|
use trace::trace;
|
||||||
use trace::{FlatTrace, Tracer, NoopTracer, ExecutiveTracer};
|
use trace::{FlatTrace, Tracer, NoopTracer, ExecutiveTracer};
|
||||||
|
@ -16,11 +16,10 @@
|
|||||||
|
|
||||||
//! Transaction Execution environment.
|
//! Transaction Execution environment.
|
||||||
use common::*;
|
use common::*;
|
||||||
use state::*;
|
use state::{State, Substate};
|
||||||
use engines::Engine;
|
use engines::Engine;
|
||||||
use executive::*;
|
use executive::*;
|
||||||
use evm::{self, Schedule, Ext, ContractCreateResult, MessageCallResult, Factory};
|
use evm::{self, Schedule, Ext, ContractCreateResult, MessageCallResult, Factory};
|
||||||
use substate::*;
|
|
||||||
use types::executed::CallType;
|
use types::executed::CallType;
|
||||||
use trace::{Tracer, VMTracer};
|
use trace::{Tracer, VMTracer};
|
||||||
|
|
||||||
@ -299,10 +298,9 @@ impl<'a, T, V> Ext for Externalities<'a, T, V> where T: 'a + Tracer, V: 'a + VMT
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use common::*;
|
use common::*;
|
||||||
use state::*;
|
|
||||||
use engines::Engine;
|
use engines::Engine;
|
||||||
use evm::{Ext};
|
use evm::Ext;
|
||||||
use substate::*;
|
use state::{State, Substate};
|
||||||
use tests::helpers::*;
|
use tests::helpers::*;
|
||||||
use devtools::GuardedTempResult;
|
use devtools::GuardedTempResult;
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -15,13 +15,12 @@
|
|||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use super::test_common::*;
|
use super::test_common::*;
|
||||||
use state::*;
|
use state::{State, Substate};
|
||||||
use executive::*;
|
use executive::*;
|
||||||
use engines::Engine;
|
use engines::Engine;
|
||||||
use evm;
|
use evm;
|
||||||
use evm::{Schedule, Ext, Factory, Finalize, VMType, ContractCreateResult, MessageCallResult};
|
use evm::{Schedule, Ext, Factory, Finalize, VMType, ContractCreateResult, MessageCallResult};
|
||||||
use externalities::*;
|
use externalities::*;
|
||||||
use substate::*;
|
|
||||||
use types::executed::CallType;
|
use types::executed::CallType;
|
||||||
use tests::helpers::*;
|
use tests::helpers::*;
|
||||||
use ethjson;
|
use ethjson;
|
||||||
|
@ -132,10 +132,8 @@ mod basic_types;
|
|||||||
mod env_info;
|
mod env_info;
|
||||||
mod pod_account;
|
mod pod_account;
|
||||||
mod state;
|
mod state;
|
||||||
mod account;
|
|
||||||
mod account_db;
|
mod account_db;
|
||||||
mod builtin;
|
mod builtin;
|
||||||
mod substate;
|
|
||||||
mod executive;
|
mod executive;
|
||||||
mod externalities;
|
mod externalities;
|
||||||
mod verification;
|
mod verification;
|
||||||
|
@ -15,8 +15,8 @@
|
|||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use util::*;
|
use util::*;
|
||||||
use account::*;
|
use state::Account;
|
||||||
use account_db::*;
|
use account_db::AccountDBMut;
|
||||||
use ethjson;
|
use ethjson;
|
||||||
use types::account_diff::*;
|
use types::account_diff::*;
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ impl StateProducer {
|
|||||||
let address_hash = H256::random();
|
let address_hash = H256::random();
|
||||||
let balance: usize = rng.gen();
|
let balance: usize = rng.gen();
|
||||||
let nonce: usize = rng.gen();
|
let nonce: usize = rng.gen();
|
||||||
let acc = ::account::Account::new_basic(balance.into(), nonce.into()).rlp();
|
let acc = ::state::Account::new_basic(balance.into(), nonce.into()).rlp();
|
||||||
trie.insert(&address_hash[..], &acc).unwrap();
|
trie.insert(&address_hash[..], &acc).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1496
ethcore/src/state.rs
1496
ethcore/src/state.rs
File diff suppressed because it is too large
Load Diff
1499
ethcore/src/state/mod.rs
Normal file
1499
ethcore/src/state/mod.rs
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,126 +0,0 @@
|
|||||||
// Copyright 2015, 2016 Ethcore (UK) Ltd.
|
|
||||||
// This file is part of Parity.
|
|
||||||
|
|
||||||
// Parity is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
|
|
||||||
// Parity is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
use util::*;
|
|
||||||
#[cfg(test)]
|
|
||||||
use pod_state::*;
|
|
||||||
use account_diff::*;
|
|
||||||
|
|
||||||
#[derive(Debug,Clone,PartialEq,Eq)]
|
|
||||||
/// Expression for the delta between two system states. Encoded the
|
|
||||||
/// delta of every altered account.
|
|
||||||
pub struct StateDiff (BTreeMap<Address, AccountDiff>);
|
|
||||||
|
|
||||||
impl StateDiff {
|
|
||||||
#[cfg(test)]
|
|
||||||
/// Calculate and return diff between `pre` state and `post` state.
|
|
||||||
pub fn diff_pod(pre: &PodState, post: &PodState) -> StateDiff {
|
|
||||||
StateDiff(pre.get().keys().merge(post.get().keys()).filter_map(|acc| AccountDiff::diff_pod(pre.get().get(acc), post.get().get(acc)).map(|d|(acc.clone(), d))).collect())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Display for StateDiff {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
for (add, acc) in &self.0 {
|
|
||||||
try!(write!(f, "{} {}: {}", acc.existance(), add, acc));
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Deref for StateDiff {
|
|
||||||
type Target = BTreeMap<Address, AccountDiff>;
|
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod test {
|
|
||||||
use common::*;
|
|
||||||
use pod_state::*;
|
|
||||||
use account_diff::*;
|
|
||||||
use pod_account::*;
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn create_delete() {
|
|
||||||
let a = PodState::from(map![ 1.into() => PodAccount::new(69.into(), 0.into(), vec![], map![]) ]);
|
|
||||||
assert_eq!(StateDiff::diff_pod(&a, &PodState::new()), StateDiff(map![
|
|
||||||
1.into() => AccountDiff{
|
|
||||||
balance: Diff::Died(69.into()),
|
|
||||||
nonce: Diff::Died(0.into()),
|
|
||||||
code: Diff::Died(vec![]),
|
|
||||||
storage: map![],
|
|
||||||
}
|
|
||||||
]));
|
|
||||||
assert_eq!(StateDiff::diff_pod(&PodState::new(), &a), StateDiff(map![
|
|
||||||
1.into() => AccountDiff{
|
|
||||||
balance: Diff::Born(69.into()),
|
|
||||||
nonce: Diff::Born(0.into()),
|
|
||||||
code: Diff::Born(vec![]),
|
|
||||||
storage: map![],
|
|
||||||
}
|
|
||||||
]));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn create_delete_with_unchanged() {
|
|
||||||
let a = PodState::from(map![ 1.into() => PodAccount::new(69.into(), 0.into(), vec![], map![]) ]);
|
|
||||||
let b = PodState::from(map![
|
|
||||||
1.into() => PodAccount::new(69.into(), 0.into(), vec![], map![]),
|
|
||||||
2.into() => PodAccount::new(69.into(), 0.into(), vec![], map![])
|
|
||||||
]);
|
|
||||||
assert_eq!(StateDiff::diff_pod(&a, &b), StateDiff(map![
|
|
||||||
2.into() => AccountDiff{
|
|
||||||
balance: Diff::Born(69.into()),
|
|
||||||
nonce: Diff::Born(0.into()),
|
|
||||||
code: Diff::Born(vec![]),
|
|
||||||
storage: map![],
|
|
||||||
}
|
|
||||||
]));
|
|
||||||
assert_eq!(StateDiff::diff_pod(&b, &a), StateDiff(map![
|
|
||||||
2.into() => AccountDiff{
|
|
||||||
balance: Diff::Died(69.into()),
|
|
||||||
nonce: Diff::Died(0.into()),
|
|
||||||
code: Diff::Died(vec![]),
|
|
||||||
storage: map![],
|
|
||||||
}
|
|
||||||
]));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn change_with_unchanged() {
|
|
||||||
let a = PodState::from(map![
|
|
||||||
1.into() => PodAccount::new(69.into(), 0.into(), vec![], map![]),
|
|
||||||
2.into() => PodAccount::new(69.into(), 0.into(), vec![], map![])
|
|
||||||
]);
|
|
||||||
let b = PodState::from(map![
|
|
||||||
1.into() => PodAccount::new(69.into(), 1.into(), vec![], map![]),
|
|
||||||
2.into() => PodAccount::new(69.into(), 0.into(), vec![], map![])
|
|
||||||
]);
|
|
||||||
assert_eq!(StateDiff::diff_pod(&a, &b), StateDiff(map![
|
|
||||||
1.into() => AccountDiff{
|
|
||||||
balance: Diff::Same,
|
|
||||||
nonce: Diff::Changed(0.into(), 1.into()),
|
|
||||||
code: Diff::Same,
|
|
||||||
storage: map![],
|
|
||||||
}
|
|
||||||
]));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user