@@ -472,6 +472,68 @@ fn key_hash_by_block_prunes_old_entries() {
472472 } ) ;
473473}
474474
475+ #[ test]
476+ fn submissions_pruned_after_ttl_window ( ) {
477+ new_test_ext ( ) . execute_with ( || {
478+ // This must match KEY_EPOCH_HISTORY in the pallet.
479+ const KEEP : u64 = 100 ;
480+ const TOTAL : u64 = KEEP + 5 ;
481+
482+ let pair = test_sr25519_pair ( ) ;
483+ let who: AccountId32 = pair. public ( ) . into ( ) ;
484+
485+ // Helper: create a submission at a specific block with a tagged commitment.
486+ let make_submission = |block : u64 , tag : & [ u8 ] | -> TestHash {
487+ System :: set_block_number ( block) ;
488+ let commitment: TestHash = <Test as frame_system:: Config >:: Hashing :: hash ( tag) ;
489+ let ciphertext_bytes = vec ! [ block as u8 ; 4 ] ;
490+ let ciphertext: BoundedVec < u8 , FrameConstU32 < 8192 > > =
491+ BoundedVec :: truncate_from ( ciphertext_bytes) ;
492+
493+ assert_ok ! ( MevShield :: submit_encrypted(
494+ RuntimeOrigin :: signed( who. clone( ) ) ,
495+ commitment,
496+ ciphertext. clone( ) ,
497+ ) ) ;
498+
499+ <Test as frame_system:: Config >:: Hashing :: hash_of ( & (
500+ who. clone ( ) ,
501+ commitment,
502+ & ciphertext,
503+ ) )
504+ } ;
505+
506+ // With n = TOTAL and depth = KEEP, prune_before = n - KEEP = 5.
507+ let stale_block1: u64 = 1 ; // < 5, should be pruned
508+ let stale_block2: u64 = 4 ; // < 5, should be pruned
509+ let keep_block1: u64 = 5 ; // == prune_before, should be kept
510+ let keep_block2: u64 = TOTAL ; // latest, should be kept
511+
512+ let id_stale1 = make_submission ( stale_block1, b"stale-1" ) ;
513+ let id_stale2 = make_submission ( stale_block2, b"stale-2" ) ;
514+ let id_keep1 = make_submission ( keep_block1, b"keep-1" ) ;
515+ let id_keep2 = make_submission ( keep_block2, b"keep-2" ) ;
516+
517+ // Sanity: all are present before pruning.
518+ assert ! ( Submissions :: <Test >:: get( id_stale1) . is_some( ) ) ;
519+ assert ! ( Submissions :: <Test >:: get( id_stale2) . is_some( ) ) ;
520+ assert ! ( Submissions :: <Test >:: get( id_keep1) . is_some( ) ) ;
521+ assert ! ( Submissions :: <Test >:: get( id_keep2) . is_some( ) ) ;
522+
523+ // Run on_initialize at block TOTAL, triggering TTL pruning over Submissions.
524+ let n_final: TestBlockNumber = TOTAL . saturated_into ( ) ;
525+ MevShield :: on_initialize ( n_final) ;
526+
527+ // Submissions with submitted_in < prune_before (5) should be gone.
528+ assert ! ( Submissions :: <Test >:: get( id_stale1) . is_none( ) ) ;
529+ assert ! ( Submissions :: <Test >:: get( id_stale2) . is_none( ) ) ;
530+
531+ // Submissions at or after prune_before should remain.
532+ assert ! ( Submissions :: <Test >:: get( id_keep1) . is_some( ) ) ;
533+ assert ! ( Submissions :: <Test >:: get( id_keep2) . is_some( ) ) ;
534+ } ) ;
535+ }
536+
475537#[ test]
476538fn validate_unsigned_accepts_local_source_for_execute_revealed ( ) {
477539 new_test_ext ( ) . execute_with ( || {
0 commit comments