Skip to content

Commit

Permalink
test(pool): add tests for UREP-010 and UREP-020
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-miao committed Dec 5, 2023
1 parent 3c0be7f commit d679944
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion crates/pool/src/mempool/uo_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ impl UoPoolMetrics {
mod tests {
use std::collections::HashMap;

use ethers::types::H160;
use rundler_sim::{
EntityInfo, EntityInfos, MockPrechecker, MockSimulator, PrecheckError, PrecheckSettings,
PrecheckViolation, SimulationError, SimulationSettings, SimulationSuccess,
Expand Down Expand Up @@ -909,6 +910,26 @@ mod tests {
check_ops(pool.best_operations(1, 0).unwrap(), vec![replacement]);
}

#[tokio::test]
async fn too_many_ops_for_unstaked_sender() {
let mut ops = vec![];
let addr = H160::random();
for i in 0..5 {
ops.push(create_op(addr, i, 1))
}
let pool = create_pool(ops.clone());

for op in ops {
pool.add_operation(OperationOrigin::Local, op.op.clone())
.await
.unwrap();
}
assert!(pool
.add_operation(OperationOrigin::Local, ops[4].op.clone())

Check failure on line 928 in crates/pool/src/mempool/uo_pool.rs

View workflow job for this annotation

GitHub Actions / clippy

borrow of moved value: `ops`

error[E0382]: borrow of moved value: `ops` --> crates/pool/src/mempool/uo_pool.rs:928:52 | 915 | let mut ops = vec![]; | ------- move occurs because `ops` has type `std::vec::Vec<mempool::uo_pool::tests::OpWithErrors>`, which does not implement the `Copy` trait ... 922 | for op in ops { | --- `ops` moved due to this implicit call to `.into_iter()` ... 928 | .add_operation(OperationOrigin::Local, ops[4].op.clone()) | ^^^ value borrowed here after move | note: `std::iter::IntoIterator::into_iter` takes ownership of the receiver `self`, which moves `ops` --> /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/iter/traits/collect.rs:267:18 help: consider iterating over a slice of the `std::vec::Vec<mempool::uo_pool::tests::OpWithErrors>`'s content to avoid moving into the `for` loop | 922 | for op in &ops { | +
.await
.is_err());
}

#[derive(Clone, Debug)]
struct OpWithErrors {
op: UserOperation,
Expand Down Expand Up @@ -973,7 +994,7 @@ mod tests {
sim_settings: SimulationSettings::default(),
mempool_channel_configs: HashMap::new(),
num_shards: 1,
same_sender_mempool_count: 16,
same_sender_mempool_count: 4,
throttled_entity_mempool_count: 4,
throttled_entity_live_blocks: 10,
};
Expand Down

0 comments on commit d679944

Please sign in to comment.