diff --git a/src/main/java/org/tron/core/WalletSolidity.java b/src/main/java/org/tron/core/WalletSolidity.java index e3ce14bd6c8..db98ce5d16b 100644 --- a/src/main/java/org/tron/core/WalletSolidity.java +++ b/src/main/java/org/tron/core/WalletSolidity.java @@ -5,14 +5,10 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import org.tron.api.GrpcAPI.AssetIssueList; import org.tron.api.GrpcAPI.TransactionList; -import org.tron.api.GrpcAPI.WitnessList; import org.tron.common.utils.ByteArray; import org.tron.core.db.api.StoreAPI; -import org.tron.protos.Contract.AssetIssueContract; import org.tron.protos.Protocol.Transaction; -import org.tron.protos.Protocol.Witness; @Slf4j @Component @@ -21,19 +17,6 @@ public class WalletSolidity { @Autowired private StoreAPI storeAPI; - public WitnessList getWitnessList() { - List witnessAll = storeAPI.getWitnessAll(); - WitnessList witnessList = WitnessList.newBuilder().addAllWitnesses(witnessAll).build(); - return witnessList; - } - - public AssetIssueList getAssetIssueList() { - List assetIssueAll = storeAPI.getAssetIssueAll(); - AssetIssueList assetIssueList = - AssetIssueList.newBuilder().addAllAssetIssue(assetIssueAll).build(); - return assetIssueList; - } - public TransactionList getTransactionsFromThis(ByteString thisAddress, long offset, long limit) { List transactionsFromThis = storeAPI .getTransactionsFromThis(ByteArray.toHexString(thisAddress.toByteArray()), offset, limit); diff --git a/src/main/java/org/tron/core/db/api/StoreAPI.java b/src/main/java/org/tron/core/db/api/StoreAPI.java index abe67a7ee77..201ed1d7db9 100644 --- a/src/main/java/org/tron/core/db/api/StoreAPI.java +++ b/src/main/java/org/tron/core/db/api/StoreAPI.java @@ -20,9 +20,7 @@ import org.springframework.util.StringUtils; import org.tron.core.db.api.index.Index; import org.tron.core.db.api.index.TransactionIndex; -import org.tron.protos.Contract.AssetIssueContract; import org.tron.protos.Protocol.Transaction; -import org.tron.protos.Protocol.Witness; @Component @Slf4j @@ -119,17 +117,17 @@ public List getTransactionsToThis(String address, long offset, long * witness api * ******************************************************************************* */ - public List getWitnessAll() { - Index.Iface index = indexHelper.getWitnessIndex(); - return ImmutableList.copyOf(index); - } +// public List getWitnessAll() { +// Index.Iface index = indexHelper.getWitnessIndex(); +// return ImmutableList.copyOf(index); +// } /******************************************************************************** * AssetIssue api * ******************************************************************************** */ - public List getAssetIssueAll() { - Index.Iface index = indexHelper.getAssetIssueIndex(); - return ImmutableList.copyOf(index); - } +// public List getAssetIssueAll() { +// Index.Iface index = indexHelper.getAssetIssueIndex(); +// return ImmutableList.copyOf(index); +// } } diff --git a/src/main/java/org/tron/core/services/RpcApiService.java b/src/main/java/org/tron/core/services/RpcApiService.java index fda00549f59..b97e2339a5a 100755 --- a/src/main/java/org/tron/core/services/RpcApiService.java +++ b/src/main/java/org/tron/core/services/RpcApiService.java @@ -214,14 +214,14 @@ public void getAccount(Account request, StreamObserver responseObserver @Override public void listWitnesses(EmptyMessage request, StreamObserver responseObserver) { - responseObserver.onNext(walletSolidity.getWitnessList()); + responseObserver.onNext(wallet.getWitnessList()); responseObserver.onCompleted(); } @Override public void getAssetIssueList(EmptyMessage request, StreamObserver responseObserver) { - responseObserver.onNext(walletSolidity.getAssetIssueList()); + responseObserver.onNext(wallet.getAssetIssueList()); responseObserver.onCompleted(); } diff --git a/src/main/protos/api/api.proto b/src/main/protos/api/api.proto index d8312ba3789..3446a76c9bf 100644 --- a/src/main/protos/api/api.proto +++ b/src/main/protos/api/api.proto @@ -93,14 +93,14 @@ service Wallet { }; rpc CreateWitness (WitnessCreateContract) returns (Transaction) { - option (google.api.http) = { - post: "/wallet/createwitness" - body: "*" - additional_bindings { - get: "/wallet/createwitness" - } - }; + option (google.api.http) = { + post: "/wallet/createwitness" + body: "*" + additional_bindings { + get: "/wallet/createwitness" + } }; + }; rpc TransferAsset (TransferAssetContract) returns (Transaction) { option (google.api.http) = { @@ -192,14 +192,14 @@ service Wallet { }; } rpc GetAccountNet (Account) returns (AccountNetMessage) { - option (google.api.http) = { + option (google.api.http) = { post: "/wallet/getaccountnet" body: "*" additional_bindings { get: "/wallet/getaccountnet" } }; - }; + }; rpc GetAssetIssueByName (BytesMessage) returns (AssetIssueContract) { option (google.api.http) = { post: "/wallet/getassetissuebyname" @@ -333,33 +333,6 @@ service WalletSolidity { } }; } - rpc GetAssetIssueListByTimestamp (NumberMessage) returns (AssetIssueList) { - option (google.api.http) = { - post: "/walletsolidity/getassetissuelistbytimestamp" - body: "*" - additional_bindings { - get: "/walletsolidity/getassetissuelistbytimestamp" - } - }; - } - rpc GetAssetIssueByAccount (Account) returns (AssetIssueList) { - option (google.api.http) = { - post: "/walletsolidity/getassetissuebyaccount" - body: "*" - additional_bindings { - get: "/walletsolidity/getassetissuebyaccount" - } - }; - } - rpc GetAssetIssueByName (BytesMessage) returns (AssetIssueContract) { - option (google.api.http) = { - post: "/walletsolidity/getassetissuebyname" - body: "*" - additional_bindings { - get: "/walletsolidity/getassetissuebyname" - } - }; - } rpc GetNowBlock (EmptyMessage) returns (Block) { option (google.api.http) = { post: "/walletsolidity/getnowblock" @@ -378,46 +351,10 @@ service WalletSolidity { } }; } - //get transaction - rpc TotalTransaction (EmptyMessage) returns (NumberMessage) { - option (google.api.http) = { - post: "/walletsolidity/totaltransaction" - body: "*" - additional_bindings { - get: "/walletsolidity/totaltransaction" - } - }; - } - rpc GetTransactionById (BytesMessage) returns (Transaction) { - option (google.api.http) = { - post: "/walletsolidity/gettransactionbyid" - body: "*" - additional_bindings { - get: "/walletsolidity/gettransactionbyid" - } - }; - } }; service WalletExtension { - rpc GetTransactionsByTimestamp (TimePaginatedMessage) returns (TransactionList) { - option (google.api.http) = { - post: "/walletextension/gettransactionsbytimestamp" - body: "*" - additional_bindings { - get: "/walletextension/gettransactionsbytimestamp" - } - }; - } - rpc GetTransactionsByTimestampCount (TimeMessage) returns (NumberMessage) { - option (google.api.http) = { - post: "/walletextension/gettransactionsbytimestampcount" - body: "*" - additional_bindings { - get: "/walletextension/gettransactionsbytimestampcount" - } - }; - } + rpc GetTransactionsFromThis (AccountPaginated) returns (TransactionList) { option (google.api.http) = { post: "/walletextension/gettransactionsfromthis" @@ -436,24 +373,6 @@ service WalletExtension { } }; } - rpc GetTransactionsFromThisCount (Account) returns (NumberMessage) { - option (google.api.http) = { - post: "/walletextension/gettransactionsfromthiscount" - body: "*" - additional_bindings { - get: "/walletextension/gettransactionsfromthiscount" - } - }; - } - rpc GetTransactionsToThisCount (Account) returns (NumberMessage) { - option (google.api.http) = { - post: "/walletextension/gettransactionstothiscount" - body: "*" - additional_bindings { - get: "/walletextension/gettransactionstothiscount" - } - }; - } }; // the api of tron's db diff --git a/src/test/java/stest/tron/wallet/account/WalletTestAccount003.java b/src/test/java/stest/tron/wallet/account/WalletTestAccount003.java index 09afa51c672..9e2d9b17ba3 100644 --- a/src/test/java/stest/tron/wallet/account/WalletTestAccount003.java +++ b/src/test/java/stest/tron/wallet/account/WalletTestAccount003.java @@ -77,9 +77,10 @@ public class WalletTestAccount003 { private String fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list") .get(0); - /* ECKey ecKey = new ECKey(Utils.getRandom()); - byte[] NOWITNESSADDRESS = ecKey.getAddress(); - String testKeyForNoWitness = ByteArray.toHexString(ecKey.getPrivKeyBytes());*/ + //get account + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] noBandwitchAddress = ecKey1.getAddress(); + String noBandwitch = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @BeforeClass public void beforeClass() { @@ -104,10 +105,11 @@ public void testCreateAccount() { //TestVoteToNonWitnessAccount HashMap voteToNonWitnessAccount = new HashMap(); - voteToNonWitnessAccount.put("27dUQbeRLz6BavhUJE6UbNp5AtAtPuzNZv6", "1"); + voteToNonWitnessAccount.put("27dUQbeRLz6BavhUJE6UbNp5AtAtPuzNZv6", "3"); HashMap voteToInvaildAddress = new HashMap(); - voteToInvaildAddress.put("27cu1ozb4mX3m2afY68FSAqn3HmMp815d48", "1"); + voteToInvaildAddress.put("27cu1ozb4mX3m2afY68FSAqn3HmMp815d48", "4"); Assert.assertTrue(freezeBalance(FROM_ADDRESS, 10000000L, 3L, testKey002)); + voteWitness(voteToNonWitnessAccount, FROM_ADDRESS, testKey002); Assert.assertFalse(voteWitness(voteToNonWitnessAccount, FROM_ADDRESS, testKey002)); Assert.assertFalse(voteWitness(voteToInvaildAddress, FROM_ADDRESS, testKey002)); @@ -469,9 +471,9 @@ public Boolean voteWitness(HashMap witness, byte[] address, Stri .newBuilder(); byte[] addRess = WalletClient.decodeFromBase58Check(addressBase58); if (addRess == null) { - continue; + return false; } - voteBuilder.setVoteAddress(ByteString.copyFrom(address)); + voteBuilder.setVoteAddress(ByteString.copyFrom(addRess)); voteBuilder.setVoteCount(count); builder.addVotes(voteBuilder.build()); } diff --git a/src/test/java/stest/tron/wallet/account/WalletTestAccount004.java b/src/test/java/stest/tron/wallet/account/WalletTestAccount004.java index c11df2baf48..dbb1955975e 100644 --- a/src/test/java/stest/tron/wallet/account/WalletTestAccount004.java +++ b/src/test/java/stest/tron/wallet/account/WalletTestAccount004.java @@ -173,10 +173,11 @@ public Boolean freezeBalance(byte[] addRess, long freezeBalance, long freezeDura } Long afterBlockNum = 0L; - - while (afterBlockNum < beforeBlockNum) { + Integer wait = 0; + while (afterBlockNum < beforeBlockNum && wait < 10) { Block currentBlock1 = searchBlockingStubFull.getNowBlock(EmptyMessage.newBuilder().build()); afterBlockNum = currentBlock1.getBlockHeader().getRawData().getNumber(); + wait++; try { Thread.sleep(2000); logger.info("wait 2 second"); diff --git a/src/test/java/stest/tron/wallet/assetissue/WalletTestAssetIssue006.java b/src/test/java/stest/tron/wallet/assetissue/WalletTestAssetIssue006.java index 26f9dcd30d7..e1aab868f4d 100644 --- a/src/test/java/stest/tron/wallet/assetissue/WalletTestAssetIssue006.java +++ b/src/test/java/stest/tron/wallet/assetissue/WalletTestAssetIssue006.java @@ -17,10 +17,13 @@ import org.tron.api.WalletGrpc; import org.tron.api.WalletSolidityGrpc; import org.tron.common.crypto.ECKey; +import org.tron.common.utils.ByteArray; +import org.tron.common.utils.Utils; import org.tron.protos.Protocol.Account; import org.tron.protos.Protocol.Block; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.PublicMethed; @Slf4j public class WalletTestAssetIssue006 { @@ -53,14 +56,22 @@ public class WalletTestAssetIssue006 { private ManagedChannel channelSolidity = null; private WalletGrpc.WalletBlockingStub blockingStubFull = null; private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; - - private static final long now = System.currentTimeMillis(); - private String fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list") .get(0); private String soliditynode = Configuration.getByPath("testng.conf") .getStringList("solidityNode.ip.list").get(0); + private static final long now = System.currentTimeMillis(); + private static String name = "assetissue006" + Long.toString(now); + private static final long totalSupply = now; + String description = "test query assetissue by timestamp from soliditynode"; + String url = "https://testqueryassetissue.com/bytimestamp/from/soliditynode/"; + + //get account + ECKey ecKey = new ECKey(Utils.getRandom()); + byte[] queryAssetIssueFromSoliAddress = ecKey.getAddress(); + String queryAssetIssueKey = ByteArray.toHexString(ecKey.getPrivKeyBytes()); + @BeforeClass public void beforeClass() { channelFull = ManagedChannelBuilder.forTarget(fullnode) @@ -72,10 +83,42 @@ public void beforeClass() { .usePlaintext(true) .build(); blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + + Assert.assertTrue(PublicMethed.freezeBalance(FROM_ADDRESS,10000000,3,testKey002, + blockingStubFull)); + Assert.assertTrue(PublicMethed.sendcoin(queryAssetIssueFromSoliAddress,2048000000,FROM_ADDRESS, + testKey002,blockingStubFull)); + Long start = System.currentTimeMillis() + 2000; + Long end = System.currentTimeMillis() + 1000000000; + //Create a new AssetIssue success. + Assert.assertTrue(PublicMethed.createAssetIssue(queryAssetIssueFromSoliAddress, name, + totalSupply, 1, 100, start, end, 1, description, url, 1000L, + 1000L,1L,1L,queryAssetIssueKey,blockingStubFull)); } - @Test(enabled = true) + /* @Test(enabled = true) public void testGetAssetIssueListByTimestamp() { + Block currentBlock = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); + Block solidityCurrentBlock = blockingStubSolidity.getNowBlock(GrpcAPI.EmptyMessage + .newBuilder().build()); + Integer wait = 0; + while (solidityCurrentBlock.getBlockHeader().getRawData().getNumber() + < currentBlock.getBlockHeader().getRawData().getNumber() + 1 && wait < 10) { + try { + Thread.sleep(3000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + logger.info("Solidity didn't synchronize the fullnode block,please wait"); + solidityCurrentBlock = blockingStubSolidity.getNowBlock(GrpcAPI.EmptyMessage.newBuilder() + .build()); + wait++; + if (wait == 9) { + logger.info("Didn't syn,skip to next case."); + } + } + + long time = now; NumberMessage.Builder timeStamp = NumberMessage.newBuilder(); timeStamp.setNum(time); @@ -117,7 +160,7 @@ public void testExceptionGetAssetIssueListByTimestamp() { getAssetIssueListByTimestamp = Optional.ofNullable(assetIssueList); Assert.assertTrue(getAssetIssueListByTimestamp.get().getAssetIssueCount() == 0); - } + }*/ @AfterClass public void shutdown() throws InterruptedException { diff --git a/src/test/java/stest/tron/wallet/assetissue/WalletTestAssetIssue008.java b/src/test/java/stest/tron/wallet/assetissue/WalletTestAssetIssue008.java index f97a8cd1a5b..65f140f76f3 100644 --- a/src/test/java/stest/tron/wallet/assetissue/WalletTestAssetIssue008.java +++ b/src/test/java/stest/tron/wallet/assetissue/WalletTestAssetIssue008.java @@ -19,12 +19,14 @@ import org.tron.api.WalletSolidityGrpc; import org.tron.common.crypto.ECKey; import org.tron.common.utils.ByteArray; +import org.tron.common.utils.Utils; import org.tron.protos.Contract; import org.tron.protos.Protocol.Account; import org.tron.protos.Protocol.Block; import org.tron.protos.Protocol.Transaction; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.PublicMethed; import stest.tron.wallet.common.client.utils.TransactionUtils; @Slf4j @@ -59,8 +61,20 @@ public class WalletTestAssetIssue008 { private String soliditynode = Configuration.getByPath("testng.conf") .getStringList("solidityNode.ip.list").get(0); + private static final long now = System.currentTimeMillis(); + private static String name = "assetissue008" + Long.toString(now); + private static final long totalSupply = now; + String description = "test query assetissue from soliditynode"; + String url = "https://testqueryassetissue.com/from/soliditynode/"; + + //get account + ECKey ecKey = new ECKey(Utils.getRandom()); + byte[] queryAssetIssueFromSoliAddress = ecKey.getAddress(); + String queryAssetIssueKey = ByteArray.toHexString(ecKey.getPrivKeyBytes()); + @BeforeClass public void beforeClass() { + logger.info(ByteArray.toHexString(ecKey.getPrivKeyBytes())); channelFull = ManagedChannelBuilder.forTarget(fullnode) .usePlaintext(true) .build(); @@ -70,13 +84,45 @@ public void beforeClass() { .usePlaintext(true) .build(); blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + + Assert.assertTrue(PublicMethed.freezeBalance(FROM_ADDRESS,10000000,3,testKey002, + blockingStubFull)); + Assert.assertTrue(PublicMethed.sendcoin(queryAssetIssueFromSoliAddress,2048000000,FROM_ADDRESS, + testKey002,blockingStubFull)); + Long start = System.currentTimeMillis() + 2000; + Long end = System.currentTimeMillis() + 1000000000; + //Create a new AssetIssue success. + Assert.assertTrue(PublicMethed.createAssetIssue(queryAssetIssueFromSoliAddress, name, + totalSupply, 1, 100, start, end, 1, description, url, 1000L, + 1000L,1L,1L,queryAssetIssueKey,blockingStubFull)); } @Test(enabled = true) public void testGetAllAssetIssueFromSolidity() { + Block currentBlock = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); + Block solidityCurrentBlock = blockingStubSolidity.getNowBlock(GrpcAPI + .EmptyMessage.newBuilder().build()); + Integer wait = 0; + while (solidityCurrentBlock.getBlockHeader().getRawData().getNumber() + < currentBlock.getBlockHeader().getRawData().getNumber() + 1 && wait < 10) { + try { + Thread.sleep(3000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + logger.info("Solidity didn't synchronize the fullnode block,please wait"); + solidityCurrentBlock = blockingStubSolidity.getNowBlock(GrpcAPI.EmptyMessage.newBuilder() + .build()); + wait++; + if (wait == 9) { + logger.info("Didn't syn,skip to next case."); + } + } + GrpcAPI.AssetIssueList assetIssueList = blockingStubSolidity .getAssetIssueList(GrpcAPI.EmptyMessage.newBuilder().build()); + logger.info(Long.toString(assetIssueList.getAssetIssueCount())); Assert.assertTrue(assetIssueList.getAssetIssueCount() >= 1); for (Integer j = 0; j < assetIssueList.getAssetIssueCount(); j++) { Assert.assertFalse(assetIssueList.getAssetIssue(j).getOwnerAddress().isEmpty()); diff --git a/src/test/java/stest/tron/wallet/assetissue/WalletTestAssetIssue009.java b/src/test/java/stest/tron/wallet/assetissue/WalletTestAssetIssue009.java index a552baf32ca..f436dcd2afa 100644 --- a/src/test/java/stest/tron/wallet/assetissue/WalletTestAssetIssue009.java +++ b/src/test/java/stest/tron/wallet/assetissue/WalletTestAssetIssue009.java @@ -77,7 +77,7 @@ public void beforeClass() { } - @Test(enabled = true) + /* @Test(enabled = true) public void testGetAssetIssueByAccountOrNameFromSolidity() { //By name ByteString addressBs = ByteString.copyFrom(FROM_ADDRESS); @@ -107,7 +107,7 @@ public void testGetAssetIssueByAccountOrNameFromSolidity() { Assert.assertTrue(assetIssueByName.getTrxNum() > 0); logger.info("TestGetAssetIssueByNameFromSolidity"); - } + }*/ @AfterClass(enabled = true) public void shutdown() throws InterruptedException { diff --git a/src/test/java/stest/tron/wallet/assetissue/WalletTestAssetIssue011.java b/src/test/java/stest/tron/wallet/assetissue/WalletTestAssetIssue011.java index 35fbd59670b..9a9b3d13062 100644 --- a/src/test/java/stest/tron/wallet/assetissue/WalletTestAssetIssue011.java +++ b/src/test/java/stest/tron/wallet/assetissue/WalletTestAssetIssue011.java @@ -45,7 +45,7 @@ public class WalletTestAssetIssue011 { private static String name = "testAssetIssue_" + Long.toString(now); private static final long totalSupply = now; private static final long sendAmount = 10000000000L; - private static final String updateMostLongName = "w2345678901234567890123456789012"; + private static final String updateMostLongName = Long.toString(now) + "w234567890123456789"; Long freeAssetNetLimit = 10000L; Long publicFreeAssetNetLimit = 10000L; @@ -116,7 +116,7 @@ public void testTransferAssetCreateAccount() { Account queryTransferAssetAccount = PublicMethed .queryAccount(transferAssetCreateKey, blockingStubFull); Assert.assertTrue(queryTransferAssetAccount.getAssetCount() == 1); - Assert.assertTrue(PublicMethed.updateAccount(asset011Address, "wwwxxxeeef" + Assert.assertTrue(PublicMethed.updateAccount(asset011Address, Long.toString(now) .getBytes(), testKeyForAssetIssue011, blockingStubFull)); Assert.assertTrue(PublicMethed.updateAccount(transferAssetCreateAddress, updateMostLongName .getBytes(), transferAssetCreateKey, blockingStubFull)); diff --git a/src/test/java/stest/tron/wallet/common/client/GrpcClient.java b/src/test/java/stest/tron/wallet/common/client/GrpcClient.java index 67ae1e2f5c4..c9a4c2c61fd 100644 --- a/src/test/java/stest/tron/wallet/common/client/GrpcClient.java +++ b/src/test/java/stest/tron/wallet/common/client/GrpcClient.java @@ -172,7 +172,7 @@ public Optional listNodes() { return Optional.ofNullable(nodeList); } - public Optional getAssetIssueByAccount(byte[] address) { + /* public Optional getAssetIssueByAccount(byte[] address) { ByteString addressBS = ByteString.copyFrom(address); Account request = Account.newBuilder().setAddress(addressBS).build(); if(blockingStubSolidity != null) { @@ -184,9 +184,9 @@ public Optional getAssetIssueByAccount(byte[] address) { .getAssetIssueByAccount(request); return Optional.ofNullable(assetIssueList); } - } + }*/ - public AssetIssueContract getAssetIssueByName(String assetName) { + /* public AssetIssueContract getAssetIssueByName(String assetName) { ByteString assetNameBs = ByteString.copyFrom(assetName.getBytes()); BytesMessage request = BytesMessage.newBuilder().setValue(assetNameBs).build(); if(blockingStubSolidity != null) { @@ -194,24 +194,24 @@ public AssetIssueContract getAssetIssueByName(String assetName) { } else { return blockingStubFull.getAssetIssueByName(request); } - } + }*/ - public NumberMessage getTotalTransaction() { + /* public NumberMessage getTotalTransaction() { if(blockingStubSolidity != null) { return blockingStubSolidity.totalTransaction(EmptyMessage.newBuilder().build()); } else { return blockingStubFull.totalTransaction(EmptyMessage.newBuilder().build()); } - } + }*/ - public Optional getAssetIssueListByTimestamp(long time) { + /* public Optional getAssetIssueListByTimestamp(long time) { NumberMessage.Builder timeStamp = NumberMessage.newBuilder(); timeStamp.setNum(time); AssetIssueList assetIssueList = blockingStubSolidity.getAssetIssueListByTimestamp(timeStamp.build()); return Optional.ofNullable(assetIssueList); - } + }*/ - public Optional getTransactionsByTimestamp(long start, long end, int offset , int limit) { + /* public Optional getTransactionsByTimestamp(long start, long end, int offset , int limit) { TimeMessage.Builder timeMessage = TimeMessage.newBuilder(); timeMessage.setBeginInMilliseconds(start); timeMessage.setEndInMilliseconds(end); @@ -221,7 +221,7 @@ public Optional getTransactionsByTimestamp(long start, long end timePageMessage.setLimit(limit); TransactionList transactionList = blockingStubExtension.getTransactionsByTimestamp(timePageMessage.build()); return Optional.ofNullable(transactionList); - } + }*/ public Optional getTransactionsFromThis(byte[] address) { ByteString addressBS = ByteString.copyFrom(address); @@ -243,7 +243,7 @@ public Optional getTransactionsToThis(byte[] address) { return Optional.ofNullable(transactionList); } - public Optional getTransactionById(String txID){ + /* public Optional getTransactionById(String txID){ ByteString bsTxid = ByteString.copyFrom(ByteArray.fromHexString(txID)); BytesMessage request = BytesMessage.newBuilder().setValue(bsTxid).build(); if(blockingStubSolidity != null) { @@ -253,7 +253,7 @@ public Optional getTransactionById(String txID){ Transaction transaction = blockingStubFull.getTransactionById(request); return Optional.ofNullable(transaction); } - } + }*/ public Optional getBlockById(String blockID){ ByteString bsTxid = ByteString.copyFrom(ByteArray.fromHexString(blockID)); diff --git a/src/test/java/stest/tron/wallet/common/client/WalletClient.java b/src/test/java/stest/tron/wallet/common/client/WalletClient.java index 9694a8baed2..e0ea31d20f2 100644 --- a/src/test/java/stest/tron/wallet/common/client/WalletClient.java +++ b/src/test/java/stest/tron/wallet/common/client/WalletClient.java @@ -711,13 +711,13 @@ public static Optional listWitnesses() { return result; } - public static Optional getAssetIssueListByTimestamp(long timestamp) { + /* public static Optional getAssetIssueListByTimestamp(long timestamp) { return rpcCli.getAssetIssueListByTimestamp(timestamp); - } + }*/ - public static Optional getTransactionsByTimestamp(long start, long end, int offset, int limit) { + /* public static Optional getTransactionsByTimestamp(long start, long end, int offset, int limit) { return rpcCli.getTransactionsByTimestamp(start, end, offset, limit); - } + }*/ public static Optional getAssetIssueList() { return rpcCli.getAssetIssueList(); @@ -727,7 +727,7 @@ public static Optional listNodes() { return rpcCli.listNodes(); } - public static Optional getAssetIssueByAccount(byte[] address) { + /* public static Optional getAssetIssueByAccount(byte[] address) { return rpcCli.getAssetIssueByAccount(address); } @@ -737,7 +737,7 @@ public static AssetIssueContract getAssetIssueByName(String assetName) { public static GrpcAPI.NumberMessage getTotalTransaction() { return rpcCli.getTotalTransaction(); - } + }*/ public static Optional getTransactionsFromThis(byte[] address) { return rpcCli.getTransactionsFromThis(address); @@ -747,9 +747,9 @@ public static Optional getTransactionsToThis(byte[] address) { return rpcCli.getTransactionsToThis(address); } - public static Optional getTransactionById(String txID) { + /* public static Optional getTransactionById(String txID) { return rpcCli.getTransactionById(txID); - } + }*/ public boolean freezeBalance(long frozen_balance, long frozen_duration) { @@ -770,9 +770,9 @@ private FreezeBalanceContract createFreezeBalanceContract(long frozen_balance, long frozen_duration) { byte[] address = getAddress(); Contract.FreezeBalanceContract.Builder builder = Contract.FreezeBalanceContract.newBuilder(); - ByteString byteAddress = ByteString.copyFrom(address); + ByteString byteAddreess = ByteString.copyFrom(address); - builder.setOwnerAddress(byteAddress).setFrozenBalance(frozen_balance) + builder.setOwnerAddress(byteAddreess).setFrozenBalance(frozen_balance) .setFrozenDuration(frozen_duration); return builder.build(); @@ -796,9 +796,9 @@ private UnfreezeBalanceContract createUnfreezeBalanceContract() { byte[] address = getAddress(); Contract.UnfreezeBalanceContract.Builder builder = Contract.UnfreezeBalanceContract .newBuilder(); - ByteString byteAddress = ByteString.copyFrom(address); + ByteString byteAddreess = ByteString.copyFrom(address); - builder.setOwnerAddress(byteAddress); + builder.setOwnerAddress(byteAddreess); return builder.build(); } @@ -821,9 +821,9 @@ private WithdrawBalanceContract createWithdrawBalanceContract() { byte[] address = getAddress(); Contract.WithdrawBalanceContract.Builder builder = Contract.WithdrawBalanceContract .newBuilder(); - ByteString byteAddress = ByteString.copyFrom(address); + ByteString byteAddreess = ByteString.copyFrom(address); - builder.setOwnerAddress(byteAddress); + builder.setOwnerAddress(byteAddreess); return builder.build(); } diff --git a/src/test/java/stest/tron/wallet/common/client/utils/PublicMethed.java b/src/test/java/stest/tron/wallet/common/client/utils/PublicMethed.java index 24b8b41eecf..cd195456b62 100644 --- a/src/test/java/stest/tron/wallet/common/client/utils/PublicMethed.java +++ b/src/test/java/stest/tron/wallet/common/client/utils/PublicMethed.java @@ -9,10 +9,12 @@ import org.testng.Assert; import org.tron.api.GrpcAPI; import org.tron.api.WalletGrpc; +import org.tron.api.WalletSolidityGrpc; import org.tron.common.crypto.ECKey; import org.tron.common.utils.ByteArray; import org.tron.protos.Contract; import org.tron.protos.Protocol; +import org.tron.protos.Protocol.Block; public class PublicMethed { @@ -377,4 +379,29 @@ public static boolean updateAccount(byte[] addressBytes, byte[] accountNameBytes return true; } } + + public static boolean waitSolidityNodeSynFullNodeData(WalletGrpc.WalletBlockingStub + blockingStubFull, WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity) { + Block currentBlock = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); + Block solidityCurrentBlock = blockingStubSolidity.getNowBlock(GrpcAPI.EmptyMessage + .newBuilder().build()); + Integer wait = 0; + while (solidityCurrentBlock.getBlockHeader().getRawData().getNumber() + < currentBlock.getBlockHeader().getRawData().getNumber() + 1 && wait < 10) { + try { + Thread.sleep(3000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + logger.info("Solidity didn't synchronize the fullnode block,please wait"); + solidityCurrentBlock = blockingStubSolidity.getNowBlock(GrpcAPI.EmptyMessage.newBuilder() + .build()); + wait++; + if (wait == 9) { + logger.info("Didn't syn,skip to next case."); + return false; + } + } + return true; + } } diff --git a/src/test/java/stest/tron/wallet/transfer/WalletTestTransfer001.java b/src/test/java/stest/tron/wallet/transfer/WalletTestTransfer001.java index 5f700d9b7c2..505abbfabb5 100644 --- a/src/test/java/stest/tron/wallet/transfer/WalletTestTransfer001.java +++ b/src/test/java/stest/tron/wallet/transfer/WalletTestTransfer001.java @@ -175,11 +175,12 @@ public Boolean freezeBalance(byte[] addRess, long freezeBalance, long freezeDura } Long afterBlockNum = 0L; - - while (afterBlockNum < beforeBlockNum) { + Integer wait = 0; + while (afterBlockNum < beforeBlockNum && wait < 10) { Block currentBlock1 = searchBlockingStubFull .getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); afterBlockNum = currentBlock1.getBlockHeader().getRawData().getNumber(); + wait++; try { Thread.sleep(2000); logger.info("wait 2 second"); diff --git a/src/test/java/stest/tron/wallet/transfer/WalletTestTransfer002.java b/src/test/java/stest/tron/wallet/transfer/WalletTestTransfer002.java index ea3c8eaaec1..15ce194034a 100644 --- a/src/test/java/stest/tron/wallet/transfer/WalletTestTransfer002.java +++ b/src/test/java/stest/tron/wallet/transfer/WalletTestTransfer002.java @@ -73,7 +73,7 @@ public void beforeClass() { blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = true) + /* @Test(enabled = true) public void testGetTotalTransaction() { NumberMessage beforeGetTotalTransaction = blockingStubFull .totalTransaction(GrpcAPI.EmptyMessage.newBuilder().build()); @@ -93,7 +93,7 @@ public void testGetTotalTransaction() { logger.info("On soliditynode, there is no transactions,please test by manual"); } Assert.assertTrue(solidityGetTotalTransaction.getNum() > 0); - } + }*/ @AfterClass public void shutdown() throws InterruptedException { diff --git a/src/test/java/stest/tron/wallet/transfer/WalletTestTransfer003.java b/src/test/java/stest/tron/wallet/transfer/WalletTestTransfer003.java index f23ea05e775..39e9783a612 100644 --- a/src/test/java/stest/tron/wallet/transfer/WalletTestTransfer003.java +++ b/src/test/java/stest/tron/wallet/transfer/WalletTestTransfer003.java @@ -1,4 +1,3 @@ -/* package stest.tron.wallet.transfer; import com.google.protobuf.ByteString; @@ -15,6 +14,11 @@ import org.testng.annotations.Test; import org.tron.api.GrpcAPI; import org.tron.api.GrpcAPI.NumberMessage; +import org.tron.api.GrpcAPI.TimeMessage; +import org.tron.api.GrpcAPI.TimePaginatedMessage; +import org.tron.api.GrpcAPI.TransactionList; +import org.tron.api.WalletExtensionGrpc; +import org.tron.api.WalletExtensionGrpc.WalletExtensionStub; import org.tron.api.WalletGrpc; import org.tron.api.WalletSolidityGrpc; import org.tron.common.crypto.ECKey; @@ -58,6 +62,7 @@ public class WalletTestTransfer003 { private ManagedChannel channelSolidity = null; private WalletGrpc.WalletBlockingStub blockingStubFull = null; private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + private WalletExtensionGrpc.WalletExtensionBlockingStub blockingStubExtension = null; private static final long now = System.currentTimeMillis(); @@ -77,25 +82,26 @@ public void beforeClass() { .usePlaintext(true) .build(); blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + blockingStubExtension = WalletExtensionGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = false) + /* @Test(enabled = true) public void testGetTransactionById() { long start = now - 16400000; long end = now; GrpcAPI.TimeMessage.Builder timeMessage = GrpcAPI.TimeMessage.newBuilder(); timeMessage.setBeginInMilliseconds(start); timeMessage.setEndInMilliseconds(end); - GrpcAPI.TimePaginatedMessage.Builder timePageMessage = GrpcAPI.TimePaginatedMessage - .newBuilder(); + TimePaginatedMessage.Builder timePageMessage = TimePaginatedMessage.newBuilder(); timePageMessage.setTimeMessage(timeMessage); timePageMessage.setOffset(0); timePageMessage.setLimit(999); - GrpcAPI.TransactionList transactionList = blockingStubSolidity + TransactionList transactionList = blockingStubExtension .getTransactionsByTimestamp(timePageMessage.build()); Optional gettransactionbytimestamp = Optional .ofNullable(transactionList); + logger.info(Long.toString(gettransactionbytimestamp.get().getTransactionCount())); if (gettransactionbytimestamp.get().getTransactionCount() == 0) { logger.info("Last one day there is no transfaction,please test for manual!!!"); Assert.assertTrue(gettransactionbytimestamp.isPresent()); @@ -122,7 +128,7 @@ public void testGetTransactionById() { getTransactionById = Optional.ofNullable(transaction); Assert.assertFalse(getTransactionById.get().hasRawData()); } - } + }*/ @AfterClass public void shutdown() throws InterruptedException { @@ -182,4 +188,3 @@ private Transaction signTransaction(ECKey ecKey, Transaction transaction) { } -*/ diff --git a/src/test/java/stest/tron/wallet/transfer/WalletTestTransfer004.java b/src/test/java/stest/tron/wallet/transfer/WalletTestTransfer004.java new file mode 100644 index 00000000000..a8a490e6ef0 --- /dev/null +++ b/src/test/java/stest/tron/wallet/transfer/WalletTestTransfer004.java @@ -0,0 +1,291 @@ +package stest.tron.wallet.transfer; + +import com.google.protobuf.ByteString; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.Optional; +import java.util.concurrent.TimeUnit; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.spongycastle.util.encoders.Hex; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.tron.api.GrpcAPI; +import org.tron.api.GrpcAPI.NumberMessage; +import org.tron.api.GrpcAPI.Return; +import org.tron.api.GrpcAPI.TimePaginatedMessage; +import org.tron.api.GrpcAPI.TransactionList; +import org.tron.api.WalletExtensionGrpc; +import org.tron.api.WalletGrpc; +import org.tron.api.WalletSolidityGrpc; +import org.tron.common.crypto.ECKey; +import org.tron.protos.Contract; +import org.tron.protos.Protocol.Account; +import org.tron.protos.Protocol.Block; +import org.tron.protos.Protocol.Transaction; +import stest.tron.wallet.common.client.Configuration; +import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.TransactionUtils; + + +@Slf4j +public class WalletTestTransfer004 { + //testng001、testng002、testng003、testng004 + private final String testKey001 = + "8CB4480194192F30907E14B52498F594BD046E21D7C4D8FE866563A6760AC891"; + private final String testKey002 = + "FC8BF0238748587B9617EB6D15D47A66C0E07C1A1959033CF249C6532DC29FE6"; + private final String testKey003 = + "6815B367FDDE637E53E9ADC8E69424E07724333C9A2B973CFA469975E20753FC"; + private final String testKey004 = + "592BB6C9BB255409A6A43EFD18E6A74FECDDCCE93A40D96B70FBE334E6361E32"; + private final String notexist01 = + "DCB620820121A866E4E25905DC37F5025BFA5420B781C69E1BC6E1D83038C88A"; + + + //testng001、testng002、testng003、testng004 + private static final byte[] BACK_ADDRESS = Base58 + .decodeFromBase58Check("27YcHNYcxHGRf5aujYzWQaJSpQ4WN4fJkiU"); + private static final byte[] FROM_ADDRESS = Base58 + .decodeFromBase58Check("27WvzgdLiUvNAStq2BCvA1LZisdD3fBX8jv"); + private static final byte[] TO_ADDRESS = Base58 + .decodeFromBase58Check("27iDPGt91DX3ybXtExHaYvrgDt5q5d6EtFM"); + private static final byte[] NEED_CR_ADDRESS = Base58 + .decodeFromBase58Check("27QEkeaPHhUSQkw9XbxX3kCKg684eC2w67T"); + private static final byte[] ONLINE_ADDRESS = Base58 + .decodeFromBase58Check("27Vmxj4BZPCTyHnpJ1cd5Un9aehqK82dbFT"); + + private ManagedChannel channelFull = null; + private ManagedChannel channelSolidity = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + private WalletExtensionGrpc.WalletExtensionBlockingStub blockingStubExtension = null; + + private static final long now = System.currentTimeMillis(); + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + @BeforeClass + public void beforeClass() { + channelFull = ManagedChannelBuilder.forTarget(fullnode).usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + blockingStubExtension = WalletExtensionGrpc.newBlockingStub(channelSolidity); + } + + /* @Test(enabled = true) + public void testGetTransactionsByTimestamp() { + long start = now - 16400000; + long end = now; + GrpcAPI.TimeMessage.Builder timeMessage = GrpcAPI.TimeMessage.newBuilder(); + timeMessage.setBeginInMilliseconds(start); + timeMessage.setEndInMilliseconds(end); + TimePaginatedMessage.Builder timePageMessage = TimePaginatedMessage.newBuilder(); + timePageMessage.setTimeMessage(timeMessage); + timePageMessage.setOffset(0); + timePageMessage.setLimit(999); + TransactionList transactionList = blockingStubExtension + .getTransactionsByTimestamp(timePageMessage.build()); + Optional gettransactionbytimestamp = Optional + .ofNullable(transactionList); + + if (gettransactionbytimestamp.get().getTransactionCount() == 0) { + logger.info("Last one day there is no transfaction,please test for manual!!!"); + } + + Assert.assertTrue(gettransactionbytimestamp.isPresent()); + logger.info(Integer.toString(gettransactionbytimestamp.get().getTransactionCount())); + for (Integer j = 0; j < gettransactionbytimestamp.get().getTransactionCount(); j++) { + Assert.assertTrue(gettransactionbytimestamp.get().getTransaction(j).hasRawData()); + Assert.assertFalse(gettransactionbytimestamp.get().getTransaction(j) + .getRawData().getContractList().isEmpty()); + } + } + + @Test(enabled = true) + public void testExceptionTimeToGetGetTransactionsByTimestamp() { + //Start time is below zero. + long start = -10000; + long end = -1; + GrpcAPI.TimeMessage.Builder timeMessage = GrpcAPI.TimeMessage.newBuilder(); + timeMessage.setBeginInMilliseconds(start); + timeMessage.setEndInMilliseconds(end); + TimePaginatedMessage.Builder timePageMessage = TimePaginatedMessage.newBuilder(); + timePageMessage.setTimeMessage(timeMessage); + timePageMessage.setOffset(0); + timePageMessage.setLimit(999); + TransactionList transactionList = blockingStubExtension + .getTransactionsByTimestamp(timePageMessage.build()); + Optional gettransactionbytimestamp = Optional + .ofNullable(transactionList); + Assert.assertTrue(gettransactionbytimestamp.get().getTransactionCount() == 0); + + //Start time is equal with end time. + long now = System.currentTimeMillis(); + start = now; + end = now; + timeMessage = GrpcAPI.TimeMessage.newBuilder(); + timeMessage.setBeginInMilliseconds(start); + timeMessage.setEndInMilliseconds(end); + timePageMessage = TimePaginatedMessage.newBuilder(); + timePageMessage.setTimeMessage(timeMessage); + timePageMessage.setOffset(0); + timePageMessage.setLimit(999); + transactionList = blockingStubExtension + .getTransactionsByTimestamp(timePageMessage.build()); + gettransactionbytimestamp = Optional + .ofNullable(transactionList); + Assert.assertTrue(gettransactionbytimestamp.get().getTransactionCount() == 0); + + //No transeration occured. + now = System.currentTimeMillis(); + start = now; + end = now + 1; + timeMessage = GrpcAPI.TimeMessage.newBuilder(); + timeMessage.setBeginInMilliseconds(start); + timeMessage.setEndInMilliseconds(end); + timePageMessage = TimePaginatedMessage.newBuilder(); + timePageMessage.setTimeMessage(timeMessage); + timePageMessage.setOffset(0); + timePageMessage.setLimit(999); + transactionList = blockingStubExtension + .getTransactionsByTimestamp(timePageMessage.build()); + gettransactionbytimestamp = Optional + .ofNullable(transactionList); + Assert.assertTrue(gettransactionbytimestamp.get().getTransactionCount() == 0); + + + //Start time is late than currently time,no exception. + start = now + 1000000; + end = start + 1000000; + timeMessage = GrpcAPI.TimeMessage.newBuilder(); + timeMessage.setBeginInMilliseconds(start); + timeMessage.setEndInMilliseconds(end); + timePageMessage = TimePaginatedMessage.newBuilder(); + timePageMessage.setTimeMessage(timeMessage); + timePageMessage.setOffset(0); + timePageMessage.setLimit(999); + transactionList = blockingStubExtension + .getTransactionsByTimestamp(timePageMessage.build()); + gettransactionbytimestamp = Optional + .ofNullable(transactionList); + Assert.assertTrue(gettransactionbytimestamp.get().getTransactionCount() == 0); + + //Start time is late than the end time, no exception. + start = now; + end = now - 10000000; + timeMessage = GrpcAPI.TimeMessage.newBuilder(); + timeMessage.setBeginInMilliseconds(start); + timeMessage.setEndInMilliseconds(end); + timePageMessage = TimePaginatedMessage.newBuilder(); + timePageMessage.setTimeMessage(timeMessage); + timePageMessage.setOffset(0); + timePageMessage.setLimit(999); + transactionList = blockingStubExtension + .getTransactionsByTimestamp(timePageMessage.build()); + gettransactionbytimestamp = Optional + .ofNullable(transactionList); + Assert.assertTrue(gettransactionbytimestamp.get().getTransactionCount() == 0); + + //The offset is -1 + start = now - 10000000; + end = now; + timeMessage = GrpcAPI.TimeMessage.newBuilder(); + timeMessage.setBeginInMilliseconds(start); + timeMessage.setEndInMilliseconds(end); + timePageMessage = TimePaginatedMessage.newBuilder(); + timePageMessage.setTimeMessage(timeMessage); + timePageMessage.setOffset(-1); + timePageMessage.setLimit(999); + transactionList = blockingStubExtension + .getTransactionsByTimestamp(timePageMessage.build()); + gettransactionbytimestamp = Optional + .ofNullable(transactionList); + Assert.assertTrue(gettransactionbytimestamp.get().getTransactionCount() == 0); + + //The setLimit is -1 + start = now - 10000000; + end = now; + timeMessage = GrpcAPI.TimeMessage.newBuilder(); + timeMessage.setBeginInMilliseconds(start); + timeMessage.setEndInMilliseconds(end); + timePageMessage = TimePaginatedMessage.newBuilder(); + timePageMessage.setTimeMessage(timeMessage); + timePageMessage.setOffset(0); + timePageMessage.setLimit(-1); + transactionList = blockingStubExtension + .getTransactionsByTimestamp(timePageMessage.build()); + gettransactionbytimestamp = Optional + .ofNullable(transactionList); + Assert.assertTrue(gettransactionbytimestamp.get().getTransactionCount() == 0); + + + }*/ + + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + public Account queryAccount(ECKey ecKey,WalletGrpc.WalletBlockingStub blockingStubFull) { + byte[] address; + if (ecKey == null) { + String pubKey = loadPubKey(); //04 PubKey[128] + if (StringUtils.isEmpty(pubKey)) { + logger.warn("Warning: QueryAccount failed, no wallet address !!"); + return null; + } + byte[] pubKeyAsc = pubKey.getBytes(); + byte[] pubKeyHex = Hex.decode(pubKeyAsc); + ecKey = ECKey.fromPublicOnly(pubKeyHex); + } + return grpcQueryAccount(ecKey.getAddress(), blockingStubFull); + } + + public static String loadPubKey() { + char[] buf = new char[0x100]; + return String.valueOf(buf, 32, 130); + } + + public byte[] getAddress(ECKey ecKey) { + return ecKey.getAddress(); + } + + public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { + ByteString addressBs = ByteString.copyFrom(address); + Account request = Account.newBuilder().setAddress(addressBs).build(); + return blockingStubFull.getAccount(request); + } + + public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { + NumberMessage.Builder builder = NumberMessage.newBuilder(); + builder.setNum(blockNum); + return blockingStubFull.getBlockByNum(builder.build()); + } + + private Transaction signTransaction(ECKey ecKey, Transaction transaction) { + if (ecKey == null || ecKey.getPrivKey() == null) { + logger.warn("Warning: Can't sign,there is no private key !!"); + return null; + } + transaction = TransactionUtils.setTimestamp(transaction); + return TransactionUtils.sign(transaction, ecKey); + } +} + + diff --git a/src/test/java/stest/tron/wallet/transfer/WalletTestTransfer005.java b/src/test/java/stest/tron/wallet/transfer/WalletTestTransfer005.java new file mode 100644 index 00000000000..77079125e33 --- /dev/null +++ b/src/test/java/stest/tron/wallet/transfer/WalletTestTransfer005.java @@ -0,0 +1,223 @@ +package stest.tron.wallet.transfer; + +import com.google.protobuf.ByteString; +import com.googlecode.cqengine.query.simple.In; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.Optional; +import java.util.concurrent.TimeUnit; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.iterators.FilterIterator; +import org.apache.commons.lang3.StringUtils; +import org.spongycastle.util.encoders.Hex; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.tron.api.GrpcAPI; +import org.tron.api.GrpcAPI.AccountPaginated; + +import org.tron.api.GrpcAPI.NumberMessage; +import org.tron.api.WalletExtensionGrpc; +import org.tron.api.WalletGrpc; +import org.tron.api.WalletSolidityGrpc; +import org.tron.common.crypto.ECKey; +import org.tron.protos.Protocol.Account; +import org.tron.protos.Protocol.Block; +import org.tron.protos.Protocol.Transaction; +import stest.tron.wallet.common.client.Configuration; +import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.PublicMethed; +import stest.tron.wallet.common.client.utils.TransactionUtils; + + +@Slf4j +public class WalletTestTransfer005 { + + //testng001、testng002、testng003、testng004 + private final String testKey001 = + "8CB4480194192F30907E14B52498F594BD046E21D7C4D8FE866563A6760AC891"; + private final String testKey002 = + "FC8BF0238748587B9617EB6D15D47A66C0E07C1A1959033CF249C6532DC29FE6"; + private final String testKey003 = + "6815B367FDDE637E53E9ADC8E69424E07724333C9A2B973CFA469975E20753FC"; + private final String testKey004 = + "592BB6C9BB255409A6A43EFD18E6A74FECDDCCE93A40D96B70FBE334E6361E32"; + private final String notexist01 = + "DCB620820121A866E4E25905DC37F5025BFA5420B781C69E1BC6E1D83038C88A"; + + //testng001、testng002、testng003、testng004 + private static final byte[] BACK_ADDRESS = + Base58.decodeFromBase58Check("27YcHNYcxHGRf5aujYzWQaJSpQ4WN4fJkiU"); + private static final byte[] FROM_ADDRESS = + Base58.decodeFromBase58Check("27WvzgdLiUvNAStq2BCvA1LZisdD3fBX8jv"); + private static final byte[] TO_ADDRESS = + Base58.decodeFromBase58Check("27iDPGt91DX3ybXtExHaYvrgDt5q5d6EtFM"); + private static final byte[] NEED_CR_ADDRESS = + Base58.decodeFromBase58Check("27QEkeaPHhUSQkw9XbxX3kCKg684eC2w67T"); + private static final byte[] ONLINE_ADDRESS = + Base58.decodeFromBase58Check("27Vmxj4BZPCTyHnpJ1cd5Un9aehqK82dbFT"); + private static final byte[] INVAILD_ADDRESS = + Base58.decodeFromBase58Check("27cu1ozb4mX3m2afY68FSAqn3HmMp815d48"); + + private ManagedChannel channelFull = null; + private ManagedChannel channelSolidity = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + private WalletExtensionGrpc.WalletExtensionBlockingStub blockingStubExtension = null; + + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + @BeforeClass + public void beforeClass() { + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + blockingStubExtension = WalletExtensionGrpc.newBlockingStub(channelSolidity); + + //Create a transfer. + Assert.assertTrue(PublicMethed.sendcoin(TO_ADDRESS,1000000,FROM_ADDRESS, + testKey002,blockingStubFull)); + } + + @Test(enabled = true) + public void testgetTransactionsFromThis() { + + Assert.assertTrue(PublicMethed.waitSolidityNodeSynFullNodeData(blockingStubFull, + blockingStubSolidity)); + + + ByteString addressBs = ByteString.copyFrom(FROM_ADDRESS); + Account account = Account.newBuilder().setAddress(addressBs).build(); + AccountPaginated.Builder accountPaginated = AccountPaginated.newBuilder().setAccount(account); + accountPaginated.setOffset(1000); + accountPaginated.setLimit(0); + GrpcAPI.TransactionList transactionList = blockingStubExtension + .getTransactionsFromThis(accountPaginated.build()); + Optional gettransactionsfromthis = Optional + .ofNullable(transactionList); + + if (gettransactionsfromthis.get().getTransactionCount() == 0) { + logger.info("This account didn't transfation any coin to other"); + } + + Assert.assertTrue(gettransactionsfromthis.isPresent()); + Integer beforecount = gettransactionsfromthis.get().getTransactionCount(); + logger.info(Integer.toString(beforecount)); + for (Integer j = 0; j < beforecount; j++) { + Assert.assertFalse(gettransactionsfromthis.get().getTransaction(j) + .getRawData().getContractList().isEmpty()); + } + } + + @Test(enabled = true) + public void testgetTransactionsFromThisByInvaildAddress() { + //Invaild address. + ByteString addressBs = ByteString.copyFrom(INVAILD_ADDRESS); + Account account = Account.newBuilder().setAddress(addressBs).build(); + AccountPaginated.Builder accountPaginated = AccountPaginated.newBuilder().setAccount(account); + accountPaginated.setOffset(1000); + accountPaginated.setLimit(0); + GrpcAPI.TransactionList transactionList = blockingStubExtension + .getTransactionsFromThis(accountPaginated.build()); + Optional gettransactionsfromthisByInvaildAddress = Optional + .ofNullable(transactionList); + + Assert.assertTrue(gettransactionsfromthisByInvaildAddress.get().getTransactionCount() == 0); + + //Limit is -1 + addressBs = ByteString.copyFrom(INVAILD_ADDRESS); + account = Account.newBuilder().setAddress(addressBs).build(); + accountPaginated = AccountPaginated.newBuilder().setAccount(account); + accountPaginated.setOffset(1000); + accountPaginated.setLimit(-1); + transactionList = blockingStubExtension + .getTransactionsFromThis(accountPaginated.build()); + gettransactionsfromthisByInvaildAddress = Optional + .ofNullable(transactionList); + + Assert.assertTrue(gettransactionsfromthisByInvaildAddress.get().getTransactionCount() == 0); + + //offset is -1 + addressBs = ByteString.copyFrom(INVAILD_ADDRESS); + account = Account.newBuilder().setAddress(addressBs).build(); + accountPaginated = AccountPaginated.newBuilder().setAccount(account); + accountPaginated.setOffset(-1); + accountPaginated.setLimit(100); + transactionList = blockingStubExtension + .getTransactionsFromThis(accountPaginated.build()); + gettransactionsfromthisByInvaildAddress = Optional + .ofNullable(transactionList); + + Assert.assertTrue(gettransactionsfromthisByInvaildAddress.get().getTransactionCount() == 0); + + } + + + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + public Account queryAccount(ECKey ecKey,WalletGrpc.WalletBlockingStub blockingStubFull) { + byte[] address; + if (ecKey == null) { + String pubKey = loadPubKey(); //04 PubKey[128] + if (StringUtils.isEmpty(pubKey)) { + logger.warn("Warning: QueryAccount failed, no wallet address !!"); + return null; + } + byte[] pubKeyAsc = pubKey.getBytes(); + byte[] pubKeyHex = Hex.decode(pubKeyAsc); + ecKey = ECKey.fromPublicOnly(pubKeyHex); + } + return grpcQueryAccount(ecKey.getAddress(), blockingStubFull); + } + + public static String loadPubKey() { + char[] buf = new char[0x100]; + return String.valueOf(buf, 32, 130); + } + + public byte[] getAddress(ECKey ecKey) { + return ecKey.getAddress(); + } + + public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { + ByteString addressBs = ByteString.copyFrom(address); + Account request = Account.newBuilder().setAddress(addressBs).build(); + return blockingStubFull.getAccount(request); + } + + public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { + NumberMessage.Builder builder = NumberMessage.newBuilder(); + builder.setNum(blockNum); + return blockingStubFull.getBlockByNum(builder.build()); + } + + private Transaction signTransaction(ECKey ecKey, Transaction transaction) { + if (ecKey == null || ecKey.getPrivKey() == null) { + logger.warn("Warning: Can't sign,there is no private key !!"); + return null; + } + transaction = TransactionUtils.setTimestamp(transaction); + return TransactionUtils.sign(transaction, ecKey); + } +} + + diff --git a/src/test/java/stest/tron/wallet/transfer/WalletTestTransfer006.java b/src/test/java/stest/tron/wallet/transfer/WalletTestTransfer006.java new file mode 100644 index 00000000000..f4e867a4fa6 --- /dev/null +++ b/src/test/java/stest/tron/wallet/transfer/WalletTestTransfer006.java @@ -0,0 +1,223 @@ +package stest.tron.wallet.transfer; + +import com.google.protobuf.ByteString; +import com.googlecode.cqengine.query.simple.In; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.Optional; +import java.util.concurrent.TimeUnit; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.iterators.FilterIterator; +import org.apache.commons.lang3.StringUtils; +import org.spongycastle.util.encoders.Hex; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.tron.api.GrpcAPI; +import org.tron.api.GrpcAPI.AccountPaginated; + +import org.tron.api.GrpcAPI.NumberMessage; +import org.tron.api.WalletExtensionGrpc; +import org.tron.api.WalletGrpc; +import org.tron.api.WalletSolidityGrpc; +import org.tron.common.crypto.ECKey; +import org.tron.protos.Protocol.Account; +import org.tron.protos.Protocol.Block; +import org.tron.protos.Protocol.Transaction; +import stest.tron.wallet.common.client.Configuration; +import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.PublicMethed; +import stest.tron.wallet.common.client.utils.TransactionUtils; + + +@Slf4j +public class WalletTestTransfer006 { + + //testng001、testng002、testng003、testng004 + private final String testKey001 = + "8CB4480194192F30907E14B52498F594BD046E21D7C4D8FE866563A6760AC891"; + private final String testKey002 = + "FC8BF0238748587B9617EB6D15D47A66C0E07C1A1959033CF249C6532DC29FE6"; + private final String testKey003 = + "6815B367FDDE637E53E9ADC8E69424E07724333C9A2B973CFA469975E20753FC"; + private final String testKey004 = + "592BB6C9BB255409A6A43EFD18E6A74FECDDCCE93A40D96B70FBE334E6361E32"; + private final String notexist01 = + "DCB620820121A866E4E25905DC37F5025BFA5420B781C69E1BC6E1D83038C88A"; + + //testng001、testng002、testng003、testng004 + private static final byte[] BACK_ADDRESS = + Base58.decodeFromBase58Check("27YcHNYcxHGRf5aujYzWQaJSpQ4WN4fJkiU"); + private static final byte[] FROM_ADDRESS = + Base58.decodeFromBase58Check("27WvzgdLiUvNAStq2BCvA1LZisdD3fBX8jv"); + private static final byte[] TO_ADDRESS = + Base58.decodeFromBase58Check("27iDPGt91DX3ybXtExHaYvrgDt5q5d6EtFM"); + private static final byte[] NEED_CR_ADDRESS = + Base58.decodeFromBase58Check("27QEkeaPHhUSQkw9XbxX3kCKg684eC2w67T"); + private static final byte[] ONLINE_ADDRESS = + Base58.decodeFromBase58Check("27Vmxj4BZPCTyHnpJ1cd5Un9aehqK82dbFT"); + private static final byte[] INVAILD_ADDRESS = + Base58.decodeFromBase58Check("27cu1ozb4mX3m2afY68FSAqn3HmMp815d48"); + + private ManagedChannel channelFull = null; + private ManagedChannel channelSolidity = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + private WalletExtensionGrpc.WalletExtensionBlockingStub blockingStubExtension = null; + + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + @BeforeClass + public void beforeClass() { + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + blockingStubExtension = WalletExtensionGrpc.newBlockingStub(channelSolidity); + + //Create a transfer. + Assert.assertTrue(PublicMethed.sendcoin(TO_ADDRESS,1000000,FROM_ADDRESS, + testKey002,blockingStubFull)); + } + + @Test(enabled = true) + public void testgetTransactionsToThis() { + + Assert.assertTrue(PublicMethed.waitSolidityNodeSynFullNodeData(blockingStubFull, + blockingStubSolidity)); + + + ByteString addressBs = ByteString.copyFrom(TO_ADDRESS); + Account account = Account.newBuilder().setAddress(addressBs).build(); + AccountPaginated.Builder accountPaginated = AccountPaginated.newBuilder().setAccount(account); + accountPaginated.setOffset(1000); + accountPaginated.setLimit(0); + GrpcAPI.TransactionList transactionList = blockingStubExtension + .getTransactionsToThis(accountPaginated.build()); + Optional gettransactionstothis = Optional + .ofNullable(transactionList); + + if (gettransactionstothis.get().getTransactionCount() == 0) { + logger.info("This account didn't transfation any coin to other"); + } + + Assert.assertTrue(gettransactionstothis.isPresent()); + Integer beforecount = gettransactionstothis.get().getTransactionCount(); + logger.info(Integer.toString(beforecount)); + for (Integer j = 0; j < beforecount; j++) { + Assert.assertFalse(gettransactionstothis.get().getTransaction(j) + .getRawData().getContractList().isEmpty()); + } + } + + @Test(enabled = true) + public void testgetTransactionsToThisByInvaildAddress() { + //Invaild address. + ByteString addressBs = ByteString.copyFrom(INVAILD_ADDRESS); + Account account = Account.newBuilder().setAddress(addressBs).build(); + AccountPaginated.Builder accountPaginated = AccountPaginated.newBuilder().setAccount(account); + accountPaginated.setOffset(1000); + accountPaginated.setLimit(0); + GrpcAPI.TransactionList transactionList = blockingStubExtension + .getTransactionsToThis(accountPaginated.build()); + Optional gettransactionstothisByInvaildAddress = Optional + .ofNullable(transactionList); + + Assert.assertTrue(gettransactionstothisByInvaildAddress.get().getTransactionCount() == 0); + + //Limit is -1 + addressBs = ByteString.copyFrom(INVAILD_ADDRESS); + account = Account.newBuilder().setAddress(addressBs).build(); + accountPaginated = AccountPaginated.newBuilder().setAccount(account); + accountPaginated.setOffset(1000); + accountPaginated.setLimit(-1); + transactionList = blockingStubExtension + .getTransactionsToThis(accountPaginated.build()); + gettransactionstothisByInvaildAddress = Optional + .ofNullable(transactionList); + + Assert.assertTrue(gettransactionstothisByInvaildAddress.get().getTransactionCount() == 0); + + //offset is -1 + addressBs = ByteString.copyFrom(INVAILD_ADDRESS); + account = Account.newBuilder().setAddress(addressBs).build(); + accountPaginated = AccountPaginated.newBuilder().setAccount(account); + accountPaginated.setOffset(-1); + accountPaginated.setLimit(100); + transactionList = blockingStubExtension + .getTransactionsToThis(accountPaginated.build()); + gettransactionstothisByInvaildAddress = Optional + .ofNullable(transactionList); + + Assert.assertTrue(gettransactionstothisByInvaildAddress.get().getTransactionCount() == 0); + + } + + + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + public Account queryAccount(ECKey ecKey,WalletGrpc.WalletBlockingStub blockingStubFull) { + byte[] address; + if (ecKey == null) { + String pubKey = loadPubKey(); //04 PubKey[128] + if (StringUtils.isEmpty(pubKey)) { + logger.warn("Warning: QueryAccount failed, no wallet address !!"); + return null; + } + byte[] pubKeyAsc = pubKey.getBytes(); + byte[] pubKeyHex = Hex.decode(pubKeyAsc); + ecKey = ECKey.fromPublicOnly(pubKeyHex); + } + return grpcQueryAccount(ecKey.getAddress(), blockingStubFull); + } + + public static String loadPubKey() { + char[] buf = new char[0x100]; + return String.valueOf(buf, 32, 130); + } + + public byte[] getAddress(ECKey ecKey) { + return ecKey.getAddress(); + } + + public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { + ByteString addressBs = ByteString.copyFrom(address); + Account request = Account.newBuilder().setAddress(addressBs).build(); + return blockingStubFull.getAccount(request); + } + + public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { + NumberMessage.Builder builder = NumberMessage.newBuilder(); + builder.setNum(blockNum); + return blockingStubFull.getBlockByNum(builder.build()); + } + + private Transaction signTransaction(ECKey ecKey, Transaction transaction) { + if (ecKey == null || ecKey.getPrivKey() == null) { + logger.warn("Warning: Can't sign,there is no private key !!"); + return null; + } + transaction = TransactionUtils.setTimestamp(transaction); + return TransactionUtils.sign(transaction, ecKey); + } +} + + diff --git a/src/test/java/stest/tron/wallet/transfer/WalletTest_p1_Transfer_004.java b/src/test/java/stest/tron/wallet/transfer/WalletTest_p1_Transfer_004.java deleted file mode 100644 index 04368abc304..00000000000 --- a/src/test/java/stest/tron/wallet/transfer/WalletTest_p1_Transfer_004.java +++ /dev/null @@ -1,208 +0,0 @@ -package stest.tron.wallet.transfer;/* -package stest.tron.wallet.Wallettest_p1; - -import com.google.protobuf.ByteString; -import io.grpc.ManagedChannel; -import io.grpc.ManagedChannelBuilder; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; -import org.spongycastle.util.encoders.Hex; -import org.testng.Assert; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; -import org.tron.api.GrpcAPI; -import org.tron.api.GrpcAPI.NumberMessage; -import org.tron.api.GrpcAPI.Return; -import org.tron.api.WalletGrpc; -import org.tron.api.WalletSolidityGrpc; -import org.tron.common.crypto.ECKey; -import org.tron.protos.Contract; -import org.tron.protos.Protocol.Account; -import org.tron.protos.Protocol.Block; -import org.tron.protos.Protocol.Transaction; -import stest.tron.wallet.common.client.Configuration; -import stest.tron.wallet.common.client.utils.Base58; -import stest.tron.wallet.common.client.utils.TransactionUtils; - -import java.math.BigInteger; -import java.util.Optional; -import java.util.concurrent.TimeUnit; - -@Slf4j -public class WalletTest_p1_Transfer_004 { - - //testng001、testng002、testng003、testng004 - private final static String testKey001 = "8CB4480194192F30907E14B52498F594BD046E21D7C4D8FE866563A6760AC891"; - private final static String testKey002 = "FC8BF0238748587B9617EB6D15D47A66C0E07C1A1959033CF249C6532DC29FE6"; - private final static String testKey003 = "6815B367FDDE637E53E9ADC8E69424E07724333C9A2B973CFA469975E20753FC"; - private final static String testKey004 = "592BB6C9BB255409A6A43EFD18E6A74FECDDCCE93A40D96B70FBE334E6361E32"; - private final static String notexist01 = "DCB620820121A866E4E25905DC37F5025BFA5420B781C69E1BC6E1D83038C88A"; - - //testng001、testng002、testng003、testng004 - private static final byte[] BACK_ADDRESS = Base58.decodeFromBase58Check("27YcHNYcxHGRf5aujYzWQaJSpQ4WN4fJkiU"); - private static final byte[] FROM_ADDRESS = Base58.decodeFromBase58Check("27WvzgdLiUvNAStq2BCvA1LZisdD3fBX8jv"); - private static final byte[] TO_ADDRESS = Base58.decodeFromBase58Check("27iDPGt91DX3ybXtExHaYvrgDt5q5d6EtFM"); - private static final byte[] NEED_CR_ADDRESS = Base58.decodeFromBase58Check("27QEkeaPHhUSQkw9XbxX3kCKg684eC2w67T"); - private static final byte[] ONLINE_ADDRESS = Base58.decodeFromBase58Check("27Vmxj4BZPCTyHnpJ1cd5Un9aehqK82dbFT"); - - private ManagedChannel channelFull = null; - private ManagedChannel channelSolidity = null; - private WalletGrpc.WalletBlockingStub blockingStubFull = null; - private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; - - private static final long now = System.currentTimeMillis(); - - private String fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(0); - private String soliditynode = Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); - - @BeforeClass - public void beforeClass(){ - channelFull = ManagedChannelBuilder.forTarget(fullnode) - .usePlaintext(true) - .build(); - blockingStubFull = WalletGrpc.newBlockingStub(channelFull); - - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext(true) - .build(); - blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); - } - - @Test(enabled = true) - public void TestGetTransactionsByTimestamp(){ - long start = now - 7200000; - long end = now; - GrpcAPI.TimeMessage.Builder timeMessage = GrpcAPI.TimeMessage.newBuilder(); - timeMessage.setBeginInMilliseconds(start); - timeMessage.setEndInMilliseconds(end); - GrpcAPI.TransactionList transactionList = blockingStubSolidity.getTransactionsByTimestamp(timeMessage.build()); - Optional gettransactionbytimestamp = Optional.ofNullable(transactionList); - - if (gettransactionbytimestamp.get().getTransactionCount() == 0){ - logger.info("Last one day there is no transfaction,please test for manual!!!"); - } - - Assert.assertTrue(gettransactionbytimestamp.isPresent()); - logger.info(Integer.toString(gettransactionbytimestamp.get().getTransactionCount())); - for(Integer j =0; j< gettransactionbytimestamp.get().getTransactionCount(); j++){ - Assert.assertTrue(gettransactionbytimestamp.get().getTransaction(j).hasRawData()); - Assert.assertFalse(gettransactionbytimestamp.get().getTransaction(j).getRawData().getContractList().isEmpty()); - } - } - - @Test(enabled = true) - public void TestExceptionTimeToGetGetTransactionsByTimestamp(){ - //Start time is below zero. - long start = -10000; - long end = -1; - GrpcAPI.TimeMessage.Builder timeMessage = GrpcAPI.TimeMessage.newBuilder(); - timeMessage.setBeginInMilliseconds(start); - timeMessage.setEndInMilliseconds(end); - GrpcAPI.TransactionList transactionList = blockingStubSolidity.getTransactionsByTimestamp(timeMessage.build()); - Optional gettransactionbytimestamp = Optional.ofNullable(transactionList); - Assert.assertTrue(gettransactionbytimestamp.get().getTransactionCount() == 0); - - //Start time is equal with end time. - long now = System.currentTimeMillis(); - start = now; - end = now; - timeMessage = GrpcAPI.TimeMessage.newBuilder(); - timeMessage.setBeginInMilliseconds(start); - timeMessage.setEndInMilliseconds(end); - transactionList = blockingStubSolidity.getTransactionsByTimestamp(timeMessage.build()); - gettransactionbytimestamp = Optional.ofNullable(transactionList); - Assert.assertTrue(gettransactionbytimestamp.get().getTransactionCount() == 0); - - //No transeration occured. - now = System.currentTimeMillis(); - start = now; - end = now+1; - timeMessage = GrpcAPI.TimeMessage.newBuilder(); - timeMessage.setBeginInMilliseconds(start); - timeMessage.setEndInMilliseconds(end); - transactionList = blockingStubSolidity.getTransactionsByTimestamp(timeMessage.build()); - gettransactionbytimestamp = Optional.ofNullable(transactionList); - Assert.assertTrue(gettransactionbytimestamp.get().getTransactionCount() == 0); - - - //Start time is late than currently time,no exception. - start = now + 1000000; - end = start + 1000000; - timeMessage = GrpcAPI.TimeMessage.newBuilder(); - timeMessage.setBeginInMilliseconds(start); - timeMessage.setEndInMilliseconds(end); - transactionList = blockingStubSolidity.getTransactionsByTimestamp(timeMessage.build()); - gettransactionbytimestamp = Optional.ofNullable(transactionList); - Assert.assertTrue(gettransactionbytimestamp.get().getTransactionCount() == 0); - - //Start time is late than the end time, no exception. - start = now; - end = now - 10000000; - timeMessage = GrpcAPI.TimeMessage.newBuilder(); - timeMessage.setBeginInMilliseconds(start); - timeMessage.setEndInMilliseconds(end); - transactionList = blockingStubSolidity.getTransactionsByTimestamp(timeMessage.build()); - gettransactionbytimestamp = Optional.ofNullable(transactionList); - Assert.assertTrue(gettransactionbytimestamp.get().getTransactionCount() == 0); - } - - @AfterClass - public void shutdown() throws InterruptedException { - if(channelFull != null) { - channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } - if(channelSolidity != null) { - channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } - } - - public Account queryAccount(ECKey ecKey,WalletGrpc.WalletBlockingStub blockingStubFull) { - byte[] address; - if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] - if (StringUtils.isEmpty(pubKey)) { - logger.warn("Warning: QueryAccount failed, no wallet address !!"); - return null; - } - byte[] pubKeyAsc = pubKey.getBytes(); - byte[] pubKeyHex = Hex.decode(pubKeyAsc); - ecKey = ECKey.fromPublicOnly(pubKeyHex); - } - return grpcQueryAccount(ecKey.getAddress(), blockingStubFull); - } - - public static String loadPubKey() { - char[] buf = new char[0x100]; - return String.valueOf(buf, 32, 130); - } - - public byte[] getAddress(ECKey ecKey) { - return ecKey.getAddress(); - } - - public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { - ByteString addressBS = ByteString.copyFrom(address); - Account request = Account.newBuilder().setAddress(addressBS).build(); - return blockingStubFull.getAccount(request); - } - - public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { - NumberMessage.Builder builder = NumberMessage.newBuilder(); - builder.setNum(blockNum); - return blockingStubFull.getBlockByNum(builder.build()); - - } - - private Transaction signTransaction(ECKey ecKey, Transaction transaction) { - if (ecKey == null || ecKey.getPrivKey() == null) { - logger.warn("Warning: Can't sign,there is no private key !!"); - return null; - } - transaction = TransactionUtils.setTimestamp(transaction); - return TransactionUtils.sign(transaction, ecKey); - } -} - - -*/ diff --git a/src/test/java/stest/tron/wallet/transfer/WalletTest_p1_Transfer_005.java b/src/test/java/stest/tron/wallet/transfer/WalletTest_p1_Transfer_005.java deleted file mode 100644 index 9e744f98a09..00000000000 --- a/src/test/java/stest/tron/wallet/transfer/WalletTest_p1_Transfer_005.java +++ /dev/null @@ -1,179 +0,0 @@ -package stest.tron.wallet.transfer;/* -package stest.tron.wallet.Wallettest_p1; - -import com.google.protobuf.ByteString; -import com.googlecode.cqengine.query.simple.In; -import io.grpc.ManagedChannel; -import io.grpc.ManagedChannelBuilder; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.collections4.iterators.FilterIterator; -import org.apache.commons.lang3.StringUtils; -import org.spongycastle.util.encoders.Hex; -import org.testng.Assert; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; -import org.tron.api.GrpcAPI; -import org.tron.api.GrpcAPI.NumberMessage; -import org.tron.api.GrpcAPI.Return; -import org.tron.api.WalletGrpc; -import org.tron.api.WalletSolidityGrpc; -import org.tron.api.GrpcAPI.AccountPaginated; -import org.tron.common.crypto.ECKey; -import org.tron.protos.Contract; -import org.tron.protos.Protocol.Account; -import org.tron.protos.Protocol.Block; -import org.tron.protos.Protocol.Transaction; -import stest.tron.wallet.common.client.Configuration; -import stest.tron.wallet.common.client.utils.Base58; -import stest.tron.wallet.common.client.utils.TransactionUtils; - -import java.math.BigInteger; -import java.util.Optional; -import java.util.concurrent.TimeUnit; - -@Slf4j -public class WalletTest_p1_Transfer_005 { - - //testng001、testng002、testng003、testng004 - private final static String testKey001 = "8CB4480194192F30907E14B52498F594BD046E21D7C4D8FE866563A6760AC891"; - private final static String testKey002 = "FC8BF0238748587B9617EB6D15D47A66C0E07C1A1959033CF249C6532DC29FE6"; - private final static String testKey003 = "6815B367FDDE637E53E9ADC8E69424E07724333C9A2B973CFA469975E20753FC"; - private final static String testKey004 = "592BB6C9BB255409A6A43EFD18E6A74FECDDCCE93A40D96B70FBE334E6361E32"; - private final static String notexist01 = "DCB620820121A866E4E25905DC37F5025BFA5420B781C69E1BC6E1D83038C88A"; - - //testng001、testng002、testng003、testng004 - private static final byte[] BACK_ADDRESS = Base58.decodeFromBase58Check("27YcHNYcxHGRf5aujYzWQaJSpQ4WN4fJkiU"); - private static final byte[] FROM_ADDRESS = Base58.decodeFromBase58Check("27WvzgdLiUvNAStq2BCvA1LZisdD3fBX8jv"); - private static final byte[] TO_ADDRESS = Base58.decodeFromBase58Check("27iDPGt91DX3ybXtExHaYvrgDt5q5d6EtFM"); - private static final byte[] NEED_CR_ADDRESS = Base58.decodeFromBase58Check("27QEkeaPHhUSQkw9XbxX3kCKg684eC2w67T"); - private static final byte[] ONLINE_ADDRESS = Base58.decodeFromBase58Check("27Vmxj4BZPCTyHnpJ1cd5Un9aehqK82dbFT"); - private static final byte[] INVAILD_ADDRESS = Base58.decodeFromBase58Check("27cu1ozb4mX3m2afY68FSAqn3HmMp815d48"); - - private ManagedChannel channelFull = null; - private ManagedChannel channelSolidity = null; - private WalletGrpc.WalletBlockingStub blockingStubFull = null; - private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; - - - private String fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(0); - private String soliditynode = Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); - - @BeforeClass - public void beforeClass(){ - channelFull = ManagedChannelBuilder.forTarget(fullnode) - .usePlaintext(true) - .build(); - blockingStubFull = WalletGrpc.newBlockingStub(channelFull); - - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext(true) - .build(); - blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); - } - - @Test(enabled = true) - public void TestgetTransactionsFromThis(){ -*/ -/* public Optional getTransactionsFromThis(byte[] address, int offset, int limit) { - //ByteString addressBS = ByteString.copyFrom(address); - //Account account = Account.newBuilder().setAddress(addressBS).build(); - AccountPaginated.Builder accountPaginated = AccountPaginated.newBuilder(); - accountPaginated.setAccount(account); - accountPaginated.setOffset(offset); - accountPaginated.setLimit(limit); - GrpcAPI.TransactionList transactionList = blockingStubSolidity.getTransactionsFromThis(accountPaginated.build()); - return Optional.ofNullable(transactionList); - }*//* - - ByteString addressBS = ByteString.copyFrom(FROM_ADDRESS); - Account account = Account.newBuilder().setAddress(addressBS).build(); - AccountPaginated.Builder accountPaginated = AccountPaginated.newBuilder(); - accountPaginated.setAccount(account); - accountPaginated.setOffset(0); - accountPaginated.setLimit(1); - GrpcAPI.TransactionList transactionList = blockingStubSolidity.getTransactionsFromThis(accountPaginated.build()); - Optional gettransactionsfromthis= Optional.ofNullable(transactionList); - - if (gettransactionsfromthis.get().getTransactionCount() == 0){ - logger.info("This account didn't transfation any coin to other"); - } - - Assert.assertTrue(gettransactionsfromthis.isPresent()); - Integer beforecount = gettransactionsfromthis.get().getTransactionCount(); - logger.info(Integer.toString(beforecount)); - for (Integer j =0; j gettransactionsfromthisByInvaildAddress= Optional.ofNullable(transactionList); - - Assert.assertTrue(gettransactionsfromthisByInvaildAddress.get().getTransactionCount() == 0); - } - - - @AfterClass - public void shutdown() throws InterruptedException { - if(channelFull != null) { - channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } - if(channelSolidity != null) { - channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } - } - - public Account queryAccount(ECKey ecKey,WalletGrpc.WalletBlockingStub blockingStubFull) { - byte[] address; - if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] - if (StringUtils.isEmpty(pubKey)) { - logger.warn("Warning: QueryAccount failed, no wallet address !!"); - return null; - } - byte[] pubKeyAsc = pubKey.getBytes(); - byte[] pubKeyHex = Hex.decode(pubKeyAsc); - ecKey = ECKey.fromPublicOnly(pubKeyHex); - } - return grpcQueryAccount(ecKey.getAddress(), blockingStubFull); - } - - public static String loadPubKey() { - char[] buf = new char[0x100]; - return String.valueOf(buf, 32, 130); - } - - public byte[] getAddress(ECKey ecKey) { - return ecKey.getAddress(); - } - - public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { - ByteString addressBS = ByteString.copyFrom(address); - Account request = Account.newBuilder().setAddress(addressBS).build(); - return blockingStubFull.getAccount(request); - } - - public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { - NumberMessage.Builder builder = NumberMessage.newBuilder(); - builder.setNum(blockNum); - return blockingStubFull.getBlockByNum(builder.build()); - - } - - private Transaction signTransaction(ECKey ecKey, Transaction transaction) { - if (ecKey == null || ecKey.getPrivKey() == null) { - logger.warn("Warning: Can't sign,there is no private key !!"); - return null; - } - transaction = TransactionUtils.setTimestamp(transaction); - return TransactionUtils.sign(transaction, ecKey); - } -} - - -*/ diff --git a/src/test/java/stest/tron/wallet/transfer/WalletTest_p1_Transfer_006.java b/src/test/java/stest/tron/wallet/transfer/WalletTest_p1_Transfer_006.java deleted file mode 100644 index 1a214cd03b1..00000000000 --- a/src/test/java/stest/tron/wallet/transfer/WalletTest_p1_Transfer_006.java +++ /dev/null @@ -1,160 +0,0 @@ -package stest.tron.wallet.transfer;/* -package stest.tron.wallet.Wallettest_p1; - -import com.google.protobuf.ByteString; -import io.grpc.ManagedChannel; -import io.grpc.ManagedChannelBuilder; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; -import org.spongycastle.util.encoders.Hex; -import org.testng.Assert; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; -import org.tron.api.GrpcAPI; -import org.tron.api.GrpcAPI.NumberMessage; -import org.tron.api.GrpcAPI.Return; -import org.tron.api.WalletGrpc; -import org.tron.api.WalletSolidityGrpc; -import org.tron.common.crypto.ECKey; -import org.tron.protos.Contract; -import org.tron.protos.Protocol.Account; -import org.tron.protos.Protocol.Block; -import org.tron.protos.Protocol.Transaction; -import stest.tron.wallet.common.client.Configuration; -import stest.tron.wallet.common.client.utils.Base58; -import stest.tron.wallet.common.client.utils.TransactionUtils; - -import java.math.BigInteger; -import java.util.Optional; -import java.util.concurrent.TimeUnit; - -@Slf4j -public class WalletTest_p1_Transfer_006 { - - //testng001、testng002、testng003、testng004 - private final static String testKey001 = "8CB4480194192F30907E14B52498F594BD046E21D7C4D8FE866563A6760AC891"; - private final static String testKey002 = "FC8BF0238748587B9617EB6D15D47A66C0E07C1A1959033CF249C6532DC29FE6"; - private final static String testKey003 = "6815B367FDDE637E53E9ADC8E69424E07724333C9A2B973CFA469975E20753FC"; - private final static String testKey004 = "592BB6C9BB255409A6A43EFD18E6A74FECDDCCE93A40D96B70FBE334E6361E32"; - private final static String notexist01 = "DCB620820121A866E4E25905DC37F5025BFA5420B781C69E1BC6E1D83038C88A"; - - //testng001、testng002、testng003、testng004 - private static final byte[] BACK_ADDRESS = Base58.decodeFromBase58Check("27YcHNYcxHGRf5aujYzWQaJSpQ4WN4fJkiU"); - private static final byte[] FROM_ADDRESS = Base58.decodeFromBase58Check("27WvzgdLiUvNAStq2BCvA1LZisdD3fBX8jv"); - private static final byte[] TO_ADDRESS = Base58.decodeFromBase58Check("27iDPGt91DX3ybXtExHaYvrgDt5q5d6EtFM"); - private static final byte[] NEED_CR_ADDRESS = Base58.decodeFromBase58Check("27QEkeaPHhUSQkw9XbxX3kCKg684eC2w67T"); - private static final byte[] ONLINE_ADDRESS = Base58.decodeFromBase58Check("27Vmxj4BZPCTyHnpJ1cd5Un9aehqK82dbFT"); - private static final byte[] INVAILD_ADDRESS = Base58.decodeFromBase58Check("27cu1ozb4mX3m2afY68FSAqn3HmMp815d48"); - - private ManagedChannel channelFull = null; - private ManagedChannel channelSolidity = null; - private WalletGrpc.WalletBlockingStub blockingStubFull = null; - private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; - - - private String fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list").get(0); - private String soliditynode = Configuration.getByPath("testng.conf").getStringList("solidityNode.ip.list").get(0); - - @BeforeClass - public void beforeClass(){ - channelFull = ManagedChannelBuilder.forTarget(fullnode) - .usePlaintext(true) - .build(); - blockingStubFull = WalletGrpc.newBlockingStub(channelFull); - - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext(true) - .build(); - blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); - } - - @Test(enabled = true) - public void TestgetTransactionstoThis(){ - ByteString addressBS = ByteString.copyFrom(ONLINE_ADDRESS); - Account request = Account.newBuilder().setAddress(addressBS).build(); - GrpcAPI.TransactionList transactionList = blockingStubSolidity.getTransactionsToThis(request); - Optional gettransactionstothis= Optional.ofNullable(transactionList); - - if (gettransactionstothis.get().getTransactionCount() == 0){ - logger.info("This account didn't receipt any coin from others. Please test this case for manual"); - } - - Assert.assertTrue(gettransactionstothis.isPresent()); - Integer beforecount = gettransactionstothis.get().getTransactionCount(); - logger.info(Integer.toString(beforecount)); - for (Integer j =0; j gettransactionstothis= Optional.ofNullable(transactionList); - - Assert.assertTrue(gettransactionstothis.get().getTransactionCount() == 0); - } - - - @AfterClass - public void shutdown() throws InterruptedException { - if(channelFull != null) { - channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } - if(channelSolidity != null) { - channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } - } - - public Account queryAccount(ECKey ecKey,WalletGrpc.WalletBlockingStub blockingStubFull) { - byte[] address; - if (ecKey == null) { - String pubKey = loadPubKey(); //04 PubKey[128] - if (StringUtils.isEmpty(pubKey)) { - logger.warn("Warning: QueryAccount failed, no wallet address !!"); - return null; - } - byte[] pubKeyAsc = pubKey.getBytes(); - byte[] pubKeyHex = Hex.decode(pubKeyAsc); - ecKey = ECKey.fromPublicOnly(pubKeyHex); - } - return grpcQueryAccount(ecKey.getAddress(), blockingStubFull); - } - - public static String loadPubKey() { - char[] buf = new char[0x100]; - return String.valueOf(buf, 32, 130); - } - - public byte[] getAddress(ECKey ecKey) { - return ecKey.getAddress(); - } - - public Account grpcQueryAccount(byte[] address, WalletGrpc.WalletBlockingStub blockingStubFull) { - ByteString addressBS = ByteString.copyFrom(address); - Account request = Account.newBuilder().setAddress(addressBS).build(); - return blockingStubFull.getAccount(request); - } - - public Block getBlock(long blockNum, WalletGrpc.WalletBlockingStub blockingStubFull) { - NumberMessage.Builder builder = NumberMessage.newBuilder(); - builder.setNum(blockNum); - return blockingStubFull.getBlockByNum(builder.build()); - - } - - private Transaction signTransaction(ECKey ecKey, Transaction transaction) { - if (ecKey == null || ecKey.getPrivKey() == null) { - logger.warn("Warning: Can't sign,there is no private key !!"); - return null; - } - transaction = TransactionUtils.setTimestamp(transaction); - return TransactionUtils.sign(transaction, ecKey); - } -} - - -*/ diff --git a/src/test/java/stest/tron/wallet/wallettestp0/WallettestP0002.java b/src/test/java/stest/tron/wallet/wallettestp0/WallettestP0002.java index 6c176a58866..d2a1d7058a6 100644 --- a/src/test/java/stest/tron/wallet/wallettestp0/WallettestP0002.java +++ b/src/test/java/stest/tron/wallet/wallettestp0/WallettestP0002.java @@ -100,11 +100,11 @@ public void testAssetIssue() { } } - @Test(enabled = true) + /* @Test(enabled = true) public void testGetAssetIssueByName() { Contract.AssetIssueContract ret = walletClient.getAssetIssueByName(name); Assert.assertTrue(ret.getOwnerAddress() != null); - } + }*/ @Test(enabled = true) public void testTransferAsset() { @@ -120,13 +120,13 @@ public void testTransferAsset() { } - @Test(enabled = true) + /* @Test(enabled = true) public void testGetAssetIssueByAccount() { Optional result = walletClient.getAssetIssueByAccount(FROM_ADDRESS); logger.info("client " + Integer.toString(result.get().getAssetIssueCount())); //logger.info(Integer.toString(result.get().getAssetIssue(0).getNum())); Assert.assertTrue(result.get().getAssetIssueCount() == 1); - } + }*/ @Test(enabled = true) public void testGetAssetIssueList() { @@ -136,7 +136,7 @@ public void testGetAssetIssueList() { Assert.assertTrue(result.get().getAssetIssueCount() > 0); } - @Test(enabled = false) + /* @Test(enabled = false) public void testGetAssetIssueByTimestamp() { long now = System.currentTimeMillis(); Optional result = walletClient.getAssetIssueListByTimestamp(now); @@ -150,7 +150,7 @@ public void testGetAssetIssueByTimestamp() { } Assert.assertTrue(foundThisName); logger.info("This is TestGetAssetIssueByTimestamp."); - } + }*/ @Test(enabled = true) public void testParticipateAssetIssue() { diff --git a/src/test/java/stest/tron/wallet/witness/WalletTestWitness001.java b/src/test/java/stest/tron/wallet/witness/WalletTestWitness001.java index 54b923b9a85..7faf6206733 100644 --- a/src/test/java/stest/tron/wallet/witness/WalletTestWitness001.java +++ b/src/test/java/stest/tron/wallet/witness/WalletTestWitness001.java @@ -13,6 +13,7 @@ import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import org.tron.api.GrpcAPI; import org.tron.api.GrpcAPI.NumberMessage; import org.tron.api.GrpcAPI.Return; import org.tron.api.WalletGrpc; @@ -211,6 +212,7 @@ public Boolean freezeBalance(byte[] addRess, long freezeBalance, long freezeDura } ECKey ecKey = temKey; Account beforeFronzen = queryAccount(ecKey, blockingStubFull); + Long beforeFrozenBalance = 0L; //Long beforeBandwidth = beforeFronzen.getBandwidth(); if (beforeFronzen.getFrozenCount() != 0) { @@ -241,10 +243,24 @@ public Boolean freezeBalance(byte[] addRess, long freezeBalance, long freezeDura return false; } - try { - Thread.sleep(20000); - } catch (InterruptedException e) { - e.printStackTrace(); + Block currentBlock = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); + Block searchCurrentBlock = searchBlockingStubFull.getNowBlock(GrpcAPI + .EmptyMessage.newBuilder().build()); + Integer wait = 0; + while (searchCurrentBlock.getBlockHeader().getRawData().getNumber() + < currentBlock.getBlockHeader().getRawData().getNumber() && wait < 30) { + try { + Thread.sleep(3000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + logger.info("Another fullnode didn't syn the first fullnode data"); + searchCurrentBlock = searchBlockingStubFull.getNowBlock(GrpcAPI + .EmptyMessage.newBuilder().build()); + wait++; + if (wait == 9) { + logger.info("Didn't syn,skip to next case."); + } } Account afterFronzen = queryAccount(ecKey, searchBlockingStubFull);