Skip to content

Commit a115aa8

Browse files
forfreedayliukai
authored andcommitted
feat(test): Optimize test cases
1. remove `stest` package 2. optimize test cast code
1 parent c340aa8 commit a115aa8

25 files changed

Lines changed: 250 additions & 113 deletions

framework/build.gradle

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -159,35 +159,6 @@ test {
159159
}
160160
}
161161

162-
task stest(type: Test) {
163-
164-
useTestNG {
165-
suites(file('src/test/resources/testng.xml'))
166-
parallel 'tests'
167-
threadCount 4
168-
169-
}
170-
171-
testLogging {
172-
exceptionFormat = 'full'
173-
showStackTraces = "true"
174-
}
175-
176-
jacoco {
177-
destinationFile = file("$buildDir/jacoco/jacocoTest.exec")
178-
classDumpDir = file("$buildDir/jacoco/classpathdumps")
179-
}
180-
}
181-
182-
task dailyBuild(type: Test) {
183-
useTestNG {
184-
suites(file('src/test/resources/daily-build.xml'))
185-
parallel 'tests'
186-
threadCount 1
187-
}
188-
}
189-
190-
191162
jacocoTestReport {
192163
reports {
193164
xml.enabled true

framework/src/main/resources/config-localtest.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ genesis.block = {
256256
//localWitnessAccountAddress = TN3zfjYUmMFK3ZsHSsrdJoNRtGkQmZLBLz
257257

258258
localwitness = [
259-
f4df789d3210ac881cb900464dd30409453044d2777060a0c391cbdf4c6a4f57
259+
260260
]
261261

262262

framework/src/test/java/org/tron/common/crypto/BouncyCastleTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
import org.tron.common.crypto.sm2.SM2;
1313
import org.tron.common.utils.Sha256Hash;
1414

15+
/**
16+
* The reason the test case uses the private key plaintext is to ensure that, after the ECkey tool or algorithm is upgraded, the upgraded differences can be verified.
17+
*/
1518
public class BouncyCastleTest {
1619

1720
private String privString = "c85ef7d79691fe79573b1a7064c19c1a9819ebdbd1faaab1a8ec92344438aaf4";

framework/src/test/java/org/tron/common/crypto/ECKeyTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
import org.tron.common.crypto.ECKey.ECDSASignature;
2020
import org.tron.core.Wallet;
2121

22+
/**
23+
* The reason the test case uses the private key plaintext is to ensure that, after the ECkey tool or algorithm is upgraded, the upgraded differences can be verified.
24+
*/
2225
@Slf4j
2326
public class ECKeyTest {
2427

framework/src/test/java/org/tron/common/crypto/SM2KeyTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
import org.tron.common.crypto.sm2.SM2Signer;
2020
import org.tron.core.Wallet;
2121

22+
/**
23+
* The reason the test case uses the private key plaintext is to ensure that, after the ECkey tool or algorithm is upgraded, the upgraded differences can be verified.
24+
*/
2225
@Slf4j
2326
public class SM2KeyTest {
2427

framework/src/test/java/org/tron/common/crypto/SignatureInterfaceTest.java

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,26 @@
88
import org.bouncycastle.util.encoders.Hex;
99
import org.junit.Test;
1010
import org.tron.common.crypto.sm2.SM2;
11+
import org.tron.common.utils.PublicMethod;
1112

1213

1314
@Slf4j
1415
public class SignatureInterfaceTest {
1516

16-
private String SM2_privString = "128B2FA8BD433C6C068C8D803DFF79792A519A5517"
17-
+ "1B1B650C23661D15897263";
17+
private String SM2_privString = PublicMethod.getSM2RandomPrivateKey();
1818
private byte[] SM2_privateKey = Hex.decode(SM2_privString);
1919

20-
private String SM2_pubString = "04d5548c7825cbb56150a3506cd57464af8a1ae0519"
21-
+ "dfaf3c58221dc810caf28dd921073768fe3d59ce54e79a49445cf73fed23086537"
22-
+ "027264d168946d479533e";
23-
private String SM2_compressedPubString =
24-
"02d5548c7825cbb56150a3506cd57464af8a1ae0519dfaf3c58221dc810caf28dd";
20+
private String SM2_pubString = PublicMethod.getSM2PublicByPrivateKey(SM2_privString);
2521
private byte[] SM2_pubKey = Hex.decode(SM2_pubString);
26-
private byte[] SM2_compressedPubKey = Hex.decode(SM2_compressedPubString);
27-
private String SM2_address = "62e49e4c2f4e3c0653a02f8859c1e6991b759e87";
22+
private String SM2_address = PublicMethod.getSM2AddressByPrivateKey(SM2_privString);
2823

29-
30-
private String EC_privString = "c85ef7d79691fe79573b1a7064c19c1a9819ebdbd1faaab1a8ec92344438aaf4";
24+
private String EC_privString = PublicMethod.getRandomPrivateKey();
3125
private byte[] EC_privateKey = Hex.decode(EC_privString);
3226

33-
private String EC_pubString = "040947751e3022ecf3016be03ec77ab0ce3c2662b4843898cb068d74f698ccc"
34-
+ "8ad75aa17564ae80a20bb044ee7a6d903e8e8df624b089c95d66a0570f051e5a05b";
35-
private String EC_compressedPubString =
36-
"030947751e3022ecf3016be03ec77ab0ce3c2662b4843898cb068d74f6" + "98ccc8ad";
27+
private String EC_pubString = PublicMethod.getPublicByPrivateKey(EC_privString);
3728
private byte[] EC_pubKey = Hex.decode(EC_pubString);
38-
private byte[] EC_compressedPubKey = Hex.decode(EC_compressedPubString);
39-
private String EC_address = "cd2a3d9f938e13cd947ec05abc7fe734df8dd826";
29+
private String EC_address = PublicMethod.getHexAddressByPrivateKey(EC_privString);
30+
4031

4132

4233
@Test
@@ -83,11 +74,12 @@ public void testAddress() {
8374
SignInterface sign = new SM2(SM2_pubKey, false);
8475
byte[] prefix_address = sign.getAddress();
8576
byte[] address = Arrays.copyOfRange(prefix_address, 1, prefix_address.length);
86-
assertEquals(SM2_address, Hex.toHexString(address));
87-
77+
byte[] addressTmp = Arrays.copyOfRange(Hex.decode(SM2_address), 1, prefix_address.length);
78+
assertEquals(Hex.toHexString(addressTmp), Hex.toHexString(address));
8879
sign = new ECKey(EC_pubKey, false);
8980
prefix_address = sign.getAddress();
9081
address = Arrays.copyOfRange(prefix_address, 1, prefix_address.length);
91-
assertEquals(EC_address, Hex.toHexString(address));
82+
byte[] ecAddressTmp = Arrays.copyOfRange(Hex.decode(EC_address), 1, prefix_address.length);
83+
assertEquals(Hex.toHexString(ecAddressTmp), Hex.toHexString(address));
9284
}
9385
}

framework/src/test/java/org/tron/common/runtime/TvmTestUtils.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import lombok.extern.slf4j.Slf4j;
1111
import org.bouncycastle.util.encoders.Hex;
1212
import org.tron.common.crypto.Hash;
13-
import org.tron.common.utils.PublicMethod;
1413
import org.tron.common.utils.WalletUtil;
1514
import org.tron.common.utils.client.Parameter.CommonConstant;
1615
import org.tron.common.utils.client.WalletClient;

framework/src/test/java/org/tron/common/runtime/vm/Create2Test.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.tron.core.services.jsonrpc.TronJsonRpcImpl;
2626
import org.tron.protos.Protocol.Transaction;
2727

28+
2829
@Slf4j
2930
public class Create2Test extends VMTestBase {
3031
/*

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.junit.Test;
4141
import org.tron.common.utils.ByteArray;
4242
import org.tron.common.utils.FileUtil;
43+
import org.tron.common.utils.PublicMethod;
4344
import org.tron.core.Constant;
4445
import org.tron.core.config.args.Args;
4546
import org.tron.core.db2.common.WrappedByteArray;
@@ -86,7 +87,7 @@ public void initDb() {
8687
@Test
8788
public void testPutGet() {
8889
dataSourceTest.resetDb();
89-
String key1 = "2c0937534dd1b3832d05d865e8e6f2bf23218300b33a992740d45ccab7d4f519";
90+
String key1 = PublicMethod.getRandomPrivateKey();
9091
byte[] key = key1.getBytes();
9192
dataSourceTest.initDB();
9293
String value1 = "50000";
@@ -115,9 +116,9 @@ public void testupdateByBatchInner() {
115116
Args.getInstance().getOutputDirectory(), "test_updateByBatch");
116117
dataSource.initDB();
117118
dataSource.resetDb();
118-
String key1 = "431cd8c8d5abe5cb5944b0889b32482d85772fbb98987b10fbb7f17110757350";
119+
String key1 = PublicMethod.getRandomPrivateKey();
119120
String value1 = "50000";
120-
String key2 = "431cd8c8d5abe5cb5944b0889b32482d85772fbb98987b10fbb7f17110757351";
121+
String key2 = PublicMethod.getRandomPrivateKey();
121122
String value2 = "10000";
122123

123124
Map<byte[], byte[]> rows = new HashMap<>();
@@ -137,7 +138,7 @@ public void testdeleteData() {
137138
LevelDbDataSourceImpl dataSource = new LevelDbDataSourceImpl(
138139
Args.getInstance().getOutputDirectory(), "test_delete");
139140
dataSource.initDB();
140-
String key1 = "431cd8c8d5abe5cb5944b0889b32482d85772fbb98987b10fbb7f17110757350";
141+
String key1 = PublicMethod.getRandomPrivateKey();
141142
byte[] key = key1.getBytes();
142143
dataSource.deleteData(key);
143144
byte[] value = dataSource.getData(key);
@@ -153,14 +154,14 @@ public void testallKeys() {
153154
dataSource.initDB();
154155
dataSource.resetDb();
155156

156-
String key1 = "431cd8c8d5abe5cb5944b0889b32482d85772fbb98987b10fbb7f17110757321";
157+
String key1 = PublicMethod.getRandomPrivateKey();
157158
byte[] key = key1.getBytes();
158159

159160
String value1 = "50000";
160161
byte[] value = value1.getBytes();
161162

162163
dataSource.putData(key, value);
163-
String key3 = "431cd8c8d5abe5cb5944b0889b32482d85772fbb98987b10fbb7f17110757091";
164+
String key3 = PublicMethod.getRandomPrivateKey();
164165
byte[] key2 = key3.getBytes();
165166

166167
String value3 = "30000";
@@ -331,4 +332,4 @@ public void prefixQueryTest() {
331332
dataSource.resetDb();
332333
dataSource.closeDB();
333334
}
334-
}
335+
}

framework/src/test/java/org/tron/common/storage/leveldb/RocksDbDataSourceImplTest.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.tron.common.utils.ByteArray;
2626
import org.tron.common.utils.FileUtil;
2727
import org.tron.common.utils.PropUtil;
28+
import org.tron.common.utils.PublicMethod;
2829
import org.tron.core.config.args.Args;
2930
import org.tron.core.db2.common.WrappedByteArray;
3031

@@ -76,7 +77,7 @@ public static void initDb() {
7677
@Test
7778
public void testPutGet() {
7879
dataSourceTest.resetDb();
79-
String key1 = "2c0937534dd1b3832d05d865e8e6f2bf23218300b33a992740d45ccab7d4f519";
80+
String key1 = PublicMethod.getRandomPrivateKey();
8081
byte[] key = key1.getBytes();
8182
dataSourceTest.initDB();
8283
String value1 = "50000";
@@ -105,9 +106,9 @@ public void testupdateByBatchInner() {
105106
Args.getInstance().getOutputDirectory(), "test_updateByBatch");
106107
dataSource.initDB();
107108
dataSource.resetDb();
108-
String key1 = "431cd8c8d5abe5cb5944b0889b32482d85772fbb98987b10fbb7f17110757350";
109+
String key1 = PublicMethod.getRandomPrivateKey();
109110
String value1 = "50000";
110-
String key2 = "431cd8c8d5abe5cb5944b0889b32482d85772fbb98987b10fbb7f17110757351";
111+
String key2 = PublicMethod.getRandomPrivateKey();
111112
String value2 = "10000";
112113

113114
Map<byte[], byte[]> rows = new HashMap<>();
@@ -127,7 +128,7 @@ public void testdeleteData() {
127128
RocksDbDataSourceImpl dataSource = new RocksDbDataSourceImpl(
128129
Args.getInstance().getOutputDirectory(), "test_delete");
129130
dataSource.initDB();
130-
String key1 = "431cd8c8d5abe5cb5944b0889b32482d85772fbb98987b10fbb7f17110757350";
131+
String key1 = PublicMethod.getRandomPrivateKey();
131132
byte[] key = key1.getBytes();
132133
dataSource.deleteData(key);
133134
byte[] value = dataSource.getData(key);
@@ -143,14 +144,14 @@ public void testallKeys() {
143144
dataSource.initDB();
144145
dataSource.resetDb();
145146

146-
String key1 = "431cd8c8d5abe5cb5944b0889b32482d85772fbb98987b10fbb7f17110757321";
147+
String key1 = PublicMethod.getRandomPrivateKey();
147148
byte[] key = key1.getBytes();
148149

149150
String value1 = "50000";
150151
byte[] value = value1.getBytes();
151152

152153
dataSource.putData(key, value);
153-
String key3 = "431cd8c8d5abe5cb5944b0889b32482d85772fbb98987b10fbb7f17110757091";
154+
String key3 = PublicMethod.getRandomPrivateKey();
154155
byte[] key2 = key3.getBytes();
155156

156157
String value3 = "30000";

0 commit comments

Comments
 (0)