Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ public class DatabaseGrpcClient {

public DatabaseGrpcClient(String host, int port) {
channel = ManagedChannelBuilder.forAddress(host, port)
.usePlaintext(true)
.usePlaintext()
.build();
databaseBlockingStub = DatabaseGrpc.newBlockingStub(channel);
}

public DatabaseGrpcClient(String host) {
channel = ManagedChannelBuilder.forTarget(host)
.usePlaintext(true)
.usePlaintext()
.build();
databaseBlockingStub = DatabaseGrpc.newBlockingStub(channel);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ public class WalletGrpcClient {

public WalletGrpcClient(String host, int port) {
channel = ManagedChannelBuilder.forAddress(host, port)
.usePlaintext(true)
.usePlaintext()
.build();
walletBlockingStub = WalletGrpc.newBlockingStub(channel);
}

public WalletGrpcClient(String host) {
channel = ManagedChannelBuilder.forTarget(host)
.usePlaintext(true)
.usePlaintext()
.build();
walletBlockingStub = WalletGrpc.newBlockingStub(channel);
}
Expand Down
17 changes: 9 additions & 8 deletions framework/src/main/java/org/tron/program/SolidityNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.BooleanUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.tron.common.application.Application;
import org.tron.common.application.ApplicationFactory;
Expand Down Expand Up @@ -37,7 +38,7 @@ public class SolidityNode {

private AtomicLong remoteBlockNum = new AtomicLong();

private LinkedBlockingDeque<Block> blockQueue = new LinkedBlockingDeque(100);
private LinkedBlockingDeque<Block> blockQueue = new LinkedBlockingDeque<>(100);

private int exceptionSleepTime = 1000;

Expand All @@ -48,7 +49,7 @@ public SolidityNode(Manager dbManager) {
this.chainBaseManager = dbManager.getChainBaseManager();
resolveCompatibilityIssueIfUsingFullNodeDatabase();
ID.set(chainBaseManager.getDynamicPropertiesStore().getLatestSolidifiedBlockNum());
databaseGrpcClient = new DatabaseGrpcClient(Args.getInstance().getTrustNodeAddr());
databaseGrpcClient = new DatabaseGrpcClient(CommonParameter.getInstance().getTrustNodeAddr());
remoteBlockNum.set(getLastSolidityBlockNum());
}

Expand All @@ -58,13 +59,13 @@ public SolidityNode(Manager dbManager) {
public static void main(String[] args) {
logger.info("Solidity node is running.");
Args.setParam(args, Constant.TESTNET_CONF);
CommonParameter parameter = Args.getInstance();
CommonParameter parameter = CommonParameter.getInstance();

logger.info("index switch is {}",
BooleanUtils.toStringOnOff(BooleanUtils
.toBoolean(parameter.getStorage().getIndexSwitch())));

if (StringUtils.isEmpty(parameter.getTrustNodeAddr())) {
if (ObjectUtils.isEmpty(parameter.getTrustNodeAddr())) {
logger.error("Trust node is not set.");
return;
}
Expand Down Expand Up @@ -102,13 +103,13 @@ public static void main(String[] args) {

private void start() {
try {
new Thread(() -> getBlock()).start();
new Thread(() -> processBlock()).start();
new Thread(this::getBlock).start();
new Thread(this::processBlock).start();
logger.info("Success to start solid node, ID: {}, remoteBlockNum: {}.", ID.get(),
remoteBlockNum);
} catch (Exception e) {
logger
.error("Failed to start solid node, address: {}.", Args.getInstance().getTrustNodeAddr());
logger.error("Failed to start solid node, address: {}.",
CommonParameter.getInstance().getTrustNodeAddr());
System.exit(0);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void tearDown() {
}

@Test
public void testDoPost() throws IOException {
public void doPostTest() throws IOException {
URLStreamHandlerFactory urlStreamHandlerFactory = mock(URLStreamHandlerFactory.class);
URL.setURLStreamHandlerFactory(urlStreamHandlerFactory);

Expand Down Expand Up @@ -139,6 +139,7 @@ public void testDoPost() throws IOException {
while ((line = in.readLine()) != null) {
result.append(line).append("\n");
}
Assert.assertNotNull(result);
in.close();
writer.flush();
FileInputStream fileInputStream = new FileInputStream("temp.txt");
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpResponse;
import org.bouncycastle.util.encoders.Hex;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
Expand Down Expand Up @@ -80,9 +81,12 @@ public void testNormalCall() {
parameter.addProperty("owner_address", ByteArray.toHexString(ownerAddr));
parameter.addProperty("contract_address", ByteArray.toHexString(contractAddr));
parameter.addProperty("function_selector", "test()");
invokeToLocal("triggersmartcontract", parameter);
invokeToLocal("triggerconstantcontract", parameter);
invokeToLocal("estimateenergy", parameter);
HttpResponse triggersmartcontract1 = invokeToLocal("triggersmartcontract", parameter);
HttpResponse triggersmartcontract2 = invokeToLocal("triggerconstantcontract", parameter);
HttpResponse triggersmartcontract3 = invokeToLocal("estimateenergy", parameter);
Assert.assertNotNull(triggersmartcontract1);
Assert.assertNotNull(triggersmartcontract2);
Assert.assertNotNull(triggersmartcontract3);
}

public static HttpResponse invokeToLocal(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static void init() {
*/

@Before
public void setUp() throws InterruptedException {
public void setUp() {
getTransactionByIdSolidityServlet = new GetTransactionByIdSolidityServlet();
this.request = mock(HttpServletRequest.class);
this.response = mock(HttpServletResponse.class);
Expand Down Expand Up @@ -96,7 +96,7 @@ public void doPostTest() throws IOException {
httpUrlConnection.setDoOutput(true);
String postData = "{\"value\": \"309b6fa3d01353e46f57dd8a8f27611f98e392b50d035cef21"
+ "3f2c55225a8bd2\"}";
httpUrlConnection.setRequestProperty("Content-Length", "" + postData.length());
httpUrlConnection.setRequestProperty("Content-Length", String.valueOf(postData.length()));

when(httpUrlConnection.getOutputStream()).thenReturn(outContent);
OutputStreamWriter out = new OutputStreamWriter(httpUrlConnection.getOutputStream(),
Expand All @@ -121,14 +121,15 @@ public void doPostTest() throws IOException {
while ((line = in.readLine()) != null) {
result.append(line).append("\n");
}
Assert.assertNotNull(result);
in.close();
writer.flush();
FileInputStream fileInputStream = new FileInputStream("temp.txt");
InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);

StringBuffer sb = new StringBuffer();
String text = null;
StringBuilder sb = new StringBuilder();
String text;
while ((text = bufferedReader.readLine()) != null) {
sb.append(text);
}
Expand All @@ -150,7 +151,7 @@ public void doGetTest() throws IOException {
httpUrlConnection.setDoOutput(true);
String postData = "{\"value\": \"309b6fa3d01353e46f57dd8a8f27611f98e392b50d035cef21"
+ "3f2c55225a8bd2\"}";
httpUrlConnection.setRequestProperty("Content-Length", "" + postData.length());
httpUrlConnection.setRequestProperty("Content-Length", String.valueOf(postData.length()));

when(httpUrlConnection.getOutputStream()).thenReturn(outContent);
OutputStreamWriter out = new OutputStreamWriter(httpUrlConnection.getOutputStream(),
Expand All @@ -175,14 +176,15 @@ public void doGetTest() throws IOException {
while ((line = in.readLine()) != null) {
result.append(line).append("\n");
}
Assert.assertNotNull(result);
in.close();
writer.flush();
FileInputStream fileInputStream = new FileInputStream("temp.txt");
InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);

StringBuffer sb = new StringBuffer();
String text = null;
StringBuilder sb = new StringBuilder();
String text;
while ((text = bufferedReader.readLine()) != null) {
sb.append(text);
}
Expand Down
Loading