From 2ba20c354a28001ff21911f8b96d22933b3905df Mon Sep 17 00:00:00 2001 From: taihaofu Date: Mon, 28 May 2018 17:29:12 +0800 Subject: [PATCH 1/6] add wallet extension service --- api/api.proto | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/api/api.proto b/api/api.proto index 56245fb5ec6..b7a41188def 100644 --- a/api/api.proto +++ b/api/api.proto @@ -387,57 +387,60 @@ service WalletSolidity { } }; } +}; + +service WalletExtension { rpc GetTransactionsByTimestamp (TimePaginatedMessage) returns (TransactionList) { option (google.api.http) = { - post: "/walletsolidity/gettransactionsbytimestamp" + post: "/walletextension/gettransactionsbytimestamp" body: "*" additional_bindings { - get: "/walletsolidity/gettransactionsbytimestamp" + get: "/walletextension/gettransactionsbytimestamp" } }; } rpc GetTransactionsByTimestampCount (TimeMessage) returns (NumberMessage) { option (google.api.http) = { - post: "/walletsolidity/gettransactionsbytimestampcount" + post: "/walletextension/gettransactionsbytimestampcount" body: "*" additional_bindings { - get: "/walletsolidity/gettransactionsbytimestampcount" + get: "/walletextension/gettransactionsbytimestampcount" } }; } rpc GetTransactionsFromThis (AccountPaginated) returns (TransactionList) { option (google.api.http) = { - post: "/walletsolidity/gettransactionsfromthis" + post: "/walletextension/gettransactionsfromthis" body: "*" additional_bindings { - get: "/walletsolidity/gettransactionsfromthis" + get: "/walletextension/gettransactionsfromthis" } }; } rpc GetTransactionsToThis (AccountPaginated) returns (TransactionList) { option (google.api.http) = { - post: "/walletsolidity/gettransactionstothis" + post: "/walletextension/gettransactionstothis" body: "*" additional_bindings { - get: "/walletsolidity/gettransactionstothis" + get: "/walletextension/gettransactionstothis" } }; } rpc GetTransactionsFromThisCount (Account) returns (NumberMessage) { option (google.api.http) = { - post: "/walletsolidity/gettransactionsfromthiscount" + post: "/walletextension/gettransactionsfromthiscount" body: "*" additional_bindings { - get: "/walletsolidity/gettransactionsfromthiscount" + get: "/walletextension/gettransactionsfromthiscount" } }; } rpc GetTransactionsToThisCount (Account) returns (NumberMessage) { option (google.api.http) = { - post: "/walletsolidity/gettransactionstothiscount" + post: "/walletextension/gettransactionstothiscount" body: "*" additional_bindings { - get: "/walletsolidity/gettransactionstothiscount" + get: "/walletextension/gettransactionstothiscount" } }; } From da7abebcd6733dbb9787166feed4809baec9034c Mon Sep 17 00:00:00 2001 From: Heng Zhang Date: Thu, 31 May 2018 15:57:12 +0800 Subject: [PATCH 2/6] fix:remove api. --- src/main/protos/api/api.proto | 64 +++---------------- .../assetissue/WalletTestAssetIssue009.java | 54 ++++++++-------- 2 files changed, 34 insertions(+), 84 deletions(-) diff --git a/src/main/protos/api/api.proto b/src/main/protos/api/api.proto index d8312ba3789..c0365a97abe 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,25 +351,6 @@ 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 { diff --git a/src/test/java/stest/tron/wallet/assetissue/WalletTestAssetIssue009.java b/src/test/java/stest/tron/wallet/assetissue/WalletTestAssetIssue009.java index a552baf32ca..69f3a447902 100644 --- a/src/test/java/stest/tron/wallet/assetissue/WalletTestAssetIssue009.java +++ b/src/test/java/stest/tron/wallet/assetissue/WalletTestAssetIssue009.java @@ -3,21 +3,17 @@ 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.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; @@ -80,33 +76,33 @@ public void beforeClass() { @Test(enabled = true) public void testGetAssetIssueByAccountOrNameFromSolidity() { //By name - ByteString addressBs = ByteString.copyFrom(FROM_ADDRESS); - Account request = Account.newBuilder().setAddress(addressBs).build(); - GrpcAPI.AssetIssueList assetIssueList = blockingStubSolidity - .getAssetIssueByAccount(request); - Optional queryAssetIssueByAccount = Optional.ofNullable(assetIssueList); - logger.info(Integer.toString(queryAssetIssueByAccount.get().getAssetIssueCount())); - Assert.assertTrue(queryAssetIssueByAccount.get().getAssetIssueCount() >= 1); - for (Integer j = 0; j < queryAssetIssueByAccount.get().getAssetIssueCount(); j++) { - Assert.assertTrue(queryAssetIssueByAccount.get().getAssetIssue(j).getTotalSupply() > 0); - Assert.assertFalse(queryAssetIssueByAccount.get().getAssetIssue(j).getName().isEmpty()); - logger.info("TestGetAssetIssueByAccount in soliditynode ok!!!"); - - } +// ByteString addressBs = ByteString.copyFrom(FROM_ADDRESS); +// Account request = Account.newBuilder().setAddress(addressBs).build(); +// GrpcAPI.AssetIssueList assetIssueList = blockingStubSolidity +// .getAssetIssueByAccount(request); +// Optional queryAssetIssueByAccount = Optional.ofNullable(assetIssueList); +// logger.info(Integer.toString(queryAssetIssueByAccount.get().getAssetIssueCount())); +// Assert.assertTrue(queryAssetIssueByAccount.get().getAssetIssueCount() >= 1); +// for (Integer j = 0; j < queryAssetIssueByAccount.get().getAssetIssueCount(); j++) { +// Assert.assertTrue(queryAssetIssueByAccount.get().getAssetIssue(j).getTotalSupply() > 0); +// Assert.assertFalse(queryAssetIssueByAccount.get().getAssetIssue(j).getName().isEmpty()); +// logger.info("TestGetAssetIssueByAccount in soliditynode ok!!!"); +// +// } //By ID - ByteString assetName = queryAssetIssueByAccount.get().getAssetIssue(0).getName(); - GrpcAPI.BytesMessage requestAsset = GrpcAPI.BytesMessage.newBuilder().setValue(assetName) - .build(); - Contract.AssetIssueContract assetIssueByName = blockingStubSolidity - .getAssetIssueByName(requestAsset); - - Assert.assertFalse(assetIssueByName.getUrl().isEmpty()); - Assert.assertFalse(assetIssueByName.getDescription().isEmpty()); - Assert.assertTrue(assetIssueByName.getTotalSupply() > 0); - Assert.assertTrue(assetIssueByName.getTrxNum() > 0); - - logger.info("TestGetAssetIssueByNameFromSolidity"); +// ByteString assetName = queryAssetIssueByAccount.get().getAssetIssue(0).getName(); +// GrpcAPI.BytesMessage requestAsset = GrpcAPI.BytesMessage.newBuilder().setValue(assetName) +// .build(); +// Contract.AssetIssueContract assetIssueByName = blockingStubSolidity +// .getAssetIssueByName(requestAsset); +// +// Assert.assertFalse(assetIssueByName.getUrl().isEmpty()); +// Assert.assertFalse(assetIssueByName.getDescription().isEmpty()); +// Assert.assertTrue(assetIssueByName.getTotalSupply() > 0); +// Assert.assertTrue(assetIssueByName.getTrxNum() > 0); +// +// logger.info("TestGetAssetIssueByNameFromSolidity"); } @AfterClass(enabled = true) From 03db7b5ceac214615755e63cca333b3a20980e98 Mon Sep 17 00:00:00 2001 From: wangzihe Date: Thu, 31 May 2018 16:16:44 +0800 Subject: [PATCH 3/6] Delete query api case --- .../wallet/account/WalletTestAccount003.java | 16 +- .../wallet/account/WalletTestAccount004.java | 5 +- .../assetissue/WalletTestAssetIssue006.java | 53 +++- .../assetissue/WalletTestAssetIssue008.java | 46 +++ .../assetissue/WalletTestAssetIssue009.java | 58 ++-- .../assetissue/WalletTestAssetIssue011.java | 4 +- .../tron/wallet/common/client/GrpcClient.java | 20 +- .../wallet/common/client/WalletClient.java | 24 +- .../common/client/utils/PublicMethed.java | 27 ++ .../transfer/WalletTestTransfer001.java | 5 +- .../transfer/WalletTestTransfer002.java | 4 +- .../transfer/WalletTestTransfer003.java | 19 +- .../transfer/WalletTestTransfer004.java | 291 ++++++++++++++++++ .../transfer/WalletTestTransfer005.java | 223 ++++++++++++++ .../transfer/WalletTestTransfer006.java | 223 ++++++++++++++ .../transfer/WalletTest_p1_Transfer_004.java | 208 ------------- .../transfer/WalletTest_p1_Transfer_005.java | 179 ----------- .../transfer/WalletTest_p1_Transfer_006.java | 160 ---------- .../wallet/wallettestp0/WallettestP0002.java | 12 +- .../wallet/witness/WalletTestWitness001.java | 24 +- 20 files changed, 968 insertions(+), 633 deletions(-) create mode 100644 src/test/java/stest/tron/wallet/transfer/WalletTestTransfer004.java create mode 100644 src/test/java/stest/tron/wallet/transfer/WalletTestTransfer005.java create mode 100644 src/test/java/stest/tron/wallet/transfer/WalletTestTransfer006.java delete mode 100644 src/test/java/stest/tron/wallet/transfer/WalletTest_p1_Transfer_004.java delete mode 100644 src/test/java/stest/tron/wallet/transfer/WalletTest_p1_Transfer_005.java delete mode 100644 src/test/java/stest/tron/wallet/transfer/WalletTest_p1_Transfer_006.java 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 69f3a447902..f436dcd2afa 100644 --- a/src/test/java/stest/tron/wallet/assetissue/WalletTestAssetIssue009.java +++ b/src/test/java/stest/tron/wallet/assetissue/WalletTestAssetIssue009.java @@ -3,17 +3,21 @@ 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.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; @@ -73,37 +77,37 @@ public void beforeClass() { } - @Test(enabled = true) + /* @Test(enabled = true) public void testGetAssetIssueByAccountOrNameFromSolidity() { //By name -// ByteString addressBs = ByteString.copyFrom(FROM_ADDRESS); -// Account request = Account.newBuilder().setAddress(addressBs).build(); -// GrpcAPI.AssetIssueList assetIssueList = blockingStubSolidity -// .getAssetIssueByAccount(request); -// Optional queryAssetIssueByAccount = Optional.ofNullable(assetIssueList); -// logger.info(Integer.toString(queryAssetIssueByAccount.get().getAssetIssueCount())); -// Assert.assertTrue(queryAssetIssueByAccount.get().getAssetIssueCount() >= 1); -// for (Integer j = 0; j < queryAssetIssueByAccount.get().getAssetIssueCount(); j++) { -// Assert.assertTrue(queryAssetIssueByAccount.get().getAssetIssue(j).getTotalSupply() > 0); -// Assert.assertFalse(queryAssetIssueByAccount.get().getAssetIssue(j).getName().isEmpty()); -// logger.info("TestGetAssetIssueByAccount in soliditynode ok!!!"); -// -// } + ByteString addressBs = ByteString.copyFrom(FROM_ADDRESS); + Account request = Account.newBuilder().setAddress(addressBs).build(); + GrpcAPI.AssetIssueList assetIssueList = blockingStubSolidity + .getAssetIssueByAccount(request); + Optional queryAssetIssueByAccount = Optional.ofNullable(assetIssueList); + logger.info(Integer.toString(queryAssetIssueByAccount.get().getAssetIssueCount())); + Assert.assertTrue(queryAssetIssueByAccount.get().getAssetIssueCount() >= 1); + for (Integer j = 0; j < queryAssetIssueByAccount.get().getAssetIssueCount(); j++) { + Assert.assertTrue(queryAssetIssueByAccount.get().getAssetIssue(j).getTotalSupply() > 0); + Assert.assertFalse(queryAssetIssueByAccount.get().getAssetIssue(j).getName().isEmpty()); + logger.info("TestGetAssetIssueByAccount in soliditynode ok!!!"); + + } //By ID -// ByteString assetName = queryAssetIssueByAccount.get().getAssetIssue(0).getName(); -// GrpcAPI.BytesMessage requestAsset = GrpcAPI.BytesMessage.newBuilder().setValue(assetName) -// .build(); -// Contract.AssetIssueContract assetIssueByName = blockingStubSolidity -// .getAssetIssueByName(requestAsset); -// -// Assert.assertFalse(assetIssueByName.getUrl().isEmpty()); -// Assert.assertFalse(assetIssueByName.getDescription().isEmpty()); -// Assert.assertTrue(assetIssueByName.getTotalSupply() > 0); -// Assert.assertTrue(assetIssueByName.getTrxNum() > 0); -// -// logger.info("TestGetAssetIssueByNameFromSolidity"); - } + ByteString assetName = queryAssetIssueByAccount.get().getAssetIssue(0).getName(); + GrpcAPI.BytesMessage requestAsset = GrpcAPI.BytesMessage.newBuilder().setValue(assetName) + .build(); + Contract.AssetIssueContract assetIssueByName = blockingStubSolidity + .getAssetIssueByName(requestAsset); + + Assert.assertFalse(assetIssueByName.getUrl().isEmpty()); + Assert.assertFalse(assetIssueByName.getDescription().isEmpty()); + Assert.assertTrue(assetIssueByName.getTotalSupply() > 0); + 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..8a4ec24e1b7 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,22 +194,22 @@ 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) { TimeMessage.Builder timeMessage = TimeMessage.newBuilder(); @@ -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..20f5576d0b0 100644 --- a/src/test/java/stest/tron/wallet/common/client/WalletClient.java +++ b/src/test/java/stest/tron/wallet/common/client/WalletClient.java @@ -711,9 +711,9 @@ 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) { return rpcCli.getTransactionsByTimestamp(start, end, offset, limit); @@ -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..2329bb305b1 --- /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); From abbe0cef16d6df8569f1ed9d3c16e01ef8286c95 Mon Sep 17 00:00:00 2001 From: Heng Zhang Date: Thu, 31 May 2018 16:27:41 +0800 Subject: [PATCH 4/6] feat: remove api. --- api/api.proto | 87 ++------------------------------------------------- 1 file changed, 3 insertions(+), 84 deletions(-) diff --git a/api/api.proto b/api/api.proto index cc5a153516c..3446a76c9bf 100644 --- a/api/api.proto +++ b/api/api.proto @@ -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 From 9a51f18bb8abb830164b665f67e5d3a12abfeb51 Mon Sep 17 00:00:00 2001 From: Heng Zhang Date: Thu, 31 May 2018 16:37:03 +0800 Subject: [PATCH 5/6] fix:remove api. --- .../java/org/tron/core/WalletSolidity.java | 17 - .../java/org/tron/core/db/api/StoreAPI.java | 18 +- .../org/tron/core/services/RpcApiService.java | 4 +- src/main/protos/api/api.proto | 527 ------------------ 4 files changed, 10 insertions(+), 556 deletions(-) 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 c0365a97abe..d3f5a12faa9 100644 --- a/src/main/protos/api/api.proto +++ b/src/main/protos/api/api.proto @@ -1,528 +1 @@ -syntax = "proto3"; -package protocol; -import "core/Tron.proto"; -import "core/Contract.proto"; -import "google/api/annotations.proto"; - - -option java_package = "org.tron.api"; //Specify the name of the package that generated the Java file -option java_outer_classname = "GrpcAPI"; //Specify the class name of the generated Java file -option go_package = "github.com/tronprotocol/grpc-gateway/api"; - -service Wallet { - - rpc GetAccount (Account) returns (Account) { - option (google.api.http) = { - post: "/wallet/getaccount" - body: "*" - additional_bindings { - get: "/wallet/getaccount" - } - }; - }; - - rpc CreateTransaction (TransferContract) returns (Transaction) { - option (google.api.http) = { - post: "/wallet/createtransaction" - body: "*" - additional_bindings { - get: "/wallet/createtransaction" - } - }; - }; - - rpc BroadcastTransaction (Transaction) returns (Return) { - option (google.api.http) = { - post: "/wallet/broadcasttransaction" - body: "*" - additional_bindings { - get: "/wallet/broadcasttransaction" - } - }; - }; - - rpc UpdateAccount (AccountUpdateContract) returns (Transaction) { - option (google.api.http) = { - post: "/wallet/updateaccount" - body: "*" - additional_bindings { - get: "/wallet/updateaccount" - } - }; - }; - - rpc VoteWitnessAccount (VoteWitnessContract) returns (Transaction) { - option (google.api.http) = { - post: "/wallet/votewitnessaccount" - body: "*" - additional_bindings { - get: "/wallet/votewitnessaccount" - } - }; - }; - - rpc CreateAssetIssue (AssetIssueContract) returns (Transaction) { - option (google.api.http) = { - post: "/wallet/createassetissue" - body: "*" - additional_bindings { - get: "/wallet/createassetissue" - } - }; - }; - - rpc UpdateWitness (WitnessUpdateContract) returns (Transaction) { - option (google.api.http) = { - post: "/wallet/updatewitness" - body: "*" - additional_bindings { - get: "/wallet/updatewitness" - } - }; - }; - - rpc CreateAccount (AccountCreateContract) returns (Transaction) { - option (google.api.http) = { - post: "/wallet/createaccount" - body: "*" - additional_bindings { - get: "/wallet/createaccount" - } - }; - }; - - rpc CreateWitness (WitnessCreateContract) returns (Transaction) { - option (google.api.http) = { - post: "/wallet/createwitness" - body: "*" - additional_bindings { - get: "/wallet/createwitness" - } - }; - }; - - rpc TransferAsset (TransferAssetContract) returns (Transaction) { - option (google.api.http) = { - post: "/wallet/transferasset" - body: "*" - additional_bindings { - get: "/wallet/transferasset" - } - }; - } - - rpc ParticipateAssetIssue (ParticipateAssetIssueContract) returns (Transaction) { - option (google.api.http) = { - post: "/wallet/participateassetissue" - body: "*" - additional_bindings { - get: "/wallet/participateassetissue" - } - }; - } - - rpc FreezeBalance (FreezeBalanceContract) returns (Transaction) { - option (google.api.http) = { - post: "/wallet/freezebalance" - body: "*" - additional_bindings { - get: "/wallet/freezebalance" - } - }; - } - - rpc UnfreezeBalance (UnfreezeBalanceContract) returns (Transaction) { - option (google.api.http) = { - post: "/wallet/unfreezebalance" - body: "*" - additional_bindings { - get: "/wallet/unfreezebalance" - } - }; - } - - rpc UnfreezeAsset (UnfreezeAssetContract) returns (Transaction) { - option (google.api.http) = { - post: "/wallet/unfreezeasset" - body: "*" - additional_bindings { - get: "/wallet/unfreezeasset" - } - }; - } - - rpc WithdrawBalance (WithdrawBalanceContract) returns (Transaction) { - option (google.api.http) = { - post: "/wallet/withdrawbalance" - body: "*" - additional_bindings { - get: "/wallet/withdrawbalance" - } - }; - } - - rpc UpdateAsset (UpdateAssetContract) returns (Transaction) { - option (google.api.http) = { - post: "/wallet/updateasset" - body: "*" - additional_bindings { - get: "/wallet/updateasset" - } - }; - } - - rpc ListNodes (EmptyMessage) returns (NodeList) { - option (google.api.http) = { - post: "/wallet/listnodes" - body: "*" - additional_bindings { - get: "/wallet/listnodes" - } - }; - } - - rpc GetAssetIssueByAccount (Account) returns (AssetIssueList) { - option (google.api.http) = { - post: "/wallet/getassetissuebyaccount" - body: "*" - additional_bindings { - get: "/wallet/getassetissuebyaccount" - } - }; - } - rpc GetAccountNet (Account) returns (AccountNetMessage) { - 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" - body: "*" - additional_bindings { - get: "/wallet/getassetissuebyname" - } - }; - } - rpc GetNowBlock (EmptyMessage) returns (Block) { - option (google.api.http) = { - post: "/wallet/getnowblock" - body: "*" - additional_bindings { - get: "/wallet/getnowblock" - } - }; - } - rpc GetBlockByNum (NumberMessage) returns (Block) { - option (google.api.http) = { - post: "/wallet/getblockbynum" - body: "*" - additional_bindings { - get: "/wallet/getblockbynum" - } - }; - } - - rpc GetBlockById (BytesMessage) returns (Block) { - option (google.api.http) = { - post: "/wallet/getblockbyid" - body: "*" - additional_bindings { - get: "/wallet/getblockbyid" - } - }; - } - rpc GetBlockByLimitNext (BlockLimit) returns (BlockList) { - option (google.api.http) = { - post: "/wallet/getblockbylimitnext" - body: "*" - additional_bindings { - get: "/wallet/getblockbylimitnext" - } - }; - } - rpc GetBlockByLatestNum (NumberMessage) returns (BlockList) { - option (google.api.http) = { - post: "/wallet/getblockbylatestnum" - body: "*" - additional_bindings { - get: "/wallet/getblockbylatestnum" - } - }; - } - rpc GetTransactionById (BytesMessage) returns (Transaction) { - option (google.api.http) = { - post: "/wallet/gettransactionbyid" - body: "*" - additional_bindings { - get: "/wallet/gettransactionbyid" - } - }; - } - - rpc ListWitnesses (EmptyMessage) returns (WitnessList) { - option (google.api.http) = { - post: "/wallet/listwitnesses" - body: "*" - additional_bindings { - get: "/wallet/listwitnesses" - } - }; - }; - rpc GetAssetIssueList (EmptyMessage) returns (AssetIssueList) { - option (google.api.http) = { - post: "/wallet/getassetissuelist" - body: "*" - additional_bindings { - get: "/wallet/getassetissuelist" - } - }; - } - rpc TotalTransaction (EmptyMessage) returns (NumberMessage) { - option (google.api.http) = { - post: "/wallet/totaltransaction" - body: "*" - additional_bindings { - get: "/wallet/totaltransaction" - } - }; - } - rpc GetNextMaintenanceTime (EmptyMessage) returns (NumberMessage) { - option (google.api.http) = { - post: "/wallet/getnextmaintenancetime" - body: "*" - additional_bindings { - get: "/wallet/getnextmaintenancetime" - } - }; - } -}; - - -service WalletSolidity { - - rpc GetAccount (Account) returns (Account) { - option (google.api.http) = { - post: "/walletsolidity/getaccount" - body: "*" - additional_bindings { - get: "/walletsolidity/getaccount" - } - }; - }; - rpc ListWitnesses (EmptyMessage) returns (WitnessList) { - option (google.api.http) = { - post: "/walletsolidity/listwitnesses" - body: "*" - additional_bindings { - get: "/walletsolidity/listwitnesses" - } - }; - }; - rpc GetAssetIssueList (EmptyMessage) returns (AssetIssueList) { - option (google.api.http) = { - post: "/walletsolidity/getassetissuelist" - body: "*" - additional_bindings { - get: "/walletsolidity/getassetissuelist" - } - }; - } - rpc GetNowBlock (EmptyMessage) returns (Block) { - option (google.api.http) = { - post: "/walletsolidity/getnowblock" - body: "*" - additional_bindings { - get: "/walletsolidity/getnowblock" - } - }; - } - rpc GetBlockByNum (NumberMessage) returns (Block) { - option (google.api.http) = { - post: "/walletsolidity/getblockbynum" - body: "*" - additional_bindings { - get: "/walletsolidity/getblockbynum" - } - }; - } -}; - -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" - body: "*" - additional_bindings { - get: "/walletextension/gettransactionsfromthis" - } - }; - } - rpc GetTransactionsToThis (AccountPaginated) returns (TransactionList) { - option (google.api.http) = { - post: "/walletextension/gettransactionstothis" - body: "*" - additional_bindings { - get: "/walletextension/gettransactionstothis" - } - }; - } - 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 -service Database { - // for tapos - rpc getBlockReference (EmptyMessage) returns (BlockReference) { - - } - rpc GetDynamicProperties (EmptyMessage) returns (DynamicProperties) { - - } - rpc GetNowBlock (EmptyMessage) returns (Block) { - - } - rpc GetBlockByNum (NumberMessage) returns (Block) { - - } -}; - -message Return { - enum response_code { - SUCCESS = 0; - SIGERROR = 1; // error in signature - CONTRACT_VALIDATE_ERROR = 2; - CONTRACT_EXE_ERROR = 3; - BANDWITH_ERROR = 4; - DUP_TRANSACTION_ERROR = 5; - TAPOS_ERROR = 6; - TOO_BIG_TRANSACTION_ERROR = 7; - TRANSACTION_EXPIRATION_ERROR = 8; - SERVER_BUSY = 9; - OTHER_ERROR = 20; - } - - bool result = 1; - response_code code = 2; - bytes message = 3; -} - -message BlockReference { - int64 block_num = 1; - bytes block_hash = 2; -} - -// the api of tron's network such as node list. -service Network { - -}; - -message WitnessList { - repeated Witness witnesses = 1; -} -message AssetIssueList { - repeated AssetIssueContract assetIssue = 1; -} -message BlockList { - repeated Block block = 1; -} -message TransactionList { - repeated Transaction transaction = 1; -} - -// Gossip node list -message NodeList { - repeated Node nodes = 1; -} - -// Gossip node -message Node { - Address address = 1; -} - -// Gossip node address -message Address { - bytes host = 1; - int32 port = 2; -} - -message EmptyMessage { -} -message NumberMessage { - int64 num = 1; -} -message BytesMessage { - bytes value = 1; -} -message TimeMessage { - int64 beginInMilliseconds = 1; - int64 endInMilliseconds = 2; -} -message BlockLimit { - int64 startNum = 1; - int64 endNum = 2; -} -message TransactionLimit { - bytes transactionId = 1; - int64 limitNum = 2; -} -message AccountPaginated { - Account account = 1; - int64 offset = 2; - int64 limit = 3; -} -message TimePaginatedMessage { - TimeMessage timeMessage = 1; - int64 offset = 2; - int64 limit = 3; -} -message AccountNetMessage { - int64 freeNetUsed = 1; - int64 freeNetLimit = 2; - int64 NetUsed = 3; - int64 NetLimit = 4; - map assetNetUsed = 5; - map assetNetLimit = 6; - int64 TotalNetLimit = 7; - int64 TotalNetWeight = 8; -} From d1023fc42b0d334b1acd843e6fca7b0e282515df Mon Sep 17 00:00:00 2001 From: wangzihe Date: Thu, 31 May 2018 16:53:07 +0800 Subject: [PATCH 6/6] Delete query by timestmpe api case --- src/test/java/stest/tron/wallet/common/client/GrpcClient.java | 4 ++-- .../java/stest/tron/wallet/common/client/WalletClient.java | 4 ++-- .../stest/tron/wallet/transfer/WalletTestTransfer004.java | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) 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 8a4ec24e1b7..c9a4c2c61fd 100644 --- a/src/test/java/stest/tron/wallet/common/client/GrpcClient.java +++ b/src/test/java/stest/tron/wallet/common/client/GrpcClient.java @@ -211,7 +211,7 @@ public Optional listNodes() { 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); 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 20f5576d0b0..e0ea31d20f2 100644 --- a/src/test/java/stest/tron/wallet/common/client/WalletClient.java +++ b/src/test/java/stest/tron/wallet/common/client/WalletClient.java @@ -715,9 +715,9 @@ public static Optional listWitnesses() { 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(); diff --git a/src/test/java/stest/tron/wallet/transfer/WalletTestTransfer004.java b/src/test/java/stest/tron/wallet/transfer/WalletTestTransfer004.java index 2329bb305b1..a8a490e6ef0 100644 --- a/src/test/java/stest/tron/wallet/transfer/WalletTestTransfer004.java +++ b/src/test/java/stest/tron/wallet/transfer/WalletTestTransfer004.java @@ -83,7 +83,7 @@ public void beforeClass() { blockingStubExtension = WalletExtensionGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = true) + /* @Test(enabled = true) public void testGetTransactionsByTimestamp() { long start = now - 16400000; long end = now; @@ -230,7 +230,7 @@ public void testExceptionTimeToGetGetTransactionsByTimestamp() { Assert.assertTrue(gettransactionbytimestamp.get().getTransactionCount() == 0); - } + }*/ @AfterClass public void shutdown() throws InterruptedException {