Skip to content

Commit 8b5a2cb

Browse files
Merge pull request tronprotocol#2313 from tronprotocol/feature/add_TVMNewCommand_stest_back
Feature/add check contractResult stest
2 parents 45454c3 + cbcfe89 commit 8b5a2cb

File tree

15 files changed

+1323
-36
lines changed

15 files changed

+1323
-36
lines changed

deploy.sh

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
#!/bin/bash
22
if [[ "$TRAVIS_BRANCH" = "develop" || "$TRAVIS_BRANCH" = "master" ]];then
33
stestlogname="`date +%Y%m%d%H%M%S`_stest.log"
4+
timeout 10 ping -c 5 47.93.42.145 > /dev/null || exit 1
5+
timeout 10 ping -c 5 47.93.18.60 > /dev/null || exit 1
46
stest_server=""
5-
docker_num_in_67=`ssh -p 22008 -t [email protected] 'docker ps -a | wc -l'`
6-
docker_num_in_67=`echo $docker_num_in_67 | tr -d "\r"`
7-
docker_num_in_122=`ssh -p 22008 -t [email protected] 'docker ps -a | wc -l'`
8-
docker_num_in_122=`echo $docker_num_in_122 | tr -d "\r"`
9-
if [ $docker_num_in_67 -le $docker_num_in_122 ];
7+
docker_num_in_145=`ssh -p 22008 -t [email protected] 'docker ps -a | wc -l'`
8+
docker_num_in_145=`echo $docker_num_in_145 | tr -d "\r"`
9+
docker_num_in_60=`ssh -p 22008 -t [email protected] 'docker ps -a | wc -l'`
10+
docker_num_in_60=`echo $docker_num_in_60 | tr -d "\r"`
11+
if [ $docker_num_in_145 -le $docker_num_in_60 ];
1012
then
11-
docker_num=$docker_num_in_67
12-
stest_server=47.93.18.60
13+
docker_num=$docker_num_in_145
14+
stest_server=47.93.42.145
1315
else
14-
docker_num=$docker_num_in_122
15-
stest_server=47.93.42.145
16+
docker_num=$docker_num_in_60
17+
stest_server=47.93.18.60
1618
fi
1719

1820
if [[ ${docker_num} -le 3 ]];

src/test/java/stest/tron/wallet/contract/linkage/ContractLinkage002.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package stest.tron.wallet.contract.linkage;
22

