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
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public class UpdateAccountPermissionInteractive {
41, 42, 43, 44, 45, 46, 48, 49, 52, 53, 54,
55, 56, 57, 58, 59
);
static final String DEFAULT_ACTIVE_OPERATIONS =
"7fff1fc0033ef30f000000000000000000000000000000000000000000000000";
public static final Map<String, String> operationsMap = new HashMap<>();

static {
Expand Down Expand Up @@ -86,9 +88,15 @@ public class UpdateAccountPermissionInteractive {
operationsMap.put("59", "Cancel Unstake");
}

private static String opLabel(int code) {
static String opLabel(int code) {
String name = operationsMap.get(String.valueOf(code));
return name != null ? name : "Unsupported/Disabled op " + code;
if (name != null) {
return name;
}
ContractType type = ContractType.forNumber(code);
return type != null
? "Unlisted op " + code + " (" + type.name() + ")"
: "Unknown op " + code;
}

private static String contractTypeName(int code) {
Expand All @@ -115,7 +123,7 @@ public String start(String address) {
active.setType(2);
active.setPermissionName("active");
active.setThreshold(1L);
active.setOperations("7fff1fc0033ef30f000000000000000000000000000000000000000000000000");
active.setOperations(DEFAULT_ACTIVE_OPERATIONS);
active.setKeys(Lists.newArrayList(new Key(address, 1L)));
activePermissions = Lists.newArrayList(active);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.tron.core.manager;

import static org.tron.common.utils.ByteUtil.hexStringToIntegerList;

import java.util.List;
import org.junit.Assert;
import org.junit.Test;

public class UpdateAccountPermissionInteractiveTest {

@Test
public void defaultActiveOperationsExcludeShieldedTransferContract() {
List<Integer> operations =
hexStringToIntegerList(UpdateAccountPermissionInteractive.DEFAULT_ACTIVE_OPERATIONS);

Assert.assertFalse(operations.contains(51));
Assert.assertTrue(operations.contains(49));
Assert.assertTrue(operations.contains(52));
}

@Test
public void opLabelDistinguishesUnlistedAndUnknownOperations() {
Assert.assertEquals("Transfer TRX", UpdateAccountPermissionInteractive.opLabel(1));
Assert.assertEquals("Unlisted op 51 (ShieldedTransferContract)",
UpdateAccountPermissionInteractive.opLabel(51));
Assert.assertEquals("Unknown op 255", UpdateAccountPermissionInteractive.opLabel(255));
}
}