From 12116f7f568083c0d46ae10d4b728bf475510abb Mon Sep 17 00:00:00 2001 From: evalir Date: Fri, 27 Jun 2025 11:34:13 +0200 Subject: [PATCH] chore(sim): add simple bundle test --- crates/sim/src/cache.rs | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/crates/sim/src/cache.rs b/crates/sim/src/cache.rs index 1be9528b..b0746cf3 100644 --- a/crates/sim/src/cache.rs +++ b/crates/sim/src/cache.rs @@ -214,7 +214,7 @@ impl CacheInner { #[cfg(test)] mod test { - use alloy::primitives::b256; + use alloy::{eips::Encodable2718, primitives::b256}; use super::*; @@ -266,6 +266,43 @@ mod test { assert_eq!(cache.get(2), None); } + #[test] + fn test_cache_with_bundles() { + let items = vec![ + invalid_bundle_with_score(100, 1, "fbcbb9ce-2bef-4587-9c5f-61f606ca0a1a".to_string()), + invalid_bundle_with_score(100, 2, "39637ce4-5f33-4eb6-8893-8cc325a6cca3".to_string()), + invalid_bundle_with_score(100, 3, "1c008717-b187-4e53-9601-25435f5fe8b7".to_string()), + ]; + + let cache = SimCache::with_capacity(2); + + cache.add_bundles(items.clone(), 0).unwrap(); + + assert_eq!(cache.len(), 2); + assert_eq!(cache.get(300), Some(items[2].clone().try_into().unwrap())); + assert_eq!(cache.get(200), Some(items[1].clone().try_into().unwrap())); + assert_eq!(cache.get(100), None); + } + + fn invalid_bundle_with_score( + gas_limit: u64, + mpfpg: u128, + replacement_uuid: String, + ) -> signet_bundle::SignetEthBundle { + let tx = invalid_tx_with_score(gas_limit, mpfpg); + signet_bundle::SignetEthBundle { + bundle: alloy::rpc::types::mev::EthSendBundle { + txs: vec![tx.encoded_2718().into()], + block_number: 1, + min_timestamp: Some(2), + max_timestamp: Some(3), + replacement_uuid: Some(replacement_uuid), + ..Default::default() + }, + host_fills: None, + } + } + fn invalid_tx_with_score(gas_limit: u64, mpfpg: u128) -> alloy::consensus::TxEnvelope { let tx = build_alloy_tx(gas_limit, mpfpg);