4
4
import java .util .ArrayList ;
5
5
import java .util .Arrays ;
6
6
import java .util .List ;
7
+ import javax .annotation .Resource ;
7
8
import lombok .extern .slf4j .Slf4j ;
8
9
import org .junit .Assert ;
9
10
import org .junit .BeforeClass ;
12
13
import org .tron .common .utils .ByteArray ;
13
14
import org .tron .common .utils .ForkController ;
14
15
import org .tron .core .Constant ;
16
+ import org .tron .core .capsule .BytesCapsule ;
15
17
import org .tron .core .config .Parameter ;
16
18
import org .tron .core .config .Parameter .ForkBlockVersionEnum ;
17
19
import org .tron .core .config .args .Args ;
@@ -27,6 +29,11 @@ public class ProposalUtilTest extends BaseTest {
27
29
private static final String LONG_VALUE_ERROR =
28
30
"Bad chain parameter value, valid range is [0," + LONG_VALUE + "]" ;
29
31
32
+ @ Resource
33
+ private DynamicPropertiesStore dynamicPropertiesStore ;
34
+
35
+ ForkController forkUtils = ForkController .instance ();
36
+
30
37
/**
31
38
* Init .
32
39
*/
@@ -60,8 +67,6 @@ public void validProposalTypeCheck() throws ContractValidateException {
60
67
61
68
@ Test
62
69
public void validateCheck () {
63
- DynamicPropertiesStore dynamicPropertiesStore = null ;
64
- ForkController forkUtils = ForkController .instance ();
65
70
long invalidValue = -1 ;
66
71
67
72
try {
@@ -328,6 +333,66 @@ public void validateCheck() {
328
333
e .getMessage ());
329
334
}
330
335
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
+
331
396
forkUtils .getManager ().getDynamicPropertiesStore ()
332
397
.statsByVersion (ForkBlockVersionEnum .ENERGY_LIMIT .getValue (), stats );
333
398
forkUtils .reset ();
0 commit comments