|
| 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