@@ -4,16 +4,17 @@ use crate::mock::pallet_mock_version_store::MockPreviousBundleAndExecutionReceip
44use crate :: mock:: {
55 Balance , Block , BlockNumber , BlockTreePruningDepth , DOMAIN_ID , Domains , Hash ,
66 MockBundleAndExecutionReceiptVersion , MockBundleVersion , MockExecutionReceiptVersion ,
7- RuntimeCall , System , Test ,
7+ RuntimeCall , StakeEpochDuration , System , Test ,
88} ;
9+ use crate :: pallet:: DomainStakingSummary ;
910use crate :: runtime_registry:: ScheduledRuntimeUpgrade ;
1011use crate :: staking_epoch:: do_finalize_domain_current_epoch;
1112use crate :: {
1213 self as pallet_domains, BalanceOf , BlockTree , BlockTreeNodes , BundleError , Config ,
1314 ConsensusBlockHash , DomainBlockNumberFor , DomainHashingFor , DomainRegistry ,
1415 DomainRuntimeUpgradeRecords , DomainRuntimeUpgrades , ExecutionInbox , ExecutionReceiptOf ,
15- FraudProofError , HeadDomainNumber , HeadReceiptNumber , NextDomainId , OperatorConfig ,
16- RawOrigin as DomainOrigin , RuntimeRegistry , ScheduledRuntimeUpgrades ,
16+ FraudProofError , HeadDomainNumber , HeadReceiptNumber , NextDomainId , OperatorBundleCountInEpoch ,
17+ OperatorConfig , RawOrigin as DomainOrigin , RuntimeRegistry , ScheduledRuntimeUpgrades ,
1718} ;
1819use domain_runtime_primitives:: opaque:: Header as DomainHeader ;
1920use domain_runtime_primitives:: { BlockNumber as DomainBlockNumber , DEFAULT_EVM_CHAIN_ID } ;
@@ -635,6 +636,42 @@ fn test_basic_fraud_proof_processing() {
635636 }
636637}
637638
639+ #[ test]
640+ fn test_bundle_count_increments ( ) {
641+ let creator = 0u128 ;
642+ let operator = 0u64 ;
643+ let epoch_duration = StakeEpochDuration :: get ( ) ;
644+ let mut ext = new_test_ext_with_extensions ( ) ;
645+ ext. execute_with ( || {
646+ let domain_id = register_genesis_domain ( creator, 1 ) ;
647+ // extend block until epoch duration
648+ // Bundle count for operator must be equal to number of block extended
649+ let receipt = extend_block_tree_from_zero ( domain_id, operator, epoch_duration) ;
650+ let epoch_index = DomainStakingSummary :: < Test > :: get ( domain_id)
651+ . unwrap ( )
652+ . current_epoch_index ;
653+
654+ assert_eq ! (
655+ OperatorBundleCountInEpoch :: <Test >:: get( operator) ,
656+ // -1 here since first receipt is genesis and is created at the time of domain
657+ // instantiation
658+ epoch_duration as u64 - 1
659+ ) ;
660+
661+ // extend blocks to trigger epoch transition and should
662+ // reset operator bundle count.
663+ // + 2 here since extend block will extend one block and initialize another block.
664+ extend_block_tree ( domain_id, operator, epoch_duration + 2 , receipt) ;
665+ assert_eq ! ( OperatorBundleCountInEpoch :: <Test >:: get( operator) , 0 ) ;
666+ assert_eq ! (
667+ DomainStakingSummary :: <Test >:: get( domain_id)
668+ . unwrap( )
669+ . current_epoch_index,
670+ epoch_index + 1
671+ ) ;
672+ } ) ;
673+ }
674+
638675fn schedule_domain_runtime_upgrade < T : Config > (
639676 runtime_id : RuntimeId ,
640677 scheduled_at : BlockNumberFor < T > ,
0 commit comments