Skip to content

Commit def125e

Browse files
authored
Merge pull request #6499 from halibobo1205/fea/market
feat(*): disable market transaction
2 parents 114bbec + 9f932ec commit def125e

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

actuator/src/main/java/org/tron/core/utils/ProposalUtil.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,8 @@ public static void validator(DynamicPropertiesStore dynamicPropertiesStore,
356356
break;
357357
}
358358
case ALLOW_MARKET_TRANSACTION: {
359-
if (!forkController.pass(ForkBlockVersionEnum.VERSION_4_1)) {
359+
if (!forkController.pass(ForkBlockVersionEnum.VERSION_4_1)
360+
|| forkController.pass(ForkBlockVersionEnum.VERSION_4_8_1)) {
360361
throw new ContractValidateException(
361362
"Bad chain parameter id [ALLOW_MARKET_TRANSACTION]");
362363
}

framework/src/test/java/org/tron/core/actuator/utils/ProposalUtilTest.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package org.tron.core.actuator.utils;
22

3+
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertThrows;
5+
36
import com.google.protobuf.ByteString;
47
import java.util.ArrayList;
58
import java.util.Arrays;
@@ -11,6 +14,7 @@
1114
import org.junit.Assert;
1215
import org.junit.BeforeClass;
1316
import org.junit.Test;
17+
import org.junit.function.ThrowingRunnable;
1418
import org.tron.common.BaseTest;
1519
import org.tron.common.utils.ByteArray;
1620
import org.tron.common.utils.ForkController;
@@ -439,6 +443,8 @@ public void validateCheck() {
439443

440444
testAllowTvmBlobProposal();
441445

446+
testAllowMarketTransaction();
447+
442448
testAllowTvmSelfdestructRestrictionProposal();
443449

444450
forkUtils.getManager().getDynamicPropertiesStore()
@@ -710,7 +716,51 @@ private void testAllowTvmSelfdestructRestrictionProposal() {
710716
"[ALLOW_TVM_SELFDESTRUCT_RESTRICTION] has been valid, no need to propose again",
711717
e.getMessage());
712718
}
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);
713744

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);
714764
}
715765

716766
@Test

0 commit comments

Comments
 (0)