Skip to content

Commit 4ec74c0

Browse files
committed
improve Daily build
1 parent 29bcf0d commit 4ec74c0

7 files changed

Lines changed: 583 additions & 4 deletions

File tree

‎src/test/java/stest/tron/wallet/contract/trctoken/ContractTrcToken050.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public void beforeClass() {
7878
}
7979

8080

81-
@Test(enabled = true, description = "TransferToken to contract developer tokenID is 0")
81+
@Test(enabled = true, description = "TransferToken to contract address ")
8282
public void deployTransferTokenContract() {
8383

8484
Assert

‎src/test/java/stest/tron/wallet/contract/trctoken/ContractTrcToken051.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public void beforeClass() {
8080
}
8181

8282

83-
@Test(enabled = true, description = "TransferToken to contract address tokenID is 0")
83+
@Test(enabled = true, description = "TransferToken to contract developer tokenID is 0")
8484
public void deployTransferTokenContract() {
8585

8686
Assert

‎src/test/java/stest/tron/wallet/contract/trctoken/ContractTrcToken052.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ public void beforeClass() {
7878
}
7979

8080

81-
@Test(enabled = true)
82-
public void continueRun() {
81+
@Test(enabled = true, description = "TransferToken to contract address tokenID is 0")
82+
public void deployTransferTokenContract() {
8383

8484
Assert
8585
.assertTrue(PublicMethed.sendcoin(dev001Address, 2048000000, fromAddress,
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
package stest.tron.wallet.contract.trctoken;
2+
3+
import io.grpc.ManagedChannel;
4+
import io.grpc.ManagedChannelBuilder;
5+
import java.util.Optional;
6+
import java.util.concurrent.TimeUnit;
7+
import lombok.extern.slf4j.Slf4j;
8+
import org.junit.Assert;
9+
import org.testng.annotations.AfterClass;
10+
import org.testng.annotations.BeforeClass;
11+
import org.testng.annotations.BeforeSuite;
12+
import org.testng.annotations.Test;
13+
import org.tron.api.WalletGrpc;
14+
import org.tron.api.WalletSolidityGrpc;
15+
import org.tron.common.crypto.ECKey;
16+
import org.tron.common.utils.ByteArray;
17+
import org.tron.common.utils.Utils;
18+
import org.tron.core.Wallet;
19+
import org.tron.protos.Protocol.TransactionInfo;
20+
import stest.tron.wallet.common.client.Configuration;
21+
import stest.tron.wallet.common.client.Parameter.CommonConstant;
22+
import stest.tron.wallet.common.client.utils.PublicMethed;
23+
24+
@Slf4j
25+
public class ContractTrcToken076 {
26+
27+
28+
private final String testNetAccountKey = Configuration.getByPath("testng.conf")
29+
.getString("foundationAccount.key1");
30+
private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey);
31+
private Long maxFeeLimit = Configuration.getByPath("testng.conf")
32+
.getLong("defaultParameter.maxFeeLimit");
33+
private ManagedChannel channelSolidity = null;
34+
35+
private ManagedChannel channelFull = null;
36+
private WalletGrpc.WalletBlockingStub blockingStubFull = null;
37+
38+
private ManagedChannel channelFull1 = null;
39+
private WalletGrpc.WalletBlockingStub blockingStubFull1 = null;
40+
41+
42+
private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null;
43+
44+
private String fullnode = Configuration.getByPath("testng.conf")
45+
.getStringList("fullnode.ip.list").get(0);
46+
47+
48+
49+
byte[] contractAddress = null;
50+
51+
ECKey ecKey1 = new ECKey(Utils.getRandom());
52+
byte[] grammarAddress = ecKey1.getAddress();
53+
String testKeyForGrammarAddress = ByteArray.toHexString(ecKey1.getPrivKeyBytes());
54+
55+
56+
@BeforeSuite
57+
public void beforeSuite() {
58+
Wallet wallet = new Wallet();
59+
Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET);
60+
}
61+
62+
/**
63+
* constructor.
64+
*/
65+
66+
@BeforeClass(enabled = true)
67+
public void beforeClass() {
68+
PublicMethed.printAddress(testKeyForGrammarAddress);
69+
channelFull = ManagedChannelBuilder.forTarget(fullnode)
70+
.usePlaintext(true)
71+
.build();
72+
blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
73+
logger.info(Long.toString(PublicMethed.queryAccount(testNetAccountKey, blockingStubFull)
74+
.getBalance()));
75+
}
76+
77+
@Test(enabled = true, description = "Origin test ")
78+
public void testDeployTransferTokenContract() {
79+
PublicMethed
80+
.sendcoin(grammarAddress, 100000000000L, testNetAccountAddress, testNetAccountKey,
81+
blockingStubFull);
82+
PublicMethed.waitProduceNextBlock(blockingStubFull);
83+
PublicMethed.waitProduceNextBlock(blockingStubFull);
84+
85+
String contractName = "originTest";
86+
String code = Configuration.getByPath("testng.conf")
87+
.getString("code.code_ContractTrcToken076_originTest");
88+
String abi = Configuration.getByPath("testng.conf")
89+
.getString("abi.abi_ContractTrcToken076_originTest");
90+
contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit,
91+
0L, 100, null, testKeyForGrammarAddress,
92+
grammarAddress, blockingStubFull);
93+
PublicMethed.waitProduceNextBlock(blockingStubFull);
94+
PublicMethed.waitProduceNextBlock(blockingStubFull);
95+
96+
String txid = "";
97+
txid = PublicMethed.triggerContract(contractAddress,
98+
"getResult1()", "#", false,
99+
0, maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull);
100+
PublicMethed.waitProduceNextBlock(blockingStubFull);
101+
PublicMethed.waitProduceNextBlock(blockingStubFull);
102+
103+
Optional<TransactionInfo> infoById = null;
104+
infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull);
105+
logger.info("infoById:" + infoById);
106+
Long returnnumber = ByteArray.toLong(ByteArray.fromHexString(ByteArray.toHexString(
107+
infoById.get().getContractResult(0).toByteArray())));
108+
109+
Assert.assertTrue(returnnumber == 0);
110+
111+
txid = PublicMethed.triggerContract(contractAddress,
112+
"getResult2()", "#", false,
113+
0, maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull);
114+
PublicMethed.waitProduceNextBlock(blockingStubFull);
115+
PublicMethed.waitProduceNextBlock(blockingStubFull);
116+
117+
infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull);
118+
logger.info("-------------------------");
119+
120+
logger.info("infoById:" + infoById);
121+
Long returnnumber2 = ByteArray.toLong(ByteArray.fromHexString(
122+
ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())));
123+
124+
Assert.assertTrue(returnnumber2 == 0);
125+
}
126+
/**
127+
* constructor.
128+
*/
129+
130+
@AfterClass
131+
public void shutdown() throws InterruptedException {
132+
if (channelFull != null) {
133+
channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS);
134+
}
135+
}
136+
137+
}
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
package stest.tron.wallet.contract.trctoken;
2+
3+
import io.grpc.ManagedChannel;
4+
import io.grpc.ManagedChannelBuilder;
5+
import java.util.Optional;
6+
import java.util.concurrent.TimeUnit;
7+
import lombok.extern.slf4j.Slf4j;
8+
import org.junit.Assert;
9+
import org.testng.annotations.AfterClass;
10+
import org.testng.annotations.BeforeClass;
11+
import org.testng.annotations.BeforeSuite;
12+
import org.testng.annotations.Test;
13+
import org.tron.api.WalletGrpc;
14+
import org.tron.api.WalletSolidityGrpc;
15+
import org.tron.common.crypto.ECKey;
16+
import org.tron.common.utils.ByteArray;
17+
import org.tron.common.utils.Utils;
18+
import org.tron.core.Wallet;
19+
import org.tron.protos.Protocol.TransactionInfo;
20+
import stest.tron.wallet.common.client.Configuration;
21+
import stest.tron.wallet.common.client.Parameter.CommonConstant;
22+
import stest.tron.wallet.common.client.utils.PublicMethed;
23+
24+
@Slf4j
25+
public class ContractTrcToken077 {
26+
27+
28+
private final String testNetAccountKey = Configuration.getByPath("testng.conf")
29+
.getString("foundationAccount.key1");
30+
private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey);
31+
private Long maxFeeLimit = Configuration.getByPath("testng.conf")
32+
.getLong("defaultParameter.maxFeeLimit");
33+
private ManagedChannel channelSolidity = null;
34+
35+
private ManagedChannel channelFull = null;
36+
private WalletGrpc.WalletBlockingStub blockingStubFull = null;
37+
38+
private ManagedChannel channelFull1 = null;
39+
private WalletGrpc.WalletBlockingStub blockingStubFull1 = null;
40+
41+
42+
private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null;
43+
44+
private String fullnode = Configuration.getByPath("testng.conf")
45+
.getStringList("fullnode.ip.list").get(0);
46+
47+
48+
49+
byte[] contractAddress = null;
50+
51+
ECKey ecKey1 = new ECKey(Utils.getRandom());
52+
byte[] grammarAddress = ecKey1.getAddress();
53+
String testKeyForGrammarAddress = ByteArray.toHexString(ecKey1.getPrivKeyBytes());
54+
55+
56+
@BeforeSuite
57+
public void beforeSuite() {
58+
Wallet wallet = new Wallet();
59+
Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET);
60+
}
61+
62+
/**
63+
* constructor.
64+
*/
65+
66+
@BeforeClass(enabled = true)
67+
public void beforeClass() {
68+
PublicMethed.printAddress(testKeyForGrammarAddress);
69+
channelFull = ManagedChannelBuilder.forTarget(fullnode)
70+
.usePlaintext(true)
71+
.build();
72+
blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
73+
logger.info(Long.toString(PublicMethed.queryAccount(testNetAccountKey, blockingStubFull)
74+
.getBalance()));
75+
}
76+
77+
@Test(enabled = false)
78+
public void testAddress001() {
79+
PublicMethed
80+
.sendcoin(grammarAddress, 100000000000L, testNetAccountAddress, testNetAccountKey,
81+
blockingStubFull);
82+
String contractName = "AddressTest";
83+
String code = Configuration.getByPath("testng.conf")
84+
.getString("code.code_ContractTrcToken077_AddressTest");
85+
String abi = Configuration.getByPath("testng.conf")
86+
.getString("abi.abi_ContractTrcToken077_AddressTest");
87+
contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit,
88+
0L, 100, null, testKeyForGrammarAddress,
89+
grammarAddress, blockingStubFull);
90+
String txid = "";
91+
txid = PublicMethed.triggerContract(contractAddress,
92+
"addressTest()", "#", false,
93+
0, maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull);
94+
Optional<TransactionInfo> infoById = null;
95+
infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull);
96+
logger.info("infoById:" + infoById);
97+
98+
99+
}
100+
101+
@Test(enabled = true, description = "The value of address is not at the beginning of 41")
102+
public void testAddress002() {
103+
PublicMethed
104+
.sendcoin(grammarAddress, 100000000000L, testNetAccountAddress, testNetAccountKey,
105+
blockingStubFull);
106+
PublicMethed.waitProduceNextBlock(blockingStubFull);
107+
PublicMethed.waitProduceNextBlock(blockingStubFull);
108+
109+
String contractName = "AddressTest";
110+
String code = Configuration.getByPath("testng.conf")
111+
.getString("code.code_ContractTrcToken077_AddressTest1");
112+
String abi = Configuration.getByPath("testng.conf")
113+
.getString("abi.abi_ContractTrcToken077_AddressTest1");
114+
contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit,
115+
0L, 100, null, testKeyForGrammarAddress,
116+
grammarAddress, blockingStubFull);
117+
PublicMethed.waitProduceNextBlock(blockingStubFull);
118+
PublicMethed.waitProduceNextBlock(blockingStubFull);
119+
120+
String txid = "";
121+
txid = PublicMethed.triggerContract(contractAddress,
122+
"addressTest()", "#", false,
123+
0, maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull);
124+
PublicMethed.waitProduceNextBlock(blockingStubFull);
125+
PublicMethed.waitProduceNextBlock(blockingStubFull);
126+
127+
Optional<TransactionInfo> infoById = null;
128+
infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull);
129+
logger.info("infoById:" + infoById);
130+
131+
byte[] a = infoById.get().getContractResult(0).toByteArray();
132+
byte[] b = subByte(a, 11, 1);
133+
byte[] c = subByte(a, 0, 11);
134+
byte[] e = "41".getBytes();
135+
byte[] d = subByte(a, 12, 20);
136+
137+
logger.info("a:" + ByteArray.toHexString(a));
138+
139+
logger.info("b:" + ByteArray.toHexString(b));
140+
logger.info("c:" + ByteArray.toHexString(c));
141+
142+
logger.info("d:" + ByteArray.toHexString(d));
143+
144+
logger.info("41" + ByteArray.toHexString(d));
145+
String exceptedResult = "41" + ByteArray.toHexString(d);
146+
String realResult = ByteArray.toHexString(b);
147+
Assert.assertEquals(realResult, "00");
148+
Assert.assertNotEquals(realResult, "41");
149+
150+
Assert.assertEquals(exceptedResult, ByteArray.toHexString(contractAddress));
151+
152+
}
153+
154+
155+
/**
156+
* constructor.
157+
*/
158+
159+
public byte[] subByte(byte[] b, int off, int length) {
160+
byte[] b1 = new byte[length];
161+
System.arraycopy(b, off, b1, 0, length);
162+
return b1;
163+
164+
}
165+
166+
/**
167+
* constructor.
168+
*/
169+
170+
@AfterClass
171+
public void shutdown() throws InterruptedException {
172+
if (channelFull != null) {
173+
channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS);
174+
}
175+
}
176+
}

0 commit comments

Comments
 (0)