Skip to content

Commit

Permalink
Add burntrx api test case
Browse files Browse the repository at this point in the history
  • Loading branch information
pangpangfeng committed Jan 13, 2021
1 parent f09bedb commit 32a9dbe
Show file tree
Hide file tree
Showing 3 changed files with 160 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2097,6 +2097,59 @@ public static HttpResponse getBlockBalance(String httpNode, Integer blockNum, St
return response;
}

/**
* constructor.
*/
public static Long getBurnTrx(String httpNode) {
try {
final String requestUrl = "http://" + httpNode + "/wallet/getburntrx";
JsonObject blockObj = new JsonObject();
response = createConnect(requestUrl, blockObj);
} catch (Exception e) {
e.printStackTrace();
httppost.releaseConnection();
return null;
}
responseContent = HttpMethed.parseResponseContent(response);
return responseContent.getLong("burnTrxAmount");
}

/**
* constructor.
*/
public static Long getBurnTrxFromSolidity(String httpNode) {
try {
final String requestUrl = "http://" + httpNode + "/walletsolidity/getburntrx";
JsonObject blockObj = new JsonObject();
response = createConnect(requestUrl, blockObj);
} catch (Exception e) {
e.printStackTrace();
httppost.releaseConnection();
return null;
}
responseContent = HttpMethed.parseResponseContent(response);
return responseContent.getLong("burnTrxAmount");
}

/**
* constructor.
*/
public static Long getBurnTrxFromPbft(String httpNode) {
try {
final String requestUrl = "http://" + httpNode + "/walletpbft/getburntrx";
JsonObject blockObj = new JsonObject();
response = createConnect(requestUrl, blockObj);
} catch (Exception e) {
e.printStackTrace();
httppost.releaseConnection();
return null;
}
responseContent = HttpMethed.parseResponseContent(response);
return responseContent.getLong("burnTrxAmount");
}




