apikey已经配置,请完成上卖弄检查,也校验gRPC 连通性
This commit is contained in:
1 parent
d2abfd88af
commit
bd1231c2dd
5 files changed
+70
-18
No files matched your search
@@ -103,6 +103,20 @@ public class TronChainDataClientTest {
|
||||
assertEquals("scan-key", keys[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFallbackToPublicAccountEndpoint() {
|
||||
server.createContext("/scan/api/accountv2", new FixedResponseHandler(401, "unauthorized"));
|
||||
server.createContext("/scan/api/account", new FixedResponseHandler(200,
|
||||
"{\"address\":\"TAddress\",\"totalFrozenV2\":2000000}"));
|
||||
TronChainDataClient client = client(Collections.singletonList(baseUrl + "/scan"),
|
||||
Collections.singletonList(baseUrl + "/scan"));
|
||||
client.setTronscanApiKey("scan-key");
|
||||
|
||||
EnergyAndBandwidthVo summary = client.queryDelegatedResourceSummary("mainnet", "TAddress", "");
|
||||
|
||||
assertEquals(Long.valueOf(2L), summary.getStakedTrxNum());
|
||||
}
|
||||
|
||||
private TronChainDataClient client(List<String> transactions, List<String> accounts) {
|
||||
Map<String, List<String>> transactionEndpoints = new LinkedHashMap<>();
|
||||
Map<String, List<String>> accountEndpoints = new LinkedHashMap<>();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user