|
1 | 1 | package stest.tron.wallet.account;
|
2 | 2 |
|
| 3 | +import com.google.protobuf.ByteString; |
3 | 4 | import io.grpc.ManagedChannel;
|
4 | 5 | import io.grpc.ManagedChannelBuilder;
|
5 | 6 | import java.util.concurrent.TimeUnit;
|
|
9 | 10 | import org.testng.annotations.BeforeClass;
|
10 | 11 | import org.testng.annotations.BeforeSuite;
|
11 | 12 | import org.testng.annotations.Test;
|
12 |
| -import org.tron.api.GrpcAPI.AccountResourceMessage; |
| 13 | +import org.tron.api.GrpcAPI.BytesMessage; |
| 14 | +import org.tron.api.GrpcAPI.EasyTransferByPrivateMessage; |
| 15 | +import org.tron.api.GrpcAPI.EasyTransferMessage; |
13 | 16 | import org.tron.api.GrpcAPI.EmptyMessage;
|
14 | 17 | import org.tron.api.WalletGrpc;
|
15 | 18 | import org.tron.api.WalletSolidityGrpc;
|
16 | 19 | import org.tron.common.crypto.ECKey;
|
17 | 20 | import org.tron.common.utils.ByteArray;
|
18 | 21 | import org.tron.common.utils.Utils;
|
19 | 22 | import org.tron.core.Wallet;
|
| 23 | +import org.tron.protos.Contract; |
| 24 | +import org.tron.protos.Protocol; |
20 | 25 | import org.tron.protos.Protocol.Account;
|
| 26 | +import org.tron.protos.Protocol.TransactionSign; |
21 | 27 | import stest.tron.wallet.common.client.Configuration;
|
22 | 28 | import stest.tron.wallet.common.client.Parameter.CommonConstant;
|
23 | 29 | import stest.tron.wallet.common.client.utils.PublicMethed;
|
@@ -71,6 +77,64 @@ public void testgenerateAddress() {
|
71 | 77 | blockingStubSolidity.generateAddress(builder.build());
|
72 | 78 | }
|
73 | 79 |
|
| 80 | + @Test(enabled = true) |
| 81 | + public void testeasyTransfer() { |
| 82 | + ecKey1 = new ECKey(Utils.getRandom()); |
| 83 | + account011Address = ecKey1.getAddress(); |
| 84 | + account011Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); |
| 85 | + PublicMethed.printAddress(testKey002); |
| 86 | + PublicMethed.printAddress(account011Key); |
| 87 | + Assert.assertTrue(PublicMethed.sendcoin(account011Address,10000000L,fromAddress, |
| 88 | + testKey002,blockingStubFull)); |
| 89 | + |
| 90 | + |
| 91 | + String password = Long.toString(System.currentTimeMillis()); |
| 92 | + BytesMessage.Builder builder = BytesMessage.newBuilder(); |
| 93 | + builder.setValue(ByteString.copyFrom(password.getBytes())); |
| 94 | + BytesMessage result = blockingStubFull.createAddress(builder.build()); |
| 95 | + byte[] address = result.getValue().toByteArray(); |
| 96 | + |
| 97 | + Account fromAccount = PublicMethed.queryAccount(account011Key,blockingStubFull); |
| 98 | + final long beforeFromBaslance = fromAccount.getBalance(); |
| 99 | + |
| 100 | + EasyTransferByPrivateMessage.Builder builder1 = EasyTransferByPrivateMessage.newBuilder(); |
| 101 | + builder1.setPrivateKey(ByteString.copyFrom(ByteArray.fromHexString(account011Key))); |
| 102 | + builder1.setToAddress(ByteString.copyFrom(address)); |
| 103 | + builder1.setAmount(2000000L); |
| 104 | + Assert.assertTrue(blockingStubFull.easyTransferByPrivate(builder1.build()) |
| 105 | + .getResult().getCodeValue() == 0); |
| 106 | + |
| 107 | + fromAccount = PublicMethed.queryAccount(account011Key,blockingStubFull); |
| 108 | + final long afterFromBaslance = fromAccount.getBalance(); |
| 109 | + logger.info("beforeFromBaslance is " + beforeFromBaslance); |
| 110 | + logger.info("afterFromBaslance is " + afterFromBaslance); |
| 111 | + logger.info("min is " + (beforeFromBaslance - afterFromBaslance)); |
| 112 | + Assert.assertTrue(beforeFromBaslance - afterFromBaslance == 2000000L + 100000); |
| 113 | + |
| 114 | + |
| 115 | + EasyTransferMessage.Builder builder2 = EasyTransferMessage.newBuilder(); |
| 116 | + builder2.setPassPhrase(ByteString.copyFrom(password.getBytes())); |
| 117 | + builder2.setToAddress(ByteString.copyFrom(account011Address)); |
| 118 | + builder2.setAmount(100); |
| 119 | + Assert.assertTrue(blockingStubFull.easyTransfer(builder2.build()).getResult() |
| 120 | + .getCodeValue() == 0); |
| 121 | + |
| 122 | + Contract.TransferContract.Builder builder5 = Contract.TransferContract.newBuilder(); |
| 123 | + ByteString bsTo = ByteString.copyFrom(address); |
| 124 | + ByteString bsOwner = ByteString.copyFrom(account011Address); |
| 125 | + builder5.setToAddress(bsTo); |
| 126 | + builder5.setOwnerAddress(bsOwner); |
| 127 | + builder5.setAmount(100L); |
| 128 | + |
| 129 | + Contract.TransferContract contract = builder5.build(); |
| 130 | + Protocol.Transaction transaction = blockingStubFull.createTransaction(contract); |
| 131 | + |
| 132 | + TransactionSign.Builder builder4 = TransactionSign.newBuilder(); |
| 133 | + builder4.setPrivateKey(ByteString.copyFrom(ByteArray.fromHexString(account011Key))); |
| 134 | + builder4.setTransaction(transaction); |
| 135 | + blockingStubFull.getTransactionSign(builder4.build()); |
| 136 | + blockingStubFull.getTransactionSign2(builder4.build()); |
| 137 | + } |
74 | 138 |
|
75 | 139 | @AfterClass(enabled = true)
|
76 | 140 | public void shutdown() throws InterruptedException {
|
|
0 commit comments