/**
* constructor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
import org.tron.api.GrpcAPI;
import org.tron.api.GrpcAPI.EmptyMessage;
import org.tron.api.WalletGrpc;
import org.tron.api.WalletSolidityGrpc;
import org.tron.common.crypto.ECKey;
import org.tron.common.parameter.CommonParameter;
import org.tron.common.utils.ByteArray;
Expand Down Expand Up @@ -58,13 +60,22 @@ public class TransactionFee001 {

private ManagedChannel channelFull = null;
private WalletGrpc.WalletBlockingStub blockingStubFull = null;
private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null;
private ManagedChannel channelSolidity = null;
private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubPbft = null;
private ManagedChannel channelPbft = null;


ECKey ecKey1 = new ECKey(Utils.getRandom());
byte[] deployAddress = ecKey1.getAddress();
final String deployKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes());

private String fullnode = Configuration.getByPath("testng.conf")
.getStringList("fullnode.ip.list").get(0);
private String soliditynode = Configuration.getByPath("testng.conf")
.getStringList("solidityNode.ip.list").get(0);
private String soliInPbft = Configuration.getByPath("testng.conf")
.getStringList("solidityNode.ip.list").get(2);

Long startNum = 0L;
Long endNum = 0L;
Expand All @@ -76,7 +87,8 @@ public class TransactionFee001 {
Long blackHoleBalance2 = 0L;
Long witness01Increase = 0L;
Long witness02Increase = 0L;
//Long blackHoleIncrease = 0L;
Long beforeBurnTrxAmount = 0L;
Long afterBurnTrxAmount = 0L;
String txid = null;


Expand All @@ -96,15 +108,22 @@ public void beforeClass() {
.usePlaintext(true)
.build();
blockingStubFull = WalletGrpc.newBlockingStub(channelFull);

channelSolidity = ManagedChannelBuilder.forTarget(soliditynode)
.usePlaintext(true)
.build();
blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity);
channelPbft = ManagedChannelBuilder.forTarget(soliInPbft)
.usePlaintext(true)
.build();
blockingStubPbft = WalletSolidityGrpc.newBlockingStub(channelPbft);
}

@Test(enabled = true, description = "Test deploy contract with energy fee to sr")
public void test01DeployContractEnergyFeeToSr() {

Assert.assertTrue(PublicMethed.sendcoin(deployAddress, 20000000000L, fromAddress,
testKey002, blockingStubFull));
PublicMethed.waitProduceNextBlock(blockingStubFull);
PublicMethed.waitProduceNextBlock(blockingStubFull);
PublicMethed.waitSolidityNodeSynFullNodeData(blockingStubFull,blockingStubSolidity);
String filePath = "src/test/resources/soliditycode//contractLinkage003.sol";
String contractName = "divideIHaveArgsReturnStorage";
HashMap retMap = null;
Expand All @@ -122,12 +141,13 @@ public void test01DeployContractEnergyFeeToSr() {
.getAllowance();
blackHoleBalance1 = PublicMethed.queryAccount(Commons.decode58Check(blackHoleAdd),
blockingStubFull).getBalance();
beforeBurnTrxAmount = blockingStubSolidity
.getBurnTrx(EmptyMessage.newBuilder().build()).getNum();

txid = PublicMethed
.deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit,
0L, 0, null,
txid = PublicMethed.deployContractAndGetTransactionInfoById(contractName, abi, code,
"", maxFeeLimit, 0L, 0, null,
deployKey, deployAddress, blockingStubFull);
PublicMethed.waitProduceNextBlock(blockingStubFull);
PublicMethed.waitSolidityNodeSynFullNodeData(blockingStubFull,blockingStubSolidity);

endNum = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build())
.getBlockHeader().getRawData().getNumber();
Expand Down Expand Up @@ -157,12 +177,14 @@ public void test01DeployContractEnergyFeeToSr() {
Optional<Protocol.TransactionInfo> infoById =
PublicMethed.getTransactionInfoById(txid, blockingStubFull);
Assert.assertEquals(infoById.get().getFee(),infoById.get().getPackingFee());
afterBurnTrxAmount = blockingStubSolidity
.getBurnTrx(EmptyMessage.newBuilder().build()).getNum();
Assert.assertEquals(beforeBurnTrxAmount,afterBurnTrxAmount);
}

@Test(enabled = true, description = "Test update account permission fee to black hole,"
+ "trans with multi sign and fee to sr")
public void test02UpdateAccountPermissionAndMultiSiginTrans() {

ECKey ecKey1 = new ECKey(Utils.getRandom());
byte[] ownerAddress = ecKey1.getAddress();
final String ownerKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes());
Expand All @@ -174,8 +196,7 @@ public void test02UpdateAccountPermissionAndMultiSiginTrans() {

Assert.assertTrue(PublicMethed.sendcoin(ownerAddress, needCoin + 1_000_000, fromAddress,
testKey002, blockingStubFull));
PublicMethed.waitProduceNextBlock(blockingStubFull);
PublicMethed.waitProduceNextBlock(blockingStubFull);
PublicMethed.waitSolidityNodeSynFullNodeData(blockingStubFull,blockingStubSolidity);
Long balanceBefore = PublicMethed.queryAccount(ownerAddress, blockingStubFull)
.getBalance();
logger.info("balanceBefore: " + balanceBefore);
Expand All @@ -197,6 +218,8 @@ public void test02UpdateAccountPermissionAndMultiSiginTrans() {
PublicMethed.queryAccount(witnessAddress02, blockingStubFull).getAllowance();
blackHoleBalance1 = PublicMethed.queryAccount(Commons.decode58Check(blackHoleAdd),
blockingStubFull).getBalance();
beforeBurnTrxAmount = blockingStubSolidity
.getBurnTrx(EmptyMessage.newBuilder().build()).getNum();
String accountPermissionJson =
"{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner1\","
+ "\"threshold\":1,\"keys\":["
Expand All @@ -217,8 +240,7 @@ public void test02UpdateAccountPermissionAndMultiSiginTrans() {
ownerAddress, ownerKey, blockingStubFull,
ownerPermissionKeys.toArray(new String[ownerPermissionKeys.size()]));

PublicMethed.waitProduceNextBlock(blockingStubFull);
PublicMethed.waitProduceNextBlock(blockingStubFull);
PublicMethed.waitSolidityNodeSynFullNodeData(blockingStubFull,blockingStubSolidity);
Optional<Protocol.TransactionInfo> infoById =
PublicMethed.getTransactionInfoById(txid, blockingStubFull);
Assert.assertEquals(infoById.get().getPackingFee(),0);
Expand Down Expand Up @@ -265,7 +287,7 @@ public void test02UpdateAccountPermissionAndMultiSiginTrans() {
logger.info(PublicMethedForMutiSign.printPermission(PublicMethed.queryAccount(ownerAddress,
blockingStubFull).getOwnerPermission()));

PublicMethed.waitProduceNextBlock(blockingStubFull);
//PublicMethed.waitSolidityNodeSynFullNodeData(blockingStubFull,blockingStubSolidity);

startNum = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build())
.getBlockHeader().getRawData().getNumber();
Expand All @@ -276,6 +298,14 @@ public void test02UpdateAccountPermissionAndMultiSiginTrans() {
blackHoleBalance1 = PublicMethed.queryAccount(Commons.decode58Check(blackHoleAdd),
blockingStubFull).getBalance();

afterBurnTrxAmount = blockingStubSolidity
.getBurnTrx(EmptyMessage.newBuilder().build()).getNum();
Assert.assertTrue(afterBurnTrxAmount - beforeBurnTrxAmount == 100000000L);


beforeBurnTrxAmount = blockingStubSolidity
.getBurnTrx(EmptyMessage.newBuilder().build()).getNum();

Protocol.Transaction transaction = PublicMethedForMutiSign
.sendcoin2(fromAddress, 1000_000, ownerAddress, ownerKey, blockingStubFull);
txid = ByteArray.toHexString(Sha256Hash
Expand All @@ -300,7 +330,7 @@ public void test02UpdateAccountPermissionAndMultiSiginTrans() {
logger.info("TransactionSignWeight info : " + txWeight);

Assert.assertTrue(PublicMethedForMutiSign.broadcastTransaction(transaction2, blockingStubFull));
PublicMethed.waitProduceNextBlock(blockingStubFull);
PublicMethed.waitSolidityNodeSynFullNodeData(blockingStubFull,blockingStubSolidity);

endNum = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build())
.getBlockHeader().getRawData().getNumber();
Expand Down Expand Up @@ -328,6 +358,9 @@ public void test02UpdateAccountPermissionAndMultiSiginTrans() {
infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull);
Assert.assertEquals(infoById.get().getPackingFee(),0);
Assert.assertEquals(infoById.get().getFee(),1000000L);
afterBurnTrxAmount = blockingStubSolidity
.getBurnTrx(EmptyMessage.newBuilder().build()).getNum();
Assert.assertTrue(afterBurnTrxAmount - beforeBurnTrxAmount == 1000000L);
}

@Test(enabled = true, description = "Test trigger result is \"OUT_OF_TIME\""
Expand All @@ -348,8 +381,7 @@ public void test03OutOfTimeEnergyFeeToBlackHole() {
contractAddress = PublicMethed.deployContract(contractName, abi, code,
"", maxFeeLimit,
0L, 100, null, deployKey, deployAddress, blockingStubFull);
PublicMethed.waitProduceNextBlock(blockingStubFull);
PublicMethed.waitProduceNextBlock(blockingStubFull);
PublicMethed.waitSolidityNodeSynFullNodeData(blockingStubFull,blockingStubSolidity);

startNum = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build())
.getBlockHeader().getRawData().getNumber();
Expand All @@ -359,11 +391,12 @@ public void test03OutOfTimeEnergyFeeToBlackHole() {
PublicMethed.queryAccount(witnessAddress02, blockingStubFull).getAllowance();
blackHoleBalance1 = PublicMethed.queryAccount(Commons.decode58Check(blackHoleAdd),
blockingStubFull).getBalance();
beforeBurnTrxAmount = blockingStubSolidity
.getBurnTrx(EmptyMessage.newBuilder().build()).getNum();
txid = PublicMethed.triggerContract(contractAddress,
"testUseCpu(uint256)", "90100", false,
0, maxFeeLimit, deployAddress, deployKey, blockingStubFull);
// PublicMethed.waitProduceNextBlock(blockingStubFull);
PublicMethed.waitProduceNextBlock(blockingStubFull);
PublicMethed.waitSolidityNodeSynFullNodeData(blockingStubFull,blockingStubSolidity);
endNum = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build())
.getBlockHeader().getRawData().getNumber();
witness01Allowance2 =
Expand Down Expand Up @@ -396,11 +429,13 @@ public void test03OutOfTimeEnergyFeeToBlackHole() {
logger.info("receipt:" + infoById.get().getReceipt());
Assert.assertTrue(packingFee == 0L);
Assert.assertTrue(infoById.get().getFee() >= maxFeeLimit);
afterBurnTrxAmount = blockingStubSolidity
.getBurnTrx(EmptyMessage.newBuilder().build()).getNum();
Assert.assertTrue(afterBurnTrxAmount - beforeBurnTrxAmount == maxFeeLimit);
}

@Test(enabled = true, description = "Test create account with netFee to sr")
public void test04AccountCreate() {
PublicMethed.waitProduceNextBlock(blockingStubFull);
startNum = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build())
.getBlockHeader().getRawData().getNumber();
witness01Allowance1 =
Expand All @@ -409,14 +444,15 @@ public void test04AccountCreate() {
PublicMethed.queryAccount(witnessAddress02, blockingStubFull).getAllowance();
blackHoleBalance1 = PublicMethed.queryAccount(Commons.decode58Check(blackHoleAdd),
blockingStubFull).getBalance();

beforeBurnTrxAmount = blockingStubSolidity
.getBurnTrx(EmptyMessage.newBuilder().build()).getNum();
ECKey ecKey = new ECKey(Utils.getRandom());
byte[] lowBalAddress = ecKey.getAddress();
txid = PublicMethed.createAccountGetTxid(fromAddress, lowBalAddress,
testKey002, blockingStubFull);

PublicMethed.waitProduceNextBlock(blockingStubFull);
PublicMethed.waitProduceNextBlock(blockingStubFull);

PublicMethed.waitSolidityNodeSynFullNodeData(blockingStubFull,blockingStubSolidity);
endNum = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build())
.getBlockHeader().getRawData().getNumber();
witness01Allowance2 =
Expand Down Expand Up @@ -445,6 +481,9 @@ public void test04AccountCreate() {
PublicMethed.getTransactionInfoById(txid, blockingStubFull);
Assert.assertTrue(infoById.get().getPackingFee() == 0L);
Assert.assertTrue(infoById.get().getFee() == 100000L);
afterBurnTrxAmount = blockingStubSolidity
.getBurnTrx(EmptyMessage.newBuilder().build()).getNum();
Assert.assertTrue(afterBurnTrxAmount - beforeBurnTrxAmount == 100000L);
}

@Test(enabled = true, description = "Test trigger contract with netFee and energyFee to sr")
Expand All @@ -470,8 +509,8 @@ public void test05NetFeeAndEnergyFee2Sr() {
"testUseCpu(uint256)", "700", false,
0, maxFeeLimit, deployAddress, deployKey, blockingStubFull);
}
PublicMethed.waitProduceNextBlock(blockingStubFull);
PublicMethed.waitProduceNextBlock(blockingStubFull);

PublicMethed.waitSolidityNodeSynFullNodeData(blockingStubFull,blockingStubSolidity);

startNum = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build())
.getBlockHeader().getRawData().getNumber();
Expand All @@ -481,11 +520,13 @@ public void test05NetFeeAndEnergyFee2Sr() {
PublicMethed.queryAccount(witnessAddress02, blockingStubFull).getAllowance();
blackHoleBalance1 = PublicMethed.queryAccount(Commons.decode58Check(blackHoleAdd),
blockingStubFull).getBalance();
beforeBurnTrxAmount = blockingStubSolidity
.getBurnTrx(EmptyMessage.newBuilder().build()).getNum();
txid = PublicMethed.triggerContract(contractAddress,
"testUseCpu(uint256)", "700", false,
0, maxFeeLimit, deployAddress, deployKey, blockingStubFull);
// PublicMethed.waitProduceNextBlock(blockingStubFull);
PublicMethed.waitProduceNextBlock(blockingStubFull);
PublicMethed.waitSolidityNodeSynFullNodeData(blockingStubFull,blockingStubSolidity);
endNum = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build())
.getBlockHeader().getRawData().getNumber();
witness01Allowance2 =
Expand All @@ -512,6 +553,9 @@ public void test05NetFeeAndEnergyFee2Sr() {
Assert.assertTrue((Math.abs(witnessAllowance.get(ByteArray.toHexString(witnessAddress02))
- witness02Increase)) <= 2);
Assert.assertEquals(blackHoleBalance1,blackHoleBalance2);
afterBurnTrxAmount = blockingStubSolidity
.getBurnTrx(EmptyMessage.newBuilder().build()).getNum();
Assert.assertEquals(beforeBurnTrxAmount,afterBurnTrxAmount);
}

/**
Expand All @@ -530,7 +574,7 @@ public void test06CreateAssetIssue() {
Assert.assertTrue(PublicMethed
.sendcoin(tokenAccountAddress, 1028000000L, fromAddress, testKey002, blockingStubFull));

PublicMethed.waitProduceNextBlock(blockingStubFull);
PublicMethed.waitSolidityNodeSynFullNodeData(blockingStubFull,blockingStubSolidity);
startNum = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build())
.getBlockHeader().getRawData().getNumber();
witness01Allowance1 =
Expand All @@ -539,7 +583,8 @@ public void test06CreateAssetIssue() {
PublicMethed.queryAccount(witnessAddress02, blockingStubFull).getAllowance();
blackHoleBalance1 = PublicMethed.queryAccount(Commons.decode58Check(blackHoleAdd),
blockingStubFull).getBalance();

beforeBurnTrxAmount = blockingStubSolidity
.getBurnTrx(EmptyMessage.newBuilder().build()).getNum();
Long start = System.currentTimeMillis() + 2000;
Long end = System.currentTimeMillis() + 1000000000;
long now = System.currentTimeMillis();
Expand All @@ -551,7 +596,7 @@ public void test06CreateAssetIssue() {
1, 1, start, end, 1, description, url, 0L,
0L, 1L, 1L, tokenAccountKey,
blockingStubFull);
PublicMethed.waitProduceNextBlock(blockingStubFull);
PublicMethed.waitSolidityNodeSynFullNodeData(blockingStubFull,blockingStubSolidity);

endNum = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build())
.getBlockHeader().getRawData().getNumber();
Expand Down Expand Up @@ -581,6 +626,16 @@ public void test06CreateAssetIssue() {
PublicMethed.getTransactionInfoById(txid, blockingStubFull);
Assert.assertTrue(infoById.get().getPackingFee() == 0L);
Assert.assertTrue(infoById.get().getFee() == 1024000000L);
afterBurnTrxAmount = blockingStubSolidity
.getBurnTrx(EmptyMessage.newBuilder().build()).getNum();
Assert.assertTrue(afterBurnTrxAmount - beforeBurnTrxAmount == 1024000000L);

Assert.assertEquals(blockingStubFull
.getBurnTrx(EmptyMessage.newBuilder().build()),blockingStubSolidity.getBurnTrx(
EmptyMessage.newBuilder().build()));
Assert.assertEquals(blockingStubFull.getBurnTrx(EmptyMessage.newBuilder().build()),
blockingStubPbft.getBurnTrx(
EmptyMessage.newBuilder().build()));
}
/**
* constructor.
Expand Down
Loading

0 comments on commit 32a9dbe

Please sign in to comment.