|
| 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