Skip to content

Commit

Permalink
Merge branch 'add_http_stest_case' of https://github.com/tronprotocol…
Browse files Browse the repository at this point in the history
…/java-tron into add_http_stest_case
  • Loading branch information
wangzihe committed Mar 6, 2019
2 parents 49a5eb1 + e11be72 commit ffd25d3
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3085,6 +3085,7 @@ public static boolean accountPermissionUpdate(String permissionJson, byte[] owne
*/
public static long getFreezeBalanceCount(byte[] accountAddress, String ecKey, Long targetEnergy,
WalletGrpc.WalletBlockingStub blockingStubFull) {
//Precision change as the entire network freezes
AccountResourceMessage resourceInfo = getAccountResource(accountAddress,
blockingStubFull);

Expand Down Expand Up @@ -3564,4 +3565,46 @@ public static TransactionApprovedList getTransactionApprovedList(Transaction tra
return blockingStubFull.getTransactionApprovedList(transaction);
}

/**
* constructor.
*/
public static long getFreezeBalanceNetCount(byte[] accountAddress, String ecKey, Long targetNet,
WalletGrpc.WalletBlockingStub blockingStubFull) {
//Precision change as the entire network freezes
AccountResourceMessage resourceInfo = getAccountResource(accountAddress,
blockingStubFull);

Account info = queryAccount(accountAddress, blockingStubFull);

Account getAccount = queryAccount(ecKey, blockingStubFull);

long balance = info.getBalance();
long totalNetLimit = resourceInfo.getTotalNetLimit();
long totalNetWeight = resourceInfo.getTotalNetWeight();
long netUsed = resourceInfo.getNetUsed();
long netLimit = resourceInfo.getNetLimit();

if (netUsed > netLimit) {
targetNet = netUsed - netLimit + targetNet;
}

if (totalNetWeight == 0) {
return 1000_000L;
}

// totalNetLimit / (totalNetWeight + needBalance) = needNet / needBalance
final BigInteger totalNetWeightBi = BigInteger.valueOf(totalNetWeight);
long needBalance = totalNetWeightBi.multiply(BigInteger.valueOf(1_000_000))
.multiply(BigInteger.valueOf(targetNet))
.divide(BigInteger.valueOf(totalNetLimit - targetNet)).longValue();

logger.info("getFreezeBalanceNetCount, needBalance: " + needBalance);

if (needBalance < 1000000L) {
needBalance = 1000000L;
logger.info(
"getFreezeBalanceNetCount, needBalance less than 1 TRX, modify to: " + needBalance);
}
return needBalance;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ public void beforeClass() {

@Test(enabled = true, description = "Trigger contract Divide 0")
public void test1DivideInt() {
PublicMethed
PublicMethed.waitProduceNextBlock(blockingStubFull);
Assert.assertTrue(PublicMethed
.sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey,
blockingStubFull);
blockingStubFull));
PublicMethed.waitProduceNextBlock(blockingStubFull);

String contractName = "divideInt";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ public void test1Grammar001() {
ecKey1 = new ECKey(Utils.getRandom());
grammarAddress = ecKey1.getAddress();
testKeyForGrammarAddress = ByteArray.toHexString(ecKey1.getPrivKeyBytes());
PublicMethed
PublicMethed.waitProduceNextBlock(blockingStubFull);
Assert.assertTrue(PublicMethed
.sendcoin(grammarAddress, 100000000000L, testNetAccountAddress, testNetAccountKey,
blockingStubFull);
blockingStubFull));
PublicMethed.waitProduceNextBlock(blockingStubFull);
String contractName = "FunctionSelector";
String code = Configuration.getByPath("testng.conf")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@ public void beforeClass() {

@Test(enabled = true, description = "Interface type function")
public void test1Grammar007() {
PublicMethed
PublicMethed.waitProduceNextBlock(blockingStubFull);
Assert.assertTrue(PublicMethed
.sendcoin(grammarAddress2, 100000000000L, testNetAccountAddress, testNetAccountKey,
blockingStubFull);
blockingStubFull));
PublicMethed.waitProduceNextBlock(blockingStubFull);
String contractName = "dougContract";
String code = Configuration.getByPath("testng.conf")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ public void test1Grammar014() {
ecKey1 = new ECKey(Utils.getRandom());
grammarAddress3 = ecKey1.getAddress();
testKeyForGrammarAddress3 = ByteArray.toHexString(ecKey1.getPrivKeyBytes());

PublicMethed
PublicMethed.waitProduceNextBlock(blockingStubFull);
Assert.assertTrue(PublicMethed
.sendcoin(grammarAddress3, 100000000000L, testNetAccountAddress, testNetAccountKey,
blockingStubFull);
blockingStubFull));
PublicMethed.waitProduceNextBlock(blockingStubFull);
String contractName = "aContract";
String code = Configuration.getByPath("testng.conf")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ public void beforeClass() {

@Test(enabled = true, description = "Create->call.Two-level nesting")
public void testInternalTransaction001() {
PublicMethed
PublicMethed.waitProduceNextBlock(blockingStubFull);
Assert.assertTrue(PublicMethed
.sendcoin(internalTxsAddress, 100000000000L, testNetAccountAddress, testNetAccountKey,
blockingStubFull);
blockingStubFull));
PublicMethed.waitProduceNextBlock(blockingStubFull);
String contractName = "FunctionSelector";
String code = "6080604052610452806100136000396000f3006080604052600436106100325763ffffffff60e06"
Expand Down Expand Up @@ -198,9 +199,9 @@ public void testInternalTransaction001() {

@Test(enabled = true, description = "There is one internalTransaction.Only call")
public void testInternalTransaction002() {
PublicMethed
Assert.assertTrue(PublicMethed
.sendcoin(internalTxsAddress, 100000000000L, testNetAccountAddress, testNetAccountKey,
blockingStubFull);
blockingStubFull));
PublicMethed.waitProduceNextBlock(blockingStubFull);
PublicMethed.waitProduceNextBlock(blockingStubFull);
String contractName = "AContract";
Expand Down Expand Up @@ -258,9 +259,9 @@ public void testInternalTransaction002() {

@Test(enabled = true, description = "There is one internalTransaction.Only create")
public void testInternalTransaction003() {
PublicMethed
Assert.assertTrue(PublicMethed
.sendcoin(internalTxsAddress, 100000000000L, testNetAccountAddress, testNetAccountKey,
blockingStubFull);
blockingStubFull));
PublicMethed.waitProduceNextBlock(blockingStubFull);
String contractName = "AContract";
String code = "608060405260008055610296806100176000396000f30060806040526004361060525763fffffff"
Expand Down Expand Up @@ -315,9 +316,9 @@ public void testInternalTransaction003() {

@Test(enabled = true, description = "Test suicide type in internalTransaction")
public void testInternalTransaction004() {
PublicMethed
Assert.assertTrue(PublicMethed
.sendcoin(internalTxsAddress, 100000000000L, testNetAccountAddress, testNetAccountKey,
blockingStubFull);
blockingStubFull));
PublicMethed.waitProduceNextBlock(blockingStubFull);
PublicMethed.waitProduceNextBlock(blockingStubFull);
String contractName = "AAContract";
Expand Down Expand Up @@ -431,9 +432,9 @@ public void testInternalTransaction004() {

@Test(enabled = true, description = "Type is create call")
public void testInternalTransaction005() {
PublicMethed
Assert.assertTrue(PublicMethed
.sendcoin(internalTxsAddress, 100000000000L, testNetAccountAddress, testNetAccountKey,
blockingStubFull);
blockingStubFull));
PublicMethed.waitProduceNextBlock(blockingStubFull);
String contractName = "AAContract";
String code = "608060405261056d806100136000396000f3006080604052600436106100565763ffffffff7c010"
Expand Down Expand Up @@ -541,9 +542,9 @@ public void testInternalTransaction005() {

@Test(enabled = true, description = "Type is create call call")
public void testInternalTransaction006() {
PublicMethed
Assert.assertTrue(PublicMethed
.sendcoin(internalTxsAddress, 100000000000L, testNetAccountAddress, testNetAccountKey,
blockingStubFull);
blockingStubFull));
PublicMethed.waitProduceNextBlock(blockingStubFull);
String contractName = "AAContract";
String code = "608060405261056c806100136000396000f3006080604052600436106100565763ffffffff7c010"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ public void beforeClass() {

@Test(enabled = true, description = "Type is create create call call")
public void test1InternalTransaction007() {
PublicMethed
PublicMethed.waitProduceNextBlock(blockingStubFull);
Assert.assertTrue(PublicMethed
.sendcoin(internalTxsAddress, 100000000000L, testNetAccountAddress, testNetAccountKey,
blockingStubFull);
blockingStubFull));
PublicMethed.waitProduceNextBlock(blockingStubFull);
PublicMethed.waitProduceNextBlock(blockingStubFull);
String contractName = "AAContract";
Expand Down Expand Up @@ -209,9 +210,9 @@ public void test1InternalTransaction007() {

@Test(enabled = true, description = "Type is call call")
public void test2InternalTransaction008() {
PublicMethed
Assert.assertTrue(PublicMethed
.sendcoin(internalTxsAddress, 100000000000L, testNetAccountAddress, testNetAccountKey,
blockingStubFull);
blockingStubFull));
PublicMethed.waitProduceNextBlock(blockingStubFull);

String contractName = "AAContract";
Expand Down Expand Up @@ -419,9 +420,9 @@ public void test2InternalTransaction008() {

@Test(enabled = true, description = "Test suicide type in internalTransaction after call")
public void test3InternalTransaction009() {
PublicMethed
Assert.assertTrue(PublicMethed
.sendcoin(internalTxsAddress, 100000000000L, testNetAccountAddress, testNetAccountKey,
blockingStubFull);
blockingStubFull));
PublicMethed.waitProduceNextBlock(blockingStubFull);
String contractName = "AAContract";
String code = "608060405261043b806100136000396000f3006080604052600436106100405763ffffffff7"
Expand Down Expand Up @@ -595,9 +596,9 @@ public void test3InternalTransaction009() {

@Test(enabled = false, description = "Test maxfeelimit can trigger create type max time")
public void test4InternalTransaction010() {
PublicMethed
Assert.assertTrue(PublicMethed
.sendcoin(internalTxsAddress, 100000000000L, testNetAccountAddress, testNetAccountKey,
blockingStubFull);
blockingStubFull));
PublicMethed.waitProduceNextBlock(blockingStubFull);

String contractName = "AAContract";
Expand Down Expand Up @@ -768,9 +769,9 @@ public void test4InternalTransaction010() {

@Test(enabled = true, description = "Type is call create->call->call.Three-level nesting")
public void test5InternalTransaction012() {
PublicMethed
Assert.assertTrue(PublicMethed
.sendcoin(internalTxsAddress, 100000000000L, testNetAccountAddress, testNetAccountKey,
blockingStubFull);
blockingStubFull));
PublicMethed.waitProduceNextBlock(blockingStubFull);

String contractName = "AAContract";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ public void beforeClass() {

@Test(enabled = true, description = "Three-level nesting.Type is Create call->call->create")
public void testInternalTransaction013() {
PublicMethed
.sendcoin(internalTxsAddress, 100000000000L, testNetAccountAddress, testNetAccountKey,
blockingStubFull);
PublicMethed.waitProduceNextBlock(blockingStubFull);
Assert.assertTrue(PublicMethed
.sendcoin(internalTxsAddress, 100000000000L, testNetAccountAddress, testNetAccountKey,
blockingStubFull));
PublicMethed.waitProduceNextBlock(blockingStubFull);
String contractName = "AAContract";
String code = "6080604052610325806100136000396000f3006080604052600436106100325763ffff"
Expand Down Expand Up @@ -194,9 +194,9 @@ public void testInternalTransaction013() {

@Test(enabled = true, description = "Test delegatecall and callcode.")
public void testInternalTransaction014() {
PublicMethed
Assert.assertTrue(PublicMethed
.sendcoin(internalTxsAddress, 100000000000L, testNetAccountAddress, testNetAccountKey,
blockingStubFull);
blockingStubFull));
PublicMethed.waitProduceNextBlock(blockingStubFull);

String contractName = "AAContract";
Expand Down Expand Up @@ -377,9 +377,9 @@ public void testInternalTransaction014() {
@Test(enabled = true, description = "Three-level nesting.Type "
+ "is create call->call->create call->suicide")
public void testInternalTransaction015() {
PublicMethed
Assert.assertTrue(PublicMethed
.sendcoin(internalTxsAddress, 100000000000L, testNetAccountAddress, testNetAccountKey,
blockingStubFull);
blockingStubFull));
PublicMethed.waitProduceNextBlock(blockingStubFull);

String contractName = "AAContract";
Expand Down Expand Up @@ -491,9 +491,9 @@ public void testInternalTransaction015() {

@Test(enabled = false, description = "After create 80 times,then suicide")
public void testInternalTransaction016() {
PublicMethed
Assert.assertTrue(PublicMethed
.sendcoin(internalTxsAddress, 100000000000L, testNetAccountAddress, testNetAccountKey,
blockingStubFull);
blockingStubFull));
PublicMethed.waitProduceNextBlock(blockingStubFull);
String contractName = "AAContract";
String code = "608060405260008055611033806100176000396000f300608060405260043610610061576"
Expand Down Expand Up @@ -663,9 +663,9 @@ public void testInternalTransaction016() {

@Test(enabled = false, description = "After create 88 times,then suicide")
public void testInternalTransaction017() {
PublicMethed
Assert.assertTrue(PublicMethed
.sendcoin(internalTxsAddress, 100000000000L, testNetAccountAddress, testNetAccountKey,
blockingStubFull);
blockingStubFull));
PublicMethed.waitProduceNextBlock(blockingStubFull);
String contractName = "AAContract";
String code = "608060405260008055611f19806100176000396000f30060806040526004361061006157"
Expand Down Expand Up @@ -905,9 +905,9 @@ public void testInternalTransaction017() {

@Test(enabled = false, description = "Test maxfeelimit can trigger call create call max time")
public void testInternalTransaction018() {
PublicMethed
Assert.assertTrue(PublicMethed
.sendcoin(internalTxsAddress, 100000000000L, testNetAccountAddress, testNetAccountKey,
blockingStubFull);
blockingStubFull));
PublicMethed.waitProduceNextBlock(blockingStubFull);
PublicMethed.waitProduceNextBlock(blockingStubFull);

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

@Test(enabled = true)
public void testGrammar001() {
PublicMethed.waitProduceNextBlock(blockingStubFull);
Assert.assertTrue(PublicMethed
.sendcoin(grammarAddress, 1000000000L, testNetAccountAddress, testNetAccountKey,
blockingStubFull));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,10 @@ public void test1TestRequireContract() {
testKeyForAssetIssue016 = ByteArray.toHexString(ecKey1.getPrivKeyBytes());
logger.info(Long.toString(PublicMethed.queryAccount(testNetAccountKey, blockingStubFull)
.getBalance()));
PublicMethed
PublicMethed.waitProduceNextBlock(blockingStubFull);
Assert.assertTrue(PublicMethed
.sendcoin(asset016Address, 1000000000L, testNetAccountAddress, testNetAccountKey,
blockingStubFull);
blockingStubFull));

String contractName = "TestRequireContract";
String code = "608060405234801561001057600080fd5b5060b58061001f6000396000f30060806040526004361"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -620,8 +620,8 @@ public void testWitnessAddress05() {
logger.info("balanceAfter: " + balanceAfter);
Assert.assertEquals(balanceBefore, balanceAfter);

Assert.assertTrue(PublicMethed
.unFreezeBalance(fromAddress, testKey002, 0, ownerAddress, blockingStubFull));
PublicMethed
.unFreezeBalance(fromAddress, testKey002, 0, ownerAddress, blockingStubFull);
}

@Test(enabled = true, description = "Witness address account is 5")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public void testTokenBalanceContract() {
"getToken(trcToken)", tokenId, false, 0,
1000000000L, "0", 0, dev001Address, dev001Key,
blockingStubFull);

PublicMethed.waitProduceNextBlock(blockingStubFull);
infoById = PublicMethed
.getTransactionInfoById(triggerTxid, blockingStubFull);
Assert.assertTrue(infoById.get().getResultValue() != 0);
Expand All @@ -202,6 +202,7 @@ public void testTokenBalanceContract() {
"getToken(trcToken)", tokenId, false, 0,
1000000000L, "0", 0, dev001Address, dev001Key,
blockingStubFull);
PublicMethed.waitProduceNextBlock(blockingStubFull);
infoById = PublicMethed
.getTransactionInfoById(triggerTxid, blockingStubFull);
Assert.assertTrue(infoById.get().getResultValue() != 0);
Expand Down

0 comments on commit ffd25d3

Please sign in to comment.