@@ -433,6 +433,8 @@ public void validateCheck() {
433433
434434 testEnergyAdjustmentProposal ();
435435
436+ testConsensusLogicOptimizationProposal ();
437+
436438 forkUtils .getManager ().getDynamicPropertiesStore ()
437439 .statsByVersion (ForkBlockVersionEnum .ENERGY_LIMIT .getValue (), stats );
438440 forkUtils .reset ();
@@ -500,6 +502,55 @@ private void testEnergyAdjustmentProposal() {
500502 }
501503 }
502504
505+ private void testConsensusLogicOptimizationProposal () {
506+ try {
507+ ProposalUtil .validator (dynamicPropertiesStore , forkUtils ,
508+ ProposalType .CONSENSUS_LOGIC_OPTIMIZATION .getCode (), 1 );
509+ Assert .fail ();
510+ } catch (ContractValidateException e ) {
511+ Assert .assertEquals (
512+ "Bad chain parameter id [CONSENSUS_LOGIC_OPTIMIZATION]" ,
513+ e .getMessage ());
514+ }
515+
516+ long maintenanceTimeInterval = forkUtils .getManager ().getDynamicPropertiesStore ()
517+ .getMaintenanceTimeInterval ();
518+
519+ long hardForkTime =
520+ ((ForkBlockVersionEnum .VERSION_4_8_0 .getHardForkTime () - 1 ) / maintenanceTimeInterval + 1 )
521+ * maintenanceTimeInterval ;
522+ forkUtils .getManager ().getDynamicPropertiesStore ()
523+ .saveLatestBlockHeaderTimestamp (hardForkTime + 1 );
524+
525+ byte [] stats = new byte [27 ];
526+ Arrays .fill (stats , (byte ) 1 );
527+ forkUtils .getManager ().getDynamicPropertiesStore ()
528+ .statsByVersion (ForkBlockVersionEnum .VERSION_4_8_0 .getValue (), stats );
529+
530+ // Should fail because the proposal value is invalid
531+ try {
532+ ProposalUtil .validator (dynamicPropertiesStore , forkUtils ,
533+ ProposalType .CONSENSUS_LOGIC_OPTIMIZATION .getCode (), 2 );
534+ Assert .fail ();
535+ } catch (ContractValidateException e ) {
536+ Assert .assertEquals (
537+ "This value[CONSENSUS_LOGIC_OPTIMIZATION] is only allowed to be 1" ,
538+ e .getMessage ());
539+ }
540+
541+ dynamicPropertiesStore .saveConsensusLogicOptimization (1 );
542+ try {
543+ ProposalUtil .validator (dynamicPropertiesStore , forkUtils ,
544+ ProposalType .CONSENSUS_LOGIC_OPTIMIZATION .getCode (), 1 );
545+ Assert .fail ();
546+ } catch (ContractValidateException e ) {
547+ Assert .assertEquals (
548+ "[CONSENSUS_LOGIC_OPTIMIZATION] has been valid, no need to propose again" ,
549+ e .getMessage ());
550+ }
551+
552+ }
553+
503554 @ Test
504555 public void blockVersionCheck () {
505556 for (ForkBlockVersionEnum forkVersion : ForkBlockVersionEnum .values ()) {
0 commit comments