Skip to content

Commit c44105a

Browse files
authored
Merge pull request tronprotocol#3975 from tronprotocol/test/sol_v0.8.6_case
add cases for solidity v0.8.6
2 parents c61b881 + 5af5c73 commit c44105a

7 files changed

Lines changed: 804 additions & 0 deletions

File tree

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
package stest.tron.wallet.dailybuild.tvmnewcommand.newGrammar;
2+
3+
import io.grpc.ManagedChannel;
4+
import io.grpc.ManagedChannelBuilder;
5+
import java.util.HashMap;
6+
import java.util.Optional;
7+
import java.util.concurrent.TimeUnit;
8+
import lombok.extern.slf4j.Slf4j;
9+
import org.junit.Assert;
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.WalletGrpc;
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;
20+
import org.tron.protos.contract.SmartContractOuterClass;
21+
import stest.tron.wallet.common.client.Configuration;
22+
import stest.tron.wallet.common.client.Parameter;
23+
import stest.tron.wallet.common.client.utils.PublicMethed;
24+
25+
26+
27+
28+
@Slf4j
29+
public class FixbugTest086 {
30+
31+
private final String testNetAccountKey = Configuration.getByPath("testng.conf")
32+
.getString("foundationAccount.key2");
33+
private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey);
34+
byte[] mapKeyContract = null;
35+
ECKey ecKey1 = new ECKey(Utils.getRandom());
36+
byte[] contractExcAddress = ecKey1.getAddress();
37+
String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes());
38+
private Long maxFeeLimit = Configuration.getByPath("testng.conf")
39+
.getLong("defaultParameter.maxFeeLimit");
40+
private ManagedChannel channelFull = null;
41+
private WalletGrpc.WalletBlockingStub blockingStubFull = null;
42+
43+
private String fullnode = Configuration.getByPath("testng.conf")
44+
.getStringList("fullnode.ip.list").get(0);
45+
46+
@BeforeSuite
47+
public void beforeSuite() {
48+
Wallet wallet = new Wallet();
49+
Wallet.setAddressPreFixByte(Parameter.CommonConstant.ADD_PRE_FIX_BYTE_MAINNET);
50+
}
51+
52+
/**
53+
* constructor.
54+
*/
55+
56+
@BeforeClass(enabled = true)
57+
public void beforeClass() {
58+
PublicMethed.printAddress(contractExcKey);
59+
channelFull = ManagedChannelBuilder.forTarget(fullnode)
60+
.usePlaintext(true)
61+
.build();
62+
blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
63+
64+
Assert.assertTrue(PublicMethed
65+
.sendcoin(contractExcAddress, 300100_000_000L,
66+
testNetAccountAddress, testNetAccountKey, blockingStubFull));
67+
PublicMethed.waitProduceNextBlock(blockingStubFull);
68+
69+
String filePath =
70+
"src/test/resources/soliditycode/abstractContractWithMapParamsConstructor.sol";
71+
String contractName = "Cat";
72+
HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName);
73+
74+
String code = retMap.get("byteCode").toString();
75+
String abi = retMap.get("abI").toString();
76+
mapKeyContract = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit,
77+
0L, 100, null, contractExcKey,
78+
contractExcAddress, blockingStubFull);
79+
PublicMethed.waitProduceNextBlock(blockingStubFull);
80+
SmartContractOuterClass.SmartContract smartContract = PublicMethed.getContract(mapKeyContract,
81+
blockingStubFull);
82+
Assert.assertNotNull(smartContract.getAbi());
83+
}
84+
85+
86+
@Test(enabled = true, description = "abstract With Map Params")
87+
public void test01ContractWithMapParams() {
88+
String triggerTxid = PublicMethed.triggerContract(mapKeyContract, "getMapValue()", "#", false,
89+
0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull);
90+
PublicMethed.waitProduceNextBlock(blockingStubFull);
91+
92+
Optional<Protocol.TransactionInfo> transactionInfo = PublicMethed
93+
.getTransactionInfoById(triggerTxid, blockingStubFull);
94+
Assert.assertEquals(0, transactionInfo.get().getResultValue());
95+
Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS,
96+
transactionInfo.get().getReceipt().getResult());
97+
Assert.assertEquals(20,
98+
ByteArray.toInt(transactionInfo.get().getContractResult(0).toByteArray()));
99+
}
100+
101+
102+
@Test(enabled = true, description = " super skip unimplemented in abstract contract")
103+
public void test02SkipUnimplemented() {
104+
String filePath =
105+
"src/test/resources/soliditycode/super_skip_unimplemented_in_abstract_contract.sol";
106+
String contractName = "B";
107+
HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName);
108+
109+
String code = retMap.get("byteCode").toString();
110+
String abi = retMap.get("abI").toString();
111+
mapKeyContract = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit,
112+
0L, 100, null, contractExcKey,
113+
contractExcAddress, blockingStubFull);
114+
PublicMethed.waitProduceNextBlock(blockingStubFull);
115+
SmartContractOuterClass.SmartContract smartContract = PublicMethed.getContract(mapKeyContract,
116+
blockingStubFull);
117+
Assert.assertNotNull(smartContract.getAbi());
118+
119+
String triggerTxid = PublicMethed.triggerContract(mapKeyContract, "f()", "#", false,
120+
0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull);
121+
PublicMethed.waitProduceNextBlock(blockingStubFull);
122+
123+
Optional<Protocol.TransactionInfo> transactionInfo = PublicMethed
124+
.getTransactionInfoById(triggerTxid, blockingStubFull);
125+
Assert.assertEquals(0, transactionInfo.get().getResultValue());
126+
Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS,
127+
transactionInfo.get().getReceipt().getResult());
128+
Assert.assertEquals(42,
129+
ByteArray.toInt(transactionInfo.get().getContractResult(0).toByteArray()));
130+
}
131+
132+
133+
/**
134+
* constructor.
135+
*/
136+
@AfterClass
137+
public void shutdown() throws InterruptedException {
138+
PublicMethed.freedResource(contractExcAddress, contractExcKey,
139+
testNetAccountAddress, blockingStubFull);
140+
if (channelFull != null) {
141+
channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS);
142+
}
143+
}
144+
145+
146+
}
147+
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
package stest.tron.wallet.dailybuild.tvmnewcommand.newGrammar;
2+
3+
import io.grpc.ManagedChannel;
4+
import io.grpc.ManagedChannelBuilder;
5+
import java.util.HashMap;
6+
import java.util.Optional;
7+
import java.util.concurrent.TimeUnit;
8+
import lombok.extern.slf4j.Slf4j;
9+
import org.junit.Assert;
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.WalletGrpc;
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;
20+
import org.tron.protos.contract.SmartContractOuterClass;
21+
import stest.tron.wallet.common.client.Configuration;
22+
import stest.tron.wallet.common.client.Parameter;
23+
import stest.tron.wallet.common.client.utils.PublicMethed;
24+
25+
26+
27+
28+
@Slf4j
29+
public class FunctionArray2Storage086 {
30+
31+
private final String testNetAccountKey = Configuration.getByPath("testng.conf")
32+
.getString("foundationAccount.key2");
33+
private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey);
34+
byte[] mapKeyContract = null;
35+
ECKey ecKey1 = new ECKey(Utils.getRandom());
36+
byte[] contractExcAddress = ecKey1.getAddress();
37+
String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes());
38+
private Long maxFeeLimit = Configuration.getByPath("testng.conf")
39+
.getLong("defaultParameter.maxFeeLimit");
40+
private ManagedChannel channelFull = null;
41+
private WalletGrpc.WalletBlockingStub blockingStubFull = null;
42+
43+
private String fullnode = Configuration.getByPath("testng.conf")
44+
.getStringList("fullnode.ip.list").get(0);
45+
46+
@BeforeSuite
47+
public void beforeSuite() {
48+
Wallet wallet = new Wallet();
49+
Wallet.setAddressPreFixByte(Parameter.CommonConstant.ADD_PRE_FIX_BYTE_MAINNET);
50+
}
51+
52+
/**
53+
* constructor.
54+
*/
55+
56+
@BeforeClass(enabled = true)
57+
public void beforeClass() {
58+
PublicMethed.printAddress(contractExcKey);
59+
channelFull = ManagedChannelBuilder.forTarget(fullnode)
60+
.usePlaintext(true)
61+
.build();
62+
blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
63+
64+
Assert.assertTrue(PublicMethed
65+
.sendcoin(contractExcAddress, 300100_000_000L,
66+
testNetAccountAddress, testNetAccountKey, blockingStubFull));
67+
PublicMethed.waitProduceNextBlock(blockingStubFull);
68+
69+
String filePath = "src/test/resources/soliditycode/function_type_array_to_storage.sol";
70+
String contractName = "C";
71+
HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName);
72+
73+
String code = retMap.get("byteCode").toString();
74+
String abi = retMap.get("abI").toString();
75+
mapKeyContract = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit,
76+
500000000L, 100, null, contractExcKey,
77+
contractExcAddress, blockingStubFull);
78+
PublicMethed.waitProduceNextBlock(blockingStubFull);
79+
SmartContractOuterClass.SmartContract smartContract = PublicMethed.getContract(mapKeyContract,
80+
blockingStubFull);
81+
Assert.assertNotNull(smartContract.getAbi());
82+
}
83+
84+
85+
@Test(enabled = true, description = "function array test view to default")
86+
public void test01View2Default() {
87+
String triggerTxid =
88+
PublicMethed.triggerContract(mapKeyContract, "testViewToDefault()", "#", false,
89+
0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull);
90+
PublicMethed.waitProduceNextBlock(blockingStubFull);
91+
92+
Optional<Protocol.TransactionInfo> transactionInfo = PublicMethed
93+
.getTransactionInfoById(triggerTxid, blockingStubFull);
94+
Assert.assertEquals(0, transactionInfo.get().getResultValue());
95+
Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS,
96+
transactionInfo.get().getReceipt().getResult());
97+
Assert.assertEquals(12,
98+
ByteArray.toInt(transactionInfo.get().getContractResult(0).substring(0, 32).toByteArray()));
99+
Assert.assertEquals(22,
100+
ByteArray.toInt(transactionInfo.get().getContractResult(0)
101+
.substring(32, 64).toByteArray()));
102+
}
103+
104+
@Test(enabled = true, description = "function array pure to default")
105+
public void test02Pure2Default() {
106+
String triggerTxid =
107+
PublicMethed.triggerContract(mapKeyContract, "testPureToDefault()", "#", false,
108+
0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull);
109+
PublicMethed.waitProduceNextBlock(blockingStubFull);
110+
111+
Optional<Protocol.TransactionInfo> transactionInfo = PublicMethed
112+
.getTransactionInfoById(triggerTxid, blockingStubFull);
113+
Assert.assertEquals(0, transactionInfo.get().getResultValue());
114+
Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS,
115+
transactionInfo.get().getReceipt().getResult());
116+
Assert.assertEquals(13,
117+
ByteArray.toInt(transactionInfo.get().getContractResult(0).substring(0, 32).toByteArray()));
118+
Assert.assertEquals(23,
119+
ByteArray.toInt(transactionInfo.get().getContractResult(0)
120+
.substring(32, 64).toByteArray()));
121+
122+
}
123+
124+
@Test(enabled = true, description = "function array pure to view ")
125+
public void test03Pure2View() {
126+
String triggerTxid =
127+
PublicMethed.triggerContract(mapKeyContract, "testPureToView()", "#", false,
128+
0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull);
129+
PublicMethed.waitProduceNextBlock(blockingStubFull);
130+
131+
Optional<Protocol.TransactionInfo> transactionInfo = PublicMethed
132+
.getTransactionInfoById(triggerTxid, blockingStubFull);
133+
Assert.assertEquals(0, transactionInfo.get().getResultValue());
134+
Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS,
135+
transactionInfo.get().getReceipt().getResult());
136+
Assert.assertEquals(13,
137+
ByteArray.toInt(transactionInfo.get().getContractResult(0).substring(0, 32).toByteArray()));
138+
Assert.assertEquals(23,
139+
ByteArray.toInt(transactionInfo.get().getContractResult(0)
140+
.substring(32, 64).toByteArray()));
141+
}
142+
143+
144+
/**
145+
* constructor.
146+
*/
147+
@AfterClass
148+
public void shutdown() throws InterruptedException {
149+
PublicMethed.freedResource(contractExcAddress, contractExcKey,
150+
testNetAccountAddress, blockingStubFull);
151+
if (channelFull != null) {
152+
channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS);
153+
}
154+
}
155+
156+
157+
}
158+

0 commit comments

Comments
 (0)