Skip to content

Commit 7ddd2d6

Browse files
authored
Merge pull request #1844 from tronprotocol/stest_Case_merge_to_master
Stest case merge to master
2 parents 6ec04a1 + d782cb9 commit 7ddd2d6

File tree

11 files changed

+1022
-77
lines changed

11 files changed

+1022
-77
lines changed

src/test/java/stest/tron/wallet/account/WalletTestAccount006.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ public void beforeClass() {
7070

7171
@Test(enabled = true)
7272
public void testGetAccountNet() {
73+
ecKey = new ECKey(Utils.getRandom());
74+
account006Address = ecKey.getAddress();
75+
account006Key = ByteArray.toHexString(ecKey.getPrivKeyBytes());
7376
//Sendcoin to this account
7477
ByteString addressBS1 = ByteString.copyFrom(account006Address);
7578
Account request1 = Account.newBuilder().setAddress(addressBS1).build();

src/test/java/stest/tron/wallet/account/WalletTestAccount011.java

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package stest.tron.wallet.account;
22

3+
import com.google.protobuf.ByteString;
34
import io.grpc.ManagedChannel;
45
import io.grpc.ManagedChannelBuilder;
56
import java.util.concurrent.TimeUnit;
@@ -9,15 +10,20 @@
910
import org.testng.annotations.BeforeClass;
1011
import org.testng.annotations.BeforeSuite;
1112
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;
1316
import org.tron.api.GrpcAPI.EmptyMessage;
1417
import org.tron.api.WalletGrpc;
1518
import org.tron.api.WalletSolidityGrpc;
1619
import org.tron.common.crypto.ECKey;
1720
import org.tron.common.utils.ByteArray;
1821
import org.tron.common.utils.Utils;
1922
import org.tron.core.Wallet;
23+
import org.tron.protos.Contract;
24+
import org.tron.protos.Protocol;
2025
import org.tron.protos.Protocol.Account;
26+
import org.tron.protos.Protocol.TransactionSign;
2127
import stest.tron.wallet.common.client.Configuration;
2228
import stest.tron.wallet.common.client.Parameter.CommonConstant;
2329
import stest.tron.wallet.common.client.utils.PublicMethed;
@@ -71,6 +77,64 @@ public void testgenerateAddress() {
7177
blockingStubSolidity.generateAddress(builder.build());
7278
}
7379

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+
}
74138

75139
@AfterClass(enabled = true)
76140
public void shutdown() throws InterruptedException {

0 commit comments

Comments
 (0)