Skip to content

Commit 7676699

Browse files
committed
feat: optimize ZksnarkParams initialization in tests.
1 parent 704f8a5 commit 7676699

File tree

5 files changed

+23
-99
lines changed

5 files changed

+23
-99
lines changed

framework/src/test/java/org/tron/core/ShieldWalletTest.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.math.BigInteger;
88
import javax.annotation.Resource;
99
import org.junit.Assert;
10+
import org.junit.BeforeClass;
1011
import org.junit.Test;
1112
import org.tron.api.GrpcAPI.PrivateParameters;
1213
import org.tron.api.GrpcAPI.PrivateParametersWithoutAsk;
@@ -29,13 +30,14 @@ public class ShieldWalletTest extends BaseTest {
2930
@Resource
3031
private Wallet wallet;
3132

32-
static {
33-
Args.setParam(new String[] {"-d", dbPath()}, Constant.TEST_CONF);
33+
@BeforeClass
34+
public static void init() {
35+
Args.setParam(new String[]{"-d", dbPath()}, Constant.TEST_CONF);
36+
librustzcashInitZksnarkParams();
3437
}
3538

3639
@Test
3740
public void testCreateShieldedTransaction1() {
38-
librustzcashInitZksnarkParams();
3941
String transactionStr1 = new String(ByteArray.fromHexString(
4042
"0x7b0a20202020227472616e73706172656e745f66726f6d5f61646472657373223a202234433930413"
4143
+ "73241433344414546324536383932343545463430303839443634314345414337373433323433414233"
@@ -68,7 +70,6 @@ public void testCreateShieldedTransaction1() {
6870

6971
@Test
7072
public void testCreateShieldedTransaction2() {
71-
librustzcashInitZksnarkParams();
7273
String transactionStr2 = new String(ByteArray.fromHexString(
7374
"7b0a202020202261736b223a20223938666430333136376632333437623534643737323338343137663"
7475
+ "6373038643537323939643938376362613838353564653037626532346236316464653064222c0a2020"
@@ -176,7 +177,6 @@ public void testCreateShieldedTransaction2() {
176177

177178
@Test
178179
public void testCreateShieldedTransactionWithoutSpendAuthSig() {
179-
librustzcashInitZksnarkParams();
180180
String transactionStr3 = new String(ByteArray.fromHexString(
181181
"7b0a2020202022616b223a2022373161643638633466353035373464356164333735343863626538363"
182182
+ "63031663732393662393161306362303535353733313462373830383437323730326465222c0a202020"
@@ -286,7 +286,6 @@ public void testCreateShieldedTransactionWithoutSpendAuthSig() {
286286

287287
@Test
288288
public void testGetNewShieldedAddress() {
289-
librustzcashInitZksnarkParams();
290289
try {
291290
ShieldedAddressInfo shieldedAddressInfo = wallet.getNewShieldedAddress();
292291
Assert.assertNotNull(shieldedAddressInfo);
@@ -297,7 +296,6 @@ public void testGetNewShieldedAddress() {
297296

298297
@Test
299298
public void testCreateShieldedContractParameters() throws ContractExeException {
300-
librustzcashInitZksnarkParams();
301299
Args.getInstance().setAllowShieldedTransactionApi(true);
302300
Wallet wallet1 = spy(new Wallet());
303301

@@ -340,7 +338,6 @@ public void testCreateShieldedContractParameters() throws ContractExeException {
340338

341339
@Test
342340
public void testCreateShieldedContractParameters2() throws ContractExeException {
343-
librustzcashInitZksnarkParams();
344341
Args.getInstance().setAllowShieldedTransactionApi(true);
345342
Wallet wallet1 = spy(new Wallet());
346343

@@ -416,7 +413,6 @@ public void testCreateShieldedContractParameters2() throws ContractExeException
416413

417414
@Test
418415
public void testCreateShieldedContractParametersWithoutAsk() throws ContractExeException {
419-
librustzcashInitZksnarkParams();
420416
Args.getInstance().setAllowShieldedTransactionApi(true);
421417

422418
Wallet wallet1 = spy(new Wallet());

framework/src/test/java/org/tron/core/ShieldedTRC20BuilderTest.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package org.tron.core;
22

3-
import static org.tron.core.zksnark.LibrustzcashTest.librustzcashInitZksnarkParams;
4-
53
import com.google.protobuf.ByteString;
64
import java.math.BigInteger;
75
import java.util.Arrays;
@@ -12,7 +10,7 @@
1210
import org.apache.commons.lang3.tuple.Pair;
1311
import org.bouncycastle.util.encoders.Hex;
1412
import org.junit.Assert;
15-
import org.junit.Before;
13+
import org.junit.BeforeClass;
1614
import org.junit.Ignore;
1715
import org.junit.Test;
1816
import org.tron.api.GrpcAPI;
@@ -68,16 +66,16 @@ public class ShieldedTRC20BuilderTest extends BaseTest {
6866
SHIELDED_CONTRACT_ADDRESS = WalletClient.decodeFromBase58Check(SHIELDED_CONTRACT_ADDRESS_STR);
6967
DEFAULT_OVK = ByteArray
7068
.fromHexString("030c8c2bc59fb3eb8afb047a8ea4b028743d23e7d38c6fa30908358431e2314d");
71-
ZksnarkInitService.librustzcashInitZksnarkParams();
7269
PUBLIC_TO_ADDRESS = WalletClient.decodeFromBase58Check(PUBLIC_TO_ADDRESS_STR);
7370
}
7471

7572
VerifyMintProof mintContract = new VerifyMintProof();
7673
VerifyTransferProof transferContract = new VerifyTransferProof();
7774
VerifyBurnProof burnContract = new VerifyBurnProof();
7875

79-
@Before
80-
public void before() {
76+
@BeforeClass
77+
public static void initZksnarkParams() {
78+
ZksnarkInitService.librustzcashInitZksnarkParams();
8179
}
8280

8381
@Ignore
@@ -2172,7 +2170,6 @@ public void createShieldedContractParametersWithoutAskForBurn1to2()
21722170
@Ignore
21732171
@Test
21742172
public void getTriggerInputForForMint() throws Exception {
2175-
librustzcashInitZksnarkParams();
21762173
SpendingKey sk = SpendingKey.random();
21772174
ExpandedSpendingKey expsk = sk.expandedSpendingKey();
21782175
byte[] ovk = expsk.getOvk();
@@ -2241,7 +2238,6 @@ public void getTriggerInputForForMint() throws Exception {
22412238
public void testScanShieldedTRC20NotesByIvk() throws Exception {
22422239
int statNum = 1;
22432240
int endNum = 100;
2244-
librustzcashInitZksnarkParams();
22452241
SpendingKey sk = SpendingKey.decode(priKey);
22462242
FullViewingKey fvk = sk.fullViewingKey();
22472243
byte[] ivk = fvk.inViewingKey().value;
@@ -2273,7 +2269,6 @@ public void testscanShieldedTRC20NotesByOvk() throws Exception {
22732269
public void isShieldedTRC20ContractNoteSpent() throws Exception {
22742270
int statNum = 9200;
22752271
int endNum = 9240;
2276-
librustzcashInitZksnarkParams();
22772272
SpendingKey sk = SpendingKey.decode(priKey);
22782273
FullViewingKey fvk = sk.fullViewingKey();
22792274
byte[] ivk = fvk.inViewingKey().value;
@@ -2350,7 +2345,6 @@ private byte[] decodePath(byte[] encodedPath) {
23502345
private GrpcAPI.PrivateShieldedTRC20Parameters mintParams(String privKey,
23512346
long value, String contractAddr, byte[] rcm)
23522347
throws ZksnarkException, ContractValidateException {
2353-
librustzcashInitZksnarkParams();
23542348
long fromAmount = value;
23552349
SpendingKey sk = SpendingKey.decode(privKey);
23562350
ExpandedSpendingKey expsk = sk.expandedSpendingKey();

framework/src/test/java/org/tron/core/zksnark/LibrustzcashTest.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public static void init() {
8585
"config-test-mainnet.conf"
8686
);
8787
Args.getInstance().setAllowShieldedTransactionApi(true);
88+
ZksnarkInitService.librustzcashInitZksnarkParams();
8889
}
8990

9091
private static int randomInt(int minInt, int maxInt) {
@@ -115,10 +116,6 @@ public static void test(byte[] K, byte[] ovk, byte[] cv, byte[] cm, byte[] epk)
115116
null, 0, cipher_nonce, K)));
116117
}
117118

118-
public static void librustzcashInitZksnarkParams() {
119-
ZksnarkInitService.librustzcashInitZksnarkParams();
120-
}
121-
122119
@Test
123120
public void testLibsodium() throws ZksnarkException {
124121
byte[] K = new byte[32];
@@ -275,7 +272,6 @@ public long benchmarkCreateSpend() throws ZksnarkException {
275272
@Ignore
276273
@Test
277274
public void calBenchmarkSpendConcurrent() throws Exception {
278-
librustzcashInitZksnarkParams();
279275
System.out.println("--- load ok ---");
280276

281277
int count = 2;
@@ -307,7 +303,6 @@ public void calBenchmarkSpendConcurrent() throws Exception {
307303

308304
@Test
309305
public void calBenchmarkSpend() throws ZksnarkException {
310-
librustzcashInitZksnarkParams();
311306
System.out.println("--- load ok ---");
312307

313308
int count = 2;
@@ -374,7 +369,6 @@ public long benchmarkCreateSaplingSpend() throws BadItemException, ZksnarkExcept
374369

375370
@Test
376371
public void calBenchmarkCreateSaplingSpend() throws BadItemException, ZksnarkException {
377-
librustzcashInitZksnarkParams();
378372
System.out.println("--- load ok ---");
379373

380374
int count = 2;
@@ -451,7 +445,6 @@ public long benchmarkCreateSaplingOutput() throws BadItemException, ZksnarkExcep
451445

452446
@Test
453447
public void calBenchmarkCreateSaplingOutPut() throws BadItemException, ZksnarkException {
454-
librustzcashInitZksnarkParams();
455448
System.out.println("--- load ok ---");
456449

457450
int count = 2;
@@ -479,7 +472,6 @@ public void calBenchmarkCreateSaplingOutPut() throws BadItemException, ZksnarkEx
479472

480473
@Test
481474
public void checkVerifyOutErr() throws ZksnarkException {
482-
librustzcashInitZksnarkParams();
483475
System.out.println("--- load ok ---");
484476

485477
// expect fail

0 commit comments

Comments
 (0)