Skip to content

Commit

Permalink
tests: fix test_restore_mem_pool_pending_withdrawal test
Browse files Browse the repository at this point in the history
  • Loading branch information
jjyr committed May 24, 2022
1 parent aeb43e7 commit b66a149
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions crates/tests/src/tests/restore_mem_pool_pending_withdrawal.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::HashMap;
use std::collections::{HashMap, HashSet};
use std::time::Duration;

use crate::testing_tool::chain::{build_sync_tx, construct_block, restart_chain, setup_chain};
Expand Down Expand Up @@ -170,10 +170,30 @@ async fn test_restore_mem_pool_pending_withdrawal() {
let mem_pool = mem_pool.lock().await;

let mem_block = mem_pool.mem_block();
assert_eq!(mem_block.withdrawals().len(), mem_block_withdrawals.len());
assert_eq!(
mem_block.withdrawals().len(),
mem_block_withdrawals.len() + pending_withdrawals.len(),
"Consumed withdrawals"
);
assert!(
mem_block
.withdrawals()
.iter()
.take(mem_block_withdrawals.len())
.cloned()
.collect::<HashSet<H256>>()
.is_superset(
&mem_block_withdrawals
.iter()
.map(|w| w.hash().into())
.collect::<HashSet<H256>>()
),
"All saved withdrawals should in the mem block after restart"
);
assert_eq!(
mem_block.state_checkpoints().len(),
mem_block_withdrawals.len()
mem_block.withdrawals().len(),
"number of state checkpoints should be equal to the withdrawals"
);
}

Expand All @@ -195,6 +215,7 @@ async fn test_restore_mem_pool_pending_withdrawal() {
let block_withdrawals: Vec<_> = {
let withdrawals: HashMap<_, _> = mem_block_withdrawals
.into_iter()
.chain(pending_withdrawals.clone())
.map(|w| (w.hash(), w))
.collect();

Expand Down Expand Up @@ -229,9 +250,12 @@ async fn test_restore_mem_pool_pending_withdrawal() {
mem_pool.reset_mem_block().await.unwrap();

let mem_block = mem_pool.mem_block();
assert_eq!(mem_block.withdrawals().len(), pending_withdrawals.len());
assert_eq!(
mem_block.state_checkpoints().len(),
pending_withdrawals.len()
assert!(
mem_block.withdrawals().is_empty(),
"withdrawals is exhausted"
);
assert!(
mem_block.state_checkpoints().is_empty(),
"state checkpoints is empty"
);
}

0 comments on commit b66a149

Please sign in to comment.