forked from tronprotocol/java-tron
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request tronprotocol#3975 from tronprotocol/test/sol_v0.8.…
…6_case add cases for solidity v0.8.6
- Loading branch information
Showing
7 changed files
with
804 additions
and
0 deletions.
There are no files selected for viewing
147 changes: 147 additions & 0 deletions
147
...rk/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/FixbugTest086.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
package stest.tron.wallet.dailybuild.tvmnewcommand.newGrammar; | ||
|
||
import io.grpc.ManagedChannel; | ||
import io.grpc.ManagedChannelBuilder; | ||
import java.util.HashMap; | ||
import java.util.Optional; | ||
import java.util.concurrent.TimeUnit; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.junit.Assert; | ||
import org.testng.annotations.AfterClass; | ||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.BeforeSuite; | ||
import org.testng.annotations.Test; | ||
import org.tron.api.WalletGrpc; | ||
import org.tron.common.crypto.ECKey; | ||
import org.tron.common.utils.ByteArray; | ||
import org.tron.common.utils.Utils; | ||
import org.tron.core.Wallet; | ||
import org.tron.protos.Protocol; | ||
import org.tron.protos.contract.SmartContractOuterClass; | ||
import stest.tron.wallet.common.client.Configuration; | ||
import stest.tron.wallet.common.client.Parameter; | ||
import stest.tron.wallet.common.client.utils.PublicMethed; | ||
|
||
|
||
|
||
|
||
@Slf4j | ||
public class FixbugTest086 { | ||
|
||
private final String testNetAccountKey = Configuration.getByPath("testng.conf") | ||
.getString("foundationAccount.key2"); | ||
private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); | ||
byte[] mapKeyContract = null; | ||
ECKey ecKey1 = new ECKey(Utils.getRandom()); | ||
byte[] contractExcAddress = ecKey1.getAddress(); | ||
String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); | ||
private Long maxFeeLimit = Configuration.getByPath("testng.conf") | ||
.getLong("defaultParameter.maxFeeLimit"); | ||
private ManagedChannel channelFull = null; | ||
private WalletGrpc.WalletBlockingStub blockingStubFull = null; | ||
|
||
private String fullnode = Configuration.getByPath("testng.conf") | ||
.getStringList("fullnode.ip.list").get(0); | ||
|
||
@BeforeSuite | ||
public void beforeSuite() { | ||
Wallet wallet = new Wallet(); | ||
Wallet.setAddressPreFixByte(Parameter.CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); | ||
} | ||
|
||
/** | ||
* constructor. | ||
*/ | ||
|
||
@BeforeClass(enabled = true) | ||
public void beforeClass() { | ||
PublicMethed.printAddress(contractExcKey); | ||
channelFull = ManagedChannelBuilder.forTarget(fullnode) | ||
.usePlaintext(true) | ||
.build(); | ||
blockingStubFull = WalletGrpc.newBlockingStub(channelFull); | ||
|
||
Assert.assertTrue(PublicMethed | ||
.sendcoin(contractExcAddress, 300100_000_000L, | ||
testNetAccountAddress, testNetAccountKey, blockingStubFull)); | ||
PublicMethed.waitProduceNextBlock(blockingStubFull); | ||
|
||
String filePath = | ||
"src/test/resources/soliditycode/abstractContractWithMapParamsConstructor.sol"; | ||
String contractName = "Cat"; | ||
HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); | ||
|
||
String code = retMap.get("byteCode").toString(); | ||
String abi = retMap.get("abI").toString(); | ||
mapKeyContract = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, | ||
0L, 100, null, contractExcKey, | ||
contractExcAddress, blockingStubFull); | ||
PublicMethed.waitProduceNextBlock(blockingStubFull); | ||
SmartContractOuterClass.SmartContract smartContract = PublicMethed.getContract(mapKeyContract, | ||
blockingStubFull); | ||
Assert.assertNotNull(smartContract.getAbi()); | ||
} | ||
|
||
|
||
@Test(enabled = true, description = "abstract With Map Params") | ||
public void test01ContractWithMapParams() { | ||
String triggerTxid = PublicMethed.triggerContract(mapKeyContract, "getMapValue()", "#", false, | ||
0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); | ||
PublicMethed.waitProduceNextBlock(blockingStubFull); | ||
|
||
Optional<Protocol.TransactionInfo> transactionInfo = PublicMethed | ||
.getTransactionInfoById(triggerTxid, blockingStubFull); | ||
Assert.assertEquals(0, transactionInfo.get().getResultValue()); | ||
Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, | ||
transactionInfo.get().getReceipt().getResult()); | ||
Assert.assertEquals(20, | ||
ByteArray.toInt(transactionInfo.get().getContractResult(0).toByteArray())); | ||
} | ||
|
||
|
||
@Test(enabled = true, description = " super skip unimplemented in abstract contract") | ||
public void test02SkipUnimplemented() { | ||
String filePath = | ||
"src/test/resources/soliditycode/super_skip_unimplemented_in_abstract_contract.sol"; | ||
String contractName = "B"; | ||
HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); | ||
|
||
String code = retMap.get("byteCode").toString(); | ||
String abi = retMap.get("abI").toString(); | ||
mapKeyContract = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, | ||
0L, 100, null, contractExcKey, | ||
contractExcAddress, blockingStubFull); | ||
PublicMethed.waitProduceNextBlock(blockingStubFull); | ||
SmartContractOuterClass.SmartContract smartContract = PublicMethed.getContract(mapKeyContract, | ||
blockingStubFull); | ||
Assert.assertNotNull(smartContract.getAbi()); | ||
|
||
String triggerTxid = PublicMethed.triggerContract(mapKeyContract, "f()", "#", false, | ||
0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); | ||
PublicMethed.waitProduceNextBlock(blockingStubFull); | ||
|
||
Optional<Protocol.TransactionInfo> transactionInfo = PublicMethed | ||
.getTransactionInfoById(triggerTxid, blockingStubFull); | ||
Assert.assertEquals(0, transactionInfo.get().getResultValue()); | ||
Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, | ||
transactionInfo.get().getReceipt().getResult()); | ||
Assert.assertEquals(42, | ||
ByteArray.toInt(transactionInfo.get().getContractResult(0).toByteArray())); | ||
} | ||
|
||
|
||
/** | ||
* constructor. | ||
*/ | ||
@AfterClass | ||
public void shutdown() throws InterruptedException { | ||
PublicMethed.freedResource(contractExcAddress, contractExcKey, | ||
testNetAccountAddress, blockingStubFull); | ||
if (channelFull != null) { | ||
channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); | ||
} | ||
} | ||
|
||
|
||
} | ||
|
158 changes: 158 additions & 0 deletions
158
.../java/stest/tron/wallet/dailybuild/tvmnewcommand/newGrammar/FunctionArray2Storage086.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
package stest.tron.wallet.dailybuild.tvmnewcommand.newGrammar; | ||
|
||
import io.grpc.ManagedChannel; | ||
import io.grpc.ManagedChannelBuilder; | ||
import java.util.HashMap; | ||
import java.util.Optional; | ||
import java.util.concurrent.TimeUnit; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.junit.Assert; | ||
import org.testng.annotations.AfterClass; | ||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.BeforeSuite; | ||
import org.testng.annotations.Test; | ||
import org.tron.api.WalletGrpc; | ||
import org.tron.common.crypto.ECKey; | ||
import org.tron.common.utils.ByteArray; | ||
import org.tron.common.utils.Utils; | ||
import org.tron.core.Wallet; | ||
import org.tron.protos.Protocol; | ||
import org.tron.protos.contract.SmartContractOuterClass; | ||
import stest.tron.wallet.common.client.Configuration; | ||
import stest.tron.wallet.common.client.Parameter; | ||
import stest.tron.wallet.common.client.utils.PublicMethed; | ||
|
||
|
||
|
||
|
||
@Slf4j | ||
public class FunctionArray2Storage086 { | ||
|
||
private final String testNetAccountKey = Configuration.getByPath("testng.conf") | ||
.getString("foundationAccount.key2"); | ||
private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); | ||
byte[] mapKeyContract = null; | ||
ECKey ecKey1 = new ECKey(Utils.getRandom()); | ||
byte[] contractExcAddress = ecKey1.getAddress(); | ||
String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); | ||
private Long maxFeeLimit = Configuration.getByPath("testng.conf") | ||
.getLong("defaultParameter.maxFeeLimit"); | ||
private ManagedChannel channelFull = null; | ||
private WalletGrpc.WalletBlockingStub blockingStubFull = null; | ||
|
||
private String fullnode = Configuration.getByPath("testng.conf") | ||
.getStringList("fullnode.ip.list").get(0); | ||
|
||
@BeforeSuite | ||
public void beforeSuite() { | ||
Wallet wallet = new Wallet(); | ||
Wallet.setAddressPreFixByte(Parameter.CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); | ||
} | ||
|
||
/** | ||
* constructor. | ||
*/ | ||
|
||
@BeforeClass(enabled = true) | ||
public void beforeClass() { | ||
PublicMethed.printAddress(contractExcKey); | ||
channelFull = ManagedChannelBuilder.forTarget(fullnode) | ||
.usePlaintext(true) | ||
.build(); | ||
blockingStubFull = WalletGrpc.newBlockingStub(channelFull); | ||
|
||
Assert.assertTrue(PublicMethed | ||
.sendcoin(contractExcAddress, 300100_000_000L, | ||
testNetAccountAddress, testNetAccountKey, blockingStubFull)); | ||
PublicMethed.waitProduceNextBlock(blockingStubFull); | ||
|
||
String filePath = "src/test/resources/soliditycode/function_type_array_to_storage.sol"; | ||
String contractName = "C"; | ||
HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); | ||
|
||
String code = retMap.get("byteCode").toString(); | ||
String abi = retMap.get("abI").toString(); | ||
mapKeyContract = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, | ||
500000000L, 100, null, contractExcKey, | ||
contractExcAddress, blockingStubFull); | ||
PublicMethed.waitProduceNextBlock(blockingStubFull); | ||
SmartContractOuterClass.SmartContract smartContract = PublicMethed.getContract(mapKeyContract, | ||
blockingStubFull); | ||
Assert.assertNotNull(smartContract.getAbi()); | ||
} | ||
|
||
|
||
@Test(enabled = true, description = "function array test view to default") | ||
public void test01View2Default() { | ||
String triggerTxid = | ||
PublicMethed.triggerContract(mapKeyContract, "testViewToDefault()", "#", false, | ||
0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); | ||
PublicMethed.waitProduceNextBlock(blockingStubFull); | ||
|
||
Optional<Protocol.TransactionInfo> transactionInfo = PublicMethed | ||
.getTransactionInfoById(triggerTxid, blockingStubFull); | ||
Assert.assertEquals(0, transactionInfo.get().getResultValue()); | ||
Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, | ||
transactionInfo.get().getReceipt().getResult()); | ||
Assert.assertEquals(12, | ||
ByteArray.toInt(transactionInfo.get().getContractResult(0).substring(0, 32).toByteArray())); | ||
Assert.assertEquals(22, | ||
ByteArray.toInt(transactionInfo.get().getContractResult(0) | ||
.substring(32, 64).toByteArray())); | ||
} | ||
|
||
@Test(enabled = true, description = "function array pure to default") | ||
public void test02Pure2Default() { | ||
String triggerTxid = | ||
PublicMethed.triggerContract(mapKeyContract, "testPureToDefault()", "#", false, | ||
0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); | ||
PublicMethed.waitProduceNextBlock(blockingStubFull); | ||
|
||
Optional<Protocol.TransactionInfo> transactionInfo = PublicMethed | ||
.getTransactionInfoById(triggerTxid, blockingStubFull); | ||
Assert.assertEquals(0, transactionInfo.get().getResultValue()); | ||
Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, | ||
transactionInfo.get().getReceipt().getResult()); | ||
Assert.assertEquals(13, | ||
ByteArray.toInt(transactionInfo.get().getContractResult(0).substring(0, 32).toByteArray())); | ||
Assert.assertEquals(23, | ||
ByteArray.toInt(transactionInfo.get().getContractResult(0) | ||
.substring(32, 64).toByteArray())); | ||
|
||
} | ||
|
||
@Test(enabled = true, description = "function array pure to view ") | ||
public void test03Pure2View() { | ||
String triggerTxid = | ||
PublicMethed.triggerContract(mapKeyContract, "testPureToView()", "#", false, | ||
0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); | ||
PublicMethed.waitProduceNextBlock(blockingStubFull); | ||
|
||
Optional<Protocol.TransactionInfo> transactionInfo = PublicMethed | ||
.getTransactionInfoById(triggerTxid, blockingStubFull); | ||
Assert.assertEquals(0, transactionInfo.get().getResultValue()); | ||
Assert.assertEquals(Protocol.Transaction.Result.contractResult.SUCCESS, | ||
transactionInfo.get().getReceipt().getResult()); | ||
Assert.assertEquals(13, | ||
ByteArray.toInt(transactionInfo.get().getContractResult(0).substring(0, 32).toByteArray())); | ||
Assert.assertEquals(23, | ||
ByteArray.toInt(transactionInfo.get().getContractResult(0) | ||
.substring(32, 64).toByteArray())); | ||
} | ||
|
||
|
||
/** | ||
* constructor. | ||
*/ | ||
@AfterClass | ||
public void shutdown() throws InterruptedException { | ||
PublicMethed.freedResource(contractExcAddress, contractExcKey, | ||
testNetAccountAddress, blockingStubFull); | ||
if (channelFull != null) { | ||
channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); | ||
} | ||
} | ||
|
||
|
||
} | ||
|
Oops, something went wrong.