diff --git a/framework/src/test/java/org/tron/common/BaseTest.java b/framework/src/test/java/org/tron/common/BaseTest.java index 1dfbf702eff..c17d10d6ae4 100644 --- a/framework/src/test/java/org/tron/common/BaseTest.java +++ b/framework/src/test/java/org/tron/common/BaseTest.java @@ -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; @@ -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) { diff --git a/framework/src/test/java/org/tron/common/config/args/ArgsTest.java b/framework/src/test/java/org/tron/common/config/args/ArgsTest.java index 1c47599b61a..2e29b38824f 100644 --- a/framework/src/test/java/org/tron/common/config/args/ArgsTest.java +++ b/framework/src/test/java/org/tron/common/config/args/ArgsTest.java @@ -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 diff --git a/framework/src/test/java/org/tron/common/runtime/InheritanceTest.java b/framework/src/test/java/org/tron/common/runtime/InheritanceTest.java index 4121407fe35..4b57bc880d7 100644 --- a/framework/src/test/java/org/tron/common/runtime/InheritanceTest.java +++ b/framework/src/test/java/org/tron/common/runtime/InheritanceTest.java @@ -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"; } diff --git a/framework/src/test/java/org/tron/common/runtime/InternalTransactionComplexTest.java b/framework/src/test/java/org/tron/common/runtime/InternalTransactionComplexTest.java index 923f2386605..172ef40afa7 100644 --- a/framework/src/test/java/org/tron/common/runtime/InternalTransactionComplexTest.java +++ b/framework/src/test/java/org/tron/common/runtime/InternalTransactionComplexTest.java @@ -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"; } diff --git a/framework/src/test/java/org/tron/common/runtime/ProgramResultTest.java b/framework/src/test/java/org/tron/common/runtime/ProgramResultTest.java index d083b2c729c..a2e53dd8711 100644 --- a/framework/src/test/java/org/tron/common/runtime/ProgramResultTest.java +++ b/framework/src/test/java/org/tron/common/runtime/ProgramResultTest.java @@ -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"; diff --git a/framework/src/test/java/org/tron/common/runtime/RuntimeImplTest.java b/framework/src/test/java/org/tron/common/runtime/RuntimeImplTest.java index 585a625668a..0b7721a325d 100644 --- a/framework/src/test/java/org/tron/common/runtime/RuntimeImplTest.java +++ b/framework/src/test/java/org/tron/common/runtime/RuntimeImplTest.java @@ -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 diff --git a/framework/src/test/java/org/tron/common/runtime/RuntimeTransferComplexTest.java b/framework/src/test/java/org/tron/common/runtime/RuntimeTransferComplexTest.java index 366c631ea6e..c9d61db9270 100644 --- a/framework/src/test/java/org/tron/common/runtime/RuntimeTransferComplexTest.java +++ b/framework/src/test/java/org/tron/common/runtime/RuntimeTransferComplexTest.java @@ -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"; } diff --git a/framework/src/test/java/org/tron/common/runtime/vm/BandWidthRuntimeOutOfTimeTest.java b/framework/src/test/java/org/tron/common/runtime/vm/BandWidthRuntimeOutOfTimeTest.java index a0c87da01c6..afac8cd7d22 100644 --- a/framework/src/test/java/org/tron/common/runtime/vm/BandWidthRuntimeOutOfTimeTest.java +++ b/framework/src/test/java/org/tron/common/runtime/vm/BandWidthRuntimeOutOfTimeTest.java @@ -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", diff --git a/framework/src/test/java/org/tron/common/runtime/vm/BandWidthRuntimeOutOfTimeWithCheckTest.java b/framework/src/test/java/org/tron/common/runtime/vm/BandWidthRuntimeOutOfTimeWithCheckTest.java index 37167988f34..7203388f815 100644 --- a/framework/src/test/java/org/tron/common/runtime/vm/BandWidthRuntimeOutOfTimeWithCheckTest.java +++ b/framework/src/test/java/org/tron/common/runtime/vm/BandWidthRuntimeOutOfTimeWithCheckTest.java @@ -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", diff --git a/framework/src/test/java/org/tron/common/runtime/vm/BandWidthRuntimeTest.java b/framework/src/test/java/org/tron/common/runtime/vm/BandWidthRuntimeTest.java index 20e8e11535a..40c5908c2dd 100644 --- a/framework/src/test/java/org/tron/common/runtime/vm/BandWidthRuntimeTest.java +++ b/framework/src/test/java/org/tron/common/runtime/vm/BandWidthRuntimeTest.java @@ -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" diff --git a/framework/src/test/java/org/tron/common/runtime/vm/BandWidthRuntimeWithCheckTest.java b/framework/src/test/java/org/tron/common/runtime/vm/BandWidthRuntimeWithCheckTest.java index 0e7f79eb42f..e359e7eab1a 100644 --- a/framework/src/test/java/org/tron/common/runtime/vm/BandWidthRuntimeWithCheckTest.java +++ b/framework/src/test/java/org/tron/common/runtime/vm/BandWidthRuntimeWithCheckTest.java @@ -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" diff --git a/framework/src/test/java/org/tron/common/runtime/vm/BatchSendTest.java b/framework/src/test/java/org/tron/common/runtime/vm/BatchSendTest.java index a5c397e54c2..5ada5612fce 100644 --- a/framework/src/test/java/org/tron/common/runtime/vm/BatchSendTest.java +++ b/framework/src/test/java/org/tron/common/runtime/vm/BatchSendTest.java @@ -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"; diff --git a/framework/src/test/java/org/tron/common/runtime/vm/ChargeTest.java b/framework/src/test/java/org/tron/common/runtime/vm/ChargeTest.java index 78d5fc9e330..c158b2e400f 100644 --- a/framework/src/test/java/org/tron/common/runtime/vm/ChargeTest.java +++ b/framework/src/test/java/org/tron/common/runtime/vm/ChargeTest.java @@ -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"; } diff --git a/framework/src/test/java/org/tron/common/runtime/vm/EnergyWhenAssertStyleTest.java b/framework/src/test/java/org/tron/common/runtime/vm/EnergyWhenAssertStyleTest.java index 20abd7467aa..8b985d4bb1d 100644 --- a/framework/src/test/java/org/tron/common/runtime/vm/EnergyWhenAssertStyleTest.java +++ b/framework/src/test/java/org/tron/common/runtime/vm/EnergyWhenAssertStyleTest.java @@ -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"; } diff --git a/framework/src/test/java/org/tron/common/runtime/vm/EnergyWhenRequireStyleTest.java b/framework/src/test/java/org/tron/common/runtime/vm/EnergyWhenRequireStyleTest.java index 125d5220f07..19231b225f1 100644 --- a/framework/src/test/java/org/tron/common/runtime/vm/EnergyWhenRequireStyleTest.java +++ b/framework/src/test/java/org/tron/common/runtime/vm/EnergyWhenRequireStyleTest.java @@ -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"; } diff --git a/framework/src/test/java/org/tron/common/runtime/vm/EnergyWhenSendAndTransferTest.java b/framework/src/test/java/org/tron/common/runtime/vm/EnergyWhenSendAndTransferTest.java index 4db1b6a2033..009b332324b 100644 --- a/framework/src/test/java/org/tron/common/runtime/vm/EnergyWhenSendAndTransferTest.java +++ b/framework/src/test/java/org/tron/common/runtime/vm/EnergyWhenSendAndTransferTest.java @@ -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"; } diff --git a/framework/src/test/java/org/tron/common/runtime/vm/EnergyWhenTimeoutStyleTest.java b/framework/src/test/java/org/tron/common/runtime/vm/EnergyWhenTimeoutStyleTest.java index 6e99d55b668..2559b43a020 100644 --- a/framework/src/test/java/org/tron/common/runtime/vm/EnergyWhenTimeoutStyleTest.java +++ b/framework/src/test/java/org/tron/common/runtime/vm/EnergyWhenTimeoutStyleTest.java @@ -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"; } diff --git a/framework/src/test/java/org/tron/common/runtime/vm/FreezeTest.java b/framework/src/test/java/org/tron/common/runtime/vm/FreezeTest.java index 600000e6535..e1459637e19 100644 --- a/framework/src/test/java/org/tron/common/runtime/vm/FreezeTest.java +++ b/framework/src/test/java/org/tron/common/runtime/vm/FreezeTest.java @@ -7,7 +7,6 @@ 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; @@ -15,7 +14,9 @@ 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; @@ -23,7 +24,6 @@ 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; @@ -121,7 +121,8 @@ 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; @@ -129,8 +130,8 @@ public class FreezeTest { @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() @@ -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."); - } } } diff --git a/framework/src/test/java/org/tron/common/runtime/vm/FreezeV2Test.java b/framework/src/test/java/org/tron/common/runtime/vm/FreezeV2Test.java index 59df7021249..9558c701109 100644 --- a/framework/src/test/java/org/tron/common/runtime/vm/FreezeV2Test.java +++ b/framework/src/test/java/org/tron/common/runtime/vm/FreezeV2Test.java @@ -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; @@ -19,7 +18,9 @@ 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; @@ -27,7 +28,6 @@ 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; @@ -156,7 +156,8 @@ 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; @@ -164,8 +165,8 @@ public class FreezeV2Test { @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() @@ -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."); - } } } diff --git a/framework/src/test/java/org/tron/common/runtime/vm/InternalTransactionCallTest.java b/framework/src/test/java/org/tron/common/runtime/vm/InternalTransactionCallTest.java index 7f7bfd69ca4..75a8f32186c 100644 --- a/framework/src/test/java/org/tron/common/runtime/vm/InternalTransactionCallTest.java +++ b/framework/src/test/java/org/tron/common/runtime/vm/InternalTransactionCallTest.java @@ -1,18 +1,19 @@ package org.tron.common.runtime.vm; -import java.io.File; +import java.io.IOException; 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.Application; import org.tron.common.application.ApplicationFactory; import org.tron.common.application.TronApplicationContext; import org.tron.common.runtime.Runtime; import org.tron.common.runtime.TvmTestUtils; -import org.tron.common.utils.FileUtil; import org.tron.core.Constant; import org.tron.core.Wallet; import org.tron.core.config.DefaultConfig; @@ -33,7 +34,8 @@ public class InternalTransactionCallTest { private Manager dbManager; private TronApplicationContext context; private RepositoryImpl repository; - private String dbPath = "output_InternalTransactionCallTest"; + @Rule + public TemporaryFolder temporaryFolder = new TemporaryFolder(); private String OWNER_ADDRESS; private Application AppT; @@ -41,9 +43,10 @@ public class InternalTransactionCallTest { * Init data. */ @Before - public void init() { + public void init() throws IOException { Args.clearParam(); - Args.setParam(new String[]{"--output-directory", dbPath, "--support-constant", "--debug"}, + Args.setParam(new String[]{"--output-directory", + temporaryFolder.newFolder().toString(), "--support-constant", "--debug"}, Constant.TEST_CONF); context = new TronApplicationContext(DefaultConfig.class); @@ -356,11 +359,5 @@ public byte[] deployBContractAndGetItsAddress() public void destroy() { context.destroy(); Args.clearParam(); - if (FileUtil.deleteDir(new File(dbPath))) { - logger.info("Release resources successful."); - } else { - logger.warn("Release resources failure."); - } - } } diff --git a/framework/src/test/java/org/tron/common/runtime/vm/OperationsTest.java b/framework/src/test/java/org/tron/common/runtime/vm/OperationsTest.java index 965c7e0ce1a..be031d7c00b 100644 --- a/framework/src/test/java/org/tron/common/runtime/vm/OperationsTest.java +++ b/framework/src/test/java/org/tron/common/runtime/vm/OperationsTest.java @@ -2,7 +2,6 @@ import static org.junit.Assert.assertEquals; -import java.io.File; import java.util.List; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; @@ -16,7 +15,6 @@ import org.tron.common.BaseTest; import org.tron.common.parameter.CommonParameter; import org.tron.common.runtime.InternalTransaction; -import org.tron.common.utils.FileUtil; import org.tron.core.Constant; import org.tron.core.config.args.Args; import org.tron.core.exception.ContractValidateException; @@ -42,8 +40,7 @@ public class OperationsTest extends BaseTest { @BeforeClass public static void init() { - dbPath = "output_operations_test"; - Args.setParam(new String[]{"--output-directory", dbPath, "--debug"}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath(), "--debug"}, Constant.TEST_CONF); CommonParameter.getInstance().setDebug(true); VMConfig.initAllowTvmTransferTrc10(1); VMConfig.initAllowTvmConstantinople(1); @@ -58,7 +55,6 @@ public static void destroy() { ConfigLoader.disable = false; VMConfig.initVmHardFork(false); Args.clearParam(); - FileUtil.deleteDir(new File(dbPath)); VMConfig.initAllowTvmTransferTrc10(0); VMConfig.initAllowTvmConstantinople(0); VMConfig.initAllowTvmSolidity059(0); diff --git a/framework/src/test/java/org/tron/common/runtime/vm/PrecompiledContractsTest.java b/framework/src/test/java/org/tron/common/runtime/vm/PrecompiledContractsTest.java index b4365f02338..dce2cc7d105 100644 --- a/framework/src/test/java/org/tron/common/runtime/vm/PrecompiledContractsTest.java +++ b/framework/src/test/java/org/tron/common/runtime/vm/PrecompiledContractsTest.java @@ -106,8 +106,7 @@ public class PrecompiledContractsTest extends BaseTest { private static final long latestTimestamp = 1_000_000L; static { - dbPath = "output_PrecompiledContracts_test"; - 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"; WITNESS_ADDRESS = Wallet.getAddressPreFixString() + WITNESS_ADDRESS_BASE; diff --git a/framework/src/test/java/org/tron/common/runtime/vm/PrecompiledContractsVerifyProofTest.java b/framework/src/test/java/org/tron/common/runtime/vm/PrecompiledContractsVerifyProofTest.java index 08ce6be57a0..833ed6b0ac3 100644 --- a/framework/src/test/java/org/tron/common/runtime/vm/PrecompiledContractsVerifyProofTest.java +++ b/framework/src/test/java/org/tron/common/runtime/vm/PrecompiledContractsVerifyProofTest.java @@ -58,8 +58,7 @@ public class PrecompiledContractsVerifyProofTest extends BaseTest { @BeforeClass public static void init() { - dbPath = "output_PrecompiledContracts_VerifyProof_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, "config-test.conf"); + Args.setParam(new String[]{"--output-directory", dbPath()}, "config-test.conf"); DEFAULT_OVK = ByteArray .fromHexString("030c8c2bc59fb3eb8afb047a8ea4b028743d23e7d38c6fa30908358431e2314d"); SHIELDED_CONTRACT_ADDRESS = WalletClient.decodeFromBase58Check(SHIELDED_CONTRACT_ADDRESS_STR); diff --git a/framework/src/test/java/org/tron/common/runtime/vm/RepositoryTest.java b/framework/src/test/java/org/tron/common/runtime/vm/RepositoryTest.java index 1e92c67a834..5c38ed90a3c 100644 --- a/framework/src/test/java/org/tron/common/runtime/vm/RepositoryTest.java +++ b/framework/src/test/java/org/tron/common/runtime/vm/RepositoryTest.java @@ -34,8 +34,7 @@ public class RepositoryTest extends BaseTest { private Repository rootRepository; static { - dbPath = "output_DepostitTest"; - 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"; } diff --git a/framework/src/test/java/org/tron/common/runtime/vm/TimeBenchmarkTest.java b/framework/src/test/java/org/tron/common/runtime/vm/TimeBenchmarkTest.java index cc79d5f7ad6..8104a689cfa 100644 --- a/framework/src/test/java/org/tron/common/runtime/vm/TimeBenchmarkTest.java +++ b/framework/src/test/java/org/tron/common/runtime/vm/TimeBenchmarkTest.java @@ -29,8 +29,7 @@ public class TimeBenchmarkTest extends BaseTest { private long totalBalance = 30_000_000_000_000L; static { - dbPath = "output_TimeBenchmarkTest"; - 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"; } diff --git a/framework/src/test/java/org/tron/common/runtime/vm/TransferToAccountTest.java b/framework/src/test/java/org/tron/common/runtime/vm/TransferToAccountTest.java index 13f01847c81..ede47555f3f 100644 --- a/framework/src/test/java/org/tron/common/runtime/vm/TransferToAccountTest.java +++ b/framework/src/test/java/org/tron/common/runtime/vm/TransferToAccountTest.java @@ -54,8 +54,7 @@ public class TransferToAccountTest extends BaseTest { private static AccountCapsule ownerCapsule; static { - dbPath = "output_TransferToAccountTest"; - 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"; } diff --git a/framework/src/test/java/org/tron/common/runtime/vm/TransferTokenTest.java b/framework/src/test/java/org/tron/common/runtime/vm/TransferTokenTest.java index 87ff59a785b..0509cad1dc7 100644 --- a/framework/src/test/java/org/tron/common/runtime/vm/TransferTokenTest.java +++ b/framework/src/test/java/org/tron/common/runtime/vm/TransferTokenTest.java @@ -44,8 +44,7 @@ public class TransferTokenTest extends BaseTest { static { - dbPath = "output_TransferTokenTest"; - 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"; } diff --git a/framework/src/test/java/org/tron/common/runtime/vm/VMContractTestBase.java b/framework/src/test/java/org/tron/common/runtime/vm/VMContractTestBase.java index 777166a0bc0..ee49bdca7f6 100644 --- a/framework/src/test/java/org/tron/common/runtime/vm/VMContractTestBase.java +++ b/framework/src/test/java/org/tron/common/runtime/vm/VMContractTestBase.java @@ -1,13 +1,14 @@ package org.tron.common.runtime.vm; -import java.io.File; +import java.io.IOException; import lombok.extern.slf4j.Slf4j; import org.bouncycastle.util.encoders.Hex; import org.junit.After; import org.junit.Before; +import org.junit.Rule; +import org.junit.rules.TemporaryFolder; import org.tron.common.application.TronApplicationContext; import org.tron.common.runtime.Runtime; -import org.tron.common.utils.FileUtil; import org.tron.consensus.dpos.DposSlot; import org.tron.consensus.dpos.MaintenanceManager; import org.tron.core.ChainBaseManager; @@ -26,8 +27,8 @@ @Slf4j public class VMContractTestBase { - - protected String dbPath; + @Rule + public TemporaryFolder temporaryFolder = new TemporaryFolder(); protected Runtime runtime; protected Manager manager; protected Repository rootRepository; @@ -50,9 +51,9 @@ public class VMContractTestBase { } @Before - public void init() { - dbPath = "output_" + this.getClass().getName(); - Args.setParam(new String[]{"--output-directory", dbPath, "--debug"}, Constant.TEST_CONF); + public void init() throws IOException { + Args.setParam(new String[]{"--output-directory", + temporaryFolder.newFolder().toString(), "--debug"}, Constant.TEST_CONF); context = new TronApplicationContext(DefaultConfig.class); // TRdmP9bYvML7dGUX9Rbw2kZrE2TayPZmZX - 41abd4b9367799eaa3197fecb144eb71de1e049abc @@ -77,10 +78,5 @@ public void init() { public void destroy() { Args.clearParam(); context.destroy(); - if (FileUtil.deleteDir(new File(dbPath))) { - logger.info("Release resources successful."); - } else { - logger.error("Release resources failure."); - } } } diff --git a/framework/src/test/java/org/tron/common/runtime/vm/VMTestBase.java b/framework/src/test/java/org/tron/common/runtime/vm/VMTestBase.java index 1ceee84d634..18209543f62 100644 --- a/framework/src/test/java/org/tron/common/runtime/vm/VMTestBase.java +++ b/framework/src/test/java/org/tron/common/runtime/vm/VMTestBase.java @@ -1,13 +1,15 @@ package org.tron.common.runtime.vm; -import java.io.File; +import java.io.IOException; + import lombok.extern.slf4j.Slf4j; import org.bouncycastle.util.encoders.Hex; import org.junit.After; import org.junit.Before; +import org.junit.Rule; +import org.junit.rules.TemporaryFolder; import org.tron.common.application.TronApplicationContext; import org.tron.common.runtime.Runtime; -import org.tron.common.utils.FileUtil; import org.tron.core.Constant; import org.tron.core.Wallet; import org.tron.core.config.DefaultConfig; @@ -23,15 +25,17 @@ public class VMTestBase { protected Manager manager; protected TronApplicationContext context; - protected String dbPath; protected Repository rootRepository; protected String OWNER_ADDRESS; protected Runtime runtime; + @Rule + public TemporaryFolder temporaryFolder = new TemporaryFolder(); + @Before - public void init() { - dbPath = "output_" + this.getClass().getName(); - Args.setParam(new String[]{"--output-directory", dbPath, "--debug"}, Constant.TEST_CONF); + public void init() throws IOException { + Args.setParam(new String[]{"--output-directory", + temporaryFolder.newFolder().toString(), "--debug"}, Constant.TEST_CONF); context = new TronApplicationContext(DefaultConfig.class); OWNER_ADDRESS = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc"; manager = context.getBean(Manager.class); @@ -45,11 +49,6 @@ public void init() { public void destroy() { Args.clearParam(); context.destroy(); - if (FileUtil.deleteDir(new File(dbPath))) { - logger.info("Release resources successful."); - } else { - logger.error("Release resources failure."); - } } } diff --git a/framework/src/test/java/org/tron/common/runtime/vm/ValidateMultiSignContractTest.java b/framework/src/test/java/org/tron/common/runtime/vm/ValidateMultiSignContractTest.java index 765a80f3d5f..a688f5f9a29 100644 --- a/framework/src/test/java/org/tron/common/runtime/vm/ValidateMultiSignContractTest.java +++ b/framework/src/test/java/org/tron/common/runtime/vm/ValidateMultiSignContractTest.java @@ -37,8 +37,7 @@ public class ValidateMultiSignContractTest extends BaseTest { private static final byte[] longData; static { - dbPath = "output_ValidateMultiSignContract_test"; - Args.setParam(new String[]{"--output-directory", dbPath, "--debug"}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath(), "--debug"}, Constant.TEST_CONF); longData = new byte[1000000]; Arrays.fill(longData, (byte) 2); } diff --git a/framework/src/test/java/org/tron/common/runtime/vm/VoteTest.java b/framework/src/test/java/org/tron/common/runtime/vm/VoteTest.java index 22a33993589..1d85e9a7eab 100644 --- a/framework/src/test/java/org/tron/common/runtime/vm/VoteTest.java +++ b/framework/src/test/java/org/tron/common/runtime/vm/VoteTest.java @@ -19,7 +19,9 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Ignore; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TemporaryFolder; import org.tron.common.application.TronApplicationContext; import org.tron.common.parameter.CommonParameter; import org.tron.common.runtime.Runtime; @@ -264,7 +266,8 @@ private static Consumer getSmallerConsumer(long expected) { return getConsumer("<", expected); } - private static String dbPath; + @Rule + public TemporaryFolder temporaryFolder = new TemporaryFolder(); private static TronApplicationContext context; private static Manager manager; private static MaintenanceManager maintenanceManager; @@ -275,8 +278,8 @@ private static Consumer getSmallerConsumer(long expected) { @Before public void init() throws Exception { - dbPath = "output_" + VoteTest.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); CommonParameter.getInstance().setCheckFrozenTime(0); context = new TronApplicationContext(DefaultConfig.class); manager = context.getBean(Manager.class); @@ -310,11 +313,6 @@ 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."); - } } private byte[] deployContract(String contractName, String abi, String code) throws Exception { diff --git a/framework/src/test/java/org/tron/common/storage/leveldb/LevelDbDataSourceImplTest.java b/framework/src/test/java/org/tron/common/storage/leveldb/LevelDbDataSourceImplTest.java index b4ac2b4aebf..c774d10c172 100644 --- a/framework/src/test/java/org/tron/common/storage/leveldb/LevelDbDataSourceImplTest.java +++ b/framework/src/test/java/org/tron/common/storage/leveldb/LevelDbDataSourceImplTest.java @@ -26,6 +26,7 @@ import com.google.common.collect.Maps; import com.google.common.collect.Sets; import java.io.File; +import java.io.IOException; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; @@ -37,9 +38,11 @@ import org.junit.AfterClass; import org.junit.Assert; import org.junit.Before; +import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; import org.junit.contrib.java.lang.system.ExpectedSystemExit; +import org.junit.rules.TemporaryFolder; import org.tron.common.utils.ByteArray; import org.tron.common.utils.FileUtil; import org.tron.common.utils.PublicMethod; @@ -50,7 +53,8 @@ @Slf4j public class LevelDbDataSourceImplTest { - private static final String dbPath = "output-levelDb-test"; + @ClassRule + public static final TemporaryFolder temporaryFolder = new TemporaryFolder(); private static LevelDbDataSourceImpl dataSourceTest; private byte[] value1 = "10000".getBytes(); @@ -76,17 +80,14 @@ public class LevelDbDataSourceImplTest { @AfterClass public static void destroy() { Args.clearParam(); - if (FileUtil.deleteDir(new File(dbPath))) { - logger.info("Release resources successful."); - } else { - logger.info("Release resources failure."); - } } @Before - public void initDb() { - Args.setParam(new String[]{"--output-directory", dbPath}, Constant.TEST_CONF); - dataSourceTest = new LevelDbDataSourceImpl(dbPath + File.separator, "test_levelDb"); + public void initDb() throws IOException { + Args.setParam(new String[]{"--output-directory", + temporaryFolder.newFolder().toString()}, Constant.TEST_CONF); + dataSourceTest = new LevelDbDataSourceImpl( + Args.getInstance().getOutputDirectory() + File.separator, "test_levelDb"); } @Test diff --git a/framework/src/test/java/org/tron/common/storage/leveldb/RocksDbDataSourceImplTest.java b/framework/src/test/java/org/tron/common/storage/leveldb/RocksDbDataSourceImplTest.java index 62630014b23..51a5ddc96ee 100644 --- a/framework/src/test/java/org/tron/common/storage/leveldb/RocksDbDataSourceImplTest.java +++ b/framework/src/test/java/org/tron/common/storage/leveldb/RocksDbDataSourceImplTest.java @@ -8,6 +8,7 @@ import com.google.common.collect.Maps; import com.google.common.collect.Sets; import java.io.File; +import java.io.IOException; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; @@ -18,11 +19,12 @@ import lombok.extern.slf4j.Slf4j; import org.junit.AfterClass; import org.junit.Assert; -import org.junit.Before; import org.junit.BeforeClass; +import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; import org.junit.contrib.java.lang.system.ExpectedSystemExit; +import org.junit.rules.TemporaryFolder; import org.tron.common.storage.rocksdb.RocksDbDataSourceImpl; import org.tron.common.utils.ByteArray; import org.tron.common.utils.FileUtil; @@ -34,7 +36,8 @@ @Slf4j public class RocksDbDataSourceImplTest { - private static final String dbPath = "output-Rocks-test"; + @ClassRule + public static final TemporaryFolder temporaryFolder = new TemporaryFolder(); private static RocksDbDataSourceImpl dataSourceTest; private byte[] value1 = "10000".getBytes(); @@ -58,25 +61,15 @@ public class RocksDbDataSourceImplTest { */ @AfterClass public static void destroy() { - String directory = Args.getInstance().getStorage().getDbDirectory(); Args.clearParam(); - if (FileUtil.deleteDir(new File(dbPath))) { - logger.info("Release resources successful."); - } else { - logger.info("Release resources failure."); - } - - if (FileUtil.deleteDir(new File(dbPath + directory))) { - logger.info("Release resources successful."); - } else { - logger.info("Release resources failure."); - } } @BeforeClass - public static void initDb() { - Args.setParam(new String[]{"--output-directory", dbPath}, "config-test-dbbackup.conf"); - dataSourceTest = new RocksDbDataSourceImpl(dbPath + File.separator, "test_rocksDb"); + public static void initDb() throws IOException { + Args.setParam(new String[]{"--output-directory", + temporaryFolder.newFolder().toString()}, "config-test-dbbackup.conf"); + dataSourceTest = new RocksDbDataSourceImpl( + Args.getInstance().getOutputDirectory() + File.separator, "test_rocksDb"); } @Test diff --git a/framework/src/test/java/org/tron/core/BandwidthProcessorTest.java b/framework/src/test/java/org/tron/core/BandwidthProcessorTest.java index 69501c4e393..300c202e11a 100755 --- a/framework/src/test/java/org/tron/core/BandwidthProcessorTest.java +++ b/framework/src/test/java/org/tron/core/BandwidthProcessorTest.java @@ -47,8 +47,7 @@ public class BandwidthProcessorTest extends BaseTest { static { - dbPath = "output_bandwidth_processor_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); ASSET_NAME = "test_token"; ASSET_NAME_V2 = "2"; OWNER_ADDRESS = Wallet.getAddressPreFixString() + "548794500882809695a8a687866e76d4271a1abc"; diff --git a/framework/src/test/java/org/tron/core/EnergyProcessorTest.java b/framework/src/test/java/org/tron/core/EnergyProcessorTest.java index da0493e2026..1e9064cb998 100755 --- a/framework/src/test/java/org/tron/core/EnergyProcessorTest.java +++ b/framework/src/test/java/org/tron/core/EnergyProcessorTest.java @@ -24,8 +24,7 @@ public class EnergyProcessorTest extends BaseTest { private static final String USER_ADDRESS; static { - dbPath = "energy_processor_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); ASSET_NAME = "test_token"; CONTRACT_PROVIDER_ADDRESS = Wallet.getAddressPreFixString() + "548794500882809695a8a687866e76d4271a1abc"; diff --git a/framework/src/test/java/org/tron/core/ForkControllerTest.java b/framework/src/test/java/org/tron/core/ForkControllerTest.java index 20a28f9b619..74e651b3c1d 100644 --- a/framework/src/test/java/org/tron/core/ForkControllerTest.java +++ b/framework/src/test/java/org/tron/core/ForkControllerTest.java @@ -1,16 +1,16 @@ package org.tron.core; import com.google.protobuf.ByteString; -import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.List; - 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.utils.FileUtil; import org.tron.common.utils.ForkController; import org.tron.core.capsule.BlockCapsule; import org.tron.core.config.DefaultConfig; @@ -24,12 +24,14 @@ public class ForkControllerTest { private static DynamicPropertiesStore dynamicPropertiesStore; private static final ForkController forkController = ForkController.instance(); private static TronApplicationContext context; - private static final String dbPath = "output_fork_test"; + @Rule + public final TemporaryFolder temporaryFolder = new TemporaryFolder(); private static long ENERGY_LIMIT_BLOCK_NUM = 4727890L; @Before - public void init() { - Args.setParam(new String[]{"-d", dbPath, "-w"}, Constant.TEST_CONF); + public void init() throws IOException { + Args.setParam(new String[]{"-d", + temporaryFolder.newFolder().toString(), "-w"}, Constant.TEST_CONF); context = new TronApplicationContext(DefaultConfig.class); dynamicPropertiesStore = context.getBean(DynamicPropertiesStore.class); chainBaseManager = context.getBean(ChainBaseManager.class); @@ -255,7 +257,6 @@ private byte[] getBytes(int i) { public void removeDb() { Args.clearParam(); context.destroy(); - FileUtil.deleteDir(new File(dbPath)); } } diff --git a/framework/src/test/java/org/tron/core/ShieldedTRC20BuilderTest.java b/framework/src/test/java/org/tron/core/ShieldedTRC20BuilderTest.java index db62b04e6b0..ff30537ee7a 100644 --- a/framework/src/test/java/org/tron/core/ShieldedTRC20BuilderTest.java +++ b/framework/src/test/java/org/tron/core/ShieldedTRC20BuilderTest.java @@ -64,8 +64,7 @@ public class ShieldedTRC20BuilderTest extends BaseTest { private static final byte[] PUBLIC_TO_ADDRESS; static { - dbPath = "output_Shielded_TRC20_Api_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, "config-test-mainnet.conf"); + Args.setParam(new String[]{"--output-directory", dbPath()}, "config-test-mainnet.conf"); SHIELDED_CONTRACT_ADDRESS = WalletClient.decodeFromBase58Check(SHIELDED_CONTRACT_ADDRESS_STR); DEFAULT_OVK = ByteArray .fromHexString("030c8c2bc59fb3eb8afb047a8ea4b028743d23e7d38c6fa30908358431e2314d"); diff --git a/framework/src/test/java/org/tron/core/StorageMarketTest.java b/framework/src/test/java/org/tron/core/StorageMarketTest.java index 1c471032861..8b6e90e1c67 100644 --- a/framework/src/test/java/org/tron/core/StorageMarketTest.java +++ b/framework/src/test/java/org/tron/core/StorageMarketTest.java @@ -24,8 +24,7 @@ public class StorageMarketTest extends BaseTest { private static StorageMarket storageMarket; static { - dbPath = "output_storage_market_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); OWNER_ADDRESS = Wallet.getAddressPreFixString() + "548794500882809695a8a687866e76d4271a1abc"; } diff --git a/framework/src/test/java/org/tron/core/WalletTest.java b/framework/src/test/java/org/tron/core/WalletTest.java index 712a708f822..7461ff44c08 100644 --- a/framework/src/test/java/org/tron/core/WalletTest.java +++ b/framework/src/test/java/org/tron/core/WalletTest.java @@ -137,8 +137,7 @@ public class WalletTest extends BaseTest { private static boolean init; static { - dbPath = "output_wallet_test"; - Args.setParam(new String[]{"-d", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"-d", dbPath()}, Constant.TEST_CONF); OWNER_ADDRESS = Wallet.getAddressPreFixString() + "548794500882809695a8a687866e76d4271a1abc"; RECEIVER_ADDRESS = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049150"; } diff --git a/framework/src/test/java/org/tron/core/actuator/AccountPermissionUpdateActuatorTest.java b/framework/src/test/java/org/tron/core/actuator/AccountPermissionUpdateActuatorTest.java index d46545c5e16..69bac08c3e6 100644 --- a/framework/src/test/java/org/tron/core/actuator/AccountPermissionUpdateActuatorTest.java +++ b/framework/src/test/java/org/tron/core/actuator/AccountPermissionUpdateActuatorTest.java @@ -52,8 +52,7 @@ public class AccountPermissionUpdateActuatorTest extends BaseTest { private static final String KEY_ADDRESS_INVALID = "bbbb"; static { - dbPath = "output_account_permission_update_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); OWNER_ADDRESS = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc"; WITNESS_ADDRESS = Wallet.getAddressPreFixString() + "8CFC572CC20CA18B636BDD93B4FB15EA84CC2B4E"; KEY_ADDRESS = Wallet.getAddressPreFixString() + "548794500882809695a8a687866e76d4271a1abc"; diff --git a/framework/src/test/java/org/tron/core/actuator/ActuatorConstantTest.java b/framework/src/test/java/org/tron/core/actuator/ActuatorConstantTest.java index 3ad6aa1d6dd..b8c2bd4fef9 100644 --- a/framework/src/test/java/org/tron/core/actuator/ActuatorConstantTest.java +++ b/framework/src/test/java/org/tron/core/actuator/ActuatorConstantTest.java @@ -17,8 +17,7 @@ public class ActuatorConstantTest extends BaseTest { */ @BeforeClass public static void init() { - dbPath = "output_actuatorConstant_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); } @Test diff --git a/framework/src/test/java/org/tron/core/actuator/AssetIssueActuatorTest.java b/framework/src/test/java/org/tron/core/actuator/AssetIssueActuatorTest.java index 58e3ae8ed29..77c24c28797 100755 --- a/framework/src/test/java/org/tron/core/actuator/AssetIssueActuatorTest.java +++ b/framework/src/test/java/org/tron/core/actuator/AssetIssueActuatorTest.java @@ -47,8 +47,7 @@ public class AssetIssueActuatorTest extends BaseTest { private static long endTime = 0; static { - dbPath = "output_assetIssue_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); OWNER_ADDRESS = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049150"; OWNER_ADDRESS_SECOND = Wallet .getAddressPreFixString() + "548794500882809695a8a687866e76d4271a1abc"; diff --git a/framework/src/test/java/org/tron/core/actuator/CancelAllUnfreezeV2ActuatorTest.java b/framework/src/test/java/org/tron/core/actuator/CancelAllUnfreezeV2ActuatorTest.java index fcc545a0fc2..fc2dad88420 100644 --- a/framework/src/test/java/org/tron/core/actuator/CancelAllUnfreezeV2ActuatorTest.java +++ b/framework/src/test/java/org/tron/core/actuator/CancelAllUnfreezeV2ActuatorTest.java @@ -35,8 +35,7 @@ public class CancelAllUnfreezeV2ActuatorTest extends BaseTest { private static final long initBalance = 10_000_000_000L; static { - dbPath = "output_cancel_all_unfreeze_v2_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); OWNER_ADDRESS = Wallet.getAddressPreFixString() + "548794500882809695a8a687866e76d4271a1abc"; RECEIVER_ADDRESS = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049150"; OWNER_ACCOUNT_INVALID = diff --git a/framework/src/test/java/org/tron/core/actuator/ClearABIContractActuatorTest.java b/framework/src/test/java/org/tron/core/actuator/ClearABIContractActuatorTest.java index 1f6571e8868..3a23151f6bc 100644 --- a/framework/src/test/java/org/tron/core/actuator/ClearABIContractActuatorTest.java +++ b/framework/src/test/java/org/tron/core/actuator/ClearABIContractActuatorTest.java @@ -43,8 +43,7 @@ public class ClearABIContractActuatorTest extends BaseTest { private static final ABI TARGET_ABI = ABI.getDefaultInstance(); static { - dbPath = "output_clearabicontract_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); OWNER_ADDRESS = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc"; OWNER_ADDRESS_NOTEXIST = Wallet.getAddressPreFixString() + "548794500882809695a8a687866e76d4271a1abc"; diff --git a/framework/src/test/java/org/tron/core/actuator/CreateAccountActuatorTest.java b/framework/src/test/java/org/tron/core/actuator/CreateAccountActuatorTest.java index d53b0332f64..f756f3dd087 100755 --- a/framework/src/test/java/org/tron/core/actuator/CreateAccountActuatorTest.java +++ b/framework/src/test/java/org/tron/core/actuator/CreateAccountActuatorTest.java @@ -32,8 +32,7 @@ public class CreateAccountActuatorTest extends BaseTest { private static final String INVALID_ACCOUNT_ADDRESS; static { - dbPath = "output_CreateAccount_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); OWNER_ADDRESS_FIRST = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc"; OWNER_ADDRESS_SECOND = diff --git a/framework/src/test/java/org/tron/core/actuator/DelegateResourceActuatorTest.java b/framework/src/test/java/org/tron/core/actuator/DelegateResourceActuatorTest.java index b2ecae06177..95577f46e50 100644 --- a/framework/src/test/java/org/tron/core/actuator/DelegateResourceActuatorTest.java +++ b/framework/src/test/java/org/tron/core/actuator/DelegateResourceActuatorTest.java @@ -49,8 +49,7 @@ public class DelegateResourceActuatorTest extends BaseTest { private static final long initBalance = 1000_000_000_000L; static { - dbPath = "output_delegate_resource_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); OWNER_ADDRESS = Wallet.getAddressPreFixString() + "548794500882809695a8a687866e76d4271a1abc"; RECEIVER_ADDRESS = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049150"; OWNER_ACCOUNT_INVALID = diff --git a/framework/src/test/java/org/tron/core/actuator/ExchangeCreateActuatorTest.java b/framework/src/test/java/org/tron/core/actuator/ExchangeCreateActuatorTest.java index f8e4a27bda1..807d0e1be02 100644 --- a/framework/src/test/java/org/tron/core/actuator/ExchangeCreateActuatorTest.java +++ b/framework/src/test/java/org/tron/core/actuator/ExchangeCreateActuatorTest.java @@ -40,8 +40,7 @@ public class ExchangeCreateActuatorTest extends BaseTest { private static final String OWNER_ADDRESS_NOACCOUNT; static { - dbPath = "output_ExchangeCreate_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); OWNER_ADDRESS_FIRST = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc"; OWNER_ADDRESS_SECOND = diff --git a/framework/src/test/java/org/tron/core/actuator/ExchangeInjectActuatorTest.java b/framework/src/test/java/org/tron/core/actuator/ExchangeInjectActuatorTest.java index 553108d5490..6268c226c7e 100644 --- a/framework/src/test/java/org/tron/core/actuator/ExchangeInjectActuatorTest.java +++ b/framework/src/test/java/org/tron/core/actuator/ExchangeInjectActuatorTest.java @@ -41,8 +41,7 @@ public class ExchangeInjectActuatorTest extends BaseTest { private static final String OWNER_ADDRESS_NOACCOUNT; static { - dbPath = "output_ExchangeInject_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); OWNER_ADDRESS_FIRST = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc"; OWNER_ADDRESS_SECOND = diff --git a/framework/src/test/java/org/tron/core/actuator/ExchangeTransactionActuatorTest.java b/framework/src/test/java/org/tron/core/actuator/ExchangeTransactionActuatorTest.java index 5d728a61ff5..02107427cad 100644 --- a/framework/src/test/java/org/tron/core/actuator/ExchangeTransactionActuatorTest.java +++ b/framework/src/test/java/org/tron/core/actuator/ExchangeTransactionActuatorTest.java @@ -42,8 +42,7 @@ public class ExchangeTransactionActuatorTest extends BaseTest { private static final String OWNER_ADDRESS_NOACCOUNT; static { - dbPath = "output_ExchangeTransaction_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); OWNER_ADDRESS_FIRST = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc"; OWNER_ADDRESS_SECOND = diff --git a/framework/src/test/java/org/tron/core/actuator/ExchangeWithdrawActuatorTest.java b/framework/src/test/java/org/tron/core/actuator/ExchangeWithdrawActuatorTest.java index 85ea81ed932..6844925288e 100644 --- a/framework/src/test/java/org/tron/core/actuator/ExchangeWithdrawActuatorTest.java +++ b/framework/src/test/java/org/tron/core/actuator/ExchangeWithdrawActuatorTest.java @@ -42,8 +42,7 @@ public class ExchangeWithdrawActuatorTest extends BaseTest { private static final String OWNER_ADDRESS_NOACCOUNT; static { - dbPath = "output_ExchangeWithdraw_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); OWNER_ADDRESS_FIRST = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc"; OWNER_ADDRESS_SECOND = diff --git a/framework/src/test/java/org/tron/core/actuator/FreezeBalanceActuatorTest.java b/framework/src/test/java/org/tron/core/actuator/FreezeBalanceActuatorTest.java index c66a86fe58c..18eef50c36f 100644 --- a/framework/src/test/java/org/tron/core/actuator/FreezeBalanceActuatorTest.java +++ b/framework/src/test/java/org/tron/core/actuator/FreezeBalanceActuatorTest.java @@ -41,8 +41,7 @@ public class FreezeBalanceActuatorTest extends BaseTest { private static final long initBalance = 10_000_000_000L; static { - dbPath = "output_freeze_balance_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); OWNER_ADDRESS = Wallet.getAddressPreFixString() + "548794500882809695a8a687866e76d4271a1abc"; RECEIVER_ADDRESS = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049150"; OWNER_ACCOUNT_INVALID = diff --git a/framework/src/test/java/org/tron/core/actuator/FreezeBalanceV2ActuatorTest.java b/framework/src/test/java/org/tron/core/actuator/FreezeBalanceV2ActuatorTest.java index 1e6039c3e69..86b0e3143ab 100644 --- a/framework/src/test/java/org/tron/core/actuator/FreezeBalanceV2ActuatorTest.java +++ b/framework/src/test/java/org/tron/core/actuator/FreezeBalanceV2ActuatorTest.java @@ -36,8 +36,7 @@ public class FreezeBalanceV2ActuatorTest extends BaseTest { private static final long initBalance = 10_000_000_000L; static { - dbPath = "output_freeze_balance_v2_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); OWNER_ADDRESS = Wallet.getAddressPreFixString() + "548794500882809695a8a687866e76d4271a1abc"; RECEIVER_ADDRESS = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049150"; OWNER_ACCOUNT_INVALID = diff --git a/framework/src/test/java/org/tron/core/actuator/MarketCancelOrderActuatorTest.java b/framework/src/test/java/org/tron/core/actuator/MarketCancelOrderActuatorTest.java index 51b20ceab02..b5c3427f529 100644 --- a/framework/src/test/java/org/tron/core/actuator/MarketCancelOrderActuatorTest.java +++ b/framework/src/test/java/org/tron/core/actuator/MarketCancelOrderActuatorTest.java @@ -51,8 +51,7 @@ public class MarketCancelOrderActuatorTest extends BaseTest { private static final String TRX = "_"; static { - dbPath = "output_MarketCancelOrder_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); OWNER_ADDRESS_FIRST = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc"; OWNER_ADDRESS_SECOND = diff --git a/framework/src/test/java/org/tron/core/actuator/MarketSellAssetActuatorTest.java b/framework/src/test/java/org/tron/core/actuator/MarketSellAssetActuatorTest.java index a2a7cea259e..0e938cdb025 100644 --- a/framework/src/test/java/org/tron/core/actuator/MarketSellAssetActuatorTest.java +++ b/framework/src/test/java/org/tron/core/actuator/MarketSellAssetActuatorTest.java @@ -53,8 +53,7 @@ public class MarketSellAssetActuatorTest extends BaseTest { private static final String TRX = "_"; static { - dbPath = "output_MarketSellAsset_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); OWNER_ADDRESS_FIRST = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc"; OWNER_ADDRESS_SECOND = diff --git a/framework/src/test/java/org/tron/core/actuator/ParticipateAssetIssueActuatorTest.java b/framework/src/test/java/org/tron/core/actuator/ParticipateAssetIssueActuatorTest.java index 0bcfbc8820f..52e5f554374 100755 --- a/framework/src/test/java/org/tron/core/actuator/ParticipateAssetIssueActuatorTest.java +++ b/framework/src/test/java/org/tron/core/actuator/ParticipateAssetIssueActuatorTest.java @@ -41,8 +41,7 @@ public class ParticipateAssetIssueActuatorTest extends BaseTest { private static long AMOUNT = TOTAL_SUPPLY - (1000L) / TRX_NUM * NUM; static { - dbPath = "output_participateAsset_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); OWNER_ADDRESS = Wallet.getAddressPreFixString() + "548794500882809695a8a687866e76d4271a1234"; TO_ADDRESS = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc"; TO_ADDRESS_2 = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e048892"; diff --git a/framework/src/test/java/org/tron/core/actuator/ProposalApproveActuatorTest.java b/framework/src/test/java/org/tron/core/actuator/ProposalApproveActuatorTest.java index 484c6666941..2e8e78306a9 100644 --- a/framework/src/test/java/org/tron/core/actuator/ProposalApproveActuatorTest.java +++ b/framework/src/test/java/org/tron/core/actuator/ProposalApproveActuatorTest.java @@ -40,8 +40,7 @@ public class ProposalApproveActuatorTest extends BaseTest { private static final String OWNER_ADDRESS_NOACCOUNT; static { - dbPath = "output_ProposalApprove_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); OWNER_ADDRESS_FIRST = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc"; OWNER_ADDRESS_SECOND = diff --git a/framework/src/test/java/org/tron/core/actuator/ProposalCreateActuatorTest.java b/framework/src/test/java/org/tron/core/actuator/ProposalCreateActuatorTest.java index 1e95911884c..a42a4ffbe5a 100644 --- a/framework/src/test/java/org/tron/core/actuator/ProposalCreateActuatorTest.java +++ b/framework/src/test/java/org/tron/core/actuator/ProposalCreateActuatorTest.java @@ -38,8 +38,7 @@ public class ProposalCreateActuatorTest extends BaseTest { private static final String OWNER_ADDRESS_NOACCOUNT; static { - dbPath = "output_ProposalCreate_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); OWNER_ADDRESS_FIRST = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc"; OWNER_ADDRESS_SECOND = diff --git a/framework/src/test/java/org/tron/core/actuator/ProposalDeleteActuatorTest.java b/framework/src/test/java/org/tron/core/actuator/ProposalDeleteActuatorTest.java index 63e5758a907..dfd34cb620e 100644 --- a/framework/src/test/java/org/tron/core/actuator/ProposalDeleteActuatorTest.java +++ b/framework/src/test/java/org/tron/core/actuator/ProposalDeleteActuatorTest.java @@ -40,8 +40,7 @@ public class ProposalDeleteActuatorTest extends BaseTest { private static final String OWNER_ADDRESS_NOACCOUNT; static { - dbPath = "output_ProposalDelete_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); OWNER_ADDRESS_FIRST = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc"; OWNER_ADDRESS_SECOND = diff --git a/framework/src/test/java/org/tron/core/actuator/SetAccountIdActuatorTest.java b/framework/src/test/java/org/tron/core/actuator/SetAccountIdActuatorTest.java index 0b4311ca46f..e93d9ecf333 100644 --- a/framework/src/test/java/org/tron/core/actuator/SetAccountIdActuatorTest.java +++ b/framework/src/test/java/org/tron/core/actuator/SetAccountIdActuatorTest.java @@ -30,8 +30,7 @@ public class SetAccountIdActuatorTest extends BaseTest { private static final String OWNER_ADDRESS_INVALID = "aaaa"; static { - dbPath = "output_setaccountid_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); OWNER_ADDRESS = Wallet.getAddressPreFixString() + "548794500882809695a8a687866e76d4271a1abc"; OWNER_ADDRESS_1 = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc"; } diff --git a/framework/src/test/java/org/tron/core/actuator/ShieldedTransferActuatorTest.java b/framework/src/test/java/org/tron/core/actuator/ShieldedTransferActuatorTest.java index f84610cc551..b71ba432018 100755 --- a/framework/src/test/java/org/tron/core/actuator/ShieldedTransferActuatorTest.java +++ b/framework/src/test/java/org/tron/core/actuator/ShieldedTransferActuatorTest.java @@ -68,8 +68,7 @@ public class ShieldedTransferActuatorTest extends BaseTest { private Wallet wallet; static { - dbPath = "output_shield_transfer_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); ADDRESS_ONE_PRIVATE_KEY = PublicMethod.getRandomPrivateKey(); PUBLIC_ADDRESS_ONE = PublicMethod.getHexAddressByPrivateKey(ADDRESS_ONE_PRIVATE_KEY); diff --git a/framework/src/test/java/org/tron/core/actuator/TransferActuatorTest.java b/framework/src/test/java/org/tron/core/actuator/TransferActuatorTest.java index 05aea41e7c7..12df9031ca8 100644 --- a/framework/src/test/java/org/tron/core/actuator/TransferActuatorTest.java +++ b/framework/src/test/java/org/tron/core/actuator/TransferActuatorTest.java @@ -46,8 +46,7 @@ public class TransferActuatorTest extends BaseTest { private static final String To_ACCOUNT_INVALID; static { - dbPath = "output_transfer_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); OWNER_ADDRESS = Wallet.getAddressPreFixString() + "548794500882809695a8a687866e76d4271a1abc"; TO_ADDRESS = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc"; OWNER_ACCOUNT_INVALID = diff --git a/framework/src/test/java/org/tron/core/actuator/TransferAssetActuatorTest.java b/framework/src/test/java/org/tron/core/actuator/TransferAssetActuatorTest.java index 07bb8415068..8c936f16dc5 100755 --- a/framework/src/test/java/org/tron/core/actuator/TransferAssetActuatorTest.java +++ b/framework/src/test/java/org/tron/core/actuator/TransferAssetActuatorTest.java @@ -72,8 +72,7 @@ public class TransferAssetActuatorTest extends BaseTest { private static final String URL = "https://tron.network"; static { - dbPath = "output_transferasset_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); OWNER_ADDRESS = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049150"; TO_ADDRESS = Wallet.getAddressPreFixString() + "548794500882809695a8a687866e76d4271a146a"; NOT_EXIT_ADDRESS = Wallet.getAddressPreFixString() + "B56446E617E924805E4D6CA021D341FEF6E2013B"; diff --git a/framework/src/test/java/org/tron/core/actuator/UnDelegateResourceActuatorTest.java b/framework/src/test/java/org/tron/core/actuator/UnDelegateResourceActuatorTest.java index 82ed6865fb8..eea1a0bf9b7 100644 --- a/framework/src/test/java/org/tron/core/actuator/UnDelegateResourceActuatorTest.java +++ b/framework/src/test/java/org/tron/core/actuator/UnDelegateResourceActuatorTest.java @@ -38,8 +38,7 @@ public class UnDelegateResourceActuatorTest extends BaseTest { private static final long delegateBalance = 1_000_000_000L; static { - dbPath = "output_unDelegate_resource_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); OWNER_ADDRESS = Wallet.getAddressPreFixString() + "548794500882809695a8a687866e76d4271a1abc"; RECEIVER_ADDRESS = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049150"; OWNER_ACCOUNT_INVALID = diff --git a/framework/src/test/java/org/tron/core/actuator/UnfreezeAssetActuatorTest.java b/framework/src/test/java/org/tron/core/actuator/UnfreezeAssetActuatorTest.java index 0a624faf113..7471e9ba20f 100644 --- a/framework/src/test/java/org/tron/core/actuator/UnfreezeAssetActuatorTest.java +++ b/framework/src/test/java/org/tron/core/actuator/UnfreezeAssetActuatorTest.java @@ -36,8 +36,7 @@ public class UnfreezeAssetActuatorTest extends BaseTest { private static final String assetName = "testCoin"; static { - dbPath = "output_unfreeze_asset_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); OWNER_ADDRESS = Wallet.getAddressPreFixString() + "548794500882809695a8a687866e76d4271a1abc"; OWNER_ACCOUNT_INVALID = Wallet.getAddressPreFixString() + "548794500882809695a8a687866e76d4271a3456"; diff --git a/framework/src/test/java/org/tron/core/actuator/UnfreezeBalanceActuatorTest.java b/framework/src/test/java/org/tron/core/actuator/UnfreezeBalanceActuatorTest.java index 77e70f6762e..e9f1d934e5a 100644 --- a/framework/src/test/java/org/tron/core/actuator/UnfreezeBalanceActuatorTest.java +++ b/framework/src/test/java/org/tron/core/actuator/UnfreezeBalanceActuatorTest.java @@ -40,8 +40,7 @@ public class UnfreezeBalanceActuatorTest extends BaseTest { private static final long frozenBalance = 1_000_000_000L; static { - dbPath = "output_unfreeze_balance_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); OWNER_ADDRESS = Wallet.getAddressPreFixString() + "548794500882809695a8a687866e76d4271a1abc"; RECEIVER_ADDRESS = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049150"; OWNER_ACCOUNT_INVALID = diff --git a/framework/src/test/java/org/tron/core/actuator/UnfreezeBalanceV2ActuatorTest.java b/framework/src/test/java/org/tron/core/actuator/UnfreezeBalanceV2ActuatorTest.java index db2a78b1623..749052736e5 100644 --- a/framework/src/test/java/org/tron/core/actuator/UnfreezeBalanceV2ActuatorTest.java +++ b/framework/src/test/java/org/tron/core/actuator/UnfreezeBalanceV2ActuatorTest.java @@ -38,8 +38,7 @@ public class UnfreezeBalanceV2ActuatorTest extends BaseTest { private static final long frozenBalance = 1_000_000_000L; static { - dbPath = "output_unfreeze_balance_v2_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); OWNER_ADDRESS = Wallet.getAddressPreFixString() + "548794500882809695a8a687866e76d4271a1abc"; RECEIVER_ADDRESS = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049150"; OWNER_ACCOUNT_INVALID = diff --git a/framework/src/test/java/org/tron/core/actuator/UpdateAccountActuatorTest.java b/framework/src/test/java/org/tron/core/actuator/UpdateAccountActuatorTest.java index acbb9fb4d0b..0e385347836 100755 --- a/framework/src/test/java/org/tron/core/actuator/UpdateAccountActuatorTest.java +++ b/framework/src/test/java/org/tron/core/actuator/UpdateAccountActuatorTest.java @@ -32,8 +32,7 @@ public class UpdateAccountActuatorTest extends BaseTest { private static final String OWNER_ADDRESS_INVALID = "aaaa"; static { - dbPath = "output_updateaccount_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); OWNER_ADDRESS = Wallet.getAddressPreFixString() + "548794500882809695a8a687866e76d4271a1abc"; OWNER_ADDRESS_1 = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc"; } diff --git a/framework/src/test/java/org/tron/core/actuator/UpdateAssetActuatorTest.java b/framework/src/test/java/org/tron/core/actuator/UpdateAssetActuatorTest.java index b7583bc335b..3bdba2055af 100644 --- a/framework/src/test/java/org/tron/core/actuator/UpdateAssetActuatorTest.java +++ b/framework/src/test/java/org/tron/core/actuator/UpdateAssetActuatorTest.java @@ -39,8 +39,7 @@ public class UpdateAssetActuatorTest extends BaseTest { private static final String URL = "tron-my.com"; static { - dbPath = "output_updateAsset_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); OWNER_ADDRESS = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc"; OWNER_ADDRESS_NOTEXIST = Wallet.getAddressPreFixString() + "548794500882809695a8a687866e76d4271a1abc"; diff --git a/framework/src/test/java/org/tron/core/actuator/UpdateBrokerageActuatorTest.java b/framework/src/test/java/org/tron/core/actuator/UpdateBrokerageActuatorTest.java index 034415e0ef1..efd090b4b3a 100644 --- a/framework/src/test/java/org/tron/core/actuator/UpdateBrokerageActuatorTest.java +++ b/framework/src/test/java/org/tron/core/actuator/UpdateBrokerageActuatorTest.java @@ -34,8 +34,7 @@ public class UpdateBrokerageActuatorTest extends BaseTest { private static final int BROKEN_AGE = 10; static { - dbPath = "output_updatebrokerageactuator_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); OWNER_ADDRESS = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc"; OWNER_ADDRESS_NOTEXIST = Wallet.getAddressPreFixString() + "1234b9367799eaa3197fecb144eb71de1e049123"; diff --git a/framework/src/test/java/org/tron/core/actuator/UpdateEnergyLimitContractActuatorTest.java b/framework/src/test/java/org/tron/core/actuator/UpdateEnergyLimitContractActuatorTest.java index 3703dc74e87..60f52b541b9 100644 --- a/framework/src/test/java/org/tron/core/actuator/UpdateEnergyLimitContractActuatorTest.java +++ b/framework/src/test/java/org/tron/core/actuator/UpdateEnergyLimitContractActuatorTest.java @@ -47,8 +47,7 @@ public class UpdateEnergyLimitContractActuatorTest extends BaseTest { private static String OWNER_ADDRESS_NOTEXIST; static { - dbPath = "output_updateEnergyLimitContractActuator_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); } /** diff --git a/framework/src/test/java/org/tron/core/actuator/UpdateSettingContractActuatorTest.java b/framework/src/test/java/org/tron/core/actuator/UpdateSettingContractActuatorTest.java index 0445f893983..508cee731f0 100644 --- a/framework/src/test/java/org/tron/core/actuator/UpdateSettingContractActuatorTest.java +++ b/framework/src/test/java/org/tron/core/actuator/UpdateSettingContractActuatorTest.java @@ -41,8 +41,7 @@ public class UpdateSettingContractActuatorTest extends BaseTest { private static final long INVALID_PERCENT = 200L; static { - dbPath = "output_updatesettingcontract_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); OWNER_ADDRESS = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc"; OWNER_ADDRESS_NOTEXIST = Wallet.getAddressPreFixString() + "548794500882809695a8a687866e76d4271a1abc"; diff --git a/framework/src/test/java/org/tron/core/actuator/VoteWitnessActuatorTest.java b/framework/src/test/java/org/tron/core/actuator/VoteWitnessActuatorTest.java index cedd147dbaa..1a152555931 100644 --- a/framework/src/test/java/org/tron/core/actuator/VoteWitnessActuatorTest.java +++ b/framework/src/test/java/org/tron/core/actuator/VoteWitnessActuatorTest.java @@ -51,8 +51,7 @@ public class VoteWitnessActuatorTest extends BaseTest { private static boolean consensusStart; static { - dbPath = "output_VoteWitness_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); OWNER_ADDRESS = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc"; WITNESS_ADDRESS = Wallet.getAddressPreFixString() + "548794500882809695a8a687866e76d4271a1abc"; WITNESS_ADDRESS_NOACCOUNT = diff --git a/framework/src/test/java/org/tron/core/actuator/WithdrawBalanceActuatorTest.java b/framework/src/test/java/org/tron/core/actuator/WithdrawBalanceActuatorTest.java index 7010b10657a..22a4acbb838 100644 --- a/framework/src/test/java/org/tron/core/actuator/WithdrawBalanceActuatorTest.java +++ b/framework/src/test/java/org/tron/core/actuator/WithdrawBalanceActuatorTest.java @@ -36,8 +36,7 @@ public class WithdrawBalanceActuatorTest extends BaseTest { private static final long allowance = 32_000_000L; static { - dbPath = "output_withdraw_balance_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); OWNER_ADDRESS = Wallet.getAddressPreFixString() + "548794500882809695a8a687866e76d4271a1abc"; OWNER_ACCOUNT_INVALID = Wallet.getAddressPreFixString() + "548794500882809695a8a687866e76d4271a3456"; diff --git a/framework/src/test/java/org/tron/core/actuator/WithdrawExpireUnfreezeActuatorTest.java b/framework/src/test/java/org/tron/core/actuator/WithdrawExpireUnfreezeActuatorTest.java index 1544e546854..34ac0d9bbeb 100644 --- a/framework/src/test/java/org/tron/core/actuator/WithdrawExpireUnfreezeActuatorTest.java +++ b/framework/src/test/java/org/tron/core/actuator/WithdrawExpireUnfreezeActuatorTest.java @@ -39,8 +39,7 @@ public class WithdrawExpireUnfreezeActuatorTest extends BaseTest { private static final long allowance = 32_000_000L; static { - dbPath = "output_withdraw_expire_unfreeze_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); OWNER_ADDRESS = Wallet.getAddressPreFixString() + "548794500882809695a8a687866e76d4271a1abc"; OWNER_ACCOUNT_INVALID = Wallet.getAddressPreFixString() + "548794500882809695a8a687866e76d4271a3456"; diff --git a/framework/src/test/java/org/tron/core/actuator/WitnessCreateActuatorTest.java b/framework/src/test/java/org/tron/core/actuator/WitnessCreateActuatorTest.java index 721d88af2b6..0809ed2993e 100644 --- a/framework/src/test/java/org/tron/core/actuator/WitnessCreateActuatorTest.java +++ b/framework/src/test/java/org/tron/core/actuator/WitnessCreateActuatorTest.java @@ -36,8 +36,7 @@ public class WitnessCreateActuatorTest extends BaseTest { private static final String OWNER_ADDRESS_BALANCENOTSUFFIENT; static { - dbPath = "output_WitnessCreate_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); OWNER_ADDRESS_FIRST = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc"; OWNER_ADDRESS_SECOND = diff --git a/framework/src/test/java/org/tron/core/actuator/WitnessUpdateActuatorTest.java b/framework/src/test/java/org/tron/core/actuator/WitnessUpdateActuatorTest.java index 31ac6a3cf88..6ad6e381c5e 100644 --- a/framework/src/test/java/org/tron/core/actuator/WitnessUpdateActuatorTest.java +++ b/framework/src/test/java/org/tron/core/actuator/WitnessUpdateActuatorTest.java @@ -36,8 +36,7 @@ public class WitnessUpdateActuatorTest extends BaseTest { private static final String OWNER_ADDRESS_INVALID = "aaaa"; static { - dbPath = "output_WitnessUpdate_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); OWNER_ADDRESS = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc"; OWNER_ADDRESS_NOTEXIST = Wallet.getAddressPreFixString() + "548794500882809695a8a687866e76d4271a1abc"; diff --git a/framework/src/test/java/org/tron/core/actuator/utils/ProposalUtilTest.java b/framework/src/test/java/org/tron/core/actuator/utils/ProposalUtilTest.java index 5de7771dfe2..6f4df3cba8f 100644 --- a/framework/src/test/java/org/tron/core/actuator/utils/ProposalUtilTest.java +++ b/framework/src/test/java/org/tron/core/actuator/utils/ProposalUtilTest.java @@ -32,8 +32,7 @@ public class ProposalUtilTest extends BaseTest { */ @BeforeClass public static void init() { - dbPath = "output_ProposalUtil_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); } @Test diff --git a/framework/src/test/java/org/tron/core/actuator/utils/TransactionUtilTest.java b/framework/src/test/java/org/tron/core/actuator/utils/TransactionUtilTest.java index 7d737870e58..9d56876a4da 100644 --- a/framework/src/test/java/org/tron/core/actuator/utils/TransactionUtilTest.java +++ b/framework/src/test/java/org/tron/core/actuator/utils/TransactionUtilTest.java @@ -46,8 +46,7 @@ public class TransactionUtilTest extends BaseTest { */ @BeforeClass public static void init() { - dbPath = "output_transactionUtil_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); OWNER_ADDRESS = Wallet.getAddressPreFixString() + "548794500882809695a8a687866e76d4271a1abc"; } diff --git a/framework/src/test/java/org/tron/core/actuator/vm/ProgramTraceListenerTest.java b/framework/src/test/java/org/tron/core/actuator/vm/ProgramTraceListenerTest.java index 7cd1b41f5a5..089711219f8 100644 --- a/framework/src/test/java/org/tron/core/actuator/vm/ProgramTraceListenerTest.java +++ b/framework/src/test/java/org/tron/core/actuator/vm/ProgramTraceListenerTest.java @@ -1,6 +1,6 @@ package org.tron.core.actuator.vm; -import java.io.File; +import java.io.IOException; import java.lang.reflect.Field; import java.util.List; import java.util.Map; @@ -8,9 +8,10 @@ import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; +import org.junit.ClassRule; import org.junit.Test; +import org.junit.rules.TemporaryFolder; import org.tron.common.runtime.vm.DataWord; -import org.tron.common.utils.FileUtil; import org.tron.core.Constant; import org.tron.core.config.args.Args; import org.tron.core.db.TransactionStoreTest; @@ -20,7 +21,8 @@ @Slf4j(topic = "VM") public class ProgramTraceListenerTest { - private static final String dbPath = "output_programTraceListener_test"; + @ClassRule + public static TemporaryFolder temporaryFolder = new TemporaryFolder(); private static final int WORD_SIZE = 32; private ProgramTraceListener traceListener; @@ -30,15 +32,15 @@ public class ProgramTraceListenerTest { private DataWord storageWordValue = new DataWord(3); @BeforeClass - public static void init() { - Args.setParam(new String[]{"--output-directory", dbPath, "--debug"}, Constant.TEST_CONF); + public static void init() throws IOException { + Args.setParam(new String[]{"--output-directory", + temporaryFolder.newFolder().toString(), "--debug"}, Constant.TEST_CONF); } @AfterClass public static void destroy() { Args.clearParam(); - FileUtil.deleteDir(new File(dbPath)); } private void invokeProgramTraceListener(ProgramTraceListener traceListener) { diff --git a/framework/src/test/java/org/tron/core/actuator/vm/ProgramTraceTest.java b/framework/src/test/java/org/tron/core/actuator/vm/ProgramTraceTest.java index c9c4966e208..46be28deed0 100644 --- a/framework/src/test/java/org/tron/core/actuator/vm/ProgramTraceTest.java +++ b/framework/src/test/java/org/tron/core/actuator/vm/ProgramTraceTest.java @@ -1,14 +1,15 @@ package org.tron.core.actuator.vm; -import java.io.File; +import java.io.IOException; import java.math.BigInteger; import java.util.List; import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; +import org.junit.ClassRule; import org.junit.Test; +import org.junit.rules.TemporaryFolder; import org.tron.common.runtime.vm.DataWord; -import org.tron.common.utils.FileUtil; import org.tron.core.Constant; import org.tron.core.config.args.Args; import org.tron.core.vm.trace.Op; @@ -16,17 +17,19 @@ import org.tron.core.vm.trace.ProgramTrace; public class ProgramTraceTest { - private static final String dbPath = "output_programTrace_test"; + + @ClassRule + public static final TemporaryFolder temporaryFolder = new TemporaryFolder(); @BeforeClass - public static void init() { - Args.setParam(new String[]{"--output-directory", dbPath, "--debug"}, Constant.TEST_CONF); + public static void init() throws IOException { + Args.setParam(new String[]{"--output-directory", + temporaryFolder.newFolder().toString(), "--debug"}, Constant.TEST_CONF); } @AfterClass public static void destroy() { Args.clearParam(); - FileUtil.deleteDir(new File(dbPath)); } @Test diff --git a/framework/src/test/java/org/tron/core/capsule/AccountCapsuleTest.java b/framework/src/test/java/org/tron/core/capsule/AccountCapsuleTest.java index 65aab3e9e7a..de72b4be276 100644 --- a/framework/src/test/java/org/tron/core/capsule/AccountCapsuleTest.java +++ b/framework/src/test/java/org/tron/core/capsule/AccountCapsuleTest.java @@ -36,8 +36,7 @@ public class AccountCapsuleTest extends BaseTest { static AccountCapsule accountCapsule; static { - dbPath = "output_accountCapsule_test"; - Args.setParam(new String[]{"-d", dbPath, "-w"}, Constant.TEST_CONF); + Args.setParam(new String[]{"-d", dbPath(), "-w"}, Constant.TEST_CONF); OWNER_ADDRESS = Wallet.getAddressPreFixString() + "a06a17a49648a8ad32055c06f60fa14ae46df91234"; } diff --git a/framework/src/test/java/org/tron/core/capsule/BlockCapsuleTest.java b/framework/src/test/java/org/tron/core/capsule/BlockCapsuleTest.java index 88d67c3a632..0dd078dedb0 100644 --- a/framework/src/test/java/org/tron/core/capsule/BlockCapsuleTest.java +++ b/framework/src/test/java/org/tron/core/capsule/BlockCapsuleTest.java @@ -1,16 +1,16 @@ package org.tron.core.capsule; import com.google.protobuf.ByteString; -import java.io.File; +import java.io.IOException; import java.util.Arrays; - import lombok.extern.slf4j.Slf4j; import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; +import org.junit.ClassRule; import org.junit.Test; +import org.junit.rules.TemporaryFolder; import org.tron.common.utils.ByteArray; -import org.tron.common.utils.FileUtil; import org.tron.common.utils.LocalWitnesses; import org.tron.common.utils.PublicMethod; import org.tron.common.utils.Sha256Hash; @@ -33,18 +33,18 @@ public class BlockCapsuleTest { .fromHexString("9938a342238077182498b464ac0292229938a342238077182498b464ac029222"))), 1234, ByteString.copyFrom("1234567".getBytes())); - private static String dbPath = "output_bloackcapsule_test"; + @ClassRule + public static final TemporaryFolder temporaryFolder = new TemporaryFolder(); @BeforeClass - public static void init() { - Args.setParam(new String[]{"-d", dbPath}, + public static void init() throws IOException { + Args.setParam(new String[]{"-d", temporaryFolder.newFolder().toString()}, Constant.TEST_CONF); } @AfterClass public static void removeDb() { Args.clearParam(); - FileUtil.deleteDir(new File(dbPath)); } @Test diff --git a/framework/src/test/java/org/tron/core/capsule/ExchangeCapsuleTest.java b/framework/src/test/java/org/tron/core/capsule/ExchangeCapsuleTest.java index 48479287eab..791767a952f 100644 --- a/framework/src/test/java/org/tron/core/capsule/ExchangeCapsuleTest.java +++ b/framework/src/test/java/org/tron/core/capsule/ExchangeCapsuleTest.java @@ -15,8 +15,7 @@ public class ExchangeCapsuleTest extends BaseTest { static { - dbPath = "output_exchange_capsule_test_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); } /** diff --git a/framework/src/test/java/org/tron/core/capsule/TransactionCapsuleTest.java b/framework/src/test/java/org/tron/core/capsule/TransactionCapsuleTest.java index 28f7bf0e4f5..fcb2a4fbfd5 100644 --- a/framework/src/test/java/org/tron/core/capsule/TransactionCapsuleTest.java +++ b/framework/src/test/java/org/tron/core/capsule/TransactionCapsuleTest.java @@ -46,8 +46,7 @@ public class TransactionCapsuleTest extends BaseTest { @BeforeClass public static void init() { - dbPath = "output_transactioncapsule_test"; - Args.setParam(new String[]{"-d", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"-d", dbPath()}, Constant.TEST_CONF); OWNER_ADDRESS = Wallet.getAddressPreFixString() + "03702350064AD5C1A8AA6B4D74B051199CFF8EA7"; /*TO_ADDRESS = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc"; OWNER_ACCOUNT_NOT_Exist = diff --git a/framework/src/test/java/org/tron/core/capsule/VotesCapsuleTest.java b/framework/src/test/java/org/tron/core/capsule/VotesCapsuleTest.java index d2e4483cdf0..64bb660ab9a 100644 --- a/framework/src/test/java/org/tron/core/capsule/VotesCapsuleTest.java +++ b/framework/src/test/java/org/tron/core/capsule/VotesCapsuleTest.java @@ -1,15 +1,16 @@ package org.tron.core.capsule; import com.google.protobuf.ByteString; -import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.List; import lombok.extern.slf4j.Slf4j; import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; +import org.junit.ClassRule; import org.junit.Test; -import org.tron.common.utils.FileUtil; +import org.junit.rules.TemporaryFolder; import org.tron.common.utils.StringUtil; import org.tron.core.Constant; import org.tron.core.Wallet; @@ -21,7 +22,8 @@ @Slf4j public class VotesCapsuleTest { - private static String dbPath = "output_votesCapsule_test"; + @ClassRule + public static TemporaryFolder temporaryFolder = new TemporaryFolder(); private static final String OWNER_ADDRESS; private static List oldVotes; @@ -31,15 +33,15 @@ public class VotesCapsuleTest { } @BeforeClass - public static void init() { - Args.setParam(new String[]{"--output-directory", dbPath, "--debug"}, Constant.TEST_CONF); + public static void init() throws IOException { + Args.setParam(new String[]{"--output-directory", + temporaryFolder.newFolder().toString(), "--debug"}, Constant.TEST_CONF); } @AfterClass public static void destroy() { Args.clearParam(); - FileUtil.deleteDir(new File(dbPath)); } @Test diff --git a/framework/src/test/java/org/tron/core/capsule/utils/AssetUtilTest.java b/framework/src/test/java/org/tron/core/capsule/utils/AssetUtilTest.java index 8d56c1a5f21..2b07d7d7952 100644 --- a/framework/src/test/java/org/tron/core/capsule/utils/AssetUtilTest.java +++ b/framework/src/test/java/org/tron/core/capsule/utils/AssetUtilTest.java @@ -24,8 +24,7 @@ public class AssetUtilTest extends BaseTest { static { - dbPath = "output_AssetUtil_test"; - Args.setParam(new String[] {"-d", dbPath, "-w"}, Constant.TEST_CONF); + Args.setParam(new String[] {"-d", dbPath(), "-w"}, Constant.TEST_CONF); } public static byte[] randomBytes(int length) { diff --git a/framework/src/test/java/org/tron/core/capsule/utils/ExchangeProcessorTest.java b/framework/src/test/java/org/tron/core/capsule/utils/ExchangeProcessorTest.java index 3d30dabf031..3437eb0ea42 100644 --- a/framework/src/test/java/org/tron/core/capsule/utils/ExchangeProcessorTest.java +++ b/framework/src/test/java/org/tron/core/capsule/utils/ExchangeProcessorTest.java @@ -15,8 +15,7 @@ public class ExchangeProcessorTest extends BaseTest { private static ExchangeProcessor processor; static { - dbPath = "output_buy_exchange_processor_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); } /** diff --git a/framework/src/test/java/org/tron/core/config/args/DynamicArgsTest.java b/framework/src/test/java/org/tron/core/config/args/DynamicArgsTest.java index 2ca95239ad7..2a3af9c440e 100644 --- a/framework/src/test/java/org/tron/core/config/args/DynamicArgsTest.java +++ b/framework/src/test/java/org/tron/core/config/args/DynamicArgsTest.java @@ -1,13 +1,15 @@ package org.tron.core.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.ClassRule; import org.junit.Test; +import org.junit.rules.TemporaryFolder; import org.tron.common.application.TronApplicationContext; import org.tron.common.parameter.CommonParameter; -import org.tron.common.utils.FileUtil; import org.tron.common.utils.ReflectUtils; import org.tron.core.Constant; import org.tron.core.config.DefaultConfig; @@ -17,11 +19,12 @@ public class DynamicArgsTest { protected TronApplicationContext context; private DynamicArgs dynamicArgs; - private String dbPath = "output-dynamic-config-test"; + @ClassRule + public static final TemporaryFolder temporaryFolder = new TemporaryFolder(); @Before - public void init() { - Args.setParam(new String[]{"--output-directory", dbPath}, + public void init() throws IOException { + Args.setParam(new String[]{"--output-directory", temporaryFolder.newFolder().toString()}, Constant.TEST_CONF); context = new TronApplicationContext(DefaultConfig.class); dynamicArgs = context.getBean(DynamicArgs.class); @@ -32,7 +35,6 @@ public void init() { public void destroy() { Args.clearParam(); context.destroy(); - FileUtil.deleteDir(new File(dbPath)); } @Test diff --git a/framework/src/test/java/org/tron/core/db/AccountIdIndexStoreTest.java b/framework/src/test/java/org/tron/core/db/AccountIdIndexStoreTest.java index fa31b2fd451..9033e90481c 100644 --- a/framework/src/test/java/org/tron/core/db/AccountIdIndexStoreTest.java +++ b/framework/src/test/java/org/tron/core/db/AccountIdIndexStoreTest.java @@ -34,8 +34,7 @@ public class AccountIdIndexStoreTest extends BaseTest { private static AccountCapsule accountCapsule4; static { - dbPath = "output_AccountIndexStore_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); } diff --git a/framework/src/test/java/org/tron/core/db/AccountIndexStoreTest.java b/framework/src/test/java/org/tron/core/db/AccountIndexStoreTest.java index 0b449addc41..a4dc848b749 100755 --- a/framework/src/test/java/org/tron/core/db/AccountIndexStoreTest.java +++ b/framework/src/test/java/org/tron/core/db/AccountIndexStoreTest.java @@ -23,10 +23,9 @@ public class AccountIndexStoreTest extends BaseTest { private static byte[] accountName = TransactionStoreTest.randomBytes(32); static { - dbPath = "output_AccountIndexStore_test"; Args.setParam( new String[]{ - "--output-directory", dbPath, + "--output-directory", dbPath(), "--storage-db-directory", dbDirectory, "--storage-index-directory", indexDirectory }, diff --git a/framework/src/test/java/org/tron/core/db/AccountStoreTest.java b/framework/src/test/java/org/tron/core/db/AccountStoreTest.java index f199b371f9d..9249a3358dc 100755 --- a/framework/src/test/java/org/tron/core/db/AccountStoreTest.java +++ b/framework/src/test/java/org/tron/core/db/AccountStoreTest.java @@ -36,10 +36,9 @@ public class AccountStoreTest extends BaseTest { private static boolean init; static { - dbPath = "output_AccountStore_test"; Args.setParam( new String[]{ - "--output-directory", dbPath, + "--output-directory", dbPath(), "--storage-db-directory", dbDirectory, "--storage-index-directory", indexDirectory }, diff --git a/framework/src/test/java/org/tron/core/db/BandwidthPriceHistoryLoaderTest.java b/framework/src/test/java/org/tron/core/db/BandwidthPriceHistoryLoaderTest.java index 4c7af2b31fe..298b9f40235 100644 --- a/framework/src/test/java/org/tron/core/db/BandwidthPriceHistoryLoaderTest.java +++ b/framework/src/test/java/org/tron/core/db/BandwidthPriceHistoryLoaderTest.java @@ -11,16 +11,17 @@ import static org.tron.core.utils.ProposalUtil.ProposalType.TRANSACTION_FEE; import static org.tron.core.utils.ProposalUtil.ProposalType.WITNESS_127_PAY_PER_BLOCK; -import java.io.File; +import java.io.IOException; import java.util.HashMap; import java.util.Map; import lombok.extern.slf4j.Slf4j; import org.junit.After; import org.junit.Assert; import org.junit.Before; +import org.junit.ClassRule; import org.junit.Test; +import org.junit.rules.TemporaryFolder; import org.tron.common.application.TronApplicationContext; -import org.tron.common.utils.FileUtil; import org.tron.core.ChainBaseManager; import org.tron.core.Constant; import org.tron.core.capsule.ProposalCapsule; @@ -36,7 +37,8 @@ public class BandwidthPriceHistoryLoaderTest { private static ChainBaseManager chainBaseManager; private static TronApplicationContext context; - private static final String dbPath = "output-BandwidthPriceHistoryLoaderTest-test"; + @ClassRule + public static final TemporaryFolder temporaryFolder = new TemporaryFolder(); private static long t1; private static long price1; private static long t2; @@ -47,8 +49,9 @@ public class BandwidthPriceHistoryLoaderTest { // Note, here use @Before and @After instead of @BeforeClass and @AfterClass, // because it needs to initialize DB before the single test every time @Before - public void init() { - Args.setParam(new String[] {"--output-directory", dbPath}, Constant.TEST_CONF); + public void init() throws IOException { + Args.setParam(new String[] {"--output-directory", + temporaryFolder.newFolder().toString()}, Constant.TEST_CONF); context = new TronApplicationContext(DefaultConfig.class); chainBaseManager = context.getBean(ChainBaseManager.class); } @@ -57,11 +60,6 @@ public void init() { public void destroy() { Args.clearParam(); context.destroy(); - if (FileUtil.deleteDir(new File(dbPath))) { - logger.info("Release resources successful."); - } else { - logger.info("Release resources failure."); - } } public void initDB() { diff --git a/framework/src/test/java/org/tron/core/db/BlockStoreTest.java b/framework/src/test/java/org/tron/core/db/BlockStoreTest.java index cdf8dbcc29c..4f706a97dcf 100644 --- a/framework/src/test/java/org/tron/core/db/BlockStoreTest.java +++ b/framework/src/test/java/org/tron/core/db/BlockStoreTest.java @@ -11,8 +11,7 @@ public class BlockStoreTest extends BaseTest { static { - dbPath = "output-blockStore-test"; - Args.setParam(new String[]{"--output-directory", dbPath}, + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); } diff --git a/framework/src/test/java/org/tron/core/db/EnergyPriceHistoryLoaderTest.java b/framework/src/test/java/org/tron/core/db/EnergyPriceHistoryLoaderTest.java index ca115bed2bd..995d9e01ecb 100644 --- a/framework/src/test/java/org/tron/core/db/EnergyPriceHistoryLoaderTest.java +++ b/framework/src/test/java/org/tron/core/db/EnergyPriceHistoryLoaderTest.java @@ -36,8 +36,7 @@ public class EnergyPriceHistoryLoaderTest extends BaseTest { private static long price5 = 140L; static { - dbPath = "output-EnergyPriceHistoryLoaderTest-test"; - Args.setParam(new String[] {"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[] {"--output-directory", dbPath()}, Constant.TEST_CONF); } public void initDB() { diff --git a/framework/src/test/java/org/tron/core/db/KhaosDatabaseTest.java b/framework/src/test/java/org/tron/core/db/KhaosDatabaseTest.java index de895abb4b4..72214c6743e 100644 --- a/framework/src/test/java/org/tron/core/db/KhaosDatabaseTest.java +++ b/framework/src/test/java/org/tron/core/db/KhaosDatabaseTest.java @@ -8,7 +8,6 @@ import javax.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; -import org.junit.BeforeClass; import org.junit.Test; import org.tron.common.BaseTest; import org.tron.common.parameter.CommonParameter; @@ -32,14 +31,9 @@ public class KhaosDatabaseTest extends BaseTest { private KhaosDatabase khaosDatabase; static { - dbPath = "output-khaosDatabase-test"; - Args.setParam(new String[]{"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); } - @BeforeClass - public static void init() { - Args.setParam(new String[]{"-d", dbPath}, Constant.TEST_CONF); - } @Test public void testStartBlock() { diff --git a/framework/src/test/java/org/tron/core/db/ManagerTest.java b/framework/src/test/java/org/tron/core/db/ManagerTest.java index 020805c93fa..e25faf536f7 100755 --- a/framework/src/test/java/org/tron/core/db/ManagerTest.java +++ b/framework/src/test/java/org/tron/core/db/ManagerTest.java @@ -9,7 +9,7 @@ import com.google.common.collect.Maps; import com.google.common.collect.Sets; import com.google.protobuf.ByteString; -import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -22,12 +22,13 @@ 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.crypto.ECKey; import org.tron.common.runtime.RuntimeImpl; import org.tron.common.utils.ByteArray; -import org.tron.common.utils.FileUtil; import org.tron.common.utils.JsonUtil; import org.tron.common.utils.LocalWitnesses; import org.tron.common.utils.PublicMethod; @@ -100,7 +101,8 @@ public class ManagerTest extends BlockGenerate { private static DposSlot dposSlot; private static TronApplicationContext context; private static BlockCapsule blockCapsule2; - private static String dbPath = "output_manager_test"; + @Rule + public TemporaryFolder temporaryFolder = new TemporaryFolder(); private static AtomicInteger port = new AtomicInteger(0); private static String accountAddress = Wallet.getAddressPreFixString() + "548794500882809695a8a687866e76d4271a1abc"; @@ -108,8 +110,9 @@ public class ManagerTest extends BlockGenerate { private LocalWitnesses localWitnesses; @Before - public void init() { - Args.setParam(new String[]{"-d", dbPath, "-w"}, Constant.TEST_CONF); + public void init() throws IOException { + Args.setParam(new String[]{"-d", + temporaryFolder.newFolder().toString(), "-w"}, Constant.TEST_CONF); Args.getInstance().setNodeListenPort(10000 + port.incrementAndGet()); context = new TronApplicationContext(DefaultConfig.class); @@ -157,7 +160,6 @@ public void init() { public void removeDb() { Args.clearParam(); context.destroy(); - FileUtil.deleteDir(new File(dbPath)); } @Test diff --git a/framework/src/test/java/org/tron/core/db/MarketPairPriceToOrderStoreTest.java b/framework/src/test/java/org/tron/core/db/MarketPairPriceToOrderStoreTest.java index f90b5712c56..1f453cb9b41 100755 --- a/framework/src/test/java/org/tron/core/db/MarketPairPriceToOrderStoreTest.java +++ b/framework/src/test/java/org/tron/core/db/MarketPairPriceToOrderStoreTest.java @@ -23,8 +23,7 @@ public class MarketPairPriceToOrderStoreTest extends BaseTest { static { - dbPath = "output-MarketPairPriceToOrderStore-test"; - Args.setParam(new String[]{"-d", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"-d", dbPath()}, Constant.TEST_CONF); } @After diff --git a/framework/src/test/java/org/tron/core/db/NullifierStoreTest.java b/framework/src/test/java/org/tron/core/db/NullifierStoreTest.java index 5ed2f967a15..96b2fc1a74d 100644 --- a/framework/src/test/java/org/tron/core/db/NullifierStoreTest.java +++ b/framework/src/test/java/org/tron/core/db/NullifierStoreTest.java @@ -29,8 +29,7 @@ public class NullifierStoreTest extends BaseTest { private static BytesCapsule nullifier2New; static { - dbPath = "output_NullifierStore_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); } diff --git a/framework/src/test/java/org/tron/core/db/TransactionExpireTest.java b/framework/src/test/java/org/tron/core/db/TransactionExpireTest.java index f9b1a6c44e0..843e54d38a8 100644 --- a/framework/src/test/java/org/tron/core/db/TransactionExpireTest.java +++ b/framework/src/test/java/org/tron/core/db/TransactionExpireTest.java @@ -1,50 +1,47 @@ package org.tron.core.db; import com.google.protobuf.ByteString; -import java.io.File; -import java.lang.reflect.Array; +import java.io.IOException; import java.util.Arrays; import lombok.extern.slf4j.Slf4j; import org.junit.After; import org.junit.Assert; import org.junit.Before; +import org.junit.ClassRule; import org.junit.Test; +import org.junit.rules.TemporaryFolder; import org.tron.api.GrpcAPI; import org.tron.api.GrpcAPI.Return.response_code; import org.tron.common.application.TronApplicationContext; import org.tron.common.parameter.CommonParameter; import org.tron.common.utils.ByteArray; -import org.tron.common.utils.FileUtil; import org.tron.common.utils.LocalWitnesses; import org.tron.common.utils.PublicMethod; import org.tron.common.utils.Sha256Hash; -import org.tron.core.ChainBaseManager; import org.tron.core.Constant; import org.tron.core.Wallet; -import org.tron.core.capsule.AccountCapsule; import org.tron.core.capsule.BlockCapsule; import org.tron.core.capsule.TransactionCapsule; -import org.tron.core.capsule.WitnessCapsule; import org.tron.core.config.DefaultConfig; import org.tron.core.config.args.Args; -import org.tron.core.store.WitnessScheduleStore; -import org.tron.protos.Protocol; import org.tron.protos.Protocol.Transaction.Contract.ContractType; import org.tron.protos.contract.BalanceContract.TransferContract; @Slf4j public class TransactionExpireTest { - private String dbPath = "output_expire_test"; + @ClassRule + public static final TemporaryFolder temporaryFolder = new TemporaryFolder(); private TronApplicationContext context; private Wallet wallet; private Manager dbManager; private BlockCapsule blockCapsule; @Before - public void init() { - Args.setParam(new String[] {"--output-directory", dbPath}, Constant.TEST_CONF); + public void init() throws IOException { + Args.setParam(new String[] {"--output-directory", + temporaryFolder.newFolder().toString()}, Constant.TEST_CONF); CommonParameter.PARAMETER.setMinEffectiveConnection(0); context = new TronApplicationContext(DefaultConfig.class); @@ -77,11 +74,6 @@ private void initLocalWitness() { public void removeDb() { Args.clearParam(); context.destroy(); - if (FileUtil.deleteDir(new File(dbPath))) { - logger.info("Release resources successful."); - } else { - logger.info("Release resources failure."); - } } @Test diff --git a/framework/src/test/java/org/tron/core/db/TransactionHistoryTest.java b/framework/src/test/java/org/tron/core/db/TransactionHistoryTest.java index 812f19922ca..eef168938b2 100644 --- a/framework/src/test/java/org/tron/core/db/TransactionHistoryTest.java +++ b/framework/src/test/java/org/tron/core/db/TransactionHistoryTest.java @@ -24,10 +24,9 @@ public class TransactionHistoryTest extends BaseTest { private static TransactionInfoCapsule transactionInfoCapsule; static { - dbPath = "output_TransactionHistoryStore_test"; Args.setParam( new String[]{ - "--output-directory", dbPath, + "--output-directory", dbPath(), "--storage-db-directory", dbDirectory, "--storage-index-directory", indexDirectory }, diff --git a/framework/src/test/java/org/tron/core/db/TransactionRetStoreTest.java b/framework/src/test/java/org/tron/core/db/TransactionRetStoreTest.java index 04478f2c261..b8aebe00aac 100644 --- a/framework/src/test/java/org/tron/core/db/TransactionRetStoreTest.java +++ b/framework/src/test/java/org/tron/core/db/TransactionRetStoreTest.java @@ -32,8 +32,8 @@ public class TransactionRetStoreTest extends BaseTest { private static TransactionRetCapsule transactionRetCapsule; static { - dbPath = "output_TransactionRetStore_test"; - Args.setParam(new String[]{"--output-directory", dbPath, "--storage-db-directory", dbDirectory, + Args.setParam(new String[]{"--output-directory", dbPath(), + "--storage-db-directory", dbDirectory, "--storage-index-directory", indexDirectory}, Constant.TEST_CONF); } diff --git a/framework/src/test/java/org/tron/core/db/TransactionStoreTest.java b/framework/src/test/java/org/tron/core/db/TransactionStoreTest.java index f51a8744c74..1edc4aca756 100644 --- a/framework/src/test/java/org/tron/core/db/TransactionStoreTest.java +++ b/framework/src/test/java/org/tron/core/db/TransactionStoreTest.java @@ -50,9 +50,7 @@ public class TransactionStoreTest extends BaseTest { */ @BeforeClass public static void init() { - dbPath = "output_TransactionStore_test"; - Args.setParam(new String[]{"--output-directory", dbPath, "--storage-db-directory", - dbDirectory, "--storage-index-directory", indexDirectory, "-w"}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath(), "-w"}, Constant.TEST_CONF); } /** diff --git a/framework/src/test/java/org/tron/core/db/TransactionTraceTest.java b/framework/src/test/java/org/tron/core/db/TransactionTraceTest.java index 553eb46a725..161fbea9569 100644 --- a/framework/src/test/java/org/tron/core/db/TransactionTraceTest.java +++ b/framework/src/test/java/org/tron/core/db/TransactionTraceTest.java @@ -60,10 +60,9 @@ public class TransactionTraceTest extends BaseTest { private static boolean init; static { - dbPath = "output_TransactionTrace_test"; Args.setParam( new String[]{ - "--output-directory", dbPath, + "--output-directory", dbPath(), "--storage-db-directory", dbDirectory, "--storage-index-directory", indexDirectory, "-w", diff --git a/framework/src/test/java/org/tron/core/db/TxCacheDBTest.java b/framework/src/test/java/org/tron/core/db/TxCacheDBTest.java index 8b1724248a0..1b49228a968 100644 --- a/framework/src/test/java/org/tron/core/db/TxCacheDBTest.java +++ b/framework/src/test/java/org/tron/core/db/TxCacheDBTest.java @@ -23,8 +23,7 @@ public class TxCacheDBTest extends BaseTest { public static void init() { String dbDirectory = "db_TransactionCache_test"; String indexDirectory = "index_TransactionCache_test"; - dbPath = "output_TransactionCache_test"; - Args.setParam(new String[]{"--output-directory", dbPath, "--storage-db-directory", + Args.setParam(new String[]{"--output-directory", dbPath(), "--storage-db-directory", dbDirectory, "--storage-index-directory", indexDirectory, "-w"}, Constant.TEST_CONF); } diff --git a/framework/src/test/java/org/tron/core/db/VotesStoreTest.java b/framework/src/test/java/org/tron/core/db/VotesStoreTest.java index 9e5cd7c0098..48d4d1324db 100755 --- a/framework/src/test/java/org/tron/core/db/VotesStoreTest.java +++ b/framework/src/test/java/org/tron/core/db/VotesStoreTest.java @@ -19,8 +19,7 @@ public class VotesStoreTest extends BaseTest { static { - dbPath = "output-votesStore-test"; - Args.setParam(new String[]{"-d", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"-d", dbPath()}, Constant.TEST_CONF); } @Resource diff --git a/framework/src/test/java/org/tron/core/db/WitnessStoreTest.java b/framework/src/test/java/org/tron/core/db/WitnessStoreTest.java index fd91e7da72a..3190e226689 100755 --- a/framework/src/test/java/org/tron/core/db/WitnessStoreTest.java +++ b/framework/src/test/java/org/tron/core/db/WitnessStoreTest.java @@ -15,8 +15,7 @@ public class WitnessStoreTest extends BaseTest { static { - dbPath = "output-witnessStore-test"; - Args.setParam(new String[]{"-d", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"-d", dbPath()}, Constant.TEST_CONF); } @Resource diff --git a/framework/src/test/java/org/tron/core/db/api/AssetUpdateHelperTest.java b/framework/src/test/java/org/tron/core/db/api/AssetUpdateHelperTest.java index 714198bde51..ed18b1be97d 100644 --- a/framework/src/test/java/org/tron/core/db/api/AssetUpdateHelperTest.java +++ b/framework/src/test/java/org/tron/core/db/api/AssetUpdateHelperTest.java @@ -27,8 +27,7 @@ public class AssetUpdateHelperTest extends BaseTest { private static boolean init; static { - dbPath = "output_AssetUpdateHelperTest_test"; - Args.setParam(new String[]{"-d", dbPath, "-w"}, "config-test-index.conf"); + Args.setParam(new String[]{"-d", dbPath(), "-w"}, "config-test-index.conf"); Args.getInstance().setSolidityNode(true); } diff --git a/framework/src/test/java/org/tron/core/db/backup/BackupDbUtilTest.java b/framework/src/test/java/org/tron/core/db/backup/BackupDbUtilTest.java index 4ddbd88d338..0153faeab71 100644 --- a/framework/src/test/java/org/tron/core/db/backup/BackupDbUtilTest.java +++ b/framework/src/test/java/org/tron/core/db/backup/BackupDbUtilTest.java @@ -34,8 +34,10 @@ public class BackupDbUtilTest extends BaseTest { String bak2Path; int frequency; + private static final String dbPath; + static { - dbPath = "output-BackupDbUtilTest"; + dbPath = dbPath(); Args.setParam( new String[]{ "--output-directory", dbPath, diff --git a/framework/src/test/java/org/tron/core/db2/ChainbaseTest.java b/framework/src/test/java/org/tron/core/db2/ChainbaseTest.java index 86e3bfefe6b..ee9813be633 100644 --- a/framework/src/test/java/org/tron/core/db2/ChainbaseTest.java +++ b/framework/src/test/java/org/tron/core/db2/ChainbaseTest.java @@ -1,18 +1,19 @@ package org.tron.core.db2; -import java.io.File; +import java.io.IOException; import java.util.HashMap; import java.util.Map; import lombok.extern.slf4j.Slf4j; import org.junit.AfterClass; import org.junit.Assert; import org.junit.Before; +import org.junit.ClassRule; import org.junit.Test; +import org.junit.rules.TemporaryFolder; import org.rocksdb.RocksDB; import org.tron.common.storage.leveldb.LevelDbDataSourceImpl; import org.tron.common.storage.rocksdb.RocksDbDataSourceImpl; import org.tron.common.utils.ByteArray; -import org.tron.common.utils.FileUtil; import org.tron.core.Constant; import org.tron.core.config.args.Args; import org.tron.core.db.common.DbSourceInter; @@ -24,7 +25,8 @@ @Slf4j public class ChainbaseTest { - private static final String dbPath = "output-chainbase-test"; + @ClassRule + public static final TemporaryFolder temporaryFolder = new TemporaryFolder(); private Chainbase chainbase = null; private final byte[] value0 = "00000".getBytes(); @@ -61,17 +63,13 @@ public class ChainbaseTest { @AfterClass public static void destroy() { Args.clearParam(); - if (FileUtil.deleteDir(new File(dbPath))) { - logger.info("Release resources successful."); - } else { - logger.info("Release resources failure."); - } } @Before - public void initDb() { + public void initDb() throws IOException { RocksDB.loadLibrary(); - Args.setParam(new String[] {"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[] {"--output-directory", + temporaryFolder.newFolder().toString()}, Constant.TEST_CONF); } @Test diff --git a/framework/src/test/java/org/tron/core/jsonrpc/BuildTransactionTest.java b/framework/src/test/java/org/tron/core/jsonrpc/BuildTransactionTest.java index 55d7c106458..578d5869e31 100644 --- a/framework/src/test/java/org/tron/core/jsonrpc/BuildTransactionTest.java +++ b/framework/src/test/java/org/tron/core/jsonrpc/BuildTransactionTest.java @@ -32,8 +32,7 @@ public class BuildTransactionTest extends BaseTest { private Wallet wallet; static { - dbPath = "output_build_transaction_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); OWNER_ADDRESS = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc"; diff --git a/framework/src/test/java/org/tron/core/jsonrpc/JsonrpcServiceTest.java b/framework/src/test/java/org/tron/core/jsonrpc/JsonrpcServiceTest.java index 94f9d5e15f2..b3ed26b591f 100644 --- a/framework/src/test/java/org/tron/core/jsonrpc/JsonrpcServiceTest.java +++ b/framework/src/test/java/org/tron/core/jsonrpc/JsonrpcServiceTest.java @@ -64,8 +64,7 @@ public class JsonrpcServiceTest extends BaseTest { private JsonRpcServiceOnSolidity jsonRpcServiceOnSolidity; static { - dbPath = "output_jsonrpc_service_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); CommonParameter.getInstance().setJsonRpcHttpFullNodeEnable(true); CommonParameter.getInstance().setJsonRpcHttpPBFTNodeEnable(true); CommonParameter.getInstance().setJsonRpcHttpSolidityNodeEnable(true); diff --git a/framework/src/test/java/org/tron/core/jsonrpc/SectionBloomStoreTest.java b/framework/src/test/java/org/tron/core/jsonrpc/SectionBloomStoreTest.java index 9b107792d86..6e350a38999 100644 --- a/framework/src/test/java/org/tron/core/jsonrpc/SectionBloomStoreTest.java +++ b/framework/src/test/java/org/tron/core/jsonrpc/SectionBloomStoreTest.java @@ -29,8 +29,7 @@ public class SectionBloomStoreTest extends BaseTest { SectionBloomStore sectionBloomStore; static { - dbPath = "output-sectionBloomStore-test"; - Args.setParam(new String[] {"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[] {"--output-directory", dbPath()}, Constant.TEST_CONF); } @Test diff --git a/framework/src/test/java/org/tron/core/jsonrpc/WalletCursorTest.java b/framework/src/test/java/org/tron/core/jsonrpc/WalletCursorTest.java index 05d27832e1d..d460440184c 100644 --- a/framework/src/test/java/org/tron/core/jsonrpc/WalletCursorTest.java +++ b/framework/src/test/java/org/tron/core/jsonrpc/WalletCursorTest.java @@ -30,8 +30,7 @@ public class WalletCursorTest extends BaseTest { private static boolean init; static { - dbPath = "output_wallet_cursor_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"--output-directory", dbPath()}, Constant.TEST_CONF); OWNER_ADDRESS = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc"; diff --git a/framework/src/test/java/org/tron/core/metrics/MetricsApiServiceTest.java b/framework/src/test/java/org/tron/core/metrics/MetricsApiServiceTest.java index d906ba20d63..51a46b09388 100644 --- a/framework/src/test/java/org/tron/core/metrics/MetricsApiServiceTest.java +++ b/framework/src/test/java/org/tron/core/metrics/MetricsApiServiceTest.java @@ -1,16 +1,17 @@ package org.tron.core.metrics; -import java.io.File; +import java.io.IOException; import lombok.extern.slf4j.Slf4j; import org.junit.After; import org.junit.Assert; import org.junit.Before; +import org.junit.ClassRule; import org.junit.Test; +import org.junit.rules.TemporaryFolder; import org.tron.common.application.Application; import org.tron.common.application.ApplicationFactory; import org.tron.common.application.TronApplicationContext; import org.tron.common.parameter.CommonParameter; -import org.tron.common.utils.FileUtil; import org.tron.core.Constant; import org.tron.core.config.DefaultConfig; import org.tron.core.config.args.Args; @@ -21,7 +22,8 @@ @Slf4j public class MetricsApiServiceTest { - private static String dbPath = "output-metrics"; + @ClassRule + public static TemporaryFolder temporaryFolder = new TemporaryFolder(); private static String dbDirectory = "metrics-database"; private static String indexDirectory = "metrics-index"; private static int port = 10001; @@ -32,7 +34,8 @@ public class MetricsApiServiceTest { @Before - public void init() { + public void init() throws IOException { + String dbPath = temporaryFolder.newFolder().toString(); Args.setParam(new String[]{"--output-directory", dbPath, "--debug"}, Constant.TEST_CONF); Args.setParam( @@ -103,6 +106,5 @@ public void testProcessMessage() { @After public void destroy() { context.destroy(); - FileUtil.deleteDir(new File(dbPath)); } } diff --git a/framework/src/test/java/org/tron/core/metrics/prometheus/PrometheusApiServiceTest.java b/framework/src/test/java/org/tron/core/metrics/prometheus/PrometheusApiServiceTest.java index a2a812ef30b..1c6e56cbbbe 100644 --- a/framework/src/test/java/org/tron/core/metrics/prometheus/PrometheusApiServiceTest.java +++ b/framework/src/test/java/org/tron/core/metrics/prometheus/PrometheusApiServiceTest.java @@ -55,8 +55,7 @@ public class PrometheusApiServiceTest extends BaseTest { private ChainBaseManager chainManager; static { - dbPath = "output-prometheus-metric"; - Args.setParam(new String[] {"-d", dbPath, "-w"}, Constant.TEST_CONF); + Args.setParam(new String[] {"-d", dbPath(), "-w"}, Constant.TEST_CONF); Args.getInstance().setNodeListenPort(10000 + port.incrementAndGet()); initParameter(Args.getInstance()); Metrics.init(); diff --git a/framework/src/test/java/org/tron/core/net/BaseNet.java b/framework/src/test/java/org/tron/core/net/BaseNet.java index 1eab04fe106..7ae8b355168 100644 --- a/framework/src/test/java/org/tron/core/net/BaseNet.java +++ b/framework/src/test/java/org/tron/core/net/BaseNet.java @@ -14,13 +14,17 @@ import io.netty.handler.timeout.ReadTimeoutHandler; import io.netty.handler.timeout.WriteTimeoutHandler; import java.io.File; +import java.io.IOException; import java.util.Collection; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import lombok.extern.slf4j.Slf4j; import org.junit.AfterClass; +import org.junit.Assert; import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.rules.TemporaryFolder; import org.tron.common.application.Application; import org.tron.common.application.ApplicationFactory; import org.tron.common.application.TronApplicationContext; @@ -36,7 +40,8 @@ @Slf4j public class BaseNet { - private static String dbPath = "output-net"; + @ClassRule + public static final TemporaryFolder temporaryFolder = new TemporaryFolder(); private static String dbDirectory = "net-database"; private static String indexDirectory = "net-index"; private static int port = 10000; @@ -77,14 +82,18 @@ protected void initChannel(Channel ch) throws Exception { public static void init() throws Exception { executorService.execute(() -> { logger.info("Full node running."); - Args.setParam( - new String[]{ - "--output-directory", dbPath, - "--storage-db-directory", dbDirectory, - "--storage-index-directory", indexDirectory - }, - "config.conf" - ); + try { + Args.setParam( + new String[]{ + "--output-directory", temporaryFolder.newFolder().toString(), + "--storage-db-directory", dbDirectory, + "--storage-index-directory", indexDirectory + }, + "config.conf" + ); + } catch (IOException e) { + Assert.fail("create temp db directory failed"); + } CommonParameter parameter = Args.getInstance(); parameter.setNodeListenPort(port); parameter.getSeedNode().getAddressList().clear(); @@ -117,6 +126,5 @@ public static void destroy() { } Args.clearParam(); context.destroy(); - FileUtil.deleteDir(new File(dbPath)); } } diff --git a/framework/src/test/java/org/tron/core/net/messagehandler/BlockMsgHandlerTest.java b/framework/src/test/java/org/tron/core/net/messagehandler/BlockMsgHandlerTest.java index 57c27bc2382..8154d01aded 100644 --- a/framework/src/test/java/org/tron/core/net/messagehandler/BlockMsgHandlerTest.java +++ b/framework/src/test/java/org/tron/core/net/messagehandler/BlockMsgHandlerTest.java @@ -41,8 +41,7 @@ public class BlockMsgHandlerTest extends BaseTest { */ @BeforeClass public static void init() { - dbPath = "output_blockmsghandler_test"; - Args.setParam(new String[]{"--output-directory", dbPath, "--debug"}, + Args.setParam(new String[]{"--output-directory", dbPath(), "--debug"}, Constant.TEST_CONF); } diff --git a/framework/src/test/java/org/tron/core/net/messagehandler/MessageHandlerTest.java b/framework/src/test/java/org/tron/core/net/messagehandler/MessageHandlerTest.java index 215b5f495ad..7ff29b54bb7 100644 --- a/framework/src/test/java/org/tron/core/net/messagehandler/MessageHandlerTest.java +++ b/framework/src/test/java/org/tron/core/net/messagehandler/MessageHandlerTest.java @@ -3,7 +3,6 @@ import static org.mockito.Mockito.mock; import com.google.protobuf.ByteString; -import java.io.File; import java.lang.reflect.Field; import java.net.InetSocketAddress; import java.util.ArrayList; @@ -12,11 +11,12 @@ import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; +import org.junit.ClassRule; import org.junit.Test; +import org.junit.rules.TemporaryFolder; import org.mockito.Mockito; import org.springframework.context.ApplicationContext; import org.tron.common.application.TronApplicationContext; -import org.tron.common.utils.FileUtil; import org.tron.common.utils.ReflectUtils; import org.tron.common.utils.Sha256Hash; import org.tron.consensus.pbft.message.PbftMessage; @@ -39,13 +39,15 @@ public class MessageHandlerTest { private PeerConnection peer; private static P2pEventHandlerImpl p2pEventHandler; private static ApplicationContext ctx; - private static String dbPath = "output-message-handler-test"; + + @ClassRule + public static final TemporaryFolder temporaryFolder = new TemporaryFolder(); @BeforeClass public static void init() throws Exception { - 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); p2pEventHandler = context.getBean(P2pEventHandlerImpl.class); ctx = (ApplicationContext) ReflectUtils.getFieldObject(p2pEventHandler, "ctx"); @@ -59,7 +61,6 @@ public static void init() throws Exception { public static void destroy() { Args.clearParam(); context.destroy(); - FileUtil.deleteDir(new File(dbPath)); } @Before diff --git a/framework/src/test/java/org/tron/core/net/messagehandler/SyncBlockChainMsgHandlerTest.java b/framework/src/test/java/org/tron/core/net/messagehandler/SyncBlockChainMsgHandlerTest.java index 53375ec7815..25108e19b70 100644 --- a/framework/src/test/java/org/tron/core/net/messagehandler/SyncBlockChainMsgHandlerTest.java +++ b/framework/src/test/java/org/tron/core/net/messagehandler/SyncBlockChainMsgHandlerTest.java @@ -1,6 +1,5 @@ package org.tron.core.net.messagehandler; -import java.io.File; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -10,9 +9,10 @@ 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.utils.FileUtil; import org.tron.core.Constant; import org.tron.core.capsule.BlockCapsule; import org.tron.core.config.DefaultConfig; @@ -27,12 +27,13 @@ public class SyncBlockChainMsgHandlerTest { private TronApplicationContext context; private SyncBlockChainMsgHandler handler; private PeerConnection peer; - private String dbPath = "output-sync-chain-test"; + @Rule + public TemporaryFolder temporaryFolder = new TemporaryFolder(); @Before public void init() throws Exception { - 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); handler = context.getBean(SyncBlockChainMsgHandler.class); peer = context.getBean(PeerConnection.class); @@ -85,7 +86,6 @@ public void testProcessMessage() throws Exception { @After public void destroy() { Args.clearParam(); - FileUtil.deleteDir(new File(dbPath)); } } diff --git a/framework/src/test/java/org/tron/core/net/services/AdvServiceTest.java b/framework/src/test/java/org/tron/core/net/services/AdvServiceTest.java index 870dc9eef8e..d79b54f6f45 100644 --- a/framework/src/test/java/org/tron/core/net/services/AdvServiceTest.java +++ b/framework/src/test/java/org/tron/core/net/services/AdvServiceTest.java @@ -2,17 +2,18 @@ import static org.mockito.Mockito.mock; -import java.io.File; +import java.io.IOException; import java.net.InetSocketAddress; import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; +import org.junit.ClassRule; import org.junit.Test; +import org.junit.rules.TemporaryFolder; import org.mockito.Mockito; import org.springframework.context.ApplicationContext; import org.tron.common.application.TronApplicationContext; import org.tron.common.parameter.CommonParameter; -import org.tron.common.utils.FileUtil; import org.tron.common.utils.ReflectUtils; import org.tron.common.utils.Sha256Hash; import org.tron.core.Constant; @@ -31,17 +32,18 @@ import org.tron.protos.Protocol.Inventory.InventoryType; public class AdvServiceTest { - private static String dbPath = "output-adv-service-test1"; private static TronApplicationContext context; private static AdvService service; private static P2pEventHandlerImpl p2pEventHandler; private static ApplicationContext ctx; + @ClassRule + public static final TemporaryFolder temporaryFolder = new TemporaryFolder(); + @BeforeClass - public static void init() { - dbPath = "output-adv-service-test"; - Args.setParam(new String[]{"--output-directory", dbPath, "--debug"}, - Constant.TEST_CONF); + public static void init() throws IOException { + Args.setParam(new String[]{"--output-directory", + temporaryFolder.newFolder().toString(), "--debug"}, Constant.TEST_CONF); context = new TronApplicationContext(DefaultConfig.class); service = context.getBean(AdvService.class); p2pEventHandler = context.getBean(P2pEventHandlerImpl.class); @@ -52,7 +54,6 @@ public static void init() { public static void after() { Args.clearParam(); context.destroy(); - FileUtil.deleteDir(new File(dbPath)); } @Test diff --git a/framework/src/test/java/org/tron/core/net/services/EffectiveCheckServiceTest.java b/framework/src/test/java/org/tron/core/net/services/EffectiveCheckServiceTest.java index aa42e0fcb89..9104b087d26 100644 --- a/framework/src/test/java/org/tron/core/net/services/EffectiveCheckServiceTest.java +++ b/framework/src/test/java/org/tron/core/net/services/EffectiveCheckServiceTest.java @@ -1,14 +1,15 @@ package org.tron.core.net.services; -import java.io.File; +import java.io.IOException; import java.lang.reflect.Method; import java.net.InetSocketAddress; 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.utils.FileUtil; import org.tron.common.utils.ReflectUtils; import org.tron.core.Constant; import org.tron.core.config.DefaultConfig; @@ -21,12 +22,14 @@ public class EffectiveCheckServiceTest { protected TronApplicationContext context; private EffectiveCheckService service; - private String dbPath = "output-effective-service-test"; + + @Rule + public final TemporaryFolder temporaryFolder = new TemporaryFolder(); @Before - public void init() { - Args.setParam(new String[] {"--output-directory", dbPath, "--debug"}, - Constant.TEST_CONF); + public void init() throws IOException { + Args.setParam(new String[] {"--output-directory", + temporaryFolder.newFolder().toString(), "--debug"}, Constant.TEST_CONF); context = new TronApplicationContext(DefaultConfig.class); service = context.getBean(EffectiveCheckService.class); } @@ -35,7 +38,6 @@ public void init() { public void destroy() { Args.clearParam(); context.destroy(); - FileUtil.deleteDir(new File(dbPath)); } @Test diff --git a/framework/src/test/java/org/tron/core/net/services/HandShakeServiceTest.java b/framework/src/test/java/org/tron/core/net/services/HandShakeServiceTest.java index 4f074b2c825..e027749458f 100644 --- a/framework/src/test/java/org/tron/core/net/services/HandShakeServiceTest.java +++ b/framework/src/test/java/org/tron/core/net/services/HandShakeServiceTest.java @@ -4,7 +4,6 @@ import static org.tron.core.net.message.handshake.HelloMessage.getEndpointFromNode; import com.google.protobuf.ByteString; -import java.io.File; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -16,15 +15,14 @@ import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; +import org.junit.ClassRule; import org.junit.Test; +import org.junit.rules.TemporaryFolder; import org.mockito.Mockito; import org.springframework.context.ApplicationContext; import org.tron.common.application.TronApplicationContext; -import org.tron.common.utils.ByteArray; -import org.tron.common.utils.FileUtil; import org.tron.common.utils.ReflectUtils; import org.tron.common.utils.Sha256Hash; -import org.tron.consensus.pbft.message.PbftMessage; import org.tron.core.ChainBaseManager; import org.tron.core.Constant; import org.tron.core.capsule.BlockCapsule; @@ -33,7 +31,6 @@ import org.tron.core.net.P2pEventHandlerImpl; import org.tron.core.net.TronNetService; import org.tron.core.net.message.handshake.HelloMessage; -import org.tron.core.net.message.keepalive.PingMessage; import org.tron.core.net.peer.PeerConnection; import org.tron.core.net.peer.PeerManager; import org.tron.p2p.P2pConfig; @@ -51,13 +48,13 @@ public class HandShakeServiceTest { private PeerConnection peer; private static P2pEventHandlerImpl p2pEventHandler; private static ApplicationContext ctx; - private static String dbPath = "output-message-handler-test"; - + @ClassRule + public static final TemporaryFolder temporaryFolder = new TemporaryFolder(); @BeforeClass public static void init() throws Exception { - 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); p2pEventHandler = context.getBean(P2pEventHandlerImpl.class); ctx = (ApplicationContext) ReflectUtils.getFieldObject(p2pEventHandler, "ctx"); @@ -71,7 +68,6 @@ public static void init() throws Exception { public static void destroy() { Args.clearParam(); context.destroy(); - FileUtil.deleteDir(new File(dbPath)); } @Before diff --git a/framework/src/test/java/org/tron/core/net/services/RelayServiceTest.java b/framework/src/test/java/org/tron/core/net/services/RelayServiceTest.java index a5b676d0144..777472bdc35 100644 --- a/framework/src/test/java/org/tron/core/net/services/RelayServiceTest.java +++ b/framework/src/test/java/org/tron/core/net/services/RelayServiceTest.java @@ -40,8 +40,7 @@ public class RelayServiceTest extends BaseTest { */ @BeforeClass public static void init() { - dbPath = "output-relay-service-test"; - Args.setParam(new String[]{"--output-directory", dbPath, "--debug"}, + Args.setParam(new String[]{"--output-directory", dbPath(), "--debug"}, Constant.TEST_CONF); } diff --git a/framework/src/test/java/org/tron/core/net/services/SyncServiceTest.java b/framework/src/test/java/org/tron/core/net/services/SyncServiceTest.java index e51ec564886..89c081eaab5 100644 --- a/framework/src/test/java/org/tron/core/net/services/SyncServiceTest.java +++ b/framework/src/test/java/org/tron/core/net/services/SyncServiceTest.java @@ -3,7 +3,6 @@ import static org.mockito.Mockito.mock; import com.google.common.cache.Cache; -import java.io.File; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.net.InetSocketAddress; @@ -13,11 +12,12 @@ 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.mockito.Mockito; import org.springframework.context.ApplicationContext; import org.tron.common.application.TronApplicationContext; -import org.tron.common.utils.FileUtil; import org.tron.common.utils.ReflectUtils; import org.tron.core.Constant; import org.tron.core.capsule.BlockCapsule; @@ -38,7 +38,8 @@ public class SyncServiceTest { private PeerConnection peer; private P2pEventHandlerImpl p2pEventHandler; private ApplicationContext ctx; - private String dbPath = "output-sync-service-test"; + @Rule + public TemporaryFolder temporaryFolder = new TemporaryFolder(); private InetSocketAddress inetSocketAddress = new InetSocketAddress("127.0.0.2", 10001); @@ -50,8 +51,8 @@ public SyncServiceTest() { */ @Before public void init() throws Exception { - 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); service = context.getBean(SyncService.class); p2pEventHandler = context.getBean(P2pEventHandlerImpl.class); @@ -65,7 +66,6 @@ public void init() throws Exception { public void destroy() { Args.clearParam(); context.destroy(); - FileUtil.deleteDir(new File(dbPath)); } @Test diff --git a/framework/src/test/java/org/tron/core/pbft/PbftApiTest.java b/framework/src/test/java/org/tron/core/pbft/PbftApiTest.java index 8363e6028bc..9bc942d6684 100755 --- a/framework/src/test/java/org/tron/core/pbft/PbftApiTest.java +++ b/framework/src/test/java/org/tron/core/pbft/PbftApiTest.java @@ -35,8 +35,7 @@ public class PbftApiTest extends BaseTest { @BeforeClass public static void init() { - dbPath = "output_pbftAPI_test"; - Args.setParam(new String[]{"-d", dbPath, "-w"}, Constant.TEST_CONF); + Args.setParam(new String[]{"-d", dbPath(), "-w"}, Constant.TEST_CONF); } @Test diff --git a/framework/src/test/java/org/tron/core/services/ProposalServiceTest.java b/framework/src/test/java/org/tron/core/services/ProposalServiceTest.java index 53c97f07b2a..0ba32b27f2e 100644 --- a/framework/src/test/java/org/tron/core/services/ProposalServiceTest.java +++ b/framework/src/test/java/org/tron/core/services/ProposalServiceTest.java @@ -26,8 +26,7 @@ public class ProposalServiceTest extends BaseTest { @BeforeClass public static void init() { - dbPath = "output_proposal_test"; - Args.setParam(new String[]{"-d", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"-d", dbPath()}, Constant.TEST_CONF); } diff --git a/framework/src/test/java/org/tron/core/services/WalletApiTest.java b/framework/src/test/java/org/tron/core/services/WalletApiTest.java index 5c3ef49d67c..0a87c348fdb 100644 --- a/framework/src/test/java/org/tron/core/services/WalletApiTest.java +++ b/framework/src/test/java/org/tron/core/services/WalletApiTest.java @@ -1,18 +1,19 @@ package org.tron.core.services; import io.grpc.ManagedChannelBuilder; -import java.io.File; +import java.io.IOException; import lombok.extern.slf4j.Slf4j; 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.api.GrpcAPI.EmptyMessage; import org.tron.api.WalletGrpc; import org.tron.common.application.Application; import org.tron.common.application.ApplicationFactory; import org.tron.common.application.TronApplicationContext; -import org.tron.common.utils.FileUtil; import org.tron.common.utils.client.Configuration; import org.tron.core.Constant; import org.tron.core.config.DefaultConfig; @@ -22,16 +23,19 @@ @Slf4j public class WalletApiTest { + @Rule + public TemporaryFolder temporaryFolder = new TemporaryFolder(); + private static TronApplicationContext context; - private static String dbPath = "output_wallet_api_test"; private String fullnode = Configuration.getByPath("testng.conf") .getStringList("fullnode.ip.list").get(0); private RpcApiService rpcApiService; private Application appT; @Before - public void init() { - Args.setParam(new String[]{ "-d", dbPath, "--p2p-disable", "true"}, Constant.TEST_CONF); + public void init() throws IOException { + Args.setParam(new String[]{ "-d", temporaryFolder.newFolder().toString(), + "--p2p-disable", "true"}, Constant.TEST_CONF); context = new TronApplicationContext(DefaultConfig.class); appT = ApplicationFactory.create(context); rpcApiService = context.getBean(RpcApiService.class); @@ -53,7 +57,6 @@ public void listNodesTest() { public void destroy() { Args.clearParam(); context.destroy(); - FileUtil.deleteDir(new File(dbPath)); } } diff --git a/framework/src/test/java/org/tron/core/services/filter/HttpApiAccessFilterTest.java b/framework/src/test/java/org/tron/core/services/filter/HttpApiAccessFilterTest.java index 0be61682b08..6423252560b 100644 --- a/framework/src/test/java/org/tron/core/services/filter/HttpApiAccessFilterTest.java +++ b/framework/src/test/java/org/tron/core/services/filter/HttpApiAccessFilterTest.java @@ -40,8 +40,7 @@ public class HttpApiAccessFilterTest extends BaseTest { private static final CloseableHttpClient httpClient = HttpClients.createDefault(); static { - dbPath = "output_http_api_access_filter_test"; - Args.setParam(new String[]{"-d", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"-d", dbPath()}, Constant.TEST_CONF); Args.getInstance().setFullNodeAllowShieldedTransactionArgs(false); } diff --git a/framework/src/test/java/org/tron/core/services/filter/LiteFnQueryGrpcInterceptorTest.java b/framework/src/test/java/org/tron/core/services/filter/LiteFnQueryGrpcInterceptorTest.java index 999b37d8fd6..00f2c2fc086 100644 --- a/framework/src/test/java/org/tron/core/services/filter/LiteFnQueryGrpcInterceptorTest.java +++ b/framework/src/test/java/org/tron/core/services/filter/LiteFnQueryGrpcInterceptorTest.java @@ -47,7 +47,7 @@ public class LiteFnQueryGrpcInterceptorTest { public ExpectedException thrown = ExpectedException.none(); @ClassRule - public static TemporaryFolder temporaryFolder = new TemporaryFolder(); + public static final TemporaryFolder temporaryFolder = new TemporaryFolder(); /** * init logic. diff --git a/framework/src/test/java/org/tron/core/services/filter/LiteFnQueryHttpFilterTest.java b/framework/src/test/java/org/tron/core/services/filter/LiteFnQueryHttpFilterTest.java index 5522c56075d..38e0b054c2b 100644 --- a/framework/src/test/java/org/tron/core/services/filter/LiteFnQueryHttpFilterTest.java +++ b/framework/src/test/java/org/tron/core/services/filter/LiteFnQueryHttpFilterTest.java @@ -42,8 +42,7 @@ public class LiteFnQueryHttpFilterTest extends BaseTest { private final CloseableHttpClient httpClient = HttpClients.createDefault(); static { - dbPath = "output_http_filter_test"; - Args.setParam(new String[]{"-d", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"-d", dbPath()}, Constant.TEST_CONF); Args.getInstance().setFullNodeAllowShieldedTransactionArgs(false); } diff --git a/framework/src/test/java/org/tron/core/services/filter/RpcApiAccessInterceptorTest.java b/framework/src/test/java/org/tron/core/services/filter/RpcApiAccessInterceptorTest.java index 59c4509c441..7d95c0c368a 100644 --- a/framework/src/test/java/org/tron/core/services/filter/RpcApiAccessInterceptorTest.java +++ b/framework/src/test/java/org/tron/core/services/filter/RpcApiAccessInterceptorTest.java @@ -48,7 +48,7 @@ public class RpcApiAccessInterceptorTest { private static WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; private static WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubPBFT = null; @ClassRule - public static TemporaryFolder temporaryFolder = new TemporaryFolder(); + public static final TemporaryFolder temporaryFolder = new TemporaryFolder(); /** * init logic. diff --git a/framework/src/test/java/org/tron/core/services/http/GetAssetIssueListServletTest.java b/framework/src/test/java/org/tron/core/services/http/GetAssetIssueListServletTest.java index 141c349e252..71a2d4fa5d5 100644 --- a/framework/src/test/java/org/tron/core/services/http/GetAssetIssueListServletTest.java +++ b/framework/src/test/java/org/tron/core/services/http/GetAssetIssueListServletTest.java @@ -19,10 +19,9 @@ public class GetAssetIssueListServletTest extends BaseTest { private GetAssetIssueListServlet getAssetIssueListServlet; static { - dbPath = "db_GetNowBlockServlet_test"; Args.setParam( new String[]{ - "--output-directory", dbPath, + "--output-directory", dbPath(), }, Constant.TEST_CONF ); } diff --git a/framework/src/test/java/org/tron/core/services/http/GetBandwidthPricesServletTest.java b/framework/src/test/java/org/tron/core/services/http/GetBandwidthPricesServletTest.java index 90d2794be9a..40ef8ad068f 100644 --- a/framework/src/test/java/org/tron/core/services/http/GetBandwidthPricesServletTest.java +++ b/framework/src/test/java/org/tron/core/services/http/GetBandwidthPricesServletTest.java @@ -5,15 +5,12 @@ import static org.tron.common.utils.client.utils.HttpMethed.createRequest; import com.alibaba.fastjson.JSONObject; -import java.io.IOException; import java.io.UnsupportedEncodingException; import javax.annotation.Resource; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.junit.BeforeClass; -import org.junit.ClassRule; import org.junit.Test; -import org.junit.rules.TemporaryFolder; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; import org.tron.common.BaseTest; @@ -22,14 +19,12 @@ public class GetBandwidthPricesServletTest extends BaseTest { - @ClassRule - public static final TemporaryFolder temporaryFolder = new TemporaryFolder(); @Resource private GetBandwidthPricesServlet getBandwidthPricesServlet; @BeforeClass - public static void init() throws IOException { - Args.setParam(new String[]{"-d", temporaryFolder.newFolder().toString()}, Constant.TEST_CONF); + public static void init() { + Args.setParam(new String[]{"-d", dbPath()}, Constant.TEST_CONF); } @Test diff --git a/framework/src/test/java/org/tron/core/services/http/GetBrokerageServletTest.java b/framework/src/test/java/org/tron/core/services/http/GetBrokerageServletTest.java index 898108d0dcd..c7fa8f7fc58 100644 --- a/framework/src/test/java/org/tron/core/services/http/GetBrokerageServletTest.java +++ b/framework/src/test/java/org/tron/core/services/http/GetBrokerageServletTest.java @@ -19,10 +19,9 @@ public class GetBrokerageServletTest extends BaseTest { private GetBrokerageServlet getBrokerageServlet; static { - dbPath = "db_GetBrokerageServlet_test"; Args.setParam( new String[]{ - "--output-directory", dbPath, + "--output-directory", dbPath(), }, Constant.TEST_CONF ); } diff --git a/framework/src/test/java/org/tron/core/services/http/GetEnergyPricesServletTest.java b/framework/src/test/java/org/tron/core/services/http/GetEnergyPricesServletTest.java index 391f2c2d4a7..34e93c557f5 100644 --- a/framework/src/test/java/org/tron/core/services/http/GetEnergyPricesServletTest.java +++ b/framework/src/test/java/org/tron/core/services/http/GetEnergyPricesServletTest.java @@ -5,15 +5,12 @@ import static org.tron.common.utils.client.utils.HttpMethed.createRequest; import com.alibaba.fastjson.JSONObject; -import java.io.IOException; import java.io.UnsupportedEncodingException; import javax.annotation.Resource; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.junit.BeforeClass; -import org.junit.ClassRule; import org.junit.Test; -import org.junit.rules.TemporaryFolder; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; import org.tron.common.BaseTest; @@ -22,14 +19,12 @@ public class GetEnergyPricesServletTest extends BaseTest { - @ClassRule - public static final TemporaryFolder temporaryFolder = new TemporaryFolder(); @Resource private GetEnergyPricesServlet getEnergyPricesServlet; @BeforeClass - public static void init() throws IOException { - Args.setParam(new String[]{"-d", temporaryFolder.newFolder().toString()}, Constant.TEST_CONF); + public static void init() { + Args.setParam(new String[]{"-d", dbPath()}, Constant.TEST_CONF); } @Test diff --git a/framework/src/test/java/org/tron/core/services/http/GetMemoFeePricesServletTest.java b/framework/src/test/java/org/tron/core/services/http/GetMemoFeePricesServletTest.java index cdfb32cb411..a954f4f4f8f 100644 --- a/framework/src/test/java/org/tron/core/services/http/GetMemoFeePricesServletTest.java +++ b/framework/src/test/java/org/tron/core/services/http/GetMemoFeePricesServletTest.java @@ -5,15 +5,12 @@ import static org.tron.common.utils.client.utils.HttpMethed.createRequest; import com.alibaba.fastjson.JSONObject; -import java.io.IOException; import java.io.UnsupportedEncodingException; import javax.annotation.Resource; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.junit.BeforeClass; -import org.junit.ClassRule; import org.junit.Test; -import org.junit.rules.TemporaryFolder; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; import org.tron.common.BaseTest; @@ -22,14 +19,12 @@ public class GetMemoFeePricesServletTest extends BaseTest { - @ClassRule - public static final TemporaryFolder temporaryFolder = new TemporaryFolder(); @Resource private GetMemoFeePricesServlet getMemoFeePricesServlet; @BeforeClass - public static void init() throws IOException { - Args.setParam(new String[]{"-d", temporaryFolder.newFolder().toString()}, Constant.TEST_CONF); + public static void init() { + Args.setParam(new String[]{"-d",dbPath()}, Constant.TEST_CONF); } @Test diff --git a/framework/src/test/java/org/tron/core/services/http/GetNowBlockServletTest.java b/framework/src/test/java/org/tron/core/services/http/GetNowBlockServletTest.java index 682f780b249..0406d7b89cb 100644 --- a/framework/src/test/java/org/tron/core/services/http/GetNowBlockServletTest.java +++ b/framework/src/test/java/org/tron/core/services/http/GetNowBlockServletTest.java @@ -20,10 +20,9 @@ public class GetNowBlockServletTest extends BaseTest { private GetNowBlockServlet getNowBlockServlet; static { - dbPath = "db_GetNowBlockServlet_test"; Args.setParam( new String[]{ - "--output-directory", dbPath, + "--output-directory", dbPath(), }, Constant.TEST_CONF ); } diff --git a/framework/src/test/java/org/tron/core/services/http/GetRewardServletTest.java b/framework/src/test/java/org/tron/core/services/http/GetRewardServletTest.java index 47e563f01f9..c8ae67a4a79 100644 --- a/framework/src/test/java/org/tron/core/services/http/GetRewardServletTest.java +++ b/framework/src/test/java/org/tron/core/services/http/GetRewardServletTest.java @@ -37,10 +37,9 @@ public class GetRewardServletTest extends BaseTest { GetRewardServlet getRewardServlet; static { - dbPath = "db_GetRewardServlet_test"; Args.setParam( new String[]{ - "--output-directory", dbPath, + "--output-directory", dbPath(), }, Constant.TEST_CONF ); } diff --git a/framework/src/test/java/org/tron/core/services/http/ListNodesServletTest.java b/framework/src/test/java/org/tron/core/services/http/ListNodesServletTest.java index e2b8e7e9b6e..1f491ca11db 100644 --- a/framework/src/test/java/org/tron/core/services/http/ListNodesServletTest.java +++ b/framework/src/test/java/org/tron/core/services/http/ListNodesServletTest.java @@ -19,10 +19,9 @@ public class ListNodesServletTest extends BaseTest { private ListNodesServlet listNodesServlet; static { - dbPath = "db_GetNowBlockServlet_test"; Args.setParam( new String[]{ - "--output-directory", dbPath, + "--output-directory", dbPath(), }, Constant.TEST_CONF ); } diff --git a/framework/src/test/java/org/tron/core/services/http/ListProposalsServletTest.java b/framework/src/test/java/org/tron/core/services/http/ListProposalsServletTest.java index 0879d02004b..aa3a1817a3e 100644 --- a/framework/src/test/java/org/tron/core/services/http/ListProposalsServletTest.java +++ b/framework/src/test/java/org/tron/core/services/http/ListProposalsServletTest.java @@ -19,10 +19,9 @@ public class ListProposalsServletTest extends BaseTest { private ListProposalsServlet listProposalsServlet; static { - dbPath = "db_GetNowBlockServlet_test"; Args.setParam( new String[]{ - "--output-directory", dbPath, + "--output-directory", dbPath(), }, Constant.TEST_CONF ); } diff --git a/framework/src/test/java/org/tron/core/services/http/TriggerSmartContractServletTest.java b/framework/src/test/java/org/tron/core/services/http/TriggerSmartContractServletTest.java index 0525ec6e9d0..384c0cada6c 100644 --- a/framework/src/test/java/org/tron/core/services/http/TriggerSmartContractServletTest.java +++ b/framework/src/test/java/org/tron/core/services/http/TriggerSmartContractServletTest.java @@ -40,9 +40,8 @@ public class TriggerSmartContractServletTest extends BaseTest { @BeforeClass public static void init() throws Exception { - dbPath = "output_" + TriggerSmartContractServletTest.class.getName(); Args.setParam( - new String[]{"--output-directory", dbPath, "--debug", "--witness"}, Constant.TEST_CONF); + new String[]{"--output-directory", dbPath(), "--debug", "--witness"}, Constant.TEST_CONF); Args.getInstance().needSyncCheck = false; // build app context diff --git a/framework/src/test/java/org/tron/core/services/http/UtilTest.java b/framework/src/test/java/org/tron/core/services/http/UtilTest.java index 2fd69a4b8e2..5d9d8092b22 100644 --- a/framework/src/test/java/org/tron/core/services/http/UtilTest.java +++ b/framework/src/test/java/org/tron/core/services/http/UtilTest.java @@ -2,7 +2,6 @@ import com.google.protobuf.ByteString; import javax.annotation.Resource; - import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -28,9 +27,8 @@ public class UtilTest extends BaseTest { private TransactionUtil transactionUtil; static { - dbPath = "output_util_test"; OWNER_ADDRESS = Wallet.getAddressPreFixString() + "c076305e35aea1fe45a772fcaaab8a36e87bdb55"; - Args.setParam(new String[] {"-d", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[] {"-d", dbPath()}, Constant.TEST_CONF); } @Before diff --git a/framework/src/test/java/org/tron/core/services/interfaceOnPBFT/http/GetBandwidthPricesOnPBFTServletTest.java b/framework/src/test/java/org/tron/core/services/interfaceOnPBFT/http/GetBandwidthPricesOnPBFTServletTest.java index 06d552f1ede..a8e07b743c5 100644 --- a/framework/src/test/java/org/tron/core/services/interfaceOnPBFT/http/GetBandwidthPricesOnPBFTServletTest.java +++ b/framework/src/test/java/org/tron/core/services/interfaceOnPBFT/http/GetBandwidthPricesOnPBFTServletTest.java @@ -5,15 +5,12 @@ import static org.tron.common.utils.client.utils.HttpMethed.createRequest; import com.alibaba.fastjson.JSONObject; -import java.io.IOException; import java.io.UnsupportedEncodingException; import javax.annotation.Resource; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.junit.BeforeClass; -import org.junit.ClassRule; import org.junit.Test; -import org.junit.rules.TemporaryFolder; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; import org.tron.common.BaseTest; @@ -22,14 +19,12 @@ public class GetBandwidthPricesOnPBFTServletTest extends BaseTest { - @ClassRule - public static final TemporaryFolder temporaryFolder = new TemporaryFolder(); @Resource private GetBandwidthPricesOnPBFTServlet getBandwidthPricesOnPBFTServlet; @BeforeClass - public static void init() throws IOException { - Args.setParam(new String[]{"-d", temporaryFolder.newFolder().toString()}, Constant.TEST_CONF); + public static void init() { + Args.setParam(new String[]{"-d", dbPath()}, Constant.TEST_CONF); } @Test diff --git a/framework/src/test/java/org/tron/core/services/interfaceOnPBFT/http/GetEnergyPricesOnPBFTServletTest.java b/framework/src/test/java/org/tron/core/services/interfaceOnPBFT/http/GetEnergyPricesOnPBFTServletTest.java index ec2ce818da0..8785618bdbe 100644 --- a/framework/src/test/java/org/tron/core/services/interfaceOnPBFT/http/GetEnergyPricesOnPBFTServletTest.java +++ b/framework/src/test/java/org/tron/core/services/interfaceOnPBFT/http/GetEnergyPricesOnPBFTServletTest.java @@ -5,15 +5,12 @@ import static org.tron.common.utils.client.utils.HttpMethed.createRequest; import com.alibaba.fastjson.JSONObject; -import java.io.IOException; import java.io.UnsupportedEncodingException; import javax.annotation.Resource; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.junit.BeforeClass; -import org.junit.ClassRule; import org.junit.Test; -import org.junit.rules.TemporaryFolder; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; import org.tron.common.BaseTest; @@ -22,14 +19,12 @@ public class GetEnergyPricesOnPBFTServletTest extends BaseTest { - @ClassRule - public static final TemporaryFolder temporaryFolder = new TemporaryFolder(); @Resource private GetEnergyPricesOnPBFTServlet getEnergyPricesOnPBFTServlet; @BeforeClass - public static void init() throws IOException { - Args.setParam(new String[]{"-d", temporaryFolder.newFolder().toString()}, Constant.TEST_CONF); + public static void init() { + Args.setParam(new String[]{"-d", dbPath()}, Constant.TEST_CONF); } @Test diff --git a/framework/src/test/java/org/tron/core/services/interfaceOnSolidity/http/GetBandwidthPricesOnSolidityServletTest.java b/framework/src/test/java/org/tron/core/services/interfaceOnSolidity/http/GetBandwidthPricesOnSolidityServletTest.java index 6eb27113b99..4b1ace08970 100644 --- a/framework/src/test/java/org/tron/core/services/interfaceOnSolidity/http/GetBandwidthPricesOnSolidityServletTest.java +++ b/framework/src/test/java/org/tron/core/services/interfaceOnSolidity/http/GetBandwidthPricesOnSolidityServletTest.java @@ -5,15 +5,12 @@ import static org.tron.common.utils.client.utils.HttpMethed.createRequest; import com.alibaba.fastjson.JSONObject; -import java.io.IOException; import java.io.UnsupportedEncodingException; import javax.annotation.Resource; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.junit.BeforeClass; -import org.junit.ClassRule; import org.junit.Test; -import org.junit.rules.TemporaryFolder; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; import org.tron.common.BaseTest; @@ -22,14 +19,12 @@ public class GetBandwidthPricesOnSolidityServletTest extends BaseTest { - @ClassRule - public static final TemporaryFolder temporaryFolder = new TemporaryFolder(); @Resource private GetBandwidthPricesOnSolidityServlet getBandwidthPricesOnSolidityServlet; @BeforeClass - public static void init() throws IOException { - Args.setParam(new String[]{"-d", temporaryFolder.newFolder().toString()}, Constant.TEST_CONF); + public static void init() { + Args.setParam(new String[]{"-d", dbPath()}, Constant.TEST_CONF); } @Test diff --git a/framework/src/test/java/org/tron/core/services/interfaceOnSolidity/http/GetEnergyPricesOnSolidityServletTest.java b/framework/src/test/java/org/tron/core/services/interfaceOnSolidity/http/GetEnergyPricesOnSolidityServletTest.java index 174175918c1..6a26f9bc861 100644 --- a/framework/src/test/java/org/tron/core/services/interfaceOnSolidity/http/GetEnergyPricesOnSolidityServletTest.java +++ b/framework/src/test/java/org/tron/core/services/interfaceOnSolidity/http/GetEnergyPricesOnSolidityServletTest.java @@ -5,15 +5,12 @@ import static org.tron.common.utils.client.utils.HttpMethed.createRequest; import com.alibaba.fastjson.JSONObject; -import java.io.IOException; import java.io.UnsupportedEncodingException; import javax.annotation.Resource; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.junit.BeforeClass; -import org.junit.ClassRule; import org.junit.Test; -import org.junit.rules.TemporaryFolder; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; import org.tron.common.BaseTest; @@ -22,14 +19,12 @@ public class GetEnergyPricesOnSolidityServletTest extends BaseTest { - @ClassRule - public static final TemporaryFolder temporaryFolder = new TemporaryFolder(); @Resource private GetEnergyPricesOnSolidityServlet getEnergyPricesOnSolidityServlet; @BeforeClass - public static void init() throws IOException { - Args.setParam(new String[]{"-d", temporaryFolder.newFolder().toString()}, Constant.TEST_CONF); + public static void init() { + Args.setParam(new String[]{"-d", dbPath()}, Constant.TEST_CONF); } @Test diff --git a/framework/src/test/java/org/tron/core/services/stop/BlockHeightStopTest.java b/framework/src/test/java/org/tron/core/services/stop/BlockHeightStopTest.java index a05cc64aad4..66a827fc55e 100644 --- a/framework/src/test/java/org/tron/core/services/stop/BlockHeightStopTest.java +++ b/framework/src/test/java/org/tron/core/services/stop/BlockHeightStopTest.java @@ -18,10 +18,4 @@ protected void check() throws Exception { Assert.assertEquals(height, dbManager.getDynamicPropertiesStore() .getLatestBlockHeaderNumberFromDB()); } - - @Override - protected void initDbPath() { - dbPath = "output-height-stop"; - } - } diff --git a/framework/src/test/java/org/tron/core/services/stop/BlockSyncCountStopTest.java b/framework/src/test/java/org/tron/core/services/stop/BlockSyncCountStopTest.java index f974a8a4272..0ac9b93f2dc 100644 --- a/framework/src/test/java/org/tron/core/services/stop/BlockSyncCountStopTest.java +++ b/framework/src/test/java/org/tron/core/services/stop/BlockSyncCountStopTest.java @@ -19,10 +19,4 @@ protected void check() throws Exception { Assert.assertEquals(sync + currentHeader, dbManager .getDynamicPropertiesStore().getLatestBlockHeaderNumberFromDB()); } - - @Override - protected void initDbPath() { - dbPath = "output-sync-stop"; - } - } diff --git a/framework/src/test/java/org/tron/core/services/stop/BlockTimeStopTest.java b/framework/src/test/java/org/tron/core/services/stop/BlockTimeStopTest.java index 2d3fde1afdb..86c32e66507 100644 --- a/framework/src/test/java/org/tron/core/services/stop/BlockTimeStopTest.java +++ b/framework/src/test/java/org/tron/core/services/stop/BlockTimeStopTest.java @@ -37,10 +37,4 @@ protected void check() throws Exception { Assert.assertTrue(cronExpression.isSatisfiedBy(new Date(chainManager .getBlockById(chainManager.getBlockIdByNum(height)).getTimeStamp()))); } - - @Override - protected void initDbPath() { - dbPath = "output-time-stop"; - } - } diff --git a/framework/src/test/java/org/tron/core/services/stop/ConditionallyStopTest.java b/framework/src/test/java/org/tron/core/services/stop/ConditionallyStopTest.java index 617e824c58f..dc3d02e7ced 100644 --- a/framework/src/test/java/org/tron/core/services/stop/ConditionallyStopTest.java +++ b/framework/src/test/java/org/tron/core/services/stop/ConditionallyStopTest.java @@ -3,6 +3,7 @@ import com.google.common.collect.Maps; import com.google.protobuf.ByteString; import java.io.File; +import java.io.IOException; import java.time.LocalDateTime; import java.time.ZoneId; import java.time.ZonedDateTime; @@ -17,7 +18,9 @@ import org.junit.After; import org.junit.Assert; import org.junit.Before; +import org.junit.ClassRule; import org.junit.Test; +import org.junit.rules.TemporaryFolder; import org.tron.common.application.TronApplicationContext; import org.tron.common.crypto.ECKey; import org.tron.common.parameter.CommonParameter; @@ -44,6 +47,8 @@ @Slf4j public abstract class ConditionallyStopTest extends BlockGenerate { + @ClassRule + public static final TemporaryFolder temporaryFolder = new TemporaryFolder(); static ChainBaseManager chainManager; private static DposSlot dposSlot; @@ -67,14 +72,15 @@ public abstract class ConditionallyStopTest extends BlockGenerate { protected abstract void check() throws Exception; - protected abstract void initDbPath(); + protected void initDbPath() throws IOException { + dbPath = temporaryFolder.newFolder().toString(); + } @Before public void init() throws Exception { initDbPath(); - FileUtil.deleteDir(new File(dbPath)); logger.info("Full node running."); Args.setParam(new String[] {"-d", dbPath, "-w"}, Constant.TEST_CONF); Args.getInstance().setNodeListenPort(10000 + port.incrementAndGet()); @@ -108,7 +114,6 @@ public void init() throws Exception { public void destroy() { Args.clearParam(); context.destroy(); - FileUtil.deleteDir(new File(dbPath)); } private void generateBlock(Map witnessAndAccount) throws Exception { diff --git a/framework/src/test/java/org/tron/core/witness/ProposalControllerTest.java b/framework/src/test/java/org/tron/core/witness/ProposalControllerTest.java index 769b09770c2..c7b55ed4417 100644 --- a/framework/src/test/java/org/tron/core/witness/ProposalControllerTest.java +++ b/framework/src/test/java/org/tron/core/witness/ProposalControllerTest.java @@ -29,8 +29,7 @@ public class ProposalControllerTest extends BaseTest { private static boolean init; static { - dbPath = "output_proposal_controller_test"; - Args.setParam(new String[]{"-d", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"-d", dbPath()}, Constant.TEST_CONF); } @Before diff --git a/framework/src/test/java/org/tron/core/witness/WitnessControllerTest.java b/framework/src/test/java/org/tron/core/witness/WitnessControllerTest.java index dcca6e4bc65..26e46ac138c 100644 --- a/framework/src/test/java/org/tron/core/witness/WitnessControllerTest.java +++ b/framework/src/test/java/org/tron/core/witness/WitnessControllerTest.java @@ -20,8 +20,7 @@ public class WitnessControllerTest extends BaseTest { static { - dbPath = "output_witness_controller_test"; - Args.setParam(new String[]{"-d", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"-d", dbPath()}, Constant.TEST_CONF); } @Test diff --git a/framework/src/test/java/org/tron/core/zksnark/LibrustzcashTest.java b/framework/src/test/java/org/tron/core/zksnark/LibrustzcashTest.java index 38fdce334b2..67353eb24b1 100644 --- a/framework/src/test/java/org/tron/core/zksnark/LibrustzcashTest.java +++ b/framework/src/test/java/org/tron/core/zksnark/LibrustzcashTest.java @@ -73,10 +73,9 @@ public class LibrustzcashTest extends BaseTest { @BeforeClass public static void init() { - dbPath = "output_Librustzcash_test"; Args.setParam( new String[]{ - "--output-directory", dbPath, + "--output-directory", dbPath(), "--storage-db-directory", dbDirectory, "--storage-index-directory", indexDirectory, "-w", diff --git a/framework/src/test/java/org/tron/core/zksnark/MerkleContainerTest.java b/framework/src/test/java/org/tron/core/zksnark/MerkleContainerTest.java index 678eb137df0..6216ab41f3f 100644 --- a/framework/src/test/java/org/tron/core/zksnark/MerkleContainerTest.java +++ b/framework/src/test/java/org/tron/core/zksnark/MerkleContainerTest.java @@ -38,8 +38,7 @@ public class MerkleContainerTest extends BaseTest { static { - dbPath = "MerkleContainerTest"; - Args.setParam(new String[]{"-d", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"-d", dbPath()}, Constant.TEST_CONF); } /*@Before diff --git a/framework/src/test/java/org/tron/core/zksnark/MerkleTreeTest.java b/framework/src/test/java/org/tron/core/zksnark/MerkleTreeTest.java index a3048a14375..cb70adb35a2 100644 --- a/framework/src/test/java/org/tron/core/zksnark/MerkleTreeTest.java +++ b/framework/src/test/java/org/tron/core/zksnark/MerkleTreeTest.java @@ -31,10 +31,9 @@ public class MerkleTreeTest extends BaseTest { private static boolean init; static { - dbPath = "output_ShieldedTransaction_test"; Args.setParam( new String[]{ - "--output-directory", dbPath, + "--output-directory", dbPath(), "--storage-db-directory", dbDirectory, "--storage-index-directory", indexDirectory, "-w", diff --git a/framework/src/test/java/org/tron/core/zksnark/NoteEncDecryTest.java b/framework/src/test/java/org/tron/core/zksnark/NoteEncDecryTest.java index e2b8ef43306..e59060540e9 100644 --- a/framework/src/test/java/org/tron/core/zksnark/NoteEncDecryTest.java +++ b/framework/src/test/java/org/tron/core/zksnark/NoteEncDecryTest.java @@ -22,7 +22,6 @@ @Slf4j public class NoteEncDecryTest extends BaseTest { - private static final String dbPath = "note_encdec_test"; private static final String FROM_ADDRESS; private static final String ADDRESS_ONE_PRIVATE_KEY; private static final long OWNER_BALANCE = 100_000_000; @@ -41,7 +40,7 @@ public class NoteEncDecryTest extends BaseTest { private Wallet wallet; static { - Args.setParam(new String[]{"--output-directory", dbPath}, "config-localtest.conf"); + Args.setParam(new String[]{"--output-directory", dbPath()}, "config-localtest.conf"); FROM_ADDRESS = Wallet.getAddressPreFixString() + "a7d8a35b260395c14aa456297662092ba3b76fc0"; ADDRESS_ONE_PRIVATE_KEY = "7f7f701e94d4f1dd60ee5205e7ea8ee31121427210417b608a6b2e96433549a7"; } diff --git a/framework/src/test/java/org/tron/core/zksnark/SendCoinShieldTest.java b/framework/src/test/java/org/tron/core/zksnark/SendCoinShieldTest.java index 5fafe0724dc..4a844c49c3c 100644 --- a/framework/src/test/java/org/tron/core/zksnark/SendCoinShieldTest.java +++ b/framework/src/test/java/org/tron/core/zksnark/SendCoinShieldTest.java @@ -110,8 +110,7 @@ public class SendCoinShieldTest extends BaseTest { private static boolean init; static { - dbPath = "output_ShieldedTransaction_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, "config-test-mainnet.conf"); + Args.setParam(new String[]{"--output-directory", dbPath()}, "config-test-mainnet.conf"); Args.getInstance().setZenTokenId(String.valueOf(tokenId)); PUBLIC_ADDRESS_ONE = Wallet.getAddressPreFixString() + "a7d8a35b260395c14aa456297662092ba3b76fc0"; diff --git a/framework/src/test/java/org/tron/core/zksnark/ShieldedReceiveTest.java b/framework/src/test/java/org/tron/core/zksnark/ShieldedReceiveTest.java index e52021986fc..819bfede557 100755 --- a/framework/src/test/java/org/tron/core/zksnark/ShieldedReceiveTest.java +++ b/framework/src/test/java/org/tron/core/zksnark/ShieldedReceiveTest.java @@ -122,8 +122,7 @@ public class ShieldedReceiveTest extends BaseTest { private static boolean init; static { - dbPath = "receive_description_test"; - Args.setParam(new String[]{"--output-directory", dbPath}, "config-localtest.conf"); + Args.setParam(new String[]{"--output-directory", dbPath()}, "config-localtest.conf"); FROM_ADDRESS = Wallet.getAddressPreFixString() + "a7d8a35b260395c14aa456297662092ba3b76fc0"; ADDRESS_ONE_PRIVATE_KEY = "7f7f701e94d4f1dd60ee5205e7ea8ee31121427210417b608a6b2e96433549a7"; } diff --git a/framework/src/test/java/org/tron/program/AccountVoteWitnessTest.java b/framework/src/test/java/org/tron/program/AccountVoteWitnessTest.java index 9f61d91a938..decdbff5e25 100755 --- a/framework/src/test/java/org/tron/program/AccountVoteWitnessTest.java +++ b/framework/src/test/java/org/tron/program/AccountVoteWitnessTest.java @@ -22,8 +22,7 @@ public class AccountVoteWitnessTest extends BaseTest { private MaintenanceManager maintenanceManager; static { - dbPath = "output_witness_test"; - Args.setParam(new String[]{"-d", dbPath}, Constant.TEST_CONF); + Args.setParam(new String[]{"-d", dbPath()}, Constant.TEST_CONF); } private static Boolean deleteFolder(File index) { diff --git a/framework/src/test/java/org/tron/program/SolidityNodeTest.java b/framework/src/test/java/org/tron/program/SolidityNodeTest.java index 4d151cda7f0..3ec8959e821 100755 --- a/framework/src/test/java/org/tron/program/SolidityNodeTest.java +++ b/framework/src/test/java/org/tron/program/SolidityNodeTest.java @@ -1,33 +1,34 @@ package org.tron.program; import java.io.File; +import java.io.IOException; +import javax.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; -import org.tron.common.application.TronApplicationContext; +import org.tron.common.BaseTest; import org.tron.common.client.DatabaseGrpcClient; import org.tron.core.Constant; -import org.tron.core.config.DefaultConfig; import org.tron.core.config.args.Args; import org.tron.core.services.RpcApiService; import org.tron.protos.Protocol.Block; import org.tron.protos.Protocol.DynamicProperties; @Slf4j -public class SolidityNodeTest { +public class SolidityNodeTest extends BaseTest { - private static TronApplicationContext context; - - private static RpcApiService rpcApiService; - private static String dbPath = "output_sn_test"; + @Resource + RpcApiService rpcApiService; static { - Args.setParam(new String[]{"-d", dbPath}, Constant.TEST_CONF); - context = new TronApplicationContext(DefaultConfig.class); + try { + Args.setParam(new String[]{"-d", temporaryFolder.newFolder().toString()}, Constant.TEST_CONF); + } catch (IOException e) { + Assert.fail("create temp directory failed."); + } Args.getInstance().setSolidityNode(true); - rpcApiService = context.getBean(RpcApiService.class); } /** @@ -35,8 +36,6 @@ public class SolidityNodeTest { */ @BeforeClass public static void init() { - rpcApiService.init(Args.getInstance()); - rpcApiService.start(); } /** @@ -45,14 +44,6 @@ public static void init() { @AfterClass public static void removeDb() { Args.clearParam(); - rpcApiService.stop(); - context.destroy(); - File dbFolder = new File(dbPath); - if (deleteFolder(dbFolder)) { - logger.info("Release resources successful."); - } else { - logger.info("Release resources failure."); - } } private static Boolean deleteFolder(File index) { @@ -75,6 +66,8 @@ public void testSolidityArgs() { @Test public void testSolidityGrpcCall() { + rpcApiService.init(Args.getInstance()); + rpcApiService.start(); DatabaseGrpcClient databaseGrpcClient = null; String address = Args.getInstance().getTrustNodeAddr(); try { @@ -98,6 +91,7 @@ public void testSolidityGrpcCall() { logger.error("Failed to create database grpc client {}", address); } databaseGrpcClient.shutdown(); + rpcApiService.stop(); } } diff --git a/framework/src/test/java/org/tron/program/SupplementTest.java b/framework/src/test/java/org/tron/program/SupplementTest.java index 5655ee4a098..f370a871006 100644 --- a/framework/src/test/java/org/tron/program/SupplementTest.java +++ b/framework/src/test/java/org/tron/program/SupplementTest.java @@ -5,12 +5,15 @@ import static org.junit.Assert.assertTrue; import java.io.File; +import java.io.IOException; import java.math.BigInteger; import javax.annotation.Resource; import org.junit.BeforeClass; +import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import org.junit.rules.TemporaryFolder; import org.junit.runner.RunWith; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; @@ -34,7 +37,9 @@ @ContextConfiguration(classes = {DefaultConfig.class}) public class SupplementTest { - private static final String dbPath = "output_coverage_test"; + @ClassRule + public static final TemporaryFolder temporaryFolder = new TemporaryFolder(); + private static String dbPath; @Resource private StorageRowStore storageRowStore; @@ -43,7 +48,8 @@ public class SupplementTest { public ExpectedException thrown = ExpectedException.none(); @BeforeClass - public static void init() { + public static void init() throws IOException { + dbPath = temporaryFolder.newFolder().toString(); Args.setParam(new String[]{"--output-directory", dbPath, "--debug"}, Constant.TEST_CONF); } @@ -53,7 +59,8 @@ public void testGet() throws Exception { assertNotNull(storageRowCapsule); DbBackupConfig dbBackupConfig = new DbBackupConfig(); - dbBackupConfig.initArgs(true, "propPath", "bak1path/", "bak2path/", 1); + String p = dbPath + File.separator; + dbBackupConfig.initArgs(true, p + "propPath", p + "bak1path/", p + "bak2path/", 1); WalletUtils.generateFullNewWalletFile("123456", new File(dbPath)); WalletUtils.generateLightNewWalletFile("123456", new File(dbPath));