1414import org .tron .api .GrpcAPI .NumberMessage ;
1515import org .tron .api .GrpcAPI .Return ;
1616import org .tron .api .WalletGrpc ;
17+ import org .tron .api .WalletSolidityGrpc ;
1718import org .tron .common .crypto .ECKey ;
1819import org .tron .common .utils .ByteArray ;
1920import org .tron .protos .Contract .FreezeBalanceContract ;
@@ -38,29 +39,41 @@ public class WalletTest_p1_Account_001 {
3839 private final static String testKey003 = "6815B367FDDE637E53E9ADC8E69424E07724333C9A2B973CFA469975E20753FC" ;
3940 private final static String testKey004 = "592BB6C9BB255409A6A43EFD18E6A74FECDDCCE93A40D96B70FBE334E6361E32" ;
4041 private final static String invalidTestKey = "592BB6C9BB255409A6A45EFD18E9A74FECDDCCE93A40D96B70FBE334E6361E36" ;
42+ private final static String solidityKey = "86ff0c39337e9e97526c80af51f0e80411f5a1251473035f380f3671c1aa2b4b" ;
4143
4244 //testng001、testng002、testng003、testng004
4345 private static final byte [] BACK_ADDRESS = Base58 .decodeFromBase58Check ("27YcHNYcxHGRf5aujYzWQaJSpQ4WN4fJkiU" );
4446 private static final byte [] FROM_ADDRESS = Base58 .decodeFromBase58Check ("27WvzgdLiUvNAStq2BCvA1LZisdD3fBX8jv" );
4547 private static final byte [] TO_ADDRESS = Base58 .decodeFromBase58Check ("27iDPGt91DX3ybXtExHaYvrgDt5q5d6EtFM" );
4648 private static final byte [] NEED_CR_ADDRESS = Base58 .decodeFromBase58Check ("27QEkeaPHhUSQkw9XbxX3kCKg684eC2w67T" );
4749
50+
4851 private ManagedChannel channelFull = null ;
52+ private ManagedChannel channelSolidity = null ;
4953 private WalletGrpc .WalletBlockingStub blockingStubFull = null ;
50- //private String fullnode = "39.105.111.178:50051";
54+ private WalletSolidityGrpc .WalletSolidityBlockingStub blockingStubSolidity = null ;
55+
56+ private static final long now = System .currentTimeMillis ();
57+
5158 private String fullnode = Configuration .getByPath ("testng.conf" ).getStringList ("fullnode.ip.list" ).get (0 );
59+ private String soliditynode = Configuration .getByPath ("testng.conf" ).getStringList ("solidityNode.ip.list" ).get (0 );
5260
5361 @ BeforeClass
5462 public void beforeClass (){
5563 channelFull = ManagedChannelBuilder .forTarget (fullnode )
5664 .usePlaintext (true )
5765 .build ();
5866 blockingStubFull = WalletGrpc .newBlockingStub (channelFull );
67+
68+ channelSolidity = ManagedChannelBuilder .forTarget (soliditynode )
69+ .usePlaintext (true )
70+ .build ();
71+ blockingStubSolidity = WalletSolidityGrpc .newBlockingStub (channelSolidity );
5972 }
6073
6174
6275 @ Test
63- public void TestQueryAccount (){
76+ public void TestQueryAccountFromFullnode (){
6477 //查询成功,能够获取到账户类型,账户余额,最近一次操作时间等信息
6578 Account queryResult = queryAccount (testKey002 , blockingStubFull );
6679 Assert .assertTrue (queryResult .getBalance () > 0 );
@@ -76,11 +89,31 @@ public void TestQueryAccount(){
7689 Assert .assertTrue (invalidQueryResult .getAddress ().isEmpty ());
7790 }
7891
92+ @ Test
93+ public void TestQueryAccountFromSoliditynode (){
94+ //查询成功,能够获取到账户类型,账户余额,最近一次操作时间等信息
95+ Account queryResult = SolidityqueryAccount (solidityKey ,blockingStubSolidity );
96+ Assert .assertTrue (queryResult .getBalance () > 0 );
97+ Assert .assertTrue (queryResult .getBandwidth () >= 0 );
98+ Assert .assertTrue (queryResult .getAccountName ().toByteArray ().length > 0 );
99+ Assert .assertFalse (queryResult .getAddress ().isEmpty ());
100+
101+ //查询失败,无异常报出
102+ Account invalidQueryResult = SolidityqueryAccount (invalidTestKey ,blockingStubSolidity );
103+ //logger.info(invalidQueryResult.getAddress().toString());
104+ Assert .assertTrue (invalidQueryResult .getAccountName ().isEmpty ());
105+ //logger.info(ByteArray.toStr(invalidQueryResult.getAddress().toByteArray()));
106+ Assert .assertTrue (invalidQueryResult .getAddress ().isEmpty ());
107+ }
108+
79109 @ AfterClass
80110 public void shutdown () throws InterruptedException {
81- if (channelFull != null ) {
111+ if (channelFull != null ) {
82112 channelFull .shutdown ().awaitTermination (5 , TimeUnit .SECONDS );
83113 }
114+ if (channelSolidity != null ) {
115+ channelSolidity .shutdown ().awaitTermination (5 , TimeUnit .SECONDS );
116+ }
84117 }
85118
86119 public Account queryAccount (String priKey ,WalletGrpc .WalletBlockingStub blockingStubFull ) {
@@ -106,6 +139,30 @@ public Account queryAccount(String priKey,WalletGrpc.WalletBlockingStub blocking
106139 return grpcQueryAccount (ecKey .getAddress (), blockingStubFull );
107140 }
108141
142+ public Account SolidityqueryAccount (String priKey ,WalletSolidityGrpc .WalletSolidityBlockingStub blockingStubSolidity ) {
143+
144+ byte [] address ;
145+ ECKey temKey = null ;
146+ try {
147+ BigInteger priK = new BigInteger (priKey , 16 );
148+ temKey = ECKey .fromPrivate (priK );
149+ } catch (Exception ex ) {
150+ ex .printStackTrace ();
151+ }
152+ ECKey ecKey = temKey ;
153+ if (ecKey == null ) {
154+ String pubKey = loadPubKey (); //04 PubKey[128]
155+ if (StringUtils .isEmpty (pubKey )) {
156+ logger .warn ("Warning: QueryAccount failed, no wallet address !!" );
157+ return null ;
158+ }
159+ byte [] pubKeyAsc = pubKey .getBytes ();
160+ byte [] pubKeyHex = Hex .decode (pubKeyAsc );
161+ ecKey = ECKey .fromPublicOnly (pubKeyHex );
162+ }
163+ return grpcQueryAccountSolidity (ecKey .getAddress (),blockingStubSolidity );
164+ }
165+
109166 public static String loadPubKey () {
110167 char [] buf = new char [0x100 ];
111168 return String .valueOf (buf , 32 , 130 );
@@ -121,6 +178,14 @@ public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub bl
121178 return blockingStubFull .getAccount (request );
122179 }
123180
181+ public Account grpcQueryAccountSolidity (byte [] address , WalletSolidityGrpc .WalletSolidityBlockingStub blockingStubSolidity ) {
182+ ByteString addressBS = ByteString .copyFrom (address );
183+ Account request = Account .newBuilder ().setAddress (addressBS ).build ();
184+ return blockingStubSolidity .getAccount (request );
185+ }
186+
187+
188+
124189 public Block getBlock (long blockNum , WalletGrpc .WalletBlockingStub blockingStubFull ) {
125190 NumberMessage .Builder builder = NumberMessage .newBuilder ();
126191 builder .setNum (blockNum );
0 commit comments