|
1 | 1 | package org.tron.core.actuator.utils; |
2 | 2 |
|
| 3 | +import static org.junit.Assert.assertEquals; |
| 4 | +import static org.junit.Assert.assertThrows; |
| 5 | + |
3 | 6 | import com.google.protobuf.ByteString; |
4 | 7 | import java.util.ArrayList; |
5 | 8 | import java.util.Arrays; |
|
11 | 14 | import org.junit.Assert; |
12 | 15 | import org.junit.BeforeClass; |
13 | 16 | import org.junit.Test; |
| 17 | +import org.junit.function.ThrowingRunnable; |
14 | 18 | import org.tron.common.BaseTest; |
15 | 19 | import org.tron.common.utils.ByteArray; |
16 | 20 | import org.tron.common.utils.ForkController; |
@@ -439,6 +443,8 @@ public void validateCheck() { |
439 | 443 |
|
440 | 444 | testAllowTvmBlobProposal(); |
441 | 445 |
|
| 446 | + testAllowMarketTransaction(); |
| 447 | + |
442 | 448 | testAllowTvmSelfdestructRestrictionProposal(); |
443 | 449 |
|
444 | 450 | forkUtils.getManager().getDynamicPropertiesStore() |
@@ -710,7 +716,51 @@ private void testAllowTvmSelfdestructRestrictionProposal() { |
710 | 716 | "[ALLOW_TVM_SELFDESTRUCT_RESTRICTION] has been valid, no need to propose again", |
711 | 717 | e.getMessage()); |
712 | 718 | } |
| 719 | + } |
| 720 | + |
| 721 | + private void testAllowMarketTransaction() { |
| 722 | + ThrowingRunnable off = () -> ProposalUtil.validator(dynamicPropertiesStore, forkUtils, |
| 723 | + ProposalType.ALLOW_MARKET_TRANSACTION.getCode(), 0); |
| 724 | + ThrowingRunnable open = () -> ProposalUtil.validator(dynamicPropertiesStore, forkUtils, |
| 725 | + ProposalType.ALLOW_MARKET_TRANSACTION.getCode(), 1); |
| 726 | + String err = "Bad chain parameter id [ALLOW_MARKET_TRANSACTION]"; |
| 727 | + |
| 728 | + ContractValidateException thrown = assertThrows(ContractValidateException.class, open); |
| 729 | + assertEquals(err, thrown.getMessage()); |
| 730 | + |
| 731 | + activateFork(ForkBlockVersionEnum.VERSION_4_1); |
| 732 | + |
| 733 | + try { |
| 734 | + open.run(); |
| 735 | + } catch (Throwable e) { |
| 736 | + Assert.fail(e.getMessage()); |
| 737 | + } |
| 738 | + |
| 739 | + thrown = assertThrows(ContractValidateException.class, off); |
| 740 | + assertEquals("This value[ALLOW_MARKET_TRANSACTION] is only allowed to be 1", |
| 741 | + thrown.getMessage()); |
| 742 | + |
| 743 | + activateFork(ForkBlockVersionEnum.VERSION_4_8_1); |
713 | 744 |
|
| 745 | + thrown = assertThrows(ContractValidateException.class, open); |
| 746 | + assertEquals(err, thrown.getMessage()); |
| 747 | + |
| 748 | + thrown = assertThrows(ContractValidateException.class, off); |
| 749 | + assertEquals(err, thrown.getMessage()); |
| 750 | + } |
| 751 | + |
| 752 | + private void activateFork(ForkBlockVersionEnum forkVersion) { |
| 753 | + byte[] stats = new byte[27]; |
| 754 | + Arrays.fill(stats, (byte) 1); |
| 755 | + forkUtils.getManager().getDynamicPropertiesStore() |
| 756 | + .statsByVersion(forkVersion.getValue(), stats); |
| 757 | + |
| 758 | + long maintenanceTimeInterval = forkUtils.getManager().getDynamicPropertiesStore() |
| 759 | + .getMaintenanceTimeInterval(); |
| 760 | + long hardForkTime = ((forkVersion.getHardForkTime() - 1) / maintenanceTimeInterval + 1) |
| 761 | + * maintenanceTimeInterval; |
| 762 | + forkUtils.getManager().getDynamicPropertiesStore() |
| 763 | + .saveLatestBlockHeaderTimestamp(hardForkTime + 1); |
714 | 764 | } |
715 | 765 |
|
716 | 766 | @Test |
|
0 commit comments