Skip to content

Commit

Permalink
Merge pull request tronprotocol#5498 from tronprotocol/release_v4.7.3
Browse files Browse the repository at this point in the history
  • Loading branch information
halibobo1205 authored Sep 15, 2023
2 parents 9f8cebd + b81a63e commit de23b55
Show file tree
Hide file tree
Showing 173 changed files with 835 additions and 677 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ private boolean handleException(Throwable e) {
private void dump() {
if (!isValid.get()) {
logger.info("bloomFilters is not valid.");
return;
}
FileUtil.createDirIfNotExists(this.cacheDir.toString());
logger.info("dump bloomFilters start.");
Expand Down
2 changes: 1 addition & 1 deletion common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ dependencies {
compile 'org.aspectj:aspectjrt:1.8.13'
compile 'org.aspectj:aspectjweaver:1.8.13'
compile 'org.aspectj:aspectjtools:1.8.13'
compile group: 'io.github.tronprotocol', name: 'libp2p', version: '1.2.0',{
compile group: 'com.github.tronprotocol', name: 'libp2p', version: 'test-v2.0.2',{
exclude group: 'io.grpc', module: 'grpc-context'
exclude group: 'io.grpc', module: 'grpc-core'
exclude group: 'io.grpc', module: 'grpc-netty'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private boolean isDisabled(String endpoint) {
disabled = disabledApiList.contains(endpoint.split("/")[2].toLowerCase());
}
} catch (Exception e) {
logger.error("check isDisabled except, endpoint={}, error is {}", endpoint, e.getMessage());
logger.warn("check isDisabled except, endpoint={}, {}", endpoint, e.getMessage());
}

return disabled;
Expand Down
15 changes: 6 additions & 9 deletions framework/src/main/java/org/tron/core/services/http/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.commons.lang3.StringUtils;
import org.bouncycastle.util.encoders.Hex;
import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.http.MimeTypes;
import org.eclipse.jetty.util.MultiMap;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.UrlEncoded;
Expand Down Expand Up @@ -78,8 +79,6 @@ public class Util {
public static final String FUNCTION_SELECTOR = "function_selector";
public static final String FUNCTION_PARAMETER = "parameter";
public static final String CALL_DATA = "data";
public static final String APPLICATION_FORM_URLENCODED = "application/x-www-form-urlencoded";
public static final String APPLICATION_JSON = "application/json";

public static String printTransactionFee(String transactionFee) {
JSONObject jsonObject = new JSONObject();
Expand Down Expand Up @@ -525,7 +524,6 @@ public static byte[] getAddress(HttpServletRequest request) throws Exception {

private static String checkGetParam(HttpServletRequest request, String key) throws Exception {
String method = request.getMethod();
String value = null;

if (HttpMethod.GET.toString().toUpperCase().equalsIgnoreCase(method)) {
return request.getParameter(key);
Expand All @@ -535,8 +533,10 @@ private static String checkGetParam(HttpServletRequest request, String key) thro
if (StringUtils.isBlank(contentType)) {
return null;
}
if (APPLICATION_JSON.toLowerCase().contains(contentType)) {
value = getRequestValue(request);
if (contentType.contains(MimeTypes.Type.FORM_ENCODED.asString())) {
return request.getParameter(key);
} else {
String value = getRequestValue(request);
if (StringUtils.isBlank(value)) {
return null;
}
Expand All @@ -545,13 +545,10 @@ private static String checkGetParam(HttpServletRequest request, String key) thro
if (jsonObject != null) {
return jsonObject.getString(key);
}
} else if (APPLICATION_FORM_URLENCODED.toLowerCase().contains(contentType)) {
return request.getParameter(key);
} else {
return null;
}
}
return value;
return null;
}

public static String getRequestValue(HttpServletRequest request) throws IOException {
Expand Down
28 changes: 17 additions & 11 deletions framework/src/test/java/org/tron/common/BaseTest.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package org.tron.common;

import com.google.protobuf.ByteString;
import java.io.File;
import java.io.IOException;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.ClassRule;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.tron.common.crypto.ECKey;
import org.tron.common.parameter.CommonParameter;
import org.tron.common.utils.FileUtil;
import org.tron.common.utils.Sha256Hash;
import org.tron.consensus.base.Param;
import org.tron.core.ChainBaseManager;
Expand All @@ -28,22 +29,27 @@
@DirtiesContext
public abstract class BaseTest {

protected static String dbPath;
@ClassRule
public static final TemporaryFolder temporaryFolder = new TemporaryFolder();

@Resource
protected Manager dbManager;
@Resource
protected ChainBaseManager chainBaseManager;


public static String dbPath() {
try {
return temporaryFolder.newFolder().toString();
} catch (IOException e) {
Assert.fail("create temp folder failed");
}
return null;
}

@AfterClass
public static void destroy() {
Args.clearParam();
if (StringUtils.isNotEmpty(dbPath)) {
if (FileUtil.deleteDir(new File(dbPath))) {
logger.info("Release resources successful.");
} else {
logger.info("Release resources failure.");
}
}
}

public Protocol.Block getSignedBlock(ByteString witness, long time, byte[] privateKey) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
package org.tron.common.config.args;

import java.io.File;
import java.io.IOException;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.tron.common.parameter.RateLimiterInitialization;
import org.tron.common.utils.FileUtil;
import org.tron.core.Constant;
import org.tron.core.config.args.Args;


public class ArgsTest {

private static final String dbPath = "output_arg_test";
@Rule
public final TemporaryFolder temporaryFolder = new TemporaryFolder();

@Before
public void init() {
Args.setParam(new String[] {"--output-directory", dbPath, "--p2p-disable", "true",
public void init() throws IOException {
Args.setParam(new String[] {"--output-directory",
temporaryFolder.newFolder().toString(), "--p2p-disable", "true",
"--debug"}, Constant.TEST_CONF);
}

@After
public void destroy() {
Args.clearParam();
FileUtil.deleteDir(new File(dbPath));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ public class InheritanceTest extends BaseTest {
private static boolean init;

static {
dbPath = "output_InheritanceTest";
Args.setParam(new String[]{"--output-directory", dbPath, "--debug"}, Constant.TEST_CONF);
Args.setParam(new String[]{"--output-directory", dbPath(), "--debug"}, Constant.TEST_CONF);
OWNER_ADDRESS = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ public class InternalTransactionComplexTest extends BaseTest {
private static boolean init;

static {
dbPath = "output_InternalTransactionComplexTest";
Args.setParam(new String[]{"--output-directory", dbPath, "--debug", "--support-constant"},
Args.setParam(new String[]{"--output-directory", dbPath(), "--debug", "--support-constant"},
Constant.TEST_CONF);
OWNER_ADDRESS = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ public class ProgramResultTest extends BaseTest {
private static boolean init;

static {
dbPath = "output_InternalTransactionComplexTest";
Args.setParam(new String[]{"--output-directory", dbPath, "--debug", "--support-constant"},
Args.setParam(new String[]{"--output-directory", dbPath(), "--debug", "--support-constant"},
Constant.TEST_CONF);
OWNER_ADDRESS = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc";
TRANSFER_TO = Wallet.getAddressPreFixString() + "548794500882809695a8a687866e76d4271a1abc";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public class RuntimeImplTest extends BaseTest {
private final long creatorTotalBalance = 3_000_000_000L;

static {
dbPath = "output_RuntimeImplTest";
Args.setParam(new String[]{"--output-directory", dbPath, "--debug"}, Constant.TEST_CONF);
Args.setParam(new String[]{"--output-directory", dbPath(), "--debug"}, Constant.TEST_CONF);
callerAddress = Hex
.decode(Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc");
creatorAddress = Hex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ public class RuntimeTransferComplexTest extends BaseTest {
private static boolean init;

static {
dbPath = "output_RuntimeTransferComplexTest";
Args.setParam(new String[]{"--output-directory", dbPath, "--debug"}, Constant.TEST_CONF);
Args.setParam(new String[]{"--output-directory", dbPath(), "--debug"}, Constant.TEST_CONF);
OWNER_ADDRESS = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc";
TRANSFER_TO = Wallet.getAddressPreFixString() + "548794500882809695a8a687866e76d4271a1abc";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,9 @@ public class BandWidthRuntimeOutOfTimeTest extends BaseTest {
private static boolean init;

static {
dbPath = "output_bandwidth_runtime_out_of_time_test";
Args.setParam(
new String[]{
"--output-directory", dbPath,
"--output-directory", dbPath(),
"--storage-db-directory", dbDirectory,
"--storage-index-directory", indexDirectory,
"-w",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,9 @@ public class BandWidthRuntimeOutOfTimeWithCheckTest extends BaseTest {
private static boolean init;

static {
dbPath = "output_bandwidth_runtime_out_of_time_with_check_test";
Args.setParam(
new String[]{
"--output-directory", dbPath,
"--output-directory", dbPath(),
"--storage-db-directory", dbDirectory,
"--storage-index-directory", indexDirectory,
"-w",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,9 @@ public class BandWidthRuntimeTest extends BaseTest {

@BeforeClass
public static void init() {
dbPath = "output_bandwidth_runtime_test";
Args.setParam(
new String[]{
"--output-directory", dbPath,
"--output-directory", dbPath(),
"--storage-db-directory", dbDirectory,
"--storage-index-directory", indexDirectory,
"-w"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,9 @@ public class BandWidthRuntimeWithCheckTest extends BaseTest {
private static boolean init;

static {
dbPath = "output_bandwidth_runtime_with_check_test";
Args.setParam(
new String[]{
"--output-directory", dbPath,
"--output-directory", dbPath(),
"--storage-db-directory", dbDirectory,
"--storage-index-directory", indexDirectory,
"-w"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ public class BatchSendTest extends BaseTest {
private static final AccountCapsule ownerCapsule;

static {
dbPath = "output_BatchSendTest";
Args.setParam(new String[]{"--output-directory", dbPath, "--debug"}, Constant.TEST_CONF);
Args.setParam(new String[]{"--output-directory", dbPath(), "--debug"}, Constant.TEST_CONF);
OWNER_ADDRESS = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc";
TRANSFER_TO = Wallet.getAddressPreFixString() + "548794500882809695a8a687866e76d4271a1abc";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ public class ChargeTest extends BaseTest {
private long totalBalance = 100_000_000_000_000L;

static {
dbPath = "output_ChargeTest";
Args.setParam(new String[]{"--output-directory", dbPath, "--debug"}, Constant.TEST_CONF);
Args.setParam(new String[]{"--output-directory", dbPath(), "--debug"}, Constant.TEST_CONF);
OWNER_ADDRESS = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ public class EnergyWhenAssertStyleTest extends BaseTest {
private long totalBalance = 30_000_000_000_000L;

static {
dbPath = "output_EnergyWhenAssertStyleTest";
Args.setParam(new String[]{"--output-directory", dbPath, "--debug"}, Constant.TEST_CONF);
Args.setParam(new String[]{"--output-directory", dbPath(), "--debug"}, Constant.TEST_CONF);
OWNER_ADDRESS = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ public class EnergyWhenRequireStyleTest extends BaseTest {
private long totalBalance = 30_000_000_000_000L;

static {
dbPath = "output_EnergyWhenRequireStyleTest";
Args.setParam(new String[]{"--output-directory", dbPath, "--debug"}, Constant.TEST_CONF);
Args.setParam(new String[]{"--output-directory", dbPath(), "--debug"}, Constant.TEST_CONF);
OWNER_ADDRESS = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ public class EnergyWhenSendAndTransferTest extends BaseTest {
private long totalBalance = 30_000_000_000_000L;

static {
dbPath = "output_EnergyWhenSendAndTransferTest";
Args.setParam(new String[]{"--output-directory", dbPath, "--debug"}, Constant.TEST_CONF);
Args.setParam(new String[]{"--output-directory", dbPath(), "--debug"}, Constant.TEST_CONF);
OWNER_ADDRESS = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ public class EnergyWhenTimeoutStyleTest extends BaseTest {
private long totalBalance = 30_000_000_000_000L;

static {
dbPath = "output_CPUTimeTest";
Args.setParam(new String[]{"--output-directory", dbPath},
Args.setParam(new String[]{"--output-directory", dbPath()},
Constant.TEST_CONF);
OWNER_ADDRESS = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc";
}
Expand Down
16 changes: 6 additions & 10 deletions framework/src/test/java/org/tron/common/runtime/vm/FreezeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@
import static org.tron.protos.contract.Common.ResourceCode.ENERGY;

import com.google.protobuf.ByteString;
import java.io.File;
import java.util.Arrays;
import java.util.function.Consumer;
import lombok.extern.slf4j.Slf4j;
import org.bouncycastle.util.encoders.Hex;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.tron.common.application.TronApplicationContext;
import org.tron.common.runtime.Runtime;
import org.tron.common.runtime.RuntimeImpl;
import org.tron.common.runtime.TVMTestResult;
import org.tron.common.runtime.TvmTestUtils;
import org.tron.common.utils.Commons;
import org.tron.common.utils.FastByteComparisons;
import org.tron.common.utils.FileUtil;
import org.tron.common.utils.StringUtil;
import org.tron.common.utils.WalletUtil;
import org.tron.common.utils.client.utils.AbiUtil;
Expand Down Expand Up @@ -121,16 +121,17 @@ public class FreezeTest {
private static final String userCStr = "27juXSbMvL6pb8VgmKRgW6ByCfw5RqZjUuo";
private static final byte[] userC = Commons.decode58Check(userCStr);

private static String dbPath;
@Rule
public final TemporaryFolder temporaryFolder = new TemporaryFolder();
private static TronApplicationContext context;
private static Manager manager;
private static byte[] owner;
private static Repository rootRepository;

@Before
public void init() throws Exception {
dbPath = "output_" + FreezeTest.class.getName();
Args.setParam(new String[]{"--output-directory", dbPath, "--debug"}, Constant.TEST_CONF);
Args.setParam(new String[]{"--output-directory",
temporaryFolder.newFolder().toString(), "--debug"}, Constant.TEST_CONF);
context = new TronApplicationContext(DefaultConfig.class);
manager = context.getBean(Manager.class);
owner = Hex.decode(Wallet.getAddressPreFixString()
Expand Down Expand Up @@ -1042,10 +1043,5 @@ public void destroy() {
VMConfig.initVmHardFork(false);
Args.clearParam();
context.destroy();
if (FileUtil.deleteDir(new File(dbPath))) {
logger.info("Release resources successful.");
} else {
logger.error("Release resources failure.");
}
}
}
Loading

0 comments on commit de23b55

Please sign in to comment.