Skip to content

Commit 5453334

Browse files
add stest case
1 parent cb03339 commit 5453334

11 files changed

Lines changed: 405 additions & 24 deletions

File tree

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import io.grpc.ManagedChannel;
44
import io.grpc.ManagedChannelBuilder;
55
import java.util.HashMap;
6+
import java.util.Optional;
67
import java.util.concurrent.TimeUnit;
78
import lombok.extern.slf4j.Slf4j;
89
import org.junit.Assert;
@@ -18,6 +19,7 @@
1819
import org.tron.core.Wallet;
1920
import org.tron.protos.Protocol.Account;
2021
import org.tron.protos.Protocol.SmartContract;
22+
import org.tron.protos.Protocol.TransactionInfo;
2123
import stest.tron.wallet.common.client.Configuration;
2224
import stest.tron.wallet.common.client.Parameter.CommonConstant;
2325
import stest.tron.wallet.common.client.utils.PublicMethed;
@@ -68,10 +70,19 @@ public void beforeClass() {
6870

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

‎src/test/java/stest/tron/wallet/dailybuild/exceptionfee/AssertException.java‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import org.tron.common.utils.Utils;
2020
import org.tron.core.Wallet;
2121
import org.tron.protos.Protocol.Account;
22+
import org.tron.protos.Protocol.Transaction;
23+
import org.tron.protos.Protocol.Transaction.Result.contractResult;
2224
import org.tron.protos.Protocol.TransactionInfo;
2325
import stest.tron.wallet.common.client.Configuration;
2426
import stest.tron.wallet.common.client.Parameter.CommonConstant;
@@ -129,6 +131,22 @@ public void test1DivideInt() {
129131
PublicMethed.waitProduceNextBlock(blockingStubFull1);
130132
Optional<TransactionInfo> infoById = null;
131133
infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull);
134+
logger.info("infoById:" + infoById);
135+
Optional<Transaction> ById = PublicMethed.getTransactionById(txid, blockingStubFull);
136+
logger.info("getRet:" + ById.get().getRet(0));
137+
logger.info("getNumber:" + ById.get().getRet(0).getContractRet().getNumber());
138+
logger.info("getContractRetValue:" + ById.get().getRet(0).getContractRetValue());
139+
logger.info("getContractRet:" + ById.get().getRet(0).getContractRet());
140+
141+
Assert.assertEquals(ById.get().getRet(0).getContractRet().getNumber(),
142+
contractResult.ILLEGAL_OPERATION_VALUE);
143+
Assert.assertEquals(ById.get().getRet(0).getContractRetValue(), 8);
144+
Assert.assertEquals(ById.get().getRet(0).getContractRet(), contractResult.ILLEGAL_OPERATION);
145+
146+
Assert
147+
.assertEquals(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()), "");
148+
Assert.assertEquals(contractResult.ILLEGAL_OPERATION, infoById.get().getReceipt().getResult());
149+
132150
Long fee = infoById.get().getFee();
133151
Long netUsed = infoById.get().getReceipt().getNetUsage();
134152
Long energyUsed = infoById.get().getReceipt().getEnergyUsage();

0 commit comments

Comments
 (0)