Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion actuator/src/main/java/org/tron/core/utils/ProposalUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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]");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -439,6 +443,8 @@ public void validateCheck() {

testAllowTvmBlobProposal();

testAllowMarketTransaction();

testAllowTvmSelfdestructRestrictionProposal();

forkUtils.getManager().getDynamicPropertiesStore()
Expand Down Expand Up @@ -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);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there implicit version information here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bad chain parameter id [ALLOW_MARKET_TRANSACTION] since 4.8.1, like this?
I noticed that the previous notice lacked version information. Is the newly added version information meant to distinguish between versions before 4.1 and versions 4.8.1 and later?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s also fine to keep it as is now.

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
Expand Down