Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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;
Expand All @@ -17,6 +18,7 @@
import org.tron.core.Wallet;
import org.tron.protos.Protocol.Account;
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.PublicMethed;
Expand Down Expand Up @@ -53,10 +55,6 @@ public void beforeClass() {
blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
Assert.assertTrue(PublicMethed.sendcoin(linkage001Address,20000000L,fromAddress,
testKey002,blockingStubFull));
Assert.assertTrue(PublicMethed.freezeBalanceGetEnergy(linkage001Address, 5000000L,
3,1,linkage001Key,blockingStubFull));
/* Assert.assertTrue(PublicMethed.buyStorage(5000000L,linkage001Address,linkage001Key,
blockingStubFull));*/

}

Expand All @@ -68,6 +66,19 @@ public void deployContentValue() {

String payableCode = "608060405260008054600160a060020a03199081166201000117909155600180548216620100021790556002805482166201000317905560038054821662010004179055600480548216620100051790556005805482166201000617905560068054909116620100071790556104ce8061007a6000396000f3006080604052600436106100da5763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416630a90265081146100df5780630dfb51ac146100fc57806345bd20101461012d5780634efaaa1b1461014257806352ae1b811461016657806353c4263f1461017b5780635fd8c710146101905780637c369c90146101a55780637f2b7f93146101ba5780638259d5531461020f578063906fbec914610227578063961a8be71461023c578063cee14bb414610251578063ec9928bd14610275578063fb4f32aa14610292575b600080fd5b3480156100eb57600080fd5b506100fa6004356024356102a7565b005b34801561010857600080fd5b506101116102dc565b60408051600160a060020a039092168252519081900360200190f35b34801561013957600080fd5b506101116102eb565b34801561014e57600080fd5b506100fa600160a060020a03600435166024356102fa565b34801561017257600080fd5b50610111610320565b34801561018757600080fd5b5061011161032f565b34801561019c57600080fd5b506100fa61033e565b3480156101b157600080fd5b5061011161035d565b3480156101c657600080fd5b50604080516020600480358082013583810280860185019096528085526100fa9536959394602494938501929182918501908490808284375094975061036c9650505050505050565b34801561021b57600080fd5b506100fa6004356103c6565b34801561023357600080fd5b506101116103f7565b34801561024857600080fd5b50610111610406565b34801561025d57600080fd5b506100fa600160a060020a0360043516602435610415565b34801561028157600080fd5b506100fa600435602435151561044d565b34801561029e57600080fd5b506100fa610483565b60015460408051848152602081018490528151600160a060020a0390931692818301926000928290030181855af45050505050565b600654600160a060020a031681565b600354600160a060020a031681565b816080528060a0526000608060406080620100016000f4151561031c57600080fd5b5050565b600254600160a060020a031681565b600454600160a060020a031681565b600354604051600160a060020a03909116906000818181855af4505050565b600554600160a060020a031681565b6005546040518251600160a060020a039092169183919081906020808501910280838360005b838110156103aa578181015183820152602001610392565b50505050905001915050600060405180830381855af450505050565b600654604080518381529051600160a060020a039092169160208083019260009291908290030181855af450505050565b600054600160a060020a031681565b600154600160a060020a031681565b6000805460408051600160a060020a03868116825260208201869052825193169381830193909290918290030181855af45050505050565b6004546040805184815283151560208201528151600160a060020a0390931692818301926000928290030181855af45050505050565b600254604051600160a060020a03909116906000818181855af45050505600a165627a7a72305820bf65c4013bea4495f2cbccf685ee1442e2585d226cf4bd8184c636cdd1d485dc0029";
String payableAbi = "[{\"constant\":false,\"inputs\":[{\"name\":\"frozen_Balance\",\"type\":\"uint256\"},{\"name\":\"frozen_Duration\",\"type\":\"uint256\"}],\"name\":\"freezeBalance\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"deleteProposalAddress\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"withdrawBalanceAddress\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"witnessAddr\",\"type\":\"address\"},{\"name\":\"voteValue\",\"type\":\"uint256\"}],\"name\":\"voteUsingAssembly\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"unFreezeBalanceAddress\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"approveProposalAddress\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"withdrawBalance\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"createProposalAddress\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"data\",\"type\":\"bytes32[]\"}],\"name\":\"createProposal\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"id\",\"type\":\"uint256\"}],\"name\":\"deleteProposal\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"voteContractAddress\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"freezeBalanceAddress\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"witnessAddr\",\"type\":\"address\"},{\"name\":\"voteValue\",\"type\":\"uint256\"}],\"name\":\"voteForSingleWitness\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"id\",\"type\":\"uint256\"},{\"name\":\"isApprove\",\"type\":\"bool\"}],\"name\":\"approveProposal\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"unFreezeBalance\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"constructor\"}]";

Long maxFeeLimit = 20000000L;
//Value is equal balance,this will be failed.
String txid = PublicMethed.deployContractAndGetTransactionInfoById(contractName,payableAbi,
payableCode,"",maxFeeLimit, 20000000L, 100,null,
linkage001Key,linkage001Address,blockingStubFull);
Optional<TransactionInfo> infoById = null;
infoById = PublicMethed.getTransactionInfoById(txid,blockingStubFull);
Assert.assertTrue(infoById.get().getResultValue() == 1);

Assert.assertTrue(PublicMethed.freezeBalanceGetEnergy(linkage001Address, 5000000L,
3,1,linkage001Key,blockingStubFull));
maxFeeLimit = 20000000L - 5000000L;
AccountResourceMessage accountResource = PublicMethed.getAccountResource(linkage001Address,
blockingStubFull);
Long energyLimit = accountResource.getEnergyLimit();
Expand All @@ -79,16 +90,19 @@ public void deployContentValue() {
logger.info("before energy usage is " + Long.toString(energyUsage));
//logger.info("before storage limit is " + Long.toString(storageLimit));
//logger.info("before storage usaged is " + Long.toString(storageUsage));
Long maxFeeLimit = 5000000L;


Account account = PublicMethed.queryAccount(linkage001Key,blockingStubFull);
Long beforeAccountBalance = account.getBalance();
logger.info("before balance is " + Long.toString(account.getBalance()));
//Value is 1
txid = PublicMethed.deployContractAndGetTransactionInfoById(contractName,payableAbi,payableCode,
"",maxFeeLimit, 1L, 100,null,linkage001Key,
linkage001Address,blockingStubFull);
infoById = PublicMethed.getTransactionInfoById(txid,blockingStubFull);
Assert.assertTrue(infoById.get().getResultValue() == 0);
byte[] contractAddress = infoById.get().getContractAddress().toByteArray();

//Value is 1 drop.
byte [] contractAddress = PublicMethed.deployContract(contractName,payableAbi,payableCode,"",maxFeeLimit,
1L, 100,null,linkage001Key,linkage001Address,blockingStubFull);
SmartContract smartContract = PublicMethed.getContract(contractAddress,blockingStubFull);

accountResource = PublicMethed.getAccountResource(linkage001Address,blockingStubFull);
energyLimit = accountResource.getEnergyLimit();
Expand All @@ -112,18 +126,27 @@ public void deployContentValue() {
//Value is account all balance plus 1.
account = PublicMethed.queryAccount(linkage001Key,blockingStubFull);
Long valueBalance = account.getBalance();
contractAddress = PublicMethed.deployContract(contractName,payableAbi,payableCode,"",maxFeeLimit,
valueBalance + 1, 100,null,linkage001Key,linkage001Address,blockingStubFull);
contractAddress = PublicMethed.deployContract(contractName,payableAbi,payableCode,"",
maxFeeLimit, valueBalance + 1, 100,null,linkage001Key,
linkage001Address,blockingStubFull);
Assert.assertTrue(contractAddress == null);

//Value is account all balance.
Assert.assertTrue(PublicMethed.freezeBalance(linkage001Address, 5000000L,
3,linkage001Key,blockingStubFull));
account = PublicMethed.queryAccount(linkage001Key,blockingStubFull);
valueBalance = account.getBalance();
contractAddress = PublicMethed.deployContract(contractName,payableAbi,payableCode,"",maxFeeLimit,
valueBalance, 100,null,linkage001Key,linkage001Address,blockingStubFull);
smartContract = PublicMethed.getContract(contractAddress,blockingStubFull);
Assert.assertTrue(PublicMethed.queryAccount(linkage001Key,blockingStubFull).getBalance() == 0);
Assert.assertTrue(PublicMethed.queryAccount(contractAddress,blockingStubFull).getBalance() == valueBalance);
txid = PublicMethed.deployContractAndGetTransactionInfoById(contractName,payableAbi,payableCode,
"",maxFeeLimit, valueBalance, 100,null,linkage001Key,
linkage001Address,blockingStubFull);
infoById = PublicMethed.getTransactionInfoById(txid,blockingStubFull);
Assert.assertTrue(infoById.get().getResultValue() == 0);
contractAddress = infoById.get().getContractAddress().toByteArray();

Assert.assertTrue(PublicMethed.queryAccount(linkage001Key,blockingStubFull)
.getBalance() == 0);
Assert.assertTrue(PublicMethed.queryAccount(contractAddress,blockingStubFull)
.getBalance() == valueBalance);



Expand Down