tests (and fixes)

This commit is contained in:
NikVolf 2016-07-05 12:23:56 +03:00
parent c96686620a
commit 8052824f3f
3 changed files with 58 additions and 16 deletions

View File

@ -94,14 +94,14 @@ mod test {
storage: map![], storage: map![],
} }
])); ]));
assert_eq!(super::diff_pod(&PodState::new(), &a), StateDiff(map![ assert_eq!(super::diff_pod(&PodState::new(), &a), StateDiff{ raw: map![
1.into() => AccountDiff{ 1.into() => AccountDiff{
balance: Diff::Born(69.into()), balance: Diff::Born(69.into()),
nonce: Diff::Born(0.into()), nonce: Diff::Born(0.into()),
code: Diff::Born(vec![]), code: Diff::Born(vec![]),
storage: map![], storage: map![],
} }
])); ]});
} }
#[test] #[test]
@ -111,22 +111,22 @@ mod test {
1.into() => PodAccount::new(69.into(), 0.into(), vec![], map![]), 1.into() => PodAccount::new(69.into(), 0.into(), vec![], map![]),
2.into() => PodAccount::new(69.into(), 0.into(), vec![], map![]) 2.into() => PodAccount::new(69.into(), 0.into(), vec![], map![])
]); ]);
assert_eq!(super::diff_pod(&a, &b), StateDiff(map![ assert_eq!(super::diff_pod(&a, &b), StateDiff { raw: map![
2.into() => AccountDiff{ 2.into() => AccountDiff{
balance: Diff::Born(69.into()), balance: Diff::Born(69.into()),
nonce: Diff::Born(0.into()), nonce: Diff::Born(0.into()),
code: Diff::Born(vec![]), code: Diff::Born(vec![]),
storage: map![], storage: map![],
} }
])); ]});
assert_eq!(super::diff_pod(&b, &a), StateDiff(map![ assert_eq!(super::diff_pod(&b, &a), StateDiff { raw: map![
2.into() => AccountDiff{ 2.into() => AccountDiff{
balance: Diff::Died(69.into()), balance: Diff::Died(69.into()),
nonce: Diff::Died(0.into()), nonce: Diff::Died(0.into()),
code: Diff::Died(vec![]), code: Diff::Died(vec![]),
storage: map![], storage: map![],
} }
])); ]});
} }
#[test] #[test]
@ -139,14 +139,14 @@ mod test {
1.into() => PodAccount::new(69.into(), 1.into(), vec![], map![]), 1.into() => PodAccount::new(69.into(), 1.into(), vec![], map![]),
2.into() => PodAccount::new(69.into(), 0.into(), vec![], map![]) 2.into() => PodAccount::new(69.into(), 0.into(), vec![], map![])
]); ]);
assert_eq!(super::diff_pod(&a, &b), StateDiff(map![ assert_eq!(super::diff_pod(&a, &b), StateDiff { raw: map![
1.into() => AccountDiff{ 1.into() => AccountDiff{
balance: Diff::Same, balance: Diff::Same,
nonce: Diff::Changed(0.into(), 1.into()), nonce: Diff::Changed(0.into(), 1.into()),
code: Diff::Same, code: Diff::Same,
storage: map![], storage: map![],
} }
])); ]});
} }
} }

View File

