Skip to content
Merged
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
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.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import static org.tron.protos.contract.Common.ResourceCode.ENERGY;

import com.google.protobuf.ByteString;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand All @@ -19,15 +18,16 @@
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 @@ -156,16 +156,17 @@ public class FreezeV2Test {
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_" + FreezeV2Test.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 @@ -1044,10 +1045,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