diff --git a/actuator/src/main/java/org/tron/core/utils/ProposalUtil.java b/actuator/src/main/java/org/tron/core/utils/ProposalUtil.java index 6df6ba80a80..d7e2f1c0949 100644 --- a/actuator/src/main/java/org/tron/core/utils/ProposalUtil.java +++ b/actuator/src/main/java/org/tron/core/utils/ProposalUtil.java @@ -356,7 +356,8 @@ public static void validator(DynamicPropertiesStore dynamicPropertiesStore, break; } case ALLOW_MARKET_TRANSACTION: { - if (!forkController.pass(ForkBlockVersionEnum.VERSION_4_1)) { + if (!forkController.pass(ForkBlockVersionEnum.VERSION_4_1) + || forkController.pass(ForkBlockVersionEnum.VERSION_4_8_1)) { throw new ContractValidateException( "Bad chain parameter id [ALLOW_MARKET_TRANSACTION]"); } diff --git a/framework/src/test/java/org/tron/core/actuator/utils/ProposalUtilTest.java b/framework/src/test/java/org/tron/core/actuator/utils/ProposalUtilTest.java index d83f7f14e29..2ca466fb4da 100644 --- a/framework/src/test/java/org/tron/core/actuator/utils/ProposalUtilTest.java +++ b/framework/src/test/java/org/tron/core/actuator/utils/ProposalUtilTest.java @@ -1,5 +1,8 @@ package org.tron.core.actuator.utils; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThrows; + import com.google.protobuf.ByteString; import java.util.ArrayList; import java.util.Arrays; @@ -11,6 +14,7 @@ import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.function.ThrowingRunnable; import org.tron.common.BaseTest; import org.tron.common.utils.ByteArray; import org.tron.common.utils.ForkController; @@ -439,6 +443,8 @@ public void validateCheck() { testAllowTvmBlobProposal(); + testAllowMarketTransaction(); + testAllowTvmSelfdestructRestrictionProposal(); forkUtils.getManager().getDynamicPropertiesStore() @@ -710,7 +716,51 @@ private void testAllowTvmSelfdestructRestrictionProposal() { "[ALLOW_TVM_SELFDESTRUCT_RESTRICTION] has been valid, no need to propose again", e.getMessage()); } + } + + private void testAllowMarketTransaction() { + ThrowingRunnable off = () -> ProposalUtil.validator(dynamicPropertiesStore, forkUtils, + ProposalType.ALLOW_MARKET_TRANSACTION.getCode(), 0); + ThrowingRunnable open = () -> ProposalUtil.validator(dynamicPropertiesStore, forkUtils, + ProposalType.ALLOW_MARKET_TRANSACTION.getCode(), 1); + String err = "Bad chain parameter id [ALLOW_MARKET_TRANSACTION]"; + + ContractValidateException thrown = assertThrows(ContractValidateException.class, open); + assertEquals(err, thrown.getMessage()); + + activateFork(ForkBlockVersionEnum.VERSION_4_1); + + try { + open.run(); + } catch (Throwable e) { + Assert.fail(e.getMessage()); + } + + thrown = assertThrows(ContractValidateException.class, off); + assertEquals("This value[ALLOW_MARKET_TRANSACTION] is only allowed to be 1", + thrown.getMessage()); + + activateFork(ForkBlockVersionEnum.VERSION_4_8_1); + thrown = assertThrows(ContractValidateException.class, open); + assertEquals(err, thrown.getMessage()); + + thrown = assertThrows(ContractValidateException.class, off); + assertEquals(err, thrown.getMessage()); + } + + private void activateFork(ForkBlockVersionEnum forkVersion) { + byte[] stats = new byte[27]; + Arrays.fill(stats, (byte) 1); + forkUtils.getManager().getDynamicPropertiesStore() + .statsByVersion(forkVersion.getValue(), stats); + + long maintenanceTimeInterval = forkUtils.getManager().getDynamicPropertiesStore() + .getMaintenanceTimeInterval(); + long hardForkTime = ((forkVersion.getHardForkTime() - 1) / maintenanceTimeInterval + 1) + * maintenanceTimeInterval; + forkUtils.getManager().getDynamicPropertiesStore() + .saveLatestBlockHeaderTimestamp(hardForkTime + 1); } @Test