Skip to content

Commit 9b9e819

Browse files
committed
Add test for only one proof in queue
1 parent 26328ec commit 9b9e819

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

crates/batcher/src/types/batch_queue.rs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,70 @@ mod test {
797797
);
798798
}
799799

800+
#[test]
801+
fn batch_finalization_algorithm_works_single_high_fee_proof() {
802+
// Test the scenario: 1 proof with high fee that should be viable
803+
let proof_generator_addr = Address::random();
804+
let payment_service_addr = Address::random();
805+
let sender_addr = Address::random();
806+
let bytes_for_verification_data = vec![42_u8; 10];
807+
let dummy_signature = Signature {
808+
r: U256::from(1),
809+
s: U256::from(2),
810+
v: 3,
811+
};
812+
let verification_data = VerificationData {
813+
proving_system: ProvingSystemId::Risc0,
814+
proof: bytes_for_verification_data.clone(),
815+
pub_input: Some(bytes_for_verification_data.clone()),
816+
verification_key: Some(bytes_for_verification_data.clone()),
817+
vm_program_code: Some(bytes_for_verification_data),
818+
proof_generator_addr,
819+
};
820+
let chain_id = U256::from(42);
821+
822+
// Single entry with very high fee - should definitely be viable
823+
let nonce = U256::from(1);
824+
let high_max_fee = U256::from(1_000_000_000_000_000_000u128); // Very high fee - 1 ETH
825+
let nonced_verification_data = NoncedVerificationData::new(
826+
verification_data,
827+
nonce,
828+
high_max_fee,
829+
chain_id,
830+
payment_service_addr,
831+
);
832+
let vd_commitment: VerificationDataCommitment = nonced_verification_data.clone().into();
833+
let entry = BatchQueueEntry::new_for_testing(
834+
nonced_verification_data,
835+
vd_commitment,
836+
dummy_signature,
837+
sender_addr,
838+
);
839+
let batch_priority = BatchQueueEntryPriority::new(high_max_fee, nonce);
840+
841+
let mut batch_queue = BatchQueue::new();
842+
batch_queue.push(entry, batch_priority);
843+
844+
let gas_price = U256::from(10_000_000_000u64); // 10 gwei gas price
845+
let mut test_queue = batch_queue.clone();
846+
let finalized_batch = extract_batch_directly(
847+
&mut test_queue,
848+
gas_price,
849+
5000000, // Large byte size limit
850+
50, // Large proof quantity limit
851+
DEFAULT_CONSTANT_GAS_COST,
852+
);
853+
854+
// This should succeed and return the single proof
855+
assert!(finalized_batch.is_ok(), "Should successfully extract batch with single high-fee proof");
856+
let batch = finalized_batch.unwrap();
857+
assert_eq!(batch.len(), 1, "Batch should contain exactly 1 proof");
858+
assert_eq!(batch[0].nonced_verification_data.max_fee, high_max_fee);
859+
860+
// The queue should now be empty (no rejected entries to put back)
861+
assert_eq!(test_queue.len(), 0, "Queue should be empty after extracting the single viable proof");
862+
}
863+
800864
#[test]
801865
fn batch_finalization_algorithm_works_not_bigger_than_max_batch_proof_qty() {
802866
// The following information will be the same for each entry, it is just some dummy data to see

0 commit comments

Comments
 (0)