forked from tronprotocol/java-tron
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolidityNodeTest.java
More file actions
executable file
·99 lines (85 loc) · 2.74 KB
/
SolidityNodeTest.java
File metadata and controls
executable file
·99 lines (85 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package org.tron.program;
import java.io.File;
import lombok.extern.slf4j.Slf4j;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.tron.common.application.TronApplicationContext;
import org.tron.common.application.Application;
import org.tron.common.application.ApplicationFactory;
import org.tron.common.overlay.client.DatabaseGrpcClient;
import org.tron.core.Constant;
import org.tron.core.config.DefaultConfig;
import org.tron.core.config.args.Args;
import org.tron.core.services.RpcApiService;
import org.tron.protos.Protocol.Block;
import org.tron.protos.Protocol.DynamicProperties;
@Slf4j
public class SolidityNodeTest {
private static TronApplicationContext context;
private static RpcApiService rpcApiService;
private static Application appT;
private static String dbPath = "output_witness_test";
static {
Args.setParam(new String[]{"-d", dbPath}, Constant.TEST_CONF);
context = new TronApplicationContext(DefaultConfig.class);
Args.getInstance().setSolidityNode(true);
appT = ApplicationFactory.create(context);
rpcApiService = context.getBean(RpcApiService.class);
}
/**
* init db.
*/
@BeforeClass
public static void init() {
rpcApiService.start();
}
/**
* remo db when after test.
*/
@AfterClass
public static void removeDb() {
Args.clearParam();
rpcApiService.stop();
File dbFolder = new File(dbPath);
if (deleteFolder(dbFolder)) {
logger.info("Release resources successful.");
} else {
logger.info("Release resources failure.");
}
context.destroy();
}
private static Boolean deleteFolder(File index) {
if (!index.isDirectory() || index.listFiles().length <= 0) {
return index.delete();
}
for (File file : index.listFiles()) {
if (null != file && !deleteFolder(file)) {
return false;
}
}
return index.delete();
}
@Test
public void testSolidityArgs() {
Assert.assertNotNull(Args.getInstance().getTrustNodeAddr());
Assert.assertTrue(Args.getInstance().isSolidityNode());
}
@Test
public void testSolidityGrpcCall() {
DatabaseGrpcClient databaseGrpcClient = null;
String addr = Args.getInstance().getTrustNodeAddr();
try {
databaseGrpcClient = new DatabaseGrpcClient(addr);
} catch (Exception e) {
logger.error("Failed to create database grpc client {}", addr);
}
Assert.assertNotNull(databaseGrpcClient);
DynamicProperties dynamicProperties = databaseGrpcClient.getDynamicProperties();
Assert.assertNotNull(dynamicProperties);
Block genisisBlock = databaseGrpcClient.getBlock(0);
Assert.assertNotNull(genisisBlock);
Assert.assertFalse(genisisBlock.getTransactionsList().isEmpty());
}
}