Skip to content
Merged
Show file tree
Hide file tree
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 @@ -83,6 +83,7 @@ public void testGetEnergy() {
Assert.assertTrue(account009Info.getAccountResource().getEnergyUsage() == 0);
Assert.assertTrue(account009Info.getAccountResource().getFrozenBalanceForEnergy()
.getExpireTime() == 0);

Assert.assertTrue(PublicMethed.freezeBalanceGetEnergy(account009Address, 1000000L,
3,1,account009Key,blockingStubFull));
account009Info = PublicMethed.queryAccount(account009Key,blockingStubFull);
Expand All @@ -92,7 +93,7 @@ public void testGetEnergy() {

AccountResourceMessage account009Resource = PublicMethed.getAccountResource(account009Address,
blockingStubFull);
Assert.assertTrue(account009Resource.getTotalEnergyLimit() == 32400000000L);
Assert.assertTrue(account009Resource.getTotalEnergyLimit() == 50000000000L);
Assert.assertTrue(account009Resource.getEnergyLimit() > 0);
Assert.assertTrue(account009Resource.getTotalEnergyWeight() >= 1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ public static byte[] getFinalAddress(String priKey) {
Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET);
WalletClient walletClient;
walletClient = new WalletClient(priKey);
walletClient.init(0);
//walletClient.init(0);
return walletClient.getAddress();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public class ContractLinkage004 {
private String fullnode = Configuration.getByPath("testng.conf")
.getStringList("fullnode.ip.list").get(0);

String contractName;
String code;
String abi;

ECKey ecKey1 = new ECKey(Utils.getRandom());
byte[] linkage004Address = ecKey1.getAddress();
String linkage004Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes());
Expand All @@ -54,6 +58,8 @@ public void beforeClass() {
blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
Assert.assertTrue(PublicMethed.sendcoin(linkage004Address,20000000L,fromAddress,
testKey003,blockingStubFull));
Assert.assertTrue(PublicMethed.freezeBalance(linkage004Address,1000000L,
3,linkage004Key,blockingStubFull));
}

@Test(enabled = true)
Expand All @@ -67,11 +73,9 @@ public void getTransactionInfoById() {

logger.info("before energy limit is " + Long.toString(energyLimit));
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;
String contractName = "tronNative";
String code = "608060405260008054600160a060020a03199081166201000117909155600180548216620100021"
final Long maxFeeLimit = 15000000L;
contractName = "tronNative";
code = "608060405260008054600160a060020a03199081166201000117909155600180548216620100021"
+ "790556002805482166201000317905560038054821662010004179055600480548216620100051790556005"
+ "8054821662010006179055600680549091166201000717905534801561007757600080fd5b506104ce80610"
+ "0876000396000f3006080604052600436106100da5763ffffffff7c01000000000000000000000000000000"
Expand Down Expand Up @@ -103,7 +107,7 @@ public void getTransactionInfoById() {
+ "00160a060020a0390931692818301926000928290030181855af45050505050565b600254604051600160a0"
+ "60020a03909116906000818181855af45050505600a165627a7a7230582076efe233a097282a46d3aefb879"
+ "b720ed02a4ad3c6cf053cc5936a01e366c7dc0029";
String abi = "[{\"constant\":false,\"inputs\":[{\"name\":\"frozen_Balance\",\"type\":\"uint256"
abi = "[{\"constant\":false,\"inputs\":[{\"name\":\"frozen_Balance\",\"type\":\"uint256"
+ "\"},{\"name\":\"frozen_Duration\",\"type\":\"uint256\"}],\"name\":\"freezeBalance\",\"o"
+ "utputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"}"
+ ",{\"constant\":true,\"inputs\":[],\"name\":\"deleteProposalAddress\",\"outputs\":[{\"na"
Expand Down Expand Up @@ -157,6 +161,39 @@ public void getTransactionInfoById() {
Assert.assertTrue(infoById.get().getReceipt().getEnergyUsage() == 0);
//Assert.assertTrue(infoById.get().getReceipt().getStorageFee() > 0);
//Assert.assertTrue(infoById.get().getReceipt().getStorageDelta() > 200);
}

@Test(enabled = false)
public void testFeeLimitIsTooSmall() {
Account account = PublicMethed.queryAccount(linkage004Address,blockingStubFull);
Long maxFeeLimit = 0L;
//When the fee limit is 0.
String txid = PublicMethed.deployContractAndGetTransactionInfoById(contractName,abi,code,
"",maxFeeLimit, 0L, 50,null,linkage004Key,linkage004Address,blockingStubFull);
logger.info("testFeeLimitIsTooSmall, the txid is " + txid);
Optional<TransactionInfo> infoById = PublicMethed.getTransactionInfoById(txid,blockingStubFull);
logger.info("0, Result valse is " + Integer.toString(infoById.get().getResultValue()));
Assert.assertTrue(infoById.get().getResultValue() == 1);

//When the fee limit is only short with 1 sun.
maxFeeLimit = 14082200L - 1L;
txid = PublicMethed.deployContractAndGetTransactionInfoById(contractName,abi,code,
"",maxFeeLimit, 0L, 50,null,linkage004Key,linkage004Address,blockingStubFull);
logger.info("testFeeLimitIsTooSmall, the txid is " + txid);
infoById = PublicMethed.getTransactionInfoById(txid,blockingStubFull);
logger.info("1000, Result value is " + Integer.toString(infoById.get().getResultValue()));
Assert.assertTrue(infoById.get().getResultValue() == 1);

//When the fee limit is just ok.
maxFeeLimit = 14082200L;
txid = PublicMethed.deployContractAndGetTransactionInfoById(contractName,abi,code,
"",maxFeeLimit, 0L, 50,null,linkage004Key,linkage004Address,blockingStubFull);
logger.info("testFeeLimitIsTooSmall, the txid is " + txid);
infoById = PublicMethed.getTransactionInfoById(txid,blockingStubFull);
logger.info("1000, Result value is " + Integer.toString(infoById.get().getResultValue()));
Assert.assertTrue(infoById.get().getResultValue() == 0);





Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,6 @@ public void triggerUseTriggerEnergyUsage() {

Assert.assertTrue(PublicMethed.freezeBalanceGetEnergy(triggerAddress,100000000L,
3,1,triggerKey,blockingStubFull));

txid = PublicMethed.triggerContract(kittyCoreContractAddress,
"createGen0Auction(uint256)", "0", false,
0, 100000000L, triggerAddress, triggerKey, blockingStubFull);
Expand All @@ -375,11 +374,6 @@ public void triggerUseTriggerEnergyUsage() {
Assert.assertTrue(infoById.get().getReceipt().getOriginEnergyUsage() > 10000);
Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() == infoById.get().getReceipt().getEnergyUsage() + infoById.get().getReceipt().getOriginEnergyUsage());
Assert.assertTrue(infoById.get().getReceipt().getEnergyUsage() == infoById.get().getReceipt().getOriginEnergyUsage());





}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
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 ContractScenario012 {

//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<TransactionInfo> infoById = null;

ECKey ecKey1 = new ECKey(Utils.getRandom());
byte[] contract012Address = ecKey1.getAddress();
String contract012Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes());

ECKey ecKey2 = new ECKey(Utils.getRandom());
byte[] receiverAddress = ecKey2.getAddress();
String receiverKey = ByteArray.toHexString(ecKey2.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(contract012Key);
PublicMethed.printAddress(receiverKey);
channelFull = ManagedChannelBuilder.forTarget(fullnode)
.usePlaintext(true)
.build();
blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
Assert.assertTrue(PublicMethed.sendcoin(contract012Address,2000000000L,fromAddress,
testKey002,blockingStubFull));
}

@Test(enabled = true)
public void deployTransactionCoin() {
AccountResourceMessage accountResource = PublicMethed.getAccountResource(contract012Address,
blockingStubFull);
Long energyLimit = accountResource.getEnergyLimit();
//Long storageLimit = accountResource.getStorageLimit();
Long energyUsage = accountResource.getEnergyUsed();
//Long storageUsage = accountResource.getStorageUsed();

logger.info("before energy limit is " + Long.toString(energyLimit));
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;
String contractName = "TransactionCoin";
String code = "60806040526000805561029f806100176000396000f3006080604052600436106100985763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166312065fe0811461009d5780632e52d606146100b7578063483f5a7f146100cc5780634f8632ba146100e25780635896476c146101135780638b47145f14610128578063b6b55f2514610144578063f46771d91461014f578063ff18253b14610163575b600080fd5b6100a561019b565b60408051918252519081900360200190f35b3480156100c357600080fd5b506100a56101a0565b6100e0600160a060020a03600435166101a6565b005b3480156100ee57600080fd5b506100f76101df565b60408051600160a060020a039092168252519081900360200190f35b34801561011f57600080fd5b506100e06101ee565b6101306101f9565b604080519115158252519081900360200190f35b610130600435610217565b6100e0600160a060020a036004351661023a565b34801561016f57600080fd5b5061017861026c565b60408051600160a060020a03909316835260208301919091528051918290030190f35b303190565b60005481565b604051600160a060020a038216903480156108fc02916000818181858888f193505050501580156101db573d6000803e3d6000fd5b5050565b600154600160a060020a031681565b600080546001019055565b6040516000903390829060019082818181858883f194505050505090565b604051600090339083156108fc0290849084818181858888f19695505050505050565b604051600160a060020a0382169060009060059082818181858883f193505050501580156101db573d6000803e3d6000fd5b33803190915600a165627a7a72305820fd081d59bd77b97252e4a657177023ae7352e1fe802dd638ec6b9fa5df59d6110029";
String abi = "[{\"constant\":false,\"inputs\":[],\"name\":\"getBalance\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"n\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_receiver\",\"type\":\"address\"}],\"name\":\"sendToAddress\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"user\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"nPlusOne\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"depositOneCoin\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"money\",\"type\":\"uint256\"}],\"name\":\"deposit\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_receiver\",\"type\":\"address\"}],\"name\":\"sendToAddress2\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"getSenderBalance\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"},{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"constructor\"}]";
contractAddress = PublicMethed.deployContract(contractName,abi,code,"",maxFeeLimit,
0L, 100,null,contract012Key,contract012Address,blockingStubFull);
SmartContract smartContract = PublicMethed.getContract(contractAddress,blockingStubFull);
Assert.assertTrue(smartContract.getAbi() != null);
}

@Test(enabled = false)
public void triggerTransactionCoin() {
//When the contract has no money,transaction coin failed.
String receiveAddress = "\"" + Base58.encode58Check(receiverAddress)
+ "\"";
txid = PublicMethed.triggerContract(contractAddress,
"sendToAddress2(address)", receiveAddress, false,
0, 100000000L, contract012Address, contract012Key, blockingStubFull);
logger.info(txid);
infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull);
Assert.assertTrue(infoById.get().getResultValue() == 1);
logger.info("energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal());
Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() > 0);
Assert.assertTrue(infoById.get().getFee() == infoById.get().getReceipt().getEnergyFee());
Assert.assertFalse(infoById.get().getContractAddress().isEmpty());

//Send some trx to the contract account.
Assert.assertTrue(PublicMethed.sendcoin(contractAddress,100000L,contract012Address,
contract012Key,blockingStubFull));


//This time, trigger the methed sendToAddress2 is OK.
txid = PublicMethed.triggerContract(contractAddress,
"sendToAddress2(address)", receiveAddress, false,
0, 100000000L, contract012Address, contract012Key, 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);
}
}
}