Skip to content

Commit a3b837d

Browse files
authored
Merge pull request #5241 from forfreeday/feat/clean_test_merge
feat(test): optimize test case
2 parents c340aa8 + b7ffe58 commit a3b837d

25 files changed

Lines changed: 253 additions & 188 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 & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,6 @@ genesis.block = {
188188
accountType = "AssetIssue"
189189
address = "TJCnKsPa7y5okkXvQAidZBzqx3QyQ6sxMW"
190190
balance = "25000000000000000"
191-
#priKey = D95611A9AF2A2A45359106222ED1AFED48853D9A44DEFF8DC7913F5CBA727366
192-
#password = 2VYRqa8qKkU1kQYiLtGv7UiFPZpE3v+Nx5E/XLpyc2Y=
193191
},
194192

195193
# the account of payment
@@ -198,8 +196,6 @@ genesis.block = {
198196
accountType = "AssetIssue"
199197
address = "TGehVcNhud84JDCGrNHKVz9jEAVKUpbuiv"
200198
balance = "10000000000000000"
201-
#priKey = cba92a516ea09f620a16ff7ee95ce0df1d56550a8babe9964981a7144c8a784a
202-
#password = y6kqUW6gn2IKFv9+6Vzg3x1WVQqLq+mWSYGnFEyKeEo=
203199
},
204200

205201
# the account of coin burn
@@ -208,8 +204,6 @@ genesis.block = {
208204
accountType = "AssetIssue"
209205
address = "THKrowiEfCe8evdbaBzDDvQjM5DGeB3s3F"
210206
balance = "-9223372036854775808"
211-
#priKey = 8E812436A0E3323166E1F0E8BA79E19E217B2C4A53C970D4CCA0CFB1078979DF
212-
#password = joEkNqDjMjFm4fDounnhniF7LEpTyXDUzKDPsQeJed8=
213207
}
214208
]
215209

@@ -218,27 +212,23 @@ genesis.block = {
218212
address: TN3zfjYUmMFK3ZsHSsrdJoNRtGkQmZLBLz
219213
url = "http://Test.org",
220214
voteCount = 106
221-
#priKey = f4df789d3210ac881cb900464dd30409453044d2777060a0c391cbdf4c6a4f57 6666
222215
},
223216
// {
224217
// address: TPrLL5ckUdMaPNgJYmGv23qtYjBE34aBf8
225218
// url = "http://Mercury.org",
226219
// voteCount = 105
227-
// #priKey = f5583fd20e13073900a513f333ed13db8c9e83e7e3cf37e74adacef96c5afeaa 7777
228220
// },
229221
// {
230222
// address: TEZBh76rouEQpB2zqYVopbRXGx7RfyWorT
231223
// #address: 27TfVERREG3FeWMHEAQ95tWHG4sb3ANn3Qe
232224
// url = "http://Venus.org",
233225
// voteCount = 104
234-
// #priKey = 9f5c5e48bf87cf92017313082e8cf0f58ccfce423097f0fcebf801695fc99bd4 8888
235226
// },
236227
// {
237228
// address: TN27wbfCLEN1gP2PZAxHgU3QZrntsLyxdj
238229
// #address: 27b8RUuyZnNPFNZGct2bZkNu9MnGWNAdH3Z
239230
// url = "http://Earth.org",
240231
// voteCount = 103
241-
// #priKey = 6781f44d9a2083b14fad1702b8e9ba82749162b795e2fc3f136192fc63f80de2 9999
242232
// },
243233
]
244234

@@ -256,7 +246,7 @@ genesis.block = {
256246
//localWitnessAccountAddress = TN3zfjYUmMFK3ZsHSsrdJoNRtGkQmZLBLz
257247

258248
localwitness = [
259-
f4df789d3210ac881cb900464dd30409453044d2777060a0c391cbdf4c6a4f57
249+
260250
]
261251

262252

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
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,
17+
* after the ECkey tool or algorithm is upgraded,
18+
* the upgraded differences can be verified.
19+
*/
1520
public class BouncyCastleTest {
1621

1722
private String privString = "c85ef7d79691fe79573b1a7064c19c1a9819ebdbd1faaab1a8ec92344438aaf4";

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
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,
24+
* after the ECkey tool or algorithm is upgraded,
25+
* the upgraded differences can be verified.
26+
*/
2227
@Slf4j
2328
public class ECKeyTest {
2429

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
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,
24+
* after the ECkey tool or algorithm is upgraded,
25+
* the upgraded differences can be verified.
26+
*/
2227
@Slf4j
2328
public class SM2KeyTest {
2429

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)