Skip to content

Commit 631c5df

Browse files
authored
Merge pull request #5080 from lurais/feature/auto_stop_opt
fix(test): add wallet unit test
2 parents 0cb97fe + 172010e commit 631c5df

2 files changed

Lines changed: 72 additions & 0 deletions

File tree

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,5 +1066,17 @@ public void testEstimateEnergyOutOfTime() {
10661066
Assert.assertTrue(true);
10671067
}
10681068
}
1069+
1070+
@Test
1071+
public void testListNodes() {
1072+
try {
1073+
GrpcAPI.NodeList nodeList = wallet.listNodes();
1074+
} catch (Exception e) {
1075+
Assert.assertTrue(e instanceof NullPointerException);
1076+
}
1077+
Args.getInstance().setP2pDisable(true);
1078+
GrpcAPI.NodeList nodeList = wallet.listNodes();
1079+
Assert.assertTrue(nodeList.getNodesList().size() == 0);
1080+
}
10691081
}
10701082

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package org.tron.core.services;
2+
3+
import io.grpc.ManagedChannelBuilder;
4+
import java.io.File;
5+
import lombok.extern.slf4j.Slf4j;
6+
import org.junit.After;
7+
import org.junit.Assert;
8+
import org.junit.Before;
9+
import org.junit.Test;
10+
import org.tron.api.GrpcAPI.EmptyMessage;
11+
import org.tron.api.WalletGrpc;
12+
import org.tron.common.application.Application;
13+
import org.tron.common.application.ApplicationFactory;
14+
import org.tron.common.application.TronApplicationContext;
15+
import org.tron.common.utils.FileUtil;
16+
import org.tron.core.Constant;
17+
import org.tron.core.config.DefaultConfig;
18+
import org.tron.core.config.args.Args;
19+
import stest.tron.wallet.common.client.Configuration;
20+
21+
@Slf4j
22+
public class WalletApiTest {
23+
24+
private static TronApplicationContext context;
25+
private static String dbPath = "output_wallet_api_test";
26+
private String fullnode = Configuration.getByPath("testng.conf")
27+
.getStringList("fullnode.ip.list").get(0);
28+
private RpcApiService rpcApiService;
29+
private Application appT;
30+
31+
@Before
32+
public void init() {
33+
Args.setParam(new String[]{ "-d", dbPath, "--p2p-disable", "true"}, Constant.TEST_CONF);
34+
context = new TronApplicationContext(DefaultConfig.class);
35+
appT = ApplicationFactory.create(context);
36+
rpcApiService = context.getBean(RpcApiService.class);
37+
appT.addService(rpcApiService);
38+
appT.initServices(Args.getInstance());
39+
appT.startServices();
40+
appT.startup();
41+
}
42+
43+
@Test
44+
public void listNodesTest() {
45+
WalletGrpc.WalletBlockingStub walletStub = WalletGrpc
46+
.newBlockingStub(ManagedChannelBuilder.forTarget(fullnode)
47+
.usePlaintext(true)
48+
.build());
49+
Assert.assertTrue(walletStub.listNodes(EmptyMessage.getDefaultInstance())
50+
.getNodesList().size() == 0);
51+
}
52+
53+
@After
54+
public void destroy() {
55+
Args.clearParam();
56+
context.destroy();
57+
FileUtil.deleteDir(new File(dbPath));
58+
}
59+
60+
}

0 commit comments

Comments
 (0)