Skip to content

Commit df190a8

Browse files
committed
unittest for windows
1 parent 412b300 commit df190a8

12 files changed

Lines changed: 75 additions & 5 deletions

‎src/test/java/org/tron/common/runtime/InheritanceTest.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import org.junit.BeforeClass;
77
import org.junit.Test;
88
import org.spongycastle.util.encoders.Hex;
9+
import org.tron.common.application.Application;
10+
import org.tron.common.application.ApplicationFactory;
911
import org.tron.common.application.TronApplicationContext;
1012
import org.testng.Assert;
1113
import org.tron.common.storage.DepositImpl;
@@ -26,13 +28,15 @@ public class InheritanceTest {
2628
private static Runtime runtime;
2729
private static Manager dbManager;
2830
private static TronApplicationContext context;
31+
private static Application appT;
2932
private static DepositImpl deposit;
3033
private static final String dbPath = "output_InheritanceTest";
3134
private static final String OWNER_ADDRESS;
3235

3336
static {
3437
Args.setParam(new String[]{"--output-directory", dbPath,"--debug"}, Constant.TEST_CONF);
3538
context = new TronApplicationContext(DefaultConfig.class);
39+
appT = ApplicationFactory.create(context);
3640
OWNER_ADDRESS = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc";
3741
}
3842

@@ -130,6 +134,8 @@ public void inheritanceTest()
130134
@AfterClass
131135
public static void destroy() {
132136
Args.clearParam();
137+
appT.shutdownServices();
138+
appT.shutdown();
133139
context.destroy();
134140
if (FileUtil.deleteDir(new File(dbPath))) {
135141
logger.info("Release resources successful.");

‎src/test/java/org/tron/common/runtime/InternalTransactionComplexTest.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import org.junit.Test;
88
import org.spongycastle.util.encoders.Hex;
99
import org.testng.Assert;
10+
import org.tron.common.application.Application;
11+
import org.tron.common.application.ApplicationFactory;
1012
import org.tron.common.application.TronApplicationContext;
1113
import org.tron.common.runtime.vm.DataWord;
1214
import org.tron.common.storage.DepositImpl;
@@ -28,6 +30,7 @@ public class InternalTransactionComplexTest {
2830
private static Runtime runtime;
2931
private static Manager dbManager;
3032
private static TronApplicationContext context;
33+
private static Application appT;
3134
private static DepositImpl deposit;
3235
private static final String dbPath = "output_InternalTransactionComplexTest";
3336
private static final String OWNER_ADDRESS;
@@ -36,6 +39,7 @@ public class InternalTransactionComplexTest {
3639
Args.setParam(new String[]{"--output-directory", dbPath, "--debug", "--support-constant"},
3740
Constant.TEST_CONF);
3841
context = new TronApplicationContext(DefaultConfig.class);
42+
appT = ApplicationFactory.create(context);
3943
OWNER_ADDRESS = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc";
4044
}
4145

@@ -168,6 +172,8 @@ private byte[] deployCallerContractAndGetItsAddress(byte[] calledContractAddress
168172
@AfterClass
169173
public static void destroy() {
170174
Args.clearParam();
175+
appT.shutdownServices();
176+
appT.shutdown();
171177
context.destroy();
172178
if (FileUtil.deleteDir(new File(dbPath))) {
173179
logger.info("Release resources successful.");

‎src/test/java/org/tron/common/runtime/RuntimeTransferComplexTest.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import org.junit.BeforeClass;
77
import org.junit.Test;
88
import org.spongycastle.util.encoders.Hex;
9+
import org.tron.common.application.Application;
10+
import org.tron.common.application.ApplicationFactory;
911
import org.tron.common.application.TronApplicationContext;
1012
import org.testng.Assert;
1113
import org.tron.common.storage.DepositImpl;
@@ -27,6 +29,7 @@ public class RuntimeTransferComplexTest {
2729
private static Runtime runtime;
2830
private static Manager dbManager;
2931
private static TronApplicationContext context;
32+
private static Application appT;
3033
private static DepositImpl deposit;
3134
private static final String dbPath = "output_RuntimeTransferComplexTest";
3235
private static final String OWNER_ADDRESS;
@@ -35,6 +38,7 @@ public class RuntimeTransferComplexTest {
3538
static {
3639
Args.setParam(new String[]{"--output-directory", dbPath, "--debug"}, Constant.TEST_CONF);
3740
context = new TronApplicationContext(DefaultConfig.class);
41+
appT = ApplicationFactory.create(context);
3842
OWNER_ADDRESS = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc";
3943
TRANSFER_TO = Wallet.getAddressPreFixString() + "548794500882809695a8a687866e76d4271a1abc";
4044
}
@@ -167,6 +171,8 @@ public void TransferTrxToContractAccountWhenTriggerAContract()
167171
@AfterClass
168172
public static void destroy() {
169173
Args.clearParam();
174+
appT.shutdownServices();
175+
appT.shutdown();
170176
context.destroy();
171177
if (FileUtil.deleteDir(new File(dbPath))) {
172178
logger.info("Release resources successful.");

‎src/test/java/org/tron/common/runtime/vm/ChargeTest.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import org.junit.Test;
99
import org.spongycastle.util.encoders.Hex;
1010
import org.testng.Assert;
11+
import org.tron.common.application.Application;
12+
import org.tron.common.application.ApplicationFactory;
1113
import org.tron.common.application.TronApplicationContext;
1214
import org.tron.common.runtime.TVMTestResult;
1315
import org.tron.common.runtime.TVMTestUtils;
@@ -30,6 +32,7 @@ public class ChargeTest {
3032

3133
private Manager dbManager;
3234
private TronApplicationContext context;
35+
private Application appT;
3336
private DepositImpl deposit;
3437
private String dbPath = "output_ChargeTest";
3538
private String OWNER_ADDRESS;
@@ -43,6 +46,7 @@ public void init() {
4346
Args.setParam(new String[]{"--output-directory", dbPath, "--debug"},
4447
Constant.TEST_CONF);
4548
context = new TronApplicationContext(DefaultConfig.class);
49+
appT = ApplicationFactory.create(context);
4650
OWNER_ADDRESS = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc";
4751
dbManager = context.getBean(Manager.class);
4852
deposit = DepositImpl.createRoot(dbManager);
@@ -338,6 +342,8 @@ public void testCreateDepthAndWidth()
338342
@After
339343
public void destroy() {
340344
Args.clearParam();
345+
appT.shutdownServices();
346+
appT.shutdown();
341347
context.destroy();
342348
if (FileUtil.deleteDir(new File(dbPath))) {
343349
logger.info("Release resources successful.");

‎src/test/java/org/tron/common/runtime/vm/EnergyWhenAssertStyleTest.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import org.spongycastle.util.encoders.Hex;
1010
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
1111
import org.testng.Assert;
12+
import org.tron.common.application.Application;
13+
import org.tron.common.application.ApplicationFactory;
1214
import org.tron.common.application.TronApplicationContext;
1315
import org.tron.common.runtime.TVMTestResult;
1416
import org.tron.common.runtime.TVMTestUtils;
@@ -35,6 +37,7 @@ public class EnergyWhenAssertStyleTest {
3537

3638
private Manager dbManager;
3739
private AnnotationConfigApplicationContext context;
40+
private Application appT;
3841
private DepositImpl deposit;
3942
private String dbPath = "output_EnergyWhenAssertStyleTest";
4043
private String OWNER_ADDRESS;
@@ -48,6 +51,7 @@ public void init() {
4851
Args.setParam(new String[]{"--output-directory", dbPath, "--debug"}, Constant.TEST_CONF);
4952
// context = new AnnotationConfigApplicationContext(DefaultConfig.class);
5053
context = new TronApplicationContext(DefaultConfig.class);
54+
appT = ApplicationFactory.create(context);
5155
OWNER_ADDRESS = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc";
5256
dbManager = context.getBean(Manager.class);
5357
deposit = DepositImpl.createRoot(dbManager);
@@ -493,6 +497,8 @@ public void overflowTest()
493497
@After
494498
public void destroy() {
495499
Args.clearParam();
500+
appT.shutdownServices();
501+
appT.shutdown();
496502
context.destroy();
497503
if (FileUtil.deleteDir(new File(dbPath))) {
498504
logger.info("Release resources successful.");

‎src/test/java/org/tron/common/runtime/vm/EnergyWhenRequireStyleTest.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
import org.junit.Test;
99
import org.spongycastle.util.encoders.Hex;
1010
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
11+
import org.springframework.context.support.ApplicationObjectSupport;
1112
import org.testng.Assert;
13+
import org.tron.common.application.Application;
14+
import org.tron.common.application.ApplicationFactory;
1215
import org.tron.common.application.TronApplicationContext;
1316
import org.tron.common.runtime.TVMTestResult;
1417
import org.tron.common.runtime.TVMTestUtils;
@@ -32,6 +35,7 @@ public class EnergyWhenRequireStyleTest {
3235

3336
private Manager dbManager;
3437
private AnnotationConfigApplicationContext context;
38+
private Application appT;
3539
private DepositImpl deposit;
3640
private String dbPath = "output_EnergyWhenRequireStyleTest";
3741
private String OWNER_ADDRESS;
@@ -45,6 +49,7 @@ public void init() {
4549
Args.setParam(new String[]{"--output-directory", dbPath, "--debug"}, Constant.TEST_CONF);
4650
// context = new AnnotationConfigApplicationContext(DefaultConfig.class);
4751
context = new TronApplicationContext(DefaultConfig.class);
52+
appT = ApplicationFactory.create(context);
4853
OWNER_ADDRESS = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc";
4954
dbManager = context.getBean(Manager.class);
5055
deposit = DepositImpl.createRoot(dbManager);
@@ -453,6 +458,8 @@ public void reach64CallDepth() {
453458
@After
454459
public void destroy() {
455460
Args.clearParam();
461+
appT.shutdownServices();
462+
appT.shutdown();
456463
context.destroy();
457464
if (FileUtil.deleteDir(new File(dbPath))) {
458465
logger.info("Release resources successful.");

‎src/test/java/org/tron/common/runtime/vm/EnergyWhenSendAndTransferTest.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ public TVMTestResult deploySendAndTransferTestContract(long value, long feeLimit
237237
@After
238238
public void destroy() {
239239
Args.clearParam();
240+
AppT.shutdownServices();
240241
AppT.shutdown();
241242
context.destroy();
242243
if (FileUtil.deleteDir(new File(dbPath))) {

‎src/test/java/org/tron/common/runtime/vm/EnergyWhenTimeoutStyleTest.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import org.junit.Test;
88
import org.spongycastle.util.encoders.Hex;
99
import org.testng.Assert;
10+
import org.tron.common.application.Application;
11+
import org.tron.common.application.ApplicationFactory;
1012
import org.tron.common.application.TronApplicationContext;
1113
import org.tron.common.runtime.TVMTestResult;
1214
import org.tron.common.runtime.TVMTestUtils;
@@ -29,6 +31,7 @@ public class EnergyWhenTimeoutStyleTest {
2931

3032
private Manager dbManager;
3133
private TronApplicationContext context;
34+
private Application appT;
3235
private DepositImpl deposit;
3336
private String dbPath = "output_CPUTimeTest";
3437
private String OWNER_ADDRESS;
@@ -42,6 +45,7 @@ public void init() {
4245
Args.setParam(new String[]{"--output-directory", dbPath},
4346
Constant.TEST_CONF);
4447
context = new TronApplicationContext(DefaultConfig.class);
48+
appT = ApplicationFactory.create(context);
4549
OWNER_ADDRESS = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc";
4650
dbManager = context.getBean(Manager.class);
4751
deposit = DepositImpl.createRoot(dbManager);
@@ -121,6 +125,8 @@ public TVMTestResult deployEndlessLoopContract(long value, long feeLimit,
121125
@After
122126
public void destroy() {
123127
Args.clearParam();
128+
appT.shutdownServices();
129+
appT.shutdown();
124130
context.destroy();
125131
if (FileUtil.deleteDir(new File(dbPath))) {
126132
logger.info("Release resources successful.");

‎src/test/java/org/tron/common/runtime/vm/PrecompiledContractsTest.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import org.junit.Test;
1818
import org.spongycastle.util.Arrays;
1919
import org.spongycastle.util.encoders.Hex;
20+
import org.tron.common.application.Application;
21+
import org.tron.common.application.ApplicationFactory;
2022
import org.tron.common.application.TronApplicationContext;
2123
import org.tron.common.runtime.vm.PrecompiledContracts.PrecompiledContract;
2224
import org.tron.common.runtime.vm.program.ProgramResult;
@@ -68,6 +70,7 @@ public class PrecompiledContractsTest {
6870
"0000000000000000000000000000000000000000000000000000000000010009");
6971

7072
private static TronApplicationContext context;
73+
private static Application appT;
7174
private static Manager dbManager;
7275
private static final String dbPath = "output_PrecompiledContracts_test";
7376
private static final String ACCOUNT_NAME = "account";
@@ -84,6 +87,7 @@ public class PrecompiledContractsTest {
8487
static {
8588
Args.setParam(new String[]{"--output-directory", dbPath, "--debug"}, Constant.TEST_CONF);
8689
context = new TronApplicationContext(DefaultConfig.class);
90+
appT = ApplicationFactory.create(context);
8791
OWNER_ADDRESS = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc";
8892
WITNESS_ADDRESS = Wallet.getAddressPreFixString() + WITNESS_ADDRESS_BASE;
8993

@@ -324,6 +328,8 @@ public void convertFromTronBase58AddressNative() {
324328
@AfterClass
325329
public static void destroy() {
326330
Args.clearParam();
331+
appT.shutdownServices();
332+
appT.shutdown();
327333
context.destroy();
328334
if (FileUtil.deleteDir(new File(dbPath))) {
329335
logger.info("Release resources successful.");

‎src/test/java/org/tron/common/storage/leveldb/LevelDbDataSourceImplTest.java‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public void testPutGet() {
9393
assertNotNull(dataSourceTest.getData(key));
9494
assertEquals(1, dataSourceTest.allKeys().size());
9595
assertEquals("50000", ByteArray.toStr(dataSourceTest.getData(key1.getBytes())));
96-
96+
dataSourceTest.closeDB();
9797
}
9898

9999
@Test
@@ -102,7 +102,7 @@ public void testReset() {
102102
Args.getInstance().getOutputDirectory(), "test_reset");
103103
dataSource.resetDb();
104104
assertEquals(0, dataSource.allKeys().size());
105-
//dataSource.closeDB();
105+
dataSource.closeDB();
106106
}
107107

108108
@Test
@@ -125,6 +125,7 @@ public void testupdateByBatchInner() {
125125
assertEquals("50000", ByteArray.toStr(dataSource.getData(key1.getBytes())));
126126
assertEquals("10000", ByteArray.toStr(dataSource.getData(key2.getBytes())));
127127
assertEquals(2, dataSource.allKeys().size());
128+
dataSource.closeDB();
128129
}
129130

130131
@Test
@@ -138,7 +139,7 @@ public void testdeleteData() {
138139
byte[] value = dataSource.getData(key);
139140
String s = ByteArray.toStr(value);
140141
assertNull(s);
141-
142+
dataSource.closeDB();
142143
}
143144

144145
@Test
@@ -164,6 +165,7 @@ public void testallKeys() {
164165
dataSource.putData(key2, value2);
165166
assertEquals(2, dataSource.allKeys().size());
166167
dataSource.resetDb();
168+
dataSource.closeDB();
167169
}
168170

169171
@Test(timeout = 1000)
@@ -198,6 +200,7 @@ public void allKeysTest() {
198200
});
199201
assertEquals(2, dataSource.allKeys().size());
200202
dataSource.resetDb();
203+
dataSource.closeDB();
201204
}
202205

203206
private void putSomeKeyValue(LevelDbDataSourceImpl dataSource) {
@@ -231,6 +234,7 @@ public void seekTest() {
231234

232235
putSomeKeyValue(dataSource);
233236
dataSource.resetDb();
237+
dataSource.closeDB();
234238
}
235239

236240
@Test
@@ -247,6 +251,7 @@ public void getValuesNext() {
247251
Assert.assertTrue("getValuesNext", hashSet.contains(ByteArray.toStr(valeu)));
248252
});
249253
dataSource.resetDb();
254+
dataSource.closeDB();
250255
}
251256

252257
@Test
@@ -265,5 +270,6 @@ public void getValuesPrev() {
265270
seekKeyLimitNext = dataSource.getValuesPrev("0000000100".getBytes(), 2);
266271
Assert.assertEquals("getValuesPrev2", 0, seekKeyLimitNext.size());
267272
dataSource.resetDb();
273+
dataSource.closeDB();
268274
}
269275
}

0 commit comments

Comments
 (0)