diff --git a/src/test/java/stest/tron/wallet/contract/linkage/ContractLinkage005.java b/src/test/java/stest/tron/wallet/contract/linkage/ContractLinkage005.java new file mode 100644 index 00000000000..479046d28b1 --- /dev/null +++ b/src/test/java/stest/tron/wallet/contract/linkage/ContractLinkage005.java @@ -0,0 +1,202 @@ +package stest.tron.wallet.contract.linkage; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +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.GrpcAPI.AccountResourceMessage; +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.Account; +import org.tron.protos.Protocol.TransactionInfo; +import stest.tron.wallet.common.client.Configuration; +import stest.tron.wallet.common.client.Parameter.CommonConstant; +import stest.tron.wallet.common.client.utils.PublicMethed; + +@Slf4j +public class ContractLinkage005 { + + //testng001、testng002、testng003、testng004 + private final String testKey003 = + "FC8BF0238748587B9617EB6D15D47A66C0E07C1A1959033CF249C6532DC29FE6"; + private final byte[] fromAddress = PublicMethed.getFinalAddress(testKey003); + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + + String contractName; + String code; + String abi; + Long currentFee; + Long zeroForCycleCost; + Long firstForCycleCost; + Long secondForCycleCost; + Long thirdForCycleCost; + Long forthForCycleCost; + Long fifthForCycleCost; + Long zeroForCycleTimes = 498L; + Long firstForCycleTimes = 500L; + Long secondForCycleTimes = 502L; + Long thirdForCycleTimes = 504L; + Long forthForCycleTimes = 506L; + Long fifthForCycleTimes = 508L; + byte [] contractAddress; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] linkage005Address = ecKey1.getAddress(); + String linkage005Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(linkage005Key); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + + } + + @Test(enabled = true) + public void testEnergyCostDetail() { + Assert.assertTrue(PublicMethed.sendcoin(linkage005Address,2000000000000L,fromAddress, + testKey003,blockingStubFull)); + Assert.assertTrue(PublicMethed.freezeBalance(linkage005Address,1000000L, + 3,linkage005Key,blockingStubFull)); + Assert.assertTrue(PublicMethed.freezeBalanceGetEnergy(linkage005Address,1000000L, + 3,1,linkage005Key,blockingStubFull)); + + final Long maxFeeLimit = 150000000L; + contractName = "EnergyCost"; + code = "6080604052600060035534801561001557600080fd5b5061027b806100256000396000f3006080604052600436106100825763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416633755cd3c81146100875780637d965688146100b1578063a05b2577146100c9578063b0d6304d146100e1578063bbe1d75b14610115578063f8a8fd6d1461012a578063fe75faab14610141575b600080fd5b34801561009357600080fd5b5061009f600435610159565b60408051918252519081900360200190f35b3480156100bd57600080fd5b5061009f600435610178565b3480156100d557600080fd5b5061009f600435610198565b3480156100ed57600080fd5b5061009f73ffffffffffffffffffffffffffffffffffffffff600435811690602435166101e2565b34801561012157600080fd5b5061009f6101ff565b34801561013657600080fd5b5061013f610205565b005b34801561014d57600080fd5b5061009f600435610218565b600080548290811061016757fe5b600091825260209091200154905081565b600080805b83811015610191576001918201910161017d565b5092915050565b600080805b838110156101915760008054600181810183559180527f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e56301829055918201910161019d565b600260209081526000928352604080842090915290825290205481565b60015481565b600380546001019055610216610205565b565b60006102238261022e565b600181905592915050565b600061023c6002830361022e565b6102486001840361022e565b01929150505600a165627a7a72305820bc44fd5f3a0e48cc057752b52e3abf50cd7dc75b3874ea7d049893cf1a2e345f0029"; + abi = "[{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"iarray\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"a\",\"type\":\"uint256\"}],\"name\":\"testUseCpu\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"a\",\"type\":\"uint256\"}],\"name\":\"testUseStorage\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"address\"},{\"name\":\"\",\"type\":\"address\"}],\"name\":\"m\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"calculatedFibNumber\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"test\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"n\",\"type\":\"uint256\"}],\"name\":\"setFibonacci\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]"; + + + + contractAddress = PublicMethed.deployContract(contractName,abi,code, + "",maxFeeLimit, 0L, 100,null,linkage005Key, + linkage005Address,blockingStubFull); + + firstForCycleTimes = 1000L; + secondForCycleTimes = 1002L; + thirdForCycleTimes = 1004L; + + String txid = PublicMethed.triggerContract(contractAddress, + "testUseCpu(uint256)",firstForCycleTimes.toString(), false, + 0, 100000000L, linkage005Address, linkage005Key, blockingStubFull); + Optional infoById = PublicMethed.getTransactionInfoById(txid,blockingStubFull); + firstForCycleCost = infoById.get().getReceipt().getEnergyUsageTotal(); + + txid = PublicMethed.triggerContract(contractAddress, + "testUseCpu(uint256)",secondForCycleTimes.toString(), false, + 0, 100000000L, linkage005Address, linkage005Key, blockingStubFull); + infoById = PublicMethed.getTransactionInfoById(txid,blockingStubFull); + secondForCycleCost = infoById.get().getReceipt().getEnergyUsageTotal(); + + txid = PublicMethed.triggerContract(contractAddress, + "testUseCpu(uint256)",thirdForCycleTimes.toString(), false, + 0, 100000000L, linkage005Address, linkage005Key, blockingStubFull); + infoById = PublicMethed.getTransactionInfoById(txid,blockingStubFull); + thirdForCycleCost = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info(firstForCycleCost.toString()); + logger.info(secondForCycleCost.toString()); + logger.info(thirdForCycleCost.toString()); + + Assert.assertTrue(thirdForCycleCost - secondForCycleCost + == secondForCycleCost - firstForCycleCost); + + + zeroForCycleTimes = 498L; + firstForCycleTimes = 500L; + secondForCycleTimes = 502L; + thirdForCycleTimes = 504L; + forthForCycleTimes = 506L; + fifthForCycleTimes = 508L; + + txid = PublicMethed.triggerContract(contractAddress, + "testUseStorage(uint256)",zeroForCycleTimes.toString(), false, + 0, 100000000L, linkage005Address, linkage005Key, blockingStubFull); + infoById = PublicMethed.getTransactionInfoById(txid,blockingStubFull); + zeroForCycleCost = infoById.get().getReceipt().getEnergyUsageTotal(); + + txid = PublicMethed.triggerContract(contractAddress, + "testUseStorage(uint256)",firstForCycleTimes.toString(), false, + 0, 100000000L, linkage005Address, linkage005Key, blockingStubFull); + infoById = PublicMethed.getTransactionInfoById(txid,blockingStubFull); + firstForCycleCost = infoById.get().getReceipt().getEnergyUsageTotal(); + + txid = PublicMethed.triggerContract(contractAddress, + "testUseStorage(uint256)",secondForCycleTimes.toString(), false, + 0, 100000000L, linkage005Address, linkage005Key, blockingStubFull); + infoById = PublicMethed.getTransactionInfoById(txid,blockingStubFull); + secondForCycleCost = infoById.get().getReceipt().getEnergyUsageTotal(); + + txid = PublicMethed.triggerContract(contractAddress, + "testUseStorage(uint256)",thirdForCycleTimes.toString(), false, + 0, 100000000L, linkage005Address, linkage005Key, blockingStubFull); + infoById = PublicMethed.getTransactionInfoById(txid,blockingStubFull); + thirdForCycleCost = infoById.get().getReceipt().getEnergyUsageTotal(); + + txid = PublicMethed.triggerContract(contractAddress, + "testUseStorage(uint256)",forthForCycleTimes.toString(), false, + 0, 100000000L, linkage005Address, linkage005Key, blockingStubFull); + infoById = PublicMethed.getTransactionInfoById(txid,blockingStubFull); + forthForCycleCost = infoById.get().getReceipt().getEnergyUsageTotal(); + + txid = PublicMethed.triggerContract(contractAddress, + "testUseStorage(uint256)",fifthForCycleTimes.toString(), false, + 0, 100000000L, linkage005Address, linkage005Key, blockingStubFull); + infoById = PublicMethed.getTransactionInfoById(txid,blockingStubFull); + fifthForCycleCost = infoById.get().getReceipt().getEnergyUsageTotal(); + + + + /* logger.info("Zero cost is " + zeroForCycleCost); + logger.info("First cost is " + firstForCycleCost); + logger.info("Second cost is " + secondForCycleCost); + logger.info("Third cost is " + thirdForCycleCost); + logger.info("Forth cost is " + forthForCycleCost); + logger.info("Fifth cost is " + fifthForCycleCost); + logger.info(Long.toString(firstForCycleCost - zeroForCycleCost)); + logger.info(Long.toString(secondForCycleCost - firstForCycleCost)); + logger.info(Long.toString(thirdForCycleCost - secondForCycleCost)); + logger.info(Long.toString(forthForCycleCost - thirdForCycleCost)); + logger.info(Long.toString(fifthForCycleCost - forthForCycleCost));*/ + + Assert.assertTrue(thirdForCycleCost - secondForCycleCost + == secondForCycleCost - firstForCycleCost); + Assert.assertTrue(fifthForCycleCost - forthForCycleCost + == forthForCycleCost - thirdForCycleCost); + + + + } + + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} + + diff --git a/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario013.java b/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario013.java new file mode 100644 index 00000000000..67358ca479a --- /dev/null +++ b/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario013.java @@ -0,0 +1,123 @@ +package stest.tron.wallet.contract.scenario; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +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.GrpcAPI.AccountResourceMessage; +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.SmartContract; +import org.tron.protos.Protocol.TransactionInfo; +import stest.tron.wallet.common.client.Configuration; +import stest.tron.wallet.common.client.Parameter.CommonConstant; +import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.PublicMethed; + +@Slf4j +public class ContractScenario013 { + + //testng001、testng002、testng003、testng004 + private final String testKey002 = + "FC8BF0238748587B9617EB6D15D47A66C0E07C1A1959033CF249C6532DC29FE6"; + private final byte[] fromAddress = PublicMethed.getFinalAddress(testKey002); + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + + byte[] contractAddress = null; + String txid = ""; + Optional infoById = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contract013Address = ecKey1.getAddress(); + String contract013Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contract013Key); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + Assert.assertTrue(PublicMethed.sendcoin(contract013Address,2000000000L,fromAddress, + testKey002,blockingStubFull)); + } + + @Test(enabled = true) + public void deployTronTrxAndSunContract() { + AccountResourceMessage accountResource = PublicMethed.getAccountResource(contract013Address, + blockingStubFull); + Long energyLimit = accountResource.getEnergyLimit(); + Long energyUsage = accountResource.getEnergyUsed(); + + logger.info("before energy limit is " + Long.toString(energyLimit)); + logger.info("before energy usage is " + Long.toString(energyUsage)); + Long maxFeeLimit = 5000000L; + String contractName = "TronTrxAndSunContract"; + String code = "6080604052348015600f57600080fd5b50600180141515601e57600080fd5b603c80141515602c57600080fd5b610e1080141515603b57600080fd5b6201518080141515604b57600080fd5b62093a8080141515605b57600080fd5b6301e1338080141515606c57600080fd5b620f424080141515607c57600080fd5b60358060896000396000f3006080604052600080fd00a165627a7a723058206a36395ee2292959a89e7956d6826a7107c490331e4505fc319010873c26392b0029"; + String abi = "[{\"inputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"}]"; + txid = PublicMethed.deployContractAndGetTransactionInfoById(contractName,abi,code,"", + maxFeeLimit, 0L, 100,null,contract013Key,contract013Address,blockingStubFull); + logger.info(txid); + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + //logger.info("result is " + infoById.get().getResultValue()); + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() > 0); + Assert.assertFalse(infoById.get().getContractAddress().isEmpty()); + } + + @Test(enabled = true) + public void triggerTronTrxAndSunContract() { + AccountResourceMessage accountResource = PublicMethed.getAccountResource(contract013Address, + blockingStubFull); + Long energyLimit = accountResource.getEnergyLimit(); + Long energyUsage = accountResource.getEnergyUsed(); + + logger.info("before energy limit is " + Long.toString(energyLimit)); + logger.info("before energy usage is " + Long.toString(energyUsage)); + Long maxFeeLimit = 5000000L; + String contractName = "TronTrxAndSunContract"; + String code = "608060405234801561001057600080fd5b5061011a806100206000396000f300608060405260043610603f576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806316ada547146044575b600080fd5b348015604f57600080fd5b506056606c565b6040518082815260200191505060405180910390f35b6000600180141515607c57600080fd5b603c80141515608a57600080fd5b610e1080141515609957600080fd5b620151808014151560a957600080fd5b62093a808014151560b957600080fd5b6301e133808014151560ca57600080fd5b620f42408014151560da57600080fd5b60018014151560e857600080fd5b429050905600a165627a7a72305820eacfee595582d9244a2fb5f052905bd240f87864fb8f602f85fd31fe3b89cda80029"; + String abi = "[{\"constant\":false,\"inputs\":[],\"name\":\"time\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]"; + contractAddress = PublicMethed.deployContract(contractName,abi,code,"",maxFeeLimit, + 0L, 100,null,contract013Key,contract013Address,blockingStubFull); + + txid = PublicMethed.triggerContract(contractAddress, + "time()", "#", false, + 0, 100000000L, contract013Address, contract013Key, blockingStubFull); + logger.info(txid); + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + logger.info("result is " + infoById.get().getResultValue()); + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() > 0); + Assert.assertTrue(infoById.get().getFee() == infoById.get().getReceipt().getEnergyFee()); + Assert.assertFalse(infoById.get().getContractAddress().isEmpty()); + } + + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } +} + + diff --git a/src/test/java/stest/tron/wallet/onlineStress/TestExceptionCodeAndAbi.java b/src/test/java/stest/tron/wallet/onlineStress/TestExceptionCodeAndAbi.java index d416e9e1f1c..334dcb39f6e 100644 --- a/src/test/java/stest/tron/wallet/onlineStress/TestExceptionCodeAndAbi.java +++ b/src/test/java/stest/tron/wallet/onlineStress/TestExceptionCodeAndAbi.java @@ -40,6 +40,8 @@ public class TestExceptionCodeAndAbi { private String fullnode = Configuration.getByPath("testng.conf") .getStringList("fullnode.ip.list").get(0); + byte[] contractAddress = null; + @BeforeSuite public void beforeSuite() { @@ -56,6 +58,7 @@ public void beforeClass() { blockingStubFull = WalletGrpc.newBlockingStub(channelFull); logger.info(Long.toString(PublicMethed.queryAccount(testNetAccountKey,blockingStubFull) .getBalance())); + Assert.assertTrue(PublicMethed.freezeBalance(testNetAccountAddress,10000000L,3,testNetAccountKey,blockingStubFull)); Assert.assertTrue(PublicMethed.freezeBalanceGetEnergy(testNetAccountAddress,10000000L, 3,1,testNetAccountKey,blockingStubFull)); /* Assert.assertTrue(PublicMethed.buyStorage(50000000L,testNetAccountAddress, @@ -83,18 +86,19 @@ public void testExceptionCodeAndAbi() { byte[] contractAddress; Optional infoById = null; Long energyTotal; - while (times++ < 10000) { + + while (times++ < 50) { String contractName = "Fomo3D"; - String code1 = "608060405234801561001057600080fd5b50610731806100206000396000f3006080604052600436106100a35763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166306fdde0381146100a8578063095ea7b31461013257806318160ddd146101585780632f745c591461017f5780636352211e146101a35780636914db60146101d757806370a08231146101ef57806395d89b4114610210578063a9059cbb14610225578063b2e6ceeb14610249575b600080fd5b3480156100b457600080fd5b506100bd610261565b6040805160208082528351818301528351919283929083019185019080838360005b838110156100f75781810151838201526020016100df565b50505050905090810190601f1680156101245780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561013e57600080fd5b50610156600160a060020a0360043516602435610298565b005b34801561016457600080fd5b5061016d61032d565b60408051918252519081900360200190f35b34801561018b57600080fd5b5061016d600160a060020a0360043516602435610336565b3480156101af57600080fd5b506101bb60043561035e565b60408051600160a060020a039092168252519081900360200190f35b3480156101e357600080fd5b506100bd600435610397565b3480156101fb57600080fd5b5061016d600160a060020a0360043516610438565b34801561021c57600080fd5b506100bd610453565b34801561023157600080fd5b50610156600160a060020a036004351660243561048a565b34801561025557600080fd5b5061015660043561059d565b60408051808201909152601181527f54726f6e2045524337323120546f6b656e000000000000000000000000000000602082015290565b6102a18161035e565b600160a060020a031633146102b557600080fd5b33600160a060020a03831614156102cb57600080fd5b336000818152600360209081526040808320600160a060020a03871680855290835292819020859055805185815290519293927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a35050565b64e8d4a5100090565b600160a060020a03919091166000908152600460209081526040808320938352929052205490565b60008181526002602052604081205460ff16151561037b57600080fd5b50600090815260016020526040902054600160a060020a031690565b60008181526005602090815260409182902080548351601f600260001961010060018616150201909316929092049182018490048402810184019094528084526060939283018282801561042c5780601f106104015761010080835404028352916020019161042c565b820191906000526020600020905b81548152906001019060200180831161040f57829003601f168201915b50505050509050919050565b600160a060020a031660009081526020819052604090205490565b60408051808201909152600581527f5437323154000000000000000000000000000000000000000000000000000000602082015290565b6000818152600260205260408120543391849160ff1615156104ab57600080fd5b6104b48461035e565b600160a060020a038481169116146104cb57600080fd5b600160a060020a0383811690831614156104e457600080fd5b600160a060020a03821615156104f957600080fd5b508161050581856106a7565b600160a060020a0381811660008181526020818152604080832080546000190190558883526001808352818420805473ffffffffffffffffffffffffffffffffffffffff19169689169687179055858452838352928190208054909301909255815188815291517fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050505050565b600081815260026020526040812054819060ff1615156105bc57600080fd5b6105c58361035e565b9150339050600160a060020a0382168114156105e057600080fd5b600160a060020a03808316600090815260036020908152604080832093851683529290522054831461061157600080fd5b600160a060020a0382811660008181526020818152604080832080546000190190558783526001808352818420805473ffffffffffffffffffffffffffffffffffffffff19169688169687179055858452838352928190208054909301909255815187815291517fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a3505050565b60005b600160a060020a0383166000908152600460209081526040808320848452909152902054821461070057600160a060020a03831660009081526004602090815260408083208484529091528120556001016106aa565b5050505600a165627a7a72305820d3ca2ca957b72f4c5028c633a6ad4bafe13572bf949793fabe72e34eb640d2c50029"; + //String code = "608060405234801561001057600080fd5b50610731806100206000396000f3006080604052600436106100a35763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166306fdde0381146100a8578063095ea7b31461013257806318160ddd146101585780632f745c591461017f5780636352211e146101a35780636914db60146101d757806370a08231146101ef57806395d89b4114610210578063a9059cbb14610225578063b2e6ceeb14610249575b600080fd5b3480156100b457600080fd5b506100bd610261565b6040805160208082528351818301528351919283929083019185019080838360005b838110156100f75781810151838201526020016100df565b50505050905090810190601f1680156101245780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561013e57600080fd5b50610156600160a060020a0360043516602435610298565b005b34801561016457600080fd5b5061016d61032d565b60408051918252519081900360200190f35b34801561018b57600080fd5b5061016d600160a060020a0360043516602435610336565b3480156101af57600080fd5b506101bb60043561035e565b60408051600160a060020a039092168252519081900360200190f35b3480156101e357600080fd5b506100bd600435610397565b3480156101fb57600080fd5b5061016d600160a060020a0360043516610438565b34801561021c57600080fd5b506100bd610453565b34801561023157600080fd5b50610156600160a060020a036004351660243561048a565b34801561025557600080fd5b5061015660043561059d565b60408051808201909152601181527f54726f6e2045524337323120546f6b656e000000000000000000000000000000602082015290565b6102a18161035e565b600160a060020a031633146102b557600080fd5b33600160a060020a03831614156102cb57600080fd5b336000818152600360209081526040808320600160a060020a03871680855290835292819020859055805185815290519293927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a35050565b64e8d4a5100090565b600160a060020a03919091166000908152600460209081526040808320938352929052205490565b60008181526002602052604081205460ff16151561037b57600080fd5b50600090815260016020526040902054600160a060020a031690565b60008181526005602090815260409182902080548351601f600260001961010060018616150201909316929092049182018490048402810184019094528084526060939283018282801561042c5780601f106104015761010080835404028352916020019161042c565b820191906000526020600020905b81548152906001019060200180831161040f57829003601f168201915b50505050509050919050565b600160a060020a031660009081526020819052604090205490565b60408051808201909152600581527f5437323154000000000000000000000000000000000000000000000000000000602082015290565b6000818152600260205260408120543391849160ff1615156104ab57600080fd5b6104b48461035e565b600160a060020a038481169116146104cb57600080fd5b600160a060020a0383811690831614156104e457600080fd5b600160a060020a03821615156104f957600080fd5b508161050581856106a7565b600160a060020a0381811660008181526020818152604080832080546000190190558883526001808352818420805473ffffffffffffffffffffffffffffffffffffffff19169689169687179055858452838352928190208054909301909255815188815291517fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050505050565b600081815260026020526040812054819060ff1615156105bc57600080fd5b6105c58361035e565b9150339050600160a060020a0382168114156105e057600080fd5b600160a060020a03808316600090815260036020908152604080832093851683529290522054831461061157600080fd5b600160a060020a0382811660008181526020818152604080832080546000190190558783526001808352818420805473ffffffffffffffffffffffffffffffffffffffff19169688169687179055858452838352928190208054909301909255815187815291517fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a3505050565b60005b600160a060020a0383166000908152600460209081526040808320848452909152902054821461070057600160a060020a03831660009081526004602090815260408083208484529091528120556001016106aa565b5050505600a165627a7a72305820d3ca2ca957b72f4c5028c633a6ad4bafe13572bf949793fabe72e34eb640d2c50029"; String code = "60806040" + getRandomCode(2734) + getRandomCode(1000) + "0029"; - String abi = "[{\"constant\":true,\"inputs\":[],\"name\":\"name\",\"outputs\":[{\"name\":\"_name\",\"type\":\"string\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"totalSupply\",\"outputs\":[{\"name\":\"_totalSupply\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"decimals\",\"outputs\":[{\"name\":\"_decimals\",\"type\":\"uint8\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"MAX_UINT256\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_owner\",\"type\":\"address\"}],\"name\":\"balanceOf\",\"outputs\":[{\"name\":\"balance\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"symbol\",\"outputs\":[{\"name\":\"_symbol\",\"type\":\"string\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_to\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"transfer\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_to\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"},{\"name\":\"_data\",\"type\":\"bytes\"}],\"name\":\"transfer\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_to\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"},{\"name\":\"_data\",\"type\":\"bytes\"},{\"name\":\"_custom_fallback\",\"type\":\"string\"}],\"name\":\"transfer\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"_from\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"_to\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_value\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"_data\",\"type\":\"bytes\"}],\"name\":\"Transfer\",\"type\":\"event\"}]"; + String abi = "[{\"constant\":true,\"inputs\":[],\"name\":\"name\",\"outputs\":[{\"name\":\"_name\",\"type\":\"string\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"totalSupply1\",\"outputs\":[{\"name\":\"_totalSupply1\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"decimals\",\"outputs\":[{\"name\":\"_decimals\",\"type\":\"uint8\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"MAX_UINT256\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_owner\",\"type\":\"address\"}],\"name\":\"balanceOf\",\"outputs\":[{\"name\":\"balance\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"symbol\",\"outputs\":[{\"name\":\"_symbol\",\"type\":\"string\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_to\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"transfer\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_to\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"},{\"name\":\"_data\",\"type\":\"bytes\"}],\"name\":\"transfer\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_to\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"},{\"name\":\"_data\",\"type\":\"bytes\"},{\"name\":\"_custom_fallback\",\"type\":\"string\"}],\"name\":\"transfer\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"_from\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"_to\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_value\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"_data\",\"type\":\"bytes\"}],\"name\":\"Transfer\",\"type\":\"event\"}]"; txid = PublicMethed.deployContractAndGetTransactionInfoById(contractName,abi,code,"", maxFeeLimit, 0L, 100,null,testNetAccountKey,testNetAccountAddress,blockingStubFull); logger.info("createGen0 " + txid); infoById = PublicMethed.getTransactionInfoById(txid,blockingStubFull); energyTotal = infoById.get().getReceipt().getEnergyUsageTotal(); - writeCsv("","","", "","",txid,energyTotal.toString()); + writeCsv(code,abi,"", "","",txid,energyTotal.toString()); } //final SmartContract smartContract = PublicMethed.getContract(contractAddress, @@ -121,6 +125,46 @@ public void testExceptionCodeAndAbi() { //logger.info(smartContract.getAbi().toString()); } + @Test(enabled = false) + public void testtimeout() { + String txid; + Long energyTotal; + String contractName = "timeout"; + String code = "6080604052600060035534801561001557600080fd5b5061027b806100256000396000f3006080604052600436106100825763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416633755cd3c81146100875780637d965688146100b1578063a05b2577146100c9578063b0d6304d146100e1578063bbe1d75b14610115578063f8a8fd6d1461012a578063fe75faab14610141575b600080fd5b34801561009357600080fd5b5061009f600435610159565b60408051918252519081900360200190f35b3480156100bd57600080fd5b5061009f600435610178565b3480156100d557600080fd5b5061009f600435610198565b3480156100ed57600080fd5b5061009f73ffffffffffffffffffffffffffffffffffffffff600435811690602435166101e2565b34801561012157600080fd5b5061009f6101ff565b34801561013657600080fd5b5061013f610205565b005b34801561014d57600080fd5b5061009f600435610218565b600080548290811061016757fe5b600091825260209091200154905081565b600080805b83811015610191576001918201910161017d565b5092915050565b600080805b838110156101915760008054600181810183559180527f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e56301829055918201910161019d565b600260209081526000928352604080842090915290825290205481565b60015481565b600380546001019055610216610205565b565b60006102238261022e565b600181905592915050565b600061023c6002830361022e565b6102486001840361022e565b01929150505600a165627a7a7230582077fd7ac1cd0908622d05db388922d485d6f8e3a546590b97ec8398f87f0c8a580029"; + String abi = "[{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"iarray\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"a\",\"type\":\"uint256\"}],\"name\":\"testUseCpu\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"a\",\"type\":\"uint256\"}],\"name\":\"testUseStorage\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"address\"},{\"name\":\"\",\"type\":\"address\"}],\"name\":\"m\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"calculatedFibNumber\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"test\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"n\",\"type\":\"uint256\"}],\"name\":\"setFibonacci\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]"; + contractAddress = PublicMethed.deployContract(contractName,abi,code,"", + 100000000000L, 0L, 100,null,testNetAccountKey,testNetAccountAddress,blockingStubFull); + //logger.info("timeout txid: " + txid); + Optional infoById = null; + //infoById = PublicMethed.getTransactionInfoById(txid,blockingStubFull); + Integer triggerNum = 24950; + Long energy; + while (triggerNum < 25820) { + txid = PublicMethed.triggerContract(contractAddress, + "testUseCpu(uint256)", triggerNum.toString(), false, + 0, 1000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull); + + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + infoById = PublicMethed.getTransactionInfoById(txid,blockingStubFull); + energy = infoById.get().getReceipt().getEnergyUsageTotal(); + + writeCsv(Integer.toString(infoById.get().getResultValue()),triggerNum.toString(), + energy.toString(), "","",txid,""); + if (triggerNum >= 25800) { + triggerNum = 24950; + } + triggerNum = triggerNum + 20; + + } + + + + } + @AfterClass public void shutdown() throws InterruptedException { if (channelFull != null) { @@ -143,13 +187,13 @@ public static void writeCsv(String feeString,String cpuFeeString,String cpuUsage String netUsageString, String netFeeString,String txid,String energyTotalString) { try { - File csv = new File("/Users/wangzihe/Documents/exceptionCode.csv"); + File csv = new File("/Users/wangzihe/Documents/timeoutCpuEnergy.csv"); String time = Long.toString(System.currentTimeMillis()); BufferedWriter bw = new BufferedWriter(new FileWriter(csv, true)); /* bw.write(time + "," + feeString + "," + cpuFeeString + "," + cpuUsageString + "," + netUsageString + "," + netFeeString + "," + txid);*/ - bw.write(time + "," + energyTotalString + "," + txid); + bw.write(time + "," + feeString + "," + cpuFeeString + "," + cpuUsageString + "," + txid); bw.newLine(); bw.close(); } catch (FileNotFoundException e) { diff --git a/src/test/java/stest/tron/wallet/onlineStress/TestNetFomo3D.java b/src/test/java/stest/tron/wallet/onlineStress/TestNetFomo3D.java index 10379c226fa..82f3eeca8fd 100644 --- a/src/test/java/stest/tron/wallet/onlineStress/TestNetFomo3D.java +++ b/src/test/java/stest/tron/wallet/onlineStress/TestNetFomo3D.java @@ -76,6 +76,15 @@ public void deployErc721CryptoKitties() { byte[] contractAddress = PublicMethed.deployContract(contractName,abi,code,"",maxFeeLimit, 0L, 100,null,testNetAccountKey,testNetAccountAddress,blockingStubFull); + + code = "608060405234801561001057600080fd5b5061011a806100206000396000f300608060405260043610603f576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063f8a8fd6d146044575b600080fd5b348015604f57600080fd5b506056606c565b6040518082815260200191505060405180910390f35b6000600180141515607c57600080fd5b603c80141515608a57600080fd5b610e1080141515609957600080fd5b620151808014151560a957600080fd5b62093a808014151560b957600080fd5b6301e133808014151560ca57600080fd5b620f42408014151560da57600080fd5b60018014151560e857600080fd5b429050905600a165627a7a72305820e8f9994ec320bbc329299a1cec491445178da2a60b219fb25e91adb9c4e4aa930029"; + abi = "[{\"constant\":false,\"inputs\":[],\"name\":\"test\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]"; + + String txid = PublicMethed.deployContractAndGetTransactionInfoById(contractName,abi, + code,"",maxFeeLimit, 0L, 100,null, + testNetAccountKey,testNetAccountAddress,blockingStubFull); + + final SmartContract smartContract = PublicMethed.getContract(contractAddress,blockingStubFull); accountResource = PublicMethed.getAccountResource(testNetAccountAddress,blockingStubFull); cpuLimit = accountResource.getEnergyLimit();