Test.
This commit is contained in:
parent
039c0056bc
commit
6933bb971b
@ -874,6 +874,44 @@ mod tests {
|
|||||||
assert_eq!(bc.ancestry_iter(block_hashes[0].clone()).unwrap().collect::<Vec<_>>(), block_hashes)
|
assert_eq!(bc.ancestry_iter(block_hashes[0].clone()).unwrap().collect::<Vec<_>>(), block_hashes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[cfg_attr(feature="dev", allow(cyclomatic_complexity))]
|
||||||
|
fn test_find_uncles() {
|
||||||
|
let mut canon_chain = ChainGenerator::default();
|
||||||
|
let mut finalizer = BlockFinalizer::default();
|
||||||
|
let genesis = canon_chain.generate(&mut finalizer).unwrap();
|
||||||
|
let b1b = canon_chain.fork(1).generate(&mut finalizer.fork()).unwrap();
|
||||||
|
let b1a = canon_chain.generate(&mut finalizer).unwrap();
|
||||||
|
let b2b = canon_chain.fork(1).generate(&mut finalizer.fork()).unwrap();
|
||||||
|
let b2a = canon_chain.generate(&mut finalizer).unwrap();
|
||||||
|
let b3b = canon_chain.fork(1).generate(&mut finalizer.fork()).unwrap();
|
||||||
|
let b3a = canon_chain.generate(&mut finalizer).unwrap();
|
||||||
|
let b4b = canon_chain.fork(1).generate(&mut finalizer.fork()).unwrap();
|
||||||
|
let b4a = canon_chain.generate(&mut finalizer).unwrap();
|
||||||
|
let b5b = canon_chain.fork(1).generate(&mut finalizer.fork()).unwrap();
|
||||||
|
let b5a = canon_chain.generate(&mut finalizer).unwrap();
|
||||||
|
|
||||||
|
let temp = RandomTempPath::new();
|
||||||
|
let bc = BlockChain::new(BlockChainConfig::default(), &genesis, temp.as_path());
|
||||||
|
bc.insert_block(&b1a, vec![]);
|
||||||
|
bc.insert_block(&b1b, vec![]);
|
||||||
|
bc.insert_block(&b2a, vec![]);
|
||||||
|
bc.insert_block(&b2b, vec![]);
|
||||||
|
bc.insert_block(&b3a, vec![]);
|
||||||
|
bc.insert_block(&b3b, vec![]);
|
||||||
|
bc.insert_block(&b4a, vec![]);
|
||||||
|
bc.insert_block(&b4b, vec![]);
|
||||||
|
bc.insert_block(&b5a, vec![]);
|
||||||
|
bc.insert_block(&b5b, vec![]);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
[&b4b, &b3b, &b2b].iter().map(|b| BlockView::new(b).header()).collect::<Vec<_>>(),
|
||||||
|
bc.find_uncle_headers(&BlockView::new(&b4a).header_view().sha3(), 3).unwrap()
|
||||||
|
);
|
||||||
|
|
||||||
|
// TODO: insert block that already includes one of them as an uncle to check it's not allowed.
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg_attr(feature="dev", allow(cyclomatic_complexity))]
|
#[cfg_attr(feature="dev", allow(cyclomatic_complexity))]
|
||||||
fn test_small_fork() {
|
fn test_small_fork() {
|
||||||
|
@ -29,7 +29,7 @@ pub type BlockNumber = u64;
|
|||||||
/// which is non-specific.
|
/// which is non-specific.
|
||||||
///
|
///
|
||||||
/// Doesn't do all that much on its own.
|
/// Doesn't do all that much on its own.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone, Eq)]
|
||||||
pub struct Header {
|
pub struct Header {
|
||||||
// TODO: make all private.
|
// TODO: make all private.
|
||||||
/// Parent hash.
|
/// Parent hash.
|
||||||
@ -70,6 +70,25 @@ pub struct Header {
|
|||||||
pub bare_hash: RefCell<Option<H256>>,
|
pub bare_hash: RefCell<Option<H256>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl PartialEq for Header {
|
||||||
|
fn eq(&self, c: &Header) -> bool {
|
||||||
|
self.parent_hash == c.parent_hash &&
|
||||||
|
self.timestamp == c.timestamp &&
|
||||||
|
self.number == c.number &&
|
||||||
|
self.author == c.author &&
|
||||||
|
self.transactions_root == c.transactions_root &&
|
||||||
|
self.uncles_hash == c.uncles_hash &&
|
||||||
|
self.extra_data == c.extra_data &&
|
||||||
|
self.state_root == c.state_root &&
|
||||||
|
self.receipts_root == c.receipts_root &&
|
||||||
|
self.log_bloom == c.log_bloom &&
|
||||||
|
self.gas_used == c.gas_used &&
|
||||||
|
self.gas_limit == c.gas_limit &&
|
||||||
|
self.difficulty == c.difficulty &&
|
||||||
|
self.seal == c.seal
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Default for Header {
|
impl Default for Header {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Header {
|
Header {
|
||||||
|
Loading…
Reference in New Issue
Block a user