@ -16,7 +16,45 @@
//! Client RPC tests //! Client RPC tests
use nanoipc;
use std::sync::Arc;
use std::io::Write;
use std::sync::atomic::{Ordering, AtomicBool};
use client::{BlockChainClient, MiningBlockChainClient, Client, ClientConfig, BlockID, RemoteClient};
use block::IsBlock;
use tests::helpers::*;
use common::*;
use devtools::*;
use miner::Miner;
use crossbeam;
pub fn run_test_worker(scope: &crossbeam::Scope, stop: Arc<AtomicBool>, socket_path: &str) {
let socket_path = socket_path.to_owned();
scope.spawn(move || {
let client = Client::new(
ClientConfig::default(),
get_test_spec(),
dir.as_path(),
Arc::new(Miner::with_spec(get_test_spec())),
IoChannel::disconnected()).unwrap();
let mut worker = nanoipc::Worker::new(&Arc::new(client));
worker.add_reqrep(&socket_path).unwrap();
while !stop.load(Ordering::Relaxed) {
worker.poll();
}
});
}
#[test] #[test]
fn can_be_created() { fn can_be_created() {
crossbeam::scope(|scope| {
let stop_guard = StopGuard::new();
let socket_path = "ipc:///tmp/parity-client-rpc-10.ipc";
run_test_worker(scope, stop_guard.share(), socket_path);
let remote_client = nanoipc::init_client::<RemoteClient<_>>(socket_path).unwrap();
let non_existant = remote_client.block_header(BlockID::Number(188));
assert!(non_existant.is_none());
})
} }

View File

@ -120,7 +120,7 @@ mod tests {
from_block: BlockID::Earliest, from_block: BlockID::Earliest,
to_block: BlockID::Latest, to_block: BlockID::Latest,
address: None, address: None,
topics: [None, None, None, None] topics: vec![None, None, None, None],
}; };
let possibilities = none_filter.bloom_possibilities(); let possibilities = none_filter.bloom_possibilities();
@ -135,9 +135,11 @@ mod tests {
from_block: BlockID::Earliest, from_block: BlockID::Earliest,
to_block: BlockID::Latest, to_block: BlockID::Latest,
address: Some(vec![Address::from_str("b372018f3be9e171df0581136b59d2faf73a7d5d").unwrap()]), address: Some(vec![Address::from_str("b372018f3be9e171df0581136b59d2faf73a7d5d").unwrap()]),
topics: [ topics: vec![
Some(vec![H256::from_str("ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9").unwrap()]), Some(vec![H256::from_str("ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9").unwrap()]),
None, None, None None,
None,
None,
] ]
}; };
@ -151,10 +153,11 @@ mod tests {
from_block: BlockID::Earliest, from_block: BlockID::Earliest,
to_block: BlockID::Latest, to_block: BlockID::Latest,
address: Some(vec![Address::from_str("b372018f3be9e171df0581136b59d2faf73a7d5d").unwrap()]), address: Some(vec![Address::from_str("b372018f3be9e171df0581136b59d2faf73a7d5d").unwrap()]),
topics: [ topics: vec![
Some(vec![H256::from_str("ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9").unwrap()]), Some(vec![H256::from_str("ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9").unwrap()]),
Some(vec![H256::from_str("ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9").unwrap()]), Some(vec![H256::from_str("ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9").unwrap()]),
None, None None,
None,
] ]
}; };
@ -171,7 +174,7 @@ mod tests {
Address::from_str("b372018f3be9e171df0581136b59d2faf73a7d5d").unwrap(), Address::from_str("b372018f3be9e171df0581136b59d2faf73a7d5d").unwrap(),
Address::from_str("b372018f3be9e171df0581136b59d2faf73a7d5d").unwrap(), Address::from_str("b372018f3be9e171df0581136b59d2faf73a7d5d").unwrap(),
]), ]),
topics: [ topics: vec![
Some(vec![ Some(vec![
H256::from_str("ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9").unwrap(), H256::from_str("ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9").unwrap(),
H256::from_str("ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9").unwrap() H256::from_str("ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9").unwrap()
@ -197,10 +200,11 @@ mod tests {
from_block: BlockID::Earliest, from_block: BlockID::Earliest,
to_block: BlockID::Latest, to_block: BlockID::Latest,
address: Some(vec![Address::from_str("b372018f3be9e171df0581136b59d2faf73a7d5d").unwrap()]), address: Some(vec![Address::from_str("b372018f3be9e171df0581136b59d2faf73a7d5d").unwrap()]),
topics: [ topics: vec![
Some(vec![H256::from_str("ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9").unwrap()]), Some(vec![H256::from_str("ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9").unwrap()]),
Some(vec![H256::from_str("ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23fa").unwrap()]), Some(vec![H256::from_str("ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23fa").unwrap()]),
None, None None,
None,
] ]
}; };