3+
import static org.tron.protos.Protocol.Transaction.Result.contractResult.SUCCESS_VALUE;
4+
35
import io.grpc.ManagedChannel;
46
import io.grpc.ManagedChannelBuilder;
57
import java.util.HashMap;
8+
import java.util.Optional;
69
import java.util.concurrent.TimeUnit;
710
import lombok.extern.slf4j.Slf4j;
811
import org.junit.Assert;
@@ -18,6 +21,9 @@
1821
import org.tron.core.Wallet;
1922
import org.tron.protos.Protocol.Account;
2023
import org.tron.protos.Protocol.SmartContract;
24+
import org.tron.protos.Protocol.Transaction;
25+
import org.tron.protos.Protocol.Transaction.Result.contractResult;
26+
import org.tron.protos.Protocol.TransactionInfo;
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;
@@ -68,10 +74,24 @@ public void beforeClass() {
6874

6975
@Test(enabled = true)
7076
public void updateSetting() {
71-
Assert.assertTrue(PublicMethed.sendcoin(linkage002Address, 200000000000L, fromAddress,
72-
testKey002, blockingStubFull));
77+
String sendcoin = PublicMethed
78+
.sendcoinGetTransactionId(linkage002Address, 200000000000L, fromAddress,
79+
testKey002, blockingStubFull);
7380
Account info;
7481
PublicMethed.waitProduceNextBlock(blockingStubFull);
82+
PublicMethed.waitProduceNextBlock(blockingStubFull);
83+
Optional<TransactionInfo> infoById0 = null;
84+
infoById0 = PublicMethed.getTransactionInfoById(sendcoin, blockingStubFull);
85+
logger.info("infoById0 " + infoById0.get());
86+
Assert.assertEquals(ByteArray.toHexString(infoById0.get().getContractResult(0).toByteArray()),
87+
"");
88+
Assert.assertEquals(infoById0.get().getResult().getNumber(), 0);
89+
Optional<Transaction> ById = PublicMethed.getTransactionById(sendcoin, blockingStubFull);
90+
Assert.assertEquals(ById.get().getRet(0).getContractRet().getNumber(),
91+
SUCCESS_VALUE);
92+
Assert.assertEquals(ById.get().getRet(0).getContractRetValue(), SUCCESS_VALUE);
93+
Assert.assertEquals(ById.get().getRet(0).getContractRet(), contractResult.SUCCESS);
94+
7595
Assert.assertTrue(PublicMethed.freezeBalanceGetEnergy(linkage002Address, 50000000L,
7696
3, 1, linkage002Key, blockingStubFull));
7797
AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(linkage002Address,
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
package stest.tron.wallet.contract.scenario;
2+
3+
import static org.tron.protos.Protocol.Transaction.Result.contractResult.SUCCESS_VALUE;
4+
5+
import io.grpc.ManagedChannel;
6+
import io.grpc.ManagedChannelBuilder;
7+
import java.util.HashMap;
8+
import java.util.Optional;
9+
import java.util.concurrent.TimeUnit;
10+
import lombok.extern.slf4j.Slf4j;
11+
import org.junit.Assert;
12+
import org.testng.annotations.AfterClass;
13+
import org.testng.annotations.BeforeClass;
14+
import org.testng.annotations.BeforeSuite;
15+
import org.testng.annotations.Test;
16+
import org.tron.api.GrpcAPI.AccountResourceMessage;
17+
import org.tron.api.WalletGrpc;
18+
import org.tron.api.WalletSolidityGrpc;
19+
import org.tron.common.crypto.ECKey;
20+
import org.tron.common.utils.ByteArray;
21+
import org.tron.common.utils.Utils;
22+
import org.tron.core.Wallet;
23+
import org.tron.protos.Protocol.Account;
24+
import org.tron.protos.Protocol.SmartContract;
25+
import org.tron.protos.Protocol.Transaction;
26+
import org.tron.protos.Protocol.Transaction.Result.contractResult;
27+
import org.tron.protos.Protocol.TransactionInfo;
28+
import stest.tron.wallet.common.client.Configuration;
29+
import stest.tron.wallet.common.client.Parameter.CommonConstant;
30+
import stest.tron.wallet.common.client.utils.PublicMethed;
31+
32+
@Slf4j
33+
public class ContractScenario014 {
34+
35+
private final String testNetAccountKey = Configuration.getByPath("testng.conf")
36+
.getString("foundationAccount.key2");
37+
private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey);
38+
private Long maxFeeLimit = Configuration.getByPath("testng.conf")
39+
.getLong("defaultParameter.maxFeeLimit");
40+
private ManagedChannel channelSolidity = null;
41+
42+
private ManagedChannel channelFull = null;
43+
private WalletGrpc.WalletBlockingStub blockingStubFull = null;
44+
45+
private ManagedChannel channelFull1 = null;
46+
private WalletGrpc.WalletBlockingStub blockingStubFull1 = null;
47+
48+
49+
private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null;
50+
51+
private String fullnode = Configuration.getByPath("testng.conf")
52+
.getStringList("fullnode.ip.list").get(0);
53+
private String fullnode1 = Configuration.getByPath("testng.conf")
54+
.getStringList("fullnode.ip.list").get(1);
55+
56+
private String soliditynode = Configuration.getByPath("testng.conf")
57+
.getStringList("solidityNode.ip.list").get(0);
58+
59+
byte[] contractAddress = null;
60+
61+
ECKey ecKey1 = new ECKey(Utils.getRandom());
62+
byte[] contractExcAddress = ecKey1.getAddress();
63+
String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes());
64+
65+
66+
@BeforeSuite
67+
public void beforeSuite() {
68+
Wallet wallet = new Wallet();
69+
Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET);
70+
}
71+
72+
/**
73+
* constructor.
74+
*/
75+
76+
@BeforeClass(enabled = true)
77+
public void beforeClass() {
78+
PublicMethed.printAddress(contractExcKey);
79+
channelFull = ManagedChannelBuilder.forTarget(fullnode)
80+
.usePlaintext(true)
81+
.build();
82+
blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
83+
channelFull1 = ManagedChannelBuilder.forTarget(fullnode1)
84+
.usePlaintext(true)
85+
.build();
86+
blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1);
87+
88+
channelSolidity = ManagedChannelBuilder.forTarget(soliditynode)
89+
.usePlaintext(true)
90+
.build();
91+
blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity);
92+
}
93+
94+
@Test(enabled = true, description = "Clear a contract with ABI created by itself")
95+
public void testClearAbi() {
96+
Assert.assertTrue(PublicMethed
97+
.sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey,
98+
blockingStubFull));
99+
100+
PublicMethed.waitProduceNextBlock(blockingStubFull);
101+
String filePath = "src/test/resources/soliditycode/ClearAbi001.sol";
102+
String contractName = "testConstantContract";
103+
HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName);
104+
String code = retMap.get("byteCode").toString();
105+
String abi = retMap.get("abI").toString();
106+
107+
contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit,
108+
0L, 100, null, contractExcKey,
109+
contractExcAddress, blockingStubFull);
110+
PublicMethed.waitProduceNextBlock(blockingStubFull);
111+
SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull);
112+
Assert.assertFalse(smartContract.getAbi().toString().isEmpty());
113+
Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName));
114+
Assert.assertFalse(smartContract.getBytecode().toString().isEmpty());
115+
Account info;
116+
117+
AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress,
118+
blockingStubFull);
119+
info = PublicMethed.queryAccount(contractExcKey, blockingStubFull);
120+
Long beforeBalance = info.getBalance();
121+
Long beforeEnergyUsed = resourceInfo.getEnergyUsed();
122+
Long beforeNetUsed = resourceInfo.getNetUsed();
123+
Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed();
124+
logger.info("beforeBalance:" + beforeBalance);
125+
logger.info("beforeEnergyUsed:" + beforeEnergyUsed);
126+
logger.info("beforeNetUsed:" + beforeNetUsed);
127+
logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed);
128+
129+
String txid = PublicMethed
130+
.clearContractAbi(contractAddress, contractExcAddress, contractExcKey,
131+
blockingStubFull);
132+
PublicMethed.waitProduceNextBlock(blockingStubFull);
133+
Optional<TransactionInfo> infoById = null;
134+
infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull);
135+
Assert.assertEquals(0,infoById.get().getResultValue());
136+
Assert.assertEquals("",
137+
ByteArray.toHexString(infoById.get().getResMessage().toByteArray()));
138+
139+
Optional<Transaction> byId = PublicMethed.getTransactionById(txid, blockingStubFull);
140+
Assert.assertEquals(byId.get().getRet(0).getContractRet().getNumber(),
141+
SUCCESS_VALUE);
142+
Assert.assertEquals(byId.get().getRet(0).getContractRetValue(), SUCCESS_VALUE);
143+
Assert.assertEquals(byId.get().getRet(0).getContractRet(), contractResult.SUCCESS);
144+
145+
smartContract = PublicMethed.getContract(contractAddress, blockingStubFull);
146+
Assert.assertTrue(smartContract.getAbi().toString().isEmpty());
147+
Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName));
148+
Assert.assertFalse(smartContract.getBytecode().toString().isEmpty());
149+
150+
151+
}
152+
153+
154+
/**
155+
* constructor.
156+
*/
157+
@AfterClass
158+
public void shutdown() throws InterruptedException {
159+
if (channelFull != null) {
160+
channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS);
161+
}
162+
if (channelFull1 != null) {
163+
channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS);
164+
}
165+
if (channelSolidity != null) {
166+
channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS);
167+
}
168+
}
169+
170+
171+
}

0 commit comments

Comments
 (0)