Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SWvheerden committed Dec 11, 2024
1 parent e783167 commit 4c99216
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/sharechain/p2chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,8 @@ impl P2Chain {

#[cfg(test)]
mod test {
use std::cmp;

use tari_core::{
blocks::{Block, BlockHeader},
proof_of_work::{Difficulty, DifficultyAdjustment},
Expand Down Expand Up @@ -684,8 +686,9 @@ mod test {
prev_block = Some(block.clone());

chain.add_block_to_chain(block.clone()).unwrap();
assert_eq!(chain.get_max_chain_length() as u64, cmp::min(i, 10));
assert_eq!(chain.lowest_chain_level_height().unwrap(), i.saturating_sub(10));
}
// 0..9 blocks should have been trimmed out

for i in 0..70 {
assert!(chain.level_at_height(i).is_none());
Expand Down Expand Up @@ -957,7 +960,7 @@ mod test {

let mut prev_block = None;
let mut tari_block = Block::new(BlockHeader::new(0), AggregateBody::empty());
for i in 0..5 {
for i in 0..20 {
tari_block.header.nonce = i;
let address = new_random_address();
let block = P2BlockBuilder::new(prev_block.as_ref())
Expand Down Expand Up @@ -999,7 +1002,7 @@ mod test {
chain.add_block_to_chain(block.clone()).unwrap();

let level = chain.get_tip().unwrap();
assert_eq!(level.height, 4);
assert_eq!(level.height, 19);

let address = new_random_address();
let block = P2BlockBuilder::new(prev_block.as_ref())
Expand All @@ -1023,8 +1026,13 @@ mod test {

chain.add_block_to_chain(block.clone()).unwrap();

let level = chain.get_tip().unwrap();
assert_eq!(level.height, 4);
assert_eq!(chain.get_height(), 19);
assert_eq!(chain.get_max_chain_length() as u64, 10);
assert_eq!(chain.lowest_chain_level_height().unwrap(), 9);

// let see if those higher blocks are also there
assert!(chain.levels.contains_key(&2000));
assert!(chain.levels.contains_key(&20000));
}

#[test]
Expand Down

0 comments on commit 4c99216

Please sign in to comment.