44import java .util .ArrayList ;
55import java .util .Arrays ;
66import java .util .List ;
7+ import javax .annotation .Resource ;
78import lombok .extern .slf4j .Slf4j ;
89import org .junit .Assert ;
910import org .junit .BeforeClass ;
1213import org .tron .common .utils .ByteArray ;
1314import org .tron .common .utils .ForkController ;
1415import org .tron .core .Constant ;
16+ import org .tron .core .capsule .BytesCapsule ;
1517import org .tron .core .config .Parameter ;
1618import org .tron .core .config .Parameter .ForkBlockVersionEnum ;
1719import org .tron .core .config .args .Args ;
@@ -27,6 +29,11 @@ public class ProposalUtilTest extends BaseTest {
2729 private static final String LONG_VALUE_ERROR =
2830 "Bad chain parameter value, valid range is [0," + LONG_VALUE + "]" ;
2931
32+ @ Resource
33+ private DynamicPropertiesStore dynamicPropertiesStore ;
34+
35+ ForkController forkUtils = ForkController .instance ();
36+
3037 /**
3138 * Init .
3239 */
@@ -60,8 +67,6 @@ public void validProposalTypeCheck() throws ContractValidateException {
6067
6168 @ Test
6269 public void validateCheck () {
63- DynamicPropertiesStore dynamicPropertiesStore = null ;
64- ForkController forkUtils = ForkController .instance ();
6570 long invalidValue = -1 ;
6671
6772 try {
@@ -328,6 +333,66 @@ public void validateCheck() {
328333 e .getMessage ());
329334 }
330335
336+ try {
337+ ProposalUtil .validator (dynamicPropertiesStore , forkUtils ,
338+ ProposalType .ALLOW_OLD_REWARD_OPT .getCode (), 2 );
339+ Assert .fail ();
340+ } catch (ContractValidateException e ) {
341+ Assert .assertEquals (
342+ "Bad chain parameter id [ALLOW_OLD_REWARD_OPT]" ,
343+ e .getMessage ());
344+ }
345+ hardForkTime =
346+ ((ForkBlockVersionEnum .VERSION_4_7_4 .getHardForkTime () - 1 ) / maintenanceTimeInterval + 1 )
347+ * maintenanceTimeInterval ;
348+ forkUtils .getManager ().getDynamicPropertiesStore ()
349+ .saveLatestBlockHeaderTimestamp (hardForkTime + 1 );
350+ forkUtils .getManager ().getDynamicPropertiesStore ()
351+ .statsByVersion (ForkBlockVersionEnum .VERSION_4_7_4 .getValue (), stats );
352+ try {
353+ ProposalUtil .validator (dynamicPropertiesStore , forkUtils ,
354+ ProposalType .ALLOW_OLD_REWARD_OPT .getCode (), 2 );
355+ Assert .fail ();
356+ } catch (ContractValidateException e ) {
357+ Assert .assertEquals (
358+ "This value[ALLOW_OLD_REWARD_OPT] is only allowed to be 1" ,
359+ e .getMessage ());
360+ }
361+ try {
362+ ProposalUtil .validator (dynamicPropertiesStore , forkUtils ,
363+ ProposalType .ALLOW_OLD_REWARD_OPT .getCode (), 1 );
364+ Assert .fail ();
365+ } catch (ContractValidateException e ) {
366+ Assert .assertEquals (
367+ "[ALLOW_NEW_REWARD] proposal must be approved "
368+ + "before [ALLOW_OLD_REWARD_OPT] can be proposed" ,
369+ e .getMessage ());
370+ }
371+ dynamicPropertiesStore .saveCurrentCycleNumber (0 );
372+ dynamicPropertiesStore .saveNewRewardAlgorithmEffectiveCycle ();
373+ dynamicPropertiesStore .saveAllowNewReward (1 );
374+ try {
375+ ProposalUtil .validator (dynamicPropertiesStore , forkUtils ,
376+ ProposalType .ALLOW_OLD_REWARD_OPT .getCode (), 1 );
377+ Assert .fail ();
378+ } catch (ContractValidateException e ) {
379+ Assert .assertEquals (
380+ "no need old reward opt, ALLOW_NEW_REWARD from start cycle 1" ,
381+ e .getMessage ());
382+ }
383+ dynamicPropertiesStore .put ("NEW_REWARD_ALGORITHM_EFFECTIVE_CYCLE" .getBytes (),
384+ new BytesCapsule (ByteArray .fromLong (4000 )));
385+ dynamicPropertiesStore .saveAllowOldRewardOpt (1 );
386+ try {
387+ ProposalUtil .validator (dynamicPropertiesStore , forkUtils ,
388+ ProposalType .ALLOW_OLD_REWARD_OPT .getCode (), 1 );
389+ Assert .fail ();
390+ } catch (ContractValidateException e ) {
391+ Assert .assertEquals (
392+ "[ALLOW_OLD_REWARD_OPT] has been valid, no need to propose again" ,
393+ e .getMessage ());
394+ }
395+
331396 forkUtils .getManager ().getDynamicPropertiesStore ()
332397 .statsByVersion (ForkBlockVersionEnum .ENERGY_LIMIT .getValue (), stats );
333398 forkUtils .reset ();
0 commit comments