Skip to content

Commit

Permalink
fix(tests): submit withdrawal edge case
Browse files Browse the repository at this point in the history
If withdrawal is still in queue for a while and rpc submitter holds the
mem pool lock, withdrawal may be pushed to mem block. Because produce
block fn will refresh mem block by default, withdrawal will be included
in block.

Provide new `produce_block_and_refresh_mem_pool` fn to skip refresh mem
pool when produce new block.
  • Loading branch information
zeroqn committed Jul 28, 2022
1 parent bada602 commit 3d54888
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
19 changes: 18 additions & 1 deletion crates/tests/src/testing_tool/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,31 @@ impl TestChain {
&mut self,
deposit_requests: Vec<DepositRequest>,
withdrawals: Vec<WithdrawalRequestExtra>,
) -> anyhow::Result<()> {
self.produce_block_and_refresh_mem_pool(deposit_requests, withdrawals, true)
.await
}

pub async fn produce_block_and_refresh_mem_pool(
&mut self,
deposit_requests: Vec<DepositRequest>,
withdrawals: Vec<WithdrawalRequestExtra>,
refresh_mem_pool: bool,
) -> anyhow::Result<()> {
let rollup_cell = CellOutput::new_builder()
.type_(Some(self.rollup_type_script.clone()).pack())
.build();

let block_result = {
let mut mem_pool = self.mem_pool().await;
construct_block(&self.inner, &mut mem_pool, deposit_requests.clone()).await?
construct_block_with_timestamp(
&self.inner,
&mut mem_pool,
deposit_requests.clone(),
0,
refresh_mem_pool,
)
.await?
};

self.l1_committed_block_number += 1;
Expand Down
12 changes: 3 additions & 9 deletions crates/tests/src/tests/rpc_server/submit_withdrawal_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,16 @@ async fn test_submit_withdrawal_request() {
// Expect rpc error since we don't configure valid rpc url
assert!(err.to_string().contains("get_cells error"));

let withdrawal_hash = rpc_server
rpc_server
.submit_withdrawal_request_finalized_custodian_unchecked(&withdrawal)
.await
.unwrap();

let is_in_queue = rpc_server
.is_request_in_queue(withdrawal_hash)
chain
.produce_block_and_refresh_mem_pool(vec![], vec![], false)
.await
.unwrap();

if !is_in_queue {
chain.produce_block(vec![], vec![withdrawal]).await.unwrap();
} else {
chain.produce_block(vec![], vec![]).await.unwrap();
}

let snap = mem_pool_state.load();
let state = snap.state().unwrap();
let balance_after_withdrawal = state
Expand Down

0 comments on commit 3d54888

Please sign in to comment.