apikey已经配置,请完成上卖弄检查,也校验gRPC 连通性

This commit is contained in:
lu7213 committed 2026-10-16 23:07:48 -04:00
1 parent d2abfd88af
commit bd1231c2dd
5 files changed
+70 -18

No files matched your search

@@ -0,0 +1,37 @@
package com.ruoyi.system.service;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import org.junit.Assume;
import org.junit.Test;
import org.tron.api.GrpcAPI;
import org.tron.api.WalletGrpc;
import org.tron.protos.Protocol;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.assertTrue;
/** 真实网络检查,默认跳过;使用 -Dtron.grpc.integration=true 显式启用。 */
public class TronGrpcConnectivityTest {
@Test
public void shouldQueryLatestBlockFromAllNetworks() throws Exception {
Assume.assumeTrue(Boolean.getBoolean("tron.grpc.integration"));
assertLatestBlock("grpc.trongrid.io");
assertLatestBlock("grpc.nile.trongrid.io");
assertLatestBlock("grpc.shasta.trongrid.io");
}
private void assertLatestBlock(String host) throws Exception {
ManagedChannel channel = ManagedChannelBuilder.forAddress(host, 50051).usePlaintext().build();
try {
Protocol.Block block = WalletGrpc.newBlockingStub(channel)
.withDeadlineAfter(60, TimeUnit.SECONDS)
.getNowBlock(GrpcAPI.EmptyMessage.getDefaultInstance());
assertTrue(host + " 未返回有效区块", block.hasBlockHeader()
&& block.getBlockHeader().getRawData().getNumber() > 0L);
} finally {
channel.shutdownNow().awaitTermination(5, TimeUnit.SECONDS);
}
}
}