From b4bfe5e9064147da215d4af51cac62c97e4a50db Mon Sep 17 00:00:00 2001 From: xiechang33 <354035097@qq.com> Date: Mon, 29 Apr 2019 18:46:13 +0800 Subject: [PATCH 01/90] add tvm stest --- .../common/client/utils/PublicMethed.java | 290 ++++++++++++++++++ .../client/utils/PublicMethedForMutiSign.java | 90 ++++++ .../resources/soliditycode/ClearAbi001.sol | 7 + .../resources/soliditycode/ClearAbi005.sol | 26 ++ .../soliditycode/ShiftCommand001.sol | 18 ++ .../soliditycode/TriggerConstant001.sol | 10 + .../soliditycode/TriggerConstant002.sol | 10 + .../soliditycode/TriggerConstant003.sol | 8 + .../soliditycode/TriggerConstant004.sol | 8 + .../soliditycode/TriggerConstant015.sol | 24 ++ .../soliditycode/TvmNewCommand043.sol | 18 ++ .../soliditycode/TvmNewCommand103.sol | 8 + .../soliditycode/TvmNewCommand107.sol | 9 + .../soliditycode/TvmNewCommand108.sol | 7 + .../soliditycode/TvmNewCommand109.sol | 7 + .../soliditycode/TvmOldCommand001.sol | 11 + 16 files changed, 551 insertions(+) create mode 100644 src/test/resources/soliditycode/ClearAbi001.sol create mode 100644 src/test/resources/soliditycode/ClearAbi005.sol create mode 100644 src/test/resources/soliditycode/ShiftCommand001.sol create mode 100644 src/test/resources/soliditycode/TriggerConstant001.sol create mode 100644 src/test/resources/soliditycode/TriggerConstant002.sol create mode 100644 src/test/resources/soliditycode/TriggerConstant003.sol create mode 100644 src/test/resources/soliditycode/TriggerConstant004.sol create mode 100644 src/test/resources/soliditycode/TriggerConstant015.sol create mode 100644 src/test/resources/soliditycode/TvmNewCommand043.sol create mode 100644 src/test/resources/soliditycode/TvmNewCommand103.sol create mode 100644 src/test/resources/soliditycode/TvmNewCommand107.sol create mode 100644 src/test/resources/soliditycode/TvmNewCommand108.sol create mode 100644 src/test/resources/soliditycode/TvmNewCommand109.sol create mode 100644 src/test/resources/soliditycode/TvmOldCommand001.sol diff --git a/src/test/java/stest/tron/wallet/common/client/utils/PublicMethed.java b/src/test/java/stest/tron/wallet/common/client/utils/PublicMethed.java index 3ecb6beed9d..eb82f070cfe 100644 --- a/src/test/java/stest/tron/wallet/common/client/utils/PublicMethed.java +++ b/src/test/java/stest/tron/wallet/common/client/utils/PublicMethed.java @@ -3701,4 +3701,294 @@ public static HashMap getBycodeAbiForLibrary(String solFile, return retMap; } + public static String triggerConstantContract(byte[] contractAddress, String method, + String argsStr, + Boolean isHex, long callValue, long feeLimit, String tokenId, long tokenValue, + byte[] ownerAddress, + String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + ECKey temKey = null; + try { + BigInteger priK = new BigInteger(priKey, 16); + temKey = ECKey.fromPrivate(priK); + } catch (Exception ex) { + ex.printStackTrace(); + } + final ECKey ecKey = temKey; + if (argsStr.equalsIgnoreCase("#")) { + logger.info("argsstr is #"); + argsStr = ""; + } + + byte[] owner = ownerAddress; + byte[] input = Hex.decode(AbiUtil.parseMethod(method, argsStr, isHex)); + + Contract.TriggerSmartContract.Builder builder = Contract.TriggerSmartContract.newBuilder(); + builder.setOwnerAddress(ByteString.copyFrom(owner)); + builder.setContractAddress(ByteString.copyFrom(contractAddress)); + builder.setData(ByteString.copyFrom(input)); + builder.setCallValue(callValue); + builder.setTokenId(Long.parseLong(tokenId)); + builder.setCallTokenValue(tokenValue); + Contract.TriggerSmartContract triggerContract = builder.build(); + + TransactionExtention transactionExtention = blockingStubFull + .triggerConstantContract(triggerContract); + if (transactionExtention == null || !transactionExtention.getResult().getResult()) { + System.out.println("RPC create call trx failed!"); + System.out.println("Code = " + transactionExtention.getResult().getCode()); + System.out + .println("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); + return null; + } + Transaction transaction = transactionExtention.getTransaction(); + if (transaction.getRetCount() != 0 + && transactionExtention.getConstantResult(0) != null + && transactionExtention.getResult() != null) { + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + System.out.println("message:" + transaction.getRet(0).getRet()); + System.out.println(":" + ByteArray + .toStr(transactionExtention.getResult().getMessage().toByteArray())); + System.out.println("Result:" + Hex.toHexString(result)); + return null; + } + + final TransactionExtention.Builder texBuilder = TransactionExtention.newBuilder(); + Transaction.Builder transBuilder = Transaction.newBuilder(); + Transaction.raw.Builder rawBuilder = transactionExtention.getTransaction().getRawData() + .toBuilder(); + rawBuilder.setFeeLimit(feeLimit); + transBuilder.setRawData(rawBuilder); + for (int i = 0; i < transactionExtention.getTransaction().getSignatureCount(); i++) { + ByteString s = transactionExtention.getTransaction().getSignature(i); + transBuilder.setSignature(i, s); + } + for (int i = 0; i < transactionExtention.getTransaction().getRetCount(); i++) { + Result r = transactionExtention.getTransaction().getRet(i); + transBuilder.setRet(i, r); + } + texBuilder.setTransaction(transBuilder); + texBuilder.setResult(transactionExtention.getResult()); + texBuilder.setTxid(transactionExtention.getTxid()); + transactionExtention = texBuilder.build(); + if (transactionExtention == null) { + return null; + } + Return ret = transactionExtention.getResult(); + if (!ret.getResult()) { + System.out.println("Code = " + ret.getCode()); + System.out.println("Message = " + ret.getMessage().toStringUtf8()); + return null; + } + transaction = transactionExtention.getTransaction(); + if (transaction == null || transaction.getRawData().getContractCount() == 0) { + System.out.println("Transaction is empty"); + return null; + } + transaction = signTransaction(ecKey, transaction); + System.out.println( + "trigger txid = " + ByteArray.toHexString(Sha256Hash.hash(transaction.getRawData() + .toByteArray()))); + GrpcAPI.Return response = broadcastTransaction(transaction, blockingStubFull); + if (response.getResult() == false) { + return null; + } else { + return ByteArray.toHexString(Sha256Hash.hash(transaction.getRawData().toByteArray())); + } + } + + public static String clearContractABI(byte[] contractAddress, + byte[] ownerAddress, + String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + ECKey temKey = null; + try { + BigInteger priK = new BigInteger(priKey, 16); + temKey = ECKey.fromPrivate(priK); + } catch (Exception ex) { + ex.printStackTrace(); + } + final ECKey ecKey = temKey; + + byte[] owner = ownerAddress; + + Contract.ClearABIContract.Builder builder = Contract.ClearABIContract + .newBuilder(); + builder.setOwnerAddress(ByteString.copyFrom(owner)); + builder.setContractAddress(ByteString.copyFrom(contractAddress)); + + Contract.ClearABIContract clearABIContract = builder.build(); + + TransactionExtention transactionExtention = blockingStubFull + .clearContractABI(clearABIContract); + if (transactionExtention == null || !transactionExtention.getResult().getResult()) { + System.out.println("RPC create call trx failed!"); + System.out.println("Code = " + transactionExtention.getResult().getCode()); + System.out + .println("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); + return null; + } + Transaction transaction = transactionExtention.getTransaction(); + if (transaction.getRetCount() != 0 + && transactionExtention.getConstantResult(0) != null + && transactionExtention.getResult() != null) { + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + System.out.println("message:" + transaction.getRet(0).getRet()); + System.out.println(":" + ByteArray + .toStr(transactionExtention.getResult().getMessage().toByteArray())); + System.out.println("Result:" + Hex.toHexString(result)); + return null; + } + + final TransactionExtention.Builder texBuilder = TransactionExtention.newBuilder(); + Transaction.Builder transBuilder = Transaction.newBuilder(); + Transaction.raw.Builder rawBuilder = transactionExtention.getTransaction().getRawData() + .toBuilder(); + transBuilder.setRawData(rawBuilder); + for (int i = 0; i < transactionExtention.getTransaction().getSignatureCount(); i++) { + ByteString s = transactionExtention.getTransaction().getSignature(i); + transBuilder.setSignature(i, s); + } + for (int i = 0; i < transactionExtention.getTransaction().getRetCount(); i++) { + Result r = transactionExtention.getTransaction().getRet(i); + transBuilder.setRet(i, r); + } + texBuilder.setTransaction(transBuilder); + texBuilder.setResult(transactionExtention.getResult()); + texBuilder.setTxid(transactionExtention.getTxid()); + transactionExtention = texBuilder.build(); + if (transactionExtention == null) { + return null; + } + Return ret = transactionExtention.getResult(); + if (!ret.getResult()) { + System.out.println("Code = " + ret.getCode()); + System.out.println("Message = " + ret.getMessage().toStringUtf8()); + return null; + } + transaction = transactionExtention.getTransaction(); + if (transaction == null || transaction.getRawData().getContractCount() == 0) { + System.out.println("Transaction is empty"); + return null; + } + transaction = signTransaction(ecKey, transaction); + System.out.println( + "trigger txid = " + ByteArray.toHexString(Sha256Hash.hash(transaction.getRawData() + .toByteArray()))); + GrpcAPI.Return response = broadcastTransaction(transaction, blockingStubFull); + if (response.getResult() == false) { + return null; + } else { + return ByteArray.toHexString(Sha256Hash.hash(transaction.getRawData().toByteArray())); + } + } + + + public static TransactionExtention clearContractABIForExtention(byte[] contractAddress, + byte[] ownerAddress, + String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + ECKey temKey = null; + try { + BigInteger priK = new BigInteger(priKey, 16); + temKey = ECKey.fromPrivate(priK); + } catch (Exception ex) { + ex.printStackTrace(); + } + final ECKey ecKey = temKey; + + byte[] owner = ownerAddress; + + Contract.ClearABIContract.Builder builder = Contract.ClearABIContract + .newBuilder(); + builder.setOwnerAddress(ByteString.copyFrom(owner)); + builder.setContractAddress(ByteString.copyFrom(contractAddress)); + + Contract.ClearABIContract clearABIContract = builder.build(); + + TransactionExtention transactionExtention = blockingStubFull + .clearContractABI(clearABIContract); + return transactionExtention; + + } + + + public static TransactionExtention triggerConstantContractForExtention(byte[] contractAddress, + String method, + String argsStr, + Boolean isHex, long callValue, long feeLimit, String tokenId, long tokenValue, + byte[] ownerAddress, + String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + ECKey temKey = null; + try { + BigInteger priK = new BigInteger(priKey, 16); + temKey = ECKey.fromPrivate(priK); + } catch (Exception ex) { + ex.printStackTrace(); + } + final ECKey ecKey = temKey; + if (argsStr.equalsIgnoreCase("#")) { + logger.info("argsstr is #"); + argsStr = ""; + } + + byte[] owner = ownerAddress; + byte[] input = Hex.decode(AbiUtil.parseMethod(method, argsStr, isHex)); + + Contract.TriggerSmartContract.Builder builder = Contract.TriggerSmartContract.newBuilder(); + builder.setOwnerAddress(ByteString.copyFrom(owner)); + builder.setContractAddress(ByteString.copyFrom(contractAddress)); + builder.setData(ByteString.copyFrom(input)); + builder.setCallValue(callValue); + builder.setTokenId(Long.parseLong(tokenId)); + builder.setCallTokenValue(tokenValue); + Contract.TriggerSmartContract triggerContract = builder.build(); + + TransactionExtention transactionExtention = blockingStubFull + .triggerConstantContract(triggerContract); + return transactionExtention; + + } + + /** + * constructor. + */ + + public static TransactionExtention triggerContractForExtention(byte[] contractAddress, + String method, String argsStr, + Boolean isHex, long callValue, long feeLimit, String tokenId, long tokenValue, + byte[] ownerAddress, + String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + ECKey temKey = null; + try { + BigInteger priK = new BigInteger(priKey, 16); + temKey = ECKey.fromPrivate(priK); + } catch (Exception ex) { + ex.printStackTrace(); + } + final ECKey ecKey = temKey; + if (argsStr.equalsIgnoreCase("#")) { + logger.info("argsstr is #"); + argsStr = ""; + } + + byte[] owner = ownerAddress; + byte[] input = Hex.decode(AbiUtil.parseMethod(method, argsStr, isHex)); + + Contract.TriggerSmartContract.Builder builder = Contract.TriggerSmartContract.newBuilder(); + builder.setOwnerAddress(ByteString.copyFrom(owner)); + builder.setContractAddress(ByteString.copyFrom(contractAddress)); + builder.setData(ByteString.copyFrom(input)); + builder.setCallValue(callValue); + builder.setTokenId(Long.parseLong(tokenId)); + builder.setCallTokenValue(tokenValue); + Contract.TriggerSmartContract triggerContract = builder.build(); + + TransactionExtention transactionExtention = blockingStubFull.triggerContract(triggerContract); + return transactionExtention; + + } + } \ No newline at end of file diff --git a/src/test/java/stest/tron/wallet/common/client/utils/PublicMethedForMutiSign.java b/src/test/java/stest/tron/wallet/common/client/utils/PublicMethedForMutiSign.java index e82dc0420ea..27fc1ff6156 100644 --- a/src/test/java/stest/tron/wallet/common/client/utils/PublicMethedForMutiSign.java +++ b/src/test/java/stest/tron/wallet/common/client/utils/PublicMethedForMutiSign.java @@ -4510,4 +4510,94 @@ public static Boolean exchangeCreate1(byte[] firstTokenId, long firstTokenBalanc return broadcastTransaction(transaction, blockingStubFull); } + + + public static boolean clearContractABI(byte[] contractAddress, + byte[] ownerAddress, + String priKey, WalletGrpc.WalletBlockingStub blockingStubFull, int permissionId, + String[] permissionKeyString) { + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + ECKey temKey = null; + try { + BigInteger priK = new BigInteger(priKey, 16); + temKey = ECKey.fromPrivate(priK); + } catch (Exception ex) { + ex.printStackTrace(); + } + final ECKey ecKey = temKey; + + byte[] owner = ownerAddress; + + Contract.ClearABIContract.Builder builder = Contract.ClearABIContract + .newBuilder(); + builder.setOwnerAddress(ByteString.copyFrom(owner)); + builder.setContractAddress(ByteString.copyFrom(contractAddress)); + + Contract.ClearABIContract clearABIContract = builder.build(); + + TransactionExtention transactionExtention = blockingStubFull + .clearContractABI(clearABIContract); + if (transactionExtention == null || !transactionExtention.getResult().getResult()) { + System.out.println("RPC create call trx failed!"); + System.out.println("Code = " + transactionExtention.getResult().getCode()); + System.out + .println("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); + return false; + } + Transaction transaction = transactionExtention.getTransaction(); + if (transaction.getRetCount() != 0 + && transactionExtention.getConstantResult(0) != null + && transactionExtention.getResult() != null) { + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + System.out.println("message:" + transaction.getRet(0).getRet()); + System.out.println(":" + ByteArray + .toStr(transactionExtention.getResult().getMessage().toByteArray())); + System.out.println("Result:" + Hex.toHexString(result)); + return false; + } + + final TransactionExtention.Builder texBuilder = TransactionExtention.newBuilder(); + Transaction.Builder transBuilder = Transaction.newBuilder(); + Transaction.raw.Builder rawBuilder = transactionExtention.getTransaction().getRawData() + .toBuilder(); + transBuilder.setRawData(rawBuilder); + for (int i = 0; i < transactionExtention.getTransaction().getSignatureCount(); i++) { + ByteString s = transactionExtention.getTransaction().getSignature(i); + transBuilder.setSignature(i, s); + } + for (int i = 0; i < transactionExtention.getTransaction().getRetCount(); i++) { + Result r = transactionExtention.getTransaction().getRet(i); + transBuilder.setRet(i, r); + } + texBuilder.setTransaction(transBuilder); + texBuilder.setResult(transactionExtention.getResult()); + texBuilder.setTxid(transactionExtention.getTxid()); + transactionExtention = texBuilder.build(); + if (transactionExtention == null) { + return false; + } + Return ret = transactionExtention.getResult(); + if (!ret.getResult()) { + System.out.println("Code = " + ret.getCode()); + System.out.println("Message = " + ret.getMessage().toStringUtf8()); + return false; + } + transaction = transactionExtention.getTransaction(); + if (transaction == null || transaction.getRawData().getContractCount() == 0) { + System.out.println("Transaction is empty"); + return false; + } + try { + transaction = setPermissionId(transaction, permissionId); + } catch (CancelException e) { + e.printStackTrace(); + } + transaction = signTransaction(transaction, blockingStubFull, permissionKeyString); + System.out.println( + "trigger txid = " + ByteArray.toHexString(Sha256Hash.hash(transaction.getRawData() + .toByteArray()))); + return broadcastTransaction(transaction, blockingStubFull); + + } + } diff --git a/src/test/resources/soliditycode/ClearAbi001.sol b/src/test/resources/soliditycode/ClearAbi001.sol new file mode 100644 index 00000000000..fccc59e14be --- /dev/null +++ b/src/test/resources/soliditycode/ClearAbi001.sol @@ -0,0 +1,7 @@ +//pragma solidity ^0.4.0; + +contract testConstantContract{ +function testPayable() public view returns (int z) { +return 1; +} +} \ No newline at end of file diff --git a/src/test/resources/soliditycode/ClearAbi005.sol b/src/test/resources/soliditycode/ClearAbi005.sol new file mode 100644 index 00000000000..a3115398386 --- /dev/null +++ b/src/test/resources/soliditycode/ClearAbi005.sol @@ -0,0 +1,26 @@ +contract Factory { + event Deployed(address addr, uint256 salt, address sender); + function deploy(bytes memory code, uint256 salt) public returns(address){ + address addr; + assembly { + addr := create2(0, add(code, 0x20), mload(code), salt) + if iszero(extcodesize(addr)) { + revert(0, 0) + } + } + emit Deployed(addr, salt, msg.sender); + return addr; + } +} + + + +contract TestConstract { + uint public i=0; + constructor () public { + } + function plusOne() public returns(uint){ + i++; + return i; + } +} \ No newline at end of file diff --git a/src/test/resources/soliditycode/ShiftCommand001.sol b/src/test/resources/soliditycode/ShiftCommand001.sol new file mode 100644 index 00000000000..574ee2b571b --- /dev/null +++ b/src/test/resources/soliditycode/ShiftCommand001.sol @@ -0,0 +1,18 @@ +contract TestBitwiseShift { + + function shlTest(uint256 num, uint256 input) public returns (bytes32 out) { + assembly { + out := shl(num, input) + } + } + function shrTest(uint256 num, uint256 input) public returns (bytes32 out) { + assembly { + out := shr(num, input) + } + } + function sarTest(uint256 num, uint256 input) public returns (bytes32 out) { + assembly { + out := sar(num, input) + } + } + } \ No newline at end of file diff --git a/src/test/resources/soliditycode/TriggerConstant001.sol b/src/test/resources/soliditycode/TriggerConstant001.sol new file mode 100644 index 00000000000..56e04e4584c --- /dev/null +++ b/src/test/resources/soliditycode/TriggerConstant001.sol @@ -0,0 +1,10 @@ +//pragma solidity ^0.4.0; + +contract testConstantContract{ +uint256 public i; +function testPayable() public payable returns (uint256 z) { +i=1; +z=i; +return z; +} +} \ No newline at end of file diff --git a/src/test/resources/soliditycode/TriggerConstant002.sol b/src/test/resources/soliditycode/TriggerConstant002.sol new file mode 100644 index 00000000000..44332e58c51 --- /dev/null +++ b/src/test/resources/soliditycode/TriggerConstant002.sol @@ -0,0 +1,10 @@ +//pragma solidity ^0.4.0; + +contract testConstantContract{ + uint256 public i; + function testNoPayable() public returns (uint256 z) { + i=1; + z=i; + return z; + } + } \ No newline at end of file diff --git a/src/test/resources/soliditycode/TriggerConstant003.sol b/src/test/resources/soliditycode/TriggerConstant003.sol new file mode 100644 index 00000000000..bc9270b2135 --- /dev/null +++ b/src/test/resources/soliditycode/TriggerConstant003.sol @@ -0,0 +1,8 @@ +//pragma solidity ^0.4.0; + +contract testConstantContract{ +function testView() public view returns (uint256 z) { +uint256 i=1; +return i; +} +} \ No newline at end of file diff --git a/src/test/resources/soliditycode/TriggerConstant004.sol b/src/test/resources/soliditycode/TriggerConstant004.sol new file mode 100644 index 00000000000..fce77178ca7 --- /dev/null +++ b/src/test/resources/soliditycode/TriggerConstant004.sol @@ -0,0 +1,8 @@ +//pragma solidity ^0.4.0; + +contract testConstantContract{ +function testPure() public pure returns (uint256 z) { +uint256 i=1; +return i; +} +} \ No newline at end of file diff --git a/src/test/resources/soliditycode/TriggerConstant015.sol b/src/test/resources/soliditycode/TriggerConstant015.sol new file mode 100644 index 00000000000..d926c43c824 --- /dev/null +++ b/src/test/resources/soliditycode/TriggerConstant015.sol @@ -0,0 +1,24 @@ +contract Factory { + event Deployed(address addr, uint256 salt, address sender); + function deploy(bytes memory code, uint256 salt) public returns(address){ + address addr; + assembly { + addr := create2(0, add(code, 0x20), mload(code), salt) + if iszero(extcodesize(addr)) { + revert(0, 0) + } + } + emit Deployed(addr, salt, msg.sender); + return addr; + } +} + + + +contract TestConstract { + constructor () public { + } + function plusOne() public returns(uint){ + return 1; + } +} \ No newline at end of file diff --git a/src/test/resources/soliditycode/TvmNewCommand043.sol b/src/test/resources/soliditycode/TvmNewCommand043.sol new file mode 100644 index 00000000000..04d9f7dde28 --- /dev/null +++ b/src/test/resources/soliditycode/TvmNewCommand043.sol @@ -0,0 +1,18 @@ +contract TestBitwiseShift { + + function shlTest(int256 num, int256 input) public returns (bytes32 out) { + assembly { + out := shl(num, input) + } + } + function shrTest(int256 num, int256 input) public returns (bytes32 out) { + assembly { + out := shr(num, input) + } + } + function sarTest(int256 num, int256 input) public returns (bytes32 out) { + assembly { + out := sar(num, input) + } + } + } \ No newline at end of file diff --git a/src/test/resources/soliditycode/TvmNewCommand103.sol b/src/test/resources/soliditycode/TvmNewCommand103.sol new file mode 100644 index 00000000000..7ad130c87c6 --- /dev/null +++ b/src/test/resources/soliditycode/TvmNewCommand103.sol @@ -0,0 +1,8 @@ +//pragma solidity ^0.4.0; + +contract testConstantContract{ +function testView() public constant returns (uint256 z) { +uint256 i=1; +return i; +} +} \ No newline at end of file diff --git a/src/test/resources/soliditycode/TvmNewCommand107.sol b/src/test/resources/soliditycode/TvmNewCommand107.sol new file mode 100644 index 00000000000..4dcd33ad7b0 --- /dev/null +++ b/src/test/resources/soliditycode/TvmNewCommand107.sol @@ -0,0 +1,9 @@ +//pragma solidity ^0.4.0; + + contract testConstantContract{ + int256 public i; + function testPayable() public returns (int z) { + z=1+1; + return z; + } + } \ No newline at end of file diff --git a/src/test/resources/soliditycode/TvmNewCommand108.sol b/src/test/resources/soliditycode/TvmNewCommand108.sol new file mode 100644 index 00000000000..b44d5c82731 --- /dev/null +++ b/src/test/resources/soliditycode/TvmNewCommand108.sol @@ -0,0 +1,7 @@ +//pragma solidity ^0.4.0; + + contract testConstantContract{ + function test() pure public returns (int z) { + return 1; + } + } \ No newline at end of file diff --git a/src/test/resources/soliditycode/TvmNewCommand109.sol b/src/test/resources/soliditycode/TvmNewCommand109.sol new file mode 100644 index 00000000000..864f01f7fb4 --- /dev/null +++ b/src/test/resources/soliditycode/TvmNewCommand109.sol @@ -0,0 +1,7 @@ +//pragma solidity ^0.4.0; + + contract testConstantContract{ + function test() view public returns (int z) { + return 1; + } + } \ No newline at end of file diff --git a/src/test/resources/soliditycode/TvmOldCommand001.sol b/src/test/resources/soliditycode/TvmOldCommand001.sol new file mode 100644 index 00000000000..9f3cf079ea1 --- /dev/null +++ b/src/test/resources/soliditycode/TvmOldCommand001.sol @@ -0,0 +1,11 @@ +//pragma solidity ^0.4.0; + +contract binaryRightContract{ + function binaryMoveR(int i)public returns (int z) { + return z = 5 >> i; + } + function binaryLiftR(int i)public returns (int z) { + return z = 5 << i; + } + +} \ No newline at end of file From dfb4eb8541a441405b3a80a05d239329d03bcc15 Mon Sep 17 00:00:00 2001 From: xiechang33 <354035097@qq.com> Date: Mon, 29 Apr 2019 18:51:39 +0800 Subject: [PATCH 02/90] add tvm stest --- .../tvmnewcommand/clearabi/ClearAbi001.java | 168 ++ .../tvmnewcommand/clearabi/ClearAbi002.java | 161 ++ .../tvmnewcommand/clearabi/ClearAbi003.java | 160 ++ .../tvmnewcommand/clearabi/ClearAbi004.java | 127 ++ .../tvmnewcommand/clearabi/ClearAbi005.java | 209 +++ .../tvmnewcommand/clearabi/ClearAbi006.java | 129 ++ .../tvmnewcommand/clearabi/ClearAbi007.java | 140 ++ .../tvmnewcommand/clearabi/ClearAbi008.java | 174 ++ .../shiftcommand/ShiftCommand001.java | 260 +++ .../shiftcommand/ShiftCommand002.java | 283 +++ .../shiftcommand/ShiftCommand003.java | 352 ++++ .../shiftcommand/ShiftCommand004.java | 1099 +++++++++++ .../shiftcommand/ShiftCommand005.java | 1104 +++++++++++ .../shiftcommand/ShiftCommand006.java | 1620 +++++++++++++++++ .../triggerconstant/TriggerConstant001.java | 163 ++ .../triggerconstant/TriggerConstant002.java | 162 ++ .../triggerconstant/TriggerConstant003.java | 162 ++ .../triggerconstant/TriggerConstant004.java | 164 ++ .../triggerconstant/TriggerConstant005.java | 164 ++ .../triggerconstant/TriggerConstant006.java | 163 ++ .../triggerconstant/TriggerConstant007.java | 164 ++ .../triggerconstant/TriggerConstant008.java | 164 ++ .../triggerconstant/TriggerConstant009.java | 188 ++ .../triggerconstant/TriggerConstant010.java | 188 ++ .../triggerconstant/TriggerConstant011.java | 188 ++ .../triggerconstant/TriggerConstant012.java | 188 ++ .../triggerconstant/TriggerConstant013.java | 226 +++ .../triggerconstant/TriggerConstant014.java | 227 +++ .../triggerconstant/TriggerConstant015.java | 211 +++ .../triggerconstant/TriggerConstant016.java | 206 +++ .../triggerconstant/TriggerConstant017.java | 186 ++ .../triggerconstant/TriggerConstant018.java | 162 ++ .../triggerconstant/TriggerConstant019.java | 186 ++ .../triggerconstant/TriggerConstant020.java | 186 ++ .../triggerconstant/TriggerConstant021.java | 162 ++ .../triggerconstant/TriggerConstant022.java | 161 ++ .../triggerconstant/TriggerConstant023.java | 161 ++ .../triggerconstant/TriggerConstant024.java | 169 ++ .../triggerconstant/TriggerConstant025.java | 169 ++ .../triggerconstant/TriggerConstant026.java | 171 ++ .../soliditycode/TriggerConstant024.sol | 9 + 41 files changed, 10636 insertions(+) create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi001.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi002.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi003.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi004.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi005.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi006.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi007.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi008.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand001.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand002.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand003.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand004.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand005.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand006.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant001.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant002.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant003.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant004.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant005.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant006.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant007.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant008.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant009.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant010.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant011.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant012.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant013.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant014.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant015.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant016.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant017.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant018.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant019.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant020.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant021.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant022.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant023.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant024.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant025.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant026.java create mode 100644 src/test/resources/soliditycode/TriggerConstant024.sol diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi001.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi001.java new file mode 100644 index 00000000000..30bfad351a3 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi001.java @@ -0,0 +1,168 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.clearabi; + +import static org.hamcrest.core.StringContains.containsString; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +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.GrpcAPI.TransactionExtention; +import org.tron.api.WalletGrpc; +import org.tron.api.WalletSolidityGrpc; +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.SmartContract; +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 ClearAbi001 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + ECKey ecKey2 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress1 = ecKey2.getAddress(); + String contractExcKey1 = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + @Test(enabled = true, description = "Clear a contract created by other account") + public void testClearAbi() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress1, 10000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/ClearAbi001.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); + Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + + TransactionExtention transactionExtention = PublicMethed + .clearContractABIForExtention(contractAddress, contractExcAddress1, contractExcKey1, + blockingStubFull); + Assert + .assertThat(transactionExtention.getResult().getCode().toString(), + containsString("CONTRACT_VALIDATE_ERROR")); + Assert + .assertThat(transactionExtention.getResult().getMessage().toStringUtf8(), + containsString("is not the owner of the contract")); + + smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); + Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + + + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi002.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi002.java new file mode 100644 index 00000000000..ba3bdca020a --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi002.java @@ -0,0 +1,161 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.clearabi; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +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.api.WalletSolidityGrpc; +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.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; + +@Slf4j +public class ClearAbi002 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + @Test(enabled = true, description = "Clear a contract with ABI created by itself") + public void testClearAbi() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/ClearAbi001.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); + Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + + String txid = PublicMethed + .clearContractABI(contractAddress, contractExcAddress, contractExcKey, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(infoById.get().getResultValue() == 0); + + smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); + Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + + + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi003.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi003.java new file mode 100644 index 00000000000..f4100ebafdc --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi003.java @@ -0,0 +1,160 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.clearabi; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +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.api.WalletSolidityGrpc; +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.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; + +@Slf4j +public class ClearAbi003 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + @Test(enabled = true, description = "Clear a contract without ABI") + public void testClearAbi() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/ClearAbi001.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, "[]", code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); + Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + + String txid = PublicMethed + .clearContractABI(contractAddress, contractExcAddress, contractExcKey, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Assert.assertTrue(infoById.get().getResultValue() == 0); + + smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); + Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + + + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi004.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi004.java new file mode 100644 index 00000000000..3c0b7f1f460 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi004.java @@ -0,0 +1,127 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.clearabi; + +import static org.hamcrest.core.StringContains.containsString; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +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.TransactionExtention; +import org.tron.api.WalletGrpc; +import org.tron.api.WalletSolidityGrpc; +import org.tron.common.crypto.ECKey; +import org.tron.common.utils.ByteArray; +import org.tron.common.utils.Utils; +import org.tron.core.Wallet; +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 ClearAbi004 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + @Test(enabled = true, description = "Clear a account address") + public void testClearAbi() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + TransactionExtention transactionExtention = PublicMethed + .clearContractABIForExtention(contractExcAddress, contractExcAddress, contractExcKey, + blockingStubFull); + Assert + .assertThat(transactionExtention.getResult().getCode().toString(), + containsString("CONTRACT_VALIDATE_ERROR")); + Assert + .assertThat(transactionExtention.getResult().getMessage().toStringUtf8(), + containsString("contract validate error : Contract not exists")); + + + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi005.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi005.java new file mode 100644 index 00000000000..fab5abcfdcb --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi005.java @@ -0,0 +1,209 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.clearabi; + +import static org.hamcrest.core.StringContains.containsString; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +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.GrpcAPI.TransactionExtention; +import org.tron.api.WalletGrpc; +import org.tron.api.WalletSolidityGrpc; +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.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 ClearAbi005 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + @Test(enabled = true, description = "clear a contract created by create2 (without ABI)") + public void testClearAbi() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/ClearAbi005.sol"; + String contractName = "Factory"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + + String contractName1 = "TestConstract"; + HashMap retMap1 = PublicMethed.getBycodeAbi(filePath, contractName1); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + String txid = ""; + String num = "\"" + code1 + "\"" + "," + 1; + txid = PublicMethed + .triggerContract(contractAddress, + "deploy(bytes,uint256)", num, false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + byte[] returnAddressBytes = infoById.get().getInternalTransactions(0).getTransferToAddress() + .toByteArray(); + String returnAddress = Base58.encode58Check(returnAddressBytes); + logger.info("returnAddress:" + returnAddress); + SmartContract smartContract = PublicMethed.getContract(returnAddressBytes, blockingStubFull); + Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + TransactionExtention transactionExtention = PublicMethed + .clearContractABIForExtention(returnAddressBytes, contractExcAddress, contractExcKey, + blockingStubFull); + Assert + .assertThat(transactionExtention.getResult().getCode().toString(), + containsString("CONTRACT_VALIDATE_ERROR")); + Assert + .assertThat(transactionExtention.getResult().getMessage().toStringUtf8(), + containsString("is not the owner of the contract")); + + smartContract = PublicMethed.getContract(returnAddressBytes, blockingStubFull); + Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + } + + + /** + * testClearAbitestClearAbi constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi006.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi006.java new file mode 100644 index 00000000000..4f1c12f4ebc --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi006.java @@ -0,0 +1,129 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.clearabi; + +import static org.hamcrest.core.StringContains.containsString; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +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.TransactionExtention; +import org.tron.api.WalletGrpc; +import org.tron.api.WalletSolidityGrpc; +import org.tron.common.crypto.ECKey; +import org.tron.common.utils.ByteArray; +import org.tron.common.utils.Utils; +import org.tron.core.Wallet; +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 ClearAbi006 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + ECKey ecKey2 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress1 = ecKey2.getAddress(); + String contractExcKey1 = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + @Test(enabled = true, description = "Clear a uninitialized account") + public void testClearAbi() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + TransactionExtention transactionExtention = PublicMethed + .clearContractABIForExtention(contractExcAddress1, contractExcAddress, contractExcKey, + blockingStubFull); + Assert + .assertThat(transactionExtention.getResult().getCode().toString(), + containsString("CONTRACT_VALIDATE_ERROR")); + Assert + .assertThat(transactionExtention.getResult().getMessage().toStringUtf8() + , containsString("contract validate error : Contract not exists")); + + + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi007.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi007.java new file mode 100644 index 00000000000..91622bd0ba9 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi007.java @@ -0,0 +1,140 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.clearabi; + +import static org.hamcrest.core.StringContains.containsString; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +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.TransactionExtention; +import org.tron.api.WalletGrpc; +import org.tron.api.WalletSolidityGrpc; +import org.tron.common.crypto.ECKey; +import org.tron.common.utils.ByteArray; +import org.tron.common.utils.Utils; +import org.tron.core.Wallet; +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 ClearAbi007 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + ECKey ecKey2 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress1 = ecKey2.getAddress(); + String contractExcKey1 = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + @Test(enabled = true, description = "Clear a not meet the rules address") + public void testClearAbi() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + byte[] fakeAddress = "412B5D".getBytes(); + TransactionExtention transactionExtention = PublicMethed + .clearContractABIForExtention(fakeAddress, contractExcAddress, contractExcKey, + blockingStubFull); + Assert + .assertThat(transactionExtention.getResult().getCode().toString(), + containsString("CONTRACT_VALIDATE_ERROR")); + Assert + .assertThat(transactionExtention.getResult().getMessage().toStringUtf8() + , containsString("contract validate error : Contract not exists")); + byte[] fakeAddress1 = "412B5D3405B2D26767C9C09886D53DEAFF6EB718AC111".getBytes(); + + TransactionExtention transactionExtention1 = PublicMethed + .clearContractABIForExtention(fakeAddress1, contractExcAddress, contractExcKey, + blockingStubFull); + Assert + .assertThat(transactionExtention1.getResult().getCode().toString(), + containsString("CONTRACT_VALIDATE_ERROR")); + Assert + .assertThat(transactionExtention1.getResult().getMessage().toStringUtf8() + , containsString("contract validate error : Contract not exists")); + + + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi008.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi008.java new file mode 100644 index 00000000000..a3e615d9a03 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi008.java @@ -0,0 +1,174 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.clearabi; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +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.api.WalletSolidityGrpc; +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.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; + +@Slf4j +public class ClearAbi008 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + @Test(enabled = true, description = "Clear a contract with ABI created by itself," + + "clear a contract by itself again") + public void testClearAbi() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/ClearAbi001.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); + Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + + String txid = PublicMethed + .clearContractABI(contractAddress, contractExcAddress, contractExcKey, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Assert.assertTrue(infoById.get().getResultValue() == 0); + + smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); + Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + + String txid1 = PublicMethed + .clearContractABI(contractAddress, contractExcAddress, contractExcKey, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById1 = null; + infoById1 = PublicMethed.getTransactionInfoById(txid1, blockingStubFull); + Assert.assertTrue(infoById1.get().getResultValue() == 0); + + smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); + Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + + + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand001.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand001.java new file mode 100644 index 00000000000..fba69654406 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand001.java @@ -0,0 +1,260 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.shiftcommand; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +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.api.WalletSolidityGrpc; +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 ShiftCommand001 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + + @Test(enabled = true, description = "Trigger old ShiftLeft ShiftRight") + public void test1OldInstruction() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TvmOldCommand001.sol"; + String contractName = "binaryRightContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull1); + + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + String num = "1"; + txid = PublicMethed.triggerContract(contractAddress, + "binaryMoveR(int256)", num, false, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + Optional infoById = null; + PublicMethed.waitProduceNextBlock(blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull1); + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull1); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + txid = PublicMethed.triggerContract(contractAddress, + "binaryLiftR(int256)", num, false, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Assert.assertTrue(infoById.get().getResultValue() == 0); + + + } + + @Test(enabled = true, description = "Trigger new ShiftLeft ShiftRight ShiftRightSigned") + public void test2NewInstruction() { + String filePath = "src/test/resources/soliditycode/ShiftCommand001.sol"; + String contractName = "TestBitwiseShift"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + String num = "1" + "," + "5"; + + txid = PublicMethed.triggerContract(contractAddress, + "sarTest(uint256,uint256)", num, false, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + txid = PublicMethed.triggerContract(contractAddress, + "shlTest(uint256,uint256)", num, false, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Assert.assertTrue(infoById.get().getResultValue() == 0); + txid = PublicMethed.triggerContract(contractAddress, + "shrTest(uint256,uint256)", num, false, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Assert.assertTrue(infoById.get().getResultValue() == 0); + } + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand002.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand002.java new file mode 100644 index 00000000000..8f31615cfdf --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand002.java @@ -0,0 +1,283 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.shiftcommand; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +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.api.WalletSolidityGrpc; +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 ShiftCommand002 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + + @Test(enabled = true, description = "OLd compiler compile shift instruction") + public void test1Oldcompile() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + String contractName = "TestBitwiseShift"; + String code = "608060405234801561001057600080fd5b50d3801561001d57600080fd5b50d2801561002a5" + + "7600080fd5b506101478061003a6000396000f3006080604052600436106100565763ffffffff7c0100" + + "000000000000000000000000000000000000000000000000000000600035041663614eb4da811461005" + + "b578063b5675d6d146100a2578063baf27c0c146100d7575b600080fd5b34801561006757600080fd5b" + + "50d3801561007457600080fd5b50d2801561008157600080fd5b5061009060043560243561010c565b6" + + "0408051918252519081900360200190f35b3480156100ae57600080fd5b50d380156100bb57600080fd" + + "5b50d280156100c857600080fd5b50610090600435602435610111565b3480156100e357600080fd5b5" + + "0d380156100f057600080fd5b50d280156100fd57600080fd5b50610090600435602435610116565b90" + + "1b90565b901d90565b901c905600a165627a7a723058200d5cc53ffdc6db62c4d7414d8b7d95c98218e" + + "50b4c1ea5961d527de1439733450029"; + String abi = "[{\"constant\":false,\"inputs\":[{\"name\":\"num\",\"type\":\"uint256\"}," + + "{\"name\":\"input\",\"type\":\"uint256\"}],\"name\":\"shlTest\",\"outputs\":" + + "[{\"name\":\"out\",\"type\":\"bytes32\"}],\"payable\":false,\"stateMutability\":" + + "\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":" + + "\"num\",\"type\":\"uint256\"},{\"name\":\"input\",\"type\":\"uint256\"}],\"name" + + "\":\"sarTest\",\"outputs\":[{\"name\":\"out\",\"type\":\"bytes32\"}],\"payable" + + "\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant" + + "\":false,\"inputs\":[{\"name\":\"num\",\"type\":\"uint256\"},{\"name\":\"input\"" + + ",\"type\":\"uint256\"}],\"name\":\"shrTest\",\"outputs\":[{\"name\":\"out\",\"" + + "type\":\"bytes32\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"" + + "type\":\"function\"}]"; + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + String num = "1" + "," + "5"; + + txid = PublicMethed.triggerContract(contractAddress, + "sarTest(uint256,uint256)", num, false, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + txid = PublicMethed.triggerContract(contractAddress, + "shlTest(uint256,uint256)", num, false, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Assert.assertTrue(infoById.get().getResultValue() == 0); + txid = PublicMethed.triggerContract(contractAddress, + "shrTest(uint256,uint256)", num, false, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Assert.assertTrue(infoById.get().getResultValue() == 0); + + } + + @Test(enabled = true, description = "New compiler compile shift instruction") + public void test2Newcompile() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + String filePath = "src/test/resources/soliditycode/ShiftCommand001.sol"; + String contractName = "TestBitwiseShift"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + String num = "1" + "," + "5"; + + txid = PublicMethed.triggerContract(contractAddress, + "sarTest(uint256,uint256)", num, false, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + txid = PublicMethed.triggerContract(contractAddress, + "shlTest(uint256,uint256)", num, false, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Assert.assertTrue(infoById.get().getResultValue() == 0); + txid = PublicMethed.triggerContract(contractAddress, + "shrTest(uint256,uint256)", num, false, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Assert.assertTrue(infoById.get().getResultValue() == 0); + + } + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand003.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand003.java new file mode 100644 index 00000000000..6b45dd8a862 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand003.java @@ -0,0 +1,352 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.shiftcommand; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +import java.util.Optional; +import java.util.concurrent.TimeUnit; +import lombok.extern.slf4j.Slf4j; +import org.junit.Assert; +import org.spongycastle.util.encoders.Hex; +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.api.WalletSolidityGrpc; +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.DataWord; +import stest.tron.wallet.common.client.utils.PublicMethed; + +@Slf4j +public class ShiftCommand003 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + @Test(enabled = true, description = "Trigger new ShiftLeft with displacement number too short ") + public void test1ShiftLeft() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/ShiftCommand001.sol"; + String contractName = "TestBitwiseShift"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + + byte[] originNumber = new DataWord( + ByteArray + .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .getData(); + byte[] valueNumber = new DataWord( + ByteArray.fromHexString("0x01")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); + System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); + String param = Hex.toHexString(paramBytes); + logger.info("param:" + param); + txid = PublicMethed.triggerContract(contractAddress, + "shlTest(uint256,uint256)", param, true, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + String returnString = (ByteArray + .toHexString(infoById.get().getContractResult(0).toByteArray())); + logger.info("returnString:" + returnString); + Assert.assertEquals(ByteArray.toLong(ByteArray + .fromHexString("0001fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe")), + ByteArray.toLong(ByteArray + .fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); + } + + + @Test(enabled = true, description = "Trigger new ShiftRight with displacement number too short ") + public void test2ShiftRight() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + + byte[] originNumber = new DataWord( + ByteArray + .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .getData(); + byte[] valueNumber = new DataWord( + ByteArray.fromHexString("0x01")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); + System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); + String param = Hex.toHexString(paramBytes); + logger.info("param:" + param); + txid = PublicMethed.triggerContract(contractAddress, + "shrTest(uint256,uint256)", param, true, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + String returnString = (ByteArray + .toHexString(infoById.get().getContractResult(0).toByteArray())); + logger.info("returnString:" + returnString); + Assert.assertEquals(ByteArray.toLong(ByteArray + .fromHexString("00007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")), + ByteArray.toLong(ByteArray + .fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); + } + + + @Test(enabled = true, description = "Trigger new ShiftRightSigned with displacement number too short ") + public void test3ShiftRightSigned() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + + byte[] originNumber = new DataWord( + ByteArray + .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .getData(); + byte[] valueNumber = new DataWord( + ByteArray.fromHexString("0x01")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); + System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); + String param = Hex.toHexString(paramBytes); + logger.info("param:" + param); + txid = PublicMethed.triggerContract(contractAddress, + "sarTest(uint256,uint256)", param, true, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + String returnString = (ByteArray + .toHexString(infoById.get().getContractResult(0).toByteArray())); + logger.info("returnString:" + returnString); + Assert.assertEquals(ByteArray.toLong(ByteArray + .fromHexString("00007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")), + ByteArray.toLong(ByteArray + .fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); + } + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand004.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand004.java new file mode 100644 index 00000000000..d20fbdaf253 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand004.java @@ -0,0 +1,1099 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.shiftcommand; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +import java.util.Optional; +import java.util.concurrent.TimeUnit; +import lombok.extern.slf4j.Slf4j; +import org.junit.Assert; +import org.spongycastle.util.encoders.Hex; +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.api.WalletSolidityGrpc; +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.DataWord; +import stest.tron.wallet.common.client.utils.PublicMethed; + +@Slf4j +public class ShiftCommand004 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + @Test(enabled = true, description = "Trigger new ShiftLeft,value is " + + "0x0000000000000000000000000000000000000000000000000000000000000001 and Displacement number" + + "is 0x00") + public void test1ShiftLeft() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/ShiftCommand001.sol"; + String contractName = "TestBitwiseShift"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + byte[] originNumber = new DataWord( + ByteArray + .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000001")) + .getData(); + byte[] valueNumber = new DataWord( + ByteArray.fromHexString("0x00")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); + System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); + String param = Hex.toHexString(paramBytes); + + txid = PublicMethed.triggerContract(contractAddress, + "shlTest(uint256,uint256)", param, true, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + String returnString = (ByteArray + .toHexString(infoById.get().getContractResult(0).toByteArray())); + logger.info("returnString:" + returnString); + Assert.assertEquals(ByteArray.toLong(ByteArray + .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000001")), + ByteArray.toLong(ByteArray + .fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); + } + + @Test(enabled = true, description = "Trigger new ShiftLeft,value is " + + "0x0000000000000000000000000000000000000000000000000000000000000001 and Displacement number" + + "is 0x01") + public void test2ShiftLeft() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + + byte[] originNumber = new DataWord( + ByteArray + .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000001")) + .getData(); + byte[] valueNumber = new DataWord( + ByteArray + .fromHexString("0x01")) + .getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); + System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); + String param = Hex.toHexString(paramBytes); + + txid = PublicMethed.triggerContract(contractAddress, + "shlTest(uint256,uint256)", param, true, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + + String returnString = (ByteArray + .toHexString(infoById.get().getContractResult(0).toByteArray())); + logger.info("returnString:" + returnString); + Assert.assertEquals(ByteArray.toLong(ByteArray + .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000002")), + ByteArray.toLong(ByteArray + .fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); + } + + + @Test(enabled = true, description = "Trigger new ShiftLeft,value is " + + "0x0000000000000000000000000000000000000000000000000000000000000001 and Displacement number" + + "is 0xff") + public void test3ShiftLeft() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + + byte[] originNumber = new DataWord( + ByteArray + .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000001")) + .getData(); + byte[] valueNumber = new DataWord( + ByteArray + .fromHexString("0xff")) + .getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); + System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); + String param = Hex.toHexString(paramBytes); + + txid = PublicMethed.triggerContract(contractAddress, + "shlTest(uint256,uint256)", param, true, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + String returnString = (ByteArray + .toHexString(infoById.get().getContractResult(0).toByteArray())); + logger.info("returnString:" + returnString); + Assert.assertEquals(ByteArray.toLong(ByteArray + .fromHexString("0x8000000000000000000000000000000000000000000000000000000000000000")), + ByteArray.toLong(ByteArray + .fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); + } + + + @Test(enabled = true, description = "Trigger new ShiftLeft,value is " + + "0x0000000000000000000000000000000000000000000000000000000000000001 and Displacement number" + + "is 0x0100") + public void test4ShiftLeft() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + + byte[] originNumber = new DataWord( + ByteArray + .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000001")) + .getData(); + byte[] valueNumber = new DataWord( + ByteArray.fromHexString("0x0100")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); + System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); + String param = Hex.toHexString(paramBytes); + txid = PublicMethed.triggerContract(contractAddress, + "shlTest(uint256,uint256)", param, true, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + String returnString = (ByteArray + .toHexString(infoById.get().getContractResult(0).toByteArray())); + logger.info("returnString:" + returnString); + Assert.assertEquals(ByteArray.toLong(ByteArray + .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000000")), + ByteArray.toLong(ByteArray + .fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); + } + + @Test(enabled = true, description = "Trigger new ShiftLeft,value is " + + "0x0000000000000000000000000000000000000000000000000000000000000001 and Displacement number" + + "is 0x0101") + public void test5ShiftLeft() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + + byte[] originNumber = new DataWord( + ByteArray + .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000001")) + .getData(); + byte[] valueNumber = new DataWord( + ByteArray.fromHexString("0x0101")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); + System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); + String param = Hex.toHexString(paramBytes); + txid = PublicMethed.triggerContract(contractAddress, + "shlTest(uint256,uint256)", param, true, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + String returnString = (ByteArray + .toHexString(infoById.get().getContractResult(0).toByteArray())); + logger.info("returnString:" + returnString); + Assert.assertEquals(ByteArray.toLong(ByteArray + .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000000")), + ByteArray.toLong(ByteArray + .fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); + } + + @Test(enabled = true, description = "Trigger new ShiftLeft,value is " + + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + + "is 0x00") + public void test6ShiftLeft() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + + byte[] originNumber = new DataWord( + ByteArray + .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .getData(); + byte[] valueNumber = new DataWord( + ByteArray.fromHexString("0x00")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); + System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); + String param = Hex.toHexString(paramBytes); + txid = PublicMethed.triggerContract(contractAddress, + "shlTest(uint256,uint256)", param, true, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + String returnString = (ByteArray + .toHexString(infoById.get().getContractResult(0).toByteArray())); + logger.info("returnString:" + returnString); + Assert.assertEquals(ByteArray.toLong(ByteArray + .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")), + ByteArray.toLong(ByteArray + .fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); + } + + @Test(enabled = true, description = "Trigger new ShiftLeft,value is " + + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + + "is 0x01") + public void test7ShiftLeft() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/ShiftCommand001.sol"; + String contractName = "TestBitwiseShift"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + + byte[] originNumber = new DataWord( + ByteArray + .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .getData(); + byte[] valueNumber = new DataWord( + ByteArray.fromHexString("0x01")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); + System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); + String param = Hex.toHexString(paramBytes); + + txid = PublicMethed.triggerContract(contractAddress, + "shlTest(uint256,uint256)", param, true, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + String returnString = (ByteArray + .toHexString(infoById.get().getContractResult(0).toByteArray())); + logger.info("returnString:" + returnString); + Assert.assertEquals(ByteArray.toLong(ByteArray + .fromHexString("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe")), + ByteArray.toLong(ByteArray + .fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); + } + + + @Test(enabled = true, description = "Trigger new ShiftLeft,value is " + + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + + "is 0xff") + public void test8ShiftLeft() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + byte[] originNumber = new DataWord( + ByteArray + .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .getData(); + byte[] valueNumber = new DataWord( + ByteArray.fromHexString("0xff")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); + System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); + String param = Hex.toHexString(paramBytes); + + txid = PublicMethed.triggerContract(contractAddress, + "shlTest(uint256,uint256)", param, true, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + String returnString = (ByteArray + .toHexString(infoById.get().getContractResult(0).toByteArray())); + logger.info("returnString:" + returnString); + Assert.assertEquals(ByteArray.toLong(ByteArray + .fromHexString("0x8000000000000000000000000000000000000000000000000000000000000000")), + ByteArray.toLong(ByteArray + .fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); + } + + + @Test(enabled = true, description = "Trigger new ShiftLeft,value is " + + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + + "is 0x0100") + public void test9ShiftLeft() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + + byte[] originNumber = new DataWord( + ByteArray + .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .getData(); + byte[] valueNumber = new DataWord( + ByteArray.fromHexString("0x0100")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); + System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); + String param = Hex.toHexString(paramBytes); + + txid = PublicMethed.triggerContract(contractAddress, + "shlTest(uint256,uint256)", param, true, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + String returnString = (ByteArray + .toHexString(infoById.get().getContractResult(0).toByteArray())); + logger.info("returnString:" + returnString); + Assert.assertEquals(ByteArray.toLong(ByteArray + .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000000")), + ByteArray.toLong(ByteArray + .fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); + } + + + @Test(enabled = true, description = "Trigger new ShiftLeft,value is " + + "0x0000000000000000000000000000000000000000000000000000000000000000 and Displacement number" + + "is 0x01") + public void testShiftLeft10() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + byte[] originNumber = new DataWord( + ByteArray + .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000000")) + .getData(); + byte[] valueNumber = new DataWord( + ByteArray.fromHexString("0x01")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); + System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); + String param = Hex.toHexString(paramBytes); + + txid = PublicMethed.triggerContract(contractAddress, + "shlTest(uint256,uint256)", param, true, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + String returnString = (ByteArray + .toHexString(infoById.get().getContractResult(0).toByteArray())); + logger.info("returnString:" + returnString); + Assert.assertEquals(ByteArray.toLong(ByteArray + .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000000")), + ByteArray.toLong(ByteArray + .fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); + } + + @Test(enabled = true, description = "Trigger new ShiftLeft,value is " + + "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + + "is 0x01") + public void testShiftLeft11() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + byte[] originNumber = new DataWord( + ByteArray + .fromHexString("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .getData(); + byte[] valueNumber = new DataWord( + ByteArray.fromHexString("0x01")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); + System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); + String param = Hex.toHexString(paramBytes); + + txid = PublicMethed.triggerContract(contractAddress, + "shlTest(uint256,uint256)", param, true, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + String returnString = (ByteArray + .toHexString(infoById.get().getContractResult(0).toByteArray())); + logger.info("returnString:" + returnString); + Assert.assertEquals(ByteArray.toLong(ByteArray + .fromHexString("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe")), + ByteArray.toLong(ByteArray + .fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); + } + + @Test(enabled = true, description = "Trigger new ShiftLeft,value is " + + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + + "is 0x0101") + public void testShiftLeft12() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TvmNewCommand043.sol"; + String contractName = "TestBitwiseShift"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + + byte[] originNumber = new DataWord( + ByteArray + .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .getData(); + byte[] valueNumber = new DataWord( + ByteArray.fromHexString("0x0101")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); + System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); + String param = Hex.toHexString(paramBytes); + + txid = PublicMethed.triggerContract(contractAddress, + "shlTest(int256,int256)", param, true, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + String returnString = (ByteArray + .toHexString(infoById.get().getContractResult(0).toByteArray())); + logger.info("returnString:" + returnString); + Assert.assertEquals(ByteArray.toLong(ByteArray + .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000000")), + ByteArray.toLong(ByteArray + .fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand005.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand005.java new file mode 100644 index 00000000000..268715c8d98 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand005.java @@ -0,0 +1,1104 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.shiftcommand; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +import java.util.Optional; +import java.util.concurrent.TimeUnit; +import lombok.extern.slf4j.Slf4j; +import org.junit.Assert; +import org.spongycastle.util.encoders.Hex; +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.api.WalletSolidityGrpc; +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.DataWord; +import stest.tron.wallet.common.client.utils.PublicMethed; + +@Slf4j +public class ShiftCommand005 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + @Test(enabled = true, description = "Trigger new ShiftRight,value is " + + "0x0000000000000000000000000000000000000000000000000000000000000001 and Displacement number" + + "is 0x00") + public void test1ShiftRight() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/ShiftCommand001.sol"; + String contractName = "TestBitwiseShift"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + + byte[] originNumber = new DataWord( + ByteArray + .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000001")) + .getData(); + byte[] valueNumber = new DataWord( + ByteArray.fromHexString("0x00")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); + System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); + String param = Hex.toHexString(paramBytes); + + txid = PublicMethed.triggerContract(contractAddress, + "shrTest(uint256,uint256)", param, true, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Long returnnumber14 = ByteArray.toLong(ByteArray + .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + String returnString = (ByteArray + .toHexString(infoById.get().getContractResult(0).toByteArray())); + logger.info("returnString:" + returnString); + Assert.assertEquals(ByteArray.toLong(ByteArray + .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000001")), + ByteArray.toLong(ByteArray + .fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); + } + + @Test(enabled = true, description = "Trigger new ShiftRight,value is " + + "0x0000000000000000000000000000000000000000000000000000000000000001 and Displacement number" + + "is 0x01") + public void test2ShiftRight() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + byte[] originNumber = new DataWord( + ByteArray + .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000001")) + .getData(); + byte[] valueNumber = new DataWord( + ByteArray.fromHexString("0x01")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); + System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); + String param = Hex.toHexString(paramBytes); + + txid = PublicMethed.triggerContract(contractAddress, + "shrTest(uint256,uint256)", param, true, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + String returnString = (ByteArray + .toHexString(infoById.get().getContractResult(0).toByteArray())); + logger.info("returnString:" + returnString); + Assert.assertEquals(ByteArray.toLong(ByteArray + .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000000")), + ByteArray.toLong(ByteArray + .fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); + } + + @Test(enabled = true, description = "Trigger new ShiftRight,value is " + + "0x8000000000000000000000000000000000000000000000000000000000000000 and Displacement number" + + "is 0x01") + public void test3ShiftRight() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + + String originNumber = String.valueOf(ByteArray.toLong(ByteArray + .fromHexString("0x8000000000000000000000000000000000000000000000000000000000000000"))); + String valueNumber = String.valueOf(ByteArray.toLong((ByteArray + .fromHexString("0x01")))); + String num = valueNumber + "," + originNumber; + + logger.info("returnnumber:" + originNumber); + logger.info("returnnumber1:" + valueNumber); + + txid = PublicMethed.triggerContract(contractAddress, + "shrTest(uint256,uint256)", num, false, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + String returnString = (ByteArray + .toHexString(infoById.get().getContractResult(0).toByteArray())); + logger.info("returnString:" + returnString); + Assert.assertEquals(ByteArray.toLong(ByteArray + .fromHexString("0x4000000000000000000000000000000000000000000000000000000000000000")), + ByteArray.toLong(ByteArray + .fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); + } + + @Test(enabled = true, description = "Trigger new ShiftRight,value is " + + "0x8000000000000000000000000000000000000000000000000000000000000000 and Displacement number" + + "is 0xff") + public void test4ShiftRight() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + byte[] originNumber = new DataWord( + ByteArray + .fromHexString("0x8000000000000000000000000000000000000000000000000000000000000000")) + .getData(); + byte[] valueNumber = new DataWord( + ByteArray + .fromHexString("0xff")) + .getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); + System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); + String param = Hex.toHexString(paramBytes); + txid = PublicMethed.triggerContract(contractAddress, + "shrTest(uint256,uint256)", param, true, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Long returnnumber14 = ByteArray.toLong(ByteArray + .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + String returnString = (ByteArray + .toHexString(infoById.get().getContractResult(0).toByteArray())); + logger.info("returnString:" + returnString); + Assert.assertEquals(ByteArray.toLong(ByteArray + .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000001")), + ByteArray.toLong(ByteArray + .fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); + } + + + @Test(enabled = true, description = "Trigger new ShiftRight,value is " + + "0x8000000000000000000000000000000000000000000000000000000000000000 and Displacement number" + + "is 0x0100") + public void test5ShiftRight() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + + byte[] originNumber = new DataWord( + ByteArray + .fromHexString("0x8000000000000000000000000000000000000000000000000000000000000000")) + .getData(); + byte[] valueNumber = new DataWord( + ByteArray.fromHexString("0x0100")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); + System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); + String param = Hex.toHexString(paramBytes); + + txid = PublicMethed.triggerContract(contractAddress, + "shrTest(uint256,uint256)", param, true, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + String returnString = (ByteArray + .toHexString(infoById.get().getContractResult(0).toByteArray())); + logger.info("returnString:" + returnString); + Assert.assertEquals(ByteArray.toLong(ByteArray + .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000000")), + ByteArray.toLong(ByteArray + .fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); + } + + @Test(enabled = true, description = "Trigger new ShiftRight,value is " + + "0x8000000000000000000000000000000000000000000000000000000000000000 and Displacement number" + + "is 0x0101") + public void test6ShiftRight() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + + byte[] originNumber = new DataWord( + ByteArray + .fromHexString("0x8000000000000000000000000000000000000000000000000000000000000000")) + .getData(); + byte[] valueNumber = new DataWord( + ByteArray.fromHexString("0x0101")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); + System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); + String param = Hex.toHexString(paramBytes); + + txid = PublicMethed.triggerContract(contractAddress, + "shrTest(uint256,uint256)", param, true, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + String returnString = (ByteArray + .toHexString(infoById.get().getContractResult(0).toByteArray())); + logger.info("returnString:" + returnString); + Assert.assertEquals(ByteArray.toLong(ByteArray + .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000000")), + ByteArray.toLong(ByteArray + .fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); + } + + @Test(enabled = true, description = "Trigger new ShiftRight,value is " + + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + + "is 0x00") + public void test7ShiftRight() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + + byte[] originNumber = new DataWord( + ByteArray + .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .getData(); + byte[] valueNumber = new DataWord( + ByteArray.fromHexString("0x00")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); + System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); + String param = Hex.toHexString(paramBytes); + + txid = PublicMethed.triggerContract(contractAddress, + "shrTest(uint256,uint256)", param, true, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + String returnString = (ByteArray + .toHexString(infoById.get().getContractResult(0).toByteArray())); + logger.info("returnString:" + returnString); + Assert.assertEquals(ByteArray.toLong(ByteArray + .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")), + ByteArray.toLong(ByteArray + .fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); + } + + @Test(enabled = true, description = "Trigger new ShiftRight,value is " + + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + + "is 0x01") + public void test8ShiftRight() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + + byte[] originNumber = new DataWord( + ByteArray + .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .getData(); + byte[] valueNumber = new DataWord( + ByteArray.fromHexString("0x01")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); + System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); + String param = Hex.toHexString(paramBytes); + + txid = PublicMethed.triggerContract(contractAddress, + "shrTest(uint256,uint256)", param, true, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Long returnnumber14 = ByteArray.toLong(ByteArray + .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + String returnString = (ByteArray + .toHexString(infoById.get().getContractResult(0).toByteArray())); + logger.info("returnString:" + returnString); + Assert.assertEquals(ByteArray.toLong(ByteArray + .fromHexString("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")), + ByteArray.toLong(ByteArray + .fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); + } + + @Test(enabled = true, description = "Trigger new ShiftRight,value is " + + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + + "is 0xff") + public void test9ShiftRight() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + + byte[] originNumber = new DataWord( + ByteArray + .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .getData(); + byte[] valueNumber = new DataWord( + ByteArray.fromHexString("0xff")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); + System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); + String param = Hex.toHexString(paramBytes); + + txid = PublicMethed.triggerContract(contractAddress, + "shrTest(uint256,uint256)", param, true, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Long returnnumber14 = ByteArray.toLong(ByteArray + .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + String returnString = (ByteArray + .toHexString(infoById.get().getContractResult(0).toByteArray())); + logger.info("returnString:" + returnString); + Assert.assertEquals(ByteArray.toLong(ByteArray + .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000001")), + ByteArray.toLong(ByteArray + .fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); + } + + @Test(enabled = true, description = "Trigger new ShiftRight,value is " + + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + + "is 0x0100") + public void testShiftRight10() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + + byte[] originNumber = new DataWord( + ByteArray + .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .getData(); + byte[] valueNumber = new DataWord( + ByteArray.fromHexString("0x0100")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); + System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); + String param = Hex.toHexString(paramBytes); + + txid = PublicMethed.triggerContract(contractAddress, + "shrTest(uint256,uint256)", param, true, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + String returnString = (ByteArray + .toHexString(infoById.get().getContractResult(0).toByteArray())); + logger.info("returnString:" + returnString); + Assert.assertEquals(ByteArray.toLong(ByteArray + .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000000")), + ByteArray.toLong(ByteArray + .fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); + } + + @Test(enabled = true, description = "Trigger new ShiftRight,value is " + + "0x0000000000000000000000000000000000000000000000000000000000000000 and Displacement number" + + "is 0x01") + public void testShiftRight11() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/ShiftCommand001.sol"; + String contractName = "TestBitwiseShift"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + byte[] originNumber = new DataWord( + ByteArray + .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000000")) + .getData(); + byte[] valueNumber = new DataWord( + ByteArray.fromHexString("0x01")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); + System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); + String param = Hex.toHexString(paramBytes); + + txid = PublicMethed.triggerContract(contractAddress, + "shrTest(uint256,uint256)", param, true, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + String returnString = (ByteArray + .toHexString(infoById.get().getContractResult(0).toByteArray())); + logger.info("returnString:" + returnString); + Assert.assertEquals(ByteArray.toLong(ByteArray + .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000000")), + ByteArray.toLong(ByteArray + .fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); + } + + + @Test(enabled = true, description = "Trigger new ShiftRight,value is " + + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + + "is 0x0101") + public void testShiftRight12() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TvmNewCommand043.sol"; + String contractName = "TestBitwiseShift"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + + byte[] originNumber = new DataWord( + ByteArray + .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .getData(); + byte[] valueNumber = new DataWord( + ByteArray.fromHexString("0x0101")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); + System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); + String param = Hex.toHexString(paramBytes); + + txid = PublicMethed.triggerContract(contractAddress, + "shrTest(int256,int256)", param, true, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + String returnString = (ByteArray + .toHexString(infoById.get().getContractResult(0).toByteArray())); + logger.info("returnString:" + returnString); + Assert.assertEquals(ByteArray.toLong(ByteArray + .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000000")), + ByteArray.toLong(ByteArray + .fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); + } + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand006.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand006.java new file mode 100644 index 00000000000..aca1c0ac9b6 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand006.java @@ -0,0 +1,1620 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.shiftcommand; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +import java.util.Optional; +import java.util.concurrent.TimeUnit; +import lombok.extern.slf4j.Slf4j; +import org.junit.Assert; +import org.spongycastle.util.encoders.Hex; +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.api.WalletSolidityGrpc; +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.DataWord; +import stest.tron.wallet.common.client.utils.PublicMethed; + +@Slf4j +public class ShiftCommand006 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + @Test(enabled = true, description = "Trigger new ShiftRightSigned,value is " + + "0x0000000000000000000000000000000000000000000000000000000000000001 and Displacement number" + + "is 0x00") + public void test1ShiftRightSigned() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/ShiftCommand001.sol"; + String contractName = "TestBitwiseShift"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + byte[] originNumber = new DataWord( + ByteArray + .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000001")) + .getData(); + byte[] valueNumber = new DataWord( + ByteArray.fromHexString("0x00")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); + System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); + String param = Hex.toHexString(paramBytes); + + txid = PublicMethed.triggerContract(contractAddress, + "sarTest(uint256,uint256)", param, true, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + String returnString = (ByteArray + .toHexString(infoById.get().getContractResult(0).toByteArray())); + logger.info("returnString:" + returnString); + Assert.assertEquals(ByteArray.toLong(ByteArray + .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000001")), + ByteArray.toLong(ByteArray + .fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); + } + + @Test(enabled = true, description = "Trigger new ShiftRightSigned,value is " + + "0x0000000000000000000000000000000000000000000000000000000000000001 and Displacement number" + + "is 0x01") + public void test2ShiftRightSigned() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + byte[] originNumber = new DataWord( + ByteArray + .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000001")) + .getData(); + byte[] valueNumber = new DataWord( + ByteArray.fromHexString("0x01")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); + System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); + String param = Hex.toHexString(paramBytes); + + txid = PublicMethed.triggerContract(contractAddress, + "sarTest(uint256,uint256)", param, true, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Long returnnumber14 = ByteArray.toLong(ByteArray + .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + String returnString = (ByteArray + .toHexString(infoById.get().getContractResult(0).toByteArray())); + logger.info("returnString:" + returnString); + Assert.assertEquals(ByteArray.toLong(ByteArray + .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000000")), + ByteArray.toLong(ByteArray + .fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); + } + + @Test(enabled = true, description = "Trigger new ShiftRightSigned,value is " + + "0x8000000000000000000000000000000000000000000000000000000000000000 and Displacement number" + + "is 0x01") + public void test3ShiftRightSigned() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + + byte[] originNumber = new DataWord( + ByteArray + .fromHexString("0x8000000000000000000000000000000000000000000000000000000000000000")) + .getData(); + byte[] valueNumber = new DataWord( + ByteArray.fromHexString("0x01")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); + System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); + String param = Hex.toHexString(paramBytes); + + txid = PublicMethed.triggerContract(contractAddress, + "sarTest(uint256,uint256)", param, true, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + String returnString = (ByteArray + .toHexString(infoById.get().getContractResult(0).toByteArray())); + logger.info("returnString:" + returnString); + Assert.assertEquals(ByteArray.toLong(ByteArray + .fromHexString("0xc000000000000000000000000000000000000000000000000000000000000000")), + ByteArray.toLong(ByteArray + .fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); + } + + @Test(enabled = true, description = "Trigger new ShiftRightSigned,value is " + + "0x8000000000000000000000000000000000000000000000000000000000000000 and Displacement number" + + "is 0xff") + public void test4ShiftRightSigned() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + + byte[] originNumber = new DataWord( + ByteArray + .fromHexString("0x8000000000000000000000000000000000000000000000000000000000000000")) + .getData(); + byte[] valueNumber = new DataWord( + ByteArray + .fromHexString("0xff")) + .getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); + System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); + String param = Hex.toHexString(paramBytes); + + txid = PublicMethed.triggerContract(contractAddress, + "sarTest(uint256,uint256)", param, true, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Long returnnumber14 = ByteArray.toLong(ByteArray + .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + String returnString = (ByteArray + .toHexString(infoById.get().getContractResult(0).toByteArray())); + logger.info("returnString:" + returnString); + Assert.assertEquals(ByteArray.toLong(ByteArray + .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")), + ByteArray.toLong(ByteArray + .fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); + } + + @Test(enabled = true, description = "Trigger new ShiftRightSigned,value is " + + "0x8000000000000000000000000000000000000000000000000000000000000000 and Displacement number" + + "is 0x0100") + public void test5ShiftRightSigned() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + byte[] originNumber = new DataWord( + ByteArray + .fromHexString("0x8000000000000000000000000000000000000000000000000000000000000000")) + .getData(); + byte[] valueNumber = new DataWord( + ByteArray.fromHexString("0x0100")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); + System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); + String param = Hex.toHexString(paramBytes); + txid = PublicMethed.triggerContract(contractAddress, + "sarTest(uint256,uint256)", param, true, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Long returnnumber14 = ByteArray.toLong(ByteArray + .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + String returnString = (ByteArray + .toHexString(infoById.get().getContractResult(0).toByteArray())); + logger.info("returnString:" + returnString); + Assert.assertEquals(ByteArray.toLong(ByteArray + .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")), + ByteArray.toLong(ByteArray + .fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); + } + + @Test(enabled = true, description = "Trigger new ShiftRightSigned,value is " + + "0x8000000000000000000000000000000000000000000000000000000000000000 and Displacement number" + + "is 0x0101") + public void test6ShiftRightSigned() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + + byte[] originNumber = new DataWord( + ByteArray + .fromHexString("0x8000000000000000000000000000000000000000000000000000000000000000")) + .getData(); + byte[] valueNumber = new DataWord( + ByteArray.fromHexString("0x0101")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); + System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); + String param = Hex.toHexString(paramBytes); + txid = PublicMethed.triggerContract(contractAddress, + "sarTest(uint256,uint256)", param, true, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Long returnnumber14 = ByteArray.toLong(ByteArray + .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + String returnString = (ByteArray + .toHexString(infoById.get().getContractResult(0).toByteArray())); + logger.info("returnString:" + returnString); + Assert.assertEquals(ByteArray.toLong(ByteArray + .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")), + ByteArray.toLong(ByteArray + .fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); + } + + @Test(enabled = true, description = "Trigger new ShiftRightSigned,value is " + + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + + "is 0x00") + public void test7ShiftRightSigned() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + + byte[] originNumber = new DataWord( + ByteArray + .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .getData(); + byte[] valueNumber = new DataWord( + ByteArray + .fromHexString("0x00")) + .getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); + System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); + String param = Hex.toHexString(paramBytes); + + txid = PublicMethed.triggerContract(contractAddress, + "sarTest(uint256,uint256)", param, true, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Long returnnumber14 = ByteArray.toLong(ByteArray + .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + String returnString = (ByteArray + .toHexString(infoById.get().getContractResult(0).toByteArray())); + logger.info("returnString:" + returnString); + Assert.assertEquals(ByteArray.toLong(ByteArray + .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")), + ByteArray.toLong(ByteArray + .fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); + + } + + @Test(enabled = true, description = "Trigger new ShiftRightSigned,value is " + + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + + "is 0x01") + public void test8ShiftRightSigned() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + + byte[] originNumber = new DataWord( + ByteArray + .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .getData(); + byte[] valueNumber = new DataWord( + ByteArray + .fromHexString("0x01")) + .getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); + System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); + String param = Hex.toHexString(paramBytes); + + txid = PublicMethed.triggerContract(contractAddress, + "sarTest(uint256,uint256)", param, true, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Long returnnumber14 = ByteArray.toLong(ByteArray + .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + String returnString = (ByteArray + .toHexString(infoById.get().getContractResult(0).toByteArray())); + logger.info("returnString:" + returnString); + Assert.assertEquals(ByteArray.toLong(ByteArray + .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")), + ByteArray.toLong(ByteArray + .fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); + } + + @Test(enabled = true, description = "Trigger new ShiftRightSigned,value is " + + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + + "is 0xff") + public void test9ShiftRightSigned() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + + byte[] originNumber = new DataWord( + ByteArray + .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .getData(); + byte[] valueNumber = new DataWord( + ByteArray + .fromHexString("0xff")) + .getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); + System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); + String param = Hex.toHexString(paramBytes); + txid = PublicMethed.triggerContract(contractAddress, + "sarTest(uint256,uint256)", param, true, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Long returnnumber14 = ByteArray.toLong(ByteArray + .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + String returnString = (ByteArray + .toHexString(infoById.get().getContractResult(0).toByteArray())); + logger.info("returnString:" + returnString); + Assert.assertEquals(ByteArray.toLong(ByteArray + .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")), + ByteArray.toLong(ByteArray + .fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); + } + + + @Test(enabled = true, description = "Trigger new ShiftRightSigned,value is " + + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + + "is 0x0100") + public void testShiftRightSigned10() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + byte[] originNumber = new DataWord( + ByteArray + .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .getData(); + byte[] valueNumber = new DataWord( + ByteArray + .fromHexString("0x0100")) + .getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); + System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); + String param = Hex.toHexString(paramBytes); + + txid = PublicMethed.triggerContract(contractAddress, + "sarTest(uint256,uint256)", param, true, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Long returnnumber14 = ByteArray.toLong(ByteArray + .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + String returnString = (ByteArray + .toHexString(infoById.get().getContractResult(0).toByteArray())); + logger.info("returnString:" + returnString); + Assert.assertEquals(ByteArray.toLong(ByteArray + .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")), + ByteArray.toLong(ByteArray + .fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); + } + + + @Test(enabled = true, description = "Trigger new ShiftRightSigned,value is " + + "0x0000000000000000000000000000000000000000000000000000000000000000 and Displacement number" + + "is 0x01") + public void testShiftRightSigned11() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + byte[] originNumber = new DataWord( + ByteArray + .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000000")) + .getData(); + byte[] valueNumber = new DataWord( + ByteArray + .fromHexString("0x01")) + .getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); + System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); + String param = Hex.toHexString(paramBytes); + + txid = PublicMethed.triggerContract(contractAddress, + "sarTest(uint256,uint256)", param, true, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Long returnnumber14 = ByteArray.toLong(ByteArray + .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + String returnString = (ByteArray + .toHexString(infoById.get().getContractResult(0).toByteArray())); + logger.info("returnString:" + returnString); + Assert.assertEquals(ByteArray.toLong(ByteArray + .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000000")), + ByteArray.toLong(ByteArray + .fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); + } + + + @Test(enabled = true, description = "Trigger new ShiftRightSigned,value is " + + "0x4000000000000000000000000000000000000000000000000000000000000000 and Displacement number" + + "is 0xfe") + public void testShiftRightSigned12() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + byte[] originNumber = new DataWord( + ByteArray + .fromHexString("0x4000000000000000000000000000000000000000000000000000000000000000")) + .getData(); + byte[] valueNumber = new DataWord( + ByteArray + .fromHexString("0xfe")) + .getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); + System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); + String param = Hex.toHexString(paramBytes); + + txid = PublicMethed.triggerContract(contractAddress, + "sarTest(uint256,uint256)", param, true, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Long returnnumber14 = ByteArray.toLong(ByteArray + .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + String returnString = (ByteArray + .toHexString(infoById.get().getContractResult(0).toByteArray())); + logger.info("returnString:" + returnString); + Assert.assertEquals(ByteArray.toLong(ByteArray + .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000001")), + ByteArray.toLong(ByteArray + .fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); + } + + @Test(enabled = true, description = "Trigger new ShiftRightSigned,value is " + + "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + + "is 0xf8") + public void testShiftRightSigned13() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + byte[] originNumber = new DataWord( + ByteArray + .fromHexString("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .getData(); + byte[] valueNumber = new DataWord( + ByteArray + .fromHexString("0xf8")) + .getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); + System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); + String param = Hex.toHexString(paramBytes); + + txid = PublicMethed.triggerContract(contractAddress, + "sarTest(uint256,uint256)", param, true, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Long returnnumber14 = ByteArray.toLong(ByteArray + .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + String returnString = (ByteArray + .toHexString(infoById.get().getContractResult(0).toByteArray())); + logger.info("returnString:" + returnString); + Assert.assertEquals(ByteArray.toLong(ByteArray + .fromHexString("0x000000000000000000000000000000000000000000000000000000000000007f")), + ByteArray.toLong(ByteArray + .fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); + } + + + @Test(enabled = true, description = "Trigger new ShiftRightSigned,value is " + + "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + + "is 0xfe") + public void testShiftRightSigned14() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + + byte[] originNumber = new DataWord( + ByteArray + .fromHexString("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .getData(); + byte[] valueNumber = new DataWord( + ByteArray.fromHexString("0xfe")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); + System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); + String param = Hex.toHexString(paramBytes); + txid = PublicMethed.triggerContract(contractAddress, + "sarTest(uint256,uint256)", param, true, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Long returnnumber14 = ByteArray.toLong(ByteArray + .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + String returnString = (ByteArray + .toHexString(infoById.get().getContractResult(0).toByteArray())); + logger.info("returnString:" + returnString); + Assert.assertEquals(ByteArray.toLong(ByteArray + .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000001")), + ByteArray.toLong(ByteArray + .fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); + } + + @Test(enabled = true, description = "Trigger new ShiftRightSigned,value is " + + "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + + "is 0xff") + public void testShiftRightSigned15() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + + byte[] originNumber = new DataWord( + ByteArray + .fromHexString("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .getData(); + byte[] valueNumber = new DataWord( + ByteArray.fromHexString("0xff")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); + System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); + + String param = Hex.toHexString(paramBytes); + txid = PublicMethed.triggerContract(contractAddress, + "sarTest(uint256,uint256)", param, true, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Long returnnumber14 = ByteArray.toLong(ByteArray + .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + String returnString = (ByteArray + .toHexString(infoById.get().getContractResult(0).toByteArray())); + logger.info("returnString:" + returnString); + Assert.assertEquals(ByteArray.toLong(ByteArray + .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000000")), + ByteArray.toLong(ByteArray + .fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); + } + + + @Test(enabled = true, description = "Trigger new ShiftRightSigned,value is " + + "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + + "is 0x0100") + public void testShiftRightSigned16() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + + byte[] originNumber = new DataWord( + ByteArray + .fromHexString("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .getData(); + byte[] valueNumber = new DataWord( + ByteArray.fromHexString("0x0100")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); + System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); + + String param = Hex.toHexString(paramBytes); + txid = PublicMethed.triggerContract(contractAddress, + "sarTest(uint256,uint256)", param, true, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Long returnnumber14 = ByteArray.toLong(ByteArray + .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + String returnString = (ByteArray + .toHexString(infoById.get().getContractResult(0).toByteArray())); + logger.info("returnString:" + returnString); + Assert.assertEquals(ByteArray.toLong(ByteArray + .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000000")), + ByteArray.toLong(ByteArray + .fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); + } + + @Test(enabled = true, description = "Trigger new ShiftRightSigned,value is " + + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + + "is 0x0101") + public void testShiftRightSigned17() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TvmNewCommand043.sol"; + String contractName = "TestBitwiseShift"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + byte[] originNumber = new DataWord( + ByteArray + .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .getData(); + byte[] valueNumber = new DataWord( + ByteArray + .fromHexString("0x0101")) + .getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); + System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); + String param = Hex.toHexString(paramBytes); + + txid = PublicMethed.triggerContract(contractAddress, + "sarTest(int256,int256)", param, true, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Long returnnumber14 = ByteArray.toLong(ByteArray + .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + String returnString = (ByteArray + .toHexString(infoById.get().getContractResult(0).toByteArray())); + logger.info("returnString:" + returnString); + Assert.assertEquals(ByteArray.toLong(ByteArray + .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")), + ByteArray.toLong(ByteArray + .fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); + } + + @Test(enabled = true, description = "Trigger new ShiftRightSigned,value is " + + "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + + "is 0x0101") + public void testShiftRightSigned18() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TvmNewCommand043.sol"; + String contractName = "TestBitwiseShift"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + + byte[] originNumber = new DataWord( + ByteArray + .fromHexString("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .getData(); + byte[] valueNumber = new DataWord( + ByteArray.fromHexString("0x0101")).getData(); + byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; + System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); + System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); + + String param = Hex.toHexString(paramBytes); + txid = PublicMethed.triggerContract(contractAddress, + "sarTest(int256,int256)", param, true, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + String returnString = (ByteArray + .toHexString(infoById.get().getContractResult(0).toByteArray())); + logger.info("returnString:" + returnString); + Assert.assertEquals(ByteArray.toLong(ByteArray + .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000000")), + ByteArray.toLong(ByteArray + .fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); + } + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant001.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant001.java new file mode 100644 index 00000000000..bb0317ee6a7 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant001.java @@ -0,0 +1,163 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.triggerconstant; + +import static org.hamcrest.core.StringContains.containsString; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +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.GrpcAPI.TransactionExtention; +import org.tron.api.WalletGrpc; +import org.tron.api.WalletSolidityGrpc; +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.SmartContract; +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 TriggerConstant001 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + @Test(enabled = true, description = "TriggerConstantContract a payable function without ABI") + public void testTriggerConstantContract() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TriggerConstant001.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, "[]", code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); + Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + + TransactionExtention transactionExtention = PublicMethed + .triggerConstantContractForExtention(contractAddress, + "testPayable()", "#", false, + 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + System.out.println("Code = " + transactionExtention.getResult().getCode()); + System.out + .println("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); + + Assert + .assertThat(transactionExtention.getResult().getCode().toString(), + containsString("CONTRACT_EXE_ERROR")); + Assert + .assertThat(transactionExtention.getResult().getMessage().toStringUtf8(), + containsString("Attempt to call a state modifying opcode inside STATICCALL")); + + + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant002.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant002.java new file mode 100644 index 00000000000..d04fc8d4a93 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant002.java @@ -0,0 +1,162 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.triggerconstant; + +import static org.hamcrest.core.StringContains.containsString; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +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.GrpcAPI.TransactionExtention; +import org.tron.api.WalletGrpc; +import org.tron.api.WalletSolidityGrpc; +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.SmartContract; +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 TriggerConstant002 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + @Test(enabled = true, description = "TriggerConstantContract a non-payable function without ABI") + public void testTriggerConstantContract() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TriggerConstant002.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, "[]", code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); + Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + + TransactionExtention transactionExtention = PublicMethed + .triggerConstantContractForExtention(contractAddress, + "testNoPayable()", "#", false, + 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + System.out.println("Code = " + transactionExtention.getResult().getCode()); + System.out + .println("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); + + Assert + .assertThat(transactionExtention.getResult().getCode().toString(), + containsString("CONTRACT_EXE_ERROR")); + Assert + .assertThat(transactionExtention.getResult().getMessage().toStringUtf8(), + containsString("Attempt to call a state modifying opcode inside STATICCALL")); + + + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant003.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant003.java new file mode 100644 index 00000000000..63474b61b33 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant003.java @@ -0,0 +1,162 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.triggerconstant; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +import java.util.concurrent.TimeUnit; +import lombok.extern.slf4j.Slf4j; +import org.junit.Assert; +import org.spongycastle.util.encoders.Hex; +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.GrpcAPI.TransactionExtention; +import org.tron.api.WalletGrpc; +import org.tron.api.WalletSolidityGrpc; +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.SmartContract; +import org.tron.protos.Protocol.Transaction; +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 TriggerConstant003 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + @Test(enabled = true, description = "TriggerConstantContract a view function without ABI") + public void testTriggerConstantContract() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TriggerConstant003.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, "[]", code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); + Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + + TransactionExtention transactionExtention = PublicMethed + .triggerConstantContractForExtention(contractAddress, + "testView()", "#", false, + 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + + Transaction transaction = transactionExtention.getTransaction(); + + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + System.out.println("message:" + transaction.getRet(0).getRet()); + System.out.println(":" + ByteArray + .toStr(transactionExtention.getResult().getMessage().toByteArray())); + System.out.println("Result:" + Hex.toHexString(result)); + + Assert.assertEquals(1, ByteArray.toLong(ByteArray + .fromHexString(Hex + .toHexString(result)))); + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant004.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant004.java new file mode 100644 index 00000000000..e9ba6410e7e --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant004.java @@ -0,0 +1,164 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.triggerconstant; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +import java.util.concurrent.TimeUnit; +import lombok.extern.slf4j.Slf4j; +import org.junit.Assert; +import org.spongycastle.util.encoders.Hex; +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.GrpcAPI.TransactionExtention; +import org.tron.api.WalletGrpc; +import org.tron.api.WalletSolidityGrpc; +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.SmartContract; +import org.tron.protos.Protocol.Transaction; +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 TriggerConstant004 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + @Test(enabled = true, description = "TriggerConstantContract a pure function without ABI") + public void testTriggerConstantContract() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TriggerConstant004.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, "[]", code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); + Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + + TransactionExtention transactionExtention = PublicMethed + .triggerConstantContractForExtention(contractAddress, + "testPure()", "#", false, + 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + + Transaction transaction = transactionExtention.getTransaction(); + + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + System.out.println("message:" + transaction.getRet(0).getRet()); + System.out.println(":" + ByteArray + .toStr(transactionExtention.getResult().getMessage().toByteArray())); + System.out.println("Result:" + Hex.toHexString(result)); + + Assert.assertEquals(1, ByteArray.toLong(ByteArray + .fromHexString(Hex + .toHexString(result)))); + + + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant005.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant005.java new file mode 100644 index 00000000000..7bcc2b92bd4 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant005.java @@ -0,0 +1,164 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.triggerconstant; + +import static org.hamcrest.core.StringContains.containsString; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +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.GrpcAPI.TransactionExtention; +import org.tron.api.WalletGrpc; +import org.tron.api.WalletSolidityGrpc; +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.SmartContract; +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 TriggerConstant005 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + @Test(enabled = true, description = "TriggerConstantContract a payable function with ABI") + public void testTriggerConstantContract() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TriggerConstant001.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); + Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + + TransactionExtention transactionExtention = PublicMethed + .triggerConstantContractForExtention(contractAddress, + "testPayable()", "#", false, + 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + System.out.println("Code = " + transactionExtention.getResult().getCode()); + System.out + .println("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); + + Assert + .assertThat(transactionExtention.getResult().getCode().toString(), + containsString("CONTRACT_EXE_ERROR")); + Assert + .assertThat(transactionExtention.getResult().getMessage().toStringUtf8() + , containsString("Attempt to call a state modifying opcode inside STATICCALL")); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant006.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant006.java new file mode 100644 index 00000000000..475a6cf7672 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant006.java @@ -0,0 +1,163 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.triggerconstant; + +import static org.hamcrest.core.StringContains.containsString; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +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.GrpcAPI.TransactionExtention; +import org.tron.api.WalletGrpc; +import org.tron.api.WalletSolidityGrpc; +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.SmartContract; +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 TriggerConstant006 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + @Test(enabled = true, description = "TriggerConstantContract a non-payable function with ABI") + public void testTriggerConstantContract() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TriggerConstant002.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); + Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + + TransactionExtention transactionExtention = PublicMethed + .triggerConstantContractForExtention(contractAddress, + "testNoPayable()", "#", false, + 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + System.out.println("Code = " + transactionExtention.getResult().getCode()); + System.out + .println("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); + + Assert + .assertThat(transactionExtention.getResult().getCode().toString(), + containsString("CONTRACT_EXE_ERROR")); + Assert + .assertThat(transactionExtention.getResult().getMessage().toStringUtf8() + , containsString("Attempt to call a state modifying opcode inside STATICCALL")); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant007.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant007.java new file mode 100644 index 00000000000..6f60e8535cf --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant007.java @@ -0,0 +1,164 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.triggerconstant; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +import java.util.concurrent.TimeUnit; +import lombok.extern.slf4j.Slf4j; +import org.junit.Assert; +import org.spongycastle.util.encoders.Hex; +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.GrpcAPI.TransactionExtention; +import org.tron.api.WalletGrpc; +import org.tron.api.WalletSolidityGrpc; +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.SmartContract; +import org.tron.protos.Protocol.Transaction; +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 TriggerConstant007 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + @Test(enabled = true, description = "TriggerConstantContract a view function with ABI") + public void testTriggerConstantContract() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TriggerConstant003.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); + Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + + TransactionExtention transactionExtention = PublicMethed + .triggerConstantContractForExtention(contractAddress, + "testView()", "#", false, + 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + + Transaction transaction = transactionExtention.getTransaction(); + + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + System.out.println("message:" + transaction.getRet(0).getRet()); + System.out.println(":" + ByteArray + .toStr(transactionExtention.getResult().getMessage().toByteArray())); + System.out.println("Result:" + Hex.toHexString(result)); + + Assert.assertEquals(1, ByteArray.toLong(ByteArray + .fromHexString(Hex + .toHexString(result)))); + + + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant008.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant008.java new file mode 100644 index 00000000000..0a2baa46408 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant008.java @@ -0,0 +1,164 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.triggerconstant; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +import java.util.concurrent.TimeUnit; +import lombok.extern.slf4j.Slf4j; +import org.junit.Assert; +import org.spongycastle.util.encoders.Hex; +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.GrpcAPI.TransactionExtention; +import org.tron.api.WalletGrpc; +import org.tron.api.WalletSolidityGrpc; +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.SmartContract; +import org.tron.protos.Protocol.Transaction; +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 TriggerConstant008 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + @Test(enabled = true, description = "TriggerConstantContract a pure function with ABI") + public void testTriggerConstantContract() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TriggerConstant004.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); + Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + + TransactionExtention transactionExtention = PublicMethed + .triggerConstantContractForExtention(contractAddress, + "testPure()", "#", false, + 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + + Transaction transaction = transactionExtention.getTransaction(); + + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + System.out.println("message:" + transaction.getRet(0).getRet()); + System.out.println(":" + ByteArray + .toStr(transactionExtention.getResult().getMessage().toByteArray())); + System.out.println("Result:" + Hex.toHexString(result)); + + Assert.assertEquals(1, ByteArray.toLong(ByteArray + .fromHexString(Hex + .toHexString(result)))); + + + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant009.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant009.java new file mode 100644 index 00000000000..3012e7ff698 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant009.java @@ -0,0 +1,188 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.triggerconstant; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +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.api.WalletSolidityGrpc; +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.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; + +@Slf4j +public class TriggerConstant009 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + @Test(enabled = true, description = "TriggerContract a payable function without ABI") + public void testTriggerContract() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TriggerConstant001.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, "[]", code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); + Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + + txid = PublicMethed + .triggerContract(contractAddress, + "testPayable()", "#", false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Long returnnumber = ByteArray.toLong(ByteArray + .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + Assert.assertTrue(1 == returnnumber); + + + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant010.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant010.java new file mode 100644 index 00000000000..ebf7924df23 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant010.java @@ -0,0 +1,188 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.triggerconstant; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +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.api.WalletSolidityGrpc; +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.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; + +@Slf4j +public class TriggerConstant010 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + @Test(enabled = true, description = "TriggerContract a non-payable function without ABI") + public void testTriggerContract() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TriggerConstant002.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, "[]", code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); + Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + + txid = PublicMethed + .triggerContract(contractAddress, + "testNoPayable()", "#", false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Long returnnumber = ByteArray.toLong(ByteArray + .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + Assert.assertTrue(1 == returnnumber); + + + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant011.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant011.java new file mode 100644 index 00000000000..0abef07bab9 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant011.java @@ -0,0 +1,188 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.triggerconstant; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +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.api.WalletSolidityGrpc; +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.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; + +@Slf4j +public class TriggerConstant011 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + @Test(enabled = true, description = "TriggerContract a view function without ABI") + public void testTriggerContract() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TriggerConstant003.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, "[]", code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); + Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + + txid = PublicMethed + .triggerContract(contractAddress, + "testView()", "#", false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Long returnnumber = ByteArray.toLong(ByteArray + .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + Assert.assertTrue(1 == returnnumber); + + + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant012.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant012.java new file mode 100644 index 00000000000..72acf13386d --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant012.java @@ -0,0 +1,188 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.triggerconstant; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +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.api.WalletSolidityGrpc; +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.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; + +@Slf4j +public class TriggerConstant012 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + @Test(enabled = true, description = "TriggerContract a pure function without ABI") + public void testTriggerContract() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TriggerConstant004.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, "[]", code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); + Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + + txid = PublicMethed + .triggerContract(contractAddress, + "testPure()", "#", false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Long returnnumber = ByteArray.toLong(ByteArray + .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + Assert.assertTrue(1 == returnnumber); + + + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant013.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant013.java new file mode 100644 index 00000000000..d2ce96c2fe3 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant013.java @@ -0,0 +1,226 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.triggerconstant; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +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.api.WalletSolidityGrpc; +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.Base58; +import stest.tron.wallet.common.client.utils.PublicMethed; + +@Slf4j +public class TriggerConstant013 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + @Test(enabled = true, description = "triggerContract a constant function created by create2") + public void testTriggerContract() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TriggerConstant015.sol"; + String contractName = "Factory"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + + String contractName1 = "TestConstract"; + HashMap retMap1 = PublicMethed.getBycodeAbi(filePath, contractName1); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + String txid = ""; + String num = "\"" + code1 + "\"" + "," + 1; + txid = PublicMethed + .triggerContract(contractAddress, + "deploy(bytes,uint256)", num, false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + byte[] returnAddressBytes = infoById.get().getInternalTransactions(0).getTransferToAddress() + .toByteArray(); + String returnAddress = Base58.encode58Check(returnAddressBytes); + logger.info("returnAddress:" + returnAddress); + txid = PublicMethed + .triggerContract(returnAddressBytes, + "plusOne()", "#", false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById1 = null; + infoById1 = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee1 = infoById1.get().getFee(); + Long netUsed1 = infoById1.get().getReceipt().getNetUsage(); + Long energyUsed1 = infoById1.get().getReceipt().getEnergyUsage(); + Long netFee1 = infoById1.get().getReceipt().getNetFee(); + long energyUsageTotal1 = infoById1.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee1:" + fee1); + logger.info("netUsed1:" + netUsed1); + logger.info("energyUsed1:" + energyUsed1); + logger.info("netFee1:" + netFee1); + logger.info("energyUsageTotal1:" + energyUsageTotal1); + + Account infoafter1 = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter1 = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance1 = infoafter1.getBalance(); + Long afterEnergyUsed1 = resourceInfoafter1.getEnergyUsed(); + Long afterNetUsed1 = resourceInfoafter1.getNetUsed(); + Long afterFreeNetUsed1 = resourceInfoafter1.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance1); + logger.info("afterEnergyUsed:" + afterEnergyUsed1); + logger.info("afterNetUsed:" + afterNetUsed1); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed1); + + Assert.assertTrue(infoById1.get().getResultValue() == 0); + Assert.assertTrue(afterBalance1 + fee1 == afterBalance); + Assert.assertTrue(afterEnergyUsed + energyUsed1 >= afterEnergyUsed1); + Long returnnumber = ByteArray.toLong(ByteArray + .fromHexString(ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); + Assert.assertTrue(1 == returnnumber); + + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant014.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant014.java new file mode 100644 index 00000000000..f2f0a0faa1a --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant014.java @@ -0,0 +1,227 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.triggerconstant; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +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.api.WalletSolidityGrpc; +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.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 TriggerConstant014 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + @Test(enabled = true, description = "TriggerContract a non-constant function created by create2") + public void testTriggerContract() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/ClearAbi005.sol"; + String contractName = "Factory"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + + String contractName1 = "TestConstract"; + HashMap retMap1 = PublicMethed.getBycodeAbi(filePath, contractName1); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + String txid = ""; + String num = "\"" + code1 + "\"" + "," + 1; + txid = PublicMethed + .triggerContract(contractAddress, + "deploy(bytes,uint256)", num, false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + byte[] returnAddressBytes = infoById.get().getInternalTransactions(0).getTransferToAddress() + .toByteArray(); + String returnAddress = Base58.encode58Check(returnAddressBytes); + logger.info("returnAddress:" + returnAddress); + txid = PublicMethed + .triggerContract(returnAddressBytes, + "plusOne()", "#", false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById1 = null; + infoById1 = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee1 = infoById1.get().getFee(); + Long netUsed1 = infoById1.get().getReceipt().getNetUsage(); + Long energyUsed1 = infoById1.get().getReceipt().getEnergyUsage(); + Long netFee1 = infoById1.get().getReceipt().getNetFee(); + long energyUsageTotal1 = infoById1.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee1:" + fee1); + logger.info("netUsed1:" + netUsed1); + logger.info("energyUsed1:" + energyUsed1); + logger.info("netFee1:" + netFee1); + logger.info("energyUsageTotal1:" + energyUsageTotal1); + + Account infoafter1 = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter1 = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance1 = infoafter1.getBalance(); + Long afterEnergyUsed1 = resourceInfoafter1.getEnergyUsed(); + Long afterNetUsed1 = resourceInfoafter1.getNetUsed(); + Long afterFreeNetUsed1 = resourceInfoafter1.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance1); + logger.info("afterEnergyUsed:" + afterEnergyUsed1); + logger.info("afterNetUsed:" + afterNetUsed1); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed1); + + Assert.assertTrue(infoById1.get().getResultValue() == 0); + Assert.assertTrue(afterBalance1 + fee1 == afterBalance); + Assert.assertTrue(afterEnergyUsed + energyUsed1 >= afterEnergyUsed1); + Long returnnumber = ByteArray.toLong(ByteArray + .fromHexString(ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); + Assert.assertTrue(1 == returnnumber); + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant015.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant015.java new file mode 100644 index 00000000000..4731bf53695 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant015.java @@ -0,0 +1,211 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.triggerconstant; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +import java.util.Optional; +import java.util.concurrent.TimeUnit; +import lombok.extern.slf4j.Slf4j; +import org.junit.Assert; +import org.spongycastle.util.encoders.Hex; +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.GrpcAPI.TransactionExtention; +import org.tron.api.WalletGrpc; +import org.tron.api.WalletSolidityGrpc; +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.SmartContract; +import org.tron.protos.Protocol.Transaction; +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 TriggerConstant015 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + @Test(enabled = true, description = "TriggerConstantContract a constant function created by create2") + public void testTriggerConstantContract() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TriggerConstant015.sol"; + String contractName = "Factory"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + + String contractName1 = "TestConstract"; + HashMap retMap1 = PublicMethed.getBycodeAbi(filePath, contractName1); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + String txid = ""; + String num = "\"" + code1 + "\"" + "," + 1; + txid = PublicMethed + .triggerContract(contractAddress, + "deploy(bytes,uint256)", num, false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + byte[] returnAddressBytes = infoById.get().getInternalTransactions(0).getTransferToAddress() + .toByteArray(); + SmartContract smartContract = PublicMethed.getContract(returnAddressBytes, blockingStubFull); + Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + String returnAddress = Base58.encode58Check(returnAddressBytes); + logger.info("returnAddress:" + returnAddress); + TransactionExtention transactionExtention = PublicMethed + .triggerConstantContractForExtention(returnAddressBytes, + "plusOne()", "#", false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + Transaction transaction = transactionExtention.getTransaction(); + + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + System.out.println("message:" + transaction.getRet(0).getRet()); + System.out.println(":" + ByteArray + .toStr(transactionExtention.getResult().getMessage().toByteArray())); + System.out.println("Result:" + Hex.toHexString(result)); + + Assert.assertEquals(1, ByteArray.toLong(ByteArray + .fromHexString(Hex + .toHexString(result)))); + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant016.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant016.java new file mode 100644 index 00000000000..e98745bb30d --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant016.java @@ -0,0 +1,206 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.triggerconstant; + +import static org.hamcrest.core.StringContains.containsString; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +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.GrpcAPI.TransactionExtention; +import org.tron.api.WalletGrpc; +import org.tron.api.WalletSolidityGrpc; +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.Base58; +import stest.tron.wallet.common.client.utils.PublicMethed; + +@Slf4j +public class TriggerConstant016 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + @Test(enabled = true, description = "TriggerConstantContract a non-constant function created by create2") + public void testTriggerConstantContract() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/ClearAbi005.sol"; + String contractName = "Factory"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + + String contractName1 = "TestConstract"; + HashMap retMap1 = PublicMethed.getBycodeAbi(filePath, contractName1); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + String txid = ""; + String num = "\"" + code1 + "\"" + "," + 1; + txid = PublicMethed + .triggerContract(contractAddress, + "deploy(bytes,uint256)", num, false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + byte[] returnAddressBytes = infoById.get().getInternalTransactions(0).getTransferToAddress() + .toByteArray(); + String returnAddress = Base58.encode58Check(returnAddressBytes); + logger.info("returnAddress:" + returnAddress); + TransactionExtention transactionExtention = PublicMethed + .triggerConstantContractForExtention(returnAddressBytes, + "plusOne()", "#", false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + System.out.println("Code = " + transactionExtention.getResult().getCode()); + System.out + .println("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); + + Assert + .assertThat(transactionExtention.getResult().getCode().toString(), + containsString("CONTRACT_EXE_ERROR")); + Assert + .assertThat(transactionExtention.getResult().getMessage().toStringUtf8() + , containsString("Attempt to call a state modifying opcode inside STATICCALL")); + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant017.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant017.java new file mode 100644 index 00000000000..30b88200ad2 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant017.java @@ -0,0 +1,186 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.triggerconstant; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +import java.util.Optional; +import java.util.concurrent.TimeUnit; +import lombok.extern.slf4j.Slf4j; +import org.junit.Assert; +import org.spongycastle.util.encoders.Hex; +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.GrpcAPI.TransactionExtention; +import org.tron.api.WalletGrpc; +import org.tron.api.WalletSolidityGrpc; +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.SmartContract; +import org.tron.protos.Protocol.Transaction; +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 TriggerConstant017 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + @Test(enabled = true, description = "TriggerConstantContract a constant function which is " + + "deployed with ABI, but cleared ABI later") + public void testTriggerConstantContract() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/ClearAbi001.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + TransactionExtention transactionExtention = PublicMethed + .triggerConstantContractForExtention(contractAddress, + "testPayable()", "#", false, + 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + Transaction transaction = transactionExtention.getTransaction(); + + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + System.out.println("message:" + transaction.getRet(0).getRet()); + System.out.println(":" + ByteArray + .toStr(transactionExtention.getResult().getMessage().toByteArray())); + System.out.println("Result:" + Hex.toHexString(result)); + + Assert.assertEquals(1, ByteArray.toLong(ByteArray + .fromHexString(Hex + .toHexString(result)))); + String txid = ""; + txid = PublicMethed + .clearContractABI(contractAddress, contractExcAddress, contractExcKey, blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Assert.assertTrue(infoById.get().getResultValue() == 0); + + SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); + Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + + TransactionExtention transactionExtention1 = PublicMethed + .triggerConstantContractForExtention(contractAddress, + "testPayable()", "#", false, + 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + Transaction transaction1 = transactionExtention1.getTransaction(); + + byte[] result1 = transactionExtention1.getConstantResult(0).toByteArray(); + System.out.println("message:" + transaction1.getRet(0).getRet()); + System.out.println(":" + ByteArray + .toStr(transactionExtention1.getResult().getMessage().toByteArray())); + System.out.println("Result:" + Hex.toHexString(result1)); + + Assert.assertEquals(1, ByteArray.toLong(ByteArray + .fromHexString(Hex + .toHexString(result1)))); + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant018.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant018.java new file mode 100644 index 00000000000..8b2ccb15947 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant018.java @@ -0,0 +1,162 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.triggerconstant; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +import java.util.concurrent.TimeUnit; +import lombok.extern.slf4j.Slf4j; +import org.junit.Assert; +import org.spongycastle.util.encoders.Hex; +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.GrpcAPI.TransactionExtention; +import org.tron.api.WalletGrpc; +import org.tron.api.WalletSolidityGrpc; +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.SmartContract; +import org.tron.protos.Protocol.Transaction; +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 TriggerConstant018 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + @Test(enabled = true, description = "TriggerContract a pure function with ABI") + public void testTriggerContract() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TriggerConstant004.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); + Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + TransactionExtention transactionExtention = PublicMethed + .triggerContractForExtention(contractAddress, + "testPure()", "#", false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + + Transaction transaction = transactionExtention.getTransaction(); + + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + System.out.println("message:" + transaction.getRet(0).getRet()); + System.out.println(":" + ByteArray + .toStr(transactionExtention.getResult().getMessage().toByteArray())); + System.out.println("Result:" + Hex.toHexString(result)); + + Assert.assertEquals(1, ByteArray.toLong(ByteArray + .fromHexString(Hex + .toHexString(result)))); + + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant019.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant019.java new file mode 100644 index 00000000000..82c48a2715c --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant019.java @@ -0,0 +1,186 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.triggerconstant; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +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.api.WalletSolidityGrpc; +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.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; + +@Slf4j +public class TriggerConstant019 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + @Test(enabled = true, description = "TriggerContract a payable function with ABI") + public void testTriggerContract() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TriggerConstant001.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); + Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + txid = PublicMethed + .triggerContract(contractAddress, + "testPayable()", "#", false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Long returnnumber = ByteArray.toLong(ByteArray + .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + Assert.assertTrue(1 == returnnumber); + + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant020.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant020.java new file mode 100644 index 00000000000..a91d7f930a8 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant020.java @@ -0,0 +1,186 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.triggerconstant; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +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.api.WalletSolidityGrpc; +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.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; + +@Slf4j +public class TriggerConstant020 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + @Test(enabled = true, description = "TriggerContract a non-payable function with ABI") + public void testTriggerContract() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TriggerConstant002.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); + Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + txid = PublicMethed + .triggerContract(contractAddress, + "testNoPayable()", "#", false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Long returnnumber = ByteArray.toLong(ByteArray + .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + Assert.assertTrue(1 == returnnumber); + + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant021.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant021.java new file mode 100644 index 00000000000..c83423ef2ea --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant021.java @@ -0,0 +1,162 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.triggerconstant; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +import java.util.concurrent.TimeUnit; +import lombok.extern.slf4j.Slf4j; +import org.junit.Assert; +import org.spongycastle.util.encoders.Hex; +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.GrpcAPI.TransactionExtention; +import org.tron.api.WalletGrpc; +import org.tron.api.WalletSolidityGrpc; +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.SmartContract; +import org.tron.protos.Protocol.Transaction; +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 TriggerConstant021 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + @Test(enabled = true, description = "TriggerContract a view function with ABI") + public void testTriggerContract() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TriggerConstant003.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); + Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + TransactionExtention transactionExtention = PublicMethed + .triggerContractForExtention(contractAddress, + "testView()", "#", false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + + Transaction transaction = transactionExtention.getTransaction(); + + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + System.out.println("message:" + transaction.getRet(0).getRet()); + System.out.println(":" + ByteArray + .toStr(transactionExtention.getResult().getMessage().toByteArray())); + System.out.println("Result:" + Hex.toHexString(result)); + + Assert.assertEquals(1, ByteArray.toLong(ByteArray + .fromHexString(Hex + .toHexString(result)))); + + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant022.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant022.java new file mode 100644 index 00000000000..a20c69316ae --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant022.java @@ -0,0 +1,161 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.triggerconstant; + +import static org.hamcrest.core.StringContains.containsString; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +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.GrpcAPI.TransactionExtention; +import org.tron.api.WalletGrpc; +import org.tron.api.WalletSolidityGrpc; +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.SmartContract; +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 TriggerConstant022 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + @Test(enabled = true, description = "TriggerContract a non-payable function " + + "with ABI(constant ABI)") + public void testTriggerContract() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TriggerConstant002.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = "[{\"constant\":true,\"inputs\":[],\"name\":\"testNoPayable\",\"outputs\":[{\"name\":\"z\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"i\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"}]"; + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); + Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + TransactionExtention transactionExtention = PublicMethed + .triggerContractForExtention(contractAddress, + "testNoPayable()", "#", false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + System.out.println("Code = " + transactionExtention.getResult().getCode()); + System.out + .println("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); + + Assert + .assertThat(transactionExtention.getResult().getCode().toString(), + containsString("CONTRACT_EXE_ERROR")); + Assert + .assertThat(transactionExtention.getResult().getMessage().toStringUtf8() + , containsString("Attempt to call a state modifying opcode inside STATICCALL")); + + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant023.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant023.java new file mode 100644 index 00000000000..55b93b81b0c --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant023.java @@ -0,0 +1,161 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.triggerconstant; + +import static org.hamcrest.core.StringContains.containsString; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +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.GrpcAPI.TransactionExtention; +import org.tron.api.WalletGrpc; +import org.tron.api.WalletSolidityGrpc; +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.SmartContract; +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 TriggerConstant023 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + @Test(enabled = true, description = "TriggerConstantContract a non-payable function with" + + " ABI(constant ABI )") + public void testTriggerConstantContract() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TriggerConstant002.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = "[{\"constant\":true,\"inputs\":[],\"name\":\"testNoPayable\",\"outputs\":[{\"name\":\"z\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"i\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"}]"; + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); + Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + TransactionExtention transactionExtention = PublicMethed + .triggerConstantContractForExtention(contractAddress, + "testNoPayable()", "#", false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + System.out.println("Code = " + transactionExtention.getResult().getCode()); + System.out + .println("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); + + Assert + .assertThat(transactionExtention.getResult().getCode().toString(), + containsString("CONTRACT_EXE_ERROR")); + Assert + .assertThat(transactionExtention.getResult().getMessage().toStringUtf8() + , containsString("Attempt to call a state modifying opcode inside STATICCALL")); + + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant024.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant024.java new file mode 100644 index 00000000000..02669c90f95 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant024.java @@ -0,0 +1,169 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.triggerconstant; + +import static org.hamcrest.core.StringContains.containsString; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +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.GrpcAPI.TransactionExtention; +import org.tron.api.WalletGrpc; +import org.tron.api.WalletSolidityGrpc; +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.SmartContract; +import org.tron.protos.Protocol.Transaction; +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 TriggerConstant024 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + @Test(enabled = true, description = "TriggerConstantContract a view method with ABI ,method has " + + "revert()") + public void testTriggerConstantContract() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TriggerConstant024.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); + Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + + TransactionExtention transactionExtention = PublicMethed + .triggerConstantContractForExtention(contractAddress, + "testView()", "#", false, + 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + + Transaction transaction = transactionExtention.getTransaction(); + + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + System.out.println("message:" + transaction.getRet(0).getRet()); + System.out.println(":" + ByteArray + .toStr(transactionExtention.getResult().getMessage().toByteArray())); + + Assert + .assertThat(transaction.getRet(0).getRet().toString(), + containsString("FAILED")); + Assert + .assertThat(ByteArray + .toStr(transactionExtention.getResult().getMessage().toByteArray()) + , containsString("REVERT opcode executed")); + + + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant025.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant025.java new file mode 100644 index 00000000000..b4b8cfffa97 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant025.java @@ -0,0 +1,169 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.triggerconstant; + +import static org.hamcrest.core.StringContains.containsString; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +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.GrpcAPI.TransactionExtention; +import org.tron.api.WalletGrpc; +import org.tron.api.WalletSolidityGrpc; +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.SmartContract; +import org.tron.protos.Protocol.Transaction; +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 TriggerConstant025 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + @Test(enabled = true, description = "TriggerContract a view method with ABI ,method has " + + "revert()") + public void testTriggerContract() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TriggerConstant024.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); + Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + + TransactionExtention transactionExtention = PublicMethed + .triggerContractForExtention(contractAddress, + "testView()", "#", false, + 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + + Transaction transaction = transactionExtention.getTransaction(); + + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + System.out.println("message:" + transaction.getRet(0).getRet()); + System.out.println(":" + ByteArray + .toStr(transactionExtention.getResult().getMessage().toByteArray())); + + Assert + .assertThat(transaction.getRet(0).getRet().toString(), + containsString("FAILED")); + Assert + .assertThat(ByteArray + .toStr(transactionExtention.getResult().getMessage().toByteArray()) + , containsString("REVERT opcode executed")); + + + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant026.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant026.java new file mode 100644 index 00000000000..70d357f622c --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant026.java @@ -0,0 +1,171 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.triggerconstant; + +import static org.hamcrest.core.StringContains.containsString; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +import java.util.concurrent.TimeUnit; +import lombok.extern.slf4j.Slf4j; +import org.junit.Assert; +import org.spongycastle.util.encoders.Hex; +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.GrpcAPI.TransactionExtention; +import org.tron.api.WalletGrpc; +import org.tron.api.WalletSolidityGrpc; +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.SmartContract; +import org.tron.protos.Protocol.Transaction; +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 TriggerConstant026 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + @Test(enabled = true, description = "TriggerConstantContract a view method without ABI,method has" + + "revert()") + public void testTriggerConstantContract() { + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TriggerConstant004.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, "[]", code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); + Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + + TransactionExtention transactionExtention = PublicMethed + .triggerConstantContractForExtention(contractAddress, + "testView()", "#", false, + 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + + Transaction transaction = transactionExtention.getTransaction(); + + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + System.out.println("message:" + transaction.getRet(0).getRet()); + System.out.println(":" + ByteArray + .toStr(transactionExtention.getResult().getMessage().toByteArray())); + System.out.println("Result:" + Hex.toHexString(result)); + + Assert + .assertThat(transaction.getRet(0).getRet().toString(), + containsString("FAILED")); + Assert + .assertThat(ByteArray + .toStr(transactionExtention.getResult().getMessage().toByteArray()) + , containsString("REVERT opcode executed")); + + + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} diff --git a/src/test/resources/soliditycode/TriggerConstant024.sol b/src/test/resources/soliditycode/TriggerConstant024.sol new file mode 100644 index 00000000000..287b0fc9782 --- /dev/null +++ b/src/test/resources/soliditycode/TriggerConstant024.sol @@ -0,0 +1,9 @@ +//pragma solidity ^0.4.0; + +contract testConstantContract{ +function testView() public view returns (uint256 z) { +uint256 i=1; +revert(); +return i; +} +} \ No newline at end of file From 505165aaaddef9d352241a293a172de24ab017ac Mon Sep 17 00:00:00 2001 From: dannaguo Date: Mon, 6 May 2019 19:11:30 +0800 Subject: [PATCH 03/90] add create2 and extcodehash test cases --- .../common/client/utils/PublicMethed.java | 31 + .../tvmnewcommand/create2/Create2Test001.java | 363 +++++++++ .../tvmnewcommand/create2/Create2Test002.java | 363 +++++++++ .../tvmnewcommand/create2/Create2Test003.java | 508 +++++++++++++ .../tvmnewcommand/create2/Create2Test004.java | 471 ++++++++++++ .../tvmnewcommand/create2/Create2Test005.java | 359 +++++++++ .../tvmnewcommand/create2/Create2Test006.java | 358 +++++++++ .../tvmnewcommand/create2/Create2Test007.java | 358 +++++++++ .../tvmnewcommand/create2/Create2Test008.java | 358 +++++++++ .../tvmnewcommand/create2/Create2Test009.java | 365 +++++++++ .../tvmnewcommand/create2/Create2Test010.java | 210 ++++++ .../tvmnewcommand/create2/Create2Test011.java | 369 ++++++++++ .../tvmnewcommand/create2/Create2Test012.java | 396 ++++++++++ .../tvmnewcommand/create2/Create2Test013.java | 436 +++++++++++ .../tvmnewcommand/create2/Create2Test014.java | 560 ++++++++++++++ .../tvmnewcommand/create2/Create2Test015.java | 422 +++++++++++ .../tvmnewcommand/create2/Create2Test016.java | 421 +++++++++++ .../tvmnewcommand/create2/Create2Test017.java | 405 ++++++++++ .../tvmnewcommand/create2/Create2Test018.java | 360 +++++++++ .../extCodeHash/ExtCodeHashTest001.java | 246 +++++++ .../extCodeHash/ExtCodeHashTest002.java | 244 ++++++ .../extCodeHash/ExtCodeHashTest003.java | 334 +++++++++ .../extCodeHash/ExtCodeHashTest004.java | 254 +++++++ .../extCodeHash/ExtCodeHashTest005.java | 697 ++++++++++++++++++ .../extCodeHash/ExtCodeHashTest006.java | 184 +++++ .../extCodeHash/ExtCodeHashTest007.java | 601 +++++++++++++++ .../extCodeHash/ExtCodeHashTest008.java | 512 +++++++++++++ .../soliditycode/create2CallContract.sol | 37 + .../soliditycode/create2contract.sol | 39 + .../resources/soliditycode/extCodeHash.sol | 13 + .../soliditycode/extCodeHashConstruct.sol | 14 + .../soliditycode/extCodeHashTestNoPayable.sol | 8 + 32 files changed, 10296 insertions(+) create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test001.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test002.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test003.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test004.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test005.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test006.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test007.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test008.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test009.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test010.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test011.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test012.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test013.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test014.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test015.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test016.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test017.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test018.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest001.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest002.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest003.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest004.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest005.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest006.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest007.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest008.java create mode 100644 src/test/resources/soliditycode/create2CallContract.sol create mode 100644 src/test/resources/soliditycode/create2contract.sol create mode 100644 src/test/resources/soliditycode/extCodeHash.sol create mode 100644 src/test/resources/soliditycode/extCodeHashConstruct.sol create mode 100644 src/test/resources/soliditycode/extCodeHashTestNoPayable.sol diff --git a/src/test/java/stest/tron/wallet/common/client/utils/PublicMethed.java b/src/test/java/stest/tron/wallet/common/client/utils/PublicMethed.java index eb82f070cfe..7a90531d481 100644 --- a/src/test/java/stest/tron/wallet/common/client/utils/PublicMethed.java +++ b/src/test/java/stest/tron/wallet/common/client/utils/PublicMethed.java @@ -2,6 +2,7 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.google.common.primitives.Longs; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonParser; @@ -46,6 +47,7 @@ import org.tron.common.crypto.ECKey.ECDSASignature; import org.tron.common.crypto.Hash; import org.tron.common.utils.ByteArray; +import org.tron.common.utils.ByteUtil; import org.tron.core.Wallet; import org.tron.keystore.WalletFile; import org.tron.protos.Contract; @@ -3991,4 +3993,33 @@ public static TransactionExtention triggerContractForExtention(byte[] contractAd } + public static String create2(String[] parameters) { + if (parameters == null || parameters.length != 3) { + logger.error("create2 needs 3 parameter:\ncreate2 address code salt"); + return null; + } + + byte[] address = WalletClient.decodeFromBase58Check(parameters[0]); + if (!WalletClient.addressValid(address)) { + logger.error("length of address must be 21 bytes."); + return null; + } + + byte[] code = Hex.decode(parameters[1]); + byte[] temp = Longs.toByteArray(Long.parseLong(parameters[2])); + if (temp.length != 8) { + logger.error("Invalid salt!"); + return null; + } + byte[] salt = new byte[32]; + System.arraycopy(temp, 0, salt, 24, 8); + + byte[] mergedData = ByteUtil.merge(address, salt, Hash.sha3(code)); + String create2Address = Base58.encode58Check(Hash.sha3omit12(mergedData)); + + logger.info("create2 Address: " + create2Address); + + return create2Address; + } + } \ No newline at end of file diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test001.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test001.java new file mode 100644 index 00000000000..58a02bff896 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test001.java @@ -0,0 +1,363 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.create2; + +import com.google.protobuf.ByteString; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +import java.util.List; +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.WalletClient; +import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.PublicMethed; + +@Slf4j +public class Create2Test001 { + + private final String testKey002 = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + 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(1); + private long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + + private byte[] factoryContractAddress = null; + private byte[] testContractAddress = null; + + private ECKey ecKey1 = new ECKey(Utils.getRandom()); + private byte[] dev001Address = ecKey1.getAddress(); + private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + private ECKey ecKey2 = new ECKey(Utils.getRandom()); + private byte[] user001Address = ecKey2.getAddress(); + private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + @BeforeClass(enabled = true) + public void beforeClass() { + + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + + PublicMethed.printAddress(dev001Key); + PublicMethed.printAddress(user001Key); + } + + @Test(enabled = true, description = "Deploy factory contract generated by new solidity") + public void test01DeployFactoryContract() { + Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, + 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + //before deploy, check account resource + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long energyLimit = accountResource.getEnergyLimit(); + long energyUsage = accountResource.getEnergyUsed(); + long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before energyLimit is " + Long.toString(energyLimit)); + logger.info("before energyUsage is " + Long.toString(energyUsage)); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "Factory"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + final String transferTokenTxid = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", + maxFeeLimit, 0L, 0, 10000, + "0", 0, null, dev001Key, + dev001Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + energyLimit = accountResource.getEnergyLimit(); + energyUsage = accountResource.getEnergyUsed(); + long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + + logger.info("after energyLimit is " + Long.toString(energyLimit)); + logger.info("after energyUsage is " + Long.toString(energyUsage)); + logger.info("after balanceAfter is " + Long.toString(balanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); + } + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + factoryContractAddress = infoById.get().getContractAddress().toByteArray(); + SmartContract smartContract = PublicMethed.getContract(factoryContractAddress, + blockingStubFull); + Assert.assertNotNull(smartContract.getAbi()); + } + + + @Test(enabled = true, description = "Trigger create2 function to deploy test contract") + public void test02TriggerCreate2ToDeployTestContract() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String testContractCode = retMap.get("byteCode").toString(); + + Long salt = 1L; + + String param = "\"" + testContractCode + "\"," + salt; + + final String triggerTxid = PublicMethed.triggerContract(factoryContractAddress, + "deploy(bytes,uint256)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + logger.info( + "the value: " + PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + + List retList = PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + + logger.info("actualSalt: " + actualSalt); + + byte[] tmpAddress = new byte[20]; + System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); + logger.info("address_hex: " + addressHex); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + logger.info("address_final: " + addressFinal); + + testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("transaction failed with message: " + + infoById.get().getResMessage().toStringUtf8()); + } + + SmartContract smartContract = PublicMethed.getContract(testContractAddress, blockingStubFull); + + // contract created by create2, doesn't have ABI + Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); + + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); + + // the contract address in transaction info, + // contract address of create2 contract is factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); + + String msgSender = Base58.encode58Check(ByteArray.fromHexString(retList.get(2))); + Assert.assertNotEquals(msgSender, Base58.encode58Check(user001Address)); + } + + + @Test(enabled = true, description = "Trigger Test contact") + public void test03TriggerTestContract() { + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + final String triggerTxid = PublicMethed.triggerContract(testContractAddress, + "plusOne()", "#", false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + logger.info( + "the value: " + PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray())); + + List retList = PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray()); + + Long ret = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); + + logger.info("ret: " + ret); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("transaction failed with message: " + infoById.get().getResMessage()); + } + + SmartContract smartContract = PublicMethed.getContract(infoById.get().getContractAddress() + .toByteArray(), blockingStubFull); + + long consumeUserPercent = smartContract.getConsumeUserResourcePercent(); + logger.info("ConsumeURPercent: " + consumeUserPercent); + + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + user001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + user001Address, blockingStubFull); + + } + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } +} + + diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test002.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test002.java new file mode 100644 index 00000000000..88571f54032 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test002.java @@ -0,0 +1,363 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.create2; + +import com.google.protobuf.ByteString; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +import java.util.List; +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.WalletClient; +import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.PublicMethed; + +@Slf4j +public class Create2Test002 { + + private final String testKey002 = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + 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(1); + private long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + + private byte[] factoryContractAddress = null; + private byte[] testContractAddress = null; + + private ECKey ecKey1 = new ECKey(Utils.getRandom()); + private byte[] dev001Address = ecKey1.getAddress(); + private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + private ECKey ecKey2 = new ECKey(Utils.getRandom()); + private byte[] user001Address = ecKey2.getAddress(); + private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + @BeforeClass(enabled = true) + public void beforeClass() { + + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + + PublicMethed.printAddress(dev001Key); + PublicMethed.printAddress(user001Key); + } + + @Test(enabled = true, description = "Deploy factory contract") + public void test01DeployFactoryContract() { + Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, + 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + //before deploy, check account resource + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long energyLimit = accountResource.getEnergyLimit(); + long energyUsage = accountResource.getEnergyUsed(); + long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before energyLimit is " + Long.toString(energyLimit)); + logger.info("before energyUsage is " + Long.toString(energyUsage)); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "Factory"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + final String transferTokenTxid = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", + maxFeeLimit, 0L, 0, 10000, + "0", 0, null, dev001Key, + dev001Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + energyLimit = accountResource.getEnergyLimit(); + energyUsage = accountResource.getEnergyUsed(); + long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + + logger.info("after energyLimit is " + Long.toString(energyLimit)); + logger.info("after energyUsage is " + Long.toString(energyUsage)); + logger.info("after balanceAfter is " + Long.toString(balanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); + } + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + factoryContractAddress = infoById.get().getContractAddress().toByteArray(); + SmartContract smartContract = PublicMethed.getContract(factoryContractAddress, + blockingStubFull); + Assert.assertNotNull(smartContract.getAbi()); + } + + + @Test(enabled = true, description = "Trigger create2 command without meta data hash in bytecode") + public void test02TriggerCreate2ToDeployTestContract() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String testContractCode = "608060405234801561001057600080fd5b50d3801561001d57600080fd5b50d2801" + + "561002a57600080fd5b5060c9806100396000396000f3fe6080604052348015600f57600080fd5b50d38015" + + "601b57600080fd5b50d28015602757600080fd5b50600436106066577c01000000000000000000000000000" + + "00000000000000000000000000000600035046368e5c0668114606b578063e5aa3d58146083575b600080fd" + + "5b60716089565b60408051918252519081900360200190f35b60716097565b6000805460010190819055905" + + "65b6000548156fe"; + + Long salt = 1L; + + String param = "\"" + testContractCode + "\"," + salt; + + final String triggerTxid = PublicMethed.triggerContract(factoryContractAddress, + "deploy(bytes,uint256)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + logger.info( + "the value: " + PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + + List retList = PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + + logger.info("actualSalt: " + actualSalt); + + byte[] tmpAddress = new byte[20]; + System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); + logger.info("address_hex: " + addressHex); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + logger.info("address_final: " + addressFinal); + + testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); + + SmartContract smartContract = PublicMethed.getContract(testContractAddress, blockingStubFull); + + // contract created by create2, doesn't have ABI + Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); + + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); + + // the contract address in transaction info, + // contract address of create2 contract is factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); + + String msgSender = Base58.encode58Check(ByteArray.fromHexString(retList.get(2))); + Assert.assertNotEquals(msgSender, Base58.encode58Check(user001Address)); + } + + + @Test(enabled = true, description = "Trigger Test contract") + public void test03TriggerTestContract() { + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + final String triggerTxid = PublicMethed.triggerContract(testContractAddress, + "plusOne()", "#", false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + logger.info( + "the value: " + PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray())); + + List retList = PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray()); + + Long ret = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); + + logger.info("ret: " + ret); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("transaction failed with message: " + infoById.get().getResMessage()); + } + + SmartContract smartContract = PublicMethed.getContract(infoById.get().getContractAddress() + .toByteArray(), blockingStubFull); + + long consumeUserPercent = smartContract.getConsumeUserResourcePercent(); + logger.info("ConsumeURPercent: " + consumeUserPercent); + + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + user001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + user001Address, blockingStubFull); + } + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } +} + + diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test003.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test003.java new file mode 100644 index 00000000000..ed433350800 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test003.java @@ -0,0 +1,508 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.create2; + +import static org.hamcrest.core.StringContains.containsString; + +import com.google.protobuf.ByteString; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +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.PublicMethed; + +@Slf4j +public class Create2Test003 { + + private final String testKey002 = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + 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(1); + private long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + + private byte[] factoryContractAddress = null; + private byte[] testContractAddress = null; + + private ECKey ecKey1 = new ECKey(Utils.getRandom()); + private byte[] dev001Address = ecKey1.getAddress(); + private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + private ECKey ecKey2 = new ECKey(Utils.getRandom()); + private byte[] user001Address = ecKey2.getAddress(); + private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + @BeforeClass(enabled = true) + public void beforeClass() { + + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + + PublicMethed.printAddress(dev001Key); + PublicMethed.printAddress(user001Key); + } + + @Test(enabled = true, description = "Deploy factory contract") + public void test01DeployFactoryContract() { + Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, + 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + //before deploy, check account resource + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long energyLimit = accountResource.getEnergyLimit(); + long energyUsage = accountResource.getEnergyUsed(); + long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before energyLimit is " + Long.toString(energyLimit)); + logger.info("before energyUsage is " + Long.toString(energyUsage)); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "Factory"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + final String transferTokenTxid = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", + maxFeeLimit, 0L, 0, 10000, + "0", 0, null, dev001Key, + dev001Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + energyLimit = accountResource.getEnergyLimit(); + energyUsage = accountResource.getEnergyUsed(); + long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + + logger.info("after energyLimit is " + Long.toString(energyLimit)); + logger.info("after energyUsage is " + Long.toString(energyUsage)); + logger.info("after balanceAfter is " + Long.toString(balanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); + } + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + factoryContractAddress = infoById.get().getContractAddress().toByteArray(); + SmartContract smartContract = PublicMethed.getContract(factoryContractAddress, + blockingStubFull); + Assert.assertNotNull(smartContract.getAbi()); + } + + @Test(enabled = true, description = "Trigger create2 command with invalid bytecode") + public void test02TriggerCreate2WithInvalidBytecode() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String testContractCode = "608060405234801561001057600080fd5b50d3801561001d57600080fd5b50d2801" + + "561002a57600080fd5b5060c9806100396000396000f5fe6080604052348015600f57600080fd5b50d38015" + + "601b57600080fd5b50d28015602757600080fd5b50600436106066577c01000000000000000000000000000" + + "00000000000000000000000000000600035046368e5c0668114606b578063e5aa3d58146083575b600080fd" + + "5b60716089565b60408051918252519081900360200190f35b60716097565b6000805460010190819055905" + + "65b6000548156fea165627a7a72305820f3e3c0646a8c8d521fe819f10a592327469f611f0d9e8206697f7f" + + "3436ff3c7d0029"; + + Long salt = 1L; + + String param = "\"" + testContractCode + "\"," + salt; + + final String triggerTxid = PublicMethed.triggerContract(factoryContractAddress, + "deploy(bytes,uint256)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + Assert.assertEquals(1, infoById.get().getResultValue()); + Assert + .assertThat(infoById.get().getResMessage().toStringUtf8(), + containsString("Not enough energy for 'SWAP1' operation executing")); + } + + @Test(enabled = true, description = "Trigger create2 command with empty bytecode") + public void test03TriggerCreate2WithEmptyBytecode() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String testContractCode = ""; + + Long salt = 1L; + + String param = "\"" + testContractCode + "\"," + salt; + + final String triggerTxid = PublicMethed.triggerContract(factoryContractAddress, + "deploy(bytes,uint256)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + Assert.assertEquals(1, infoById.get().getResultValue()); + Assert + .assertThat(infoById.get().getResMessage().toStringUtf8(), + containsString("REVERT opcode executed")); + } + + @Test(enabled = true, description = "Trigger create2 command with \"6080\" bytecode") + public void test04TriggerCreate2WithShortBytecode() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String testContractCode = "6080"; + + Long salt = 1L; + + String param = "\"" + testContractCode + "\"," + salt; + + final String triggerTxid = PublicMethed.triggerContract(factoryContractAddress, + "deploy(bytes,uint256)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + Assert.assertEquals(1, infoById.get().getResultValue()); + Assert + .assertThat(infoById.get().getResMessage().toStringUtf8(), + containsString("REVERT opcode executed")); + } + + @Test(enabled = true, description = "Trigger create2 command with \"00000000000\" bytecode") + public void test05TriggerCreate2WithZeroBytecode() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String testContractCode = "000000000000000000000000000000"; + + Long salt = 1L; + + String param = "\"" + testContractCode + "\"," + salt; + + final String triggerTxid = PublicMethed.triggerContract(factoryContractAddress, + "deploy(bytes,uint256)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + Assert.assertEquals(1, infoById.get().getResultValue()); + Assert + .assertThat(infoById.get().getResMessage().toStringUtf8(), + containsString("REVERT opcode executed")); + } + + @Test(enabled = true, description = "Trigger create2 command with NULL bytecode") + public void test06TriggerCreate2WithNullBytecode() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String testContractCode = null; + + Long salt = 1L; + + String param = "\"" + testContractCode + "\"," + salt; + boolean ret = false; + + try { + final String triggerTxid = PublicMethed.triggerContract(factoryContractAddress, + "deploy(bytes,uint256)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + } catch (org.spongycastle.util.encoders.DecoderException e) { + logger.info("Expected org.spongycastle.util.encoders.DecoderException!"); + ret = true; + } + Assert.assertTrue(ret); + + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + user001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + user001Address, blockingStubFull); + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } +} + + diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test004.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test004.java new file mode 100644 index 00000000000..cce87979d19 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test004.java @@ -0,0 +1,471 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.create2; + +import static org.hamcrest.core.StringContains.containsString; + +import com.google.protobuf.ByteString; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +import java.util.List; +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.WalletClient; +import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.PublicMethed; + +@Slf4j +public class Create2Test004 { + + private final String testKey002 = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + 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(1); + private long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + + private byte[] factoryContractAddress = null; + private byte[] factoryContractAddress2 = null; + private byte[] testContractAddress = null; + private byte[] testContractAddress2 = null; + + private ECKey ecKey1 = new ECKey(Utils.getRandom()); + private byte[] dev001Address = ecKey1.getAddress(); + private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + private ECKey ecKey2 = new ECKey(Utils.getRandom()); + private byte[] user001Address = ecKey2.getAddress(); + private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + @BeforeClass(enabled = true) + public void beforeClass() { + + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + + PublicMethed.printAddress(dev001Key); + PublicMethed.printAddress(user001Key); + } + + @Test(enabled = true, description = "Deploy factory contract") + public void test01DeployFactoryContract() { + Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, + 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + //before deploy, check account resource + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long energyLimit = accountResource.getEnergyLimit(); + long energyUsage = accountResource.getEnergyUsed(); + long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before energyLimit is " + Long.toString(energyLimit)); + logger.info("before energyUsage is " + Long.toString(energyUsage)); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "Factory"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + final String transferTokenTxid = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", + maxFeeLimit, 0L, 0, 10000, + "0", 0, null, dev001Key, + dev001Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + energyLimit = accountResource.getEnergyLimit(); + energyUsage = accountResource.getEnergyUsed(); + long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + + logger.info("after energyLimit is " + Long.toString(energyLimit)); + logger.info("after energyUsage is " + Long.toString(energyUsage)); + logger.info("after balanceAfter is " + Long.toString(balanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); + } + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + factoryContractAddress = infoById.get().getContractAddress().toByteArray(); + SmartContract smartContract = PublicMethed.getContract(factoryContractAddress, + blockingStubFull); + Assert.assertNotNull(smartContract.getAbi()); + } + + @Test(enabled = true, description = "Trigger create2 command with factory bytecode") + public void test02TriggerCreate2ToDeployFactory2Contract() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 150000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "Factory"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String testContractCode = retMap.get("byteCode").toString(); + + Long salt = 1L; + + String param = "\"" + testContractCode + "\"," + salt; + + final String triggerTxid = PublicMethed.triggerContract(factoryContractAddress, + "deploy(bytes,uint256)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + logger.info( + "the value: " + PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + + List retList = PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + + logger.info("actualSalt: " + actualSalt); + + byte[] tmpAddress = new byte[20]; + System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); + logger.info("address_hex: " + addressHex); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + logger.info("address_final: " + addressFinal); + + factoryContractAddress2 = WalletClient.decodeFromBase58Check(addressFinal); + + SmartContract smartContract = PublicMethed + .getContract(factoryContractAddress2, blockingStubFull); + + // contract created by create2, doesn't have ABI + Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); + + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); + + // the contract address in transaction info, + // contract address of create2 contract is factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); + } + + + @Test(enabled = true, description = "Trigger create2 command with test bytecode using factory") + public void test03TriggerCreate2ToDeployTestContract() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 80000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String testContractCode = retMap.get("byteCode").toString(); + + Long salt = 1L; + + String param = "\"" + testContractCode + "\"," + salt; + + final String triggerTxid = PublicMethed.triggerContract(factoryContractAddress, + "deploy(bytes,uint256)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + logger.info( + "the value: " + PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + + List retList = PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + + logger.info("actualSalt: " + actualSalt); + + byte[] tmpAddress = new byte[20]; + System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); + logger.info("address_hex: " + addressHex); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + logger.info("address_final: " + addressFinal); + + testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); + + SmartContract smartContract = PublicMethed.getContract(testContractAddress, blockingStubFull); + + // contract created by create2, doesn't have ABI + Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); + + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); + + // the contract address in transaction info, + // contract address of create2 contract is factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); + + // different contract address with different bytecode, same salt and address + Assert.assertNotEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(testContractAddress)); + } + + @Test(enabled = true, description = "Trigger create2 command with test bytecode using factory2") + public void test04TriggerCreate2ToDeployTestContract2() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 80000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String testContractCode = retMap.get("byteCode").toString(); + + Long salt = 1L; + + String param = "\"" + testContractCode + "\"," + salt; + + final String triggerTxid = PublicMethed.triggerContract(factoryContractAddress2, + "deploy(bytes,uint256)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + Assert.assertEquals(1, infoById.get().getResultValue()); + Assert + .assertThat(infoById.get().getResMessage().toStringUtf8(), + containsString("Not enough energy for 'SWAP1' operation executing")); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + user001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + user001Address, blockingStubFull); + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } +} + + diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test005.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test005.java new file mode 100644 index 00000000000..1d68ee02648 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test005.java @@ -0,0 +1,359 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.create2; + +import com.google.protobuf.ByteString; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +import java.util.List; +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.WalletClient; +import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.PublicMethed; + +@Slf4j +public class Create2Test005 { + + private final String testKey002 = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + 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(1); + private long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + + private byte[] factoryContractAddress = null; + private byte[] testContractAddress = null; + + private ECKey ecKey1 = new ECKey(Utils.getRandom()); + private byte[] dev001Address = ecKey1.getAddress(); + private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + private ECKey ecKey2 = new ECKey(Utils.getRandom()); + private byte[] user001Address = ecKey2.getAddress(); + private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + @BeforeClass(enabled = true) + public void beforeClass() { + + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + + PublicMethed.printAddress(dev001Key); + PublicMethed.printAddress(user001Key); + } + + @Test(enabled = true, description = "Deploy factory contract") + public void test01DeployFactoryContract() { + Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, + 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + //before deploy, check account resource + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long energyLimit = accountResource.getEnergyLimit(); + long energyUsage = accountResource.getEnergyUsed(); + long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before energyLimit is " + Long.toString(energyLimit)); + logger.info("before energyUsage is " + Long.toString(energyUsage)); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "Factory"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + final String transferTokenTxid = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", + maxFeeLimit, 0L, 0, 10000, + "0", 0, null, dev001Key, + dev001Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + energyLimit = accountResource.getEnergyLimit(); + energyUsage = accountResource.getEnergyUsed(); + long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + + logger.info("after energyLimit is " + Long.toString(energyLimit)); + logger.info("after energyUsage is " + Long.toString(energyUsage)); + logger.info("after balanceAfter is " + Long.toString(balanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); + } + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + factoryContractAddress = infoById.get().getContractAddress().toByteArray(); + SmartContract smartContract = PublicMethed.getContract(factoryContractAddress, + blockingStubFull); + Assert.assertNotNull(smartContract.getAbi()); + } + + + @Test(enabled = true, description = "Trigger create2 command with 0 extended bytecode") + public void test02TriggerCreate2ToDeployTestContract() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String testContractCode = "608060405234801561001057600080fd5b50d3801561001d57600080fd5b50d2801" + + "561002a57600080fd5b5060c9806100396000396000f3fe6080604052348015600f57600080fd5b50d38015" + + "601b57600080fd5b50d28015602757600080fd5b50600436106066577c01000000000000000000000000000" + + "00000000000000000000000000000600035046368e5c0668114606b578063e5aa3d58146083575b600080fd" + + "5b60716089565b60408051918252519081900360200190f35b60716097565b6000805460010190819055905" + + "65b6000548156fe0000000000000000000000000000000000000000000000000000000000000000000000"; + + Long salt = 1L; + + String param = "\"" + testContractCode + "\"," + salt; + + final String triggerTxid = PublicMethed.triggerContract(factoryContractAddress, + "deploy(bytes,uint256)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + logger.info( + "the value: " + PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + + List retList = PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + + logger.info("actualSalt: " + actualSalt); + + byte[] tmpAddress = new byte[20]; + System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); + logger.info("address_hex: " + addressHex); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + logger.info("address_final: " + addressFinal); + + testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); + + SmartContract smartContract = PublicMethed.getContract(testContractAddress, blockingStubFull); + + // contract created by create2, doesn't have ABI + Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); + + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); + + // the contract address in transaction info, + // contract address of create2 contract is factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); + } + + + @Test(enabled = true, description = "Trigger test contract") + public void test03TriggerTestContract() { + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + final String triggerTxid = PublicMethed.triggerContract(testContractAddress, + "plusOne()", "#", false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + logger.info( + "the value: " + PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray())); + + List retList = PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray()); + + Long ret = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); + + logger.info("ret: " + ret); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("transaction failed with message: " + infoById.get().getResMessage()); + } + + SmartContract smartContract = PublicMethed.getContract(infoById.get().getContractAddress() + .toByteArray(), blockingStubFull); + + long consumeUserPercent = smartContract.getConsumeUserResourcePercent(); + logger.info("ConsumeURPercent: " + consumeUserPercent); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + user001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + user001Address, blockingStubFull); + } + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } +} + + diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test006.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test006.java new file mode 100644 index 00000000000..fc13e53508d --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test006.java @@ -0,0 +1,358 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.create2; + +import com.google.protobuf.ByteString; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +import java.util.List; +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.WalletClient; +import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.PublicMethed; + +@Slf4j +public class Create2Test006 { + + private final String testKey002 = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + 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(1); + private long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + + private byte[] factoryContractAddress = null; + private byte[] testContractAddress = null; + + private ECKey ecKey1 = new ECKey(Utils.getRandom()); + private byte[] dev001Address = ecKey1.getAddress(); + private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + private ECKey ecKey2 = new ECKey(Utils.getRandom()); + private byte[] user001Address = ecKey2.getAddress(); + private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + @BeforeClass(enabled = true) + public void beforeClass() { + + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + + PublicMethed.printAddress(dev001Key); + PublicMethed.printAddress(user001Key); + } + + @Test(enabled = true, description = "Deploy factory contract") + public void test01DeployFactoryContract() { + Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, + 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + //before deploy, check account resource + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long energyLimit = accountResource.getEnergyLimit(); + long energyUsage = accountResource.getEnergyUsed(); + long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before energyLimit is " + Long.toString(energyLimit)); + logger.info("before energyUsage is " + Long.toString(energyUsage)); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "Factory"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + final String transferTokenTxid = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", + maxFeeLimit, 0L, 0, 10000, + "0", 0, null, dev001Key, + dev001Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + energyLimit = accountResource.getEnergyLimit(); + energyUsage = accountResource.getEnergyUsed(); + long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + + logger.info("after energyLimit is " + Long.toString(energyLimit)); + logger.info("after energyUsage is " + Long.toString(energyUsage)); + logger.info("after balanceAfter is " + Long.toString(balanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); + } + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + factoryContractAddress = infoById.get().getContractAddress().toByteArray(); + SmartContract smartContract = PublicMethed.getContract(factoryContractAddress, + blockingStubFull); + Assert.assertNotNull(smartContract.getAbi()); + } + + @Test(enabled = true, description = "Trigger create2 with salt 0") + public void test02TriggerCreate2ToDeployTestContract() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String testContractCode = retMap.get("byteCode").toString(); + Long salt = 0L; + + String param = "\"" + testContractCode + "\"," + salt; + + final String triggerTxid = PublicMethed.triggerContract(factoryContractAddress, + "deploy(bytes,uint256)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + logger.info( + "the value: " + PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + + List retList = PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + + logger.info("actualSalt: " + actualSalt); + + byte[] tmpAddress = new byte[20]; + System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); + logger.info("address_hex: " + addressHex); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + logger.info("address_final: " + addressFinal); + + testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + SmartContract smartContract = PublicMethed.getContract(testContractAddress, blockingStubFull); + + Assert.assertEquals(salt, actualSalt); + + // contract created by create2, doesn't have ABI + Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); + + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); + + // the contract address in transaction info, + // contract address of create2 contract is factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); + } + + @Test(enabled = true, description = "Trigger test contract") + public void test03TriggerTestContract() { + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + final String triggerTxid = PublicMethed.triggerContract(testContractAddress, + "plusOne()", "#", false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + logger.info( + "the value: " + PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray())); + + List retList = PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray()); + + Long ret = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); + + logger.info("ret: " + ret); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("transaction failed with message: " + infoById.get().getResMessage()); + } + + SmartContract smartContract = PublicMethed.getContract(infoById.get().getContractAddress() + .toByteArray(), blockingStubFull); + + long consumeUserPercent = smartContract.getConsumeUserResourcePercent(); + logger.info("ConsumeURPercent: " + consumeUserPercent); + + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + user001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + user001Address, blockingStubFull); + } + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } +} + + diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test007.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test007.java new file mode 100644 index 00000000000..93667d9d01c --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test007.java @@ -0,0 +1,358 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.create2; + +import com.google.protobuf.ByteString; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +import java.util.List; +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.WalletClient; +import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.PublicMethed; + +@Slf4j +public class Create2Test007 { + + private final String testKey002 = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + 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(1); + private long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + + private byte[] factoryContractAddress = null; + private byte[] testContractAddress = null; + + private ECKey ecKey1 = new ECKey(Utils.getRandom()); + private byte[] dev001Address = ecKey1.getAddress(); + private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + private ECKey ecKey2 = new ECKey(Utils.getRandom()); + private byte[] user001Address = ecKey2.getAddress(); + private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + @BeforeClass(enabled = true) + public void beforeClass() { + + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + + PublicMethed.printAddress(dev001Key); + PublicMethed.printAddress(user001Key); + } + + @Test(enabled = true, description = "Deploy factory contract") + public void test01DeployFactoryContract() { + Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, + 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + //before deploy, check account resource + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long energyLimit = accountResource.getEnergyLimit(); + long energyUsage = accountResource.getEnergyUsed(); + long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before energyLimit is " + Long.toString(energyLimit)); + logger.info("before energyUsage is " + Long.toString(energyUsage)); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "Factory"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + final String transferTokenTxid = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", + maxFeeLimit, 0L, 0, 10000, + "0", 0, null, dev001Key, + dev001Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + energyLimit = accountResource.getEnergyLimit(); + energyUsage = accountResource.getEnergyUsed(); + long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + + logger.info("after energyLimit is " + Long.toString(energyLimit)); + logger.info("after energyUsage is " + Long.toString(energyUsage)); + logger.info("after balanceAfter is " + Long.toString(balanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); + } + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + factoryContractAddress = infoById.get().getContractAddress().toByteArray(); + SmartContract smartContract = PublicMethed.getContract(factoryContractAddress, + blockingStubFull); + Assert.assertNotNull(smartContract.getAbi()); + } + + @Test(enabled = true, description = "Trigger create2 with salt -1") + public void test02TriggerCreate2ToDeployTestContract() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String testContractCode = retMap.get("byteCode").toString(); + Long salt = -1L; + + String param = "\"" + testContractCode + "\"," + salt; + + final String triggerTxid = PublicMethed.triggerContract(factoryContractAddress, + "deploy(bytes,uint256)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + logger.info( + "the value: " + PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + + List retList = PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + + logger.info("actualSalt: " + actualSalt); + + byte[] tmpAddress = new byte[20]; + System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); + logger.info("address_hex: " + addressHex); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + logger.info("address_final: " + addressFinal); + + testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + SmartContract smartContract = PublicMethed.getContract(testContractAddress, blockingStubFull); + + Assert.assertEquals(salt, actualSalt); + + // contract created by create2, doesn't have ABI + Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); + + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); + + // the contract address in transaction info, + // contract address of create2 contract is factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); + } + + @Test(enabled = true, description = "Trigger test contract") + public void test03TriggerTestContract() { + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + final String triggerTxid = PublicMethed.triggerContract(testContractAddress, + "plusOne()", "#", false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + logger.info( + "the value: " + PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray())); + + List retList = PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray()); + + Long ret = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); + + logger.info("ret: " + ret); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("transaction failed with message: " + infoById.get().getResMessage()); + } + + SmartContract smartContract = PublicMethed.getContract(infoById.get().getContractAddress() + .toByteArray(), blockingStubFull); + + long consumeUserPercent = smartContract.getConsumeUserResourcePercent(); + logger.info("ConsumeURPercent: " + consumeUserPercent); + + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + user001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + user001Address, blockingStubFull); + } + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } +} + + diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test008.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test008.java new file mode 100644 index 00000000000..2605a1e87d2 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test008.java @@ -0,0 +1,358 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.create2; + +import com.google.protobuf.ByteString; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +import java.util.List; +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.WalletClient; +import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.PublicMethed; + +@Slf4j +public class Create2Test008 { + + private final String testKey002 = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + 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(1); + private long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + + private byte[] factoryContractAddress = null; + private byte[] testContractAddress = null; + + private ECKey ecKey1 = new ECKey(Utils.getRandom()); + private byte[] dev001Address = ecKey1.getAddress(); + private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + private ECKey ecKey2 = new ECKey(Utils.getRandom()); + private byte[] user001Address = ecKey2.getAddress(); + private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + @BeforeClass(enabled = true) + public void beforeClass() { + + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + + PublicMethed.printAddress(dev001Key); + PublicMethed.printAddress(user001Key); + } + + @Test(enabled = true, description = "Deploy factory contract") + public void test01DeployFactoryContract() { + Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, + 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + //before deploy, check account resource + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long energyLimit = accountResource.getEnergyLimit(); + long energyUsage = accountResource.getEnergyUsed(); + long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before energyLimit is " + Long.toString(energyLimit)); + logger.info("before energyUsage is " + Long.toString(energyUsage)); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "Factory"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + final String transferTokenTxid = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", + maxFeeLimit, 0L, 0, 10000, + "0", 0, null, dev001Key, + dev001Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + energyLimit = accountResource.getEnergyLimit(); + energyUsage = accountResource.getEnergyUsed(); + long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + + logger.info("after energyLimit is " + Long.toString(energyLimit)); + logger.info("after energyUsage is " + Long.toString(energyUsage)); + logger.info("after balanceAfter is " + Long.toString(balanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); + } + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + factoryContractAddress = infoById.get().getContractAddress().toByteArray(); + SmartContract smartContract = PublicMethed.getContract(factoryContractAddress, + blockingStubFull); + Assert.assertNotNull(smartContract.getAbi()); + } + + @Test(enabled = true, description = "Trigger create2 with salt 100") + public void test02TriggerCreate2ToDeployTestContract() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String testContractCode = retMap.get("byteCode").toString(); + Long salt = 100L; + + String param = "\"" + testContractCode + "\"," + salt; + + final String triggerTxid = PublicMethed.triggerContract(factoryContractAddress, + "deploy(bytes,uint256)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + logger.info( + "the value: " + PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + + List retList = PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + + logger.info("actualSalt: " + actualSalt); + + byte[] tmpAddress = new byte[20]; + System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); + logger.info("address_hex: " + addressHex); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + logger.info("address_final: " + addressFinal); + + testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + SmartContract smartContract = PublicMethed.getContract(testContractAddress, blockingStubFull); + + Assert.assertEquals(salt, actualSalt); + + // contract created by create2, doesn't have ABI + Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); + + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); + + // the contract address in transaction info, + // contract address of create2 contract is factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); + } + + @Test(enabled = true, description = "Trigger test contract") + public void test03TriggerTestContract() { + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + final String triggerTxid = PublicMethed.triggerContract(testContractAddress, + "plusOne()", "#", false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + logger.info( + "the value: " + PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray())); + + List retList = PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray()); + + Long ret = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); + + logger.info("ret: " + ret); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("transaction failed with message: " + infoById.get().getResMessage()); + } + + SmartContract smartContract = PublicMethed.getContract(infoById.get().getContractAddress() + .toByteArray(), blockingStubFull); + + long consumeUserPercent = smartContract.getConsumeUserResourcePercent(); + logger.info("ConsumeURPercent: " + consumeUserPercent); + + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + user001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + user001Address, blockingStubFull); + } + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } +} + + diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test009.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test009.java new file mode 100644 index 00000000000..29214cc5b1b --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test009.java @@ -0,0 +1,365 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.create2; + +import com.google.protobuf.ByteString; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +import java.util.List; +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.WalletClient; +import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.PublicMethed; + +@Slf4j +public class Create2Test009 { + + private final String testKey002 = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + 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(1); + private long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + + private byte[] factoryContractAddress = null; + private byte[] testContractAddress = null; + + private ECKey ecKey1 = new ECKey(Utils.getRandom()); + private byte[] dev001Address = ecKey1.getAddress(); + private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + private ECKey ecKey2 = new ECKey(Utils.getRandom()); + private byte[] user001Address = ecKey2.getAddress(); + private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + @BeforeClass(enabled = true) + public void beforeClass() { + + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + + PublicMethed.printAddress(dev001Key); + PublicMethed.printAddress(user001Key); + } + + @Test(enabled = true, description = "Deploy factory contract generated by new solidity") + public void test01DeployFactoryContract() { + Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, + 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + //before deploy, check account resource + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long energyLimit = accountResource.getEnergyLimit(); + long energyUsage = accountResource.getEnergyUsed(); + long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before energyLimit is " + Long.toString(energyLimit)); + logger.info("before energyUsage is " + Long.toString(energyUsage)); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "Factory"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + final String transferTokenTxid = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", + maxFeeLimit, 0L, 0, 10000, + "0", 0, null, dev001Key, + dev001Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + energyLimit = accountResource.getEnergyLimit(); + energyUsage = accountResource.getEnergyUsed(); + long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + + logger.info("after energyLimit is " + Long.toString(energyLimit)); + logger.info("after energyUsage is " + Long.toString(energyUsage)); + logger.info("after balanceAfter is " + Long.toString(balanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); + } + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + factoryContractAddress = infoById.get().getContractAddress().toByteArray(); + SmartContract smartContract = PublicMethed.getContract(factoryContractAddress, + blockingStubFull); + Assert.assertNotNull(smartContract.getAbi()); + } + + + @Test(enabled = true, description = "Trigger create2 function to deploy test contract") + public void test02TriggerCreate2ToDeployTestContract() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String testContractCode = retMap.get("byteCode").toString(); + + Long salt = 1L; + + String param = "\"" + testContractCode + "\"," + salt; + + final String triggerTxid = PublicMethed.triggerContract(factoryContractAddress, + "deploy(bytes,uint256)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + logger.info( + "the value: " + PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + + List retList = PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + + logger.info("actualSalt: " + actualSalt); + + byte[] tmpAddress = new byte[20]; + System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); + logger.info("address_hex: " + addressHex); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + logger.info("address_final: " + addressFinal); + + testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + SmartContract smartContract = PublicMethed.getContract(testContractAddress, blockingStubFull); + + // contract created by create2, doesn't have ABI + Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); + + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); + + // the contract address in transaction info, + // contract address of create2 contract is factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); + + String[] parameter = {Base58.encode58Check(user001Address), testContractCode, salt.toString()}; + logger.info(PublicMethed.create2(parameter)); + + Assert.assertEquals(Base58.encode58Check(testContractAddress), PublicMethed.create2(parameter)); + + } + + + @Test(enabled = true, description = "Trigger Test contact") + public void test03TriggerTestContract() { + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + final String triggerTxid = PublicMethed.triggerContract(testContractAddress, + "plusOne()", "#", false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + logger.info( + "the value: " + PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray())); + + List retList = PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray()); + + Long ret = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); + + logger.info("ret: " + ret); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("transaction failed with message: " + infoById.get().getResMessage()); + } + + SmartContract smartContract = PublicMethed.getContract(infoById.get().getContractAddress() + .toByteArray(), blockingStubFull); + + long consumeUserPercent = smartContract.getConsumeUserResourcePercent(); + logger.info("ConsumeURPercent: " + consumeUserPercent); + + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + user001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + user001Address, blockingStubFull); + } + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } +} + + diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test010.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test010.java new file mode 100644 index 00000000000..363f35195ac --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test010.java @@ -0,0 +1,210 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.create2; + +import com.google.protobuf.ByteString; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +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.PublicMethed; + +@Slf4j +public class Create2Test010 { + + private final String testKey002 = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + 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(1); + private long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + + private byte[] factoryContractAddress = null; + private byte[] testContractAddress = null; + + private ECKey ecKey1 = new ECKey(Utils.getRandom()); + private byte[] dev001Address = ecKey1.getAddress(); + private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + private ECKey ecKey2 = new ECKey(Utils.getRandom()); + private byte[] user001Address = ecKey2.getAddress(); + private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + @BeforeClass(enabled = true) + public void beforeClass() { + + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + + PublicMethed.printAddress(dev001Key); + PublicMethed.printAddress(user001Key); + } + + @Test(enabled = true, description = "TransferToken with correct value, deploy transfer contract") + public void test01DeployFactoryContract() { + Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, + 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + //before deploy, check account resource + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long energyLimit = accountResource.getEnergyLimit(); + long energyUsage = accountResource.getEnergyUsed(); + long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before energyLimit is " + Long.toString(energyLimit)); + logger.info("before energyUsage is " + Long.toString(energyUsage)); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "Factory"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + final String transferTokenTxid = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", + maxFeeLimit, 0L, 0, 10000, + "0", 0, null, dev001Key, + dev001Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + energyLimit = accountResource.getEnergyLimit(); + energyUsage = accountResource.getEnergyUsed(); + long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + + logger.info("after energyLimit is " + Long.toString(energyLimit)); + logger.info("after energyUsage is " + Long.toString(energyUsage)); + logger.info("after balanceAfter is " + Long.toString(balanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); + } + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + factoryContractAddress = infoById.get().getContractAddress().toByteArray(); + SmartContract smartContract = PublicMethed.getContract(factoryContractAddress, + blockingStubFull); + Assert.assertNotNull(smartContract.getAbi()); + } + + + @Test(enabled = true, description = "Trigger create2 with salt empty") + public void test02TriggerCreate2ToDeployTestContract() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String testContractCode = retMap.get("byteCode").toString(); + + String param = "\"" + testContractCode + "\"," + null; + boolean ret = false; + try { + final String triggerTxid = PublicMethed.triggerContract(factoryContractAddress, + "deploy(bytes,uint256)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + } catch (NullPointerException e) { + logger.info("Expected NullPointerException!"); + ret = true; + } + Assert.assertTrue(ret); + + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + user001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + user001Address, blockingStubFull); + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } +} + + diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test011.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test011.java new file mode 100644 index 00000000000..eeb73d935d1 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test011.java @@ -0,0 +1,369 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.create2; + +import com.google.protobuf.ByteString; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +import java.util.List; +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.WalletClient; +import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.PublicMethed; + +@Slf4j +public class Create2Test011 { + + private final String testKey002 = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + 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(1); + private long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + + private byte[] factoryContractAddress = null; + private byte[] testContractAddress = null; + + private ECKey ecKey1 = new ECKey(Utils.getRandom()); + private byte[] dev001Address = ecKey1.getAddress(); + private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + private ECKey ecKey2 = new ECKey(Utils.getRandom()); + private byte[] user001Address = ecKey2.getAddress(); + private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + @BeforeClass(enabled = true) + public void beforeClass() { + + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + + PublicMethed.printAddress(dev001Key); + PublicMethed.printAddress(user001Key); + } + + @Test(enabled = true, description = "Deploy factory contract") + public void test01DeployFactoryContract() { + Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, + 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + //before deploy, check account resource + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long energyLimit = accountResource.getEnergyLimit(); + long energyUsage = accountResource.getEnergyUsed(); + long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before energyLimit is " + Long.toString(energyLimit)); + logger.info("before energyUsage is " + Long.toString(energyUsage)); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "FactoryBytes"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + final String transferTokenTxid = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", + maxFeeLimit, 0L, 0, 10000, + "0", 0, null, dev001Key, + dev001Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + energyLimit = accountResource.getEnergyLimit(); + energyUsage = accountResource.getEnergyUsed(); + long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + + logger.info("after energyLimit is " + Long.toString(energyLimit)); + logger.info("after energyUsage is " + Long.toString(energyUsage)); + logger.info("after balanceAfter is " + Long.toString(balanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); + } + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + factoryContractAddress = infoById.get().getContractAddress().toByteArray(); + SmartContract smartContract = PublicMethed.getContract(factoryContractAddress, + blockingStubFull); + Assert.assertNotNull(smartContract.getAbi()); + } + + + @Test(enabled = true, description = "Trigger create2 with salt f * 64") + public void test02TriggerCreate2ToDeployTestContract() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String testContractCode = retMap.get("byteCode").toString(); + + String saltHexString = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"; + logger.info("saltHexString: " + saltHexString); + + String param = "\"" + testContractCode + "\",\"" + saltHexString + "\""; + + final String triggerTxid = PublicMethed.triggerContract(factoryContractAddress, + "deploy(bytes,bytes32)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + logger.info( + "the value: " + PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + + List retList = PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + + // The first + byte[] tmpAddress = new byte[20]; + System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); + logger.info("addressHex: " + addressHex); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + logger.info("addressFinal: " + addressFinal); + testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); + + String actualSalt = retList.get(1); + logger.info("actualSalt: " + actualSalt); + + byte[] tmpSenderAddress = new byte[20]; + System.arraycopy(ByteArray.fromHexString(retList.get(2)), 12, tmpSenderAddress, 0, 20); + String senderAddressHex = "41" + ByteArray.toHexString(tmpAddress); + logger.info("senderAddressHex: " + senderAddressHex); + String senderAddressFinal = Base58.encode58Check(ByteArray.fromHexString(senderAddressHex)); + logger.info("senderAddressFinal: " + senderAddressFinal); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + SmartContract smartContract = PublicMethed.getContract(testContractAddress, blockingStubFull); + + Assert.assertEquals(saltHexString, actualSalt); + + // contract created by create2, doesn't have ABI + Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); + + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); + + // the contract address in transaction info, + // contract address of create2 contract is factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); + } + + + @Test(enabled = true, description = "Trigger test contract") + public void test03TriggerTestContract() { + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + final String triggerTxid = PublicMethed.triggerContract(testContractAddress, + "plusOne()", "#", false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + logger.info( + "the value: " + PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray())); + + List retList = PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray()); + + Long ret = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); + + logger.info("ret: " + ret); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("transaction failed with message: " + infoById.get().getResMessage()); + } + + SmartContract smartContract = PublicMethed.getContract(infoById.get().getContractAddress() + .toByteArray(), blockingStubFull); + + long consumeUserPercent = smartContract.getConsumeUserResourcePercent(); + logger.info("ConsumeURPercent: " + consumeUserPercent); + + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + user001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + user001Address, blockingStubFull); + } + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } +} + + diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test012.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test012.java new file mode 100644 index 00000000000..219bc889d1e --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test012.java @@ -0,0 +1,396 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.create2; + +import com.google.protobuf.ByteString; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +import java.util.List; +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.WalletClient; +import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.PublicMethed; + +@Slf4j +public class Create2Test012 { + + private final String testKey002 = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + 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(1); + private long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + + private byte[] factoryContractAddress = null; + private byte[] testContractAddress = null; + private byte[] testContractAddress2 = null; + + private ECKey ecKey1 = new ECKey(Utils.getRandom()); + private byte[] dev001Address = ecKey1.getAddress(); + private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + private ECKey ecKey2 = new ECKey(Utils.getRandom()); + private byte[] user001Address = ecKey2.getAddress(); + private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + @BeforeClass(enabled = true) + public void beforeClass() { + + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + + PublicMethed.printAddress(dev001Key); + PublicMethed.printAddress(user001Key); + } + + @Test(enabled = true, description = "Deploy factory contract") + public void test01DeployFactoryContract() { + Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, + 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + //before deploy, check account resource + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long energyLimit = accountResource.getEnergyLimit(); + long energyUsage = accountResource.getEnergyUsed(); + long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before energyLimit is " + Long.toString(energyLimit)); + logger.info("before energyUsage is " + Long.toString(energyUsage)); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "Factory"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + final String transferTokenTxid = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", + maxFeeLimit, 0L, 0, 10000, + "0", 0, null, dev001Key, + dev001Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + energyLimit = accountResource.getEnergyLimit(); + energyUsage = accountResource.getEnergyUsed(); + long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + + logger.info("after energyLimit is " + Long.toString(energyLimit)); + logger.info("after energyUsage is " + Long.toString(energyUsage)); + logger.info("after balanceAfter is " + Long.toString(balanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); + } + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + factoryContractAddress = infoById.get().getContractAddress().toByteArray(); + SmartContract smartContract = PublicMethed.getContract(factoryContractAddress, + blockingStubFull); + Assert.assertNotNull(smartContract.getAbi()); + } + + + @Test(enabled = true, description = "Trigger create2 command with test bytecode and salt 1") + public void test02TriggerCreate2ToDeployTestContract() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 80000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String testContractCode = retMap.get("byteCode").toString(); + + Long salt = 1L; + + String param = "\"" + testContractCode + "\"," + salt; + + final String triggerTxid = PublicMethed.triggerContract(factoryContractAddress, + "deploy(bytes,uint256)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + logger.info( + "the value: " + PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + + List retList = PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + + logger.info("actualSalt: " + actualSalt); + + byte[] tmpAddress = new byte[20]; + System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); + logger.info("address_hex: " + addressHex); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + logger.info("address_final: " + addressFinal); + + testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); + + SmartContract smartContract = PublicMethed.getContract(testContractAddress, blockingStubFull); + + Assert.assertEquals(salt, actualSalt); + + // contract created by create2, doesn't have ABI + Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); + + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); + + // the contract address in transaction info, + // contract address of create2 contract is factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); + } + + + @Test(enabled = true, description = "Trigger create2 command with test bytecode and salt 2") + public void test03TriggerCreate2ToDeployTestContract2() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 80000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String testContractCode = retMap.get("byteCode").toString(); + + Long salt = 2L; + + String param = "\"" + testContractCode + "\"," + salt; + + final String triggerTxid = PublicMethed.triggerContract(factoryContractAddress, + "deploy(bytes,uint256)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + logger.info( + "the value: " + PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + + List retList = PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + + logger.info("actualSalt: " + actualSalt); + + byte[] tmpAddress = new byte[20]; + System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); + logger.info("address_hex: " + addressHex); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + logger.info("address_final: " + addressFinal); + + testContractAddress2 = WalletClient.decodeFromBase58Check(addressFinal); + + SmartContract smartContract = PublicMethed.getContract(testContractAddress, blockingStubFull); + + Assert.assertEquals(salt, actualSalt); + + // contract created by create2, doesn't have ABI + Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); + + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); + + // the contract address in transaction info, + // contract address of create2 contract is factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); + + // contract address are different with different salt + Assert.assertNotEquals(Base58.encode58Check(testContractAddress), + Base58.encode58Check(testContractAddress2)); + + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + user001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + user001Address, blockingStubFull); + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } +} + + diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test013.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test013.java new file mode 100644 index 00000000000..5e800d573a5 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test013.java @@ -0,0 +1,436 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.create2; + +import static org.hamcrest.core.StringContains.containsString; + +import com.google.protobuf.ByteString; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +import java.util.List; +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.WalletClient; +import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.PublicMethed; + +@Slf4j +public class Create2Test013 { + + private final String testKey002 = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + 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(1); + private long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + + private byte[] factoryContractAddress = null; + private byte[] testContractAddress = null; + + private ECKey ecKey1 = new ECKey(Utils.getRandom()); + private byte[] dev001Address = ecKey1.getAddress(); + private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + private ECKey ecKey2 = new ECKey(Utils.getRandom()); + private byte[] user001Address = ecKey2.getAddress(); + private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + @BeforeClass(enabled = true) + public void beforeClass() { + + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + + PublicMethed.printAddress(dev001Key); + PublicMethed.printAddress(user001Key); + } + + @Test(enabled = true, description = "Deploy factory contract") + public void test01DeployFactoryContract() { + Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, + 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + //before deploy, check account resource + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long energyLimit = accountResource.getEnergyLimit(); + long energyUsage = accountResource.getEnergyUsed(); + long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before energyLimit is " + Long.toString(energyLimit)); + logger.info("before energyUsage is " + Long.toString(energyUsage)); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "Factory"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + final String transferTokenTxid = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", + maxFeeLimit, 0L, 0, 10000, + "0", 0, null, dev001Key, + dev001Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + energyLimit = accountResource.getEnergyLimit(); + energyUsage = accountResource.getEnergyUsed(); + long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + + logger.info("after energyLimit is " + Long.toString(energyLimit)); + logger.info("after energyUsage is " + Long.toString(energyUsage)); + logger.info("after balanceAfter is " + Long.toString(balanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); + } + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + factoryContractAddress = infoById.get().getContractAddress().toByteArray(); + SmartContract smartContract = PublicMethed.getContract(factoryContractAddress, + blockingStubFull); + Assert.assertNotNull(smartContract.getAbi()); + } + + @Test(enabled = true, description = "Trigger factory contract to deploy test contract") + public void test02TriggerCreate2ToDeployTestContract() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String testContractCode = retMap.get("byteCode").toString(); + + Long salt = 1L; + + String param = "\"" + testContractCode + "\"," + salt; + + final String triggerTxid = PublicMethed.triggerContract(factoryContractAddress, + "deploy(bytes,uint256)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + logger.info( + "the value: " + PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + + List retList = PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + + logger.info("actualSalt: " + actualSalt); + + byte[] tmpAddress = new byte[20]; + System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); + logger.info("address_hex: " + addressHex); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + logger.info("address_final: " + addressFinal); + + testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + SmartContract smartContract = PublicMethed.getContract(testContractAddress, blockingStubFull); + + // contract created by create2, doesn't have ABI + Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); + + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); + + // the contract address in transaction info, + // contract address of create2 contract is factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); + } + + @Test(enabled = true, description = "Trigger factory contract to deploy test contract again " + + "with same code, salt and address") + public void test03TriggerCreate2ToDeployTestContractAgain() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String testContractCode = retMap.get("byteCode").toString(); + Long salt = 1L; + + String param = "\"" + testContractCode + "\"," + salt; + + final String triggerTxid = PublicMethed.triggerContract(factoryContractAddress, + "deploy(bytes,uint256)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + Assert.assertEquals(1, infoById.get().getResultValue()); + Assert + .assertThat(infoById.get().getResMessage().toStringUtf8(), + containsString("Not enough energy for 'SWAP1' operation executing")); + } + + @Test(enabled = true, description = "Trigger test1 contract") + public void test04TriggerTestContract() { + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + final String triggerTxid = PublicMethed.triggerContract(testContractAddress, + "plusOne()", "#", false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + logger.info( + "the value: " + PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray())); + + List retList = PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray()); + + Long ret = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); + + logger.info("ret: " + ret); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("transaction failed with message: " + infoById.get().getResMessage()); + } + + SmartContract smartContract = PublicMethed.getContract(infoById.get().getContractAddress() + .toByteArray(), blockingStubFull); + + long consumeUserPercent = smartContract.getConsumeUserResourcePercent(); + logger.info("ConsumeURPercent: " + consumeUserPercent); + + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + user001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + user001Address, blockingStubFull); + } + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } +} + + diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test014.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test014.java new file mode 100644 index 00000000000..4e80b4598c8 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test014.java @@ -0,0 +1,560 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.create2; + +import com.google.protobuf.ByteString; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +import java.util.List; +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.WalletClient; +import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.PublicMethed; + +@Slf4j +public class Create2Test014 { + + private final String testKey002 = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + 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(1); + private long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + + private byte[] factoryContractAddress = null; + private byte[] testContractAddress = null; + private byte[] testContractAddress2 = null; + + private ECKey ecKey1 = new ECKey(Utils.getRandom()); + private byte[] dev001Address = ecKey1.getAddress(); + private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + private ECKey ecKey2 = new ECKey(Utils.getRandom()); + private byte[] user001Address = ecKey2.getAddress(); + private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + @BeforeClass(enabled = true) + public void beforeClass() { + + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + + PublicMethed.printAddress(dev001Key); + PublicMethed.printAddress(user001Key); + } + + @Test(enabled = true, description = "Deploy factory contract") + public void test01DeployFactoryContract() { + Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, + 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + //before deploy, check account resource + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long energyLimit = accountResource.getEnergyLimit(); + long energyUsage = accountResource.getEnergyUsed(); + long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before energyLimit is " + Long.toString(energyLimit)); + logger.info("before energyUsage is " + Long.toString(energyUsage)); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "Factory"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + final String transferTokenTxid = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", + maxFeeLimit, 0L, 0, 10000, + "0", 0, null, dev001Key, + dev001Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + energyLimit = accountResource.getEnergyLimit(); + energyUsage = accountResource.getEnergyUsed(); + long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + + logger.info("after energyLimit is " + Long.toString(energyLimit)); + logger.info("after energyUsage is " + Long.toString(energyUsage)); + logger.info("after balanceAfter is " + Long.toString(balanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); + } + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + factoryContractAddress = infoById.get().getContractAddress().toByteArray(); + SmartContract smartContract = PublicMethed.getContract(factoryContractAddress, + blockingStubFull); + Assert.assertNotNull(smartContract.getAbi()); + } + + + @Test(enabled = true, description = "Trigger factory contract with Test " + + "bytecode and salt using user account") + public void test02TriggerCreate2ToDeployTestContract() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String testContractCode = retMap.get("byteCode").toString(); + Long salt = 1L; + + String param = "\"" + testContractCode + "\"," + salt; + + final String triggerTxid = PublicMethed.triggerContract(factoryContractAddress, + "deploy(bytes,uint256)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + logger.info( + "the value: " + PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + + List retList = PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + + logger.info("actualSalt: " + actualSalt); + + byte[] tmpAddress = new byte[20]; + System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); + logger.info("address_hex: " + addressHex); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + logger.info("address_final: " + addressFinal); + + testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + SmartContract smartContract = PublicMethed.getContract(testContractAddress, blockingStubFull); + + // contract created by create2, doesn't have ABI + Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); + + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); + + // the contract address in transaction info, + // contract address of create2 contract is factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); + } + + + @Test(enabled = true, description = "Same code, salt and address," + + " create contract using develop account") + public void test03TriggerCreate2ToDeployTestContract() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String testContractCode = retMap.get("byteCode").toString(); + Long salt = 1L; + + String param = "\"" + testContractCode + "\"," + salt; + + final String triggerTxid = PublicMethed.triggerContract(factoryContractAddress, + "deploy(bytes,uint256)", param, false, callValue, + 1000000000L, "0", 0, dev001Address, dev001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + logger.info( + "the value: " + PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + + List retList = PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + + logger.info("actualSalt: " + actualSalt); + + byte[] tmpAddress = new byte[20]; + System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); + logger.info("address_hex: " + addressHex); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + logger.info("address_final: " + addressFinal); + + testContractAddress2 = WalletClient.decodeFromBase58Check(addressFinal); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + SmartContract smartContract = PublicMethed.getContract(testContractAddress2, blockingStubFull); + + // contract created by create2, doesn't have ABI + Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); + + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); + + // the contract address in transaction info, + // contract address of create2 contract is factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); + + // contract address are different + Assert.assertNotEquals(Base58.encode58Check(testContractAddress), + Base58.encode58Check(testContractAddress2)); + } + + @Test(enabled = true, description = "Trigger test1 contract") + public void test04TriggerTest1Contract() { + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + final String triggerTxid = PublicMethed.triggerContract(testContractAddress, + "plusOne()", "#", false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + logger.info( + "the value: " + PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray())); + + List retList = PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray()); + + Long ret = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); + + logger.info("ret: " + ret); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("transaction failed with message: " + infoById.get().getResMessage()); + } + + SmartContract smartContract = PublicMethed.getContract(infoById.get().getContractAddress() + .toByteArray(), blockingStubFull); + + long consumeUserPercent = smartContract.getConsumeUserResourcePercent(); + logger.info("ConsumeURPercent: " + consumeUserPercent); + } + + @Test(enabled = true, description = "Trigger test2 contract") + public void test05TriggerTest2Contract() { + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + final String triggerTxid = PublicMethed.triggerContract(testContractAddress2, + "plusOne()", "#", false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + logger.info( + "the value: " + PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray())); + + List retList = PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray()); + + Long ret = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); + + logger.info("ret: " + ret); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("transaction failed with message: " + infoById.get().getResMessage()); + } + + SmartContract smartContract = PublicMethed.getContract(infoById.get().getContractAddress() + .toByteArray(), blockingStubFull); + + long consumeUserPercent = smartContract.getConsumeUserResourcePercent(); + logger.info("ConsumeURPercent: " + consumeUserPercent); + + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + user001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + user001Address, blockingStubFull); + } + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } +} + + diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test015.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test015.java new file mode 100644 index 00000000000..97749c9dedc --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test015.java @@ -0,0 +1,422 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.create2; + +import com.google.protobuf.ByteString; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +import java.util.List; +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.WalletClient; +import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.PublicMethed; + +@Slf4j +public class Create2Test015 { + + private final String testKey002 = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + 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(1); + private long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + + private byte[] factoryContractAddress = null; + private byte[] callerContractAddress = null; + private byte[] testContractAddress = null; + + private ECKey ecKey1 = new ECKey(Utils.getRandom()); + private byte[] dev001Address = ecKey1.getAddress(); + private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + private ECKey ecKey2 = new ECKey(Utils.getRandom()); + private byte[] user001Address = ecKey2.getAddress(); + private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + @BeforeClass(enabled = true) + public void beforeClass() { + + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + + PublicMethed.printAddress(dev001Key); + PublicMethed.printAddress(user001Key); + } + + @Test(enabled = true, description = "Deploy caller contract") + public void test01DeployCallerContract() { + Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, + 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + //before deploy, check account resource + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long energyLimit = accountResource.getEnergyLimit(); + long energyUsage = accountResource.getEnergyUsed(); + long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before energyLimit is " + Long.toString(energyLimit)); + logger.info("before energyUsage is " + Long.toString(energyUsage)); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + String filePath = "./src/test/resources/soliditycode/create2CallContract.sol"; + String contractName = "callerContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + final String transferTokenTxid = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", + maxFeeLimit, 0L, 0, 10000, + "0", 0, null, dev001Key, + dev001Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + energyLimit = accountResource.getEnergyLimit(); + energyUsage = accountResource.getEnergyUsed(); + long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + + logger.info("after energyLimit is " + Long.toString(energyLimit)); + logger.info("after energyUsage is " + Long.toString(energyUsage)); + logger.info("after balanceAfter is " + Long.toString(balanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); + } + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + callerContractAddress = infoById.get().getContractAddress().toByteArray(); + SmartContract smartContract = PublicMethed.getContract(callerContractAddress, + blockingStubFull); + Assert.assertNotNull(smartContract.getAbi()); + } + + @Test(enabled = true, description = "Deploy factory contract") + public void test02DeployFactoryContract() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, + 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + //before deploy, check account resource + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long energyLimit = accountResource.getEnergyLimit(); + long energyUsage = accountResource.getEnergyUsed(); + long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before energyLimit is " + Long.toString(energyLimit)); + logger.info("before energyUsage is " + Long.toString(energyUsage)); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "Factory"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + final String transferTokenTxid = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", + maxFeeLimit, 0L, 0, 10000, + "0", 0, null, dev001Key, + dev001Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + energyLimit = accountResource.getEnergyLimit(); + energyUsage = accountResource.getEnergyUsed(); + long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + + logger.info("after energyLimit is " + Long.toString(energyLimit)); + logger.info("after energyUsage is " + Long.toString(energyUsage)); + logger.info("after balanceAfter is " + Long.toString(balanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); + } + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + factoryContractAddress = infoById.get().getContractAddress().toByteArray(); + SmartContract smartContract = PublicMethed.getContract(factoryContractAddress, + blockingStubFull); + Assert.assertNotNull(smartContract.getAbi()); + } + + @Test(enabled = true, description = "Trigger callCreate2 function in caller contract " + + "with factory contract address") + public void test03TriggerCreate2ToDeployTestContract() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String testContractCode = retMap.get("byteCode").toString(); + Long salt = 1L; + + String param = "\"" + Base58.encode58Check(factoryContractAddress) + + "\",\"" + testContractCode + "\"," + salt; + + final String triggerTxid = PublicMethed.triggerContract(callerContractAddress, + "callCreate2(address,bytes,uint256)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + logger.info( + "the value: " + PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + + List retList = PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + + logger.info("actualSalt: " + actualSalt); + + byte[] tmpAddress = new byte[20]; + System.arraycopy(ByteArray.fromHexString(retList.get(0)), + 12, tmpAddress, 0, 20); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); + logger.info("address_hex: " + addressHex); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + logger.info("address_final: " + addressFinal); + + testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + SmartContract smartContract = PublicMethed.getContract(testContractAddress, blockingStubFull); + + // contract created by create2, doesn't have ABI + Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); + + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); + + // call type make the caller contract to be the owner of + // test contract (the contract address in transaction info) + Assert.assertEquals(Base58.encode58Check(callerContractAddress), + Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); + } + + @Test(enabled = true, description = "Trigger test contract") + public void test04TriggerTestContract() { + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + final String triggerTxid = PublicMethed.triggerContract(testContractAddress, + "plusOne()", "#", false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + logger.info( + "the value: " + PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray())); + + List retList = PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray()); + + Long ret = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); + + logger.info("ret: " + ret); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("transaction failed with message: " + infoById.get().getResMessage()); + } + + SmartContract smartContract = PublicMethed.getContract(infoById.get().getContractAddress() + .toByteArray(), blockingStubFull); + + long consumeUserPercent = smartContract.getConsumeUserResourcePercent(); + logger.info("ConsumeURPercent: " + consumeUserPercent); + + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + user001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + user001Address, blockingStubFull); + } + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } +} + + diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test016.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test016.java new file mode 100644 index 00000000000..b2e60f55d91 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test016.java @@ -0,0 +1,421 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.create2; + +import com.google.protobuf.ByteString; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +import java.util.List; +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.WalletClient; +import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.PublicMethed; + +@Slf4j +public class Create2Test016 { + + private final String testKey002 = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + 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(1); + private long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + + private byte[] factoryContractAddress = null; + private byte[] callerContractAddress = null; + private byte[] testContractAddress = null; + + private ECKey ecKey1 = new ECKey(Utils.getRandom()); + private byte[] dev001Address = ecKey1.getAddress(); + private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + private ECKey ecKey2 = new ECKey(Utils.getRandom()); + private byte[] user001Address = ecKey2.getAddress(); + private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + @BeforeClass(enabled = true) + public void beforeClass() { + + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + + PublicMethed.printAddress(dev001Key); + PublicMethed.printAddress(user001Key); + } + + @Test(enabled = true, description = "TransferToken with correct value, deploy transfer contract") + public void test01DeployCallerContract() { + Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, + 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + //before deploy, check account resource + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long energyLimit = accountResource.getEnergyLimit(); + long energyUsage = accountResource.getEnergyUsed(); + long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before energyLimit is " + Long.toString(energyLimit)); + logger.info("before energyUsage is " + Long.toString(energyUsage)); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + String filePath = "./src/test/resources/soliditycode/create2CallContract.sol"; + String contractName = "callerContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + final String transferTokenTxid = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", + maxFeeLimit, 0L, 0, 10000, + "0", 0, null, dev001Key, + dev001Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + energyLimit = accountResource.getEnergyLimit(); + energyUsage = accountResource.getEnergyUsed(); + long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + + logger.info("after energyLimit is " + Long.toString(energyLimit)); + logger.info("after energyUsage is " + Long.toString(energyUsage)); + logger.info("after balanceAfter is " + Long.toString(balanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); + } + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + callerContractAddress = infoById.get().getContractAddress().toByteArray(); + SmartContract smartContract = PublicMethed.getContract(callerContractAddress, + blockingStubFull); + Assert.assertNotNull(smartContract.getAbi()); + } + + @Test(enabled = true, description = "TransferToken with correct value, deploy transfer contract") + public void test02DeployFactoryContract() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, + 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + //before deploy, check account resource + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long energyLimit = accountResource.getEnergyLimit(); + long energyUsage = accountResource.getEnergyUsed(); + long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before energyLimit is " + Long.toString(energyLimit)); + logger.info("before energyUsage is " + Long.toString(energyUsage)); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "Factory"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + final String transferTokenTxid = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", + maxFeeLimit, 0L, 0, 10000, + "0", 0, null, dev001Key, + dev001Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + energyLimit = accountResource.getEnergyLimit(); + energyUsage = accountResource.getEnergyUsed(); + long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + + logger.info("after energyLimit is " + Long.toString(energyLimit)); + logger.info("after energyUsage is " + Long.toString(energyUsage)); + logger.info("after balanceAfter is " + Long.toString(balanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); + } + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + factoryContractAddress = infoById.get().getContractAddress().toByteArray(); + SmartContract smartContract = PublicMethed.getContract(factoryContractAddress, + blockingStubFull); + Assert.assertNotNull(smartContract.getAbi()); + } + + @Test(enabled = true, description = "TransferToken with correct value, deploy receive contract") + public void test03TriggerCreate2ToDeployTestContract() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String testContractCode = retMap.get("byteCode").toString(); + + Long salt = 1L; + + String param = "\"" + Base58.encode58Check(factoryContractAddress) + + "\",\"" + testContractCode + "\"," + salt; + + final String triggerTxid = PublicMethed.triggerContract(callerContractAddress, + "delegateCallCreate2(address,bytes,uint256)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + logger.info( + "the value: " + PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + + List retList = PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + + logger.info("actualSalt: " + actualSalt); + + byte[] tmpAddress = new byte[20]; + System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); + logger.info("address_hex: " + addressHex); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + logger.info("address_final: " + addressFinal); + + testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + SmartContract smartContract = PublicMethed.getContract(testContractAddress, blockingStubFull); + + // contract created by create2, doesn't have ABI + Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); + + // delegatecall type make the caller contract to be the owner of test contract (contract info) + Assert.assertEquals(Base58.encode58Check(callerContractAddress), + Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); + + // call type make the caller contract to be the owner of test contract + // (the contract address in transaction info) + Assert.assertEquals(Base58.encode58Check(callerContractAddress), + Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); + } + + @Test(enabled = true, description = "Trigger test contract") + public void test04TriggerTestContract() { + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + final String triggerTxid = PublicMethed.triggerContract(testContractAddress, + "plusOne()", "#", false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + logger.info( + "the value: " + PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray())); + + List retList = PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray()); + + Long ret = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); + + logger.info("ret: " + ret); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("transaction failed with message: " + infoById.get().getResMessage()); + } + + SmartContract smartContract = PublicMethed.getContract(infoById.get().getContractAddress() + .toByteArray(), blockingStubFull); + + long consumeUserPercent = smartContract.getConsumeUserResourcePercent(); + logger.info("ConsumeURPercent: " + consumeUserPercent); + + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + user001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + user001Address, blockingStubFull); + } + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } +} + + diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test017.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test017.java new file mode 100644 index 00000000000..98a1bde95e4 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test017.java @@ -0,0 +1,405 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.create2; + +import com.google.protobuf.ByteString; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +import java.util.List; +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.WalletClient; +import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.PublicMethed; + +@Slf4j +public class Create2Test017 { + + private final String testKey002 = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + 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(1); + private long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + + private byte[] factoryContractAddress = null; + private byte[] testContractAddress = null; + + private ECKey ecKey1 = new ECKey(Utils.getRandom()); + private byte[] dev001Address = ecKey1.getAddress(); + private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + private ECKey ecKey2 = new ECKey(Utils.getRandom()); + private byte[] user001Address = ecKey2.getAddress(); + private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + @BeforeClass(enabled = true) + public void beforeClass() { + + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + + PublicMethed.printAddress(dev001Key); + PublicMethed.printAddress(user001Key); + } + + @Test(enabled = true, description = "Deploy factory contract") + public void test01DeployFactoryContract() { + Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, + 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + //before deploy, check account resource + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long energyLimit = accountResource.getEnergyLimit(); + long energyUsage = accountResource.getEnergyUsed(); + long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before energyLimit is " + Long.toString(energyLimit)); + logger.info("before energyUsage is " + Long.toString(energyUsage)); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "FactoryBytes"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + final String transferTokenTxid = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", + maxFeeLimit, 0L, 0, 10000, + "0", 0, null, dev001Key, + dev001Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + energyLimit = accountResource.getEnergyLimit(); + energyUsage = accountResource.getEnergyUsed(); + long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + + logger.info("after energyLimit is " + Long.toString(energyLimit)); + logger.info("after energyUsage is " + Long.toString(energyUsage)); + logger.info("after balanceAfter is " + Long.toString(balanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); + } + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + factoryContractAddress = infoById.get().getContractAddress().toByteArray(); + SmartContract smartContract = PublicMethed.getContract(factoryContractAddress, + blockingStubFull); + Assert.assertNotNull(smartContract.getAbi()); + } + + @Test(enabled = true, description = "Trigger create2 with salt efffe") + public void test02TriggerCreate2ToDeployTestContract() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String testContractCode = retMap.get("byteCode").toString(); + + final String saltHexString = "EFFFE"; + final String expectedSalt = "0EFFFE0000000000000000000000000000000000000000000000000000000000"; + + logger.info("saltHexString: " + saltHexString); + + String param = "\"" + testContractCode + "\",\"" + saltHexString + "\""; + + final String triggerTxid = PublicMethed.triggerContract(factoryContractAddress, + "deploy(bytes,bytes32)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + logger.info( + "the value: " + PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + + List retList = PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + + // The first + byte[] tmpAddress = new byte[20]; + System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); + logger.info("addressHex: " + addressHex); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + logger.info("addressFinal: " + addressFinal); + testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); + + String actualSalt = retList.get(1); + logger.info("actualSalt: " + actualSalt); + + byte[] tmpSenderAddress = new byte[20]; + System.arraycopy(ByteArray.fromHexString(retList.get(2)), 12, tmpSenderAddress, 0, 20); + String senderAddressHex = "41" + ByteArray.toHexString(tmpAddress); + logger.info("senderAddressHex: " + senderAddressHex); + String senderAddressFinal = Base58.encode58Check(ByteArray.fromHexString(senderAddressHex)); + logger.info("senderAddressFinal: " + senderAddressFinal); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + SmartContract smartContract = PublicMethed.getContract(testContractAddress, blockingStubFull); + + Assert.assertEquals(expectedSalt, actualSalt); + + // contract created by create2, doesn't have ABI + Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); + + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); + + // the contract address in transaction info, + // contract address of create2 contract is factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); + } + + @Test(enabled = true, description = "Trigger create2 with salt affffa") + public void test03TriggerCreate2ToDeployTestContract() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String testContractCode = retMap.get("byteCode").toString(); + + final String saltHexString = "AFFFFA"; + final String expectedSalt = "AFFFFA0000000000000000000000000000000000000000000000000000000000"; + logger.info("saltHexString: " + saltHexString); + + String param = "\"" + testContractCode + "\",\"" + saltHexString + "\""; + + final String triggerTxid = PublicMethed.triggerContract(factoryContractAddress, + "deploy(bytes,bytes32)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + logger.info( + "the value: " + PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + + List retList = PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + + // The first + byte[] tmpAddress = new byte[20]; + System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); + logger.info("addressHex: " + addressHex); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + logger.info("addressFinal: " + addressFinal); + testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); + + String actualSalt = retList.get(1); + logger.info("actualSalt: " + actualSalt); + + byte[] tmpSenderAddress = new byte[20]; + System.arraycopy(ByteArray.fromHexString(retList.get(2)), 12, tmpSenderAddress, 0, 20); + String senderAddressHex = "41" + ByteArray.toHexString(tmpAddress); + logger.info("senderAddressHex: " + senderAddressHex); + String senderAddressFinal = Base58.encode58Check(ByteArray.fromHexString(senderAddressHex)); + logger.info("senderAddressFinal: " + senderAddressFinal); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + SmartContract smartContract = PublicMethed.getContract(testContractAddress, blockingStubFull); + + Assert.assertEquals(expectedSalt, actualSalt); + + // contract created by create2, doesn't have ABI + Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); + + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); + + // the contract address in transaction info, + // contract address of create2 contract is factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); + + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + user001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + user001Address, blockingStubFull); + } + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } +} + + diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test018.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test018.java new file mode 100644 index 00000000000..6698b38acaa --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test018.java @@ -0,0 +1,360 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.create2; + +import com.google.protobuf.ByteString; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +import java.util.List; +import java.util.Optional; +import java.util.Random; +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.WalletClient; +import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.PublicMethed; + +@Slf4j +public class Create2Test018 { + + private final String testKey002 = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + 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(1); + private long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + + private byte[] factoryContractAddress = null; + private byte[] testContractAddress = null; + + private ECKey ecKey1 = new ECKey(Utils.getRandom()); + private byte[] dev001Address = ecKey1.getAddress(); + private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + private String witnessKey001 = Configuration.getByPath("testng.conf") + .getString("witness.key2"); + private byte[] witnessAddress001 = PublicMethed.getFinalAddress(witnessKey001); + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + @BeforeClass(enabled = true) + public void beforeClass() { + + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + + PublicMethed.printAddress(dev001Key); + PublicMethed.printAddress(witnessKey001); + } + + @Test(enabled = true, description = "Deploy factory contract generated by new solidity") + public void test01DeployFactoryContract() { + Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.sendcoin(witnessAddress001, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, + 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + //before deploy, check account resource + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long energyLimit = accountResource.getEnergyLimit(); + long energyUsage = accountResource.getEnergyUsed(); + long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before energyLimit is " + Long.toString(energyLimit)); + logger.info("before energyUsage is " + Long.toString(energyUsage)); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "Factory"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + final String transferTokenTxid = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", + maxFeeLimit, 0L, 0, 10000, + "0", 0, null, dev001Key, + dev001Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + energyLimit = accountResource.getEnergyLimit(); + energyUsage = accountResource.getEnergyUsed(); + long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + + logger.info("after energyLimit is " + Long.toString(energyLimit)); + logger.info("after energyUsage is " + Long.toString(energyUsage)); + logger.info("after balanceAfter is " + Long.toString(balanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); + } + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + factoryContractAddress = infoById.get().getContractAddress().toByteArray(); + SmartContract smartContract = PublicMethed.getContract(factoryContractAddress, + blockingStubFull); + Assert.assertNotNull(smartContract.getAbi()); + } + + + @Test(enabled = true, description = "Trigger create2 function to deploy test contract " + + "using Witness account") + public void test02TriggerCreate2ToDeployTestContract() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 9000_000_000_000L, 0, 1, + ByteString.copyFrom(witnessAddress001), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(witnessAddress001, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(witnessAddress001, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String testContractCode = retMap.get("byteCode").toString(); + Long salt = new Random().nextLong(); + + String param = "\"" + testContractCode + "\"," + salt; + + final String triggerTxid = PublicMethed.triggerContract(factoryContractAddress, + "deploy(bytes,uint256)", param, false, callValue, + 1000000000L, "0", 0, witnessAddress001, witnessKey001, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(witnessAddress001, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(witnessAddress001, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + logger.info( + "the value: " + PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + + List retList = PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + + logger.info("actualSalt: " + actualSalt); + + byte[] tmpAddress = new byte[20]; + System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); + logger.info("address_hex: " + addressHex); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + logger.info("address_final: " + addressFinal); + + testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + SmartContract smartContract = PublicMethed.getContract(testContractAddress, blockingStubFull); + + // contract created by create2, doesn't have ABI + Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); + + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); + + // the contract address in transaction info, + // contract address of create2 contract is factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); + } + + + @Test(enabled = true, description = "Trigger Test contact") + public void test03TriggerTestContract() { + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(witnessAddress001, witnessKey001, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(witnessAddress001), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(witnessAddress001, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(witnessAddress001, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + final String triggerTxid = PublicMethed.triggerContract(testContractAddress, + "plusOne()", "#", false, callValue, + 1000000000L, "0", 0, witnessAddress001, witnessKey001, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(witnessAddress001, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(witnessAddress001, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + logger.info( + "the value: " + PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray())); + + List retList = PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray()); + + Long ret = ByteArray.toLong(ByteArray.fromHexString(retList.get(0))); + + logger.info("ret: " + ret); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("transaction failed with message: " + infoById.get().getResMessage()); + } + + SmartContract smartContract = PublicMethed.getContract(infoById.get().getContractAddress() + .toByteArray(), blockingStubFull); + + long consumeUserPercent = smartContract.getConsumeUserResourcePercent(); + logger.info("ConsumeURPercent: " + consumeUserPercent); + + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + witnessAddress001, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + witnessAddress001, blockingStubFull); + + + } + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } +} + + diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest001.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest001.java new file mode 100644 index 00000000000..70858118ffa --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest001.java @@ -0,0 +1,246 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.extCodeHash; + +import com.google.protobuf.ByteString; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +import java.util.List; +import java.util.Optional; +import java.util.concurrent.TimeUnit; +import lombok.extern.slf4j.Slf4j; +import org.junit.Assert; +import org.spongycastle.util.encoders.Hex; +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.crypto.Hash; +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 ExtCodeHashTest001 { + + private final String testKey002 = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + 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(1); + private long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + + private byte[] extCodeHashContractAddress = null; + private byte[] testContractAddress = null; + + private String expectedCodeHash = null; + + private ECKey ecKey1 = new ECKey(Utils.getRandom()); + private byte[] dev001Address = ecKey1.getAddress(); + private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + private ECKey ecKey2 = new ECKey(Utils.getRandom()); + private byte[] user001Address = ecKey2.getAddress(); + private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + @BeforeClass(enabled = true) + public void beforeClass() { + + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + + PublicMethed.printAddress(dev001Key); + PublicMethed.printAddress(user001Key); + } + + @Test(enabled = true, description = "Deploy extcodehash contract") + public void test01DeployExtCodeHashContract() { + Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, + 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + //before deploy, check account resource + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long energyLimit = accountResource.getEnergyLimit(); + long energyUsage = accountResource.getEnergyUsed(); + long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before energyLimit is " + Long.toString(energyLimit)); + logger.info("before energyUsage is " + Long.toString(energyUsage)); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + String filePath = "./src/test/resources/soliditycode/extCodeHash.sol"; + String contractName = "TestExtCodeHash"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + expectedCodeHash = ByteArray.toHexString(Hash.sha3(Hex.decode(code))); + logger.info("expectedCodeHash: " + expectedCodeHash); + + final String transferTokenTxid = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", + maxFeeLimit, 0L, 0, 10000, + "0", 0, null, dev001Key, + dev001Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + energyLimit = accountResource.getEnergyLimit(); + energyUsage = accountResource.getEnergyUsed(); + long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + + logger.info("after energyLimit is " + Long.toString(energyLimit)); + logger.info("after energyUsage is " + Long.toString(energyUsage)); + logger.info("after balanceAfter is " + Long.toString(balanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); + } + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + extCodeHashContractAddress = infoById.get().getContractAddress().toByteArray(); + SmartContract smartContract = PublicMethed.getContract(extCodeHashContractAddress, + blockingStubFull); + Assert.assertNotNull(smartContract.getAbi()); + } + + @Test(enabled = true, description = "Get the extcodehash of a normal address") + public void test02GetNormalAddressCodeHash() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String param = "\"" + Base58.encode58Check(dev001Address) + "\""; + final String triggerTxid = PublicMethed.triggerContract(extCodeHashContractAddress, + "getCodeHashByAddr(address)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("transaction failed with message: " + + infoById.get().getResMessage().toStringUtf8()); + } + + List retList = PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray()); + + logger.info( + "the value: " + retList); + + Assert.assertEquals("C5D2460186F7233C927E7DB2DCC703C0E500B653CA82273B7BFAD8045D85A470", + retList.get(0)); + + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + user001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + user001Address, blockingStubFull); + } + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } +} + + diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest002.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest002.java new file mode 100644 index 00000000000..06b618823fe --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest002.java @@ -0,0 +1,244 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.extCodeHash; + +import com.google.protobuf.ByteString; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +import java.util.List; +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 ExtCodeHashTest002 { + + private final String testKey002 = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + 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(1); + private long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + + private byte[] extCodeHashContractAddress = null; + private byte[] testContractAddress = null; + + private String expectedCodeHash = null; + + private ECKey ecKey1 = new ECKey(Utils.getRandom()); + private byte[] dev001Address = ecKey1.getAddress(); + private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + private ECKey ecKey2 = new ECKey(Utils.getRandom()); + private byte[] user001Address = ecKey2.getAddress(); + private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + @BeforeClass(enabled = true) + public void beforeClass() { + + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + + PublicMethed.printAddress(dev001Key); + PublicMethed.printAddress(user001Key); + } + + @Test(enabled = true, description = "Deploy extcodehash contract") + public void test01DeployExtCodeHashContract() { + Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, + 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + //before deploy, check account resource + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long energyLimit = accountResource.getEnergyLimit(); + long energyUsage = accountResource.getEnergyUsed(); + long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before energyLimit is " + Long.toString(energyLimit)); + logger.info("before energyUsage is " + Long.toString(energyUsage)); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + String filePath = "./src/test/resources/soliditycode/extCodeHash.sol"; + String contractName = "TestExtCodeHash"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + final String transferTokenTxid = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", + maxFeeLimit, 0L, 0, 10000, + "0", 0, null, dev001Key, + dev001Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + energyLimit = accountResource.getEnergyLimit(); + energyUsage = accountResource.getEnergyUsed(); + long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + + logger.info("after energyLimit is " + Long.toString(energyLimit)); + logger.info("after energyUsage is " + Long.toString(energyUsage)); + logger.info("after balanceAfter is " + Long.toString(balanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); + } + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + extCodeHashContractAddress = infoById.get().getContractAddress().toByteArray(); + SmartContract smartContract = PublicMethed.getContract(extCodeHashContractAddress, + blockingStubFull); + Assert.assertNotNull(smartContract.getAbi()); + } + + @Test(enabled = true, description = "Get a contract extcodehash") + public void test02GetContactCodeHash() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String param = "\"" + Base58.encode58Check(extCodeHashContractAddress) + "\""; + final String triggerTxid = PublicMethed.triggerContract(extCodeHashContractAddress, + "getCodeHashByAddr(address)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + List retList = PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray()); + + logger.info("the value: " + retList); + + Assert.assertFalse(retList.isEmpty()); + Assert.assertNotEquals("C5D2460186F7233C927E7DB2DCC703C0E500B653CA82273B7BFAD8045D85A470", + retList.get(0)); + Assert.assertNotEquals("0000000000000000000000000000000000000000000000000000000000000000", + retList.get(0)); + + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + user001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + user001Address, blockingStubFull); + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } +} + + diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest003.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest003.java new file mode 100644 index 00000000000..9c264e01014 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest003.java @@ -0,0 +1,334 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.extCodeHash; + +import com.google.protobuf.ByteString; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +import java.util.List; +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 ExtCodeHashTest003 { + + private final String testKey002 = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + 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(1); + private long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + + private byte[] extCodeHashContractAddress = null; + private byte[] testContractAddress = null; + + private String expectedCodeHash = null; + + private ECKey ecKey1 = new ECKey(Utils.getRandom()); + private byte[] dev001Address = ecKey1.getAddress(); + private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + private ECKey ecKey2 = new ECKey(Utils.getRandom()); + private byte[] user001Address = ecKey2.getAddress(); + private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + + private ECKey ecKey3 = new ECKey(Utils.getRandom()); + private byte[] testAddress = ecKey3.getAddress(); + private String testKey = ByteArray.toHexString(ecKey3.getPrivKeyBytes()); + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + @BeforeClass(enabled = true) + public void beforeClass() { + + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + + PublicMethed.printAddress(dev001Key); + PublicMethed.printAddress(user001Key); + } + + @Test(enabled = true, description = "Deploy extcodehash contract") + public void test01DeployExtCodeHashContract() { + Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, + 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + //before deploy, check account resource + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long energyLimit = accountResource.getEnergyLimit(); + long energyUsage = accountResource.getEnergyUsed(); + long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before energyLimit is " + Long.toString(energyLimit)); + logger.info("before energyUsage is " + Long.toString(energyUsage)); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + String filePath = "./src/test/resources/soliditycode/extCodeHash.sol"; + String contractName = "TestExtCodeHash"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + final String transferTokenTxid = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", + maxFeeLimit, 0L, 0, 10000, + "0", 0, null, dev001Key, + dev001Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + energyLimit = accountResource.getEnergyLimit(); + energyUsage = accountResource.getEnergyUsed(); + long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + + logger.info("after energyLimit is " + Long.toString(energyLimit)); + logger.info("after energyUsage is " + Long.toString(energyUsage)); + logger.info("after balanceAfter is " + Long.toString(balanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); + } + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + extCodeHashContractAddress = infoById.get().getContractAddress().toByteArray(); + SmartContract smartContract = PublicMethed.getContract(extCodeHashContractAddress, + blockingStubFull); + Assert.assertNotNull(smartContract.getAbi()); + } + + @Test(enabled = true, description = "Get a not exist account extcodehash") + public void test02GetNotExistAddressCodeHash() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String param = "\"" + Base58.encode58Check(testAddress) + "\""; + final String triggerTxid = PublicMethed.triggerContract(extCodeHashContractAddress, + "getCodeHashByAddr(address)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + List retList = PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray()); + + logger.info( + "the value: " + retList); + + Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000000", + retList.get(0)); + + SmartContract smartContract = PublicMethed + .getContract(extCodeHashContractAddress, blockingStubFull); + logger.info(smartContract.getBytecode().toStringUtf8()); + } + + @Test(enabled = true, description = "Active the account and get extcodehash again") + public void test03ActiveAccountGetCodeHash() { + + Assert.assertTrue(PublicMethed.sendcoin(testAddress, 1000000, fromAddress, + testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String param = "\"" + Base58.encode58Check(testAddress) + "\""; + final String triggerTxid = PublicMethed.triggerContract(extCodeHashContractAddress, + "getCodeHashByAddr(address)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + List retList = PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray()); + + logger.info("the value: " + retList); + + Assert.assertEquals("C5D2460186F7233C927E7DB2DCC703C0E500B653CA82273B7BFAD8045D85A470", + retList.get(0)); + + SmartContract smartContract = PublicMethed + .getContract(extCodeHashContractAddress, blockingStubFull); + logger.info(smartContract.getBytecode().toStringUtf8()); + + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + user001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + user001Address, blockingStubFull); + } + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } +} + + diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest004.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest004.java new file mode 100644 index 00000000000..d67346ac6a2 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest004.java @@ -0,0 +1,254 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.extCodeHash; + +import com.google.protobuf.ByteString; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +import java.util.List; +import java.util.Optional; +import java.util.concurrent.TimeUnit; +import lombok.extern.slf4j.Slf4j; +import org.junit.Assert; +import org.spongycastle.util.encoders.Hex; +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.crypto.Hash; +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.WalletClient; +import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.PublicMethed; + +@Slf4j +public class ExtCodeHashTest004 { + + private final String testKey002 = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + 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(1); + private long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + + private byte[] extCodeHashContractAddress = null; + private String testContractAddress = null; + + private String expectedCodeHash = null; + + private ECKey ecKey1 = new ECKey(Utils.getRandom()); + private byte[] dev001Address = ecKey1.getAddress(); + private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + private ECKey ecKey2 = new ECKey(Utils.getRandom()); + private byte[] user001Address = ecKey2.getAddress(); + private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + @BeforeClass(enabled = true) + public void beforeClass() { + + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + + PublicMethed.printAddress(dev001Key); + PublicMethed.printAddress(user001Key); + } + + @Test(enabled = true, description = "Deploy extcodehash contract") + public void test01DeployExtCodeHashContract() { + Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, + 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + //before deploy, check account resource + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long energyLimit = accountResource.getEnergyLimit(); + long energyUsage = accountResource.getEnergyUsed(); + long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before energyLimit is " + Long.toString(energyLimit)); + logger.info("before energyUsage is " + Long.toString(energyUsage)); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + String filePath = "./src/test/resources/soliditycode/extCodeHash.sol"; + String contractName = "TestExtCodeHash"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + final String abi = retMap.get("abI").toString(); + + expectedCodeHash = ByteArray.toHexString(Hash.sha3(Hex.decode(code))); + logger.info("expectedCodeHash: " + expectedCodeHash); + + Long salt = 100L; + String[] parameter = {Base58.encode58Check(user001Address), code, salt.toString()}; + logger.info(PublicMethed.create2(parameter)); + testContractAddress = PublicMethed.create2(parameter); + + final String transferTokenTxid = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", + maxFeeLimit, 0L, 0, 10000, + "0", 0, null, dev001Key, + dev001Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + energyLimit = accountResource.getEnergyLimit(); + energyUsage = accountResource.getEnergyUsed(); + long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + + logger.info("after energyLimit is " + Long.toString(energyLimit)); + logger.info("after energyUsage is " + Long.toString(energyUsage)); + logger.info("after balanceAfter is " + Long.toString(balanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); + } + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + extCodeHashContractAddress = infoById.get().getContractAddress().toByteArray(); + SmartContract smartContract = PublicMethed.getContract(extCodeHashContractAddress, + blockingStubFull); + Assert.assertNotNull(smartContract.getAbi()); + } + + @Test(enabled = true, description = "Get a not deployed create2 extcodehash") + public void test02GetCreate2CodeHash() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String param = + "\"" + Base58.encode58Check(WalletClient.decodeFromBase58Check(testContractAddress)) + "\""; + final String triggerTxid = PublicMethed.triggerContract(extCodeHashContractAddress, + "getCodeHashByAddr(address)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + List retList = PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray()); + + logger.info( + "the value: " + retList); + + Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000000", + retList.get(0)); + + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + user001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + user001Address, blockingStubFull); + } + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } +} + + diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest005.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest005.java new file mode 100644 index 00000000000..c1b992e28e6 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest005.java @@ -0,0 +1,697 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.extCodeHash; + +import com.google.protobuf.ByteString; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.math.BigInteger; +import java.util.HashMap; +import java.util.List; +import java.util.Optional; +import java.util.concurrent.TimeUnit; +import lombok.extern.slf4j.Slf4j; +import org.junit.Assert; +import org.spongycastle.util.encoders.Hex; +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.runtime.vm.DataWord; +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.PublicMethed; + +@Slf4j +public class ExtCodeHashTest005 { + + private final String testKey002 = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + 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(1); + private long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + + private byte[] extCodeHashContractAddress = null; + private byte[] testContractAddress = null; + + private String contractCodeHash = null; + + private ECKey ecKey1 = new ECKey(Utils.getRandom()); + private byte[] dev001Address = ecKey1.getAddress(); + private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + private ECKey ecKey2 = new ECKey(Utils.getRandom()); + private byte[] user001Address = ecKey2.getAddress(); + private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + + private ECKey ecKey3 = new ECKey(Utils.getRandom()); + private byte[] testAddress = ecKey3.getAddress(); + private String testKey = ByteArray.toHexString(ecKey3.getPrivKeyBytes()); + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + @BeforeClass(enabled = true) + public void beforeClass() { + + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + + PublicMethed.printAddress(dev001Key); + PublicMethed.printAddress(user001Key); + } + + @Test(enabled = true, description = "Deploy extcodehash contract") + public void test01DeployExtCodeHashContract() { + Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, + 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + //before deploy, check account resource + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long energyLimit = accountResource.getEnergyLimit(); + long energyUsage = accountResource.getEnergyUsed(); + long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before energyLimit is " + Long.toString(energyLimit)); + logger.info("before energyUsage is " + Long.toString(energyUsage)); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + String filePath = "./src/test/resources/soliditycode/extCodeHash.sol"; + String contractName = "TestExtCodeHash"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + final String transferTokenTxid = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", + maxFeeLimit, 0L, 0, 10000, + "0", 0, null, dev001Key, + dev001Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + energyLimit = accountResource.getEnergyLimit(); + energyUsage = accountResource.getEnergyUsed(); + long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + + logger.info("after energyLimit is " + Long.toString(energyLimit)); + logger.info("after energyUsage is " + Long.toString(energyUsage)); + logger.info("after balanceAfter is " + Long.toString(balanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); + } + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + extCodeHashContractAddress = infoById.get().getContractAddress().toByteArray(); + SmartContract smartContract = PublicMethed.getContract(extCodeHashContractAddress, + blockingStubFull); + Assert.assertNotNull(smartContract.getAbi()); + } + + @Test(enabled = true, description = "Get codehash of a real contract by uint") + public void test02GetContractCodeHash() { + + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String testAddress = ByteArray.toHexString(extCodeHashContractAddress); + logger.info("realAddress: " + testAddress); + byte[] fullHexAddr = new DataWord(testAddress).getData(); + + final String triggerTxid = PublicMethed.triggerContract(extCodeHashContractAddress, + "getCodeHashByUint(uint256)", Hex.toHexString(fullHexAddr), true, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + List retList = PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray()); + + logger.info("the value: " + retList); + + Assert.assertFalse(retList.isEmpty()); + Assert.assertNotEquals("C5D2460186F7233C927E7DB2DCC703C0E500B653CA82273B7BFAD8045D85A470", + retList.get(0)); + Assert.assertNotEquals("0000000000000000000000000000000000000000000000000000000000000000", + retList.get(0)); + + contractCodeHash = retList.get(0); + + SmartContract smartContract = PublicMethed + .getContract(extCodeHashContractAddress, blockingStubFull); + logger.info(smartContract.getBytecode().toStringUtf8()); + } + + @Test(enabled = true, description = "Get codehash of a fake address by uint") + public void test03GetInvalidAddressCodeHash() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String fakeAddress = "41660757B2543F4849D3F42B90F58DE1C14C7E0038"; + logger.info("realAddress: " + fakeAddress); + byte[] fullHexAddr = new DataWord(fakeAddress).getData(); + + final String triggerTxid = PublicMethed.triggerContract(extCodeHashContractAddress, + "getCodeHashByUint(uint256)", Hex.toHexString(fullHexAddr), true, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + List retList = PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray()); + + logger.info("the value: " + retList); + + Assert.assertFalse(retList.isEmpty()); + + Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000000", + retList.get(0)); + + SmartContract smartContract = PublicMethed + .getContract(extCodeHashContractAddress, blockingStubFull); + logger.info(smartContract.getBytecode().toStringUtf8()); + } + + @Test(enabled = true, description = "Get codehash of a normal account by uint") + public void test04GetNormalAddressCodeHash() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String fakeAddress = ByteArray.toHexString(user001Address); + logger.info("realAddress: " + fakeAddress); + byte[] fullHexAddr = new DataWord(fakeAddress).getData(); + + final String triggerTxid = PublicMethed.triggerContract(extCodeHashContractAddress, + "getCodeHashByUint(uint256)", Hex.toHexString(fullHexAddr), true, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + List retList = PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray()); + + logger.info("the value: " + retList); + Assert.assertFalse(retList.isEmpty()); + + Assert.assertEquals("C5D2460186F7233C927E7DB2DCC703C0E500B653CA82273B7BFAD8045D85A470", + retList.get(0)); + + SmartContract smartContract = PublicMethed + .getContract(extCodeHashContractAddress, blockingStubFull); + logger.info(smartContract.getBytecode().toStringUtf8()); + } + + @Test(enabled = true, description = "Get codehash of a empty address by uint") + public void test05GetEmptyAddressCodeHash() { + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String fakeAddress = ""; + + logger.info("realAddress: " + fakeAddress); + byte[] fullHexAddr = new DataWord(fakeAddress).getData(); + + final String triggerTxid = PublicMethed.triggerContract(extCodeHashContractAddress, + "getCodeHashByUint(uint256)", Hex.toHexString(fullHexAddr), true, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + List retList = PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray()); + + logger.info("the value: " + retList); + Assert.assertFalse(retList.isEmpty()); + + Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000000", + retList.get(0)); + + SmartContract smartContract = PublicMethed + .getContract(extCodeHashContractAddress, blockingStubFull); + logger.info(smartContract.getBytecode().toStringUtf8()); + } + + @Test(enabled = true, description = "Get codehash of a fffffff*64 address by uint") + public void test06GetFakeAddressCodeHash() { + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String fakeAddress = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"; + + logger.info("realAddress: " + fakeAddress); + byte[] fullHexAddr = new DataWord(fakeAddress).getData(); + + final String triggerTxid = PublicMethed.triggerContract(extCodeHashContractAddress, + "getCodeHashByUint(uint256)", Hex.toHexString(fullHexAddr), true, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + List retList = PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray()); + + logger.info("the value: " + retList); + Assert.assertFalse(retList.isEmpty()); + + Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000000", + retList.get(0)); + + SmartContract smartContract = PublicMethed + .getContract(extCodeHashContractAddress, blockingStubFull); + logger.info(smartContract.getBytecode().toStringUtf8()); + } + + @Test(enabled = true, description = "Get codehash of a real contract plus 2**160 by uint") + public void test07GetContractAddress96CodeHash() { + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + BigInteger bigIntAddr = new DataWord(extCodeHashContractAddress).sValue(); + String bigIntAddrChange = BigInteger.valueOf(2).pow(160).add(bigIntAddr).toString(16); + byte[] fullHexAddr = new DataWord(bigIntAddrChange).getData(); + + final String triggerTxid = PublicMethed.triggerContract(extCodeHashContractAddress, + "getCodeHashByUint(uint256)", Hex.toHexString(fullHexAddr), true, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + List retList = PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray()); + + logger.info("the value: " + retList); + Assert.assertFalse(retList.isEmpty()); + + // expect the code hash same + Assert.assertEquals(contractCodeHash, retList.get(0)); + + SmartContract smartContract = PublicMethed + .getContract(extCodeHashContractAddress, blockingStubFull); + logger.info(smartContract.getBytecode().toStringUtf8()); + + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + user001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + user001Address, blockingStubFull); + } + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } +} + + diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest006.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest006.java new file mode 100644 index 00000000000..b0ccf9f8e98 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest006.java @@ -0,0 +1,184 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.extCodeHash; + +import com.google.protobuf.ByteString; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +import java.util.List; +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.PublicMethed; + +@Slf4j +public class ExtCodeHashTest006 { + + private final String testKey002 = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + 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(1); + private long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + + private byte[] extCodeHashContractAddress = null; + private byte[] testContractAddress = null; + + private String expectedCodeHash = null; + + private ECKey ecKey1 = new ECKey(Utils.getRandom()); + private byte[] dev001Address = ecKey1.getAddress(); + private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + private ECKey ecKey2 = new ECKey(Utils.getRandom()); + private byte[] user001Address = ecKey2.getAddress(); + private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + + private ECKey ecKey3 = new ECKey(Utils.getRandom()); + private byte[] testAddress = ecKey3.getAddress(); + private String testKey = ByteArray.toHexString(ecKey3.getPrivKeyBytes()); + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + @BeforeClass(enabled = true) + public void beforeClass() { + + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + + PublicMethed.printAddress(dev001Key); + PublicMethed.printAddress(user001Key); + } + + @Test(enabled = true, description = "Get the EXTCODEHASH of an account created " + + "in the current transaction") + public void test01DeployExtCodeHashContract() { + Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, + 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + //before deploy, check account resource + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long energyLimit = accountResource.getEnergyLimit(); + long energyUsage = accountResource.getEnergyUsed(); + long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before energyLimit is " + Long.toString(energyLimit)); + logger.info("before energyUsage is " + Long.toString(energyUsage)); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + String filePath = "./src/test/resources/soliditycode/extCodeHashConstruct.sol"; + String contractName = "CounterConstruct"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + final String transferTokenTxid = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", + maxFeeLimit, 0L, 0, 10000, + "0", 0, null, dev001Key, + dev001Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + energyLimit = accountResource.getEnergyLimit(); + energyUsage = accountResource.getEnergyUsed(); + long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + + logger.info("after energyLimit is " + Long.toString(energyLimit)); + logger.info("after energyUsage is " + Long.toString(energyUsage)); + logger.info("after balanceAfter is " + Long.toString(balanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); + } + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + extCodeHashContractAddress = infoById.get().getContractAddress().toByteArray(); + SmartContract smartContract = PublicMethed.getContract(extCodeHashContractAddress, + blockingStubFull); + Assert.assertNotNull(smartContract.getAbi()); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + List retList = PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getTopics(0).toByteArray()); + + logger.info("the value: " + retList); + + Assert.assertFalse(retList.isEmpty()); + Assert.assertNotEquals("C5D2460186F7233C927E7DB2DCC703C0E500B653CA82273B7BFAD8045D85A470", + retList.get(0)); + Assert.assertNotEquals("0000000000000000000000000000000000000000000000000000000000000000", + retList.get(0)); + + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + user001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + user001Address, blockingStubFull); + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } +} + + diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest007.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest007.java new file mode 100644 index 00000000000..763653ec49d --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest007.java @@ -0,0 +1,601 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.extCodeHash; + +import com.google.protobuf.ByteString; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +import java.util.List; +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 ExtCodeHashTest007 { + + private final String testKey002 = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + 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(1); + private long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + + private byte[] testAddressOld = null; + private byte[] testAddressNew = null; + private byte[] testAddress2 = null; + private byte[] extCodeHashContractAddress = null; + + private String expectedCodeHash = null; + private String expectedCodeHashOld = null; + + + private ECKey ecKey1 = new ECKey(Utils.getRandom()); + private byte[] dev001Address = ecKey1.getAddress(); + private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + private ECKey ecKey2 = new ECKey(Utils.getRandom()); + private byte[] user001Address = ecKey2.getAddress(); + private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + @BeforeClass(enabled = true) + public void beforeClass() { + + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + + PublicMethed.printAddress(dev001Key); + PublicMethed.printAddress(user001Key); + } + + @Test(enabled = true, description = "Deploy testNoPayable contract using old solidity") + public void test01DeployTestContractOld() { + Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, + 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + //before deploy, check account resource + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long energyLimit = accountResource.getEnergyLimit(); + long energyUsage = accountResource.getEnergyUsed(); + long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before energyLimit is " + Long.toString(energyLimit)); + logger.info("before energyUsage is " + Long.toString(energyUsage)); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + String contractName = "testExtHashContract"; + String code = "608060405234801561001057600080fd5b50d3801561001d57600080fd5b50d2801561002a576000" + + "80fd5b5060ef806100396000396000f30060806040526004361060485763ffffffff7c010000000000000000" + + "0000000000000000000000000000000000000000600035041663c518aa0f8114604d578063e5aa3d58146089" + + "575b600080fd5b348015605857600080fd5b50d38015606457600080fd5b50d28015607057600080fd5b5060" + + "7760b3565b60408051918252519081900360200190f35b348015609457600080fd5b50d3801560a057600080" + + "fd5b50d2801560ac57600080fd5b50607760bd565b6001600081905590565b600054815600a165627a7a7230" + + "5820766b4e2fca9081689cd89419411d2cbc5588a17a5c9fa900fd9cfe4b0d9652be0029"; + String abi = "[{\"constant\":false,\"inputs\":[],\"name\":\"testNoPayable\"," + + "\"outputs\":[{\"name\":\"z\",\"type\":\"uint256\"}],\"payable\":false," + + "\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true," + + "\"inputs\":[],\"name\":\"i\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}]," + + "\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"}]"; + + final String transferTokenTxid = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", + maxFeeLimit, 0L, 0, 10000, + "0", 0, null, dev001Key, + dev001Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + energyLimit = accountResource.getEnergyLimit(); + energyUsage = accountResource.getEnergyUsed(); + long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + + logger.info("after energyLimit is " + Long.toString(energyLimit)); + logger.info("after energyUsage is " + Long.toString(energyUsage)); + logger.info("after balanceAfter is " + Long.toString(balanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); + } + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + testAddressOld = infoById.get().getContractAddress().toByteArray(); + SmartContract smartContract = PublicMethed.getContract(testAddressOld, + blockingStubFull); + } + + @Test(enabled = true, description = "Deploy testNoPayable contract using new solidity") + public void test02DeployTestContractNew() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, + 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + //before deploy, check account resource + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long energyLimit = accountResource.getEnergyLimit(); + long energyUsage = accountResource.getEnergyUsed(); + long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before energyLimit is " + Long.toString(energyLimit)); + logger.info("before energyUsage is " + Long.toString(energyUsage)); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + String filePath = "./src/test/resources/soliditycode/extCodeHashTestNoPayable.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + final String transferTokenTxid = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", + maxFeeLimit, 0L, 0, 10000, + "0", 0, null, dev001Key, + dev001Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + energyLimit = accountResource.getEnergyLimit(); + energyUsage = accountResource.getEnergyUsed(); + long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + + logger.info("after energyLimit is " + Long.toString(energyLimit)); + logger.info("after energyUsage is " + Long.toString(energyUsage)); + logger.info("after balanceAfter is " + Long.toString(balanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); + } + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + testAddressNew = infoById.get().getContractAddress().toByteArray(); + SmartContract smartContract = PublicMethed.getContract(testAddressNew, + blockingStubFull); + } + + @Test(enabled = true, description = "Deploy extcodehash contract") + public void test03DeployExtCodeHashContract() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, + 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + //before deploy, check account resource + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long energyLimit = accountResource.getEnergyLimit(); + long energyUsage = accountResource.getEnergyUsed(); + long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before energyLimit is " + Long.toString(energyLimit)); + logger.info("before energyUsage is " + Long.toString(energyUsage)); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + String filePath = "./src/test/resources/soliditycode/extCodeHash.sol"; + String contractName = "TestExtCodeHash"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + final String transferTokenTxid = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", + maxFeeLimit, 0L, 0, 10000, + "0", 0, null, dev001Key, + dev001Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + energyLimit = accountResource.getEnergyLimit(); + energyUsage = accountResource.getEnergyUsed(); + long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + + logger.info("after energyLimit is " + Long.toString(energyLimit)); + logger.info("after energyUsage is " + Long.toString(energyUsage)); + logger.info("after balanceAfter is " + Long.toString(balanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); + } + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + extCodeHashContractAddress = infoById.get().getContractAddress().toByteArray(); + SmartContract smartContract = PublicMethed.getContract(extCodeHashContractAddress, + blockingStubFull); + } + + @Test(enabled = true, description = "Get contract code hash with old solidity") + public void test04GetTestOldCodeHash() { + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String param = "\"" + Base58.encode58Check(testAddressOld) + "\""; + final String triggerTxid = PublicMethed.triggerContract(extCodeHashContractAddress, + "getCodeHashByAddr(address)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + List retList = PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray()); + + logger.info( + "the value: " + retList); + + expectedCodeHashOld = retList.get(0); + + Assert.assertFalse(retList.isEmpty()); + } + + @Test(enabled = true, description = "Get contract code hash with new solidity") + public void test05GetTestNewCodeHash() { + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String param = "\"" + Base58.encode58Check(testAddressNew) + "\""; + final String triggerTxid = PublicMethed.triggerContract(extCodeHashContractAddress, + "getCodeHashByAddr(address)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + List retList = PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray()); + + logger.info("the value: " + retList); + Assert.assertFalse(retList.isEmpty()); + + Assert.assertNotEquals(retList.get(0), expectedCodeHashOld); + expectedCodeHash = retList.get(0); + } + + @Test(enabled = true, description = "Deploy contract using new solidity again") + public void test06DeployTest2Contract() { + Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, + 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + //before deploy, check account resource + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long energyLimit = accountResource.getEnergyLimit(); + long energyUsage = accountResource.getEnergyUsed(); + long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before energyLimit is " + Long.toString(energyLimit)); + logger.info("before energyUsage is " + Long.toString(energyUsage)); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + String filePath = "./src/test/resources/soliditycode/extCodeHashTestNoPayable.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + final String transferTokenTxid = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", + maxFeeLimit, 0L, 0, 10000, + "0", 0, null, dev001Key, + dev001Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + energyLimit = accountResource.getEnergyLimit(); + energyUsage = accountResource.getEnergyUsed(); + long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + + logger.info("after energyLimit is " + Long.toString(energyLimit)); + logger.info("after energyUsage is " + Long.toString(energyUsage)); + logger.info("after balanceAfter is " + Long.toString(balanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); + } + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + testAddress2 = infoById.get().getContractAddress().toByteArray(); + SmartContract smartContract = PublicMethed.getContract(testAddress2, + blockingStubFull); + } + + @Test(enabled = true, description = "Get contract code hash with test2") + public void test07GetTest2CodeHash() { + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String param = "\"" + Base58.encode58Check(testAddress2) + "\""; + final String triggerTxid = PublicMethed.triggerContract(extCodeHashContractAddress, + "getCodeHashByAddr(address)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + List retList = PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray()); + + logger.info("the value: " + retList); + Assert.assertFalse(retList.isEmpty()); + + Assert.assertEquals(expectedCodeHash, retList.get(0)); + + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + user001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + user001Address, blockingStubFull); + } + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } +} + + diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest008.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest008.java new file mode 100644 index 00000000000..6ef73cdfb29 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest008.java @@ -0,0 +1,512 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.extCodeHash; + +import com.google.protobuf.ByteString; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +import java.util.List; +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.WalletClient; +import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.PublicMethed; + +@Slf4j +public class ExtCodeHashTest008 { + + private final String testKey002 = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + 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(1); + private long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + + private byte[] factoryContractAddress = null; + private byte[] extCodeHashContractAddress = null; + private byte[] testContractAddress = null; + + private String expectedCodeHash = null; + + private ECKey ecKey1 = new ECKey(Utils.getRandom()); + private byte[] dev001Address = ecKey1.getAddress(); + private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + private ECKey ecKey2 = new ECKey(Utils.getRandom()); + private byte[] user001Address = ecKey2.getAddress(); + private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + @BeforeClass(enabled = true) + public void beforeClass() { + + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + + PublicMethed.printAddress(dev001Key); + PublicMethed.printAddress(user001Key); + } + + @Test(enabled = true, description = "Deploy extcodehash contract") + public void test01DeployExtCodeHashContract() { + Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, + 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + //before deploy, check account resource + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long energyLimit = accountResource.getEnergyLimit(); + long energyUsage = accountResource.getEnergyUsed(); + long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before energyLimit is " + Long.toString(energyLimit)); + logger.info("before energyUsage is " + Long.toString(energyUsage)); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + String filePath = "./src/test/resources/soliditycode/extCodeHash.sol"; + String contractName = "TestExtCodeHash"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + final String transferTokenTxid = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", + maxFeeLimit, 0L, 0, 10000, + "0", 0, null, dev001Key, + dev001Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + energyLimit = accountResource.getEnergyLimit(); + energyUsage = accountResource.getEnergyUsed(); + long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + + logger.info("after energyLimit is " + Long.toString(energyLimit)); + logger.info("after energyUsage is " + Long.toString(energyUsage)); + logger.info("after balanceAfter is " + Long.toString(balanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); + } + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + extCodeHashContractAddress = infoById.get().getContractAddress().toByteArray(); + SmartContract smartContract = PublicMethed.getContract(extCodeHashContractAddress, + blockingStubFull); + } + + @Test(enabled = true, description = "Get code hash of create2 empty contract") + public void test02GetTestContractCodeHash() { + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String testContractCode = retMap.get("byteCode").toString(); + Long salt = 1L; + + String[] parameter = {Base58.encode58Check(user001Address), testContractCode, salt.toString()}; + logger.info(PublicMethed.create2(parameter)); + + Long callValue = Long.valueOf(0); + + String param = "\"" + PublicMethed.create2(parameter) + "\""; + final String triggerTxid = PublicMethed.triggerContract(extCodeHashContractAddress, + "getCodeHashByAddr(address)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + List retList = PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray()); + + logger.info("the value: " + retList); + + Assert.assertFalse(retList.isEmpty()); + Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000000", + retList.get(0)); + } + + @Test(enabled = true, description = "Deploy factory contract") + public void test03DeployFactoryContract() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, + 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + //before deploy, check account resource + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long energyLimit = accountResource.getEnergyLimit(); + long energyUsage = accountResource.getEnergyUsed(); + long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before energyLimit is " + Long.toString(energyLimit)); + logger.info("before energyUsage is " + Long.toString(energyUsage)); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "Factory"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + final String transferTokenTxid = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", + maxFeeLimit, 0L, 0, 10000, + "0", 0, null, dev001Key, + dev001Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + energyLimit = accountResource.getEnergyLimit(); + energyUsage = accountResource.getEnergyUsed(); + long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + + logger.info("after energyLimit is " + Long.toString(energyLimit)); + logger.info("after energyUsage is " + Long.toString(energyUsage)); + logger.info("after balanceAfter is " + Long.toString(balanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); + } + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + factoryContractAddress = infoById.get().getContractAddress().toByteArray(); + SmartContract smartContract = PublicMethed.getContract(factoryContractAddress, + blockingStubFull); + Assert.assertNotNull(smartContract.getAbi()); + } + + @Test(enabled = true, description = "Trigger create2 function to deploy test contract") + public void test04TriggerCreate2ToDeployTestContract() { + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String testContractCode = retMap.get("byteCode").toString(); + Long salt = 1L; + + String param = "\"" + testContractCode + "\"," + salt; + + final String triggerTxid = PublicMethed.triggerContract(factoryContractAddress, + "deploy(bytes,uint256)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + logger.info( + "the value: " + PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + + List retList = PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + + logger.info("actualSalt: " + actualSalt); + + byte[] tmpAddress = new byte[20]; + System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); + logger.info("address_hex: " + addressHex); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + logger.info("address_final: " + addressFinal); + + testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + SmartContract smartContract = PublicMethed.getContract(testContractAddress, blockingStubFull); + + // contract created by create2, doesn't have ABI + Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); + + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); + + // the contract address in transaction info, + // contract address of create2 contract is factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); + } + + @Test(enabled = true, description = "Get code hash of test contract") + public void test05GetTestContractCodeHash() { + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String param = "\"" + Base58.encode58Check(testContractAddress) + "\""; + final String triggerTxid = PublicMethed.triggerContract(extCodeHashContractAddress, + "getCodeHashByAddr(address)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + List retList = PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray()); + + logger.info("the value: " + retList); + + Assert.assertFalse(retList.isEmpty()); + Assert.assertNotEquals("C5D2460186F7233C927E7DB2DCC703C0E500B653CA82273B7BFAD8045D85A470", + retList.get(0)); + Assert.assertNotEquals("0000000000000000000000000000000000000000000000000000000000000000", + retList.get(0)); + + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + user001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + user001Address, blockingStubFull); + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } +} + + diff --git a/src/test/resources/soliditycode/create2CallContract.sol b/src/test/resources/soliditycode/create2CallContract.sol new file mode 100644 index 00000000000..fe5c13c16c5 --- /dev/null +++ b/src/test/resources/soliditycode/create2CallContract.sol @@ -0,0 +1,37 @@ +contract callerContract { + constructor() payable public{} + function() payable external{} + function delegateCallCreate2(address called_address, bytes memory code, uint256 salt) public { + called_address.delegatecall(abi.encodeWithSignature("deploy(bytes,uint256)",code,salt)); + } + function callCreate2(address called_address,bytes memory code, uint256 salt) public { + called_address.call(abi.encodeWithSignature("deploy(bytes,uint256)",code,salt)); + } +} + + +contract Factory { + event Deployed(address addr, uint256 salt, address sender); + function deploy(bytes memory code, uint256 salt) public returns(address){ + address addr; + assembly { + addr := create2(0, add(code, 0x20), mload(code), salt) + if iszero(extcodesize(addr)) { + revert(0, 0) + } + } + emit Deployed(addr, salt, msg.sender); + return addr; + } +} + + +contract TestConstract { + uint public i; + constructor () public { + } + function plusOne() public returns(uint){ + i++; + return i; + } +} \ No newline at end of file diff --git a/src/test/resources/soliditycode/create2contract.sol b/src/test/resources/soliditycode/create2contract.sol new file mode 100644 index 00000000000..1943d6e9cdc --- /dev/null +++ b/src/test/resources/soliditycode/create2contract.sol @@ -0,0 +1,39 @@ +contract Factory { + event Deployed(address addr, uint256 salt, address sender); + function deploy(bytes memory code, uint256 salt) public returns(address){ + address addr; + assembly { + addr := create2(0, add(code, 0x20), mload(code), salt) + if iszero(extcodesize(addr)) { + revert(0, 0) + } + } + emit Deployed(addr, salt, msg.sender); + return addr; + } +} + +contract FactoryBytes { + event Deployed(address addr, bytes32 salt, address sender); + function deploy(bytes memory code, bytes32 salt) public returns(address){ + address addr; + assembly { + addr := create2(0, add(code, 0x20), mload(code), salt) + if iszero(extcodesize(addr)) { + revert(0, 0) + } + } + emit Deployed(addr, salt, msg.sender); + return addr; + } +} + +contract TestConstract { + uint public i; + constructor () public { + } + function plusOne() public returns(uint){ + i++; + return i; + } +} \ No newline at end of file diff --git a/src/test/resources/soliditycode/extCodeHash.sol b/src/test/resources/soliditycode/extCodeHash.sol new file mode 100644 index 00000000000..d6209770682 --- /dev/null +++ b/src/test/resources/soliditycode/extCodeHash.sol @@ -0,0 +1,13 @@ +contract TestExtCodeHash { + + function getCodeHashByAddr(address _addr) public returns (bytes32 _hash) { + assembly { + _hash := extcodehash(_addr) + } + } + function getCodeHashByUint(uint256 _addr) public returns (bytes32 _hash) { + assembly { + _hash := extcodehash(_addr) + } + } +} diff --git a/src/test/resources/soliditycode/extCodeHashConstruct.sol b/src/test/resources/soliditycode/extCodeHashConstruct.sol new file mode 100644 index 00000000000..6bb91b3d3b1 --- /dev/null +++ b/src/test/resources/soliditycode/extCodeHashConstruct.sol @@ -0,0 +1,14 @@ +contract CounterConstruct { + uint count = 0; + address payable owner; + event LogResult(bytes32 _hashBefore); + constructor() public{ + owner = msg.sender; + address addr = address(this); + bytes32 _hashBefore; + assembly { + _hashBefore := extcodehash(addr) + } + emit LogResult(_hashBefore); + } + } \ No newline at end of file diff --git a/src/test/resources/soliditycode/extCodeHashTestNoPayable.sol b/src/test/resources/soliditycode/extCodeHashTestNoPayable.sol new file mode 100644 index 00000000000..c3a2ad8c6ae --- /dev/null +++ b/src/test/resources/soliditycode/extCodeHashTestNoPayable.sol @@ -0,0 +1,8 @@ +contract testConstantContract{ +uint256 public i; +function testNoPayable() public returns (uint256 z) { +i=1; +z=i; +return z; +} +} \ No newline at end of file From 19614d29240e926f362c81d867d9679c23d2480b Mon Sep 17 00:00:00 2001 From: xiechang33 <354035097@qq.com> Date: Tue, 7 May 2019 17:46:07 +0800 Subject: [PATCH 04/90] improve tvmNewCommand stest --- .../common/client/utils/HttpMethed.java | 53 ++++- .../http/HttpTestConstantContract001.java | 165 +++++++++++++++ .../WalletTestMutiSign018.java | 188 ++++++++++++++++++ .../tvmnewcommand/clearabi/ClearAbi001.java | 1 - .../tvmnewcommand/clearabi/ClearAbi002.java | 1 - .../tvmnewcommand/clearabi/ClearAbi003.java | 1 - .../tvmnewcommand/clearabi/ClearAbi004.java | 1 - .../tvmnewcommand/clearabi/ClearAbi005.java | 1 - .../tvmnewcommand/clearabi/ClearAbi006.java | 1 - .../tvmnewcommand/clearabi/ClearAbi007.java | 1 - .../tvmnewcommand/clearabi/ClearAbi008.java | 1 - .../shiftcommand/ShiftCommand001.java | 1 - .../shiftcommand/ShiftCommand002.java | 2 - .../shiftcommand/ShiftCommand003.java | 5 - .../shiftcommand/ShiftCommand004.java | 31 +-- .../shiftcommand/ShiftCommand005.java | 22 -- .../shiftcommand/ShiftCommand006.java | 26 --- .../triggerconstant/TriggerConstant001.java | 1 - .../triggerconstant/TriggerConstant002.java | 1 - .../triggerconstant/TriggerConstant003.java | 1 - .../triggerconstant/TriggerConstant004.java | 1 - .../triggerconstant/TriggerConstant005.java | 1 - .../triggerconstant/TriggerConstant006.java | 1 - .../triggerconstant/TriggerConstant007.java | 1 - .../triggerconstant/TriggerConstant008.java | 1 - .../triggerconstant/TriggerConstant009.java | 1 - .../triggerconstant/TriggerConstant010.java | 1 - .../triggerconstant/TriggerConstant011.java | 1 - .../triggerconstant/TriggerConstant012.java | 1 - .../triggerconstant/TriggerConstant013.java | 1 - .../triggerconstant/TriggerConstant014.java | 1 - .../triggerconstant/TriggerConstant015.java | 1 - .../triggerconstant/TriggerConstant016.java | 1 - .../triggerconstant/TriggerConstant017.java | 1 - .../triggerconstant/TriggerConstant018.java | 1 - .../triggerconstant/TriggerConstant019.java | 1 - .../triggerconstant/TriggerConstant020.java | 1 - .../triggerconstant/TriggerConstant021.java | 1 - .../triggerconstant/TriggerConstant022.java | 1 - .../triggerconstant/TriggerConstant023.java | 1 - .../triggerconstant/TriggerConstant024.java | 1 - .../triggerconstant/TriggerConstant025.java | 1 - .../triggerconstant/TriggerConstant026.java | 1 - src/test/resources/testng.conf | 2 +- 44 files changed, 411 insertions(+), 118 deletions(-) create mode 100644 src/test/java/stest/tron/wallet/dailybuild/http/HttpTestConstantContract001.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/operationupdate/WalletTestMutiSign018.java diff --git a/src/test/java/stest/tron/wallet/common/client/utils/HttpMethed.java b/src/test/java/stest/tron/wallet/common/client/utils/HttpMethed.java index 99d6051e33d..52bc9b26868 100644 --- a/src/test/java/stest/tron/wallet/common/client/utils/HttpMethed.java +++ b/src/test/java/stest/tron/wallet/common/client/utils/HttpMethed.java @@ -8,7 +8,6 @@ import java.nio.charset.Charset; import java.util.HashMap; import java.util.Map; - import lombok.extern.slf4j.Slf4j; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; @@ -2116,4 +2115,56 @@ public static String str2hex(String str) { } return sb.toString().trim(); } + + + /** + * constructor. + */ + public static HttpResponse triggerConstantContract(String httpNode, byte[] ownerAddress, + String contractAddress, String functionSelector, String parameter) { + try { + final String requestUrl = "http://" + httpNode + "/wallet/triggerconstantcontract"; + JsonObject userBaseObj2 = new JsonObject(); + userBaseObj2.addProperty("owner_address", ByteArray.toHexString(ownerAddress)); + userBaseObj2.addProperty("contract_address", contractAddress); + userBaseObj2.addProperty("function_selector", functionSelector); + userBaseObj2.addProperty("parameter", parameter); + response = createConnect(requestUrl, userBaseObj2); + return response; + } catch (Exception e) { + e.printStackTrace(); + httppost.releaseConnection(); + return null; + } + } + + + /** + * constructor. + */ + public static HttpResponse clearABiGetTxid(String httpNode, byte[] ownerAddress, + String contractAddress, String fromKey) { + try { + final String requestUrl = "http://" + httpNode + "/wallet/clearabi"; + JsonObject userBaseObj2 = new JsonObject(); + userBaseObj2.addProperty("owner_address", ByteArray.toHexString(ownerAddress)); + userBaseObj2.addProperty("contract_address", contractAddress); + response = createConnect(requestUrl, userBaseObj2); + transactionString = EntityUtils.toString(response.getEntity()); + logger.info(transactionString); + + transactionSignString = gettransactionsign(httpNode, transactionString, fromKey); + + logger.info(transactionSignString); + response = broadcastTransaction(httpNode, transactionSignString); + + + } catch (Exception e) { + e.printStackTrace(); + httppost.releaseConnection(); + return null; + } + return response; + } + } diff --git a/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestConstantContract001.java b/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestConstantContract001.java new file mode 100644 index 00000000000..79f834d96b2 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestConstantContract001.java @@ -0,0 +1,165 @@ +package stest.tron.wallet.dailybuild.http; + +import static org.hamcrest.core.StringContains.containsString; + +import com.alibaba.fastjson.JSONObject; +import java.util.HashMap; +import lombok.extern.slf4j.Slf4j; +import org.apache.http.HttpResponse; +import org.junit.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.Test; +import org.tron.common.crypto.ECKey; +import org.tron.common.utils.ByteArray; +import org.tron.common.utils.Utils; +import stest.tron.wallet.common.client.Configuration; +import stest.tron.wallet.common.client.utils.HttpMethed; +import stest.tron.wallet.common.client.utils.PublicMethed; + +@Slf4j +public class HttpTestConstantContract001 { + + private final String testKey002 = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key1"); + private final byte[] fromAddress = PublicMethed.getFinalAddress(testKey002); + private JSONObject responseContent; + private HttpResponse response; + private String httpnode = Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list") + .get(0); + + ECKey ecKey2 = new ECKey(Utils.getRandom()); + byte[] assetOwnerAddress = ecKey2.getAddress(); + String assetOwnerKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + String contractAddress; + String abi; + Long amount = 2048000000L; + + String description = Configuration.getByPath("testng.conf") + .getString("defaultParameter.assetDescription"); + String url = Configuration.getByPath("testng.conf") + .getString("defaultParameter.assetUrl"); + private static final long now = System.currentTimeMillis(); + private static String name = "testAssetIssue002_" + Long.toString(now); + private static final long totalSupply = now; + private static String assetIssueId; + private static String contractName; + + + /** + * constructor. + */ + @Test(enabled = true, description = "Deploy smart contract by http") + public void test1DeployContract() { + PublicMethed.printAddress(assetOwnerKey); + HttpMethed.waitToProduceOneBlock(httpnode); + response = HttpMethed.sendCoin(httpnode, fromAddress, assetOwnerAddress, amount, testKey002); + Assert.assertTrue(HttpMethed.verificationResult(response)); + HttpMethed.waitToProduceOneBlock(httpnode); + + response = HttpMethed.getAccount(httpnode, assetOwnerAddress); + responseContent = HttpMethed.parseResponseContent(response); + HttpMethed.printJsonContent(responseContent); + + String filePath = "src/test/resources/soliditycode/TriggerConstant003.sol"; + contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + abi = retMap.get("abI").toString(); + + String txid = HttpMethed.deployContractGetTxid(httpnode, contractName, abi, code, 1000000L, + 1000000000L, 100, 11111111111111L, + 0L, null, 0L, assetOwnerAddress, assetOwnerKey); + + HttpMethed.waitToProduceOneBlock(httpnode); + logger.info(txid); + response = HttpMethed.getTransactionById(httpnode, txid); + responseContent = HttpMethed.parseResponseContent(response); + HttpMethed.printJsonContent(responseContent); + Assert.assertTrue(!responseContent.getString("contract_address").isEmpty()); + contractAddress = responseContent.getString("contract_address"); + + response = HttpMethed.getTransactionInfoById(httpnode, txid); + responseContent = HttpMethed.parseResponseContent(response); + String receiptString = responseContent.getString("receipt"); + Assert + .assertEquals(HttpMethed.parseStringContent(receiptString).getString("result"), "SUCCESS"); + } + + /** + * constructor. + */ + @Test(enabled = true, description = "Get contract by http") + public void test2GetContract() { + response = HttpMethed.getContract(httpnode, contractAddress); + responseContent = HttpMethed.parseResponseContent(response); + HttpMethed.printJsonContent(responseContent); + Assert.assertEquals(responseContent.getString("consume_user_resource_percent"), "100"); + Assert.assertEquals(responseContent.getString("contract_address"), contractAddress); + Assert.assertEquals(responseContent.getString("origin_address"), + ByteArray.toHexString(assetOwnerAddress)); + Assert + .assertThat(responseContent.getString("abi") + , containsString("testView")); + + Assert.assertEquals(responseContent.getString("origin_energy_limit"), "11111111111111"); + Assert.assertEquals(responseContent.getString("name"), contractName); + } + + /** + * constructor. + */ + @Test(enabled = true, description = "Trigger contract by http") + public void test3TriggerConstantContract() { + + HttpResponse httpResponse = HttpMethed + .triggerConstantContract(httpnode, assetOwnerAddress, contractAddress, + "testView()", + ""); + + responseContent = HttpMethed.parseResponseContent(httpResponse); + HttpMethed.printJsonContent(responseContent); + Assert.assertEquals(responseContent.getString("result"), "{\"result\":true}"); + Assert.assertEquals(responseContent.getString("constant_result"), + "[\"0000000000000000000000000000000000000000000000000000000000000001\"]"); + } + + /** + * constructor. + */ + @Test(enabled = true, description = "Trigger contract by http") + public void test4ClearABIContract() { + + HttpResponse httpResponse = HttpMethed + .clearABiGetTxid(httpnode, assetOwnerAddress, contractAddress, assetOwnerKey); + + responseContent = HttpMethed.parseResponseContent(httpResponse); + HttpMethed.printJsonContent(responseContent); + Assert.assertEquals(responseContent.getString("result"), "true"); + + } + + /** + * constructor. + */ + @Test(enabled = true, description = "Get contract by http") + public void test5GetContract() { + response = HttpMethed.getContract(httpnode, contractAddress); + responseContent = HttpMethed.parseResponseContent(response); + HttpMethed.printJsonContent(responseContent); + Assert.assertEquals(responseContent.getString("consume_user_resource_percent"), "100"); + Assert.assertEquals(responseContent.getString("contract_address"), contractAddress); + Assert.assertEquals(responseContent.getString("origin_address"), + ByteArray.toHexString(assetOwnerAddress)); + Assert.assertEquals(responseContent.getString("abi"), "{}"); + Assert.assertEquals(responseContent.getString("origin_energy_limit"), "11111111111111"); + Assert.assertEquals(responseContent.getString("name"), contractName); + } + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + HttpMethed.disConnect(); + } +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/operationupdate/WalletTestMutiSign018.java b/src/test/java/stest/tron/wallet/dailybuild/operationupdate/WalletTestMutiSign018.java new file mode 100644 index 00000000000..23fc3446630 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/operationupdate/WalletTestMutiSign018.java @@ -0,0 +1,188 @@ +package stest.tron.wallet.dailybuild.operationupdate; + +import com.google.protobuf.ByteString; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Optional; +import java.util.concurrent.TimeUnit; +import lombok.extern.slf4j.Slf4j; +import org.testng.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.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.Block; +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; +import stest.tron.wallet.common.client.utils.PublicMethedForMutiSign; + +@Slf4j +public class WalletTestMutiSign018 { + + private final String testKey002 = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key1"); + private final byte[] fromAddress = PublicMethed.getFinalAddress(testKey002); + + private long multiSignFee = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.multiSignFee"); + private long updateAccountPermissionFee = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.updateAccountPermissionFee"); + private final String operations = Configuration.getByPath("testng.conf") + .getString("defaultParameter.operations"); + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + ArrayList txidList = new ArrayList(); + + Optional infoById = null; + Long beforeTime; + Long afterTime; + Long beforeBlockNum; + Long afterBlockNum; + Block currentBlock; + Long currentBlockNum; + String[] permissionKeyString = new String[2]; + String[] ownerKeyString = new String[2]; + String accountPermissionJson = ""; + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] manager1Address = ecKey1.getAddress(); + String manager1Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + ECKey ecKey2 = new ECKey(Utils.getRandom()); + byte[] manager2Address = ecKey2.getAddress(); + String manager2Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + + ECKey ecKey3 = new ECKey(Utils.getRandom()); + byte[] ownerAddress = ecKey3.getAddress(); + String ownerKey = ByteArray.toHexString(ecKey3.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + } + + @Test(enabled = true, threadPoolSize = 1, invocationCount = 1) + public void testMutiSignForClearContractAbi() { + ecKey1 = new ECKey(Utils.getRandom()); + manager1Address = ecKey1.getAddress(); + manager1Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + ecKey2 = new ECKey(Utils.getRandom()); + manager2Address = ecKey2.getAddress(); + manager2Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + + ecKey3 = new ECKey(Utils.getRandom()); + ownerAddress = ecKey3.getAddress(); + ownerKey = ByteArray.toHexString(ecKey3.getPrivKeyBytes()); + PublicMethed.printAddress(ownerKey); + + long needcoin = updateAccountPermissionFee + multiSignFee * 4; + + Assert.assertTrue( + PublicMethed.sendcoin(ownerAddress, needcoin + 100000000L, fromAddress, testKey002, + blockingStubFull)); + Assert.assertTrue(PublicMethed + .freezeBalanceForReceiver(fromAddress, 1000000000, 0, 0, ByteString.copyFrom(ownerAddress), + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed + .freezeBalanceForReceiver(fromAddress, 1000000000, 0, 1, ByteString.copyFrom(ownerAddress), + testKey002, blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + Long balanceBefore = PublicMethed.queryAccount(ownerAddress, blockingStubFull) + .getBalance(); + logger.info("balanceBefore: " + balanceBefore); + + permissionKeyString[0] = manager1Key; + permissionKeyString[1] = manager2Key; + PublicMethed.waitProduceNextBlock(blockingStubFull); + ownerKeyString[0] = ownerKey; + ownerKeyString[1] = manager1Key; + accountPermissionJson = + "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" + + "{\"address\":\"" + PublicMethed.getAddressString(manager1Key) + "\",\"weight\":1}," + + "{\"address\":\"" + PublicMethed.getAddressString(ownerKey) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," + + "\"operations\":\"" + operations + "\"," + + "\"keys\":[" + + "{\"address\":\"" + PublicMethed.getAddressString(manager1Key) + "\",\"weight\":1}," + + "{\"address\":\"" + PublicMethed.getAddressString(manager2Key) + "\",\"weight\":1}" + + "]}]}"; + logger.info(accountPermissionJson); + PublicMethedForMutiSign.accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, + blockingStubFull, ownerKeyString); + + Long maxFeeLimit = 1000000000L; + String filePath = "src/test/resources/soliditycode/TriggerConstant004.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + byte[] contractAddress = PublicMethedForMutiSign.deployContract1(contractName, abi, code, + "", maxFeeLimit, + 0L, 100, null, ownerKey, ownerAddress, blockingStubFull, 2, permissionKeyString); + logger.info("address:" + Base58.encode58Check(contractAddress)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); + Assert.assertTrue(smartContract.getAbi().toString() != null); + Assert.assertTrue(PublicMethedForMutiSign + .clearContractABI(contractAddress, ownerAddress, ownerKey, + blockingStubFull, 2, permissionKeyString)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + Assert.assertTrue( + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, ownerAddress, blockingStubFull)); + Assert.assertTrue( + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, ownerAddress, blockingStubFull)); + } + + /** + * constructor. + */ + + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } +} \ No newline at end of file diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi001.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi001.java index 30bfad351a3..368278aaa38 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi001.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi001.java @@ -93,7 +93,6 @@ public void beforeClass() { @Test(enabled = true, description = "Clear a contract created by other account") public void testClearAbi() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi002.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi002.java index ba3bdca020a..3eff6970c1b 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi002.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi002.java @@ -89,7 +89,6 @@ public void beforeClass() { @Test(enabled = true, description = "Clear a contract with ABI created by itself") public void testClearAbi() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi003.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi003.java index f4100ebafdc..454d6f6c613 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi003.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi003.java @@ -89,7 +89,6 @@ public void beforeClass() { @Test(enabled = true, description = "Clear a contract without ABI") public void testClearAbi() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi004.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi004.java index 3c0b7f1f460..6a98b8c9a76 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi004.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi004.java @@ -86,7 +86,6 @@ public void beforeClass() { @Test(enabled = true, description = "Clear a account address") public void testClearAbi() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi005.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi005.java index fab5abcfdcb..c5f51b9e836 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi005.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi005.java @@ -93,7 +93,6 @@ public void beforeClass() { @Test(enabled = true, description = "clear a contract created by create2 (without ABI)") public void testClearAbi() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi006.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi006.java index 4f1c12f4ebc..d2a2a51c1a3 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi006.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi006.java @@ -88,7 +88,6 @@ public void beforeClass() { @Test(enabled = true, description = "Clear a uninitialized account") public void testClearAbi() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi007.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi007.java index 91622bd0ba9..317794543ce 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi007.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi007.java @@ -88,7 +88,6 @@ public void beforeClass() { @Test(enabled = true, description = "Clear a not meet the rules address") public void testClearAbi() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi008.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi008.java index a3e615d9a03..df75a2473b4 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi008.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi008.java @@ -90,7 +90,6 @@ public void beforeClass() { @Test(enabled = true, description = "Clear a contract with ABI created by itself," + "clear a contract by itself again") public void testClearAbi() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand001.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand001.java index fba69654406..d64354fb6d2 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand001.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand001.java @@ -89,7 +89,6 @@ public void beforeClass() { @Test(enabled = true, description = "Trigger old ShiftLeft ShiftRight") public void test1OldInstruction() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand002.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand002.java index 8f31615cfdf..eac053fb372 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand002.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand002.java @@ -89,7 +89,6 @@ public void beforeClass() { @Test(enabled = true, description = "OLd compiler compile shift instruction") public void test1Oldcompile() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); @@ -186,7 +185,6 @@ public void test1Oldcompile() { @Test(enabled = true, description = "New compiler compile shift instruction") public void test2Newcompile() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand003.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand003.java index 6b45dd8a862..ce1da2c0d00 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand003.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand003.java @@ -90,7 +90,6 @@ public void beforeClass() { @Test(enabled = true, description = "Trigger new ShiftLeft with displacement number too short ") public void test1ShiftLeft() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); @@ -179,11 +178,9 @@ public void test1ShiftLeft() { @Test(enabled = true, description = "Trigger new ShiftRight with displacement number too short ") public void test2ShiftRight() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull); @@ -257,11 +254,9 @@ public void test2ShiftRight() { @Test(enabled = true, description = "Trigger new ShiftRightSigned with displacement number too short ") public void test3ShiftRightSigned() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand004.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand004.java index d20fbdaf253..44bbd31ec3a 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand004.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand004.java @@ -92,11 +92,9 @@ public void beforeClass() { + "0x0000000000000000000000000000000000000000000000000000000000000001 and Displacement number" + "is 0x00") public void test1ShiftLeft() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); String filePath = "src/test/resources/soliditycode/ShiftCommand001.sol"; String contractName = "TestBitwiseShift"; HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); @@ -181,7 +179,6 @@ public void test1ShiftLeft() { + "0x0000000000000000000000000000000000000000000000000000000000000001 and Displacement number" + "is 0x01") public void test2ShiftLeft() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); @@ -264,11 +261,9 @@ public void test2ShiftLeft() { + "0x0000000000000000000000000000000000000000000000000000000000000001 and Displacement number" + "is 0xff") public void test3ShiftLeft() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -347,11 +342,9 @@ public void test3ShiftLeft() { + "0x0000000000000000000000000000000000000000000000000000000000000001 and Displacement number" + "is 0x0100") public void test4ShiftLeft() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -426,11 +419,9 @@ public void test4ShiftLeft() { + "0x0000000000000000000000000000000000000000000000000000000000000001 and Displacement number" + "is 0x0101") public void test5ShiftLeft() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull); @@ -504,11 +495,9 @@ public void test5ShiftLeft() { + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + "is 0x00") public void test6ShiftLeft() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull); @@ -582,9 +571,8 @@ public void test6ShiftLeft() { + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + "is 0x01") public void test7ShiftLeft() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); PublicMethed.waitProduceNextBlock(blockingStubFull); String filePath = "src/test/resources/soliditycode/ShiftCommand001.sol"; @@ -673,11 +661,9 @@ public void test7ShiftLeft() { + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + "is 0xff") public void test8ShiftLeft() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -753,13 +739,10 @@ public void test8ShiftLeft() { + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + "is 0x0100") public void test9ShiftLeft() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); Account info; - AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); @@ -834,9 +817,8 @@ public void test9ShiftLeft() { + "0x0000000000000000000000000000000000000000000000000000000000000000 and Displacement number" + "is 0x01") public void testShiftLeft10() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); PublicMethed.waitProduceNextBlock(blockingStubFull); Account info; @@ -913,11 +895,9 @@ public void testShiftLeft10() { + "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + "is 0x01") public void testShiftLeft11() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -992,7 +972,6 @@ public void testShiftLeft11() { + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + "is 0x0101") public void testShiftLeft12() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand005.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand005.java index 268715c8d98..492073f8739 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand005.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand005.java @@ -92,11 +92,9 @@ public void beforeClass() { + "0x0000000000000000000000000000000000000000000000000000000000000001 and Displacement number" + "is 0x00") public void test1ShiftRight() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); String filePath = "src/test/resources/soliditycode/ShiftCommand001.sol"; String contractName = "TestBitwiseShift"; HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); @@ -184,11 +182,9 @@ public void test1ShiftRight() { + "0x0000000000000000000000000000000000000000000000000000000000000001 and Displacement number" + "is 0x01") public void test2ShiftRight() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -263,11 +259,9 @@ public void test2ShiftRight() { + "0x8000000000000000000000000000000000000000000000000000000000000000 and Displacement number" + "is 0x01") public void test3ShiftRight() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -341,11 +335,9 @@ public void test3ShiftRight() { + "0x8000000000000000000000000000000000000000000000000000000000000000 and Displacement number" + "is 0xff") public void test4ShiftRight() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -424,11 +416,9 @@ public void test4ShiftRight() { + "0x8000000000000000000000000000000000000000000000000000000000000000 and Displacement number" + "is 0x0100") public void test5ShiftRight() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -504,11 +494,9 @@ public void test5ShiftRight() { + "0x8000000000000000000000000000000000000000000000000000000000000000 and Displacement number" + "is 0x0101") public void test6ShiftRight() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -584,11 +572,9 @@ public void test6ShiftRight() { + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + "is 0x00") public void test7ShiftRight() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -664,11 +650,9 @@ public void test7ShiftRight() { + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + "is 0x01") public void test8ShiftRight() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -746,7 +730,6 @@ public void test8ShiftRight() { + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + "is 0xff") public void test9ShiftRight() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); @@ -828,7 +811,6 @@ public void test9ShiftRight() { + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + "is 0x0100") public void testShiftRight10() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); @@ -908,11 +890,9 @@ public void testShiftRight10() { + "0x0000000000000000000000000000000000000000000000000000000000000000 and Displacement number" + "is 0x01") public void testShiftRight11() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); String filePath = "src/test/resources/soliditycode/ShiftCommand001.sol"; String contractName = "TestBitwiseShift"; HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); @@ -998,11 +978,9 @@ public void testShiftRight11() { + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + "is 0x0101") public void testShiftRight12() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); String filePath = "src/test/resources/soliditycode/TvmNewCommand043.sol"; String contractName = "TestBitwiseShift"; HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand006.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand006.java index aca1c0ac9b6..84f6fe290fd 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand006.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand006.java @@ -92,11 +92,9 @@ public void beforeClass() { + "0x0000000000000000000000000000000000000000000000000000000000000001 and Displacement number" + "is 0x00") public void test1ShiftRightSigned() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); String filePath = "src/test/resources/soliditycode/ShiftCommand001.sol"; String contractName = "TestBitwiseShift"; HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); @@ -181,7 +179,6 @@ public void test1ShiftRightSigned() { + "0x0000000000000000000000000000000000000000000000000000000000000001 and Displacement number" + "is 0x01") public void test2ShiftRightSigned() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); @@ -262,7 +259,6 @@ public void test2ShiftRightSigned() { + "0x8000000000000000000000000000000000000000000000000000000000000000 and Displacement number" + "is 0x01") public void test3ShiftRightSigned() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); @@ -342,7 +338,6 @@ public void test3ShiftRightSigned() { + "0x8000000000000000000000000000000000000000000000000000000000000000 and Displacement number" + "is 0xff") public void test4ShiftRightSigned() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); @@ -426,7 +421,6 @@ public void test4ShiftRightSigned() { + "0x8000000000000000000000000000000000000000000000000000000000000000 and Displacement number" + "is 0x0100") public void test5ShiftRightSigned() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); @@ -506,7 +500,6 @@ public void test5ShiftRightSigned() { + "0x8000000000000000000000000000000000000000000000000000000000000000 and Displacement number" + "is 0x0101") public void test6ShiftRightSigned() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); @@ -587,7 +580,6 @@ public void test6ShiftRightSigned() { + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + "is 0x00") public void test7ShiftRightSigned() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); @@ -672,11 +664,9 @@ public void test7ShiftRightSigned() { + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + "is 0x01") public void test8ShiftRightSigned() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -756,11 +746,9 @@ public void test8ShiftRightSigned() { + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + "is 0xff") public void test9ShiftRightSigned() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -840,11 +828,9 @@ public void test9ShiftRightSigned() { + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + "is 0x0100") public void testShiftRightSigned10() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -924,11 +910,9 @@ public void testShiftRightSigned10() { + "0x0000000000000000000000000000000000000000000000000000000000000000 and Displacement number" + "is 0x01") public void testShiftRightSigned11() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -1008,7 +992,6 @@ public void testShiftRightSigned11() { + "0x4000000000000000000000000000000000000000000000000000000000000000 and Displacement number" + "is 0xfe") public void testShiftRightSigned12() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); @@ -1091,7 +1074,6 @@ public void testShiftRightSigned12() { + "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + "is 0xf8") public void testShiftRightSigned13() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); @@ -1175,7 +1157,6 @@ public void testShiftRightSigned13() { + "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + "is 0xfe") public void testShiftRightSigned14() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); @@ -1256,7 +1237,6 @@ public void testShiftRightSigned14() { + "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + "is 0xff") public void testShiftRightSigned15() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); @@ -1339,11 +1319,9 @@ public void testShiftRightSigned15() { + "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + "is 0x0100") public void testShiftRightSigned16() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -1421,11 +1399,9 @@ public void testShiftRightSigned16() { + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + "is 0x0101") public void testShiftRightSigned17() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); String filePath = "src/test/resources/soliditycode/TvmNewCommand043.sol"; String contractName = "TestBitwiseShift"; HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); @@ -1514,11 +1490,9 @@ public void testShiftRightSigned17() { + "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + "is 0x0101") public void testShiftRightSigned18() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); String filePath = "src/test/resources/soliditycode/TvmNewCommand043.sol"; String contractName = "TestBitwiseShift"; HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant001.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant001.java index bb0317ee6a7..374c8142444 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant001.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant001.java @@ -90,7 +90,6 @@ public void beforeClass() { @Test(enabled = true, description = "TriggerConstantContract a payable function without ABI") public void testTriggerConstantContract() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant002.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant002.java index d04fc8d4a93..973d336bc49 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant002.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant002.java @@ -90,7 +90,6 @@ public void beforeClass() { @Test(enabled = true, description = "TriggerConstantContract a non-payable function without ABI") public void testTriggerConstantContract() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant003.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant003.java index 63474b61b33..3254e160e22 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant003.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant003.java @@ -90,7 +90,6 @@ public void beforeClass() { @Test(enabled = true, description = "TriggerConstantContract a view function without ABI") public void testTriggerConstantContract() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant004.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant004.java index e9ba6410e7e..9d680712b62 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant004.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant004.java @@ -90,7 +90,6 @@ public void beforeClass() { @Test(enabled = true, description = "TriggerConstantContract a pure function without ABI") public void testTriggerConstantContract() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant005.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant005.java index 7bcc2b92bd4..1fa72ed3f9e 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant005.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant005.java @@ -90,7 +90,6 @@ public void beforeClass() { @Test(enabled = true, description = "TriggerConstantContract a payable function with ABI") public void testTriggerConstantContract() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant006.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant006.java index 475a6cf7672..91f781de242 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant006.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant006.java @@ -90,7 +90,6 @@ public void beforeClass() { @Test(enabled = true, description = "TriggerConstantContract a non-payable function with ABI") public void testTriggerConstantContract() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant007.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant007.java index 6f60e8535cf..d66cade847e 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant007.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant007.java @@ -90,7 +90,6 @@ public void beforeClass() { @Test(enabled = true, description = "TriggerConstantContract a view function with ABI") public void testTriggerConstantContract() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant008.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant008.java index 0a2baa46408..a8ee51e7495 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant008.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant008.java @@ -90,7 +90,6 @@ public void beforeClass() { @Test(enabled = true, description = "TriggerConstantContract a pure function with ABI") public void testTriggerConstantContract() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant009.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant009.java index 3012e7ff698..f44619ac05a 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant009.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant009.java @@ -89,7 +89,6 @@ public void beforeClass() { @Test(enabled = true, description = "TriggerContract a payable function without ABI") public void testTriggerContract() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant010.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant010.java index ebf7924df23..b91f92e1db7 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant010.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant010.java @@ -89,7 +89,6 @@ public void beforeClass() { @Test(enabled = true, description = "TriggerContract a non-payable function without ABI") public void testTriggerContract() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant011.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant011.java index 0abef07bab9..4e334fe986a 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant011.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant011.java @@ -89,7 +89,6 @@ public void beforeClass() { @Test(enabled = true, description = "TriggerContract a view function without ABI") public void testTriggerContract() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant012.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant012.java index 72acf13386d..cef6e444b86 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant012.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant012.java @@ -89,7 +89,6 @@ public void beforeClass() { @Test(enabled = true, description = "TriggerContract a pure function without ABI") public void testTriggerContract() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant013.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant013.java index d2ce96c2fe3..036b76ecc84 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant013.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant013.java @@ -89,7 +89,6 @@ public void beforeClass() { @Test(enabled = true, description = "triggerContract a constant function created by create2") public void testTriggerContract() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant014.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant014.java index f2f0a0faa1a..a76f183f761 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant014.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant014.java @@ -90,7 +90,6 @@ public void beforeClass() { @Test(enabled = true, description = "TriggerContract a non-constant function created by create2") public void testTriggerContract() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant015.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant015.java index 4731bf53695..88a1b6a9715 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant015.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant015.java @@ -93,7 +93,6 @@ public void beforeClass() { @Test(enabled = true, description = "TriggerConstantContract a constant function created by create2") public void testTriggerConstantContract() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant016.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant016.java index e98745bb30d..9c2dc403cb0 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant016.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant016.java @@ -92,7 +92,6 @@ public void beforeClass() { @Test(enabled = true, description = "TriggerConstantContract a non-constant function created by create2") public void testTriggerConstantContract() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant017.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant017.java index 30b88200ad2..6b7adf8c732 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant017.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant017.java @@ -93,7 +93,6 @@ public void beforeClass() { @Test(enabled = true, description = "TriggerConstantContract a constant function which is " + "deployed with ABI, but cleared ABI later") public void testTriggerConstantContract() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant018.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant018.java index 8b2ccb15947..a96ab14537b 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant018.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant018.java @@ -90,7 +90,6 @@ public void beforeClass() { @Test(enabled = true, description = "TriggerContract a pure function with ABI") public void testTriggerContract() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant019.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant019.java index 82c48a2715c..55d101966f4 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant019.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant019.java @@ -89,7 +89,6 @@ public void beforeClass() { @Test(enabled = true, description = "TriggerContract a payable function with ABI") public void testTriggerContract() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant020.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant020.java index a91d7f930a8..d4cfe208e4a 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant020.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant020.java @@ -89,7 +89,6 @@ public void beforeClass() { @Test(enabled = true, description = "TriggerContract a non-payable function with ABI") public void testTriggerContract() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant021.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant021.java index c83423ef2ea..fd3b68fcb6e 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant021.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant021.java @@ -90,7 +90,6 @@ public void beforeClass() { @Test(enabled = true, description = "TriggerContract a view function with ABI") public void testTriggerContract() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant022.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant022.java index a20c69316ae..29fa1076afb 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant022.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant022.java @@ -91,7 +91,6 @@ public void beforeClass() { @Test(enabled = true, description = "TriggerContract a non-payable function " + "with ABI(constant ABI)") public void testTriggerContract() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant023.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant023.java index 55b93b81b0c..18627c37dbd 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant023.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant023.java @@ -91,7 +91,6 @@ public void beforeClass() { @Test(enabled = true, description = "TriggerConstantContract a non-payable function with" + " ABI(constant ABI )") public void testTriggerConstantContract() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant024.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant024.java index 02669c90f95..861bbcddd9e 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant024.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant024.java @@ -92,7 +92,6 @@ public void beforeClass() { @Test(enabled = true, description = "TriggerConstantContract a view method with ABI ,method has " + "revert()") public void testTriggerConstantContract() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant025.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant025.java index b4b8cfffa97..3aed0161027 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant025.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant025.java @@ -92,7 +92,6 @@ public void beforeClass() { @Test(enabled = true, description = "TriggerContract a view method with ABI ,method has " + "revert()") public void testTriggerContract() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant026.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant026.java index 70d357f622c..bb4642cc602 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant026.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant026.java @@ -93,7 +93,6 @@ public void beforeClass() { @Test(enabled = true, description = "TriggerConstantContract a view method without ABI,method has" + "revert()") public void testTriggerConstantContract() { - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); diff --git a/src/test/resources/testng.conf b/src/test/resources/testng.conf index 6979508212c..d77bc1cdf90 100644 --- a/src/test/resources/testng.conf +++ b/src/test/resources/testng.conf @@ -141,7 +141,7 @@ defaultParameter = { httpConnectionTimeout = 2000 httpSoTimeout = 2000 createWitnessAmount = 9999000000 - operations = 7fff1fc0037e0000000000000000000000000000000000000000000000000000 + operations = 7fff1fc0037e0100000000000000000000000000000000000000000000000000 solidityCompilerVersion = "v5" solidityCompile = "solcDIR/solc" } From 9038522c00b7393e1beacc5f2921c95c1d7aca62 Mon Sep 17 00:00:00 2001 From: xiechang33 <354035097@qq.com> Date: Fri, 10 May 2019 12:09:59 +0800 Subject: [PATCH 05/90] add tvm stest --- .../transferfailed/TransferFailed001.java | 596 ++++++++++++++ .../transferfailed/TransferFailed002.java | 585 ++++++++++++++ .../transferfailed/TransferFailed003.java | 726 ++++++++++++++++++ .../transferfailed/TransferFailed004.java | 279 +++++++ .../soliditycode/TransferFailed001.sol | 70 ++ 5 files changed, 2256 insertions(+) create mode 100644 src/test/java/stest/tron/wallet/dailybuild/transferfailed/TransferFailed001.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/transferfailed/TransferFailed002.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/transferfailed/TransferFailed003.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/transferfailed/TransferFailed004.java create mode 100644 src/test/resources/soliditycode/TransferFailed001.sol diff --git a/src/test/java/stest/tron/wallet/dailybuild/transferfailed/TransferFailed001.java b/src/test/java/stest/tron/wallet/dailybuild/transferfailed/TransferFailed001.java new file mode 100644 index 00000000000..e7a2146939c --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/transferfailed/TransferFailed001.java @@ -0,0 +1,596 @@ +package stest.tron.wallet.dailybuild.transferfailed; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +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.api.WalletSolidityGrpc; +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.Transaction.Result.contractResult; +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 TransferFailed001 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + + @Test(enabled = true, description = "Transfer balance enough") + public void test1TransferEnough() { + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; + String contractName = "EnergyOfTransferFailedTest"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractAddress, 3000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + String num = "1"; + txid = PublicMethed.triggerContract(contractAddress, + "testTransferTrxInsufficientBalance(uint256)", num, false, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + Optional infoById = null; + PublicMethed.waitProduceNextBlock(blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull1); + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull1); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee - 1 == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + + + } + + + @Test(enabled = true, description = "Transfer trx insufficient balance") + public void test2TransferTrxInsufficientBalance() { + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; + String contractName = "EnergyOfTransferFailedTest"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + String num = "1"; + txid = PublicMethed.triggerContract(contractAddress, + "testTransferTrxInsufficientBalance(uint256)", num, false, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + Optional infoById = null; + PublicMethed.waitProduceNextBlock(blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull1); + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull1); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + logger.info("infoById:" + infoById); + Assert.assertTrue(infoById.get().getResultValue() == 1); + Assert.assertEquals(contractResult.REVERT, infoById.get().getReceipt().getResult()); + Assert.assertEquals( + "REVERT opcode executed", + ByteArray.toStr(infoById.get().getResMessage().toByteArray())); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Assert.assertNotEquals(10000000, energyUsageTotal); + + + } + + + @Test(enabled = true, description = "Transfer trx nonexistent target") + public void test3TransferTrxNonexistentTarget() { + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; + String contractName = "EnergyOfTransferFailedTest"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractAddress, 1000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + ECKey ecKey2 = new ECKey(Utils.getRandom()); + byte[] nonexistentAddress = ecKey2.getAddress(); + String txid = ""; + String num = "1" + ",\"" + Base58.encode58Check(nonexistentAddress) + "\""; + + txid = PublicMethed.triggerContract(contractAddress, + "testTransferTrxNonexistentTarget(uint256,address)", num, false, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + Optional infoById = null; + PublicMethed.waitProduceNextBlock(blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull1); + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + logger.info("infobyid : --- " + infoById); + + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull1); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 1); + Assert.assertEquals(contractResult.TRANSFER_FAILED, infoById.get().getReceipt().getResult()); + Assert.assertEquals( + "transfer trx failed: Validate InternalTransfer error, no ToAccount." + + " And not allowed to create account in smart contract.", + ByteArray.toStr(infoById.get().getResMessage().toByteArray())); + + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Assert.assertNotEquals(10000000, energyUsageTotal); + + + } + + + @Test(enabled = true, description = "Transfer trx to myself") + public void test4TransferTrxSelf() { + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; + String contractName = "EnergyOfTransferFailedTest"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractAddress, 1000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + String num = "1"; + + txid = PublicMethed.triggerContract(contractAddress, + "testTransferTrxSelf(uint256)", num, false, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + Optional infoById = null; + PublicMethed.waitProduceNextBlock(blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull1); + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + logger.info("infobyid : --- " + infoById); + + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull1); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 1); + Assert.assertEquals(contractResult.TRANSFER_FAILED, infoById.get().getReceipt().getResult()); + Assert.assertEquals( + "transfer trx failed: Cannot transfer trx to yourself.", + ByteArray.toStr(infoById.get().getResMessage().toByteArray())); + + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Assert.assertNotEquals(10000000, energyUsageTotal); + + + } + + + @Test(enabled = true, description = "Transfer trx nonexistent target and insufficient balance") + public void test5TransferTrxNonexistentTarget() { + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; + String contractName = "EnergyOfTransferFailedTest"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractAddress, 1000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + ECKey ecKey2 = new ECKey(Utils.getRandom()); + byte[] nonexistentAddress = ecKey2.getAddress(); + String txid = ""; + String num = "10000000" + ",\"" + Base58.encode58Check(nonexistentAddress) + "\""; + + txid = PublicMethed.triggerContract(contractAddress, + "testTransferTrxNonexistentTarget(uint256,address)", num, false, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + Optional infoById = null; + PublicMethed.waitProduceNextBlock(blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull1); + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + logger.info("infobyid : --- " + infoById); + + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull1); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 1); + Assert.assertEquals(contractResult.REVERT, infoById.get().getReceipt().getResult()); + Assert.assertEquals( + "REVERT opcode executed", + ByteArray.toStr(infoById.get().getResMessage().toByteArray())); + + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Assert.assertNotEquals(10000000, energyUsageTotal); + + + } + + + @Test(enabled = true, description = "Transfer trx to myself and insufficient balance") + public void test6TransferTrxSelf() { + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; + String contractName = "EnergyOfTransferFailedTest"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractAddress, 1000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + ECKey ecKey2 = new ECKey(Utils.getRandom()); + String txid = ""; + String num = "1000000000"; + + txid = PublicMethed.triggerContract(contractAddress, + "testTransferTrxSelf(uint256)", num, false, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + Optional infoById = null; + PublicMethed.waitProduceNextBlock(blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull1); + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + logger.info("infobyid : --- " + infoById); + + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull1); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 1); + Assert.assertEquals(contractResult.REVERT, infoById.get().getReceipt().getResult()); + Assert.assertEquals( + "REVERT opcode executed", + ByteArray.toStr(infoById.get().getResMessage().toByteArray())); + + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Assert.assertNotEquals(10000000, energyUsageTotal); + + + } + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/transferfailed/TransferFailed002.java b/src/test/java/stest/tron/wallet/dailybuild/transferfailed/TransferFailed002.java new file mode 100644 index 00000000000..69c469ba3e8 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/transferfailed/TransferFailed002.java @@ -0,0 +1,585 @@ +package stest.tron.wallet.dailybuild.transferfailed; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +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.api.WalletSolidityGrpc; +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.Transaction.Result.contractResult; +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 TransferFailed002 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + + @Test(enabled = true, description = "Send balance enough") + public void test1SendEnough() { + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; + String contractName = "EnergyOfTransferFailedTest"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractAddress, 3000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + String num = "1"; + txid = PublicMethed.triggerContract(contractAddress, + "testSendTrxInsufficientBalance(uint256)", num, false, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + Optional infoById = null; + PublicMethed.waitProduceNextBlock(blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull1); + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull1); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + logger.info("infoById:" + infoById); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee - 1 == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + + + } + + + @Test(enabled = true, description = "Send balance not enough") + public void test2SendNotEnough() { + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 100000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; + String contractName = "EnergyOfTransferFailedTest"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + String num = "1"; + txid = PublicMethed.triggerContract(contractAddress, + "testSendTrxInsufficientBalance(uint256)", num, false, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + Optional infoById = null; + PublicMethed.waitProduceNextBlock(blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull1); + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull1); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + logger.info("infoById:" + infoById); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Assert.assertNotEquals(10000000, energyUsageTotal); + + + } + + + @Test(enabled = true, description = "Send trx nonexistent target") + public void test3SendTrxNonexistentTarget() { + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; + String contractName = "EnergyOfTransferFailedTest"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractAddress, 1000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + ECKey ecKey2 = new ECKey(Utils.getRandom()); + byte[] nonexistentAddress = ecKey2.getAddress(); + String txid = ""; + String num = "1" + ",\"" + Base58.encode58Check(nonexistentAddress) + "\""; + + txid = PublicMethed.triggerContract(contractAddress, + "testSendTrxNonexistentTarget(uint256,address)", num, false, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + Optional infoById = null; + PublicMethed.waitProduceNextBlock(blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull1); + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + logger.info("infobyid : --- " + infoById); + + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull1); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 1); + Assert.assertEquals(contractResult.TRANSFER_FAILED, infoById.get().getReceipt().getResult()); + Assert.assertEquals( + "transfer trx failed: Validate InternalTransfer error, no ToAccount." + + " And not allowed to create account in smart contract.", + ByteArray.toStr(infoById.get().getResMessage().toByteArray())); + + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Assert.assertNotEquals(10000000, energyUsageTotal); + + + } + + + @Test(enabled = true, description = "Send trx self") + public void test4SendTrxSelf() { + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; + String contractName = "EnergyOfTransferFailedTest"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractAddress, 1000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + String num = "1"; + txid = PublicMethed.triggerContract(contractAddress, + "testSendTrxSelf(uint256)", num, false, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + Optional infoById = null; + PublicMethed.waitProduceNextBlock(blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull1); + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + logger.info("infobyid : --- " + infoById); + + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull1); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 1); + Assert.assertEquals(contractResult.TRANSFER_FAILED, infoById.get().getReceipt().getResult()); + Assert.assertEquals( + "transfer trx failed: Cannot transfer trx to yourself.", + ByteArray.toStr(infoById.get().getResMessage().toByteArray())); + + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Assert.assertNotEquals(10000000, energyUsageTotal); + Assert.assertNotEquals(10000000, energyUsageTotal); + + + } + + + @Test(enabled = true, description = "Send trx nonexistent target and balance not enough") + public void test5SendTrxNonexistentTarget() { + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; + String contractName = "EnergyOfTransferFailedTest"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractAddress, 1000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + ECKey ecKey2 = new ECKey(Utils.getRandom()); + byte[] nonexistentAddress = ecKey2.getAddress(); + String txid = ""; + + String num = "100000000" + ",\"" + Base58.encode58Check(contractExcAddress) + "\""; + + txid = PublicMethed.triggerContract(contractAddress, + "testSendTrxNonexistentTarget(uint256,address)", num, false, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + Optional infoById = null; + PublicMethed.waitProduceNextBlock(blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull1); + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + logger.info("infobyid : --- " + infoById); + + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull1); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Assert.assertNotEquals(10000000, energyUsageTotal); + + } + + + @Test(enabled = true, description = "Send trx self and balance not enough") + public void test6SendTrxSelf() { + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; + String contractName = "EnergyOfTransferFailedTest"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractAddress, 1000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + ECKey ecKey2 = new ECKey(Utils.getRandom()); + String txid = ""; + + String num = "1000000000"; + + txid = PublicMethed.triggerContract(contractAddress, + "testSendTrxSelf(uint256)", num, false, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + Optional infoById = null; + PublicMethed.waitProduceNextBlock(blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull1); + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + logger.info("infobyid : --- " + infoById); + + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull1); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Assert.assertNotEquals(10000000, energyUsageTotal); + + + } + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/transferfailed/TransferFailed003.java b/src/test/java/stest/tron/wallet/dailybuild/transferfailed/TransferFailed003.java new file mode 100644 index 00000000000..41f96ab3cd2 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/transferfailed/TransferFailed003.java @@ -0,0 +1,726 @@ +package stest.tron.wallet.dailybuild.transferfailed; + +import com.google.protobuf.ByteString; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +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.api.WalletSolidityGrpc; +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.Transaction.Result.contractResult; +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 TransferFailed003 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + private static ByteString assetAccountId = null; + private static final long now = System.currentTimeMillis(); + private static String tokenName = "testAssetIssue_" + Long.toString(now); + private static final long TotalSupply = 10000000L; + + String description = Configuration.getByPath("testng.conf") + .getString("defaultParameter.assetDescription"); + String url = Configuration.getByPath("testng.conf") + .getString("defaultParameter.assetUrl"); + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + + @Test(enabled = true, description = "TransferToken enough tokenBalance") + public void test1TransferTokenEnough() { + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 3100_000_000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + long start = System.currentTimeMillis() + 2000; + long end = System.currentTimeMillis() + 1000000000; + + //Create a new AssetIssue success. + Assert + .assertTrue(PublicMethed.createAssetIssue(contractExcAddress, tokenName, TotalSupply, 1, + 10000, start, end, 1, description, url, 100000L, + 100000L, 1L, 1L, contractExcKey, blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + assetAccountId = PublicMethed.queryAccount(contractExcAddress, blockingStubFull) + .getAssetIssuedID(); + + String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; + String contractName = "EnergyOfTransferFailedTest"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed.transferAsset(contractAddress, + assetAccountId.toByteArray(), 100L, contractExcAddress, contractExcKey, + blockingStubFull)); + + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long testNetAccountCountBefore = PublicMethed + .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long contractAccountCountBefore = PublicMethed + .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + logger.info("testNetAccountCountBefore:" + testNetAccountCountBefore); + logger.info("contractAccountCountBefore:" + contractAccountCountBefore); + String txid = ""; + String num = "1" + ",\"" + assetAccountId.toStringUtf8() + "\""; + txid = PublicMethed.triggerContract(contractAddress, + "testTransferTokenInsufficientBalance(uint256,trcToken)", num, false, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + Optional infoById = null; + PublicMethed.waitProduceNextBlock(blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull1); + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull1); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + Long testNetAccountCountAfter = PublicMethed + .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long contractAccountCountAfter = PublicMethed + .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + logger.info("testNetAccountCountAfter:" + testNetAccountCountAfter); + logger.info("contractAccountCountAfter:" + contractAccountCountAfter); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(testNetAccountCountBefore + 1 == testNetAccountCountAfter); + Assert.assertTrue(contractAccountCountBefore - 1 == contractAccountCountAfter); + + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + + + } + + @Test(enabled = true, description = "TransferToken insufficient tokenBalance") + public void test2TransferTokenNotEnough() { + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 100_000_000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long testNetAccountCountBefore = PublicMethed + .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long contractAccountCountBefore = PublicMethed + .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + logger.info("testNetAccountCountBefore:" + testNetAccountCountBefore); + logger.info("contractAccountCountBefore:" + contractAccountCountBefore); + String txid = ""; + String num = "1000" + ",\"" + assetAccountId.toStringUtf8() + "\""; + txid = PublicMethed.triggerContract(contractAddress, + "testTransferTokenInsufficientBalance(uint256,trcToken)", num, false, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + Optional infoById = null; + PublicMethed.waitProduceNextBlock(blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull1); + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull1); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + Long testNetAccountCountAfter = PublicMethed + .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long contractAccountCountAfter = PublicMethed + .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + logger.info("testNetAccountCountAfter:" + testNetAccountCountAfter); + logger.info("contractAccountCountAfter:" + contractAccountCountAfter); + logger.info("infoById:" + infoById); + Assert.assertTrue(infoById.get().getResultValue() == 1); + Assert.assertEquals(contractResult.REVERT, infoById.get().getReceipt().getResult()); + Assert.assertEquals( + "REVERT opcode executed", + ByteArray.toStr(infoById.get().getResMessage().toByteArray())); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertEquals(testNetAccountCountBefore, testNetAccountCountAfter); + Assert.assertEquals(contractAccountCountBefore, contractAccountCountAfter); + + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Assert.assertNotEquals(10000000, energyUsageTotal); + + } + + + @Test(enabled = true, description = "TransferToken to nonexistent target") + public void test3TransferTokenNonexistentTarget() { + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 10000_000_000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long testNetAccountCountBefore = PublicMethed + .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long contractAccountCountBefore = PublicMethed + .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + logger.info("testNetAccountCountBefore:" + testNetAccountCountBefore); + logger.info("contractAccountCountBefore:" + contractAccountCountBefore); + String txid = ""; + ECKey ecKey2 = new ECKey(Utils.getRandom()); + byte[] nonexistentAddress = ecKey2.getAddress(); + String num = + "\"1" + "\",\"" + Base58.encode58Check(nonexistentAddress) + "\",\"" + assetAccountId + .toStringUtf8() + "\""; + txid = PublicMethed.triggerContract(contractAddress, + "testTransferTokenNonexistentTarget(uint256,address,trcToken)", num, false, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + Optional infoById = null; + PublicMethed.waitProduceNextBlock(blockingStubFull); + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + logger.info("infoById:" + infoById); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull1); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + Long testNetAccountCountAfter = PublicMethed + .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long contractAccountCountAfter = PublicMethed + .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + logger.info("testNetAccountCountAfter:" + testNetAccountCountAfter); + logger.info("contractAccountCountAfter:" + contractAccountCountAfter); + + Assert.assertTrue(infoById.get().getResultValue() == 1); + Assert.assertEquals(contractResult.TRANSFER_FAILED, infoById.get().getReceipt().getResult()); + Assert.assertEquals( + "transfer trc10 failed: Validate InternalTransfer error, no ToAccount." + + " And not allowed to create account in smart contract.", + ByteArray.toStr(infoById.get().getResMessage().toByteArray())); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertEquals(testNetAccountCountBefore, testNetAccountCountAfter); + Assert.assertEquals(contractAccountCountBefore, contractAccountCountAfter); + + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Assert.assertNotEquals(10000000, energyUsageTotal); + + + } + + + @Test(enabled = true, description = "TransferToken to myself") + public void test4TransferTokenSelf() { + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 100_000_000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long testNetAccountCountBefore = PublicMethed + .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long contractAccountCountBefore = PublicMethed + .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + logger.info("testNetAccountCountBefore:" + testNetAccountCountBefore); + logger.info("contractAccountCountBefore:" + contractAccountCountBefore); + String txid = ""; + String num = "1" + ",\"" + assetAccountId.toStringUtf8() + "\""; + txid = PublicMethed.triggerContract(contractAddress, + "testTransferTokenSelf(uint256,trcToken)", num, false, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + Optional infoById = null; + PublicMethed.waitProduceNextBlock(blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull1); + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + logger.info("infoById:" + infoById); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull1); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + Long testNetAccountCountAfter = PublicMethed + .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long contractAccountCountAfter = PublicMethed + .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + logger.info("testNetAccountCountAfter:" + testNetAccountCountAfter); + logger.info("contractAccountCountAfter:" + contractAccountCountAfter); + + Assert.assertTrue(infoById.get().getResultValue() == 1); + Assert.assertEquals(contractResult.TRANSFER_FAILED, infoById.get().getReceipt().getResult()); + Assert.assertEquals( + "transfer trc10 failed: Cannot transfer asset to yourself.", + ByteArray.toStr(infoById.get().getResMessage().toByteArray())); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertEquals(testNetAccountCountBefore, testNetAccountCountAfter); + Assert.assertEquals(contractAccountCountBefore, contractAccountCountAfter); + + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Assert.assertNotEquals(10000000, energyUsageTotal); + + + } + + + @Test(enabled = true, description = "TransferToken notexist tokenID ") + public void test5TransferTokenNotexist() { + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 100_000_000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long testNetAccountCountBefore = PublicMethed + .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long contractAccountCountBefore = PublicMethed + .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + logger.info("testNetAccountCountBefore:" + testNetAccountCountBefore); + logger.info("contractAccountCountBefore:" + contractAccountCountBefore); + String txid = ""; + String fakeassetAccountId = Long.toString(0L); + + String num = "1" + ",\"" + fakeassetAccountId + "\""; + txid = PublicMethed.triggerContract(contractAddress, + "testTransferTokenInsufficientBalance(uint256,trcToken)", num, false, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + Optional infoById = null; + PublicMethed.waitProduceNextBlock(blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull1); + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + logger.info("infoById:" + infoById); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull1); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + Long testNetAccountCountAfter = PublicMethed + .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long contractAccountCountAfter = PublicMethed + .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + logger.info("testNetAccountCountAfter:" + testNetAccountCountAfter); + logger.info("contractAccountCountAfter:" + contractAccountCountAfter); + + Assert.assertTrue(infoById.get().getResultValue() == 1); + Assert.assertEquals(contractResult.REVERT, infoById.get().getReceipt().getResult()); + Assert.assertEquals( + "REVERT opcode executed", + ByteArray.toStr(infoById.get().getResMessage().toByteArray())); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertEquals(testNetAccountCountBefore, testNetAccountCountAfter); + Assert.assertEquals(contractAccountCountBefore, contractAccountCountAfter); + + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + + + } + + + @Test(enabled = true, description = "TransferToken to nonexistent target and " + + "insufficient tokenBalance") + public void test7TransferTokenNonexistentTarget() { + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 10000_000_000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long testNetAccountCountBefore = PublicMethed + .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long contractAccountCountBefore = PublicMethed + .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + logger.info("testNetAccountCountBefore:" + testNetAccountCountBefore); + logger.info("contractAccountCountBefore:" + contractAccountCountBefore); + String txid = ""; + ECKey ecKey2 = new ECKey(Utils.getRandom()); + byte[] nonexistentAddress = ecKey2.getAddress(); + String num = + "\"100000000000" + "\",\"" + Base58.encode58Check(nonexistentAddress) + "\",\"" + + assetAccountId + .toStringUtf8() + "\""; + txid = PublicMethed.triggerContract(contractAddress, + "testTransferTokenNonexistentTarget(uint256,address,trcToken)", num, false, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + Optional infoById = null; + PublicMethed.waitProduceNextBlock(blockingStubFull); + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + logger.info("infoById:" + infoById); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull1); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + Long testNetAccountCountAfter = PublicMethed + .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long contractAccountCountAfter = PublicMethed + .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + logger.info("testNetAccountCountAfter:" + testNetAccountCountAfter); + logger.info("contractAccountCountAfter:" + contractAccountCountAfter); + + Assert.assertTrue(infoById.get().getResultValue() == 1); + Assert.assertEquals(contractResult.REVERT, infoById.get().getReceipt().getResult()); + Assert.assertEquals( + "REVERT opcode executed", + ByteArray.toStr(infoById.get().getResMessage().toByteArray())); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertEquals(testNetAccountCountBefore, testNetAccountCountAfter); + Assert.assertEquals(contractAccountCountBefore, contractAccountCountAfter); + + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Assert.assertNotEquals(10000000, energyUsageTotal); + + + } + + + @Test(enabled = true, description = "TransferToken to myself and insufficient tokenBalance") + public void test8TransferTokenSelf() { + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 100_000_000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long testNetAccountCountBefore = PublicMethed + .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long contractAccountCountBefore = PublicMethed + .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + logger.info("testNetAccountCountBefore:" + testNetAccountCountBefore); + logger.info("contractAccountCountBefore:" + contractAccountCountBefore); + String txid = ""; + String num = "1000000000000000" + ",\"" + assetAccountId.toStringUtf8() + "\""; + txid = PublicMethed.triggerContract(contractAddress, + "testTransferTokenSelf(uint256,trcToken)", num, false, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + Optional infoById = null; + PublicMethed.waitProduceNextBlock(blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull1); + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + logger.info("infoById:" + infoById); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull1); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + Long testNetAccountCountAfter = PublicMethed + .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long contractAccountCountAfter = PublicMethed + .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + logger.info("testNetAccountCountAfter:" + testNetAccountCountAfter); + logger.info("contractAccountCountAfter:" + contractAccountCountAfter); + + Assert.assertTrue(infoById.get().getResultValue() == 1); + Assert.assertEquals(contractResult.REVERT, infoById.get().getReceipt().getResult()); + Assert.assertEquals( + "REVERT opcode executed", + ByteArray.toStr(infoById.get().getResMessage().toByteArray())); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertEquals(testNetAccountCountBefore, testNetAccountCountAfter); + Assert.assertEquals(contractAccountCountBefore, contractAccountCountAfter); + + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + + Assert.assertNotEquals(10000000, energyUsageTotal); + + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/transferfailed/TransferFailed004.java b/src/test/java/stest/tron/wallet/dailybuild/transferfailed/TransferFailed004.java new file mode 100644 index 00000000000..8b7dc290c0f --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/transferfailed/TransferFailed004.java @@ -0,0 +1,279 @@ +package stest.tron.wallet.dailybuild.transferfailed; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +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.api.WalletSolidityGrpc; +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.Transaction.Result.contractResult; +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 TransferFailed004 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + + @Test(enabled = true, description = "Suicide existent target") + public void test1SuicideExistentTarget() { + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; + String contractName = "EnergyOfTransferFailedTest"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractAddress, 3000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + ECKey ecKey2 = new ECKey(Utils.getRandom()); + byte[] existentAddress = ecKey2.getAddress(); + Assert.assertTrue(PublicMethed + .sendcoin(existentAddress, 1000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + String txid = ""; + String num = "\"" + Base58.encode58Check(existentAddress) + "\""; + txid = PublicMethed.triggerContract(contractAddress, + "testSuicideNonexistentTarget(address)", num, false, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + Optional infoById = null; + PublicMethed.waitProduceNextBlock(blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull1); + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull1); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + Account contractafter = PublicMethed.queryAccount(contractAddress, blockingStubFull1); + long contractBalance = contractafter.getBalance(); + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertEquals(contractBalance, 0); + + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + + + } + + + @Test(enabled = true, description = "Suicide nonexistent target") + public void test2SuicideNonexistentTarget() { + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; + String contractName = "EnergyOfTransferFailedTest"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractAddress, 1000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + ECKey ecKey2 = new ECKey(Utils.getRandom()); + byte[] nonexistentAddress = ecKey2.getAddress(); + String txid = ""; + String num = "\"" + Base58.encode58Check(nonexistentAddress) + "\""; + + txid = PublicMethed.triggerContract(contractAddress, + "testSuicideNonexistentTarget(address)", num, false, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + Optional infoById = null; + PublicMethed.waitProduceNextBlock(blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull1); + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + logger.info("infobyid : --- " + infoById); + + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull1); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 1); + Assert.assertEquals(contractResult.TRANSFER_FAILED, infoById.get().getReceipt().getResult()); + Assert.assertEquals( + "transfer all token or transfer all trx failed in suicide: " + + "Validate InternalTransfer error, no ToAccount. And not allowed " + + "to create account in smart contract.", + ByteArray.toStr(infoById.get().getResMessage().toByteArray())); + + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Assert.assertNotEquals(10000000, energyUsageTotal); + + + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} diff --git a/src/test/resources/soliditycode/TransferFailed001.sol b/src/test/resources/soliditycode/TransferFailed001.sol new file mode 100644 index 00000000000..9d93d196c05 --- /dev/null +++ b/src/test/resources/soliditycode/TransferFailed001.sol @@ -0,0 +1,70 @@ +contract EnergyOfTransferFailedTest { + constructor() payable public { + + } + // InsufficientBalance + function testTransferTrxInsufficientBalance(uint256 i) payable public{ + msg.sender.transfer(i); + } + + function testSendTrxInsufficientBalance(uint256 i) payable public{ + msg.sender.send(i); + } + + function testTransferTokenInsufficientBalance(uint256 i,trcToken tokenId) payable public{ + msg.sender.transferToken(i, tokenId); + } + + function testCallTrxInsufficientBalance(uint256 i,address payable caller) public { + caller.call.value(i)(abi.encodeWithSignature("test()")); + } + + function testCreateTrxInsufficientBalance(uint256 i) payable public { + (new Caller).value(i)(); + } + + // NonexistentTarget + + function testSendTrxNonexistentTarget(uint256 i,address payable nonexistentTarget) payable public { + nonexistentTarget.send(i); + } + + function testTransferTrxNonexistentTarget(uint256 i,address payable nonexistentTarget) payable public { + nonexistentTarget.transfer(i); + } + + function testTransferTokenNonexistentTarget(uint256 i,address payable nonexistentTarget, trcToken tokenId) payable public { + nonexistentTarget.transferToken(i, tokenId); + } + + function testCallTrxNonexistentTarget(uint256 i,address payable nonexistentTarget) payable public { + nonexistentTarget.call.value(i)(abi.encodeWithSignature("test()")); + } + + function testSuicideNonexistentTarget(address payable nonexistentTarget) payable public { + selfdestruct(nonexistentTarget); + } + + // target is self + function testTransferTrxSelf(uint256 i) payable public{ + address payable self = address(uint160(address(this))); + self.transfer(i); + } + + function testSendTrxSelf(uint256 i) payable public{ + address payable self = address(uint160(address(this))); + self.send(i); + } + + function testTransferTokenSelf(uint256 i,trcToken tokenId) payable public{ + address payable self = address(uint160(address(this))); + self.transferToken(i, tokenId); + } +} + + + +contract Caller { + constructor() payable public {} + function test() payable public {} +} \ No newline at end of file From da4317045c9ee136e85645dad0bfa1ba806b8983 Mon Sep 17 00:00:00 2001 From: wangming Date: Fri, 10 May 2019 14:54:04 +0800 Subject: [PATCH 06/90] add TransferFailed 005-007 --- .../soliditycode/TransferFailed005.sol | 90 +++++++++++++++++++ .../soliditycode/TransferFailed006.sol | 90 +++++++++++++++++++ .../soliditycode/TransferFailed007.sol | 90 +++++++++++++++++++ 3 files changed, 270 insertions(+) create mode 100644 src/test/resources/soliditycode/TransferFailed005.sol create mode 100644 src/test/resources/soliditycode/TransferFailed006.sol create mode 100644 src/test/resources/soliditycode/TransferFailed007.sol diff --git a/src/test/resources/soliditycode/TransferFailed005.sol b/src/test/resources/soliditycode/TransferFailed005.sol new file mode 100644 index 00000000000..aa39aafa152 --- /dev/null +++ b/src/test/resources/soliditycode/TransferFailed005.sol @@ -0,0 +1,90 @@ +contract EnergyOfTransferFailedTest { + constructor() payable public { + + } + // InsufficientBalance + function testTransferTrxInsufficientBalance(uint256 i) payable public{ + msg.sender.transfer(i); + } + + function testSendTrxInsufficientBalance(uint256 i) payable public{ + msg.sender.send(i); + } + + function testTransferTokenInsufficientBalance(uint256 i,trcToken tokenId) payable public{ + msg.sender.transferToken(i, tokenId); + } + + function testCallTrxInsufficientBalance(uint256 i,address payable caller) public returns (bool,bytes memory){ + return caller.call.value(i)(abi.encodeWithSignature("test()")); + } + + function testCreateTrxInsufficientBalance(uint256 i) payable public { + (new Caller).value(i)(); + } + + // NonexistentTarget + + function testSendTrxNonexistentTarget(uint256 i,address payable nonexistentTarget) payable public { + require(address(this).balance >= i); + nonexistentTarget.send(i); + } + + function testTransferTrxNonexistentTarget(uint256 i,address payable nonexistentTarget) payable public { + require(address(this).balance >= i); + nonexistentTarget.transfer(i); + } + + function testTransferTokenNonexistentTarget(uint256 i,address payable nonexistentTarget, trcToken tokenId) payable public { + require(address(this).balance >= i); + nonexistentTarget.transferToken(i, tokenId); + } + + function testCallTrxNonexistentTarget(uint256 i,address payable nonexistentTarget) payable public { + require(address(this).balance >= i); + nonexistentTarget.call.value(i)(abi.encodeWithSignature("test()")); + } + + function testSuicideNonexistentTarget(address payable nonexistentTarget) payable public { + selfdestruct(nonexistentTarget); + } + + // target is self + function testTransferTrxSelf(uint256 i) payable public{ + require(address(this).balance >= i); + address payable self = address(uint160(address(this))); + self.transfer(i); + } + + function testSendTrxSelf(uint256 i) payable public{ + require(address(this).balance >= i); + address payable self = address(uint160(address(this))); + self.send(i); + } + + function testTransferTokenSelf(uint256 i,trcToken tokenId) payable public{ + require(address(this).balance >= i); + address payable self = address(uint160(address(this))); + self.transferToken(i, tokenId); + } + + event Deployed(address addr, uint256 salt, address sender); + function deploy(bytes memory code, uint256 salt) public returns(address){ + address addr; + assembly { + addr := create2(10, add(code, 0x20), mload(code), salt) + //if iszero(extcodesize(addr)) { + // revert(0, 0) + //} + } + //emit Deployed(addr, salt, msg.sender); + return addr; + } +} + + + +contract Caller { + constructor() payable public {} + function test() payable public returns (uint256 ){return 1;} +} \ No newline at end of file diff --git a/src/test/resources/soliditycode/TransferFailed006.sol b/src/test/resources/soliditycode/TransferFailed006.sol new file mode 100644 index 00000000000..aa39aafa152 --- /dev/null +++ b/src/test/resources/soliditycode/TransferFailed006.sol @@ -0,0 +1,90 @@ +contract EnergyOfTransferFailedTest { + constructor() payable public { + + } + // InsufficientBalance + function testTransferTrxInsufficientBalance(uint256 i) payable public{ + msg.sender.transfer(i); + } + + function testSendTrxInsufficientBalance(uint256 i) payable public{ + msg.sender.send(i); + } + + function testTransferTokenInsufficientBalance(uint256 i,trcToken tokenId) payable public{ + msg.sender.transferToken(i, tokenId); + } + + function testCallTrxInsufficientBalance(uint256 i,address payable caller) public returns (bool,bytes memory){ + return caller.call.value(i)(abi.encodeWithSignature("test()")); + } + + function testCreateTrxInsufficientBalance(uint256 i) payable public { + (new Caller).value(i)(); + } + + // NonexistentTarget + + function testSendTrxNonexistentTarget(uint256 i,address payable nonexistentTarget) payable public { + require(address(this).balance >= i); + nonexistentTarget.send(i); + } + + function testTransferTrxNonexistentTarget(uint256 i,address payable nonexistentTarget) payable public { + require(address(this).balance >= i); + nonexistentTarget.transfer(i); + } + + function testTransferTokenNonexistentTarget(uint256 i,address payable nonexistentTarget, trcToken tokenId) payable public { + require(address(this).balance >= i); + nonexistentTarget.transferToken(i, tokenId); + } + + function testCallTrxNonexistentTarget(uint256 i,address payable nonexistentTarget) payable public { + require(address(this).balance >= i); + nonexistentTarget.call.value(i)(abi.encodeWithSignature("test()")); + } + + function testSuicideNonexistentTarget(address payable nonexistentTarget) payable public { + selfdestruct(nonexistentTarget); + } + + // target is self + function testTransferTrxSelf(uint256 i) payable public{ + require(address(this).balance >= i); + address payable self = address(uint160(address(this))); + self.transfer(i); + } + + function testSendTrxSelf(uint256 i) payable public{ + require(address(this).balance >= i); + address payable self = address(uint160(address(this))); + self.send(i); + } + + function testTransferTokenSelf(uint256 i,trcToken tokenId) payable public{ + require(address(this).balance >= i); + address payable self = address(uint160(address(this))); + self.transferToken(i, tokenId); + } + + event Deployed(address addr, uint256 salt, address sender); + function deploy(bytes memory code, uint256 salt) public returns(address){ + address addr; + assembly { + addr := create2(10, add(code, 0x20), mload(code), salt) + //if iszero(extcodesize(addr)) { + // revert(0, 0) + //} + } + //emit Deployed(addr, salt, msg.sender); + return addr; + } +} + + + +contract Caller { + constructor() payable public {} + function test() payable public returns (uint256 ){return 1;} +} \ No newline at end of file diff --git a/src/test/resources/soliditycode/TransferFailed007.sol b/src/test/resources/soliditycode/TransferFailed007.sol new file mode 100644 index 00000000000..aa39aafa152 --- /dev/null +++ b/src/test/resources/soliditycode/TransferFailed007.sol @@ -0,0 +1,90 @@ +contract EnergyOfTransferFailedTest { + constructor() payable public { + + } + // InsufficientBalance + function testTransferTrxInsufficientBalance(uint256 i) payable public{ + msg.sender.transfer(i); + } + + function testSendTrxInsufficientBalance(uint256 i) payable public{ + msg.sender.send(i); + } + + function testTransferTokenInsufficientBalance(uint256 i,trcToken tokenId) payable public{ + msg.sender.transferToken(i, tokenId); + } + + function testCallTrxInsufficientBalance(uint256 i,address payable caller) public returns (bool,bytes memory){ + return caller.call.value(i)(abi.encodeWithSignature("test()")); + } + + function testCreateTrxInsufficientBalance(uint256 i) payable public { + (new Caller).value(i)(); + } + + // NonexistentTarget + + function testSendTrxNonexistentTarget(uint256 i,address payable nonexistentTarget) payable public { + require(address(this).balance >= i); + nonexistentTarget.send(i); + } + + function testTransferTrxNonexistentTarget(uint256 i,address payable nonexistentTarget) payable public { + require(address(this).balance >= i); + nonexistentTarget.transfer(i); + } + + function testTransferTokenNonexistentTarget(uint256 i,address payable nonexistentTarget, trcToken tokenId) payable public { + require(address(this).balance >= i); + nonexistentTarget.transferToken(i, tokenId); + } + + function testCallTrxNonexistentTarget(uint256 i,address payable nonexistentTarget) payable public { + require(address(this).balance >= i); + nonexistentTarget.call.value(i)(abi.encodeWithSignature("test()")); + } + + function testSuicideNonexistentTarget(address payable nonexistentTarget) payable public { + selfdestruct(nonexistentTarget); + } + + // target is self + function testTransferTrxSelf(uint256 i) payable public{ + require(address(this).balance >= i); + address payable self = address(uint160(address(this))); + self.transfer(i); + } + + function testSendTrxSelf(uint256 i) payable public{ + require(address(this).balance >= i); + address payable self = address(uint160(address(this))); + self.send(i); + } + + function testTransferTokenSelf(uint256 i,trcToken tokenId) payable public{ + require(address(this).balance >= i); + address payable self = address(uint160(address(this))); + self.transferToken(i, tokenId); + } + + event Deployed(address addr, uint256 salt, address sender); + function deploy(bytes memory code, uint256 salt) public returns(address){ + address addr; + assembly { + addr := create2(10, add(code, 0x20), mload(code), salt) + //if iszero(extcodesize(addr)) { + // revert(0, 0) + //} + } + //emit Deployed(addr, salt, msg.sender); + return addr; + } +} + + + +contract Caller { + constructor() payable public {} + function test() payable public returns (uint256 ){return 1;} +} \ No newline at end of file From d8a6cd287e5447415fb7ba5a11a2570548c0fbde Mon Sep 17 00:00:00 2001 From: wangming Date: Fri, 10 May 2019 14:57:47 +0800 Subject: [PATCH 07/90] add TransferFailed case 005-007 --- .../transferfailed/TransferFailed005.java | 280 ++++++++++++++++++ .../transferfailed/TransferFailed006.java | 240 +++++++++++++++ .../transferfailed/TransferFailed007.java | 211 +++++++++++++ 3 files changed, 731 insertions(+) create mode 100644 src/test/java/stest/tron/wallet/dailybuild/transferfailed/TransferFailed005.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/transferfailed/TransferFailed006.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/transferfailed/TransferFailed007.java diff --git a/src/test/java/stest/tron/wallet/dailybuild/transferfailed/TransferFailed005.java b/src/test/java/stest/tron/wallet/dailybuild/transferfailed/TransferFailed005.java new file mode 100644 index 00000000000..73d0631cdac --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/transferfailed/TransferFailed005.java @@ -0,0 +1,280 @@ +package stest.tron.wallet.dailybuild.TransferFailed; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +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.api.WalletSolidityGrpc; +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.Base58; +import stest.tron.wallet.common.client.utils.PublicMethed; + +@Slf4j +public class TransferFailed005 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key1"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private final Long maxFeeLimit = Configuration.getByPath("testng.cong") + .getLong("defaultParameter.maxFeeLimit"); + + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + byte[] contractAddress = null; + byte[] contractAddress1 = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] accountExcAddress = ecKey1.getAddress(); + String accountExcKey = 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(accountExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + } + + @Test(enabled = true, description = "deploy contract for trigger") + public void deployContract() { + Assert.assertTrue(PublicMethed + .sendcoin(accountExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + String filePath = "src/test/resources/soliditycode/TransferFailed005.sol"; + String contractName = "EnergyOfTransferFailedTest"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + String Txid1 = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, 0L, 100L, + null, accountExcKey, accountExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = PublicMethed + .getTransactionInfoById(Txid1, blockingStubFull); + contractAddress = infoById.get().getContractAddress().toByteArray(); + Assert.assertEquals(0, infoById.get().getResultValue()); + + filePath = "src/test/resources/soliditycode/TransferFailed005.sol"; + contractName = "Caller"; + retMap = PublicMethed.getBycodeAbi(filePath, contractName); + code = retMap.get("byteCode").toString(); + abi = retMap.get("abI").toString(); + + Txid1 = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, 0L, 100L, + null, accountExcKey, accountExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + infoById = PublicMethed + .getTransactionInfoById(Txid1, blockingStubFull); + contractAddress1 = infoById.get().getContractAddress().toByteArray(); + logger.info("caller address : " + Base58.encode58Check(contractAddress1)); + Assert.assertEquals(0, infoById.get().getResultValue()); + } + + @Test(enabled = true, description = "TransferFailed for function call_value") + public void triggerContract() { + Account info = null; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(accountExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(accountExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + + Assert.assertTrue(PublicMethed + .sendcoin(contractAddress, 1000100L, accountExcAddress, accountExcKey, blockingStubFull)); + Assert.assertTrue(PublicMethed + .sendcoin(contractAddress1, 1, accountExcAddress, accountExcKey, blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + logger.info( + "contractAddress balance before: " + PublicMethed + .queryAccount(contractAddress, blockingStubFull) + .getBalance()); + logger.info( + "callerAddress balance before: " + PublicMethed + .queryAccount(contractAddress1, blockingStubFull) + .getBalance()); + long paramValue = 1000000; + + // transfer trx to self`s account + String param = "\"" + paramValue + "\",\"" + Base58.encode58Check(contractAddress) + "\""; + String triggerTxid = PublicMethed.triggerContract(contractAddress, + "testCallTrxInsufficientBalance(uint256,address)", param, false, 0L, + maxFeeLimit, accountExcAddress, accountExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + Assert.assertEquals(infoById.get().getResultValue(), 1); + Assert.assertEquals("FAILED", infoById.get().getResult().toString()); + Assert.assertEquals("TRANSFER_FAILED", infoById.get().getReceipt().getResult().toString()); + Assert.assertEquals("transfer trx failed: Cannot transfer trx to yourself.", + infoById.get().getResMessage().toStringUtf8()); + Assert.assertEquals(1000100L, + PublicMethed.queryAccount(contractAddress, blockingStubFull).getBalance()); + Assert.assertEquals(1L, + PublicMethed.queryAccount(contractAddress1, blockingStubFull).getBalance()); + Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() < 10000000); + + // transfer trx to unactivate account + ECKey ecKey2 = new ECKey(Utils.getRandom()); + byte[] accountExcAddress2 = ecKey2.getAddress(); + param = "\"" + paramValue + "\",\"" + Base58.encode58Check(accountExcAddress2) + "\""; + triggerTxid = PublicMethed.triggerContract(contractAddress, + "testCallTrxInsufficientBalance(uint256,address)", param, false, 0L, + maxFeeLimit, accountExcAddress, accountExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + Assert.assertEquals(infoById.get().getResultValue(), 1); + Assert.assertEquals("FAILED", infoById.get().getResult().toString()); + Assert.assertEquals("TRANSFER_FAILED", infoById.get().getReceipt().getResult().toString()); + Assert.assertEquals( + "transfer trx failed: Validate InternalTransfer error, no ToAccount. " + + "And not allowed to create account in smart contract.", + infoById.get().getResMessage().toStringUtf8()); + Assert.assertEquals(1000100L, + PublicMethed.queryAccount(contractAddress, blockingStubFull).getBalance()); + Assert.assertEquals(1L, + PublicMethed.queryAccount(contractAddress1, blockingStubFull).getBalance()); + Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() < 10000000); + + // transfer trx to caller, value enough , function success contractResult(call_value) failed + param = "\"" + paramValue + "\",\"" + Base58.encode58Check(contractAddress1) + "\""; + triggerTxid = PublicMethed.triggerContract(contractAddress, + "testCallTrxInsufficientBalance(uint256,address)", param, false, 0L, + maxFeeLimit, accountExcAddress, accountExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + logger.info(infoById.get().getReceipt().getResult() + ""); + + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + int contractResult = ByteArray + .toInt(infoById.get().getContractResult(0).toByteArray()); + Assert.assertEquals(1, contractResult); + + Assert.assertEquals(infoById.get().getResultValue(), 0); + Assert.assertEquals(infoById.get().getResult().toString(), "SUCESS"); + Assert.assertEquals(100L, + PublicMethed.queryAccount(contractAddress, blockingStubFull).getBalance()); + Assert.assertEquals(1000001L, + PublicMethed.queryAccount(contractAddress1, blockingStubFull).getBalance()); + Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() < 10000000); + + // transfer trx to caller, value not enough, function success + // but contractResult(call_value) failed + triggerTxid = PublicMethed.triggerContract(contractAddress, + "testCallTrxInsufficientBalance(uint256,address)", param, false, 0L, + maxFeeLimit, accountExcAddress, accountExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull); + fee = infoById.get().getFee(); + netUsed = infoById.get().getReceipt().getNetUsage(); + energyUsed = infoById.get().getReceipt().getEnergyUsage(); + netFee = infoById.get().getReceipt().getNetFee(); + energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + //contractResult`s first boolean value + contractResult = ByteArray + .toInt(infoById.get().getContractResult(0).toByteArray()); + Assert.assertEquals(0, contractResult); + Assert.assertEquals(infoById.get().getResultValue(), 0); + Assert.assertEquals(infoById.get().getResult().toString(), "SUCESS"); + Assert.assertEquals(100L, + PublicMethed.queryAccount(contractAddress, blockingStubFull).getBalance()); + Assert.assertEquals(1000001L, + PublicMethed.queryAccount(contractAddress1, blockingStubFull).getBalance()); + Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() < 10000000); + + + } + + /** + * constructor. + */ + @AfterClass + + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/transferfailed/TransferFailed006.java b/src/test/java/stest/tron/wallet/dailybuild/transferfailed/TransferFailed006.java new file mode 100644 index 00000000000..85db5b5d2b3 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/transferfailed/TransferFailed006.java @@ -0,0 +1,240 @@ +package stest.tron.wallet.dailybuild.TransferFailed; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +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.api.WalletSolidityGrpc; +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.Base58; +import stest.tron.wallet.common.client.utils.PublicMethed; + +@Slf4j +public class TransferFailed006 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key1"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private final Long maxFeeLimit = Configuration.getByPath("testng.cong") + .getLong("defaultParameter.maxFeeLimit"); + + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + byte[] contractAddress = null; + byte[] contractAddress1 = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] accountExcAddress = ecKey1.getAddress(); + String accountExcKey = 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(accountExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + } + + @Test(enabled = true, description = "deploy contract for trigger") + public void deployContract() { + Assert.assertTrue(PublicMethed + .sendcoin(accountExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + String filePath = "src/test/resources/soliditycode/TransferFailed006.sol"; + String contractName = "EnergyOfTransferFailedTest"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + String Txid1 = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, 0L, 100L, + null, accountExcKey, accountExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = PublicMethed + .getTransactionInfoById(Txid1, blockingStubFull); + contractAddress = infoById.get().getContractAddress().toByteArray(); + Assert.assertEquals(0, infoById.get().getResultValue()); + + filePath = "src/test/resources/soliditycode/TransferFailed006.sol"; + contractName = "Caller"; + retMap = PublicMethed.getBycodeAbi(filePath, contractName); + code = retMap.get("byteCode").toString(); + abi = retMap.get("abI").toString(); + + Txid1 = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, 0L, 100L, + null, accountExcKey, accountExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + infoById = PublicMethed + .getTransactionInfoById(Txid1, blockingStubFull); + contractAddress1 = infoById.get().getContractAddress().toByteArray(); + logger.info("caller address : " + Base58.encode58Check(contractAddress1)); + Assert.assertEquals(0, infoById.get().getResultValue()); + } + + @Test(enabled = true, description = "TransferFailed for create") + public void triggerContract() { + Account info = null; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(accountExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(accountExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + + Assert.assertTrue(PublicMethed + .sendcoin(contractAddress, 1000100L, accountExcAddress, accountExcKey, blockingStubFull)); + Assert.assertTrue(PublicMethed + .sendcoin(contractAddress1, 1, accountExcAddress, accountExcKey, blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + logger.info( + "contractAddress balance before: " + PublicMethed + .queryAccount(contractAddress, blockingStubFull) + .getBalance()); + logger.info( + "callerAddress balance before: " + PublicMethed + .queryAccount(contractAddress1, blockingStubFull) + .getBalance()); + long paramValue = 1000000; + String param = "\"" + paramValue + "\""; + + String triggerTxid = PublicMethed.triggerContract(contractAddress, + "testCreateTrxInsufficientBalance(uint256)", param, false, 0L, + maxFeeLimit, accountExcAddress, accountExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + logger.info(infoById.get().getReceipt().getResult() + ""); + + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + logger.info( + "contractAddress balance before: " + PublicMethed + .queryAccount(contractAddress, blockingStubFull) + .getBalance()); + logger.info( + "callerAddress balance before: " + PublicMethed + .queryAccount(contractAddress1, blockingStubFull) + .getBalance()); + Assert.assertEquals(infoById.get().getResultValue(), 0); + Assert.assertFalse(infoById.get().getInternalTransactions(0).getRejected()); + Assert.assertEquals(100L, + PublicMethed.queryAccount(contractAddress, blockingStubFull).getBalance()); + Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() < 10000000); + + triggerTxid = PublicMethed.triggerContract(contractAddress, + "testCreateTrxInsufficientBalance(uint256)", param, false, 0L, + maxFeeLimit, accountExcAddress, accountExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull); + fee = infoById.get().getFee(); + netUsed = infoById.get().getReceipt().getNetUsage(); + energyUsed = infoById.get().getReceipt().getEnergyUsage(); + netFee = infoById.get().getReceipt().getNetFee(); + energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + logger.info( + "contractAddress balance before: " + PublicMethed + .queryAccount(contractAddress, blockingStubFull) + .getBalance()); + logger.info( + "callerAddress balance before: " + PublicMethed + .queryAccount(contractAddress1, blockingStubFull) + .getBalance()); + + Assert.assertEquals(infoById.get().getResultValue(), 1); + Assert.assertEquals(infoById.get().getResMessage().toStringUtf8(), "REVERT opcode executed"); + Assert.assertEquals(100L, + PublicMethed.queryAccount(contractAddress, blockingStubFull).getBalance()); + Assert.assertEquals(1L, + PublicMethed.queryAccount(contractAddress1, blockingStubFull).getBalance()); + Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() < 10000000); + + + } + + /** + * constructor. + */ + @AfterClass + + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/transferfailed/TransferFailed007.java b/src/test/java/stest/tron/wallet/dailybuild/transferfailed/TransferFailed007.java new file mode 100644 index 00000000000..3818b50b1eb --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/transferfailed/TransferFailed007.java @@ -0,0 +1,211 @@ +package stest.tron.wallet.dailybuild.TransferFailed; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +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.api.WalletSolidityGrpc; +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 TransferFailed007 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key1"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private final Long maxFeeLimit = Configuration.getByPath("testng.cong") + .getLong("defaultParameter.maxFeeLimit"); + + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + byte[] contractAddress = null; + byte[] contractAddress1 = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] accountExcAddress = ecKey1.getAddress(); + String accountExcKey = 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(accountExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + } + + @Test(enabled = true, description = "deploy contract for trigger") + public void deployContract() { + Assert.assertTrue(PublicMethed + .sendcoin(accountExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + String filePath = "src/test/resources/soliditycode/TransferFailed007.sol"; + String contractName = "EnergyOfTransferFailedTest"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + String Txid1 = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, 0L, 100L, + null, accountExcKey, accountExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = PublicMethed + .getTransactionInfoById(Txid1, blockingStubFull); + contractAddress = infoById.get().getContractAddress().toByteArray(); + Assert.assertEquals(0, infoById.get().getResultValue()); + } + + @Test(enabled = true, description = "TransferFailed for create2") + public void triggerContract() { + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(accountExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(accountExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + + Assert.assertTrue(PublicMethed + .sendcoin(contractAddress, 15L, accountExcAddress, accountExcKey, blockingStubFull)); + logger.info( + "contractAddress balance before: " + PublicMethed + .queryAccount(contractAddress, blockingStubFull) + .getBalance()); + + String filePath = "./src/test/resources/soliditycode/TransferFailed007.sol"; + String contractName = "Caller"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String testContractCode = retMap.get("byteCode").toString(); + Long salt = 1L; + + String param = "\"" + testContractCode + "\"," + salt; + + String triggerTxid = PublicMethed.triggerContract(contractAddress, + "deploy(bytes,uint256)", param, false, 0L, + maxFeeLimit, accountExcAddress, accountExcKey, blockingStubFull); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + long afterBalance = 0L; + afterBalance = PublicMethed.queryAccount(contractAddress, blockingStubFull) + .getBalance(); + logger.info( + "contractAddress balance after : " + PublicMethed + .queryAccount(contractAddress, blockingStubFull) + .getBalance()); + Assert.assertEquals(0, infoById.get().getResultValue()); + Assert.assertEquals("SUCESS", infoById.get().getResult().toString()); + Assert.assertEquals(5L, afterBalance); + Assert.assertFalse(infoById.get().getInternalTransactions(0).getRejected()); + Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() < 10000000); + + triggerTxid = PublicMethed.triggerContract(contractAddress, + "deploy(bytes,uint256)", param, false, 0L, + maxFeeLimit, accountExcAddress, accountExcKey, blockingStubFull); + + infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + fee = infoById.get().getFee(); + netUsed = infoById.get().getReceipt().getNetUsage(); + energyUsed = infoById.get().getReceipt().getEnergyUsage(); + netFee = infoById.get().getReceipt().getNetFee(); + energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + afterBalance = PublicMethed.queryAccount(contractAddress, blockingStubFull).getBalance(); + logger.info( + "contractAddress balance after : " + PublicMethed + .queryAccount(contractAddress, blockingStubFull) + .getBalance()); + Assert.assertEquals(0, infoById.get().getResultValue()); + Assert.assertEquals("SUCESS", infoById.get().getResult().toString()); + Assert.assertEquals(5L, afterBalance); + Assert.assertEquals(0, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray())); + Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() < 10000000); + + } + + /** + * constructor. + */ + @AfterClass + + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } +} From 2c26067b0cca0b7fa3ffa030495cf28a669aa132 Mon Sep 17 00:00:00 2001 From: dannaguo Date: Fri, 10 May 2019 16:55:27 +0800 Subject: [PATCH 08/90] add extcodehash command stress test case --- .../common/client/utils/PublicMethed.java | 98 +++ .../onlinestress/ExtCodeHashStressTest.java | 637 ++++++++++++++++++ .../soliditycode/extCodeHashStress.sol | 34 + src/test/resources/testng.conf | 6 +- 4 files changed, 772 insertions(+), 3 deletions(-) create mode 100644 src/test/java/stest/tron/wallet/onlinestress/ExtCodeHashStressTest.java create mode 100644 src/test/resources/soliditycode/extCodeHashStress.sol diff --git a/src/test/java/stest/tron/wallet/common/client/utils/PublicMethed.java b/src/test/java/stest/tron/wallet/common/client/utils/PublicMethed.java index 7a90531d481..54aed00bee1 100644 --- a/src/test/java/stest/tron/wallet/common/client/utils/PublicMethed.java +++ b/src/test/java/stest/tron/wallet/common/client/utils/PublicMethed.java @@ -2365,6 +2365,104 @@ public static String triggerContract(byte[] contractAddress, String method, Stri "0", 0, ownerAddress, priKey, blockingStubFull); } + /** + * constructor. + */ + + public static String triggerParamListContract(byte[] contractAddress, String method, + List params, + Boolean isHex, long callValue, long feeLimit, String tokenId, long tokenValue, + byte[] ownerAddress, + String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { + + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + ECKey temKey = null; + try { + BigInteger priK = new BigInteger(priKey, 16); + temKey = ECKey.fromPrivate(priK); + } catch (Exception ex) { + ex.printStackTrace(); + } + final ECKey ecKey = temKey; + + byte[] owner = ownerAddress; + byte[] input = Hex.decode(AbiUtil.parseMethod(method, params)); + + Contract.TriggerSmartContract.Builder builder = Contract.TriggerSmartContract.newBuilder(); + builder.setOwnerAddress(ByteString.copyFrom(owner)); + builder.setContractAddress(ByteString.copyFrom(contractAddress)); + builder.setData(ByteString.copyFrom(input)); + builder.setCallValue(callValue); + builder.setTokenId(Long.parseLong(tokenId)); + builder.setCallTokenValue(tokenValue); + Contract.TriggerSmartContract triggerContract = builder.build(); + + TransactionExtention transactionExtention = blockingStubFull.triggerContract(triggerContract); + if (transactionExtention == null || !transactionExtention.getResult().getResult()) { + System.out.println("RPC create call trx failed!"); + System.out.println("Code = " + transactionExtention.getResult().getCode()); + System.out + .println("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); + return null; + } + Transaction transaction = transactionExtention.getTransaction(); + if (transaction.getRetCount() != 0 + && transactionExtention.getConstantResult(0) != null + && transactionExtention.getResult() != null) { + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + System.out.println("message:" + transaction.getRet(0).getRet()); + System.out.println(":" + ByteArray + .toStr(transactionExtention.getResult().getMessage().toByteArray())); + System.out.println("Result:" + Hex.toHexString(result)); + return null; + } + + final TransactionExtention.Builder texBuilder = TransactionExtention.newBuilder(); + Transaction.Builder transBuilder = Transaction.newBuilder(); + Transaction.raw.Builder rawBuilder = transactionExtention.getTransaction().getRawData() + .toBuilder(); + rawBuilder.setFeeLimit(feeLimit); + transBuilder.setRawData(rawBuilder); + for (int i = 0; i < transactionExtention.getTransaction().getSignatureCount(); i++) { + ByteString s = transactionExtention.getTransaction().getSignature(i); + transBuilder.setSignature(i, s); + } + for (int i = 0; i < transactionExtention.getTransaction().getRetCount(); i++) { + Result r = transactionExtention.getTransaction().getRet(i); + transBuilder.setRet(i, r); + } + texBuilder.setTransaction(transBuilder); + texBuilder.setResult(transactionExtention.getResult()); + texBuilder.setTxid(transactionExtention.getTxid()); + transactionExtention = texBuilder.build(); + if (transactionExtention == null) { + return null; + } + Return ret = transactionExtention.getResult(); + if (!ret.getResult()) { + System.out.println("Code = " + ret.getCode()); + System.out.println("Message = " + ret.getMessage().toStringUtf8()); + return null; + } + transaction = transactionExtention.getTransaction(); + if (transaction == null || transaction.getRawData().getContractCount() == 0) { + System.out.println("Transaction is empty"); + return null; + } + transaction = signTransaction(ecKey, transaction); + System.out.println( + "trigger txid = " + ByteArray.toHexString(Sha256Hash.hash(transaction.getRawData() + .toByteArray()))); + GrpcAPI.Return response = broadcastTransaction(transaction, blockingStubFull); + if (response.getResult() == false) { + return null; + } else { + return ByteArray.toHexString(Sha256Hash.hash(transaction.getRawData().toByteArray())); + } + + + } + /** * constructor. */ diff --git a/src/test/java/stest/tron/wallet/onlinestress/ExtCodeHashStressTest.java b/src/test/java/stest/tron/wallet/onlinestress/ExtCodeHashStressTest.java new file mode 100644 index 00000000000..14e2c27e7e3 --- /dev/null +++ b/src/test/java/stest/tron/wallet/onlinestress/ExtCodeHashStressTest.java @@ -0,0 +1,637 @@ +package stest.tron.wallet.onlinestress; + +import com.google.protobuf.ByteString; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicLong; +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.WalletClient; +import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.PublicMethed; + +@Slf4j +public class ExtCodeHashStressTest { + + private AtomicLong count = new AtomicLong(); + private AtomicLong errorCount = new AtomicLong(); + private long startTime = System.currentTimeMillis(); + + private final String testKey002 = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + 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(1); + private long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + + private byte[] extCodeHashContractAddress = null; + private byte[] normalContractAddress = null; + private byte[] testContractAddress = null; + + private byte[] dev001Address = fromAddress; + private String dev001Key = testKey002; + + private ECKey ecKey2 = new ECKey(Utils.getRandom()); + private byte[] user001Address = ecKey2.getAddress(); + private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + @BeforeClass(enabled = true) + public void beforeClass() { + + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + + PublicMethed.printAddress(dev001Key); + PublicMethed.printAddress(user001Key); + } + + + @Test(enabled = true, description = "Deploy a normal contract to be used for stress testing.") + public void test01DeployNormalContract() { + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + //before deploy, check account resource + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long energyLimit = accountResource.getEnergyLimit(); + long energyUsage = accountResource.getEnergyUsed(); + long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before energyLimit is " + Long.toString(energyLimit)); + logger.info("before energyUsage is " + Long.toString(energyUsage)); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + String filePath = "./src/test/resources/soliditycode/extCodeHashStress.sol"; + String contractName = "TriggerNormal"; //TBVEkA72g1wFoBBVLSXFZ2Bp944oL17NeU + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + normalContractAddress = deployContract(code, abi, contractName, blockingStubFull); + + SmartContract smartContract = PublicMethed.getContract(normalContractAddress, + blockingStubFull); + Assert.assertNotNull(smartContract.getAbi()); + } + + + @Test(enabled = true, description = "Deploy a extcodehash contract.") + public void test02DeployExtCodeHashContract() { + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + //before deploy, check account resource + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long energyLimit = accountResource.getEnergyLimit(); + long energyUsage = accountResource.getEnergyUsed(); + long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before energyLimit is " + Long.toString(energyLimit)); + logger.info("before energyUsage is " + Long.toString(energyUsage)); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + String filePath = "./src/test/resources/soliditycode/extCodeHashStress.sol"; + String contractName = "Trigger"; //THAx2PcAtRCerwrLGN237dahqSUfq5wLnR + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + extCodeHashContractAddress = deployContract(code, abi, contractName, blockingStubFull); + + SmartContract smartContract = PublicMethed.getContract(extCodeHashContractAddress, + blockingStubFull); + Assert.assertNotNull(smartContract.getAbi()); + } + + /** + * trigger. + */ + public byte[] deployContract(String bytecode, String abi, String contractName, + WalletGrpc.WalletBlockingStub blockingStubFull) { + + final String transferTokenTxid = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, bytecode, "", + maxFeeLimit, 0L, 0, 10000, + "0", 0, null, dev001Key, + dev001Address, blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + Optional infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage() + .toStringUtf8()); + } + + return infoById.get().getContractAddress().toByteArray(); + } + + /** + * trigger. + */ + public String triggerContractWithMaxFeeLimit(byte[] testAddress, byte[] user001Address, + String user001Key, long maxFeeLimit) { + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 10000_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + Long callValue = Long.valueOf(0); + + String param = "\"" + Base58.encode58Check(testAddress) + "\""; + final String triggerTxid = PublicMethed.triggerContract(extCodeHashContractAddress, + "test(address)", param, false, callValue, + maxFeeLimit, "0", 0, user001Address, user001Key, + blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + scheduledExecutorService + .schedule(new CheckTask(triggerTxid, blockingStubFull), 15, TimeUnit.SECONDS); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + logger + .info("transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + + if (infoById.get().getResMessage().toStringUtf8().toLowerCase().contains("cpu")) { + throw new IllegalArgumentException(); + } + if (infoById.get().getResMessage().toStringUtf8().toLowerCase().contains("timeout")) { + throw new IllegalArgumentException(); + } + return "ok"; + } + + + /** + * trigger. + */ + public String triggerAndGetExtCodeHashList(List testAddress, byte[] user001Address, + String user001Key, long maxFeeLimit, WalletGrpc.WalletBlockingStub blockingStubFull) { + + Long callValue = Long.valueOf(0); + List params = new ArrayList<>(); + for (int i = 0; i < testAddress.size(); i++) { + params.add(Base58.encode58Check(testAddress.get(i))); + } + final String triggerTxid = PublicMethed.triggerParamListContract(extCodeHashContractAddress, + "test(address[])", Arrays.asList(params), false, callValue, + maxFeeLimit, "0", 0, user001Address, user001Key, + blockingStubFull); + + scheduledExecutorService + .schedule(new CheckTask(triggerTxid, blockingStubFull), 15, TimeUnit.SECONDS); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + logger + .info( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + + return "ok"; + + } + + /** + * trigger. + */ + public void triggerAndGetExtCodeHash(byte[] testAddress, byte[] user001Address, + String user001Key, long maxFeeLimit, WalletGrpc.WalletBlockingStub blockingStubFull) { + + Long callValue = Long.valueOf(0); + + String param = "\"" + Base58.encode58Check(testAddress) + "\""; + final String triggerTxid = PublicMethed.triggerContract(normalContractAddress, + "test(address)", param, false, callValue, + 314982000, "0", 0, user001Address, user001Key, + blockingStubFull); + + scheduledExecutorService + .schedule(new CheckTask(triggerTxid, blockingStubFull), 15, TimeUnit.SECONDS); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + logger + .info( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + private synchronized void wirteLine(String fileName, String line) { + try { + BufferedWriter out = new BufferedWriter(new FileWriter(fileName, true)); + out.write(line); + out.newLine(); + out.flush(); + out.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + class DeployTask implements Runnable { + + Map addressList; + CountDownLatch countDownLatch; + WalletGrpc.WalletBlockingStub stub; + int index; + + DeployTask(Map addressList, int index, CountDownLatch countDownLatch, + WalletGrpc.WalletBlockingStub stub) { + this.index = index; + this.addressList = addressList; + this.countDownLatch = countDownLatch; + this.stub = stub; + } + + @Override + public void run() { + logger.info("depoying :" + index); + String code = Configuration.getByPath("testng.conf") + .getString("code.code_veryLarge"); + String abi = Configuration.getByPath("testng.conf") + .getString("abi.abi_veryLarge"); + try { + byte[] deployedAddress = deployContract(code, abi, "test" + index, stub); + String address = Base58.encode58Check(deployedAddress); + wirteLine( + "src/test/resources/addresses2", + address); + logger.info("deployed : " + index + " " + address); + } catch (Throwable e) { + logger.error("deploy error: ", e); + } finally { + countDownLatch.countDown(); + } + } + } + + @Test(enabled = true, description = "Deploy multiple long bytecode contract " + + "and write address to file.") + public void test03DeployMultiLongByteCodeContract() { + + ExecutorService pool = Executors.newFixedThreadPool(30); + Map addressMap = new ConcurrentHashMap<>(); + int size = 10_000_000; + int stubSize = 30; + List stubs = new ArrayList<>(); + for (int i = 0; i < stubSize; i++) { + stubs.add(WalletGrpc.newBlockingStub(channelFull)); + } + + CountDownLatch count = new CountDownLatch(size); + for (int i = 0; i < size; i++) { + + String contractName = "extcodehashContract" + i; + logger.info("[" + i + "]contractName: " + contractName); + pool.submit(new DeployTask(addressMap, i, count, stubs.get(i % stubSize))); + + } + + try { + count.await(); + for (String s : addressMap.keySet()) { + System.out.println(s); + } + + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(2); + + class CheckTask implements Runnable { + + String txid; + WalletGrpc.WalletBlockingStub client; + + CheckTask(String txid, WalletGrpc.WalletBlockingStub client) { + this.txid = txid; + this.client = client; + } + + @Override + public void run() { + + Optional infoById = PublicMethed + .getTransactionInfoById(this.txid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + if (infoById.get().getResultValue() != 0) { + logger.error("txid:" + this.txid); + logger.error( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + logger.info("infoById" + infoById); + } + } + + + @Test(enabled = true, description = "Calculate the contract maxfeelimit.", + threadPoolSize = 1, invocationCount = 1) + public void test04StressGetExtCodeHashContract() { + + ECKey ecKey2 = new ECKey(Utils.getRandom()); + byte[] user001Address = ecKey2.getAddress(); + String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + + extCodeHashContractAddress = WalletClient + .decodeFromBase58Check("TEsdDpJQrLBDPmJfDF2Ex53iMfzetqHvn9"); + + // long bytecode contract + testContractAddress = WalletClient.decodeFromBase58Check("TDqSAv8gLFXQRfug5Pr1Ev6zrEj1efC8qe"); + + HashMap retMap = new HashMap<>(); + + long feeLimit = 314982000; + // long feeLimit = 393624800; + // long feeLimit = 406731800; + + long base = 100; + long lastSuccess = feeLimit; + int failed = 0; + + for (int i = 0; i < 1000000000; i++) { + try { + String retCode = triggerContractWithMaxFeeLimit(testContractAddress, user001Address, + user001Key, + feeLimit); + logger.info("[" + i + "]retCode: " + retCode); + logger.info("[" + i + "]feeLimit: " + feeLimit); + lastSuccess = feeLimit; + base *= 2; + feeLimit += base; + failed = 0; + } catch (Exception e) { + failed++; + if (failed > 3) { + break; + } + logger.error("cpu timeout"); + feeLimit = lastSuccess; + base = 100; + } + } + } + + + @Test(enabled = true, description = "Trigger extcodeHash contract stress.") + public void test05TriggerContract() throws FileNotFoundException { + + BufferedReader reader = null; + List addresses = new ArrayList<>(); + try { + reader = new BufferedReader(new FileReader("src/test/resources/addresses")); + String line = reader.readLine(); + while (line != null) { + System.out.println(line); + // read next line + line = reader.readLine(); + addresses.add(line); + } + reader.close(); + } catch (IOException e) { + e.printStackTrace(); + } + ExecutorService pool = Executors.newFixedThreadPool(50); + int stubSize = 50; + List stubs = new ArrayList<>(); + for (int i = 0; i < stubSize; i++) { + stubs.add(WalletGrpc.newBlockingStub(channelFull)); + } + + int paramsSize = 75; // the address count per trigger + int trigger = 0; + for (int i = 0; i + paramsSize < addresses.size(); i += paramsSize) { + System.err.println(trigger++); + System.err.println(i + " " + (i + paramsSize)); + pool.submit(new TriggerTask(addresses.subList(i, i + paramsSize), stubs.get( + (int) (Math.random() * 100 % stubSize)))); + } + + try { + Thread.sleep(100000000); + } catch ( + InterruptedException e) { + e.printStackTrace(); + } + } + + class TriggerTask implements Runnable { + + List addresses; + WalletGrpc.WalletBlockingStub stub; + + TriggerTask(List addresses, WalletGrpc.WalletBlockingStub stub) { + this.addresses = addresses; + this.stub = stub; + } + + @Override + public void run() { + triggerContact(this.addresses.toArray(new String[0]), stub); + } + } + + /** + * trigger. + */ + public void triggerContact(String[] testList, WalletGrpc.WalletBlockingStub stub) { + + final byte[] user001Address = fromAddress; + final String user001Key = testKey002; + + extCodeHashContractAddress = WalletClient + .decodeFromBase58Check("TEsdDpJQrLBDPmJfDF2Ex53iMfzetqHvn9"); + + final long feeLimit = maxFeeLimit; + count.getAndAdd(1); + if (count.get() % 100 == 0) { + long cost = (System.currentTimeMillis() - startTime) / 1000; + logger.info("Count:" + count.get() + ", cost:" + cost + + ", avg:" + count.get() / cost + ", errCount:" + errorCount); + } + + List addressList = new ArrayList<>(); + + for (int k = 0; k < testList.length; k++) { + addressList.add(WalletClient.decodeFromBase58Check(testList[k])); + } + triggerAndGetExtCodeHashList(addressList, user001Address, user001Key, feeLimit, stub); + } + + + @Test(enabled = true, description = "Trigger normal contract stress.") + public void test06TriggerNormalContract() throws FileNotFoundException { + + BufferedReader reader = null; + List addresses = new ArrayList<>(); + try { + reader = new BufferedReader(new FileReader( + "/Users/tron/Documents/GitHub/java-tron-odyseeyv3.2/src/test/resources/addresses")); + String line = reader.readLine(); + while (line != null) { + System.out.println(line); + // read next line + line = reader.readLine(); + addresses.add(line); + } + reader.close(); + } catch (IOException e) { + e.printStackTrace(); + } + ExecutorService pool = Executors.newFixedThreadPool(50); + int stubSize = 50; + List stubs = new ArrayList<>(); + for (int i = 0; i < stubSize; i++) { + stubs.add(WalletGrpc.newBlockingStub(channelFull)); + } + + int paramsSize = 50; + int trigger = 0; + for (int i = 0; i + paramsSize < addresses.size(); i += 1) { + System.err.println(trigger++); + System.err.println(i + " " + (i + paramsSize)); + pool.submit( + new TriggerNormalTask(addresses.subList(0, 0 + paramsSize), stubs.get( + (int) (Math.random() * 100 % stubSize)))); + } + + try { + Thread.sleep(100000000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + class TriggerNormalTask implements Runnable { + + List addresses; + WalletGrpc.WalletBlockingStub stub; + + TriggerNormalTask(List addresses, WalletGrpc.WalletBlockingStub stub) { + this.addresses = addresses; + this.stub = stub; + } + + @Override + public void run() { + triggerNormalContact(this.addresses.toArray(new String[0]), stub); + } + } + + /** + * trigger. + */ + public void triggerNormalContact(String[] testList, WalletGrpc.WalletBlockingStub stub) { + + final byte[] user001Address = fromAddress; + final String user001Key = testKey002; + + normalContractAddress = WalletClient + .decodeFromBase58Check("TCkqZ2YaCvmkc7bj8UCXVQs7wi7U4xr925"); + + final long feeLimit = maxFeeLimit; + count.getAndAdd(1); + if (count.get() % 100 == 0) { + long cost = (System.currentTimeMillis() - startTime) / 1000; + logger.info("Count:" + count.get() + ", cost:" + cost + + ", avg:" + count.get() / cost + ", errCount:" + errorCount); + } + + List addressList = new ArrayList<>(); + + for (int k = 0; k < testList.length; k++) { + addressList.add(WalletClient.decodeFromBase58Check(testList[k])); + } + + triggerAndGetExtCodeHash(normalContractAddress, user001Address, + user001Key, feeLimit, stub); + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } +} + + diff --git a/src/test/resources/soliditycode/extCodeHashStress.sol b/src/test/resources/soliditycode/extCodeHashStress.sol new file mode 100644 index 00000000000..141090958e8 --- /dev/null +++ b/src/test/resources/soliditycode/extCodeHashStress.sol @@ -0,0 +1,34 @@ +contract Trigger { + function test(address addr) public returns(uint i) { + bytes32 hash; + while (gasleft() > 1000) { + assembly { + hash := extcodehash(addr) + } + i++; + } + } + + function test(address[] memory addrs) public returns(uint i) { + bytes32 hash; + uint i = 0; + for (; i < addrs.length; i++) { + address addr = addrs[i]; + assembly { + hash := extcodehash(addr) + } + } + return i; + } + } + + + + contract TriggerNormal { + function test(address addr) public returns(uint i) { + i = 0; + while (gasleft() > 100000) { + i++; + } + } + } \ No newline at end of file diff --git a/src/test/resources/testng.conf b/src/test/resources/testng.conf index d77bc1cdf90..f2262daf49f 100644 --- a/src/test/resources/testng.conf +++ b/src/test/resources/testng.conf @@ -47,7 +47,6 @@ solidityNode = { "47.94.197.215:18895", #new beta2 "101.200.52.146:18895", - ] } @@ -71,8 +70,6 @@ foundationAccount = { #Main_in_mock_foundationAccount_key #key1 = 7c4977817417495f4ca0c35ab3d5a25e247355d68f89f593f3fea2ab62c8644f #key2 = 1fe1d91bbe3ac4ac5dc9866c157ef7615ec248e3fd4f7d2b49b0428da5e046b2 - - } @@ -307,6 +304,8 @@ code = { code_ContractTrcToken078_AddressTest4 = "6080604052610264806100136000396000f30060806040526004361061003d5763ffffffff60e060020a600035041663648efe8b811461003f578063b45f578b14610059578063d818452114610073575b005b61003d600160a060020a036004358116906024351661008d565b61003d600160a060020a036004358116906024351661011c565b61003d600160a060020a03600435811690602435166101a9565b81600160a060020a031660405180807f7472616e73666572546f286164647265737329000000000000000000000000008152506013019050604051809103902060e060020a9004826040518263ffffffff1660e060020a0281526004018082600160a060020a0316600160a060020a031681526020019150506000604051808303816000875af2505050505050565b81600160a060020a031660405180807f7472616e73666572546f286164647265737329000000000000000000000000008152506013019050604051809103902060e060020a9004826040518263ffffffff1660e060020a0281526004018082600160a060020a0316600160a060020a03168152602001915050600060405180830381865af4505050505050565b81600160a060020a031660405180807f7472616e73666572546f286164647265737329000000000000000000000000008152506013019050604051809103902060e060020a9004826040518263ffffffff1660e060020a0281526004018082600160a060020a0316600160a060020a031681526020019150506000604051808303816000875af15050505050505600a165627a7a7230582068a85b5cb5a41f10a7ba8250baed5adf37129ff04399bccae69e483fc85448a90029" code_ContractTrcToken078_AddressTest5 = "6080604052610166806100136000396000f3006080604052600436106100325763ffffffff60e060020a6000350416630223024e8114610034578063a03fa7e314610055575b005b61003273ffffffffffffffffffffffffffffffffffffffff60043516610076565b61003273ffffffffffffffffffffffffffffffffffffffff600435166100f7565b8073ffffffffffffffffffffffffffffffffffffffff16600560405180807f73657449282900000000000000000000000000000000000000000000000000008152506006019050604051809103902060e060020a9004906040518263ffffffff1660e060020a02815260040160006040518083038185885af1505050505050565b60405173ffffffffffffffffffffffffffffffffffffffff82169060009060059082818181858883f19350505050158015610136573d6000803e3d6000fd5b50505600a165627a7a72305820ede28ac9884104396c5d52bbf3f480cb637f61bc331c2dc561670e6d2700ad630029" code_ContractTrcToken078_AddressTest6 = "6080604052610172806100136000396000f30060806040526004361061004b5763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166367e404ce8114610087578063938b5f32146100df575b6040805132815233602082015281517fdaf0d4aa9a5679e832ac921da67b43572b4326ee2565442d3ed255b48cfb5161929181900390910190a1005b34801561009357600080fd5b50d380156100a057600080fd5b50d280156100ad57600080fd5b506100b661010e565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b3480156100eb57600080fd5b50d380156100f857600080fd5b50d2801561010557600080fd5b506100b661012a565b60015473ffffffffffffffffffffffffffffffffffffffff1681565b60005473ffffffffffffffffffffffffffffffffffffffff16815600a165627a7a7230582084426e82a8fde9cefb0ae9f1561ce743354adada27d217c8614c28829eecbcda0029" + code_veryLarge = "60806040523480156200001157600080fd5b50d380156200001f57600080fd5b50d280156200002d57600080fd5b5061c2ec806200003e6000396000f3fe6080604052600436106200003c577c010000000000000000000000000000000000000000000000000000000060003504631a695230811462000041575b600080fd5b62000077600480360360208110156200005957600080fd5b503573ffffffffffffffffffffffffffffffffffffffff1662000079565b005b6040516000906200008a906200c1dc565b604051809103906000f080158015620000a7573d6000803e3d6000fd5b5050604051620000b7906200c1dc565b604051809103906000f080158015620000d4573d6000803e3d6000fd5b5050604051620000e4906200c1dc565b604051809103906000f08015801562000101573d6000803e3d6000fd5b505060405162000111906200c1dc565b604051809103906000f0801580156200012e573d6000803e3d6000fd5b50506040516200013e906200c1dc565b604051809103906000f0801580156200015b573d6000803e3d6000fd5b50506040516200016b906200c1dc565b604051809103906000f08015801562000188573d6000803e3d6000fd5b505060405162000198906200c1dc565b604051809103906000f080158015620001b5573d6000803e3d6000fd5b5050604051620001c5906200c1dc565b604051809103906000f080158015620001e2573d6000803e3d6000fd5b5050604051620001f2906200c1dc565b604051809103906000f0801580156200020f573d6000803e3d6000fd5b50506040516200021f906200c1dc565b604051809103906000f0801580156200023c573d6000803e3d6000fd5b50506040516200024c906200c1dc565b604051809103906000f08015801562000269573d6000803e3d6000fd5b505060405162000279906200c1dc565b604051809103906000f08015801562000296573d6000803e3d6000fd5b5050604051620002a6906200c1dc565b604051809103906000f080158015620002c3573d6000803e3d6000fd5b5050604051620002d3906200c1dc565b604051809103906000f080158015620002f0573d6000803e3d6000fd5b505060405162000300906200c1dc565b604051809103906000f0801580156200031d573d6000803e3d6000fd5b50506040516200032d906200c1dc565b604051809103906000f0801580156200034a573d6000803e3d6000fd5b50506040516200035a906200c1dc565b604051809103906000f08015801562000377573d6000803e3d6000fd5b505060405162000387906200c1dc565b604051809103906000f080158015620003a4573d6000803e3d6000fd5b5050604051620003b4906200c1dc565b604051809103906000f080158015620003d1573d6000803e3d6000fd5b5050604051620003e1906200c1dc565b604051809103906000f080158015620003fe573d6000803e3d6000fd5b50506040516200040e906200c1dc565b604051809103906000f0801580156200042b573d6000803e3d6000fd5b50506040516200043b906200c1dc565b604051809103906000f08015801562000458573d6000803e3d6000fd5b505060405162000468906200c1dc565b604051809103906000f08015801562000485573d6000803e3d6000fd5b505060405162000495906200c1dc565b604051809103906000f080158015620004b2573d6000803e3d6000fd5b5050604051620004c2906200c1dc565b604051809103906000f080158015620004df573d6000803e3d6000fd5b5050604051620004ef906200c1dc565b604051809103906000f0801580156200050c573d6000803e3d6000fd5b50506040516200051c906200c1dc565b604051809103906000f08015801562000539573d6000803e3d6000fd5b505060405162000549906200c1dc565b604051809103906000f08015801562000566573d6000803e3d6000fd5b505060405162000576906200c1dc565b604051809103906000f08015801562000593573d6000803e3d6000fd5b5050604051620005a3906200c1dc565b604051809103906000f080158015620005c0573d6000803e3d6000fd5b5050604051620005d0906200c1dc565b604051809103906000f080158015620005ed573d6000803e3d6000fd5b5050604051620005fd906200c1dc565b604051809103906000f0801580156200061a573d6000803e3d6000fd5b50506040516200062a906200c1dc565b604051809103906000f08015801562000647573d6000803e3d6000fd5b505060405162000657906200c1dc565b604051809103906000f08015801562000674573d6000803e3d6000fd5b505060405162000684906200c1dc565b604051809103906000f080158015620006a1573d6000803e3d6000fd5b5050604051620006b1906200c1dc565b604051809103906000f080158015620006ce573d6000803e3d6000fd5b5050604051620006de906200c1dc565b604051809103906000f080158015620006fb573d6000803e3d6000fd5b50506040516200070b906200c1dc565b604051809103906000f08015801562000728573d6000803e3d6000fd5b505060405162000738906200c1dc565b604051809103906000f08015801562000755573d6000803e3d6000fd5b505060405162000765906200c1dc565b604051809103906000f08015801562000782573d6000803e3d6000fd5b505060405162000792906200c1dc565b604051809103906000f080158015620007af573d6000803e3d6000fd5b5050604051620007bf906200c1dc565b604051809103906000f080158015620007dc573d6000803e3d6000fd5b5050604051620007ec906200c1dc565b604051809103906000f08015801562000809573d6000803e3d6000fd5b505060405162000819906200c1dc565b604051809103906000f08015801562000836573d6000803e3d6000fd5b505060405162000846906200c1dc565b604051809103906000f08015801562000863573d6000803e3d6000fd5b505060405162000873906200c1dc565b604051809103906000f08015801562000890573d6000803e3d6000fd5b5050604051620008a0906200c1dc565b604051809103906000f080158015620008bd573d6000803e3d6000fd5b5050604051620008cd906200c1dc565b604051809103906000f080158015620008ea573d6000803e3d6000fd5b5050604051620008fa906200c1dc565b604051809103906000f08015801562000917573d6000803e3d6000fd5b505060405162000927906200c1dc565b604051809103906000f08015801562000944573d6000803e3d6000fd5b505060405162000954906200c1dc565b604051809103906000f08015801562000971573d6000803e3d6000fd5b505060405162000981906200c1dc565b604051809103906000f0801580156200099e573d6000803e3d6000fd5b5050604051620009ae906200c1dc565b604051809103906000f080158015620009cb573d6000803e3d6000fd5b5050604051620009db906200c1dc565b604051809103906000f080158015620009f8573d6000803e3d6000fd5b505060405162000a08906200c1dc565b604051809103906000f08015801562000a25573d6000803e3d6000fd5b505060405162000a35906200c1dc565b604051809103906000f08015801562000a52573d6000803e3d6000fd5b505060405162000a62906200c1dc565b604051809103906000f08015801562000a7f573d6000803e3d6000fd5b505060405162000a8f906200c1dc565b604051809103906000f08015801562000aac573d6000803e3d6000fd5b505060405162000abc906200c1dc565b604051809103906000f08015801562000ad9573d6000803e3d6000fd5b505060405162000ae9906200c1dc565b604051809103906000f08015801562000b06573d6000803e3d6000fd5b505060405162000b16906200c1dc565b604051809103906000f08015801562000b33573d6000803e3d6000fd5b505060405162000b43906200c1dc565b604051809103906000f08015801562000b60573d6000803e3d6000fd5b505060405162000b70906200c1dc565b604051809103906000f08015801562000b8d573d6000803e3d6000fd5b505060405162000b9d906200c1dc565b604051809103906000f08015801562000bba573d6000803e3d6000fd5b505060405162000bca906200c1dc565b604051809103906000f08015801562000be7573d6000803e3d6000fd5b505060405162000bf7906200c1dc565b604051809103906000f08015801562000c14573d6000803e3d6000fd5b505060405162000c24906200c1dc565b604051809103906000f08015801562000c41573d6000803e3d6000fd5b505060405162000c51906200c1dc565b604051809103906000f08015801562000c6e573d6000803e3d6000fd5b505060405162000c7e906200c1dc565b604051809103906000f08015801562000c9b573d6000803e3d6000fd5b505060405162000cab906200c1dc565b604051809103906000f08015801562000cc8573d6000803e3d6000fd5b505060405162000cd8906200c1dc565b604051809103906000f08015801562000cf5573d6000803e3d6000fd5b505060405162000d05906200c1dc565b604051809103906000f08015801562000d22573d6000803e3d6000fd5b505060405162000d32906200c1dc565b604051809103906000f08015801562000d4f573d6000803e3d6000fd5b505060405162000d5f906200c1dc565b604051809103906000f08015801562000d7c573d6000803e3d6000fd5b505060405162000d8c906200c1dc565b604051809103906000f08015801562000da9573d6000803e3d6000fd5b505060405162000db9906200c1dc565b604051809103906000f08015801562000dd6573d6000803e3d6000fd5b505060405162000de6906200c1dc565b604051809103906000f08015801562000e03573d6000803e3d6000fd5b505060405162000e13906200c1dc565b604051809103906000f08015801562000e30573d6000803e3d6000fd5b505060405162000e40906200c1dc565b604051809103906000f08015801562000e5d573d6000803e3d6000fd5b505060405162000e6d906200c1dc565b604051809103906000f08015801562000e8a573d6000803e3d6000fd5b505060405162000e9a906200c1dc565b604051809103906000f08015801562000eb7573d6000803e3d6000fd5b505060405162000ec7906200c1dc565b604051809103906000f08015801562000ee4573d6000803e3d6000fd5b505060405162000ef4906200c1dc565b604051809103906000f08015801562000f11573d6000803e3d6000fd5b505060405162000f21906200c1dc565b604051809103906000f08015801562000f3e573d6000803e3d6000fd5b505060405162000f4e906200c1dc565b604051809103906000f08015801562000f6b573d6000803e3d6000fd5b505060405162000f7b906200c1dc565b604051809103906000f08015801562000f98573d6000803e3d6000fd5b505060405162000fa8906200c1dc565b604051809103906000f08015801562000fc5573d6000803e3d6000fd5b505060405162000fd5906200c1dc565b604051809103906000f08015801562000ff2573d6000803e3d6000fd5b505060405162001002906200c1dc565b604051809103906000f0801580156200101f573d6000803e3d6000fd5b50506040516200102f906200c1dc565b604051809103906000f0801580156200104c573d6000803e3d6000fd5b50506040516200105c906200c1dc565b604051809103906000f08015801562001079573d6000803e3d6000fd5b505060405162001089906200c1dc565b604051809103906000f080158015620010a6573d6000803e3d6000fd5b5050604051620010b6906200c1dc565b604051809103906000f080158015620010d3573d6000803e3d6000fd5b5050604051620010e3906200c1dc565b604051809103906000f08015801562001100573d6000803e3d6000fd5b505060405162001110906200c1dc565b604051809103906000f0801580156200112d573d6000803e3d6000fd5b50506040516200113d906200c1dc565b604051809103906000f0801580156200115a573d6000803e3d6000fd5b50506040516200116a906200c1dc565b604051809103906000f08015801562001187573d6000803e3d6000fd5b505060405162001197906200c1dc565b604051809103906000f080158015620011b4573d6000803e3d6000fd5b5050604051620011c4906200c1dc565b604051809103906000f080158015620011e1573d6000803e3d6000fd5b5050604051620011f1906200c1dc565b604051809103906000f0801580156200120e573d6000803e3d6000fd5b50506040516200121e906200c1dc565b604051809103906000f0801580156200123b573d6000803e3d6000fd5b50506040516200124b906200c1dc565b604051809103906000f08015801562001268573d6000803e3d6000fd5b505060405162001278906200c1dc565b604051809103906000f08015801562001295573d6000803e3d6000fd5b5050604051620012a5906200c1dc565b604051809103906000f080158015620012c2573d6000803e3d6000fd5b5050604051620012d2906200c1dc565b604051809103906000f080158015620012ef573d6000803e3d6000fd5b5050604051620012ff906200c1dc565b604051809103906000f0801580156200131c573d6000803e3d6000fd5b50506040516200132c906200c1dc565b604051809103906000f08015801562001349573d6000803e3d6000fd5b505060405162001359906200c1dc565b604051809103906000f08015801562001376573d6000803e3d6000fd5b505060405162001386906200c1dc565b604051809103906000f080158015620013a3573d6000803e3d6000fd5b5050604051620013b3906200c1dc565b604051809103906000f080158015620013d0573d6000803e3d6000fd5b5050604051620013e0906200c1dc565b604051809103906000f080158015620013fd573d6000803e3d6000fd5b50506040516200140d906200c1dc565b604051809103906000f0801580156200142a573d6000803e3d6000fd5b50506040516200143a906200c1dc565b604051809103906000f08015801562001457573d6000803e3d6000fd5b505060405162001467906200c1dc565b604051809103906000f08015801562001484573d6000803e3d6000fd5b505060405162001494906200c1dc565b604051809103906000f080158015620014b1573d6000803e3d6000fd5b5050604051620014c1906200c1dc565b604051809103906000f080158015620014de573d6000803e3d6000fd5b5050604051620014ee906200c1dc565b604051809103906000f0801580156200150b573d6000803e3d6000fd5b50506040516200151b906200c1dc565b604051809103906000f08015801562001538573d6000803e3d6000fd5b505060405162001548906200c1dc565b604051809103906000f08015801562001565573d6000803e3d6000fd5b505060405162001575906200c1dc565b604051809103906000f08015801562001592573d6000803e3d6000fd5b5050604051620015a2906200c1dc565b604051809103906000f080158015620015bf573d6000803e3d6000fd5b5050604051620015cf906200c1dc565b604051809103906000f080158015620015ec573d6000803e3d6000fd5b5050604051620015fc906200c1dc565b604051809103906000f08015801562001619573d6000803e3d6000fd5b505060405162001629906200c1dc565b604051809103906000f08015801562001646573d6000803e3d6000fd5b505060405162001656906200c1dc565b604051809103906000f08015801562001673573d6000803e3d6000fd5b505060405162001683906200c1dc565b604051809103906000f080158015620016a0573d6000803e3d6000fd5b5050604051620016b0906200c1dc565b604051809103906000f080158015620016cd573d6000803e3d6000fd5b5050604051620016dd906200c1dc565b604051809103906000f080158015620016fa573d6000803e3d6000fd5b50506040516200170a906200c1dc565b604051809103906000f08015801562001727573d6000803e3d6000fd5b505060405162001737906200c1dc565b604051809103906000f08015801562001754573d6000803e3d6000fd5b505060405162001764906200c1dc565b604051809103906000f08015801562001781573d6000803e3d6000fd5b505060405162001791906200c1dc565b604051809103906000f080158015620017ae573d6000803e3d6000fd5b5050604051620017be906200c1dc565b604051809103906000f080158015620017db573d6000803e3d6000fd5b5050604051620017eb906200c1dc565b604051809103906000f08015801562001808573d6000803e3d6000fd5b505060405162001818906200c1dc565b604051809103906000f08015801562001835573d6000803e3d6000fd5b505060405162001845906200c1dc565b604051809103906000f08015801562001862573d6000803e3d6000fd5b505060405162001872906200c1dc565b604051809103906000f0801580156200188f573d6000803e3d6000fd5b50506040516200189f906200c1dc565b604051809103906000f080158015620018bc573d6000803e3d6000fd5b5050604051620018cc906200c1dc565b604051809103906000f080158015620018e9573d6000803e3d6000fd5b5050604051620018f9906200c1dc565b604051809103906000f08015801562001916573d6000803e3d6000fd5b505060405162001926906200c1dc565b604051809103906000f08015801562001943573d6000803e3d6000fd5b505060405162001953906200c1dc565b604051809103906000f08015801562001970573d6000803e3d6000fd5b505060405162001980906200c1dc565b604051809103906000f0801580156200199d573d6000803e3d6000fd5b5050604051620019ad906200c1dc565b604051809103906000f080158015620019ca573d6000803e3d6000fd5b5050604051620019da906200c1dc565b604051809103906000f080158015620019f7573d6000803e3d6000fd5b505060405162001a07906200c1dc565b604051809103906000f08015801562001a24573d6000803e3d6000fd5b505060405162001a34906200c1dc565b604051809103906000f08015801562001a51573d6000803e3d6000fd5b505060405162001a61906200c1dc565b604051809103906000f08015801562001a7e573d6000803e3d6000fd5b505060405162001a8e906200c1dc565b604051809103906000f08015801562001aab573d6000803e3d6000fd5b505060405162001abb906200c1dc565b604051809103906000f08015801562001ad8573d6000803e3d6000fd5b505060405162001ae8906200c1dc565b604051809103906000f08015801562001b05573d6000803e3d6000fd5b505060405162001b15906200c1dc565b604051809103906000f08015801562001b32573d6000803e3d6000fd5b505060405162001b42906200c1dc565b604051809103906000f08015801562001b5f573d6000803e3d6000fd5b505060405162001b6f906200c1dc565b604051809103906000f08015801562001b8c573d6000803e3d6000fd5b505060405162001b9c906200c1dc565b604051809103906000f08015801562001bb9573d6000803e3d6000fd5b505060405162001bc9906200c1dc565b604051809103906000f08015801562001be6573d6000803e3d6000fd5b505060405162001bf6906200c1dc565b604051809103906000f08015801562001c13573d6000803e3d6000fd5b505060405162001c23906200c1dc565b604051809103906000f08015801562001c40573d6000803e3d6000fd5b505060405162001c50906200c1dc565b604051809103906000f08015801562001c6d573d6000803e3d6000fd5b505060405162001c7d906200c1dc565b604051809103906000f08015801562001c9a573d6000803e3d6000fd5b505060405162001caa906200c1dc565b604051809103906000f08015801562001cc7573d6000803e3d6000fd5b505060405162001cd7906200c1dc565b604051809103906000f08015801562001cf4573d6000803e3d6000fd5b505060405162001d04906200c1dc565b604051809103906000f08015801562001d21573d6000803e3d6000fd5b505060405162001d31906200c1dc565b604051809103906000f08015801562001d4e573d6000803e3d6000fd5b505060405162001d5e906200c1dc565b604051809103906000f08015801562001d7b573d6000803e3d6000fd5b505060405162001d8b906200c1dc565b604051809103906000f08015801562001da8573d6000803e3d6000fd5b505060405162001db8906200c1dc565b604051809103906000f08015801562001dd5573d6000803e3d6000fd5b505060405162001de5906200c1dc565b604051809103906000f08015801562001e02573d6000803e3d6000fd5b505060405162001e12906200c1dc565b604051809103906000f08015801562001e2f573d6000803e3d6000fd5b505060405162001e3f906200c1dc565b604051809103906000f08015801562001e5c573d6000803e3d6000fd5b505060405162001e6c906200c1dc565b604051809103906000f08015801562001e89573d6000803e3d6000fd5b505060405162001e99906200c1dc565b604051809103906000f08015801562001eb6573d6000803e3d6000fd5b505060405162001ec6906200c1dc565b604051809103906000f08015801562001ee3573d6000803e3d6000fd5b505060405162001ef3906200c1dc565b604051809103906000f08015801562001f10573d6000803e3d6000fd5b505060405162001f20906200c1dc565b604051809103906000f08015801562001f3d573d6000803e3d6000fd5b505060405162001f4d906200c1dc565b604051809103906000f08015801562001f6a573d6000803e3d6000fd5b505060405162001f7a906200c1dc565b604051809103906000f08015801562001f97573d6000803e3d6000fd5b505060405162001fa7906200c1dc565b604051809103906000f08015801562001fc4573d6000803e3d6000fd5b505060405162001fd4906200c1dc565b604051809103906000f08015801562001ff1573d6000803e3d6000fd5b505060405162002001906200c1dc565b604051809103906000f0801580156200201e573d6000803e3d6000fd5b50506040516200202e906200c1dc565b604051809103906000f0801580156200204b573d6000803e3d6000fd5b50506040516200205b906200c1dc565b604051809103906000f08015801562002078573d6000803e3d6000fd5b505060405162002088906200c1dc565b604051809103906000f080158015620020a5573d6000803e3d6000fd5b5050604051620020b5906200c1dc565b604051809103906000f080158015620020d2573d6000803e3d6000fd5b5050604051620020e2906200c1dc565b604051809103906000f080158015620020ff573d6000803e3d6000fd5b50506040516200210f906200c1dc565b604051809103906000f0801580156200212c573d6000803e3d6000fd5b50506040516200213c906200c1dc565b604051809103906000f08015801562002159573d6000803e3d6000fd5b505060405162002169906200c1dc565b604051809103906000f08015801562002186573d6000803e3d6000fd5b505060405162002196906200c1dc565b604051809103906000f080158015620021b3573d6000803e3d6000fd5b5050604051620021c3906200c1dc565b604051809103906000f080158015620021e0573d6000803e3d6000fd5b5050604051620021f0906200c1dc565b604051809103906000f0801580156200220d573d6000803e3d6000fd5b50506040516200221d906200c1dc565b604051809103906000f0801580156200223a573d6000803e3d6000fd5b50506040516200224a906200c1dc565b604051809103906000f08015801562002267573d6000803e3d6000fd5b505060405162002277906200c1dc565b604051809103906000f08015801562002294573d6000803e3d6000fd5b5050604051620022a4906200c1dc565b604051809103906000f080158015620022c1573d6000803e3d6000fd5b5050604051620022d1906200c1dc565b604051809103906000f080158015620022ee573d6000803e3d6000fd5b5050604051620022fe906200c1dc565b604051809103906000f0801580156200231b573d6000803e3d6000fd5b50506040516200232b906200c1dc565b604051809103906000f08015801562002348573d6000803e3d6000fd5b505060405162002358906200c1dc565b604051809103906000f08015801562002375573d6000803e3d6000fd5b505060405162002385906200c1dc565b604051809103906000f080158015620023a2573d6000803e3d6000fd5b5050604051620023b2906200c1dc565b604051809103906000f080158015620023cf573d6000803e3d6000fd5b5050604051620023df906200c1dc565b604051809103906000f080158015620023fc573d6000803e3d6000fd5b50506040516200240c906200c1dc565b604051809103906000f08015801562002429573d6000803e3d6000fd5b505060405162002439906200c1dc565b604051809103906000f08015801562002456573d6000803e3d6000fd5b505060405162002466906200c1dc565b604051809103906000f08015801562002483573d6000803e3d6000fd5b505060405162002493906200c1dc565b604051809103906000f080158015620024b0573d6000803e3d6000fd5b5050604051620024c0906200c1dc565b604051809103906000f080158015620024dd573d6000803e3d6000fd5b5050604051620024ed906200c1dc565b604051809103906000f0801580156200250a573d6000803e3d6000fd5b50506040516200251a906200c1dc565b604051809103906000f08015801562002537573d6000803e3d6000fd5b505060405162002547906200c1dc565b604051809103906000f08015801562002564573d6000803e3d6000fd5b505060405162002574906200c1dc565b604051809103906000f08015801562002591573d6000803e3d6000fd5b5050604051620025a1906200c1dc565b604051809103906000f080158015620025be573d6000803e3d6000fd5b5050604051620025ce906200c1dc565b604051809103906000f080158015620025eb573d6000803e3d6000fd5b5050604051620025fb906200c1dc565b604051809103906000f08015801562002618573d6000803e3d6000fd5b505060405162002628906200c1dc565b604051809103906000f08015801562002645573d6000803e3d6000fd5b505060405162002655906200c1dc565b604051809103906000f08015801562002672573d6000803e3d6000fd5b505060405162002682906200c1dc565b604051809103906000f0801580156200269f573d6000803e3d6000fd5b5050604051620026af906200c1dc565b604051809103906000f080158015620026cc573d6000803e3d6000fd5b5050604051620026dc906200c1dc565b604051809103906000f080158015620026f9573d6000803e3d6000fd5b505060405162002709906200c1dc565b604051809103906000f08015801562002726573d6000803e3d6000fd5b505060405162002736906200c1dc565b604051809103906000f08015801562002753573d6000803e3d6000fd5b505060405162002763906200c1dc565b604051809103906000f08015801562002780573d6000803e3d6000fd5b505060405162002790906200c1dc565b604051809103906000f080158015620027ad573d6000803e3d6000fd5b5050604051620027bd906200c1dc565b604051809103906000f080158015620027da573d6000803e3d6000fd5b5050604051620027ea906200c1dc565b604051809103906000f08015801562002807573d6000803e3d6000fd5b505060405162002817906200c1dc565b604051809103906000f08015801562002834573d6000803e3d6000fd5b505060405162002844906200c1dc565b604051809103906000f08015801562002861573d6000803e3d6000fd5b505060405162002871906200c1dc565b604051809103906000f0801580156200288e573d6000803e3d6000fd5b50506040516200289e906200c1dc565b604051809103906000f080158015620028bb573d6000803e3d6000fd5b5050604051620028cb906200c1dc565b604051809103906000f080158015620028e8573d6000803e3d6000fd5b5050604051620028f8906200c1dc565b604051809103906000f08015801562002915573d6000803e3d6000fd5b505060405162002925906200c1dc565b604051809103906000f08015801562002942573d6000803e3d6000fd5b505060405162002952906200c1dc565b604051809103906000f0801580156200296f573d6000803e3d6000fd5b50506040516200297f906200c1dc565b604051809103906000f0801580156200299c573d6000803e3d6000fd5b5050604051620029ac906200c1dc565b604051809103906000f080158015620029c9573d6000803e3d6000fd5b5050604051620029d9906200c1dc565b604051809103906000f080158015620029f6573d6000803e3d6000fd5b505060405162002a06906200c1dc565b604051809103906000f08015801562002a23573d6000803e3d6000fd5b505060405162002a33906200c1dc565b604051809103906000f08015801562002a50573d6000803e3d6000fd5b505060405162002a60906200c1dc565b604051809103906000f08015801562002a7d573d6000803e3d6000fd5b505060405162002a8d906200c1dc565b604051809103906000f08015801562002aaa573d6000803e3d6000fd5b505060405162002aba906200c1dc565b604051809103906000f08015801562002ad7573d6000803e3d6000fd5b505060405162002ae7906200c1dc565b604051809103906000f08015801562002b04573d6000803e3d6000fd5b505060405162002b14906200c1dc565b604051809103906000f08015801562002b31573d6000803e3d6000fd5b505060405162002b41906200c1dc565b604051809103906000f08015801562002b5e573d6000803e3d6000fd5b505060405162002b6e906200c1dc565b604051809103906000f08015801562002b8b573d6000803e3d6000fd5b505060405162002b9b906200c1dc565b604051809103906000f08015801562002bb8573d6000803e3d6000fd5b505060405162002bc8906200c1dc565b604051809103906000f08015801562002be5573d6000803e3d6000fd5b505060405162002bf5906200c1dc565b604051809103906000f08015801562002c12573d6000803e3d6000fd5b505060405162002c22906200c1dc565b604051809103906000f08015801562002c3f573d6000803e3d6000fd5b505060405162002c4f906200c1dc565b604051809103906000f08015801562002c6c573d6000803e3d6000fd5b505060405162002c7c906200c1dc565b604051809103906000f08015801562002c99573d6000803e3d6000fd5b505060405162002ca9906200c1dc565b604051809103906000f08015801562002cc6573d6000803e3d6000fd5b505060405162002cd6906200c1dc565b604051809103906000f08015801562002cf3573d6000803e3d6000fd5b505060405162002d03906200c1dc565b604051809103906000f08015801562002d20573d6000803e3d6000fd5b505060405162002d30906200c1dc565b604051809103906000f08015801562002d4d573d6000803e3d6000fd5b505060405162002d5d906200c1dc565b604051809103906000f08015801562002d7a573d6000803e3d6000fd5b505060405162002d8a906200c1dc565b604051809103906000f08015801562002da7573d6000803e3d6000fd5b505060405162002db7906200c1dc565b604051809103906000f08015801562002dd4573d6000803e3d6000fd5b505060405162002de4906200c1dc565b604051809103906000f08015801562002e01573d6000803e3d6000fd5b505060405162002e11906200c1dc565b604051809103906000f08015801562002e2e573d6000803e3d6000fd5b505060405162002e3e906200c1dc565b604051809103906000f08015801562002e5b573d6000803e3d6000fd5b505060405162002e6b906200c1dc565b604051809103906000f08015801562002e88573d6000803e3d6000fd5b505060405162002e98906200c1dc565b604051809103906000f08015801562002eb5573d6000803e3d6000fd5b505060405162002ec5906200c1dc565b604051809103906000f08015801562002ee2573d6000803e3d6000fd5b505060405162002ef2906200c1dc565b604051809103906000f08015801562002f0f573d6000803e3d6000fd5b505060405162002f1f906200c1dc565b604051809103906000f08015801562002f3c573d6000803e3d6000fd5b505060405162002f4c906200c1dc565b604051809103906000f08015801562002f69573d6000803e3d6000fd5b505060405162002f79906200c1dc565b604051809103906000f08015801562002f96573d6000803e3d6000fd5b505060405162002fa6906200c1dc565b604051809103906000f08015801562002fc3573d6000803e3d6000fd5b505060405162002fd3906200c1dc565b604051809103906000f08015801562002ff0573d6000803e3d6000fd5b505060405162003000906200c1dc565b604051809103906000f0801580156200301d573d6000803e3d6000fd5b50506040516200302d906200c1dc565b604051809103906000f0801580156200304a573d6000803e3d6000fd5b50506040516200305a906200c1dc565b604051809103906000f08015801562003077573d6000803e3d6000fd5b505060405162003087906200c1dc565b604051809103906000f080158015620030a4573d6000803e3d6000fd5b5050604051620030b4906200c1dc565b604051809103906000f080158015620030d1573d6000803e3d6000fd5b5050604051620030e1906200c1dc565b604051809103906000f080158015620030fe573d6000803e3d6000fd5b50506040516200310e906200c1dc565b604051809103906000f0801580156200312b573d6000803e3d6000fd5b50506040516200313b906200c1dc565b604051809103906000f08015801562003158573d6000803e3d6000fd5b505060405162003168906200c1dc565b604051809103906000f08015801562003185573d6000803e3d6000fd5b505060405162003195906200c1dc565b604051809103906000f080158015620031b2573d6000803e3d6000fd5b5050604051620031c2906200c1dc565b604051809103906000f080158015620031df573d6000803e3d6000fd5b5050604051620031ef906200c1dc565b604051809103906000f0801580156200320c573d6000803e3d6000fd5b50506040516200321c906200c1dc565b604051809103906000f08015801562003239573d6000803e3d6000fd5b505060405162003249906200c1dc565b604051809103906000f08015801562003266573d6000803e3d6000fd5b505060405162003276906200c1dc565b604051809103906000f08015801562003293573d6000803e3d6000fd5b5050604051620032a3906200c1dc565b604051809103906000f080158015620032c0573d6000803e3d6000fd5b5050604051620032d0906200c1dc565b604051809103906000f080158015620032ed573d6000803e3d6000fd5b5050604051620032fd906200c1dc565b604051809103906000f0801580156200331a573d6000803e3d6000fd5b50506040516200332a906200c1dc565b604051809103906000f08015801562003347573d6000803e3d6000fd5b505060405162003357906200c1dc565b604051809103906000f08015801562003374573d6000803e3d6000fd5b505060405162003384906200c1dc565b604051809103906000f080158015620033a1573d6000803e3d6000fd5b5050604051620033b1906200c1dc565b604051809103906000f080158015620033ce573d6000803e3d6000fd5b5050604051620033de906200c1dc565b604051809103906000f080158015620033fb573d6000803e3d6000fd5b50506040516200340b906200c1dc565b604051809103906000f08015801562003428573d6000803e3d6000fd5b505060405162003438906200c1dc565b604051809103906000f08015801562003455573d6000803e3d6000fd5b505060405162003465906200c1dc565b604051809103906000f08015801562003482573d6000803e3d6000fd5b505060405162003492906200c1dc565b604051809103906000f080158015620034af573d6000803e3d6000fd5b5050604051620034bf906200c1dc565b604051809103906000f080158015620034dc573d6000803e3d6000fd5b5050604051620034ec906200c1dc565b604051809103906000f08015801562003509573d6000803e3d6000fd5b505060405162003519906200c1dc565b604051809103906000f08015801562003536573d6000803e3d6000fd5b505060405162003546906200c1dc565b604051809103906000f08015801562003563573d6000803e3d6000fd5b505060405162003573906200c1dc565b604051809103906000f08015801562003590573d6000803e3d6000fd5b5050604051620035a0906200c1dc565b604051809103906000f080158015620035bd573d6000803e3d6000fd5b5050604051620035cd906200c1dc565b604051809103906000f080158015620035ea573d6000803e3d6000fd5b5050604051620035fa906200c1dc565b604051809103906000f08015801562003617573d6000803e3d6000fd5b505060405162003627906200c1dc565b604051809103906000f08015801562003644573d6000803e3d6000fd5b505060405162003654906200c1dc565b604051809103906000f08015801562003671573d6000803e3d6000fd5b505060405162003681906200c1dc565b604051809103906000f0801580156200369e573d6000803e3d6000fd5b5050604051620036ae906200c1dc565b604051809103906000f080158015620036cb573d6000803e3d6000fd5b5050604051620036db906200c1dc565b604051809103906000f080158015620036f8573d6000803e3d6000fd5b505060405162003708906200c1dc565b604051809103906000f08015801562003725573d6000803e3d6000fd5b505060405162003735906200c1dc565b604051809103906000f08015801562003752573d6000803e3d6000fd5b505060405162003762906200c1dc565b604051809103906000f0801580156200377f573d6000803e3d6000fd5b50506040516200378f906200c1dc565b604051809103906000f080158015620037ac573d6000803e3d6000fd5b5050604051620037bc906200c1dc565b604051809103906000f080158015620037d9573d6000803e3d6000fd5b5050604051620037e9906200c1dc565b604051809103906000f08015801562003806573d6000803e3d6000fd5b505060405162003816906200c1dc565b604051809103906000f08015801562003833573d6000803e3d6000fd5b505060405162003843906200c1dc565b604051809103906000f08015801562003860573d6000803e3d6000fd5b505060405162003870906200c1dc565b604051809103906000f0801580156200388d573d6000803e3d6000fd5b50506040516200389d906200c1dc565b604051809103906000f080158015620038ba573d6000803e3d6000fd5b5050604051620038ca906200c1dc565b604051809103906000f080158015620038e7573d6000803e3d6000fd5b5050604051620038f7906200c1dc565b604051809103906000f08015801562003914573d6000803e3d6000fd5b505060405162003924906200c1dc565b604051809103906000f08015801562003941573d6000803e3d6000fd5b505060405162003951906200c1dc565b604051809103906000f0801580156200396e573d6000803e3d6000fd5b50506040516200397e906200c1dc565b604051809103906000f0801580156200399b573d6000803e3d6000fd5b5050604051620039ab906200c1dc565b604051809103906000f080158015620039c8573d6000803e3d6000fd5b5050604051620039d8906200c1dc565b604051809103906000f080158015620039f5573d6000803e3d6000fd5b505060405162003a05906200c1dc565b604051809103906000f08015801562003a22573d6000803e3d6000fd5b505060405162003a32906200c1dc565b604051809103906000f08015801562003a4f573d6000803e3d6000fd5b505060405162003a5f906200c1dc565b604051809103906000f08015801562003a7c573d6000803e3d6000fd5b505060405162003a8c906200c1dc565b604051809103906000f08015801562003aa9573d6000803e3d6000fd5b505060405162003ab9906200c1dc565b604051809103906000f08015801562003ad6573d6000803e3d6000fd5b505060405162003ae6906200c1dc565b604051809103906000f08015801562003b03573d6000803e3d6000fd5b505060405162003b13906200c1dc565b604051809103906000f08015801562003b30573d6000803e3d6000fd5b505060405162003b40906200c1dc565b604051809103906000f08015801562003b5d573d6000803e3d6000fd5b505060405162003b6d906200c1dc565b604051809103906000f08015801562003b8a573d6000803e3d6000fd5b505060405162003b9a906200c1dc565b604051809103906000f08015801562003bb7573d6000803e3d6000fd5b505060405162003bc7906200c1dc565b604051809103906000f08015801562003be4573d6000803e3d6000fd5b505060405162003bf4906200c1dc565b604051809103906000f08015801562003c11573d6000803e3d6000fd5b505060405162003c21906200c1dc565b604051809103906000f08015801562003c3e573d6000803e3d6000fd5b505060405162003c4e906200c1dc565b604051809103906000f08015801562003c6b573d6000803e3d6000fd5b505060405162003c7b906200c1dc565b604051809103906000f08015801562003c98573d6000803e3d6000fd5b505060405162003ca8906200c1dc565b604051809103906000f08015801562003cc5573d6000803e3d6000fd5b505060405162003cd5906200c1dc565b604051809103906000f08015801562003cf2573d6000803e3d6000fd5b505060405162003d02906200c1dc565b604051809103906000f08015801562003d1f573d6000803e3d6000fd5b505060405162003d2f906200c1dc565b604051809103906000f08015801562003d4c573d6000803e3d6000fd5b505060405162003d5c906200c1dc565b604051809103906000f08015801562003d79573d6000803e3d6000fd5b505060405162003d89906200c1dc565b604051809103906000f08015801562003da6573d6000803e3d6000fd5b505060405162003db6906200c1dc565b604051809103906000f08015801562003dd3573d6000803e3d6000fd5b505060405162003de3906200c1dc565b604051809103906000f08015801562003e00573d6000803e3d6000fd5b505060405162003e10906200c1dc565b604051809103906000f08015801562003e2d573d6000803e3d6000fd5b505060405162003e3d906200c1dc565b604051809103906000f08015801562003e5a573d6000803e3d6000fd5b505060405162003e6a906200c1dc565b604051809103906000f08015801562003e87573d6000803e3d6000fd5b505060405162003e97906200c1dc565b604051809103906000f08015801562003eb4573d6000803e3d6000fd5b505060405162003ec4906200c1dc565b604051809103906000f08015801562003ee1573d6000803e3d6000fd5b505060405162003ef1906200c1dc565b604051809103906000f08015801562003f0e573d6000803e3d6000fd5b505060405162003f1e906200c1dc565b604051809103906000f08015801562003f3b573d6000803e3d6000fd5b505060405162003f4b906200c1dc565b604051809103906000f08015801562003f68573d6000803e3d6000fd5b505060405162003f78906200c1dc565b604051809103906000f08015801562003f95573d6000803e3d6000fd5b505060405162003fa5906200c1dc565b604051809103906000f08015801562003fc2573d6000803e3d6000fd5b505060405162003fd2906200c1dc565b604051809103906000f08015801562003fef573d6000803e3d6000fd5b505060405162003fff906200c1dc565b604051809103906000f0801580156200401c573d6000803e3d6000fd5b50506040516200402c906200c1dc565b604051809103906000f08015801562004049573d6000803e3d6000fd5b505060405162004059906200c1dc565b604051809103906000f08015801562004076573d6000803e3d6000fd5b505060405162004086906200c1dc565b604051809103906000f080158015620040a3573d6000803e3d6000fd5b5050604051620040b3906200c1dc565b604051809103906000f080158015620040d0573d6000803e3d6000fd5b5050604051620040e0906200c1dc565b604051809103906000f080158015620040fd573d6000803e3d6000fd5b50506040516200410d906200c1dc565b604051809103906000f0801580156200412a573d6000803e3d6000fd5b50506040516200413a906200c1dc565b604051809103906000f08015801562004157573d6000803e3d6000fd5b505060405162004167906200c1dc565b604051809103906000f08015801562004184573d6000803e3d6000fd5b505060405162004194906200c1dc565b604051809103906000f080158015620041b1573d6000803e3d6000fd5b5050604051620041c1906200c1dc565b604051809103906000f080158015620041de573d6000803e3d6000fd5b5050604051620041ee906200c1dc565b604051809103906000f0801580156200420b573d6000803e3d6000fd5b50506040516200421b906200c1dc565b604051809103906000f08015801562004238573d6000803e3d6000fd5b505060405162004248906200c1dc565b604051809103906000f08015801562004265573d6000803e3d6000fd5b505060405162004275906200c1dc565b604051809103906000f08015801562004292573d6000803e3d6000fd5b5050604051620042a2906200c1dc565b604051809103906000f080158015620042bf573d6000803e3d6000fd5b5050604051620042cf906200c1dc565b604051809103906000f080158015620042ec573d6000803e3d6000fd5b5050604051620042fc906200c1dc565b604051809103906000f08015801562004319573d6000803e3d6000fd5b505060405162004329906200c1dc565b604051809103906000f08015801562004346573d6000803e3d6000fd5b505060405162004356906200c1dc565b604051809103906000f08015801562004373573d6000803e3d6000fd5b505060405162004383906200c1dc565b604051809103906000f080158015620043a0573d6000803e3d6000fd5b5050604051620043b0906200c1dc565b604051809103906000f080158015620043cd573d6000803e3d6000fd5b5050604051620043dd906200c1dc565b604051809103906000f080158015620043fa573d6000803e3d6000fd5b50506040516200440a906200c1dc565b604051809103906000f08015801562004427573d6000803e3d6000fd5b505060405162004437906200c1dc565b604051809103906000f08015801562004454573d6000803e3d6000fd5b505060405162004464906200c1dc565b604051809103906000f08015801562004481573d6000803e3d6000fd5b505060405162004491906200c1dc565b604051809103906000f080158015620044ae573d6000803e3d6000fd5b5050604051620044be906200c1dc565b604051809103906000f080158015620044db573d6000803e3d6000fd5b5050604051620044eb906200c1dc565b604051809103906000f08015801562004508573d6000803e3d6000fd5b505060405162004518906200c1dc565b604051809103906000f08015801562004535573d6000803e3d6000fd5b505060405162004545906200c1dc565b604051809103906000f08015801562004562573d6000803e3d6000fd5b505060405162004572906200c1dc565b604051809103906000f0801580156200458f573d6000803e3d6000fd5b50506040516200459f906200c1dc565b604051809103906000f080158015620045bc573d6000803e3d6000fd5b5050604051620045cc906200c1dc565b604051809103906000f080158015620045e9573d6000803e3d6000fd5b5050604051620045f9906200c1dc565b604051809103906000f08015801562004616573d6000803e3d6000fd5b505060405162004626906200c1dc565b604051809103906000f08015801562004643573d6000803e3d6000fd5b505060405162004653906200c1dc565b604051809103906000f08015801562004670573d6000803e3d6000fd5b505060405162004680906200c1dc565b604051809103906000f0801580156200469d573d6000803e3d6000fd5b5050604051620046ad906200c1dc565b604051809103906000f080158015620046ca573d6000803e3d6000fd5b5050604051620046da906200c1dc565b604051809103906000f080158015620046f7573d6000803e3d6000fd5b505060405162004707906200c1dc565b604051809103906000f08015801562004724573d6000803e3d6000fd5b505060405162004734906200c1dc565b604051809103906000f08015801562004751573d6000803e3d6000fd5b505060405162004761906200c1dc565b604051809103906000f0801580156200477e573d6000803e3d6000fd5b50506040516200478e906200c1dc565b604051809103906000f080158015620047ab573d6000803e3d6000fd5b5050604051620047bb906200c1dc565b604051809103906000f080158015620047d8573d6000803e3d6000fd5b5050604051620047e8906200c1dc565b604051809103906000f08015801562004805573d6000803e3d6000fd5b505060405162004815906200c1dc565b604051809103906000f08015801562004832573d6000803e3d6000fd5b505060405162004842906200c1dc565b604051809103906000f0801580156200485f573d6000803e3d6000fd5b50506040516200486f906200c1dc565b604051809103906000f0801580156200488c573d6000803e3d6000fd5b50506040516200489c906200c1dc565b604051809103906000f080158015620048b9573d6000803e3d6000fd5b5050604051620048c9906200c1dc565b604051809103906000f080158015620048e6573d6000803e3d6000fd5b5050604051620048f6906200c1dc565b604051809103906000f08015801562004913573d6000803e3d6000fd5b505060405162004923906200c1dc565b604051809103906000f08015801562004940573d6000803e3d6000fd5b505060405162004950906200c1dc565b604051809103906000f0801580156200496d573d6000803e3d6000fd5b50506040516200497d906200c1dc565b604051809103906000f0801580156200499a573d6000803e3d6000fd5b5050604051620049aa906200c1dc565b604051809103906000f080158015620049c7573d6000803e3d6000fd5b5050604051620049d7906200c1dc565b604051809103906000f080158015620049f4573d6000803e3d6000fd5b505060405162004a04906200c1dc565b604051809103906000f08015801562004a21573d6000803e3d6000fd5b505060405162004a31906200c1dc565b604051809103906000f08015801562004a4e573d6000803e3d6000fd5b505060405162004a5e906200c1dc565b604051809103906000f08015801562004a7b573d6000803e3d6000fd5b505060405162004a8b906200c1dc565b604051809103906000f08015801562004aa8573d6000803e3d6000fd5b505060405162004ab8906200c1dc565b604051809103906000f08015801562004ad5573d6000803e3d6000fd5b505060405162004ae5906200c1dc565b604051809103906000f08015801562004b02573d6000803e3d6000fd5b505060405162004b12906200c1dc565b604051809103906000f08015801562004b2f573d6000803e3d6000fd5b505060405162004b3f906200c1dc565b604051809103906000f08015801562004b5c573d6000803e3d6000fd5b505060405162004b6c906200c1dc565b604051809103906000f08015801562004b89573d6000803e3d6000fd5b505060405162004b99906200c1dc565b604051809103906000f08015801562004bb6573d6000803e3d6000fd5b505060405162004bc6906200c1dc565b604051809103906000f08015801562004be3573d6000803e3d6000fd5b505060405162004bf3906200c1dc565b604051809103906000f08015801562004c10573d6000803e3d6000fd5b505060405162004c20906200c1dc565b604051809103906000f08015801562004c3d573d6000803e3d6000fd5b505060405162004c4d906200c1dc565b604051809103906000f08015801562004c6a573d6000803e3d6000fd5b505060405162004c7a906200c1dc565b604051809103906000f08015801562004c97573d6000803e3d6000fd5b505060405162004ca7906200c1dc565b604051809103906000f08015801562004cc4573d6000803e3d6000fd5b505060405162004cd4906200c1dc565b604051809103906000f08015801562004cf1573d6000803e3d6000fd5b505060405162004d01906200c1dc565b604051809103906000f08015801562004d1e573d6000803e3d6000fd5b505060405162004d2e906200c1dc565b604051809103906000f08015801562004d4b573d6000803e3d6000fd5b505060405162004d5b906200c1dc565b604051809103906000f08015801562004d78573d6000803e3d6000fd5b505060405162004d88906200c1dc565b604051809103906000f08015801562004da5573d6000803e3d6000fd5b505060405162004db5906200c1dc565b604051809103906000f08015801562004dd2573d6000803e3d6000fd5b505060405162004de2906200c1dc565b604051809103906000f08015801562004dff573d6000803e3d6000fd5b505060405162004e0f906200c1dc565b604051809103906000f08015801562004e2c573d6000803e3d6000fd5b505060405162004e3c906200c1dc565b604051809103906000f08015801562004e59573d6000803e3d6000fd5b505060405162004e69906200c1dc565b604051809103906000f08015801562004e86573d6000803e3d6000fd5b505060405162004e96906200c1dc565b604051809103906000f08015801562004eb3573d6000803e3d6000fd5b505060405162004ec3906200c1dc565b604051809103906000f08015801562004ee0573d6000803e3d6000fd5b505060405162004ef0906200c1dc565b604051809103906000f08015801562004f0d573d6000803e3d6000fd5b505060405162004f1d906200c1dc565b604051809103906000f08015801562004f3a573d6000803e3d6000fd5b505060405162004f4a906200c1dc565b604051809103906000f08015801562004f67573d6000803e3d6000fd5b505060405162004f77906200c1dc565b604051809103906000f08015801562004f94573d6000803e3d6000fd5b505060405162004fa4906200c1dc565b604051809103906000f08015801562004fc1573d6000803e3d6000fd5b505060405162004fd1906200c1dc565b604051809103906000f08015801562004fee573d6000803e3d6000fd5b505060405162004ffe906200c1dc565b604051809103906000f0801580156200501b573d6000803e3d6000fd5b50506040516200502b906200c1dc565b604051809103906000f08015801562005048573d6000803e3d6000fd5b505060405162005058906200c1dc565b604051809103906000f08015801562005075573d6000803e3d6000fd5b505060405162005085906200c1dc565b604051809103906000f080158015620050a2573d6000803e3d6000fd5b5050604051620050b2906200c1dc565b604051809103906000f080158015620050cf573d6000803e3d6000fd5b5050604051620050df906200c1dc565b604051809103906000f080158015620050fc573d6000803e3d6000fd5b50506040516200510c906200c1dc565b604051809103906000f08015801562005129573d6000803e3d6000fd5b505060405162005139906200c1dc565b604051809103906000f08015801562005156573d6000803e3d6000fd5b505060405162005166906200c1dc565b604051809103906000f08015801562005183573d6000803e3d6000fd5b505060405162005193906200c1dc565b604051809103906000f080158015620051b0573d6000803e3d6000fd5b5050604051620051c0906200c1dc565b604051809103906000f080158015620051dd573d6000803e3d6000fd5b5050604051620051ed906200c1dc565b604051809103906000f0801580156200520a573d6000803e3d6000fd5b50506040516200521a906200c1dc565b604051809103906000f08015801562005237573d6000803e3d6000fd5b505060405162005247906200c1dc565b604051809103906000f08015801562005264573d6000803e3d6000fd5b505060405162005274906200c1dc565b604051809103906000f08015801562005291573d6000803e3d6000fd5b5050604051620052a1906200c1dc565b604051809103906000f080158015620052be573d6000803e3d6000fd5b5050604051620052ce906200c1dc565b604051809103906000f080158015620052eb573d6000803e3d6000fd5b5050604051620052fb906200c1dc565b604051809103906000f08015801562005318573d6000803e3d6000fd5b505060405162005328906200c1dc565b604051809103906000f08015801562005345573d6000803e3d6000fd5b505060405162005355906200c1dc565b604051809103906000f08015801562005372573d6000803e3d6000fd5b505060405162005382906200c1dc565b604051809103906000f0801580156200539f573d6000803e3d6000fd5b5050604051620053af906200c1dc565b604051809103906000f080158015620053cc573d6000803e3d6000fd5b5050604051620053dc906200c1dc565b604051809103906000f080158015620053f9573d6000803e3d6000fd5b505060405162005409906200c1dc565b604051809103906000f08015801562005426573d6000803e3d6000fd5b505060405162005436906200c1dc565b604051809103906000f08015801562005453573d6000803e3d6000fd5b505060405162005463906200c1dc565b604051809103906000f08015801562005480573d6000803e3d6000fd5b505060405162005490906200c1dc565b604051809103906000f080158015620054ad573d6000803e3d6000fd5b5050604051620054bd906200c1dc565b604051809103906000f080158015620054da573d6000803e3d6000fd5b5050604051620054ea906200c1dc565b604051809103906000f08015801562005507573d6000803e3d6000fd5b505060405162005517906200c1dc565b604051809103906000f08015801562005534573d6000803e3d6000fd5b505060405162005544906200c1dc565b604051809103906000f08015801562005561573d6000803e3d6000fd5b505060405162005571906200c1dc565b604051809103906000f0801580156200558e573d6000803e3d6000fd5b50506040516200559e906200c1dc565b604051809103906000f080158015620055bb573d6000803e3d6000fd5b5050604051620055cb906200c1dc565b604051809103906000f080158015620055e8573d6000803e3d6000fd5b5050604051620055f8906200c1dc565b604051809103906000f08015801562005615573d6000803e3d6000fd5b505060405162005625906200c1dc565b604051809103906000f08015801562005642573d6000803e3d6000fd5b505060405162005652906200c1dc565b604051809103906000f0801580156200566f573d6000803e3d6000fd5b50506040516200567f906200c1dc565b604051809103906000f0801580156200569c573d6000803e3d6000fd5b5050604051620056ac906200c1dc565b604051809103906000f080158015620056c9573d6000803e3d6000fd5b5050604051620056d9906200c1dc565b604051809103906000f080158015620056f6573d6000803e3d6000fd5b505060405162005706906200c1dc565b604051809103906000f08015801562005723573d6000803e3d6000fd5b505060405162005733906200c1dc565b604051809103906000f08015801562005750573d6000803e3d6000fd5b505060405162005760906200c1dc565b604051809103906000f0801580156200577d573d6000803e3d6000fd5b50506040516200578d906200c1dc565b604051809103906000f080158015620057aa573d6000803e3d6000fd5b5050604051620057ba906200c1dc565b604051809103906000f080158015620057d7573d6000803e3d6000fd5b5050604051620057e7906200c1dc565b604051809103906000f08015801562005804573d6000803e3d6000fd5b505060405162005814906200c1dc565b604051809103906000f08015801562005831573d6000803e3d6000fd5b505060405162005841906200c1dc565b604051809103906000f0801580156200585e573d6000803e3d6000fd5b50506040516200586e906200c1dc565b604051809103906000f0801580156200588b573d6000803e3d6000fd5b50506040516200589b906200c1dc565b604051809103906000f080158015620058b8573d6000803e3d6000fd5b5050604051620058c8906200c1dc565b604051809103906000f080158015620058e5573d6000803e3d6000fd5b5050604051620058f5906200c1dc565b604051809103906000f08015801562005912573d6000803e3d6000fd5b505060405162005922906200c1dc565b604051809103906000f0801580156200593f573d6000803e3d6000fd5b50506040516200594f906200c1dc565b604051809103906000f0801580156200596c573d6000803e3d6000fd5b50506040516200597c906200c1dc565b604051809103906000f08015801562005999573d6000803e3d6000fd5b5050604051620059a9906200c1dc565b604051809103906000f080158015620059c6573d6000803e3d6000fd5b5050604051620059d6906200c1dc565b604051809103906000f080158015620059f3573d6000803e3d6000fd5b505060405162005a03906200c1dc565b604051809103906000f08015801562005a20573d6000803e3d6000fd5b505060405162005a30906200c1dc565b604051809103906000f08015801562005a4d573d6000803e3d6000fd5b505060405162005a5d906200c1dc565b604051809103906000f08015801562005a7a573d6000803e3d6000fd5b505060405162005a8a906200c1dc565b604051809103906000f08015801562005aa7573d6000803e3d6000fd5b505060405162005ab7906200c1dc565b604051809103906000f08015801562005ad4573d6000803e3d6000fd5b505060405162005ae4906200c1dc565b604051809103906000f08015801562005b01573d6000803e3d6000fd5b505060405162005b11906200c1dc565b604051809103906000f08015801562005b2e573d6000803e3d6000fd5b505060405162005b3e906200c1dc565b604051809103906000f08015801562005b5b573d6000803e3d6000fd5b505060405162005b6b906200c1dc565b604051809103906000f08015801562005b88573d6000803e3d6000fd5b505060405162005b98906200c1dc565b604051809103906000f08015801562005bb5573d6000803e3d6000fd5b505060405162005bc5906200c1dc565b604051809103906000f08015801562005be2573d6000803e3d6000fd5b505060405162005bf2906200c1dc565b604051809103906000f08015801562005c0f573d6000803e3d6000fd5b505060405162005c1f906200c1dc565b604051809103906000f08015801562005c3c573d6000803e3d6000fd5b505060405162005c4c906200c1dc565b604051809103906000f08015801562005c69573d6000803e3d6000fd5b505060405162005c79906200c1dc565b604051809103906000f08015801562005c96573d6000803e3d6000fd5b505060405162005ca6906200c1dc565b604051809103906000f08015801562005cc3573d6000803e3d6000fd5b505060405162005cd3906200c1dc565b604051809103906000f08015801562005cf0573d6000803e3d6000fd5b505060405162005d00906200c1dc565b604051809103906000f08015801562005d1d573d6000803e3d6000fd5b505060405162005d2d906200c1dc565b604051809103906000f08015801562005d4a573d6000803e3d6000fd5b505060405162005d5a906200c1dc565b604051809103906000f08015801562005d77573d6000803e3d6000fd5b505060405162005d87906200c1dc565b604051809103906000f08015801562005da4573d6000803e3d6000fd5b505060405162005db4906200c1dc565b604051809103906000f08015801562005dd1573d6000803e3d6000fd5b505060405162005de1906200c1dc565b604051809103906000f08015801562005dfe573d6000803e3d6000fd5b505060405162005e0e906200c1dc565b604051809103906000f08015801562005e2b573d6000803e3d6000fd5b505060405162005e3b906200c1dc565b604051809103906000f08015801562005e58573d6000803e3d6000fd5b505060405162005e68906200c1dc565b604051809103906000f08015801562005e85573d6000803e3d6000fd5b505060405162005e95906200c1dc565b604051809103906000f08015801562005eb2573d6000803e3d6000fd5b505060405162005ec2906200c1dc565b604051809103906000f08015801562005edf573d6000803e3d6000fd5b505060405162005eef906200c1dc565b604051809103906000f08015801562005f0c573d6000803e3d6000fd5b505060405162005f1c906200c1dc565b604051809103906000f08015801562005f39573d6000803e3d6000fd5b505060405162005f49906200c1dc565b604051809103906000f08015801562005f66573d6000803e3d6000fd5b505060405162005f76906200c1dc565b604051809103906000f08015801562005f93573d6000803e3d6000fd5b505060405162005fa3906200c1dc565b604051809103906000f08015801562005fc0573d6000803e3d6000fd5b505060405162005fd0906200c1dc565b604051809103906000f08015801562005fed573d6000803e3d6000fd5b505060405162005ffd906200c1dc565b604051809103906000f0801580156200601a573d6000803e3d6000fd5b50506040516200602a906200c1dc565b604051809103906000f08015801562006047573d6000803e3d6000fd5b505060405162006057906200c1dc565b604051809103906000f08015801562006074573d6000803e3d6000fd5b505060405162006084906200c1dc565b604051809103906000f080158015620060a1573d6000803e3d6000fd5b5050604051620060b1906200c1dc565b604051809103906000f080158015620060ce573d6000803e3d6000fd5b5050604051620060de906200c1dc565b604051809103906000f080158015620060fb573d6000803e3d6000fd5b50506040516200610b906200c1dc565b604051809103906000f08015801562006128573d6000803e3d6000fd5b505060405162006138906200c1dc565b604051809103906000f08015801562006155573d6000803e3d6000fd5b505060405162006165906200c1dc565b604051809103906000f08015801562006182573d6000803e3d6000fd5b505060405162006192906200c1dc565b604051809103906000f080158015620061af573d6000803e3d6000fd5b5050604051620061bf906200c1dc565b604051809103906000f080158015620061dc573d6000803e3d6000fd5b5050604051620061ec906200c1dc565b604051809103906000f08015801562006209573d6000803e3d6000fd5b505060405162006219906200c1dc565b604051809103906000f08015801562006236573d6000803e3d6000fd5b505060405162006246906200c1dc565b604051809103906000f08015801562006263573d6000803e3d6000fd5b505060405162006273906200c1dc565b604051809103906000f08015801562006290573d6000803e3d6000fd5b5050604051620062a0906200c1dc565b604051809103906000f080158015620062bd573d6000803e3d6000fd5b5050604051620062cd906200c1dc565b604051809103906000f080158015620062ea573d6000803e3d6000fd5b5050604051620062fa906200c1dc565b604051809103906000f08015801562006317573d6000803e3d6000fd5b505060405162006327906200c1dc565b604051809103906000f08015801562006344573d6000803e3d6000fd5b505060405162006354906200c1dc565b604051809103906000f08015801562006371573d6000803e3d6000fd5b505060405162006381906200c1dc565b604051809103906000f0801580156200639e573d6000803e3d6000fd5b5050604051620063ae906200c1dc565b604051809103906000f080158015620063cb573d6000803e3d6000fd5b5050604051620063db906200c1dc565b604051809103906000f080158015620063f8573d6000803e3d6000fd5b505060405162006408906200c1dc565b604051809103906000f08015801562006425573d6000803e3d6000fd5b505060405162006435906200c1dc565b604051809103906000f08015801562006452573d6000803e3d6000fd5b505060405162006462906200c1dc565b604051809103906000f0801580156200647f573d6000803e3d6000fd5b50506040516200648f906200c1dc565b604051809103906000f080158015620064ac573d6000803e3d6000fd5b5050604051620064bc906200c1dc565b604051809103906000f080158015620064d9573d6000803e3d6000fd5b5050604051620064e9906200c1dc565b604051809103906000f08015801562006506573d6000803e3d6000fd5b505060405162006516906200c1dc565b604051809103906000f08015801562006533573d6000803e3d6000fd5b505060405162006543906200c1dc565b604051809103906000f08015801562006560573d6000803e3d6000fd5b505060405162006570906200c1dc565b604051809103906000f0801580156200658d573d6000803e3d6000fd5b50506040516200659d906200c1dc565b604051809103906000f080158015620065ba573d6000803e3d6000fd5b5050604051620065ca906200c1dc565b604051809103906000f080158015620065e7573d6000803e3d6000fd5b5050604051620065f7906200c1dc565b604051809103906000f08015801562006614573d6000803e3d6000fd5b505060405162006624906200c1dc565b604051809103906000f08015801562006641573d6000803e3d6000fd5b505060405162006651906200c1dc565b604051809103906000f0801580156200666e573d6000803e3d6000fd5b50506040516200667e906200c1dc565b604051809103906000f0801580156200669b573d6000803e3d6000fd5b5050604051620066ab906200c1dc565b604051809103906000f080158015620066c8573d6000803e3d6000fd5b5050604051620066d8906200c1dc565b604051809103906000f080158015620066f5573d6000803e3d6000fd5b505060405162006705906200c1dc565b604051809103906000f08015801562006722573d6000803e3d6000fd5b505060405162006732906200c1dc565b604051809103906000f0801580156200674f573d6000803e3d6000fd5b50506040516200675f906200c1dc565b604051809103906000f0801580156200677c573d6000803e3d6000fd5b50506040516200678c906200c1dc565b604051809103906000f080158015620067a9573d6000803e3d6000fd5b5050604051620067b9906200c1dc565b604051809103906000f080158015620067d6573d6000803e3d6000fd5b5050604051620067e6906200c1dc565b604051809103906000f08015801562006803573d6000803e3d6000fd5b505060405162006813906200c1dc565b604051809103906000f08015801562006830573d6000803e3d6000fd5b505060405162006840906200c1dc565b604051809103906000f0801580156200685d573d6000803e3d6000fd5b50506040516200686d906200c1dc565b604051809103906000f0801580156200688a573d6000803e3d6000fd5b50506040516200689a906200c1dc565b604051809103906000f080158015620068b7573d6000803e3d6000fd5b5050604051620068c7906200c1dc565b604051809103906000f080158015620068e4573d6000803e3d6000fd5b5050604051620068f4906200c1dc565b604051809103906000f08015801562006911573d6000803e3d6000fd5b505060405162006921906200c1dc565b604051809103906000f0801580156200693e573d6000803e3d6000fd5b50506040516200694e906200c1dc565b604051809103906000f0801580156200696b573d6000803e3d6000fd5b50506040516200697b906200c1dc565b604051809103906000f08015801562006998573d6000803e3d6000fd5b5050604051620069a8906200c1dc565b604051809103906000f080158015620069c5573d6000803e3d6000fd5b5050604051620069d5906200c1dc565b604051809103906000f080158015620069f2573d6000803e3d6000fd5b505060405162006a02906200c1dc565b604051809103906000f08015801562006a1f573d6000803e3d6000fd5b505060405162006a2f906200c1dc565b604051809103906000f08015801562006a4c573d6000803e3d6000fd5b505060405162006a5c906200c1dc565b604051809103906000f08015801562006a79573d6000803e3d6000fd5b505060405162006a89906200c1dc565b604051809103906000f08015801562006aa6573d6000803e3d6000fd5b505060405162006ab6906200c1dc565b604051809103906000f08015801562006ad3573d6000803e3d6000fd5b505060405162006ae3906200c1dc565b604051809103906000f08015801562006b00573d6000803e3d6000fd5b505060405162006b10906200c1dc565b604051809103906000f08015801562006b2d573d6000803e3d6000fd5b505060405162006b3d906200c1dc565b604051809103906000f08015801562006b5a573d6000803e3d6000fd5b505060405162006b6a906200c1dc565b604051809103906000f08015801562006b87573d6000803e3d6000fd5b505060405162006b97906200c1dc565b604051809103906000f08015801562006bb4573d6000803e3d6000fd5b505060405162006bc4906200c1dc565b604051809103906000f08015801562006be1573d6000803e3d6000fd5b505060405162006bf1906200c1dc565b604051809103906000f08015801562006c0e573d6000803e3d6000fd5b505060405162006c1e906200c1dc565b604051809103906000f08015801562006c3b573d6000803e3d6000fd5b505060405162006c4b906200c1dc565b604051809103906000f08015801562006c68573d6000803e3d6000fd5b505060405162006c78906200c1dc565b604051809103906000f08015801562006c95573d6000803e3d6000fd5b505060405162006ca5906200c1dc565b604051809103906000f08015801562006cc2573d6000803e3d6000fd5b505060405162006cd2906200c1dc565b604051809103906000f08015801562006cef573d6000803e3d6000fd5b505060405162006cff906200c1dc565b604051809103906000f08015801562006d1c573d6000803e3d6000fd5b505060405162006d2c906200c1dc565b604051809103906000f08015801562006d49573d6000803e3d6000fd5b505060405162006d59906200c1dc565b604051809103906000f08015801562006d76573d6000803e3d6000fd5b505060405162006d86906200c1dc565b604051809103906000f08015801562006da3573d6000803e3d6000fd5b505060405162006db3906200c1dc565b604051809103906000f08015801562006dd0573d6000803e3d6000fd5b505060405162006de0906200c1dc565b604051809103906000f08015801562006dfd573d6000803e3d6000fd5b505060405162006e0d906200c1dc565b604051809103906000f08015801562006e2a573d6000803e3d6000fd5b505060405162006e3a906200c1dc565b604051809103906000f08015801562006e57573d6000803e3d6000fd5b505060405162006e67906200c1dc565b604051809103906000f08015801562006e84573d6000803e3d6000fd5b505060405162006e94906200c1dc565b604051809103906000f08015801562006eb1573d6000803e3d6000fd5b505060405162006ec1906200c1dc565b604051809103906000f08015801562006ede573d6000803e3d6000fd5b505060405162006eee906200c1dc565b604051809103906000f08015801562006f0b573d6000803e3d6000fd5b505060405162006f1b906200c1dc565b604051809103906000f08015801562006f38573d6000803e3d6000fd5b505060405162006f48906200c1dc565b604051809103906000f08015801562006f65573d6000803e3d6000fd5b505060405162006f75906200c1dc565b604051809103906000f08015801562006f92573d6000803e3d6000fd5b505060405162006fa2906200c1dc565b604051809103906000f08015801562006fbf573d6000803e3d6000fd5b505060405162006fcf906200c1dc565b604051809103906000f08015801562006fec573d6000803e3d6000fd5b505060405162006ffc906200c1dc565b604051809103906000f08015801562007019573d6000803e3d6000fd5b505060405162007029906200c1dc565b604051809103906000f08015801562007046573d6000803e3d6000fd5b505060405162007056906200c1dc565b604051809103906000f08015801562007073573d6000803e3d6000fd5b505060405162007083906200c1dc565b604051809103906000f080158015620070a0573d6000803e3d6000fd5b5050604051620070b0906200c1dc565b604051809103906000f080158015620070cd573d6000803e3d6000fd5b5050604051620070dd906200c1dc565b604051809103906000f080158015620070fa573d6000803e3d6000fd5b50506040516200710a906200c1dc565b604051809103906000f08015801562007127573d6000803e3d6000fd5b505060405162007137906200c1dc565b604051809103906000f08015801562007154573d6000803e3d6000fd5b505060405162007164906200c1dc565b604051809103906000f08015801562007181573d6000803e3d6000fd5b505060405162007191906200c1dc565b604051809103906000f080158015620071ae573d6000803e3d6000fd5b5050604051620071be906200c1dc565b604051809103906000f080158015620071db573d6000803e3d6000fd5b5050604051620071eb906200c1dc565b604051809103906000f08015801562007208573d6000803e3d6000fd5b505060405162007218906200c1dc565b604051809103906000f08015801562007235573d6000803e3d6000fd5b505060405162007245906200c1dc565b604051809103906000f08015801562007262573d6000803e3d6000fd5b505060405162007272906200c1dc565b604051809103906000f0801580156200728f573d6000803e3d6000fd5b50506040516200729f906200c1dc565b604051809103906000f080158015620072bc573d6000803e3d6000fd5b5050604051620072cc906200c1dc565b604051809103906000f080158015620072e9573d6000803e3d6000fd5b5050604051620072f9906200c1dc565b604051809103906000f08015801562007316573d6000803e3d6000fd5b505060405162007326906200c1dc565b604051809103906000f08015801562007343573d6000803e3d6000fd5b505060405162007353906200c1dc565b604051809103906000f08015801562007370573d6000803e3d6000fd5b505060405162007380906200c1dc565b604051809103906000f0801580156200739d573d6000803e3d6000fd5b5050604051620073ad906200c1dc565b604051809103906000f080158015620073ca573d6000803e3d6000fd5b5050604051620073da906200c1dc565b604051809103906000f080158015620073f7573d6000803e3d6000fd5b505060405162007407906200c1dc565b604051809103906000f08015801562007424573d6000803e3d6000fd5b505060405162007434906200c1dc565b604051809103906000f08015801562007451573d6000803e3d6000fd5b505060405162007461906200c1dc565b604051809103906000f0801580156200747e573d6000803e3d6000fd5b50506040516200748e906200c1dc565b604051809103906000f080158015620074ab573d6000803e3d6000fd5b5050604051620074bb906200c1dc565b604051809103906000f080158015620074d8573d6000803e3d6000fd5b5050604051620074e8906200c1dc565b604051809103906000f08015801562007505573d6000803e3d6000fd5b505060405162007515906200c1dc565b604051809103906000f08015801562007532573d6000803e3d6000fd5b505060405162007542906200c1dc565b604051809103906000f0801580156200755f573d6000803e3d6000fd5b50506040516200756f906200c1dc565b604051809103906000f0801580156200758c573d6000803e3d6000fd5b50506040516200759c906200c1dc565b604051809103906000f080158015620075b9573d6000803e3d6000fd5b5050604051620075c9906200c1dc565b604051809103906000f080158015620075e6573d6000803e3d6000fd5b5050604051620075f6906200c1dc565b604051809103906000f08015801562007613573d6000803e3d6000fd5b505060405162007623906200c1dc565b604051809103906000f08015801562007640573d6000803e3d6000fd5b505060405162007650906200c1dc565b604051809103906000f0801580156200766d573d6000803e3d6000fd5b50506040516200767d906200c1dc565b604051809103906000f0801580156200769a573d6000803e3d6000fd5b5050604051620076aa906200c1dc565b604051809103906000f080158015620076c7573d6000803e3d6000fd5b5050604051620076d7906200c1dc565b604051809103906000f080158015620076f4573d6000803e3d6000fd5b505060405162007704906200c1dc565b604051809103906000f08015801562007721573d6000803e3d6000fd5b505060405162007731906200c1dc565b604051809103906000f0801580156200774e573d6000803e3d6000fd5b50506040516200775e906200c1dc565b604051809103906000f0801580156200777b573d6000803e3d6000fd5b50506040516200778b906200c1dc565b604051809103906000f080158015620077a8573d6000803e3d6000fd5b5050604051620077b8906200c1dc565b604051809103906000f080158015620077d5573d6000803e3d6000fd5b5050604051620077e5906200c1dc565b604051809103906000f08015801562007802573d6000803e3d6000fd5b505060405162007812906200c1dc565b604051809103906000f0801580156200782f573d6000803e3d6000fd5b50506040516200783f906200c1dc565b604051809103906000f0801580156200785c573d6000803e3d6000fd5b50506040516200786c906200c1dc565b604051809103906000f08015801562007889573d6000803e3d6000fd5b505060405162007899906200c1dc565b604051809103906000f080158015620078b6573d6000803e3d6000fd5b5050604051620078c6906200c1dc565b604051809103906000f080158015620078e3573d6000803e3d6000fd5b5050604051620078f3906200c1dc565b604051809103906000f08015801562007910573d6000803e3d6000fd5b505060405162007920906200c1dc565b604051809103906000f0801580156200793d573d6000803e3d6000fd5b50506040516200794d906200c1dc565b604051809103906000f0801580156200796a573d6000803e3d6000fd5b50506040516200797a906200c1dc565b604051809103906000f08015801562007997573d6000803e3d6000fd5b5050604051620079a7906200c1dc565b604051809103906000f080158015620079c4573d6000803e3d6000fd5b5050604051620079d4906200c1dc565b604051809103906000f080158015620079f1573d6000803e3d6000fd5b505060405162007a01906200c1dc565b604051809103906000f08015801562007a1e573d6000803e3d6000fd5b505060405162007a2e906200c1dc565b604051809103906000f08015801562007a4b573d6000803e3d6000fd5b505060405162007a5b906200c1dc565b604051809103906000f08015801562007a78573d6000803e3d6000fd5b505060405162007a88906200c1dc565b604051809103906000f08015801562007aa5573d6000803e3d6000fd5b505060405162007ab5906200c1dc565b604051809103906000f08015801562007ad2573d6000803e3d6000fd5b505060405162007ae2906200c1dc565b604051809103906000f08015801562007aff573d6000803e3d6000fd5b505060405162007b0f906200c1dc565b604051809103906000f08015801562007b2c573d6000803e3d6000fd5b505060405162007b3c906200c1dc565b604051809103906000f08015801562007b59573d6000803e3d6000fd5b505060405162007b69906200c1dc565b604051809103906000f08015801562007b86573d6000803e3d6000fd5b505060405162007b96906200c1dc565b604051809103906000f08015801562007bb3573d6000803e3d6000fd5b505060405162007bc3906200c1dc565b604051809103906000f08015801562007be0573d6000803e3d6000fd5b505060405162007bf0906200c1dc565b604051809103906000f08015801562007c0d573d6000803e3d6000fd5b505060405162007c1d906200c1dc565b604051809103906000f08015801562007c3a573d6000803e3d6000fd5b505060405162007c4a906200c1dc565b604051809103906000f08015801562007c67573d6000803e3d6000fd5b505060405162007c77906200c1dc565b604051809103906000f08015801562007c94573d6000803e3d6000fd5b505060405162007ca4906200c1dc565b604051809103906000f08015801562007cc1573d6000803e3d6000fd5b505060405162007cd1906200c1dc565b604051809103906000f08015801562007cee573d6000803e3d6000fd5b505060405162007cfe906200c1dc565b604051809103906000f08015801562007d1b573d6000803e3d6000fd5b505060405162007d2b906200c1dc565b604051809103906000f08015801562007d48573d6000803e3d6000fd5b505060405162007d58906200c1dc565b604051809103906000f08015801562007d75573d6000803e3d6000fd5b505060405162007d85906200c1dc565b604051809103906000f08015801562007da2573d6000803e3d6000fd5b505060405162007db2906200c1dc565b604051809103906000f08015801562007dcf573d6000803e3d6000fd5b505060405162007ddf906200c1dc565b604051809103906000f08015801562007dfc573d6000803e3d6000fd5b505060405162007e0c906200c1dc565b604051809103906000f08015801562007e29573d6000803e3d6000fd5b505060405162007e39906200c1dc565b604051809103906000f08015801562007e56573d6000803e3d6000fd5b505060405162007e66906200c1dc565b604051809103906000f08015801562007e83573d6000803e3d6000fd5b505060405162007e93906200c1dc565b604051809103906000f08015801562007eb0573d6000803e3d6000fd5b505060405162007ec0906200c1dc565b604051809103906000f08015801562007edd573d6000803e3d6000fd5b505060405162007eed906200c1dc565b604051809103906000f08015801562007f0a573d6000803e3d6000fd5b505060405162007f1a906200c1dc565b604051809103906000f08015801562007f37573d6000803e3d6000fd5b505060405162007f47906200c1dc565b604051809103906000f08015801562007f64573d6000803e3d6000fd5b505060405162007f74906200c1dc565b604051809103906000f08015801562007f91573d6000803e3d6000fd5b505060405162007fa1906200c1dc565b604051809103906000f08015801562007fbe573d6000803e3d6000fd5b505060405162007fce906200c1dc565b604051809103906000f08015801562007feb573d6000803e3d6000fd5b505060405162007ffb906200c1dc565b604051809103906000f08015801562008018573d6000803e3d6000fd5b505060405162008028906200c1dc565b604051809103906000f08015801562008045573d6000803e3d6000fd5b505060405162008055906200c1dc565b604051809103906000f08015801562008072573d6000803e3d6000fd5b505060405162008082906200c1dc565b604051809103906000f0801580156200809f573d6000803e3d6000fd5b5050604051620080af906200c1dc565b604051809103906000f080158015620080cc573d6000803e3d6000fd5b5050604051620080dc906200c1dc565b604051809103906000f080158015620080f9573d6000803e3d6000fd5b505060405162008109906200c1dc565b604051809103906000f08015801562008126573d6000803e3d6000fd5b505060405162008136906200c1dc565b604051809103906000f08015801562008153573d6000803e3d6000fd5b505060405162008163906200c1dc565b604051809103906000f08015801562008180573d6000803e3d6000fd5b505060405162008190906200c1dc565b604051809103906000f080158015620081ad573d6000803e3d6000fd5b5050604051620081bd906200c1dc565b604051809103906000f080158015620081da573d6000803e3d6000fd5b5050604051620081ea906200c1dc565b604051809103906000f08015801562008207573d6000803e3d6000fd5b505060405162008217906200c1dc565b604051809103906000f08015801562008234573d6000803e3d6000fd5b505060405162008244906200c1dc565b604051809103906000f08015801562008261573d6000803e3d6000fd5b505060405162008271906200c1dc565b604051809103906000f0801580156200828e573d6000803e3d6000fd5b50506040516200829e906200c1dc565b604051809103906000f080158015620082bb573d6000803e3d6000fd5b5050604051620082cb906200c1dc565b604051809103906000f080158015620082e8573d6000803e3d6000fd5b5050604051620082f8906200c1dc565b604051809103906000f08015801562008315573d6000803e3d6000fd5b505060405162008325906200c1dc565b604051809103906000f08015801562008342573d6000803e3d6000fd5b505060405162008352906200c1dc565b604051809103906000f0801580156200836f573d6000803e3d6000fd5b50506040516200837f906200c1dc565b604051809103906000f0801580156200839c573d6000803e3d6000fd5b5050604051620083ac906200c1dc565b604051809103906000f080158015620083c9573d6000803e3d6000fd5b5050604051620083d9906200c1dc565b604051809103906000f080158015620083f6573d6000803e3d6000fd5b505060405162008406906200c1dc565b604051809103906000f08015801562008423573d6000803e3d6000fd5b505060405162008433906200c1dc565b604051809103906000f08015801562008450573d6000803e3d6000fd5b505060405162008460906200c1dc565b604051809103906000f0801580156200847d573d6000803e3d6000fd5b50506040516200848d906200c1dc565b604051809103906000f080158015620084aa573d6000803e3d6000fd5b5050604051620084ba906200c1dc565b604051809103906000f080158015620084d7573d6000803e3d6000fd5b5050604051620084e7906200c1dc565b604051809103906000f08015801562008504573d6000803e3d6000fd5b505060405162008514906200c1dc565b604051809103906000f08015801562008531573d6000803e3d6000fd5b505060405162008541906200c1dc565b604051809103906000f0801580156200855e573d6000803e3d6000fd5b50506040516200856e906200c1dc565b604051809103906000f0801580156200858b573d6000803e3d6000fd5b50506040516200859b906200c1dc565b604051809103906000f080158015620085b8573d6000803e3d6000fd5b5050604051620085c8906200c1dc565b604051809103906000f080158015620085e5573d6000803e3d6000fd5b5050604051620085f5906200c1dc565b604051809103906000f08015801562008612573d6000803e3d6000fd5b505060405162008622906200c1dc565b604051809103906000f0801580156200863f573d6000803e3d6000fd5b50506040516200864f906200c1dc565b604051809103906000f0801580156200866c573d6000803e3d6000fd5b50506040516200867c906200c1dc565b604051809103906000f08015801562008699573d6000803e3d6000fd5b5050604051620086a9906200c1dc565b604051809103906000f080158015620086c6573d6000803e3d6000fd5b5050604051620086d6906200c1dc565b604051809103906000f080158015620086f3573d6000803e3d6000fd5b505060405162008703906200c1dc565b604051809103906000f08015801562008720573d6000803e3d6000fd5b505060405162008730906200c1dc565b604051809103906000f0801580156200874d573d6000803e3d6000fd5b50506040516200875d906200c1dc565b604051809103906000f0801580156200877a573d6000803e3d6000fd5b50506040516200878a906200c1dc565b604051809103906000f080158015620087a7573d6000803e3d6000fd5b5050604051620087b7906200c1dc565b604051809103906000f080158015620087d4573d6000803e3d6000fd5b5050604051620087e4906200c1dc565b604051809103906000f08015801562008801573d6000803e3d6000fd5b505060405162008811906200c1dc565b604051809103906000f0801580156200882e573d6000803e3d6000fd5b50506040516200883e906200c1dc565b604051809103906000f0801580156200885b573d6000803e3d6000fd5b50506040516200886b906200c1dc565b604051809103906000f08015801562008888573d6000803e3d6000fd5b505060405162008898906200c1dc565b604051809103906000f080158015620088b5573d6000803e3d6000fd5b5050604051620088c5906200c1dc565b604051809103906000f080158015620088e2573d6000803e3d6000fd5b5050604051620088f2906200c1dc565b604051809103906000f0801580156200890f573d6000803e3d6000fd5b50506040516200891f906200c1dc565b604051809103906000f0801580156200893c573d6000803e3d6000fd5b50506040516200894c906200c1dc565b604051809103906000f08015801562008969573d6000803e3d6000fd5b505060405162008979906200c1dc565b604051809103906000f08015801562008996573d6000803e3d6000fd5b5050604051620089a6906200c1dc565b604051809103906000f080158015620089c3573d6000803e3d6000fd5b5050604051620089d3906200c1dc565b604051809103906000f080158015620089f0573d6000803e3d6000fd5b505060405162008a00906200c1dc565b604051809103906000f08015801562008a1d573d6000803e3d6000fd5b505060405162008a2d906200c1dc565b604051809103906000f08015801562008a4a573d6000803e3d6000fd5b505060405162008a5a906200c1dc565b604051809103906000f08015801562008a77573d6000803e3d6000fd5b505060405162008a87906200c1dc565b604051809103906000f08015801562008aa4573d6000803e3d6000fd5b505060405162008ab4906200c1dc565b604051809103906000f08015801562008ad1573d6000803e3d6000fd5b505060405162008ae1906200c1dc565b604051809103906000f08015801562008afe573d6000803e3d6000fd5b505060405162008b0e906200c1dc565b604051809103906000f08015801562008b2b573d6000803e3d6000fd5b505060405162008b3b906200c1dc565b604051809103906000f08015801562008b58573d6000803e3d6000fd5b505060405162008b68906200c1dc565b604051809103906000f08015801562008b85573d6000803e3d6000fd5b505060405162008b95906200c1dc565b604051809103906000f08015801562008bb2573d6000803e3d6000fd5b505060405162008bc2906200c1dc565b604051809103906000f08015801562008bdf573d6000803e3d6000fd5b505060405162008bef906200c1dc565b604051809103906000f08015801562008c0c573d6000803e3d6000fd5b505060405162008c1c906200c1dc565b604051809103906000f08015801562008c39573d6000803e3d6000fd5b505060405162008c49906200c1dc565b604051809103906000f08015801562008c66573d6000803e3d6000fd5b505060405162008c76906200c1dc565b604051809103906000f08015801562008c93573d6000803e3d6000fd5b505060405162008ca3906200c1dc565b604051809103906000f08015801562008cc0573d6000803e3d6000fd5b505060405162008cd0906200c1dc565b604051809103906000f08015801562008ced573d6000803e3d6000fd5b505060405162008cfd906200c1dc565b604051809103906000f08015801562008d1a573d6000803e3d6000fd5b505060405162008d2a906200c1dc565b604051809103906000f08015801562008d47573d6000803e3d6000fd5b505060405162008d57906200c1dc565b604051809103906000f08015801562008d74573d6000803e3d6000fd5b505060405162008d84906200c1dc565b604051809103906000f08015801562008da1573d6000803e3d6000fd5b505060405162008db1906200c1dc565b604051809103906000f08015801562008dce573d6000803e3d6000fd5b505060405162008dde906200c1dc565b604051809103906000f08015801562008dfb573d6000803e3d6000fd5b505060405162008e0b906200c1dc565b604051809103906000f08015801562008e28573d6000803e3d6000fd5b505060405162008e38906200c1dc565b604051809103906000f08015801562008e55573d6000803e3d6000fd5b505060405162008e65906200c1dc565b604051809103906000f08015801562008e82573d6000803e3d6000fd5b505060405162008e92906200c1dc565b604051809103906000f08015801562008eaf573d6000803e3d6000fd5b505060405162008ebf906200c1dc565b604051809103906000f08015801562008edc573d6000803e3d6000fd5b505060405162008eec906200c1dc565b604051809103906000f08015801562008f09573d6000803e3d6000fd5b505060405162008f19906200c1dc565b604051809103906000f08015801562008f36573d6000803e3d6000fd5b505060405162008f46906200c1dc565b604051809103906000f08015801562008f63573d6000803e3d6000fd5b505060405162008f73906200c1dc565b604051809103906000f08015801562008f90573d6000803e3d6000fd5b505060405162008fa0906200c1dc565b604051809103906000f08015801562008fbd573d6000803e3d6000fd5b505060405162008fcd906200c1dc565b604051809103906000f08015801562008fea573d6000803e3d6000fd5b505060405162008ffa906200c1dc565b604051809103906000f08015801562009017573d6000803e3d6000fd5b505060405162009027906200c1dc565b604051809103906000f08015801562009044573d6000803e3d6000fd5b505060405162009054906200c1dc565b604051809103906000f08015801562009071573d6000803e3d6000fd5b505060405162009081906200c1dc565b604051809103906000f0801580156200909e573d6000803e3d6000fd5b5050604051620090ae906200c1dc565b604051809103906000f080158015620090cb573d6000803e3d6000fd5b5050604051620090db906200c1dc565b604051809103906000f080158015620090f8573d6000803e3d6000fd5b505060405162009108906200c1dc565b604051809103906000f08015801562009125573d6000803e3d6000fd5b505060405162009135906200c1dc565b604051809103906000f08015801562009152573d6000803e3d6000fd5b505060405162009162906200c1dc565b604051809103906000f0801580156200917f573d6000803e3d6000fd5b50506040516200918f906200c1dc565b604051809103906000f080158015620091ac573d6000803e3d6000fd5b5050604051620091bc906200c1dc565b604051809103906000f080158015620091d9573d6000803e3d6000fd5b5050604051620091e9906200c1dc565b604051809103906000f08015801562009206573d6000803e3d6000fd5b505060405162009216906200c1dc565b604051809103906000f08015801562009233573d6000803e3d6000fd5b505060405162009243906200c1dc565b604051809103906000f08015801562009260573d6000803e3d6000fd5b505060405162009270906200c1dc565b604051809103906000f0801580156200928d573d6000803e3d6000fd5b50506040516200929d906200c1dc565b604051809103906000f080158015620092ba573d6000803e3d6000fd5b5050604051620092ca906200c1dc565b604051809103906000f080158015620092e7573d6000803e3d6000fd5b5050604051620092f7906200c1dc565b604051809103906000f08015801562009314573d6000803e3d6000fd5b505060405162009324906200c1dc565b604051809103906000f08015801562009341573d6000803e3d6000fd5b505060405162009351906200c1dc565b604051809103906000f0801580156200936e573d6000803e3d6000fd5b50506040516200937e906200c1dc565b604051809103906000f0801580156200939b573d6000803e3d6000fd5b5050604051620093ab906200c1dc565b604051809103906000f080158015620093c8573d6000803e3d6000fd5b5050604051620093d8906200c1dc565b604051809103906000f080158015620093f5573d6000803e3d6000fd5b505060405162009405906200c1dc565b604051809103906000f08015801562009422573d6000803e3d6000fd5b505060405162009432906200c1dc565b604051809103906000f0801580156200944f573d6000803e3d6000fd5b50506040516200945f906200c1dc565b604051809103906000f0801580156200947c573d6000803e3d6000fd5b50506040516200948c906200c1dc565b604051809103906000f080158015620094a9573d6000803e3d6000fd5b5050604051620094b9906200c1dc565b604051809103906000f080158015620094d6573d6000803e3d6000fd5b5050604051620094e6906200c1dc565b604051809103906000f08015801562009503573d6000803e3d6000fd5b505060405162009513906200c1dc565b604051809103906000f08015801562009530573d6000803e3d6000fd5b505060405162009540906200c1dc565b604051809103906000f0801580156200955d573d6000803e3d6000fd5b50506040516200956d906200c1dc565b604051809103906000f0801580156200958a573d6000803e3d6000fd5b50506040516200959a906200c1dc565b604051809103906000f080158015620095b7573d6000803e3d6000fd5b5050604051620095c7906200c1dc565b604051809103906000f080158015620095e4573d6000803e3d6000fd5b5050604051620095f4906200c1dc565b604051809103906000f08015801562009611573d6000803e3d6000fd5b505060405162009621906200c1dc565b604051809103906000f0801580156200963e573d6000803e3d6000fd5b50506040516200964e906200c1dc565b604051809103906000f0801580156200966b573d6000803e3d6000fd5b50506040516200967b906200c1dc565b604051809103906000f08015801562009698573d6000803e3d6000fd5b5050604051620096a8906200c1dc565b604051809103906000f080158015620096c5573d6000803e3d6000fd5b5050604051620096d5906200c1dc565b604051809103906000f080158015620096f2573d6000803e3d6000fd5b505060405162009702906200c1dc565b604051809103906000f0801580156200971f573d6000803e3d6000fd5b50506040516200972f906200c1dc565b604051809103906000f0801580156200974c573d6000803e3d6000fd5b50506040516200975c906200c1dc565b604051809103906000f08015801562009779573d6000803e3d6000fd5b505060405162009789906200c1dc565b604051809103906000f080158015620097a6573d6000803e3d6000fd5b5050604051620097b6906200c1dc565b604051809103906000f080158015620097d3573d6000803e3d6000fd5b5050604051620097e3906200c1dc565b604051809103906000f08015801562009800573d6000803e3d6000fd5b505060405162009810906200c1dc565b604051809103906000f0801580156200982d573d6000803e3d6000fd5b50506040516200983d906200c1dc565b604051809103906000f0801580156200985a573d6000803e3d6000fd5b50506040516200986a906200c1dc565b604051809103906000f08015801562009887573d6000803e3d6000fd5b505060405162009897906200c1dc565b604051809103906000f080158015620098b4573d6000803e3d6000fd5b5050604051620098c4906200c1dc565b604051809103906000f080158015620098e1573d6000803e3d6000fd5b5050604051620098f1906200c1dc565b604051809103906000f0801580156200990e573d6000803e3d6000fd5b50506040516200991e906200c1dc565b604051809103906000f0801580156200993b573d6000803e3d6000fd5b50506040516200994b906200c1dc565b604051809103906000f08015801562009968573d6000803e3d6000fd5b505060405162009978906200c1dc565b604051809103906000f08015801562009995573d6000803e3d6000fd5b5050604051620099a5906200c1dc565b604051809103906000f080158015620099c2573d6000803e3d6000fd5b5050604051620099d2906200c1dc565b604051809103906000f080158015620099ef573d6000803e3d6000fd5b5050604051620099ff906200c1dc565b604051809103906000f08015801562009a1c573d6000803e3d6000fd5b505060405162009a2c906200c1dc565b604051809103906000f08015801562009a49573d6000803e3d6000fd5b505060405162009a59906200c1dc565b604051809103906000f08015801562009a76573d6000803e3d6000fd5b505060405162009a86906200c1dc565b604051809103906000f08015801562009aa3573d6000803e3d6000fd5b505060405162009ab3906200c1dc565b604051809103906000f08015801562009ad0573d6000803e3d6000fd5b505060405162009ae0906200c1dc565b604051809103906000f08015801562009afd573d6000803e3d6000fd5b505060405162009b0d906200c1dc565b604051809103906000f08015801562009b2a573d6000803e3d6000fd5b505060405162009b3a906200c1dc565b604051809103906000f08015801562009b57573d6000803e3d6000fd5b505060405162009b67906200c1dc565b604051809103906000f08015801562009b84573d6000803e3d6000fd5b505060405162009b94906200c1dc565b604051809103906000f08015801562009bb1573d6000803e3d6000fd5b505060405162009bc1906200c1dc565b604051809103906000f08015801562009bde573d6000803e3d6000fd5b505060405162009bee906200c1dc565b604051809103906000f08015801562009c0b573d6000803e3d6000fd5b505060405162009c1b906200c1dc565b604051809103906000f08015801562009c38573d6000803e3d6000fd5b505060405162009c48906200c1dc565b604051809103906000f08015801562009c65573d6000803e3d6000fd5b505060405162009c75906200c1dc565b604051809103906000f08015801562009c92573d6000803e3d6000fd5b505060405162009ca2906200c1dc565b604051809103906000f08015801562009cbf573d6000803e3d6000fd5b505060405162009ccf906200c1dc565b604051809103906000f08015801562009cec573d6000803e3d6000fd5b505060405162009cfc906200c1dc565b604051809103906000f08015801562009d19573d6000803e3d6000fd5b505060405162009d29906200c1dc565b604051809103906000f08015801562009d46573d6000803e3d6000fd5b505060405162009d56906200c1dc565b604051809103906000f08015801562009d73573d6000803e3d6000fd5b505060405162009d83906200c1dc565b604051809103906000f08015801562009da0573d6000803e3d6000fd5b505060405162009db0906200c1dc565b604051809103906000f08015801562009dcd573d6000803e3d6000fd5b505060405162009ddd906200c1dc565b604051809103906000f08015801562009dfa573d6000803e3d6000fd5b505060405162009e0a906200c1dc565b604051809103906000f08015801562009e27573d6000803e3d6000fd5b505060405162009e37906200c1dc565b604051809103906000f08015801562009e54573d6000803e3d6000fd5b505060405162009e64906200c1dc565b604051809103906000f08015801562009e81573d6000803e3d6000fd5b505060405162009e91906200c1dc565b604051809103906000f08015801562009eae573d6000803e3d6000fd5b505060405162009ebe906200c1dc565b604051809103906000f08015801562009edb573d6000803e3d6000fd5b505060405162009eeb906200c1dc565b604051809103906000f08015801562009f08573d6000803e3d6000fd5b505060405162009f18906200c1dc565b604051809103906000f08015801562009f35573d6000803e3d6000fd5b505060405162009f45906200c1dc565b604051809103906000f08015801562009f62573d6000803e3d6000fd5b505060405162009f72906200c1dc565b604051809103906000f08015801562009f8f573d6000803e3d6000fd5b505060405162009f9f906200c1dc565b604051809103906000f08015801562009fbc573d6000803e3d6000fd5b505060405162009fcc906200c1dc565b604051809103906000f08015801562009fe9573d6000803e3d6000fd5b505060405162009ff9906200c1dc565b604051809103906000f0801580156200a016573d6000803e3d6000fd5b50506040516200a026906200c1dc565b604051809103906000f0801580156200a043573d6000803e3d6000fd5b50506040516200a053906200c1dc565b604051809103906000f0801580156200a070573d6000803e3d6000fd5b50506040516200a080906200c1dc565b604051809103906000f0801580156200a09d573d6000803e3d6000fd5b50506040516200a0ad906200c1dc565b604051809103906000f0801580156200a0ca573d6000803e3d6000fd5b50506040516200a0da906200c1dc565b604051809103906000f0801580156200a0f7573d6000803e3d6000fd5b50506040516200a107906200c1dc565b604051809103906000f0801580156200a124573d6000803e3d6000fd5b50506040516200a134906200c1dc565b604051809103906000f0801580156200a151573d6000803e3d6000fd5b50506040516200a161906200c1dc565b604051809103906000f0801580156200a17e573d6000803e3d6000fd5b50506040516200a18e906200c1dc565b604051809103906000f0801580156200a1ab573d6000803e3d6000fd5b50506040516200a1bb906200c1dc565b604051809103906000f0801580156200a1d8573d6000803e3d6000fd5b50506040516200a1e8906200c1dc565b604051809103906000f0801580156200a205573d6000803e3d6000fd5b50506040516200a215906200c1dc565b604051809103906000f0801580156200a232573d6000803e3d6000fd5b50506040516200a242906200c1dc565b604051809103906000f0801580156200a25f573d6000803e3d6000fd5b50506040516200a26f906200c1dc565b604051809103906000f0801580156200a28c573d6000803e3d6000fd5b50506040516200a29c906200c1dc565b604051809103906000f0801580156200a2b9573d6000803e3d6000fd5b50506040516200a2c9906200c1dc565b604051809103906000f0801580156200a2e6573d6000803e3d6000fd5b50506040516200a2f6906200c1dc565b604051809103906000f0801580156200a313573d6000803e3d6000fd5b50506040516200a323906200c1dc565b604051809103906000f0801580156200a340573d6000803e3d6000fd5b50506040516200a350906200c1dc565b604051809103906000f0801580156200a36d573d6000803e3d6000fd5b50506040516200a37d906200c1dc565b604051809103906000f0801580156200a39a573d6000803e3d6000fd5b50506040516200a3aa906200c1dc565b604051809103906000f0801580156200a3c7573d6000803e3d6000fd5b50506040516200a3d7906200c1dc565b604051809103906000f0801580156200a3f4573d6000803e3d6000fd5b50506040516200a404906200c1dc565b604051809103906000f0801580156200a421573d6000803e3d6000fd5b50506040516200a431906200c1dc565b604051809103906000f0801580156200a44e573d6000803e3d6000fd5b50506040516200a45e906200c1dc565b604051809103906000f0801580156200a47b573d6000803e3d6000fd5b50506040516200a48b906200c1dc565b604051809103906000f0801580156200a4a8573d6000803e3d6000fd5b50506040516200a4b8906200c1dc565b604051809103906000f0801580156200a4d5573d6000803e3d6000fd5b50506040516200a4e5906200c1dc565b604051809103906000f0801580156200a502573d6000803e3d6000fd5b50506040516200a512906200c1dc565b604051809103906000f0801580156200a52f573d6000803e3d6000fd5b50506040516200a53f906200c1dc565b604051809103906000f0801580156200a55c573d6000803e3d6000fd5b50506040516200a56c906200c1dc565b604051809103906000f0801580156200a589573d6000803e3d6000fd5b50506040516200a599906200c1dc565b604051809103906000f0801580156200a5b6573d6000803e3d6000fd5b50506040516200a5c6906200c1dc565b604051809103906000f0801580156200a5e3573d6000803e3d6000fd5b50506040516200a5f3906200c1dc565b604051809103906000f0801580156200a610573d6000803e3d6000fd5b50506040516200a620906200c1dc565b604051809103906000f0801580156200a63d573d6000803e3d6000fd5b50506040516200a64d906200c1dc565b604051809103906000f0801580156200a66a573d6000803e3d6000fd5b50506040516200a67a906200c1dc565b604051809103906000f0801580156200a697573d6000803e3d6000fd5b50506040516200a6a7906200c1dc565b604051809103906000f0801580156200a6c4573d6000803e3d6000fd5b50506040516200a6d4906200c1dc565b604051809103906000f0801580156200a6f1573d6000803e3d6000fd5b50506040516200a701906200c1dc565b604051809103906000f0801580156200a71e573d6000803e3d6000fd5b50506040516200a72e906200c1dc565b604051809103906000f0801580156200a74b573d6000803e3d6000fd5b50506040516200a75b906200c1dc565b604051809103906000f0801580156200a778573d6000803e3d6000fd5b50506040516200a788906200c1dc565b604051809103906000f0801580156200a7a5573d6000803e3d6000fd5b50506040516200a7b5906200c1dc565b604051809103906000f0801580156200a7d2573d6000803e3d6000fd5b50506040516200a7e2906200c1dc565b604051809103906000f0801580156200a7ff573d6000803e3d6000fd5b50506040516200a80f906200c1dc565b604051809103906000f0801580156200a82c573d6000803e3d6000fd5b50506040516200a83c906200c1dc565b604051809103906000f0801580156200a859573d6000803e3d6000fd5b50506040516200a869906200c1dc565b604051809103906000f0801580156200a886573d6000803e3d6000fd5b50506040516200a896906200c1dc565b604051809103906000f0801580156200a8b3573d6000803e3d6000fd5b50506040516200a8c3906200c1dc565b604051809103906000f0801580156200a8e0573d6000803e3d6000fd5b50506040516200a8f0906200c1dc565b604051809103906000f0801580156200a90d573d6000803e3d6000fd5b50506040516200a91d906200c1dc565b604051809103906000f0801580156200a93a573d6000803e3d6000fd5b50506040516200a94a906200c1dc565b604051809103906000f0801580156200a967573d6000803e3d6000fd5b50506040516200a977906200c1dc565b604051809103906000f0801580156200a994573d6000803e3d6000fd5b50506040516200a9a4906200c1dc565b604051809103906000f0801580156200a9c1573d6000803e3d6000fd5b50506040516200a9d1906200c1dc565b604051809103906000f0801580156200a9ee573d6000803e3d6000fd5b50506040516200a9fe906200c1dc565b604051809103906000f0801580156200aa1b573d6000803e3d6000fd5b50506040516200aa2b906200c1dc565b604051809103906000f0801580156200aa48573d6000803e3d6000fd5b50506040516200aa58906200c1dc565b604051809103906000f0801580156200aa75573d6000803e3d6000fd5b50506040516200aa85906200c1dc565b604051809103906000f0801580156200aaa2573d6000803e3d6000fd5b50506040516200aab2906200c1dc565b604051809103906000f0801580156200aacf573d6000803e3d6000fd5b50506040516200aadf906200c1dc565b604051809103906000f0801580156200aafc573d6000803e3d6000fd5b50506040516200ab0c906200c1dc565b604051809103906000f0801580156200ab29573d6000803e3d6000fd5b50506040516200ab39906200c1dc565b604051809103906000f0801580156200ab56573d6000803e3d6000fd5b50506040516200ab66906200c1dc565b604051809103906000f0801580156200ab83573d6000803e3d6000fd5b50506040516200ab93906200c1dc565b604051809103906000f0801580156200abb0573d6000803e3d6000fd5b50506040516200abc0906200c1dc565b604051809103906000f0801580156200abdd573d6000803e3d6000fd5b50506040516200abed906200c1dc565b604051809103906000f0801580156200ac0a573d6000803e3d6000fd5b50506040516200ac1a906200c1dc565b604051809103906000f0801580156200ac37573d6000803e3d6000fd5b50506040516200ac47906200c1dc565b604051809103906000f0801580156200ac64573d6000803e3d6000fd5b50506040516200ac74906200c1dc565b604051809103906000f0801580156200ac91573d6000803e3d6000fd5b50506040516200aca1906200c1dc565b604051809103906000f0801580156200acbe573d6000803e3d6000fd5b50506040516200acce906200c1dc565b604051809103906000f0801580156200aceb573d6000803e3d6000fd5b50506040516200acfb906200c1dc565b604051809103906000f0801580156200ad18573d6000803e3d6000fd5b50506040516200ad28906200c1dc565b604051809103906000f0801580156200ad45573d6000803e3d6000fd5b50506040516200ad55906200c1dc565b604051809103906000f0801580156200ad72573d6000803e3d6000fd5b50506040516200ad82906200c1dc565b604051809103906000f0801580156200ad9f573d6000803e3d6000fd5b50506040516200adaf906200c1dc565b604051809103906000f0801580156200adcc573d6000803e3d6000fd5b50506040516200addc906200c1dc565b604051809103906000f0801580156200adf9573d6000803e3d6000fd5b50506040516200ae09906200c1dc565b604051809103906000f0801580156200ae26573d6000803e3d6000fd5b50506040516200ae36906200c1dc565b604051809103906000f0801580156200ae53573d6000803e3d6000fd5b50506040516200ae63906200c1dc565b604051809103906000f0801580156200ae80573d6000803e3d6000fd5b50506040516200ae90906200c1dc565b604051809103906000f0801580156200aead573d6000803e3d6000fd5b50506040516200aebd906200c1dc565b604051809103906000f0801580156200aeda573d6000803e3d6000fd5b50506040516200aeea906200c1dc565b604051809103906000f0801580156200af07573d6000803e3d6000fd5b50506040516200af17906200c1dc565b604051809103906000f0801580156200af34573d6000803e3d6000fd5b50506040516200af44906200c1dc565b604051809103906000f0801580156200af61573d6000803e3d6000fd5b50506040516200af71906200c1dc565b604051809103906000f0801580156200af8e573d6000803e3d6000fd5b50506040516200af9e906200c1dc565b604051809103906000f0801580156200afbb573d6000803e3d6000fd5b50506040516200afcb906200c1dc565b604051809103906000f0801580156200afe8573d6000803e3d6000fd5b50506040516200aff8906200c1dc565b604051809103906000f0801580156200b015573d6000803e3d6000fd5b50506040516200b025906200c1dc565b604051809103906000f0801580156200b042573d6000803e3d6000fd5b50506040516200b052906200c1dc565b604051809103906000f0801580156200b06f573d6000803e3d6000fd5b50506040516200b07f906200c1dc565b604051809103906000f0801580156200b09c573d6000803e3d6000fd5b50506040516200b0ac906200c1dc565b604051809103906000f0801580156200b0c9573d6000803e3d6000fd5b50506040516200b0d9906200c1dc565b604051809103906000f0801580156200b0f6573d6000803e3d6000fd5b50506040516200b106906200c1dc565b604051809103906000f0801580156200b123573d6000803e3d6000fd5b50506040516200b133906200c1dc565b604051809103906000f0801580156200b150573d6000803e3d6000fd5b50506040516200b160906200c1dc565b604051809103906000f0801580156200b17d573d6000803e3d6000fd5b50506040516200b18d906200c1dc565b604051809103906000f0801580156200b1aa573d6000803e3d6000fd5b50506040516200b1ba906200c1dc565b604051809103906000f0801580156200b1d7573d6000803e3d6000fd5b50506040516200b1e7906200c1dc565b604051809103906000f0801580156200b204573d6000803e3d6000fd5b50506040516200b214906200c1dc565b604051809103906000f0801580156200b231573d6000803e3d6000fd5b50506040516200b241906200c1dc565b604051809103906000f0801580156200b25e573d6000803e3d6000fd5b50506040516200b26e906200c1dc565b604051809103906000f0801580156200b28b573d6000803e3d6000fd5b50506040516200b29b906200c1dc565b604051809103906000f0801580156200b2b8573d6000803e3d6000fd5b50506040516200b2c8906200c1dc565b604051809103906000f0801580156200b2e5573d6000803e3d6000fd5b50506040516200b2f5906200c1dc565b604051809103906000f0801580156200b312573d6000803e3d6000fd5b50506040516200b322906200c1dc565b604051809103906000f0801580156200b33f573d6000803e3d6000fd5b50506040516200b34f906200c1dc565b604051809103906000f0801580156200b36c573d6000803e3d6000fd5b50506040516200b37c906200c1dc565b604051809103906000f0801580156200b399573d6000803e3d6000fd5b50506040516200b3a9906200c1dc565b604051809103906000f0801580156200b3c6573d6000803e3d6000fd5b50506040516200b3d6906200c1dc565b604051809103906000f0801580156200b3f3573d6000803e3d6000fd5b50506040516200b403906200c1dc565b604051809103906000f0801580156200b420573d6000803e3d6000fd5b50506040516200b430906200c1dc565b604051809103906000f0801580156200b44d573d6000803e3d6000fd5b50506040516200b45d906200c1dc565b604051809103906000f0801580156200b47a573d6000803e3d6000fd5b50506040516200b48a906200c1dc565b604051809103906000f0801580156200b4a7573d6000803e3d6000fd5b50506040516200b4b7906200c1dc565b604051809103906000f0801580156200b4d4573d6000803e3d6000fd5b50506040516200b4e4906200c1dc565b604051809103906000f0801580156200b501573d6000803e3d6000fd5b50506040516200b511906200c1dc565b604051809103906000f0801580156200b52e573d6000803e3d6000fd5b50506040516200b53e906200c1dc565b604051809103906000f0801580156200b55b573d6000803e3d6000fd5b50506040516200b56b906200c1dc565b604051809103906000f0801580156200b588573d6000803e3d6000fd5b50506040516200b598906200c1dc565b604051809103906000f0801580156200b5b5573d6000803e3d6000fd5b50506040516200b5c5906200c1dc565b604051809103906000f0801580156200b5e2573d6000803e3d6000fd5b50506040516200b5f2906200c1dc565b604051809103906000f0801580156200b60f573d6000803e3d6000fd5b50506040516200b61f906200c1dc565b604051809103906000f0801580156200b63c573d6000803e3d6000fd5b50506040516200b64c906200c1dc565b604051809103906000f0801580156200b669573d6000803e3d6000fd5b50506040516200b679906200c1dc565b604051809103906000f0801580156200b696573d6000803e3d6000fd5b50506040516200b6a6906200c1dc565b604051809103906000f0801580156200b6c3573d6000803e3d6000fd5b50506040516200b6d3906200c1dc565b604051809103906000f0801580156200b6f0573d6000803e3d6000fd5b50506040516200b700906200c1dc565b604051809103906000f0801580156200b71d573d6000803e3d6000fd5b50506040516200b72d906200c1dc565b604051809103906000f0801580156200b74a573d6000803e3d6000fd5b50506040516200b75a906200c1dc565b604051809103906000f0801580156200b777573d6000803e3d6000fd5b50506040516200b787906200c1dc565b604051809103906000f0801580156200b7a4573d6000803e3d6000fd5b50506040516200b7b4906200c1dc565b604051809103906000f0801580156200b7d1573d6000803e3d6000fd5b50506040516200b7e1906200c1dc565b604051809103906000f0801580156200b7fe573d6000803e3d6000fd5b50506040516200b80e906200c1dc565b604051809103906000f0801580156200b82b573d6000803e3d6000fd5b50506040516200b83b906200c1dc565b604051809103906000f0801580156200b858573d6000803e3d6000fd5b50506040516200b868906200c1dc565b604051809103906000f0801580156200b885573d6000803e3d6000fd5b50506040516200b895906200c1dc565b604051809103906000f0801580156200b8b2573d6000803e3d6000fd5b50506040516200b8c2906200c1dc565b604051809103906000f0801580156200b8df573d6000803e3d6000fd5b50506040516200b8ef906200c1dc565b604051809103906000f0801580156200b90c573d6000803e3d6000fd5b50506040516200b91c906200c1dc565b604051809103906000f0801580156200b939573d6000803e3d6000fd5b50506040516200b949906200c1dc565b604051809103906000f0801580156200b966573d6000803e3d6000fd5b50506040516200b976906200c1dc565b604051809103906000f0801580156200b993573d6000803e3d6000fd5b50506040516200b9a3906200c1dc565b604051809103906000f0801580156200b9c0573d6000803e3d6000fd5b50506040516200b9d0906200c1dc565b604051809103906000f0801580156200b9ed573d6000803e3d6000fd5b50506040516200b9fd906200c1dc565b604051809103906000f0801580156200ba1a573d6000803e3d6000fd5b50506040516200ba2a906200c1dc565b604051809103906000f0801580156200ba47573d6000803e3d6000fd5b50506040516200ba57906200c1dc565b604051809103906000f0801580156200ba74573d6000803e3d6000fd5b50506040516200ba84906200c1dc565b604051809103906000f0801580156200baa1573d6000803e3d6000fd5b50506040516200bab1906200c1dc565b604051809103906000f0801580156200bace573d6000803e3d6000fd5b50506040516200bade906200c1dc565b604051809103906000f0801580156200bafb573d6000803e3d6000fd5b50506040516200bb0b906200c1dc565b604051809103906000f0801580156200bb28573d6000803e3d6000fd5b50506040516200bb38906200c1dc565b604051809103906000f0801580156200bb55573d6000803e3d6000fd5b50506040516200bb65906200c1dc565b604051809103906000f0801580156200bb82573d6000803e3d6000fd5b50506040516200bb92906200c1dc565b604051809103906000f0801580156200bbaf573d6000803e3d6000fd5b50506040516200bbbf906200c1dc565b604051809103906000f0801580156200bbdc573d6000803e3d6000fd5b50506040516200bbec906200c1dc565b604051809103906000f0801580156200bc09573d6000803e3d6000fd5b50506040516200bc19906200c1dc565b604051809103906000f0801580156200bc36573d6000803e3d6000fd5b50506040516200bc46906200c1dc565b604051809103906000f0801580156200bc63573d6000803e3d6000fd5b50506040516200bc73906200c1dc565b604051809103906000f0801580156200bc90573d6000803e3d6000fd5b50506040516200bca0906200c1dc565b604051809103906000f0801580156200bcbd573d6000803e3d6000fd5b50506040516200bccd906200c1dc565b604051809103906000f0801580156200bcea573d6000803e3d6000fd5b50506040516200bcfa906200c1dc565b604051809103906000f0801580156200bd17573d6000803e3d6000fd5b50506040516200bd27906200c1dc565b604051809103906000f0801580156200bd44573d6000803e3d6000fd5b50506040516200bd54906200c1dc565b604051809103906000f0801580156200bd71573d6000803e3d6000fd5b50506040516200bd81906200c1dc565b604051809103906000f0801580156200bd9e573d6000803e3d6000fd5b50506040516200bdae906200c1dc565b604051809103906000f0801580156200bdcb573d6000803e3d6000fd5b50506040516200bddb906200c1dc565b604051809103906000f0801580156200bdf8573d6000803e3d6000fd5b50506040516200be08906200c1dc565b604051809103906000f0801580156200be25573d6000803e3d6000fd5b50506040516200be35906200c1dc565b604051809103906000f0801580156200be52573d6000803e3d6000fd5b50506040516200be62906200c1dc565b604051809103906000f0801580156200be7f573d6000803e3d6000fd5b50506040516200be8f906200c1dc565b604051809103906000f0801580156200beac573d6000803e3d6000fd5b50506040516200bebc906200c1dc565b604051809103906000f0801580156200bed9573d6000803e3d6000fd5b50506040516200bee9906200c1dc565b604051809103906000f0801580156200bf06573d6000803e3d6000fd5b50506040516200bf16906200c1dc565b604051809103906000f0801580156200bf33573d6000803e3d6000fd5b50506040516200bf43906200c1dc565b604051809103906000f0801580156200bf60573d6000803e3d6000fd5b50506040516200bf70906200c1dc565b604051809103906000f0801580156200bf8d573d6000803e3d6000fd5b50506040516200bf9d906200c1dc565b604051809103906000f0801580156200bfba573d6000803e3d6000fd5b50506040516200bfca906200c1dc565b604051809103906000f0801580156200bfe7573d6000803e3d6000fd5b50506040516200bff7906200c1dc565b604051809103906000f0801580156200c014573d6000803e3d6000fd5b50506040516200c024906200c1dc565b604051809103906000f0801580156200c041573d6000803e3d6000fd5b50506040516200c051906200c1dc565b604051809103906000f0801580156200c06e573d6000803e3d6000fd5b50506040516200c07e906200c1dc565b604051809103906000f0801580156200c09b573d6000803e3d6000fd5b50506040516200c0ab906200c1dc565b604051809103906000f0801580156200c0c8573d6000803e3d6000fd5b50506040516200c0d8906200c1dc565b604051809103906000f0801580156200c0f5573d6000803e3d6000fd5b50506040516200c105906200c1dc565b604051809103906000f0801580156200c122573d6000803e3d6000fd5b50506040516200c132906200c1dc565b604051809103906000f0801580156200c14f573d6000803e3d6000fd5b50506040516200c15f906200c1dc565b604051809103906000f0801580156200c17c573d6000803e3d6000fd5b50506040516200c18c906200c1dc565b604051809103906000f0801580156200c1a9573d6000803e3d6000fd5b50506040516200c1b9906200c1dc565b604051809103906000f0801580156200c1d6573d6000803e3d6000fd5b50505050565b60d7806200c1ea8339019056fe608060405234801561001057600080fd5b50d3801561001d57600080fd5b50d2801561002a57600080fd5b50609e806100396000396000f3fe6080604052600436106038577c010000000000000000000000000000000000000000000000000000000060003504631a6952308114603d575b600080fd5b606d60048036036020811015605157600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16606f565b005b5056fea165627a7a7230582083f7a0331a259c77978d4e827b5b676f9e07ff2fa04be79c314e25873f3b11040029a165627a7a7230582084782da67a2e82014f2871d2e67c7a7d13b0595d88286112fb82e4f6ea3cf8700029" + } @@ -479,5 +478,6 @@ abi = { abi_ContractTrcToken078_AddressTest5 = "[{\"constant\":false,\"inputs\":[{\"name\":\"c\",\"type\":\"address\"}],\"name\":\"setIinC\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"toAddress\",\"type\":\"address\"}],\"name\":\"transferTo\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"constructor\"},{\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"fallback\"}]" abi_ContractTrcToken078_AddressTest6 = "[{\"constant\":true,\"inputs\":[],\"name\":\"sender\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"origin\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"constructor\"},{\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"fallback\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"\",\"type\":\"address\"}],\"name\":\"log\",\"type\":\"event\"}]" + abi_veryLarge = "[{\"constant\":false,\"inputs\":[],\"name\":\"getBalance\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"Address\",\"type\":\"address\"}],\"name\":\"transfer\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"num\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"constructor\"}]" } \ No newline at end of file From e2c117c19e95e1dc5150702ea64839d404d5c97b Mon Sep 17 00:00:00 2001 From: xiechang33 <354035097@qq.com> Date: Fri, 10 May 2019 17:27:24 +0800 Subject: [PATCH 09/90] add tvm stest --- .../WalletTestMutiSign018.java | 139 +++++++++++++++++- 1 file changed, 136 insertions(+), 3 deletions(-) diff --git a/src/test/java/stest/tron/wallet/dailybuild/operationupdate/WalletTestMutiSign018.java b/src/test/java/stest/tron/wallet/dailybuild/operationupdate/WalletTestMutiSign018.java index 23fc3446630..706e18c2dd8 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/operationupdate/WalletTestMutiSign018.java +++ b/src/test/java/stest/tron/wallet/dailybuild/operationupdate/WalletTestMutiSign018.java @@ -83,7 +83,7 @@ public void beforeSuite() { * constructor. */ - @BeforeClass(enabled = true) + @BeforeClass(enabled = false) public void beforeClass() { channelFull = ManagedChannelBuilder.forTarget(fullnode) .usePlaintext(true) @@ -95,8 +95,8 @@ public void beforeClass() { blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); } - @Test(enabled = true, threadPoolSize = 1, invocationCount = 1) - public void testMutiSignForClearContractAbi() { + @Test(enabled = false, threadPoolSize = 1, invocationCount = 1) + public void test1MutiSignForClearContractAbi() { ecKey1 = new ECKey(Utils.getRandom()); manager1Address = ecKey1.getAddress(); manager1Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -172,6 +172,139 @@ public void testMutiSignForClearContractAbi() { PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, ownerAddress, blockingStubFull)); } + @Test(enabled = false, threadPoolSize = 1, invocationCount = 1) + public void test2MutiSignForClearContractAbiForDefault() { + ecKey1 = new ECKey(Utils.getRandom()); + manager1Address = ecKey1.getAddress(); + manager1Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + ecKey2 = new ECKey(Utils.getRandom()); + manager2Address = ecKey2.getAddress(); + manager2Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + + ecKey3 = new ECKey(Utils.getRandom()); + ownerAddress = ecKey3.getAddress(); + ownerKey = ByteArray.toHexString(ecKey3.getPrivKeyBytes()); + PublicMethed.printAddress(ownerKey); + + long needcoin = updateAccountPermissionFee + multiSignFee * 4; + + Assert.assertTrue( + PublicMethed.sendcoin(ownerAddress, needcoin + 100000000L, fromAddress, testKey002, + blockingStubFull)); + Assert.assertTrue(PublicMethed + .freezeBalanceForReceiver(fromAddress, 1000000000, 0, 0, ByteString.copyFrom(ownerAddress), + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed + .freezeBalanceForReceiver(fromAddress, 1000000000, 0, 1, ByteString.copyFrom(ownerAddress), + testKey002, blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + Long balanceBefore = PublicMethed.queryAccount(ownerAddress, blockingStubFull) + .getBalance(); + logger.info("balanceBefore: " + balanceBefore); + + permissionKeyString[0] = manager1Key; + permissionKeyString[1] = manager2Key; + PublicMethed.waitProduceNextBlock(blockingStubFull); + ownerKeyString[0] = ownerKey; + ownerKeyString[1] = manager1Key; + String operationsDefault = "7fff1fc0034e0100000000000000000000000000000000000000000000000000"; + accountPermissionJson = + "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":2,\"keys\":[" + + "{\"address\":\"" + PublicMethed.getAddressString(manager1Key) + "\",\"weight\":1}," + + "{\"address\":\"" + PublicMethed.getAddressString(ownerKey) + + "\",\"weight\":1}]}," + + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," + + "\"operations\":\"" + operationsDefault + "\"," + + "\"keys\":[" + + "{\"address\":\"" + PublicMethed.getAddressString(manager1Key) + "\",\"weight\":1}," + + "{\"address\":\"" + PublicMethed.getAddressString(manager2Key) + "\",\"weight\":1}" + + "]}]}"; + logger.info(accountPermissionJson); + PublicMethedForMutiSign.accountPermissionUpdate(accountPermissionJson, ownerAddress, ownerKey, + blockingStubFull, ownerKeyString); + + Long maxFeeLimit = 1000000000L; + String filePath = "src/test/resources/soliditycode/TriggerConstant004.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + byte[] contractAddress = PublicMethedForMutiSign.deployContract1(contractName, abi, code, + "", maxFeeLimit, + 0L, 100, null, ownerKey, ownerAddress, blockingStubFull, 2, permissionKeyString); + logger.info("address:" + Base58.encode58Check(contractAddress)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); + Assert.assertTrue(smartContract.getAbi().toString() != null); + Assert.assertTrue(PublicMethedForMutiSign + .clearContractABI(contractAddress, ownerAddress, ownerKey, + blockingStubFull, 2, permissionKeyString)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + Assert.assertTrue( + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, ownerAddress, blockingStubFull)); + Assert.assertTrue( + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, ownerAddress, blockingStubFull)); + } + + + @Test(enabled = false, threadPoolSize = 1, invocationCount = 1) + public void test3MutiSignForClearContractAbiForDefault() { + ecKey3 = new ECKey(Utils.getRandom()); + ownerAddress = ecKey3.getAddress(); + ownerKey = ByteArray.toHexString(ecKey3.getPrivKeyBytes()); + PublicMethed.printAddress(ownerKey); + + long needcoin = updateAccountPermissionFee + multiSignFee * 4; + + Assert.assertTrue( + PublicMethed.sendcoin(ownerAddress, needcoin + 100000000L, fromAddress, testKey002, + blockingStubFull)); + Assert.assertTrue(PublicMethed + .freezeBalanceForReceiver(fromAddress, 1000000000, 0, 0, ByteString.copyFrom(ownerAddress), + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed + .freezeBalanceForReceiver(fromAddress, 1000000000, 0, 1, ByteString.copyFrom(ownerAddress), + testKey002, blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + Long balanceBefore = PublicMethed.queryAccount(ownerAddress, blockingStubFull) + .getBalance(); + logger.info("balanceBefore: " + balanceBefore); + + String[] activeDefaultKeyString = new String[1]; + + activeDefaultKeyString[0] = ownerKey; + PublicMethed.waitProduceNextBlock(blockingStubFull); + + Long maxFeeLimit = 1000000000L; + String filePath = "src/test/resources/soliditycode/TriggerConstant004.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + byte[] contractAddress = PublicMethedForMutiSign.deployContract1(contractName, abi, code, + "", maxFeeLimit, + 0L, 100, null, ownerKey, ownerAddress, blockingStubFull, 2, activeDefaultKeyString); + logger.info("address:" + Base58.encode58Check(contractAddress)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); + Assert.assertTrue(smartContract.getAbi().toString() != null); + Assert.assertTrue(PublicMethedForMutiSign + .clearContractABI(contractAddress, ownerAddress, ownerKey, + blockingStubFull, 2, activeDefaultKeyString)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + Assert.assertTrue( + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, ownerAddress, blockingStubFull)); + Assert.assertTrue( + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, ownerAddress, blockingStubFull)); + } + /** * constructor. */ From 643e78ba971e8a662719e0a72649a3e165eaa48d Mon Sep 17 00:00:00 2001 From: xiechang33 <354035097@qq.com> Date: Fri, 10 May 2019 17:56:37 +0800 Subject: [PATCH 10/90] add tvm stest --- .../{ => tvmnewcommand}/transferfailed/TransferFailed001.java | 2 +- .../{ => tvmnewcommand}/transferfailed/TransferFailed002.java | 2 +- .../{ => tvmnewcommand}/transferfailed/TransferFailed003.java | 2 +- .../{ => tvmnewcommand}/transferfailed/TransferFailed004.java | 2 +- .../{ => tvmnewcommand}/transferfailed/TransferFailed005.java | 2 +- .../{ => tvmnewcommand}/transferfailed/TransferFailed006.java | 2 +- .../{ => tvmnewcommand}/transferfailed/TransferFailed007.java | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) rename src/test/java/stest/tron/wallet/dailybuild/{ => tvmnewcommand}/transferfailed/TransferFailed001.java (99%) rename src/test/java/stest/tron/wallet/dailybuild/{ => tvmnewcommand}/transferfailed/TransferFailed002.java (99%) rename src/test/java/stest/tron/wallet/dailybuild/{ => tvmnewcommand}/transferfailed/TransferFailed003.java (99%) rename src/test/java/stest/tron/wallet/dailybuild/{ => tvmnewcommand}/transferfailed/TransferFailed004.java (99%) rename src/test/java/stest/tron/wallet/dailybuild/{ => tvmnewcommand}/transferfailed/TransferFailed005.java (99%) rename src/test/java/stest/tron/wallet/dailybuild/{ => tvmnewcommand}/transferfailed/TransferFailed006.java (99%) rename src/test/java/stest/tron/wallet/dailybuild/{ => tvmnewcommand}/transferfailed/TransferFailed007.java (99%) diff --git a/src/test/java/stest/tron/wallet/dailybuild/transferfailed/TransferFailed001.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed001.java similarity index 99% rename from src/test/java/stest/tron/wallet/dailybuild/transferfailed/TransferFailed001.java rename to src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed001.java index e7a2146939c..5a814215ef3 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/transferfailed/TransferFailed001.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed001.java @@ -1,4 +1,4 @@ -package stest.tron.wallet.dailybuild.transferfailed; +package stest.tron.wallet.dailybuild.tvmnewcommand.transferfailed; import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; diff --git a/src/test/java/stest/tron/wallet/dailybuild/transferfailed/TransferFailed002.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed002.java similarity index 99% rename from src/test/java/stest/tron/wallet/dailybuild/transferfailed/TransferFailed002.java rename to src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed002.java index 69c469ba3e8..80d56d8cc73 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/transferfailed/TransferFailed002.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed002.java @@ -1,4 +1,4 @@ -package stest.tron.wallet.dailybuild.transferfailed; +package stest.tron.wallet.dailybuild.tvmnewcommand.transferfailed; import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; diff --git a/src/test/java/stest/tron/wallet/dailybuild/transferfailed/TransferFailed003.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed003.java similarity index 99% rename from src/test/java/stest/tron/wallet/dailybuild/transferfailed/TransferFailed003.java rename to src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed003.java index 41f96ab3cd2..433daf54a0b 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/transferfailed/TransferFailed003.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed003.java @@ -1,4 +1,4 @@ -package stest.tron.wallet.dailybuild.transferfailed; +package stest.tron.wallet.dailybuild.tvmnewcommand.transferfailed; import com.google.protobuf.ByteString; import io.grpc.ManagedChannel; diff --git a/src/test/java/stest/tron/wallet/dailybuild/transferfailed/TransferFailed004.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed004.java similarity index 99% rename from src/test/java/stest/tron/wallet/dailybuild/transferfailed/TransferFailed004.java rename to src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed004.java index 8b7dc290c0f..5cf400575c8 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/transferfailed/TransferFailed004.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed004.java @@ -1,4 +1,4 @@ -package stest.tron.wallet.dailybuild.transferfailed; +package stest.tron.wallet.dailybuild.tvmnewcommand.transferfailed; import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; diff --git a/src/test/java/stest/tron/wallet/dailybuild/transferfailed/TransferFailed005.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed005.java similarity index 99% rename from src/test/java/stest/tron/wallet/dailybuild/transferfailed/TransferFailed005.java rename to src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed005.java index 73d0631cdac..e9ddbc4c4bf 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/transferfailed/TransferFailed005.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed005.java @@ -1,4 +1,4 @@ -package stest.tron.wallet.dailybuild.TransferFailed; +package stest.tron.wallet.dailybuild.tvmnewcommand.transferfailed; import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; diff --git a/src/test/java/stest/tron/wallet/dailybuild/transferfailed/TransferFailed006.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed006.java similarity index 99% rename from src/test/java/stest/tron/wallet/dailybuild/transferfailed/TransferFailed006.java rename to src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed006.java index 85db5b5d2b3..5e3b3616c30 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/transferfailed/TransferFailed006.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed006.java @@ -1,4 +1,4 @@ -package stest.tron.wallet.dailybuild.TransferFailed; +package stest.tron.wallet.dailybuild.tvmnewcommand.transferfailed; import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; diff --git a/src/test/java/stest/tron/wallet/dailybuild/transferfailed/TransferFailed007.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed007.java similarity index 99% rename from src/test/java/stest/tron/wallet/dailybuild/transferfailed/TransferFailed007.java rename to src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed007.java index 3818b50b1eb..e5690dd4e92 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/transferfailed/TransferFailed007.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed007.java @@ -1,4 +1,4 @@ -package stest.tron.wallet.dailybuild.TransferFailed; +package stest.tron.wallet.dailybuild.tvmnewcommand.transferfailed; import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; From d88e7600d79ead2a130748cbe3ecef69f51408f0 Mon Sep 17 00:00:00 2001 From: wangming Date: Thu, 16 May 2019 11:30:05 +0800 Subject: [PATCH 11/90] modify extcodehashStressTest --- .../onlinestress/ExtCodeHashStressTest.java | 16 ++++++++-------- .../resources/soliditycode/extCodeHashStress.sol | 13 ++++++++++++- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/test/java/stest/tron/wallet/onlinestress/ExtCodeHashStressTest.java b/src/test/java/stest/tron/wallet/onlinestress/ExtCodeHashStressTest.java index 14e2c27e7e3..5e2f08a0131 100644 --- a/src/test/java/stest/tron/wallet/onlinestress/ExtCodeHashStressTest.java +++ b/src/test/java/stest/tron/wallet/onlinestress/ExtCodeHashStressTest.java @@ -344,7 +344,7 @@ public void test03DeployMultiLongByteCodeContract() { ExecutorService pool = Executors.newFixedThreadPool(30); Map addressMap = new ConcurrentHashMap<>(); - int size = 10_000_000; + int size = 50_0_000; int stubSize = 30; List stubs = new ArrayList<>(); for (int i = 0; i < stubSize; i++) { @@ -454,7 +454,7 @@ public void test05TriggerContract() throws FileNotFoundException { BufferedReader reader = null; List addresses = new ArrayList<>(); try { - reader = new BufferedReader(new FileReader("src/test/resources/addresses")); + reader = new BufferedReader(new FileReader("src/test/resources/address2")); String line = reader.readLine(); while (line != null) { System.out.println(line); @@ -485,7 +485,7 @@ public void test05TriggerContract() throws FileNotFoundException { try { Thread.sleep(100000000); } catch ( - InterruptedException e) { + InterruptedException e) { e.printStackTrace(); } } @@ -515,9 +515,9 @@ public void triggerContact(String[] testList, WalletGrpc.WalletBlockingStub stub final String user001Key = testKey002; extCodeHashContractAddress = WalletClient - .decodeFromBase58Check("TEsdDpJQrLBDPmJfDF2Ex53iMfzetqHvn9"); + .decodeFromBase58Check("TJGYcUspHrwPgy72YeaVjD4Skep9Ji8Pnn"); - final long feeLimit = maxFeeLimit; + final long feeLimit = 102471600; count.getAndAdd(1); if (count.get() % 100 == 0) { long cost = (System.currentTimeMillis() - startTime) / 1000; @@ -541,7 +541,7 @@ public void test06TriggerNormalContract() throws FileNotFoundException { List addresses = new ArrayList<>(); try { reader = new BufferedReader(new FileReader( - "/Users/tron/Documents/GitHub/java-tron-odyseeyv3.2/src/test/resources/addresses")); + "src/test/resources/address2")); String line = reader.readLine(); while (line != null) { System.out.println(line); @@ -602,9 +602,9 @@ public void triggerNormalContact(String[] testList, WalletGrpc.WalletBlockingStu final String user001Key = testKey002; normalContractAddress = WalletClient - .decodeFromBase58Check("TCkqZ2YaCvmkc7bj8UCXVQs7wi7U4xr925"); + .decodeFromBase58Check("TFUSarvJtCSQhDifdRaioytThohLSLCjq4"); - final long feeLimit = maxFeeLimit; + final long feeLimit = 51079600; count.getAndAdd(1); if (count.get() % 100 == 0) { long cost = (System.currentTimeMillis() - startTime) / 1000; diff --git a/src/test/resources/soliditycode/extCodeHashStress.sol b/src/test/resources/soliditycode/extCodeHashStress.sol index 141090958e8..0d8ceadf219 100644 --- a/src/test/resources/soliditycode/extCodeHashStress.sol +++ b/src/test/resources/soliditycode/extCodeHashStress.sol @@ -31,4 +31,15 @@ contract Trigger { i++; } } - } \ No newline at end of file + } + + contract TriggerNormal { + function test(address[] memory addrs) public returns(uint i) { + bytes32 hash; + uint i = 0; + for (; i < addrs.length; i++) { + address addr = addrs[i]; + addr.balance; + } + } + } \ No newline at end of file From f5a5ec49ee90694cadbc34ffc91d8575aa744527 Mon Sep 17 00:00:00 2001 From: wubin1 Date: Fri, 17 May 2019 15:02:21 +0800 Subject: [PATCH 12/90] update read me --- .../org/tron/common/runtime/vm/LogInfo.java | 2 +- .../org/tron/core/capsule/BlockCapsule.java | 6 + .../core/capsule/TransactionInfoCapsule.java | 13 +- .../capsule/TransactionResultListCapsule.java | 125 ++++++++++++++++++ src/main/java/org/tron/core/db/Manager.java | 32 ++++- .../core/db/TransactionResultListStore.java | 17 +++ src/main/protos/core/Tron.proto | 70 ++++++++++ 7 files changed, 256 insertions(+), 9 deletions(-) create mode 100644 src/main/java/org/tron/core/capsule/TransactionResultListCapsule.java create mode 100644 src/main/java/org/tron/core/db/TransactionResultListStore.java diff --git a/src/main/java/org/tron/common/runtime/vm/LogInfo.java b/src/main/java/org/tron/common/runtime/vm/LogInfo.java index fff2299bc1a..3068d543ac9 100644 --- a/src/main/java/org/tron/common/runtime/vm/LogInfo.java +++ b/src/main/java/org/tron/common/runtime/vm/LogInfo.java @@ -24,7 +24,7 @@ import java.util.List; import org.spongycastle.util.encoders.Hex; import org.tron.common.utils.ByteUtil; -import org.tron.protos.Protocol.TransactionInfo.Log; +import org.tron.protos.Protocol.TransactionResult.Log; /** * @author Roman Mandeleil diff --git a/src/main/java/org/tron/core/capsule/BlockCapsule.java b/src/main/java/org/tron/core/capsule/BlockCapsule.java index 25e3a134d4d..45b9b034715 100755 --- a/src/main/java/org/tron/core/capsule/BlockCapsule.java +++ b/src/main/java/org/tron/core/capsule/BlockCapsule.java @@ -25,6 +25,8 @@ import java.util.List; import java.util.Vector; import java.util.stream.Collectors; +import lombok.Getter; +import lombok.Setter; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.tron.common.crypto.ECKey; @@ -44,6 +46,10 @@ @Slf4j(topic = "capsule") public class BlockCapsule implements ProtoCapsule { + @Getter + @Setter + private TransactionResultListCapsule result; + public static class BlockId extends Sha256Hash { @Override diff --git a/src/main/java/org/tron/core/capsule/TransactionInfoCapsule.java b/src/main/java/org/tron/core/capsule/TransactionInfoCapsule.java index 91aaa0ea8af..4379da77815 100644 --- a/src/main/java/org/tron/core/capsule/TransactionInfoCapsule.java +++ b/src/main/java/org/tron/core/capsule/TransactionInfoCapsule.java @@ -1,5 +1,6 @@ package org.tron.core.capsule; +import com.google.common.collect.Lists; import com.google.protobuf.ByteString; import com.google.protobuf.InvalidProtocolBufferException; import java.util.ArrayList; @@ -177,7 +178,7 @@ public static TransactionInfoCapsule buildInstance(TransactionCapsule trxCap, Bl List logList = new ArrayList<>(); programResult.getLogInfoList().forEach( logInfo -> { - logList.add(LogInfo.buildLog(logInfo)); + logList.add(buildLog(logInfo)); } ); builder.addAllLog(logList); @@ -224,4 +225,14 @@ public static TransactionInfoCapsule buildInstance(TransactionCapsule trxCap, Bl return new TransactionInfoCapsule(builder.build()); } + + public static Log buildLog(LogInfo logInfo) { + List topics = Lists.newArrayList(); + logInfo.getTopics().forEach(topic -> { + topics.add(ByteString.copyFrom(topic.getData())); + }); + ByteString address = ByteString.copyFrom(logInfo.getAddress()); + ByteString data = ByteString.copyFrom(logInfo.getData()); + return Log.newBuilder().setAddress(address).addAllTopics(topics).setData(data).build(); + } } \ No newline at end of file diff --git a/src/main/java/org/tron/core/capsule/TransactionResultListCapsule.java b/src/main/java/org/tron/core/capsule/TransactionResultListCapsule.java new file mode 100644 index 00000000000..0ef4ac62efb --- /dev/null +++ b/src/main/java/org/tron/core/capsule/TransactionResultListCapsule.java @@ -0,0 +1,125 @@ +package org.tron.core.capsule; + +import com.google.protobuf.ByteString; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.tron.common.runtime.vm.LogInfo; +import org.tron.common.runtime.vm.program.InternalTransaction; +import org.tron.common.runtime.vm.program.ProgramResult; +import org.tron.core.config.args.Args; +import org.tron.core.db.TransactionTrace; +import org.tron.protos.Protocol; +import org.tron.protos.Protocol.Block; +import org.tron.protos.Protocol.TransactionInfo; +import org.tron.protos.Protocol.TransactionResult.Log; +import org.tron.protos.Protocol.TransactionResult.code; +import org.tron.protos.Protocol.TransactionResult; +import org.tron.protos.Protocol.TransactionResultList; + +@Slf4j(topic = "capsule") +public class TransactionResultListCapsule implements ProtoCapsule { + private TransactionResultList transactionResultList; + + public TransactionResultListCapsule(BlockCapsule blockCapsule) { + transactionResultList = TransactionResultList.newBuilder().build(); + if (Objects.isNull(blockCapsule)) { + return; + } + TransactionResultList.Builder build = transactionResultList.toBuilder(). + setBlockNumber(blockCapsule.getNum()).setBlockTimeStamp(blockCapsule.getTimeStamp()); + transactionResultList = build.build(); + } + + public void addTransactionResult(TransactionResult result) { + this.transactionResultList = this.transactionResultList.toBuilder().addTransactionresult(result).build(); + } + + public static TransactionResult buildInstance(TransactionCapsule trxCap, BlockCapsule block, + TransactionTrace trace) { + + TransactionResult.Builder builder = TransactionResult.newBuilder(); + ReceiptCapsule traceReceipt = trace.getReceipt(); + builder.setResult(code.SUCESS); + if (StringUtils.isNoneEmpty(trace.getRuntimeError()) || Objects + .nonNull(trace.getRuntimeResult().getException())) { + builder.setResult(code.FAILED); + builder.setResMessage(ByteString.copyFromUtf8(trace.getRuntimeError())); + } + builder.setId(ByteString.copyFrom(trxCap.getTransactionId().getBytes())); + ProgramResult programResult = trace.getRuntimeResult(); + long fee = + programResult.getRet().getFee() + traceReceipt.getEnergyFee() + + traceReceipt.getNetFee() + traceReceipt.getMultiSignFee(); + ByteString contractResult = ByteString.copyFrom(programResult.getHReturn()); + ByteString ContractAddress = ByteString.copyFrom(programResult.getContractAddress()); + + builder.setFee(fee); + builder.addContractResult(contractResult); + builder.setContractAddress(ContractAddress); + builder.setUnfreezeAmount(programResult.getRet().getUnfreezeAmount()); + builder.setAssetIssueID(programResult.getRet().getAssetIssueID()); + builder.setExchangeId(programResult.getRet().getExchangeId()); + builder.setWithdrawAmount(programResult.getRet().getWithdrawAmount()); + builder.setExchangeReceivedAmount(programResult.getRet().getExchangeReceivedAmount()); + builder.setExchangeInjectAnotherAmount(programResult.getRet().getExchangeInjectAnotherAmount()); + builder.setExchangeWithdrawAnotherAmount( + programResult.getRet().getExchangeWithdrawAnotherAmount()); + + List logList = new ArrayList<>(); + programResult.getLogInfoList().forEach( + logInfo -> { + logList.add(LogInfo.buildLog(logInfo)); + } + ); + builder.addAllLog(logList); + builder.setReceipt(traceReceipt.getReceipt()); + + if (Args.getInstance().isSaveInternalTx() && null != programResult.getInternalTransactions()) { + for (InternalTransaction internalTransaction : programResult + .getInternalTransactions()) { + Protocol.InternalTransaction.Builder internalTrxBuilder = Protocol.InternalTransaction + .newBuilder(); + // set hash + internalTrxBuilder.setHash(ByteString.copyFrom(internalTransaction.getHash())); + // set caller + internalTrxBuilder.setCallerAddress(ByteString.copyFrom(internalTransaction.getSender())); + // set TransferTo + internalTrxBuilder + .setTransferToAddress(ByteString.copyFrom(internalTransaction.getTransferToAddress())); + //TODO: "for loop" below in future for multiple token case, we only have one for now. + Protocol.InternalTransaction.CallValueInfo.Builder callValueInfoBuilder = + Protocol.InternalTransaction.CallValueInfo.newBuilder(); + // trx will not be set token name + callValueInfoBuilder.setCallValue(internalTransaction.getValue()); + // Just one transferBuilder for now. + internalTrxBuilder.addCallValueInfo(callValueInfoBuilder); + internalTransaction.getTokenInfo().forEach((tokenId, amount) -> { + Protocol.InternalTransaction.CallValueInfo.Builder tokenInfoBuilder = + Protocol.InternalTransaction.CallValueInfo.newBuilder(); + tokenInfoBuilder.setTokenId(tokenId); + tokenInfoBuilder.setCallValue(amount); + internalTrxBuilder.addCallValueInfo(tokenInfoBuilder); + }); + // Token for loop end here + internalTrxBuilder.setNote(ByteString.copyFrom(internalTransaction.getNote().getBytes())); + internalTrxBuilder.setRejected(internalTransaction.isRejected()); + builder.addInternalTransactions(internalTrxBuilder); + } + } + + return builder.build(); + } + + @Override + public byte[] getData() { + return transactionResultList.toByteArray(); + } + + @Override + public TransactionResultList getInstance() { + return transactionResultList; + } +} \ No newline at end of file diff --git a/src/main/java/org/tron/core/db/Manager.java b/src/main/java/org/tron/core/db/Manager.java index 5608d22e1f3..f1c2270e216 100644 --- a/src/main/java/org/tron/core/db/Manager.java +++ b/src/main/java/org/tron/core/db/Manager.java @@ -70,6 +70,7 @@ import org.tron.core.capsule.ExchangeCapsule; import org.tron.core.capsule.TransactionCapsule; import org.tron.core.capsule.TransactionInfoCapsule; +import org.tron.core.capsule.TransactionResultListCapsule; import org.tron.core.capsule.WitnessCapsule; import org.tron.core.capsule.utils.BlockUtil; import org.tron.core.config.Parameter.ChainConstant; @@ -109,6 +110,7 @@ import org.tron.protos.Protocol.AccountType; import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.Transaction.Contract; +import org.tron.protos.Protocol.TransactionResult; @Slf4j(topic = "DB") @@ -135,6 +137,8 @@ public class Manager { @Autowired @Getter private BlockIndexStore blockIndexStore; + @Getter + private TransactionResultListStore resultStore; @Autowired private AccountIdIndexStore accountIdIndexStore; @Autowired @@ -845,6 +849,10 @@ private void applyBlock(BlockCapsule block) throws ContractValidateException, processBlock(block); this.blockStore.put(block.getBlockId().getBytes(), block); this.blockIndexStore.put(block.getBlockId()); + if (block.getTransactions().size() != 0) { + this.resultStore.put(block.getBlockId().getBytes(), block.getResult()); + } + updateFork(block); if (System.currentTimeMillis() - block.getTimeStamp() >= 60_000) { revokingStore.setMaxFlushCount(SnapshotManager.DEFAULT_MAX_FLUSH_COUNT); @@ -1191,12 +1199,12 @@ public boolean hasBlocks() { /** * Process transaction. */ - public boolean processTransaction(final TransactionCapsule trxCap, BlockCapsule blockCap) + public TransactionResult processTransaction(final TransactionCapsule trxCap, BlockCapsule blockCap) throws ValidateSignatureException, ContractValidateException, ContractExeException, AccountResourceInsufficientException, TransactionExpirationException, TooBigTransactionException, TooBigTransactionResultException, DupTransactionException, TaposException, ReceiptCheckErrException, VMIllegalException { if (trxCap == null) { - return false; + return null; } validateTapos(trxCap); @@ -1254,10 +1262,13 @@ public boolean processTransaction(final TransactionCapsule trxCap, BlockCapsule .ifPresent(t -> t.put(trxCap.getTransactionId().getBytes(), new BytesCapsule(ByteArray.fromLong(trxCap.getBlockNum())))); - TransactionInfoCapsule transactionInfo = TransactionInfoCapsule + TransactionResult transactionInfo = TransactionResultListCapsule .buildInstance(trxCap, blockCap, trace); - transactionHistoryStore.put(trxCap.getTransactionId().getBytes(), transactionInfo); + TransactionInfoCapsule transactionInfo2 = TransactionInfoCapsule + .buildInstance(trxCap, blockCap, trace); + + transactionHistoryStore.put(trxCap.getTransactionId().getBytes(), transactionInfo2); // if event subscribe is enabled, post contract triggers to queue postContractTrigger(trace, false); @@ -1266,7 +1277,7 @@ public boolean processTransaction(final TransactionCapsule trxCap, BlockCapsule ownerAddressSet.add(ByteArray.toHexString(TransactionCapsule.getOwner(contract))); } - return true; + return transactionInfo; } @@ -1327,6 +1338,8 @@ public synchronized BlockCapsule generateBlock( logger.warn("Witness permission is wrong"); return null; } + TransactionResultListCapsule transationResultCapsule = + new TransactionResultListCapsule(blockCapsule); Set accountSet = new HashSet<>(); Iterator iterator = pendingTransactions.iterator(); @@ -1372,11 +1385,12 @@ public synchronized BlockCapsule generateBlock( // apply transaction try (ISession tmpSeesion = revokingStore.buildSession()) { fastSyncCallBack.preExeTrans(); - processTransaction(trx, blockCapsule); + TransactionResult result = processTransaction(trx, blockCapsule); fastSyncCallBack.exeTransFinish(); tmpSeesion.merge(); // push into block blockCapsule.addTransaction(trx); + transationResultCapsule.addTransactionResult(result); if (fromPending) { iterator.remove(); } @@ -1428,6 +1442,7 @@ public synchronized BlockCapsule generateBlock( blockCapsule.setMerkleRoot(); blockCapsule.sign(privateKey); + blockCapsule.setResult(transationResultCapsule); try { this.pushBlock(blockCapsule); @@ -1516,6 +1531,10 @@ public void processBlock(BlockCapsule block) Thread.currentThread().interrupt(); } } + + TransactionResultListCapsule transationResultCapsule = + new TransactionResultListCapsule(block); + try { fastSyncCallBack.preExecute(block); for (TransactionCapsule transactionCapsule : block.getTransactions()) { @@ -1524,7 +1543,6 @@ public void processBlock(BlockCapsule block) transactionCapsule.setVerified(true); } fastSyncCallBack.preExeTrans(); - processTransaction(transactionCapsule, block); fastSyncCallBack.exeTransFinish(); } fastSyncCallBack.executePushFinish(); diff --git a/src/main/java/org/tron/core/db/TransactionResultListStore.java b/src/main/java/org/tron/core/db/TransactionResultListStore.java new file mode 100644 index 00000000000..c2f52d9912f --- /dev/null +++ b/src/main/java/org/tron/core/db/TransactionResultListStore.java @@ -0,0 +1,17 @@ +package org.tron.core.db; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; +import org.tron.core.capsule.TransactionResultListCapsule; + +@Slf4j(topic = "DB") +@Component +public class TransactionResultListStore extends TronStoreWithRevoking { + + @Autowired + public TransactionResultListStore(@Value("transactionResultListStore") String dbName) { + super(dbName); + } +} diff --git a/src/main/protos/core/Tron.proto b/src/main/protos/core/Tron.proto index 123a71b475d..44fd76831f5 100644 --- a/src/main/protos/core/Tron.proto +++ b/src/main/protos/core/Tron.proto @@ -338,6 +338,41 @@ message Transaction { repeated Result ret = 5; } +message TransactionResult { + enum code { + SUCESS = 0; + FAILED = 1; + } + message Log { + bytes address = 1; + repeated bytes topics = 2; + bytes data = 3; + } + bytes id = 1; + int64 fee = 2; + repeated bytes contractResult = 5; + bytes contract_address = 6; + ResourceReceipt receipt = 7; + repeated Log log = 8; + code result = 9; + bytes resMessage = 10; + + string assetIssueID = 14; + int64 withdraw_amount = 15; + int64 unfreeze_amount = 16; + repeated InternalTransaction internal_transactions = 17; + int64 exchange_received_amount = 18; + int64 exchange_inject_another_amount = 19; + int64 exchange_withdraw_another_amount = 20; + int64 exchange_id = 21; +} + +message TransactionResultList { + int64 blockNumber = 1; + int64 blockTimeStamp = 2; + repeated TransactionResult transactionresult = 3; +} + message TransactionInfo { enum code { SUCESS = 0; @@ -634,6 +669,41 @@ message NodeInfo { int64 allowAdaptiveEnergy = 19; } + message TransactionResult { + enum code { + SUCESS = 0; + FAILED = 1; + } + message Log { + bytes address = 1; + repeated bytes topics = 2; + bytes data = 3; + } + bytes id = 1; + int64 fee = 2; + repeated bytes contractResult = 5; + bytes contract_address = 6; + ResourceReceipt receipt = 7; + repeated Log log = 8; + code result = 9; + bytes resMessage = 10; + + string assetIssueID = 14; + int64 withdraw_amount = 15; + int64 unfreeze_amount = 16; + repeated InternalTransaction internal_transactions = 17; + int64 exchange_received_amount = 18; + int64 exchange_inject_another_amount = 19; + int64 exchange_withdraw_another_amount = 20; + int64 exchange_id = 21; + } + + message TransactionResultList { + int64 blockNumber = 1; + int64 blockTimeStamp = 2; + repeated TransactionResult transactionresult = 3; + } + message MachineInfo { int32 threadCount = 1; int32 deadLockThreadCount = 2; From 21d6fb12924c255a6b0da35618e1fdf2dea37d47 Mon Sep 17 00:00:00 2001 From: wangming Date: Mon, 20 May 2019 14:34:00 +0800 Subject: [PATCH 13/90] modify checkstyle --- .../tvmnewcommand/clearabi/ClearAbi006.java | 12 ++++-------- .../tvmnewcommand/clearabi/ClearAbi007.java | 8 ++++---- .../tvmnewcommand/shiftcommand/ShiftCommand003.java | 9 +++++---- .../transferfailed/TransferFailed005.java | 2 +- .../transferfailed/TransferFailed006.java | 2 +- .../transferfailed/TransferFailed007.java | 2 +- .../triggerconstant/TriggerConstant005.java | 10 ++++------ .../triggerconstant/TriggerConstant006.java | 10 ++++------ .../triggerconstant/TriggerConstant015.java | 3 ++- .../triggerconstant/TriggerConstant016.java | 7 ++++--- .../triggerconstant/TriggerConstant022.java | 10 +++++++--- .../triggerconstant/TriggerConstant023.java | 10 +++++++--- .../triggerconstant/TriggerConstant024.java | 4 ++-- .../triggerconstant/TriggerConstant025.java | 9 +++------ .../triggerconstant/TriggerConstant026.java | 5 ++--- .../wallet/onlinestress/ExtCodeHashStressTest.java | 3 +-- 16 files changed, 52 insertions(+), 54 deletions(-) diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi006.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi006.java index d2a2a51c1a3..169010caa28 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi006.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi006.java @@ -97,17 +97,13 @@ public void testClearAbi() { TransactionExtention transactionExtention = PublicMethed .clearContractABIForExtention(contractExcAddress1, contractExcAddress, contractExcKey, blockingStubFull); - Assert - .assertThat(transactionExtention.getResult().getCode().toString(), - containsString("CONTRACT_VALIDATE_ERROR")); - Assert - .assertThat(transactionExtention.getResult().getMessage().toStringUtf8() - , containsString("contract validate error : Contract not exists")); - + Assert.assertThat(transactionExtention.getResult().getCode().toString(), + containsString("CONTRACT_VALIDATE_ERROR")); + Assert.assertThat(transactionExtention.getResult().getMessage().toStringUtf8(), + containsString("contract validate error : Contract not exists")); } - /** * constructor. */ diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi007.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi007.java index 317794543ce..87b42860c73 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi007.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi007.java @@ -101,8 +101,8 @@ public void testClearAbi() { .assertThat(transactionExtention.getResult().getCode().toString(), containsString("CONTRACT_VALIDATE_ERROR")); Assert - .assertThat(transactionExtention.getResult().getMessage().toStringUtf8() - , containsString("contract validate error : Contract not exists")); + .assertThat(transactionExtention.getResult().getMessage().toStringUtf8(), + containsString("contract validate error : Contract not exists")); byte[] fakeAddress1 = "412B5D3405B2D26767C9C09886D53DEAFF6EB718AC111".getBytes(); TransactionExtention transactionExtention1 = PublicMethed @@ -112,8 +112,8 @@ public void testClearAbi() { .assertThat(transactionExtention1.getResult().getCode().toString(), containsString("CONTRACT_VALIDATE_ERROR")); Assert - .assertThat(transactionExtention1.getResult().getMessage().toStringUtf8() - , containsString("contract validate error : Contract not exists")); + .assertThat(transactionExtention1.getResult().getMessage().toStringUtf8(), + containsString("contract validate error : Contract not exists")); } diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand003.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand003.java index ce1da2c0d00..a7a22a798fd 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand003.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand003.java @@ -117,7 +117,6 @@ public void test1ShiftLeft() { logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; byte[] originNumber = new DataWord( ByteArray @@ -130,6 +129,7 @@ public void test1ShiftLeft() { System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); String param = Hex.toHexString(paramBytes); logger.info("param:" + param); + String txid = ""; txid = PublicMethed.triggerContract(contractAddress, "shlTest(uint256,uint256)", param, true, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); @@ -193,7 +193,6 @@ public void test2ShiftRight() { logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; byte[] originNumber = new DataWord( ByteArray @@ -206,6 +205,7 @@ public void test2ShiftRight() { System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); String param = Hex.toHexString(paramBytes); logger.info("param:" + param); + String txid = ""; txid = PublicMethed.triggerContract(contractAddress, "shrTest(uint256,uint256)", param, true, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); @@ -252,7 +252,8 @@ public void test2ShiftRight() { } - @Test(enabled = true, description = "Trigger new ShiftRightSigned with displacement number too short ") + @Test(enabled = true, description = "Trigger new ShiftRightSigned " + + "with displacement number too short ") public void test3ShiftRightSigned() { Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, @@ -269,7 +270,6 @@ public void test3ShiftRightSigned() { logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; byte[] originNumber = new DataWord( ByteArray @@ -282,6 +282,7 @@ public void test3ShiftRightSigned() { System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); String param = Hex.toHexString(paramBytes); logger.info("param:" + param); + String txid = ""; txid = PublicMethed.triggerContract(contractAddress, "sarTest(uint256,uint256)", param, true, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed005.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed005.java index e9ddbc4c4bf..b284e381a82 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed005.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed005.java @@ -77,7 +77,7 @@ public void beforeClass() { } - @Test(enabled = true, description = "deploy contract for trigger") + @Test(enabled = true, description = "Deploy contract for trigger") public void deployContract() { Assert.assertTrue(PublicMethed .sendcoin(accountExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed006.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed006.java index 5e3b3616c30..d10dc0d7870 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed006.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed006.java @@ -77,7 +77,7 @@ public void beforeClass() { } - @Test(enabled = true, description = "deploy contract for trigger") + @Test(enabled = true, description = "Deploy contract for trigger") public void deployContract() { Assert.assertTrue(PublicMethed .sendcoin(accountExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed007.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed007.java index e5690dd4e92..1cf72eae84b 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed007.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed007.java @@ -76,7 +76,7 @@ public void beforeClass() { } - @Test(enabled = true, description = "deploy contract for trigger") + @Test(enabled = true, description = "Deploy contract for trigger") public void deployContract() { Assert.assertTrue(PublicMethed .sendcoin(accountExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant005.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant005.java index 1fa72ed3f9e..92085685d1e 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant005.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant005.java @@ -131,12 +131,10 @@ public void testTriggerConstantContract() { System.out .println("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); - Assert - .assertThat(transactionExtention.getResult().getCode().toString(), - containsString("CONTRACT_EXE_ERROR")); - Assert - .assertThat(transactionExtention.getResult().getMessage().toStringUtf8() - , containsString("Attempt to call a state modifying opcode inside STATICCALL")); + Assert.assertThat(transactionExtention.getResult().getCode().toString(), + containsString("CONTRACT_EXE_ERROR")); + Assert.assertThat(transactionExtention.getResult().getMessage().toStringUtf8(), + containsString("Attempt to call a state modifying opcode inside STATICCALL")); PublicMethed.waitProduceNextBlock(blockingStubFull); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant006.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant006.java index 91f781de242..fc2456626c3 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant006.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant006.java @@ -130,12 +130,10 @@ public void testTriggerConstantContract() { System.out .println("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); - Assert - .assertThat(transactionExtention.getResult().getCode().toString(), - containsString("CONTRACT_EXE_ERROR")); - Assert - .assertThat(transactionExtention.getResult().getMessage().toStringUtf8() - , containsString("Attempt to call a state modifying opcode inside STATICCALL")); + Assert.assertThat(transactionExtention.getResult().getCode().toString(), + containsString("CONTRACT_EXE_ERROR")); + Assert.assertThat(transactionExtention.getResult().getMessage().toStringUtf8(), + containsString("Attempt to call a state modifying opcode inside STATICCALL")); PublicMethed.waitProduceNextBlock(blockingStubFull); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant015.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant015.java index 88a1b6a9715..a4d968a6e75 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant015.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant015.java @@ -91,7 +91,8 @@ public void beforeClass() { blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = true, description = "TriggerConstantContract a constant function created by create2") + @Test(enabled = true, description = "TriggerConstantContract a constant function " + + "created by create2") public void testTriggerConstantContract() { Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant016.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant016.java index 9c2dc403cb0..8185881ee02 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant016.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant016.java @@ -90,7 +90,8 @@ public void beforeClass() { blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = true, description = "TriggerConstantContract a non-constant function created by create2") + @Test(enabled = true, description = "TriggerConstantContract a non-constant function " + + "created by create2") public void testTriggerConstantContract() { Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, @@ -180,8 +181,8 @@ public void testTriggerConstantContract() { .assertThat(transactionExtention.getResult().getCode().toString(), containsString("CONTRACT_EXE_ERROR")); Assert - .assertThat(transactionExtention.getResult().getMessage().toStringUtf8() - , containsString("Attempt to call a state modifying opcode inside STATICCALL")); + .assertThat(transactionExtention.getResult().getMessage().toStringUtf8(), + containsString("Attempt to call a state modifying opcode inside STATICCALL")); } diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant022.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant022.java index 29fa1076afb..83b0ea8842e 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant022.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant022.java @@ -99,7 +99,11 @@ public void testTriggerContract() { String contractName = "testConstantContract"; HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); String code = retMap.get("byteCode").toString(); - String abi = "[{\"constant\":true,\"inputs\":[],\"name\":\"testNoPayable\",\"outputs\":[{\"name\":\"z\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"i\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"}]"; + String abi = "[{\"constant\":true,\"inputs\":[],\"name\":\"testNoPayable\",\"outputs\":[{\"" + + "name\":\"z\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable" + + "\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"i\",\"outputs\":" + + "[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\"," + + "\"type\":\"function\"}]"; contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, contractExcKey, @@ -134,8 +138,8 @@ public void testTriggerContract() { .assertThat(transactionExtention.getResult().getCode().toString(), containsString("CONTRACT_EXE_ERROR")); Assert - .assertThat(transactionExtention.getResult().getMessage().toStringUtf8() - , containsString("Attempt to call a state modifying opcode inside STATICCALL")); + .assertThat(transactionExtention.getResult().getMessage().toStringUtf8(), + containsString("Attempt to call a state modifying opcode inside STATICCALL")); } diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant023.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant023.java index 18627c37dbd..8ba7c44b951 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant023.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant023.java @@ -99,7 +99,11 @@ public void testTriggerConstantContract() { String contractName = "testConstantContract"; HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); String code = retMap.get("byteCode").toString(); - String abi = "[{\"constant\":true,\"inputs\":[],\"name\":\"testNoPayable\",\"outputs\":[{\"name\":\"z\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"i\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"}]"; + String abi = "[{\"constant\":true,\"inputs\":[],\"name\":\"testNoPayable\",\"outputs\":[{\"name" + + "\":\"z\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"" + + "type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"i\",\"outputs\":[{\"na" + + "me\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\"" + + ":\"function\"}]"; contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, contractExcKey, @@ -134,8 +138,8 @@ public void testTriggerConstantContract() { .assertThat(transactionExtention.getResult().getCode().toString(), containsString("CONTRACT_EXE_ERROR")); Assert - .assertThat(transactionExtention.getResult().getMessage().toStringUtf8() - , containsString("Attempt to call a state modifying opcode inside STATICCALL")); + .assertThat(transactionExtention.getResult().getMessage().toStringUtf8(), + containsString("Attempt to call a state modifying opcode inside STATICCALL")); } diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant024.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant024.java index 861bbcddd9e..fc67ae81c8d 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant024.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant024.java @@ -141,8 +141,8 @@ public void testTriggerConstantContract() { containsString("FAILED")); Assert .assertThat(ByteArray - .toStr(transactionExtention.getResult().getMessage().toByteArray()) - , containsString("REVERT opcode executed")); + .toStr(transactionExtention.getResult().getMessage().toByteArray()), + containsString("REVERT opcode executed")); } diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant025.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant025.java index 3aed0161027..d97293a2888 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant025.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant025.java @@ -136,13 +136,10 @@ public void testTriggerContract() { System.out.println(":" + ByteArray .toStr(transactionExtention.getResult().getMessage().toByteArray())); - Assert - .assertThat(transaction.getRet(0).getRet().toString(), + Assert.assertThat(transaction.getRet(0).getRet().toString(), containsString("FAILED")); - Assert - .assertThat(ByteArray - .toStr(transactionExtention.getResult().getMessage().toByteArray()) - , containsString("REVERT opcode executed")); + Assert.assertThat(ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray()), + containsString("REVERT opcode executed")); } diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant026.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant026.java index bb4642cc602..540f91843f5 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant026.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant026.java @@ -142,9 +142,8 @@ public void testTriggerConstantContract() { .assertThat(transaction.getRet(0).getRet().toString(), containsString("FAILED")); Assert - .assertThat(ByteArray - .toStr(transactionExtention.getResult().getMessage().toByteArray()) - , containsString("REVERT opcode executed")); + .assertThat(ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray()), + containsString("REVERT opcode executed")); } diff --git a/src/test/java/stest/tron/wallet/onlinestress/ExtCodeHashStressTest.java b/src/test/java/stest/tron/wallet/onlinestress/ExtCodeHashStressTest.java index 5e2f08a0131..43028647c2a 100644 --- a/src/test/java/stest/tron/wallet/onlinestress/ExtCodeHashStressTest.java +++ b/src/test/java/stest/tron/wallet/onlinestress/ExtCodeHashStressTest.java @@ -484,8 +484,7 @@ public void test05TriggerContract() throws FileNotFoundException { try { Thread.sleep(100000000); - } catch ( - InterruptedException e) { + } catch (InterruptedException e) { e.printStackTrace(); } } From 42e3566999cb3821b9f7943e284486a29d4a77a2 Mon Sep 17 00:00:00 2001 From: wangming Date: Tue, 21 May 2019 20:00:58 +0800 Subject: [PATCH 14/90] modify testcase runTime --- .../tvmnewcommand/clearabi/ClearAbi001.java | 159 ++- .../tvmnewcommand/clearabi/ClearAbi002.java | 2 +- .../tvmnewcommand/clearabi/ClearAbi003.java | 2 +- .../tvmnewcommand/clearabi/ClearAbi004.java | 2 +- .../tvmnewcommand/clearabi/ClearAbi006.java | 2 +- .../tvmnewcommand/clearabi/ClearAbi007.java | 2 +- .../tvmnewcommand/create2/Create2Test001.java | 373 +++++- .../tvmnewcommand/create2/Create2Test002.java | 98 +- .../tvmnewcommand/create2/Create2Test003.java | 174 +-- .../tvmnewcommand/create2/Create2Test004.java | 40 +- .../tvmnewcommand/create2/Create2Test005.java | 1 - .../extCodeHash/ExtCodeHashTest001.java | 465 ++++++- .../extCodeHash/ExtCodeHashTest002.java | 6 +- .../extCodeHash/ExtCodeHashTest003.java | 8 +- .../extCodeHash/ExtCodeHashTest004.java | 6 +- .../extCodeHash/ExtCodeHashTest006.java | 4 +- .../transferfailed/TransferFailed001.java | 67 +- .../transferfailed/TransferFailed002.java | 57 +- .../transferfailed/TransferFailed003.java | 31 +- .../transferfailed/TransferFailed004.java | 80 +- .../transferfailed/TransferFailed005.java | 262 +++- .../transferfailed/TransferFailed006.java | 4 +- .../transferfailed/TransferFailed007.java | 4 +- .../triggerconstant/TriggerConstant001.java | 1152 ++++++++++++++++- .../triggerconstant/TriggerConstant002.java | 2 +- .../triggerconstant/TriggerConstant003.java | 2 +- .../triggerconstant/TriggerConstant004.java | 2 +- .../triggerconstant/TriggerConstant005.java | 2 +- .../triggerconstant/TriggerConstant006.java | 2 +- .../triggerconstant/TriggerConstant007.java | 2 +- .../triggerconstant/TriggerConstant008.java | 2 +- .../triggerconstant/TriggerConstant009.java | 2 +- .../triggerconstant/TriggerConstant010.java | 2 +- .../triggerconstant/TriggerConstant011.java | 2 +- .../triggerconstant/TriggerConstant012.java | 2 +- .../triggerconstant/TriggerConstant013.java | 109 +- .../triggerconstant/TriggerConstant014.java | 104 +- .../triggerconstant/TriggerConstant015.java | 2 +- .../triggerconstant/TriggerConstant016.java | 2 +- .../triggerconstant/TriggerConstant018.java | 2 +- .../triggerconstant/TriggerConstant019.java | 2 +- .../triggerconstant/TriggerConstant020.java | 2 +- .../triggerconstant/TriggerConstant021.java | 2 +- .../triggerconstant/TriggerConstant022.java | 2 +- .../triggerconstant/TriggerConstant023.java | 2 +- .../triggerconstant/TriggerConstant024.java | 2 +- .../triggerconstant/TriggerConstant025.java | 2 +- .../triggerconstant/TriggerConstant026.java | 2 +- .../soliditycode/TransferFailed001.sol | 24 + .../soliditycode/TriggerConstant001.sol | 30 +- 50 files changed, 2914 insertions(+), 398 deletions(-) diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi001.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi001.java index 368278aaa38..7c2f63ac3f2 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi001.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi001.java @@ -5,6 +5,7 @@ import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import java.util.HashMap; +import java.util.Optional; import java.util.concurrent.TimeUnit; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; @@ -22,6 +23,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; @@ -89,10 +91,7 @@ public void beforeClass() { .usePlaintext(true) .build(); blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); - } - @Test(enabled = true, description = "Clear a contract created by other account") - public void testClearAbi() { Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); @@ -100,6 +99,10 @@ public void testClearAbi() { .sendcoin(contractExcAddress1, 10000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); PublicMethed.waitProduceNextBlock(blockingStubFull); + } + + @Test(enabled = true, description = "Clear a contract created by other account") + public void testClearAbi001() { String filePath = "src/test/resources/soliditycode/ClearAbi001.sol"; String contractName = "testConstantContract"; HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); @@ -147,6 +150,156 @@ public void testClearAbi() { } + @Test(enabled = true, description = "Clear a contract with ABI created by itself") + public void testClearAbi002() { +// String filePath = "src/test/resources/soliditycode/ClearAbi001.sol"; + String contractName = "testConstantContract"; +// HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); +// String code = retMap.get("byteCode").toString(); +// String abi = retMap.get("abI").toString(); +// +// contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, +// 0L, 100, null, contractExcKey, +// contractExcAddress, blockingStubFull); +// PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); + Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + + String txid = PublicMethed + .clearContractABI(contractAddress, contractExcAddress, contractExcKey, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(infoById.get().getResultValue() == 0); + + smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); + Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + } + + + @Test(enabled = true, description = "Clear a contract without ABI") + public void testClearAbi003() { +// String filePath = "src/test/resources/soliditycode/ClearAbi001.sol"; + String contractName = "testConstantContract"; +// HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); +// String code = retMap.get("byteCode").toString(); +// String abi = retMap.get("abI").toString(); +// +// contractAddress = PublicMethed.deployContract(contractName, "[]", code, "", maxFeeLimit, +// 0L, 100, null, contractExcKey, +// contractExcAddress, blockingStubFull); +// PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); + Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + + String txid = PublicMethed + .clearContractABI(contractAddress, contractExcAddress, contractExcKey, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Assert.assertTrue(infoById.get().getResultValue() == 0); + + smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); + Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + + + } + + @Test(enabled = true, description = "Clear a account address") + public void testClearAbi004() { + TransactionExtention transactionExtention = PublicMethed + .clearContractABIForExtention(contractExcAddress, contractExcAddress, contractExcKey, + blockingStubFull); + Assert + .assertThat(transactionExtention.getResult().getCode().toString(), + containsString("CONTRACT_VALIDATE_ERROR")); + Assert + .assertThat(transactionExtention.getResult().getMessage().toStringUtf8(), + containsString("contract validate error : Contract not exists")); + } + + + @Test(enabled = true, description = "Clear a uninitialized account") + public void testClearAbi005() { + + ECKey ecKeyN = new ECKey(Utils.getRandom()); + byte[] contractExcAddressN = ecKeyN.getAddress(); + String contractExcKeyN = ByteArray.toHexString(ecKeyN.getPrivKeyBytes()); + + TransactionExtention transactionExtention = PublicMethed + .clearContractABIForExtention(contractExcAddressN, contractExcAddress, contractExcKey, + blockingStubFull); + Assert.assertThat(transactionExtention.getResult().getCode().toString(), + containsString("CONTRACT_VALIDATE_ERROR")); + Assert.assertThat(transactionExtention.getResult().getMessage().toStringUtf8(), + containsString("contract validate error : Contract not exists")); + + } + + @Test(enabled = true, description = "Clear a not meet the rules address") + public void testClearAbi006() { + byte[] fakeAddress = "412B5D".getBytes(); + TransactionExtention transactionExtention = PublicMethed + .clearContractABIForExtention(fakeAddress, contractExcAddress, contractExcKey, + blockingStubFull); + Assert + .assertThat(transactionExtention.getResult().getCode().toString(), + containsString("CONTRACT_VALIDATE_ERROR")); + Assert + .assertThat(transactionExtention.getResult().getMessage().toStringUtf8(), + containsString("contract validate error : Contract not exists")); + byte[] fakeAddress1 = "412B5D3405B2D26767C9C09886D53DEAFF6EB718AC111".getBytes(); + + TransactionExtention transactionExtention1 = PublicMethed + .clearContractABIForExtention(fakeAddress1, contractExcAddress, contractExcKey, + blockingStubFull); + Assert + .assertThat(transactionExtention1.getResult().getCode().toString(), + containsString("CONTRACT_VALIDATE_ERROR")); + Assert + .assertThat(transactionExtention1.getResult().getMessage().toStringUtf8(), + containsString("contract validate error : Contract not exists")); + + + } + /** * constructor. */ diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi002.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi002.java index 3eff6970c1b..31b22bcbda0 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi002.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi002.java @@ -87,7 +87,7 @@ public void beforeClass() { blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = true, description = "Clear a contract with ABI created by itself") + @Test(enabled = false, description = "Clear a contract with ABI created by itself") public void testClearAbi() { Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi003.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi003.java index 454d6f6c613..5df6b55d13c 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi003.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi003.java @@ -87,7 +87,7 @@ public void beforeClass() { blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = true, description = "Clear a contract without ABI") + @Test(enabled = false, description = "Clear a contract without ABI") public void testClearAbi() { Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi004.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi004.java index 6a98b8c9a76..ec9a1be5ea8 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi004.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi004.java @@ -84,7 +84,7 @@ public void beforeClass() { blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = true, description = "Clear a account address") + @Test(enabled = false, description = "Clear a account address") public void testClearAbi() { Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi006.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi006.java index 169010caa28..6c1d07b3d6d 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi006.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi006.java @@ -86,7 +86,7 @@ public void beforeClass() { blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = true, description = "Clear a uninitialized account") + @Test(enabled = false, description = "Clear a uninitialized account") public void testClearAbi() { Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi007.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi007.java index 87b42860c73..8191b470252 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi007.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi007.java @@ -86,7 +86,7 @@ public void beforeClass() { blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = true, description = "Clear a not meet the rules address") + @Test(enabled = false, description = "Clear a not meet the rules address") public void testClearAbi() { Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test001.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test001.java index 58a02bff896..31ca94e6898 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test001.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test001.java @@ -1,5 +1,7 @@ package stest.tron.wallet.dailybuild.tvmnewcommand.create2; +import static org.hamcrest.core.StringContains.containsString; + import com.google.protobuf.ByteString; import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; @@ -40,8 +42,8 @@ public class Create2Test001 { .getStringList("fullnode.ip.list").get(1); private long maxFeeLimit = Configuration.getByPath("testng.conf") .getLong("defaultParameter.maxFeeLimit"); - private byte[] factoryContractAddress = null; + private byte[] factoryContractAddress2 = null; private byte[] testContractAddress = null; private ECKey ecKey1 = new ECKey(Utils.getRandom()); @@ -75,9 +77,9 @@ public void beforeClass() { @Test(enabled = true, description = "Deploy factory contract generated by new solidity") public void test01DeployFactoryContract() { - Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, + Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 10000_000_000L, fromAddress, testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 10000_000_000L, fromAddress, testKey002, blockingStubFull)); Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, @@ -90,14 +92,14 @@ public void test01DeployFactoryContract() { PublicMethed.waitProduceNextBlock(blockingStubFull); //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, - blockingStubFull); - long energyLimit = accountResource.getEnergyLimit(); - long energyUsage = accountResource.getEnergyUsed(); - long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); - logger.info("before energyLimit is " + Long.toString(energyLimit)); - logger.info("before energyUsage is " + Long.toString(energyUsage)); - logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + //AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + // blockingStubFull); + //long energyLimit = accountResource.getEnergyLimit(); + //long energyUsage = accountResource.getEnergyUsed(); + //long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + //logger.info("before energyLimit is " + Long.toString(energyLimit)); + //logger.info("before energyUsage is " + Long.toString(energyUsage)); + //logger.info("before balanceBefore is " + Long.toString(balanceBefore)); String filePath = "./src/test/resources/soliditycode/create2contract.sol"; String contractName = "Factory"; @@ -113,14 +115,14 @@ public void test01DeployFactoryContract() { dev001Address, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); - energyLimit = accountResource.getEnergyLimit(); - energyUsage = accountResource.getEnergyUsed(); - long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + //accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + //energyLimit = accountResource.getEnergyLimit(); + //energyUsage = accountResource.getEnergyUsed(); + //long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); - logger.info("after energyLimit is " + Long.toString(energyLimit)); - logger.info("after energyUsage is " + Long.toString(energyUsage)); - logger.info("after balanceAfter is " + Long.toString(balanceAfter)); + //logger.info("after energyLimit is " + Long.toString(energyLimit)); + //logger.info("after energyUsage is " + Long.toString(energyUsage)); + //logger.info("after balanceAfter is " + Long.toString(balanceAfter)); Optional infoById = PublicMethed .getTransactionInfoById(transferTokenTxid, blockingStubFull); @@ -139,15 +141,14 @@ public void test01DeployFactoryContract() { Assert.assertNotNull(smartContract.getAbi()); } - - @Test(enabled = true, description = "Trigger create2 function to deploy test contract") + @Test(enabled = true, description = "Trigger create2 command with test bytecode using factory") public void test02TriggerCreate2ToDeployTestContract() { Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, - PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 80000L, blockingStubFull), 0, 1, ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + /*AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); @@ -165,7 +166,7 @@ public void test02TriggerCreate2ToDeployTestContract() { logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); - logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore));*/ Long callValue = Long.valueOf(0); @@ -185,7 +186,7 @@ public void test02TriggerCreate2ToDeployTestContract() { blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + /*accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitAfter = accountResource.getEnergyLimit(); long devEnergyUsageAfter = accountResource.getEnergyUsed(); long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -202,7 +203,7 @@ public void test02TriggerCreate2ToDeployTestContract() { logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); - logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter));*/ Optional infoById = PublicMethed .getTransactionInfoById(triggerTxid, blockingStubFull); @@ -211,6 +212,11 @@ public void test02TriggerCreate2ToDeployTestContract() { logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + logger.info( "the value: " + PublicMethed .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); @@ -231,11 +237,319 @@ public void test02TriggerCreate2ToDeployTestContract() { testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); + SmartContract smartContract = PublicMethed.getContract(testContractAddress, blockingStubFull); + + // contract created by create2, doesn't have ABI + Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); + + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); + + // the contract address in transaction info, + // contract address of create2 contract is factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); + + // different contract address with different bytecode, same salt and address + Assert.assertNotEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(testContractAddress)); + } + + @Test(enabled = true, description = "Trigger create2 command with factory bytecode") + public void test02TriggerCreate2ToDeployFactory2Contract() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 150000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + /*AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore));*/ + + Long callValue = Long.valueOf(0); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "Factory"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String testContractCode = retMap.get("byteCode").toString(); + + Long salt = 1L; + + String param = "\"" + testContractCode + "\"," + salt; + + final String triggerTxid = PublicMethed.triggerContract(factoryContractAddress, + "deploy(bytes,uint256)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + /*accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter));*/ + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + if (infoById.get().getResultValue() != 0) { - Assert.fail("transaction failed with message: " - + infoById.get().getResMessage().toStringUtf8()); + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); } + logger.info( + "the value: " + PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + + List retList = PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + + logger.info("actualSalt: " + actualSalt); + + byte[] tmpAddress = new byte[20]; + System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); + logger.info("address_hex: " + addressHex); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + logger.info("address_final: " + addressFinal); + + factoryContractAddress2 = WalletClient.decodeFromBase58Check(addressFinal); + + SmartContract smartContract = PublicMethed + .getContract(factoryContractAddress2, blockingStubFull); + + // contract created by create2, doesn't have ABI + Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); + + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); + + // the contract address in transaction info, + // contract address of create2 contract is factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); + } + + @Test(enabled = true, description = "Trigger create2 command with test bytecode using factory2") + public void test03TriggerCreate2ToDeployTestContract2() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 80000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + /*AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore));*/ + + Long callValue = Long.valueOf(0); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String testContractCode = retMap.get("byteCode").toString(); + + Long salt = 1L; + + String param = "\"" + testContractCode + "\"," + salt; + + final String triggerTxid = PublicMethed.triggerContract(factoryContractAddress2, + "deploy(bytes,uint256)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + /*accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter));*/ + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + Assert.assertEquals(1, infoById.get().getResultValue()); + Assert + .assertThat(infoById.get().getResMessage().toStringUtf8(), + containsString("Not enough energy for 'SWAP1' operation executing")); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + user001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + user001Address, blockingStubFull); + } + + @Test(enabled = true, description = "Trigger create2 command without meta data hash in bytecode") + public void test04TriggerCreate2ToDeployTestContract() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + //AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + // blockingStubFull); + //long devEnergyLimitBefore = accountResource.getEnergyLimit(); + //long devEnergyUsageBefore = accountResource.getEnergyUsed(); + //long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + //logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + //logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + //logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + //accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + //long userEnergyLimitBefore = accountResource.getEnergyLimit(); + //long userEnergyUsageBefore = accountResource.getEnergyUsed(); + //long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + // .getBalance(); + + //logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + //logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + //logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String testContractCode = "608060405234801561001057600080fd5b50d3801561001d57600080fd5b50d2801" + + "561002a57600080fd5b5060c9806100396000396000f3fe6080604052348015600f57600080fd5b50d38015" + + "601b57600080fd5b50d28015602757600080fd5b50600436106066577c01000000000000000000000000000" + + "00000000000000000000000000000600035046368e5c0668114606b578063e5aa3d58146083575b600080fd" + + "5b60716089565b60408051918252519081900360200190f35b60716097565b6000805460010190819055905" + + "65b6000548156fe"; + + Long salt = 1L; + + String param = "\"" + testContractCode + "\"," + salt; + + final String triggerTxid = PublicMethed.triggerContract(factoryContractAddress, + "deploy(bytes,uint256)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + //accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + //long devEnergyLimitAfter = accountResource.getEnergyLimit(); + //long devEnergyUsageAfter = accountResource.getEnergyUsed(); + //long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + //logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + //logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + //logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + //accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + //long userEnergyLimitAfter = accountResource.getEnergyLimit(); + //long userEnergyUsageAfter = accountResource.getEnergyUsed(); + //long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + // .getBalance(); + + //logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + //logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + //logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + logger.info( + "the value: " + PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + + List retList = PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + + logger.info("actualSalt: " + actualSalt); + + byte[] tmpAddress = new byte[20]; + System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); + logger.info("address_hex: " + addressHex); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + logger.info("address_final: " + addressFinal); + + testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); + SmartContract smartContract = PublicMethed.getContract(testContractAddress, blockingStubFull); // contract created by create2, doesn't have ABI @@ -254,9 +568,8 @@ public void test02TriggerCreate2ToDeployTestContract() { Assert.assertNotEquals(msgSender, Base58.encode58Check(user001Address)); } - - @Test(enabled = true, description = "Trigger Test contact") - public void test03TriggerTestContract() { + @Test(enabled = false, description = "Trigger Test contact") + public void test04TriggerTestContract() { Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test002.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test002.java index 88571f54032..86af6004a14 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test002.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test002.java @@ -73,7 +73,7 @@ public void beforeClass() { PublicMethed.printAddress(user001Key); } - @Test(enabled = true, description = "Deploy factory contract") + @Test(enabled = false, description = "Deploy factory contract") public void test01DeployFactoryContract() { Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); @@ -90,14 +90,14 @@ public void test01DeployFactoryContract() { PublicMethed.waitProduceNextBlock(blockingStubFull); //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, - blockingStubFull); - long energyLimit = accountResource.getEnergyLimit(); - long energyUsage = accountResource.getEnergyUsed(); - long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); - logger.info("before energyLimit is " + Long.toString(energyLimit)); - logger.info("before energyUsage is " + Long.toString(energyUsage)); - logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + //AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + // blockingStubFull); + //long energyLimit = accountResource.getEnergyLimit(); + //long energyUsage = accountResource.getEnergyUsed(); + //long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + //logger.info("before energyLimit is " + Long.toString(energyLimit)); + //logger.info("before energyUsage is " + Long.toString(energyUsage)); + //logger.info("before balanceBefore is " + Long.toString(balanceBefore)); String filePath = "./src/test/resources/soliditycode/create2contract.sol"; String contractName = "Factory"; @@ -113,14 +113,14 @@ public void test01DeployFactoryContract() { dev001Address, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); - energyLimit = accountResource.getEnergyLimit(); - energyUsage = accountResource.getEnergyUsed(); - long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + //accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + //energyLimit = accountResource.getEnergyLimit(); + //energyUsage = accountResource.getEnergyUsed(); + //long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); - logger.info("after energyLimit is " + Long.toString(energyLimit)); - logger.info("after energyUsage is " + Long.toString(energyUsage)); - logger.info("after balanceAfter is " + Long.toString(balanceAfter)); + //logger.info("after energyLimit is " + Long.toString(energyLimit)); + //logger.info("after energyUsage is " + Long.toString(energyUsage)); + //logger.info("after balanceAfter is " + Long.toString(balanceAfter)); Optional infoById = PublicMethed .getTransactionInfoById(transferTokenTxid, blockingStubFull); @@ -140,32 +140,32 @@ public void test01DeployFactoryContract() { } - @Test(enabled = true, description = "Trigger create2 command without meta data hash in bytecode") + @Test(enabled = false, description = "Trigger create2 command without meta data hash in bytecode") public void test02TriggerCreate2ToDeployTestContract() { Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, blockingStubFull), 0, 1, ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, - blockingStubFull); - long devEnergyLimitBefore = accountResource.getEnergyLimit(); - long devEnergyUsageBefore = accountResource.getEnergyUsed(); - long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + //AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + // blockingStubFull); + //long devEnergyLimitBefore = accountResource.getEnergyLimit(); + //long devEnergyUsageBefore = accountResource.getEnergyUsed(); + //long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); - logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); - logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); - logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + //logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + //logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + //logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); - accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); - long userEnergyLimitBefore = accountResource.getEnergyLimit(); - long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) - .getBalance(); + //accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + //long userEnergyLimitBefore = accountResource.getEnergyLimit(); + //long userEnergyUsageBefore = accountResource.getEnergyUsed(); + //long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + // .getBalance(); - logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); - logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); - logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + //logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + //logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + //logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); Long callValue = Long.valueOf(0); @@ -186,24 +186,24 @@ public void test02TriggerCreate2ToDeployTestContract() { blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); - long devEnergyLimitAfter = accountResource.getEnergyLimit(); - long devEnergyUsageAfter = accountResource.getEnergyUsed(); - long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + //accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + //long devEnergyLimitAfter = accountResource.getEnergyLimit(); + //long devEnergyUsageAfter = accountResource.getEnergyUsed(); + //long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); - logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); - logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); - logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + //logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + //logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + //logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); - accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); - long userEnergyLimitAfter = accountResource.getEnergyLimit(); - long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) - .getBalance(); + //accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + //long userEnergyLimitAfter = accountResource.getEnergyLimit(); + //long userEnergyUsageAfter = accountResource.getEnergyUsed(); + //long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + // .getBalance(); - logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); - logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); - logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + //logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + //logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + //logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); Optional infoById = PublicMethed .getTransactionInfoById(triggerTxid, blockingStubFull); @@ -256,7 +256,7 @@ public void test02TriggerCreate2ToDeployTestContract() { } - @Test(enabled = true, description = "Trigger Test contract") + @Test(enabled = false, description = "Trigger Test contract") public void test03TriggerTestContract() { Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test003.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test003.java index ed433350800..7749f813d51 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test003.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test003.java @@ -89,14 +89,14 @@ public void test01DeployFactoryContract() { PublicMethed.waitProduceNextBlock(blockingStubFull); //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, - blockingStubFull); - long energyLimit = accountResource.getEnergyLimit(); - long energyUsage = accountResource.getEnergyUsed(); - long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); - logger.info("before energyLimit is " + Long.toString(energyLimit)); - logger.info("before energyUsage is " + Long.toString(energyUsage)); - logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + //AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + // blockingStubFull); + //long energyLimit = accountResource.getEnergyLimit(); + //long energyUsage = accountResource.getEnergyUsed(); + //long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + //logger.info("before energyLimit is " + Long.toString(energyLimit)); + //logger.info("before energyUsage is " + Long.toString(energyUsage)); + //logger.info("before balanceBefore is " + Long.toString(balanceBefore)); String filePath = "./src/test/resources/soliditycode/create2contract.sol"; String contractName = "Factory"; @@ -112,14 +112,14 @@ public void test01DeployFactoryContract() { dev001Address, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); - energyLimit = accountResource.getEnergyLimit(); - energyUsage = accountResource.getEnergyUsed(); - long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + //accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + //energyLimit = accountResource.getEnergyLimit(); + //energyUsage = accountResource.getEnergyUsed(); + //long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); - logger.info("after energyLimit is " + Long.toString(energyLimit)); - logger.info("after energyUsage is " + Long.toString(energyUsage)); - logger.info("after balanceAfter is " + Long.toString(balanceAfter)); + //logger.info("after energyLimit is " + Long.toString(energyLimit)); + //logger.info("after energyUsage is " + Long.toString(energyUsage)); + //logger.info("after balanceAfter is " + Long.toString(balanceAfter)); Optional infoById = PublicMethed .getTransactionInfoById(transferTokenTxid, blockingStubFull); @@ -145,25 +145,25 @@ public void test02TriggerCreate2WithInvalidBytecode() { blockingStubFull), 0, 1, ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, - blockingStubFull); - long devEnergyLimitBefore = accountResource.getEnergyLimit(); - long devEnergyUsageBefore = accountResource.getEnergyUsed(); - long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + //AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + // blockingStubFull); + //long devEnergyLimitBefore = accountResource.getEnergyLimit(); + //long devEnergyUsageBefore = accountResource.getEnergyUsed(); + //long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); - logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); - logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); - logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + //logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + //logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + //logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); - accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); - long userEnergyLimitBefore = accountResource.getEnergyLimit(); - long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) - .getBalance(); + //accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + //long userEnergyLimitBefore = accountResource.getEnergyLimit(); + //long userEnergyUsageBefore = accountResource.getEnergyUsed(); + //long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + // .getBalance(); - logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); - logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); - logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + //logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + //logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + //logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); Long callValue = Long.valueOf(0); @@ -185,24 +185,24 @@ public void test02TriggerCreate2WithInvalidBytecode() { blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); - long devEnergyLimitAfter = accountResource.getEnergyLimit(); - long devEnergyUsageAfter = accountResource.getEnergyUsed(); - long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + //accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + //long devEnergyLimitAfter = accountResource.getEnergyLimit(); + //long devEnergyUsageAfter = accountResource.getEnergyUsed(); + //long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); - logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); - logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); - logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + //logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + //logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + //logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); - accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); - long userEnergyLimitAfter = accountResource.getEnergyLimit(); - long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) - .getBalance(); + //accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + //long userEnergyLimitAfter = accountResource.getEnergyLimit(); + //long userEnergyUsageAfter = accountResource.getEnergyUsed(); + //long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + // .getBalance(); - logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); - logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); - logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + //logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + //logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + //logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); Optional infoById = PublicMethed .getTransactionInfoById(triggerTxid, blockingStubFull); @@ -224,25 +224,25 @@ public void test03TriggerCreate2WithEmptyBytecode() { blockingStubFull), 0, 1, ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, - blockingStubFull); - long devEnergyLimitBefore = accountResource.getEnergyLimit(); - long devEnergyUsageBefore = accountResource.getEnergyUsed(); - long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + //AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + // blockingStubFull); + //long devEnergyLimitBefore = accountResource.getEnergyLimit(); + //long devEnergyUsageBefore = accountResource.getEnergyUsed(); + //long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); - logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); - logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); - logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + //logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + //logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + //logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); - accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); - long userEnergyLimitBefore = accountResource.getEnergyLimit(); - long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) - .getBalance(); + //accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + //long userEnergyLimitBefore = accountResource.getEnergyLimit(); + //long userEnergyUsageBefore = accountResource.getEnergyUsed(); + //long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + // .getBalance(); - logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); - logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); - logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + //logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + //logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + //logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); Long callValue = Long.valueOf(0); @@ -258,24 +258,24 @@ public void test03TriggerCreate2WithEmptyBytecode() { blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); - long devEnergyLimitAfter = accountResource.getEnergyLimit(); - long devEnergyUsageAfter = accountResource.getEnergyUsed(); - long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + //accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + //long devEnergyLimitAfter = accountResource.getEnergyLimit(); + //long devEnergyUsageAfter = accountResource.getEnergyUsed(); + //long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); - logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); - logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); - logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + //logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + //logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + //logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); - accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); - long userEnergyLimitAfter = accountResource.getEnergyLimit(); - long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) - .getBalance(); + //accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + //long userEnergyLimitAfter = accountResource.getEnergyLimit(); + //long userEnergyUsageAfter = accountResource.getEnergyUsed(); + //long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + // .getBalance(); - logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); - logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); - logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + //logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + //logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + //logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); Optional infoById = PublicMethed .getTransactionInfoById(triggerTxid, blockingStubFull); @@ -297,7 +297,7 @@ public void test04TriggerCreate2WithShortBytecode() { blockingStubFull), 0, 1, ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + /*AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); @@ -315,7 +315,7 @@ public void test04TriggerCreate2WithShortBytecode() { logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); - logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore));*/ Long callValue = Long.valueOf(0); @@ -331,7 +331,7 @@ public void test04TriggerCreate2WithShortBytecode() { blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + /*accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitAfter = accountResource.getEnergyLimit(); long devEnergyUsageAfter = accountResource.getEnergyUsed(); long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -348,7 +348,7 @@ public void test04TriggerCreate2WithShortBytecode() { logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); - logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter));*/ Optional infoById = PublicMethed .getTransactionInfoById(triggerTxid, blockingStubFull); @@ -370,7 +370,7 @@ public void test05TriggerCreate2WithZeroBytecode() { blockingStubFull), 0, 1, ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + /*AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); @@ -388,7 +388,7 @@ public void test05TriggerCreate2WithZeroBytecode() { logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); - logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore));*/ Long callValue = Long.valueOf(0); @@ -404,7 +404,7 @@ public void test05TriggerCreate2WithZeroBytecode() { blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + /*accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitAfter = accountResource.getEnergyLimit(); long devEnergyUsageAfter = accountResource.getEnergyUsed(); long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -421,7 +421,7 @@ public void test05TriggerCreate2WithZeroBytecode() { logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); - logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter));*/ Optional infoById = PublicMethed .getTransactionInfoById(triggerTxid, blockingStubFull); @@ -443,7 +443,7 @@ public void test06TriggerCreate2WithNullBytecode() { blockingStubFull), 0, 1, ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + /*AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); @@ -461,7 +461,7 @@ public void test06TriggerCreate2WithNullBytecode() { logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); - logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore));*/ Long callValue = Long.valueOf(0); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test004.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test004.java index cce87979d19..1b6760f3669 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test004.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test004.java @@ -77,7 +77,7 @@ public void beforeClass() { PublicMethed.printAddress(user001Key); } - @Test(enabled = true, description = "Deploy factory contract") + @Test(enabled = false, description = "Deploy factory contract") public void test01DeployFactoryContract() { Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); @@ -94,14 +94,14 @@ public void test01DeployFactoryContract() { PublicMethed.waitProduceNextBlock(blockingStubFull); //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + /*AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); long energyLimit = accountResource.getEnergyLimit(); long energyUsage = accountResource.getEnergyUsed(); long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); logger.info("before energyLimit is " + Long.toString(energyLimit)); logger.info("before energyUsage is " + Long.toString(energyUsage)); - logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + logger.info("before balanceBefore is " + Long.toString(balanceBefore));*/ String filePath = "./src/test/resources/soliditycode/create2contract.sol"; String contractName = "Factory"; @@ -117,14 +117,14 @@ public void test01DeployFactoryContract() { dev001Address, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + /*accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); energyLimit = accountResource.getEnergyLimit(); energyUsage = accountResource.getEnergyUsed(); long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); logger.info("after energyLimit is " + Long.toString(energyLimit)); logger.info("after energyUsage is " + Long.toString(energyUsage)); - logger.info("after balanceAfter is " + Long.toString(balanceAfter)); + logger.info("after balanceAfter is " + Long.toString(balanceAfter));*/ Optional infoById = PublicMethed .getTransactionInfoById(transferTokenTxid, blockingStubFull); @@ -143,14 +143,14 @@ public void test01DeployFactoryContract() { Assert.assertNotNull(smartContract.getAbi()); } - @Test(enabled = true, description = "Trigger create2 command with factory bytecode") + @Test(enabled = false, description = "Trigger create2 command with factory bytecode") public void test02TriggerCreate2ToDeployFactory2Contract() { Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 150000L, blockingStubFull), 0, 1, ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + /*AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); @@ -168,7 +168,7 @@ public void test02TriggerCreate2ToDeployFactory2Contract() { logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); - logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore));*/ Long callValue = Long.valueOf(0); @@ -188,7 +188,7 @@ public void test02TriggerCreate2ToDeployFactory2Contract() { blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + /*accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitAfter = accountResource.getEnergyLimit(); long devEnergyUsageAfter = accountResource.getEnergyUsed(); long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -205,7 +205,7 @@ public void test02TriggerCreate2ToDeployFactory2Contract() { logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); - logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter));*/ Optional infoById = PublicMethed .getTransactionInfoById(triggerTxid, blockingStubFull); @@ -256,14 +256,14 @@ public void test02TriggerCreate2ToDeployFactory2Contract() { } - @Test(enabled = true, description = "Trigger create2 command with test bytecode using factory") + @Test(enabled = false, description = "Trigger create2 command with test bytecode using factory") public void test03TriggerCreate2ToDeployTestContract() { Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 80000L, blockingStubFull), 0, 1, ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + /*AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); @@ -281,7 +281,7 @@ public void test03TriggerCreate2ToDeployTestContract() { logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); - logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore));*/ Long callValue = Long.valueOf(0); @@ -301,7 +301,7 @@ public void test03TriggerCreate2ToDeployTestContract() { blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + /*accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitAfter = accountResource.getEnergyLimit(); long devEnergyUsageAfter = accountResource.getEnergyUsed(); long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -318,7 +318,7 @@ public void test03TriggerCreate2ToDeployTestContract() { logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); - logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter));*/ Optional infoById = PublicMethed .getTransactionInfoById(triggerTxid, blockingStubFull); @@ -371,14 +371,14 @@ public void test03TriggerCreate2ToDeployTestContract() { Base58.encode58Check(testContractAddress)); } - @Test(enabled = true, description = "Trigger create2 command with test bytecode using factory2") + @Test(enabled = false, description = "Trigger create2 command with test bytecode using factory2") public void test04TriggerCreate2ToDeployTestContract2() { Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 80000L, blockingStubFull), 0, 1, ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + /*AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); @@ -396,7 +396,7 @@ public void test04TriggerCreate2ToDeployTestContract2() { logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); - logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore));*/ Long callValue = Long.valueOf(0); @@ -416,7 +416,7 @@ public void test04TriggerCreate2ToDeployTestContract2() { blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + /*accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitAfter = accountResource.getEnergyLimit(); long devEnergyUsageAfter = accountResource.getEnergyUsed(); long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -433,7 +433,7 @@ public void test04TriggerCreate2ToDeployTestContract2() { logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); - logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter));*/ Optional infoById = PublicMethed .getTransactionInfoById(triggerTxid, blockingStubFull); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test005.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test005.java index 1d68ee02648..54fcfa5daa1 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test005.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test005.java @@ -252,7 +252,6 @@ public void test02TriggerCreate2ToDeployTestContract() { Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); } - @Test(enabled = true, description = "Trigger test contract") public void test03TriggerTestContract() { diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest001.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest001.java index 70858118ffa..adc4d15db8a 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest001.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest001.java @@ -25,6 +25,7 @@ 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.WalletClient; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.PublicMethed; @@ -44,6 +45,7 @@ public class ExtCodeHashTest001 { private byte[] extCodeHashContractAddress = null; private byte[] testContractAddress = null; + private String testContractAddress2 = null; private String expectedCodeHash = null; @@ -55,6 +57,10 @@ public class ExtCodeHashTest001 { private byte[] user001Address = ecKey2.getAddress(); private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + private ECKey ecKey3 = new ECKey(Utils.getRandom()); + private byte[] testAddress = ecKey3.getAddress(); + private String testKey = ByteArray.toHexString(ecKey3.getPrivKeyBytes()); + @BeforeSuite public void beforeSuite() { Wallet wallet = new Wallet(); @@ -145,7 +151,7 @@ public void test01DeployExtCodeHashContract() { Assert.assertNotNull(smartContract.getAbi()); } - @Test(enabled = true, description = "Get the extcodehash of a normal address") + @Test(enabled = false, description = "Get the extcodehash of a normal address") public void test02GetNormalAddressCodeHash() { Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, @@ -222,6 +228,463 @@ public void test02GetNormalAddressCodeHash() { Assert.assertEquals("C5D2460186F7233C927E7DB2DCC703C0E500B653CA82273B7BFAD8045D85A470", retList.get(0)); + /*PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + user001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + user001Address, blockingStubFull);*/ + } + + @Test(enabled = true, description = "Get a contract extcodehash") + public void test03GetContactCodeHash() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String param = "\"" + Base58.encode58Check(extCodeHashContractAddress) + "\""; + final String triggerTxid = PublicMethed.triggerContract(extCodeHashContractAddress, + "getCodeHashByAddr(address)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + List retList = PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray()); + + logger.info("the value: " + retList); + + Assert.assertFalse(retList.isEmpty()); + Assert.assertNotEquals("C5D2460186F7233C927E7DB2DCC703C0E500B653CA82273B7BFAD8045D85A470", + retList.get(0)); + Assert.assertNotEquals("0000000000000000000000000000000000000000000000000000000000000000", + retList.get(0)); + + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + user001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + user001Address, blockingStubFull); + } + + @Test(enabled = true, description = "Get a not exist account extcodehash") + public void test04GetNotExistAddressCodeHash() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String param = "\"" + Base58.encode58Check(testAddress) + "\""; + final String triggerTxid = PublicMethed.triggerContract(extCodeHashContractAddress, + "getCodeHashByAddr(address)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + List retList = PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray()); + + logger.info( + "the value: " + retList); + + Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000000", + retList.get(0)); + + SmartContract smartContract = PublicMethed + .getContract(extCodeHashContractAddress, blockingStubFull); + logger.info(smartContract.getBytecode().toStringUtf8()); + } + + @Test(enabled = true, description = "Active the account and get extcodehash again") + public void test05ActiveAccountGetCodeHash() { + + Assert.assertTrue(PublicMethed.sendcoin(testAddress, 1000000, fromAddress, + testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String param = "\"" + Base58.encode58Check(testAddress) + "\""; + final String triggerTxid = PublicMethed.triggerContract(extCodeHashContractAddress, + "getCodeHashByAddr(address)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + List retList = PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray()); + + logger.info("the value: " + retList); + + Assert.assertEquals("C5D2460186F7233C927E7DB2DCC703C0E500B653CA82273B7BFAD8045D85A470", + retList.get(0)); + + SmartContract smartContract = PublicMethed + .getContract(extCodeHashContractAddress, blockingStubFull); + logger.info(smartContract.getBytecode().toStringUtf8()); + + /*PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + user001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + user001Address, blockingStubFull);*/ + } + + @Test(enabled = true, description = "Get a not deployed create2 extcodehash") + public void test06GetCreate2CodeHash() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + String filePath = "./src/test/resources/soliditycode/extCodeHash.sol"; + String contractName = "TestExtCodeHash"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + final String abi = retMap.get("abI").toString(); + + Long salt = 100L; + String[] parameter = {Base58.encode58Check(user001Address), code, salt.toString()}; + logger.info(PublicMethed.create2(parameter)); + testContractAddress2 = PublicMethed.create2(parameter); + + Long callValue = Long.valueOf(0); + + String param = + "\"" + Base58.encode58Check(WalletClient.decodeFromBase58Check(testContractAddress2)) + "\""; + final String triggerTxid = PublicMethed.triggerContract(extCodeHashContractAddress, + "getCodeHashByAddr(address)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + List retList = PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray()); + + logger.info( + "the value: " + retList); + + Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000000", + retList.get(0)); + + /*PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + user001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + user001Address, blockingStubFull);*/ + } + + @Test(enabled = true, description = "Get the EXTCODEHASH of an account created " + + "in the current transaction") + public void test07DeployExtCodeHashContract() { + Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, + 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + //before deploy, check account resource + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long energyLimit = accountResource.getEnergyLimit(); + long energyUsage = accountResource.getEnergyUsed(); + long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before energyLimit is " + Long.toString(energyLimit)); + logger.info("before energyUsage is " + Long.toString(energyUsage)); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + String filePath = "./src/test/resources/soliditycode/extCodeHashConstruct.sol"; + String contractName = "CounterConstruct"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + final String transferTokenTxid = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", + maxFeeLimit, 0L, 0, 10000, + "0", 0, null, dev001Key, + dev001Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + energyLimit = accountResource.getEnergyLimit(); + energyUsage = accountResource.getEnergyUsed(); + long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + + logger.info("after energyLimit is " + Long.toString(energyLimit)); + logger.info("after energyUsage is " + Long.toString(energyUsage)); + logger.info("after balanceAfter is " + Long.toString(balanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); + } + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + extCodeHashContractAddress = infoById.get().getContractAddress().toByteArray(); + SmartContract smartContract = PublicMethed.getContract(extCodeHashContractAddress, + blockingStubFull); + Assert.assertNotNull(smartContract.getAbi()); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + List retList = PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getTopics(0).toByteArray()); + + logger.info("the value: " + retList); + + Assert.assertFalse(retList.isEmpty()); + Assert.assertNotEquals("C5D2460186F7233C927E7DB2DCC703C0E500B653CA82273B7BFAD8045D85A470", + retList.get(0)); + Assert.assertNotEquals("0000000000000000000000000000000000000000000000000000000000000000", + retList.get(0)); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, dev001Address, blockingStubFull); PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest002.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest002.java index 06b618823fe..eb3c733a7f1 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest002.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest002.java @@ -9,6 +9,7 @@ import java.util.concurrent.TimeUnit; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; +import org.junit.runners.AllTests; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeSuite; @@ -28,6 +29,7 @@ @Slf4j public class ExtCodeHashTest002 { + private final boolean AllTest = false; private final String testKey002 = Configuration.getByPath("testng.conf") .getString("foundationAccount.key2"); @@ -74,7 +76,7 @@ public void beforeClass() { PublicMethed.printAddress(user001Key); } - @Test(enabled = true, description = "Deploy extcodehash contract") + @Test(enabled = AllTest, description = "Deploy extcodehash contract") public void test01DeployExtCodeHashContract() { Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); @@ -140,7 +142,7 @@ public void test01DeployExtCodeHashContract() { Assert.assertNotNull(smartContract.getAbi()); } - @Test(enabled = true, description = "Get a contract extcodehash") + @Test(enabled = AllTest, description = "Get a contract extcodehash") public void test02GetContactCodeHash() { Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest003.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest003.java index 9c264e01014..c97b9a02b2f 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest003.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest003.java @@ -29,6 +29,8 @@ @Slf4j public class ExtCodeHashTest003 { + private final static boolean AllTest = false; + private final String testKey002 = Configuration.getByPath("testng.conf") .getString("foundationAccount.key2"); private final byte[] fromAddress = PublicMethed.getFinalAddress(testKey002); @@ -78,7 +80,7 @@ public void beforeClass() { PublicMethed.printAddress(user001Key); } - @Test(enabled = true, description = "Deploy extcodehash contract") + @Test(enabled = AllTest, description = "Deploy extcodehash contract") public void test01DeployExtCodeHashContract() { Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); @@ -144,7 +146,7 @@ public void test01DeployExtCodeHashContract() { Assert.assertNotNull(smartContract.getAbi()); } - @Test(enabled = true, description = "Get a not exist account extcodehash") + @Test(enabled = AllTest, description = "Get a not exist account extcodehash") public void test02GetNotExistAddressCodeHash() { Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, @@ -226,7 +228,7 @@ public void test02GetNotExistAddressCodeHash() { logger.info(smartContract.getBytecode().toStringUtf8()); } - @Test(enabled = true, description = "Active the account and get extcodehash again") + @Test(enabled = AllTest, description = "Active the account and get extcodehash again") public void test03ActiveAccountGetCodeHash() { Assert.assertTrue(PublicMethed.sendcoin(testAddress, 1000000, fromAddress, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest004.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest004.java index d67346ac6a2..ea609cc77ad 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest004.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest004.java @@ -31,6 +31,7 @@ @Slf4j public class ExtCodeHashTest004 { + private final boolean AllTest = false; private final String testKey002 = Configuration.getByPath("testng.conf") .getString("foundationAccount.key2"); @@ -47,7 +48,6 @@ public class ExtCodeHashTest004 { private String testContractAddress = null; private String expectedCodeHash = null; - private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] dev001Address = ecKey1.getAddress(); private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); @@ -77,7 +77,7 @@ public void beforeClass() { PublicMethed.printAddress(user001Key); } - @Test(enabled = true, description = "Deploy extcodehash contract") + @Test(enabled = AllTest, description = "Deploy extcodehash contract") public void test01DeployExtCodeHashContract() { Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); @@ -152,7 +152,7 @@ public void test01DeployExtCodeHashContract() { Assert.assertNotNull(smartContract.getAbi()); } - @Test(enabled = true, description = "Get a not deployed create2 extcodehash") + @Test(enabled = AllTest, description = "Get a not deployed create2 extcodehash") public void test02GetCreate2CodeHash() { Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest006.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest006.java index b0ccf9f8e98..de1a2b185fc 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest006.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest006.java @@ -27,7 +27,7 @@ @Slf4j public class ExtCodeHashTest006 { - + private final boolean AllTest = false; private final String testKey002 = Configuration.getByPath("testng.conf") .getString("foundationAccount.key2"); private final byte[] fromAddress = PublicMethed.getFinalAddress(testKey002); @@ -77,7 +77,7 @@ public void beforeClass() { PublicMethed.printAddress(user001Key); } - @Test(enabled = true, description = "Get the EXTCODEHASH of an account created " + @Test(enabled = AllTest, description = "Get the EXTCODEHASH of an account created " + "in the current transaction") public void test01DeployExtCodeHashContract() { Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed001.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed001.java index 5a814215ef3..2ffbeacdcc8 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed001.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed001.java @@ -88,13 +88,11 @@ public void beforeClass() { blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - - @Test(enabled = true, description = "Transfer balance enough") - public void test1TransferEnough() { + @Test(enabled = true, description = "Transfer trx insufficient balance") + public void test1TransferTrxInsufficientBalance() { Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; String contractName = "EnergyOfTransferFailedTest"; HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); @@ -105,9 +103,7 @@ public void test1TransferEnough() { 0L, 100, null, contractExcKey, contractExcAddress, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethed - .sendcoin(contractAddress, 3000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); + Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -128,7 +124,6 @@ public void test1TransferEnough() { 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); Optional infoById = null; PublicMethed.waitProduceNextBlock(blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull1); infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); Long fee = infoById.get().getFee(); Long netUsed = infoById.get().getReceipt().getNetUsage(); @@ -152,22 +147,28 @@ public void test1TransferEnough() { logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); logger.info("afterFreeNetUsed:" + afterFreeNetUsed); - - Assert.assertTrue(infoById.get().getResultValue() == 0); - Assert.assertTrue(afterBalance + fee - 1 == beforeBalance); + logger.info("infoById:" + infoById); + Assert.assertTrue(infoById.get().getResultValue() == 1); + Assert.assertEquals(contractResult.REVERT, infoById.get().getReceipt().getResult()); + Assert.assertEquals( + "REVERT opcode executed", + ByteArray.toStr(infoById.get().getResMessage().toByteArray())); + Assert.assertTrue(afterBalance + fee == beforeBalance); Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Assert.assertNotEquals(10000000, energyUsageTotal); } - @Test(enabled = true, description = "Transfer trx insufficient balance") - public void test2TransferTrxInsufficientBalance() { - Assert.assertTrue(PublicMethed + @Test(enabled = true, description = "Transfer balance enough") + public void test2TransferEnough() { + /*Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; String contractName = "EnergyOfTransferFailedTest"; HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); @@ -177,8 +178,10 @@ public void test2TransferTrxInsufficientBalance() { contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, contractExcKey, contractExcAddress, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); - + PublicMethed.waitProduceNextBlock(blockingStubFull);*/ + Assert.assertTrue(PublicMethed + .sendcoin(contractAddress, 3000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -199,7 +202,6 @@ public void test2TransferTrxInsufficientBalance() { 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); Optional infoById = null; PublicMethed.waitProduceNextBlock(blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull1); infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); Long fee = infoById.get().getFee(); Long netUsed = infoById.get().getReceipt().getNetUsage(); @@ -223,17 +225,12 @@ public void test2TransferTrxInsufficientBalance() { logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); logger.info("afterFreeNetUsed:" + afterFreeNetUsed); - logger.info("infoById:" + infoById); - Assert.assertTrue(infoById.get().getResultValue() == 1); - Assert.assertEquals(contractResult.REVERT, infoById.get().getReceipt().getResult()); - Assert.assertEquals( - "REVERT opcode executed", - ByteArray.toStr(infoById.get().getResMessage().toByteArray())); - Assert.assertTrue(afterBalance + fee == beforeBalance); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee - 1 == beforeBalance); Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - Assert.assertNotEquals(10000000, energyUsageTotal); } @@ -241,7 +238,7 @@ public void test2TransferTrxInsufficientBalance() { @Test(enabled = true, description = "Transfer trx nonexistent target") public void test3TransferTrxNonexistentTarget() { - Assert.assertTrue(PublicMethed + /*Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; @@ -253,7 +250,7 @@ public void test3TransferTrxNonexistentTarget() { contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, contractExcKey, contractExcAddress, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull);*/ Assert.assertTrue(PublicMethed .sendcoin(contractAddress, 1000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); @@ -281,7 +278,6 @@ public void test3TransferTrxNonexistentTarget() { 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); Optional infoById = null; PublicMethed.waitProduceNextBlock(blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull1); infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); logger.info("infobyid : --- " + infoById); @@ -327,7 +323,7 @@ public void test3TransferTrxNonexistentTarget() { @Test(enabled = true, description = "Transfer trx to myself") public void test4TransferTrxSelf() { - Assert.assertTrue(PublicMethed + /*Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; @@ -342,7 +338,7 @@ public void test4TransferTrxSelf() { PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractAddress, 1000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); + blockingStubFull));*/ Account info; @@ -365,7 +361,6 @@ public void test4TransferTrxSelf() { 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); Optional infoById = null; PublicMethed.waitProduceNextBlock(blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull1); infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); logger.info("infobyid : --- " + infoById); @@ -410,7 +405,7 @@ public void test4TransferTrxSelf() { @Test(enabled = true, description = "Transfer trx nonexistent target and insufficient balance") public void test5TransferTrxNonexistentTarget() { - Assert.assertTrue(PublicMethed + /*Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; @@ -425,7 +420,7 @@ public void test5TransferTrxNonexistentTarget() { PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractAddress, 1000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); + blockingStubFull));*/ Account info; @@ -449,7 +444,6 @@ public void test5TransferTrxNonexistentTarget() { "testTransferTrxNonexistentTarget(uint256,address)", num, false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); Optional infoById = null; - PublicMethed.waitProduceNextBlock(blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull1); infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); logger.info("infobyid : --- " + infoById); @@ -495,7 +489,7 @@ public void test5TransferTrxNonexistentTarget() { @Test(enabled = true, description = "Transfer trx to myself and insufficient balance") public void test6TransferTrxSelf() { - Assert.assertTrue(PublicMethed + /*Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; @@ -510,7 +504,7 @@ public void test6TransferTrxSelf() { PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractAddress, 1000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); + blockingStubFull));*/ Account info; @@ -534,7 +528,6 @@ public void test6TransferTrxSelf() { 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); Optional infoById = null; PublicMethed.waitProduceNextBlock(blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull1); infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); logger.info("infobyid : --- " + infoById); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed002.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed002.java index 80d56d8cc73..3bf1adc5b74 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed002.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed002.java @@ -88,13 +88,11 @@ public void beforeClass() { blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - - @Test(enabled = true, description = "Send balance enough") - public void test1SendEnough() { + @Test(enabled = true, description = "Send balance not enough") + public void test1SendNotEnough() { Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + .sendcoin(contractExcAddress, 100000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; String contractName = "EnergyOfTransferFailedTest"; HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); @@ -105,9 +103,7 @@ public void test1SendEnough() { 0L, 100, null, contractExcKey, contractExcAddress, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethed - .sendcoin(contractAddress, 3000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); + Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -128,7 +124,6 @@ public void test1SendEnough() { 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); Optional infoById = null; PublicMethed.waitProduceNextBlock(blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull1); infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); Long fee = infoById.get().getFee(); Long netUsed = infoById.get().getReceipt().getNetUsage(); @@ -155,20 +150,21 @@ public void test1SendEnough() { logger.info("infoById:" + infoById); Assert.assertTrue(infoById.get().getResultValue() == 0); - Assert.assertTrue(afterBalance + fee - 1 == beforeBalance); + Assert.assertTrue(afterBalance + fee == beforeBalance); Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Assert.assertNotEquals(10000000, energyUsageTotal); } - - @Test(enabled = true, description = "Send balance not enough") - public void test2SendNotEnough() { - Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 100000000L, testNetAccountAddress, testNetAccountKey, + @Test(enabled = true, description = "Send balance enough") + public void test2SendEnough() { + /*Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; String contractName = "EnergyOfTransferFailedTest"; HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); @@ -178,8 +174,10 @@ public void test2SendNotEnough() { contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, contractExcKey, contractExcAddress, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); - + PublicMethed.waitProduceNextBlock(blockingStubFull);*/ + Assert.assertTrue(PublicMethed + .sendcoin(contractAddress, 3000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -200,7 +198,6 @@ public void test2SendNotEnough() { 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); Optional infoById = null; PublicMethed.waitProduceNextBlock(blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull1); infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); Long fee = infoById.get().getFee(); Long netUsed = infoById.get().getReceipt().getNetUsage(); @@ -227,19 +224,17 @@ public void test2SendNotEnough() { logger.info("infoById:" + infoById); Assert.assertTrue(infoById.get().getResultValue() == 0); - Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(afterBalance + fee - 1 == beforeBalance); Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - Assert.assertNotEquals(10000000, energyUsageTotal); - } @Test(enabled = true, description = "Send trx nonexistent target") public void test3SendTrxNonexistentTarget() { - Assert.assertTrue(PublicMethed + /*Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; @@ -254,7 +249,7 @@ public void test3SendTrxNonexistentTarget() { PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractAddress, 1000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); + blockingStubFull));*/ Account info; @@ -279,7 +274,6 @@ public void test3SendTrxNonexistentTarget() { 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); Optional infoById = null; PublicMethed.waitProduceNextBlock(blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull1); infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); logger.info("infobyid : --- " + infoById); @@ -325,7 +319,7 @@ public void test3SendTrxNonexistentTarget() { @Test(enabled = true, description = "Send trx self") public void test4SendTrxSelf() { - Assert.assertTrue(PublicMethed + /*Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; @@ -340,7 +334,7 @@ public void test4SendTrxSelf() { PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractAddress, 1000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); + blockingStubFull));*/ Account info; @@ -362,7 +356,6 @@ public void test4SendTrxSelf() { 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); Optional infoById = null; PublicMethed.waitProduceNextBlock(blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull1); infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); logger.info("infobyid : --- " + infoById); @@ -408,7 +401,7 @@ public void test4SendTrxSelf() { @Test(enabled = true, description = "Send trx nonexistent target and balance not enough") public void test5SendTrxNonexistentTarget() { - Assert.assertTrue(PublicMethed + /*Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; @@ -423,7 +416,7 @@ public void test5SendTrxNonexistentTarget() { PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractAddress, 1000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); + blockingStubFull));*/ Account info; @@ -449,7 +442,6 @@ public void test5SendTrxNonexistentTarget() { 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); Optional infoById = null; PublicMethed.waitProduceNextBlock(blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull1); infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); logger.info("infobyid : --- " + infoById); @@ -488,7 +480,7 @@ public void test5SendTrxNonexistentTarget() { @Test(enabled = true, description = "Send trx self and balance not enough") public void test6SendTrxSelf() { - Assert.assertTrue(PublicMethed + /*Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; @@ -503,7 +495,7 @@ public void test6SendTrxSelf() { PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(contractAddress, 1000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); + blockingStubFull));*/ Account info; @@ -528,7 +520,6 @@ public void test6SendTrxSelf() { 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); Optional infoById = null; PublicMethed.waitProduceNextBlock(blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull1); infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); logger.info("infobyid : --- " + infoById); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed003.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed003.java index 433daf54a0b..61c6ddbd2e6 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed003.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed003.java @@ -101,7 +101,7 @@ public void beforeClass() { @Test(enabled = true, description = "TransferToken enough tokenBalance") public void test1TransferTokenEnough() { Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 3100_000_000L, testNetAccountAddress, testNetAccountKey, + .sendcoin(contractExcAddress, 10000_000_000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); PublicMethed.waitProduceNextBlock(blockingStubFull); @@ -157,7 +157,6 @@ public void test1TransferTokenEnough() { 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); Optional infoById = null; PublicMethed.waitProduceNextBlock(blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull1); infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); Long fee = infoById.get().getFee(); Long netUsed = infoById.get().getReceipt().getNetUsage(); @@ -202,10 +201,10 @@ public void test1TransferTokenEnough() { @Test(enabled = true, description = "TransferToken insufficient tokenBalance") public void test2TransferTokenNotEnough() { - Assert.assertTrue(PublicMethed + /*Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 100_000_000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull);*/ Account info; @@ -233,7 +232,6 @@ public void test2TransferTokenNotEnough() { 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); Optional infoById = null; PublicMethed.waitProduceNextBlock(blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull1); infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); Long fee = infoById.get().getFee(); Long netUsed = infoById.get().getReceipt().getNetUsage(); @@ -283,10 +281,10 @@ public void test2TransferTokenNotEnough() { @Test(enabled = true, description = "TransferToken to nonexistent target") public void test3TransferTokenNonexistentTarget() { - Assert.assertTrue(PublicMethed + /*Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 10000_000_000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull);*/ Account info; @@ -370,10 +368,10 @@ public void test3TransferTokenNonexistentTarget() { @Test(enabled = true, description = "TransferToken to myself") public void test4TransferTokenSelf() { - Assert.assertTrue(PublicMethed + /*Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 100_000_000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull);*/ Account info; @@ -401,7 +399,6 @@ public void test4TransferTokenSelf() { 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); Optional infoById = null; PublicMethed.waitProduceNextBlock(blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull1); infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); logger.info("infoById:" + infoById); Long fee = infoById.get().getFee(); @@ -453,10 +450,10 @@ public void test4TransferTokenSelf() { @Test(enabled = true, description = "TransferToken notexist tokenID ") public void test5TransferTokenNotexist() { - Assert.assertTrue(PublicMethed + /*Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 100_000_000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull);*/ Account info; @@ -486,7 +483,6 @@ public void test5TransferTokenNotexist() { 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); Optional infoById = null; PublicMethed.waitProduceNextBlock(blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull1); infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); logger.info("infoById:" + infoById); Long fee = infoById.get().getFee(); @@ -538,10 +534,10 @@ public void test5TransferTokenNotexist() { @Test(enabled = true, description = "TransferToken to nonexistent target and " + "insufficient tokenBalance") public void test7TransferTokenNonexistentTarget() { - Assert.assertTrue(PublicMethed + /*Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 10000_000_000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull);*/ Account info; @@ -625,10 +621,10 @@ public void test7TransferTokenNonexistentTarget() { @Test(enabled = true, description = "TransferToken to myself and insufficient tokenBalance") public void test8TransferTokenSelf() { - Assert.assertTrue(PublicMethed + /*Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 100_000_000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull);*/ Account info; @@ -656,7 +652,6 @@ public void test8TransferTokenSelf() { 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); Optional infoById = null; PublicMethed.waitProduceNextBlock(blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull1); infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); logger.info("infoById:" + infoById); Long fee = infoById.get().getFee(); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed004.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed004.java index 5cf400575c8..7cc9a828899 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed004.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed004.java @@ -59,6 +59,9 @@ public class TransferFailed004 { byte[] contractExcAddress = ecKey1.getAddress(); String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + ECKey ecKey2 = new ECKey(Utils.getRandom()); + byte[] nonexistentAddress = ecKey2.getAddress(); + @BeforeSuite public void beforeSuite() { @@ -88,13 +91,11 @@ public void beforeClass() { blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - - @Test(enabled = true, description = "Suicide existent target") - public void test1SuicideExistentTarget() { + @Test(enabled = true, description = "Suicide nonexistent target") + public void test1SuicideNonexistentTarget() { Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; String contractName = "EnergyOfTransferFailedTest"; HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); @@ -106,8 +107,9 @@ public void test1SuicideExistentTarget() { contractExcAddress, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed - .sendcoin(contractAddress, 3000000L, testNetAccountAddress, testNetAccountKey, + .sendcoin(contractAddress, 1000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); + Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -121,22 +123,17 @@ public void test1SuicideExistentTarget() { logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - ECKey ecKey2 = new ECKey(Utils.getRandom()); - byte[] existentAddress = ecKey2.getAddress(); - Assert.assertTrue(PublicMethed - .sendcoin(existentAddress, 1000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); - String txid = ""; - String num = "\"" + Base58.encode58Check(existentAddress) + "\""; + String num = "\"" + Base58.encode58Check(nonexistentAddress) + "\""; + txid = PublicMethed.triggerContract(contractAddress, "testSuicideNonexistentTarget(address)", num, false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); Optional infoById = null; PublicMethed.waitProduceNextBlock(blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull1); infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + logger.info("infobyid : --- " + infoById); + Long fee = infoById.get().getFee(); Long netUsed = infoById.get().getReceipt().getNetUsage(); Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); @@ -159,24 +156,30 @@ public void test1SuicideExistentTarget() { logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); logger.info("afterFreeNetUsed:" + afterFreeNetUsed); - Account contractafter = PublicMethed.queryAccount(contractAddress, blockingStubFull1); - long contractBalance = contractafter.getBalance(); - Assert.assertTrue(infoById.get().getResultValue() == 0); - Assert.assertEquals(contractBalance, 0); + Assert.assertTrue(infoById.get().getResultValue() == 1); + Assert.assertEquals(contractResult.TRANSFER_FAILED, infoById.get().getReceipt().getResult()); + Assert.assertEquals( + "transfer all token or transfer all trx failed in suicide: " + + "Validate InternalTransfer error, no ToAccount. And not allowed " + + "to create account in smart contract.", + ByteArray.toStr(infoById.get().getResMessage().toByteArray())); + + Assert.assertTrue(afterBalance + fee == beforeBalance); Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Assert.assertNotEquals(10000000, energyUsageTotal); } - - @Test(enabled = true, description = "Suicide nonexistent target") - public void test2SuicideNonexistentTarget() { - Assert.assertTrue(PublicMethed + @Test(enabled = true, description = "Suicide existent target") + public void test2SuicideExistentTarget() { + /*Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; String contractName = "EnergyOfTransferFailedTest"; HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); @@ -188,9 +191,8 @@ public void test2SuicideNonexistentTarget() { contractExcAddress, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed - .sendcoin(contractAddress, 1000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - + .sendcoin(contractAddress, 3000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull));*/ Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -204,20 +206,20 @@ public void test2SuicideNonexistentTarget() { logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - ECKey ecKey2 = new ECKey(Utils.getRandom()); - byte[] nonexistentAddress = ecKey2.getAddress(); + + Assert.assertTrue(PublicMethed + .sendcoin(nonexistentAddress, 1000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String txid = ""; String num = "\"" + Base58.encode58Check(nonexistentAddress) + "\""; - txid = PublicMethed.triggerContract(contractAddress, "testSuicideNonexistentTarget(address)", num, false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); Optional infoById = null; PublicMethed.waitProduceNextBlock(blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull1); infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); - logger.info("infobyid : --- " + infoById); - Long fee = infoById.get().getFee(); Long netUsed = infoById.get().getReceipt().getNetUsage(); Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); @@ -240,25 +242,21 @@ public void test2SuicideNonexistentTarget() { logger.info("afterEnergyUsed:" + afterEnergyUsed); logger.info("afterNetUsed:" + afterNetUsed); logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + Account contractafter = PublicMethed.queryAccount(contractAddress, blockingStubFull1); + long contractBalance = contractafter.getBalance(); + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertEquals(contractBalance, 0); - Assert.assertTrue(infoById.get().getResultValue() == 1); - Assert.assertEquals(contractResult.TRANSFER_FAILED, infoById.get().getReceipt().getResult()); - Assert.assertEquals( - "transfer all token or transfer all trx failed in suicide: " - + "Validate InternalTransfer error, no ToAccount. And not allowed " - + "to create account in smart contract.", - ByteArray.toStr(infoById.get().getResMessage().toByteArray())); - - Assert.assertTrue(afterBalance + fee == beforeBalance); Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - Assert.assertNotEquals(10000000, energyUsageTotal); } + + /** * constructor. */ diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed005.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed005.java index b284e381a82..182435ae050 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed005.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed005.java @@ -75,12 +75,38 @@ public void beforeClass() { .build(); blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + { + Assert.assertTrue(PublicMethed + .sendcoin(accountExcAddress, 10000_000_000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + String filePath = "src/test/resources/soliditycode/TransferFailed005.sol"; + String contractName = "EnergyOfTransferFailedTest"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed + .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100L, + null, accountExcKey, accountExcAddress, blockingStubFull); + + filePath = "src/test/resources/soliditycode/TransferFailed005.sol"; + contractName = "Caller"; + retMap = PublicMethed.getBycodeAbi(filePath, contractName); + code = retMap.get("byteCode").toString(); + abi = retMap.get("abI").toString(); + + contractAddress1 = PublicMethed + .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100L, + null, accountExcKey, accountExcAddress, blockingStubFull); + } } - @Test(enabled = true, description = "Deploy contract for trigger") + @Test(enabled = false, description = "Deploy contract for trigger") public void deployContract() { Assert.assertTrue(PublicMethed - .sendcoin(accountExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + .sendcoin(accountExcAddress, 10000_000_000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); PublicMethed.waitProduceNextBlock(blockingStubFull); @@ -90,14 +116,16 @@ public void deployContract() { String code = retMap.get("byteCode").toString(); String abi = retMap.get("abI").toString(); - String Txid1 = PublicMethed + contractAddress = PublicMethed + .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100L, + null, accountExcKey, accountExcAddress, blockingStubFull); + /*String Txid1 = PublicMethed .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, 0L, 100L, null, accountExcKey, accountExcAddress, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); Optional infoById = PublicMethed .getTransactionInfoById(Txid1, blockingStubFull); contractAddress = infoById.get().getContractAddress().toByteArray(); - Assert.assertEquals(0, infoById.get().getResultValue()); + //Assert.assertEquals(0, infoById.get().getResultValue());*/ filePath = "src/test/resources/soliditycode/TransferFailed005.sol"; contractName = "Caller"; @@ -105,19 +133,21 @@ public void deployContract() { code = retMap.get("byteCode").toString(); abi = retMap.get("abI").toString(); - Txid1 = PublicMethed + contractAddress1 = PublicMethed + .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100L, + null, accountExcKey, accountExcAddress, blockingStubFull); + /*Txid1 = PublicMethed .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, 0L, 100L, null, accountExcKey, accountExcAddress, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); infoById = PublicMethed .getTransactionInfoById(Txid1, blockingStubFull); contractAddress1 = infoById.get().getContractAddress().toByteArray(); logger.info("caller address : " + Base58.encode58Check(contractAddress1)); - Assert.assertEquals(0, infoById.get().getResultValue()); + Assert.assertEquals(0, infoById.get().getResultValue());*/ } - @Test(enabled = true, description = "TransferFailed for function call_value") - public void triggerContract() { + @Test(enabled = true, description = "TransferFailed for function call_value ") + public void triggerContract01() { Account info = null; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(accountExcAddress, @@ -134,9 +164,8 @@ public void triggerContract() { Assert.assertTrue(PublicMethed .sendcoin(contractAddress, 1000100L, accountExcAddress, accountExcKey, blockingStubFull)); - Assert.assertTrue(PublicMethed - .sendcoin(contractAddress1, 1, accountExcAddress, accountExcKey, blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); + //Assert.assertTrue(PublicMethed + // .sendcoin(contractAddress1, 1, accountExcAddress, accountExcKey, blockingStubFull)); PublicMethed.waitProduceNextBlock(blockingStubFull); logger.info( @@ -165,7 +194,7 @@ public void triggerContract() { infoById.get().getResMessage().toStringUtf8()); Assert.assertEquals(1000100L, PublicMethed.queryAccount(contractAddress, blockingStubFull).getBalance()); - Assert.assertEquals(1L, + Assert.assertEquals(0L, PublicMethed.queryAccount(contractAddress1, blockingStubFull).getBalance()); Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() < 10000000); @@ -189,7 +218,7 @@ public void triggerContract() { infoById.get().getResMessage().toStringUtf8()); Assert.assertEquals(1000100L, PublicMethed.queryAccount(contractAddress, blockingStubFull).getBalance()); - Assert.assertEquals(1L, + Assert.assertEquals(0L, PublicMethed.queryAccount(contractAddress1, blockingStubFull).getBalance()); Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() < 10000000); @@ -223,7 +252,7 @@ public void triggerContract() { Assert.assertEquals(infoById.get().getResult().toString(), "SUCESS"); Assert.assertEquals(100L, PublicMethed.queryAccount(contractAddress, blockingStubFull).getBalance()); - Assert.assertEquals(1000001L, + Assert.assertEquals(1000000L, PublicMethed.queryAccount(contractAddress1, blockingStubFull).getBalance()); Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() < 10000000); @@ -254,13 +283,212 @@ public void triggerContract() { Assert.assertEquals(infoById.get().getResult().toString(), "SUCESS"); Assert.assertEquals(100L, PublicMethed.queryAccount(contractAddress, blockingStubFull).getBalance()); - Assert.assertEquals(1000001L, + Assert.assertEquals(1000000L, PublicMethed.queryAccount(contractAddress1, blockingStubFull).getBalance()); Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() < 10000000); } + @Test(enabled = true, description = "TransferFailed for create") + public void triggerContract02() { + Account info = null; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(accountExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(accountExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + + Assert.assertTrue(PublicMethed + .sendcoin(contractAddress, 1000100L, accountExcAddress, accountExcKey, blockingStubFull)); + //Assert.assertTrue(PublicMethed + // .sendcoin(contractAddress1, 1, accountExcAddress, accountExcKey, blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + logger.info( + "contractAddress balance before: " + PublicMethed + .queryAccount(contractAddress, blockingStubFull) + .getBalance()); + logger.info( + "callerAddress balance before: " + PublicMethed + .queryAccount(contractAddress1, blockingStubFull) + .getBalance()); + long paramValue = 1000000; + String param = "\"" + paramValue + "\""; + + String triggerTxid = PublicMethed.triggerContract(contractAddress, + "testCreateTrxInsufficientBalance(uint256)", param, false, 0L, + maxFeeLimit, accountExcAddress, accountExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + logger.info(infoById.get().getReceipt().getResult() + ""); + + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + logger.info( + "contractAddress balance before: " + PublicMethed + .queryAccount(contractAddress, blockingStubFull) + .getBalance()); + logger.info( + "callerAddress balance before: " + PublicMethed + .queryAccount(contractAddress1, blockingStubFull) + .getBalance()); + Assert.assertEquals(infoById.get().getResultValue(), 0); + Assert.assertFalse(infoById.get().getInternalTransactions(0).getRejected()); + Assert.assertEquals(200L, + PublicMethed.queryAccount(contractAddress, blockingStubFull).getBalance()); + Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() < 10000000); + + triggerTxid = PublicMethed.triggerContract(contractAddress, + "testCreateTrxInsufficientBalance(uint256)", param, false, 0L, + maxFeeLimit, accountExcAddress, accountExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull); + fee = infoById.get().getFee(); + netUsed = infoById.get().getReceipt().getNetUsage(); + energyUsed = infoById.get().getReceipt().getEnergyUsage(); + netFee = infoById.get().getReceipt().getNetFee(); + energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + logger.info( + "contractAddress balance before: " + PublicMethed + .queryAccount(contractAddress, blockingStubFull) + .getBalance()); + logger.info( + "callerAddress balance before: " + PublicMethed + .queryAccount(contractAddress1, blockingStubFull) + .getBalance()); + + Assert.assertEquals(infoById.get().getResultValue(), 1); + Assert.assertEquals(infoById.get().getResMessage().toStringUtf8(), "REVERT opcode executed"); + Assert.assertEquals(200L, + PublicMethed.queryAccount(contractAddress, blockingStubFull).getBalance()); + Assert.assertEquals(1000000L, + PublicMethed.queryAccount(contractAddress1, blockingStubFull).getBalance()); + Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() < 10000000); + + + } + + @Test(enabled = true, description = "TransferFailed for create2") + public void triggerContract03() { + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(accountExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(accountExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + + Assert.assertTrue(PublicMethed + .sendcoin(contractAddress, 15L, accountExcAddress, accountExcKey, blockingStubFull)); + logger.info( + "contractAddress balance before: " + PublicMethed + .queryAccount(contractAddress, blockingStubFull) + .getBalance()); + + String filePath = "./src/test/resources/soliditycode/TransferFailed007.sol"; + String contractName = "Caller"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String testContractCode = retMap.get("byteCode").toString(); + Long salt = 1L; + + String param = "\"" + testContractCode + "\"," + salt; + + String triggerTxid = PublicMethed.triggerContract(contractAddress, + "deploy(bytes,uint256)", param, false, 0L, + maxFeeLimit, accountExcAddress, accountExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + long afterBalance = 0L; + afterBalance = PublicMethed.queryAccount(contractAddress, blockingStubFull) + .getBalance(); + logger.info( + "contractAddress balance after : " + PublicMethed + .queryAccount(contractAddress, blockingStubFull) + .getBalance()); + Assert.assertEquals(0, infoById.get().getResultValue()); + Assert.assertEquals("SUCESS", infoById.get().getResult().toString()); + Assert.assertEquals(205L, afterBalance); + Assert.assertFalse(infoById.get().getInternalTransactions(0).getRejected()); + Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() < 10000000); + + triggerTxid = PublicMethed.triggerContract(contractAddress, + "deploy2(bytes,uint256)", param, false, 0L, + maxFeeLimit, accountExcAddress, accountExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + fee = infoById.get().getFee(); + netUsed = infoById.get().getReceipt().getNetUsage(); + energyUsed = infoById.get().getReceipt().getEnergyUsage(); + netFee = infoById.get().getReceipt().getNetFee(); + energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + afterBalance = PublicMethed.queryAccount(contractAddress, blockingStubFull).getBalance(); + logger.info( + "contractAddress balance after : " + PublicMethed + .queryAccount(contractAddress, blockingStubFull) + .getBalance()); + Assert.assertEquals(1, infoById.get().getResultValue()); + Assert.assertEquals("FAILED", infoById.get().getResult().toString()); + Assert.assertEquals(205L, afterBalance); + Assert.assertEquals(0, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray())); + Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() < 10000000); + + } + + /** * constructor. */ diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed006.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed006.java index d10dc0d7870..1fa6ed77279 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed006.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed006.java @@ -77,7 +77,7 @@ public void beforeClass() { } - @Test(enabled = true, description = "Deploy contract for trigger") + @Test(enabled = false, description = "Deploy contract for trigger") public void deployContract() { Assert.assertTrue(PublicMethed .sendcoin(accountExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, @@ -116,7 +116,7 @@ public void deployContract() { Assert.assertEquals(0, infoById.get().getResultValue()); } - @Test(enabled = true, description = "TransferFailed for create") + @Test(enabled = false, description = "TransferFailed for create") public void triggerContract() { Account info = null; diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed007.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed007.java index 1cf72eae84b..ae98ce42096 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed007.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed007.java @@ -76,7 +76,7 @@ public void beforeClass() { } - @Test(enabled = true, description = "Deploy contract for trigger") + @Test(enabled = false, description = "Deploy contract for trigger") public void deployContract() { Assert.assertTrue(PublicMethed .sendcoin(accountExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, @@ -99,7 +99,7 @@ public void deployContract() { Assert.assertEquals(0, infoById.get().getResultValue()); } - @Test(enabled = true, description = "TransferFailed for create2") + @Test(enabled = false, description = "TransferFailed for create2") public void triggerContract() { Account info; diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant001.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant001.java index 374c8142444..6f39a2f5a92 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant001.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant001.java @@ -5,9 +5,11 @@ import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import java.util.HashMap; +import java.util.Optional; import java.util.concurrent.TimeUnit; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; +import org.spongycastle.util.encoders.Hex; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeSuite; @@ -22,6 +24,8 @@ import org.tron.core.Wallet; import org.tron.protos.Protocol.Account; import org.tron.protos.Protocol.SmartContract; +import org.tron.protos.Protocol.Transaction; +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; @@ -53,7 +57,8 @@ public class TriggerConstant001 { private String soliditynode = Configuration.getByPath("testng.conf") .getStringList("solidityNode.ip.list").get(0); - byte[] contractAddress = null; + byte[] contractAddressNoAbi = null; + byte[] contractAddressWithAbi = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] contractExcAddress = ecKey1.getAddress(); @@ -86,25 +91,92 @@ public void beforeClass() { .usePlaintext(true) .build(); blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + + { + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 10000_000_000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TriggerConstant001.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddressNoAbi = PublicMethed.deployContract(contractName, "[]", code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddressNoAbi, blockingStubFull); + Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + + contractAddressWithAbi = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract2 = PublicMethed.getContract(contractAddressWithAbi, blockingStubFull); + Assert.assertFalse(smartContract2.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract2.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract2.getBytecode().toString().isEmpty()); + + } } @Test(enabled = true, description = "TriggerConstantContract a payable function without ABI") - public void testTriggerConstantContract() { - Assert.assertTrue(PublicMethed + public void test01TriggerConstantContract() { + + /*Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed);*/ + String txid = ""; + + TransactionExtention transactionExtention = PublicMethed + .triggerConstantContractForExtention(contractAddressNoAbi, + "testPayable()", "#", false, + 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + System.out.println("Code = " + transactionExtention.getResult().getCode()); + System.out + .println("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); + + Assert + .assertThat(transactionExtention.getResult().getCode().toString(), + containsString("CONTRACT_EXE_ERROR")); + Assert + .assertThat(transactionExtention.getResult().getMessage().toStringUtf8(), + containsString("Attempt to call a state modifying opcode inside STATICCALL")); + + + } + + @Test(enabled = true, description = "TriggerConstantContract a non-payable function without ABI") + public void test02TriggerConstantContract() { + /*Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); PublicMethed.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TriggerConstant001.sol"; + String filePath = "src/test/resources/soliditycode/TriggerConstant002.sol"; String contractName = "testConstantContract"; HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); String code = retMap.get("byteCode").toString(); String abi = retMap.get("abI").toString(); - contractAddress = PublicMethed.deployContract(contractName, "[]", code, "", maxFeeLimit, + contractAddressNoAbi = PublicMethed.deployContract(contractName, "[]", code, "", maxFeeLimit, 0L, 100, null, contractExcKey, contractExcAddress, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddressNoAbi, blockingStubFull); Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); @@ -120,12 +192,11 @@ public void testTriggerConstantContract() { logger.info("beforeBalance:" + beforeBalance); logger.info("beforeEnergyUsed:" + beforeEnergyUsed); logger.info("beforeNetUsed:" + beforeNetUsed); - logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - String txid = ""; + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed);*/ TransactionExtention transactionExtention = PublicMethed - .triggerConstantContractForExtention(contractAddress, - "testPayable()", "#", false, + .triggerConstantContractForExtention(contractAddressNoAbi, + "testNoPayable()", "#", false, 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); System.out.println("Code = " + transactionExtention.getResult().getCode()); System.out @@ -141,6 +212,1067 @@ public void testTriggerConstantContract() { } + @Test(enabled = true, description = "TriggerConstantContract a view function without ABI") + public void test03TriggerConstantContract() { + /*Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TriggerConstant003.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddressNoAbi = PublicMethed.deployContract(contractName, "[]", code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddressNoAbi, blockingStubFull); + Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed);*/ + + TransactionExtention transactionExtention = PublicMethed + .triggerConstantContractForExtention(contractAddressNoAbi, + "testView()", "#", false, + 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + + Transaction transaction = transactionExtention.getTransaction(); + + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + System.out.println("message:" + transaction.getRet(0).getRet()); + System.out.println(":" + ByteArray + .toStr(transactionExtention.getResult().getMessage().toByteArray())); + System.out.println("Result:" + Hex.toHexString(result)); + + Assert.assertEquals(1, ByteArray.toLong(ByteArray + .fromHexString(Hex + .toHexString(result)))); + } + + @Test(enabled = true, description = "TriggerConstantContract a pure function without ABI") + public void test04TriggerConstantContract() { + /*Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TriggerConstant004.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddressNoAbi = PublicMethed.deployContract(contractName, "[]", code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddressNoAbi, blockingStubFull); + Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed);*/ + + TransactionExtention transactionExtention = PublicMethed + .triggerConstantContractForExtention(contractAddressNoAbi, + "testPure()", "#", false, + 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + + Transaction transaction = transactionExtention.getTransaction(); + + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + System.out.println("message:" + transaction.getRet(0).getRet()); + System.out.println(":" + ByteArray + .toStr(transactionExtention.getResult().getMessage().toByteArray())); + System.out.println("Result:" + Hex.toHexString(result)); + + Assert.assertEquals(1, ByteArray.toLong(ByteArray + .fromHexString(Hex + .toHexString(result)))); + + + } + + @Test(enabled = true, description = "TriggerConstantContract a payable function with ABI") + public void test05TriggerConstantContract() { + /*Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TriggerConstant001.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddressNoAbi = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddressNoAbi, blockingStubFull); + Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed);*/ + String txid = ""; + + TransactionExtention transactionExtention = PublicMethed + .triggerConstantContractForExtention(contractAddressNoAbi, + "testPayable()", "#", false, + 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + System.out.println("Code = " + transactionExtention.getResult().getCode()); + System.out + .println("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); + + Assert.assertThat(transactionExtention.getResult().getCode().toString(), + containsString("CONTRACT_EXE_ERROR")); + Assert.assertThat(transactionExtention.getResult().getMessage().toStringUtf8(), + containsString("Attempt to call a state modifying opcode inside STATICCALL")); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + + } + + @Test(enabled = true, description = "TriggerConstantContract a non-payable function with ABI") + public void test06TriggerConstantContract() { + /*Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TriggerConstant002.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddressNoAbi = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddressNoAbi, blockingStubFull); + Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed);*/ + + TransactionExtention transactionExtention = PublicMethed + .triggerConstantContractForExtention(contractAddressWithAbi, + "testNoPayable()", "#", false, + 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + System.out.println("Code = " + transactionExtention.getResult().getCode()); + System.out + .println("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); + + Assert.assertThat(transactionExtention.getResult().getCode().toString(), + containsString("CONTRACT_EXE_ERROR")); + Assert.assertThat(transactionExtention.getResult().getMessage().toStringUtf8(), + containsString("Attempt to call a state modifying opcode inside STATICCALL")); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + + } + + @Test(enabled = true, description = "TriggerConstantContract a view function with ABI") + public void test07TriggerConstantContract() { + /*Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TriggerConstant003.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddressNoAbi = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddressNoAbi, blockingStubFull); + Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed);*/ + + TransactionExtention transactionExtention = PublicMethed + .triggerConstantContractForExtention(contractAddressWithAbi, + "testView()", "#", false, + 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + + Transaction transaction = transactionExtention.getTransaction(); + + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + System.out.println("message:" + transaction.getRet(0).getRet()); + System.out.println(":" + ByteArray + .toStr(transactionExtention.getResult().getMessage().toByteArray())); + System.out.println("Result:" + Hex.toHexString(result)); + + Assert.assertEquals(1, ByteArray.toLong(ByteArray + .fromHexString(Hex + .toHexString(result)))); + + + } + + @Test(enabled = true, description = "TriggerConstantContract a pure function with ABI") + public void test08TriggerConstantContract() { + /*Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TriggerConstant004.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddressNoAbi = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddressNoAbi, blockingStubFull); + Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed);*/ + + TransactionExtention transactionExtention = PublicMethed + .triggerConstantContractForExtention(contractAddressWithAbi, + "testPure()", "#", false, + 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + + Transaction transaction = transactionExtention.getTransaction(); + + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + System.out.println("message:" + transaction.getRet(0).getRet()); + System.out.println(":" + ByteArray + .toStr(transactionExtention.getResult().getMessage().toByteArray())); + System.out.println("Result:" + Hex.toHexString(result)); + + Assert.assertEquals(1, ByteArray.toLong(ByteArray + .fromHexString(Hex + .toHexString(result)))); + + + } + + @Test(enabled = true, description = "TriggerContract a payable function without ABI") + public void test09TriggerContract() { + /*Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TriggerConstant001.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddressNoAbi = PublicMethed.deployContract(contractName, "[]", code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddressNoAbi, blockingStubFull); + Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty());*/ + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + + txid = PublicMethed + .triggerContract(contractAddressNoAbi, + "testPayable()", "#", false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Long returnnumber = ByteArray.toLong(ByteArray + .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + Assert.assertTrue(1 == returnnumber); + + + } + + @Test(enabled = true, description = "TriggerContract a non-payable function without ABI") + public void test10TriggerContract() { + /*Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TriggerConstant002.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddressNoAbi = PublicMethed.deployContract(contractName, "[]", code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddressNoAbi, blockingStubFull); + Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty());*/ + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + + txid = PublicMethed + .triggerContract(contractAddressNoAbi, + "testNoPayable()", "#", false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Long returnnumber = ByteArray.toLong(ByteArray + .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + Assert.assertTrue(1 == returnnumber); + + + } + + @Test(enabled = true, description = "TriggerContract a view function without ABI") + public void test11TriggerContract() { + /*Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TriggerConstant003.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddressNoAbi = PublicMethed.deployContract(contractName, "[]", code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddressNoAbi, blockingStubFull); + Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty());*/ + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + + txid = PublicMethed + .triggerContract(contractAddressNoAbi, + "testView()", "#", false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Long returnnumber = ByteArray.toLong(ByteArray + .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + Assert.assertTrue(1 == returnnumber); + + + } + + @Test(enabled = true, description = "TriggerContract a pure function without ABI") + public void test12TriggerContract() { + /*Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TriggerConstant004.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddressNoAbi = PublicMethed.deployContract(contractName, "[]", code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddressNoAbi, blockingStubFull); + Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty());*/ + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + + txid = PublicMethed + .triggerContract(contractAddressNoAbi, + "testPure()", "#", false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Long returnnumber = ByteArray.toLong(ByteArray + .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + Assert.assertTrue(1 == returnnumber); + + + } + + @Test(enabled = true, description = "TriggerContract a pure function with ABI") + public void test18TriggerContract() { + /*Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TriggerConstant004.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddressNoAbi = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddressNoAbi, blockingStubFull); + Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed);*/ + TransactionExtention transactionExtention = PublicMethed + .triggerContractForExtention(contractAddressWithAbi, + "testPure()", "#", false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + + Transaction transaction = transactionExtention.getTransaction(); + + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + System.out.println("message:" + transaction.getRet(0).getRet()); + System.out.println(":" + ByteArray + .toStr(transactionExtention.getResult().getMessage().toByteArray())); + System.out.println("Result:" + Hex.toHexString(result)); + + Assert.assertEquals(1, ByteArray.toLong(ByteArray + .fromHexString(Hex + .toHexString(result)))); + + } + + @Test(enabled = true, description = "TriggerContract a payable function with ABI") + public void test19TriggerContract() { + /*Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TriggerConstant001.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddressNoAbi = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddressNoAbi, blockingStubFull); + Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty());*/ + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + txid = PublicMethed + .triggerContract(contractAddressWithAbi, + "testPayable()", "#", false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Long returnnumber = ByteArray.toLong(ByteArray + .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + Assert.assertTrue(1 == returnnumber); + + } + + @Test(enabled = true, description = "TriggerContract a non-payable function with ABI") + public void test20TriggerContract() { + /*Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TriggerConstant002.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddressNoAbi = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddressNoAbi, blockingStubFull); + Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty());*/ + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + String txid = ""; + txid = PublicMethed + .triggerContract(contractAddressNoAbi, + "testNoPayable()", "#", false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Long returnnumber = ByteArray.toLong(ByteArray + .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + Assert.assertTrue(1 == returnnumber); + + } + + @Test(enabled = true, description = "TriggerContract a view function with ABI") + public void test21TriggerContract() { + /*Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TriggerConstant003.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddressNoAbi = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddressNoAbi, blockingStubFull); + Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed);*/ + TransactionExtention transactionExtention = PublicMethed + .triggerContractForExtention(contractAddressWithAbi, + "testView()", "#", false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + + Transaction transaction = transactionExtention.getTransaction(); + + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + System.out.println("message:" + transaction.getRet(0).getRet()); + System.out.println(":" + ByteArray + .toStr(transactionExtention.getResult().getMessage().toByteArray())); + System.out.println("Result:" + Hex.toHexString(result)); + + Assert.assertEquals(1, ByteArray.toLong(ByteArray + .fromHexString(Hex + .toHexString(result)))); + + } + + @Test(enabled = true, description = "TriggerConstantContract a view method with ABI ,method has " + + "revert()") + public void test24TriggerConstantContract() { + /*Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TriggerConstant024.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddressNoAbi = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddressNoAbi, blockingStubFull); + Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed);*/ + + TransactionExtention transactionExtention = PublicMethed + .triggerConstantContractForExtention(contractAddressWithAbi, + "testView2()", "#", false, + 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + + Transaction transaction = transactionExtention.getTransaction(); + + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + System.out.println("message:" + transaction.getRet(0).getRet()); + System.out.println(":" + ByteArray + .toStr(transactionExtention.getResult().getMessage().toByteArray())); + + Assert + .assertThat(transaction.getRet(0).getRet().toString(), + containsString("FAILED")); + Assert + .assertThat(ByteArray + .toStr(transactionExtention.getResult().getMessage().toByteArray()), + containsString("REVERT opcode executed")); + + + } + + @Test(enabled = true, description = "TriggerContract a view method with ABI ,method has " + + "revert()") + public void test25TriggerContract() { + /*Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TriggerConstant024.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddressNoAbi = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddressNoAbi, blockingStubFull); + Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed);*/ + + TransactionExtention transactionExtention = PublicMethed + .triggerContractForExtention(contractAddressWithAbi, + "testView2()", "#", false, + 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + + Transaction transaction = transactionExtention.getTransaction(); + + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + System.out.println("message:" + transaction.getRet(0).getRet()); + System.out.println(":" + ByteArray + .toStr(transactionExtention.getResult().getMessage().toByteArray())); + + Assert.assertThat(transaction.getRet(0).getRet().toString(), + containsString("FAILED")); + Assert.assertThat(ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray()), + containsString("REVERT opcode executed")); + + + } + + @Test(enabled = true, description = "TriggerConstantContract a view method without ABI,method has" + + "revert()") + public void testTriggerConstantContract() { + /*Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TriggerConstant004.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddressNoAbi = PublicMethed.deployContract(contractName, "[]", code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddressNoAbi, blockingStubFull); + Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed);*/ + + TransactionExtention transactionExtention = PublicMethed + .triggerConstantContractForExtention(contractAddressNoAbi, + "testView2()", "#", false, + 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + + Transaction transaction = transactionExtention.getTransaction(); + + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + System.out.println("message:" + transaction.getRet(0).getRet()); + System.out.println(":" + ByteArray + .toStr(transactionExtention.getResult().getMessage().toByteArray())); + System.out.println("Result:" + Hex.toHexString(result)); + + Assert + .assertThat(transaction.getRet(0).getRet().toString(), + containsString("FAILED")); + Assert + .assertThat(ByteArray.toStr(transactionExtention.getResult().getMessage().toByteArray()), + containsString("REVERT opcode executed")); + + + } /** * constructor. diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant002.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant002.java index 973d336bc49..acc77a07a5b 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant002.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant002.java @@ -88,7 +88,7 @@ public void beforeClass() { blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = true, description = "TriggerConstantContract a non-payable function without ABI") + @Test(enabled = false, description = "TriggerConstantContract a non-payable function without ABI") public void testTriggerConstantContract() { Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant003.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant003.java index 3254e160e22..2c567610ae6 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant003.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant003.java @@ -88,7 +88,7 @@ public void beforeClass() { blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = true, description = "TriggerConstantContract a view function without ABI") + @Test(enabled = false, description = "TriggerConstantContract a view function without ABI") public void testTriggerConstantContract() { Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant004.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant004.java index 9d680712b62..94da7df47ee 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant004.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant004.java @@ -88,7 +88,7 @@ public void beforeClass() { blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = true, description = "TriggerConstantContract a pure function without ABI") + @Test(enabled = false, description = "TriggerConstantContract a pure function without ABI") public void testTriggerConstantContract() { Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant005.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant005.java index 92085685d1e..64f24d62584 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant005.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant005.java @@ -88,7 +88,7 @@ public void beforeClass() { blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = true, description = "TriggerConstantContract a payable function with ABI") + @Test(enabled = false, description = "TriggerConstantContract a payable function with ABI") public void testTriggerConstantContract() { Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant006.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant006.java index fc2456626c3..b9cb1998d4b 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant006.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant006.java @@ -88,7 +88,7 @@ public void beforeClass() { blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = true, description = "TriggerConstantContract a non-payable function with ABI") + @Test(enabled = false, description = "TriggerConstantContract a non-payable function with ABI") public void testTriggerConstantContract() { Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant007.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant007.java index d66cade847e..6dc8e0f33bf 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant007.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant007.java @@ -88,7 +88,7 @@ public void beforeClass() { blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = true, description = "TriggerConstantContract a view function with ABI") + @Test(enabled = false, description = "TriggerConstantContract a view function with ABI") public void testTriggerConstantContract() { Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant008.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant008.java index a8ee51e7495..a714d5de1be 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant008.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant008.java @@ -88,7 +88,7 @@ public void beforeClass() { blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = true, description = "TriggerConstantContract a pure function with ABI") + @Test(enabled = false, description = "TriggerConstantContract a pure function with ABI") public void testTriggerConstantContract() { Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant009.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant009.java index f44619ac05a..31c6ecc7ef7 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant009.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant009.java @@ -87,7 +87,7 @@ public void beforeClass() { blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = true, description = "TriggerContract a payable function without ABI") + @Test(enabled = false, description = "TriggerContract a payable function without ABI") public void testTriggerContract() { Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant010.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant010.java index b91f92e1db7..d5268d6aeb2 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant010.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant010.java @@ -87,7 +87,7 @@ public void beforeClass() { blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = true, description = "TriggerContract a non-payable function without ABI") + @Test(enabled = false, description = "TriggerContract a non-payable function without ABI") public void testTriggerContract() { Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant011.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant011.java index 4e334fe986a..f74c9663e93 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant011.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant011.java @@ -87,7 +87,7 @@ public void beforeClass() { blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = true, description = "TriggerContract a view function without ABI") + @Test(enabled = false, description = "TriggerContract a view function without ABI") public void testTriggerContract() { Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant012.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant012.java index cef6e444b86..d6d2a31738c 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant012.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant012.java @@ -87,7 +87,7 @@ public void beforeClass() { blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = true, description = "TriggerContract a pure function without ABI") + @Test(enabled = false, description = "TriggerContract a pure function without ABI") public void testTriggerContract() { Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant013.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant013.java index 036b76ecc84..f557c7d8df5 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant013.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant013.java @@ -7,11 +7,13 @@ import java.util.concurrent.TimeUnit; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; +import org.spongycastle.util.encoders.Hex; 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.GrpcAPI.TransactionExtention; import org.tron.api.WalletGrpc; import org.tron.api.WalletSolidityGrpc; import org.tron.common.crypto.ECKey; @@ -19,6 +21,8 @@ import org.tron.common.utils.Utils; import org.tron.core.Wallet; import org.tron.protos.Protocol.Account; +import org.tron.protos.Protocol.SmartContract; +import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.TransactionInfo; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.Parameter.CommonConstant; @@ -53,6 +57,7 @@ public class TriggerConstant013 { .getStringList("solidityNode.ip.list").get(0); byte[] contractAddress = null; + byte[] returnAddressBytes = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] contractExcAddress = ecKey1.getAddress(); @@ -88,7 +93,7 @@ public void beforeClass() { } @Test(enabled = true, description = "triggerContract a constant function created by create2") - public void testTriggerContract() { + public void test01TriggerContract() { Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); @@ -160,7 +165,7 @@ public void testTriggerContract() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - byte[] returnAddressBytes = infoById.get().getInternalTransactions(0).getTransferToAddress() + returnAddressBytes = infoById.get().getInternalTransactions(0).getTransferToAddress() .toByteArray(); String returnAddress = Base58.encode58Check(returnAddressBytes); logger.info("returnAddress:" + returnAddress); @@ -205,6 +210,106 @@ public void testTriggerContract() { } + @Test(enabled = true, description = "TriggerConstantContract a constant function " + + "created by create2") + public void test15TriggerConstantContract() { + /*Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TriggerConstant015.sol"; + String contractName = "Factory"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + + String contractName1 = "TestConstract"; + HashMap retMap1 = PublicMethed.getBycodeAbi(filePath, contractName1); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + String txid = ""; + String num = "\"" + code1 + "\"" + "," + 1; + txid = PublicMethed + .triggerContract(contractAddress, + "deploy(bytes,uint256)", num, false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + byte[] returnAddressBytes = infoById.get().getInternalTransactions(0).getTransferToAddress() + .toByteArray();*/ + SmartContract smartContract = PublicMethed.getContract(returnAddressBytes, blockingStubFull); + Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + String returnAddress = Base58.encode58Check(returnAddressBytes); + logger.info("returnAddress:" + returnAddress); + TransactionExtention transactionExtention = PublicMethed + .triggerConstantContractForExtention(returnAddressBytes, + "plusOne()", "#", false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + Transaction transaction = transactionExtention.getTransaction(); + + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + System.out.println("message:" + transaction.getRet(0).getRet()); + System.out.println(":" + ByteArray + .toStr(transactionExtention.getResult().getMessage().toByteArray())); + System.out.println("Result:" + Hex.toHexString(result)); + + Assert.assertEquals(1, ByteArray.toLong(ByteArray + .fromHexString(Hex + .toHexString(result)))); + } + + /** * constructor. */ diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant014.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant014.java index a76f183f761..14954d61070 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant014.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant014.java @@ -1,5 +1,7 @@ package stest.tron.wallet.dailybuild.tvmnewcommand.triggerconstant; +import static org.hamcrest.core.StringContains.containsString; + import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import java.util.HashMap; @@ -12,6 +14,7 @@ import org.testng.annotations.BeforeSuite; import org.testng.annotations.Test; import org.tron.api.GrpcAPI.AccountResourceMessage; +import org.tron.api.GrpcAPI.TransactionExtention; import org.tron.api.WalletGrpc; import org.tron.api.WalletSolidityGrpc; import org.tron.common.crypto.ECKey; @@ -54,6 +57,7 @@ public class TriggerConstant014 { .getStringList("solidityNode.ip.list").get(0); byte[] contractAddress = null; + byte[] returnAddressBytes = null; ECKey ecKey1 = new ECKey(Utils.getRandom()); byte[] contractExcAddress = ecKey1.getAddress(); @@ -89,7 +93,7 @@ public void beforeClass() { } @Test(enabled = true, description = "TriggerContract a non-constant function created by create2") - public void testTriggerContract() { + public void test01TriggerContract() { Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); @@ -162,7 +166,7 @@ public void testTriggerContract() { Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - byte[] returnAddressBytes = infoById.get().getInternalTransactions(0).getTransferToAddress() + returnAddressBytes = infoById.get().getInternalTransactions(0).getTransferToAddress() .toByteArray(); String returnAddress = Base58.encode58Check(returnAddressBytes); logger.info("returnAddress:" + returnAddress); @@ -205,6 +209,102 @@ public void testTriggerContract() { Assert.assertTrue(1 == returnnumber); } + @Test(enabled = true, description = "TriggerConstantContract a non-constant function " + + "created by create2") + public void test16TriggerConstantContract() { + // TriggerConstant016.java + /*Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/ClearAbi005.sol"; + String contractName = "Factory"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + + String contractName1 = "TestConstract"; + HashMap retMap1 = PublicMethed.getBycodeAbi(filePath, contractName1); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + String txid = ""; + String num = "\"" + code1 + "\"" + "," + 1; + txid = PublicMethed + .triggerContract(contractAddress, + "deploy(bytes,uint256)", num, false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + byte[] returnAddressBytes = infoById.get().getInternalTransactions(0).getTransferToAddress() + .toByteArray();*/ + String returnAddress = Base58.encode58Check(returnAddressBytes); + logger.info("returnAddress:" + returnAddress); + TransactionExtention transactionExtention = PublicMethed + .triggerConstantContractForExtention(returnAddressBytes, + "plusOne()", "#", false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + System.out.println("Code = " + transactionExtention.getResult().getCode()); + System.out + .println("Message = " + transactionExtention.getResult().getMessage().toStringUtf8()); + + Assert + .assertThat(transactionExtention.getResult().getCode().toString(), + containsString("CONTRACT_EXE_ERROR")); + Assert + .assertThat(transactionExtention.getResult().getMessage().toStringUtf8(), + containsString("Attempt to call a state modifying opcode inside STATICCALL")); + } + /** * constructor. diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant015.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant015.java index a4d968a6e75..088d2c2c53e 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant015.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant015.java @@ -91,7 +91,7 @@ public void beforeClass() { blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = true, description = "TriggerConstantContract a constant function " + @Test(enabled = false, description = "TriggerConstantContract a constant function " + "created by create2") public void testTriggerConstantContract() { Assert.assertTrue(PublicMethed diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant016.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant016.java index 8185881ee02..02876fe2289 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant016.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant016.java @@ -90,7 +90,7 @@ public void beforeClass() { blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = true, description = "TriggerConstantContract a non-constant function " + @Test(enabled = false, description = "TriggerConstantContract a non-constant function " + "created by create2") public void testTriggerConstantContract() { Assert.assertTrue(PublicMethed diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant018.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant018.java index a96ab14537b..ac5c092a472 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant018.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant018.java @@ -88,7 +88,7 @@ public void beforeClass() { blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = true, description = "TriggerContract a pure function with ABI") + @Test(enabled = false, description = "TriggerContract a pure function with ABI") public void testTriggerContract() { Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant019.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant019.java index 55d101966f4..1c34629672a 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant019.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant019.java @@ -87,7 +87,7 @@ public void beforeClass() { blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = true, description = "TriggerContract a payable function with ABI") + @Test(enabled = false, description = "TriggerContract a payable function with ABI") public void testTriggerContract() { Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant020.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant020.java index d4cfe208e4a..f110a68dde6 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant020.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant020.java @@ -87,7 +87,7 @@ public void beforeClass() { blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = true, description = "TriggerContract a non-payable function with ABI") + @Test(enabled = false, description = "TriggerContract a non-payable function with ABI") public void testTriggerContract() { Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant021.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant021.java index fd3b68fcb6e..4bc9c426825 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant021.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant021.java @@ -88,7 +88,7 @@ public void beforeClass() { blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = true, description = "TriggerContract a view function with ABI") + @Test(enabled = false, description = "TriggerContract a view function with ABI") public void testTriggerContract() { Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant022.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant022.java index 83b0ea8842e..b1462c4c8e8 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant022.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant022.java @@ -88,7 +88,7 @@ public void beforeClass() { blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = true, description = "TriggerContract a non-payable function " + @Test(enabled = false, description = "TriggerContract a non-payable function " + "with ABI(constant ABI)") public void testTriggerContract() { Assert.assertTrue(PublicMethed diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant023.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant023.java index 8ba7c44b951..255aadf3d16 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant023.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant023.java @@ -88,7 +88,7 @@ public void beforeClass() { blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = true, description = "TriggerConstantContract a non-payable function with" + @Test(enabled = false, description = "TriggerConstantContract a non-payable function with" + " ABI(constant ABI )") public void testTriggerConstantContract() { Assert.assertTrue(PublicMethed diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant024.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant024.java index fc67ae81c8d..c18cb73d435 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant024.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant024.java @@ -89,7 +89,7 @@ public void beforeClass() { blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = true, description = "TriggerConstantContract a view method with ABI ,method has " + @Test(enabled = false, description = "TriggerConstantContract a view method with ABI ,method has " + "revert()") public void testTriggerConstantContract() { Assert.assertTrue(PublicMethed diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant025.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant025.java index d97293a2888..50d6b6cdc83 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant025.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant025.java @@ -89,7 +89,7 @@ public void beforeClass() { blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = true, description = "TriggerContract a view method with ABI ,method has " + @Test(enabled = false, description = "TriggerContract a view method with ABI ,method has " + "revert()") public void testTriggerContract() { Assert.assertTrue(PublicMethed diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant026.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant026.java index 540f91843f5..4bd21c4df88 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant026.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant026.java @@ -90,7 +90,7 @@ public void beforeClass() { blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = true, description = "TriggerConstantContract a view method without ABI,method has" + @Test(enabled = false, description = "TriggerConstantContract a view method without ABI,method has" + "revert()") public void testTriggerConstantContract() { Assert.assertTrue(PublicMethed diff --git a/src/test/resources/soliditycode/TransferFailed001.sol b/src/test/resources/soliditycode/TransferFailed001.sol index 9d93d196c05..020de72084a 100644 --- a/src/test/resources/soliditycode/TransferFailed001.sol +++ b/src/test/resources/soliditycode/TransferFailed001.sol @@ -60,6 +60,30 @@ contract EnergyOfTransferFailedTest { address payable self = address(uint160(address(this))); self.transferToken(i, tokenId); } + + event Deployed(address addr, uint256 salt, address sender); + function deploy(bytes memory code, uint256 salt) public returns(address){ + address addr; + assembly { + addr := create2(10, add(code, 0x20), mload(code), salt) + //if iszero(extcodesize(addr)) { + // revert(0, 0) + //} + } + //emit Deployed(addr, salt, msg.sender); + return addr; + } + function deploy2(bytes memory code, uint256 salt) public returns(address){ + address addr; + assembly { + addr := create2(300, add(code, 0x20), mload(code), salt) + //if iszero(extcodesize(addr)) { + // revert(0, 0) + //} + } + //emit Deployed(addr, salt, msg.sender); + return addr; + } } diff --git a/src/test/resources/soliditycode/TriggerConstant001.sol b/src/test/resources/soliditycode/TriggerConstant001.sol index 56e04e4584c..515b9e07724 100644 --- a/src/test/resources/soliditycode/TriggerConstant001.sol +++ b/src/test/resources/soliditycode/TriggerConstant001.sol @@ -1,10 +1,28 @@ //pragma solidity ^0.4.0; contract testConstantContract{ -uint256 public i; -function testPayable() public payable returns (uint256 z) { -i=1; -z=i; -return z; -} + uint256 public i; + function testPayable() public payable returns (uint256 z) { + i=1; + z=i; + return z; + } + function testNoPayable() public returns (uint256 z) { + i=1; + z=i; + return z; + } + function testView() public view returns (uint256 z) { + uint256 i=1; + return i; + } + function testPure() public pure returns (uint256 z) { + uint256 i=1; + return i; + } + function testView2() public view returns (uint256 z) { + uint256 i=1; + revert(); + return i; + } } \ No newline at end of file From f53fd639d87fb03b864b7028fedbf9fb5668bee9 Mon Sep 17 00:00:00 2001 From: lvs007 Date: Tue, 28 May 2019 15:39:11 +0800 Subject: [PATCH 15/90] modify the class name --- src/main/java/org/tron/core/db/AccountStore.java | 6 +++--- src/main/java/org/tron/core/db/Manager.java | 8 +++----- .../db/{fast => accountstate}/AccountStateEntity.java | 2 +- .../tron/core/db/{fast => accountstate}/TrieService.java | 4 ++-- .../callback/AccountStateCallBack.java} | 8 ++++---- .../storetrie/AccountStateStoreTrie.java | 6 +++--- 6 files changed, 16 insertions(+), 18 deletions(-) rename src/main/java/org/tron/core/db/{fast => accountstate}/AccountStateEntity.java (96%) rename src/main/java/org/tron/core/db/{fast => accountstate}/TrieService.java (93%) rename src/main/java/org/tron/core/db/{fast/callback/FastSyncCallBack.java => accountstate/callback/AccountStateCallBack.java} (95%) rename src/main/java/org/tron/core/db/{fast => accountstate}/storetrie/AccountStateStoreTrie.java (91%) diff --git a/src/main/java/org/tron/core/db/AccountStore.java b/src/main/java/org/tron/core/db/AccountStore.java index d3174f93afd..b42d1f064ff 100644 --- a/src/main/java/org/tron/core/db/AccountStore.java +++ b/src/main/java/org/tron/core/db/AccountStore.java @@ -11,8 +11,8 @@ import org.springframework.stereotype.Component; import org.tron.core.Wallet; import org.tron.core.capsule.AccountCapsule; -import org.tron.core.db.fast.callback.FastSyncCallBack; -import org.tron.core.db.fast.storetrie.AccountStateStoreTrie; +import org.tron.core.db.accountstate.callback.AccountStateCallBack; +import org.tron.core.db.accountstate.storetrie.AccountStateStoreTrie; @Slf4j(topic = "DB") @Component @@ -21,7 +21,7 @@ public class AccountStore extends TronStoreWithRevoking { private static Map assertsAddress = new HashMap<>(); // key = name , value = address @Autowired - private FastSyncCallBack fastSyncCallBack; + private AccountStateCallBack fastSyncCallBack; @Autowired private AccountStateStoreTrie accountStateStoreTrie; diff --git a/src/main/java/org/tron/core/db/Manager.java b/src/main/java/org/tron/core/db/Manager.java index 5608d22e1f3..eb6b08087d7 100644 --- a/src/main/java/org/tron/core/db/Manager.java +++ b/src/main/java/org/tron/core/db/Manager.java @@ -31,8 +31,6 @@ import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; import java.util.stream.Collectors; @@ -77,8 +75,8 @@ import org.tron.core.config.args.GenesisBlock; import org.tron.core.db.KhaosDatabase.KhaosBlock; import org.tron.core.db.api.AssetUpdateHelper; -import org.tron.core.db.fast.TrieService; -import org.tron.core.db.fast.callback.FastSyncCallBack; +import org.tron.core.db.accountstate.TrieService; +import org.tron.core.db.accountstate.callback.AccountStateCallBack; import org.tron.core.db2.core.ISession; import org.tron.core.db2.core.ITronChainBase; import org.tron.core.db2.core.SnapshotManager; @@ -223,7 +221,7 @@ public class Manager { private ForkController forkController = ForkController.instance(); @Autowired - private FastSyncCallBack fastSyncCallBack; + private AccountStateCallBack fastSyncCallBack; @Autowired private TrieService trieService; diff --git a/src/main/java/org/tron/core/db/fast/AccountStateEntity.java b/src/main/java/org/tron/core/db/accountstate/AccountStateEntity.java similarity index 96% rename from src/main/java/org/tron/core/db/fast/AccountStateEntity.java rename to src/main/java/org/tron/core/db/accountstate/AccountStateEntity.java index 6055c05b388..45d8adb4df1 100644 --- a/src/main/java/org/tron/core/db/fast/AccountStateEntity.java +++ b/src/main/java/org/tron/core/db/accountstate/AccountStateEntity.java @@ -1,4 +1,4 @@ -package org.tron.core.db.fast; +package org.tron.core.db.accountstate; import lombok.extern.slf4j.Slf4j; import org.tron.core.Wallet; diff --git a/src/main/java/org/tron/core/db/fast/TrieService.java b/src/main/java/org/tron/core/db/accountstate/TrieService.java similarity index 93% rename from src/main/java/org/tron/core/db/fast/TrieService.java rename to src/main/java/org/tron/core/db/accountstate/TrieService.java index bb4c3edc60e..0dd5827006a 100644 --- a/src/main/java/org/tron/core/db/fast/TrieService.java +++ b/src/main/java/org/tron/core/db/accountstate/TrieService.java @@ -1,4 +1,4 @@ -package org.tron.core.db.fast; +package org.tron.core.db.accountstate; import com.google.protobuf.ByteString; import com.google.protobuf.Internal; @@ -9,7 +9,7 @@ import org.tron.common.crypto.Hash; import org.tron.core.capsule.BlockCapsule; import org.tron.core.db.Manager; -import org.tron.core.db.fast.storetrie.AccountStateStoreTrie; +import org.tron.core.db.accountstate.storetrie.AccountStateStoreTrie; @Slf4j(topic = "AccountState") @Component diff --git a/src/main/java/org/tron/core/db/fast/callback/FastSyncCallBack.java b/src/main/java/org/tron/core/db/accountstate/callback/AccountStateCallBack.java similarity index 95% rename from src/main/java/org/tron/core/db/fast/callback/FastSyncCallBack.java rename to src/main/java/org/tron/core/db/accountstate/callback/AccountStateCallBack.java index 577f1b89f4a..fe0d44896a3 100644 --- a/src/main/java/org/tron/core/db/fast/callback/FastSyncCallBack.java +++ b/src/main/java/org/tron/core/db/accountstate/callback/AccountStateCallBack.java @@ -1,4 +1,4 @@ -package org.tron.core.db.fast.callback; +package org.tron.core.db.accountstate.callback; import com.google.protobuf.ByteString; import com.google.protobuf.Internal; @@ -16,8 +16,8 @@ import org.tron.core.capsule.BlockCapsule; import org.tron.core.capsule.utils.RLP; import org.tron.core.db.Manager; -import org.tron.core.db.fast.AccountStateEntity; -import org.tron.core.db.fast.storetrie.AccountStateStoreTrie; +import org.tron.core.db.accountstate.AccountStateEntity; +import org.tron.core.db.accountstate.storetrie.AccountStateStoreTrie; import org.tron.core.exception.BadBlockException; import org.tron.core.trie.TrieImpl; import org.tron.core.trie.TrieImpl.Node; @@ -25,7 +25,7 @@ @Slf4j(topic = "AccountState") @Component -public class FastSyncCallBack { +public class AccountStateCallBack { private BlockCapsule blockCapsule; private volatile boolean execute = false; diff --git a/src/main/java/org/tron/core/db/fast/storetrie/AccountStateStoreTrie.java b/src/main/java/org/tron/core/db/accountstate/storetrie/AccountStateStoreTrie.java similarity index 91% rename from src/main/java/org/tron/core/db/fast/storetrie/AccountStateStoreTrie.java rename to src/main/java/org/tron/core/db/accountstate/storetrie/AccountStateStoreTrie.java index 0c85c3ef34e..df3a3a157ee 100644 --- a/src/main/java/org/tron/core/db/fast/storetrie/AccountStateStoreTrie.java +++ b/src/main/java/org/tron/core/db/accountstate/storetrie/AccountStateStoreTrie.java @@ -1,4 +1,4 @@ -package org.tron.core.db.fast.storetrie; +package org.tron.core.db.accountstate.storetrie; import javax.annotation.PostConstruct; import lombok.extern.slf4j.Slf4j; @@ -9,8 +9,8 @@ import org.tron.core.capsule.BytesCapsule; import org.tron.core.capsule.utils.RLP; import org.tron.core.db.TronStoreWithRevoking; -import org.tron.core.db.fast.AccountStateEntity; -import org.tron.core.db.fast.TrieService; +import org.tron.core.db.accountstate.AccountStateEntity; +import org.tron.core.db.accountstate.TrieService; import org.tron.core.db2.common.DB; import org.tron.core.trie.TrieImpl; From 2e3306dcb082d160b23706605efb11beab3a451a Mon Sep 17 00:00:00 2001 From: lvs007 Date: Tue, 28 May 2019 15:45:45 +0800 Subject: [PATCH 16/90] modify the class name --- .../java/org/tron/core/db/AccountStore.java | 4 ++-- src/main/java/org/tron/core/db/Manager.java | 22 +++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/tron/core/db/AccountStore.java b/src/main/java/org/tron/core/db/AccountStore.java index b42d1f064ff..7740eb9be97 100644 --- a/src/main/java/org/tron/core/db/AccountStore.java +++ b/src/main/java/org/tron/core/db/AccountStore.java @@ -21,7 +21,7 @@ public class AccountStore extends TronStoreWithRevoking { private static Map assertsAddress = new HashMap<>(); // key = name , value = address @Autowired - private AccountStateCallBack fastSyncCallBack; + private AccountStateCallBack accountStateCallBack; @Autowired private AccountStateStoreTrie accountStateStoreTrie; @@ -41,7 +41,7 @@ public AccountCapsule get(byte[] key) { @Override public void put(byte[] key, AccountCapsule item) { super.put(key, item); - fastSyncCallBack.accountCallBack(key, item); + accountStateCallBack.accountCallBack(key, item); } /** diff --git a/src/main/java/org/tron/core/db/Manager.java b/src/main/java/org/tron/core/db/Manager.java index eb6b08087d7..258665e4294 100644 --- a/src/main/java/org/tron/core/db/Manager.java +++ b/src/main/java/org/tron/core/db/Manager.java @@ -221,7 +221,7 @@ public class Manager { private ForkController forkController = ForkController.instance(); @Autowired - private AccountStateCallBack fastSyncCallBack; + private AccountStateCallBack accountStateCallBack; @Autowired private TrieService trieService; @@ -432,7 +432,7 @@ public void stopRepushTriggerThread() { @PostConstruct public void init() { Message.setManager(this); - fastSyncCallBack.setManager(this); + accountStateCallBack.setManager(this); trieService.setManager(this); revokingStore.disable(); revokingStore.check(); @@ -1318,7 +1318,7 @@ public synchronized BlockCapsule generateBlock( session.reset(); session.setValue(revokingStore.buildSession()); // - fastSyncCallBack.preExecute(blockCapsule); + accountStateCallBack.preExecute(blockCapsule); if (needCheckWitnessPermission && !witnessService. validateWitnessPermission(witnessCapsule.getAddress())) { @@ -1369,9 +1369,9 @@ public synchronized BlockCapsule generateBlock( } // apply transaction try (ISession tmpSeesion = revokingStore.buildSession()) { - fastSyncCallBack.preExeTrans(); + accountStateCallBack.preExeTrans(); processTransaction(trx, blockCapsule); - fastSyncCallBack.exeTransFinish(); + accountStateCallBack.exeTransFinish(); tmpSeesion.merge(); // push into block blockCapsule.addTransaction(trx); @@ -1413,7 +1413,7 @@ public synchronized BlockCapsule generateBlock( } } // end of while - fastSyncCallBack.executeGenerateFinish(); + accountStateCallBack.executeGenerateFinish(); session.reset(); if (postponedTrxCount > 0) { @@ -1515,19 +1515,19 @@ public void processBlock(BlockCapsule block) } } try { - fastSyncCallBack.preExecute(block); + accountStateCallBack.preExecute(block); for (TransactionCapsule transactionCapsule : block.getTransactions()) { transactionCapsule.setBlockNum(block.getNum()); if (block.generatedByMyself) { transactionCapsule.setVerified(true); } - fastSyncCallBack.preExeTrans(); + accountStateCallBack.preExeTrans(); processTransaction(transactionCapsule, block); - fastSyncCallBack.exeTransFinish(); + accountStateCallBack.exeTransFinish(); } - fastSyncCallBack.executePushFinish(); + accountStateCallBack.executePushFinish(); } finally { - fastSyncCallBack.exceptionFinish(); + accountStateCallBack.exceptionFinish(); } boolean needMaint = needMaintenance(block.getTimeStamp()); From 801d79e714dd8a79145970fed6370486b28fb2b8 Mon Sep 17 00:00:00 2001 From: xiechang33 <354035097@qq.com> Date: Wed, 29 May 2019 15:21:40 +0800 Subject: [PATCH 17/90] add resource receive test --- .gitignore | 2 +- .../transferfailed/TestResourceReceiver.java | 200 ++++++++++++++++++ 2 files changed, 201 insertions(+), 1 deletion(-) create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TestResourceReceiver.java diff --git a/.gitignore b/.gitignore index b980800f353..3580691939b 100644 --- a/.gitignore +++ b/.gitignore @@ -51,7 +51,7 @@ src/main/resources/META-INF/ /output_witness/ output* nodeId.properties -Wallet + # vm_trace /vm_trace/ diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TestResourceReceiver.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TestResourceReceiver.java new file mode 100644 index 00000000000..f3e110916aa --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TestResourceReceiver.java @@ -0,0 +1,200 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.transferfailed; + +import com.google.protobuf.ByteString; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +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.api.WalletSolidityGrpc; +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.Base58; +import stest.tron.wallet.common.client.utils.PublicMethed; + +@Slf4j +public class TestResourceReceiver { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + + @Test(enabled = true, description = "Suicide existent Target") + public void test1SuicideExistentTarget() { + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; + String contractName = "EnergyOfTransferFailedTest"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractAddress, 3000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(testNetAccountAddress, + 1000000, 0, 1, + ByteString.copyFrom(contractAddress), testNetAccountKey, blockingStubFull)); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + ECKey ecKey2 = new ECKey(Utils.getRandom()); + byte[] existentAddress = ecKey2.getAddress(); + Assert.assertTrue(PublicMethed + .sendcoin(contractAddress, 1000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + String txid = ""; + String num = "\"" + Base58.encode58Check(contractAddress) + "\""; + txid = PublicMethed.triggerContract(contractAddress, + "testSuicideNonexistentTarget(address)", num, false, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + Optional infoById = null; + PublicMethed.waitProduceNextBlock(blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull1); + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull1); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + Account contractafter = PublicMethed.queryAccount(contractAddress, blockingStubFull1); + long contractBalance = contractafter.getBalance(); + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertEquals(contractBalance, 0); + txid = PublicMethed.triggerContract(contractAddress, + "testSuicideNonexistentTarget(address)", num, false, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + Assert.assertNull(txid); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + PublicMethed.unFreezeBalance(testNetAccountAddress, testNetAccountKey, 1, + contractAddress, blockingStubFull); + + + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} From a399ba35f9c4d3fccce8b3ebdb3b5fab872aa8e5 Mon Sep 17 00:00:00 2001 From: wubin01 Date: Wed, 29 May 2019 15:46:49 +0800 Subject: [PATCH 18/90] optimization fast forward function --- .../common/overlay/server/FastForward.java | 14 ++++----- src/main/java/org/tron/core/db/Manager.java | 7 +++++ .../org/tron/core/net/TronNetDelegate.java | 19 ++++-------- .../org/tron/core/net/TronNetService.java | 12 +++++++- .../net/messagehandler/BlockMsgHandler.java | 29 +++++++++++++------ .../org/tron/core/net/service/AdvService.java | 26 +++++++++++++---- 6 files changed, 69 insertions(+), 38 deletions(-) diff --git a/src/main/java/org/tron/common/overlay/server/FastForward.java b/src/main/java/org/tron/common/overlay/server/FastForward.java index 83c911a0d64..28b68aa0836 100644 --- a/src/main/java/org/tron/common/overlay/server/FastForward.java +++ b/src/main/java/org/tron/common/overlay/server/FastForward.java @@ -16,6 +16,7 @@ import org.tron.common.overlay.discover.node.NodeManager; import org.tron.core.config.args.Args; import org.tron.core.db.Manager; +import org.tron.core.db.WitnessScheduleStore; import org.tron.core.db.WitnessStore; import org.tron.core.services.WitnessService; import org.tron.protos.Protocol.ReasonCode; @@ -29,7 +30,7 @@ public class FastForward { private Manager manager; - private WitnessStore witnessStore; + private WitnessScheduleStore witnessScheduleStore; private NodeManager nodeManager; @@ -54,18 +55,14 @@ public void init() { } manager = ctx.getBean(Manager.class); - witnessStore = ctx.getBean(WitnessStore.class); + witnessScheduleStore = ctx.getBean(WitnessScheduleStore.class); nodeManager = ctx.getBean(NodeManager.class); channelManager = ctx.getBean(ChannelManager.class); backupManager = ctx.getBean(BackupManager.class); - if (args.getFastForwardNodes().size() > 0) { - fastForwardNodes = args.getFastForwardNodes(); - } - executorService.scheduleWithFixedDelay(() -> { try { - if (witnessStore.get(witnessAddress) != null && + if (witnessScheduleStore.getActiveWitnesses().contains(witnessAddress) && backupManager.getStatus().equals(BackupStatusEnum.MASTER) && !WitnessService.isNeedSyncCheck()) { connect(); @@ -90,11 +87,10 @@ private void disconnect() { InetAddress address = new InetSocketAddress(node.getHost(), node.getPort()).getAddress(); channelManager.getActiveNodes().remove(address); channelManager.getActivePeers().forEach(channel -> { - if (channel.getNode().equals(node)) { + if (channel.getInetAddress().equals(address)) { channel.disconnect(ReasonCode.RESET); } }); }); } - } diff --git a/src/main/java/org/tron/core/db/Manager.java b/src/main/java/org/tron/core/db/Manager.java index 5608d22e1f3..2982a450c6c 100644 --- a/src/main/java/org/tron/core/db/Manager.java +++ b/src/main/java/org/tron/core/db/Manager.java @@ -103,6 +103,8 @@ import org.tron.core.exception.VMIllegalException; import org.tron.core.exception.ValidateScheduleException; import org.tron.core.exception.ValidateSignatureException; +import org.tron.core.net.TronNetService; +import org.tron.core.net.message.BlockMessage; import org.tron.core.services.WitnessService; import org.tron.core.witness.ProposalController; import org.tron.core.witness.WitnessController; @@ -165,6 +167,9 @@ public class Manager { @Getter private StorageRowStore storageRowStore; + @Setter + private TronNetService tronNetService; + // for network @Autowired private PeersStore peersStore; @@ -1429,6 +1434,8 @@ public synchronized BlockCapsule generateBlock( blockCapsule.setMerkleRoot(); blockCapsule.sign(privateKey); + tronNetService.fastForward(new BlockMessage(blockCapsule)); + try { this.pushBlock(blockCapsule); return blockCapsule; diff --git a/src/main/java/org/tron/core/net/TronNetDelegate.java b/src/main/java/org/tron/core/net/TronNetDelegate.java index 969c42d7123..da170016627 100644 --- a/src/main/java/org/tron/core/net/TronNetDelegate.java +++ b/src/main/java/org/tron/core/net/TronNetDelegate.java @@ -2,7 +2,6 @@ import java.util.Collection; import java.util.LinkedList; -import java.util.List; import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; import lombok.Getter; @@ -15,9 +14,8 @@ import org.tron.core.capsule.BlockCapsule; import org.tron.core.capsule.BlockCapsule.BlockId; import org.tron.core.capsule.TransactionCapsule; -import org.tron.core.capsule.WitnessCapsule; import org.tron.core.db.Manager; -import org.tron.core.db.WitnessStore; +import org.tron.core.db.WitnessScheduleStore; import org.tron.core.exception.AccountResourceInsufficientException; import org.tron.core.exception.BadBlockException; import org.tron.core.exception.BadItemException; @@ -57,7 +55,7 @@ public class TronNetDelegate { private Manager dbManager; @Autowired - private WitnessStore witnessStore; + private WitnessScheduleStore witnessScheduleStore; @Getter private Object blockLock = new Object(); @@ -218,18 +216,11 @@ public void pushTransaction(TransactionCapsule trx) throws P2pException { public boolean validBlock(BlockCapsule block) throws P2pException { try { - if (!block.validateSignature(dbManager)) { + if (!block.validateSignature(dbManager) || + !witnessScheduleStore.getActiveWitnesses().contains(block.getWitnessAddress())) { return false; } - boolean flag = false; - List witnesses = witnessStore.getAllWitnesses(); - for (WitnessCapsule witness : witnesses) { - if (witness.getAddress().equals(block.getWitnessAddress())) { - flag = true; - break; - } - } - return flag; + return true; } catch (ValidateSignatureException e) { throw new P2pException(TypeEnum.BAD_BLOCK, e); } diff --git a/src/main/java/org/tron/core/net/TronNetService.java b/src/main/java/org/tron/core/net/TronNetService.java index 0fa16eb7f50..bd30c726b65 100644 --- a/src/main/java/org/tron/core/net/TronNetService.java +++ b/src/main/java/org/tron/core/net/TronNetService.java @@ -5,8 +5,10 @@ import org.springframework.stereotype.Component; import org.tron.common.overlay.message.Message; import org.tron.common.overlay.server.ChannelManager; +import org.tron.core.db.Manager; import org.tron.core.exception.P2pException; import org.tron.core.exception.P2pException.TypeEnum; +import org.tron.core.net.message.BlockMessage; import org.tron.core.net.message.TronMessage; import org.tron.core.net.messagehandler.BlockMsgHandler; import org.tron.core.net.messagehandler.ChainInventoryMsgHandler; @@ -55,7 +57,11 @@ public class TronNetService { @Autowired private TransactionsMsgHandler transactionsMsgHandler; + @Autowired + private Manager manager; + public void start() { + manager.setTronNetService(this); channelManager.init(); advService.init(); syncService.init(); @@ -77,6 +83,10 @@ public void broadcast(Message msg) { advService.broadcast(msg); } + public void fastForward(BlockMessage msg) { + advService.fastForward(msg); + } + protected void onMessage(PeerConnection peer, TronMessage msg) { try { switch (msg.getType()) { @@ -107,7 +117,7 @@ protected void onMessage(PeerConnection peer, TronMessage msg) { } private void processException(PeerConnection peer, TronMessage msg, Exception ex) { - ReasonCode code = null; + ReasonCode code; if (ex instanceof P2pException) { TypeEnum type = ((P2pException) ex).getType(); diff --git a/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java b/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java index 943874047bc..39264da6147 100644 --- a/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java +++ b/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java @@ -45,18 +45,24 @@ public class BlockMsgHandler implements TronMsgHandler { public void processMessage(PeerConnection peer, TronMessage msg) throws P2pException { BlockMessage blockMessage = (BlockMessage) msg; - - check(peer, blockMessage); - BlockId blockId = blockMessage.getBlockId(); Item item = new Item(blockId, InventoryType.BLOCK); + + if (fastForward || peer.isFastForwardPeer()) { + peer.getAdvInvReceive().put(item, System.currentTimeMillis()); + } else { + check(peer, blockMessage); + } + if (peer.getSyncBlockRequested().containsKey(blockId)) { peer.getSyncBlockRequested().remove(blockId); syncService.processBlock(peer, blockMessage); } else { - logger.info("Receive block {} from {}, cost {}ms", blockId.getString(), peer.getInetAddress(), - System.currentTimeMillis() - peer.getAdvInvRequest().get(item)); - peer.getAdvInvRequest().remove(item); + Long time = peer.getAdvInvRequest().remove(item); + if (time != null) { + logger.info("Receive block {} from {}, cost {}ms", blockId.getString(), peer.getInetAddress(), + System.currentTimeMillis() - time); + } processBlock(peer, blockMessage.getBlockCapsule()); } } @@ -81,14 +87,19 @@ private void processBlock(PeerConnection peer, BlockCapsule block) throws P2pExc BlockId blockId = block.getBlockId(); if (!tronNetDelegate.containBlock(block.getParentBlockId())) { logger.warn("Get unlink block {} from {}, head is {}.", blockId.getString(), - peer.getInetAddress(), tronNetDelegate - .getHeadBlockId().getString()); + peer.getInetAddress(), tronNetDelegate.getHeadBlockId().getString()); syncService.startSync(peer); return; } + long headNum = tronNetDelegate.getHeadBlockId().getNum(); + if (block.getNum() <= headNum) { + logger.info("Receive block num {} <= head num {}, from peer {}", + block.getNum(), headNum, peer.getInetAddress()); + } + if (fastForward && tronNetDelegate.validBlock(block)) { - advService.broadcast(new BlockMessage(block)); + advService.fastForward(new BlockMessage(block)); } tronNetDelegate.processBlock(block); diff --git a/src/main/java/org/tron/core/net/service/AdvService.java b/src/main/java/org/tron/core/net/service/AdvService.java index 36e74cb77a4..27dede579ff 100644 --- a/src/main/java/org/tron/core/net/service/AdvService.java +++ b/src/main/java/org/tron/core/net/service/AdvService.java @@ -97,7 +97,7 @@ public void close() { synchronized public boolean addInv(Item item) { - if (fastForward && !InventoryType.BLOCK.equals(item.getType())) { + if (fastForward) { return false; } @@ -135,7 +135,7 @@ public Message getMessage(Item item) { public void broadcast(Message msg) { - if (fastForward && !(msg instanceof BlockMessage)) { + if (fastForward) { return; } @@ -174,6 +174,24 @@ public void broadcast(Message msg) { } } + public void fastForward(BlockMessage msg) { + Item item = new Item(msg.getBlockId(), InventoryType.BLOCK); + List peers = tronNetDelegate.getActivePeer().stream() + .filter(peer -> !peer.isNeedSyncFromPeer() && !peer.isNeedSyncFromUs()) + .filter(peer -> peer.getAdvInvReceive().getIfPresent(item) == null && peer.getAdvInvSpread().getIfPresent(item) == null) + .collect(Collectors.toList()); + + if (!fastForward) { + peers = peers.stream().filter(peer -> peer.isFastForwardPeer()).collect(Collectors.toList()); + } + + peers.forEach(peer -> { + peer.sendMessage(msg); + peer.getAdvInvSpread().put(item, System.currentTimeMillis()); + }); + } + + public void onDisconnect(PeerConnection peer) { if (!peer.getAdvInvRequest().isEmpty()) { peer.getAdvInvRequest().keySet().forEach(item -> { @@ -228,6 +246,7 @@ synchronized private void consumerInvToSpread() { List peers = tronNetDelegate.getActivePeer().stream() .filter(peer -> !peer.isNeedSyncFromPeer() && !peer.isNeedSyncFromUs()) + .filter(peer -> !peer.isFastForwardPeer()) .collect(Collectors.toList()); if (invToSpread.isEmpty() || peers.isEmpty()) { @@ -285,9 +304,6 @@ public int getSize(PeerConnection peer) { public void sendInv() { send.forEach((peer, ids) -> ids.forEach((key, value) -> { - if (key.equals(InventoryType.TRX) && peer.isFastForwardPeer()) { - return; - } if (key.equals(InventoryType.BLOCK)) { value.sort(Comparator.comparingLong(value1 -> new BlockId(value1).getNum())); } From 8434febff2e86d07419bfbb26bdcec1c75933099 Mon Sep 17 00:00:00 2001 From: wangming Date: Wed, 29 May 2019 17:11:48 +0800 Subject: [PATCH 19/90] add create2 case 019-020 --- .../tvmnewcommand/create2/Create2Test019.java | 292 ++++++++++++++++ .../tvmnewcommand/create2/Create2Test020.java | 317 ++++++++++++++++++ 2 files changed, 609 insertions(+) create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test019.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test020.java diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test019.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test019.java new file mode 100644 index 00000000000..a0fa59f33bc --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test019.java @@ -0,0 +1,292 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.create2; + +import com.google.protobuf.ByteString; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +import java.util.List; +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.WalletClient; +import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.PublicMethed; + +@Slf4j +public class Create2Test019 { + + private final String testKey002 = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + 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(1); + private long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + + private byte[] factoryContractAddress = null; + private byte[] testContractAddress = null; + + private ECKey ecKey1 = new ECKey(Utils.getRandom()); + private byte[] dev001Address = ecKey1.getAddress(); + private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + private ECKey ecKey2 = new ECKey(Utils.getRandom()); + private byte[] user001Address = ecKey2.getAddress(); + private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + @BeforeClass(enabled = true) + public void beforeClass() { + + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + + PublicMethed.printAddress(dev001Key); + PublicMethed.printAddress(user001Key); + } + + + public byte[] subByte(byte[] b, int off, int length) { + byte[] b1 = new byte[length]; + System.arraycopy(b, off, b1, 0, length); + return b1; + + } + + @Test(enabled = true, description = "Deploy factory contract") + public void test01DeployFactoryContract() { + Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 10000_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 10000_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, + 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + //before deploy, check account resource + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long energyLimit = accountResource.getEnergyLimit(); + long energyUsage = accountResource.getEnergyUsed(); + long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before energyLimit is " + Long.toString(energyLimit)); + logger.info("before energyUsage is " + Long.toString(energyUsage)); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + String filePath = "./src/test/resources/soliditycode/suicide001.sol"; + String contractName = "factory"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + final String transferTokenTxid = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", + maxFeeLimit, 0L, 0, 10000, + "0", 0, null, dev001Key, + dev001Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + energyLimit = accountResource.getEnergyLimit(); + energyUsage = accountResource.getEnergyUsed(); + long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + + logger.info("after energyLimit is " + Long.toString(energyLimit)); + logger.info("after energyUsage is " + Long.toString(energyUsage)); + logger.info("after balanceAfter is " + Long.toString(balanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); + } + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + factoryContractAddress = infoById.get().getContractAddress().toByteArray(); + SmartContract smartContract = PublicMethed.getContract(factoryContractAddress, + blockingStubFull); + Assert.assertNotNull(smartContract.getAbi()); + } + + @Test(enabled = true, description = "contract A new B contract,A suicide,contract B still exist") + public void test02TriggerTestContract() { + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String triggerTxid = PublicMethed.triggerContract(factoryContractAddress, + "testCreateTrxInsufficientBalance()", "#", false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + + byte[] a = infoById.get().getContractResult(0).toByteArray(); + byte[] b = subByte(a, 11, 1); + byte[] c = subByte(a, 0, 11); + byte[] e = "41".getBytes(); + byte[] d = subByte(a, 12, 20); + + logger.info("a:" + ByteArray.toHexString(a)); + + logger.info("b:" + ByteArray.toHexString(b)); + logger.info("c:" + ByteArray.toHexString(c)); + + logger.info("d:" + ByteArray.toHexString(d)); + + logger.info("41" + ByteArray.toHexString(d)); + String exceptedResult = "41" + ByteArray.toHexString(d); + String realResult = ByteArray.toHexString(b); + Assert.assertEquals(realResult, "00"); + Assert.assertNotEquals(realResult, "41"); + + + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(exceptedResult)); + logger.info("B Address : " + addressFinal); + + //B Address is created by A, Trigger contract B + triggerTxid = PublicMethed.triggerContract(ByteArray.fromHexString(exceptedResult), + "test()", "#", false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + Assert.assertEquals(infoById.get().getResultValue(),0); + Assert.assertEquals(ByteArray.toLong(infoById.get().getContractResult(0).toByteArray()),1); + Assert.assertEquals("SUCESS",infoById.get().getResult().toString()); + + + triggerTxid = PublicMethed.triggerContract(factoryContractAddress, + "kill()", "#", false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + String note = ByteArray + .toStr(infoById.get().getInternalTransactions(0).getNote().toByteArray()); + + Assert.assertEquals(infoById.get().getResultValue(),0); + Assert.assertEquals("SUCESS",infoById.get().getResult().toString()); + Assert.assertEquals("suicide", note); + + + + triggerTxid = PublicMethed.triggerContract(ByteArray.fromHexString(exceptedResult), + "test()", "#", false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + Assert.assertEquals(infoById.get().getResultValue(),0); + Assert.assertEquals("SUCESS",infoById.get().getResult().toString()); + Assert.assertEquals(ByteArray.toStr(infoById.get().getResMessage().toByteArray()), + "null"); + Assert.assertEquals(infoById.get().getResult().toString(),"OTHER_ERROR"); + + } + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } +} + + diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test020.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test020.java new file mode 100644 index 00000000000..15131bcfb39 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test020.java @@ -0,0 +1,317 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.create2; + +import static org.hamcrest.core.StringContains.containsString; + +import com.google.protobuf.ByteString; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +import java.util.List; +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.WalletClient; +import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.PublicMethed; + +@Slf4j +public class Create2Test020 { + + private final String testKey002 = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + 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(1); + private long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + + private byte[] factoryContractAddress = null; + private byte[] testContractAddress = null; + + private ECKey ecKey1 = new ECKey(Utils.getRandom()); + private byte[] dev001Address = ecKey1.getAddress(); + private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + private ECKey ecKey2 = new ECKey(Utils.getRandom()); + private byte[] user001Address = ecKey2.getAddress(); + private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + @BeforeClass(enabled = true) + public void beforeClass() { + + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + + PublicMethed.printAddress(dev001Key); + PublicMethed.printAddress(user001Key); + } + + + public byte[] subByte(byte[] b, int off, int length) { + byte[] b1 = new byte[length]; + System.arraycopy(b, off, b1, 0, length); + return b1; + + } + + @Test(enabled = true, description = "Deploy factory contract") + public void test01DeployFactoryContract() { + Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 10000_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 10000_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, + 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + //before deploy, check account resource + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long energyLimit = accountResource.getEnergyLimit(); + long energyUsage = accountResource.getEnergyUsed(); + long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before energyLimit is " + Long.toString(energyLimit)); + logger.info("before energyUsage is " + Long.toString(energyUsage)); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + String filePath = "./src/test/resources/soliditycode/suicide002.sol"; + String contractName = "Factory"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + final String transferTokenTxid = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", + maxFeeLimit, 0L, 0, 10000, + "0", 0, null, dev001Key, + dev001Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + energyLimit = accountResource.getEnergyLimit(); + energyUsage = accountResource.getEnergyUsed(); + long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + + logger.info("after energyLimit is " + Long.toString(energyLimit)); + logger.info("after energyUsage is " + Long.toString(energyUsage)); + logger.info("after balanceAfter is " + Long.toString(balanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); + } + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + factoryContractAddress = infoById.get().getContractAddress().toByteArray(); + SmartContract smartContract = PublicMethed.getContract(factoryContractAddress, + blockingStubFull); + Assert.assertNotNull(smartContract.getAbi()); + } + + @Test(enabled = true, description = "function create2 ") + public void test02TriggerTestContract() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String filePath = "./src/test/resources/soliditycode/suicide002.sol"; + String contractName = "TestConstract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String testContractCode = retMap.get("byteCode").toString(); + Long salt = 1L; + + String param = "\"" + testContractCode + "\"," + salt; + + String triggerTxid = PublicMethed.triggerContract(factoryContractAddress, + "deploy(bytes,uint256)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + byte[] a = infoById.get().getContractResult(0).toByteArray(); + byte[] b = subByte(a, 11, 1); + byte[] c = subByte(a, 0, 11); + byte[] e = "41".getBytes(); + byte[] d = subByte(a, 12, 20); + + logger.info("a:" + ByteArray.toHexString(a)); + + logger.info("b:" + ByteArray.toHexString(b)); + logger.info("c:" + ByteArray.toHexString(c)); + + logger.info("d:" + ByteArray.toHexString(d)); + + logger.info("41" + ByteArray.toHexString(d)); + String exceptedResult = "41" + ByteArray.toHexString(d); + String realResult = ByteArray.toHexString(b); + Assert.assertEquals(realResult, "00"); + Assert.assertNotEquals(realResult, "41"); + + + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(exceptedResult)); + logger.info("B Address : " + addressFinal); + + Assert.assertEquals(infoById.get().getResult().toString(),"SUCESS"); + Assert.assertEquals(infoById.get().getResultValue(),0); + + + triggerTxid = PublicMethed.triggerContract(factoryContractAddress, + "deploy2(bytes,uint256)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + byte[] a1 = infoById.get().getContractResult(0).toByteArray(); + byte[] b1 = subByte(a, 11, 1); + byte[] c1 = subByte(a, 0, 11); + byte[] e1 = "41".getBytes(); + byte[] d1 = subByte(a, 12, 20); + + logger.info("a:" + ByteArray.toHexString(a)); + + logger.info("b:" + ByteArray.toHexString(b)); + logger.info("c:" + ByteArray.toHexString(c)); + + logger.info("d:" + ByteArray.toHexString(d)); + + logger.info("41" + ByteArray.toHexString(d)); + exceptedResult = "41" + ByteArray.toHexString(d); + realResult = ByteArray.toHexString(b); + Assert.assertEquals(realResult, "00"); + Assert.assertNotEquals(realResult, "41"); + + + addressFinal = Base58.encode58Check(ByteArray.fromHexString(exceptedResult)); + logger.info("B Address : " + addressFinal); + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + devEnergyLimitAfter = accountResource.getEnergyLimit(); + devEnergyUsageAfter = accountResource.getEnergyUsed(); + devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + userEnergyLimitAfter = accountResource.getEnergyLimit(); + userEnergyUsageAfter = accountResource.getEnergyUsed(); + userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + Assert.assertEquals(infoById.get().getResultValue(),1); + Assert.assertEquals(infoById.get().getResult().toString(),"FAILED"); + Assert.assertThat(ByteArray.toStr(infoById.get().getResMessage().toByteArray()), + containsString("Not enough energy for 'SWAP1' operation executing: ")); + + + + } + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } +} + + From 5d4e59118af8ff53e4d49d19dc167349236840b7 Mon Sep 17 00:00:00 2001 From: wangming Date: Wed, 29 May 2019 17:31:25 +0800 Subject: [PATCH 20/90] modify case --- .../tvmnewcommand/create2/Create2Test020.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test020.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test020.java index 15131bcfb39..6c8bcdf426c 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test020.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test020.java @@ -250,11 +250,11 @@ public void test02TriggerTestContract() { infoById = PublicMethed .getTransactionInfoById(triggerTxid, blockingStubFull); - byte[] a1 = infoById.get().getContractResult(0).toByteArray(); - byte[] b1 = subByte(a, 11, 1); - byte[] c1 = subByte(a, 0, 11); - byte[] e1 = "41".getBytes(); - byte[] d1 = subByte(a, 12, 20); + a = infoById.get().getContractResult(0).toByteArray(); + b = subByte(a, 11, 1); + c = subByte(a, 0, 11); + e = "41".getBytes(); + d = subByte(a, 12, 20); logger.info("a:" + ByteArray.toHexString(a)); From 59ca167e8406d43f062afed7940e30f032241eb7 Mon Sep 17 00:00:00 2001 From: xiechang33 <354035097@qq.com> Date: Wed, 29 May 2019 20:12:03 +0800 Subject: [PATCH 21/90] improve create2 stest --- .../tvmnewcommand/create2/Create2Test019.java | 238 ++++++++++++++++++ 1 file changed, 238 insertions(+) create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test019.java diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test019.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test019.java new file mode 100644 index 00000000000..be6c98f0e99 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test019.java @@ -0,0 +1,238 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.create2; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +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.api.WalletSolidityGrpc; +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.Base58; +import stest.tron.wallet.common.client.utils.PublicMethed; + +@Slf4j +public class Create2Test019 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + private byte[] contractExcAddress = PublicMethed + .getFinalAddress("9fc9b78370cdeab1bc11ba5e387e5e4f205f17d1957b1bebf4ce6d0330a448a4"); + private String contractExcKey = "9fc9b78370cdeab1bc11ba5e387e5e4f205f17d1957b1bebf4ce6d0330a448a4"; + + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + @Test(enabled = true, description = "triggerContract a constant function created by create2") + public void testTriggerContract() { + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/create2contractn.sol"; + String contractName = "Factory"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + + byte[] bytes = ByteArray.fromHexString("418EA294A47A944C75787DDB7270D73472AEE87FC0"); + String param2 = "\"" + Base58.encode58Check(bytes) + "\""; + if (PublicMethed.queryAccount(bytes, blockingStubFull).getTypeValue() == 2) { + String txidn = PublicMethed + .triggerContract(bytes, + "testSuicideNonexistentTarget(address)", param2, false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + } + Assert.assertTrue(PublicMethed + .sendcoin(bytes, 1000000L, contractExcAddress, contractExcKey, blockingStubFull)); + String contractName1 = "TestConstract"; + HashMap retMap1 = PublicMethed.getBycodeAbi(filePath, contractName1); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + String txid = ""; + String num = "\"" + code1 + "\"" + "," + 1; + txid = PublicMethed + .triggerContract(contractAddress, + "deploy(bytes,uint256)", num, false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + + byte[] returnAddressBytes = infoById.get().getInternalTransactions(0).getTransferToAddress() + .toByteArray(); + String returnAddress = Base58.encode58Check(returnAddressBytes); + Assert.assertEquals(Base58.encode58Check(bytes), returnAddress); + logger.info("returnAddress:" + returnAddress); + txid = PublicMethed + .triggerContract(returnAddressBytes, + "i()", "#", false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById1 = null; + infoById1 = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee1 = infoById1.get().getFee(); + Long netUsed1 = infoById1.get().getReceipt().getNetUsage(); + Long energyUsed1 = infoById1.get().getReceipt().getEnergyUsage(); + Long netFee1 = infoById1.get().getReceipt().getNetFee(); + long energyUsageTotal1 = infoById1.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee1:" + fee1); + logger.info("netUsed1:" + netUsed1); + logger.info("energyUsed1:" + energyUsed1); + logger.info("netFee1:" + netFee1); + logger.info("energyUsageTotal1:" + energyUsageTotal1); + + Account infoafter1 = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter1 = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance1 = infoafter1.getBalance(); + Long afterEnergyUsed1 = resourceInfoafter1.getEnergyUsed(); + Long afterNetUsed1 = resourceInfoafter1.getNetUsed(); + Long afterFreeNetUsed1 = resourceInfoafter1.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance1); + logger.info("afterEnergyUsed:" + afterEnergyUsed1); + logger.info("afterNetUsed:" + afterNetUsed1); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed1); + + Assert.assertTrue(infoById1.get().getResultValue() == 0); + Assert.assertTrue(afterBalance1 + fee1 == afterBalance); + Assert.assertTrue(afterEnergyUsed + energyUsed1 >= afterEnergyUsed1); + Long returnnumber = ByteArray.toLong(ByteArray + .fromHexString(ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); + Assert.assertTrue(1 == returnnumber); + Account account = PublicMethed.queryAccount(returnAddressBytes, blockingStubFull); + int typeValue = account.getTypeValue(); + Assert.assertEquals(2, typeValue); + Assert.assertEquals(account.getBalance(), 1000000); + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} From f18f5f92567c00f6f8847b3cd7ff15a5b8a235fb Mon Sep 17 00:00:00 2001 From: wangzihe Date: Wed, 29 May 2019 20:59:08 +0800 Subject: [PATCH 22/90] Add delegate resource to smart contract --- .../tvmnewcommand/create2/Create2Test021.java | 50 +++++++++++++++---- 1 file changed, 41 insertions(+), 9 deletions(-) diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test021.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test021.java index 72e98eee521..34e321cff86 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test021.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test021.java @@ -1,5 +1,6 @@ package stest.tron.wallet.dailybuild.tvmnewcommand.create2; +import com.google.protobuf.ByteString; import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import java.util.HashMap; @@ -58,6 +59,7 @@ public class Create2Test021 { private byte[] contractExcAddress = PublicMethed .getFinalAddress("9fc9b78370cdeab1bc11ba5e387e5e4f205f17d1957b1bebf4ce6d0330a448a4"); private String contractExcKey = "9fc9b78370cdeab1bc11ba5e387e5e4f205f17d1957b1bebf4ce6d0330a448a4"; + byte[] bytes; @BeforeSuite @@ -86,13 +88,15 @@ public void beforeClass() { .usePlaintext(true) .build(); blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } @Test(enabled = true, description = "triggerContract a constant function created by create2") public void testTriggerContract() { Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); + Assert.assertTrue(PublicMethed.freezeBalance(contractExcAddress,100000000L,0,contractExcKey,blockingStubFull)); PublicMethed.waitProduceNextBlock(blockingStubFull); String filePath = "src/test/resources/soliditycode/create2contractn.sol"; String contractName = "Factory"; @@ -118,16 +122,30 @@ public void testTriggerContract() { logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - byte[] bytes = ByteArray.fromHexString("418EA294A47A944C75787DDB7270D73472AEE87FC0"); - String param2 = "\"" + Base58.encode58Check(bytes) + "\""; - if (PublicMethed.queryAccount(bytes, blockingStubFull).getTypeValue() == 2) { - String txidn = PublicMethed - .triggerContract(bytes, - "testSuicideNonexistentTarget(address)", param2, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - } + bytes = ByteArray.fromHexString("418EA294A47A944C75787DDB7270D73472AEE87FC0"); + + String param2 = "\"" + Base58.encode58Check(contractExcAddress) + "\""; + String txidn = PublicMethed + .triggerContract(bytes, + "testSuicideNonexistentTarget(address)", param2, false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(bytes, 1000000L, contractExcAddress, contractExcKey, blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account account1 = PublicMethed.queryAccount(bytes, blockingStubFull); + int typeValue1 = account1.getTypeValue(); + Assert.assertEquals(0, typeValue1); + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(contractExcAddress,1000000L,0,0, + ByteString.copyFrom(bytes),contractExcKey,blockingStubFull)); + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(contractExcAddress,1000000L,0,1, + ByteString.copyFrom(bytes),contractExcKey,blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Long beforeExcAccountBalance = PublicMethed.queryAccount(contractExcAddress,blockingStubFull).getBalance(); + Assert.assertTrue(PublicMethed.getAccountResource(bytes,blockingStubFull).getNetLimit() > 0); + Assert.assertTrue(PublicMethed.getAccountResource(bytes,blockingStubFull).getEnergyLimit() > 0); + + String contractName1 = "TestConstract"; HashMap retMap1 = PublicMethed.getBycodeAbi(filePath, contractName1); String code1 = retMap1.get("byteCode").toString(); @@ -140,6 +158,15 @@ public void testTriggerContract() { 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertFalse(PublicMethed.freezeBalanceForReceiver(contractExcAddress,1000000L,0,0, + ByteString.copyFrom(bytes),contractExcKey,blockingStubFull)); + Assert.assertFalse(PublicMethed.freezeBalanceForReceiver(contractExcAddress,1000000L,0,1, + ByteString.copyFrom(bytes),contractExcKey,blockingStubFull)); + Long afterExcAccountBalance = PublicMethed.queryAccount(contractExcAddress,blockingStubFull).getBalance(); + Assert.assertTrue(PublicMethed.getAccountResource(bytes,blockingStubFull).getNetLimit() == 0); + Assert.assertTrue(PublicMethed.getAccountResource(bytes,blockingStubFull).getEnergyLimit() == 0); + Assert.assertTrue(afterExcAccountBalance - beforeExcAccountBalance == 1000000L*2); + Optional infoById = null; infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); Long fee = infoById.get().getFee(); @@ -222,6 +249,11 @@ public void testTriggerContract() { */ @AfterClass public void shutdown() throws InterruptedException { + PublicMethed.unFreezeBalance(contractExcAddress,contractExcKey,0,null,blockingStubFull); + PublicMethed.unFreezeBalance(contractExcAddress,contractExcKey,1,null,blockingStubFull); + PublicMethed.unFreezeBalance(contractExcAddress,contractExcKey,0,bytes,blockingStubFull); + PublicMethed.unFreezeBalance(contractExcAddress,contractExcKey,0,bytes,blockingStubFull); + if (channelFull != null) { channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); } From 2f04d50ccc61283b1aa7170c97885627b3566484 Mon Sep 17 00:00:00 2001 From: xiechang33 <354035097@qq.com> Date: Wed, 29 May 2019 21:12:08 +0800 Subject: [PATCH 23/90] improve dailybuild stability --- .../tvmnewcommand/create2/Create2Test021.java | 52 +++++++++++-------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test021.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test021.java index 34e321cff86..60646d1a46b 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test021.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test021.java @@ -96,7 +96,11 @@ public void testTriggerContract() { Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); - Assert.assertTrue(PublicMethed.freezeBalance(contractExcAddress,100000000L,0,contractExcKey,blockingStubFull)); + Assert.assertTrue(PublicMethed + .freezeBalance(contractExcAddress, 1000000000L, 0, contractExcKey, blockingStubFull)); + Assert.assertTrue(PublicMethed + .freezeBalanceGetEnergy(contractExcAddress, 1000000000L, 0, 1, contractExcKey, + blockingStubFull)); PublicMethed.waitProduceNextBlock(blockingStubFull); String filePath = "src/test/resources/soliditycode/create2contractn.sol"; String contractName = "Factory"; @@ -136,15 +140,16 @@ public void testTriggerContract() { Account account1 = PublicMethed.queryAccount(bytes, blockingStubFull); int typeValue1 = account1.getTypeValue(); Assert.assertEquals(0, typeValue1); - Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(contractExcAddress,1000000L,0,0, - ByteString.copyFrom(bytes),contractExcKey,blockingStubFull)); - Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(contractExcAddress,1000000L,0,1, - ByteString.copyFrom(bytes),contractExcKey,blockingStubFull)); + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(contractExcAddress, 1000000L, 0, 0, + ByteString.copyFrom(bytes), contractExcKey, blockingStubFull)); + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(contractExcAddress, 1000000L, 0, 1, + ByteString.copyFrom(bytes), contractExcKey, blockingStubFull)); PublicMethed.waitProduceNextBlock(blockingStubFull); - Long beforeExcAccountBalance = PublicMethed.queryAccount(contractExcAddress,blockingStubFull).getBalance(); - Assert.assertTrue(PublicMethed.getAccountResource(bytes,blockingStubFull).getNetLimit() > 0); - Assert.assertTrue(PublicMethed.getAccountResource(bytes,blockingStubFull).getEnergyLimit() > 0); - + Long beforeExcAccountBalance = PublicMethed.queryAccount(contractExcAddress, blockingStubFull) + .getBalance(); + Assert.assertTrue(PublicMethed.getAccountResource(bytes, blockingStubFull).getNetLimit() > 0); + Assert + .assertTrue(PublicMethed.getAccountResource(bytes, blockingStubFull).getEnergyLimit() > 0); String contractName1 = "TestConstract"; HashMap retMap1 = PublicMethed.getBycodeAbi(filePath, contractName1); @@ -158,14 +163,19 @@ public void testTriggerContract() { 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - Assert.assertFalse(PublicMethed.freezeBalanceForReceiver(contractExcAddress,1000000L,0,0, - ByteString.copyFrom(bytes),contractExcKey,blockingStubFull)); - Assert.assertFalse(PublicMethed.freezeBalanceForReceiver(contractExcAddress,1000000L,0,1, - ByteString.copyFrom(bytes),contractExcKey,blockingStubFull)); - Long afterExcAccountBalance = PublicMethed.queryAccount(contractExcAddress,blockingStubFull).getBalance(); - Assert.assertTrue(PublicMethed.getAccountResource(bytes,blockingStubFull).getNetLimit() == 0); - Assert.assertTrue(PublicMethed.getAccountResource(bytes,blockingStubFull).getEnergyLimit() == 0); - Assert.assertTrue(afterExcAccountBalance - beforeExcAccountBalance == 1000000L*2); + Assert.assertFalse(PublicMethed.freezeBalanceForReceiver(contractExcAddress, 1000000L, 0, 0, + ByteString.copyFrom(bytes), contractExcKey, blockingStubFull)); + Assert.assertFalse(PublicMethed.freezeBalanceForReceiver(contractExcAddress, 1000000L, 0, 1, + ByteString.copyFrom(bytes), contractExcKey, blockingStubFull)); + Long afterExcAccountBalance = PublicMethed.queryAccount(contractExcAddress, blockingStubFull) + .getBalance(); + Assert.assertTrue(PublicMethed.getAccountResource(bytes, blockingStubFull).getNetLimit() == 0); + Assert + .assertTrue(PublicMethed.getAccountResource(bytes, blockingStubFull).getEnergyLimit() == 0); + logger.info("afterExcAccountBalance:" + afterExcAccountBalance); + logger.info("beforeExcAccountBalance:" + beforeExcAccountBalance); + + Assert.assertTrue(afterExcAccountBalance - beforeExcAccountBalance == 1000000L * 2); Optional infoById = null; infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); @@ -249,10 +259,10 @@ public void testTriggerContract() { */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethed.unFreezeBalance(contractExcAddress,contractExcKey,0,null,blockingStubFull); - PublicMethed.unFreezeBalance(contractExcAddress,contractExcKey,1,null,blockingStubFull); - PublicMethed.unFreezeBalance(contractExcAddress,contractExcKey,0,bytes,blockingStubFull); - PublicMethed.unFreezeBalance(contractExcAddress,contractExcKey,0,bytes,blockingStubFull); + PublicMethed.unFreezeBalance(contractExcAddress, contractExcKey, 0, null, blockingStubFull); + PublicMethed.unFreezeBalance(contractExcAddress, contractExcKey, 1, null, blockingStubFull); + PublicMethed.unFreezeBalance(contractExcAddress, contractExcKey, 0, bytes, blockingStubFull); + PublicMethed.unFreezeBalance(contractExcAddress, contractExcKey, 0, bytes, blockingStubFull); if (channelFull != null) { channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); From 4949db860c4098968b22a5ae21521fd626511211 Mon Sep 17 00:00:00 2001 From: wangzihe Date: Thu, 30 May 2019 12:06:37 +0800 Subject: [PATCH 24/90] Add delegate resource to smart contract --- .../tvmnewcommand/create2/Create2Test021.java | 56 ++++++++++++------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test021.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test021.java index 60646d1a46b..a2f306cd39e 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test021.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test021.java @@ -58,9 +58,14 @@ public class Create2Test021 { ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] contractExcAddress = PublicMethed .getFinalAddress("9fc9b78370cdeab1bc11ba5e387e5e4f205f17d1957b1bebf4ce6d0330a448a4"); - private String contractExcKey = "9fc9b78370cdeab1bc11ba5e387e5e4f205f17d1957b1bebf4ce6d0330a448a4"; + private String contractExcKey = + "9fc9b78370cdeab1bc11ba5e387e5e4f205f17d1957b1bebf4ce6d0330a448a4"; byte[] bytes; + ECKey ecKey2 = new ECKey(Utils.getRandom()); + byte[] resourceOnwerAddress = ecKey2.getAddress(); + String resourceOnwerKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + @BeforeSuite public void beforeSuite() { @@ -75,6 +80,7 @@ public void beforeSuite() { @BeforeClass(enabled = true) public void beforeClass() { PublicMethed.printAddress(contractExcKey); + PublicMethed.printAddress(resourceOnwerKey); channelFull = ManagedChannelBuilder.forTarget(fullnode) .usePlaintext(true) .build(); @@ -97,10 +103,9 @@ public void testTriggerContract() { .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); Assert.assertTrue(PublicMethed - .freezeBalance(contractExcAddress, 1000000000L, 0, contractExcKey, blockingStubFull)); - Assert.assertTrue(PublicMethed - .freezeBalanceGetEnergy(contractExcAddress, 1000000000L, 0, 1, contractExcKey, + .sendcoin(resourceOnwerAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); String filePath = "src/test/resources/soliditycode/create2contractn.sol"; String contractName = "Factory"; @@ -140,13 +145,13 @@ public void testTriggerContract() { Account account1 = PublicMethed.queryAccount(bytes, blockingStubFull); int typeValue1 = account1.getTypeValue(); Assert.assertEquals(0, typeValue1); - Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(contractExcAddress, 1000000L, 0, 0, - ByteString.copyFrom(bytes), contractExcKey, blockingStubFull)); - Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(contractExcAddress, 1000000L, 0, 1, - ByteString.copyFrom(bytes), contractExcKey, blockingStubFull)); + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(resourceOnwerAddress, 1000000L, 0, 0, + ByteString.copyFrom(bytes), resourceOnwerKey, blockingStubFull)); + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(resourceOnwerAddress, 1000000L, 0, 1, + ByteString.copyFrom(bytes), resourceOnwerKey, blockingStubFull)); PublicMethed.waitProduceNextBlock(blockingStubFull); - Long beforeExcAccountBalance = PublicMethed.queryAccount(contractExcAddress, blockingStubFull) - .getBalance(); + final Long beforeExcAccountBalance = PublicMethed + .queryAccount(resourceOnwerAddress, blockingStubFull).getBalance(); Assert.assertTrue(PublicMethed.getAccountResource(bytes, blockingStubFull).getNetLimit() > 0); Assert .assertTrue(PublicMethed.getAccountResource(bytes, blockingStubFull).getEnergyLimit() > 0); @@ -163,19 +168,28 @@ public void testTriggerContract() { 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - Assert.assertFalse(PublicMethed.freezeBalanceForReceiver(contractExcAddress, 1000000L, 0, 0, - ByteString.copyFrom(bytes), contractExcKey, blockingStubFull)); - Assert.assertFalse(PublicMethed.freezeBalanceForReceiver(contractExcAddress, 1000000L, 0, 1, - ByteString.copyFrom(bytes), contractExcKey, blockingStubFull)); - Long afterExcAccountBalance = PublicMethed.queryAccount(contractExcAddress, blockingStubFull) + Assert.assertFalse(PublicMethed.freezeBalanceForReceiver(resourceOnwerAddress, 5000000L, 0, 0, + ByteString.copyFrom(bytes), resourceOnwerKey, blockingStubFull)); + Assert.assertFalse(PublicMethed.freezeBalanceForReceiver(resourceOnwerAddress, 5000000L, 0, 1, + ByteString.copyFrom(bytes), resourceOnwerKey, blockingStubFull)); + Long afterExcAccountBalance = PublicMethed.queryAccount(resourceOnwerAddress, blockingStubFull) .getBalance(); Assert.assertTrue(PublicMethed.getAccountResource(bytes, blockingStubFull).getNetLimit() == 0); Assert .assertTrue(PublicMethed.getAccountResource(bytes, blockingStubFull).getEnergyLimit() == 0); - logger.info("afterExcAccountBalance:" + afterExcAccountBalance); + logger.info("afterExcAccountBalance: " + afterExcAccountBalance); logger.info("beforeExcAccountBalance:" + beforeExcAccountBalance); - Assert.assertTrue(afterExcAccountBalance - beforeExcAccountBalance == 1000000L * 2); + Assert.assertTrue(afterExcAccountBalance - beforeExcAccountBalance == 0); + + Assert.assertTrue(PublicMethed.unFreezeBalance(resourceOnwerAddress,resourceOnwerKey, + 0,bytes,blockingStubFull)); + Assert.assertTrue(PublicMethed.unFreezeBalance(resourceOnwerAddress,resourceOnwerKey, + 1,bytes,blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Long afterUnfreezeBalance = PublicMethed.queryAccount(resourceOnwerAddress,blockingStubFull) + .getBalance(); + Assert.assertTrue(afterUnfreezeBalance == beforeExcAccountBalance + 1000000L * 2); Optional infoById = null; infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); @@ -259,10 +273,10 @@ public void testTriggerContract() { */ @AfterClass public void shutdown() throws InterruptedException { - PublicMethed.unFreezeBalance(contractExcAddress, contractExcKey, 0, null, blockingStubFull); - PublicMethed.unFreezeBalance(contractExcAddress, contractExcKey, 1, null, blockingStubFull); - PublicMethed.unFreezeBalance(contractExcAddress, contractExcKey, 0, bytes, blockingStubFull); - PublicMethed.unFreezeBalance(contractExcAddress, contractExcKey, 0, bytes, blockingStubFull); + //PublicMethed.unFreezeBalance(contractExcAddress, contractExcKey, 0, null, blockingStubFull); + //PublicMethed.unFreezeBalance(contractExcAddress, contractExcKey, 1, null, blockingStubFull); + //PublicMethed.unFreezeBalance(contractExcAddress, contractExcKey, 0, bytes, blockingStubFull); + //PublicMethed.unFreezeBalance(contractExcAddress, contractExcKey, 0, bytes, blockingStubFull); if (channelFull != null) { channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); From 538b97b62332073113302b2a0a419e3098c841e5 Mon Sep 17 00:00:00 2001 From: wangzihe Date: Thu, 30 May 2019 14:16:44 +0800 Subject: [PATCH 25/90] Add delegate resource to smart contract --- .../tvmnewcommand/create2/Create2Test021.java | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test021.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test021.java index a2f306cd39e..eeba3715670 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test021.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test021.java @@ -61,6 +61,12 @@ public class Create2Test021 { private String contractExcKey = "9fc9b78370cdeab1bc11ba5e387e5e4f205f17d1957b1bebf4ce6d0330a448a4"; byte[] bytes; + private static final long now = System.currentTimeMillis(); + private static final String name = "Asset008_" + Long.toString(now); + private static final long totalSupply = now; + String description = "just-test"; + String url = "https://github.com/tronprotocol/wallet-cli/"; + ECKey ecKey2 = new ECKey(Utils.getRandom()); byte[] resourceOnwerAddress = ecKey2.getAddress(); @@ -97,16 +103,22 @@ public void beforeClass() { } - @Test(enabled = true, description = "triggerContract a constant function created by create2") - public void testTriggerContract() { + @Test(enabled = true, description = "TriggerContract a constant function created by create2") + public void test1TriggerContract() { Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); Assert.assertTrue(PublicMethed - .sendcoin(resourceOnwerAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + .sendcoin(resourceOnwerAddress, 1000000000L + 1024000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); PublicMethed.waitProduceNextBlock(blockingStubFull); + //Create 3 the same name token. + Long start = System.currentTimeMillis() + 2000; + Long end = System.currentTimeMillis() + 1000000000; + Assert.assertTrue(PublicMethed.createAssetIssue(resourceOnwerAddress, + name, totalSupply, 1, 1, start, end, 1, description, url, + 2000L, 2000L, 1L, 1L, resourceOnwerKey, blockingStubFull)); String filePath = "src/test/resources/soliditycode/create2contractn.sol"; String contractName = "Factory"; HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); @@ -267,6 +279,21 @@ public void testTriggerContract() { Assert.assertEquals(account.getBalance(), 1000000); } + @Test(enabled = true, description = "Create2 contract can transfer trx and token.") + public void test2TriggerContract() { + //Trigger contract to transfer trx and token. + Account getAssetIdFromAccount = PublicMethed.queryAccount(resourceOnwerAddress, blockingStubFull); + final ByteString assetAccountId = getAssetIdFromAccount.getAssetIssuedID(); + Long contractBeforeBalance = PublicMethed.queryAccount(bytes,blockingStubFull).getBalance(); + + + + + + + + + } /** * constructor. From 8713be08ad09350c4195edf48fa958fbc2d2d10e Mon Sep 17 00:00:00 2001 From: xiechang33 <354035097@qq.com> Date: Thu, 30 May 2019 15:38:19 +0800 Subject: [PATCH 26/90] improve dailybuild stability --- .../tvmnewcommand/create2/Create2Test021.java | 87 +++++++++++++++---- .../soliditycode/create2contractn.sol | 6 ++ 2 files changed, 75 insertions(+), 18 deletions(-) diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test021.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test021.java index eeba3715670..a8fe952cadb 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test021.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test021.java @@ -66,7 +66,7 @@ public class Create2Test021 { private static final long totalSupply = now; String description = "just-test"; String url = "https://github.com/tronprotocol/wallet-cli/"; - + ByteString assetAccountId = null; ECKey ecKey2 = new ECKey(Utils.getRandom()); byte[] resourceOnwerAddress = ecKey2.getAddress(); @@ -109,7 +109,8 @@ public void test1TriggerContract() { .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); Assert.assertTrue(PublicMethed - .sendcoin(resourceOnwerAddress, 1000000000L + 1024000000L, testNetAccountAddress, testNetAccountKey, + .sendcoin(resourceOnwerAddress, 1000000000L + 1024000000L, testNetAccountAddress, + testNetAccountKey, blockingStubFull)); PublicMethed.waitProduceNextBlock(blockingStubFull); @@ -143,7 +144,7 @@ public void test1TriggerContract() { logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - bytes = ByteArray.fromHexString("418EA294A47A944C75787DDB7270D73472AEE87FC0"); + bytes = ByteArray.fromHexString("416CED4D6BF0AE10676347961BEFB7F47A8664AE36"); String param2 = "\"" + Base58.encode58Check(contractExcAddress) + "\""; String txidn = PublicMethed @@ -153,6 +154,17 @@ public void test1TriggerContract() { PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(bytes, 1000000L, contractExcAddress, contractExcKey, blockingStubFull)); + //Trigger contract to transfer trx and token. + Account getAssetIdFromAccount = PublicMethed + .queryAccount(resourceOnwerAddress, blockingStubFull); + assetAccountId = getAssetIdFromAccount.getAssetIssuedID(); + Long contractBeforeBalance = PublicMethed.queryAccount(bytes, blockingStubFull).getBalance(); + + Assert.assertTrue( + PublicMethed.transferAsset(bytes, assetAccountId.toByteArray(), 100, resourceOnwerAddress, + resourceOnwerKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); Account account1 = PublicMethed.queryAccount(bytes, blockingStubFull); int typeValue1 = account1.getTypeValue(); @@ -194,12 +206,12 @@ public void test1TriggerContract() { Assert.assertTrue(afterExcAccountBalance - beforeExcAccountBalance == 0); - Assert.assertTrue(PublicMethed.unFreezeBalance(resourceOnwerAddress,resourceOnwerKey, - 0,bytes,blockingStubFull)); - Assert.assertTrue(PublicMethed.unFreezeBalance(resourceOnwerAddress,resourceOnwerKey, - 1,bytes,blockingStubFull)); + Assert.assertTrue(PublicMethed.unFreezeBalance(resourceOnwerAddress, resourceOnwerKey, + 0, bytes, blockingStubFull)); + Assert.assertTrue(PublicMethed.unFreezeBalance(resourceOnwerAddress, resourceOnwerKey, + 1, bytes, blockingStubFull)); PublicMethed.waitProduceNextBlock(blockingStubFull); - Long afterUnfreezeBalance = PublicMethed.queryAccount(resourceOnwerAddress,blockingStubFull) + Long afterUnfreezeBalance = PublicMethed.queryAccount(resourceOnwerAddress, blockingStubFull) .getBalance(); Assert.assertTrue(afterUnfreezeBalance == beforeExcAccountBalance + 1000000L * 2); @@ -281,18 +293,57 @@ public void test1TriggerContract() { @Test(enabled = true, description = "Create2 contract can transfer trx and token.") public void test2TriggerContract() { - //Trigger contract to transfer trx and token. - Account getAssetIdFromAccount = PublicMethed.queryAccount(resourceOnwerAddress, blockingStubFull); - final ByteString assetAccountId = getAssetIdFromAccount.getAssetIssuedID(); - Long contractBeforeBalance = PublicMethed.queryAccount(bytes,blockingStubFull).getBalance(); - - - - - - + Account accountbefore = PublicMethed.queryAccount(bytes, blockingStubFull); + int typeValue = accountbefore.getTypeValue(); + Assert.assertEquals(2, typeValue); + long accountbeforeBalance = accountbefore.getBalance(); + Assert.assertEquals(accountbeforeBalance, 1000000); + Account contractExcAddressbefore = PublicMethed + .queryAccount(contractExcAddress, blockingStubFull); + long contractExcAddressbeforeBalance = contractExcAddressbefore.getBalance(); + String num = "1"; + String txid = PublicMethed + .triggerContract(bytes, + "testTransfer(uint256)", num, false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional transactionInfoById = PublicMethed + .getTransactionInfoById(txid, blockingStubFull); + Assert.assertTrue(transactionInfoById.get().getResultValue() == 0); + Long fee1 = transactionInfoById.get().getFee(); + + Account accountafter = PublicMethed.queryAccount(bytes, blockingStubFull); + long accountafterBalance = accountafter.getBalance(); + Assert.assertTrue(accountbeforeBalance - 1 == accountafterBalance); + + Account contractExcAddressafter = PublicMethed + .queryAccount(contractExcAddress, blockingStubFull); + long contractExcAddressafterBalance = contractExcAddressafter.getBalance(); + Assert.assertTrue(contractExcAddressbeforeBalance + 1 - fee1 == contractExcAddressafterBalance); + + num = "1" + ",\"" + assetAccountId.toStringUtf8() + "\""; + Long returnAddressBytesAccountCountBefore = PublicMethed + .getAssetIssueValue(bytes, assetAccountId, blockingStubFull); + Long contractExcAddressAccountCountBefore = PublicMethed + .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + String txid1 = PublicMethed + .triggerContract(bytes, + "testTransferToken(uint256,trcToken)", num, false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + Optional transactionInfoById1 = PublicMethed + .getTransactionInfoById(txid1, blockingStubFull); + Assert.assertTrue(transactionInfoById1.get().getResultValue() == 0); + Long returnAddressBytesAccountCountAfter = PublicMethed + .getAssetIssueValue(bytes, assetAccountId, blockingStubFull); + + Long contractExcAddressAccountCountAfter = PublicMethed + .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Assert.assertTrue( + returnAddressBytesAccountCountBefore - 1 == returnAddressBytesAccountCountAfter); + Assert.assertTrue( + contractExcAddressAccountCountBefore + 1 == contractExcAddressAccountCountAfter); } /** diff --git a/src/test/resources/soliditycode/create2contractn.sol b/src/test/resources/soliditycode/create2contractn.sol index dd0412c8a6d..e0e3ae64c16 100644 --- a/src/test/resources/soliditycode/create2contractn.sol +++ b/src/test/resources/soliditycode/create2contractn.sol @@ -17,6 +17,12 @@ contract Factory { contract TestConstract { uint public i=1; + function testTransfer(uint256 i) payable public{ + msg.sender.transfer(i); + } + function testTransferToken(uint256 i,trcToken tokenId) payable public{ + msg.sender.transferToken(i, tokenId); + } function testSuicideNonexistentTarget(address payable nonexistentTarget) payable public { selfdestruct(nonexistentTarget); } From 2974c484ae339601a8bef210ea5f288276cc3910 Mon Sep 17 00:00:00 2001 From: xiechang33 <354035097@qq.com> Date: Thu, 30 May 2019 18:41:35 +0800 Subject: [PATCH 27/90] improve dailybuild stability --- .../tvmnewcommand/create2/Create2Test021.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test021.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test021.java index a8fe952cadb..a030c67e3e2 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test021.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test021.java @@ -182,7 +182,21 @@ public void test1TriggerContract() { String contractName1 = "TestConstract"; HashMap retMap1 = PublicMethed.getBycodeAbi(filePath, contractName1); - String code1 = retMap1.get("byteCode").toString(); + String code1 = "6080604052600160005534801561001557600080fd5b50d3801561002257600080fd5b50" + + "d2801561002f57600080fd5b506101fd8061003f6000396000f3fe60806040526004361061005b577" + + "c01000000000000000000000000000000000000000000000000000000006000350463040821fc8114" + + "61006057806317b6ad5b1461007f578063cc133e94146100b2578063e5aa3d58146100d5575b60008" + + "0fd5b61007d6004803603602081101561007657600080fd5b5035610116565b005b61007d60048036" + + "03602081101561009557600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16610" + + "147565b61007d600480360360408110156100c857600080fd5b5080359060200135610160565b3480" + + "156100e157600080fd5b50d380156100ee57600080fd5b50d280156100fb57600080fd5b506101046" + + "101cb565b60408051918252519081900360200190f35b604051339082156108fc0290839060008181" + + "81858888f19350505050158015610143573d6000803e3d6000fd5b5050565b8073fffffffffffffff" + + "fffffffffffffffffffffffff16ff5b3382156108fc0283838015801561017657600080fd5b508067" + + "80000000000000001115801561018e57600080fd5b5080620f4240101580156101a157600080fd5b5" + + "0604051600081818185878a8ad09450505050501580156101c6573d6000803e3d6000fd5b50505056" + + "5b6000548156fea165627a7a72305820485b773c60fed3b76621350dd3da7ecf152a2d37ca02dc195" + + "d6f8a26aec196850029"; String abi1 = retMap1.get("abI").toString(); String txid = ""; String num = "\"" + code1 + "\"" + "," + 1; From 82d7663757666701fd8c0ede10b4c5d60df05e41 Mon Sep 17 00:00:00 2001 From: wubin01 Date: Fri, 31 May 2019 11:54:34 +0800 Subject: [PATCH 28/90] optimizing network statistics --- .../overlay/discover/node/NodeHandler.java | 5 +- .../node/statistics/NodeStatistics.java | 54 ++++++++----------- .../tron/common/overlay/server/Channel.java | 27 ---------- .../common/overlay/server/MessageQueue.java | 40 ++++++++------ .../overlay/server/MessageRoundtrip.java | 41 ++------------ .../common/overlay/server/P2pHandler.java | 1 - .../common/overlay/server/PeerStatistics.java | 37 ------------- .../tron/common/overlay/server/SyncPool.java | 34 +++--------- .../server/TronChannelInitializer.java | 21 -------- .../net/messagehandler/BlockMsgHandler.java | 14 +++-- .../tron/core/net/peer/PeerConnection.java | 18 +++++-- .../org/tron/core/net/service/AdvService.java | 6 +-- .../tron/core/services/NodeInfoService.java | 2 +- 13 files changed, 88 insertions(+), 212 deletions(-) delete mode 100644 src/main/java/org/tron/common/overlay/server/PeerStatistics.java diff --git a/src/main/java/org/tron/common/overlay/discover/node/NodeHandler.java b/src/main/java/org/tron/common/overlay/discover/node/NodeHandler.java index fece3822772..f60934bd96e 100644 --- a/src/main/java/org/tron/common/overlay/discover/node/NodeHandler.java +++ b/src/main/java/org/tron/common/overlay/discover/node/NodeHandler.java @@ -95,7 +95,7 @@ public NodeHandler(Node node, NodeManager nodeManager) { this.node = node; this.nodeManager = nodeManager; this.inetSocketAddress = new InetSocketAddress(node.getHost(), node.getPort()); - this.nodeStatistics = new NodeStatistics(node); + this.nodeStatistics = new NodeStatistics(); changeState(State.Discovered); } @@ -201,8 +201,7 @@ public void handlePing(PingMessage msg) { public void handlePong(PongMessage msg) { if (waitForPong) { waitForPong = false; - getNodeStatistics().discoverMessageLatency - .add((double) System.currentTimeMillis() - pingSent); + getNodeStatistics().discoverMessageLatency.add(System.currentTimeMillis() - pingSent); getNodeStatistics().lastPongReplyTime.set(System.currentTimeMillis()); node.setId(msg.getFrom().getId()); if (msg.getVersion() != Args.getInstance().getNodeP2pVersion()) { diff --git a/src/main/java/org/tron/common/overlay/discover/node/statistics/NodeStatistics.java b/src/main/java/org/tron/common/overlay/discover/node/statistics/NodeStatistics.java index 5b859658bc0..e6e14aee06a 100644 --- a/src/main/java/org/tron/common/overlay/discover/node/statistics/NodeStatistics.java +++ b/src/main/java/org/tron/common/overlay/discover/node/statistics/NodeStatistics.java @@ -21,6 +21,7 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; import lombok.Getter; +import lombok.Setter; import org.tron.common.overlay.discover.node.Node; import org.tron.core.config.args.Args; import org.tron.protos.Protocol.ReasonCode; @@ -48,12 +49,15 @@ public class NodeStatistics { public final MessageCount tcpFlow = new MessageCount(); public final SimpleStatter discoverMessageLatency; + public final SimpleStatter pingMessageLatency; + public final AtomicLong lastPongReplyTime = new AtomicLong(0L); // in milliseconds private Reputation reputation; - public NodeStatistics(Node node) { - discoverMessageLatency = new SimpleStatter(node.getIdString()); + public NodeStatistics() { + discoverMessageLatency = new SimpleStatter(); + pingMessageLatency = new SimpleStatter(); reputation = new Reputation(this); } @@ -182,40 +186,26 @@ public String toString() { } public class SimpleStatter { - - private final String name; - private volatile double last; - private volatile double sum; - private AtomicInteger count = new AtomicInteger(); - - public SimpleStatter(String name) { - this.name = name; - } - - public void add(double value) { + private long sum; + @Getter + private long count; + @Getter + private long last; + @Getter + private long min; + @Getter + private long max; + + public void add(long value) { last = value; sum += value; - count.incrementAndGet(); - } - - public double getLast() { - return last; - } - - public int getCount() { - return count.get(); - } - - public double getSum() { - return sum; - } - - public double getAvrg() { - return count.get() == 0 ? 0 : sum / count.get(); + min = min == 0? value : Math.min(min, value); + max = Math.max(max, value); + count++; } - public String getName() { - return name; + public long getAvrg() { + return count == 0 ? 0 : sum / count; } } diff --git a/src/main/java/org/tron/common/overlay/server/Channel.java b/src/main/java/org/tron/common/overlay/server/Channel.java index b2433855235..20cc1465ecb 100644 --- a/src/main/java/org/tron/common/overlay/server/Channel.java +++ b/src/main/java/org/tron/common/overlay/server/Channel.java @@ -1,20 +1,3 @@ -/* - * Copyright (c) [2016] [ ] - * This file is part of the ethereumJ library. - * - * The ethereumJ library is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * The ethereumJ library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with the ethereumJ library. If not, see . - */ package org.tron.common.overlay.server; import io.netty.channel.ChannelHandlerContext; @@ -90,10 +73,6 @@ public class Channel { private volatile boolean isDisconnect; - private String remoteId; - - private PeerStatistics peerStats = new PeerStatistics(); - private boolean isTrustPeer; private boolean isFastForwardPeer; @@ -103,8 +82,6 @@ public void init(ChannelPipeline pipeline, String remoteId, boolean discoveryMod this.channelManager = channelManager; - this.remoteId = remoteId; - isActive = remoteId != null && !remoteId.isEmpty(); startTime = System.currentTimeMillis(); @@ -197,10 +174,6 @@ public enum TronState { SYNC_FAILED } - public PeerStatistics getPeerStats() { - return peerStats; - } - public Node getNode() { return node; } diff --git a/src/main/java/org/tron/common/overlay/server/MessageQueue.java b/src/main/java/org/tron/common/overlay/server/MessageQueue.java index 3deb4532592..478308fb273 100644 --- a/src/main/java/org/tron/common/overlay/server/MessageQueue.java +++ b/src/main/java/org/tron/common/overlay/server/MessageQueue.java @@ -30,6 +30,8 @@ public class MessageQueue { private volatile long sendTime; + private volatile long sendPing; + private Thread sendMsgThread; private Channel channel; @@ -84,14 +86,18 @@ public void activate(ChannelHandlerContext ctx) { sendMsgThread.setName("sendMsgThread-" + ctx.channel().remoteAddress()); sendMsgThread.start(); } - + public void setChannel(Channel channel) { this.channel = channel; } public boolean sendMessage(Message msg) { - if (msg instanceof PingMessage && sendTime > System.currentTimeMillis() - 10_000) { - return false; + long now = System.currentTimeMillis(); + if (msg instanceof PingMessage) { + if (now - sendTime < 10_000 && now - sendPing < 60_000) { + return false; + } + sendPing = now; } if (needToLog(msg)) { logger.info("Send to {}, {} ", ctx.channel().remoteAddress(), msg); @@ -111,10 +117,13 @@ public void receivedMessage(Message msg) { logger.info("Receive from {}, {}", ctx.channel().remoteAddress(), msg); } channel.getNodeStatistics().messageStatistics.addTcpInMessage(msg); - MessageRoundtrip messageRoundtrip = requestQueue.peek(); - if (messageRoundtrip != null && messageRoundtrip.getMsg().getAnswerMessage() == msg - .getClass()) { + MessageRoundtrip rt = requestQueue.peek(); + if (rt != null && rt.getMsg().getAnswerMessage() == msg.getClass()) { requestQueue.remove(); + if (rt.getMsg() instanceof PingMessage) { + channel.getNodeStatistics().pingMessageLatency + .add(System.currentTimeMillis() - rt.getTime()); + } } } @@ -150,23 +159,22 @@ private boolean needToLog(Message msg) { } private void send() { - MessageRoundtrip messageRoundtrip = requestQueue.peek(); - if (!sendMsgFlag || messageRoundtrip == null) { + MessageRoundtrip rt = requestQueue.peek(); + if (!sendMsgFlag || rt == null) { return; } - if (messageRoundtrip.getRetryTimes() > 0 && !messageRoundtrip.hasToRetry()) { + if (rt.getRetryTimes() > 0 && !rt.hasToRetry()) { return; } - if (messageRoundtrip.getRetryTimes() > 0) { + if (rt.getRetryTimes() > 0) { channel.getNodeStatistics().nodeDisconnectedLocal(ReasonCode.PING_TIMEOUT); - logger - .warn("Wait {} timeout. close channel {}.", messageRoundtrip.getMsg().getAnswerMessage(), - ctx.channel().remoteAddress()); + logger.warn("Wait {} timeout. close channel {}.", + rt.getMsg().getAnswerMessage(), ctx.channel().remoteAddress()); channel.close(); return; } - Message msg = messageRoundtrip.getMsg(); + Message msg = rt.getMsg(); ctx.writeAndFlush(msg.getSendData()).addListener((ChannelFutureListener) future -> { if (!future.isSuccess()) { @@ -174,8 +182,8 @@ private void send() { } }); - messageRoundtrip.incRetryTimes(); - messageRoundtrip.saveTime(); + rt.incRetryTimes(); + rt.saveTime(); } } diff --git a/src/main/java/org/tron/common/overlay/server/MessageRoundtrip.java b/src/main/java/org/tron/common/overlay/server/MessageRoundtrip.java index c72b131e5e4..4e05b80fec4 100644 --- a/src/main/java/org/tron/common/overlay/server/MessageRoundtrip.java +++ b/src/main/java/org/tron/common/overlay/server/MessageRoundtrip.java @@ -1,51 +1,18 @@ -/* - * Copyright (c) [2016] [ ] - * This file is part of the ethereumJ library. - * - * The ethereumJ library is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * The ethereumJ library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with the ethereumJ library. If not, see . - */ package org.tron.common.overlay.server; import org.tron.common.overlay.message.Message; -/** - * Utility wraps around a message to keep track of the number of times it has been offered This - * class also contains the last time a message was offered and is updated when an answer has been - * received to it can be removed from the queue. - * - * @author Roman Mandeleil - */ public class MessageRoundtrip { private final Message msg; - private long lastTimestamp = 0; + private long time = 0; private long retryTimes = 0; - private boolean answered = false; public MessageRoundtrip(Message msg) { this.msg = msg; saveTime(); } - public boolean isAnswered() { - return answered; - } - - public void answer() { - answered = true; - } - public long getRetryTimes() { return retryTimes; } @@ -55,15 +22,15 @@ public void incRetryTimes() { } public void saveTime() { - lastTimestamp = System.currentTimeMillis(); + time = System.currentTimeMillis(); } public long getTime() { - return lastTimestamp; + return time; } public boolean hasToRetry() { - return 20000 < System.currentTimeMillis() - lastTimestamp; + return 20000 < System.currentTimeMillis() - time; } public Message getMsg() { diff --git a/src/main/java/org/tron/common/overlay/server/P2pHandler.java b/src/main/java/org/tron/common/overlay/server/P2pHandler.java index e5dae36a51e..a80169f5339 100644 --- a/src/main/java/org/tron/common/overlay/server/P2pHandler.java +++ b/src/main/java/org/tron/common/overlay/server/P2pHandler.java @@ -73,7 +73,6 @@ public void channelRead0(final ChannelHandlerContext ctx, P2pMessage msg) { } hasPing = false; channel.getNodeStatistics().lastPongReplyTime.set(System.currentTimeMillis()); - channel.getPeerStats().pong(sendPingTime); break; case P2P_DISCONNECT: channel.getNodeStatistics() diff --git a/src/main/java/org/tron/common/overlay/server/PeerStatistics.java b/src/main/java/org/tron/common/overlay/server/PeerStatistics.java deleted file mode 100644 index 5b1128ff740..00000000000 --- a/src/main/java/org/tron/common/overlay/server/PeerStatistics.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) [2016] [ ] - * This file is part of the ethereumJ library. - * - * The ethereumJ library is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * The ethereumJ library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with the ethereumJ library. If not, see . - */ -package org.tron.common.overlay.server; - -/** - * @author Mikhail Kalinin - * @since 29.02.2016 - */ -public class PeerStatistics { - - private double avgLatency = 0; - private long pingCount = 0; - - public void pong(long pingStamp) { - long latency = System.currentTimeMillis() - pingStamp; - avgLatency = ((avgLatency * pingCount) + latency) / ++pingCount; - } - - public double getAvgLatency() { - return avgLatency; - } -} diff --git a/src/main/java/org/tron/common/overlay/server/SyncPool.java b/src/main/java/org/tron/common/overlay/server/SyncPool.java index f444f0862e8..d8a7c131933 100644 --- a/src/main/java/org/tron/common/overlay/server/SyncPool.java +++ b/src/main/java/org/tron/common/overlay/server/SyncPool.java @@ -133,32 +133,13 @@ private void fillUp() { } synchronized void logActivePeers() { - - logger.info("-------- active connect channel {}", activePeersCount.get()); - logger.info("-------- passive connect channel {}", passivePeersCount.get()); - logger.info("-------- all connect channel {}", channelManager.getActivePeers().size()); - for (Channel channel : channelManager.getActivePeers()) { - logger.info(channel.toString()); - } - - if (logger.isInfoEnabled()) { - StringBuilder sb = new StringBuilder("Peer stats:\n"); - sb.append("Active peers\n"); - sb.append("============\n"); - Set activeSet = new HashSet<>(); - for (PeerConnection peer : new ArrayList<>(activePeers)) { - sb.append(peer.log()).append('\n'); - activeSet.add(peer.getNode()); - } - sb.append("Other connected peers\n"); - sb.append("============\n"); - for (Channel peer : new ArrayList<>(channelManager.getActivePeers())) { - if (!activeSet.contains(peer.getNode())) { - sb.append(peer.getNode()).append('\n'); - } - } - logger.info(sb.toString()); + String str = String.format("\n\n============ Peer stats: all %d, active %d, passive %d\n\n", + channelManager.getActivePeers().size(), activePeersCount.get(), passivePeersCount.get()); + StringBuilder sb = new StringBuilder(str); + for (PeerConnection peer : new ArrayList<>(activePeers)) { + sb.append(peer.log()).append('\n'); } + logger.info(sb.toString()); } public List getActivePeers() { @@ -180,7 +161,8 @@ public synchronized void onConnect(Channel peer) { activePeersCount.incrementAndGet(); } activePeers.add(peerConnection); - activePeers.sort(Comparator.comparingDouble(c -> c.getPeerStats().getAvgLatency())); + activePeers. + sort(Comparator.comparingDouble(c -> c.getNodeStatistics().pingMessageLatency.getAvrg())); peerConnection.onConnect(); } } diff --git a/src/main/java/org/tron/common/overlay/server/TronChannelInitializer.java b/src/main/java/org/tron/common/overlay/server/TronChannelInitializer.java index bc6ad417d37..4ffefd92ae2 100644 --- a/src/main/java/org/tron/common/overlay/server/TronChannelInitializer.java +++ b/src/main/java/org/tron/common/overlay/server/TronChannelInitializer.java @@ -1,20 +1,3 @@ -/* - * Copyright (c) [2016] [ ] - * This file is part of the ethereumJ library. - * - * The ethereumJ library is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * The ethereumJ library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with the ethereumJ library. If not, see . - */ package org.tron.common.overlay.server; import io.netty.channel.ChannelFutureListener; @@ -29,10 +12,6 @@ import org.springframework.stereotype.Component; import org.tron.core.net.peer.PeerConnection; -/** - * @author Roman Mandeleil - * @since 01.11.2014 - */ @Slf4j(topic = "net") @Component @Scope("prototype") diff --git a/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java b/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java index 39264da6147..bf8c89d60a5 100644 --- a/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java +++ b/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java @@ -39,6 +39,8 @@ public class BlockMsgHandler implements TronMsgHandler { private int maxBlockSize = BLOCK_SIZE + 1000; + private int threshold = 3; + private boolean fastForward = Args.getInstance().isFastForward(); @Override @@ -60,7 +62,8 @@ public void processMessage(PeerConnection peer, TronMessage msg) throws P2pExcep } else { Long time = peer.getAdvInvRequest().remove(item); if (time != null) { - logger.info("Receive block {} from {}, cost {}ms", blockId.getString(), peer.getInetAddress(), + logger.info("Receive block {} from {}, cost {}ms", blockId.getString(), + peer.getInetAddress(), System.currentTimeMillis() - time); } processBlock(peer, blockMessage.getBlockCapsule()); @@ -98,8 +101,13 @@ private void processBlock(PeerConnection peer, BlockCapsule block) throws P2pExc block.getNum(), headNum, peer.getInetAddress()); } - if (fastForward && tronNetDelegate.validBlock(block)) { - advService.fastForward(new BlockMessage(block)); + if (fastForward) { + if (headNum - block.getNum() > threshold) { + return; + } + if (tronNetDelegate.validBlock(block)) { + advService.fastForward(new BlockMessage(block)); + } } tronNetDelegate.processBlock(block); diff --git a/src/main/java/org/tron/core/net/peer/PeerConnection.java b/src/main/java/org/tron/core/net/peer/PeerConnection.java index 353541c89f8..fed6b0b1131 100644 --- a/src/main/java/org/tron/core/net/peer/PeerConnection.java +++ b/src/main/java/org/tron/core/net/peer/PeerConnection.java @@ -18,6 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; +import org.tron.common.overlay.discover.node.statistics.NodeStatistics.SimpleStatter; import org.tron.common.overlay.message.HelloMessage; import org.tron.common.overlay.message.Message; import org.tron.common.overlay.server.Channel; @@ -172,7 +173,8 @@ public String log() { // nodeStatistics.toString()); //// return String.format( - "Peer %s: [ %18s, ping %6s ms]-----------\n" + "Peer %s [%8s]\n" + + "ping msg: count %d, max-average-min-last: %d %d %d %d\n" + "connect time: %ds\n" + "last know block num: %s\n" + "needSyncFromPeer:%b\n" @@ -183,10 +185,16 @@ public String log() { + "remainNum:%d\n" + "syncChainRequested:%d\n" + "blockInProcess:%d\n", - this.getNode().getHost() + ":" + this.getNode().getPort(), - this.getNode().getHexIdShort(), - (int) this.getPeerStats().getAvgLatency(), - (now - super.getStartTime()) / 1000, + getNode().getHost() + ":" + getNode().getPort(), + getNode().getHexIdShort(), + + getNodeStatistics().pingMessageLatency.getCount(), + getNodeStatistics().pingMessageLatency.getMax(), + getNodeStatistics().pingMessageLatency.getAvrg(), + getNodeStatistics().pingMessageLatency.getMin(), + getNodeStatistics().pingMessageLatency.getLast(), + + (now - getStartTime()) / 1000, blockBothHave.getNum(), isNeedSyncFromPeer(), isNeedSyncFromUs(), diff --git a/src/main/java/org/tron/core/net/service/AdvService.java b/src/main/java/org/tron/core/net/service/AdvService.java index 27dede579ff..d9b5e530091 100644 --- a/src/main/java/org/tron/core/net/service/AdvService.java +++ b/src/main/java/org/tron/core/net/service/AdvService.java @@ -160,8 +160,7 @@ public void broadcast(Message msg) { TransactionMessage trxMsg = (TransactionMessage) msg; item = new Item(trxMsg.getMessageId(), InventoryType.TRX); trxCount.add(); - trxCache.put(item, - new TransactionMessage(((TransactionMessage) msg).getTransactionCapsule().getInstance())); + trxCache.put(item, new TransactionMessage(trxMsg.getTransactionCapsule().getInstance())); } else { logger.error("Adv item is neither block nor trx, type: {}", msg.getType()); return; @@ -178,7 +177,8 @@ public void fastForward(BlockMessage msg) { Item item = new Item(msg.getBlockId(), InventoryType.BLOCK); List peers = tronNetDelegate.getActivePeer().stream() .filter(peer -> !peer.isNeedSyncFromPeer() && !peer.isNeedSyncFromUs()) - .filter(peer -> peer.getAdvInvReceive().getIfPresent(item) == null && peer.getAdvInvSpread().getIfPresent(item) == null) + .filter(peer -> peer.getAdvInvReceive().getIfPresent(item) == null + && peer.getAdvInvSpread().getIfPresent(item) == null) .collect(Collectors.toList()); if (!fastForward) { diff --git a/src/main/java/org/tron/core/services/NodeInfoService.java b/src/main/java/org/tron/core/services/NodeInfoService.java index 141ac56c17c..36103be5bec 100644 --- a/src/main/java/org/tron/core/services/NodeInfoService.java +++ b/src/main/java/org/tron/core/services/NodeInfoService.java @@ -127,7 +127,7 @@ private void setConnectInfo(NodeInfo nodeInfo) { PeerInfo peerInfo = new PeerInfo(); peerInfo.setHeadBlockWeBothHave(peerConnection.getBlockBothHave().getString()); peerInfo.setActive(peerConnection.isActive()); - peerInfo.setAvgLatency(peerConnection.getPeerStats().getAvgLatency()); + peerInfo.setAvgLatency(peerConnection.getNodeStatistics().pingMessageLatency.getAvrg()); peerInfo.setBlockInPorcSize(peerConnection.getSyncBlockInProcess().size()); peerInfo.setConnectTime(peerConnection.getStartTime()); peerInfo.setDisconnectTimes(peerConnection.getNodeStatistics().getDisconnectTimes()); From fe164989139b82f695990fe9fba9757fc1758746 Mon Sep 17 00:00:00 2001 From: wangming Date: Fri, 31 May 2019 14:54:51 +0800 Subject: [PATCH 29/90] add case --- .../tvmnewcommand/create2/Create2Test019.java | 238 -------------- .../tvmnewcommand/create2/Create2Test023.java | 290 ++++++++++++++++++ ...reate2Test020.java => Create2Test024.java} | 54 +--- .../resources/soliditycode/Create2Test023.sol | 31 ++ .../resources/soliditycode/Create2Test024.sol | 56 ++++ 5 files changed, 393 insertions(+), 276 deletions(-) delete mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test019.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test023.java rename src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/{Create2Test020.java => Create2Test024.java} (87%) create mode 100644 src/test/resources/soliditycode/Create2Test023.sol create mode 100644 src/test/resources/soliditycode/Create2Test024.sol diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test019.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test019.java deleted file mode 100644 index be6c98f0e99..00000000000 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test019.java +++ /dev/null @@ -1,238 +0,0 @@ -package stest.tron.wallet.dailybuild.tvmnewcommand.create2; - -import io.grpc.ManagedChannel; -import io.grpc.ManagedChannelBuilder; -import java.util.HashMap; -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.api.WalletSolidityGrpc; -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.Base58; -import stest.tron.wallet.common.client.utils.PublicMethed; - -@Slf4j -public class Create2Test019 { - - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); - private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); - private Long maxFeeLimit = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.maxFeeLimit"); - private ManagedChannel channelSolidity = null; - - private ManagedChannel channelFull = null; - private WalletGrpc.WalletBlockingStub blockingStubFull = null; - - private ManagedChannel channelFull1 = null; - private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - - - private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; - - private String fullnode = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(0); - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - - private String soliditynode = Configuration.getByPath("testng.conf") - .getStringList("solidityNode.ip.list").get(0); - - byte[] contractAddress = null; - - ECKey ecKey1 = new ECKey(Utils.getRandom()); - private byte[] contractExcAddress = PublicMethed - .getFinalAddress("9fc9b78370cdeab1bc11ba5e387e5e4f205f17d1957b1bebf4ce6d0330a448a4"); - private String contractExcKey = "9fc9b78370cdeab1bc11ba5e387e5e4f205f17d1957b1bebf4ce6d0330a448a4"; - - - - @BeforeSuite - public void beforeSuite() { - Wallet wallet = new Wallet(); - Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); - } - - /** - * constructor. - */ - - @BeforeClass(enabled = true) - public void beforeClass() { - PublicMethed.printAddress(contractExcKey); - channelFull = ManagedChannelBuilder.forTarget(fullnode) - .usePlaintext(true) - .build(); - blockingStubFull = WalletGrpc.newBlockingStub(channelFull); - channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext(true) - .build(); - blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - - channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) - .usePlaintext(true) - .build(); - blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); - } - - @Test(enabled = true, description = "triggerContract a constant function created by create2") - public void testTriggerContract() { - Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/create2contractn.sol"; - String contractName = "Factory"; - HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); - Account info; - - AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, - blockingStubFull); - info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); - logger.info("beforeBalance:" + beforeBalance); - logger.info("beforeEnergyUsed:" + beforeEnergyUsed); - logger.info("beforeNetUsed:" + beforeNetUsed); - logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - - byte[] bytes = ByteArray.fromHexString("418EA294A47A944C75787DDB7270D73472AEE87FC0"); - String param2 = "\"" + Base58.encode58Check(bytes) + "\""; - if (PublicMethed.queryAccount(bytes, blockingStubFull).getTypeValue() == 2) { - String txidn = PublicMethed - .triggerContract(bytes, - "testSuicideNonexistentTarget(address)", param2, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - } - Assert.assertTrue(PublicMethed - .sendcoin(bytes, 1000000L, contractExcAddress, contractExcKey, blockingStubFull)); - String contractName1 = "TestConstract"; - HashMap retMap1 = PublicMethed.getBycodeAbi(filePath, contractName1); - String code1 = retMap1.get("byteCode").toString(); - String abi1 = retMap1.get("abI").toString(); - String txid = ""; - String num = "\"" + code1 + "\"" + "," + 1; - txid = PublicMethed - .triggerContract(contractAddress, - "deploy(bytes,uint256)", num, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - - PublicMethed.waitProduceNextBlock(blockingStubFull); - Optional infoById = null; - infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); - long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); - - logger.info("fee:" + fee); - logger.info("netUsed:" + netUsed); - logger.info("energyUsed:" + energyUsed); - logger.info("netFee:" + netFee); - logger.info("energyUsageTotal:" + energyUsageTotal); - - Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); - logger.info("afterBalance:" + afterBalance); - logger.info("afterEnergyUsed:" + afterEnergyUsed); - logger.info("afterNetUsed:" + afterNetUsed); - logger.info("afterFreeNetUsed:" + afterFreeNetUsed); - - Assert.assertTrue(infoById.get().getResultValue() == 0); - - byte[] returnAddressBytes = infoById.get().getInternalTransactions(0).getTransferToAddress() - .toByteArray(); - String returnAddress = Base58.encode58Check(returnAddressBytes); - Assert.assertEquals(Base58.encode58Check(bytes), returnAddress); - logger.info("returnAddress:" + returnAddress); - txid = PublicMethed - .triggerContract(returnAddressBytes, - "i()", "#", false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); - Optional infoById1 = null; - infoById1 = PublicMethed.getTransactionInfoById(txid, blockingStubFull); - Long fee1 = infoById1.get().getFee(); - Long netUsed1 = infoById1.get().getReceipt().getNetUsage(); - Long energyUsed1 = infoById1.get().getReceipt().getEnergyUsage(); - Long netFee1 = infoById1.get().getReceipt().getNetFee(); - long energyUsageTotal1 = infoById1.get().getReceipt().getEnergyUsageTotal(); - - logger.info("fee1:" + fee1); - logger.info("netUsed1:" + netUsed1); - logger.info("energyUsed1:" + energyUsed1); - logger.info("netFee1:" + netFee1); - logger.info("energyUsageTotal1:" + energyUsageTotal1); - - Account infoafter1 = PublicMethed.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter1 = PublicMethed.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance1 = infoafter1.getBalance(); - Long afterEnergyUsed1 = resourceInfoafter1.getEnergyUsed(); - Long afterNetUsed1 = resourceInfoafter1.getNetUsed(); - Long afterFreeNetUsed1 = resourceInfoafter1.getFreeNetUsed(); - logger.info("afterBalance:" + afterBalance1); - logger.info("afterEnergyUsed:" + afterEnergyUsed1); - logger.info("afterNetUsed:" + afterNetUsed1); - logger.info("afterFreeNetUsed:" + afterFreeNetUsed1); - - Assert.assertTrue(infoById1.get().getResultValue() == 0); - Assert.assertTrue(afterBalance1 + fee1 == afterBalance); - Assert.assertTrue(afterEnergyUsed + energyUsed1 >= afterEnergyUsed1); - Long returnnumber = ByteArray.toLong(ByteArray - .fromHexString(ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); - Assert.assertTrue(1 == returnnumber); - Account account = PublicMethed.queryAccount(returnAddressBytes, blockingStubFull); - int typeValue = account.getTypeValue(); - Assert.assertEquals(2, typeValue); - Assert.assertEquals(account.getBalance(), 1000000); - } - - - /** - * constructor. - */ - @AfterClass - public void shutdown() throws InterruptedException { - if (channelFull != null) { - channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } - if (channelFull1 != null) { - channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } - if (channelSolidity != null) { - channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } - } - - -} diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test023.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test023.java new file mode 100644 index 00000000000..aed91c3bf3d --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test023.java @@ -0,0 +1,290 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.create2; + +import com.google.protobuf.ByteString; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +import java.util.List; +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.WalletClient; +import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.PublicMethed; + +@Slf4j +public class Create2Test023 { + + private final String testKey002 = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + 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(1); + private long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + + private byte[] factoryContractAddress = null; + private byte[] testContractAddress = null; + + private ECKey ecKey1 = new ECKey(Utils.getRandom()); + private byte[] dev001Address = ecKey1.getAddress(); + private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + private ECKey ecKey2 = new ECKey(Utils.getRandom()); + private byte[] user001Address = ecKey2.getAddress(); + private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + @BeforeClass(enabled = true) + public void beforeClass() { + + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + + PublicMethed.printAddress(dev001Key); + PublicMethed.printAddress(user001Key); + } + + + public byte[] subByte(byte[] b, int off, int length) { + byte[] b1 = new byte[length]; + System.arraycopy(b, off, b1, 0, length); + return b1; + + } + + @Test(enabled = true, description = "Deploy factory contract") + public void test01DeployFactoryContract() { + Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 10000_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 10000_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, + 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + //before deploy, check account resource + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long energyLimit = accountResource.getEnergyLimit(); + long energyUsage = accountResource.getEnergyUsed(); + long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before energyLimit is " + Long.toString(energyLimit)); + logger.info("before energyUsage is " + Long.toString(energyUsage)); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + String filePath = "./src/test/resources/soliditycode/Create2Test023.sol"; + String contractName = "factory"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + final String transferTokenTxid = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", + maxFeeLimit, 0L, 0, 10000, + "0", 0, null, dev001Key, + dev001Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + energyLimit = accountResource.getEnergyLimit(); + energyUsage = accountResource.getEnergyUsed(); + long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + + logger.info("after energyLimit is " + Long.toString(energyLimit)); + logger.info("after energyUsage is " + Long.toString(energyUsage)); + logger.info("after balanceAfter is " + Long.toString(balanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); + } + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + factoryContractAddress = infoById.get().getContractAddress().toByteArray(); + SmartContract smartContract = PublicMethed.getContract(factoryContractAddress, + blockingStubFull); + Assert.assertNotNull(smartContract.getAbi()); + } + + @Test(enabled = true, description = "contract A new B contract,A suicide,contract B still exist") + public void test02TriggerTestContract() { + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String triggerTxid = PublicMethed.triggerContract(factoryContractAddress, + "testCreate()", "#", false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + + byte[] a = infoById.get().getContractResult(0).toByteArray(); + byte[] b = subByte(a, 11, 1); + byte[] c = subByte(a, 0, 11); + byte[] e = "41".getBytes(); + byte[] d = subByte(a, 12, 20); + + logger.info("a:" + ByteArray.toHexString(a)); + + logger.info("b:" + ByteArray.toHexString(b)); + logger.info("c:" + ByteArray.toHexString(c)); + + logger.info("d:" + ByteArray.toHexString(d)); + + logger.info("41" + ByteArray.toHexString(d)); + String exceptedResult = "41" + ByteArray.toHexString(d); + String realResult = ByteArray.toHexString(b); + Assert.assertEquals(realResult, "00"); + Assert.assertNotEquals(realResult, "41"); + + + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(exceptedResult)); + logger.info("B Address : " + addressFinal); + + //B Address is created by A, Trigger contract B + triggerTxid = PublicMethed.triggerContract(ByteArray.fromHexString(exceptedResult), + "test()", "#", false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + Assert.assertEquals(infoById.get().getResultValue(),0); + Assert.assertEquals(ByteArray.toLong(infoById.get().getContractResult(0).toByteArray()),1); + Assert.assertEquals("SUCESS",infoById.get().getResult().toString()); + + + triggerTxid = PublicMethed.triggerContract(factoryContractAddress, + "kill()", "#", false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + String note = ByteArray + .toStr(infoById.get().getInternalTransactions(0).getNote().toByteArray()); + + Assert.assertEquals(infoById.get().getResultValue(),0); + Assert.assertEquals("SUCESS",infoById.get().getResult().toString()); + Assert.assertEquals("suicide", note); + + + + triggerTxid = PublicMethed.triggerContract(ByteArray.fromHexString(exceptedResult), + "test()", "#", false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + Assert.assertEquals(infoById.get().getResultValue(),0); + Assert.assertEquals("SUCESS",infoById.get().getResult().toString()); + Assert.assertEquals(1,ByteArray.toInt(infoById.get().getContractResult(0).toByteArray())); + + } + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } +} + + diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test020.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test024.java similarity index 87% rename from src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test020.java rename to src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test024.java index 6c8bcdf426c..c127bc37715 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test020.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test024.java @@ -30,7 +30,7 @@ import stest.tron.wallet.common.client.utils.PublicMethed; @Slf4j -public class Create2Test020 { +public class Create2Test024 { private final String testKey002 = Configuration.getByPath("testng.conf") .getString("foundationAccount.key2"); @@ -89,13 +89,13 @@ public void test01DeployFactoryContract() { testKey002, blockingStubFull)); Assert.assertTrue(PublicMethed.sendcoin(user001Address, 10000_000_000L, fromAddress, testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, - PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + //Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + // PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, + // blockingStubFull), 0, 1, + // ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, - 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + //Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, + // 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); PublicMethed.waitProduceNextBlock(blockingStubFull); @@ -109,7 +109,7 @@ public void test01DeployFactoryContract() { logger.info("before energyUsage is " + Long.toString(energyUsage)); logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - String filePath = "./src/test/resources/soliditycode/suicide002.sol"; + String filePath = "./src/test/resources/soliditycode/Create2Test024.sol"; String contractName = "Factory"; HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); @@ -149,12 +149,12 @@ public void test01DeployFactoryContract() { Assert.assertNotNull(smartContract.getAbi()); } - @Test(enabled = true, description = "function create2 ") + @Test(enabled = true, description = "create2 not allowed create2 twice in function") public void test02TriggerTestContract() { - Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, - PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + //Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + // PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + // blockingStubFull), 0, 1, + // ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); @@ -178,12 +178,12 @@ public void test02TriggerTestContract() { Long callValue = Long.valueOf(0); - String filePath = "./src/test/resources/soliditycode/suicide002.sol"; + String filePath = "./src/test/resources/soliditycode/Create2Test024.sol"; String contractName = "TestConstract"; HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); String testContractCode = retMap.get("byteCode").toString(); - Long salt = 1L; + Long salt = 4L; String param = "\"" + testContractCode + "\"," + salt; @@ -236,7 +236,7 @@ public void test02TriggerTestContract() { String addressFinal = Base58.encode58Check(ByteArray.fromHexString(exceptedResult)); - logger.info("B Address : " + addressFinal); + logger.info("create2 Address : " + addressFinal); Assert.assertEquals(infoById.get().getResult().toString(),"SUCESS"); Assert.assertEquals(infoById.get().getResultValue(),0); @@ -250,28 +250,6 @@ public void test02TriggerTestContract() { infoById = PublicMethed .getTransactionInfoById(triggerTxid, blockingStubFull); - a = infoById.get().getContractResult(0).toByteArray(); - b = subByte(a, 11, 1); - c = subByte(a, 0, 11); - e = "41".getBytes(); - d = subByte(a, 12, 20); - - logger.info("a:" + ByteArray.toHexString(a)); - - logger.info("b:" + ByteArray.toHexString(b)); - logger.info("c:" + ByteArray.toHexString(c)); - - logger.info("d:" + ByteArray.toHexString(d)); - - logger.info("41" + ByteArray.toHexString(d)); - exceptedResult = "41" + ByteArray.toHexString(d); - realResult = ByteArray.toHexString(b); - Assert.assertEquals(realResult, "00"); - Assert.assertNotEquals(realResult, "41"); - - - addressFinal = Base58.encode58Check(ByteArray.fromHexString(exceptedResult)); - logger.info("B Address : " + addressFinal); accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); devEnergyLimitAfter = accountResource.getEnergyLimit(); devEnergyUsageAfter = accountResource.getEnergyUsed(); diff --git a/src/test/resources/soliditycode/Create2Test023.sol b/src/test/resources/soliditycode/Create2Test023.sol new file mode 100644 index 00000000000..4c3f8af9f2b --- /dev/null +++ b/src/test/resources/soliditycode/Create2Test023.sol @@ -0,0 +1,31 @@ +contract factory { + constructor() payable public { + } + + function deploy(bytes memory code, uint256 salt) public returns(address){ + Caller addr; + assembly { + addr := create2(0, add(code, 0x20), mload(code), salt) + if iszero(extcodesize(addr)) { + revert(0, 0) + } + } + return address(addr); + } + + function testCreate() payable public returns (address){ + Caller add = (new Caller).value(0)(); + return address(add); + } + + function kill( ) payable public{ + selfdestruct(msg.sender); + } +} + + + +contract Caller { + constructor() payable public {} + function test() payable public returns (uint256){return 1;} +} \ No newline at end of file diff --git a/src/test/resources/soliditycode/Create2Test024.sol b/src/test/resources/soliditycode/Create2Test024.sol new file mode 100644 index 00000000000..f5a9d032cff --- /dev/null +++ b/src/test/resources/soliditycode/Create2Test024.sol @@ -0,0 +1,56 @@ +contract Factory { + event Deployed(address addr, uint256 salt, address sender); + function deploy(bytes memory code, uint256 salt) public returns(address){ + TestConstract addr; + TestConstract addr1; + assembly { + addr := create2(0, add(code, 0x20), mload(code), salt) + if iszero(extcodesize(addr)) { + revert(0, 0) + } + } + + addr.testSuicideNonexistentTarget(msg.sender); + addr.set(); + emit Deployed(address(addr), salt, msg.sender); + return address(addr); + } + + function deploy2(bytes memory code, uint256 salt) public returns(address){ + TestConstract addr; + TestConstract addr1; + assembly { + addr := create2(0, add(code, 0x20), mload(code), salt) + if iszero(extcodesize(addr)) { + revert(0, 0) + } + } + + //addr.testSuicideNonexistentTarget(msg.sender); + //addr.set(); + + assembly { + addr1 := create2(0, add(code, 0x20), mload(code), salt) + if iszero(extcodesize(addr)) { + revert(0, 0) + } + } + emit Deployed(address(addr), salt, msg.sender); + return address(addr); + } +} + + + +contract TestConstract { + uint public i=1; + constructor () public { + } + + function set() public{ + i=9; + } + function testSuicideNonexistentTarget(address payable nonexistentTarget) payable public { + selfdestruct(nonexistentTarget); + } +} \ No newline at end of file From 63dff987b0d605f7b62a1d817b09b6cfffdc87b6 Mon Sep 17 00:00:00 2001 From: xiechang33 <354035097@qq.com> Date: Fri, 31 May 2019 15:02:02 +0800 Subject: [PATCH 30/90] improve dailybuild stability --- .../tvmnewcommand/create2/Create2Test019.java | 286 +++++++++ .../tvmnewcommand/create2/Create2Test020.java | 582 ++++++++++++++++++ .../transferfailed/TestResourceReceiver.java | 4 +- .../soliditycode/create2contract22.sol | 75 +++ .../soliditycode/create2contractn2.sol | 26 + 5 files changed, 971 insertions(+), 2 deletions(-) create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test019.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test020.java create mode 100644 src/test/resources/soliditycode/create2contract22.sol create mode 100644 src/test/resources/soliditycode/create2contractn2.sol diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test019.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test019.java new file mode 100644 index 00000000000..8c158d9d5aa --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test019.java @@ -0,0 +1,286 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.create2; + +import static org.hamcrest.core.StringContains.containsString; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +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.GrpcAPI.TransactionExtention; +import org.tron.api.WalletGrpc; +import org.tron.api.WalletSolidityGrpc; +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.Base58; +import stest.tron.wallet.common.client.utils.PublicMethed; + +@Slf4j +public class Create2Test019 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + @Test(enabled = true, description = "triggerContract a constant function created by create2") + public void testTriggerContract() { + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/create2contractn2.sol"; + String contractName = "Factory"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + + String contractName1 = "TestConstract"; + HashMap retMap1 = PublicMethed.getBycodeAbi(filePath, contractName1); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + String txid = ""; + String num = "\"" + code1 + "\"" + "," + 1; + txid = PublicMethed + .triggerContract(contractAddress, + "deploy(bytes,uint256)", num, false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + byte[] returnAddressBytes = infoById.get().getInternalTransactions(0).getTransferToAddress() + .toByteArray(); + String returnAddress = Base58.encode58Check(returnAddressBytes); + logger.info("returnAddress:" + returnAddress); + txid = PublicMethed + .triggerContract(returnAddressBytes, + "i()", "#", false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById1 = null; + infoById1 = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee1 = infoById1.get().getFee(); + Long netUsed1 = infoById1.get().getReceipt().getNetUsage(); + Long energyUsed1 = infoById1.get().getReceipt().getEnergyUsage(); + Long netFee1 = infoById1.get().getReceipt().getNetFee(); + long energyUsageTotal1 = infoById1.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee1:" + fee1); + logger.info("netUsed1:" + netUsed1); + logger.info("energyUsed1:" + energyUsed1); + logger.info("netFee1:" + netFee1); + logger.info("energyUsageTotal1:" + energyUsageTotal1); + + Account infoafter1 = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter1 = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance1 = infoafter1.getBalance(); + Long afterEnergyUsed1 = resourceInfoafter1.getEnergyUsed(); + Long afterNetUsed1 = resourceInfoafter1.getNetUsed(); + Long afterFreeNetUsed1 = resourceInfoafter1.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance1); + logger.info("afterEnergyUsed:" + afterEnergyUsed1); + logger.info("afterNetUsed:" + afterNetUsed1); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed1); + + Assert.assertTrue(infoById1.get().getResultValue() == 0); + Assert.assertTrue(afterBalance1 + fee1 == afterBalance); + Assert.assertTrue(afterEnergyUsed + energyUsed1 >= afterEnergyUsed1); + Long returnnumber = ByteArray.toLong(ByteArray + .fromHexString(ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); + Assert.assertTrue(1 == returnnumber); + txid = PublicMethed + .triggerContract(returnAddressBytes, + "set()", "#", false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + txid = PublicMethed + .triggerContract(returnAddressBytes, + "i()", "#", false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + infoById1 = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + returnnumber = ByteArray.toLong(ByteArray + .fromHexString(ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); + Assert.assertTrue(5 == returnnumber); + + String param1 = "\"" + Base58.encode58Check(returnAddressBytes) + "\""; + + txid = PublicMethed + .triggerContract(returnAddressBytes, + "testSuicideNonexistentTarget(address)", param1, false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + Optional infoById2 = PublicMethed + .getTransactionInfoById(txid, blockingStubFull); + + Assert.assertEquals("suicide", ByteArray + .toStr(infoById2.get().getInternalTransactions(0).getNote().toByteArray())); + TransactionExtention transactionExtention = PublicMethed + .triggerContractForExtention(returnAddressBytes, + "i()", "#", false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + + Assert + .assertThat(transactionExtention.getResult().getCode().toString(), + containsString("CONTRACT_VALIDATE_ERROR")); + Assert + .assertThat(transactionExtention.getResult().getMessage().toStringUtf8() + , containsString("contract validate error : No contract or not a smart contract")); + + txid = PublicMethed + .triggerContract(contractAddress, + "deploy(bytes,uint256)", num, false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + Optional infoById3 = PublicMethed + .getTransactionInfoById(txid, blockingStubFull); + byte[] returnAddressBytes1 = infoById3.get().getInternalTransactions(0).getTransferToAddress() + .toByteArray(); + String returnAddress1 = Base58.encode58Check(returnAddressBytes1); + Assert.assertEquals(returnAddress1, returnAddress); + txid = PublicMethed + .triggerContract(returnAddressBytes1, + "i()", "#", false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + + infoById1 = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + returnnumber = ByteArray.toLong(ByteArray + .fromHexString(ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); + Assert.assertTrue(1 == returnnumber); + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test020.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test020.java new file mode 100644 index 00000000000..96e0e6f4eb8 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test020.java @@ -0,0 +1,582 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.create2; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +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.api.WalletSolidityGrpc; +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.Base58; +import stest.tron.wallet.common.client.utils.PublicMethed; + +@Slf4j +public class Create2Test020 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + @Test(enabled = true, description = "triggerContract a constant function created by create2") + public void testTriggerContract() { + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/create2contract22.sol"; + String contractName = "Factory"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + + String contractName1 = "TestConstract"; + HashMap retMap1 = PublicMethed.getBycodeAbi(filePath, contractName1); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + String txid = ""; + String num = "\"" + code1 + "\"" + "," + 1000001; + txid = PublicMethed + .triggerContract(contractAddress, + "deploy(bytes,trcToken)", num, false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + byte[] returnAddressBytes = infoById.get().getInternalTransactions(0).getTransferToAddress() + .toByteArray(); + String returnAddress = Base58.encode58Check(returnAddressBytes); + logger.info("returnAddress:" + returnAddress); + txid = PublicMethed + .triggerContract(returnAddressBytes, + "i()", "#", false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById1 = null; + infoById1 = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee1 = infoById1.get().getFee(); + Long netUsed1 = infoById1.get().getReceipt().getNetUsage(); + Long energyUsed1 = infoById1.get().getReceipt().getEnergyUsage(); + Long netFee1 = infoById1.get().getReceipt().getNetFee(); + long energyUsageTotal1 = infoById1.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee1:" + fee1); + logger.info("netUsed1:" + netUsed1); + logger.info("energyUsed1:" + energyUsed1); + logger.info("netFee1:" + netFee1); + logger.info("energyUsageTotal1:" + energyUsageTotal1); + + Account infoafter1 = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter1 = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance1 = infoafter1.getBalance(); + Long afterEnergyUsed1 = resourceInfoafter1.getEnergyUsed(); + Long afterNetUsed1 = resourceInfoafter1.getNetUsed(); + Long afterFreeNetUsed1 = resourceInfoafter1.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance1); + logger.info("afterEnergyUsed:" + afterEnergyUsed1); + logger.info("afterNetUsed:" + afterNetUsed1); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed1); + + Assert.assertTrue(infoById1.get().getResultValue() == 0); + Assert.assertTrue(afterBalance1 + fee1 == afterBalance); + Assert.assertTrue(afterEnergyUsed + energyUsed1 >= afterEnergyUsed1); + Long returnnumber = ByteArray.toLong(ByteArray + .fromHexString(ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); + Assert.assertTrue(1 == returnnumber); + + } + + + @Test(enabled = true, description = "triggerContract a constant function created by create2") + public void testTriggerContract1() { + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/create2contract22.sol"; + String contractName = "Factory1"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + + String contractName1 = "TestConstract"; + HashMap retMap1 = PublicMethed.getBycodeAbi(filePath, contractName1); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + String txid = ""; + String num = "\"" + code1 + "\"" + "," + 1000001; + txid = PublicMethed + .triggerContract(contractAddress, + "deploy(bytes,uint8)", num, false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + byte[] returnAddressBytes = infoById.get().getInternalTransactions(0).getTransferToAddress() + .toByteArray(); + String returnAddress = Base58.encode58Check(returnAddressBytes); + logger.info("returnAddress:" + returnAddress); + txid = PublicMethed + .triggerContract(returnAddressBytes, + "i()", "#", false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById1 = null; + infoById1 = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee1 = infoById1.get().getFee(); + Long netUsed1 = infoById1.get().getReceipt().getNetUsage(); + Long energyUsed1 = infoById1.get().getReceipt().getEnergyUsage(); + Long netFee1 = infoById1.get().getReceipt().getNetFee(); + long energyUsageTotal1 = infoById1.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee1:" + fee1); + logger.info("netUsed1:" + netUsed1); + logger.info("energyUsed1:" + energyUsed1); + logger.info("netFee1:" + netFee1); + logger.info("energyUsageTotal1:" + energyUsageTotal1); + + Account infoafter1 = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter1 = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance1 = infoafter1.getBalance(); + Long afterEnergyUsed1 = resourceInfoafter1.getEnergyUsed(); + Long afterNetUsed1 = resourceInfoafter1.getNetUsed(); + Long afterFreeNetUsed1 = resourceInfoafter1.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance1); + logger.info("afterEnergyUsed:" + afterEnergyUsed1); + logger.info("afterNetUsed:" + afterNetUsed1); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed1); + + Assert.assertTrue(infoById1.get().getResultValue() == 0); + Assert.assertTrue(afterBalance1 + fee1 == afterBalance); + Assert.assertTrue(afterEnergyUsed + energyUsed1 >= afterEnergyUsed1); + Long returnnumber = ByteArray.toLong(ByteArray + .fromHexString(ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); + Assert.assertTrue(1 == returnnumber); + + + } + + + @Test(enabled = true, description = "triggerContract a constant function created by create2") + public void testTriggerContract2() { + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/create2contract22.sol"; + String contractName = "Factory2"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + + String contractName1 = "TestConstract"; + HashMap retMap1 = PublicMethed.getBycodeAbi(filePath, contractName1); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + String txid = ""; + String num = "\"" + code1 + "\"" + ",\"" + Base58.encode58Check(contractExcAddress) + "\""; + txid = PublicMethed + .triggerContract(contractAddress, + "deploy(bytes,address)", num, false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + byte[] returnAddressBytes = infoById.get().getInternalTransactions(0).getTransferToAddress() + .toByteArray(); + String returnAddress = Base58.encode58Check(returnAddressBytes); + logger.info("returnAddress:" + returnAddress); + txid = PublicMethed + .triggerContract(returnAddressBytes, + "i()", "#", false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById1 = null; + infoById1 = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee1 = infoById1.get().getFee(); + Long netUsed1 = infoById1.get().getReceipt().getNetUsage(); + Long energyUsed1 = infoById1.get().getReceipt().getEnergyUsage(); + Long netFee1 = infoById1.get().getReceipt().getNetFee(); + long energyUsageTotal1 = infoById1.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee1:" + fee1); + logger.info("netUsed1:" + netUsed1); + logger.info("energyUsed1:" + energyUsed1); + logger.info("netFee1:" + netFee1); + logger.info("energyUsageTotal1:" + energyUsageTotal1); + + Account infoafter1 = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter1 = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance1 = infoafter1.getBalance(); + Long afterEnergyUsed1 = resourceInfoafter1.getEnergyUsed(); + Long afterNetUsed1 = resourceInfoafter1.getNetUsed(); + Long afterFreeNetUsed1 = resourceInfoafter1.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance1); + logger.info("afterEnergyUsed:" + afterEnergyUsed1); + logger.info("afterNetUsed:" + afterNetUsed1); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed1); + + Assert.assertTrue(infoById1.get().getResultValue() == 0); + Assert.assertTrue(afterBalance1 + fee1 == afterBalance); + Assert.assertTrue(afterEnergyUsed + energyUsed1 >= afterEnergyUsed1); + Long returnnumber = ByteArray.toLong(ByteArray + .fromHexString(ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); + Assert.assertTrue(1 == returnnumber); + + + } + + + @Test(enabled = true, description = "triggerContract a constant function created by create2") + public void testTriggerContract3() { + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/create2contract22.sol"; + String contractName = "Factory3"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + + String contractName1 = "TestConstract"; + HashMap retMap1 = PublicMethed.getBycodeAbi(filePath, contractName1); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + String txid = ""; + String num = "\"" + code1 + "\"" + ",\"" + Base58.encode58Check(contractExcAddress) + "\""; + txid = PublicMethed + .triggerContract(contractAddress, + "deploy(bytes,string)", num, false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + byte[] returnAddressBytes = infoById.get().getInternalTransactions(0).getTransferToAddress() + .toByteArray(); + String returnAddress = Base58.encode58Check(returnAddressBytes); + logger.info("returnAddress:" + returnAddress); + txid = PublicMethed + .triggerContract(returnAddressBytes, + "i()", "#", false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById1 = null; + infoById1 = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee1 = infoById1.get().getFee(); + Long netUsed1 = infoById1.get().getReceipt().getNetUsage(); + Long energyUsed1 = infoById1.get().getReceipt().getEnergyUsage(); + Long netFee1 = infoById1.get().getReceipt().getNetFee(); + long energyUsageTotal1 = infoById1.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee1:" + fee1); + logger.info("netUsed1:" + netUsed1); + logger.info("energyUsed1:" + energyUsed1); + logger.info("netFee1:" + netFee1); + logger.info("energyUsageTotal1:" + energyUsageTotal1); + + Account infoafter1 = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter1 = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance1 = infoafter1.getBalance(); + Long afterEnergyUsed1 = resourceInfoafter1.getEnergyUsed(); + Long afterNetUsed1 = resourceInfoafter1.getNetUsed(); + Long afterFreeNetUsed1 = resourceInfoafter1.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance1); + logger.info("afterEnergyUsed:" + afterEnergyUsed1); + logger.info("afterNetUsed:" + afterNetUsed1); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed1); + + Assert.assertTrue(infoById1.get().getResultValue() == 0); + Assert.assertTrue(afterBalance1 + fee1 == afterBalance); + Assert.assertTrue(afterEnergyUsed + energyUsed1 >= afterEnergyUsed1); + Long returnnumber = ByteArray.toLong(ByteArray + .fromHexString(ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); + Assert.assertTrue(1 == returnnumber); + + + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TestResourceReceiver.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TestResourceReceiver.java index f3e110916aa..697e8b22c02 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TestResourceReceiver.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TestResourceReceiver.java @@ -70,7 +70,7 @@ public void beforeSuite() { * constructor. */ - @BeforeClass(enabled = true) + @BeforeClass(enabled = false) public void beforeClass() { PublicMethed.printAddress(contractExcKey); channelFull = ManagedChannelBuilder.forTarget(fullnode) @@ -89,7 +89,7 @@ public void beforeClass() { } - @Test(enabled = true, description = "Suicide existent Target") + @Test(enabled = false, description = "Suicide existent Target") public void test1SuicideExistentTarget() { Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, diff --git a/src/test/resources/soliditycode/create2contract22.sol b/src/test/resources/soliditycode/create2contract22.sol new file mode 100644 index 00000000000..c94ed896765 --- /dev/null +++ b/src/test/resources/soliditycode/create2contract22.sol @@ -0,0 +1,75 @@ +contract Factory { + event Deployed(address addr, trcToken salt, address sender); + function deploy(bytes memory code, trcToken salt) public returns(address){ + address addr; + assembly { + addr := create2(0, add(code, 0x20), mload(code), salt) + if iszero(extcodesize(addr)) { + revert(0, 0) + } + } + emit Deployed(addr, salt, msg.sender); + return addr; + } +} + + +contract Factory1 { + event Deployed(address addr, uint8 salt, address sender); + function deploy(bytes memory code, uint8 salt) public returns(address){ + address addr; + assembly { + addr := create2(0, add(code, 0x20), mload(code), salt) + if iszero(extcodesize(addr)) { + revert(0, 0) + } + } + emit Deployed(addr, salt, msg.sender); + return addr; + } +} + +contract Factory2 { + event Deployed(address addr, address salt, address sender); + function deploy(bytes memory code, address salt) public returns(address){ + address addr; + assembly { + addr := create2(0, add(code, 0x20), mload(code), salt) + if iszero(extcodesize(addr)) { + revert(0, 0) + } + } + emit Deployed(addr, salt, msg.sender); + return addr; + } +} + + +contract Factory3 { + event Deployed(address addr, string salt, address sender); + function deploy(bytes memory code, string memory salt) public returns(address){ + address addr; + assembly { + addr := create2(0, add(code, 0x20), mload(code), salt) + if iszero(extcodesize(addr)) { + revert(0, 0) + } + } + emit Deployed(addr, salt, msg.sender); + return addr; + } +} + + +contract TestConstract { + uint public i=1; + function testTransfer(uint256 i) payable public{ + msg.sender.transfer(i); + } + function testTransferToken(uint256 i,trcToken tokenId) payable public{ + msg.sender.transferToken(i, tokenId); + } + function testSuicideNonexistentTarget(address payable nonexistentTarget) payable public { + selfdestruct(nonexistentTarget); + } +} diff --git a/src/test/resources/soliditycode/create2contractn2.sol b/src/test/resources/soliditycode/create2contractn2.sol new file mode 100644 index 00000000000..626988c4e04 --- /dev/null +++ b/src/test/resources/soliditycode/create2contractn2.sol @@ -0,0 +1,26 @@ +contract Factory { + event Deployed(address addr, uint256 salt, address sender); + function deploy(bytes memory code, uint256 salt) public returns(address){ + address addr; + assembly { + addr := create2(0, add(code, 0x20), mload(code), salt) + if iszero(extcodesize(addr)) { + revert(0, 0) + } + } + emit Deployed(addr, salt, msg.sender); + return addr; + } +} + + + +contract TestConstract { + uint public i=1; + function set() payable public { + i=5; + } + function testSuicideNonexistentTarget(address payable nonexistentTarget) payable public { + selfdestruct(nonexistentTarget); + } +} \ No newline at end of file From a746780b4190770ca4bda9667be5da6fac805c7e Mon Sep 17 00:00:00 2001 From: wubin01 Date: Mon, 3 Jun 2019 11:33:36 +0800 Subject: [PATCH 31/90] modify blockUpdateTimeout to 30s --- .../org/tron/common/overlay/server/MessageQueue.java | 2 +- .../java/org/tron/core/net/peer/PeerConnection.java | 12 ++++++------ .../java/org/tron/core/net/peer/PeerStatusCheck.java | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/tron/common/overlay/server/MessageQueue.java b/src/main/java/org/tron/common/overlay/server/MessageQueue.java index 478308fb273..5da9bc172b4 100644 --- a/src/main/java/org/tron/common/overlay/server/MessageQueue.java +++ b/src/main/java/org/tron/common/overlay/server/MessageQueue.java @@ -86,7 +86,7 @@ public void activate(ChannelHandlerContext ctx) { sendMsgThread.setName("sendMsgThread-" + ctx.channel().remoteAddress()); sendMsgThread.start(); } - + public void setChannel(Channel channel) { this.channel = channel; } diff --git a/src/main/java/org/tron/core/net/peer/PeerConnection.java b/src/main/java/org/tron/core/net/peer/PeerConnection.java index fed6b0b1131..0bf553d9c04 100644 --- a/src/main/java/org/tron/core/net/peer/PeerConnection.java +++ b/src/main/java/org/tron/core/net/peer/PeerConnection.java @@ -43,8 +43,6 @@ public class PeerConnection extends Channel { @Autowired private AdvService advService; - private int invCacheSize = 100_000; - @Setter @Getter private BlockId signUpErrorBlockId; @@ -53,6 +51,8 @@ public class PeerConnection extends Channel { @Getter private HelloMessage helloMessage; + private int invCacheSize = 100_000; + @Setter @Getter private Cache advInvReceive = CacheBuilder.newBuilder().maximumSize(invCacheSize) @@ -76,7 +76,7 @@ public void setBlockBothHave(BlockId blockId) { } @Getter - private long blockBothHaveUpdateTime = System.currentTimeMillis(); + private volatile long blockBothHaveUpdateTime = System.currentTimeMillis(); @Setter @Getter @@ -84,7 +84,7 @@ public void setBlockBothHave(BlockId blockId) { @Setter @Getter - private long remainNum; + private volatile long remainNum; @Getter private Cache syncBlockIdCache = CacheBuilder.newBuilder() @@ -108,11 +108,11 @@ public void setBlockBothHave(BlockId blockId) { @Setter @Getter - private boolean needSyncFromPeer; + private volatile boolean needSyncFromPeer; @Setter @Getter - private boolean needSyncFromUs; + private volatile boolean needSyncFromUs; public boolean isIdle() { return advInvRequest.isEmpty() && syncBlockRequested.isEmpty() && syncChainRequested == null; diff --git a/src/main/java/org/tron/core/net/peer/PeerStatusCheck.java b/src/main/java/org/tron/core/net/peer/PeerStatusCheck.java index a07f6c39e94..c7cd04565ff 100644 --- a/src/main/java/org/tron/core/net/peer/PeerStatusCheck.java +++ b/src/main/java/org/tron/core/net/peer/PeerStatusCheck.java @@ -20,7 +20,7 @@ public class PeerStatusCheck { private ScheduledExecutorService peerStatusCheckExecutor = Executors .newSingleThreadScheduledExecutor(); - private int blockUpdateTimeout = 20_000; + private int blockUpdateTimeout = 30_000; public void init() { peerStatusCheckExecutor.scheduleWithFixedDelay(() -> { From fdc85c821b11a33deaf218dfc06fd06371767f41 Mon Sep 17 00:00:00 2001 From: wangming Date: Mon, 3 Jun 2019 15:26:37 +0800 Subject: [PATCH 32/90] add test case --- .../tvmnewcommand/create2/Create2Test002.java | 6 +- .../tvmnewcommand/create2/Create2Test019.java | 3 +- .../tvmnewcommand/create2/Create2Test025.java | 278 ++++++++++ .../extCodeHash/ExtCodeHashTest005.java | 18 + .../extCodeHash/ExtCodeHashTest007.java | 3 +- .../extCodeHash/ExtCodeHashTest009.java | 512 ++++++++++++++++++ .../extCodeHash/ExtCodeHashTest010.java | 392 ++++++++++++++ .../resources/soliditycode/Create2Test025.sol | 27 + .../soliditycode/ExtCodeHashTest010.sol | 46 ++ .../soliditycode/create2CallContract.sol | 4 +- .../TransferFailed005.sol | 106 ++++ .../TransferFailed007.sol | 90 +++ 12 files changed, 1478 insertions(+), 7 deletions(-) create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test025.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest009.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest010.java create mode 100644 src/test/resources/soliditycode/Create2Test025.sol create mode 100644 src/test/resources/soliditycode/ExtCodeHashTest010.sol create mode 100644 src/test/resources/soliditycode_v0.4.25/TransferFailed005.sol create mode 100644 src/test/resources/soliditycode_v0.4.25/TransferFailed007.sol diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test002.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test002.java index 86af6004a14..1deb99458a5 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test002.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test002.java @@ -73,7 +73,7 @@ public void beforeClass() { PublicMethed.printAddress(user001Key); } - @Test(enabled = false, description = "Deploy factory contract") + @Test(enabled = true, description = "Deploy factory contract") public void test01DeployFactoryContract() { Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); @@ -140,7 +140,7 @@ public void test01DeployFactoryContract() { } - @Test(enabled = false, description = "Trigger create2 command without meta data hash in bytecode") + @Test(enabled = true, description = "Trigger create2 command without meta data hash in bytecode") public void test02TriggerCreate2ToDeployTestContract() { Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, @@ -256,7 +256,7 @@ public void test02TriggerCreate2ToDeployTestContract() { } - @Test(enabled = false, description = "Trigger Test contract") + @Test(enabled = true, description = "Trigger Test contract") public void test03TriggerTestContract() { Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test019.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test019.java index 8c158d9d5aa..86b6622c216 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test019.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test019.java @@ -90,7 +90,8 @@ public void beforeClass() { blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = true, description = "triggerContract a constant function created by create2") + @Test(enabled = true, description = "seted Value of Contract that created by create2," + + " should not be stored after contact suicided ande create2 again") public void testTriggerContract() { Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test025.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test025.java new file mode 100644 index 00000000000..53ed8df448f --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test025.java @@ -0,0 +1,278 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.create2; + +import static org.hamcrest.core.StringContains.containsString; + +import com.google.protobuf.ByteString; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +import java.util.List; +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.Transaction; +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.WalletClient; +import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.PublicMethed; +import zmq.socket.pubsub.Pub; + +@Slf4j +public class Create2Test025 { + + private final String testKey002 = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + 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(1); + private long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + + private byte[] factoryContractAddress = null; + private byte[] testContractAddress = null; + + private ECKey ecKey1 = new ECKey(Utils.getRandom()); + private byte[] dev001Address = ecKey1.getAddress(); + private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + private ECKey ecKey2 = new ECKey(Utils.getRandom()); + private byte[] user001Address = ecKey2.getAddress(); + private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + @BeforeClass(enabled = true) + public void beforeClass() { + + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + + PublicMethed.printAddress(dev001Key); + PublicMethed.printAddress(user001Key); + } + + + public byte[] subByte(byte[] b, int off, int length) { + byte[] b1 = new byte[length]; + System.arraycopy(b, off, b1, 0, length); + return b1; + + } + + @Test(enabled = true, description = "Deploy factory contract") + public void test01DeployFactoryContract() { + Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 10000_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 10000_000_000L, fromAddress, + testKey002, blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + //before deploy, check account resource + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long energyLimit = accountResource.getEnergyLimit(); + long energyUsage = accountResource.getEnergyUsed(); + long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before energyLimit is " + Long.toString(energyLimit)); + logger.info("before energyUsage is " + Long.toString(energyUsage)); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + String filePath = "./src/test/resources/soliditycode/Create2Test025.sol"; + String contractName = "Factory"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + code += "05"; + final String transferTokenTxid = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", + maxFeeLimit, 0L, 0, 10000, + "0", 0, null, dev001Key, + dev001Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + energyLimit = accountResource.getEnergyLimit(); + energyUsage = accountResource.getEnergyUsed(); + long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + + logger.info("after energyLimit is " + Long.toString(energyLimit)); + logger.info("after energyUsage is " + Long.toString(energyUsage)); + logger.info("after balanceAfter is " + Long.toString(balanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); + } + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + factoryContractAddress = infoById.get().getContractAddress().toByteArray(); + SmartContract smartContract = PublicMethed.getContract(factoryContractAddress, + blockingStubFull); + Assert.assertNotNull(smartContract.getAbi()); + } + + @Test(enabled = true, description = "create2 bytecode with parm") + public void test02TriggerTestContract() { + //Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + // PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + // blockingStubFull), 0, 1, + // ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + String filePath = "./src/test/resources/soliditycode/Create2Test025.sol"; + String contractName = "TestContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String testContractCode = retMap.get("byteCode").toString(); + testContractCode += "0000000000000000000000000000000000000000000000000000000000000005"; + Long salt = 4L; + + String param = "\"" + testContractCode + "\"," + salt; + + String triggerTxid = PublicMethed.triggerContract(factoryContractAddress, + "create2(bytes,uint256)", param, false, 0L, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + logger.info( + "the value: " + PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + + List retList = PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + + logger.info("actualSalt: " + actualSalt); + + byte[] tmpAddress = new byte[20]; + System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); + logger.info("address_hex: " + addressHex); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + logger.info("address_final: " + addressFinal); + + testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); + + + String Txid = PublicMethed.triggerContract(testContractAddress, + "getNum()", "#", false, 0L, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + Optional infoById2 = PublicMethed.getTransactionInfoById(Txid,blockingStubFull); + TransactionInfo transactionInfo2 = infoById2.get(); + int NUM = ByteArray.toInt(transactionInfo2.getContractResult(0).toByteArray()); + + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + userEnergyLimitAfter = accountResource.getEnergyLimit(); + userEnergyUsageAfter = accountResource.getEnergyUsed(); + userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + logger.info("NUM :" +NUM); + Assert.assertEquals(infoById.get().getResult().toString(),"SUCESS"); + Assert.assertEquals(infoById.get().getResultValue(),0); + Assert.assertEquals(5,NUM); + + + + } + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } +} + + diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest005.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest005.java index c1b992e28e6..4a1ae8ec7fe 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest005.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest005.java @@ -26,6 +26,7 @@ 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 @@ -78,6 +79,19 @@ public void beforeClass() { PublicMethed.printAddress(dev001Key); PublicMethed.printAddress(user001Key); + + String fakeAddress = ""; + + logger.info("realAddress: " + fakeAddress); + byte[] fullHexAddr = new DataWord(fakeAddress).getData(); + logger.info("fullHexAddr ++= "+ Hex.toHexString(fullHexAddr)); + + fakeAddress = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"; + + logger.info("realAddress: " + fakeAddress); + fullHexAddr = new DataWord(fakeAddress).getData(); + logger.info("fullHexAddr ++= "+Hex.toHexString(fullHexAddr)); + } @Test(enabled = true, description = "Deploy extcodehash contract") @@ -444,6 +458,8 @@ public void test05GetEmptyAddressCodeHash() { logger.info("realAddress: " + fakeAddress); byte[] fullHexAddr = new DataWord(fakeAddress).getData(); + logger.info("fullHexAddr ++= "+ Hex.toHexString(fullHexAddr)); + final String triggerTxid = PublicMethed.triggerContract(extCodeHashContractAddress, "getCodeHashByUint(uint256)", Hex.toHexString(fullHexAddr), true, callValue, @@ -533,6 +549,8 @@ public void test06GetFakeAddressCodeHash() { logger.info("realAddress: " + fakeAddress); byte[] fullHexAddr = new DataWord(fakeAddress).getData(); + logger.info("fullHexAddr ++= "+Hex.toHexString(fullHexAddr)); + final String triggerTxid = PublicMethed.triggerContract(extCodeHashContractAddress, "getCodeHashByUint(uint256)", Hex.toHexString(fullHexAddr), true, callValue, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest007.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest007.java index 763653ec49d..c294e24445f 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest007.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest007.java @@ -349,7 +349,7 @@ public void test04GetTestOldCodeHash() { "the value: " + retList); expectedCodeHashOld = retList.get(0); - + Assert.assertEquals("B4AB5B9FF1A4FF7793E60EBFF0C769443AF66D0A6F9455AF145432CE8BA78175",expectedCodeHashOld); Assert.assertFalse(retList.isEmpty()); } @@ -432,6 +432,7 @@ public void test05GetTestNewCodeHash() { Assert.assertNotEquals(retList.get(0), expectedCodeHashOld); expectedCodeHash = retList.get(0); + Assert.assertEquals("34DB53BD1F7214367E8D6B2A7A6FBBF0E3B7DDB4939ECADE4CDEF6749C27A2DA",expectedCodeHash); } @Test(enabled = true, description = "Deploy contract using new solidity again") diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest009.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest009.java new file mode 100644 index 00000000000..963ab54a07a --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest009.java @@ -0,0 +1,512 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.extCodeHash; + +import com.google.protobuf.ByteString; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +import java.util.List; +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.WalletClient; +import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.PublicMethed; + +@Slf4j +public class ExtCodeHashTest009 { + + private final String testKey002 = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + 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(1); + private long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + + private byte[] factoryContractAddress = null; + private byte[] extCodeHashContractAddress = null; + private byte[] testContractAddress = null; + + private String expectedCodeHash = null; + + private ECKey ecKey1 = new ECKey(Utils.getRandom()); + private byte[] dev001Address = ecKey1.getAddress(); + private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + private ECKey ecKey2 = new ECKey(Utils.getRandom()); + private byte[] user001Address = ecKey2.getAddress(); + private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + @BeforeClass(enabled = true) + public void beforeClass() { + + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + + PublicMethed.printAddress(dev001Key); + PublicMethed.printAddress(user001Key); + } + + @Test(enabled = true, description = "Deploy extcodehash contract") + public void test01DeployExtCodeHashContract() { + Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, + 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + //before deploy, check account resource + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long energyLimit = accountResource.getEnergyLimit(); + long energyUsage = accountResource.getEnergyUsed(); + long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before energyLimit is " + Long.toString(energyLimit)); + logger.info("before energyUsage is " + Long.toString(energyUsage)); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + String filePath = "./src/test/resources/soliditycode/extCodeHash.sol"; + String contractName = "TestExtCodeHash"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + final String transferTokenTxid = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", + maxFeeLimit, 0L, 0, 10000, + "0", 0, null, dev001Key, + dev001Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + energyLimit = accountResource.getEnergyLimit(); + energyUsage = accountResource.getEnergyUsed(); + long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + + logger.info("after energyLimit is " + Long.toString(energyLimit)); + logger.info("after energyUsage is " + Long.toString(energyUsage)); + logger.info("after balanceAfter is " + Long.toString(balanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); + } + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + extCodeHashContractAddress = infoById.get().getContractAddress().toByteArray(); + SmartContract smartContract = PublicMethed.getContract(extCodeHashContractAddress, + blockingStubFull); + } + + @Test(enabled = true, description = "Get code hash of create2 empty contract") + public void test02GetTestContractCodeHash() { + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String testContractCode = retMap.get("byteCode").toString(); + Long salt = 1L; + + String[] parameter = {Base58.encode58Check(user001Address), testContractCode, salt.toString()}; + logger.info(PublicMethed.create2(parameter)); + + Long callValue = Long.valueOf(0); + + String param = "\"" + PublicMethed.create2(parameter) + "\""; + final String triggerTxid = PublicMethed.triggerContract(extCodeHashContractAddress, + "getCodeHashByAddr(address)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + List retList = PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray()); + + logger.info("the value: " + retList); + + Assert.assertFalse(retList.isEmpty()); + Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000000", + retList.get(0)); + } + + @Test(enabled = true, description = "Deploy factory contract") + public void test03DeployFactoryContract() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, + 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + //before deploy, check account resource + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long energyLimit = accountResource.getEnergyLimit(); + long energyUsage = accountResource.getEnergyUsed(); + long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before energyLimit is " + Long.toString(energyLimit)); + logger.info("before energyUsage is " + Long.toString(energyUsage)); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "Factory"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + final String transferTokenTxid = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", + maxFeeLimit, 0L, 0, 10000, + "0", 0, null, dev001Key, + dev001Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + energyLimit = accountResource.getEnergyLimit(); + energyUsage = accountResource.getEnergyUsed(); + long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + + logger.info("after energyLimit is " + Long.toString(energyLimit)); + logger.info("after energyUsage is " + Long.toString(energyUsage)); + logger.info("after balanceAfter is " + Long.toString(balanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); + } + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + factoryContractAddress = infoById.get().getContractAddress().toByteArray(); + SmartContract smartContract = PublicMethed.getContract(factoryContractAddress, + blockingStubFull); + Assert.assertNotNull(smartContract.getAbi()); + } + + @Test(enabled = true, description = "Trigger create2 function to deploy test contract") + public void test04TriggerCreate2ToDeployTestContract() { + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String testContractCode = retMap.get("byteCode").toString(); + Long salt = 1L; + + String param = "\"" + testContractCode + "\"," + salt; + + final String triggerTxid = PublicMethed.triggerContract(factoryContractAddress, + "deploy(bytes,uint256)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + logger.info( + "the value: " + PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + + List retList = PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + + logger.info("actualSalt: " + actualSalt); + + byte[] tmpAddress = new byte[20]; + System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); + logger.info("address_hex: " + addressHex); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + logger.info("address_final: " + addressFinal); + + testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + SmartContract smartContract = PublicMethed.getContract(testContractAddress, blockingStubFull); + + // contract created by create2, doesn't have ABI + Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); + + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); + + // the contract address in transaction info, + // contract address of create2 contract is factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); + } + + @Test(enabled = true, description = "Get code hash of test contract") + public void test05GetTestContractCodeHash() { + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String param = "\"" + Base58.encode58Check(testContractAddress) + "\""; + final String triggerTxid = PublicMethed.triggerContract(extCodeHashContractAddress, + "getCodeHashByAddr(address)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + List retList = PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray()); + + logger.info("the value: " + retList); + + Assert.assertFalse(retList.isEmpty()); + Assert.assertNotEquals("C5D2460186F7233C927E7DB2DCC703C0E500B653CA82273B7BFAD8045D85A470", + retList.get(0)); + Assert.assertNotEquals("0000000000000000000000000000000000000000000000000000000000000000", + retList.get(0)); + + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + user001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + user001Address, blockingStubFull); + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } +} + + diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest010.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest010.java new file mode 100644 index 00000000000..6fc1acf4bbe --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest010.java @@ -0,0 +1,392 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.extCodeHash; + +import com.google.protobuf.ByteString; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +import java.util.List; +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.WalletClient; +import stest.tron.wallet.common.client.utils.Base58; +import stest.tron.wallet.common.client.utils.PublicMethed; + +@Slf4j +public class ExtCodeHashTest010 { + + private final String testKey002 = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + 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(1); + private long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + + private byte[] factoryContractAddress = null; + private byte[] extCodeHashContractAddress = null; + private byte[] testContractAddress = null; + + private String expectedCodeHash = null; + + private ECKey ecKey1 = new ECKey(Utils.getRandom()); + private byte[] dev001Address = ecKey1.getAddress(); + private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + private ECKey ecKey2 = new ECKey(Utils.getRandom()); + private byte[] user001Address = ecKey2.getAddress(); + private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + @BeforeClass(enabled = true) + public void beforeClass() { + + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + + PublicMethed.printAddress(dev001Key); + PublicMethed.printAddress(user001Key); + } + + @Test(enabled = true, description = "Deploy extcodehash contract") + public void test01DeployExtCodeHashContract() { + Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + /*Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, + 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull));*/ + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + //before deploy, check account resource + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long energyLimit = accountResource.getEnergyLimit(); + long energyUsage = accountResource.getEnergyUsed(); + long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before energyLimit is " + Long.toString(energyLimit)); + logger.info("before energyUsage is " + Long.toString(energyUsage)); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + String filePath = "./src/test/resources/soliditycode/ExtCodeHashTest010.sol"; + String contractName = "Counter"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + final String transferTokenTxid = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", + maxFeeLimit, 0L, 0, 10000, + "0", 0, null, dev001Key, + dev001Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + energyLimit = accountResource.getEnergyLimit(); + energyUsage = accountResource.getEnergyUsed(); + long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + + logger.info("after energyLimit is " + Long.toString(energyLimit)); + logger.info("after energyUsage is " + Long.toString(energyUsage)); + logger.info("after balanceAfter is " + Long.toString(balanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + + if (infoById.get().getResultValue() != 0) { + Assert.fail("deploy transaction failed with message: " + infoById.get().getResMessage()); + } + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + extCodeHashContractAddress = infoById.get().getContractAddress().toByteArray(); + SmartContract smartContract = PublicMethed.getContract(extCodeHashContractAddress, + blockingStubFull); + } + + + @Test(enabled = true, description = "The EXTCODEHASH of an account that selfdestructed in the current transaction. but later been revert") + public void test02GetTestContractCodeHash() { + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + + /*Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull));*/ + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + + final String triggerTxid = PublicMethed.triggerContract(extCodeHashContractAddress, + "getCodeHashRevert()", "#", false, 0l, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + List retList = PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray()); + + logger.info("the value: " + retList); + + Assert.assertFalse(retList.isEmpty()); + Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000000", + retList.get(0)); + } + + + @Test(enabled = true, description = "The EXTCODEHASH of an account that create in the current transaction. but later been revert") + public void test03GetTestContractCodeHash() { + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + + /*Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull));*/ + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + + final String triggerTxid = PublicMethed.triggerContract(extCodeHashContractAddress, + "getCodeHashCreate()", "#", false, 0l, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + List retList = PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray()); + + logger.info("the value: " + retList); + + Assert.assertFalse(retList.isEmpty()); + Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000000", + retList.get(0)); + } + + @Test(enabled = true, description = "The EXTCODEHASH of an account that selfdestructed in the current transaction.") + public void test04GetTestContractCodeHash() { + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + + /*Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull));*/ + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + + String param = "\"" + Base58.encode58Check(extCodeHashContractAddress) + "\""; + final String triggerTxid = PublicMethed.triggerContract(extCodeHashContractAddress, + "getCodeHashSuicide(address)", param, false, 0l, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + List retList = PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray()); + + logger.info("the value: " + retList); + + Assert.assertFalse(retList.isEmpty()); + Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000000", + retList.get(0)); + } + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } +} + + diff --git a/src/test/resources/soliditycode/Create2Test025.sol b/src/test/resources/soliditycode/Create2Test025.sol new file mode 100644 index 00000000000..87aef52b0c7 --- /dev/null +++ b/src/test/resources/soliditycode/Create2Test025.sol @@ -0,0 +1,27 @@ +contract Factory { + event Deployed(address addr, uint256 salt, address sender); + constructor() public { + } + + function create2(bytes memory code, uint256 salt) public returns(address){ + address addr; + assembly { + addr := create2(0, add(code, 0x20), mload(code), salt) + if iszero(extcodesize(addr)) { + revert(0, 0) + } + } + emit Deployed(addr, salt, msg.sender); + return addr; + } +} + +contract TestContract{ + uint256 public num; + constructor(uint256 j) public{ + num = j; + } + function getNum() public returns (uint256){ + return num; + } +} \ No newline at end of file diff --git a/src/test/resources/soliditycode/ExtCodeHashTest010.sol b/src/test/resources/soliditycode/ExtCodeHashTest010.sol new file mode 100644 index 00000000000..bfa8a7fa0d8 --- /dev/null +++ b/src/test/resources/soliditycode/ExtCodeHashTest010.sol @@ -0,0 +1,46 @@ +contract Counter { + uint count = 0; + address payable owner; + event LogResult(bytes32 _hashBefore, bytes32 _hashAfter); + constructor() public{ + owner = msg.sender; + } + function getCodeHashSuicide(address addr) public returns (bytes32 _hashBefore){ + assembly{ + _hashBefore := extcodehash(addr) + } + selfdestruct(owner); + return _hashBefore; + } + + function getCodeHashRevert() public returns (bytes32 _hashBefore, bytes32 _hashAfter) { + address addr = address(this); + assembly { + _hashBefore := extcodehash(addr) + } + if (owner == msg.sender) { + selfdestruct(owner); + } + assembly { + _hashAfter := extcodehash(addr) + } + revert(); + emit LogResult(_hashBefore, _hashAfter); + } + + function getCodeHashCreate() public returns (bytes32 _hashBefore){ + TestContract A = (new TestContract).value(0)(); + address addr = address(A); + assembly{ + _hashBefore := extcodehash(addr) + } + revert(); + return _hashBefore; + } +} + +contract TestContract{ + uint256 count = 1; + constructor() public payable{ + } +} \ No newline at end of file diff --git a/src/test/resources/soliditycode/create2CallContract.sol b/src/test/resources/soliditycode/create2CallContract.sol index fe5c13c16c5..f2de1c7ee13 100644 --- a/src/test/resources/soliditycode/create2CallContract.sol +++ b/src/test/resources/soliditycode/create2CallContract.sol @@ -4,8 +4,8 @@ contract callerContract { function delegateCallCreate2(address called_address, bytes memory code, uint256 salt) public { called_address.delegatecall(abi.encodeWithSignature("deploy(bytes,uint256)",code,salt)); } - function callCreate2(address called_address,bytes memory code, uint256 salt) public { - called_address.call(abi.encodeWithSignature("deploy(bytes,uint256)",code,salt)); + function callCreate2(address called_address,bytes memory code, uint256 salt) public returns(bool,bytes memory){ + return called_address.call(abi.encodeWithSignature("deploy(bytes,uint256)",code,salt)); } } diff --git a/src/test/resources/soliditycode_v0.4.25/TransferFailed005.sol b/src/test/resources/soliditycode_v0.4.25/TransferFailed005.sol new file mode 100644 index 00000000000..d3179a30191 --- /dev/null +++ b/src/test/resources/soliditycode_v0.4.25/TransferFailed005.sol @@ -0,0 +1,106 @@ +contract EnergyOfTransferFailedTest { + constructor() payable public { + + } + function testTransferTokenCompiledLongMax() payable public{ + address(0x1).transferToken(1,9223372036855775827); + } + + function testTransferTokenCompiledLongMin() payable public{ + //address(0x1).transferToken(1,-9223372036855775828); + } + + function testTransferTokenCompiledLongMin1() payable public{ + address(0x1).tokenBalance(trcToken(-9223372036855775828)); + } + + function testTransferTokenCompiledLongMax1() payable public{ + address(0x1).tokenBalance(trcToken(9223372036855775827)); + } + + // InsufficientBalance + function testTransferTrxInsufficientBalance(uint256 i) payable public{ + msg.sender.transfer(i); + } + + function testSendTrxInsufficientBalance(uint256 i) payable public{ + msg.sender.send(i); + } + + function testTransferTokenInsufficientBalance(uint256 i,trcToken tokenId) payable public{ + msg.sender.transferToken(i, tokenId); + } + + function testCallTrxInsufficientBalance(uint256 i,address caller) public returns (bool){ + return caller.call.value(i)(abi.encodeWithSignature("test()")); + } + + function testCreateTrxInsufficientBalance(uint256 i) payable public { + (new Caller).value(i)(); + } + + // NonexistentTarget + + function testSendTrxNonexistentTarget(uint256 i,address nonexistentTarget) payable public { + require(address(this).balance >= i); + nonexistentTarget.send(i); + } + + function testTransferTrxNonexistentTarget(uint256 i,address nonexistentTarget) payable public { + require(address(this).balance >= i); + nonexistentTarget.transfer(i); + } + + function testTransferTokenNonexistentTarget(uint256 i,address nonexistentTarget, trcToken tokenId) payable public { + require(address(this).balance >= i); + nonexistentTarget.transferToken(i, tokenId); + } + + function testCallTrxNonexistentTarget(uint256 i,address nonexistentTarget) payable public { + require(address(this).balance >= i); + nonexistentTarget.call.value(i)(abi.encodeWithSignature("test()")); + } + + function testSuicideNonexistentTarget(address nonexistentTarget) payable public { + selfdestruct(nonexistentTarget); + } + + // target is self + function testTransferTrxSelf(uint256 i) payable public{ + require(address(this).balance >= i); + address self = address(uint160(address(this))); + self.transfer(i); + } + + function testSendTrxSelf(uint256 i) payable public{ + require(address(this).balance >= i); + address self = address(uint160(address(this))); + self.send(i); + } + + function testTransferTokenSelf(uint256 i,trcToken tokenId) payable public{ + require(address(this).balance >= i); + address self = address(uint160(address(this))); + self.transferToken(i, tokenId); + } + + event Deployed(address addr, uint256 salt, address sender); + function deploy(bytes memory code, uint256 salt) public returns(address){ + address addr; + assembly { + addr := create2(10, add(code, 0x20), mload(code), salt) + //if iszero(extcodesize(addr)) { + // revert(0, 0) + //} + } + //emit Deployed(addr, salt, msg.sender); + return addr; + } +} + + + +contract Caller { + constructor() payable public {} + function test() payable public returns (uint256 ){return 1;} +} \ No newline at end of file diff --git a/src/test/resources/soliditycode_v0.4.25/TransferFailed007.sol b/src/test/resources/soliditycode_v0.4.25/TransferFailed007.sol new file mode 100644 index 00000000000..ffd6f10c486 --- /dev/null +++ b/src/test/resources/soliditycode_v0.4.25/TransferFailed007.sol @@ -0,0 +1,90 @@ +contract EnergyOfTransferFailedTest { + constructor() payable public { + + } + // InsufficientBalance + function testTransferTrxInsufficientBalance(uint256 i) payable public{ + msg.sender.transfer(i); + } + + function testSendTrxInsufficientBalance(uint256 i) payable public{ + msg.sender.send(i); + } + + function testTransferTokenInsufficientBalance(uint256 i,trcToken tokenId) payable public{ + msg.sender.transferToken(i, tokenId); + } + + function testCallTrxInsufficientBalance(uint256 i,address caller) public returns (bool){ + return caller.call.value(i)(abi.encodeWithSignature("test()")); + } + + function testCreateTrxInsufficientBalance(uint256 i) payable public { + (new Caller).value(i)(); + } + + // NonexistentTarget + + function testSendTrxNonexistentTarget(uint256 i,address nonexistentTarget) payable public { + require(address(this).balance >= i); + nonexistentTarget.send(i); + } + + function testTransferTrxNonexistentTarget(uint256 i,address nonexistentTarget) payable public { + require(address(this).balance >= i); + nonexistentTarget.transfer(i); + } + + function testTransferTokenNonexistentTarget(uint256 i,address nonexistentTarget, trcToken tokenId) payable public { + require(address(this).balance >= i); + nonexistentTarget.transferToken(i, tokenId); + } + + function testCallTrxNonexistentTarget(uint256 i,address nonexistentTarget) payable public { + require(address(this).balance >= i); + nonexistentTarget.call.value(i)(abi.encodeWithSignature("test()")); + } + + function testSuicideNonexistentTarget(address nonexistentTarget) payable public { + selfdestruct(nonexistentTarget); + } + + // target is self + function testTransferTrxSelf(uint256 i) payable public{ + require(address(this).balance >= i); + address self = address(uint160(address(this))); + self.transfer(i); + } + + function testSendTrxSelf(uint256 i) payable public{ + require(address(this).balance >= i); + address self = address(uint160(address(this))); + self.send(i); + } + + function testTransferTokenSelf(uint256 i,trcToken tokenId) payable public{ + require(address(this).balance >= i); + address self = address(uint160(address(this))); + self.transferToken(i, tokenId); + } + + event Deployed(address addr, uint256 salt, address sender); + function deploy(bytes memory code, uint256 salt) public returns(address){ + address addr; + assembly { + addr := create2(10, add(code, 0x20), mload(code), salt) + //if iszero(extcodesize(addr)) { + // revert(0, 0) + //} + } + //emit Deployed(addr, salt, msg.sender); + return addr; + } +} + + + +contract Caller { + constructor() payable public {} + function test() payable public returns (uint256 ){return 1;} +} \ No newline at end of file From 19bab744c79e0a8d0caa6e194248685f4c4cdba4 Mon Sep 17 00:00:00 2001 From: wubin01 Date: Mon, 3 Jun 2019 15:34:01 +0800 Subject: [PATCH 33/90] modify fast forward schedule function --- .../org/tron/common/overlay/server/FastForward.java | 13 +++---------- .../java/org/tron/core/net/service/AdvService.java | 1 + 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/tron/common/overlay/server/FastForward.java b/src/main/java/org/tron/common/overlay/server/FastForward.java index 28b68aa0836..cde93ec54e5 100644 --- a/src/main/java/org/tron/common/overlay/server/FastForward.java +++ b/src/main/java/org/tron/common/overlay/server/FastForward.java @@ -1,5 +1,6 @@ package org.tron.common.overlay.server; +import com.google.protobuf.ByteString; import java.net.InetAddress; import java.net.InetSocketAddress; import java.util.List; @@ -13,11 +14,8 @@ import org.tron.common.backup.BackupManager; import org.tron.common.backup.BackupManager.BackupStatusEnum; import org.tron.common.overlay.discover.node.Node; -import org.tron.common.overlay.discover.node.NodeManager; import org.tron.core.config.args.Args; -import org.tron.core.db.Manager; import org.tron.core.db.WitnessScheduleStore; -import org.tron.core.db.WitnessStore; import org.tron.core.services.WitnessService; import org.tron.protos.Protocol.ReasonCode; @@ -28,12 +26,8 @@ public class FastForward { @Autowired private ApplicationContext ctx; - private Manager manager; - private WitnessScheduleStore witnessScheduleStore; - private NodeManager nodeManager; - private ChannelManager channelManager; private BackupManager backupManager; @@ -42,7 +36,8 @@ public class FastForward { private Args args = Args.getInstance(); private List fastForwardNodes = args.getFastForwardNodes(); - private byte[] witnessAddress = args.getLocalWitnesses().getWitnessAccountAddress(); + private ByteString witnessAddress = ByteString + .copyFrom(args.getLocalWitnesses().getWitnessAccountAddress()); private int keySize = args.getLocalWitnesses().getPrivateKeys().size(); public void init() { @@ -54,9 +49,7 @@ public void init() { return; } - manager = ctx.getBean(Manager.class); witnessScheduleStore = ctx.getBean(WitnessScheduleStore.class); - nodeManager = ctx.getBean(NodeManager.class); channelManager = ctx.getBean(ChannelManager.class); backupManager = ctx.getBean(BackupManager.class); diff --git a/src/main/java/org/tron/core/net/service/AdvService.java b/src/main/java/org/tron/core/net/service/AdvService.java index d9b5e530091..f2817a132ff 100644 --- a/src/main/java/org/tron/core/net/service/AdvService.java +++ b/src/main/java/org/tron/core/net/service/AdvService.java @@ -188,6 +188,7 @@ public void fastForward(BlockMessage msg) { peers.forEach(peer -> { peer.sendMessage(msg); peer.getAdvInvSpread().put(item, System.currentTimeMillis()); + peer.setBlockBothHave(msg.getBlockId()); }); } From 86ad14540044f61e1562fd43f8eb6622caf4f89d Mon Sep 17 00:00:00 2001 From: wubin01 Date: Mon, 3 Jun 2019 16:47:35 +0800 Subject: [PATCH 34/90] modify for generateBlock test --- src/main/java/org/tron/core/db/Manager.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/tron/core/db/Manager.java b/src/main/java/org/tron/core/db/Manager.java index 2982a450c6c..ddb287e653e 100644 --- a/src/main/java/org/tron/core/db/Manager.java +++ b/src/main/java/org/tron/core/db/Manager.java @@ -1434,7 +1434,9 @@ public synchronized BlockCapsule generateBlock( blockCapsule.setMerkleRoot(); blockCapsule.sign(privateKey); - tronNetService.fastForward(new BlockMessage(blockCapsule)); + if (tronNetService != null) { + tronNetService.fastForward(new BlockMessage(blockCapsule)); + } try { this.pushBlock(blockCapsule); From eefe9c1b7627495de6a4b0082f5aed6bac6bc489 Mon Sep 17 00:00:00 2001 From: wubin1 Date: Mon, 3 Jun 2019 17:07:13 +0800 Subject: [PATCH 35/90] optimize transaction history database --- .circleci/config.yml | 17 +-- sharttmp.sh | 0 .../org/tron/common/runtime/vm/LogInfo.java | 2 +- src/main/java/org/tron/core/Wallet.java | 12 +- .../org/tron/core/capsule/BlockCapsule.java | 2 +- .../core/capsule/TransactionInfoCapsule.java | 13 +- .../capsule/TransactionResultListCapsule.java | 125 ------------------ .../core/capsule/TransactionRetCapsule.java | 45 +++++++ .../java/org/tron/core/config/Parameter.java | 1 + .../java/org/tron/core/config/args/Args.java | 11 ++ .../java/org/tron/core/db/AccountStore.java | 8 +- src/main/java/org/tron/core/db/Manager.java | 65 +++++---- .../core/db/TransactionResultListStore.java | 17 --- .../org/tron/core/db/TransactionRetStore.java | 47 +++++++ .../org/tron/core/db/TransactionStore.java | 13 ++ .../AccountStateEntity.java | 2 +- .../{fast => accountstate}/TrieService.java | 4 +- .../callback/AccountStateCallBack.java} | 8 +- .../storetrie/AccountStateStoreTrie.java | 6 +- .../tron/core/services/WitnessService.java | 28 ++-- .../services/http/FullNodeHttpApiService.java | 6 + .../solidity/SolidityNodeHttpApiService.java | 6 + .../solidity/HttpApiOnSolidityService.java | 5 + src/main/protos/core/Tron.proto | 74 +---------- src/main/resources/config.conf | 2 + 25 files changed, 221 insertions(+), 298 deletions(-) create mode 100644 sharttmp.sh delete mode 100644 src/main/java/org/tron/core/capsule/TransactionResultListCapsule.java create mode 100644 src/main/java/org/tron/core/capsule/TransactionRetCapsule.java delete mode 100644 src/main/java/org/tron/core/db/TransactionResultListStore.java create mode 100644 src/main/java/org/tron/core/db/TransactionRetStore.java rename src/main/java/org/tron/core/db/{fast => accountstate}/AccountStateEntity.java (96%) rename src/main/java/org/tron/core/db/{fast => accountstate}/TrieService.java (93%) rename src/main/java/org/tron/core/db/{fast/callback/FastSyncCallBack.java => accountstate/callback/AccountStateCallBack.java} (95%) rename src/main/java/org/tron/core/db/{fast => accountstate}/storetrie/AccountStateStoreTrie.java (91%) diff --git a/.circleci/config.yml b/.circleci/config.yml index fa5b396a34f..2aaa0121d5b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -14,12 +14,13 @@ jobs: - checkout - run: name: multi_os_result - command: curl http://60.205.215.34/multi_os_result + command: echo "curl http://60.205.215.34/multi_os_result" +# +# - run: +# name: Daily Build Report +# command: curl http://60.205.215.34/Daily_Build_Task_Report +# +# - run: +# name: Download Links +# command: sh DownloadLinks.sh - - run: - name: Daily Build Report - command: curl http://60.205.215.34/Daily_Build_Task_Report - - - run: - name: Download Links - command: sh DownloadLinks.sh diff --git a/sharttmp.sh b/sharttmp.sh new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/main/java/org/tron/common/runtime/vm/LogInfo.java b/src/main/java/org/tron/common/runtime/vm/LogInfo.java index 3068d543ac9..fff2299bc1a 100644 --- a/src/main/java/org/tron/common/runtime/vm/LogInfo.java +++ b/src/main/java/org/tron/common/runtime/vm/LogInfo.java @@ -24,7 +24,7 @@ import java.util.List; import org.spongycastle.util.encoders.Hex; import org.tron.common.utils.ByteUtil; -import org.tron.protos.Protocol.TransactionResult.Log; +import org.tron.protos.Protocol.TransactionInfo.Log; /** * @author Roman Mandeleil diff --git a/src/main/java/org/tron/core/Wallet.java b/src/main/java/org/tron/core/Wallet.java index 5c72ca06355..52b1a532ea2 100755 --- a/src/main/java/org/tron/core/Wallet.java +++ b/src/main/java/org/tron/core/Wallet.java @@ -93,7 +93,6 @@ import org.tron.core.capsule.TransactionInfoCapsule; import org.tron.core.capsule.TransactionResultCapsule; import org.tron.core.capsule.WitnessCapsule; -import org.tron.core.capsule.utils.TransactionUtil; import org.tron.core.config.Parameter.ChainConstant; import org.tron.core.config.args.Args; import org.tron.core.db.AccountIdIndexStore; @@ -103,6 +102,7 @@ import org.tron.core.db.EnergyProcessor; import org.tron.core.db.Manager; import org.tron.core.exception.AccountResourceInsufficientException; +import org.tron.core.exception.BadItemException; import org.tron.core.exception.ContractExeException; import org.tron.core.exception.ContractValidateException; import org.tron.core.exception.DupTransactionException; @@ -1229,7 +1229,7 @@ public TransactionInfo getTransactionInfoById(ByteString transactionId) { if (Objects.isNull(transactionId)) { return null; } - TransactionInfoCapsule transactionInfoCapsule = null; + TransactionInfoCapsule transactionInfoCapsule; try { transactionInfoCapsule = dbManager.getTransactionHistoryStore() .get(transactionId.toByteArray()); @@ -1239,7 +1239,13 @@ public TransactionInfo getTransactionInfoById(ByteString transactionId) { if (transactionInfoCapsule != null) { return transactionInfoCapsule.getInstance(); } - return null; + try { + transactionInfoCapsule = dbManager.getTransactionRetStore().getTransactionInfo(transactionId.toByteArray()); + } catch (BadItemException e) { + return null; + } + + return transactionInfoCapsule.getInstance(); } public Proposal getProposalById(ByteString proposalId) { diff --git a/src/main/java/org/tron/core/capsule/BlockCapsule.java b/src/main/java/org/tron/core/capsule/BlockCapsule.java index 45b9b034715..490e1a9fb34 100755 --- a/src/main/java/org/tron/core/capsule/BlockCapsule.java +++ b/src/main/java/org/tron/core/capsule/BlockCapsule.java @@ -48,7 +48,7 @@ public class BlockCapsule implements ProtoCapsule { @Getter @Setter - private TransactionResultListCapsule result; + private TransactionRetCapsule result; public static class BlockId extends Sha256Hash { diff --git a/src/main/java/org/tron/core/capsule/TransactionInfoCapsule.java b/src/main/java/org/tron/core/capsule/TransactionInfoCapsule.java index 4379da77815..91aaa0ea8af 100644 --- a/src/main/java/org/tron/core/capsule/TransactionInfoCapsule.java +++ b/src/main/java/org/tron/core/capsule/TransactionInfoCapsule.java @@ -1,6 +1,5 @@ package org.tron.core.capsule; -import com.google.common.collect.Lists; import com.google.protobuf.ByteString; import com.google.protobuf.InvalidProtocolBufferException; import java.util.ArrayList; @@ -178,7 +177,7 @@ public static TransactionInfoCapsule buildInstance(TransactionCapsule trxCap, Bl List logList = new ArrayList<>(); programResult.getLogInfoList().forEach( logInfo -> { - logList.add(buildLog(logInfo)); + logList.add(LogInfo.buildLog(logInfo)); } ); builder.addAllLog(logList); @@ -225,14 +224,4 @@ public static TransactionInfoCapsule buildInstance(TransactionCapsule trxCap, Bl return new TransactionInfoCapsule(builder.build()); } - - public static Log buildLog(LogInfo logInfo) { - List topics = Lists.newArrayList(); - logInfo.getTopics().forEach(topic -> { - topics.add(ByteString.copyFrom(topic.getData())); - }); - ByteString address = ByteString.copyFrom(logInfo.getAddress()); - ByteString data = ByteString.copyFrom(logInfo.getData()); - return Log.newBuilder().setAddress(address).addAllTopics(topics).setData(data).build(); - } } \ No newline at end of file diff --git a/src/main/java/org/tron/core/capsule/TransactionResultListCapsule.java b/src/main/java/org/tron/core/capsule/TransactionResultListCapsule.java deleted file mode 100644 index 0ef4ac62efb..00000000000 --- a/src/main/java/org/tron/core/capsule/TransactionResultListCapsule.java +++ /dev/null @@ -1,125 +0,0 @@ -package org.tron.core.capsule; - -import com.google.protobuf.ByteString; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; -import org.tron.common.runtime.vm.LogInfo; -import org.tron.common.runtime.vm.program.InternalTransaction; -import org.tron.common.runtime.vm.program.ProgramResult; -import org.tron.core.config.args.Args; -import org.tron.core.db.TransactionTrace; -import org.tron.protos.Protocol; -import org.tron.protos.Protocol.Block; -import org.tron.protos.Protocol.TransactionInfo; -import org.tron.protos.Protocol.TransactionResult.Log; -import org.tron.protos.Protocol.TransactionResult.code; -import org.tron.protos.Protocol.TransactionResult; -import org.tron.protos.Protocol.TransactionResultList; - -@Slf4j(topic = "capsule") -public class TransactionResultListCapsule implements ProtoCapsule { - private TransactionResultList transactionResultList; - - public TransactionResultListCapsule(BlockCapsule blockCapsule) { - transactionResultList = TransactionResultList.newBuilder().build(); - if (Objects.isNull(blockCapsule)) { - return; - } - TransactionResultList.Builder build = transactionResultList.toBuilder(). - setBlockNumber(blockCapsule.getNum()).setBlockTimeStamp(blockCapsule.getTimeStamp()); - transactionResultList = build.build(); - } - - public void addTransactionResult(TransactionResult result) { - this.transactionResultList = this.transactionResultList.toBuilder().addTransactionresult(result).build(); - } - - public static TransactionResult buildInstance(TransactionCapsule trxCap, BlockCapsule block, - TransactionTrace trace) { - - TransactionResult.Builder builder = TransactionResult.newBuilder(); - ReceiptCapsule traceReceipt = trace.getReceipt(); - builder.setResult(code.SUCESS); - if (StringUtils.isNoneEmpty(trace.getRuntimeError()) || Objects - .nonNull(trace.getRuntimeResult().getException())) { - builder.setResult(code.FAILED); - builder.setResMessage(ByteString.copyFromUtf8(trace.getRuntimeError())); - } - builder.setId(ByteString.copyFrom(trxCap.getTransactionId().getBytes())); - ProgramResult programResult = trace.getRuntimeResult(); - long fee = - programResult.getRet().getFee() + traceReceipt.getEnergyFee() - + traceReceipt.getNetFee() + traceReceipt.getMultiSignFee(); - ByteString contractResult = ByteString.copyFrom(programResult.getHReturn()); - ByteString ContractAddress = ByteString.copyFrom(programResult.getContractAddress()); - - builder.setFee(fee); - builder.addContractResult(contractResult); - builder.setContractAddress(ContractAddress); - builder.setUnfreezeAmount(programResult.getRet().getUnfreezeAmount()); - builder.setAssetIssueID(programResult.getRet().getAssetIssueID()); - builder.setExchangeId(programResult.getRet().getExchangeId()); - builder.setWithdrawAmount(programResult.getRet().getWithdrawAmount()); - builder.setExchangeReceivedAmount(programResult.getRet().getExchangeReceivedAmount()); - builder.setExchangeInjectAnotherAmount(programResult.getRet().getExchangeInjectAnotherAmount()); - builder.setExchangeWithdrawAnotherAmount( - programResult.getRet().getExchangeWithdrawAnotherAmount()); - - List logList = new ArrayList<>(); - programResult.getLogInfoList().forEach( - logInfo -> { - logList.add(LogInfo.buildLog(logInfo)); - } - ); - builder.addAllLog(logList); - builder.setReceipt(traceReceipt.getReceipt()); - - if (Args.getInstance().isSaveInternalTx() && null != programResult.getInternalTransactions()) { - for (InternalTransaction internalTransaction : programResult - .getInternalTransactions()) { - Protocol.InternalTransaction.Builder internalTrxBuilder = Protocol.InternalTransaction - .newBuilder(); - // set hash - internalTrxBuilder.setHash(ByteString.copyFrom(internalTransaction.getHash())); - // set caller - internalTrxBuilder.setCallerAddress(ByteString.copyFrom(internalTransaction.getSender())); - // set TransferTo - internalTrxBuilder - .setTransferToAddress(ByteString.copyFrom(internalTransaction.getTransferToAddress())); - //TODO: "for loop" below in future for multiple token case, we only have one for now. - Protocol.InternalTransaction.CallValueInfo.Builder callValueInfoBuilder = - Protocol.InternalTransaction.CallValueInfo.newBuilder(); - // trx will not be set token name - callValueInfoBuilder.setCallValue(internalTransaction.getValue()); - // Just one transferBuilder for now. - internalTrxBuilder.addCallValueInfo(callValueInfoBuilder); - internalTransaction.getTokenInfo().forEach((tokenId, amount) -> { - Protocol.InternalTransaction.CallValueInfo.Builder tokenInfoBuilder = - Protocol.InternalTransaction.CallValueInfo.newBuilder(); - tokenInfoBuilder.setTokenId(tokenId); - tokenInfoBuilder.setCallValue(amount); - internalTrxBuilder.addCallValueInfo(tokenInfoBuilder); - }); - // Token for loop end here - internalTrxBuilder.setNote(ByteString.copyFrom(internalTransaction.getNote().getBytes())); - internalTrxBuilder.setRejected(internalTransaction.isRejected()); - builder.addInternalTransactions(internalTrxBuilder); - } - } - - return builder.build(); - } - - @Override - public byte[] getData() { - return transactionResultList.toByteArray(); - } - - @Override - public TransactionResultList getInstance() { - return transactionResultList; - } -} \ No newline at end of file diff --git a/src/main/java/org/tron/core/capsule/TransactionRetCapsule.java b/src/main/java/org/tron/core/capsule/TransactionRetCapsule.java new file mode 100644 index 00000000000..8b35bbfb397 --- /dev/null +++ b/src/main/java/org/tron/core/capsule/TransactionRetCapsule.java @@ -0,0 +1,45 @@ +package org.tron.core.capsule; + +import com.google.protobuf.InvalidProtocolBufferException; +import java.util.Objects; +import lombok.extern.slf4j.Slf4j; +import org.tron.core.exception.BadItemException; +import org.tron.protos.Protocol.TransactionInfo; +import org.tron.protos.Protocol.TransactionRet; + +@Slf4j(topic = "capsule") +public class TransactionRetCapsule implements ProtoCapsule { + private TransactionRet transactionRet; + + public TransactionRetCapsule(BlockCapsule blockCapsule) { + transactionRet = TransactionRet.newBuilder().build(); + if (Objects.isNull(blockCapsule)) { + return; + } + TransactionRet.Builder build = transactionRet.toBuilder(). + setBlockNumber(blockCapsule.getNum()).setBlockTimeStamp(blockCapsule.getTimeStamp()); + transactionRet = build.build(); + } + + public TransactionRetCapsule(byte[] data) throws BadItemException { + try { + this.transactionRet = transactionRet.parseFrom(data); + } catch (InvalidProtocolBufferException e) { + throw new BadItemException("TransactionInfoCapsule proto data parse exception"); + } + } + + public void addTransactionInfo(TransactionInfo result) { + this.transactionRet = this.transactionRet.toBuilder().addTransactioninfo(result).build(); + } + + @Override + public byte[] getData() { + return transactionRet.toByteArray(); + } + + @Override + public TransactionRet getInstance() { + return transactionRet; + } +} \ No newline at end of file diff --git a/src/main/java/org/tron/core/config/Parameter.java b/src/main/java/org/tron/core/config/Parameter.java index 38a99adadc9..12732495156 100644 --- a/src/main/java/org/tron/core/config/Parameter.java +++ b/src/main/java/org/tron/core/config/Parameter.java @@ -33,6 +33,7 @@ public class NodeConstant { public static final long MAX_BLOCKS_SYNC_FROM_ONE_PEER = 1000; public static final long SYNC_CHAIN_LIMIT_NUM = 500; public static final int MAX_TRANSACTION_PENDING = 2000; + public static final int MAX_HTTP_CONNECT_NUMBER = 50; } public class NetConstants { diff --git a/src/main/java/org/tron/core/config/args/Args.java b/src/main/java/org/tron/core/config/args/Args.java index f57933f66cf..25c87796bfc 100644 --- a/src/main/java/org/tron/core/config/args/Args.java +++ b/src/main/java/org/tron/core/config/args/Args.java @@ -47,6 +47,7 @@ import org.tron.core.config.Configuration; import org.tron.core.config.Parameter.ChainConstant; import org.tron.core.config.Parameter.NetConstants; +import org.tron.core.config.Parameter.NodeConstant; import org.tron.core.db.AccountStore; import org.tron.core.db.backup.DbBackupConfig; import org.tron.keystore.CipherException; @@ -105,6 +106,11 @@ public class Args { @Parameter(names = {"--long-running-time"}) private int longRunningTime = 10; + @Getter + @Setter + @Parameter(names = {"--max-connect-number"}) + private int maxHttpConnectNumber = 50; + @Getter @Parameter(description = "--seed-nodes") private List seedNodes = new ArrayList<>(); @@ -535,6 +541,7 @@ public static void clearParam() { INSTANCE.minTimeRatio = 0.0; INSTANCE.maxTimeRatio = 5.0; INSTANCE.longRunningTime = 10; + INSTANCE.maxHttpConnectNumber = 50; INSTANCE.allowMultiSign = 0; INSTANCE.trxExpirationTimeInMilliseconds = 0; INSTANCE.allowProtoFilterNum = 0; @@ -804,6 +811,10 @@ public static void setParam(final String[] args, final String confFileName) { INSTANCE.blockProducedTimeOut = config.hasPath("node.blockProducedTimeOut") ? config.getInt("node.blockProducedTimeOut") : ChainConstant.BLOCK_PRODUCED_TIME_OUT; + + INSTANCE.maxHttpConnectNumber = config.hasPath("node.maxHttpConnectNumber") ? + config.getInt("node.maxHttpConnectNumber") : NodeConstant.MAX_HTTP_CONNECT_NUMBER; + if (INSTANCE.blockProducedTimeOut < 30) { INSTANCE.blockProducedTimeOut = 30; } diff --git a/src/main/java/org/tron/core/db/AccountStore.java b/src/main/java/org/tron/core/db/AccountStore.java index d3174f93afd..7740eb9be97 100644 --- a/src/main/java/org/tron/core/db/AccountStore.java +++ b/src/main/java/org/tron/core/db/AccountStore.java @@ -11,8 +11,8 @@ import org.springframework.stereotype.Component; import org.tron.core.Wallet; import org.tron.core.capsule.AccountCapsule; -import org.tron.core.db.fast.callback.FastSyncCallBack; -import org.tron.core.db.fast.storetrie.AccountStateStoreTrie; +import org.tron.core.db.accountstate.callback.AccountStateCallBack; +import org.tron.core.db.accountstate.storetrie.AccountStateStoreTrie; @Slf4j(topic = "DB") @Component @@ -21,7 +21,7 @@ public class AccountStore extends TronStoreWithRevoking { private static Map assertsAddress = new HashMap<>(); // key = name , value = address @Autowired - private FastSyncCallBack fastSyncCallBack; + private AccountStateCallBack accountStateCallBack; @Autowired private AccountStateStoreTrie accountStateStoreTrie; @@ -41,7 +41,7 @@ public AccountCapsule get(byte[] key) { @Override public void put(byte[] key, AccountCapsule item) { super.put(key, item); - fastSyncCallBack.accountCallBack(key, item); + accountStateCallBack.accountCallBack(key, item); } /** diff --git a/src/main/java/org/tron/core/db/Manager.java b/src/main/java/org/tron/core/db/Manager.java index f1c2270e216..032444c19aa 100644 --- a/src/main/java/org/tron/core/db/Manager.java +++ b/src/main/java/org/tron/core/db/Manager.java @@ -31,8 +31,6 @@ import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; import java.util.stream.Collectors; @@ -70,7 +68,7 @@ import org.tron.core.capsule.ExchangeCapsule; import org.tron.core.capsule.TransactionCapsule; import org.tron.core.capsule.TransactionInfoCapsule; -import org.tron.core.capsule.TransactionResultListCapsule; +import org.tron.core.capsule.TransactionRetCapsule; import org.tron.core.capsule.WitnessCapsule; import org.tron.core.capsule.utils.BlockUtil; import org.tron.core.config.Parameter.ChainConstant; @@ -78,8 +76,8 @@ import org.tron.core.config.args.GenesisBlock; import org.tron.core.db.KhaosDatabase.KhaosBlock; import org.tron.core.db.api.AssetUpdateHelper; -import org.tron.core.db.fast.TrieService; -import org.tron.core.db.fast.callback.FastSyncCallBack; +import org.tron.core.db.accountstate.TrieService; +import org.tron.core.db.accountstate.callback.AccountStateCallBack; import org.tron.core.db2.core.ISession; import org.tron.core.db2.core.ITronChainBase; import org.tron.core.db2.core.SnapshotManager; @@ -110,7 +108,7 @@ import org.tron.protos.Protocol.AccountType; import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.Transaction.Contract; -import org.tron.protos.Protocol.TransactionResult; +import org.tron.protos.Protocol.TransactionInfo; @Slf4j(topic = "DB") @@ -137,8 +135,9 @@ public class Manager { @Autowired @Getter private BlockIndexStore blockIndexStore; + @Autowired @Getter - private TransactionResultListStore resultStore; + private TransactionRetStore transactionRetStore; @Autowired private AccountIdIndexStore accountIdIndexStore; @Autowired @@ -227,7 +226,7 @@ public class Manager { private ForkController forkController = ForkController.instance(); @Autowired - private FastSyncCallBack fastSyncCallBack; + private AccountStateCallBack accountStateCallBack; @Autowired private TrieService trieService; @@ -438,7 +437,7 @@ public void stopRepushTriggerThread() { @PostConstruct public void init() { Message.setManager(this); - fastSyncCallBack.setManager(this); + accountStateCallBack.setManager(this); trieService.setManager(this); revokingStore.disable(); revokingStore.check(); @@ -850,7 +849,7 @@ private void applyBlock(BlockCapsule block) throws ContractValidateException, this.blockStore.put(block.getBlockId().getBytes(), block); this.blockIndexStore.put(block.getBlockId()); if (block.getTransactions().size() != 0) { - this.resultStore.put(block.getBlockId().getBytes(), block.getResult()); + this.transactionRetStore.put(ByteArray.fromLong(block.getNum()), block.getResult()); } updateFork(block); @@ -1199,7 +1198,7 @@ public boolean hasBlocks() { /** * Process transaction. */ - public TransactionResult processTransaction(final TransactionCapsule trxCap, BlockCapsule blockCap) + public TransactionInfo processTransaction(final TransactionCapsule trxCap, BlockCapsule blockCap) throws ValidateSignatureException, ContractValidateException, ContractExeException, AccountResourceInsufficientException, TransactionExpirationException, TooBigTransactionException, TooBigTransactionResultException, DupTransactionException, TaposException, ReceiptCheckErrException, VMIllegalException { @@ -1262,14 +1261,9 @@ public TransactionResult processTransaction(final TransactionCapsule trxCap, Blo .ifPresent(t -> t.put(trxCap.getTransactionId().getBytes(), new BytesCapsule(ByteArray.fromLong(trxCap.getBlockNum())))); - TransactionResult transactionInfo = TransactionResultListCapsule - .buildInstance(trxCap, blockCap, trace); - - TransactionInfoCapsule transactionInfo2 = TransactionInfoCapsule + TransactionInfoCapsule transactionInfo = TransactionInfoCapsule .buildInstance(trxCap, blockCap, trace); - transactionHistoryStore.put(trxCap.getTransactionId().getBytes(), transactionInfo2); - // if event subscribe is enabled, post contract triggers to queue postContractTrigger(trace, false); Contract contract = trxCap.getInstance().getRawData().getContract(0); @@ -1277,7 +1271,7 @@ public TransactionResult processTransaction(final TransactionCapsule trxCap, Blo ownerAddressSet.add(ByteArray.toHexString(TransactionCapsule.getOwner(contract))); } - return transactionInfo; + return transactionInfo.getInstance(); } @@ -1331,15 +1325,15 @@ public synchronized BlockCapsule generateBlock( session.reset(); session.setValue(revokingStore.buildSession()); // - fastSyncCallBack.preExecute(blockCapsule); + accountStateCallBack.preExecute(blockCapsule); if (needCheckWitnessPermission && !witnessService. validateWitnessPermission(witnessCapsule.getAddress())) { logger.warn("Witness permission is wrong"); return null; } - TransactionResultListCapsule transationResultCapsule = - new TransactionResultListCapsule(blockCapsule); + TransactionRetCapsule transationRetCapsule = + new TransactionRetCapsule(blockCapsule); Set accountSet = new HashSet<>(); Iterator iterator = pendingTransactions.iterator(); @@ -1384,13 +1378,13 @@ public synchronized BlockCapsule generateBlock( } // apply transaction try (ISession tmpSeesion = revokingStore.buildSession()) { - fastSyncCallBack.preExeTrans(); - TransactionResult result = processTransaction(trx, blockCapsule); - fastSyncCallBack.exeTransFinish(); + accountStateCallBack.preExeTrans(); + TransactionInfo result = processTransaction(trx, blockCapsule); + accountStateCallBack.exeTransFinish(); tmpSeesion.merge(); // push into block blockCapsule.addTransaction(trx); - transationResultCapsule.addTransactionResult(result); + transationRetCapsule.addTransactionInfo(result); if (fromPending) { iterator.remove(); } @@ -1429,7 +1423,7 @@ public synchronized BlockCapsule generateBlock( } } // end of while - fastSyncCallBack.executeGenerateFinish(); + accountStateCallBack.executeGenerateFinish(); session.reset(); if (postponedTrxCount > 0) { @@ -1442,7 +1436,7 @@ public synchronized BlockCapsule generateBlock( blockCapsule.setMerkleRoot(); blockCapsule.sign(privateKey); - blockCapsule.setResult(transationResultCapsule); + blockCapsule.setResult(transationRetCapsule); try { this.pushBlock(blockCapsule); @@ -1532,24 +1526,27 @@ public void processBlock(BlockCapsule block) } } - TransactionResultListCapsule transationResultCapsule = - new TransactionResultListCapsule(block); + TransactionRetCapsule transationRetCapsule = + new TransactionRetCapsule(block); try { - fastSyncCallBack.preExecute(block); + accountStateCallBack.preExecute(block); for (TransactionCapsule transactionCapsule : block.getTransactions()) { transactionCapsule.setBlockNum(block.getNum()); if (block.generatedByMyself) { transactionCapsule.setVerified(true); } - fastSyncCallBack.preExeTrans(); - fastSyncCallBack.exeTransFinish(); + accountStateCallBack.preExeTrans(); + TransactionInfo result = processTransaction(transactionCapsule, block); + accountStateCallBack.exeTransFinish(); + Optional.ofNullable(result).ifPresent(t -> transationRetCapsule.addTransactionInfo(result)); } - fastSyncCallBack.executePushFinish(); + accountStateCallBack.executePushFinish(); } finally { - fastSyncCallBack.exceptionFinish(); + accountStateCallBack.exceptionFinish(); } + block.setResult(transationRetCapsule); boolean needMaint = needMaintenance(block.getTimeStamp()); if (needMaint) { if (block.getNum() == 1) { diff --git a/src/main/java/org/tron/core/db/TransactionResultListStore.java b/src/main/java/org/tron/core/db/TransactionResultListStore.java deleted file mode 100644 index c2f52d9912f..00000000000 --- a/src/main/java/org/tron/core/db/TransactionResultListStore.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.tron.core.db; - -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; -import org.tron.core.capsule.TransactionResultListCapsule; - -@Slf4j(topic = "DB") -@Component -public class TransactionResultListStore extends TronStoreWithRevoking { - - @Autowired - public TransactionResultListStore(@Value("transactionResultListStore") String dbName) { - super(dbName); - } -} diff --git a/src/main/java/org/tron/core/db/TransactionRetStore.java b/src/main/java/org/tron/core/db/TransactionRetStore.java new file mode 100644 index 00000000000..c6100c75a1c --- /dev/null +++ b/src/main/java/org/tron/core/db/TransactionRetStore.java @@ -0,0 +1,47 @@ +package org.tron.core.db; + +import com.google.protobuf.ByteString; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; +import org.tron.common.utils.ByteArray; +import org.tron.common.utils.Sha256Hash; +import org.tron.core.capsule.TransactionCapsule; +import org.tron.core.capsule.TransactionInfoCapsule; +import org.tron.core.capsule.TransactionRetCapsule; +import org.tron.core.exception.BadItemException; +import java.util.Objects; +import org.tron.protos.Protocol.TransactionInfo; + +@Slf4j(topic = "DB") +@Component +public class TransactionRetStore extends TronStoreWithRevoking { + + @Autowired + private TransactionStore transactionStore; + + @Autowired + public TransactionRetStore(@Value("transactionRetStore") String dbName) { + super(dbName); + } + + public TransactionInfoCapsule getTransactionInfo(byte[] key) throws BadItemException { + long blockNumber = transactionStore.getBlockNumber(key); + if (blockNumber == -1) { + return null; + } + byte[] value = revokingDB.getUnchecked(ByteArray.fromLong(blockNumber)); + TransactionRetCapsule result = new TransactionRetCapsule(value); + if (Objects.isNull(result)) { + return null; + } + for (TransactionInfo transactionResultInfo : result.getInstance().getTransactioninfoList()) { + if (transactionResultInfo.getId().equals(ByteString.copyFrom(key))) { + return new TransactionInfoCapsule(transactionResultInfo); + } + } + return null; + } + +} diff --git a/src/main/java/org/tron/core/db/TransactionStore.java b/src/main/java/org/tron/core/db/TransactionStore.java index 08d9abf4e3a..c29f707d0c9 100644 --- a/src/main/java/org/tron/core/db/TransactionStore.java +++ b/src/main/java/org/tron/core/db/TransactionStore.java @@ -67,6 +67,19 @@ private TransactionCapsule getTransactionFromKhaosDatabase(byte[] key, long high return null; } + public long getBlockNumber(byte[] key) { + byte[] value = revokingDB.getUnchecked(key); + if (ArrayUtils.isEmpty(value)) { + return -1; + } + TransactionCapsule transactionCapsule = null; + if (value.length == 8) { + return ByteArray.toLong(value); + } + + return transactionCapsule == null ? -1 : transactionCapsule.getBlockNum(); + } + @Override public TransactionCapsule get(byte[] key) throws BadItemException { byte[] value = revokingDB.getUnchecked(key); diff --git a/src/main/java/org/tron/core/db/fast/AccountStateEntity.java b/src/main/java/org/tron/core/db/accountstate/AccountStateEntity.java similarity index 96% rename from src/main/java/org/tron/core/db/fast/AccountStateEntity.java rename to src/main/java/org/tron/core/db/accountstate/AccountStateEntity.java index 6055c05b388..45d8adb4df1 100644 --- a/src/main/java/org/tron/core/db/fast/AccountStateEntity.java +++ b/src/main/java/org/tron/core/db/accountstate/AccountStateEntity.java @@ -1,4 +1,4 @@ -package org.tron.core.db.fast; +package org.tron.core.db.accountstate; import lombok.extern.slf4j.Slf4j; import org.tron.core.Wallet; diff --git a/src/main/java/org/tron/core/db/fast/TrieService.java b/src/main/java/org/tron/core/db/accountstate/TrieService.java similarity index 93% rename from src/main/java/org/tron/core/db/fast/TrieService.java rename to src/main/java/org/tron/core/db/accountstate/TrieService.java index bb4c3edc60e..0dd5827006a 100644 --- a/src/main/java/org/tron/core/db/fast/TrieService.java +++ b/src/main/java/org/tron/core/db/accountstate/TrieService.java @@ -1,4 +1,4 @@ -package org.tron.core.db.fast; +package org.tron.core.db.accountstate; import com.google.protobuf.ByteString; import com.google.protobuf.Internal; @@ -9,7 +9,7 @@ import org.tron.common.crypto.Hash; import org.tron.core.capsule.BlockCapsule; import org.tron.core.db.Manager; -import org.tron.core.db.fast.storetrie.AccountStateStoreTrie; +import org.tron.core.db.accountstate.storetrie.AccountStateStoreTrie; @Slf4j(topic = "AccountState") @Component diff --git a/src/main/java/org/tron/core/db/fast/callback/FastSyncCallBack.java b/src/main/java/org/tron/core/db/accountstate/callback/AccountStateCallBack.java similarity index 95% rename from src/main/java/org/tron/core/db/fast/callback/FastSyncCallBack.java rename to src/main/java/org/tron/core/db/accountstate/callback/AccountStateCallBack.java index 577f1b89f4a..fe0d44896a3 100644 --- a/src/main/java/org/tron/core/db/fast/callback/FastSyncCallBack.java +++ b/src/main/java/org/tron/core/db/accountstate/callback/AccountStateCallBack.java @@ -1,4 +1,4 @@ -package org.tron.core.db.fast.callback; +package org.tron.core.db.accountstate.callback; import com.google.protobuf.ByteString; import com.google.protobuf.Internal; @@ -16,8 +16,8 @@ import org.tron.core.capsule.BlockCapsule; import org.tron.core.capsule.utils.RLP; import org.tron.core.db.Manager; -import org.tron.core.db.fast.AccountStateEntity; -import org.tron.core.db.fast.storetrie.AccountStateStoreTrie; +import org.tron.core.db.accountstate.AccountStateEntity; +import org.tron.core.db.accountstate.storetrie.AccountStateStoreTrie; import org.tron.core.exception.BadBlockException; import org.tron.core.trie.TrieImpl; import org.tron.core.trie.TrieImpl.Node; @@ -25,7 +25,7 @@ @Slf4j(topic = "AccountState") @Component -public class FastSyncCallBack { +public class AccountStateCallBack { private BlockCapsule blockCapsule; private volatile boolean execute = false; diff --git a/src/main/java/org/tron/core/db/fast/storetrie/AccountStateStoreTrie.java b/src/main/java/org/tron/core/db/accountstate/storetrie/AccountStateStoreTrie.java similarity index 91% rename from src/main/java/org/tron/core/db/fast/storetrie/AccountStateStoreTrie.java rename to src/main/java/org/tron/core/db/accountstate/storetrie/AccountStateStoreTrie.java index 0c85c3ef34e..df3a3a157ee 100644 --- a/src/main/java/org/tron/core/db/fast/storetrie/AccountStateStoreTrie.java +++ b/src/main/java/org/tron/core/db/accountstate/storetrie/AccountStateStoreTrie.java @@ -1,4 +1,4 @@ -package org.tron.core.db.fast.storetrie; +package org.tron.core.db.accountstate.storetrie; import javax.annotation.PostConstruct; import lombok.extern.slf4j.Slf4j; @@ -9,8 +9,8 @@ import org.tron.core.capsule.BytesCapsule; import org.tron.core.capsule.utils.RLP; import org.tron.core.db.TronStoreWithRevoking; -import org.tron.core.db.fast.AccountStateEntity; -import org.tron.core.db.fast.TrieService; +import org.tron.core.db.accountstate.AccountStateEntity; +import org.tron.core.db.accountstate.TrieService; import org.tron.core.db2.common.DB; import org.tron.core.trie.TrieImpl; diff --git a/src/main/java/org/tron/core/services/WitnessService.java b/src/main/java/org/tron/core/services/WitnessService.java index 9f203762b14..00d447974be 100755 --- a/src/main/java/org/tron/core/services/WitnessService.java +++ b/src/main/java/org/tron/core/services/WitnessService.java @@ -256,23 +256,23 @@ private BlockProductionCondition tryProduceBlock() throws InterruptedException { block = generateBlock(scheduledTime, scheduledWitness, controller.lastHeadBlockIsMaintenance()); - } - if (block == null) { - logger.warn("exception when generate block"); - return BlockProductionCondition.EXCEPTION_PRODUCING_BLOCK; - } + if (block == null) { + logger.warn("exception when generate block"); + return BlockProductionCondition.EXCEPTION_PRODUCING_BLOCK; + } - int blockProducedTimeOut = Args.getInstance().getBlockProducedTimeOut(); + int blockProducedTimeOut = Args.getInstance().getBlockProducedTimeOut(); - long timeout = Math - .min(ChainConstant.BLOCK_PRODUCED_INTERVAL * blockProducedTimeOut / 100 + 500, - ChainConstant.BLOCK_PRODUCED_INTERVAL); - if (DateTime.now().getMillis() - now > timeout) { - logger.warn("Task timeout ( > {}ms),startTime:{},endTime:{}", timeout, new DateTime(now), - DateTime.now()); - tronApp.getDbManager().eraseBlock(); - return BlockProductionCondition.TIME_OUT; + long timeout = Math + .min(ChainConstant.BLOCK_PRODUCED_INTERVAL * blockProducedTimeOut / 100 + 500, + ChainConstant.BLOCK_PRODUCED_INTERVAL); + if (DateTime.now().getMillis() - now > timeout) { + logger.warn("Task timeout ( > {}ms),startTime:{},endTime:{}", timeout, new DateTime(now), + DateTime.now()); + tronApp.getDbManager().eraseBlock(); + return BlockProductionCondition.TIME_OUT; + } } logger.info( diff --git a/src/main/java/org/tron/core/services/http/FullNodeHttpApiService.java b/src/main/java/org/tron/core/services/http/FullNodeHttpApiService.java index e32a9edd72e..99e8e270b16 100644 --- a/src/main/java/org/tron/core/services/http/FullNodeHttpApiService.java +++ b/src/main/java/org/tron/core/services/http/FullNodeHttpApiService.java @@ -1,6 +1,7 @@ package org.tron.core.services.http; import lombok.extern.slf4j.Slf4j; +import org.eclipse.jetty.server.ConnectionLimit; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; @@ -274,6 +275,11 @@ public void start() { context.addServlet(new ServletHolder(setAccountServlet), "/setaccountid"); context.addServlet(new ServletHolder(getAccountByIdServlet), "/getaccountbyid"); + int maxHttpConnectNumber = Args.getInstance().getMaxHttpConnectNumber(); + if (maxHttpConnectNumber > 0) { + server.addBean(new ConnectionLimit(maxHttpConnectNumber, server)); + } + server.start(); } catch (Exception e) { logger.debug("IOException: {}", e.getMessage()); diff --git a/src/main/java/org/tron/core/services/http/solidity/SolidityNodeHttpApiService.java b/src/main/java/org/tron/core/services/http/solidity/SolidityNodeHttpApiService.java index b3ea436cadb..c17942501a7 100644 --- a/src/main/java/org/tron/core/services/http/solidity/SolidityNodeHttpApiService.java +++ b/src/main/java/org/tron/core/services/http/solidity/SolidityNodeHttpApiService.java @@ -1,6 +1,7 @@ package org.tron.core.services.http.solidity; import lombok.extern.slf4j.Slf4j; +import org.eclipse.jetty.server.ConnectionLimit; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; @@ -143,6 +144,11 @@ public void start() { context.addServlet(new ServletHolder(getNodeInfoServlet), "/wallet/getnodeinfo"); + int maxHttpConnectNumber = Args.getInstance().getMaxHttpConnectNumber(); + if (maxHttpConnectNumber > 0) { + server.addBean(new ConnectionLimit(maxHttpConnectNumber, server)); + } + server.start(); } catch (Exception e) { logger.debug("IOException: {}", e.getMessage()); diff --git a/src/main/java/org/tron/core/services/interfaceOnSolidity/http/solidity/HttpApiOnSolidityService.java b/src/main/java/org/tron/core/services/interfaceOnSolidity/http/solidity/HttpApiOnSolidityService.java index a014f565ebf..fa92780b525 100644 --- a/src/main/java/org/tron/core/services/interfaceOnSolidity/http/solidity/HttpApiOnSolidityService.java +++ b/src/main/java/org/tron/core/services/interfaceOnSolidity/http/solidity/HttpApiOnSolidityService.java @@ -1,6 +1,7 @@ package org.tron.core.services.interfaceOnSolidity.http.solidity; import lombok.extern.slf4j.Slf4j; +import org.eclipse.jetty.server.ConnectionLimit; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; @@ -130,6 +131,10 @@ public void start() { context.addServlet(new ServletHolder(getNodeInfoOnSolidityServlet), "/wallet/getnodeinfo"); + int maxHttpConnectNumber = Args.getInstance().getMaxHttpConnectNumber(); + if (maxHttpConnectNumber > 0) { + server.addBean(new ConnectionLimit(maxHttpConnectNumber, server)); + } server.start(); } catch (Exception e) { logger.debug("IOException: {}", e.getMessage()); diff --git a/src/main/protos/core/Tron.proto b/src/main/protos/core/Tron.proto index 44fd76831f5..601aab42e27 100644 --- a/src/main/protos/core/Tron.proto +++ b/src/main/protos/core/Tron.proto @@ -338,7 +338,7 @@ message Transaction { repeated Result ret = 5; } -message TransactionResult { +message TransactionInfo { enum code { SUCESS = 0; FAILED = 1; @@ -350,6 +350,8 @@ message TransactionResult { } bytes id = 1; int64 fee = 2; + int64 blockNumber = 3; + int64 blockTimeStamp = 4; repeated bytes contractResult = 5; bytes contract_address = 6; ResourceReceipt receipt = 7; @@ -367,41 +369,10 @@ message TransactionResult { int64 exchange_id = 21; } -message TransactionResultList { +message TransactionRet { int64 blockNumber = 1; int64 blockTimeStamp = 2; - repeated TransactionResult transactionresult = 3; -} - -message TransactionInfo { - enum code { - SUCESS = 0; - FAILED = 1; - } - message Log { - bytes address = 1; - repeated bytes topics = 2; - bytes data = 3; - } - bytes id = 1; - int64 fee = 2; - int64 blockNumber = 3; - int64 blockTimeStamp = 4; - repeated bytes contractResult = 5; - bytes contract_address = 6; - ResourceReceipt receipt = 7; - repeated Log log = 8; - code result = 9; - bytes resMessage = 10; - - string assetIssueID = 14; - int64 withdraw_amount = 15; - int64 unfreeze_amount = 16; - repeated InternalTransaction internal_transactions = 17; - int64 exchange_received_amount = 18; - int64 exchange_inject_another_amount = 19; - int64 exchange_withdraw_another_amount = 20; - int64 exchange_id = 21; + repeated TransactionInfo transactioninfo = 3; } message Transactions { @@ -669,41 +640,6 @@ message NodeInfo { int64 allowAdaptiveEnergy = 19; } - message TransactionResult { - enum code { - SUCESS = 0; - FAILED = 1; - } - message Log { - bytes address = 1; - repeated bytes topics = 2; - bytes data = 3; - } - bytes id = 1; - int64 fee = 2; - repeated bytes contractResult = 5; - bytes contract_address = 6; - ResourceReceipt receipt = 7; - repeated Log log = 8; - code result = 9; - bytes resMessage = 10; - - string assetIssueID = 14; - int64 withdraw_amount = 15; - int64 unfreeze_amount = 16; - repeated InternalTransaction internal_transactions = 17; - int64 exchange_received_amount = 18; - int64 exchange_inject_another_amount = 19; - int64 exchange_withdraw_another_amount = 20; - int64 exchange_id = 21; - } - - message TransactionResultList { - int64 blockNumber = 1; - int64 blockTimeStamp = 2; - repeated TransactionResult transactionresult = 3; - } - message MachineInfo { int32 threadCount = 1; int32 deadLockThreadCount = 2; diff --git a/src/main/resources/config.conf b/src/main/resources/config.conf index 12cf3d269c5..2b3f5d2e5ce 100644 --- a/src/main/resources/config.conf +++ b/src/main/resources/config.conf @@ -122,6 +122,8 @@ node { minParticipationRate = 15 + maxHttpConnectNumber = 50 + # check the peer data transfer ,disconnect factor disconnectNumberFactor = 0.4 maxConnectNumberFactor = 0.8 From a4bf5661688dfa1725aa404d90a40267648cd285 Mon Sep 17 00:00:00 2001 From: wubin1 Date: Mon, 3 Jun 2019 17:16:21 +0800 Subject: [PATCH 36/90] remove unuse line --- sharttmp.sh | 0 src/main/java/org/tron/core/db/Manager.java | 5 ----- 2 files changed, 5 deletions(-) delete mode 100644 sharttmp.sh diff --git a/sharttmp.sh b/sharttmp.sh deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/src/main/java/org/tron/core/db/Manager.java b/src/main/java/org/tron/core/db/Manager.java index 66eb7de3df4..032444c19aa 100644 --- a/src/main/java/org/tron/core/db/Manager.java +++ b/src/main/java/org/tron/core/db/Manager.java @@ -1537,14 +1537,9 @@ public void processBlock(BlockCapsule block) transactionCapsule.setVerified(true); } accountStateCallBack.preExeTrans(); -<<<<<<< HEAD TransactionInfo result = processTransaction(transactionCapsule, block); accountStateCallBack.exeTransFinish(); Optional.ofNullable(result).ifPresent(t -> transationRetCapsule.addTransactionInfo(result)); -======= - processTransaction(transactionCapsule, block); - accountStateCallBack.exeTransFinish(); ->>>>>>> e9e78b056b0380e6ae141c0f9ba0baef1348936c } accountStateCallBack.executePushFinish(); } finally { From 50ac43a1314839b5eaf21cd1853e3e72ddc337cc Mon Sep 17 00:00:00 2001 From: wubin01 Date: Tue, 4 Jun 2019 15:14:54 +0800 Subject: [PATCH 37/90] modify block message handle log --- .../core/net/messagehandler/BlockMsgHandler.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java b/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java index bf8c89d60a5..06c2fa7e482 100644 --- a/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java +++ b/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java @@ -3,7 +3,9 @@ import static org.tron.core.config.Parameter.ChainConstant.BLOCK_PRODUCED_INTERVAL; import static org.tron.core.config.Parameter.ChainConstant.BLOCK_SIZE; +import com.google.protobuf.ByteString; import lombok.extern.slf4j.Slf4j; +import org.spongycastle.util.encoders.Hex; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.core.capsule.BlockCapsule; @@ -61,11 +63,12 @@ public void processMessage(PeerConnection peer, TronMessage msg) throws P2pExcep syncService.processBlock(peer, blockMessage); } else { Long time = peer.getAdvInvRequest().remove(item); - if (time != null) { - logger.info("Receive block {} from {}, cost {}ms", blockId.getString(), - peer.getInetAddress(), - System.currentTimeMillis() - time); - } + long cost = time == null ? 0 : System.currentTimeMillis() - time; + logger.info("Receive block {}, witness: {} from {}, fetch cost {}ms", + blockId.getString(), + Hex.toHexString(blockMessage.getBlockCapsule().getWitnessAddress().toByteArray()), + peer.getInetAddress(), + cost); processBlock(peer, blockMessage.getBlockCapsule()); } } @@ -97,7 +100,7 @@ private void processBlock(PeerConnection peer, BlockCapsule block) throws P2pExc long headNum = tronNetDelegate.getHeadBlockId().getNum(); if (block.getNum() <= headNum) { - logger.info("Receive block num {} <= head num {}, from peer {}", + logger.warn("Receive block num {} <= head num {}, from peer {}", block.getNum(), headNum, peer.getInetAddress()); } From 80adc84b8513a8c3cb746fc1e67471283057bdf4 Mon Sep 17 00:00:00 2001 From: wubin01 Date: Wed, 5 Jun 2019 11:21:07 +0800 Subject: [PATCH 38/90] modify sonar problem --- .../java/org/tron/common/overlay/server/FastForward.java | 4 +--- .../java/org/tron/common/overlay/server/P2pHandler.java | 5 +---- src/main/java/org/tron/core/net/TronNetDelegate.java | 7 ++----- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/tron/common/overlay/server/FastForward.java b/src/main/java/org/tron/common/overlay/server/FastForward.java index cde93ec54e5..8c9a7e0a001 100644 --- a/src/main/java/org/tron/common/overlay/server/FastForward.java +++ b/src/main/java/org/tron/common/overlay/server/FastForward.java @@ -26,8 +26,6 @@ public class FastForward { @Autowired private ApplicationContext ctx; - private WitnessScheduleStore witnessScheduleStore; - private ChannelManager channelManager; private BackupManager backupManager; @@ -49,9 +47,9 @@ public void init() { return; } - witnessScheduleStore = ctx.getBean(WitnessScheduleStore.class); channelManager = ctx.getBean(ChannelManager.class); backupManager = ctx.getBean(BackupManager.class); + WitnessScheduleStore witnessScheduleStore = ctx.getBean(WitnessScheduleStore.class); executorService.scheduleWithFixedDelay(() -> { try { diff --git a/src/main/java/org/tron/common/overlay/server/P2pHandler.java b/src/main/java/org/tron/common/overlay/server/P2pHandler.java index a80169f5339..3346506396d 100644 --- a/src/main/java/org/tron/common/overlay/server/P2pHandler.java +++ b/src/main/java/org/tron/common/overlay/server/P2pHandler.java @@ -33,13 +33,10 @@ public class P2pHandler extends SimpleChannelInboundHandler { private volatile boolean hasPing = false; - private volatile long sendPingTime; - @Override - public void handlerAdded(ChannelHandlerContext ctx) throws Exception { + public void handlerAdded(ChannelHandlerContext ctx) { pingTask = pingTimer.scheduleAtFixedRate(() -> { if (!hasPing) { - sendPingTime = System.currentTimeMillis(); hasPing = msgQueue.sendMessage(PING_MESSAGE); } }, 10, 10, TimeUnit.SECONDS); diff --git a/src/main/java/org/tron/core/net/TronNetDelegate.java b/src/main/java/org/tron/core/net/TronNetDelegate.java index da170016627..962bda538ca 100644 --- a/src/main/java/org/tron/core/net/TronNetDelegate.java +++ b/src/main/java/org/tron/core/net/TronNetDelegate.java @@ -216,11 +216,8 @@ public void pushTransaction(TransactionCapsule trx) throws P2pException { public boolean validBlock(BlockCapsule block) throws P2pException { try { - if (!block.validateSignature(dbManager) || - !witnessScheduleStore.getActiveWitnesses().contains(block.getWitnessAddress())) { - return false; - } - return true; + return witnessScheduleStore.getActiveWitnesses().contains(block.getWitnessAddress()) + && block.validateSignature(dbManager); } catch (ValidateSignatureException e) { throw new P2pException(TypeEnum.BAD_BLOCK, e); } From 75d270910e72bf9ef446bea033d181dfff53d69a Mon Sep 17 00:00:00 2001 From: wubin01 Date: Wed, 5 Jun 2019 15:21:09 +0800 Subject: [PATCH 39/90] add witness to trustNode --- src/main/java/org/tron/common/overlay/server/Channel.java | 2 +- .../org/tron/common/overlay/server/ChannelManager.java | 4 ++-- .../java/org/tron/common/overlay/server/FastForward.java | 3 +-- .../org/tron/common/overlay/server/HandshakeHandler.java | 2 +- src/main/java/org/tron/core/net/TronNetDelegate.java | 8 ++++++++ .../org/tron/core/net/messagehandler/BlockMsgHandler.java | 1 + 6 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/tron/common/overlay/server/Channel.java b/src/main/java/org/tron/common/overlay/server/Channel.java index 20cc1465ecb..66b30c1cf7b 100644 --- a/src/main/java/org/tron/common/overlay/server/Channel.java +++ b/src/main/java/org/tron/common/overlay/server/Channel.java @@ -106,7 +106,7 @@ public void init(ChannelPipeline pipeline, String remoteId, boolean discoveryMod } public void publicHandshakeFinished(ChannelHandlerContext ctx, HelloMessage msg) { - isTrustPeer = channelManager.getTrustNodes().containsKey(getInetAddress()); + isTrustPeer = channelManager.getTrustNodes().getIfPresent(getInetAddress()) != null; isFastForwardPeer = channelManager.getFastForwardNodes().containsKey(getInetAddress()); ctx.pipeline().remove(handshakeHandler); msgQueue.activate(ctx); diff --git a/src/main/java/org/tron/common/overlay/server/ChannelManager.java b/src/main/java/org/tron/common/overlay/server/ChannelManager.java index b558c91b31b..d0565295080 100644 --- a/src/main/java/org/tron/common/overlay/server/ChannelManager.java +++ b/src/main/java/org/tron/common/overlay/server/ChannelManager.java @@ -50,7 +50,7 @@ public class ChannelManager { .maximumSize(1000).expireAfterWrite(30, TimeUnit.SECONDS).recordStats().build(); @Getter - private Map trustNodes = new ConcurrentHashMap(); + private Cache trustNodes = CacheBuilder.newBuilder().maximumSize(100).build(); @Getter private Map activeNodes = new ConcurrentHashMap(); @@ -126,7 +126,7 @@ public void notifyDisconnect(Channel channel) { public synchronized boolean processPeer(Channel peer) { - if (!trustNodes.containsKey(peer.getInetAddress())) { + if (trustNodes.getIfPresent(peer.getInetAddress()) == null) { if (recentlyDisconnected.getIfPresent(peer) != null) { logger.info("Peer {} recently disconnected.", peer.getInetAddress()); return false; diff --git a/src/main/java/org/tron/common/overlay/server/FastForward.java b/src/main/java/org/tron/common/overlay/server/FastForward.java index 8c9a7e0a001..37b539b19c1 100644 --- a/src/main/java/org/tron/common/overlay/server/FastForward.java +++ b/src/main/java/org/tron/common/overlay/server/FastForward.java @@ -54,8 +54,7 @@ public void init() { executorService.scheduleWithFixedDelay(() -> { try { if (witnessScheduleStore.getActiveWitnesses().contains(witnessAddress) && - backupManager.getStatus().equals(BackupStatusEnum.MASTER) && - !WitnessService.isNeedSyncCheck()) { + backupManager.getStatus().equals(BackupStatusEnum.MASTER)) { connect(); } else { disconnect(); diff --git a/src/main/java/org/tron/common/overlay/server/HandshakeHandler.java b/src/main/java/org/tron/common/overlay/server/HandshakeHandler.java index 05760377ed1..9f9a6b54708 100644 --- a/src/main/java/org/tron/common/overlay/server/HandshakeHandler.java +++ b/src/main/java/org/tron/common/overlay/server/HandshakeHandler.java @@ -123,7 +123,7 @@ private void handleHelloMsg(ChannelHandlerContext ctx, HelloMessage msg) { if (remoteId.length != 64) { InetAddress address = ((InetSocketAddress) ctx.channel().remoteAddress()).getAddress(); - if (!channelManager.getTrustNodes().keySet().contains(address) && !syncPool.isCanConnect()) { + if (channelManager.getTrustNodes().getIfPresent(address) == null && !syncPool.isCanConnect()) { channel.disconnect(ReasonCode.TOO_MANY_PEERS); return; } diff --git a/src/main/java/org/tron/core/net/TronNetDelegate.java b/src/main/java/org/tron/core/net/TronNetDelegate.java index 962bda538ca..f9a38aba7ec 100644 --- a/src/main/java/org/tron/core/net/TronNetDelegate.java +++ b/src/main/java/org/tron/core/net/TronNetDelegate.java @@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.common.overlay.message.Message; +import org.tron.common.overlay.server.ChannelManager; import org.tron.common.overlay.server.SyncPool; import org.tron.common.utils.Sha256Hash; import org.tron.core.capsule.BlockCapsule; @@ -51,6 +52,9 @@ public class TronNetDelegate { @Autowired private SyncPool syncPool; + @Autowired + private ChannelManager channelManager; + @Autowired private Manager dbManager; @@ -72,6 +76,10 @@ public boolean offer(BlockId blockId) { } }; + public void trustNode (PeerConnection peer) { + channelManager.getTrustNodes().put(peer.getInetAddress(), peer.getNode()); + } + public Collection getActivePeer() { return syncPool.getActivePeers(); } diff --git a/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java b/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java index 06c2fa7e482..1f89ff564bb 100644 --- a/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java +++ b/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java @@ -110,6 +110,7 @@ private void processBlock(PeerConnection peer, BlockCapsule block) throws P2pExc } if (tronNetDelegate.validBlock(block)) { advService.fastForward(new BlockMessage(block)); + tronNetDelegate.trustNode(peer); } } From e273b3a350de4b1f054dd435a2406cf795337a55 Mon Sep 17 00:00:00 2001 From: wubin01 Date: Wed, 5 Jun 2019 15:50:47 +0800 Subject: [PATCH 40/90] add fastforwad node note --- src/main/java/org/tron/core/net/peer/PeerConnection.java | 9 ++++----- src/main/java/org/tron/core/net/service/AdvService.java | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/tron/core/net/peer/PeerConnection.java b/src/main/java/org/tron/core/net/peer/PeerConnection.java index 0bf553d9c04..f1fb61baab4 100644 --- a/src/main/java/org/tron/core/net/peer/PeerConnection.java +++ b/src/main/java/org/tron/core/net/peer/PeerConnection.java @@ -43,10 +43,6 @@ public class PeerConnection extends Channel { @Autowired private AdvService advService; - @Setter - @Getter - private BlockId signUpErrorBlockId; - @Setter @Getter private HelloMessage helloMessage; @@ -67,6 +63,9 @@ public class PeerConnection extends Channel { @Getter private Map advInvRequest = new ConcurrentHashMap<>(); + @Setter + private BlockId fastForwardBlock; + @Getter private BlockId blockBothHave = new BlockId(); @@ -195,7 +194,7 @@ public String log() { getNodeStatistics().pingMessageLatency.getLast(), (now - getStartTime()) / 1000, - blockBothHave.getNum(), + fastForwardBlock != null ? fastForwardBlock.getNum() : blockBothHave.getNum(), isNeedSyncFromPeer(), isNeedSyncFromUs(), syncBlockToFetch.size(), diff --git a/src/main/java/org/tron/core/net/service/AdvService.java b/src/main/java/org/tron/core/net/service/AdvService.java index f2817a132ff..96edd1c2274 100644 --- a/src/main/java/org/tron/core/net/service/AdvService.java +++ b/src/main/java/org/tron/core/net/service/AdvService.java @@ -188,7 +188,7 @@ public void fastForward(BlockMessage msg) { peers.forEach(peer -> { peer.sendMessage(msg); peer.getAdvInvSpread().put(item, System.currentTimeMillis()); - peer.setBlockBothHave(msg.getBlockId()); + peer.setFastForwardBlock(msg.getBlockId()); }); } From a3b417b25b227125116733dbd0d461d3f4f97669 Mon Sep 17 00:00:00 2001 From: wubin1 Date: Wed, 5 Jun 2019 15:34:05 +0800 Subject: [PATCH 41/90] fix bug --- src/main/java/org/tron/core/Wallet.java | 2 +- src/main/java/org/tron/core/db/Manager.java | 4 +++- src/main/java/org/tron/core/db/TransactionRetStore.java | 2 +- src/main/java/org/tron/core/db/TransactionStore.java | 8 ++++---- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/tron/core/Wallet.java b/src/main/java/org/tron/core/Wallet.java index 52b1a532ea2..43eec4079ad 100755 --- a/src/main/java/org/tron/core/Wallet.java +++ b/src/main/java/org/tron/core/Wallet.java @@ -1245,7 +1245,7 @@ public TransactionInfo getTransactionInfoById(ByteString transactionId) { return null; } - return transactionInfoCapsule.getInstance(); + return transactionInfoCapsule == null ? null : transactionInfoCapsule.getInstance(); } public Proposal getProposalById(ByteString proposalId) { diff --git a/src/main/java/org/tron/core/db/Manager.java b/src/main/java/org/tron/core/db/Manager.java index 032444c19aa..ec49449d071 100644 --- a/src/main/java/org/tron/core/db/Manager.java +++ b/src/main/java/org/tron/core/db/Manager.java @@ -1539,7 +1539,9 @@ public void processBlock(BlockCapsule block) accountStateCallBack.preExeTrans(); TransactionInfo result = processTransaction(transactionCapsule, block); accountStateCallBack.exeTransFinish(); - Optional.ofNullable(result).ifPresent(t -> transationRetCapsule.addTransactionInfo(result)); + if (Objects.nonNull(result)) { + transationRetCapsule.addTransactionInfo(result); + } } accountStateCallBack.executePushFinish(); } finally { diff --git a/src/main/java/org/tron/core/db/TransactionRetStore.java b/src/main/java/org/tron/core/db/TransactionRetStore.java index c6100c75a1c..5a4794371f6 100644 --- a/src/main/java/org/tron/core/db/TransactionRetStore.java +++ b/src/main/java/org/tron/core/db/TransactionRetStore.java @@ -33,7 +33,7 @@ public TransactionInfoCapsule getTransactionInfo(byte[] key) throws BadItemExcep } byte[] value = revokingDB.getUnchecked(ByteArray.fromLong(blockNumber)); TransactionRetCapsule result = new TransactionRetCapsule(value); - if (Objects.isNull(result)) { + if (Objects.isNull(result) || Objects.isNull(result.getInstance())) { return null; } for (TransactionInfo transactionResultInfo : result.getInstance().getTransactioninfoList()) { diff --git a/src/main/java/org/tron/core/db/TransactionStore.java b/src/main/java/org/tron/core/db/TransactionStore.java index c29f707d0c9..14931ecd4e7 100644 --- a/src/main/java/org/tron/core/db/TransactionStore.java +++ b/src/main/java/org/tron/core/db/TransactionStore.java @@ -67,17 +67,17 @@ private TransactionCapsule getTransactionFromKhaosDatabase(byte[] key, long high return null; } - public long getBlockNumber(byte[] key) { + public long getBlockNumber(byte[] key) throws BadItemException { byte[] value = revokingDB.getUnchecked(key); if (ArrayUtils.isEmpty(value)) { return -1; } - TransactionCapsule transactionCapsule = null; + if (value.length == 8) { return ByteArray.toLong(value); } - - return transactionCapsule == null ? -1 : transactionCapsule.getBlockNum(); + TransactionCapsule transactionCapsule = new TransactionCapsule(value); + return transactionCapsule.getBlockNum(); } @Override From 4c326abd217647031f5f2bd87a72f781a56e4393 Mon Sep 17 00:00:00 2001 From: wubin1 Date: Wed, 5 Jun 2019 17:50:57 +0800 Subject: [PATCH 42/90] add input null check --- src/main/java/org/tron/core/db/Manager.java | 1 + src/test/java/org/tron/core/WalletTest.java | 42 +++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/src/main/java/org/tron/core/db/Manager.java b/src/main/java/org/tron/core/db/Manager.java index ec49449d071..314916c7961 100644 --- a/src/main/java/org/tron/core/db/Manager.java +++ b/src/main/java/org/tron/core/db/Manager.java @@ -1776,6 +1776,7 @@ public void closeAllStore() { closeOneStore(delegatedResourceAccountIndexStore); closeOneStore(assetIssueV2Store); closeOneStore(exchangeV2Store); + closeOneStore(transactionRetStore); logger.info("******** end to close db ********"); } diff --git a/src/test/java/org/tron/core/WalletTest.java b/src/test/java/org/tron/core/WalletTest.java index ef4beba632c..f445c228787 100644 --- a/src/test/java/org/tron/core/WalletTest.java +++ b/src/test/java/org/tron/core/WalletTest.java @@ -47,11 +47,15 @@ import org.tron.core.capsule.ExchangeCapsule; import org.tron.core.capsule.ProposalCapsule; import org.tron.core.capsule.TransactionCapsule; +import org.tron.core.capsule.TransactionInfoCapsule; +import org.tron.core.capsule.TransactionRetCapsule; import org.tron.core.config.DefaultConfig; import org.tron.core.config.Parameter.ChainParameters; import org.tron.core.config.args.Args; import org.tron.core.db.DynamicPropertiesStore; import org.tron.core.db.Manager; +import org.tron.core.db.TransactionRetStore; +import org.tron.core.db.TransactionTrace; import org.tron.protos.Contract.AssetIssueContract; import org.tron.protos.Contract.TransferContract; import org.tron.protos.Protocol; @@ -64,6 +68,7 @@ import org.tron.protos.Protocol.Transaction; import org.tron.protos.Protocol.Transaction.Contract; import org.tron.protos.Protocol.Transaction.Contract.ContractType; +import org.tron.protos.Protocol.TransactionInfo; @Slf4j public class WalletTest { @@ -134,22 +139,27 @@ private static void initTransaction() { getBuildTransferContract(ACCOUNT_ADDRESS_ONE, ACCOUNT_ADDRESS_TWO), TRANSACTION_TIMESTAMP_ONE, BLOCK_NUM_ONE); addTransactionToStore(transaction1); + transaction2 = getBuildTransaction( getBuildTransferContract(ACCOUNT_ADDRESS_TWO, ACCOUNT_ADDRESS_THREE), TRANSACTION_TIMESTAMP_TWO, BLOCK_NUM_TWO); addTransactionToStore(transaction2); + transaction3 = getBuildTransaction( getBuildTransferContract(ACCOUNT_ADDRESS_THREE, ACCOUNT_ADDRESS_FOUR), TRANSACTION_TIMESTAMP_THREE, BLOCK_NUM_THREE); addTransactionToStore(transaction3); + transaction4 = getBuildTransaction( getBuildTransferContract(ACCOUNT_ADDRESS_FOUR, ACCOUNT_ADDRESS_FIVE), TRANSACTION_TIMESTAMP_FOUR, BLOCK_NUM_FOUR); addTransactionToStore(transaction4); + transaction5 = getBuildTransaction( getBuildTransferContract(ACCOUNT_ADDRESS_FIVE, ACCOUNT_ADDRESS_ONE), TRANSACTION_TIMESTAMP_FIVE, BLOCK_NUM_FIVE); addTransactionToStore(transaction5); + transaction6 = getBuildTransaction( getBuildTransferContract(ACCOUNT_ADDRESS_ONE, ACCOUNT_ADDRESS_SIX), TRANSACTION_TIMESTAMP_FIVE, BLOCK_NUM_FIVE); @@ -162,6 +172,15 @@ private static void addTransactionToStore(Transaction transaction) { .put(transactionCapsule.getTransactionId().getBytes(), transactionCapsule); } + private static void addTransactionInfoToStore(Transaction transaction, TransactionRetCapsule transactionRetCapsule) { + TransactionInfoCapsule transactionInfo = new TransactionInfoCapsule(); + transactionInfo.setId(transaction.getRawData().toByteArray()); + transactionRetCapsule.addTransactionInfo(transactionInfo.getInstance()); + manager.getTransactionHistoryStore() + .put(transactionInfo.getId(), transactionInfo); + } + + private static Transaction getBuildTransaction( TransferContract transferContract, long transactionTimestamp, long refBlockNum) { return Transaction.newBuilder().setRawData( @@ -186,19 +205,32 @@ private static void initBlock() { block1 = getBuildBlock(BLOCK_TIMESTAMP_ONE, BLOCK_NUM_ONE, BLOCK_WITNESS_ONE, ACCOUNT_ADDRESS_ONE, transaction1, transaction2); + TransactionRetCapsule transationRetCapsule = + new TransactionRetCapsule(new BlockCapsule(block1)); + addBlockToStore(block1); + addTransactionInfoToStore(transaction1, transationRetCapsule); + block2 = getBuildBlock(BLOCK_TIMESTAMP_TWO, BLOCK_NUM_TWO, BLOCK_WITNESS_TWO, ACCOUNT_ADDRESS_TWO, transaction2, transaction3); addBlockToStore(block2); + addTransactionInfoToStore(transaction2, transationRetCapsule); + block3 = getBuildBlock(BLOCK_TIMESTAMP_THREE, BLOCK_NUM_THREE, BLOCK_WITNESS_THREE, ACCOUNT_ADDRESS_THREE, transaction2, transaction4); addBlockToStore(block3); + addTransactionInfoToStore(transaction3, transationRetCapsule); + block4 = getBuildBlock(BLOCK_TIMESTAMP_FOUR, BLOCK_NUM_FOUR, BLOCK_WITNESS_FOUR, ACCOUNT_ADDRESS_FOUR, transaction4, transaction5); addBlockToStore(block4); + addTransactionInfoToStore(transaction4, transationRetCapsule); + block5 = getBuildBlock(BLOCK_TIMESTAMP_FIVE, BLOCK_NUM_FIVE, BLOCK_WITNESS_FIVE, ACCOUNT_ADDRESS_FIVE, transaction5, transaction3); addBlockToStore(block5); + addTransactionInfoToStore(transaction5, transationRetCapsule); + manager.getTransactionRetStore().put(ByteArray.fromLong(new BlockCapsule(block1).getNum()), transationRetCapsule); } private static void addBlockToStore(Block block) { @@ -336,6 +368,16 @@ public void getBlocksByLimit() { Assert.assertFalse("getBlocksByLimit8", blocksByLimit.getBlockList().contains(block5)); } + @Test + public void getTransactionInfoById() { + TransactionInfo transactionById = wallet.getTransactionInfoById( + ByteString + .copyFrom(new TransactionCapsule(transaction1).getTransactionId().getBytes())); + + Assert.assertEquals("gettransactioninfobyid", transactionById.getId().toByteArray(), + new TransactionCapsule(transaction1).getTransactionId().getBytes()); + } + @Ignore @Test public void getTransactionById() { From 5473c667fea0161f08b163536a73fa07654b719f Mon Sep 17 00:00:00 2001 From: wubin1 Date: Thu, 6 Jun 2019 11:29:36 +0800 Subject: [PATCH 43/90] add unit test --- src/test/java/org/tron/core/WalletTest.java | 55 ++++++++++++++------- 1 file changed, 37 insertions(+), 18 deletions(-) diff --git a/src/test/java/org/tron/core/WalletTest.java b/src/test/java/org/tron/core/WalletTest.java index f445c228787..4a10ffec558 100644 --- a/src/test/java/org/tron/core/WalletTest.java +++ b/src/test/java/org/tron/core/WalletTest.java @@ -56,6 +56,7 @@ import org.tron.core.db.Manager; import org.tron.core.db.TransactionRetStore; import org.tron.core.db.TransactionTrace; +import org.tron.core.exception.BadItemException; import org.tron.protos.Contract.AssetIssueContract; import org.tron.protos.Contract.TransferContract; import org.tron.protos.Protocol; @@ -172,12 +173,11 @@ private static void addTransactionToStore(Transaction transaction) { .put(transactionCapsule.getTransactionId().getBytes(), transactionCapsule); } - private static void addTransactionInfoToStore(Transaction transaction, TransactionRetCapsule transactionRetCapsule) { + private static void addTransactionInfoToStore(Transaction transaction) { TransactionInfoCapsule transactionInfo = new TransactionInfoCapsule(); - transactionInfo.setId(transaction.getRawData().toByteArray()); - transactionRetCapsule.addTransactionInfo(transactionInfo.getInstance()); - manager.getTransactionHistoryStore() - .put(transactionInfo.getId(), transactionInfo); + byte[] trxId = transaction.getRawData().toByteArray(); + transactionInfo.setId(trxId); + manager.getTransactionHistoryStore().put(trxId, transactionInfo); } @@ -205,32 +205,28 @@ private static void initBlock() { block1 = getBuildBlock(BLOCK_TIMESTAMP_ONE, BLOCK_NUM_ONE, BLOCK_WITNESS_ONE, ACCOUNT_ADDRESS_ONE, transaction1, transaction2); - TransactionRetCapsule transationRetCapsule = - new TransactionRetCapsule(new BlockCapsule(block1)); - addBlockToStore(block1); - addTransactionInfoToStore(transaction1, transationRetCapsule); + addTransactionInfoToStore(transaction1); block2 = getBuildBlock(BLOCK_TIMESTAMP_TWO, BLOCK_NUM_TWO, BLOCK_WITNESS_TWO, ACCOUNT_ADDRESS_TWO, transaction2, transaction3); addBlockToStore(block2); - addTransactionInfoToStore(transaction2, transationRetCapsule); + addTransactionInfoToStore(transaction2); block3 = getBuildBlock(BLOCK_TIMESTAMP_THREE, BLOCK_NUM_THREE, BLOCK_WITNESS_THREE, ACCOUNT_ADDRESS_THREE, transaction2, transaction4); addBlockToStore(block3); - addTransactionInfoToStore(transaction3, transationRetCapsule); + addTransactionInfoToStore(transaction3); block4 = getBuildBlock(BLOCK_TIMESTAMP_FOUR, BLOCK_NUM_FOUR, BLOCK_WITNESS_FOUR, ACCOUNT_ADDRESS_FOUR, transaction4, transaction5); addBlockToStore(block4); - addTransactionInfoToStore(transaction4, transationRetCapsule); + addTransactionInfoToStore(transaction4); block5 = getBuildBlock(BLOCK_TIMESTAMP_FIVE, BLOCK_NUM_FIVE, BLOCK_WITNESS_FIVE, ACCOUNT_ADDRESS_FIVE, transaction5, transaction3); addBlockToStore(block5); - addTransactionInfoToStore(transaction5, transationRetCapsule); - manager.getTransactionRetStore().put(ByteArray.fromLong(new BlockCapsule(block1).getNum()), transationRetCapsule); + addTransactionInfoToStore(transaction5); } private static void addBlockToStore(Block block) { @@ -370,12 +366,35 @@ public void getBlocksByLimit() { @Test public void getTransactionInfoById() { - TransactionInfo transactionById = wallet.getTransactionInfoById( + TransactionInfo transactionById1 = wallet.getTransactionInfoById( ByteString - .copyFrom(new TransactionCapsule(transaction1).getTransactionId().getBytes())); + .copyFrom(transaction1.getRawData().toByteArray())); + Assert.assertEquals("gettransactioninfobyid", ByteString.copyFrom(transactionById1.getId().toByteArray()), + ByteString.copyFrom(transaction1.getRawData().toByteArray())); - Assert.assertEquals("gettransactioninfobyid", transactionById.getId().toByteArray(), - new TransactionCapsule(transaction1).getTransactionId().getBytes()); + TransactionInfo transactionById2 = wallet.getTransactionInfoById( + ByteString + .copyFrom(transaction2.getRawData().toByteArray())); + Assert.assertEquals("gettransactioninfobyid", ByteString.copyFrom(transactionById2.getId().toByteArray()), + ByteString.copyFrom(transaction2.getRawData().toByteArray())); + + TransactionInfo transactionById3 = wallet.getTransactionInfoById( + ByteString + .copyFrom(transaction3.getRawData().toByteArray())); + Assert.assertEquals("gettransactioninfobyid", ByteString.copyFrom(transactionById3.getId().toByteArray()), + ByteString.copyFrom(transaction3.getRawData().toByteArray())); + + TransactionInfo transactionById4 = wallet.getTransactionInfoById( + ByteString + .copyFrom(transaction4.getRawData().toByteArray())); + Assert.assertEquals("gettransactioninfobyid", ByteString.copyFrom(transactionById4.getId().toByteArray()), + ByteString.copyFrom(transaction4.getRawData().toByteArray())); + + TransactionInfo transactionById5 = wallet.getTransactionInfoById( + ByteString + .copyFrom(transaction5.getRawData().toByteArray())); + Assert.assertEquals("gettransactioninfobyid", ByteString.copyFrom(transactionById5.getId().toByteArray()), + ByteString.copyFrom(transaction5.getRawData().toByteArray())); } @Ignore From 33faedd594675dd2ea15e3b9d115dab602fb0bc2 Mon Sep 17 00:00:00 2001 From: wubin01 Date: Thu, 6 Jun 2019 17:22:18 +0800 Subject: [PATCH 44/90] modify fastForward logic --- .../java/org/tron/core/net/TronNetDelegate.java | 7 +++++++ .../core/net/messagehandler/BlockMsgHandler.java | 15 +++++---------- .../org/tron/core/net/service/AdvService.java | 1 + 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/tron/core/net/TronNetDelegate.java b/src/main/java/org/tron/core/net/TronNetDelegate.java index f9a38aba7ec..ffa9d57c85a 100644 --- a/src/main/java/org/tron/core/net/TronNetDelegate.java +++ b/src/main/java/org/tron/core/net/TronNetDelegate.java @@ -6,6 +6,7 @@ import java.util.concurrent.ConcurrentLinkedQueue; import lombok.Getter; import lombok.extern.slf4j.Slf4j; +import org.spongycastle.util.encoders.Hex; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.tron.common.overlay.message.Message; @@ -177,6 +178,12 @@ public void processBlock(BlockCapsule block) throws P2pException { synchronized (blockLock) { try { if (!freshBlockId.contains(block.getBlockId())) { + if (block.getNum() <= getHeadBlockId().getNum() && !containBlock(block.getBlockId())) { + logger.warn("Receive a fork block {} witness {}, head block {}", + Hex.toHexString(block.getWitnessAddress().toByteArray()), + block.getBlockId().getString(), + getHeadBlockId().getString()); + } dbManager.pushBlock(block); freshBlockId.add(block.getBlockId()); logger.info("Success process block {}.", block.getBlockId().getString()); diff --git a/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java b/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java index 1f89ff564bb..fb5ccffd462 100644 --- a/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java +++ b/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java @@ -52,9 +52,7 @@ public void processMessage(PeerConnection peer, TronMessage msg) throws P2pExcep BlockId blockId = blockMessage.getBlockId(); Item item = new Item(blockId, InventoryType.BLOCK); - if (fastForward || peer.isFastForwardPeer()) { - peer.getAdvInvReceive().put(item, System.currentTimeMillis()); - } else { + if (!fastForward && !peer.isFastForwardPeer()) { check(peer, blockMessage); } @@ -98,18 +96,15 @@ private void processBlock(PeerConnection peer, BlockCapsule block) throws P2pExc return; } - long headNum = tronNetDelegate.getHeadBlockId().getNum(); - if (block.getNum() <= headNum) { - logger.warn("Receive block num {} <= head num {}, from peer {}", - block.getNum(), headNum, peer.getInetAddress()); - } - if (fastForward) { - if (headNum - block.getNum() > threshold) { + if (tronNetDelegate.getHeadBlockId().getNum() - block.getNum() > threshold) { + logger.warn("Receive a low block {}, Head {}", + blockId.getString(), tronNetDelegate.getHeadBlockId().getString()); return; } if (tronNetDelegate.validBlock(block)) { advService.fastForward(new BlockMessage(block)); + peer.getAdvInvReceive().put(new Item(blockId, InventoryType.BLOCK), System.currentTimeMillis()); tronNetDelegate.trustNode(peer); } } diff --git a/src/main/java/org/tron/core/net/service/AdvService.java b/src/main/java/org/tron/core/net/service/AdvService.java index 96edd1c2274..2ba8e60da2d 100644 --- a/src/main/java/org/tron/core/net/service/AdvService.java +++ b/src/main/java/org/tron/core/net/service/AdvService.java @@ -175,6 +175,7 @@ public void broadcast(Message msg) { public void fastForward(BlockMessage msg) { Item item = new Item(msg.getBlockId(), InventoryType.BLOCK); + invToFetch.put(item, System.currentTimeMillis()); List peers = tronNetDelegate.getActivePeer().stream() .filter(peer -> !peer.isNeedSyncFromPeer() && !peer.isNeedSyncFromUs()) .filter(peer -> peer.getAdvInvReceive().getIfPresent(item) == null From 184fe50d112797f3454adf5b6da114671f74ca0b Mon Sep 17 00:00:00 2001 From: wubin01 Date: Thu, 6 Jun 2019 17:25:44 +0800 Subject: [PATCH 45/90] modify fastForward logic --- .../java/org/tron/core/net/messagehandler/BlockMsgHandler.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java b/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java index fb5ccffd462..dd7dcbde60d 100644 --- a/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java +++ b/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java @@ -103,8 +103,9 @@ private void processBlock(PeerConnection peer, BlockCapsule block) throws P2pExc return; } if (tronNetDelegate.validBlock(block)) { + peer.getAdvInvReceive() + .put(new Item(blockId, InventoryType.BLOCK), System.currentTimeMillis()); advService.fastForward(new BlockMessage(block)); - peer.getAdvInvReceive().put(new Item(blockId, InventoryType.BLOCK), System.currentTimeMillis()); tronNetDelegate.trustNode(peer); } } From 8ee72537855adb2c44053034847f54161fa0a90e Mon Sep 17 00:00:00 2001 From: wubin01 Date: Thu, 6 Jun 2019 17:27:57 +0800 Subject: [PATCH 46/90] modify fastForward logic --- src/main/java/org/tron/core/net/service/AdvService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/tron/core/net/service/AdvService.java b/src/main/java/org/tron/core/net/service/AdvService.java index 2ba8e60da2d..e9a240243f4 100644 --- a/src/main/java/org/tron/core/net/service/AdvService.java +++ b/src/main/java/org/tron/core/net/service/AdvService.java @@ -175,7 +175,8 @@ public void broadcast(Message msg) { public void fastForward(BlockMessage msg) { Item item = new Item(msg.getBlockId(), InventoryType.BLOCK); - invToFetch.put(item, System.currentTimeMillis()); + invToFetchCache.put(item, System.currentTimeMillis()); + invToFetch.remove(item); List peers = tronNetDelegate.getActivePeer().stream() .filter(peer -> !peer.isNeedSyncFromPeer() && !peer.isNeedSyncFromUs()) .filter(peer -> peer.getAdvInvReceive().getIfPresent(item) == null From 41adb1a43a0e9a41470db6eaa8d0d81d19b7dae7 Mon Sep 17 00:00:00 2001 From: wubin01 Date: Thu, 6 Jun 2019 17:33:40 +0800 Subject: [PATCH 47/90] modify processblock log logic --- src/main/java/org/tron/core/net/TronNetDelegate.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/tron/core/net/TronNetDelegate.java b/src/main/java/org/tron/core/net/TronNetDelegate.java index ffa9d57c85a..c9143fc7fbd 100644 --- a/src/main/java/org/tron/core/net/TronNetDelegate.java +++ b/src/main/java/org/tron/core/net/TronNetDelegate.java @@ -178,7 +178,7 @@ public void processBlock(BlockCapsule block) throws P2pException { synchronized (blockLock) { try { if (!freshBlockId.contains(block.getBlockId())) { - if (block.getNum() <= getHeadBlockId().getNum() && !containBlock(block.getBlockId())) { + if (block.getNum() <= getHeadBlockId().getNum()) { logger.warn("Receive a fork block {} witness {}, head block {}", Hex.toHexString(block.getWitnessAddress().toByteArray()), block.getBlockId().getString(), From 3b5497adf2a10e51a74f2724f4b63f9d4ffa2041 Mon Sep 17 00:00:00 2001 From: wubin01 Date: Thu, 6 Jun 2019 17:51:45 +0800 Subject: [PATCH 48/90] modify processblock logic --- .../tron/core/net/messagehandler/BlockMsgHandler.java | 10 +++++++--- .../java/org/tron/core/net/service/AdvService.java | 7 +++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java b/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java index dd7dcbde60d..dc1f6f13d13 100644 --- a/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java +++ b/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java @@ -50,8 +50,8 @@ public void processMessage(PeerConnection peer, TronMessage msg) throws P2pExcep BlockMessage blockMessage = (BlockMessage) msg; BlockId blockId = blockMessage.getBlockId(); - Item item = new Item(blockId, InventoryType.BLOCK); + Item item = new Item(blockId, InventoryType.BLOCK); if (!fastForward && !peer.isFastForwardPeer()) { check(peer, blockMessage); } @@ -96,6 +96,11 @@ private void processBlock(PeerConnection peer, BlockCapsule block) throws P2pExc return; } + Item item = new Item(blockId, InventoryType.BLOCK); + if (peer.isFastForwardPeer()) { + advService.addInvToCache(item); + } + if (fastForward) { if (tronNetDelegate.getHeadBlockId().getNum() - block.getNum() > threshold) { logger.warn("Receive a low block {}, Head {}", @@ -103,8 +108,7 @@ private void processBlock(PeerConnection peer, BlockCapsule block) throws P2pExc return; } if (tronNetDelegate.validBlock(block)) { - peer.getAdvInvReceive() - .put(new Item(blockId, InventoryType.BLOCK), System.currentTimeMillis()); + peer.getAdvInvReceive().put(item, System.currentTimeMillis()); advService.fastForward(new BlockMessage(block)); tronNetDelegate.trustNode(peer); } diff --git a/src/main/java/org/tron/core/net/service/AdvService.java b/src/main/java/org/tron/core/net/service/AdvService.java index e9a240243f4..1664033ba44 100644 --- a/src/main/java/org/tron/core/net/service/AdvService.java +++ b/src/main/java/org/tron/core/net/service/AdvService.java @@ -95,6 +95,11 @@ public void close() { fetchExecutor.shutdown(); } + synchronized public void addInvToCache(Item item) { + invToFetchCache.put(item, System.currentTimeMillis()); + invToFetch.remove(item); + } + synchronized public boolean addInv(Item item) { if (fastForward) { @@ -175,8 +180,6 @@ public void broadcast(Message msg) { public void fastForward(BlockMessage msg) { Item item = new Item(msg.getBlockId(), InventoryType.BLOCK); - invToFetchCache.put(item, System.currentTimeMillis()); - invToFetch.remove(item); List peers = tronNetDelegate.getActivePeer().stream() .filter(peer -> !peer.isNeedSyncFromPeer() && !peer.isNeedSyncFromUs()) .filter(peer -> peer.getAdvInvReceive().getIfPresent(item) == null From 67ef9304dc1649b17f8929998dc338ce6dbef35b Mon Sep 17 00:00:00 2001 From: wubin01 Date: Thu, 6 Jun 2019 17:54:42 +0800 Subject: [PATCH 49/90] modify processblock msg logic --- .../java/org/tron/core/net/messagehandler/BlockMsgHandler.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java b/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java index dc1f6f13d13..50dfa58f84a 100644 --- a/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java +++ b/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java @@ -51,7 +51,6 @@ public void processMessage(PeerConnection peer, TronMessage msg) throws P2pExcep BlockMessage blockMessage = (BlockMessage) msg; BlockId blockId = blockMessage.getBlockId(); - Item item = new Item(blockId, InventoryType.BLOCK); if (!fastForward && !peer.isFastForwardPeer()) { check(peer, blockMessage); } @@ -60,7 +59,7 @@ public void processMessage(PeerConnection peer, TronMessage msg) throws P2pExcep peer.getSyncBlockRequested().remove(blockId); syncService.processBlock(peer, blockMessage); } else { - Long time = peer.getAdvInvRequest().remove(item); + Long time = peer.getAdvInvRequest().remove(new Item(blockId, InventoryType.BLOCK)); long cost = time == null ? 0 : System.currentTimeMillis() - time; logger.info("Receive block {}, witness: {} from {}, fetch cost {}ms", blockId.getString(), From fe56e2c9748c789bec76a3e21455a907dd33b371 Mon Sep 17 00:00:00 2001 From: wubin01 Date: Thu, 6 Jun 2019 17:56:53 +0800 Subject: [PATCH 50/90] modify processblock log --- src/main/java/org/tron/core/net/TronNetDelegate.java | 4 ++-- .../org/tron/core/net/messagehandler/BlockMsgHandler.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/tron/core/net/TronNetDelegate.java b/src/main/java/org/tron/core/net/TronNetDelegate.java index c9143fc7fbd..680a53a47f3 100644 --- a/src/main/java/org/tron/core/net/TronNetDelegate.java +++ b/src/main/java/org/tron/core/net/TronNetDelegate.java @@ -179,9 +179,9 @@ public void processBlock(BlockCapsule block) throws P2pException { try { if (!freshBlockId.contains(block.getBlockId())) { if (block.getNum() <= getHeadBlockId().getNum()) { - logger.warn("Receive a fork block {} witness {}, head block {}", - Hex.toHexString(block.getWitnessAddress().toByteArray()), + logger.warn("Receive a fork block {} witness {}, head {}", block.getBlockId().getString(), + Hex.toHexString(block.getWitnessAddress().toByteArray()), getHeadBlockId().getString()); } dbManager.pushBlock(block); diff --git a/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java b/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java index 50dfa58f84a..dbb1005c171 100644 --- a/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java +++ b/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java @@ -102,7 +102,7 @@ private void processBlock(PeerConnection peer, BlockCapsule block) throws P2pExc if (fastForward) { if (tronNetDelegate.getHeadBlockId().getNum() - block.getNum() > threshold) { - logger.warn("Receive a low block {}, Head {}", + logger.warn("Receive a low block {}, head {}", blockId.getString(), tronNetDelegate.getHeadBlockId().getString()); return; } From d9454e9d39ae17f25b3d9cbe0cf8275bffee957b Mon Sep 17 00:00:00 2001 From: wubin1 Date: Mon, 10 Jun 2019 11:55:22 +0800 Subject: [PATCH 51/90] add unit test for transaction ret --- .../core/capsule/TransactionRetCapsule.java | 8 +- .../org/tron/core/db/TransactionRetStore.java | 4 +- src/test/java/org/tron/core/WalletTest.java | 19 ++--- .../tron/core/db/TransactionRetStoreTest.java | 77 +++++++++++++++++++ 4 files changed, 94 insertions(+), 14 deletions(-) create mode 100644 src/test/java/org/tron/core/db/TransactionRetStoreTest.java diff --git a/src/main/java/org/tron/core/capsule/TransactionRetCapsule.java b/src/main/java/org/tron/core/capsule/TransactionRetCapsule.java index 8b35bbfb397..e84bbda1d41 100644 --- a/src/main/java/org/tron/core/capsule/TransactionRetCapsule.java +++ b/src/main/java/org/tron/core/capsule/TransactionRetCapsule.java @@ -16,11 +16,15 @@ public TransactionRetCapsule(BlockCapsule blockCapsule) { if (Objects.isNull(blockCapsule)) { return; } - TransactionRet.Builder build = transactionRet.toBuilder(). - setBlockNumber(blockCapsule.getNum()).setBlockTimeStamp(blockCapsule.getTimeStamp()); + TransactionRet.Builder build = transactionRet.toBuilder() + .setBlockNumber(blockCapsule.getNum()).setBlockTimeStamp(blockCapsule.getTimeStamp()); transactionRet = build.build(); } + public TransactionRetCapsule() { + transactionRet = TransactionRet.newBuilder().build(); + } + public TransactionRetCapsule(byte[] data) throws BadItemException { try { this.transactionRet = transactionRet.parseFrom(data); diff --git a/src/main/java/org/tron/core/db/TransactionRetStore.java b/src/main/java/org/tron/core/db/TransactionRetStore.java index 5a4794371f6..36f3a0dd383 100644 --- a/src/main/java/org/tron/core/db/TransactionRetStore.java +++ b/src/main/java/org/tron/core/db/TransactionRetStore.java @@ -1,17 +1,15 @@ package org.tron.core.db; import com.google.protobuf.ByteString; +import java.util.Objects; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import org.tron.common.utils.ByteArray; -import org.tron.common.utils.Sha256Hash; -import org.tron.core.capsule.TransactionCapsule; import org.tron.core.capsule.TransactionInfoCapsule; import org.tron.core.capsule.TransactionRetCapsule; import org.tron.core.exception.BadItemException; -import java.util.Objects; import org.tron.protos.Protocol.TransactionInfo; @Slf4j(topic = "DB") diff --git a/src/test/java/org/tron/core/WalletTest.java b/src/test/java/org/tron/core/WalletTest.java index 4a10ffec558..259856fc75c 100644 --- a/src/test/java/org/tron/core/WalletTest.java +++ b/src/test/java/org/tron/core/WalletTest.java @@ -48,15 +48,11 @@ import org.tron.core.capsule.ProposalCapsule; import org.tron.core.capsule.TransactionCapsule; import org.tron.core.capsule.TransactionInfoCapsule; -import org.tron.core.capsule.TransactionRetCapsule; import org.tron.core.config.DefaultConfig; import org.tron.core.config.Parameter.ChainParameters; import org.tron.core.config.args.Args; import org.tron.core.db.DynamicPropertiesStore; import org.tron.core.db.Manager; -import org.tron.core.db.TransactionRetStore; -import org.tron.core.db.TransactionTrace; -import org.tron.core.exception.BadItemException; import org.tron.protos.Contract.AssetIssueContract; import org.tron.protos.Contract.TransferContract; import org.tron.protos.Protocol; @@ -369,31 +365,36 @@ public void getTransactionInfoById() { TransactionInfo transactionById1 = wallet.getTransactionInfoById( ByteString .copyFrom(transaction1.getRawData().toByteArray())); - Assert.assertEquals("gettransactioninfobyid", ByteString.copyFrom(transactionById1.getId().toByteArray()), + Assert.assertEquals("gettransactioninfobyid", + ByteString.copyFrom(transactionById1.getId().toByteArray()), ByteString.copyFrom(transaction1.getRawData().toByteArray())); TransactionInfo transactionById2 = wallet.getTransactionInfoById( ByteString .copyFrom(transaction2.getRawData().toByteArray())); - Assert.assertEquals("gettransactioninfobyid", ByteString.copyFrom(transactionById2.getId().toByteArray()), + Assert.assertEquals("gettransactioninfobyid", + ByteString.copyFrom(transactionById2.getId().toByteArray()), ByteString.copyFrom(transaction2.getRawData().toByteArray())); TransactionInfo transactionById3 = wallet.getTransactionInfoById( ByteString .copyFrom(transaction3.getRawData().toByteArray())); - Assert.assertEquals("gettransactioninfobyid", ByteString.copyFrom(transactionById3.getId().toByteArray()), + Assert.assertEquals("gettransactioninfobyid", + ByteString.copyFrom(transactionById3.getId().toByteArray()), ByteString.copyFrom(transaction3.getRawData().toByteArray())); TransactionInfo transactionById4 = wallet.getTransactionInfoById( ByteString .copyFrom(transaction4.getRawData().toByteArray())); - Assert.assertEquals("gettransactioninfobyid", ByteString.copyFrom(transactionById4.getId().toByteArray()), + Assert.assertEquals("gettransactioninfobyid", + ByteString.copyFrom(transactionById4.getId().toByteArray()), ByteString.copyFrom(transaction4.getRawData().toByteArray())); TransactionInfo transactionById5 = wallet.getTransactionInfoById( ByteString .copyFrom(transaction5.getRawData().toByteArray())); - Assert.assertEquals("gettransactioninfobyid", ByteString.copyFrom(transactionById5.getId().toByteArray()), + Assert.assertEquals("gettransactioninfobyid", + ByteString.copyFrom(transactionById5.getId().toByteArray()), ByteString.copyFrom(transaction5.getRawData().toByteArray())); } diff --git a/src/test/java/org/tron/core/db/TransactionRetStoreTest.java b/src/test/java/org/tron/core/db/TransactionRetStoreTest.java new file mode 100644 index 00000000000..ad4b52b06d6 --- /dev/null +++ b/src/test/java/org/tron/core/db/TransactionRetStoreTest.java @@ -0,0 +1,77 @@ +package org.tron.core.db; + +import java.io.File; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.tron.common.application.TronApplicationContext; +import org.tron.common.utils.ByteArray; +import org.tron.common.utils.FileUtil; +import org.tron.core.Constant; +import org.tron.core.capsule.TransactionCapsule; +import org.tron.core.capsule.TransactionInfoCapsule; +import org.tron.core.capsule.TransactionRetCapsule; +import org.tron.core.config.DefaultConfig; +import org.tron.core.config.args.Args; +import org.tron.core.exception.BadItemException; +import org.tron.protos.Protocol.Transaction; + +public class TransactionRetStoreTest { + + private static String dbPath = "output_TransactionRetStore_test"; + private static String dbDirectory = "db_TransactionRetStore_test"; + private static String indexDirectory = "index_TransactionRetStore_test"; + private static TronApplicationContext context; + private static TransactionRetStore transactionRetStore; + private static Transaction transaction; + private static TransactionStore transactionStore; + private static final byte[] transactionId = TransactionStoreTest.randomBytes(32); + private static final byte[] blockNum = ByteArray.fromLong(1); + + static { + Args.setParam( + new String[]{ + "--output-directory", dbPath, + "--storage-db-directory", dbDirectory, + "--storage-index-directory", indexDirectory + }, + Constant.TEST_CONF + ); + context = new TronApplicationContext(DefaultConfig.class); + } + + @AfterClass + public static void destroy() { + Args.clearParam(); + context.destroy(); + FileUtil.deleteDir(new File(dbPath)); + } + + @BeforeClass + public static void init() { + transactionRetStore = context.getBean(TransactionRetStore.class); + transactionStore = context.getBean(TransactionStore.class); + TransactionInfoCapsule transactionInfoCapsule = new TransactionInfoCapsule(); + + transactionInfoCapsule.setId(transactionId); + transactionInfoCapsule.setFee(1000L); + transactionInfoCapsule.setBlockNumber(100L); + transactionInfoCapsule.setBlockTimeStamp(200L); + + TransactionRetCapsule transactionRetCapsule = new TransactionRetCapsule(); + transactionRetCapsule.addTransactionInfo(transactionInfoCapsule.getInstance()); + transactionRetStore.put(blockNum, transactionRetCapsule); + transaction = Transaction.newBuilder().build(); + TransactionCapsule transactionCapsule = new TransactionCapsule(transaction); + transactionCapsule.setBlockNum(1); + transactionStore.put(transactionId, transactionCapsule); + } + + @Test + public void get() throws BadItemException { + //test get and has Method + TransactionInfoCapsule resultCapsule = transactionRetStore.getTransactionInfo(transactionId); + Assert.assertNotNull("get transaction ret store", resultCapsule); + } +} \ No newline at end of file From 589f02d920dd50590983b34a628c7dffb28806ea Mon Sep 17 00:00:00 2001 From: wubin1 Date: Mon, 10 Jun 2019 11:56:54 +0800 Subject: [PATCH 52/90] add unit test for transaction ret --- src/test/java/org/tron/core/db/TransactionRetStoreTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/org/tron/core/db/TransactionRetStoreTest.java b/src/test/java/org/tron/core/db/TransactionRetStoreTest.java index ad4b52b06d6..8fdd6d76b59 100644 --- a/src/test/java/org/tron/core/db/TransactionRetStoreTest.java +++ b/src/test/java/org/tron/core/db/TransactionRetStoreTest.java @@ -70,7 +70,6 @@ public static void init() { @Test public void get() throws BadItemException { - //test get and has Method TransactionInfoCapsule resultCapsule = transactionRetStore.getTransactionInfo(transactionId); Assert.assertNotNull("get transaction ret store", resultCapsule); } From 44541420cba4ba4232439c63da990825a40195bb Mon Sep 17 00:00:00 2001 From: wubin1 Date: Mon, 10 Jun 2019 12:07:18 +0800 Subject: [PATCH 53/90] add unit test for transaction ret --- src/main/java/org/tron/core/capsule/TransactionRetCapsule.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/tron/core/capsule/TransactionRetCapsule.java b/src/main/java/org/tron/core/capsule/TransactionRetCapsule.java index e84bbda1d41..8fd483df5fa 100644 --- a/src/main/java/org/tron/core/capsule/TransactionRetCapsule.java +++ b/src/main/java/org/tron/core/capsule/TransactionRetCapsule.java @@ -21,6 +21,7 @@ public TransactionRetCapsule(BlockCapsule blockCapsule) { transactionRet = build.build(); } + // only for test public TransactionRetCapsule() { transactionRet = TransactionRet.newBuilder().build(); } From e06c9e454346a35aba471f4f33a8d19b862b2e75 Mon Sep 17 00:00:00 2001 From: wubin1 Date: Mon, 10 Jun 2019 14:33:02 +0800 Subject: [PATCH 54/90] fix check style error --- src/main/java/org/tron/core/Wallet.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/tron/core/Wallet.java b/src/main/java/org/tron/core/Wallet.java index 43eec4079ad..a48f4301924 100755 --- a/src/main/java/org/tron/core/Wallet.java +++ b/src/main/java/org/tron/core/Wallet.java @@ -1240,7 +1240,8 @@ public TransactionInfo getTransactionInfoById(ByteString transactionId) { return transactionInfoCapsule.getInstance(); } try { - transactionInfoCapsule = dbManager.getTransactionRetStore().getTransactionInfo(transactionId.toByteArray()); + transactionInfoCapsule = dbManager.getTransactionRetStore() + .getTransactionInfo(transactionId.toByteArray()); } catch (BadItemException e) { return null; } From 8c9574261d43c314c2168ba6ea63ae25818239ac Mon Sep 17 00:00:00 2001 From: wangzihe Date: Tue, 11 Jun 2019 17:19:58 +0800 Subject: [PATCH 55/90] Replace the docker server ip --- deploy.sh | 8 +++---- .../wallet/account/WalletTestAccount013.java | 1 + src/test/resources/testng.conf | 22 +++++++++++++------ 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/deploy.sh b/deploy.sh index a0f83b13148..c162b55a86a 100644 --- a/deploy.sh +++ b/deploy.sh @@ -2,17 +2,17 @@ if [[ "$TRAVIS_BRANCH" = "develop" || "$TRAVIS_BRANCH" = "master" ]];then stestlogname="`date +%Y%m%d%H%M%S`_stest.log" stest_server="" - docker_num_in_67=`ssh -p 22008 -t java-tron@47.94.231.67 'docker ps -a | wc -l'` + docker_num_in_67=`ssh -p 22008 -t java-tron@47.93.18.60 'docker ps -a | wc -l'` docker_num_in_67=`echo $docker_num_in_67 | tr -d "\r"` - docker_num_in_122=`ssh -p 22008 -t java-tron@47.94.10.122 'docker ps -a | wc -l'` + docker_num_in_122=`ssh -p 22008 -t java-tron@47.93.42.145 'docker ps -a | wc -l'` docker_num_in_122=`echo $docker_num_in_122 | tr -d "\r"` if [ $docker_num_in_67 -le $docker_num_in_122 ]; then docker_num=$docker_num_in_67 - stest_server=47.94.231.67 + stest_server=47.93.18.60 else docker_num=$docker_num_in_122 - stest_server=47.94.10.122 + stest_server=47.93.42.145 fi if [[ ${docker_num} -le 3 ]]; diff --git a/src/test/java/stest/tron/wallet/account/WalletTestAccount013.java b/src/test/java/stest/tron/wallet/account/WalletTestAccount013.java index 31094624859..afd6fc07c4c 100644 --- a/src/test/java/stest/tron/wallet/account/WalletTestAccount013.java +++ b/src/test/java/stest/tron/wallet/account/WalletTestAccount013.java @@ -394,6 +394,7 @@ public void test5DelegateResourceAboutTriggerContract() { //sendcoin to Account6 Assert.assertTrue(PublicMethed.sendcoin(accountForDeployAddress, 10000000000L, fromAddress, testKey002, blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); //deploy contract under Account6 Integer consumeUserResourcePercent = 0; diff --git a/src/test/resources/testng.conf b/src/test/resources/testng.conf index 3566037bfd9..cd66082e4d7 100644 --- a/src/test/resources/testng.conf +++ b/src/test/resources/testng.conf @@ -6,8 +6,8 @@ net { fullnode = { ip.list = [ #Docker env - "127.0.0.1:50051", - "127.0.0.1:50052", + #"127.0.0.1:50051", + #"127.0.0.1:50052", #Continue Integration //"47.93.14.253:50051", #"101.200.51.70:50051", @@ -20,6 +20,9 @@ fullnode = { #Replay env #"47.94.239.172:50051", #"39.105.89.183:50051", + #New beat1 + "39.106.145.222:50052", + "101.200.46.37:50052", #New beta1 "47.94.197.215:50051", @@ -43,23 +46,28 @@ fullnode = { solidityNode = { ip.list = [ #Docker env - "127.0.0.1:50053", - "127.0.0.1:50062", + #"127.0.0.1:50053", + #"127.0.0.1:50062", #MainNet #"39.105.66.80:50051", #Continue Integration #"47.94.135.251:50051", #"47.94.9.222:50061", #new beta1 - #"47.94.197.215:18895", + "101.200.46.37:50053", + "101.200.46.37:50062", + #new beta2 - #"101.200.52.146:18895", + "101.200.52.146:18895", ] } httpnode = { ip.list = [ + "101.200.46.37:50191", + "39.106.145.222:50093", + "101.200.46.37:50094", #"39.105.89.183:8090", #"39.107.248.113:8090", #"39.105.89.183:8091", @@ -159,7 +167,7 @@ defaultParameter = { delayTransactionFee = 100000 cancleDelayTransactionFee = 50000 solidityCompilerVersion = "v5" - solidityCompile = "solcDIR/solc" + solidityCompile = "/Users/wangzihe/Downloads/solc.0.5.4" } From 4bf6c193c36fdc4eef9a7dc155ea99b53d9d2973 Mon Sep 17 00:00:00 2001 From: wangming Date: Wed, 12 Jun 2019 12:03:28 +0800 Subject: [PATCH 56/90] modify tvmnewCommand Case --- .../common/client/utils/PublicMethed.java | 6 +- .../trctoken/ContractTrcToken014.java | 4 +- .../trctoken/ContractTrcToken064.java | 1 + .../trctoken/ContractTrcToken075.java | 1 + .../trctoken/ContractTrcToken076.java | 5 - .../trctoken/ContractTrcToken077.java | 3 - .../trctoken/ContractTrcToken078.java | 19 - .../tvmnewcommand/checkCodeSize.java | 208 ++++++ .../tvmnewcommand/clearabi/ClearAbi001.java | 29 +- .../tvmnewcommand/clearabi/ClearAbi008.java | 2 +- .../tvmnewcommand/create2/Create2Test001.java | 281 +++----- .../tvmnewcommand/create2/Create2Test002.java | 77 +- .../tvmnewcommand/create2/Create2Test003.java | 144 ++-- .../tvmnewcommand/create2/Create2Test005.java | 6 +- .../tvmnewcommand/create2/Create2Test006.java | 659 +++++++++++++++++- .../tvmnewcommand/create2/Create2Test007.java | 6 +- .../tvmnewcommand/create2/Create2Test008.java | 6 +- .../tvmnewcommand/create2/Create2Test009.java | 6 +- .../tvmnewcommand/create2/Create2Test010.java | 4 +- .../tvmnewcommand/create2/Create2Test011.java | 6 +- .../tvmnewcommand/create2/Create2Test012.java | 6 +- .../tvmnewcommand/create2/Create2Test013.java | 8 +- .../tvmnewcommand/create2/Create2Test014.java | 78 +++ .../tvmnewcommand/create2/Create2Test015.java | 154 +++- .../tvmnewcommand/create2/Create2Test016.java | 9 +- .../tvmnewcommand/create2/Create2Test017.java | 6 +- .../tvmnewcommand/create2/Create2Test018.java | 6 +- .../tvmnewcommand/create2/Create2Test019.java | 6 +- .../tvmnewcommand/create2/Create2Test020.java | 59 +- .../tvmnewcommand/create2/Create2Test023.java | 2 + .../tvmnewcommand/create2/Create2Test025.java | 26 +- .../extCodeHash/ExtCodeHashTest001.java | 8 +- .../extCodeHash/ExtCodeHashTest003.java | 2 +- .../extCodeHash/ExtCodeHashTest005.java | 9 +- .../extCodeHash/ExtCodeHashTest007.java | 6 +- .../extCodeHash/ExtCodeHashTest010.java | 19 +- .../shiftcommand/ShiftCommand001.java | 4 +- .../shiftcommand/ShiftCommand003.java | 7 +- .../shiftcommand/ShiftCommand004.java | 45 +- .../shiftcommand/ShiftCommand005.java | 48 +- .../shiftcommand/ShiftCommand006.java | 77 +- .../transferfailed/TransferFailed001.java | 323 +++++++++ .../transferfailed/TransferFailed003.java | 1 - .../transferfailed/TransferFailed005.java | 15 +- .../transferfailed/old/TransferFailed005.java | 509 ++++++++++++++ .../triggerconstant/TriggerConstant001.java | 6 +- .../triggerconstant/TriggerConstant003.java | 63 +- .../triggerconstant/TriggerConstant005.java | 4 +- .../triggerconstant/TriggerConstant026.java | 4 +- .../soliditycode/TransferFailed001.sol | 33 + .../soliditycode/TriggerConstant003.sol | 4 + .../soliditycode/create2contract.sol | 13 + .../soliditycode/create2contract22.sol | 71 +- src/test/resources/soliditycode/demo.sol | 73 ++ src/test/resources/soliditycode/event001.sol | 10 + src/test/resources/soliditycode/event002.sol | 52 ++ .../resources/soliditycode/suicide001.sol | 32 + .../resources/soliditycode/suicide002.sol | 43 ++ .../TransferFailed001.sol | 0 59 files changed, 2585 insertions(+), 729 deletions(-) create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/checkCodeSize.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/old/TransferFailed005.java create mode 100644 src/test/resources/soliditycode/demo.sol create mode 100644 src/test/resources/soliditycode/event001.sol create mode 100644 src/test/resources/soliditycode/event002.sol create mode 100644 src/test/resources/soliditycode/suicide001.sol create mode 100644 src/test/resources/soliditycode/suicide002.sol create mode 100644 src/test/resources/soliditycode_v0.4.25/TransferFailed001.sol diff --git a/src/test/java/stest/tron/wallet/common/client/utils/PublicMethed.java b/src/test/java/stest/tron/wallet/common/client/utils/PublicMethed.java index 0d41643a039..16757b43c22 100644 --- a/src/test/java/stest/tron/wallet/common/client/utils/PublicMethed.java +++ b/src/test/java/stest/tron/wallet/common/client/utils/PublicMethed.java @@ -1678,16 +1678,16 @@ public static boolean waitProduceNextBlock(WalletGrpc.WalletBlockingStub Integer wait = 0; logger.info("Block num is " + Long.toString(currentBlock .getBlockHeader().getRawData().getNumber())); - while (nextNum <= currentNum + 1 && wait <= 15) { + while (nextNum <= currentNum + 1 && wait <= 45) { try { - Thread.sleep(3000); + Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } logger.info("Wait to produce next block"); nextBlock = blockingStubFull.getNowBlock(GrpcAPI.EmptyMessage.newBuilder().build()); nextNum = nextBlock.getBlockHeader().getRawData().getNumber(); - if (wait == 15) { + if (wait == 45) { logger.info("These 45 second didn't produce a block,please check."); return false; } diff --git a/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken014.java b/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken014.java index d2909dc6b07..e36aa099385 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken014.java +++ b/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken014.java @@ -355,6 +355,7 @@ public void test03TriggerContract() { 1000000000L, assetAccountId.toStringUtf8(), 2, user001Address, user001Key, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); infoById = PublicMethed .getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() != 0); @@ -407,6 +408,7 @@ public void test03TriggerContract() { 1000000000L, assetAccountId.toStringUtf8(), 2, user001Address, user001Key, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() != 0); Assert.assertEquals(FAILED, infoById.get().getResult()); @@ -527,7 +529,7 @@ public void test03TriggerContract() { "transferTokenTest(address,uint256,trcToken)", param, false, callValue, 1000000000L, assetAccountId.toStringUtf8(), 2, user001Address, user001Key, blockingStubFull); - + PublicMethed.waitProduceNextBlock(blockingStubFull); infoById = PublicMethed .getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() != 0); diff --git a/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken064.java b/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken064.java index f3c169adc47..bd109f0933a 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken064.java +++ b/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken064.java @@ -320,6 +320,7 @@ public void test03TriggerContract() { 1000000000L, assetAccountId.toStringUtf8(), 2, user001Address, user001Key, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); infoById = PublicMethed .getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() != 0); diff --git a/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken075.java b/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken075.java index 75343e7687e..642f990f254 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken075.java +++ b/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken075.java @@ -230,6 +230,7 @@ public void testTokenBalanceContract() { .getTransactionInfoById(triggerTxid, blockingStubFull); logger.info("Trigger energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); + PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() != 0); Assert.assertEquals(FAILED, infoById.get().getResult()); Assert.assertEquals("REVERT opcode executed", diff --git a/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken076.java b/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken076.java index 4d216784749..a29c4721113 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken076.java +++ b/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken076.java @@ -80,7 +80,6 @@ public void testDeployTransferTokenContract() { .sendcoin(grammarAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); String filePath = "./src/test/resources/soliditycode/contractTrcToken076.sol"; String contractName = "Test"; @@ -98,19 +97,16 @@ public void testDeployTransferTokenContract() { contractAddress = infoById.get().getContractAddress().toByteArray(); - PublicMethed.waitProduceNextBlock(blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); PublicMethed.triggerContract(contractAddress, "test()", "#", false, 0, maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); txid = PublicMethed.triggerContract(contractAddress, "getResult1()", "#", false, 0, maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); @@ -125,7 +121,6 @@ public void testDeployTransferTokenContract() { "getResult2()", "#", false, 0, maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); diff --git a/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken077.java b/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken077.java index e4adf390894..91e263ee75b 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken077.java +++ b/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken077.java @@ -113,7 +113,6 @@ public void testAddress002() { .sendcoin(grammarAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); String filePath = "./src/test/resources/soliditycode/contractTrcToken077.sol"; String contractName = "trcToken077"; @@ -131,14 +130,12 @@ public void testAddress002() { contractAddress = deployById.get().getContractAddress().toByteArray(); logger.info("infoById:" + deployById); PublicMethed.waitProduceNextBlock(blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); String txid = ""; txid = PublicMethed.triggerContract(contractAddress, "addressTest()", "#", false, 0, maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); diff --git a/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken078.java b/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken078.java index c6d2be29a0c..b1bb16de8f6 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken078.java +++ b/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken078.java @@ -88,9 +88,6 @@ public void testOriginCall001() { .sendcoin(internalTxsAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - PublicMethed - .freezeBalanceGetEnergy(internalTxsAddress, 10000000000L, 0L, 1, priKey, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); String filePath = "./src/test/resources/soliditycode/contractTrcToken078.sol"; String contractName = "callerContract"; @@ -104,7 +101,6 @@ public void testOriginCall001() { 1000000L, 100, null, testKeyForinternalTxsAddress, internalTxsAddress, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); Optional infoById = PublicMethed .getTransactionInfoById(txid, blockingStubFull); logger.info("infoById : " + infoById); @@ -127,8 +123,6 @@ public void testOriginCall001() { byte[] contractAddress1; contractAddress1 = infoById.get().getContractAddress().toByteArray(); - PublicMethed.waitProduceNextBlock(blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); String filePath2 = "./src/test/resources/soliditycode/contractTrcToken078.sol"; @@ -143,8 +137,6 @@ public void testOriginCall001() { 1000000L, 100, null, testKeyForinternalTxsAddress, internalTxsAddress, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); infoById = PublicMethed .getTransactionInfoById(txid, blockingStubFull); @@ -159,8 +151,6 @@ public void testOriginCall001() { "sendToB2(address,address)", initParmes, false, 0, maxFeeLimit, internalTxsAddress, testKeyForinternalTxsAddress, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); Optional infoById2 = null; infoById2 = PublicMethed.getTransactionInfoById(txid2, blockingStubFull); logger.info("Trigger InfobyId: " + infoById2); @@ -180,7 +170,6 @@ public void testOriginDelegatecall001() { .sendcoin(internalTxsAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); String filePath = "./src/test/resources/soliditycode/contractTrcToken078.sol"; String contractName = "callerContract"; @@ -198,8 +187,6 @@ public void testOriginDelegatecall001() { logger.info("infoById : " + infoById); contractAddress = infoById.get().getContractAddress().toByteArray(); - PublicMethed.waitProduceNextBlock(blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); String filePath1 = "./src/test/resources/soliditycode/contractTrcToken078.sol"; String contractName1 = "calledContract"; @@ -212,8 +199,6 @@ public void testOriginDelegatecall001() { 1000000L, 100, null, testKeyForinternalTxsAddress, internalTxsAddress, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); infoById = PublicMethed .getTransactionInfoById(txid, blockingStubFull); logger.info("infoById : " + infoById); @@ -231,8 +216,6 @@ public void testOriginDelegatecall001() { 1000000L, 100, null, testKeyForinternalTxsAddress, internalTxsAddress, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); infoById = PublicMethed .getTransactionInfoById(txid, blockingStubFull); logger.info("infoById : " + infoById); @@ -246,8 +229,6 @@ public void testOriginDelegatecall001() { "sendToB(address,address)", initParmes, false, 0, maxFeeLimit, internalTxsAddress, testKeyForinternalTxsAddress, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); Optional infoById2 = null; infoById2 = PublicMethed.getTransactionInfoById(txid2, blockingStubFull); logger.info("infoById : " + infoById2); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/checkCodeSize.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/checkCodeSize.java new file mode 100644 index 00000000000..96c23826eb0 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/checkCodeSize.java @@ -0,0 +1,208 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand; + +import com.google.protobuf.ByteString; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +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.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 checkCodeSize { + + private final String testKey002 = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key1"); + 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); + private long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + + private static final long now = System.currentTimeMillis(); + private static String tokenName = "testAssetIssue_" + Long.toString(now); + private static ByteString assetAccountId = null; + private static final long TotalSupply = 1000L; + private byte[] transferTokenContractAddress = null; + private byte[] confirmContractAddress = null; + + private String description = Configuration.getByPath("testng.conf") + .getString("defaultParameter.assetDescription"); + private String url = Configuration.getByPath("testng.conf") + .getString("defaultParameter.assetUrl"); + + private ECKey ecKey1 = new ECKey(Utils.getRandom()); + private byte[] dev001Address = ecKey1.getAddress(); + private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + @BeforeClass(enabled = true) + public void beforeClass() { + + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + + PublicMethed.printAddress(dev001Key); + } + + @Test(enabled = false, description = "DeployContract with correct tokenValue and tokenId") + public void deployTransferTokenContract() { + Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 1000_000_000L, fromAddress, + testKey002, blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + //before deploy, check account resource + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long energyLimit = accountResource.getEnergyLimit(); + long energyUsage = accountResource.getEnergyUsed(); + long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + + logger.info("before energyLimit is " + Long.toString(energyLimit)); + logger.info("before energyUsage is " + Long.toString(energyUsage)); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + String filePath = "./src/test/resources/soliditycode/demo.sol"; + String contractName = "tokenTest"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + transferTokenContractAddress = PublicMethed + .deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, dev001Key, + dev001Address, blockingStubFull); + + code = "6080604052303b600055610211806100186000396000f3006080604052600436106100565763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663a5a23074811461005b578063dce4a4471461009c578063eb4dd8f214610159575b600080fd5b34801561006757600080fd5b50d3801561007457600080fd5b50d2801561008157600080fd5b5061008a6101a1565b60408051918252519081900360200190f35b3480156100a857600080fd5b50d380156100b557600080fd5b50d280156100c257600080fd5b506100e473ffffffffffffffffffffffffffffffffffffffff600435166101a7565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561011e578181015183820152602001610106565b50505050905090810190601f16801561014b5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561016557600080fd5b50d3801561017257600080fd5b50d2801561017f57600080fd5b5061008a73ffffffffffffffffffffffffffffffffffffffff600435166101ce565b60005490565b60408051603f833b908101601f191682019092528181529080600060208401853c50919050565b6000813b823b15156101df57600080fd5b929150505600a165627a7a72305820309e6f0e0ad58fd7067f04813defe26c999d00f1975d75d8685fd398ec6ccb2e0029"; + abi = "[{\"constant\":false,\"inputs\":[],\"name\":\"getCodeSize\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_addr\",\"type\":\"address\"}],\"name\":\"at\",\"outputs\":[{\"name\":\"o_code\",\"type\":\"bytes\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"addr\",\"type\":\"address\"}],\"name\":\"confirm\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"constructor\"}]"; + contractName = "confirmTest"; + confirmContractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, dev001Key, + dev001Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + } + + @Test(enabled = false, description = "trigger") + public void triggerConfirm() { + long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + String contractname = "pulsone()"; + + String trxid = PublicMethed + .triggerContract(transferTokenContractAddress, contractname, "#", false, 0L, maxFeeLimit, + dev001Address, dev001Key, blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(trxid, blockingStubFull); + + logger.info("TrxId = " + trxid); + logger.info("Info = \n" + infoById); + //logger.info("contractResult = " + ByteArray + // .toLong(infoById.get().getContractResult(0).toByteArray())); + + contractname = "getCodeSize()"; + + trxid = PublicMethed + .triggerContract(transferTokenContractAddress, contractname, "#", false, 0L, maxFeeLimit, + dev001Address, dev001Key, blockingStubFull); + infoById = null; + infoById = PublicMethed.getTransactionInfoById(trxid, blockingStubFull); + + logger.info("TrxId = " + trxid); + logger.info("Info = \n" + infoById); + logger.info("contractResult = " + ByteArray + .toLong(infoById.get().getContractResult(0).toByteArray())); + + contractname = "getCodeSize()"; + + trxid = PublicMethed + .triggerContract(confirmContractAddress, contractname, "#", false, 0L, maxFeeLimit, + dev001Address, dev001Key, blockingStubFull); + infoById = null; + infoById = PublicMethed.getTransactionInfoById(trxid, blockingStubFull); + + logger.info("TrxId = " + trxid); + logger.info("Info = \n" + infoById); + logger.info("contractResult = " + ByteArray + .toLong(infoById.get().getContractResult(0).toByteArray())); + + balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + String parm = "\"" + Base58.encode58Check(transferTokenContractAddress) + "\""; + contractname = "confirm(address)"; + + trxid = PublicMethed + .triggerContract(confirmContractAddress, contractname, parm, false, 0L, maxFeeLimit, + dev001Address, dev001Key, blockingStubFull); + infoById = null; + infoById = PublicMethed.getTransactionInfoById(trxid, blockingStubFull); + + logger.info("TrxId = " + trxid); + logger.info("Info = \n" + infoById); + logger.info("contractResult = " + ByteArray + .toLong(infoById.get().getContractResult(0).toByteArray())); + + balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + parm = "\"" + Base58.encode58Check(transferTokenContractAddress) + "\""; + contractname = "at(address)"; + + trxid = PublicMethed + .triggerContract(confirmContractAddress, contractname, parm, false, 0L, maxFeeLimit, + dev001Address, dev001Key, blockingStubFull); + infoById = null; + infoById = PublicMethed.getTransactionInfoById(trxid, blockingStubFull); + + logger.info("TrxId = " + trxid); + logger.info("Info = \n" + infoById); + logger.info("contractResult = " + ByteArray + .toLong(infoById.get().getContractResult(0).toByteArray())); + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } +} + + diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi001.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi001.java index 7c2f63ac3f2..e80d5035479 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi001.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi001.java @@ -152,16 +152,8 @@ public void testClearAbi001() { @Test(enabled = true, description = "Clear a contract with ABI created by itself") public void testClearAbi002() { -// String filePath = "src/test/resources/soliditycode/ClearAbi001.sol"; + String contractName = "testConstantContract"; -// HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); -// String code = retMap.get("byteCode").toString(); -// String abi = retMap.get("abI").toString(); -// -// contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, -// 0L, 100, null, contractExcKey, -// contractExcAddress, blockingStubFull); -// PublicMethed.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); @@ -187,7 +179,14 @@ public void testClearAbi002() { Optional infoById = null; infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); - Assert.assertTrue(infoById.get().getResultValue() == 0); + + String txid1 = PublicMethed + .clearContractABI(contractAddress, contractExcAddress, contractExcKey, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById1 = null; + infoById1 = PublicMethed.getTransactionInfoById(txid1, blockingStubFull); + Assert.assertTrue(infoById1.get().getResultValue() == 0); smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); @@ -198,16 +197,8 @@ public void testClearAbi002() { @Test(enabled = true, description = "Clear a contract without ABI") public void testClearAbi003() { -// String filePath = "src/test/resources/soliditycode/ClearAbi001.sol"; + String contractName = "testConstantContract"; -// HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); -// String code = retMap.get("byteCode").toString(); -// String abi = retMap.get("abI").toString(); -// -// contractAddress = PublicMethed.deployContract(contractName, "[]", code, "", maxFeeLimit, -// 0L, 100, null, contractExcKey, -// contractExcAddress, blockingStubFull); -// PublicMethed.waitProduceNextBlock(blockingStubFull); SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi008.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi008.java index df75a2473b4..5905ce01b2d 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi008.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi008.java @@ -87,7 +87,7 @@ public void beforeClass() { blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = true, description = "Clear a contract with ABI created by itself," + @Test(enabled = false, description = "Clear a contract with ABI created by itself," + "clear a contract by itself again") public void testClearAbi() { Assert.assertTrue(PublicMethed diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test001.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test001.java index 31ca94e6898..9b5e4b3545e 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test001.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test001.java @@ -81,25 +81,15 @@ public void test01DeployFactoryContract() { testKey002, blockingStubFull)); Assert.assertTrue(PublicMethed.sendcoin(user001Address, 10000_000_000L, fromAddress, testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + /*Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, blockingStubFull), 0, 1, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, - 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); + 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull));*/ - PublicMethed.waitProduceNextBlock(blockingStubFull); - - //before deploy, check account resource - //AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, - // blockingStubFull); - //long energyLimit = accountResource.getEnergyLimit(); - //long energyUsage = accountResource.getEnergyUsed(); - //long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); - //logger.info("before energyLimit is " + Long.toString(energyLimit)); - //logger.info("before energyUsage is " + Long.toString(energyUsage)); - //logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + //PublicMethed.waitProduceNextBlock(blockingStubFull); String filePath = "./src/test/resources/soliditycode/create2contract.sol"; String contractName = "Factory"; @@ -115,15 +105,6 @@ public void test01DeployFactoryContract() { dev001Address, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - //accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); - //energyLimit = accountResource.getEnergyLimit(); - //energyUsage = accountResource.getEnergyUsed(); - //long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); - - //logger.info("after energyLimit is " + Long.toString(energyLimit)); - //logger.info("after energyUsage is " + Long.toString(energyUsage)); - //logger.info("after balanceAfter is " + Long.toString(balanceAfter)); - Optional infoById = PublicMethed .getTransactionInfoById(transferTokenTxid, blockingStubFull); @@ -143,30 +124,6 @@ public void test01DeployFactoryContract() { @Test(enabled = true, description = "Trigger create2 command with test bytecode using factory") public void test02TriggerCreate2ToDeployTestContract() { - Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, - PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 80000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - /*AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, - blockingStubFull); - long devEnergyLimitBefore = accountResource.getEnergyLimit(); - long devEnergyUsageBefore = accountResource.getEnergyUsed(); - long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); - - logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); - logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); - logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); - - accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); - long userEnergyLimitBefore = accountResource.getEnergyLimit(); - long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) - .getBalance(); - - logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); - logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); - logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore));*/ Long callValue = Long.valueOf(0); @@ -186,25 +143,6 @@ public void test02TriggerCreate2ToDeployTestContract() { blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - /*accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); - long devEnergyLimitAfter = accountResource.getEnergyLimit(); - long devEnergyUsageAfter = accountResource.getEnergyUsed(); - long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); - - logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); - logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); - logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); - - accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); - long userEnergyLimitAfter = accountResource.getEnergyLimit(); - long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) - .getBalance(); - - logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); - logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); - logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter));*/ - Optional infoById = PublicMethed .getTransactionInfoById(triggerTxid, blockingStubFull); @@ -258,30 +196,6 @@ public void test02TriggerCreate2ToDeployTestContract() { @Test(enabled = true, description = "Trigger create2 command with factory bytecode") public void test02TriggerCreate2ToDeployFactory2Contract() { - Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, - PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 150000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - - /*AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, - blockingStubFull); - long devEnergyLimitBefore = accountResource.getEnergyLimit(); - long devEnergyUsageBefore = accountResource.getEnergyUsed(); - long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); - - logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); - logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); - logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); - - accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); - long userEnergyLimitBefore = accountResource.getEnergyLimit(); - long userEnergyUsageBefore = accountResource.getEnergyUsed(); - long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) - .getBalance(); - - logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); - logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); - logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore));*/ Long callValue = Long.valueOf(0); @@ -301,25 +215,6 @@ public void test02TriggerCreate2ToDeployFactory2Contract() { blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - /*accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); - long devEnergyLimitAfter = accountResource.getEnergyLimit(); - long devEnergyUsageAfter = accountResource.getEnergyUsed(); - long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); - - logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); - logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); - logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); - - accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); - long userEnergyLimitAfter = accountResource.getEnergyLimit(); - long userEnergyUsageAfter = accountResource.getEnergyUsed(); - long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) - .getBalance(); - - logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); - logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); - logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter));*/ - Optional infoById = PublicMethed .getTransactionInfoById(triggerTxid, blockingStubFull); @@ -370,12 +265,42 @@ public void test02TriggerCreate2ToDeployFactory2Contract() { @Test(enabled = true, description = "Trigger create2 command with test bytecode using factory2") public void test03TriggerCreate2ToDeployTestContract2() { - Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, - PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 80000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - /*AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + Long callValue = Long.valueOf(0); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String testContractCode = retMap.get("byteCode").toString(); + + Long salt = 1L; + + String param = "\"" + testContractCode + "\"," + salt; + + final String triggerTxid = PublicMethed.triggerContract(factoryContractAddress2, + "deploy(bytes,uint256)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + Assert.assertEquals(1, infoById.get().getResultValue()); + Assert + .assertThat(infoById.get().getResMessage().toStringUtf8(), + containsString("Not enough energy for 'SWAP1' operation executing")); + } + + @Test(enabled = true, description = "Trigger create2 command without meta data hash in bytecode") + public void test04TriggerCreate2ToDeployTestContract() { + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); @@ -393,27 +318,28 @@ public void test03TriggerCreate2ToDeployTestContract2() { logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); - logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore));*/ + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); Long callValue = Long.valueOf(0); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; - String contractName = "TestConstract"; - HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); - - String testContractCode = retMap.get("byteCode").toString(); + String testContractCode = "608060405234801561001057600080fd5b50d3801561001d57600080fd5b50d2801" + + "561002a57600080fd5b5060c9806100396000396000f3fe6080604052348015600f57600080fd5b50d38015" + + "601b57600080fd5b50d28015602757600080fd5b50600436106066577c01000000000000000000000000000" + + "00000000000000000000000000000600035046368e5c0668114606b578063e5aa3d58146083575b600080fd" + + "5b60716089565b60408051918252519081900360200190f35b60716097565b6000805460010190819055905" + + "65b6000548156fe"; Long salt = 1L; String param = "\"" + testContractCode + "\"," + salt; - final String triggerTxid = PublicMethed.triggerContract(factoryContractAddress2, + final String triggerTxid = PublicMethed.triggerContract(factoryContractAddress, "deploy(bytes,uint256)", param, false, callValue, 1000000000L, "0", 0, user001Address, user001Key, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - /*accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitAfter = accountResource.getEnergyLimit(); long devEnergyUsageAfter = accountResource.getEnergyUsed(); long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -430,7 +356,7 @@ public void test03TriggerCreate2ToDeployTestContract2() { logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); - logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter));*/ + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); Optional infoById = PublicMethed .getTransactionInfoById(triggerTxid, blockingStubFull); @@ -439,47 +365,51 @@ public void test03TriggerCreate2ToDeployTestContract2() { logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); - Assert.assertEquals(1, infoById.get().getResultValue()); - Assert - .assertThat(infoById.get().getResMessage().toStringUtf8(), - containsString("Not enough energy for 'SWAP1' operation executing")); - PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, - dev001Address, blockingStubFull); - PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, - dev001Address, blockingStubFull); - PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, - user001Address, blockingStubFull); - PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, - user001Address, blockingStubFull); - } + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } - @Test(enabled = true, description = "Trigger create2 command without meta data hash in bytecode") - public void test04TriggerCreate2ToDeployTestContract() { - Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, - PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + logger.info( + "the value: " + PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); - //AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, - // blockingStubFull); - //long devEnergyLimitBefore = accountResource.getEnergyLimit(); - //long devEnergyUsageBefore = accountResource.getEnergyUsed(); - //long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + List retList = PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); - //logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); - //logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); - //logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); - //accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); - //long userEnergyLimitBefore = accountResource.getEnergyLimit(); - //long userEnergyUsageBefore = accountResource.getEnergyUsed(); - //long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) - // .getBalance(); + logger.info("actualSalt: " + actualSalt); - //logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); - //logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); - //logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + byte[] tmpAddress = new byte[20]; + System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); + logger.info("address_hex: " + addressHex); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + logger.info("address_final: " + addressFinal); + testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); + + SmartContract smartContract = PublicMethed.getContract(testContractAddress, blockingStubFull); + + // contract created by create2, doesn't have ABI + Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); + + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); + + // the contract address in transaction info, + // contract address of create2 contract is factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); + + String msgSender = Base58.encode58Check(ByteArray.fromHexString(retList.get(2))); + Assert.assertNotEquals(msgSender, Base58.encode58Check(user001Address)); + } + + @Test(enabled = true,description = "Trigger create2 command with 0 extended bytecode") + public void test05TriggerCreate2ToDeployTestContract() { Long callValue = Long.valueOf(0); String testContractCode = "608060405234801561001057600080fd5b50d3801561001d57600080fd5b50d2801" @@ -487,7 +417,7 @@ public void test04TriggerCreate2ToDeployTestContract() { + "601b57600080fd5b50d28015602757600080fd5b50600436106066577c01000000000000000000000000000" + "00000000000000000000000000000600035046368e5c0668114606b578063e5aa3d58146083575b600080fd" + "5b60716089565b60408051918252519081900360200190f35b60716097565b6000805460010190819055905" - + "65b6000548156fe"; + + "65b6000548156fe0000000000000000000000000000000000000000000000000000000000000000000000"; Long salt = 1L; @@ -499,24 +429,6 @@ public void test04TriggerCreate2ToDeployTestContract() { blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - //accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); - //long devEnergyLimitAfter = accountResource.getEnergyLimit(); - //long devEnergyUsageAfter = accountResource.getEnergyUsed(); - //long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); - - //logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); - //logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); - //logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); - - //accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); - //long userEnergyLimitAfter = accountResource.getEnergyLimit(); - //long userEnergyUsageAfter = accountResource.getEnergyUsed(); - //long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) - // .getBalance(); - - //logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); - //logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); - //logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); Optional infoById = PublicMethed .getTransactionInfoById(triggerTxid, blockingStubFull); @@ -564,18 +476,11 @@ public void test04TriggerCreate2ToDeployTestContract() { Assert.assertEquals(Base58.encode58Check(factoryContractAddress), Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); - String msgSender = Base58.encode58Check(ByteArray.fromHexString(retList.get(2))); - Assert.assertNotEquals(msgSender, Base58.encode58Check(user001Address)); } - @Test(enabled = false, description = "Trigger Test contact") + @Test(enabled = true, description = "Trigger Test contact") public void test04TriggerTestContract() { - Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, - PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); @@ -651,14 +556,6 @@ public void test04TriggerTestContract() { long consumeUserPercent = smartContract.getConsumeUserResourcePercent(); logger.info("ConsumeURPercent: " + consumeUserPercent); - PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, - dev001Address, blockingStubFull); - PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, - dev001Address, blockingStubFull); - PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, - user001Address, blockingStubFull); - PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, - user001Address, blockingStubFull); } diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test002.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test002.java index 1deb99458a5..c65c7c0b403 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test002.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test002.java @@ -73,7 +73,7 @@ public void beforeClass() { PublicMethed.printAddress(user001Key); } - @Test(enabled = true, description = "Deploy factory contract") + @Test(enabled = false, description = "Deploy factory contract") public void test01DeployFactoryContract() { Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); @@ -87,17 +87,17 @@ public void test01DeployFactoryContract() { Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); + //PublicMethed.waitProduceNextBlock(blockingStubFull); //before deploy, check account resource - //AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, - // blockingStubFull); - //long energyLimit = accountResource.getEnergyLimit(); - //long energyUsage = accountResource.getEnergyUsed(); - //long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); - //logger.info("before energyLimit is " + Long.toString(energyLimit)); - //logger.info("before energyUsage is " + Long.toString(energyUsage)); - //logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long energyLimit = accountResource.getEnergyLimit(); + long energyUsage = accountResource.getEnergyUsed(); + long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before energyLimit is " + Long.toString(energyLimit)); + logger.info("before energyUsage is " + Long.toString(energyUsage)); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); String filePath = "./src/test/resources/soliditycode/create2contract.sol"; String contractName = "Factory"; @@ -113,14 +113,14 @@ public void test01DeployFactoryContract() { dev001Address, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - //accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); - //energyLimit = accountResource.getEnergyLimit(); - //energyUsage = accountResource.getEnergyUsed(); - //long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + energyLimit = accountResource.getEnergyLimit(); + energyUsage = accountResource.getEnergyUsed(); + long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); - //logger.info("after energyLimit is " + Long.toString(energyLimit)); - //logger.info("after energyUsage is " + Long.toString(energyUsage)); - //logger.info("after balanceAfter is " + Long.toString(balanceAfter)); + logger.info("after energyLimit is " + Long.toString(energyLimit)); + logger.info("after energyUsage is " + Long.toString(energyUsage)); + logger.info("after balanceAfter is " + Long.toString(balanceAfter)); Optional infoById = PublicMethed .getTransactionInfoById(transferTokenTxid, blockingStubFull); @@ -140,33 +140,13 @@ public void test01DeployFactoryContract() { } - @Test(enabled = true, description = "Trigger create2 command without meta data hash in bytecode") + @Test(enabled = false, description = "Trigger create2 command without meta data hash in bytecode") public void test02TriggerCreate2ToDeployTestContract() { Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, blockingStubFull), 0, 1, ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - //AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, - // blockingStubFull); - //long devEnergyLimitBefore = accountResource.getEnergyLimit(); - //long devEnergyUsageBefore = accountResource.getEnergyUsed(); - //long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); - - //logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); - //logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); - //logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); - - //accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); - //long userEnergyLimitBefore = accountResource.getEnergyLimit(); - //long userEnergyUsageBefore = accountResource.getEnergyUsed(); - //long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) - // .getBalance(); - - //logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); - //logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); - //logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); - Long callValue = Long.valueOf(0); String testContractCode = "608060405234801561001057600080fd5b50d3801561001d57600080fd5b50d2801" @@ -186,25 +166,6 @@ public void test02TriggerCreate2ToDeployTestContract() { blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - //accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); - //long devEnergyLimitAfter = accountResource.getEnergyLimit(); - //long devEnergyUsageAfter = accountResource.getEnergyUsed(); - //long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); - - //logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); - //logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); - //logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); - - //accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); - //long userEnergyLimitAfter = accountResource.getEnergyLimit(); - //long userEnergyUsageAfter = accountResource.getEnergyUsed(); - //long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) - // .getBalance(); - - //logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); - //logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); - //logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - Optional infoById = PublicMethed .getTransactionInfoById(triggerTxid, blockingStubFull); @@ -256,7 +217,7 @@ public void test02TriggerCreate2ToDeployTestContract() { } - @Test(enabled = true, description = "Trigger Test contract") + @Test(enabled = false, description = "Trigger Test contract") public void test03TriggerTestContract() { Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test003.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test003.java index 7749f813d51..1cc6b2d26b0 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test003.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test003.java @@ -145,25 +145,25 @@ public void test02TriggerCreate2WithInvalidBytecode() { blockingStubFull), 0, 1, ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - //AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, - // blockingStubFull); - //long devEnergyLimitBefore = accountResource.getEnergyLimit(); - //long devEnergyUsageBefore = accountResource.getEnergyUsed(); - //long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); - //logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); - //logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); - //logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); - //accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); - //long userEnergyLimitBefore = accountResource.getEnergyLimit(); - //long userEnergyUsageBefore = accountResource.getEnergyUsed(); - //long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) - // .getBalance(); + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); - //logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); - //logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); - //logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); Long callValue = Long.valueOf(0); @@ -185,24 +185,24 @@ public void test02TriggerCreate2WithInvalidBytecode() { blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - //accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); - //long devEnergyLimitAfter = accountResource.getEnergyLimit(); - //long devEnergyUsageAfter = accountResource.getEnergyUsed(); - //long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); - //logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); - //logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); - //logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); - //accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); - //long userEnergyLimitAfter = accountResource.getEnergyLimit(); - //long userEnergyUsageAfter = accountResource.getEnergyUsed(); - //long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) - // .getBalance(); + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); - //logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); - //logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); - //logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); Optional infoById = PublicMethed .getTransactionInfoById(triggerTxid, blockingStubFull); @@ -224,25 +224,25 @@ public void test03TriggerCreate2WithEmptyBytecode() { blockingStubFull), 0, 1, ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - //AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, - // blockingStubFull); - //long devEnergyLimitBefore = accountResource.getEnergyLimit(); - //long devEnergyUsageBefore = accountResource.getEnergyUsed(); - //long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); - //logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); - //logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); - //logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); - //accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); - //long userEnergyLimitBefore = accountResource.getEnergyLimit(); - //long userEnergyUsageBefore = accountResource.getEnergyUsed(); - //long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) - // .getBalance(); + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); - //logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); - //logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); - //logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); Long callValue = Long.valueOf(0); @@ -258,24 +258,24 @@ public void test03TriggerCreate2WithEmptyBytecode() { blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - //accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); - //long devEnergyLimitAfter = accountResource.getEnergyLimit(); - //long devEnergyUsageAfter = accountResource.getEnergyUsed(); - //long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); - //logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); - //logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); - //logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); - //accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); - //long userEnergyLimitAfter = accountResource.getEnergyLimit(); - //long userEnergyUsageAfter = accountResource.getEnergyUsed(); - //long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) - // .getBalance(); + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); - //logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); - //logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); - //logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); Optional infoById = PublicMethed .getTransactionInfoById(triggerTxid, blockingStubFull); @@ -297,7 +297,7 @@ public void test04TriggerCreate2WithShortBytecode() { blockingStubFull), 0, 1, ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - /*AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); @@ -315,7 +315,7 @@ public void test04TriggerCreate2WithShortBytecode() { logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); - logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore));*/ + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); Long callValue = Long.valueOf(0); @@ -331,7 +331,7 @@ public void test04TriggerCreate2WithShortBytecode() { blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - /*accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitAfter = accountResource.getEnergyLimit(); long devEnergyUsageAfter = accountResource.getEnergyUsed(); long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -348,7 +348,7 @@ public void test04TriggerCreate2WithShortBytecode() { logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); - logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter));*/ + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); Optional infoById = PublicMethed .getTransactionInfoById(triggerTxid, blockingStubFull); @@ -370,7 +370,7 @@ public void test05TriggerCreate2WithZeroBytecode() { blockingStubFull), 0, 1, ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - /*AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); @@ -388,7 +388,7 @@ public void test05TriggerCreate2WithZeroBytecode() { logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); - logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore));*/ + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); Long callValue = Long.valueOf(0); @@ -404,7 +404,7 @@ public void test05TriggerCreate2WithZeroBytecode() { blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - /*accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitAfter = accountResource.getEnergyLimit(); long devEnergyUsageAfter = accountResource.getEnergyUsed(); long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); @@ -421,7 +421,7 @@ public void test05TriggerCreate2WithZeroBytecode() { logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); - logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter));*/ + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); Optional infoById = PublicMethed .getTransactionInfoById(triggerTxid, blockingStubFull); @@ -443,7 +443,7 @@ public void test06TriggerCreate2WithNullBytecode() { blockingStubFull), 0, 1, ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); - /*AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); long devEnergyLimitBefore = accountResource.getEnergyLimit(); long devEnergyUsageBefore = accountResource.getEnergyUsed(); @@ -461,7 +461,7 @@ public void test06TriggerCreate2WithNullBytecode() { logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); - logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore));*/ + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); Long callValue = Long.valueOf(0); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test005.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test005.java index 54fcfa5daa1..2c3069120cc 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test005.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test005.java @@ -73,7 +73,7 @@ public void beforeClass() { PublicMethed.printAddress(user001Key); } - @Test(enabled = true, description = "Deploy factory contract") + @Test(enabled = false, description = "Deploy factory contract") public void test01DeployFactoryContract() { Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); @@ -140,7 +140,7 @@ public void test01DeployFactoryContract() { } - @Test(enabled = true, description = "Trigger create2 command with 0 extended bytecode") + @Test(enabled = false, description = "Trigger create2 command with 0 extended bytecode") public void test02TriggerCreate2ToDeployTestContract() { Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, @@ -252,7 +252,7 @@ public void test02TriggerCreate2ToDeployTestContract() { Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); } - @Test(enabled = true, description = "Trigger test contract") + @Test(enabled = false, description = "Trigger test contract") public void test03TriggerTestContract() { Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test006.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test006.java index fc13e53508d..c892288ad24 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test006.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test006.java @@ -139,7 +139,7 @@ public void test01DeployFactoryContract() { Assert.assertNotNull(smartContract.getAbi()); } - @Test(enabled = true, description = "Trigger create2 with salt 0") + @Test(enabled = true, description = "Trigger create2 with salt empty") public void test02TriggerCreate2ToDeployTestContract() { Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, @@ -172,6 +172,64 @@ public void test02TriggerCreate2ToDeployTestContract() { String contractName = "TestConstract"; HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String testContractCode = retMap.get("byteCode").toString(); + + String param = "\"" + testContractCode + "\"," + null; + boolean ret = false; + try { + final String triggerTxid = PublicMethed.triggerContract(factoryContractAddress, + "deploy(bytes,uint256)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + } catch (NullPointerException e) { + logger.info("Expected NullPointerException!"); + ret = true; + } + Assert.assertTrue(ret); + + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + user001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + user001Address, blockingStubFull); + } + + @Test(enabled = true, description = "Trigger create2 with salt 0") + public void test03TriggerCreate2ToDeployTestContract() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String testContractCode = retMap.get("byteCode").toString(); Long salt = 0L; @@ -251,8 +309,605 @@ public void test02TriggerCreate2ToDeployTestContract() { Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); } + @Test(enabled = true, description = "Trigger create2 with salt -1") + public void test04TriggerCreate2ToDeployTestContract() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String testContractCode = retMap.get("byteCode").toString(); + Long salt = -1L; + + String param = "\"" + testContractCode + "\"," + salt; + + final String triggerTxid = PublicMethed.triggerContract(factoryContractAddress, + "deploy(bytes,uint256)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + logger.info( + "the value: " + PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + + List retList = PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + + logger.info("actualSalt: " + actualSalt); + + byte[] tmpAddress = new byte[20]; + System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); + logger.info("address_hex: " + addressHex); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + logger.info("address_final: " + addressFinal); + + testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + SmartContract smartContract = PublicMethed.getContract(testContractAddress, blockingStubFull); + + Assert.assertEquals(salt, actualSalt); + + // contract created by create2, doesn't have ABI + Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); + + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); + + // the contract address in transaction info, + // contract address of create2 contract is factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); + } + + @Test(enabled = true, description = "Trigger create2 with salt 100") + public void test05TriggerCreate2ToDeployTestContract() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String testContractCode = retMap.get("byteCode").toString(); + Long salt = 100L; + + String param = "\"" + testContractCode + "\"," + salt; + + final String triggerTxid = PublicMethed.triggerContract(factoryContractAddress, + "deploy(bytes,uint256)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + logger.info( + "the value: " + PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + + List retList = PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + + logger.info("actualSalt: " + actualSalt); + + byte[] tmpAddress = new byte[20]; + System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); + logger.info("address_hex: " + addressHex); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + logger.info("address_final: " + addressFinal); + + testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + SmartContract smartContract = PublicMethed.getContract(testContractAddress, blockingStubFull); + + Assert.assertEquals(salt, actualSalt); + + // contract created by create2, doesn't have ABI + Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); + + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); + + // the contract address in transaction info, + // contract address of create2 contract is factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); + } + + @Test(enabled = true, description = "Trigger create2 with salt f * 64") + public void test06TriggerCreate2ToDeployTestContract() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String testContractCode = retMap.get("byteCode").toString(); + + String saltHexString = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"; + logger.info("saltHexString: " + saltHexString); + + String param = "\"" + testContractCode + "\",\"" + saltHexString + "\""; + + final String triggerTxid = PublicMethed.triggerContract(factoryContractAddress, + "deploy(bytes,bytes32)", param, false, callValue, + 1000000000L, "0", 0, dev001Address, dev001Key, + blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + logger.info( + "the value: " + PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + + List retList = PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + + // The first + byte[] tmpAddress = new byte[20]; + System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); + logger.info("addressHex: " + addressHex); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + logger.info("addressFinal: " + addressFinal); + testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); + + String actualSalt = retList.get(1); + logger.info("actualSalt: " + actualSalt); + + byte[] tmpSenderAddress = new byte[20]; + System.arraycopy(ByteArray.fromHexString(retList.get(2)), 12, tmpSenderAddress, 0, 20); + String senderAddressHex = "41" + ByteArray.toHexString(tmpAddress); + logger.info("senderAddressHex: " + senderAddressHex); + String senderAddressFinal = Base58.encode58Check(ByteArray.fromHexString(senderAddressHex)); + logger.info("senderAddressFinal: " + senderAddressFinal); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + SmartContract smartContract = PublicMethed.getContract(testContractAddress, blockingStubFull); + + Assert.assertEquals(saltHexString, actualSalt); + + // contract created by create2, doesn't have ABI + Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); + + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); + + // the contract address in transaction info, + // contract address of create2 contract is factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); + } + + @Test(enabled = true, description = "Trigger create2 with salt efffe") + public void test07TriggerCreate2ToDeployTestContract() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String testContractCode = retMap.get("byteCode").toString(); + + final String saltHexString = "EFFFE"; + final String expectedSalt = "0EFFFE0000000000000000000000000000000000000000000000000000000000"; + + logger.info("saltHexString: " + saltHexString); + + String param = "\"" + testContractCode + "\",\"" + saltHexString + "\""; + + final String triggerTxid = PublicMethed.triggerContract(factoryContractAddress, + "deploy(bytes,bytes32)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + logger.info( + "the value: " + PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + + List retList = PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + + // The first + byte[] tmpAddress = new byte[20]; + System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); + logger.info("addressHex: " + addressHex); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + logger.info("addressFinal: " + addressFinal); + testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); + + String actualSalt = retList.get(1); + logger.info("actualSalt: " + actualSalt); + + byte[] tmpSenderAddress = new byte[20]; + System.arraycopy(ByteArray.fromHexString(retList.get(2)), 12, tmpSenderAddress, 0, 20); + String senderAddressHex = "41" + ByteArray.toHexString(tmpAddress); + logger.info("senderAddressHex: " + senderAddressHex); + String senderAddressFinal = Base58.encode58Check(ByteArray.fromHexString(senderAddressHex)); + logger.info("senderAddressFinal: " + senderAddressFinal); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + SmartContract smartContract = PublicMethed.getContract(testContractAddress, blockingStubFull); + + Assert.assertEquals(expectedSalt, actualSalt); + + // contract created by create2, doesn't have ABI + Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); + + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); + + // the contract address in transaction info, + // contract address of create2 contract is factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); + } + + @Test(enabled = true, description = "Trigger create2 with salt affffa") + public void test08TriggerCreate2ToDeployTestContract() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String testContractCode = retMap.get("byteCode").toString(); + + final String saltHexString = "AFFFFA"; + final String expectedSalt = "AFFFFA0000000000000000000000000000000000000000000000000000000000"; + logger.info("saltHexString: " + saltHexString); + + String param = "\"" + testContractCode + "\",\"" + saltHexString + "\""; + + final String triggerTxid = PublicMethed.triggerContract(factoryContractAddress, + "deploy(bytes,bytes32)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + logger.info( + "the value: " + PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + + List retList = PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + + // The first + byte[] tmpAddress = new byte[20]; + System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); + logger.info("addressHex: " + addressHex); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + logger.info("addressFinal: " + addressFinal); + testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); + + String actualSalt = retList.get(1); + logger.info("actualSalt: " + actualSalt); + + byte[] tmpSenderAddress = new byte[20]; + System.arraycopy(ByteArray.fromHexString(retList.get(2)), 12, tmpSenderAddress, 0, 20); + String senderAddressHex = "41" + ByteArray.toHexString(tmpAddress); + logger.info("senderAddressHex: " + senderAddressHex); + String senderAddressFinal = Base58.encode58Check(ByteArray.fromHexString(senderAddressHex)); + logger.info("senderAddressFinal: " + senderAddressFinal); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + SmartContract smartContract = PublicMethed.getContract(testContractAddress, blockingStubFull); + + Assert.assertEquals(expectedSalt, actualSalt); + + // contract created by create2, doesn't have ABI + Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); + + // the contract owner of contract created by create2 is the factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); + + // the contract address in transaction info, + // contract address of create2 contract is factory contract + Assert.assertEquals(Base58.encode58Check(factoryContractAddress), + Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); + + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + dev001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, + user001Address, blockingStubFull); + PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, + user001Address, blockingStubFull); + } + @Test(enabled = true, description = "Trigger test contract") - public void test03TriggerTestContract() { + public void test09TriggerTestContract() { Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test007.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test007.java index 93667d9d01c..f4ab1ea698f 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test007.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test007.java @@ -73,7 +73,7 @@ public void beforeClass() { PublicMethed.printAddress(user001Key); } - @Test(enabled = true, description = "Deploy factory contract") + @Test(enabled = false, description = "Deploy factory contract") public void test01DeployFactoryContract() { Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); @@ -139,7 +139,7 @@ public void test01DeployFactoryContract() { Assert.assertNotNull(smartContract.getAbi()); } - @Test(enabled = true, description = "Trigger create2 with salt -1") + @Test(enabled = false, description = "Trigger create2 with salt -1") public void test02TriggerCreate2ToDeployTestContract() { Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, @@ -251,7 +251,7 @@ public void test02TriggerCreate2ToDeployTestContract() { Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); } - @Test(enabled = true, description = "Trigger test contract") + @Test(enabled = false, description = "Trigger test contract") public void test03TriggerTestContract() { Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test008.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test008.java index 2605a1e87d2..3bd45115367 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test008.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test008.java @@ -73,7 +73,7 @@ public void beforeClass() { PublicMethed.printAddress(user001Key); } - @Test(enabled = true, description = "Deploy factory contract") + @Test(enabled = false, description = "Deploy factory contract") public void test01DeployFactoryContract() { Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); @@ -139,7 +139,7 @@ public void test01DeployFactoryContract() { Assert.assertNotNull(smartContract.getAbi()); } - @Test(enabled = true, description = "Trigger create2 with salt 100") + @Test(enabled = false, description = "Trigger create2 with salt 100") public void test02TriggerCreate2ToDeployTestContract() { Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, @@ -251,7 +251,7 @@ public void test02TriggerCreate2ToDeployTestContract() { Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); } - @Test(enabled = true, description = "Trigger test contract") + @Test(enabled = false, description = "Trigger test contract") public void test03TriggerTestContract() { Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test009.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test009.java index 29214cc5b1b..cda26f9439e 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test009.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test009.java @@ -73,7 +73,7 @@ public void beforeClass() { PublicMethed.printAddress(user001Key); } - @Test(enabled = true, description = "Deploy factory contract generated by new solidity") + @Test(enabled = false, description = "Deploy factory contract generated by new solidity") public void test01DeployFactoryContract() { Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); @@ -140,7 +140,7 @@ public void test01DeployFactoryContract() { } - @Test(enabled = true, description = "Trigger create2 function to deploy test contract") + @Test(enabled = false, description = "Trigger create2 function to deploy test contract") public void test02TriggerCreate2ToDeployTestContract() { Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, @@ -258,7 +258,7 @@ public void test02TriggerCreate2ToDeployTestContract() { } - @Test(enabled = true, description = "Trigger Test contact") + @Test(enabled = false, description = "Trigger Test contact") public void test03TriggerTestContract() { Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test010.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test010.java index 363f35195ac..df968624a91 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test010.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test010.java @@ -70,7 +70,7 @@ public void beforeClass() { PublicMethed.printAddress(user001Key); } - @Test(enabled = true, description = "TransferToken with correct value, deploy transfer contract") + @Test(enabled = false, description = "TransferToken with correct value, deploy transfer contract") public void test01DeployFactoryContract() { Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); @@ -137,7 +137,7 @@ public void test01DeployFactoryContract() { } - @Test(enabled = true, description = "Trigger create2 with salt empty") + @Test(enabled = false, description = "Trigger create2 with salt empty") public void test02TriggerCreate2ToDeployTestContract() { Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test011.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test011.java index eeb73d935d1..d41603ce140 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test011.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test011.java @@ -73,7 +73,7 @@ public void beforeClass() { PublicMethed.printAddress(user001Key); } - @Test(enabled = true, description = "Deploy factory contract") + @Test(enabled = false, description = "Deploy factory contract") public void test01DeployFactoryContract() { Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); @@ -140,7 +140,7 @@ public void test01DeployFactoryContract() { } - @Test(enabled = true, description = "Trigger create2 with salt f * 64") + @Test(enabled = false, description = "Trigger create2 with salt f * 64") public void test02TriggerCreate2ToDeployTestContract() { Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, @@ -262,7 +262,7 @@ public void test02TriggerCreate2ToDeployTestContract() { } - @Test(enabled = true, description = "Trigger test contract") + @Test(enabled = false, description = "Trigger test contract") public void test03TriggerTestContract() { Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test012.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test012.java index 219bc889d1e..0d33efa7f04 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test012.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test012.java @@ -74,7 +74,7 @@ public void beforeClass() { PublicMethed.printAddress(user001Key); } - @Test(enabled = true, description = "Deploy factory contract") + @Test(enabled = false, description = "Deploy factory contract") public void test01DeployFactoryContract() { Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); @@ -141,7 +141,7 @@ public void test01DeployFactoryContract() { } - @Test(enabled = true, description = "Trigger create2 command with test bytecode and salt 1") + @Test(enabled = false, description = "Trigger create2 command with test bytecode and salt 1") public void test02TriggerCreate2ToDeployTestContract() { Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 80000L, @@ -255,7 +255,7 @@ public void test02TriggerCreate2ToDeployTestContract() { } - @Test(enabled = true, description = "Trigger create2 command with test bytecode and salt 2") + @Test(enabled = false, description = "Trigger create2 command with test bytecode and salt 2") public void test03TriggerCreate2ToDeployTestContract2() { Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 80000L, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test013.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test013.java index 5e800d573a5..82d6c405ca8 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test013.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test013.java @@ -75,7 +75,7 @@ public void beforeClass() { PublicMethed.printAddress(user001Key); } - @Test(enabled = true, description = "Deploy factory contract") + @Test(enabled = false, description = "Deploy factory contract") public void test01DeployFactoryContract() { Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); @@ -141,7 +141,7 @@ public void test01DeployFactoryContract() { Assert.assertNotNull(smartContract.getAbi()); } - @Test(enabled = true, description = "Trigger factory contract to deploy test contract") + @Test(enabled = false, description = "Trigger factory contract to deploy test contract") public void test02TriggerCreate2ToDeployTestContract() { Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, @@ -252,7 +252,7 @@ public void test02TriggerCreate2ToDeployTestContract() { Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); } - @Test(enabled = true, description = "Trigger factory contract to deploy test contract again " + @Test(enabled = false, description = "Trigger factory contract to deploy test contract again " + "with same code, salt and address") public void test03TriggerCreate2ToDeployTestContractAgain() { Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, @@ -329,7 +329,7 @@ public void test03TriggerCreate2ToDeployTestContractAgain() { containsString("Not enough energy for 'SWAP1' operation executing")); } - @Test(enabled = true, description = "Trigger test1 contract") + @Test(enabled = false, description = "Trigger test1 contract") public void test04TriggerTestContract() { Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test014.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test014.java index 4e80b4598c8..974f0e4321c 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test014.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test014.java @@ -1,5 +1,7 @@ package stest.tron.wallet.dailybuild.tvmnewcommand.create2; +import static org.hamcrest.core.StringContains.containsString; + import com.google.protobuf.ByteString; import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; @@ -253,6 +255,82 @@ public void test02TriggerCreate2ToDeployTestContract() { Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); } + @Test(enabled = true, description = "Trigger factory contract to deploy test contract again " + + "with same code, salt and address") + public void test02TriggerCreate2ToDeployTestContractAgain() { + Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, + PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, + blockingStubFull), 0, 1, + ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String testContractCode = retMap.get("byteCode").toString(); + Long salt = 1L; + + String param = "\"" + testContractCode + "\"," + salt; + + final String triggerTxid = PublicMethed.triggerContract(factoryContractAddress, + "deploy(bytes,uint256)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + Assert.assertEquals(1, infoById.get().getResultValue()); + Assert + .assertThat(infoById.get().getResMessage().toStringUtf8(), + containsString("Not enough energy for 'SWAP1' operation executing")); + } @Test(enabled = true, description = "Same code, salt and address," + " create contract using develop account") diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test015.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test015.java index 97749c9dedc..65259f1bc09 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test015.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test015.java @@ -43,7 +43,8 @@ public class Create2Test015 { private byte[] factoryContractAddress = null; private byte[] callerContractAddress = null; - private byte[] testContractAddress = null; + private byte[] callContractAddress = null; + private byte[] delegateCallContractAddress = null; private ECKey ecKey1 = new ECKey(Utils.getRandom()); private byte[] dev001Address = ecKey1.getAddress(); @@ -80,13 +81,6 @@ public void test01DeployCallerContract() { testKey002, blockingStubFull)); Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, - PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); - - Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, - 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); PublicMethed.waitProduceNextBlock(blockingStubFull); @@ -142,15 +136,6 @@ public void test01DeployCallerContract() { @Test(enabled = true, description = "Deploy factory contract") public void test02DeployFactoryContract() { - Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, - PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); - - Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, - 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); - - PublicMethed.waitProduceNextBlock(blockingStubFull); //before deploy, check account resource AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, @@ -205,10 +190,6 @@ public void test02DeployFactoryContract() { @Test(enabled = true, description = "Trigger callCreate2 function in caller contract " + "with factory contract address") public void test03TriggerCreate2ToDeployTestContract() { - Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, - PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); @@ -293,14 +274,14 @@ public void test03TriggerCreate2ToDeployTestContract() { String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); logger.info("address_final: " + addressFinal); - testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); + callContractAddress = WalletClient.decodeFromBase58Check(addressFinal); if (infoById.get().getResultValue() != 0) { Assert.fail( "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); } - SmartContract smartContract = PublicMethed.getContract(testContractAddress, blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(callContractAddress, blockingStubFull); // contract created by create2, doesn't have ABI Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); @@ -315,13 +296,118 @@ public void test03TriggerCreate2ToDeployTestContract() { Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); } - @Test(enabled = true, description = "Trigger test contract") - public void test04TriggerTestContract() { + @Test(enabled = true, description = "Trigger delegateCallCreate2 function in caller contract " + + "with factory contract address") + public void test04TriggerCreate2ToDeployTestContract() { + + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long devEnergyLimitBefore = accountResource.getEnergyLimit(); + long devEnergyUsageBefore = accountResource.getEnergyUsed(); + long devBalanceBefore = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("before trigger, devEnergyLimitBefore is " + Long.toString(devEnergyLimitBefore)); + logger.info("before trigger, devEnergyUsageBefore is " + Long.toString(devEnergyUsageBefore)); + logger.info("before trigger, devBalanceBefore is " + Long.toString(devBalanceBefore)); + + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitBefore = accountResource.getEnergyLimit(); + long userEnergyUsageBefore = accountResource.getEnergyUsed(); + long userBalanceBefore = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("before trigger, userEnergyLimitBefore is " + Long.toString(userEnergyLimitBefore)); + logger.info("before trigger, userEnergyUsageBefore is " + Long.toString(userEnergyUsageBefore)); + logger.info("before trigger, userBalanceBefore is " + Long.toString(userBalanceBefore)); + + Long callValue = Long.valueOf(0); + + String filePath = "./src/test/resources/soliditycode/create2contract.sol"; + String contractName = "TestConstract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String testContractCode = retMap.get("byteCode").toString(); + + Long salt = 1L; + + String param = "\"" + Base58.encode58Check(factoryContractAddress) + + "\",\"" + testContractCode + "\"," + salt; + + final String triggerTxid = PublicMethed.triggerContract(callerContractAddress, + "delegateCallCreate2(address,bytes,uint256)", param, false, callValue, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + long devEnergyLimitAfter = accountResource.getEnergyLimit(); + long devEnergyUsageAfter = accountResource.getEnergyUsed(); + long devBalanceAfter = PublicMethed.queryAccount(dev001Address, blockingStubFull).getBalance(); + + logger.info("after trigger, devEnergyLimitAfter is " + Long.toString(devEnergyLimitAfter)); + logger.info("after trigger, devEnergyUsageAfter is " + Long.toString(devEnergyUsageAfter)); + logger.info("after trigger, devBalanceAfter is " + Long.toString(devBalanceAfter)); - Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, - PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); + long userEnergyLimitAfter = accountResource.getEnergyLimit(); + long userEnergyUsageAfter = accountResource.getEnergyUsed(); + long userBalanceAfter = PublicMethed.queryAccount(user001Address, blockingStubFull) + .getBalance(); + + logger.info("after trigger, userEnergyLimitAfter is " + Long.toString(userEnergyLimitAfter)); + logger.info("after trigger, userEnergyUsageAfter is " + Long.toString(userEnergyUsageAfter)); + logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + logger.info( + "the value: " + PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray())); + + List retList = PublicMethed + .getStrings(transactionInfo.getLogList().get(0).getData().toByteArray()); + + Long actualSalt = ByteArray.toLong(ByteArray.fromHexString(retList.get(1))); + + logger.info("actualSalt: " + actualSalt); + + byte[] tmpAddress = new byte[20]; + System.arraycopy(ByteArray.fromHexString(retList.get(0)), 12, tmpAddress, 0, 20); + String addressHex = "41" + ByteArray.toHexString(tmpAddress); + logger.info("address_hex: " + addressHex); + String addressFinal = Base58.encode58Check(ByteArray.fromHexString(addressHex)); + logger.info("address_final: " + addressFinal); + + delegateCallContractAddress = WalletClient.decodeFromBase58Check(addressFinal); + + if (infoById.get().getResultValue() != 0) { + Assert.fail( + "transaction failed with message: " + infoById.get().getResMessage().toStringUtf8()); + } + + SmartContract smartContract = PublicMethed + .getContract(delegateCallContractAddress, blockingStubFull); + + // contract created by create2, doesn't have ABI + Assert.assertEquals(0, smartContract.getAbi().getEntrysCount()); + + // delegatecall type make the caller contract to be the owner of test contract (contract info) + Assert.assertEquals(Base58.encode58Check(callerContractAddress), + Base58.encode58Check(smartContract.getOriginAddress().toByteArray())); + + // call type make the caller contract to be the owner of test contract + // (the contract address in transaction info) + Assert.assertEquals(Base58.encode58Check(callerContractAddress), + Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); + } + + @Test(enabled = true, description = "Trigger test contract") + public void test09TriggerTestContract() { AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); @@ -345,7 +431,7 @@ public void test04TriggerTestContract() { Long callValue = Long.valueOf(0); - final String triggerTxid = PublicMethed.triggerContract(testContractAddress, + final String triggerTxid = PublicMethed.triggerContract(callContractAddress, "plusOne()", "#", false, callValue, 1000000000L, "0", 0, user001Address, user001Key, blockingStubFull); @@ -398,14 +484,6 @@ public void test04TriggerTestContract() { long consumeUserPercent = smartContract.getConsumeUserResourcePercent(); logger.info("ConsumeURPercent: " + consumeUserPercent); - PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, - dev001Address, blockingStubFull); - PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, - dev001Address, blockingStubFull); - PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, - user001Address, blockingStubFull); - PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, - user001Address, blockingStubFull); } /** diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test016.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test016.java index b2e60f55d91..d4b45711d72 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test016.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test016.java @@ -74,7 +74,7 @@ public void beforeClass() { PublicMethed.printAddress(user001Key); } - @Test(enabled = true, description = "TransferToken with correct value, deploy transfer contract") + @Test(enabled = false, description = "Deploy caller contract") public void test01DeployCallerContract() { Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); @@ -140,7 +140,7 @@ public void test01DeployCallerContract() { Assert.assertNotNull(smartContract.getAbi()); } - @Test(enabled = true, description = "TransferToken with correct value, deploy transfer contract") + @Test(enabled = false, description = "Deploy factory contract") public void test02DeployFactoryContract() { Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, @@ -202,7 +202,8 @@ public void test02DeployFactoryContract() { Assert.assertNotNull(smartContract.getAbi()); } - @Test(enabled = true, description = "TransferToken with correct value, deploy receive contract") + @Test(enabled = false, description = "Trigger delegateCallCreate2 function in caller contract " + + "with factory contract address") public void test03TriggerCreate2ToDeployTestContract() { Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, @@ -314,7 +315,7 @@ public void test03TriggerCreate2ToDeployTestContract() { Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); } - @Test(enabled = true, description = "Trigger test contract") + @Test(enabled = false, description = "Trigger test contract") public void test04TriggerTestContract() { Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test017.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test017.java index 98a1bde95e4..872dc4ebbc9 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test017.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test017.java @@ -73,7 +73,7 @@ public void beforeClass() { PublicMethed.printAddress(user001Key); } - @Test(enabled = true, description = "Deploy factory contract") + @Test(enabled = false, description = "Deploy factory contract") public void test01DeployFactoryContract() { Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); @@ -139,7 +139,7 @@ public void test01DeployFactoryContract() { Assert.assertNotNull(smartContract.getAbi()); } - @Test(enabled = true, description = "Trigger create2 with salt efffe") + @Test(enabled = false, description = "Trigger create2 with salt efffe") public void test02TriggerCreate2ToDeployTestContract() { Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, @@ -261,7 +261,7 @@ public void test02TriggerCreate2ToDeployTestContract() { Base58.encode58Check(infoById.get().getContractAddress().toByteArray())); } - @Test(enabled = true, description = "Trigger create2 with salt affffa") + @Test(enabled = false, description = "Trigger create2 with salt affffa") public void test03TriggerCreate2ToDeployTestContract() { Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test018.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test018.java index 6698b38acaa..c0a0096ae0e 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test018.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test018.java @@ -74,7 +74,7 @@ public void beforeClass() { PublicMethed.printAddress(witnessKey001); } - @Test(enabled = true, description = "Deploy factory contract generated by new solidity") + @Test(enabled = false, description = "Deploy factory contract generated by new solidity") public void test01DeployFactoryContract() { Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); @@ -141,7 +141,7 @@ public void test01DeployFactoryContract() { } - @Test(enabled = true, description = "Trigger create2 function to deploy test contract " + @Test(enabled = false, description = "Trigger create2 function to deploy test contract " + "using Witness account") public void test02TriggerCreate2ToDeployTestContract() { Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 9000_000_000_000L, 0, 1, @@ -251,7 +251,7 @@ public void test02TriggerCreate2ToDeployTestContract() { } - @Test(enabled = true, description = "Trigger Test contact") + @Test(enabled = false, description = "Trigger Test contact") public void test03TriggerTestContract() { Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test019.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test019.java index 86b6622c216..2df21ff119c 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test019.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test019.java @@ -241,8 +241,8 @@ public void testTriggerContract() { .assertThat(transactionExtention.getResult().getCode().toString(), containsString("CONTRACT_VALIDATE_ERROR")); Assert - .assertThat(transactionExtention.getResult().getMessage().toStringUtf8() - , containsString("contract validate error : No contract or not a smart contract")); + .assertThat(transactionExtention.getResult().getMessage().toStringUtf8(), + containsString("contract validate error : No contract or not a smart contract")); txid = PublicMethed .triggerContract(contractAddress, @@ -259,8 +259,8 @@ public void testTriggerContract() { "i()", "#", false, 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - infoById1 = PublicMethed.getTransactionInfoById(txid, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); + infoById1 = PublicMethed.getTransactionInfoById(txid, blockingStubFull); returnnumber = ByteArray.toLong(ByteArray .fromHexString(ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); Assert.assertTrue(1 == returnnumber); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test020.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test020.java index 96e0e6f4eb8..36eb317a473 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test020.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test020.java @@ -87,7 +87,7 @@ public void beforeClass() { blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = true, description = "triggerContract a constant function created by create2") + @Test(enabled = true, description = "deploy Factory contract, create2 with salt type : trcToken") public void testTriggerContract() { Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, @@ -205,22 +205,8 @@ public void testTriggerContract() { } - @Test(enabled = true, description = "triggerContract a constant function created by create2") + @Test(enabled = true, description = "deploy Factory contract, create2 with salt type : uint8") public void testTriggerContract1() { - Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/create2contract22.sol"; - String contractName = "Factory1"; - HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -236,6 +222,7 @@ public void testTriggerContract1() { logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); String contractName1 = "TestConstract"; + String filePath = "src/test/resources/soliditycode/create2contract22.sol"; HashMap retMap1 = PublicMethed.getBycodeAbi(filePath, contractName1); String code1 = retMap1.get("byteCode").toString(); String abi1 = retMap1.get("abI").toString(); @@ -243,7 +230,7 @@ public void testTriggerContract1() { String num = "\"" + code1 + "\"" + "," + 1000001; txid = PublicMethed .triggerContract(contractAddress, - "deploy(bytes,uint8)", num, false, + "deploy1(bytes,uint8)", num, false, 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); @@ -324,22 +311,8 @@ public void testTriggerContract1() { } - @Test(enabled = true, description = "triggerContract a constant function created by create2") + @Test(enabled = true, description = "deploy Factory contract, create2 with salt type : address") public void testTriggerContract2() { - Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/create2contract22.sol"; - String contractName = "Factory2"; - HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -355,6 +328,7 @@ public void testTriggerContract2() { logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); String contractName1 = "TestConstract"; + String filePath = "src/test/resources/soliditycode/create2contract22.sol"; HashMap retMap1 = PublicMethed.getBycodeAbi(filePath, contractName1); String code1 = retMap1.get("byteCode").toString(); String abi1 = retMap1.get("abI").toString(); @@ -362,7 +336,7 @@ public void testTriggerContract2() { String num = "\"" + code1 + "\"" + ",\"" + Base58.encode58Check(contractExcAddress) + "\""; txid = PublicMethed .triggerContract(contractAddress, - "deploy(bytes,address)", num, false, + "deploy2(bytes,address)", num, false, 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); @@ -443,22 +417,8 @@ public void testTriggerContract2() { } - @Test(enabled = true, description = "triggerContract a constant function created by create2") + @Test(enabled = true, description = "deploy Factory contract, create2 with salt type : string") public void testTriggerContract3() { - Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/create2contract22.sol"; - String contractName = "Factory3"; - HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -474,6 +434,7 @@ public void testTriggerContract3() { logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); String contractName1 = "TestConstract"; + String filePath = "src/test/resources/soliditycode/create2contract22.sol"; HashMap retMap1 = PublicMethed.getBycodeAbi(filePath, contractName1); String code1 = retMap1.get("byteCode").toString(); String abi1 = retMap1.get("abI").toString(); @@ -481,7 +442,7 @@ public void testTriggerContract3() { String num = "\"" + code1 + "\"" + ",\"" + Base58.encode58Check(contractExcAddress) + "\""; txid = PublicMethed .triggerContract(contractAddress, - "deploy(bytes,string)", num, false, + "deploy3(bytes,string)", num, false, 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test023.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test023.java index aed91c3bf3d..99f313b910d 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test023.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test023.java @@ -1,5 +1,7 @@ package stest.tron.wallet.dailybuild.tvmnewcommand.create2; +import static org.hamcrest.core.StringContains.containsString; + import com.google.protobuf.ByteString; import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test025.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test025.java index 53ed8df448f..e63db5de9ef 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test025.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test025.java @@ -77,15 +77,7 @@ public void beforeClass() { PublicMethed.printAddress(user001Key); } - - public byte[] subByte(byte[] b, int off, int length) { - byte[] b1 = new byte[length]; - System.arraycopy(b, off, b1, 0, length); - return b1; - - } - - @Test(enabled = true, description = "Deploy factory contract") + @Test(enabled = false, description = "Deploy factory contract") public void test01DeployFactoryContract() { Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 10000_000_000L, fromAddress, testKey002, blockingStubFull)); @@ -145,7 +137,7 @@ public void test01DeployFactoryContract() { Assert.assertNotNull(smartContract.getAbi()); } - @Test(enabled = true, description = "create2 bytecode with parm") + @Test(enabled = false, description = "create2 bytecode with parm") public void test02TriggerTestContract() { //Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, // PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, @@ -182,7 +174,8 @@ public void test02TriggerTestContract() { String param = "\"" + testContractCode + "\"," + salt; - String triggerTxid = PublicMethed.triggerContract(factoryContractAddress, + String triggerTxid = null; + triggerTxid = PublicMethed.triggerContract(factoryContractAddress, "create2(bytes,uint256)", param, false, 0L, 1000000000L, "0", 0, user001Address, user001Key, blockingStubFull); @@ -236,13 +229,14 @@ public void test02TriggerTestContract() { testContractAddress = WalletClient.decodeFromBase58Check(addressFinal); - String Txid = PublicMethed.triggerContract(testContractAddress, + String txid = PublicMethed.triggerContract(testContractAddress, "getNum()", "#", false, 0L, 1000000000L, "0", 0, user001Address, user001Key, blockingStubFull); - Optional infoById2 = PublicMethed.getTransactionInfoById(Txid,blockingStubFull); + Optional infoById2 = PublicMethed.getTransactionInfoById(txid, + blockingStubFull); TransactionInfo transactionInfo2 = infoById2.get(); - int NUM = ByteArray.toInt(transactionInfo2.getContractResult(0).toByteArray()); + final int Num = ByteArray.toInt(transactionInfo2.getContractResult(0).toByteArray()); accountResource = PublicMethed.getAccountResource(user001Address, blockingStubFull); @@ -255,10 +249,10 @@ public void test02TriggerTestContract() { logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); logger.info("after trigger, userBalanceAfter is " + Long.toString(userBalanceAfter)); - logger.info("NUM :" +NUM); + logger.info("NUM :" + Num); Assert.assertEquals(infoById.get().getResult().toString(),"SUCESS"); Assert.assertEquals(infoById.get().getResultValue(),0); - Assert.assertEquals(5,NUM); + Assert.assertEquals(5,Num); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest001.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest001.java index adc4d15db8a..6a4ed8c9c77 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest001.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest001.java @@ -240,10 +240,6 @@ public void test02GetNormalAddressCodeHash() { @Test(enabled = true, description = "Get a contract extcodehash") public void test03GetContactCodeHash() { - Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, - PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); @@ -544,8 +540,8 @@ public void test06GetCreate2CodeHash() { Long callValue = Long.valueOf(0); - String param = - "\"" + Base58.encode58Check(WalletClient.decodeFromBase58Check(testContractAddress2)) + "\""; + String param = "\"" + + Base58.encode58Check(WalletClient.decodeFromBase58Check(testContractAddress2)) + "\""; final String triggerTxid = PublicMethed.triggerContract(extCodeHashContractAddress, "getCodeHashByAddr(address)", param, false, callValue, 1000000000L, "0", 0, user001Address, user001Key, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest003.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest003.java index c97b9a02b2f..3135f1d6fbc 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest003.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest003.java @@ -29,7 +29,7 @@ @Slf4j public class ExtCodeHashTest003 { - private final static boolean AllTest = false; + private final boolean AllTest = false; private final String testKey002 = Configuration.getByPath("testng.conf") .getString("foundationAccount.key2"); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest005.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest005.java index 4a1ae8ec7fe..15edc1d6140 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest005.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest005.java @@ -84,13 +84,13 @@ public void beforeClass() { logger.info("realAddress: " + fakeAddress); byte[] fullHexAddr = new DataWord(fakeAddress).getData(); - logger.info("fullHexAddr ++= "+ Hex.toHexString(fullHexAddr)); + logger.info("fullHexAddr ++= " + Hex.toHexString(fullHexAddr)); fakeAddress = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"; logger.info("realAddress: " + fakeAddress); fullHexAddr = new DataWord(fakeAddress).getData(); - logger.info("fullHexAddr ++= "+Hex.toHexString(fullHexAddr)); + logger.info("fullHexAddr ++= " + Hex.toHexString(fullHexAddr)); } @@ -458,7 +458,7 @@ public void test05GetEmptyAddressCodeHash() { logger.info("realAddress: " + fakeAddress); byte[] fullHexAddr = new DataWord(fakeAddress).getData(); - logger.info("fullHexAddr ++= "+ Hex.toHexString(fullHexAddr)); + logger.info("fullHexAddr ++= " + Hex.toHexString(fullHexAddr)); final String triggerTxid = PublicMethed.triggerContract(extCodeHashContractAddress, @@ -549,7 +549,7 @@ public void test06GetFakeAddressCodeHash() { logger.info("realAddress: " + fakeAddress); byte[] fullHexAddr = new DataWord(fakeAddress).getData(); - logger.info("fullHexAddr ++= "+Hex.toHexString(fullHexAddr)); + logger.info("fullHexAddr ++= " + Hex.toHexString(fullHexAddr)); final String triggerTxid = PublicMethed.triggerContract(extCodeHashContractAddress, @@ -701,6 +701,7 @@ public void test07GetContractAddress96CodeHash() { user001Address, blockingStubFull); } + /** * constructor. */ diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest007.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest007.java index c294e24445f..de855a02eb3 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest007.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest007.java @@ -349,7 +349,8 @@ public void test04GetTestOldCodeHash() { "the value: " + retList); expectedCodeHashOld = retList.get(0); - Assert.assertEquals("B4AB5B9FF1A4FF7793E60EBFF0C769443AF66D0A6F9455AF145432CE8BA78175",expectedCodeHashOld); + Assert.assertEquals( + "B4AB5B9FF1A4FF7793E60EBFF0C769443AF66D0A6F9455AF145432CE8BA78175",expectedCodeHashOld); Assert.assertFalse(retList.isEmpty()); } @@ -432,7 +433,8 @@ public void test05GetTestNewCodeHash() { Assert.assertNotEquals(retList.get(0), expectedCodeHashOld); expectedCodeHash = retList.get(0); - Assert.assertEquals("34DB53BD1F7214367E8D6B2A7A6FBBF0E3B7DDB4939ECADE4CDEF6749C27A2DA",expectedCodeHash); + Assert.assertEquals( + "34DB53BD1F7214367E8D6B2A7A6FBBF0E3B7DDB4939ECADE4CDEF6749C27A2DA",expectedCodeHash); } @Test(enabled = true, description = "Deploy contract using new solidity again") diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest010.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest010.java index 6fc1acf4bbe..749edb6101b 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest010.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest010.java @@ -30,6 +30,7 @@ @Slf4j public class ExtCodeHashTest010 { + final boolean AllTest = false; private final String testKey002 = Configuration.getByPath("testng.conf") .getString("foundationAccount.key2"); private final byte[] fromAddress = PublicMethed.getFinalAddress(testKey002); @@ -76,7 +77,7 @@ public void beforeClass() { PublicMethed.printAddress(user001Key); } - @Test(enabled = true, description = "Deploy extcodehash contract") + @Test(enabled = AllTest, description = "Deploy extcodehash contract") public void test01DeployExtCodeHashContract() { Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); @@ -140,7 +141,8 @@ public void test01DeployExtCodeHashContract() { } - @Test(enabled = true, description = "The EXTCODEHASH of an account that selfdestructed in the current transaction. but later been revert") + @Test(enabled = AllTest, description = "The EXTCODEHASH of an account that selfdestructed in the " + + "current transaction. but later been revert") public void test02GetTestContractCodeHash() { Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); @@ -172,7 +174,7 @@ public void test02GetTestContractCodeHash() { final String triggerTxid = PublicMethed.triggerContract(extCodeHashContractAddress, - "getCodeHashRevert()", "#", false, 0l, + "getCodeHashRevert()", "#", false, 0L, 1000000000L, "0", 0, user001Address, user001Key, blockingStubFull); @@ -220,7 +222,8 @@ public void test02GetTestContractCodeHash() { } - @Test(enabled = true, description = "The EXTCODEHASH of an account that create in the current transaction. but later been revert") + @Test(enabled = AllTest, description = "The EXTCODEHASH of an account that create in the current " + + "transaction. but later been revert") public void test03GetTestContractCodeHash() { Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); @@ -252,7 +255,7 @@ public void test03GetTestContractCodeHash() { final String triggerTxid = PublicMethed.triggerContract(extCodeHashContractAddress, - "getCodeHashCreate()", "#", false, 0l, + "getCodeHashCreate()", "#", false, 0L, 1000000000L, "0", 0, user001Address, user001Key, blockingStubFull); @@ -299,7 +302,8 @@ public void test03GetTestContractCodeHash() { retList.get(0)); } - @Test(enabled = true, description = "The EXTCODEHASH of an account that selfdestructed in the current transaction.") + @Test(enabled = AllTest, description = "The EXTCODEHASH of an account that selfdestructed in the" + + " current transaction.") public void test04GetTestContractCodeHash() { Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); @@ -332,7 +336,7 @@ public void test04GetTestContractCodeHash() { String param = "\"" + Base58.encode58Check(extCodeHashContractAddress) + "\""; final String triggerTxid = PublicMethed.triggerContract(extCodeHashContractAddress, - "getCodeHashSuicide(address)", param, false, 0l, + "getCodeHashSuicide(address)", param, false, 0L, 1000000000L, "0", 0, user001Address, user001Key, blockingStubFull); @@ -378,6 +382,7 @@ public void test04GetTestContractCodeHash() { Assert.assertEquals("0000000000000000000000000000000000000000000000000000000000000000", retList.get(0)); } + /** * constructor. */ diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand001.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand001.java index d64354fb6d2..5e46c41ff4c 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand001.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand001.java @@ -103,7 +103,6 @@ public void test1OldInstruction() { 0L, 100, null, contractExcKey, contractExcAddress, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull1); Account info; @@ -125,7 +124,6 @@ public void test1OldInstruction() { 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); Optional infoById = null; PublicMethed.waitProduceNextBlock(blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull1); infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); Long fee = infoById.get().getFee(); Long netUsed = infoById.get().getReceipt().getNetUsage(); @@ -232,11 +230,13 @@ public void test2NewInstruction() { 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertEquals(10,ByteArray.toInt(infoById.get().getContractResult(0).toByteArray())); txid = PublicMethed.triggerContract(contractAddress, "shrTest(uint256,uint256)", num, false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertEquals(2,ByteArray.toInt(infoById.get().getContractResult(0).toByteArray())); } /** diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand003.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand003.java index a7a22a798fd..87e08eed76e 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand003.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand003.java @@ -94,6 +94,7 @@ public void test1ShiftLeft() { .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/ShiftCommand001.sol"; String contractName = "TestBitwiseShift"; HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); @@ -178,9 +179,6 @@ public void test1ShiftLeft() { @Test(enabled = true, description = "Trigger new ShiftRight with displacement number too short ") public void test2ShiftRight() { - Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull); @@ -255,9 +253,6 @@ public void test2ShiftRight() { @Test(enabled = true, description = "Trigger new ShiftRightSigned " + "with displacement number too short ") public void test3ShiftRightSigned() { - Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand004.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand004.java index 44bbd31ec3a..49a16cfbae5 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand004.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand004.java @@ -95,6 +95,8 @@ public void test1ShiftLeft() { Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/ShiftCommand001.sol"; String contractName = "TestBitwiseShift"; HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); @@ -179,9 +181,7 @@ public void test1ShiftLeft() { + "0x0000000000000000000000000000000000000000000000000000000000000001 and Displacement number" + "is 0x01") public void test2ShiftLeft() { - Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); + Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -261,9 +261,7 @@ public void test2ShiftLeft() { + "0x0000000000000000000000000000000000000000000000000000000000000001 and Displacement number" + "is 0xff") public void test3ShiftLeft() { - Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); + Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -342,9 +340,7 @@ public void test3ShiftLeft() { + "0x0000000000000000000000000000000000000000000000000000000000000001 and Displacement number" + "is 0x0100") public void test4ShiftLeft() { - Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); + Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -419,9 +415,6 @@ public void test4ShiftLeft() { + "0x0000000000000000000000000000000000000000000000000000000000000001 and Displacement number" + "is 0x0101") public void test5ShiftLeft() { - Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull); @@ -495,9 +488,6 @@ public void test5ShiftLeft() { + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + "is 0x00") public void test6ShiftLeft() { - Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull); @@ -571,10 +561,6 @@ public void test6ShiftLeft() { + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + "is 0x01") public void test7ShiftLeft() { - Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); String filePath = "src/test/resources/soliditycode/ShiftCommand001.sol"; String contractName = "TestBitwiseShift"; HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); @@ -661,9 +647,7 @@ public void test7ShiftLeft() { + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + "is 0xff") public void test8ShiftLeft() { - Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); + Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -739,9 +723,7 @@ public void test8ShiftLeft() { + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + "is 0x0100") public void test9ShiftLeft() { - Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); + Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull); @@ -817,10 +799,6 @@ public void test9ShiftLeft() { + "0x0000000000000000000000000000000000000000000000000000000000000000 and Displacement number" + "is 0x01") public void testShiftLeft10() { - Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -895,9 +873,7 @@ public void testShiftLeft10() { + "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + "is 0x01") public void testShiftLeft11() { - Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); + Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -972,10 +948,7 @@ public void testShiftLeft11() { + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + "is 0x0101") public void testShiftLeft12() { - Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/TvmNewCommand043.sol"; String contractName = "TestBitwiseShift"; HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand005.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand005.java index 492073f8739..33291d18812 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand005.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand005.java @@ -95,6 +95,8 @@ public void test1ShiftRight() { Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/ShiftCommand001.sol"; String contractName = "TestBitwiseShift"; HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); @@ -182,9 +184,7 @@ public void test1ShiftRight() { + "0x0000000000000000000000000000000000000000000000000000000000000001 and Displacement number" + "is 0x01") public void test2ShiftRight() { - Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); + Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -259,9 +259,7 @@ public void test2ShiftRight() { + "0x8000000000000000000000000000000000000000000000000000000000000000 and Displacement number" + "is 0x01") public void test3ShiftRight() { - Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); + Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -335,9 +333,7 @@ public void test3ShiftRight() { + "0x8000000000000000000000000000000000000000000000000000000000000000 and Displacement number" + "is 0xff") public void test4ShiftRight() { - Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); + Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -416,9 +412,7 @@ public void test4ShiftRight() { + "0x8000000000000000000000000000000000000000000000000000000000000000 and Displacement number" + "is 0x0100") public void test5ShiftRight() { - Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); + Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -494,9 +488,7 @@ public void test5ShiftRight() { + "0x8000000000000000000000000000000000000000000000000000000000000000 and Displacement number" + "is 0x0101") public void test6ShiftRight() { - Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); + Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -572,9 +564,7 @@ public void test6ShiftRight() { + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + "is 0x00") public void test7ShiftRight() { - Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); + Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -650,9 +640,7 @@ public void test7ShiftRight() { + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + "is 0x01") public void test8ShiftRight() { - Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); + Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -730,10 +718,7 @@ public void test8ShiftRight() { + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + "is 0xff") public void test9ShiftRight() { - Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -811,10 +796,7 @@ public void test9ShiftRight() { + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + "is 0x0100") public void testShiftRight10() { - Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -890,9 +872,7 @@ public void testShiftRight10() { + "0x0000000000000000000000000000000000000000000000000000000000000000 and Displacement number" + "is 0x01") public void testShiftRight11() { - Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); + String filePath = "src/test/resources/soliditycode/ShiftCommand001.sol"; String contractName = "TestBitwiseShift"; HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); @@ -978,9 +958,7 @@ public void testShiftRight11() { + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + "is 0x0101") public void testShiftRight12() { - Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); + String filePath = "src/test/resources/soliditycode/TvmNewCommand043.sol"; String contractName = "TestBitwiseShift"; HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand006.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand006.java index 84f6fe290fd..80258809be0 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand006.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand006.java @@ -179,10 +179,7 @@ public void test1ShiftRightSigned() { + "0x0000000000000000000000000000000000000000000000000000000000000001 and Displacement number" + "is 0x01") public void test2ShiftRightSigned() { - Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -259,10 +256,6 @@ public void test2ShiftRightSigned() { + "0x8000000000000000000000000000000000000000000000000000000000000000 and Displacement number" + "is 0x01") public void test3ShiftRightSigned() { - Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -338,10 +331,7 @@ public void test3ShiftRightSigned() { + "0x8000000000000000000000000000000000000000000000000000000000000000 and Displacement number" + "is 0xff") public void test4ShiftRightSigned() { - Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -421,10 +411,7 @@ public void test4ShiftRightSigned() { + "0x8000000000000000000000000000000000000000000000000000000000000000 and Displacement number" + "is 0x0100") public void test5ShiftRightSigned() { - Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -500,10 +487,7 @@ public void test5ShiftRightSigned() { + "0x8000000000000000000000000000000000000000000000000000000000000000 and Displacement number" + "is 0x0101") public void test6ShiftRightSigned() { - Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -580,10 +564,7 @@ public void test6ShiftRightSigned() { + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + "is 0x00") public void test7ShiftRightSigned() { - Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -664,9 +645,7 @@ public void test7ShiftRightSigned() { + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + "is 0x01") public void test8ShiftRightSigned() { - Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); + Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -746,9 +725,7 @@ public void test8ShiftRightSigned() { + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + "is 0xff") public void test9ShiftRightSigned() { - Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); + Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -828,9 +805,7 @@ public void test9ShiftRightSigned() { + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + "is 0x0100") public void testShiftRightSigned10() { - Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); + Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -910,9 +885,7 @@ public void testShiftRightSigned10() { + "0x0000000000000000000000000000000000000000000000000000000000000000 and Displacement number" + "is 0x01") public void testShiftRightSigned11() { - Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); + Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -992,10 +965,7 @@ public void testShiftRightSigned11() { + "0x4000000000000000000000000000000000000000000000000000000000000000 and Displacement number" + "is 0xfe") public void testShiftRightSigned12() { - Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -1074,10 +1044,7 @@ public void testShiftRightSigned12() { + "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + "is 0xf8") public void testShiftRightSigned13() { - Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -1157,10 +1124,7 @@ public void testShiftRightSigned13() { + "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + "is 0xfe") public void testShiftRightSigned14() { - Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -1237,10 +1201,7 @@ public void testShiftRightSigned14() { + "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + "is 0xff") public void testShiftRightSigned15() { - Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -1319,9 +1280,7 @@ public void testShiftRightSigned15() { + "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + "is 0x0100") public void testShiftRightSigned16() { - Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); + Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -1399,9 +1358,7 @@ public void testShiftRightSigned16() { + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + "is 0x0101") public void testShiftRightSigned17() { - Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); + String filePath = "src/test/resources/soliditycode/TvmNewCommand043.sol"; String contractName = "TestBitwiseShift"; HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); @@ -1490,9 +1447,7 @@ public void testShiftRightSigned17() { + "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + "is 0x0101") public void testShiftRightSigned18() { - Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); + String filePath = "src/test/resources/soliditycode/TvmNewCommand043.sol"; String contractName = "TestBitwiseShift"; HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed001.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed001.java index 2ffbeacdcc8..06acf158620 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed001.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed001.java @@ -1,5 +1,8 @@ package stest.tron.wallet.dailybuild.tvmnewcommand.transferfailed; +import static org.tron.protos.Protocol.TransactionInfo.code.FAILED; + +import com.google.protobuf.ByteString; import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import java.util.HashMap; @@ -23,6 +26,7 @@ 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.WalletClient; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.PublicMethed; @@ -569,6 +573,325 @@ public void test6TransferTrxSelf() { } + @Test(enabled = true, description = "preCompiled transfertoken with value," + + " long.max < value or long.min > value") + public void test7TransferTockenPreCompiled() { + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Account info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + + String txid = ""; + String num = "1"; + + txid = PublicMethed.triggerContract(contractAddress, + "testTransferTokenCompiledLongMax1()", "#", false, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + Optional infoById = null; + PublicMethed.waitProduceNextBlock(blockingStubFull); + + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + logger.info("infobyid : --- " + infoById); + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + beforeBalance = info.getBalance(); + beforeEnergyUsed = resourceInfo.getEnergyUsed(); + beforeNetUsed = resourceInfo.getNetUsed(); + beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + + Assert.assertEquals(FAILED, infoById.get().getResult()); + Assert.assertTrue(energyUsageTotal < maxFeeLimit / 10); + Assert.assertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8()); + + txid = PublicMethed.triggerContract(contractAddress, + "testTransferTokenCompiledLongMin1()", "#", false, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + infoById = null; + PublicMethed.waitProduceNextBlock(blockingStubFull); + + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + logger.info("infobyid : --- " + infoById); + fee = infoById.get().getFee(); + netUsed = infoById.get().getReceipt().getNetUsage(); + energyUsed = infoById.get().getReceipt().getEnergyUsage(); + netFee = infoById.get().getReceipt().getNetFee(); + energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + beforeBalance = info.getBalance(); + beforeEnergyUsed = resourceInfo.getEnergyUsed(); + beforeNetUsed = resourceInfo.getNetUsed(); + beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + + Assert.assertEquals(FAILED, infoById.get().getResult()); + Assert.assertTrue(energyUsageTotal < maxFeeLimit / 10); + Assert.assertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8()); + + } + + @Test(enabled = false, description = "tokenbalance") + public void test8TransferTocken() { + + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 10000_000_000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + long start = System.currentTimeMillis() + 2000; + long end = System.currentTimeMillis() + 1000000000; + String description = Configuration.getByPath("testng.conf") + .getString("defaultParameter.assetDescription"); + String url = Configuration.getByPath("testng.conf") + .getString("defaultParameter.assetUrl"); + + ByteString assetAccountId = null; + final long TotalSupply = 10000000L; + long now = System.currentTimeMillis(); + String tokenName = "testAssetIssue_" + Long.toString(now); + + //Create a new AssetIssue success. + Assert + .assertTrue(PublicMethed.createAssetIssue(contractExcAddress, tokenName, TotalSupply, 1, + 10000, start, end, 1, description, url, 100000L, + 100000L, 1L, 1L, contractExcKey, blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + assetAccountId = PublicMethed.queryAccount(contractExcAddress, blockingStubFull) + .getAssetIssuedID(); + + String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; + String contractName = "EnergyOfTransferFailedTest"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed.transferAsset(contractAddress, + assetAccountId.toByteArray(), 100L, contractExcAddress, contractExcKey, + blockingStubFull)); + + Long returnAddressBytesAccountCountBefore = PublicMethed + .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + logger.info("returnAddressBytesAccountCountBefore : " + returnAddressBytesAccountCountBefore); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long testNetAccountCountBefore = PublicMethed + .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long contractAccountCountBefore = PublicMethed + .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + logger.info("testNetAccountCountBefore:" + testNetAccountCountBefore); + logger.info("contractAccountCountBefore:" + contractAccountCountBefore); + String txid = ""; + String num = + "\"" + Base58.encode58Check(contractAddress) + "\"," + "\"" + assetAccountId.toStringUtf8() + + "\""; + //String num = "\""+Base58.encode58Check(contractAddress) +"\","+ "\"" + -1 + "\""; + txid = PublicMethed.triggerContract(contractAddress, + "testTransferTokenTest(address,uint256)", num, false, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + Optional infoById = null; + PublicMethed.waitProduceNextBlock(blockingStubFull); + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull1); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + Long testNetAccountCountAfter = PublicMethed + .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long contractAccountCountAfter = PublicMethed + .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + logger.info("testNetAccountCountAfter:" + testNetAccountCountAfter); + logger.info("contractAccountCountAfter:" + contractAccountCountAfter); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(energyUsageTotal < maxFeeLimit / 10); + Assert.assertEquals(100, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray())); + + + } + + @Test(enabled = true, description = "address(0x1) qeury tokenbalance") + public void test9TransferTocken() { + //address: 410000000000000000000000000000000000000001 + String addressx = "T9yD14Nj9j7xAB4dbGeiX9h8unkKLxmGkn"; + byte[] addressxx = WalletClient.decodeFromBase58Check(addressx); + + Assert.assertTrue(PublicMethed + .sendcoin(addressxx, 10L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + + long start = System.currentTimeMillis() + 2000; + long end = System.currentTimeMillis() + 1000000000; + String description = Configuration.getByPath("testng.conf") + .getString("defaultParameter.assetDescription"); + String url = Configuration.getByPath("testng.conf") + .getString("defaultParameter.assetUrl"); + + ByteString assetAccountId = null; + final long TotalSupply = 10000000L; + long now = System.currentTimeMillis(); + String tokenName = "testAssetIssue_" + Long.toString(now); + + //Create a new AssetIssue success. + Assert + .assertTrue(PublicMethed.createAssetIssue(contractExcAddress, tokenName, TotalSupply, 1, + 10000, start, end, 1, description, url, 100000L, + 100000L, 1L, 1L, contractExcKey, blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + assetAccountId = PublicMethed.queryAccount(contractExcAddress, blockingStubFull) + .getAssetIssuedID(); + + /*String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; + String contractName = "EnergyOfTransferFailedTest"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull);*/ + Assert.assertTrue(PublicMethed.transferAsset(addressxx, + assetAccountId.toByteArray(), 100L, contractExcAddress, contractExcKey, + blockingStubFull)); + + Long returnAddressBytesAccountCountBefore = PublicMethed + .getAssetIssueValue(addressxx, assetAccountId, blockingStubFull); + logger.info("returnAddressBytesAccountCountBefore : " + returnAddressBytesAccountCountBefore); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + Long testNetAccountCountBefore = PublicMethed + .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long contractAccountCountBefore = PublicMethed + .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + logger.info("testNetAccountCountBefore:" + testNetAccountCountBefore); + logger.info("contractAccountCountBefore:" + contractAccountCountBefore); + String txid = ""; + //String num = "\""+Base58.encode58Check(contractAddress) + // +"\","+ "\"" + assetAccountId.toStringUtf8() + "\""; + String num = "\"" + assetAccountId.toStringUtf8() + "\""; + //String num = "\""+Base58.encode58Check(contractAddress) +"\","+ "\"" + -1 + "\""; + txid = PublicMethed.triggerContract(contractAddress, + "testTransferTokenCompiledTokenId(uint256)", num, false, + 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + Optional infoById = null; + PublicMethed.waitProduceNextBlock(blockingStubFull); + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull1); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + Long testNetAccountCountAfter = PublicMethed + .getAssetIssueValue(contractExcAddress, assetAccountId, blockingStubFull); + Long contractAccountCountAfter = PublicMethed + .getAssetIssueValue(contractAddress, assetAccountId, blockingStubFull); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + logger.info("testNetAccountCountAfter:" + testNetAccountCountAfter); + logger.info("contractAccountCountAfter:" + contractAccountCountAfter); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(energyUsageTotal < maxFeeLimit / 10); + Assert.assertEquals(100, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray())); + } + + /** * constructor. */ diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed003.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed003.java index 61c6ddbd2e6..b2abcf03c9e 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed003.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed003.java @@ -113,7 +113,6 @@ public void test1TransferTokenEnough() { .assertTrue(PublicMethed.createAssetIssue(contractExcAddress, tokenName, TotalSupply, 1, 10000, start, end, 1, description, url, 100000L, 100000L, 1L, 1L, contractExcKey, blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); assetAccountId = PublicMethed.queryAccount(contractExcAddress, blockingStubFull) .getAssetIssuedID(); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed005.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed005.java index 182435ae050..8c948c94e49 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed005.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed005.java @@ -119,13 +119,13 @@ public void deployContract() { contractAddress = PublicMethed .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100L, null, accountExcKey, accountExcAddress, blockingStubFull); - /*String Txid1 = PublicMethed + String Txid1 = PublicMethed .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, 0L, 100L, null, accountExcKey, accountExcAddress, blockingStubFull); Optional infoById = PublicMethed .getTransactionInfoById(Txid1, blockingStubFull); contractAddress = infoById.get().getContractAddress().toByteArray(); - //Assert.assertEquals(0, infoById.get().getResultValue());*/ + Assert.assertEquals(0, infoById.get().getResultValue()); filePath = "src/test/resources/soliditycode/TransferFailed005.sol"; contractName = "Caller"; @@ -136,14 +136,14 @@ public void deployContract() { contractAddress1 = PublicMethed .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100L, null, accountExcKey, accountExcAddress, blockingStubFull); - /*Txid1 = PublicMethed + Txid1 = PublicMethed .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, 0L, 100L, null, accountExcKey, accountExcAddress, blockingStubFull); infoById = PublicMethed .getTransactionInfoById(Txid1, blockingStubFull); contractAddress1 = infoById.get().getContractAddress().toByteArray(); logger.info("caller address : " + Base58.encode58Check(contractAddress1)); - Assert.assertEquals(0, infoById.get().getResultValue());*/ + Assert.assertEquals(0, infoById.get().getResultValue()); } @Test(enabled = true, description = "TransferFailed for function call_value ") @@ -483,11 +483,16 @@ public void triggerContract03() { Assert.assertEquals(1, infoById.get().getResultValue()); Assert.assertEquals("FAILED", infoById.get().getResult().toString()); Assert.assertEquals(205L, afterBalance); - Assert.assertEquals(0, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray())); + Assert.assertEquals(0, ByteArray.toInt( + infoById.get().getContractResult(0).toByteArray())); Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() < 10000000); } + @Test(enabled = true, description = "TransferFailed for precompiled") + public void triggerContract05() { + + } /** * constructor. diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/old/TransferFailed005.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/old/TransferFailed005.java new file mode 100644 index 00000000000..c962179d6cf --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/old/TransferFailed005.java @@ -0,0 +1,509 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.transferfailed.old; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +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.api.WalletSolidityGrpc; +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.Base58; +import stest.tron.wallet.common.client.utils.PublicMethed; + +@Slf4j +public class TransferFailed005 { + final boolean AllTest = false; + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key1"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private final Long maxFeeLimit = Configuration.getByPath("testng.cong") + .getLong("defaultParameter.maxFeeLimit"); + + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + byte[] contractAddress = null; + byte[] contractAddress1 = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] accountExcAddress = ecKey1.getAddress(); + String accountExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + @BeforeClass(enabled = AllTest) + public void beforeClass() { + PublicMethed.printAddress(accountExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + { + Assert.assertTrue(PublicMethed + .sendcoin(accountExcAddress, 10000_000_000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + String filePath = "src/test/resources/soliditycode_v0.4.25/TransferFailed005.sol"; + String contractName = "EnergyOfTransferFailedTest"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed + .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100L, + null, accountExcKey, accountExcAddress, blockingStubFull); + + filePath = "src/test/resources/soliditycode_v0.4.25/TransferFailed005.sol"; + contractName = "Caller"; + retMap = PublicMethed.getBycodeAbi(filePath, contractName); + code = retMap.get("byteCode").toString(); + abi = retMap.get("abI").toString(); + + contractAddress1 = PublicMethed + .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100L, + null, accountExcKey, accountExcAddress, blockingStubFull); + } + } + + @Test(enabled = AllTest, description = "Deploy contract for trigger") + public void deployContract() { + Assert.assertTrue(PublicMethed + .sendcoin(accountExcAddress, 10000_000_000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + String filePath = "src/test/resources/soliditycode_v0.4.25/TransferFailed005.sol"; + String contractName = "EnergyOfTransferFailedTest"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed + .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100L, + null, accountExcKey, accountExcAddress, blockingStubFull); + /*String Txid1 = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, 0L, 100L, + null, accountExcKey, accountExcAddress, blockingStubFull); + Optional infoById = PublicMethed + .getTransactionInfoById(Txid1, blockingStubFull); + contractAddress = infoById.get().getContractAddress().toByteArray(); + //Assert.assertEquals(0, infoById.get().getResultValue());*/ + + filePath = "src/test/resources/soliditycode_v0.4.25/TransferFailed005.sol"; + contractName = "Caller"; + retMap = PublicMethed.getBycodeAbi(filePath, contractName); + code = retMap.get("byteCode").toString(); + abi = retMap.get("abI").toString(); + + contractAddress1 = PublicMethed + .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100L, + null, accountExcKey, accountExcAddress, blockingStubFull); + /*Txid1 = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, 0L, 100L, + null, accountExcKey, accountExcAddress, blockingStubFull); + infoById = PublicMethed + .getTransactionInfoById(Txid1, blockingStubFull); + contractAddress1 = infoById.get().getContractAddress().toByteArray(); + logger.info("caller address : " + Base58.encode58Check(contractAddress1)); + Assert.assertEquals(0, infoById.get().getResultValue());*/ + } + + @Test(enabled = AllTest, description = "TransferFailed for function call_value ") + public void triggerContract01() { + Account info = null; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(accountExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(accountExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + + Assert.assertTrue(PublicMethed + .sendcoin(contractAddress, 1000100L, accountExcAddress, accountExcKey, blockingStubFull)); + //Assert.assertTrue(PublicMethed + // .sendcoin(contractAddress1, 1, accountExcAddress, accountExcKey, blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + logger.info( + "contractAddress balance before: " + PublicMethed + .queryAccount(contractAddress, blockingStubFull) + .getBalance()); + logger.info( + "callerAddress balance before: " + PublicMethed + .queryAccount(contractAddress1, blockingStubFull) + .getBalance()); + long paramValue = 1000000; + + // transfer trx to self`s account + String param = "\"" + paramValue + "\",\"" + Base58.encode58Check(contractAddress) + "\""; + String triggerTxid = PublicMethed.triggerContract(contractAddress, + "testCallTrxInsufficientBalance(uint256,address)", param, false, 0L, + maxFeeLimit, accountExcAddress, accountExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + Assert.assertEquals(infoById.get().getResultValue(), 1); + Assert.assertEquals("FAILED", infoById.get().getResult().toString()); + Assert.assertEquals("UNKNOWN", infoById.get().getReceipt().getResult().toString()); + Assert.assertEquals("validateForSmartContract failure:%s", + infoById.get().getResMessage().toStringUtf8()); + Assert.assertEquals(1000100L, + PublicMethed.queryAccount(contractAddress, blockingStubFull).getBalance()); + Assert.assertEquals(0L, + PublicMethed.queryAccount(contractAddress1, blockingStubFull).getBalance()); + Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() == 100000000); + + // transfer trx to unactivate account + ECKey ecKey2 = new ECKey(Utils.getRandom()); + byte[] accountExcAddress2 = ecKey2.getAddress(); + param = "\"" + paramValue + "\",\"" + Base58.encode58Check(accountExcAddress2) + "\""; + triggerTxid = PublicMethed.triggerContract(contractAddress, + "testCallTrxInsufficientBalance(uint256,address)", param, false, 0L, + maxFeeLimit, accountExcAddress, accountExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + Assert.assertEquals(infoById.get().getResultValue(), 1); + Assert.assertEquals("FAILED", infoById.get().getResult().toString()); + Assert.assertEquals("UNKNOWN", infoById.get().getReceipt().getResult().toString()); + Assert.assertEquals( + "validateForSmartContract failure:%s", + infoById.get().getResMessage().toStringUtf8()); + Assert.assertEquals(1000100L, + PublicMethed.queryAccount(contractAddress, blockingStubFull).getBalance()); + Assert.assertEquals(0L, + PublicMethed.queryAccount(contractAddress1, blockingStubFull).getBalance()); + Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() == 100000000); + + // transfer trx to caller, value enough , function success contractResult(call_value) failed + param = "\"" + paramValue + "\",\"" + Base58.encode58Check(contractAddress1) + "\""; + triggerTxid = PublicMethed.triggerContract(contractAddress, + "testCallTrxInsufficientBalance(uint256,address)", param, false, 0L, + maxFeeLimit, accountExcAddress, accountExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + logger.info(infoById.get().getReceipt().getResult() + ""); + + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + int contractResult = ByteArray + .toInt(infoById.get().getContractResult(0).toByteArray()); + Assert.assertEquals(1, contractResult); + + Assert.assertEquals(infoById.get().getResultValue(), 0); + Assert.assertEquals(infoById.get().getResult().toString(), "SUCESS"); + Assert.assertEquals(100L, + PublicMethed.queryAccount(contractAddress, blockingStubFull).getBalance()); + Assert.assertEquals(1000000L, + PublicMethed.queryAccount(contractAddress1, blockingStubFull).getBalance()); + Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() < 10000000); + + // transfer trx to caller, value not enough, function success + // but contractResult(call_value) failed + triggerTxid = PublicMethed.triggerContract(contractAddress, + "testCallTrxInsufficientBalance(uint256,address)", param, false, 0L, + maxFeeLimit, accountExcAddress, accountExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull); + fee = infoById.get().getFee(); + netUsed = infoById.get().getReceipt().getNetUsage(); + energyUsed = infoById.get().getReceipt().getEnergyUsage(); + netFee = infoById.get().getReceipt().getNetFee(); + energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + //contractResult`s first boolean value + contractResult = ByteArray + .toInt(infoById.get().getContractResult(0).toByteArray()); + Assert.assertEquals(0, contractResult); + Assert.assertEquals(infoById.get().getResultValue(), 0); + Assert.assertEquals(infoById.get().getResult().toString(), "SUCESS"); + Assert.assertEquals(100L, + PublicMethed.queryAccount(contractAddress, blockingStubFull).getBalance()); + Assert.assertEquals(1000000L, + PublicMethed.queryAccount(contractAddress1, blockingStubFull).getBalance()); + Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() < 10000000); + + + } + + @Test(enabled = AllTest, description = "TransferFailed for create") + public void triggerContract02() { + Account info = null; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(accountExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(accountExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + + Assert.assertTrue(PublicMethed + .sendcoin(contractAddress, 1000100L, accountExcAddress, accountExcKey, blockingStubFull)); + //Assert.assertTrue(PublicMethed + // .sendcoin(contractAddress1, 1, accountExcAddress, accountExcKey, blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + logger.info( + "contractAddress balance before: " + PublicMethed + .queryAccount(contractAddress, blockingStubFull) + .getBalance()); + logger.info( + "callerAddress balance before: " + PublicMethed + .queryAccount(contractAddress1, blockingStubFull) + .getBalance()); + long paramValue = 1000000; + String param = "\"" + paramValue + "\""; + + String triggerTxid = PublicMethed.triggerContract(contractAddress, + "testCreateTrxInsufficientBalance(uint256)", param, false, 0L, + maxFeeLimit, accountExcAddress, accountExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + logger.info(infoById.get().getReceipt().getResult() + ""); + + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + logger.info( + "contractAddress balance before: " + PublicMethed + .queryAccount(contractAddress, blockingStubFull) + .getBalance()); + logger.info( + "callerAddress balance before: " + PublicMethed + .queryAccount(contractAddress1, blockingStubFull) + .getBalance()); + Assert.assertEquals(infoById.get().getResultValue(), 0); + Assert.assertFalse(infoById.get().getInternalTransactions(0).getRejected()); + Assert.assertEquals(200L, + PublicMethed.queryAccount(contractAddress, blockingStubFull).getBalance()); + Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() < 10000000); + + triggerTxid = PublicMethed.triggerContract(contractAddress, + "testCreateTrxInsufficientBalance(uint256)", param, false, 0L, + maxFeeLimit, accountExcAddress, accountExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull); + fee = infoById.get().getFee(); + netUsed = infoById.get().getReceipt().getNetUsage(); + energyUsed = infoById.get().getReceipt().getEnergyUsage(); + netFee = infoById.get().getReceipt().getNetFee(); + energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + logger.info( + "contractAddress balance before: " + PublicMethed + .queryAccount(contractAddress, blockingStubFull) + .getBalance()); + logger.info( + "callerAddress balance before: " + PublicMethed + .queryAccount(contractAddress1, blockingStubFull) + .getBalance()); + + Assert.assertEquals(infoById.get().getResultValue(), 1); + Assert.assertEquals(infoById.get().getResMessage().toStringUtf8(), "REVERT opcode executed"); + Assert.assertEquals(200L, + PublicMethed.queryAccount(contractAddress, blockingStubFull).getBalance()); + Assert.assertEquals(1000000L, + PublicMethed.queryAccount(contractAddress1, blockingStubFull).getBalance()); + Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() < 10000000); + + + } + + @Test(enabled = AllTest, description = "TransferFailed for create2") + public void triggerContract03() { + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(accountExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(accountExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + + Assert.assertTrue(PublicMethed + .sendcoin(contractAddress, 15L, accountExcAddress, accountExcKey, blockingStubFull)); + logger.info( + "contractAddress balance before: " + PublicMethed + .queryAccount(contractAddress, blockingStubFull) + .getBalance()); + + String filePath = "./src/test/resources/soliditycode_v0.4.25/TransferFailed007.sol"; + String contractName = "Caller"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String testContractCode = retMap.get("byteCode").toString(); + Long salt = 1L; + + String param = "\"" + testContractCode + "\"," + salt; + + String triggerTxid = PublicMethed.triggerContract(contractAddress, + "deploy(bytes,uint256)", param, false, 0L, + maxFeeLimit, accountExcAddress, accountExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + Optional infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + long afterBalance = 0L; + afterBalance = PublicMethed.queryAccount(contractAddress, blockingStubFull) + .getBalance(); + logger.info( + "contractAddress balance after : " + PublicMethed + .queryAccount(contractAddress, blockingStubFull) + .getBalance()); + Assert.assertEquals(1, infoById.get().getResultValue()); + Assert.assertEquals("FAILED", infoById.get().getResult().toString()); + Assert.assertEquals("Invalid operation code: opCode[fb];",ByteArray.toStr(infoById.get().getResMessage().toByteArray())); + Assert.assertEquals(215L, afterBalance); + //Assert.assertFalse(infoById.get().getInternalTransactions(0).getRejected()); + Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() == 100000000); + + triggerTxid = PublicMethed.triggerContract(contractAddress, + "deploy2(bytes,uint256)", param, false, 0L, + maxFeeLimit, accountExcAddress, accountExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + infoById = PublicMethed + .getTransactionInfoById(triggerTxid, blockingStubFull); + + fee = infoById.get().getFee(); + netUsed = infoById.get().getReceipt().getNetUsage(); + energyUsed = infoById.get().getReceipt().getEnergyUsage(); + netFee = infoById.get().getReceipt().getNetFee(); + energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + afterBalance = PublicMethed.queryAccount(contractAddress, blockingStubFull).getBalance(); + logger.info( + "contractAddress balance after : " + PublicMethed + .queryAccount(contractAddress, blockingStubFull) + .getBalance()); + Assert.assertEquals(1, infoById.get().getResultValue()); + Assert.assertEquals("FAILED", infoById.get().getResult().toString()); + Assert.assertEquals("Invalid operation code: opCode[fb];",ByteArray.toStr(infoById.get().getResMessage().toByteArray())); + //Assert.assertEquals(205L, afterBalance); + Assert.assertEquals(0, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray())); + Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() == 100000000); + + } + + + /** + * constructor. + */ + @AfterClass + + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant001.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant001.java index 6f39a2f5a92..c21a920ff28 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant001.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant001.java @@ -107,7 +107,8 @@ public void beforeClass() { 0L, 100, null, contractExcKey, contractExcAddress, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - SmartContract smartContract = PublicMethed.getContract(contractAddressNoAbi, blockingStubFull); + SmartContract smartContract = PublicMethed.getContract( + contractAddressNoAbi, blockingStubFull); Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); @@ -116,7 +117,8 @@ public void beforeClass() { 0L, 100, null, contractExcKey, contractExcAddress, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - SmartContract smartContract2 = PublicMethed.getContract(contractAddressWithAbi, blockingStubFull); + SmartContract smartContract2 = PublicMethed.getContract( + contractAddressWithAbi, blockingStubFull); Assert.assertFalse(smartContract2.getAbi().toString().isEmpty()); Assert.assertTrue(smartContract2.getName().equalsIgnoreCase(contractName)); Assert.assertFalse(smartContract2.getBytecode().toString().isEmpty()); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant003.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant003.java index 2c567610ae6..bdc4e1bb730 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant003.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant003.java @@ -88,8 +88,8 @@ public void beforeClass() { blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = false, description = "TriggerConstantContract a view function without ABI") - public void testTriggerConstantContract() { + @Test(enabled = true, description = "TriggerConstantContract a view function without ABI") + public void test001TriggerConstantContract() { Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); @@ -125,7 +125,7 @@ public void testTriggerConstantContract() { TransactionExtention transactionExtention = PublicMethed .triggerConstantContractForExtention(contractAddress, "testView()", "#", false, - 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + 0, 1000000000, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); Transaction transaction = transactionExtention.getTransaction(); @@ -141,9 +141,66 @@ public void testTriggerConstantContract() { } + @Test(enabled = true, description = "TriggerConstantContract a payable function with ABI") + public void test002TriggerConstantContract() { + + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + + TransactionExtention transactionExtention = PublicMethed + .triggerConstantContractForExtention(contractAddress, + "testPayable()", "#", false, + 0, 1000000000, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + + Transaction transaction = transactionExtention.getTransaction(); + + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + System.out.println("message:" + transaction.getRet(0).getRet()); + System.out.println(":" + ByteArray + .toStr(transactionExtention.getResult().getMessage().toByteArray())); + System.out.println("Result:" + Hex.toHexString(result)); + Assert.assertEquals("SUCESS", transaction.getRet(0).getRet().toString()); + Assert.assertEquals(1, ByteArray.toLong(ByteArray + .fromHexString(Hex + .toHexString(result)))); + + transactionExtention = PublicMethed + .triggerConstantContractForExtention(contractAddress, + "testPayable()", "#", false, + 1L, 1000000000, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + transaction = transactionExtention.getTransaction(); + + result = transactionExtention.getConstantResult(0).toByteArray(); + System.out.println("message:" + transaction.getRet(0).getRet()); + System.out.println(":" + ByteArray + .toStr(transactionExtention.getResult().getMessage().toByteArray())); + System.out.println("Result:" + Hex.toHexString(result)); + + Assert.assertEquals(1, ByteArray.toLong(ByteArray + .fromHexString(Hex + .toHexString(result)))); + Assert.assertEquals("constant cannot set call value or call token value.", + ByteArray + .toStr(transactionExtention.getResult().getMessage().toByteArray())); + Assert.assertEquals("FAILED", transaction.getRet(0).getRet().toString()); + + + } /** * constructor. */ + @AfterClass public void shutdown() throws InterruptedException { if (channelFull != null) { diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant005.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant005.java index 64f24d62584..bb592dccfeb 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant005.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant005.java @@ -88,7 +88,7 @@ public void beforeClass() { blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = false, description = "TriggerConstantContract a payable function with ABI") + @Test(enabled = true, description = "TriggerConstantContract a payable function with ABI") public void testTriggerConstantContract() { Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, @@ -135,8 +135,6 @@ public void testTriggerConstantContract() { containsString("CONTRACT_EXE_ERROR")); Assert.assertThat(transactionExtention.getResult().getMessage().toStringUtf8(), containsString("Attempt to call a state modifying opcode inside STATICCALL")); - PublicMethed.waitProduceNextBlock(blockingStubFull); - } diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant026.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant026.java index 4bd21c4df88..802d23722a7 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant026.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant026.java @@ -90,8 +90,8 @@ public void beforeClass() { blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = false, description = "TriggerConstantContract a view method without ABI,method has" - + "revert()") + @Test(enabled = false, description = "TriggerConstantContract a view method without ABI," + + "method has revert()") public void testTriggerConstantContract() { Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, diff --git a/src/test/resources/soliditycode/TransferFailed001.sol b/src/test/resources/soliditycode/TransferFailed001.sol index 020de72084a..0a59abfde60 100644 --- a/src/test/resources/soliditycode/TransferFailed001.sol +++ b/src/test/resources/soliditycode/TransferFailed001.sol @@ -2,6 +2,39 @@ contract EnergyOfTransferFailedTest { constructor() payable public { } + + function testTransferTokenCompiledLongMax() payable public{ + address(0x1).transferToken(1,9223372036855775827); + } + + function testTransferTokenCompiled() payable public{ + address(0x1).transferToken(1,1); + } + + function testTransferTokenCompiledLongMin() payable public{ + //address(0x1).transferToken(1,-9223372036855775828); + } + + function testTransferTokenCompiledLongMin1() payable public returns(uint256){ + return address(0x2).tokenBalance(trcToken(-9223372036855775828)); + } + + function testTransferTokenCompiled1() payable public returns(uint256){ + return address(0x1).tokenBalance(trcToken(1)); + } + + function testTransferTokenCompiledLongMax1() payable public returns(uint256){ + return address(0x2).tokenBalance(trcToken(9223372036855775827)); + } + + function testTransferTokenCompiledTokenId(uint256 tokenid) payable public returns(uint256){ + return address(0x1).tokenBalance(trcToken(tokenid)); + } + + function testTransferTokenTest(address addr ,uint256 tokenid) payable public returns(uint256){ + return addr.tokenBalance(trcToken(tokenid)); + } + // InsufficientBalance function testTransferTrxInsufficientBalance(uint256 i) payable public{ msg.sender.transfer(i); diff --git a/src/test/resources/soliditycode/TriggerConstant003.sol b/src/test/resources/soliditycode/TriggerConstant003.sol index bc9270b2135..0bc41cc3751 100644 --- a/src/test/resources/soliditycode/TriggerConstant003.sol +++ b/src/test/resources/soliditycode/TriggerConstant003.sol @@ -5,4 +5,8 @@ function testView() public view returns (uint256 z) { uint256 i=1; return i; } +function testPayable() public payable returns (uint256 z) { +uint256 i=1; +return i; +} } \ No newline at end of file diff --git a/src/test/resources/soliditycode/create2contract.sol b/src/test/resources/soliditycode/create2contract.sol index 1943d6e9cdc..0171f4d5486 100644 --- a/src/test/resources/soliditycode/create2contract.sol +++ b/src/test/resources/soliditycode/create2contract.sol @@ -11,6 +11,19 @@ contract Factory { emit Deployed(addr, salt, msg.sender); return addr; } + + event Deployed(address addr, bytes32 salt, address sender); + function deploy(bytes memory code, bytes32 salt) public returns(address){ + address addr; + assembly { + addr := create2(0, add(code, 0x20), mload(code), salt) + if iszero(extcodesize(addr)) { + revert(0, 0) + } + } + emit Deployed(addr, salt, msg.sender); + return addr; + } } contract FactoryBytes { diff --git a/src/test/resources/soliditycode/create2contract22.sol b/src/test/resources/soliditycode/create2contract22.sol index c94ed896765..3fc6a81faec 100644 --- a/src/test/resources/soliditycode/create2contract22.sol +++ b/src/test/resources/soliditycode/create2contract22.sol @@ -1,5 +1,10 @@ contract Factory { event Deployed(address addr, trcToken salt, address sender); + event Deployed1(address addr, uint8 salt, address sender); + event Deployed2(address addr, address salt, address sender); + event Deployed3(address addr, string salt, address sender); + + function deploy(bytes memory code, trcToken salt) public returns(address){ address addr; assembly { @@ -11,53 +16,43 @@ contract Factory { emit Deployed(addr, salt, msg.sender); return addr; } -} - -contract Factory1 { - event Deployed(address addr, uint8 salt, address sender); - function deploy(bytes memory code, uint8 salt) public returns(address){ - address addr; - assembly { - addr := create2(0, add(code, 0x20), mload(code), salt) - if iszero(extcodesize(addr)) { - revert(0, 0) + function deploy1(bytes memory code, uint8 salt) public returns(address){ + address addr; + assembly { + addr := create2(0, add(code, 0x20), mload(code), salt) + if iszero(extcodesize(addr)) { + revert(0, 0) + } } - } - emit Deployed(addr, salt, msg.sender); - return addr; + emit Deployed1(addr, salt, msg.sender); + return addr; } -} -contract Factory2 { - event Deployed(address addr, address salt, address sender); - function deploy(bytes memory code, address salt) public returns(address){ - address addr; - assembly { - addr := create2(0, add(code, 0x20), mload(code), salt) - if iszero(extcodesize(addr)) { - revert(0, 0) + function deploy2(bytes memory code, address salt) public returns(address){ + address addr; + assembly { + addr := create2(0, add(code, 0x20), mload(code), salt) + if iszero(extcodesize(addr)) { + revert(0, 0) + } } - } - emit Deployed(addr, salt, msg.sender); - return addr; + emit Deployed2(addr, salt, msg.sender); + return addr; } -} - -contract Factory3 { - event Deployed(address addr, string salt, address sender); - function deploy(bytes memory code, string memory salt) public returns(address){ - address addr; - assembly { - addr := create2(0, add(code, 0x20), mload(code), salt) - if iszero(extcodesize(addr)) { - revert(0, 0) + function deploy3(bytes memory code, string memory salt) public returns(address){ + address addr; + assembly { + addr := create2(0, add(code, 0x20), mload(code), salt) + if iszero(extcodesize(addr)) { + revert(0, 0) + } } - } - emit Deployed(addr, salt, msg.sender); - return addr; + emit Deployed3(addr, salt, msg.sender); + return addr; } + } diff --git a/src/test/resources/soliditycode/demo.sol b/src/test/resources/soliditycode/demo.sol new file mode 100644 index 00000000000..c7f6d0d4da9 --- /dev/null +++ b/src/test/resources/soliditycode/demo.sol @@ -0,0 +1,73 @@ +//pragma solidity ^0.4.24; + + contract tokenTest{ + uint256 codesize; + constructor() payable public{ + uint256 m; + address addr = address(this); + assembly { + m := extcodesize(addr) + } + codesize = m; + } + + // positive case + function pulsone() public payable{ + uint256 j = 0; + uint i = 100; + for (; i < i; i++) { + j++; + } + } + + + function getCodeSize() public returns (uint256){ + return codesize; + } + + } + + contract confirmTest{ + + uint256 codesize; + constructor() payable public{ + uint256 m; + address addr = address(this); + assembly { + m := extcodesize(addr) + + } + codesize = m; + } + + function getCodeSize() public returns (uint256){ + return codesize; + } + + function confirm(address addr) public returns (uint256){ + uint256 j; + assembly { + j := extcodesize(addr) + if iszero(extcodesize(addr)) { + revert(0, 0) + } + } + return j; + } + + function at(address _addr) public returns (bytes memory o_code) { + assembly { + // retrieve the size of the code, this needs assembly + let size := extcodesize(_addr) + // allocate output byte array - this could also be done without assembly + // by using o_code = new bytes(size) + o_code := mload(0x40) + // new "memory end" including padding + mstore(0x40, add(o_code, and(add(add(size, 0x20), 0x1f), not(0x1f)))) + // store length in memory + mstore(o_code, size) + // actually retrieve the code, this needs assembly + extcodecopy(_addr, add(o_code, 0x20), 0, size) + } + } + } \ No newline at end of file diff --git a/src/test/resources/soliditycode/event001.sol b/src/test/resources/soliditycode/event001.sol new file mode 100644 index 00000000000..7662df3a5c6 --- /dev/null +++ b/src/test/resources/soliditycode/event001.sol @@ -0,0 +1,10 @@ +contract Event { + event xixi(uint256 id) ; + event log2(uint256,uint256,uint256); + constructor() public payable{} + function messageI() payable public returns (uint ret) { + //emit log2(1,2,3); + emit xixi(1); + return 1; + } +} \ No newline at end of file diff --git a/src/test/resources/soliditycode/event002.sol b/src/test/resources/soliditycode/event002.sol new file mode 100644 index 00000000000..70a5275521c --- /dev/null +++ b/src/test/resources/soliditycode/event002.sol @@ -0,0 +1,52 @@ +pragma solidity >=0.4.0 <0.7.0; + +contract Event { + + event _0(); + event a_0() anonymous; + event a_4i(uint256 indexed x1, uint256 indexed x2 , uint256 indexed x3, uint256 indexed x4, uint256 x5)anonymous ; + event _3i(uint256 x1, uint256 indexed x2 , uint256 indexed x3, uint256 x4, uint256 x5) ; + event _1i(uint256 indexed x1, uint256, uint256 indexed, uint256 x4) ; + event a_1i(uint256) anonymous; + event _ai(uint8[2], uint8) ; + event a_ai(uint8[2], uint8) anonymous; + event _a1i(uint8[2] indexed, uint8) ; + event a_a1i(uint8[2] indexed, uint8) anonymous; + + constructor () public { + // emit a_0(); + // emit a_1i(123); + // emit a_4i(1,2,3,5,16); + // emit _0(); + emit _3i(1,2,3,5,16); + // emit _1i(1,2,3,5); + // emit _ai([1,2], 3); + // emit a_ai([3,4], 5); + // emit _a1i([1,2], 3); + // emit a_a1i([3,4], 5); + } + + function e() public { + emit _1i(1,2,3,4); + } + + function l() public { + emit a_1i(1); + } + + function k() public{ + emit a_4i(2,3,4,5,17); + emit _3i(2,3,4,5,16); + emit _1i(2,3,4,5); + emit a_1i(128); + emit _0(); + emit a_0(); + //selfdestruct(msg.sender); + //emit a_4i(1,2,3,5,16); + //emit _3i(1,2,3,5,16); + //emit _1i(1,2,3,5); + //emit a_1i(123); + //emit _0(); + //emit a_0(); + } +} \ No newline at end of file diff --git a/src/test/resources/soliditycode/suicide001.sol b/src/test/resources/soliditycode/suicide001.sol new file mode 100644 index 00000000000..3544f8bf84a --- /dev/null +++ b/src/test/resources/soliditycode/suicide001.sol @@ -0,0 +1,32 @@ +contract factory { + constructor() payable public { + } + + function create1() payable public returns (address){ + Caller add = (new Caller).value(0)(); + return address(add); + } + + function kill() payable public{ + selfdestruct(msg.sender); + } + + function create2(bytes memory code, uint256 salt) public returns(address){ + Caller addr; + Caller addr1; + assembly { + addr := create2(0, add(code, 0x20), mload(code), salt) + if iszero(extcodesize(addr)) { + revert(0, 0) + } + } + return address(addr); + } +} + + + +contract Caller { + constructor() payable public {} + function test() payable public returns (uint256){return 1;} +} \ No newline at end of file diff --git a/src/test/resources/soliditycode/suicide002.sol b/src/test/resources/soliditycode/suicide002.sol new file mode 100644 index 00000000000..160ab64f320 --- /dev/null +++ b/src/test/resources/soliditycode/suicide002.sol @@ -0,0 +1,43 @@ +contract Factory { + uint256 public num; + event Deployed(address addr, uint256 salt, address sender); + constructor() public { + } + function deploy(bytes memory code, uint256 salt) public returns(address){ + TestConstract addr; + TestConstract addr1; + assembly { + addr := create2(0, add(code, 0x20), mload(code), salt) + if iszero(extcodesize(addr)) { + revert(0, 0) + } + } + + addr.testSuicideNonexistentTarget(msg.sender); + addr.set(); + + assembly { + addr1 := create2(0, add(code, 0x20), mload(code), salt) + if iszero(extcodesize(addr)) { + revert(0, 0) + } + } + emit Deployed(address(addr), salt, msg.sender); + return address(addr); + } +} + + + +contract TestConstract { + uint public i=1; + constructor () public { + } + + function set() public{ + i=9; + } + function testSuicideNonexistentTarget(address payable nonexistentTarget) payable public { + selfdestruct(nonexistentTarget); + } +} \ No newline at end of file diff --git a/src/test/resources/soliditycode_v0.4.25/TransferFailed001.sol b/src/test/resources/soliditycode_v0.4.25/TransferFailed001.sol new file mode 100644 index 00000000000..e69de29bb2d From dc86980349199f93fa42620934cab15e2086423d Mon Sep 17 00:00:00 2001 From: wangqqqqq Date: Wed, 12 Jun 2019 15:20:52 +0800 Subject: [PATCH 57/90] Modify testcase --- .circleci/config.yml | 4 +- DownloadLinks.sh | 14 ++--- .../wallet/account/WalletTestAccount013.java | 58 ++----------------- .../scenario/ContractScenario004.java | 3 +- .../scenario/ContractScenario005.java | 3 +- .../scenario/ContractScenario006.java | 1 + .../scenario/ContractScenario012.java | 1 + .../scenario/ContractScenario013.java | 3 + .../manual/ContractScenario011.java | 1 + .../manual/ContractScenario014.java | 1 + .../mutisign/WalletTestMutiSign001.java | 1 + 11 files changed, 26 insertions(+), 64 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 2aaa0121d5b..904b933d2f8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -14,11 +14,11 @@ jobs: - checkout - run: name: multi_os_result - command: echo "curl http://60.205.215.34/multi_os_result" + command: echo "curl http://47.95.206.44:50080/multi_os_result" # # - run: # name: Daily Build Report -# command: curl http://60.205.215.34/Daily_Build_Task_Report +# command: curl http://47.95.206.44:50080/Daily_Build_Task_Report # # - run: # name: Download Links diff --git a/DownloadLinks.sh b/DownloadLinks.sh index a3d05821084..babc5a266f6 100644 --- a/DownloadLinks.sh +++ b/DownloadLinks.sh @@ -1,21 +1,21 @@ -PassFlag=`curl -s http://60.205.215.34/Daily_Build_Task_Report | grep "Failed: 0" | wc -c` +PassFlag=`curl -s http://47.95.206.44:50080/Daily_Build_Task_Report | grep "Failed: 0" | wc -c` if [ $PassFlag -eq 0 ]; then echo "Daily Build Stest Fail" echo "To view Daily Replay and Stress Test logs please visit website below on browsers" - echo "--- http://60.205.215.34/latestReplayLog" - echo "--- http://60.205.215.34/latestStressLog" + echo "--- http://47.95.206.44:50080/latestReplayLog" + echo "--- http://47.95.206.44:50080/latestStressLog" else echo "Daily Build Stest Pass" echo "Build on `date +"%Y-%m-%d"` 3:00:00 (CST), UTC +8" echo "Please visit following website to download java-tron.jar on browsers" - echo "--- http://60.205.215.34/Daily_Build/java-tron.jar" + echo "--- http://47.95.206.44:50080/Daily_Build/jFava-tron.jar" echo "To view Daily Replay and Stress Test logs please visit website below on browsers" - echo "--- http://60.205.215.34/latestReplayLog" - echo "--- http://60.205.215.34/latestStressLog" + echo "--- http://47.95.206.44:50080/latestReplayLog" + echo "--- http://47.95.206.44:50080/latestStressLog" echo "The following compressed package is provided for user to set up Fullnode. Please use Linux OS to Download" - echo "--- curl -# -O http://60.205.215.34/Daily_Build/java-tron.tar.gz" + echo "--- curl -# -O http://47.95.206.44:50080/Daily_Build/java-tron.tar.gz" echo "To unzip file use the command below" echo "--- tar -xzvf java-tron.tar.gz" fi \ No newline at end of file diff --git a/src/test/java/stest/tron/wallet/account/WalletTestAccount013.java b/src/test/java/stest/tron/wallet/account/WalletTestAccount013.java index afd6fc07c4c..9bb02aaddfc 100644 --- a/src/test/java/stest/tron/wallet/account/WalletTestAccount013.java +++ b/src/test/java/stest/tron/wallet/account/WalletTestAccount013.java @@ -385,7 +385,7 @@ public void test4DelegateResourceAboutTransferAsset() { } @Test(enabled = true) - public void test5DelegateResourceAboutTriggerContract() { + public void test5CanNotDelegateResourceToContract() { //Create Account6 ECKey ecKey6 = new ECKey(Utils.getRandom()); accountForDeployAddress = ecKey6.getAddress(); @@ -411,61 +411,13 @@ public void test5DelegateResourceAboutTriggerContract() { maxFeeLimit, 0L, consumeUserResourcePercent, null, accountForDeployKey, accountForDeployAddress, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - //Account4 DelegatedResource of Energy to Contract - Assert.assertTrue(PublicMethed.freezeBalanceForReceiver( + + //After 3.6 can not delegate resource to contract + Assert.assertFalse(PublicMethed.freezeBalanceForReceiver( account4DelegatedResourceAddress, freezeAmount, freezeDuration, 1, ByteString.copyFrom(contractAddress), account4DelegatedResourceKey, blockingStubFull)); - //Account4 DelegatedResource Energy to deploy - Assert.assertTrue(PublicMethed.freezeBalanceForReceiver( - account4DelegatedResourceAddress, freezeAmount, freezeDuration, 1, - ByteString.copyFrom(accountForDeployAddress), - account4DelegatedResourceKey, blockingStubFull)); - - //get Energy of Account013,Account4,Contract before trigger contract - final long account013CurrentEnergyUsed = PublicMethed.getAccountResource( - account013Address, blockingStubFull).getEnergyUsed(); - final long account013CurrentBandwidthUsed = PublicMethed.getAccountResource( - account013Address, blockingStubFull).getFreeNetUsed(); - final long account4CurrentEnergyUsed = PublicMethed.getAccountResource( - account4DelegatedResourceAddress, blockingStubFull).getEnergyUsed(); - final long contractCurrentEnergyUsed = PublicMethed.getAccountResource( - contractAddress, blockingStubFull).getEnergyUsed(); - final long deployCurrentEnergyUsed = PublicMethed.getAccountResource( - accountForDeployAddress, blockingStubFull).getEnergyUsed(); - - //Account013 trigger contract - String txid = PublicMethed.triggerContract(contractAddress, - "add2(uint256)", "1", false, - 0, 1000000000L, "0", 0, account013Address, testKeyForAccount013, blockingStubFull); - logger.info(txid); - infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); - logger.info(String.valueOf(infoById.get().getResultValue())); - Assert.assertTrue(infoById.get().getResultValue() == 0); - //get transaction info of Energy used and Bandwidth used - final long contractTriggerEnergyUsed = infoById.get().getReceipt().getOriginEnergyUsage(); - final long contractTriggerBandwidthUsed = infoById.get().getReceipt().getNetUsage(); - - //get Energy of Account013,Account4,Contract after trigger contract - final long account013CurrentEnergyUsedAfterTrig = PublicMethed.getAccountResource( - account013Address, blockingStubFull).getEnergyUsed(); - final long account013CurrentBandwidthUsedAfterTrig = PublicMethed.getAccountResource( - account013Address, blockingStubFull).getFreeNetUsed(); - final long account4CurrentEnergyUsedAfterTrig = PublicMethed.getAccountResource( - account4DelegatedResourceAddress, blockingStubFull).getEnergyUsed(); - final long contractCurrentEnergyUsedAfterTrig = PublicMethed.getAccountResource( - contractAddress, blockingStubFull).getEnergyUsed(); - final long deployCurrentEnergyUsedAfterTrig = PublicMethed.getAccountResource( - accountForDeployAddress, blockingStubFull).getEnergyUsed(); - //compare energy changed - Assert.assertTrue(account013CurrentEnergyUsed == account013CurrentEnergyUsedAfterTrig); - Assert.assertTrue(account4CurrentEnergyUsed == account4CurrentEnergyUsedAfterTrig); - Assert.assertTrue(contractCurrentEnergyUsed == contractCurrentEnergyUsedAfterTrig); - Assert.assertTrue(deployCurrentEnergyUsed - == deployCurrentEnergyUsedAfterTrig - contractTriggerEnergyUsed); - //compare bandwidth of Account013 before and after trigger contract - Assert.assertTrue(account013CurrentBandwidthUsed - == account013CurrentBandwidthUsedAfterTrig - contractTriggerBandwidthUsed); + } /** diff --git a/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario004.java b/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario004.java index 9584d73cd5b..2ac708412ee 100644 --- a/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario004.java +++ b/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario004.java @@ -81,14 +81,15 @@ public void deployErc20TronToken() { String code = retMap.get("byteCode").toString(); String abi = retMap.get("abI").toString(); - byte[] contractAddress; String txid = PublicMethed .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, contract004Key, contract004Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); Optional infoById = PublicMethed .getTransactionInfoById(txid, blockingStubFull); logger.info("Txid is " + txid); logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); + byte[] contractAddress; contractAddress = infoById.get().getContractAddress().toByteArray(); SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); diff --git a/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario005.java b/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario005.java index 958dc12fc60..31d1541d20d 100644 --- a/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario005.java +++ b/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario005.java @@ -84,14 +84,15 @@ public void deployIcoContract() { String code = retMap.get("byteCode").toString(); String abi = retMap.get("abI").toString(); - byte[] contractAddress = null; String txid = PublicMethed .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, contract005Key, contract005Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); Optional infoById = PublicMethed .getTransactionInfoById(txid, blockingStubFull); logger.info("Txid is " + txid); logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); + byte[] contractAddress = null; contractAddress = infoById.get().getContractAddress().toByteArray(); SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); diff --git a/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario006.java b/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario006.java index 47ac2572711..178390b015c 100644 --- a/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario006.java +++ b/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario006.java @@ -95,6 +95,7 @@ public void deployFomo3D() { String txid = PublicMethed .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, contract006Key, contract006Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); Optional infoById = PublicMethed .getTransactionInfoById(txid, blockingStubFull); contractAddress = infoById.get().getContractAddress().toByteArray(); diff --git a/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario012.java b/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario012.java index 4e496853b48..1b12c881a30 100644 --- a/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario012.java +++ b/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario012.java @@ -99,6 +99,7 @@ public void test1DeployTransactionCoin() { String txid = PublicMethed .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, contract012Key, contract012Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); logger.info("infobyid : --- " + infoById); Assert.assertTrue(infoById.get().getResultValue() == 0); diff --git a/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario013.java b/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario013.java index 4e27f167548..57eed764388 100644 --- a/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario013.java +++ b/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario013.java @@ -85,6 +85,7 @@ public void deployTronTrxAndSunContract() { txid = PublicMethed.deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, contract013Key, contract013Address, blockingStubFull); logger.info(txid); + PublicMethed.waitProduceNextBlock(blockingStubFull); infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); logger.info("energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); Assert.assertTrue(infoById.get().getResultValue() == 0); @@ -112,6 +113,7 @@ public void triggerTronTrxAndSunContract() { String txid = PublicMethed .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, contract013Key, contract013Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); logger.info("energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); @@ -122,6 +124,7 @@ public void triggerTronTrxAndSunContract() { "time()", "#", false, 0, 100000000L, contract013Address, contract013Key, blockingStubFull); logger.info(txid); + PublicMethed.waitProduceNextBlock(blockingStubFull); infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); logger.info("result is " + infoById.get().getResultValue()); logger.info("energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); diff --git a/src/test/java/stest/tron/wallet/dailybuild/manual/ContractScenario011.java b/src/test/java/stest/tron/wallet/dailybuild/manual/ContractScenario011.java index d2e592db67e..438d270fb68 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/manual/ContractScenario011.java +++ b/src/test/java/stest/tron/wallet/dailybuild/manual/ContractScenario011.java @@ -168,6 +168,7 @@ public void deploySaleClockAuction() { .deployContractWithConstantParame(contractName, abi, code, "constructor(address,uint256)", data, "", maxFeeLimit, 0L, consumeUserResourcePercent, null, deployKey, deployAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); Optional info = PublicMethed .getTransactionInfoById(deplTxid, blockingStubFull); Assert.assertTrue(info.get().getResultValue() == 0); diff --git a/src/test/java/stest/tron/wallet/dailybuild/manual/ContractScenario014.java b/src/test/java/stest/tron/wallet/dailybuild/manual/ContractScenario014.java index 0d76db4dcf3..456fdf57b46 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/manual/ContractScenario014.java +++ b/src/test/java/stest/tron/wallet/dailybuild/manual/ContractScenario014.java @@ -115,6 +115,7 @@ public void testTripleTrigger() { txid = PublicMethed.deployContractWithConstantParame(contractName, abi1, code1, "constructor(address)", parame, "", maxFeeLimit, 0L, 100, null, contract014Key, contract014Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); contractAddress2 = infoById.get().getContractAddress().toByteArray(); diff --git a/src/test/java/stest/tron/wallet/mutisign/WalletTestMutiSign001.java b/src/test/java/stest/tron/wallet/mutisign/WalletTestMutiSign001.java index fd929cf07ad..e15ad7155e3 100644 --- a/src/test/java/stest/tron/wallet/mutisign/WalletTestMutiSign001.java +++ b/src/test/java/stest/tron/wallet/mutisign/WalletTestMutiSign001.java @@ -284,6 +284,7 @@ public void testMutiSign3ParticipateAssetissue() { Assert.assertNotNull(txid); + PublicMethed.waitProduceNextBlock(blockingStubFull); infoById = PublicMethed .getTransactionInfoById(txid, blockingStubFull); balanceAfter = PublicMethed.queryAccount(participateAddress, blockingStubFull) From 65ab63c99cef62721381981e12d81bfe36dea7ca Mon Sep 17 00:00:00 2001 From: wangqqqqq Date: Wed, 12 Jun 2019 15:59:31 +0800 Subject: [PATCH 58/90] Modify testng.conf --- src/test/resources/testng.conf | 37 ++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/test/resources/testng.conf b/src/test/resources/testng.conf index cd66082e4d7..6b13ec02b00 100644 --- a/src/test/resources/testng.conf +++ b/src/test/resources/testng.conf @@ -6,8 +6,8 @@ net { fullnode = { ip.list = [ #Docker env - #"127.0.0.1:50051", - #"127.0.0.1:50052", + "127.0.0.1:50051", + "127.0.0.1:50052", #Continue Integration //"47.93.14.253:50051", #"101.200.51.70:50051", @@ -21,12 +21,12 @@ fullnode = { #"47.94.239.172:50051", #"39.105.89.183:50051", #New beat1 - "39.106.145.222:50052", - "101.200.46.37:50052", + #"39.106.145.222:50052", + #"101.200.46.37:50052", #New beta1 - "47.94.197.215:50051", - "101.200.52.146:50051", + #"47.94.197.215:50051", + #"101.200.52.146:50051", #New beta2 @@ -46,16 +46,16 @@ fullnode = { solidityNode = { ip.list = [ #Docker env - #"127.0.0.1:50053", - #"127.0.0.1:50062", + "127.0.0.1:50053", + "127.0.0.1:50062", #MainNet #"39.105.66.80:50051", #Continue Integration #"47.94.135.251:50051", #"47.94.9.222:50061", #new beta1 - "101.200.46.37:50053", - "101.200.46.37:50062", + #"101.200.46.37:50053", + #"101.200.46.37:50062", #new beta2 "101.200.52.146:18895", @@ -65,9 +65,9 @@ solidityNode = { httpnode = { ip.list = [ - "101.200.46.37:50191", - "39.106.145.222:50093", - "101.200.46.37:50094", + #"101.200.46.37:50191", + #"39.106.145.222:50093", + #"101.200.46.37:50094", #"39.105.89.183:8090", #"39.107.248.113:8090", #"39.105.89.183:8091", @@ -77,9 +77,9 @@ httpnode = { "127.0.0.1:8093", "127.0.0.1:8097", - "47.94.197.215:8091", - "101.200.52.146:8091", - "47.94.197.215:8097", + #"47.94.197.215:8091", + #"101.200.52.146:8091", + #"47.94.197.215:8097", ] } @@ -167,7 +167,10 @@ defaultParameter = { delayTransactionFee = 100000 cancleDelayTransactionFee = 50000 solidityCompilerVersion = "v5" - solidityCompile = "/Users/wangzihe/Downloads/solc.0.5.4" + solidityCompile = "solcDIR/solc" + zenTokenOwnerKey = 2925e186bb1e88988855f11ebf20ea3a6e19ed92328b0ffb576122e769d45b68 + zenTokenId = 1000001 + zenTokenFee = 10000000 } From 0861427630c183590bf4d6b941a7025bbda596be Mon Sep 17 00:00:00 2001 From: wangzihe Date: Wed, 12 Jun 2019 18:00:08 +0800 Subject: [PATCH 59/90] Change ip --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 904b933d2f8..e02044408b6 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -14,7 +14,7 @@ jobs: - checkout - run: name: multi_os_result - command: echo "curl http://47.95.206.44:50080/multi_os_result" + command: curl http://60.205.215.34/Daily_Build_Task_Report # # - run: # name: Daily Build Report From 7605e4bec941787dd1695d44e6254ee8b4481f2b Mon Sep 17 00:00:00 2001 From: wangzihe Date: Wed, 12 Jun 2019 20:21:24 +0800 Subject: [PATCH 60/90] Change ip --- deploy.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deploy.sh b/deploy.sh index c162b55a86a..787c7edc642 100644 --- a/deploy.sh +++ b/deploy.sh @@ -2,9 +2,9 @@ if [[ "$TRAVIS_BRANCH" = "develop" || "$TRAVIS_BRANCH" = "master" ]];then stestlogname="`date +%Y%m%d%H%M%S`_stest.log" stest_server="" - docker_num_in_67=`ssh -p 22008 -t java-tron@47.93.18.60 'docker ps -a | wc -l'` + docker_num_in_67=`ssh -p 22008 -t java-tron@47.93.42.145 'docker ps -a | wc -l'` docker_num_in_67=`echo $docker_num_in_67 | tr -d "\r"` - docker_num_in_122=`ssh -p 22008 -t java-tron@47.93.42.145 'docker ps -a | wc -l'` + docker_num_in_122=`ssh -p 22008 -t java-tron@47.93.18.60 'docker ps -a | wc -l'` docker_num_in_122=`echo $docker_num_in_122 | tr -d "\r"` if [ $docker_num_in_67 -le $docker_num_in_122 ]; then From 6b9bd8a3af501051153690f75e6f9a5b81aaded6 Mon Sep 17 00:00:00 2001 From: wangzihe Date: Wed, 12 Jun 2019 20:24:27 +0800 Subject: [PATCH 61/90] Change ip --- .travis.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4aebb1290c0..8aa96d7f992 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,12 +3,12 @@ language: java jdk: oraclejdk8 addons: ssh_known_hosts: - - 47.94.231.67:22008 - - 47.94.231.67:22008 - - 47.94.231.67:22008 - - 47.94.10.122:22008 - - 47.94.10.122:22008 - - 47.94.10.122:22008 + - 47.93.18.60:22008 + - 47.93.18.60:22008 + - 47.93.18.60:22008 + - 47.93.42.145:22008 + - 47.93.42.145:22008 + - 47.93.42.145:22008 sonarcloud: organization: tron-zhaohong token: From 38dc3e12a67bd8c790b5f486a0e2a835a03cd21e Mon Sep 17 00:00:00 2001 From: wangming Date: Thu, 13 Jun 2019 15:20:45 +0800 Subject: [PATCH 62/90] modify testcase --- .../tvmnewcommand/checkCodeSize.java | 208 ------- .../tvmnewcommand/clearabi/ClearAbi005.java | 2 +- .../tvmnewcommand/create2/Create2Test001.java | 14 +- .../tvmnewcommand/create2/Create2Test003.java | 19 - .../tvmnewcommand/create2/Create2Test020.java | 374 ++++++++++++- .../tvmnewcommand/create2/Create2Test021.java | 4 - .../tvmnewcommand/create2/Create2Test024.java | 26 +- .../extCodeHash/ExtCodeHashTest001.java | 16 - .../extCodeHash/ExtCodeHashTest004.java | 1 + .../extCodeHash/ExtCodeHashTest010.java | 18 - .../extCodeHash/ExtCodeHashTest011.java | 364 +++++++++++++ .../transferfailed/TransferFailed001.java | 83 +-- .../transferfailed/TransferFailed002.java | 81 --- .../transferfailed/TransferFailed003.java | 26 +- .../transferfailed/TransferFailed004.java | 16 - .../transferfailed/old/TransferFailed005.java | 509 ------------------ .../triggerconstant/TriggerConstant001.java | 491 +---------------- .../triggerconstant/TriggerConstant013.java | 73 --- .../triggerconstant/TriggerConstant014.java | 74 --- 19 files changed, 752 insertions(+), 1647 deletions(-) delete mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/checkCodeSize.java create mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest011.java delete mode 100644 src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/old/TransferFailed005.java diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/checkCodeSize.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/checkCodeSize.java deleted file mode 100644 index 96c23826eb0..00000000000 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/checkCodeSize.java +++ /dev/null @@ -1,208 +0,0 @@ -package stest.tron.wallet.dailybuild.tvmnewcommand; - -import com.google.protobuf.ByteString; -import io.grpc.ManagedChannel; -import io.grpc.ManagedChannelBuilder; -import java.util.HashMap; -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.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 checkCodeSize { - - private final String testKey002 = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key1"); - 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); - private long maxFeeLimit = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.maxFeeLimit"); - - private static final long now = System.currentTimeMillis(); - private static String tokenName = "testAssetIssue_" + Long.toString(now); - private static ByteString assetAccountId = null; - private static final long TotalSupply = 1000L; - private byte[] transferTokenContractAddress = null; - private byte[] confirmContractAddress = null; - - private String description = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetDescription"); - private String url = Configuration.getByPath("testng.conf") - .getString("defaultParameter.assetUrl"); - - private ECKey ecKey1 = new ECKey(Utils.getRandom()); - private byte[] dev001Address = ecKey1.getAddress(); - private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - - @BeforeSuite - public void beforeSuite() { - Wallet wallet = new Wallet(); - Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); - } - - /** - * constructor. - */ - @BeforeClass(enabled = true) - public void beforeClass() { - - channelFull = ManagedChannelBuilder.forTarget(fullnode) - .usePlaintext(true) - .build(); - blockingStubFull = WalletGrpc.newBlockingStub(channelFull); - - PublicMethed.printAddress(dev001Key); - } - - @Test(enabled = false, description = "DeployContract with correct tokenValue and tokenId") - public void deployTransferTokenContract() { - Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 1000_000_000L, fromAddress, - testKey002, blockingStubFull)); - - PublicMethed.waitProduceNextBlock(blockingStubFull); - - //before deploy, check account resource - AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, - blockingStubFull); - long energyLimit = accountResource.getEnergyLimit(); - long energyUsage = accountResource.getEnergyUsed(); - long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); - - logger.info("before energyLimit is " + Long.toString(energyLimit)); - logger.info("before energyUsage is " + Long.toString(energyUsage)); - logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - - String filePath = "./src/test/resources/soliditycode/demo.sol"; - String contractName = "tokenTest"; - HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); - - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - transferTokenContractAddress = PublicMethed - .deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, dev001Key, - dev001Address, blockingStubFull); - - code = "6080604052303b600055610211806100186000396000f3006080604052600436106100565763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663a5a23074811461005b578063dce4a4471461009c578063eb4dd8f214610159575b600080fd5b34801561006757600080fd5b50d3801561007457600080fd5b50d2801561008157600080fd5b5061008a6101a1565b60408051918252519081900360200190f35b3480156100a857600080fd5b50d380156100b557600080fd5b50d280156100c257600080fd5b506100e473ffffffffffffffffffffffffffffffffffffffff600435166101a7565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561011e578181015183820152602001610106565b50505050905090810190601f16801561014b5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561016557600080fd5b50d3801561017257600080fd5b50d2801561017f57600080fd5b5061008a73ffffffffffffffffffffffffffffffffffffffff600435166101ce565b60005490565b60408051603f833b908101601f191682019092528181529080600060208401853c50919050565b6000813b823b15156101df57600080fd5b929150505600a165627a7a72305820309e6f0e0ad58fd7067f04813defe26c999d00f1975d75d8685fd398ec6ccb2e0029"; - abi = "[{\"constant\":false,\"inputs\":[],\"name\":\"getCodeSize\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_addr\",\"type\":\"address\"}],\"name\":\"at\",\"outputs\":[{\"name\":\"o_code\",\"type\":\"bytes\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"addr\",\"type\":\"address\"}],\"name\":\"confirm\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"constructor\"}]"; - contractName = "confirmTest"; - confirmContractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, dev001Key, - dev001Address, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); - - } - - @Test(enabled = false, description = "trigger") - public void triggerConfirm() { - long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); - logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - - String contractname = "pulsone()"; - - String trxid = PublicMethed - .triggerContract(transferTokenContractAddress, contractname, "#", false, 0L, maxFeeLimit, - dev001Address, dev001Key, blockingStubFull); - Optional infoById = null; - infoById = PublicMethed.getTransactionInfoById(trxid, blockingStubFull); - - logger.info("TrxId = " + trxid); - logger.info("Info = \n" + infoById); - //logger.info("contractResult = " + ByteArray - // .toLong(infoById.get().getContractResult(0).toByteArray())); - - contractname = "getCodeSize()"; - - trxid = PublicMethed - .triggerContract(transferTokenContractAddress, contractname, "#", false, 0L, maxFeeLimit, - dev001Address, dev001Key, blockingStubFull); - infoById = null; - infoById = PublicMethed.getTransactionInfoById(trxid, blockingStubFull); - - logger.info("TrxId = " + trxid); - logger.info("Info = \n" + infoById); - logger.info("contractResult = " + ByteArray - .toLong(infoById.get().getContractResult(0).toByteArray())); - - contractname = "getCodeSize()"; - - trxid = PublicMethed - .triggerContract(confirmContractAddress, contractname, "#", false, 0L, maxFeeLimit, - dev001Address, dev001Key, blockingStubFull); - infoById = null; - infoById = PublicMethed.getTransactionInfoById(trxid, blockingStubFull); - - logger.info("TrxId = " + trxid); - logger.info("Info = \n" + infoById); - logger.info("contractResult = " + ByteArray - .toLong(infoById.get().getContractResult(0).toByteArray())); - - balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); - logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - - String parm = "\"" + Base58.encode58Check(transferTokenContractAddress) + "\""; - contractname = "confirm(address)"; - - trxid = PublicMethed - .triggerContract(confirmContractAddress, contractname, parm, false, 0L, maxFeeLimit, - dev001Address, dev001Key, blockingStubFull); - infoById = null; - infoById = PublicMethed.getTransactionInfoById(trxid, blockingStubFull); - - logger.info("TrxId = " + trxid); - logger.info("Info = \n" + infoById); - logger.info("contractResult = " + ByteArray - .toLong(infoById.get().getContractResult(0).toByteArray())); - - balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); - logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - - parm = "\"" + Base58.encode58Check(transferTokenContractAddress) + "\""; - contractname = "at(address)"; - - trxid = PublicMethed - .triggerContract(confirmContractAddress, contractname, parm, false, 0L, maxFeeLimit, - dev001Address, dev001Key, blockingStubFull); - infoById = null; - infoById = PublicMethed.getTransactionInfoById(trxid, blockingStubFull); - - logger.info("TrxId = " + trxid); - logger.info("Info = \n" + infoById); - logger.info("contractResult = " + ByteArray - .toLong(infoById.get().getContractResult(0).toByteArray())); - } - - - /** - * constructor. - */ - @AfterClass - public void shutdown() throws InterruptedException { - if (channelFull != null) { - channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } - } -} - - diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi005.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi005.java index c5f51b9e836..ddcd723c63b 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi005.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi005.java @@ -91,7 +91,7 @@ public void beforeClass() { blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = true, description = "clear a contract created by create2 (without ABI)") + @Test(enabled = true, description = "Clear a contract created by create2 (without ABI)") public void testClearAbi() { Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test001.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test001.java index 9b5e4b3545e..c02ca74691b 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test001.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test001.java @@ -2,7 +2,6 @@ import static org.hamcrest.core.StringContains.containsString; -import com.google.protobuf.ByteString; import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import java.util.HashMap; @@ -81,16 +80,6 @@ public void test01DeployFactoryContract() { testKey002, blockingStubFull)); Assert.assertTrue(PublicMethed.sendcoin(user001Address, 10000_000_000L, fromAddress, testKey002, blockingStubFull)); - /*Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, - PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); - - Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, - 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull));*/ - - //PublicMethed.waitProduceNextBlock(blockingStubFull); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; String contractName = "Factory"; HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); @@ -408,7 +397,7 @@ public void test04TriggerCreate2ToDeployTestContract() { Assert.assertNotEquals(msgSender, Base58.encode58Check(user001Address)); } - @Test(enabled = true,description = "Trigger create2 command with 0 extended bytecode") + @Test(enabled = true, description = "Trigger create2 command with 0 extended bytecode") public void test05TriggerCreate2ToDeployTestContract() { Long callValue = Long.valueOf(0); @@ -429,7 +418,6 @@ public void test05TriggerCreate2ToDeployTestContract() { blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethed .getTransactionInfoById(triggerTxid, blockingStubFull); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test003.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test003.java index 1cc6b2d26b0..6dd83d4f52f 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test003.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test003.java @@ -88,16 +88,6 @@ public void test01DeployFactoryContract() { PublicMethed.waitProduceNextBlock(blockingStubFull); - //before deploy, check account resource - //AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, - // blockingStubFull); - //long energyLimit = accountResource.getEnergyLimit(); - //long energyUsage = accountResource.getEnergyUsed(); - //long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); - //logger.info("before energyLimit is " + Long.toString(energyLimit)); - //logger.info("before energyUsage is " + Long.toString(energyUsage)); - //logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - String filePath = "./src/test/resources/soliditycode/create2contract.sol"; String contractName = "Factory"; HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); @@ -112,15 +102,6 @@ public void test01DeployFactoryContract() { dev001Address, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - //accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); - //energyLimit = accountResource.getEnergyLimit(); - //energyUsage = accountResource.getEnergyUsed(); - //long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); - - //logger.info("after energyLimit is " + Long.toString(energyLimit)); - //logger.info("after energyUsage is " + Long.toString(energyUsage)); - //logger.info("after balanceAfter is " + Long.toString(balanceAfter)); - Optional infoById = PublicMethed .getTransactionInfoById(transferTokenTxid, blockingStubFull); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test020.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test020.java index 36eb317a473..cf474fe87d6 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test020.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test020.java @@ -1,5 +1,7 @@ package stest.tron.wallet.dailybuild.tvmnewcommand.create2; +import static org.hamcrest.core.StringContains.containsString; + import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import java.util.HashMap; @@ -87,10 +89,10 @@ public void beforeClass() { blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); } - @Test(enabled = true, description = "deploy Factory contract, create2 with salt type : trcToken") + @Test(enabled = true, description = "Deploy Factory contract, create2 with salt type : trcToken") public void testTriggerContract() { Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); PublicMethed.waitProduceNextBlock(blockingStubFull); String filePath = "src/test/resources/soliditycode/create2contract22.sol"; @@ -205,7 +207,7 @@ public void testTriggerContract() { } - @Test(enabled = true, description = "deploy Factory contract, create2 with salt type : uint8") + @Test(enabled = true, description = "Deploy Factory contract, create2 with salt type : uint8") public void testTriggerContract1() { Account info; @@ -311,7 +313,7 @@ public void testTriggerContract1() { } - @Test(enabled = true, description = "deploy Factory contract, create2 with salt type : address") + @Test(enabled = true, description = "Deploy Factory contract, create2 with salt type : address") public void testTriggerContract2() { Account info; @@ -417,7 +419,7 @@ public void testTriggerContract2() { } - @Test(enabled = true, description = "deploy Factory contract, create2 with salt type : string") + @Test(enabled = true, description = "Deploy Factory contract, create2 with salt type : string") public void testTriggerContract3() { Account info; @@ -523,6 +525,368 @@ public void testTriggerContract3() { } + @Test(enabled = true, description = "TriggerContract a constant function created by create2") + public void testTriggerContract4() { + Account info; + Assert.assertTrue(PublicMethed + .sendcoin(contractAddress, 1000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + + String contractName1 = "TestConstract1"; + String filePath = "src/test/resources/soliditycode/create2contract22.sol"; + HashMap retMap1 = PublicMethed.getBycodeAbi(filePath, contractName1); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + String txid = ""; + String num = "\"" + code1 + "\"" + ",\"" + Base58.encode58Check(contractAddress) + "\""; + txid = PublicMethed + .triggerContract(contractAddress, + "deploy3(bytes,string)", num, false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + byte[] returnAddressBytes = infoById.get().getInternalTransactions(0).getTransferToAddress() + .toByteArray(); + String returnAddress = Base58.encode58Check(returnAddressBytes); + logger.info("returnAddress:" + returnAddress); + txid = PublicMethed + .triggerContract(returnAddressBytes, + "i()", "#", false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById1 = null; + infoById1 = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee1 = infoById1.get().getFee(); + Long netUsed1 = infoById1.get().getReceipt().getNetUsage(); + Long energyUsed1 = infoById1.get().getReceipt().getEnergyUsage(); + Long netFee1 = infoById1.get().getReceipt().getNetFee(); + long energyUsageTotal1 = infoById1.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee1:" + fee1); + logger.info("netUsed1:" + netUsed1); + logger.info("energyUsed1:" + energyUsed1); + logger.info("netFee1:" + netFee1); + logger.info("energyUsageTotal1:" + energyUsageTotal1); + + Account infoafter1 = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter1 = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance1 = infoafter1.getBalance(); + Long afterEnergyUsed1 = resourceInfoafter1.getEnergyUsed(); + Long afterNetUsed1 = resourceInfoafter1.getNetUsed(); + Long afterFreeNetUsed1 = resourceInfoafter1.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance1); + logger.info("afterEnergyUsed:" + afterEnergyUsed1); + logger.info("afterNetUsed:" + afterNetUsed1); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed1); + + Assert.assertTrue(infoById1.get().getResultValue() == 0); + Assert.assertTrue(afterBalance1 + fee1 == afterBalance); + Assert.assertTrue(afterEnergyUsed + energyUsed1 >= afterEnergyUsed1); + Long returnnumber = ByteArray.toLong(ByteArray + .fromHexString(ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); + Assert.assertTrue(2 == returnnumber); + + txid = PublicMethed + .triggerContract(contractAddress, + "deploy3(bytes,string)", num, false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + Optional infoById2 = null; + infoById2 = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + + Assert.assertTrue(infoById2.get().getResultValue() != 0); + Assert + .assertThat(ByteArray + .toStr(infoById2.get().getResMessage().toByteArray()), + containsString("Not enough energy")); + } + + + @Test(enabled = true, description = "TriggerContract a constant function created by create2") + public void testTriggerContract5() { + + Account info; + Assert.assertTrue(PublicMethed + .sendcoin(contractAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + + String contractName1 = "TestConstract2"; + String filePath = "src/test/resources/soliditycode/create2contract22.sol"; + HashMap retMap1 = PublicMethed.getBycodeAbi(filePath, contractName1); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + String txid = ""; + String num = "\"" + code1 + "\"" + ",\"" + Base58.encode58Check(contractAddress) + "\""; + txid = PublicMethed + .triggerContract(contractAddress, + "deploy3(bytes,string)", num, false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + byte[] returnAddressBytes = infoById.get().getInternalTransactions(0).getTransferToAddress() + .toByteArray(); + String returnAddress = Base58.encode58Check(returnAddressBytes); + logger.info("returnAddress:" + returnAddress); + txid = PublicMethed + .triggerContract(returnAddressBytes, + "i()", "#", false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById1 = null; + infoById1 = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee1 = infoById1.get().getFee(); + Long netUsed1 = infoById1.get().getReceipt().getNetUsage(); + Long energyUsed1 = infoById1.get().getReceipt().getEnergyUsage(); + Long netFee1 = infoById1.get().getReceipt().getNetFee(); + long energyUsageTotal1 = infoById1.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee1:" + fee1); + logger.info("netUsed1:" + netUsed1); + logger.info("energyUsed1:" + energyUsed1); + logger.info("netFee1:" + netFee1); + logger.info("energyUsageTotal1:" + energyUsageTotal1); + + Account infoafter1 = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter1 = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance1 = infoafter1.getBalance(); + Long afterEnergyUsed1 = resourceInfoafter1.getEnergyUsed(); + Long afterNetUsed1 = resourceInfoafter1.getNetUsed(); + Long afterFreeNetUsed1 = resourceInfoafter1.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance1); + logger.info("afterEnergyUsed:" + afterEnergyUsed1); + logger.info("afterNetUsed:" + afterNetUsed1); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed1); + + Assert.assertTrue(infoById1.get().getResultValue() == 0); + Assert.assertTrue(afterBalance1 + fee1 == afterBalance); + Assert.assertTrue(afterEnergyUsed + energyUsed1 >= afterEnergyUsed1); + Long returnnumber = ByteArray.toLong(ByteArray + .fromHexString(ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); + Assert.assertTrue(3 == returnnumber); + num = "\"" + code1 + "\"" + ",\"" + Base58.encode58Check(testNetAccountAddress) + "\""; + + txid = PublicMethed + .triggerContract(contractAddress, + "deploy3(bytes,string)", num, false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + Optional infoById2 = null; + infoById2 = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + + Assert.assertTrue(infoById2.get().getResultValue() != 0); + Assert + .assertThat(ByteArray + .toStr(infoById2.get().getResMessage().toByteArray()), + containsString("Not enough energy")); + } + + + @Test(enabled = true, description = "TriggerContract a constant function created by create2") + public void testTriggerContract6() { + + Account info; + Assert.assertTrue(PublicMethed + .sendcoin(contractAddress, 1000000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + + String contractName1 = "TestConstract3"; + String filePath = "src/test/resources/soliditycode/create2contract22.sol"; + HashMap retMap1 = PublicMethed.getBycodeAbi(filePath, contractName1); + String code1 = retMap1.get("byteCode").toString(); + String abi1 = retMap1.get("abI").toString(); + String txid = ""; + String num = "\"" + code1 + "\"" + ",\"" + Base58.encode58Check(contractAddress) + "\""; + txid = PublicMethed + .triggerContract(contractAddress, + "deploy3(bytes,string)", num, false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 0); + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + byte[] returnAddressBytes = infoById.get().getInternalTransactions(0).getTransferToAddress() + .toByteArray(); + String returnAddress = Base58.encode58Check(returnAddressBytes); + logger.info("returnAddress:" + returnAddress); + txid = PublicMethed + .triggerContract(returnAddressBytes, + "i()", "#", false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById1 = null; + infoById1 = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Long fee1 = infoById1.get().getFee(); + Long netUsed1 = infoById1.get().getReceipt().getNetUsage(); + Long energyUsed1 = infoById1.get().getReceipt().getEnergyUsage(); + Long netFee1 = infoById1.get().getReceipt().getNetFee(); + long energyUsageTotal1 = infoById1.get().getReceipt().getEnergyUsageTotal(); + + logger.info("fee1:" + fee1); + logger.info("netUsed1:" + netUsed1); + logger.info("energyUsed1:" + energyUsed1); + logger.info("netFee1:" + netFee1); + logger.info("energyUsageTotal1:" + energyUsageTotal1); + + Account infoafter1 = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + AccountResourceMessage resourceInfoafter1 = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + Long afterBalance1 = infoafter1.getBalance(); + Long afterEnergyUsed1 = resourceInfoafter1.getEnergyUsed(); + Long afterNetUsed1 = resourceInfoafter1.getNetUsed(); + Long afterFreeNetUsed1 = resourceInfoafter1.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance1); + logger.info("afterEnergyUsed:" + afterEnergyUsed1); + logger.info("afterNetUsed:" + afterNetUsed1); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed1); + + Assert.assertTrue(infoById1.get().getResultValue() == 0); + Assert.assertTrue(afterBalance1 + fee1 == afterBalance); + Assert.assertTrue(afterEnergyUsed + energyUsed1 >= afterEnergyUsed1); + Long returnnumber = ByteArray.toLong(ByteArray + .fromHexString(ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); + Assert.assertTrue(4 == returnnumber); + String fakeAddress = "FFFFFFF"; + + num = "\"" + code1 + "\"" + ",\"" + fakeAddress + "\""; + + txid = PublicMethed + .triggerContract(contractAddress, + "deploy3(bytes,string)", num, false, + 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + Optional infoById2 = null; + infoById2 = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + + Assert.assertTrue(infoById2.get().getResultValue() != 0); + Assert + .assertThat(ByteArray + .toStr(infoById2.get().getResMessage().toByteArray()), + containsString("Not enough energy")); + } + /** * constructor. */ diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test021.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test021.java index a030c67e3e2..52e5a104f02 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test021.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test021.java @@ -365,10 +365,6 @@ public void test2TriggerContract() { */ @AfterClass public void shutdown() throws InterruptedException { - //PublicMethed.unFreezeBalance(contractExcAddress, contractExcKey, 0, null, blockingStubFull); - //PublicMethed.unFreezeBalance(contractExcAddress, contractExcKey, 1, null, blockingStubFull); - //PublicMethed.unFreezeBalance(contractExcAddress, contractExcKey, 0, bytes, blockingStubFull); - //PublicMethed.unFreezeBalance(contractExcAddress, contractExcKey, 0, bytes, blockingStubFull); if (channelFull != null) { channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test024.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test024.java index c127bc37715..307960819a3 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test024.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test024.java @@ -2,11 +2,9 @@ import static org.hamcrest.core.StringContains.containsString; -import com.google.protobuf.ByteString; import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import java.util.HashMap; -import java.util.List; import java.util.Optional; import java.util.concurrent.TimeUnit; import lombok.extern.slf4j.Slf4j; @@ -25,7 +23,6 @@ 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.WalletClient; import stest.tron.wallet.common.client.utils.Base58; import stest.tron.wallet.common.client.utils.PublicMethed; @@ -89,14 +86,6 @@ public void test01DeployFactoryContract() { testKey002, blockingStubFull)); Assert.assertTrue(PublicMethed.sendcoin(user001Address, 10000_000_000L, fromAddress, testKey002, blockingStubFull)); - //Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, - // PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, - // blockingStubFull), 0, 1, - // ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); - - //Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, - // 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); //before deploy, check account resource @@ -151,10 +140,6 @@ public void test01DeployFactoryContract() { @Test(enabled = true, description = "create2 not allowed create2 twice in function") public void test02TriggerTestContract() { - //Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, - // PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, - // blockingStubFull), 0, 1, - // ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); @@ -234,13 +219,11 @@ public void test02TriggerTestContract() { Assert.assertEquals(realResult, "00"); Assert.assertNotEquals(realResult, "41"); - String addressFinal = Base58.encode58Check(ByteArray.fromHexString(exceptedResult)); logger.info("create2 Address : " + addressFinal); - Assert.assertEquals(infoById.get().getResult().toString(),"SUCESS"); - Assert.assertEquals(infoById.get().getResultValue(),0); - + Assert.assertEquals(infoById.get().getResult().toString(), "SUCESS"); + Assert.assertEquals(infoById.get().getResultValue(), 0); triggerTxid = PublicMethed.triggerContract(factoryContractAddress, "deploy2(bytes,uint256)", param, false, callValue, @@ -272,13 +255,12 @@ public void test02TriggerTestContract() { logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); - Assert.assertEquals(infoById.get().getResultValue(),1); - Assert.assertEquals(infoById.get().getResult().toString(),"FAILED"); + Assert.assertEquals(infoById.get().getResultValue(), 1); + Assert.assertEquals(infoById.get().getResult().toString(), "FAILED"); Assert.assertThat(ByteArray.toStr(infoById.get().getResMessage().toByteArray()), containsString("Not enough energy for 'SWAP1' operation executing: ")); - } /** diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest001.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest001.java index 6a4ed8c9c77..42e2228a20a 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest001.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest001.java @@ -228,14 +228,6 @@ public void test02GetNormalAddressCodeHash() { Assert.assertEquals("C5D2460186F7233C927E7DB2DCC703C0E500B653CA82273B7BFAD8045D85A470", retList.get(0)); - /*PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, - dev001Address, blockingStubFull); - PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, - dev001Address, blockingStubFull); - PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, - user001Address, blockingStubFull); - PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, - user001Address, blockingStubFull);*/ } @Test(enabled = true, description = "Get a contract extcodehash") @@ -489,14 +481,6 @@ public void test05ActiveAccountGetCodeHash() { .getContract(extCodeHashContractAddress, blockingStubFull); logger.info(smartContract.getBytecode().toStringUtf8()); - /*PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, - dev001Address, blockingStubFull); - PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, - dev001Address, blockingStubFull); - PublicMethed.unFreezeBalance(fromAddress, testKey002, 1, - user001Address, blockingStubFull); - PublicMethed.unFreezeBalance(fromAddress, testKey002, 0, - user001Address, blockingStubFull);*/ } @Test(enabled = true, description = "Get a not deployed create2 extcodehash") diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest004.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest004.java index ea609cc77ad..eb60051b1fb 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest004.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest004.java @@ -31,6 +31,7 @@ @Slf4j public class ExtCodeHashTest004 { + private final boolean AllTest = false; private final String testKey002 = Configuration.getByPath("testng.conf") diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest010.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest010.java index 749edb6101b..dc32ba60c46 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest010.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest010.java @@ -81,13 +81,7 @@ public void beforeClass() { public void test01DeployExtCodeHashContract() { Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); - /*Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, - PublicMethed.getFreezeBalanceCount(dev001Address, dev001Key, 170000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, - 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull));*/ PublicMethed.waitProduceNextBlock(blockingStubFull); @@ -147,10 +141,6 @@ public void test02GetTestContractCodeHash() { Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); - /*Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, - PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull));*/ AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); @@ -228,10 +218,6 @@ public void test03GetTestContractCodeHash() { Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); - /*Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, - PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull));*/ AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); @@ -308,10 +294,6 @@ public void test04GetTestContractCodeHash() { Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, testKey002, blockingStubFull)); - /*Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, - PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, - blockingStubFull), 0, 1, - ByteString.copyFrom(user001Address), testKey002, blockingStubFull));*/ AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest011.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest011.java new file mode 100644 index 00000000000..a0c92c51f72 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest011.java @@ -0,0 +1,364 @@ +package stest.tron.wallet.dailybuild.tvmnewcommand.extCodeHash; + +import static org.hamcrest.core.StringContains.containsString; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +import java.util.List; +import java.util.Optional; +import java.util.concurrent.TimeUnit; +import lombok.extern.slf4j.Slf4j; +import org.junit.Assert; +import org.spongycastle.util.encoders.Hex; +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.crypto.Hash; +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 ExtCodeHashTest011 { + + private final String testKey002 = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + 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(1); + private long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + + private byte[] extCodeHashContractAddress = null; + private byte[] testContractAddress = null; + + private String expectedCodeHash = null; + + private ECKey ecKey1 = new ECKey(Utils.getRandom()); + private byte[] dev001Address = ecKey1.getAddress(); + private String dev001Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + private ECKey ecKey2 = new ECKey(Utils.getRandom()); + private byte[] user001Address = ecKey2.getAddress(); + private String user001Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + @BeforeClass(enabled = true) + public void beforeClass() { + + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + + PublicMethed.printAddress(dev001Key); + PublicMethed.printAddress(user001Key); + } + + @Test(enabled = true, description = "Deploy extcodehash contract") + public void test01DeployExtCodeHashContract() { + Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + //before deploy, check account resource + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long energyLimit = accountResource.getEnergyLimit(); + long energyUsage = accountResource.getEnergyUsed(); + long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before energyLimit is " + Long.toString(energyLimit)); + logger.info("before energyUsage is " + Long.toString(energyUsage)); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + String filePath = "./src/test/resources/soliditycode/extCodeHash11.sol"; + String contractName = "Counter"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + expectedCodeHash = ByteArray.toHexString(Hash.sha3(Hex.decode(code))); + logger.info("expectedCodeHash: " + expectedCodeHash); + + String transferTokenTxid = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", + maxFeeLimit, 0L, 0, 10000, + "0", 0, null, dev001Key, + dev001Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + extCodeHashContractAddress = infoById.get().getContractAddress().toByteArray(); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + energyLimit = accountResource.getEnergyLimit(); + energyUsage = accountResource.getEnergyUsed(); + long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + + logger.info("after energyLimit is " + Long.toString(energyLimit)); + logger.info("after energyUsage is " + Long.toString(energyUsage)); + logger.info("after balanceAfter is " + Long.toString(balanceAfter)); + transferTokenTxid = PublicMethed.triggerContract(extCodeHashContractAddress, + "getCodeHashByAddr()", "#", false, 0, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + + Assert.assertTrue(infoById.get().getResultValue() != 0); + Assert + .assertThat(ByteArray + .toStr(infoById.get().getResMessage().toByteArray()), + containsString("REVERT opcode executed")); + } + + + @Test(enabled = true, description = "Deploy extcodehash contract") + public void test01DeployExtCodeHashContract1() { + Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + //before deploy, check account resource + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long energyLimit = accountResource.getEnergyLimit(); + long energyUsage = accountResource.getEnergyUsed(); + long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before energyLimit is " + Long.toString(energyLimit)); + logger.info("before energyUsage is " + Long.toString(energyUsage)); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + String filePath = "./src/test/resources/soliditycode/extCodeHash11.sol"; + String contractName = "Counter1"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + expectedCodeHash = ByteArray.toHexString(Hash.sha3(Hex.decode(code))); + logger.info("expectedCodeHash: " + expectedCodeHash); + + String transferTokenTxid = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", + maxFeeLimit, 0L, 0, 10000, + "0", 0, null, dev001Key, + dev001Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + extCodeHashContractAddress = infoById.get().getContractAddress().toByteArray(); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + energyLimit = accountResource.getEnergyLimit(); + energyUsage = accountResource.getEnergyUsed(); + long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + + logger.info("after energyLimit is " + Long.toString(energyLimit)); + logger.info("after energyUsage is " + Long.toString(energyUsage)); + logger.info("after balanceAfter is " + Long.toString(balanceAfter)); + transferTokenTxid = PublicMethed.triggerContract(extCodeHashContractAddress, + "getCodeHashByAddr()", "#", false, 0, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + List retList = PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray()); + + logger.info( + "the value: " + retList); + + Assert.assertEquals(retList.get(1), + retList.get(0)); + logger.info("EnergyUsageTotal: " + transactionInfo.getReceipt().getEnergyUsageTotal()); + logger.info("NetUsage: " + transactionInfo.getReceipt().getNetUsage()); + + extCodeHashContractAddress = infoById.get().getContractAddress().toByteArray(); + SmartContract smartContract = PublicMethed.getContract(extCodeHashContractAddress, + blockingStubFull); + Assert.assertNotNull(smartContract.getAbi()); + } + + + @Test(enabled = true, description = "Deploy extcodehash contract") + public void test01DeployExtCodeHashContract2() { + Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + //before deploy, check account resource + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long energyLimit = accountResource.getEnergyLimit(); + long energyUsage = accountResource.getEnergyUsed(); + long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before energyLimit is " + Long.toString(energyLimit)); + logger.info("before energyUsage is " + Long.toString(energyUsage)); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + String filePath = "./src/test/resources/soliditycode/extCodeHash11.sol"; + String contractName = "Counter2"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + expectedCodeHash = ByteArray.toHexString(Hash.sha3(Hex.decode(code))); + logger.info("expectedCodeHash: " + expectedCodeHash); + + String transferTokenTxid = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", + maxFeeLimit, 0L, 0, 10000, + "0", 0, null, dev001Key, + dev001Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + extCodeHashContractAddress = infoById.get().getContractAddress().toByteArray(); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + energyLimit = accountResource.getEnergyLimit(); + energyUsage = accountResource.getEnergyUsed(); + long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + + logger.info("after energyLimit is " + Long.toString(energyLimit)); + logger.info("after energyUsage is " + Long.toString(energyUsage)); + logger.info("after balanceAfter is " + Long.toString(balanceAfter)); + + String num = "\"" + Base58.encode58Check(dev001Address) + "\""; + + transferTokenTxid = PublicMethed.triggerContract(extCodeHashContractAddress, + "getCodeHashByAddr(address)", num, false, 0, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + List retList = PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray()); + + logger.info( + "the value: " + retList); + Assert.assertEquals(retList.get(1), + retList.get(0)); + } + + + @Test(enabled = true, description = "Deploy extcodehash contract") + public void test01DeployExtCodeHashContract3() { + Assert.assertTrue(PublicMethed.sendcoin(dev001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + Assert.assertTrue(PublicMethed.sendcoin(user001Address, 100_000_000L, fromAddress, + testKey002, blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + + //before deploy, check account resource + AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, + blockingStubFull); + long energyLimit = accountResource.getEnergyLimit(); + long energyUsage = accountResource.getEnergyUsed(); + long balanceBefore = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + logger.info("before energyLimit is " + Long.toString(energyLimit)); + logger.info("before energyUsage is " + Long.toString(energyUsage)); + logger.info("before balanceBefore is " + Long.toString(balanceBefore)); + + String filePath = "./src/test/resources/soliditycode/extCodeHash11.sol"; + String contractName = "Counter2"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + expectedCodeHash = ByteArray.toHexString(Hash.sha3(Hex.decode(code))); + logger.info("expectedCodeHash: " + expectedCodeHash); + + String transferTokenTxid = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", + maxFeeLimit, 0L, 0, 10000, + "0", 0, null, dev001Key, + dev001Address, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + extCodeHashContractAddress = infoById.get().getContractAddress().toByteArray(); + + accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); + energyLimit = accountResource.getEnergyLimit(); + energyUsage = accountResource.getEnergyUsed(); + long balanceAfter = PublicMethed.queryAccount(dev001Key, blockingStubFull).getBalance(); + + logger.info("after energyLimit is " + Long.toString(energyLimit)); + logger.info("after energyUsage is " + Long.toString(energyUsage)); + logger.info("after balanceAfter is " + Long.toString(balanceAfter)); + + String num = "\"" + Base58.encode58Check(dev001Address) + "\""; + + transferTokenTxid = PublicMethed.triggerContract(extCodeHashContractAddress, + "getCodeHashByAddr(address)", num, false, 0, + 1000000000L, "0", 0, user001Address, user001Key, + blockingStubFull); + + infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + infoById = PublicMethed + .getTransactionInfoById(transferTokenTxid, blockingStubFull); + + TransactionInfo transactionInfo = infoById.get(); + List retList = PublicMethed + .getStrings(transactionInfo.getContractResult(0).toByteArray()); + + logger.info( + "the value: " + retList); + Assert.assertEquals(retList.get(1), + retList.get(0)); + } + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } +} + + diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed001.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed001.java index 06acf158620..a69f1951aff 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed001.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed001.java @@ -169,20 +169,7 @@ public void test1TransferTrxInsufficientBalance() { @Test(enabled = true, description = "Transfer balance enough") public void test2TransferEnough() { - /*Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; - String contractName = "EnergyOfTransferFailedTest"; - HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull);*/ Assert.assertTrue(PublicMethed .sendcoin(contractAddress, 3000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); @@ -242,19 +229,7 @@ public void test2TransferEnough() { @Test(enabled = true, description = "Transfer trx nonexistent target") public void test3TransferTrxNonexistentTarget() { - /*Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; - String contractName = "EnergyOfTransferFailedTest"; - HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull);*/ Assert.assertTrue(PublicMethed .sendcoin(contractAddress, 1000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); @@ -327,22 +302,7 @@ public void test3TransferTrxNonexistentTarget() { @Test(enabled = true, description = "Transfer trx to myself") public void test4TransferTrxSelf() { - /*Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; - String contractName = "EnergyOfTransferFailedTest"; - HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethed - .sendcoin(contractAddress, 1000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull));*/ Account info; @@ -409,22 +369,6 @@ public void test4TransferTrxSelf() { @Test(enabled = true, description = "Transfer trx nonexistent target and insufficient balance") public void test5TransferTrxNonexistentTarget() { - /*Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; - String contractName = "EnergyOfTransferFailedTest"; - HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethed - .sendcoin(contractAddress, 1000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull));*/ Account info; @@ -493,22 +437,7 @@ public void test5TransferTrxNonexistentTarget() { @Test(enabled = true, description = "Transfer trx to myself and insufficient balance") public void test6TransferTrxSelf() { - /*Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; - String contractName = "EnergyOfTransferFailedTest"; - HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethed - .sendcoin(contractAddress, 1000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull));*/ Account info; @@ -573,9 +502,9 @@ public void test6TransferTrxSelf() { } - @Test(enabled = true, description = "preCompiled transfertoken with value," + @Test(enabled = true, description = "PreCompiled transfertoken with value," + " long.max < value or long.min > value") - public void test7TransferTockenPreCompiled() { + public void test7TransferTrckenPreCompiled() { AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull); @@ -665,8 +594,8 @@ public void test7TransferTockenPreCompiled() { } - @Test(enabled = false, description = "tokenbalance") - public void test8TransferTocken() { + @Test(enabled = false, description = "PreCompiled tokenbalance") + public void test8TransferTrctoken() { Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 10000_000_000L, testNetAccountAddress, testNetAccountKey, @@ -778,8 +707,8 @@ public void test8TransferTocken() { } - @Test(enabled = true, description = "address(0x1) qeury tokenbalance") - public void test9TransferTocken() { + @Test(enabled = true, description = "PreCompiled address(0x1) query tokenbalance") + public void test9TransferTrctoken() { //address: 410000000000000000000000000000000000000001 String addressx = "T9yD14Nj9j7xAB4dbGeiX9h8unkKLxmGkn"; byte[] addressxx = WalletClient.decodeFromBase58Check(addressx); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed002.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed002.java index 3bf1adc5b74..cb3187857d1 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed002.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed002.java @@ -161,20 +161,6 @@ public void test1SendNotEnough() { @Test(enabled = true, description = "Send balance enough") public void test2SendEnough() { - /*Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; - String contractName = "EnergyOfTransferFailedTest"; - HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull);*/ Assert.assertTrue(PublicMethed .sendcoin(contractAddress, 3000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); @@ -234,22 +220,6 @@ public void test2SendEnough() { @Test(enabled = true, description = "Send trx nonexistent target") public void test3SendTrxNonexistentTarget() { - /*Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; - String contractName = "EnergyOfTransferFailedTest"; - HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethed - .sendcoin(contractAddress, 1000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull));*/ Account info; @@ -319,23 +289,6 @@ public void test3SendTrxNonexistentTarget() { @Test(enabled = true, description = "Send trx self") public void test4SendTrxSelf() { - /*Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; - String contractName = "EnergyOfTransferFailedTest"; - HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethed - .sendcoin(contractAddress, 1000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull));*/ - Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -401,23 +354,6 @@ public void test4SendTrxSelf() { @Test(enabled = true, description = "Send trx nonexistent target and balance not enough") public void test5SendTrxNonexistentTarget() { - /*Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; - String contractName = "EnergyOfTransferFailedTest"; - HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethed - .sendcoin(contractAddress, 1000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull));*/ - Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -480,23 +416,6 @@ public void test5SendTrxNonexistentTarget() { @Test(enabled = true, description = "Send trx self and balance not enough") public void test6SendTrxSelf() { - /*Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; - String contractName = "EnergyOfTransferFailedTest"; - HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethed - .sendcoin(contractAddress, 1000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull));*/ - Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed003.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed003.java index b2abcf03c9e..d754f9b1819 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed003.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed003.java @@ -200,10 +200,6 @@ public void test1TransferTokenEnough() { @Test(enabled = true, description = "TransferToken insufficient tokenBalance") public void test2TransferTokenNotEnough() { - /*Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 100_000_000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull);*/ Account info; @@ -280,10 +276,6 @@ public void test2TransferTokenNotEnough() { @Test(enabled = true, description = "TransferToken to nonexistent target") public void test3TransferTokenNonexistentTarget() { - /*Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 10000_000_000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull);*/ Account info; @@ -367,10 +359,6 @@ public void test3TransferTokenNonexistentTarget() { @Test(enabled = true, description = "TransferToken to myself") public void test4TransferTokenSelf() { - /*Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 100_000_000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull);*/ Account info; @@ -449,10 +437,7 @@ public void test4TransferTokenSelf() { @Test(enabled = true, description = "TransferToken notexist tokenID ") public void test5TransferTokenNotexist() { - /*Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 100_000_000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull);*/ + Account info; @@ -533,10 +518,6 @@ public void test5TransferTokenNotexist() { @Test(enabled = true, description = "TransferToken to nonexistent target and " + "insufficient tokenBalance") public void test7TransferTokenNonexistentTarget() { - /*Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 10000_000_000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull);*/ Account info; @@ -620,10 +601,7 @@ public void test7TransferTokenNonexistentTarget() { @Test(enabled = true, description = "TransferToken to myself and insufficient tokenBalance") public void test8TransferTokenSelf() { - /*Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 100_000_000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull);*/ + Account info; diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed004.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed004.java index 7cc9a828899..a04d01b2720 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed004.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed004.java @@ -176,23 +176,7 @@ public void test1SuicideNonexistentTarget() { @Test(enabled = true, description = "Suicide existent target") public void test2SuicideExistentTarget() { - /*Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; - String contractName = "EnergyOfTransferFailedTest"; - HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethed - .sendcoin(contractAddress, 3000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull));*/ Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/old/TransferFailed005.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/old/TransferFailed005.java deleted file mode 100644 index c962179d6cf..00000000000 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/old/TransferFailed005.java +++ /dev/null @@ -1,509 +0,0 @@ -package stest.tron.wallet.dailybuild.tvmnewcommand.transferfailed.old; - -import io.grpc.ManagedChannel; -import io.grpc.ManagedChannelBuilder; -import java.util.HashMap; -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.api.WalletSolidityGrpc; -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.Base58; -import stest.tron.wallet.common.client.utils.PublicMethed; - -@Slf4j -public class TransferFailed005 { - final boolean AllTest = false; - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key1"); - private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); - private final Long maxFeeLimit = Configuration.getByPath("testng.cong") - .getLong("defaultParameter.maxFeeLimit"); - - private ManagedChannel channelSolidity = null; - - private ManagedChannel channelFull = null; - private WalletGrpc.WalletBlockingStub blockingStubFull = null; - - private ManagedChannel channelFull1 = null; - private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - - - private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; - - private String fullnode = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(0); - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - - byte[] contractAddress = null; - byte[] contractAddress1 = null; - - ECKey ecKey1 = new ECKey(Utils.getRandom()); - byte[] accountExcAddress = ecKey1.getAddress(); - String accountExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - - @BeforeSuite - public void beforeSuite() { - Wallet wallet = new Wallet(); - Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); - } - - @BeforeClass(enabled = AllTest) - public void beforeClass() { - PublicMethed.printAddress(accountExcKey); - channelFull = ManagedChannelBuilder.forTarget(fullnode) - .usePlaintext(true) - .build(); - blockingStubFull = WalletGrpc.newBlockingStub(channelFull); - channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext(true) - .build(); - blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - - { - Assert.assertTrue(PublicMethed - .sendcoin(accountExcAddress, 10000_000_000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); - - String filePath = "src/test/resources/soliditycode_v0.4.25/TransferFailed005.sol"; - String contractName = "EnergyOfTransferFailedTest"; - HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethed - .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100L, - null, accountExcKey, accountExcAddress, blockingStubFull); - - filePath = "src/test/resources/soliditycode_v0.4.25/TransferFailed005.sol"; - contractName = "Caller"; - retMap = PublicMethed.getBycodeAbi(filePath, contractName); - code = retMap.get("byteCode").toString(); - abi = retMap.get("abI").toString(); - - contractAddress1 = PublicMethed - .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100L, - null, accountExcKey, accountExcAddress, blockingStubFull); - } - } - - @Test(enabled = AllTest, description = "Deploy contract for trigger") - public void deployContract() { - Assert.assertTrue(PublicMethed - .sendcoin(accountExcAddress, 10000_000_000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); - - String filePath = "src/test/resources/soliditycode_v0.4.25/TransferFailed005.sol"; - String contractName = "EnergyOfTransferFailedTest"; - HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethed - .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100L, - null, accountExcKey, accountExcAddress, blockingStubFull); - /*String Txid1 = PublicMethed - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, 0L, 100L, - null, accountExcKey, accountExcAddress, blockingStubFull); - Optional infoById = PublicMethed - .getTransactionInfoById(Txid1, blockingStubFull); - contractAddress = infoById.get().getContractAddress().toByteArray(); - //Assert.assertEquals(0, infoById.get().getResultValue());*/ - - filePath = "src/test/resources/soliditycode_v0.4.25/TransferFailed005.sol"; - contractName = "Caller"; - retMap = PublicMethed.getBycodeAbi(filePath, contractName); - code = retMap.get("byteCode").toString(); - abi = retMap.get("abI").toString(); - - contractAddress1 = PublicMethed - .deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100L, - null, accountExcKey, accountExcAddress, blockingStubFull); - /*Txid1 = PublicMethed - .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, 0L, 100L, - null, accountExcKey, accountExcAddress, blockingStubFull); - infoById = PublicMethed - .getTransactionInfoById(Txid1, blockingStubFull); - contractAddress1 = infoById.get().getContractAddress().toByteArray(); - logger.info("caller address : " + Base58.encode58Check(contractAddress1)); - Assert.assertEquals(0, infoById.get().getResultValue());*/ - } - - @Test(enabled = AllTest, description = "TransferFailed for function call_value ") - public void triggerContract01() { - Account info = null; - - AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(accountExcAddress, - blockingStubFull); - info = PublicMethed.queryAccount(accountExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); - logger.info("beforeBalance:" + beforeBalance); - logger.info("beforeEnergyUsed:" + beforeEnergyUsed); - logger.info("beforeNetUsed:" + beforeNetUsed); - logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - - Assert.assertTrue(PublicMethed - .sendcoin(contractAddress, 1000100L, accountExcAddress, accountExcKey, blockingStubFull)); - //Assert.assertTrue(PublicMethed - // .sendcoin(contractAddress1, 1, accountExcAddress, accountExcKey, blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); - - logger.info( - "contractAddress balance before: " + PublicMethed - .queryAccount(contractAddress, blockingStubFull) - .getBalance()); - logger.info( - "callerAddress balance before: " + PublicMethed - .queryAccount(contractAddress1, blockingStubFull) - .getBalance()); - long paramValue = 1000000; - - // transfer trx to self`s account - String param = "\"" + paramValue + "\",\"" + Base58.encode58Check(contractAddress) + "\""; - String triggerTxid = PublicMethed.triggerContract(contractAddress, - "testCallTrxInsufficientBalance(uint256,address)", param, false, 0L, - maxFeeLimit, accountExcAddress, accountExcKey, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); - Optional infoById = PublicMethed - .getTransactionInfoById(triggerTxid, blockingStubFull); - - Assert.assertEquals(infoById.get().getResultValue(), 1); - Assert.assertEquals("FAILED", infoById.get().getResult().toString()); - Assert.assertEquals("UNKNOWN", infoById.get().getReceipt().getResult().toString()); - Assert.assertEquals("validateForSmartContract failure:%s", - infoById.get().getResMessage().toStringUtf8()); - Assert.assertEquals(1000100L, - PublicMethed.queryAccount(contractAddress, blockingStubFull).getBalance()); - Assert.assertEquals(0L, - PublicMethed.queryAccount(contractAddress1, blockingStubFull).getBalance()); - Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() == 100000000); - - // transfer trx to unactivate account - ECKey ecKey2 = new ECKey(Utils.getRandom()); - byte[] accountExcAddress2 = ecKey2.getAddress(); - param = "\"" + paramValue + "\",\"" + Base58.encode58Check(accountExcAddress2) + "\""; - triggerTxid = PublicMethed.triggerContract(contractAddress, - "testCallTrxInsufficientBalance(uint256,address)", param, false, 0L, - maxFeeLimit, accountExcAddress, accountExcKey, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethed - .getTransactionInfoById(triggerTxid, blockingStubFull); - - Assert.assertEquals(infoById.get().getResultValue(), 1); - Assert.assertEquals("FAILED", infoById.get().getResult().toString()); - Assert.assertEquals("UNKNOWN", infoById.get().getReceipt().getResult().toString()); - Assert.assertEquals( - "validateForSmartContract failure:%s", - infoById.get().getResMessage().toStringUtf8()); - Assert.assertEquals(1000100L, - PublicMethed.queryAccount(contractAddress, blockingStubFull).getBalance()); - Assert.assertEquals(0L, - PublicMethed.queryAccount(contractAddress1, blockingStubFull).getBalance()); - Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() == 100000000); - - // transfer trx to caller, value enough , function success contractResult(call_value) failed - param = "\"" + paramValue + "\",\"" + Base58.encode58Check(contractAddress1) + "\""; - triggerTxid = PublicMethed.triggerContract(contractAddress, - "testCallTrxInsufficientBalance(uint256,address)", param, false, 0L, - maxFeeLimit, accountExcAddress, accountExcKey, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); - - infoById = PublicMethed - .getTransactionInfoById(triggerTxid, blockingStubFull); - logger.info(infoById.get().getReceipt().getResult() + ""); - - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); - long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); - logger.info("fee:" + fee); - logger.info("netUsed:" + netUsed); - logger.info("energyUsed:" + energyUsed); - logger.info("netFee:" + netFee); - logger.info("energyUsageTotal:" + energyUsageTotal); - - int contractResult = ByteArray - .toInt(infoById.get().getContractResult(0).toByteArray()); - Assert.assertEquals(1, contractResult); - - Assert.assertEquals(infoById.get().getResultValue(), 0); - Assert.assertEquals(infoById.get().getResult().toString(), "SUCESS"); - Assert.assertEquals(100L, - PublicMethed.queryAccount(contractAddress, blockingStubFull).getBalance()); - Assert.assertEquals(1000000L, - PublicMethed.queryAccount(contractAddress1, blockingStubFull).getBalance()); - Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() < 10000000); - - // transfer trx to caller, value not enough, function success - // but contractResult(call_value) failed - triggerTxid = PublicMethed.triggerContract(contractAddress, - "testCallTrxInsufficientBalance(uint256,address)", param, false, 0L, - maxFeeLimit, accountExcAddress, accountExcKey, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); - - infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull); - fee = infoById.get().getFee(); - netUsed = infoById.get().getReceipt().getNetUsage(); - energyUsed = infoById.get().getReceipt().getEnergyUsage(); - netFee = infoById.get().getReceipt().getNetFee(); - energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); - logger.info("fee:" + fee); - logger.info("netUsed:" + netUsed); - logger.info("energyUsed:" + energyUsed); - logger.info("netFee:" + netFee); - logger.info("energyUsageTotal:" + energyUsageTotal); - - //contractResult`s first boolean value - contractResult = ByteArray - .toInt(infoById.get().getContractResult(0).toByteArray()); - Assert.assertEquals(0, contractResult); - Assert.assertEquals(infoById.get().getResultValue(), 0); - Assert.assertEquals(infoById.get().getResult().toString(), "SUCESS"); - Assert.assertEquals(100L, - PublicMethed.queryAccount(contractAddress, blockingStubFull).getBalance()); - Assert.assertEquals(1000000L, - PublicMethed.queryAccount(contractAddress1, blockingStubFull).getBalance()); - Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() < 10000000); - - - } - - @Test(enabled = AllTest, description = "TransferFailed for create") - public void triggerContract02() { - Account info = null; - - AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(accountExcAddress, - blockingStubFull); - info = PublicMethed.queryAccount(accountExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); - logger.info("beforeBalance:" + beforeBalance); - logger.info("beforeEnergyUsed:" + beforeEnergyUsed); - logger.info("beforeNetUsed:" + beforeNetUsed); - logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - - Assert.assertTrue(PublicMethed - .sendcoin(contractAddress, 1000100L, accountExcAddress, accountExcKey, blockingStubFull)); - //Assert.assertTrue(PublicMethed - // .sendcoin(contractAddress1, 1, accountExcAddress, accountExcKey, blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); - - logger.info( - "contractAddress balance before: " + PublicMethed - .queryAccount(contractAddress, blockingStubFull) - .getBalance()); - logger.info( - "callerAddress balance before: " + PublicMethed - .queryAccount(contractAddress1, blockingStubFull) - .getBalance()); - long paramValue = 1000000; - String param = "\"" + paramValue + "\""; - - String triggerTxid = PublicMethed.triggerContract(contractAddress, - "testCreateTrxInsufficientBalance(uint256)", param, false, 0L, - maxFeeLimit, accountExcAddress, accountExcKey, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); - - Optional infoById = PublicMethed - .getTransactionInfoById(triggerTxid, blockingStubFull); - logger.info(infoById.get().getReceipt().getResult() + ""); - - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); - long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); - logger.info("fee:" + fee); - logger.info("netUsed:" + netUsed); - logger.info("energyUsed:" + energyUsed); - logger.info("netFee:" + netFee); - logger.info("energyUsageTotal:" + energyUsageTotal); - - logger.info( - "contractAddress balance before: " + PublicMethed - .queryAccount(contractAddress, blockingStubFull) - .getBalance()); - logger.info( - "callerAddress balance before: " + PublicMethed - .queryAccount(contractAddress1, blockingStubFull) - .getBalance()); - Assert.assertEquals(infoById.get().getResultValue(), 0); - Assert.assertFalse(infoById.get().getInternalTransactions(0).getRejected()); - Assert.assertEquals(200L, - PublicMethed.queryAccount(contractAddress, blockingStubFull).getBalance()); - Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() < 10000000); - - triggerTxid = PublicMethed.triggerContract(contractAddress, - "testCreateTrxInsufficientBalance(uint256)", param, false, 0L, - maxFeeLimit, accountExcAddress, accountExcKey, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); - - infoById = PublicMethed.getTransactionInfoById(triggerTxid, blockingStubFull); - fee = infoById.get().getFee(); - netUsed = infoById.get().getReceipt().getNetUsage(); - energyUsed = infoById.get().getReceipt().getEnergyUsage(); - netFee = infoById.get().getReceipt().getNetFee(); - energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); - logger.info("fee:" + fee); - logger.info("netUsed:" + netUsed); - logger.info("energyUsed:" + energyUsed); - logger.info("netFee:" + netFee); - logger.info("energyUsageTotal:" + energyUsageTotal); - - logger.info( - "contractAddress balance before: " + PublicMethed - .queryAccount(contractAddress, blockingStubFull) - .getBalance()); - logger.info( - "callerAddress balance before: " + PublicMethed - .queryAccount(contractAddress1, blockingStubFull) - .getBalance()); - - Assert.assertEquals(infoById.get().getResultValue(), 1); - Assert.assertEquals(infoById.get().getResMessage().toStringUtf8(), "REVERT opcode executed"); - Assert.assertEquals(200L, - PublicMethed.queryAccount(contractAddress, blockingStubFull).getBalance()); - Assert.assertEquals(1000000L, - PublicMethed.queryAccount(contractAddress1, blockingStubFull).getBalance()); - Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() < 10000000); - - - } - - @Test(enabled = AllTest, description = "TransferFailed for create2") - public void triggerContract03() { - Account info; - - AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(accountExcAddress, - blockingStubFull); - info = PublicMethed.queryAccount(accountExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); - logger.info("beforeBalance:" + beforeBalance); - logger.info("beforeEnergyUsed:" + beforeEnergyUsed); - logger.info("beforeNetUsed:" + beforeNetUsed); - logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - - Assert.assertTrue(PublicMethed - .sendcoin(contractAddress, 15L, accountExcAddress, accountExcKey, blockingStubFull)); - logger.info( - "contractAddress balance before: " + PublicMethed - .queryAccount(contractAddress, blockingStubFull) - .getBalance()); - - String filePath = "./src/test/resources/soliditycode_v0.4.25/TransferFailed007.sol"; - String contractName = "Caller"; - HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); - String testContractCode = retMap.get("byteCode").toString(); - Long salt = 1L; - - String param = "\"" + testContractCode + "\"," + salt; - - String triggerTxid = PublicMethed.triggerContract(contractAddress, - "deploy(bytes,uint256)", param, false, 0L, - maxFeeLimit, accountExcAddress, accountExcKey, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); - - Optional infoById = PublicMethed - .getTransactionInfoById(triggerTxid, blockingStubFull); - - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); - long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); - logger.info("fee:" + fee); - logger.info("netUsed:" + netUsed); - logger.info("energyUsed:" + energyUsed); - logger.info("netFee:" + netFee); - logger.info("energyUsageTotal:" + energyUsageTotal); - - long afterBalance = 0L; - afterBalance = PublicMethed.queryAccount(contractAddress, blockingStubFull) - .getBalance(); - logger.info( - "contractAddress balance after : " + PublicMethed - .queryAccount(contractAddress, blockingStubFull) - .getBalance()); - Assert.assertEquals(1, infoById.get().getResultValue()); - Assert.assertEquals("FAILED", infoById.get().getResult().toString()); - Assert.assertEquals("Invalid operation code: opCode[fb];",ByteArray.toStr(infoById.get().getResMessage().toByteArray())); - Assert.assertEquals(215L, afterBalance); - //Assert.assertFalse(infoById.get().getInternalTransactions(0).getRejected()); - Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() == 100000000); - - triggerTxid = PublicMethed.triggerContract(contractAddress, - "deploy2(bytes,uint256)", param, false, 0L, - maxFeeLimit, accountExcAddress, accountExcKey, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); - infoById = PublicMethed - .getTransactionInfoById(triggerTxid, blockingStubFull); - - fee = infoById.get().getFee(); - netUsed = infoById.get().getReceipt().getNetUsage(); - energyUsed = infoById.get().getReceipt().getEnergyUsage(); - netFee = infoById.get().getReceipt().getNetFee(); - energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); - logger.info("fee:" + fee); - logger.info("netUsed:" + netUsed); - logger.info("energyUsed:" + energyUsed); - logger.info("netFee:" + netFee); - logger.info("energyUsageTotal:" + energyUsageTotal); - - afterBalance = PublicMethed.queryAccount(contractAddress, blockingStubFull).getBalance(); - logger.info( - "contractAddress balance after : " + PublicMethed - .queryAccount(contractAddress, blockingStubFull) - .getBalance()); - Assert.assertEquals(1, infoById.get().getResultValue()); - Assert.assertEquals("FAILED", infoById.get().getResult().toString()); - Assert.assertEquals("Invalid operation code: opCode[fb];",ByteArray.toStr(infoById.get().getResMessage().toByteArray())); - //Assert.assertEquals(205L, afterBalance); - Assert.assertEquals(0, ByteArray.toInt(infoById.get().getContractResult(0).toByteArray())); - Assert.assertTrue(infoById.get().getReceipt().getEnergyUsageTotal() == 100000000); - - } - - - /** - * constructor. - */ - @AfterClass - - public void shutdown() throws InterruptedException { - if (channelFull != null) { - channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } - if (channelFull1 != null) { - channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } - if (channelSolidity != null) { - channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } - } -} diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant001.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant001.java index c21a920ff28..0f0a046c7de 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant001.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant001.java @@ -101,7 +101,7 @@ public void beforeClass() { String contractName = "testConstantContract"; HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + final String abi = retMap.get("abI").toString(); contractAddressNoAbi = PublicMethed.deployContract(contractName, "[]", code, "", maxFeeLimit, 0L, 100, null, contractExcKey, @@ -129,19 +129,6 @@ public void beforeClass() { @Test(enabled = true, description = "TriggerConstantContract a payable function without ABI") public void test01TriggerConstantContract() { - /*Account info; - - AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, - blockingStubFull); - info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); - logger.info("beforeBalance:" + beforeBalance); - logger.info("beforeEnergyUsed:" + beforeEnergyUsed); - logger.info("beforeNetUsed:" + beforeNetUsed); - logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed);*/ String txid = ""; TransactionExtention transactionExtention = PublicMethed @@ -164,37 +151,6 @@ public void test01TriggerConstantContract() { @Test(enabled = true, description = "TriggerConstantContract a non-payable function without ABI") public void test02TriggerConstantContract() { - /*Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TriggerConstant002.sol"; - String contractName = "testConstantContract"; - HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddressNoAbi = PublicMethed.deployContract(contractName, "[]", code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); - SmartContract smartContract = PublicMethed.getContract(contractAddressNoAbi, blockingStubFull); - Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); - Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); - Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); - Account info; - - AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, - blockingStubFull); - info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); - logger.info("beforeBalance:" + beforeBalance); - logger.info("beforeEnergyUsed:" + beforeEnergyUsed); - logger.info("beforeNetUsed:" + beforeNetUsed); - logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed);*/ TransactionExtention transactionExtention = PublicMethed .triggerConstantContractForExtention(contractAddressNoAbi, @@ -216,37 +172,7 @@ public void test02TriggerConstantContract() { @Test(enabled = true, description = "TriggerConstantContract a view function without ABI") public void test03TriggerConstantContract() { - /*Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TriggerConstant003.sol"; - String contractName = "testConstantContract"; - HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddressNoAbi = PublicMethed.deployContract(contractName, "[]", code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); - SmartContract smartContract = PublicMethed.getContract(contractAddressNoAbi, blockingStubFull); - Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); - Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); - Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); - Account info; - AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, - blockingStubFull); - info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); - logger.info("beforeBalance:" + beforeBalance); - logger.info("beforeEnergyUsed:" + beforeEnergyUsed); - logger.info("beforeNetUsed:" + beforeNetUsed); - logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed);*/ TransactionExtention transactionExtention = PublicMethed .triggerConstantContractForExtention(contractAddressNoAbi, @@ -268,37 +194,7 @@ public void test03TriggerConstantContract() { @Test(enabled = true, description = "TriggerConstantContract a pure function without ABI") public void test04TriggerConstantContract() { - /*Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TriggerConstant004.sol"; - String contractName = "testConstantContract"; - HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddressNoAbi = PublicMethed.deployContract(contractName, "[]", code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); - SmartContract smartContract = PublicMethed.getContract(contractAddressNoAbi, blockingStubFull); - Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); - Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); - Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); - Account info; - AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, - blockingStubFull); - info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); - logger.info("beforeBalance:" + beforeBalance); - logger.info("beforeEnergyUsed:" + beforeEnergyUsed); - logger.info("beforeNetUsed:" + beforeNetUsed); - logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed);*/ TransactionExtention transactionExtention = PublicMethed .triggerConstantContractForExtention(contractAddressNoAbi, @@ -322,38 +218,6 @@ public void test04TriggerConstantContract() { @Test(enabled = true, description = "TriggerConstantContract a payable function with ABI") public void test05TriggerConstantContract() { - /*Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TriggerConstant001.sol"; - String contractName = "testConstantContract"; - HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddressNoAbi = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); - SmartContract smartContract = PublicMethed.getContract(contractAddressNoAbi, blockingStubFull); - Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); - Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); - Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); - Account info; - - AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, - blockingStubFull); - info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); - logger.info("beforeBalance:" + beforeBalance); - logger.info("beforeEnergyUsed:" + beforeEnergyUsed); - logger.info("beforeNetUsed:" + beforeNetUsed); - logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed);*/ - String txid = ""; TransactionExtention transactionExtention = PublicMethed .triggerConstantContractForExtention(contractAddressNoAbi, @@ -374,37 +238,7 @@ public void test05TriggerConstantContract() { @Test(enabled = true, description = "TriggerConstantContract a non-payable function with ABI") public void test06TriggerConstantContract() { - /*Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TriggerConstant002.sol"; - String contractName = "testConstantContract"; - HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddressNoAbi = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); - SmartContract smartContract = PublicMethed.getContract(contractAddressNoAbi, blockingStubFull); - Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); - Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); - Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); - Account info; - AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, - blockingStubFull); - info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); - logger.info("beforeBalance:" + beforeBalance); - logger.info("beforeEnergyUsed:" + beforeEnergyUsed); - logger.info("beforeNetUsed:" + beforeNetUsed); - logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed);*/ TransactionExtention transactionExtention = PublicMethed .triggerConstantContractForExtention(contractAddressWithAbi, @@ -425,37 +259,6 @@ public void test06TriggerConstantContract() { @Test(enabled = true, description = "TriggerConstantContract a view function with ABI") public void test07TriggerConstantContract() { - /*Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TriggerConstant003.sol"; - String contractName = "testConstantContract"; - HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddressNoAbi = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); - SmartContract smartContract = PublicMethed.getContract(contractAddressNoAbi, blockingStubFull); - Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); - Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); - Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); - Account info; - - AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, - blockingStubFull); - info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); - logger.info("beforeBalance:" + beforeBalance); - logger.info("beforeEnergyUsed:" + beforeEnergyUsed); - logger.info("beforeNetUsed:" + beforeNetUsed); - logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed);*/ TransactionExtention transactionExtention = PublicMethed .triggerConstantContractForExtention(contractAddressWithAbi, @@ -479,37 +282,7 @@ public void test07TriggerConstantContract() { @Test(enabled = true, description = "TriggerConstantContract a pure function with ABI") public void test08TriggerConstantContract() { - /*Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TriggerConstant004.sol"; - String contractName = "testConstantContract"; - HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddressNoAbi = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); - SmartContract smartContract = PublicMethed.getContract(contractAddressNoAbi, blockingStubFull); - Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); - Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); - Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); - Account info; - AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, - blockingStubFull); - info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); - logger.info("beforeBalance:" + beforeBalance); - logger.info("beforeEnergyUsed:" + beforeEnergyUsed); - logger.info("beforeNetUsed:" + beforeNetUsed); - logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed);*/ TransactionExtention transactionExtention = PublicMethed .triggerConstantContractForExtention(contractAddressWithAbi, @@ -533,24 +306,6 @@ public void test08TriggerConstantContract() { @Test(enabled = true, description = "TriggerContract a payable function without ABI") public void test09TriggerContract() { - /*Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TriggerConstant001.sol"; - String contractName = "testConstantContract"; - HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddressNoAbi = PublicMethed.deployContract(contractName, "[]", code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); - SmartContract smartContract = PublicMethed.getContract(contractAddressNoAbi, blockingStubFull); - Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); - Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); - Assert.assertFalse(smartContract.getBytecode().toString().isEmpty());*/ Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -612,24 +367,6 @@ public void test09TriggerContract() { @Test(enabled = true, description = "TriggerContract a non-payable function without ABI") public void test10TriggerContract() { - /*Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TriggerConstant002.sol"; - String contractName = "testConstantContract"; - HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddressNoAbi = PublicMethed.deployContract(contractName, "[]", code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); - SmartContract smartContract = PublicMethed.getContract(contractAddressNoAbi, blockingStubFull); - Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); - Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); - Assert.assertFalse(smartContract.getBytecode().toString().isEmpty());*/ Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -691,24 +428,7 @@ public void test10TriggerContract() { @Test(enabled = true, description = "TriggerContract a view function without ABI") public void test11TriggerContract() { - /*Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TriggerConstant003.sol"; - String contractName = "testConstantContract"; - HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddressNoAbi = PublicMethed.deployContract(contractName, "[]", code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); - SmartContract smartContract = PublicMethed.getContract(contractAddressNoAbi, blockingStubFull); - Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); - Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); - Assert.assertFalse(smartContract.getBytecode().toString().isEmpty());*/ + Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -770,24 +490,7 @@ public void test11TriggerContract() { @Test(enabled = true, description = "TriggerContract a pure function without ABI") public void test12TriggerContract() { - /*Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TriggerConstant004.sol"; - String contractName = "testConstantContract"; - HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddressNoAbi = PublicMethed.deployContract(contractName, "[]", code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); - SmartContract smartContract = PublicMethed.getContract(contractAddressNoAbi, blockingStubFull); - Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); - Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); - Assert.assertFalse(smartContract.getBytecode().toString().isEmpty());*/ + Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -849,37 +552,7 @@ public void test12TriggerContract() { @Test(enabled = true, description = "TriggerContract a pure function with ABI") public void test18TriggerContract() { - /*Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TriggerConstant004.sol"; - String contractName = "testConstantContract"; - HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddressNoAbi = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); - SmartContract smartContract = PublicMethed.getContract(contractAddressNoAbi, blockingStubFull); - Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); - Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); - Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); - Account info; - AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, - blockingStubFull); - info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); - logger.info("beforeBalance:" + beforeBalance); - logger.info("beforeEnergyUsed:" + beforeEnergyUsed); - logger.info("beforeNetUsed:" + beforeNetUsed); - logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed);*/ TransactionExtention transactionExtention = PublicMethed .triggerContractForExtention(contractAddressWithAbi, "testPure()", "#", false, @@ -901,24 +574,7 @@ public void test18TriggerContract() { @Test(enabled = true, description = "TriggerContract a payable function with ABI") public void test19TriggerContract() { - /*Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TriggerConstant001.sol"; - String contractName = "testConstantContract"; - HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddressNoAbi = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); - SmartContract smartContract = PublicMethed.getContract(contractAddressNoAbi, blockingStubFull); - Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); - Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); - Assert.assertFalse(smartContract.getBytecode().toString().isEmpty());*/ + Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -978,24 +634,6 @@ public void test19TriggerContract() { @Test(enabled = true, description = "TriggerContract a non-payable function with ABI") public void test20TriggerContract() { - /*Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TriggerConstant002.sol"; - String contractName = "testConstantContract"; - HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddressNoAbi = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); - SmartContract smartContract = PublicMethed.getContract(contractAddressNoAbi, blockingStubFull); - Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); - Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); - Assert.assertFalse(smartContract.getBytecode().toString().isEmpty());*/ Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -1055,37 +693,7 @@ public void test20TriggerContract() { @Test(enabled = true, description = "TriggerContract a view function with ABI") public void test21TriggerContract() { - /*Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TriggerConstant003.sol"; - String contractName = "testConstantContract"; - HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddressNoAbi = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); - SmartContract smartContract = PublicMethed.getContract(contractAddressNoAbi, blockingStubFull); - Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); - Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); - Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); - Account info; - AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, - blockingStubFull); - info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); - logger.info("beforeBalance:" + beforeBalance); - logger.info("beforeEnergyUsed:" + beforeEnergyUsed); - logger.info("beforeNetUsed:" + beforeNetUsed); - logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed);*/ TransactionExtention transactionExtention = PublicMethed .triggerContractForExtention(contractAddressWithAbi, "testView()", "#", false, @@ -1108,37 +716,7 @@ public void test21TriggerContract() { @Test(enabled = true, description = "TriggerConstantContract a view method with ABI ,method has " + "revert()") public void test24TriggerConstantContract() { - /*Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TriggerConstant024.sol"; - String contractName = "testConstantContract"; - HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddressNoAbi = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); - SmartContract smartContract = PublicMethed.getContract(contractAddressNoAbi, blockingStubFull); - Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); - Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); - Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); - Account info; - AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, - blockingStubFull); - info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); - logger.info("beforeBalance:" + beforeBalance); - logger.info("beforeEnergyUsed:" + beforeEnergyUsed); - logger.info("beforeNetUsed:" + beforeNetUsed); - logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed);*/ TransactionExtention transactionExtention = PublicMethed .triggerConstantContractForExtention(contractAddressWithAbi, @@ -1166,37 +744,6 @@ public void test24TriggerConstantContract() { @Test(enabled = true, description = "TriggerContract a view method with ABI ,method has " + "revert()") public void test25TriggerContract() { - /*Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TriggerConstant024.sol"; - String contractName = "testConstantContract"; - HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddressNoAbi = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); - SmartContract smartContract = PublicMethed.getContract(contractAddressNoAbi, blockingStubFull); - Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); - Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); - Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); - Account info; - - AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, - blockingStubFull); - info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); - logger.info("beforeBalance:" + beforeBalance); - logger.info("beforeEnergyUsed:" + beforeEnergyUsed); - logger.info("beforeNetUsed:" + beforeNetUsed); - logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed);*/ TransactionExtention transactionExtention = PublicMethed .triggerContractForExtention(contractAddressWithAbi, @@ -1221,37 +768,7 @@ public void test25TriggerContract() { @Test(enabled = true, description = "TriggerConstantContract a view method without ABI,method has" + "revert()") public void testTriggerConstantContract() { - /*Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TriggerConstant004.sol"; - String contractName = "testConstantContract"; - HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddressNoAbi = PublicMethed.deployContract(contractName, "[]", code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); - SmartContract smartContract = PublicMethed.getContract(contractAddressNoAbi, blockingStubFull); - Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); - Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); - Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); - Account info; - AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, - blockingStubFull); - info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); - logger.info("beforeBalance:" + beforeBalance); - logger.info("beforeEnergyUsed:" + beforeEnergyUsed); - logger.info("beforeNetUsed:" + beforeNetUsed); - logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed);*/ TransactionExtention transactionExtention = PublicMethed .triggerConstantContractForExtention(contractAddressNoAbi, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant013.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant013.java index f557c7d8df5..f35c7b4c86b 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant013.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant013.java @@ -213,80 +213,7 @@ public void test01TriggerContract() { @Test(enabled = true, description = "TriggerConstantContract a constant function " + "created by create2") public void test15TriggerConstantContract() { - /*Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/TriggerConstant015.sol"; - String contractName = "Factory"; - HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); - - Account info; - - AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, - blockingStubFull); - info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); - logger.info("beforeBalance:" + beforeBalance); - logger.info("beforeEnergyUsed:" + beforeEnergyUsed); - logger.info("beforeNetUsed:" + beforeNetUsed); - logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - - String contractName1 = "TestConstract"; - HashMap retMap1 = PublicMethed.getBycodeAbi(filePath, contractName1); - String code1 = retMap1.get("byteCode").toString(); - String abi1 = retMap1.get("abI").toString(); - String txid = ""; - String num = "\"" + code1 + "\"" + "," + 1; - txid = PublicMethed - .triggerContract(contractAddress, - "deploy(bytes,uint256)", num, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - - PublicMethed.waitProduceNextBlock(blockingStubFull); - Optional infoById = null; - infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); - long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); - - logger.info("fee:" + fee); - logger.info("netUsed:" + netUsed); - logger.info("energyUsed:" + energyUsed); - logger.info("netFee:" + netFee); - logger.info("energyUsageTotal:" + energyUsageTotal); - Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); - logger.info("afterBalance:" + afterBalance); - logger.info("afterEnergyUsed:" + afterEnergyUsed); - logger.info("afterNetUsed:" + afterNetUsed); - logger.info("afterFreeNetUsed:" + afterFreeNetUsed); - - Assert.assertTrue(infoById.get().getResultValue() == 0); - Assert.assertTrue(afterBalance + fee == beforeBalance); - Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); - Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); - Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - byte[] returnAddressBytes = infoById.get().getInternalTransactions(0).getTransferToAddress() - .toByteArray();*/ SmartContract smartContract = PublicMethed.getContract(returnAddressBytes, blockingStubFull); Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant014.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant014.java index 14954d61070..c35d9eea84d 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant014.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant014.java @@ -212,81 +212,7 @@ public void test01TriggerContract() { @Test(enabled = true, description = "TriggerConstantContract a non-constant function " + "created by create2") public void test16TriggerConstantContract() { - // TriggerConstant016.java - /*Assert.assertTrue(PublicMethed - .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/ClearAbi005.sol"; - String contractName = "Factory"; - HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); - - Account info; - - AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, - blockingStubFull); - info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); - Long beforeBalance = info.getBalance(); - Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); - Long beforeNetUsed = resourceInfo.getNetUsed(); - Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); - logger.info("beforeBalance:" + beforeBalance); - logger.info("beforeEnergyUsed:" + beforeEnergyUsed); - logger.info("beforeNetUsed:" + beforeNetUsed); - logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); - - String contractName1 = "TestConstract"; - HashMap retMap1 = PublicMethed.getBycodeAbi(filePath, contractName1); - String code1 = retMap1.get("byteCode").toString(); - String abi1 = retMap1.get("abI").toString(); - String txid = ""; - String num = "\"" + code1 + "\"" + "," + 1; - txid = PublicMethed - .triggerContract(contractAddress, - "deploy(bytes,uint256)", num, false, - 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - - PublicMethed.waitProduceNextBlock(blockingStubFull); - Optional infoById = null; - infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); - Long fee = infoById.get().getFee(); - Long netUsed = infoById.get().getReceipt().getNetUsage(); - Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); - Long netFee = infoById.get().getReceipt().getNetFee(); - long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); - - logger.info("fee:" + fee); - logger.info("netUsed:" + netUsed); - logger.info("energyUsed:" + energyUsed); - logger.info("netFee:" + netFee); - logger.info("energyUsageTotal:" + energyUsageTotal); - Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); - AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, - blockingStubFull); - Long afterBalance = infoafter.getBalance(); - Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); - Long afterNetUsed = resourceInfoafter.getNetUsed(); - Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); - logger.info("afterBalance:" + afterBalance); - logger.info("afterEnergyUsed:" + afterEnergyUsed); - logger.info("afterNetUsed:" + afterNetUsed); - logger.info("afterFreeNetUsed:" + afterFreeNetUsed); - - Assert.assertTrue(infoById.get().getResultValue() == 0); - Assert.assertTrue(afterBalance + fee == beforeBalance); - Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); - Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); - Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); - byte[] returnAddressBytes = infoById.get().getInternalTransactions(0).getTransferToAddress() - .toByteArray();*/ String returnAddress = Base58.encode58Check(returnAddressBytes); logger.info("returnAddress:" + returnAddress); TransactionExtention transactionExtention = PublicMethed From a08f0359faa7cfb19b03334350d791897e7f0065 Mon Sep 17 00:00:00 2001 From: wangming Date: Thu, 13 Jun 2019 15:46:55 +0800 Subject: [PATCH 63/90] modify config --- .circleci/config.yml | 2 +- .gitignore | 4 +- .../soliditycode/create2contract22.sol | 39 +++++++ .../resources/soliditycode/extCodeHash11.sol | 103 ++++++++++++++++++ 4 files changed, 145 insertions(+), 3 deletions(-) create mode 100644 src/test/resources/soliditycode/extCodeHash11.sol diff --git a/.circleci/config.yml b/.circleci/config.yml index e02044408b6..74940a5a754 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -14,7 +14,7 @@ jobs: - checkout - run: name: multi_os_result - command: curl http://60.205.215.34/Daily_Build_Task_Report + command: echo "curl http://60.205.215.34/multi_os_result" # # - run: # name: Daily Build Report diff --git a/.gitignore b/.gitignore index 3580691939b..9ba22fd1b58 100644 --- a/.gitignore +++ b/.gitignore @@ -51,7 +51,7 @@ src/main/resources/META-INF/ /output_witness/ output* nodeId.properties - +Wallet # vm_trace -/vm_trace/ +/vm_trace/ \ No newline at end of file diff --git a/src/test/resources/soliditycode/create2contract22.sol b/src/test/resources/soliditycode/create2contract22.sol index 3fc6a81faec..c33cb08edc3 100644 --- a/src/test/resources/soliditycode/create2contract22.sol +++ b/src/test/resources/soliditycode/create2contract22.sol @@ -68,3 +68,42 @@ contract TestConstract { selfdestruct(nonexistentTarget); } } + +contract TestConstract1 { + uint public i=2; + function testTransfer(uint256 i) payable public{ + msg.sender.transfer(i); + } + function testTransferToken(uint256 i,trcToken tokenId) payable public{ + msg.sender.transferToken(i, tokenId); + } + function testSuicideNonexistentTarget(address payable nonexistentTarget) payable public { + selfdestruct(nonexistentTarget); + } +} + +contract TestConstract2 { + uint public i=3; + function testTransfer(uint256 i) payable public{ + msg.sender.transfer(i); + } + function testTransferToken(uint256 i,trcToken tokenId) payable public{ + msg.sender.transferToken(i, tokenId); + } + function testSuicideNonexistentTarget(address payable nonexistentTarget) payable public { + selfdestruct(nonexistentTarget); + } +} + +contract TestConstract3 { + uint public i=4; + function testTransfer(uint256 i) payable public{ + msg.sender.transfer(i); + } + function testTransferToken(uint256 i,trcToken tokenId) payable public{ + msg.sender.transferToken(i, tokenId); + } + function testSuicideNonexistentTarget(address payable nonexistentTarget) payable public { + selfdestruct(nonexistentTarget); + } +} \ No newline at end of file diff --git a/src/test/resources/soliditycode/extCodeHash11.sol b/src/test/resources/soliditycode/extCodeHash11.sol new file mode 100644 index 00000000000..ad59f6cce1c --- /dev/null +++ b/src/test/resources/soliditycode/extCodeHash11.sol @@ -0,0 +1,103 @@ +contract Counter { +uint count = 0; +address payable owner; +event LogResult(bytes32 _hashBefore, bytes32 _hashAfter); +constructor() public{ +owner = msg.sender; +} +function getCodeHashByAddr() public returns (bytes32 _hashBefore, bytes32 _hashAfter) { +address addr = address(this); +assembly { +_hashBefore := extcodehash(addr) +} +if (owner == msg.sender) { +selfdestruct(owner); +} +assembly { +_hashAfter := extcodehash(addr) +} +revert(); +emit LogResult(_hashBefore, _hashAfter); +} +} + +contract Counter1 { +uint count = 0; +address payable owner; +event LogResult(bytes32 _hashBefore, bytes32 _hashAfter); +constructor() public{ +owner = msg.sender; +} +function getCodeHashByAddr() public returns (bytes32 _hashBefore, bytes32 _hashAfter) { +address addr = address(this); +assembly { +_hashBefore := extcodehash(addr) +} +if (owner == msg.sender) { +selfdestruct(owner); +} +assembly { +_hashAfter := extcodehash(addr) +} + +emit LogResult(_hashBefore, _hashAfter); +} +} + + +contract Counter2 { +uint count = 0; +address payable owner; +event LogResult(bytes32 _hashBefore, bytes32 _hashAfter); +constructor() public{ +owner = msg.sender; +} +function getCodeHashByAddr(address c) public returns (bytes32 _hashBefore, bytes32 _hashAfter) { + TestConstract t=new TestConstract(); +address addr = address(t); +assembly { +_hashBefore := extcodehash(addr) +} + addr.call(abi.encodeWithSignature("testSuicideNonexistentTarget(address)",c)); + + +assembly { +_hashAfter := extcodehash(addr) +} + +emit LogResult(_hashBefore, _hashAfter); +} +} + + +contract Counter3 { +uint count = 0; +address payable owner; +event LogResult(bytes32 _hashBefore, bytes32 _hashAfter); +constructor() public{ +owner = msg.sender; +} +function getCodeHashByAddr(address c) public returns (bytes32 _hashBefore, bytes32 _hashAfter) { + TestConstract t=new TestConstract(); +address addr = address(t); +assembly { +_hashBefore := extcodehash(addr) +} +if (owner == msg.sender) { +selfdestruct(owner); +} + +assembly { +_hashAfter := extcodehash(addr) +} + +emit LogResult(_hashBefore, _hashAfter); +} +} + +contract TestConstract { + uint public i=1; + function testSuicideNonexistentTarget(address payable nonexistentTarget) payable public { + selfdestruct(nonexistentTarget); + } +} \ No newline at end of file From 5744c3802e45bde3f382db46c57eaa68b97fb27c Mon Sep 17 00:00:00 2001 From: wangming Date: Thu, 13 Jun 2019 15:58:16 +0800 Subject: [PATCH 64/90] add httpClearABIcontract testcase --- .../http/HttpTestClearABIContract001.java | 167 ++++++++++++++++++ 1 file changed, 167 insertions(+) create mode 100644 src/test/java/stest/tron/wallet/dailybuild/http/HttpTestClearABIContract001.java diff --git a/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestClearABIContract001.java b/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestClearABIContract001.java new file mode 100644 index 00000000000..004b273b3f7 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestClearABIContract001.java @@ -0,0 +1,167 @@ +package stest.tron.wallet.dailybuild.http; + +import static org.hamcrest.core.StringContains.containsString; + +import com.alibaba.fastjson.JSONObject; +import java.util.HashMap; +import lombok.extern.slf4j.Slf4j; +import org.apache.http.HttpResponse; +import org.junit.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.Test; +import org.tron.common.crypto.ECKey; +import org.tron.common.utils.ByteArray; +import org.tron.common.utils.Utils; +import stest.tron.wallet.common.client.Configuration; +import stest.tron.wallet.common.client.utils.HttpMethed; +import stest.tron.wallet.common.client.utils.PublicMethed; + +@Slf4j +public class HttpTestClearABIContract001 { + + private final String testKey002 = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key1"); + private final byte[] fromAddress = PublicMethed.getFinalAddress(testKey002); + private JSONObject responseContent; + private HttpResponse response; + private String httpnode = Configuration.getByPath("testng.conf").getStringList("httpnode.ip.list") + .get(0); + + ECKey ecKey2 = new ECKey(Utils.getRandom()); + byte[] assetOwnerAddress = ecKey2.getAddress(); + String assetOwnerKey = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); + String contractAddress; + String abi; + Long amount = 2048000000L; + + String description = Configuration.getByPath("testng.conf") + .getString("defaultParameter.assetDescription"); + String url = Configuration.getByPath("testng.conf") + .getString("defaultParameter.assetUrl"); + private static final long now = System.currentTimeMillis(); + private static String name = "testAssetIssue002_" + Long.toString(now); + private static final long totalSupply = now; + private static String assetIssueId; + private static String contractName; + + + /** + * constructor. + */ + @Test(enabled = true, description = "Deploy smart contract by http") + public void test1DeployContract() { + PublicMethed.printAddress(assetOwnerKey); + HttpMethed.waitToProduceOneBlock(httpnode); + response = HttpMethed.sendCoin(httpnode, fromAddress, assetOwnerAddress, amount, testKey002); + Assert.assertTrue(HttpMethed.verificationResult(response)); + HttpMethed.waitToProduceOneBlock(httpnode); + + response = HttpMethed.getAccount(httpnode, assetOwnerAddress); + responseContent = HttpMethed.parseResponseContent(response); + HttpMethed.printJsonContent(responseContent); + + String filePath = "src/test/resources/soliditycode/TriggerConstant003.sol"; + contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + abi = retMap.get("abI").toString(); + logger.info("abi:" + abi); + logger.info("code:" + code); + + String txid = HttpMethed.deployContractGetTxid(httpnode, contractName, abi, code, 1000000L, + 1000000000L, 100, 11111111111111L, + 0L, 0, 0L, assetOwnerAddress, assetOwnerKey); + + HttpMethed.waitToProduceOneBlock(httpnode); + logger.info(txid); + response = HttpMethed.getTransactionById(httpnode, txid); + responseContent = HttpMethed.parseResponseContent(response); + HttpMethed.printJsonContent(responseContent); + Assert.assertTrue(!responseContent.getString("contract_address").isEmpty()); + contractAddress = responseContent.getString("contract_address"); + + response = HttpMethed.getTransactionInfoById(httpnode, txid); + responseContent = HttpMethed.parseResponseContent(response); + String receiptString = responseContent.getString("receipt"); + Assert + .assertEquals(HttpMethed.parseStringContent(receiptString).getString("result"), "SUCCESS"); + } + + /** + * constructor. + */ + @Test(enabled = true, description = "Get contract by http") + public void test2GetContract() { + response = HttpMethed.getContract(httpnode, contractAddress); + responseContent = HttpMethed.parseResponseContent(response); + HttpMethed.printJsonContent(responseContent); + Assert.assertEquals(responseContent.getString("consume_user_resource_percent"), "100"); + Assert.assertEquals(responseContent.getString("contract_address"), contractAddress); + Assert.assertEquals(responseContent.getString("origin_address"), + ByteArray.toHexString(assetOwnerAddress)); + Assert + .assertThat(responseContent.getString("abi") + , containsString("testView")); + + Assert.assertEquals(responseContent.getString("origin_energy_limit"), "11111111111111"); + Assert.assertEquals(responseContent.getString("name"), contractName); + } + + /** + * constructor. + */ + @Test(enabled = true, description = "Trigger contract by http") + public void test3TriggerConstantContract() { + + HttpResponse httpResponse = HttpMethed + .triggerConstantContract(httpnode, assetOwnerAddress, contractAddress, + "testView()", + ""); + + responseContent = HttpMethed.parseResponseContent(httpResponse); + HttpMethed.printJsonContent(responseContent); + Assert.assertEquals(responseContent.getString("result"), "{\"result\":true}"); + Assert.assertEquals(responseContent.getString("constant_result"), + "[\"0000000000000000000000000000000000000000000000000000000000000001\"]"); + } + + /** + * constructor. + */ + @Test(enabled = true, description = "Trigger contract by http") + public void test4ClearABIContract() { + + HttpResponse httpResponse = HttpMethed + .clearABiGetTxid(httpnode, assetOwnerAddress, contractAddress, assetOwnerKey); + + responseContent = HttpMethed.parseResponseContent(httpResponse); + HttpMethed.printJsonContent(responseContent); + Assert.assertEquals(responseContent.getString("result"), "true"); + + } + + /** + * constructor. + */ + @Test(enabled = true, description = "Get contract by http") + public void test5GetContract() { + response = HttpMethed.getContract(httpnode, contractAddress); + responseContent = HttpMethed.parseResponseContent(response); + HttpMethed.printJsonContent(responseContent); + Assert.assertEquals(responseContent.getString("consume_user_resource_percent"), "100"); + Assert.assertEquals(responseContent.getString("contract_address"), contractAddress); + Assert.assertEquals(responseContent.getString("origin_address"), + ByteArray.toHexString(assetOwnerAddress)); + Assert.assertEquals(responseContent.getString("abi"), "{}"); + Assert.assertEquals(responseContent.getString("origin_energy_limit"), "11111111111111"); + Assert.assertEquals(responseContent.getString("name"), contractName); + } + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + HttpMethed.disConnect(); + } +} From 7fb23873a7e211cb796907748c219b1143148865 Mon Sep 17 00:00:00 2001 From: wubin01 Date: Thu, 13 Jun 2019 17:24:25 +0800 Subject: [PATCH 65/90] modify sync logic --- .../tron/core/net/service/SyncService.java | 42 ++++++++++--------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/tron/core/net/service/SyncService.java b/src/main/java/org/tron/core/net/service/SyncService.java index 6168a2a808d..775e25943e9 100644 --- a/src/main/java/org/tron/core/net/service/SyncService.java +++ b/src/main/java/org/tron/core/net/service/SyncService.java @@ -230,26 +230,28 @@ private synchronized void handleSyncBlock() { isProcessed[0] = false; - blockWaitToProcess.forEach((msg, peerConnection) -> { - if (peerConnection.isDisconnect()) { - blockWaitToProcess.remove(msg); - invalid(msg.getBlockId()); - return; - } - final boolean[] isFound = {false}; - tronNetDelegate.getActivePeer().stream() - .filter(peer -> msg.getBlockId().equals(peer.getSyncBlockToFetch().peek())) - .forEach(peer -> { - peer.getSyncBlockToFetch().pop(); - peer.getSyncBlockInProcess().add(msg.getBlockId()); - isFound[0] = true; - }); - if (isFound[0]) { - blockWaitToProcess.remove(msg); - isProcessed[0] = true; - processSyncBlock(msg.getBlockCapsule()); - } - }); + synchronized (tronNetDelegate.getBlockLock()) { + blockWaitToProcess.forEach((msg, peerConnection) -> { + if (peerConnection.isDisconnect()) { + blockWaitToProcess.remove(msg); + invalid(msg.getBlockId()); + return; + } + final boolean[] isFound = {false}; + tronNetDelegate.getActivePeer().stream() + .filter(peer -> msg.getBlockId().equals(peer.getSyncBlockToFetch().peek())) + .forEach(peer -> { + peer.getSyncBlockToFetch().pop(); + peer.getSyncBlockInProcess().add(msg.getBlockId()); + isFound[0] = true; + }); + if (isFound[0]) { + blockWaitToProcess.remove(msg); + isProcessed[0] = true; + processSyncBlock(msg.getBlockCapsule()); + } + }); + } } } From 8ea8a614818f422cfa0c2955c025972fe38b0813 Mon Sep 17 00:00:00 2001 From: wangming Date: Fri, 14 Jun 2019 11:06:56 +0800 Subject: [PATCH 66/90] modify testcase --- .../dailybuild/trctoken/ContractTrcToken014.java | 8 ++++---- .../dailybuild/trctoken/ContractTrcToken064.java | 11 ++++++----- .../dailybuild/trctoken/ContractTrcToken075.java | 12 ++++-------- .../dailybuild/trctoken/ContractTrcToken076.java | 3 ++- .../dailybuild/trctoken/ContractTrcToken077.java | 1 + .../dailybuild/trctoken/ContractTrcToken078.java | 5 +++-- .../tvmnewcommand/create2/Create2Test020.java | 6 ++++++ .../extCodeHash/ExtCodeHashTest001.java | 2 +- .../extCodeHash/ExtCodeHashTest007.java | 16 +++++++++++----- .../extCodeHash/ExtCodeHashTest011.java | 5 +++++ .../shiftcommand/ShiftCommand001.java | 5 +++++ .../transferfailed/TransferFailed001.java | 1 + 12 files changed, 49 insertions(+), 26 deletions(-) diff --git a/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken014.java b/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken014.java index e36aa099385..2b99381852e 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken014.java +++ b/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken014.java @@ -456,7 +456,7 @@ public void test03TriggerContract() { "transferTokenTest(address,uint256,trcToken)", param, false, 0, 1000000000L, assetAccountId.toStringUtf8(), 2, user001Address, user001Key, blockingStubFull); - + PublicMethed.waitProduceNextBlock(blockingStubFull); infoById = PublicMethed .getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() != 0); @@ -480,7 +480,7 @@ public void test03TriggerContract() { "transferTokenTest(address,uint256,trcToken)", param, false, 0, 1000000000L, assetAccountId.toStringUtf8(), 2, user001Address, user001Key, blockingStubFull); - + PublicMethed.waitProduceNextBlock(blockingStubFull); infoById = PublicMethed .getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() != 0); @@ -504,7 +504,7 @@ public void test03TriggerContract() { "transferTokenTest(address,uint256,trcToken)", param, false, 0, 1000000000L, assetAccountId.toStringUtf8(), 2, user001Address, user001Key, blockingStubFull); - + PublicMethed.waitProduceNextBlock(blockingStubFull); infoById = PublicMethed .getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() != 0); @@ -551,7 +551,7 @@ public void test03TriggerContract() { "transferTokenTest(address,uint256,trcToken)", param, false, callValue, 1000000000L, assetAccountId.toStringUtf8(), 2, user001Address, user001Key, blockingStubFull); - + PublicMethed.waitProduceNextBlock(blockingStubFull); infoById = PublicMethed .getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() != 0); diff --git a/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken064.java b/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken064.java index bd109f0933a..095fd394072 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken064.java +++ b/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken064.java @@ -98,7 +98,6 @@ public void test01DeployTransferTokenContract() { ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; @@ -341,6 +340,7 @@ public void test03TriggerContract() { 1000000000L, assetAccountId.toStringUtf8(), 2, user001Address, user001Key, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); infoById = PublicMethed .getTransactionInfoById(triggerTxid, blockingStubFull); @@ -360,7 +360,7 @@ public void test03TriggerContract() { "transferTokenTest(address,uint256,trcToken)", param, false, callValue, 1000000000L, assetAccountId.toStringUtf8(), 2, user001Address, user001Key, blockingStubFull); - + PublicMethed.waitProduceNextBlock(blockingStubFull); infoById = PublicMethed .getTransactionInfoById(triggerTxid, blockingStubFull); @@ -380,7 +380,7 @@ public void test03TriggerContract() { "transferTokenTest(address,uint256,trcToken)", param, false, callValue, 1000000000L, assetAccountId.toStringUtf8(), 2, user001Address, user001Key, blockingStubFull); - + PublicMethed.waitProduceNextBlock(blockingStubFull); infoById = PublicMethed .getTransactionInfoById(triggerTxid, blockingStubFull); @@ -400,7 +400,7 @@ public void test03TriggerContract() { "transferTokenTest(address,uint256,trcToken)", param, false, callValue, 1000000000L, assetAccountId.toStringUtf8(), 2, user001Address, user001Key, blockingStubFull); - + PublicMethed.waitProduceNextBlock(blockingStubFull); infoById = PublicMethed .getTransactionInfoById(triggerTxid, blockingStubFull); @@ -417,7 +417,7 @@ public void test03TriggerContract() { "transferTokenTestValueMaxLong(address)", param, false, callValue, 1000000000L, assetAccountId.toStringUtf8(), 2, user001Address, user001Key, blockingStubFull); - + PublicMethed.waitProduceNextBlock(blockingStubFull); infoById = PublicMethed .getTransactionInfoById(triggerTxid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() != 0); @@ -433,6 +433,7 @@ public void test03TriggerContract() { "transferTokenTestValueMaxLong(address)", param, false, callValue, 1000000000L, assetAccountId.toStringUtf8(), 2, user001Address, user001Key, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); infoById = PublicMethed .getTransactionInfoById(triggerTxid, blockingStubFull); diff --git a/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken075.java b/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken075.java index 642f990f254..4a9a9d4ce0b 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken075.java +++ b/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken075.java @@ -88,7 +88,6 @@ public void testTokenBalanceContract() { Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, 10_000_000L, 0, 0, ByteString.copyFrom(dev001Address), testKey002, blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); long start = System.currentTimeMillis() + 2000; long end = System.currentTimeMillis() + 1000000000; @@ -200,7 +199,6 @@ public void testTokenBalanceContract() { Assert.assertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8()); - PublicMethed.waitProduceNextBlock(blockingStubFull); tokenId = Long.toString(0); triggerTxid = PublicMethed.triggerContract(transferTokenContractAddress, @@ -217,7 +215,6 @@ public void testTokenBalanceContract() { Assert.assertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8()); - PublicMethed.waitProduceNextBlock(blockingStubFull); tokenId = Long.toString(-1); @@ -225,24 +222,24 @@ public void testTokenBalanceContract() { "getToken(trcToken)", tokenId, false, 0, 1000000000L, "0", 0, dev001Address, dev001Key, blockingStubFull); - + PublicMethed.waitProduceNextBlock(blockingStubFull); infoById = PublicMethed .getTransactionInfoById(triggerTxid, blockingStubFull); logger.info("Trigger energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() != 0); Assert.assertEquals(FAILED, infoById.get().getResult()); Assert.assertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8()); - PublicMethed.waitProduceNextBlock(blockingStubFull); tokenId = Long.toString(Long.MIN_VALUE); triggerTxid = PublicMethed.triggerContract(transferTokenContractAddress, "getToken(trcToken)", tokenId, false, 0, 1000000000L, "0", 0, dev001Address, dev001Key, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + infoById = PublicMethed .getTransactionInfoById(triggerTxid, blockingStubFull); logger.info("Trigger energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); @@ -252,12 +249,12 @@ public void testTokenBalanceContract() { Assert.assertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8()); - PublicMethed.waitProduceNextBlock(blockingStubFull); triggerTxid = PublicMethed.triggerContract(transferTokenContractAddress, "getTokenLongMin()", "#", false, 0, 1000000000L, "0", 0, dev001Address, dev001Key, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); infoById = PublicMethed .getTransactionInfoById(triggerTxid, blockingStubFull); @@ -268,7 +265,6 @@ public void testTokenBalanceContract() { Assert.assertEquals("REVERT opcode executed", infoById.get().getResMessage().toStringUtf8()); - PublicMethed.waitProduceNextBlock(blockingStubFull); triggerTxid = PublicMethed.triggerContract(transferTokenContractAddress, "getTokenLongMax()", "#", false, 0, diff --git a/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken076.java b/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken076.java index a29c4721113..1735f9b604c 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken076.java +++ b/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken076.java @@ -91,13 +91,14 @@ public void testDeployTransferTokenContract() { .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, testKeyForGrammarAddress, grammarAddress, blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); Optional infoById = PublicMethed .getTransactionInfoById(txid, blockingStubFull); logger.info("Deploy energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); contractAddress = infoById.get().getContractAddress().toByteArray(); - PublicMethed.waitProduceNextBlock(blockingStubFull); PublicMethed.triggerContract(contractAddress, "test()", "#", false, 0, maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull); diff --git a/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken077.java b/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken077.java index 91e263ee75b..79291236b95 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken077.java +++ b/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken077.java @@ -136,6 +136,7 @@ public void testAddress002() { "addressTest()", "#", false, 0, maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); diff --git a/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken078.java b/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken078.java index b1bb16de8f6..4a5bfa91ada 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken078.java +++ b/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken078.java @@ -117,13 +117,13 @@ public void testOriginCall001() { .deployContractAndGetTransactionInfoById(contractName1, abi1, code1, "", maxFeeLimit, 1000000L, 100, null, testKeyForinternalTxsAddress, internalTxsAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); infoById = PublicMethed .getTransactionInfoById(txid, blockingStubFull); logger.info("infoById : " + infoById); byte[] contractAddress1; contractAddress1 = infoById.get().getContractAddress().toByteArray(); - PublicMethed.waitProduceNextBlock(blockingStubFull); String filePath2 = "./src/test/resources/soliditycode/contractTrcToken078.sol"; String contractName2 = "c"; @@ -151,6 +151,7 @@ public void testOriginCall001() { "sendToB2(address,address)", initParmes, false, 0, maxFeeLimit, internalTxsAddress, testKeyForinternalTxsAddress, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById2 = null; infoById2 = PublicMethed.getTransactionInfoById(txid2, blockingStubFull); logger.info("Trigger InfobyId: " + infoById2); @@ -182,12 +183,12 @@ public void testOriginDelegatecall001() { .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, 1000000L, 100, null, testKeyForinternalTxsAddress, internalTxsAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); Optional infoById = PublicMethed .getTransactionInfoById(txid, blockingStubFull); logger.info("infoById : " + infoById); contractAddress = infoById.get().getContractAddress().toByteArray(); - PublicMethed.waitProduceNextBlock(blockingStubFull); String filePath1 = "./src/test/resources/soliditycode/contractTrcToken078.sol"; String contractName1 = "calledContract"; HashMap retMap1 = PublicMethed.getBycodeAbi(filePath1, contractName1); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test020.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test020.java index cf474fe87d6..849177628fe 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test020.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test020.java @@ -633,6 +633,8 @@ public void testTriggerContract4() { .triggerContract(contractAddress, "deploy3(bytes,string)", num, false, 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById2 = null; infoById2 = PublicMethed.getTransactionInfoById(txid, blockingStubFull); @@ -754,6 +756,8 @@ public void testTriggerContract5() { .triggerContract(contractAddress, "deploy3(bytes,string)", num, false, 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById2 = null; infoById2 = PublicMethed.getTransactionInfoById(txid, blockingStubFull); @@ -877,6 +881,8 @@ public void testTriggerContract6() { .triggerContract(contractAddress, "deploy3(bytes,string)", num, false, 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById2 = null; infoById2 = PublicMethed.getTransactionInfoById(txid, blockingStubFull); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest001.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest001.java index 42e2228a20a..60ec980a7fb 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest001.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest001.java @@ -402,11 +402,11 @@ public void test05ActiveAccountGetCodeHash() { Assert.assertTrue(PublicMethed.sendcoin(testAddress, 1000000, fromAddress, testKey002, blockingStubFull)); - Assert.assertTrue(PublicMethed.freezeBalanceForReceiver(fromAddress, PublicMethed.getFreezeBalanceCount(user001Address, user001Key, 50000L, blockingStubFull), 0, 1, ByteString.copyFrom(user001Address), testKey002, blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); AccountResourceMessage accountResource = PublicMethed.getAccountResource(dev001Address, blockingStubFull); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest007.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest007.java index de855a02eb3..2104e0c6996 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest007.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest007.java @@ -171,12 +171,18 @@ public void test02DeployTestContractNew() { logger.info("before energyUsage is " + Long.toString(energyUsage)); logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - String filePath = "./src/test/resources/soliditycode/extCodeHashTestNoPayable.sol"; String contractName = "testConstantContract"; - HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); - - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String code = "608060405234801561001057600080fd5b50d3801561001d57600080fd5b50d2801561002a5760" + + "0080fd5b5060c5806100396000396000f3fe6080604052348015600f57600080fd5b50d38015601b576000" + + "80fd5b50d28015602757600080fd5b50600436106066577c01000000000000000000000000000000000000" + + "000000000000000000006000350463c518aa0f8114606b578063e5aa3d58146083575b600080fd5b607160" + + "89565b60408051918252519081900360200190f35b60716093565b6001600081905590565b6000548156fe" + + "a165627a7a723058205c5aadfbd06ea264db7b73e7b7f3c36ac64a9d520ba46b4bc7f1dc56252f17ac0029"; + String abi = "[{\"constant\":false,\"inputs\":[],\"name\":\"testNoPayable\",\"outputs\":[{\"" + + "name\":\"z\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable" + + "\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"i\",\"outputs\":" + + "[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"" + + "type\":\"function\"}]"; final String transferTokenTxid = PublicMethed .deployContractAndGetTransactionInfoById(contractName, abi, code, "", diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest011.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest011.java index a0c92c51f72..28c5fe7bde5 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest011.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest011.java @@ -128,6 +128,7 @@ public void test01DeployExtCodeHashContract() { "getCodeHashByAddr()", "#", false, 0, 1000000000L, "0", 0, user001Address, user001Key, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); infoById = PublicMethed .getTransactionInfoById(transferTokenTxid, blockingStubFull); @@ -190,6 +191,8 @@ public void test01DeployExtCodeHashContract1() { "getCodeHashByAddr()", "#", false, 0, 1000000000L, "0", 0, user001Address, user001Key, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + infoById = PublicMethed .getTransactionInfoById(transferTokenTxid, blockingStubFull); @@ -266,6 +269,7 @@ public void test01DeployExtCodeHashContract2() { "getCodeHashByAddr(address)", num, false, 0, 1000000000L, "0", 0, user001Address, user001Key, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); infoById = PublicMethed .getTransactionInfoById(transferTokenTxid, blockingStubFull); @@ -335,6 +339,7 @@ public void test01DeployExtCodeHashContract3() { 1000000000L, "0", 0, user001Address, user001Key, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); infoById = PublicMethed .getTransactionInfoById(transferTokenTxid, blockingStubFull); infoById = PublicMethed diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand001.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand001.java index 5e46c41ff4c..5362d481943 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand001.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/shiftcommand/ShiftCommand001.java @@ -122,6 +122,7 @@ public void test1OldInstruction() { txid = PublicMethed.triggerContract(contractAddress, "binaryMoveR(int256)", num, false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + Optional infoById = null; PublicMethed.waitProduceNextBlock(blockingStubFull); infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); @@ -156,6 +157,8 @@ public void test1OldInstruction() { txid = PublicMethed.triggerContract(contractAddress, "binaryLiftR(int256)", num, false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); @@ -228,12 +231,14 @@ public void test2NewInstruction() { txid = PublicMethed.triggerContract(contractAddress, "shlTest(uint256,uint256)", num, false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); Assert.assertEquals(10,ByteArray.toInt(infoById.get().getContractResult(0).toByteArray())); txid = PublicMethed.triggerContract(contractAddress, "shrTest(uint256,uint256)", num, false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); Assert.assertEquals(2,ByteArray.toInt(infoById.get().getContractResult(0).toByteArray())); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed001.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed001.java index a69f1951aff..d18552a67e0 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed001.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed001.java @@ -193,6 +193,7 @@ public void test2TransferEnough() { 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); Optional infoById = null; PublicMethed.waitProduceNextBlock(blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); Long fee = infoById.get().getFee(); Long netUsed = infoById.get().getReceipt().getNetUsage(); From 671d336dbdcec0ed22e5b92b54756de133c75b09 Mon Sep 17 00:00:00 2001 From: wangming Date: Fri, 14 Jun 2019 12:01:50 +0800 Subject: [PATCH 67/90] modify checkstyle --- .../common/client/utils/PublicMethed.java | 60 +++++++++++-------- .../client/utils/PublicMethedForMutiSign.java | 2 +- ....java => HttpTestClearAbiContract001.java} | 8 +-- .../WalletTestMutiSign018.java | 6 +- .../tvmnewcommand/clearabi/ClearAbi001.java | 16 ++--- .../tvmnewcommand/clearabi/ClearAbi002.java | 2 +- .../tvmnewcommand/clearabi/ClearAbi003.java | 2 +- .../tvmnewcommand/clearabi/ClearAbi004.java | 2 +- .../tvmnewcommand/clearabi/ClearAbi005.java | 2 +- .../tvmnewcommand/clearabi/ClearAbi006.java | 2 +- .../tvmnewcommand/clearabi/ClearAbi007.java | 4 +- .../tvmnewcommand/clearabi/ClearAbi008.java | 4 +- .../triggerconstant/TriggerConstant017.java | 2 +- 13 files changed, 61 insertions(+), 51 deletions(-) rename src/test/java/stest/tron/wallet/dailybuild/http/{HttpTestClearABIContract001.java => HttpTestClearAbiContract001.java} (97%) diff --git a/src/test/java/stest/tron/wallet/common/client/utils/PublicMethed.java b/src/test/java/stest/tron/wallet/common/client/utils/PublicMethed.java index 16757b43c22..b117d9e3c20 100644 --- a/src/test/java/stest/tron/wallet/common/client/utils/PublicMethed.java +++ b/src/test/java/stest/tron/wallet/common/client/utils/PublicMethed.java @@ -20,7 +20,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.Optional; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -49,8 +48,6 @@ import org.tron.common.crypto.Hash; import org.tron.common.utils.ByteArray; import org.tron.common.utils.ByteUtil; -import org.tron.common.utils.Utils; - import org.tron.core.Wallet; import org.tron.keystore.WalletFile; import org.tron.protos.Contract; @@ -61,7 +58,6 @@ import org.tron.protos.Protocol; import org.tron.protos.Protocol.Account; import org.tron.protos.Protocol.Block; -//import org.tron.protos.Protocol.DeferredTransaction; import org.tron.protos.Protocol.DelegatedResourceAccountIndex; import org.tron.protos.Protocol.Exchange; import org.tron.protos.Protocol.Key; @@ -74,6 +70,8 @@ import stest.tron.wallet.common.client.Parameter.CommonConstant; import stest.tron.wallet.common.client.WalletClient; +//import org.tron.protos.Protocol.DeferredTransaction; + public class PublicMethed { @@ -3061,13 +3059,10 @@ public static String triggerContract(byte[] contractAddress, String method, Stri /** * constructor. */ - - public static String triggerParamListContract(byte[] contractAddress, String method, - List params, + public static String triggerContract(byte[] contractAddress, String method, String argsStr, Boolean isHex, long callValue, long feeLimit, String tokenId, long tokenValue, byte[] ownerAddress, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { - Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); ECKey temKey = null; try { @@ -3077,9 +3072,13 @@ public static String triggerParamListContract(byte[] contractAddress, String met ex.printStackTrace(); } final ECKey ecKey = temKey; + if (argsStr.equalsIgnoreCase("#")) { + logger.info("argsstr is #"); + argsStr = ""; + } byte[] owner = ownerAddress; - byte[] input = Hex.decode(AbiUtil.parseMethod(method, params)); + byte[] input = Hex.decode(AbiUtil.parseMethod(method, argsStr, isHex)); Contract.TriggerSmartContract.Builder builder = Contract.TriggerSmartContract.newBuilder(); builder.setOwnerAddress(ByteString.copyFrom(owner)); @@ -3152,18 +3151,18 @@ public static String triggerParamListContract(byte[] contractAddress, String met } else { return ByteArray.toHexString(Sha256Hash.hash(transaction.getRawData().toByteArray())); } - - } /** * constructor. */ - public static String triggerContract(byte[] contractAddress, String method, String argsStr, + public static String triggerParamListContract(byte[] contractAddress, String method, + List params, Boolean isHex, long callValue, long feeLimit, String tokenId, long tokenValue, byte[] ownerAddress, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); ECKey temKey = null; try { @@ -3173,13 +3172,9 @@ public static String triggerContract(byte[] contractAddress, String method, Stri ex.printStackTrace(); } final ECKey ecKey = temKey; - if (argsStr.equalsIgnoreCase("#")) { - logger.info("argsstr is #"); - argsStr = ""; - } byte[] owner = ownerAddress; - byte[] input = Hex.decode(AbiUtil.parseMethod(method, argsStr, isHex)); + byte[] input = Hex.decode(AbiUtil.parseMethod(method, params)); Contract.TriggerSmartContract.Builder builder = Contract.TriggerSmartContract.newBuilder(); builder.setOwnerAddress(ByteString.copyFrom(owner)); @@ -3252,6 +3247,8 @@ public static String triggerContract(byte[] contractAddress, String method, Stri } else { return ByteArray.toHexString(Sha256Hash.hash(transaction.getRawData().toByteArray())); } + + } /** @@ -4488,6 +4485,9 @@ public static HashMap getBycodeAbiForLibrary(String solFile, return retMap; } + /** + * constructor. + */ public static String triggerConstantContract(byte[] contractAddress, String method, String argsStr, Boolean isHex, long callValue, long feeLimit, String tokenId, long tokenValue, @@ -4584,7 +4584,10 @@ public static String triggerConstantContract(byte[] contractAddress, String meth } } - public static String clearContractABI(byte[] contractAddress, + /** + * constructor. + */ + public static String clearContractAbi(byte[] contractAddress, byte[] ownerAddress, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); @@ -4604,10 +4607,10 @@ public static String clearContractABI(byte[] contractAddress, builder.setOwnerAddress(ByteString.copyFrom(owner)); builder.setContractAddress(ByteString.copyFrom(contractAddress)); - Contract.ClearABIContract clearABIContract = builder.build(); + Contract.ClearABIContract clearAbiContract = builder.build(); TransactionExtention transactionExtention = blockingStubFull - .clearContractABI(clearABIContract); + .clearContractABI(clearAbiContract); if (transactionExtention == null || !transactionExtention.getResult().getResult()) { System.out.println("RPC create call trx failed!"); System.out.println("Code = " + transactionExtention.getResult().getCode()); @@ -4670,8 +4673,10 @@ public static String clearContractABI(byte[] contractAddress, } } - - public static TransactionExtention clearContractABIForExtention(byte[] contractAddress, + /** + * constructor. + */ + public static TransactionExtention clearContractAbiForExtention(byte[] contractAddress, byte[] ownerAddress, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull) { Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); @@ -4691,15 +4696,17 @@ public static TransactionExtention clearContractABIForExtention(byte[] contractA builder.setOwnerAddress(ByteString.copyFrom(owner)); builder.setContractAddress(ByteString.copyFrom(contractAddress)); - Contract.ClearABIContract clearABIContract = builder.build(); + Contract.ClearABIContract clearAbiContract = builder.build(); TransactionExtention transactionExtention = blockingStubFull - .clearContractABI(clearABIContract); + .clearContractABI(clearAbiContract); return transactionExtention; } - + /** + * constructor. + */ public static TransactionExtention triggerConstantContractForExtention(byte[] contractAddress, String method, String argsStr, @@ -4778,6 +4785,9 @@ public static TransactionExtention triggerContractForExtention(byte[] contractAd } + /** + * constructor. + */ public static String create2(String[] parameters) { if (parameters == null || parameters.length != 3) { logger.error("create2 needs 3 parameter:\ncreate2 address code salt"); diff --git a/src/test/java/stest/tron/wallet/common/client/utils/PublicMethedForMutiSign.java b/src/test/java/stest/tron/wallet/common/client/utils/PublicMethedForMutiSign.java index 27fc1ff6156..cae1e9db857 100644 --- a/src/test/java/stest/tron/wallet/common/client/utils/PublicMethedForMutiSign.java +++ b/src/test/java/stest/tron/wallet/common/client/utils/PublicMethedForMutiSign.java @@ -4512,7 +4512,7 @@ public static Boolean exchangeCreate1(byte[] firstTokenId, long firstTokenBalanc } - public static boolean clearContractABI(byte[] contractAddress, + public static boolean clearContractAbi(byte[] contractAddress, byte[] ownerAddress, String priKey, WalletGrpc.WalletBlockingStub blockingStubFull, int permissionId, String[] permissionKeyString) { diff --git a/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestClearABIContract001.java b/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestClearAbiContract001.java similarity index 97% rename from src/test/java/stest/tron/wallet/dailybuild/http/HttpTestClearABIContract001.java rename to src/test/java/stest/tron/wallet/dailybuild/http/HttpTestClearAbiContract001.java index 004b273b3f7..15deddf3160 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestClearABIContract001.java +++ b/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestClearAbiContract001.java @@ -17,7 +17,7 @@ import stest.tron.wallet.common.client.utils.PublicMethed; @Slf4j -public class HttpTestClearABIContract001 { +public class HttpTestClearAbiContract001 { private final String testKey002 = Configuration.getByPath("testng.conf") .getString("foundationAccount.key1"); @@ -100,8 +100,8 @@ public void test2GetContract() { Assert.assertEquals(responseContent.getString("origin_address"), ByteArray.toHexString(assetOwnerAddress)); Assert - .assertThat(responseContent.getString("abi") - , containsString("testView")); + .assertThat(responseContent.getString("abi"), + containsString("testView")); Assert.assertEquals(responseContent.getString("origin_energy_limit"), "11111111111111"); Assert.assertEquals(responseContent.getString("name"), contractName); @@ -129,7 +129,7 @@ public void test3TriggerConstantContract() { * constructor. */ @Test(enabled = true, description = "Trigger contract by http") - public void test4ClearABIContract() { + public void test4ClearAbiContract() { HttpResponse httpResponse = HttpMethed .clearABiGetTxid(httpnode, assetOwnerAddress, contractAddress, assetOwnerKey); diff --git a/src/test/java/stest/tron/wallet/dailybuild/operationupdate/WalletTestMutiSign018.java b/src/test/java/stest/tron/wallet/dailybuild/operationupdate/WalletTestMutiSign018.java index 706e18c2dd8..3cb68cb9928 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/operationupdate/WalletTestMutiSign018.java +++ b/src/test/java/stest/tron/wallet/dailybuild/operationupdate/WalletTestMutiSign018.java @@ -162,7 +162,7 @@ public void test1MutiSignForClearContractAbi() { SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); Assert.assertTrue(smartContract.getAbi().toString() != null); Assert.assertTrue(PublicMethedForMutiSign - .clearContractABI(contractAddress, ownerAddress, ownerKey, + .clearContractAbi(contractAddress, ownerAddress, ownerKey, blockingStubFull, 2, permissionKeyString)); PublicMethed.waitProduceNextBlock(blockingStubFull); @@ -240,7 +240,7 @@ public void test2MutiSignForClearContractAbiForDefault() { SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); Assert.assertTrue(smartContract.getAbi().toString() != null); Assert.assertTrue(PublicMethedForMutiSign - .clearContractABI(contractAddress, ownerAddress, ownerKey, + .clearContractAbi(contractAddress, ownerAddress, ownerKey, blockingStubFull, 2, permissionKeyString)); PublicMethed.waitProduceNextBlock(blockingStubFull); @@ -295,7 +295,7 @@ public void test3MutiSignForClearContractAbiForDefault() { SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); Assert.assertTrue(smartContract.getAbi().toString() != null); Assert.assertTrue(PublicMethedForMutiSign - .clearContractABI(contractAddress, ownerAddress, ownerKey, + .clearContractAbi(contractAddress, ownerAddress, ownerKey, blockingStubFull, 2, activeDefaultKeyString)); PublicMethed.waitProduceNextBlock(blockingStubFull); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi001.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi001.java index e80d5035479..5ea098d7ab5 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi001.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi001.java @@ -132,7 +132,7 @@ public void testClearAbi001() { logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); TransactionExtention transactionExtention = PublicMethed - .clearContractABIForExtention(contractAddress, contractExcAddress1, contractExcKey1, + .clearContractAbiForExtention(contractAddress, contractExcAddress1, contractExcKey1, blockingStubFull); Assert .assertThat(transactionExtention.getResult().getCode().toString(), @@ -173,7 +173,7 @@ public void testClearAbi002() { logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); String txid = PublicMethed - .clearContractABI(contractAddress, contractExcAddress, contractExcKey, + .clearContractAbi(contractAddress, contractExcAddress, contractExcKey, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); Optional infoById = null; @@ -181,7 +181,7 @@ public void testClearAbi002() { Assert.assertTrue(infoById.get().getResultValue() == 0); String txid1 = PublicMethed - .clearContractABI(contractAddress, contractExcAddress, contractExcKey, + .clearContractAbi(contractAddress, contractExcAddress, contractExcKey, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); Optional infoById1 = null; @@ -218,7 +218,7 @@ public void testClearAbi003() { logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); String txid = PublicMethed - .clearContractABI(contractAddress, contractExcAddress, contractExcKey, + .clearContractAbi(contractAddress, contractExcAddress, contractExcKey, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); Optional infoById = null; @@ -236,7 +236,7 @@ public void testClearAbi003() { @Test(enabled = true, description = "Clear a account address") public void testClearAbi004() { TransactionExtention transactionExtention = PublicMethed - .clearContractABIForExtention(contractExcAddress, contractExcAddress, contractExcKey, + .clearContractAbiForExtention(contractExcAddress, contractExcAddress, contractExcKey, blockingStubFull); Assert .assertThat(transactionExtention.getResult().getCode().toString(), @@ -255,7 +255,7 @@ public void testClearAbi005() { String contractExcKeyN = ByteArray.toHexString(ecKeyN.getPrivKeyBytes()); TransactionExtention transactionExtention = PublicMethed - .clearContractABIForExtention(contractExcAddressN, contractExcAddress, contractExcKey, + .clearContractAbiForExtention(contractExcAddressN, contractExcAddress, contractExcKey, blockingStubFull); Assert.assertThat(transactionExtention.getResult().getCode().toString(), containsString("CONTRACT_VALIDATE_ERROR")); @@ -268,7 +268,7 @@ public void testClearAbi005() { public void testClearAbi006() { byte[] fakeAddress = "412B5D".getBytes(); TransactionExtention transactionExtention = PublicMethed - .clearContractABIForExtention(fakeAddress, contractExcAddress, contractExcKey, + .clearContractAbiForExtention(fakeAddress, contractExcAddress, contractExcKey, blockingStubFull); Assert .assertThat(transactionExtention.getResult().getCode().toString(), @@ -279,7 +279,7 @@ public void testClearAbi006() { byte[] fakeAddress1 = "412B5D3405B2D26767C9C09886D53DEAFF6EB718AC111".getBytes(); TransactionExtention transactionExtention1 = PublicMethed - .clearContractABIForExtention(fakeAddress1, contractExcAddress, contractExcKey, + .clearContractAbiForExtention(fakeAddress1, contractExcAddress, contractExcKey, blockingStubFull); Assert .assertThat(transactionExtention1.getResult().getCode().toString(), diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi002.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi002.java index 31b22bcbda0..90c661d8994 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi002.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi002.java @@ -123,7 +123,7 @@ public void testClearAbi() { logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); String txid = PublicMethed - .clearContractABI(contractAddress, contractExcAddress, contractExcKey, + .clearContractAbi(contractAddress, contractExcAddress, contractExcKey, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); Optional infoById = null; diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi003.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi003.java index 5df6b55d13c..88557f48b8a 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi003.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi003.java @@ -123,7 +123,7 @@ public void testClearAbi() { logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); String txid = PublicMethed - .clearContractABI(contractAddress, contractExcAddress, contractExcKey, + .clearContractAbi(contractAddress, contractExcAddress, contractExcKey, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); Optional infoById = null; diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi004.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi004.java index ec9a1be5ea8..f0a064753be 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi004.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi004.java @@ -93,7 +93,7 @@ public void testClearAbi() { PublicMethed.waitProduceNextBlock(blockingStubFull); TransactionExtention transactionExtention = PublicMethed - .clearContractABIForExtention(contractExcAddress, contractExcAddress, contractExcKey, + .clearContractAbiForExtention(contractExcAddress, contractExcAddress, contractExcKey, blockingStubFull); Assert .assertThat(transactionExtention.getResult().getCode().toString(), diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi005.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi005.java index ddcd723c63b..5036eeb6cfd 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi005.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi005.java @@ -173,7 +173,7 @@ public void testClearAbi() { Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); TransactionExtention transactionExtention = PublicMethed - .clearContractABIForExtention(returnAddressBytes, contractExcAddress, contractExcKey, + .clearContractAbiForExtention(returnAddressBytes, contractExcAddress, contractExcKey, blockingStubFull); Assert .assertThat(transactionExtention.getResult().getCode().toString(), diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi006.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi006.java index 6c1d07b3d6d..7928fdd8269 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi006.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi006.java @@ -95,7 +95,7 @@ public void testClearAbi() { PublicMethed.waitProduceNextBlock(blockingStubFull); TransactionExtention transactionExtention = PublicMethed - .clearContractABIForExtention(contractExcAddress1, contractExcAddress, contractExcKey, + .clearContractAbiForExtention(contractExcAddress1, contractExcAddress, contractExcKey, blockingStubFull); Assert.assertThat(transactionExtention.getResult().getCode().toString(), containsString("CONTRACT_VALIDATE_ERROR")); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi007.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi007.java index 8191b470252..a44383429a0 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi007.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi007.java @@ -95,7 +95,7 @@ public void testClearAbi() { PublicMethed.waitProduceNextBlock(blockingStubFull); byte[] fakeAddress = "412B5D".getBytes(); TransactionExtention transactionExtention = PublicMethed - .clearContractABIForExtention(fakeAddress, contractExcAddress, contractExcKey, + .clearContractAbiForExtention(fakeAddress, contractExcAddress, contractExcKey, blockingStubFull); Assert .assertThat(transactionExtention.getResult().getCode().toString(), @@ -106,7 +106,7 @@ public void testClearAbi() { byte[] fakeAddress1 = "412B5D3405B2D26767C9C09886D53DEAFF6EB718AC111".getBytes(); TransactionExtention transactionExtention1 = PublicMethed - .clearContractABIForExtention(fakeAddress1, contractExcAddress, contractExcKey, + .clearContractAbiForExtention(fakeAddress1, contractExcAddress, contractExcKey, blockingStubFull); Assert .assertThat(transactionExtention1.getResult().getCode().toString(), diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi008.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi008.java index 5905ce01b2d..0b4d16f24f2 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi008.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/clearabi/ClearAbi008.java @@ -124,7 +124,7 @@ public void testClearAbi() { logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); String txid = PublicMethed - .clearContractABI(contractAddress, contractExcAddress, contractExcKey, + .clearContractAbi(contractAddress, contractExcAddress, contractExcKey, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); Optional infoById = null; @@ -137,7 +137,7 @@ public void testClearAbi() { Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); String txid1 = PublicMethed - .clearContractABI(contractAddress, contractExcAddress, contractExcKey, + .clearContractAbi(contractAddress, contractExcAddress, contractExcKey, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); Optional infoById1 = null; diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant017.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant017.java index 6b7adf8c732..f43f98d8417 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant017.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/triggerconstant/TriggerConstant017.java @@ -137,7 +137,7 @@ public void testTriggerConstantContract() { .toHexString(result)))); String txid = ""; txid = PublicMethed - .clearContractABI(contractAddress, contractExcAddress, contractExcKey, blockingStubFull); + .clearContractAbi(contractAddress, contractExcAddress, contractExcKey, blockingStubFull); Optional infoById = null; infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); Assert.assertTrue(infoById.get().getResultValue() == 0); From b9045538d8e7ef27189b326be69b602f08ac70cb Mon Sep 17 00:00:00 2001 From: wangming Date: Fri, 14 Jun 2019 15:28:41 +0800 Subject: [PATCH 68/90] fix testcase error --- .../dailybuild/trctoken/ContractTrcToken077.java | 1 + .../tvmnewcommand/create2/Create2Test019.java | 5 +++-- .../extCodeHash/ExtCodeHashTest007.java | 16 +++++++++++----- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken077.java b/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken077.java index 79291236b95..fcfea856d56 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken077.java +++ b/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken077.java @@ -142,6 +142,7 @@ public void testAddress002() { infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); logger.info("infoById:" + infoById); + Assert.assertNotNull(infoById); byte[] a = infoById.get().getContractResult(0).toByteArray(); byte[] b = subByte(a, 11, 1); byte[] c = subByte(a, 0, 11); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test019.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test019.java index 2df21ff119c..c948f4f82a8 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test019.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test019.java @@ -215,8 +215,8 @@ public void testTriggerContract() { .triggerContract(returnAddressBytes, "i()", "#", false, 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - infoById1 = PublicMethed.getTransactionInfoById(txid, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); + infoById1 = PublicMethed.getTransactionInfoById(txid, blockingStubFull); returnnumber = ByteArray.toLong(ByteArray .fromHexString(ByteArray.toHexString(infoById1.get().getContractResult(0).toByteArray()))); Assert.assertTrue(5 == returnnumber); @@ -227,6 +227,7 @@ public void testTriggerContract() { .triggerContract(returnAddressBytes, "testSuicideNonexistentTarget(address)", param1, false, 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); Optional infoById2 = PublicMethed .getTransactionInfoById(txid, blockingStubFull); @@ -236,7 +237,7 @@ public void testTriggerContract() { .triggerContractForExtention(returnAddressBytes, "i()", "#", false, 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); - + PublicMethed.waitProduceNextBlock(blockingStubFull); Assert .assertThat(transactionExtention.getResult().getCode().toString(), containsString("CONTRACT_VALIDATE_ERROR")); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest007.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest007.java index 2104e0c6996..336744f4dee 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest007.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/extCodeHash/ExtCodeHashTest007.java @@ -468,12 +468,18 @@ public void test06DeployTest2Contract() { logger.info("before energyUsage is " + Long.toString(energyUsage)); logger.info("before balanceBefore is " + Long.toString(balanceBefore)); - String filePath = "./src/test/resources/soliditycode/extCodeHashTestNoPayable.sol"; String contractName = "testConstantContract"; - HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); - - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String code = "608060405234801561001057600080fd5b50d3801561001d57600080fd5b50d2801561002a5760" + + "0080fd5b5060c5806100396000396000f3fe6080604052348015600f57600080fd5b50d38015601b576000" + + "80fd5b50d28015602757600080fd5b50600436106066577c01000000000000000000000000000000000000" + + "000000000000000000006000350463c518aa0f8114606b578063e5aa3d58146083575b600080fd5b607160" + + "89565b60408051918252519081900360200190f35b60716093565b6001600081905590565b6000548156fe" + + "a165627a7a723058205c5aadfbd06ea264db7b73e7b7f3c36ac64a9d520ba46b4bc7f1dc56252f17ac0029"; + String abi = "[{\"constant\":false,\"inputs\":[],\"name\":\"testNoPayable\",\"outputs\":[{\"" + + "name\":\"z\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable" + + "\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"i\",\"outputs\":" + + "[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"" + + "type\":\"function\"}]"; final String transferTokenTxid = PublicMethed .deployContractAndGetTransactionInfoById(contractName, abi, code, "", From 3350cb7c1c5784c4e1da4cae89e01c3780d15510 Mon Sep 17 00:00:00 2001 From: wangming Date: Fri, 14 Jun 2019 18:58:44 +0800 Subject: [PATCH 69/90] modify ContractTrcToken077 --- .../dailybuild/trctoken/ContractTrcToken077.java | 13 +++++++++---- .../tvmnewcommand/create2/Create2Test019.java | 2 ++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken077.java b/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken077.java index fcfea856d56..d85cb0be42c 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken077.java +++ b/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken077.java @@ -114,12 +114,17 @@ public void testAddress002() { blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - String filePath = "./src/test/resources/soliditycode/contractTrcToken077.sol"; String contractName = "trcToken077"; - HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); + String code = "608060405234801561001057600080fd5b50d3801561001d57600080fd5b50d2801561002a57600" + + "080fd5b5060b0806100396000396000f3fe6080604052348015600f57600080fd5b50d38015601b57600080" + + "fd5b50d28015602757600080fd5b5060043610605c577c01000000000000000000000000000000000000000" + + "0000000000000000060003504636241c1d881146061575b600080fd5b60676079565b604080519182525190" + + "81900360200190f35b60405130908190529056fea165627a7a723058207b9b52e71420f2fa4cb55ffd55641" + + "355ec84e09d6d4545c629dde7cc01d74a100029"; + String abi = "[{\"constant\":false,\"inputs\":[],\"name\":\"addressTest\",\"outputs\":[{\"name" + + "\":\"addressValue\",\"type\":\"bytes32\"}],\"payable\":false,\"stateMutability\":\"nonp" + + "ayable\",\"type\":\"function\"}]"; String deploytxid = PublicMethed .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test019.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test019.java index c948f4f82a8..13047457688 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test019.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test019.java @@ -249,6 +249,8 @@ public void testTriggerContract() { .triggerContract(contractAddress, "deploy(bytes,uint256)", num, false, 0, maxFeeLimit, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById3 = PublicMethed .getTransactionInfoById(txid, blockingStubFull); byte[] returnAddressBytes1 = infoById3.get().getInternalTransactions(0).getTransferToAddress() From cb0333924c2abd3818588988f49cac51b45113f4 Mon Sep 17 00:00:00 2001 From: wangming Date: Fri, 14 Jun 2019 19:16:59 +0800 Subject: [PATCH 70/90] modify ContractTrcToken077 --- .../tron/wallet/dailybuild/trctoken/ContractTrcToken077.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken077.java b/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken077.java index d85cb0be42c..57e6411a8cc 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken077.java +++ b/src/test/java/stest/tron/wallet/dailybuild/trctoken/ContractTrcToken077.java @@ -130,18 +130,17 @@ public void testAddress002() { .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, testKeyForGrammarAddress, grammarAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); Optional deployById = PublicMethed .getTransactionInfoById(deploytxid, blockingStubFull); contractAddress = deployById.get().getContractAddress().toByteArray(); logger.info("infoById:" + deployById); - PublicMethed.waitProduceNextBlock(blockingStubFull); String txid = ""; txid = PublicMethed.triggerContract(contractAddress, "addressTest()", "#", false, 0, maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); Optional infoById = null; infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); From 5453334112e7cffbe48e03862349d5754bc85f4c Mon Sep 17 00:00:00 2001 From: wangming Date: Tue, 18 Jun 2019 12:12:20 +0800 Subject: [PATCH 71/90] add stest case --- .../contract/linkage/ContractLinkage002.java | 15 +- .../scenario/ContractScenario014.java | 161 ++++++++++++++++++ .../scenario/ContractScenario015.java | 155 +++++++++++++++++ .../exceptionfee/AssertException.java | 18 ++ .../grammar/ContractGrammar001.java | 24 +++ .../dailybuild/http/HttpTestSendCoin001.java | 10 +- .../tvmnewcommand/create2/Create2Test019.java | 12 ++ .../transferfailed/TransferFailed001.java | 12 +- .../transferfailed/TransferFailed003.java | 1 + .../transferfailed/TransferFailed005.java | 4 - .../soliditycode/AssertException002.sol | 17 ++ 11 files changed, 405 insertions(+), 24 deletions(-) create mode 100644 src/test/java/stest/tron/wallet/contract/scenario/ContractScenario014.java create mode 100644 src/test/java/stest/tron/wallet/contract/scenario/ContractScenario015.java create mode 100644 src/test/resources/soliditycode/AssertException002.sol diff --git a/src/test/java/stest/tron/wallet/contract/linkage/ContractLinkage002.java b/src/test/java/stest/tron/wallet/contract/linkage/ContractLinkage002.java index 060ef78118d..27e21651fc7 100644 --- a/src/test/java/stest/tron/wallet/contract/linkage/ContractLinkage002.java +++ b/src/test/java/stest/tron/wallet/contract/linkage/ContractLinkage002.java @@ -3,6 +3,7 @@ import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import java.util.HashMap; +import java.util.Optional; import java.util.concurrent.TimeUnit; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; @@ -18,6 +19,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; @@ -68,10 +70,19 @@ public void beforeClass() { @Test(enabled = true) public void updateSetting() { - Assert.assertTrue(PublicMethed.sendcoin(linkage002Address, 200000000000L, fromAddress, - testKey002, blockingStubFull)); + String sendcoin = PublicMethed + .sendcoinGetTransactionId(linkage002Address, 200000000000L, fromAddress, + testKey002, blockingStubFull); Account info; PublicMethed.waitProduceNextBlock(blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById0 = null; + infoById0 = PublicMethed.getTransactionInfoById(sendcoin, blockingStubFull); + logger.info("infoById0 " + infoById0.get()); + Assert.assertEquals(ByteArray.toHexString(infoById0.get().getContractResult(0).toByteArray()), + "SUCCESS"); + Assert.assertEquals(infoById0.get().getResult().getNumber(), 0); + Assert.assertTrue(PublicMethed.freezeBalanceGetEnergy(linkage002Address, 50000000L, 3, 1, linkage002Key, blockingStubFull)); AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(linkage002Address, diff --git a/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario014.java b/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario014.java new file mode 100644 index 00000000000..e6dd2fbc25f --- /dev/null +++ b/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario014.java @@ -0,0 +1,161 @@ +package stest.tron.wallet.contract.scenario; + + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +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.api.WalletSolidityGrpc; +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.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; + +@Slf4j +public class ContractScenario014 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + @Test(enabled = true, description = "Clear a contract with ABI created by itself") + public void testClearAbi() { + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/ClearAbi001.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); + Assert.assertFalse(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + + String txid = PublicMethed + .clearContractAbi(contractAddress, contractExcAddress, contractExcKey, + blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + Assert.assertEquals(0,infoById.get().getResultValue()); + Assert.assertEquals("SUCCESS",(infoById.get().getResMessage()).toString()); + + smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); + Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); + Assert.assertTrue(smartContract.getName().equalsIgnoreCase(contractName)); + Assert.assertFalse(smartContract.getBytecode().toString().isEmpty()); + + + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} diff --git a/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario015.java b/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario015.java new file mode 100644 index 00000000000..3f1c170091a --- /dev/null +++ b/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario015.java @@ -0,0 +1,155 @@ +package stest.tron.wallet.contract.scenario; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +import java.util.concurrent.TimeUnit; +import lombok.extern.slf4j.Slf4j; +import org.junit.Assert; +import org.spongycastle.util.encoders.Hex; +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.GrpcAPI.TransactionExtention; +import org.tron.api.WalletGrpc; +import org.tron.api.WalletSolidityGrpc; +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.Transaction; +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 ContractScenario015 { + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + + private String soliditynode = Configuration.getByPath("testng.conf") + .getStringList("solidityNode.ip.list").get(0); + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] contractExcAddress = ecKey1.getAddress(); + String contractExcKey = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(contractExcKey); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + + channelSolidity = ManagedChannelBuilder.forTarget(soliditynode) + .usePlaintext(true) + .build(); + blockingStubSolidity = WalletSolidityGrpc.newBlockingStub(channelSolidity); + } + + @Test(enabled = true, description = "TriggerConstantContract a constant function ") + public void testTriggerConstantContract() { + Assert.assertTrue(PublicMethed + .sendcoin(contractExcAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/ClearAbi001.sol"; + String contractName = "testConstantContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, contractExcKey, + contractExcAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, + blockingStubFull); + info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + TransactionExtention transactionExtention = PublicMethed + .triggerConstantContractForExtention(contractAddress, + "testPayable()", "#", false, + 0, 0, "0", 0, contractExcAddress, contractExcKey, blockingStubFull); + Transaction transaction = transactionExtention.getTransaction(); + + byte[] result = transactionExtention.getConstantResult(0).toByteArray(); + logger.info("message:" + transaction.getRet(0).getRet()); + logger.info(":" + ByteArray + .toStr(transactionExtention.getResult().getMessage().toByteArray())); + logger.info("Result:" + Hex.toHexString(result)); + logger.info("getCode"+transactionExtention.getResult().getCode().getNumber()); + Assert.assertEquals("SUCESS",transaction.getRet(0).getRet().toString()); + Assert.assertEquals(1, ByteArray.toLong(ByteArray + .fromHexString(Hex + .toHexString(result)))); + } + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelSolidity != null) { + channelSolidity.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + + +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/exceptionfee/AssertException.java b/src/test/java/stest/tron/wallet/dailybuild/exceptionfee/AssertException.java index 0483818e30e..4aadedd6cc0 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/exceptionfee/AssertException.java +++ b/src/test/java/stest/tron/wallet/dailybuild/exceptionfee/AssertException.java @@ -19,6 +19,8 @@ import org.tron.common.utils.Utils; import org.tron.core.Wallet; import org.tron.protos.Protocol.Account; +import org.tron.protos.Protocol.Transaction; +import org.tron.protos.Protocol.Transaction.Result.contractResult; import org.tron.protos.Protocol.TransactionInfo; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.Parameter.CommonConstant; @@ -129,6 +131,22 @@ public void test1DivideInt() { PublicMethed.waitProduceNextBlock(blockingStubFull1); Optional infoById = null; infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + logger.info("infoById:" + infoById); + Optional ById = PublicMethed.getTransactionById(txid, blockingStubFull); + logger.info("getRet:" + ById.get().getRet(0)); + logger.info("getNumber:" + ById.get().getRet(0).getContractRet().getNumber()); + logger.info("getContractRetValue:" + ById.get().getRet(0).getContractRetValue()); + logger.info("getContractRet:" + ById.get().getRet(0).getContractRet()); + + Assert.assertEquals(ById.get().getRet(0).getContractRet().getNumber(), + contractResult.ILLEGAL_OPERATION_VALUE); + Assert.assertEquals(ById.get().getRet(0).getContractRetValue(), 8); + Assert.assertEquals(ById.get().getRet(0).getContractRet(), contractResult.ILLEGAL_OPERATION); + + Assert + .assertEquals(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()), ""); + Assert.assertEquals(contractResult.ILLEGAL_OPERATION, infoById.get().getReceipt().getResult()); + Long fee = infoById.get().getFee(); Long netUsed = infoById.get().getReceipt().getNetUsage(); Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); diff --git a/src/test/java/stest/tron/wallet/dailybuild/grammar/ContractGrammar001.java b/src/test/java/stest/tron/wallet/dailybuild/grammar/ContractGrammar001.java index 5454a596020..6a5d097f5a7 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/grammar/ContractGrammar001.java +++ b/src/test/java/stest/tron/wallet/dailybuild/grammar/ContractGrammar001.java @@ -17,6 +17,8 @@ import org.tron.common.utils.ByteArray; import org.tron.common.utils.Utils; import org.tron.core.Wallet; +import org.tron.protos.Protocol.Transaction; +import org.tron.protos.Protocol.Transaction.Result.contractResult; import org.tron.protos.Protocol.TransactionInfo; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.Parameter.CommonConstant; @@ -119,7 +121,29 @@ public void test1Grammar001() { "select(bool,uint256)", num2, false, 0, maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + logger.info("infoById:" + infoById); + Optional ById = PublicMethed.getTransactionById(txid, blockingStubFull); + logger.info("getRet:" + ById.get().getRet(0)); + logger.info("getNumber:" + ById.get().getRet(0).getContractRet().getNumber()); + logger.info("getContractRetValue:" + ById.get().getRet(0).getContractRetValue()); + logger.info("getContractRet:" + ById.get().getRet(0).getContractRet()); + + Assert.assertEquals(ById.get().getRet(0).getContractRet().getNumber(), + contractResult.SUCCESS_VALUE); + Assert.assertEquals(ById.get().getRet(0).getContractRetValue(), 1); + Assert.assertEquals(ById.get().getRet(0).getContractRet(), contractResult.SUCCESS); + + Assert + .assertEquals(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()), + "0000000000000000000000000000000000000000000000000000000000000064"); + Assert.assertEquals(contractResult.SUCCESS, infoById.get().getReceipt().getResult()); + + logger.info("ById:" + ById); + Assert.assertEquals(ById.get().getRet(0).getRet().getNumber(), 0); + Assert.assertEquals(ById.get().getRet(0).getRetValue(), 0); + Long returnnumber2 = ByteArray.toLong(ByteArray.fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); diff --git a/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestSendCoin001.java b/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestSendCoin001.java index 2238f7f749e..970f60301bc 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestSendCoin001.java +++ b/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestSendCoin001.java @@ -4,16 +4,12 @@ import com.alibaba.fastjson.JSONObject; import lombok.extern.slf4j.Slf4j; import org.apache.http.HttpResponse; - import org.junit.Assert; - import org.testng.annotations.AfterClass; import org.testng.annotations.Test; - import org.tron.common.crypto.ECKey; import org.tron.common.utils.ByteArray; import org.tron.common.utils.Utils; - import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.utils.HttpMethed; import stest.tron.wallet.common.client.utils.PublicMethed; @@ -61,7 +57,7 @@ public void test2GetTransactionByIdFromSolidity() { String retString = responseContent.getString("ret"); JSONArray array = JSONArray.parseArray(retString); Assert.assertTrue(HttpMethed.parseStringContent(array.get(0).toString()).getString( - "contractRet") == null); + "contractRet") == "SUCCESS"); Assert.assertTrue(responseContent.size() > 4); } @@ -95,7 +91,7 @@ public void test4GetTransactionsFromThisFromSolidity() { String retString = transactionObject.getString("ret"); JSONArray array = JSONArray.parseArray(retString); Assert.assertTrue(HttpMethed.parseStringContent(array.get(0).toString()) - .getString("contractRet") == null); + .getString("contractRet") == "SUCCESS"); Assert.assertTrue(responseContent.size() == 1); } @@ -114,7 +110,7 @@ public void test5GetTransactionsToThisFromSolidity() { String retString = transactionObject.getString("ret"); JSONArray array = JSONArray.parseArray(retString); Assert.assertTrue(HttpMethed.parseStringContent(array.get(0).toString()).getString( - "contractRet") == null); + "contractRet") == "SUCCESS"); Assert.assertTrue(responseContent.size() == 1); } diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test019.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test019.java index 13047457688..5201788b6df 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test019.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test019.java @@ -93,10 +93,22 @@ public void beforeClass() { @Test(enabled = true, description = "seted Value of Contract that created by create2," + " should not be stored after contact suicided ande create2 again") public void testTriggerContract() { + String sendcoin = PublicMethed + .sendcoinGetTransactionId(contractExcAddress, 1000000000L, testNetAccountAddress, + testNetAccountKey, + blockingStubFull); + Assert.assertTrue(PublicMethed .sendcoin(contractExcAddress, 1000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById0 = null; + infoById0 = PublicMethed.getTransactionInfoById(sendcoin, blockingStubFull); + logger.info("infoById0 " + infoById0.get()); + Assert.assertEquals(ByteArray.toHexString(infoById0.get().getContractResult(0).toByteArray()), + "SUCCESS"); + Assert.assertEquals(infoById0.get().getResult().getNumber(), 0); + String filePath = "src/test/resources/soliditycode/create2contractn2.sol"; String contractName = "Factory"; HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed001.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed001.java index d18552a67e0..1a2efb62a48 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed001.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed001.java @@ -715,7 +715,7 @@ public void test9TransferTrctoken() { byte[] addressxx = WalletClient.decodeFromBase58Check(addressx); Assert.assertTrue(PublicMethed - .sendcoin(addressxx, 10L, testNetAccountAddress, testNetAccountKey, + .sendcoin(addressxx, 1000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); long start = System.currentTimeMillis() + 2000; @@ -739,16 +739,6 @@ public void test9TransferTrctoken() { assetAccountId = PublicMethed.queryAccount(contractExcAddress, blockingStubFull) .getAssetIssuedID(); - /*String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; - String contractName = "EnergyOfTransferFailedTest"; - HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - - contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, contractExcKey, - contractExcAddress, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull);*/ Assert.assertTrue(PublicMethed.transferAsset(addressxx, assetAccountId.toByteArray(), 100L, contractExcAddress, contractExcKey, blockingStubFull)); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed003.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed003.java index d754f9b1819..910ce65c936 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed003.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed003.java @@ -154,6 +154,7 @@ public void test1TransferTokenEnough() { txid = PublicMethed.triggerContract(contractAddress, "testTransferTokenInsufficientBalance(uint256,trcToken)", num, false, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); Optional infoById = null; PublicMethed.waitProduceNextBlock(blockingStubFull); infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed005.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed005.java index 8c948c94e49..88bae7d9ea1 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed005.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed005.java @@ -489,10 +489,6 @@ public void triggerContract03() { } - @Test(enabled = true, description = "TransferFailed for precompiled") - public void triggerContract05() { - - } /** * constructor. diff --git a/src/test/resources/soliditycode/AssertException002.sol b/src/test/resources/soliditycode/AssertException002.sol new file mode 100644 index 00000000000..2bff1dcec3e --- /dev/null +++ b/src/test/resources/soliditycode/AssertException002.sol @@ -0,0 +1,17 @@ +//pragma solidity ^0.4.0; + +contract AssertException{ + function divideIHaveArgsReturn(int x,int y) public returns (int z) { + return x / y; + } + function testAssert() public { + require(2==1); + } +} +contract C { + constructor() public payable { + assert(1==2); + } + function fun() public { + } +} \ No newline at end of file From 3151fb6ae2884bb746e1f6f5fd6b58145781ca06 Mon Sep 17 00:00:00 2001 From: wangming Date: Tue, 18 Jun 2019 12:31:28 +0800 Subject: [PATCH 72/90] add AssertException002 --- .../exceptionfee/AssertException002.java | 155 ++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 src/test/java/stest/tron/wallet/dailybuild/exceptionfee/AssertException002.java diff --git a/src/test/java/stest/tron/wallet/dailybuild/exceptionfee/AssertException002.java b/src/test/java/stest/tron/wallet/dailybuild/exceptionfee/AssertException002.java new file mode 100644 index 00000000000..1dfbd7bfc01 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/exceptionfee/AssertException002.java @@ -0,0 +1,155 @@ +package stest.tron.wallet.dailybuild.exceptionfee; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +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.WalletGrpc; +import org.tron.api.WalletSolidityGrpc; +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.Transaction; +import org.tron.protos.Protocol.Transaction.Result.contractResult; +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 AssertException002 { + + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String compilerVersion = Configuration.getByPath("testng.conf") + .getString("defaultParameter.solidityCompilerVersion"); + + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] grammarAddress = ecKey1.getAddress(); + String testKeyForGrammarAddress = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(testKeyForGrammarAddress); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + } + + @Test(enabled = true, description = "Support function type") + public void test1AssertException001() { + ecKey1 = new ECKey(Utils.getRandom()); + grammarAddress = ecKey1.getAddress(); + testKeyForGrammarAddress = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(grammarAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/AssertException002.sol"; + String contractName = "AssertException"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, testKeyForGrammarAddress, + grammarAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + String txid = ""; + String num = "10" + "," + "0"; + txid = PublicMethed.triggerContract(contractAddress, + "divideIHaveArgsReturn(int,int)", num, false, + 0, maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + logger.info("infoById:" + infoById); + Optional ById = PublicMethed.getTransactionById(txid, blockingStubFull); + logger.info("getRet:" + ById.get().getRet(0)); + logger.info("getNumber:" + ById.get().getRet(0).getContractRet().getNumber()); + logger.info("getContractRetValue:" + ById.get().getRet(0).getContractRetValue()); + logger.info("getContractRet:" + ById.get().getRet(0).getContractRet()); + + Assert.assertEquals(ById.get().getRet(0).getContractRet().getNumber(), + contractResult.ILLEGAL_OPERATION_VALUE); + Assert.assertEquals(ById.get().getRet(0).getContractRetValue(), 8); + Assert.assertEquals(ById.get().getRet(0).getContractRet(), contractResult.ILLEGAL_OPERATION); + + Assert + .assertEquals(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()), ""); + Assert.assertEquals(contractResult.ILLEGAL_OPERATION, infoById.get().getReceipt().getResult()); + + logger.info("ById:" + ById); + Assert.assertEquals(ById.get().getRet(0).getRet().getNumber(), 0); + Assert.assertEquals(ById.get().getRet(0).getRetValue(), 0); + + Long returnnumber2 = ByteArray.toLong(ByteArray.fromHexString( + ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); + + Assert.assertTrue(returnnumber2 == 100); + } + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + +} From 2e3faf44a53496cbb8fc6142cb67055d9705bb53 Mon Sep 17 00:00:00 2001 From: wangming Date: Tue, 18 Jun 2019 14:20:55 +0800 Subject: [PATCH 73/90] add connect check --- deploy.sh | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/deploy.sh b/deploy.sh index 787c7edc642..879e9614287 100644 --- a/deploy.sh +++ b/deploy.sh @@ -1,18 +1,20 @@ #!/bin/bash if [[ "$TRAVIS_BRANCH" = "develop" || "$TRAVIS_BRANCH" = "master" ]];then stestlogname="`date +%Y%m%d%H%M%S`_stest.log" + timeout 10 ping -c 5 47.93.42.145 > /dev/null || exit 1 + timeout 10 ping -c 5 47.93.18.60 > /dev/null || exit 1 stest_server="" - docker_num_in_67=`ssh -p 22008 -t java-tron@47.93.42.145 'docker ps -a | wc -l'` - docker_num_in_67=`echo $docker_num_in_67 | tr -d "\r"` - docker_num_in_122=`ssh -p 22008 -t java-tron@47.93.18.60 'docker ps -a | wc -l'` - docker_num_in_122=`echo $docker_num_in_122 | tr -d "\r"` - if [ $docker_num_in_67 -le $docker_num_in_122 ]; + docker_num_in_145=`ssh -p 22008 -t java-tron@47.93.42.145 'docker ps -a | wc -l'` + docker_num_in_145=`echo $docker_num_in_145 | tr -d "\r"` + docker_num_in_60=`ssh -p 22008 -t java-tron@47.93.18.60 'docker ps -a | wc -l'` + docker_num_in_60=`echo $docker_num_in_60 | tr -d "\r"` + if [ $docker_num_in_145 -le $docker_num_in_60 ]; then - docker_num=$docker_num_in_67 - stest_server=47.93.18.60 + docker_num=$docker_num_in_145 + stest_server=47.93.42.145 else - docker_num=$docker_num_in_122 - stest_server=47.93.42.145 + docker_num=$docker_num_in_60 + stest_server=47.93.18.60 fi if [[ ${docker_num} -le 3 ]]; From 04bb609ffa0d28dc07f83da674845f456e241f46 Mon Sep 17 00:00:00 2001 From: xiechang33 <354035097@qq.com> Date: Tue, 18 Jun 2019 17:00:54 +0800 Subject: [PATCH 74/90] add check contractResult stest --- .../contract/linkage/ContractLinkage002.java | 11 +- .../grammar/ContractGrammar004.java | 650 ++++++++++++++++++ .../tvmnewcommand/create2/Create2Test019.java | 11 +- .../resources/soliditycode/testOutOfMem.sol | 7 + 4 files changed, 676 insertions(+), 3 deletions(-) create mode 100644 src/test/java/stest/tron/wallet/dailybuild/grammar/ContractGrammar004.java create mode 100644 src/test/resources/soliditycode/testOutOfMem.sol diff --git a/src/test/java/stest/tron/wallet/contract/linkage/ContractLinkage002.java b/src/test/java/stest/tron/wallet/contract/linkage/ContractLinkage002.java index 27e21651fc7..bd69755e8ba 100644 --- a/src/test/java/stest/tron/wallet/contract/linkage/ContractLinkage002.java +++ b/src/test/java/stest/tron/wallet/contract/linkage/ContractLinkage002.java @@ -1,5 +1,7 @@ package stest.tron.wallet.contract.linkage; +import static org.tron.protos.Protocol.Transaction.Result.contractResult.SUCCESS_VALUE; + import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import java.util.HashMap; @@ -19,6 +21,8 @@ import org.tron.core.Wallet; import org.tron.protos.Protocol.Account; import org.tron.protos.Protocol.SmartContract; +import org.tron.protos.Protocol.Transaction; +import org.tron.protos.Protocol.Transaction.Result.contractResult; import org.tron.protos.Protocol.TransactionInfo; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.Parameter.CommonConstant; @@ -80,8 +84,13 @@ public void updateSetting() { infoById0 = PublicMethed.getTransactionInfoById(sendcoin, blockingStubFull); logger.info("infoById0 " + infoById0.get()); Assert.assertEquals(ByteArray.toHexString(infoById0.get().getContractResult(0).toByteArray()), - "SUCCESS"); + ""); Assert.assertEquals(infoById0.get().getResult().getNumber(), 0); + Optional ById = PublicMethed.getTransactionById(sendcoin, blockingStubFull); + Assert.assertEquals(ById.get().getRet(0).getContractRet().getNumber(), + SUCCESS_VALUE); + Assert.assertEquals(ById.get().getRet(0).getContractRetValue(), SUCCESS_VALUE); + Assert.assertEquals(ById.get().getRet(0).getContractRet(), contractResult.SUCCESS); Assert.assertTrue(PublicMethed.freezeBalanceGetEnergy(linkage002Address, 50000000L, 3, 1, linkage002Key, blockingStubFull)); diff --git a/src/test/java/stest/tron/wallet/dailybuild/grammar/ContractGrammar004.java b/src/test/java/stest/tron/wallet/dailybuild/grammar/ContractGrammar004.java new file mode 100644 index 00000000000..d7e6de26d26 --- /dev/null +++ b/src/test/java/stest/tron/wallet/dailybuild/grammar/ContractGrammar004.java @@ -0,0 +1,650 @@ +package stest.tron.wallet.dailybuild.grammar; + +import static org.tron.protos.Protocol.Transaction.Result.contractResult.BAD_JUMP_DESTINATION_VALUE; +import static org.tron.protos.Protocol.Transaction.Result.contractResult.ILLEGAL_OPERATION_VALUE; +import static org.tron.protos.Protocol.Transaction.Result.contractResult.OUT_OF_ENERGY_VALUE; +import static org.tron.protos.Protocol.Transaction.Result.contractResult.OUT_OF_MEMORY_VALUE; +import static org.tron.protos.Protocol.Transaction.Result.contractResult.OUT_OF_TIME_VALUE; +import static org.tron.protos.Protocol.Transaction.Result.contractResult.REVERT_VALUE; +import static org.tron.protos.Protocol.Transaction.Result.contractResult.STACK_TOO_LARGE_VALUE; +import static org.tron.protos.Protocol.Transaction.Result.contractResult.STACK_TOO_SMALL_VALUE; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +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.api.WalletSolidityGrpc; +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.SmartContract; +import org.tron.protos.Protocol.Transaction; +import org.tron.protos.Protocol.Transaction.Result.contractResult; +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 ContractGrammar004 { + + + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String compilerVersion = Configuration.getByPath("testng.conf") + .getString("defaultParameter.solidityCompilerVersion"); + + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] grammarAddress = ecKey1.getAddress(); + String testKeyForGrammarAddress = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(testKeyForGrammarAddress); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + } + + @Test(enabled = true, description = "ContractResult is OUT_OF_TIME") + public void test1Grammar001() { + ecKey1 = new ECKey(Utils.getRandom()); + grammarAddress = ecKey1.getAddress(); + testKeyForGrammarAddress = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(grammarAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + String filePath = "./src/test/resources/soliditycode/walletTestMutiSign004.sol"; + String contractName = "timeoutTest"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + byte[] contractAddress = PublicMethed.deployContract(contractName, abi, code, + "", maxFeeLimit, + 0L, 100, null, testKeyForGrammarAddress, grammarAddress, blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); + org.testng.Assert.assertTrue(smartContract.getAbi().toString() != null); + String txid = null; + Optional infoById = null; + String initParmes = "\"" + "100000" + "\""; + txid = PublicMethed.triggerContract(contractAddress, + "testUseCpu(uint256)", initParmes, false, + 0, maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + logger.info("Txid is " + txid); + logger.info("Trigger energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); + + Optional byId = PublicMethed.getTransactionById(txid, blockingStubFull); + logger.info("getRet:" + byId.get().getRet(0)); + logger.info("getNumber:" + byId.get().getRet(0).getContractRet().getNumber()); + logger.info("getContractRetValue:" + byId.get().getRet(0).getContractRetValue()); + logger.info("getContractRet:" + byId.get().getRet(0).getContractRet()); + logger.info("ById:" + byId); + + Assert.assertEquals(byId.get().getRet(0).getContractRetValue(), OUT_OF_TIME_VALUE); + Assert.assertEquals(byId.get().getRet(0).getContractRet(), contractResult.OUT_OF_TIME); + + Assert + .assertEquals(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()), ""); + Assert.assertEquals(contractResult.OUT_OF_TIME, infoById.get().getReceipt().getResult()); + + Assert.assertEquals(byId.get().getRet(0).getRet().getNumber(), 0); + Assert.assertEquals(byId.get().getRet(0).getRetValue(), 0); + + + } + + + @Test(enabled = true, description = "ContractResult is OUT_OF_MEMORY") + public void test2Grammar002() { + ecKey1 = new ECKey(Utils.getRandom()); + grammarAddress = ecKey1.getAddress(); + testKeyForGrammarAddress = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(grammarAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + String filePath = "./src/test/resources/soliditycode/testOutOfMem.sol"; + String contractName = "Test"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + byte[] contractAddress = PublicMethed.deployContract(contractName, abi, code, + "", maxFeeLimit, + 0L, 100, null, testKeyForGrammarAddress, grammarAddress, blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); + org.testng.Assert.assertTrue(smartContract.getAbi().toString() != null); + String txid = null; + Optional infoById = null; + String initParmes = "\"" + "31457280" + "\""; + txid = PublicMethed.triggerContract(contractAddress, + "testOutOfMem(uint256)", initParmes, false, + 0, maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + logger.info("Txid is " + txid); + logger.info("Trigger energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); + + Optional byId = PublicMethed.getTransactionById(txid, blockingStubFull); + logger.info("getRet:" + byId.get().getRet(0)); + logger.info("getNumber:" + byId.get().getRet(0).getContractRet().getNumber()); + logger.info("getContractRetValue:" + byId.get().getRet(0).getContractRetValue()); + logger.info("getContractRet:" + byId.get().getRet(0).getContractRet()); + logger.info("ById:" + byId); + + logger.info("infoById:" + infoById); + + Assert.assertEquals(byId.get().getRet(0).getContractRetValue(), OUT_OF_MEMORY_VALUE); + Assert.assertEquals(byId.get().getRet(0).getContractRet(), contractResult.OUT_OF_MEMORY); + + Assert + .assertEquals(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()), ""); + Assert.assertEquals(contractResult.OUT_OF_MEMORY, infoById.get().getReceipt().getResult()); + + Assert.assertEquals(byId.get().getRet(0).getRet().getNumber(), 0); + Assert.assertEquals(byId.get().getRet(0).getRetValue(), 0); + + + } + + + @Test(enabled = true, description = "ContractResult is BAD_JUMP_DESTINATION") + public void test3Grammar003() { + ecKey1 = new ECKey(Utils.getRandom()); + grammarAddress = ecKey1.getAddress(); + testKeyForGrammarAddress = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(grammarAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + String contractName = "Test"; + + String code = "608060405234801561001057600080fd5b50d3801561001d57600080fd5b50d2801561002a57600080fd5b5061011f8061003a6000396000f30060806040526004361060485763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416634ef5a0088114604d5780639093b95b14608c575b600080fd5b348015605857600080fd5b50d38015606457600080fd5b50d28015607057600080fd5b50607a60043560b8565b60408051918252519081900360200190f35b348015609757600080fd5b50d3801560a357600080fd5b50d2801560af57600080fd5b5060b660ee565b005b600060608260405190808252806020026020018201604052801560e5578160200160208202803883390190505b50905050919050565b6001805600a165627a7a7230582092ba162087e13f41c6d6c00ba493edc5a5a6250a3840ece5f99aa38b66366a700029"; + String abi = "[{\"constant\":false,\"inputs\":[{\"name\":\"x\",\"type\":\"uint256\"}],\"name\":\"testOutOfMem\",\"outputs\":[{\"name\":\"r\",\"type\":\"bytes32\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"testBadJumpDestination\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]"; + + byte[] contractAddress = PublicMethed.deployContract(contractName, abi, code, + "", maxFeeLimit, + 0L, 100, null, testKeyForGrammarAddress, grammarAddress, blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); + org.testng.Assert.assertTrue(smartContract.getAbi().toString() != null); + String txid = null; + Optional infoById = null; + txid = PublicMethed.triggerContract(contractAddress, + "testBadJumpDestination()", "#", false, + 0, maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + logger.info("Txid is " + txid); + logger.info("Trigger energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); + + Optional byId = PublicMethed.getTransactionById(txid, blockingStubFull); + logger.info("getRet:" + byId.get().getRet(0)); + logger.info("getNumber:" + byId.get().getRet(0).getContractRet().getNumber()); + logger.info("getContractRetValue:" + byId.get().getRet(0).getContractRetValue()); + logger.info("getContractRet:" + byId.get().getRet(0).getContractRet()); + logger.info("ById:" + byId); + + logger.info("infoById:" + infoById); + + Assert.assertEquals(byId.get().getRet(0).getContractRetValue(), BAD_JUMP_DESTINATION_VALUE); + Assert.assertEquals(byId.get().getRet(0).getContractRet(), contractResult.BAD_JUMP_DESTINATION); + + Assert + .assertEquals(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()), ""); + Assert + .assertEquals(contractResult.BAD_JUMP_DESTINATION, infoById.get().getReceipt().getResult()); + + Assert.assertEquals(byId.get().getRet(0).getRet().getNumber(), 0); + Assert.assertEquals(byId.get().getRet(0).getRetValue(), 0); + + + } + + + @Test(enabled = true, description = "ContractResult is OUT_OF_ENERGY") + public void test4Grammar004() { + ecKey1 = new ECKey(Utils.getRandom()); + grammarAddress = ecKey1.getAddress(); + testKeyForGrammarAddress = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(grammarAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + String filePath = "src/test/resources/soliditycode/contractUnknownException.sol"; + String contractName = "testC"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String txid = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, + 20L, 100, null, testKeyForGrammarAddress, + grammarAddress, blockingStubFull); + Optional infoById = null; + PublicMethed.waitProduceNextBlock(blockingStubFull); + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + logger.info("Txid is " + txid); + logger.info("Trigger energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); + + Optional byId = PublicMethed.getTransactionById(txid, blockingStubFull); + logger.info("getRet:" + byId.get().getRet(0)); + logger.info("getNumber:" + byId.get().getRet(0).getContractRet().getNumber()); + logger.info("getContractRetValue:" + byId.get().getRet(0).getContractRetValue()); + logger.info("getContractRet:" + byId.get().getRet(0).getContractRet()); + logger.info("ById:" + byId); + + logger.info("infoById:" + infoById); + + Assert.assertEquals(byId.get().getRet(0).getContractRetValue(), OUT_OF_ENERGY_VALUE); + Assert.assertEquals(byId.get().getRet(0).getContractRet(), contractResult.OUT_OF_ENERGY); + + Assert + .assertEquals(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()), ""); + Assert + .assertEquals(contractResult.OUT_OF_ENERGY, infoById.get().getReceipt().getResult()); + + Assert.assertEquals(byId.get().getRet(0).getRet().getNumber(), 0); + Assert.assertEquals(byId.get().getRet(0).getRetValue(), 0); + + } + + + @Test(enabled = true, description = "ContractResult is ILLEGAL_OPERATION") + public void test5Grammar005() { + ecKey1 = new ECKey(Utils.getRandom()); + grammarAddress = ecKey1.getAddress(); + testKeyForGrammarAddress = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + Assert.assertTrue(PublicMethed + .sendcoin(grammarAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + String filePath = "src/test/resources/soliditycode/assertExceptiontest1DivideInt.sol"; + String contractName = "divideIHaveArgsReturnStorage"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, testKeyForGrammarAddress, + grammarAddress, blockingStubFull); + Account info; + PublicMethed.waitProduceNextBlock(blockingStubFull); + + String txid = ""; + String num = "4" + "," + "0"; + + txid = PublicMethed.triggerContract(contractAddress, + "divideIHaveArgsReturn(int256,int256)", num, false, + 0, maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull1); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + logger.info("infoById:" + infoById); + Optional ById = PublicMethed.getTransactionById(txid, blockingStubFull); + logger.info("getRet:" + ById.get().getRet(0)); + logger.info("getNumber:" + ById.get().getRet(0).getContractRet().getNumber()); + logger.info("getContractRetValue:" + ById.get().getRet(0).getContractRetValue()); + logger.info("getContractRet:" + ById.get().getRet(0).getContractRet()); + + Assert.assertEquals(ById.get().getRet(0).getContractRet().getNumber(), + ILLEGAL_OPERATION_VALUE); + Assert.assertEquals(ById.get().getRet(0).getContractRetValue(), ILLEGAL_OPERATION_VALUE); + Assert.assertEquals(ById.get().getRet(0).getContractRet(), contractResult.ILLEGAL_OPERATION); + + Assert + .assertEquals(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()), ""); + Assert.assertEquals(contractResult.ILLEGAL_OPERATION, infoById.get().getReceipt().getResult()); + + } + + + @Test(enabled = true, description = "ContractResult is REVERT") + public void test6Grammar006() { + ecKey1 = new ECKey(Utils.getRandom()); + grammarAddress = ecKey1.getAddress(); + testKeyForGrammarAddress = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + Assert.assertTrue(PublicMethed + .sendcoin(grammarAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = + "src/test/resources/soliditycode/requireExceptiontest1TestRequireContract.sol"; + String contractName = "TestThrowsContract"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, testKeyForGrammarAddress, + grammarAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + final String txid = PublicMethed.triggerContract(contractAddress, + "testRequire()", "#", false, + 0, maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + logger.info("infoById:" + infoById); + Optional ById = PublicMethed.getTransactionById(txid, blockingStubFull); + logger.info("getRet:" + ById.get().getRet(0)); + logger.info("getNumber:" + ById.get().getRet(0).getContractRet().getNumber()); + logger.info("getContractRetValue:" + ById.get().getRet(0).getContractRetValue()); + logger.info("getContractRet:" + ById.get().getRet(0).getContractRet()); + + Assert.assertEquals(ById.get().getRet(0).getContractRet().getNumber(), + REVERT_VALUE); + Assert.assertEquals(ById.get().getRet(0).getContractRetValue(), REVERT_VALUE); + Assert.assertEquals(ById.get().getRet(0).getContractRet(), contractResult.REVERT); + + Assert + .assertEquals(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()), ""); + Assert.assertEquals(contractResult.REVERT, infoById.get().getReceipt().getResult()); + + } + + @Test(enabled = true, description = "ContractResult is SUCCESS") + public void test7Grammar007() { + ecKey1 = new ECKey(Utils.getRandom()); + grammarAddress = ecKey1.getAddress(); + testKeyForGrammarAddress = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + Assert.assertTrue(PublicMethed + .sendcoin(grammarAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + String filePath = "src/test/resources/soliditycode/assertExceptiontest1DivideInt.sol"; + String contractName = "divideIHaveArgsReturnStorage"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, testKeyForGrammarAddress, + grammarAddress, blockingStubFull); + Account info; + PublicMethed.waitProduceNextBlock(blockingStubFull); + + String txid = ""; + String num = "4" + "," + "2"; + + txid = PublicMethed.triggerContract(contractAddress, + "divideIHaveArgsReturn(int256,int256)", num, false, + 0, maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull1); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + logger.info("infoById:" + infoById); + Optional ById = PublicMethed.getTransactionById(txid, blockingStubFull); + logger.info("getRet:" + ById.get().getRet(0)); + logger.info("getNumber:" + ById.get().getRet(0).getContractRet().getNumber()); + logger.info("getContractRetValue:" + ById.get().getRet(0).getContractRetValue()); + logger.info("getContractRet:" + ById.get().getRet(0).getContractRet()); + + Assert.assertEquals(ById.get().getRet(0).getContractRet().getNumber(), + contractResult.SUCCESS_VALUE); + Assert.assertEquals(ById.get().getRet(0).getContractRetValue(), contractResult.SUCCESS_VALUE); + Assert.assertEquals(ById.get().getRet(0).getContractRet(), contractResult.SUCCESS); + + Assert.assertEquals(contractResult.SUCCESS, infoById.get().getReceipt().getResult()); + + Assert + .assertEquals(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()), + "0000000000000000000000000000000000000000000000000000000000000002"); + + } + + + @Test(enabled = true, description = "ContractResult is TRANSFER_FAILED") + public void test8Grammar008() { + ecKey1 = new ECKey(Utils.getRandom()); + grammarAddress = ecKey1.getAddress(); + testKeyForGrammarAddress = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + Assert.assertTrue(PublicMethed + .sendcoin(grammarAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; + String contractName = "EnergyOfTransferFailedTest"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, testKeyForGrammarAddress, + grammarAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Assert.assertTrue(PublicMethed + .sendcoin(contractAddress, 1000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + + Account info; + + AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(grammarAddress, + blockingStubFull); + info = PublicMethed.queryAccount(testKeyForGrammarAddress, blockingStubFull); + Long beforeBalance = info.getBalance(); + Long beforeEnergyUsed = resourceInfo.getEnergyUsed(); + Long beforeNetUsed = resourceInfo.getNetUsed(); + Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); + logger.info("beforeBalance:" + beforeBalance); + logger.info("beforeEnergyUsed:" + beforeEnergyUsed); + logger.info("beforeNetUsed:" + beforeNetUsed); + logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); + ECKey ecKey2 = new ECKey(Utils.getRandom()); + byte[] nonexistentAddress = ecKey2.getAddress(); + String txid = ""; + String num = "1" + ",\"" + Base58.encode58Check(nonexistentAddress) + "\""; + + txid = PublicMethed.triggerContract(contractAddress, + "testTransferTrxNonexistentTarget(uint256,address)", num, false, + 0, maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull); + Optional infoById = null; + PublicMethed.waitProduceNextBlock(blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull1); + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + logger.info("infobyid : --- " + infoById); + + Long fee = infoById.get().getFee(); + Long netUsed = infoById.get().getReceipt().getNetUsage(); + Long energyUsed = infoById.get().getReceipt().getEnergyUsage(); + Long netFee = infoById.get().getReceipt().getNetFee(); + long energyUsageTotal = infoById.get().getReceipt().getEnergyUsageTotal(); + logger.info("fee:" + fee); + logger.info("netUsed:" + netUsed); + logger.info("energyUsed:" + energyUsed); + logger.info("netFee:" + netFee); + logger.info("energyUsageTotal:" + energyUsageTotal); + + Account infoafter = PublicMethed.queryAccount(testKeyForGrammarAddress, blockingStubFull1); + AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(grammarAddress, + blockingStubFull1); + Long afterBalance = infoafter.getBalance(); + Long afterEnergyUsed = resourceInfoafter.getEnergyUsed(); + Long afterNetUsed = resourceInfoafter.getNetUsed(); + Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); + logger.info("afterBalance:" + afterBalance); + logger.info("afterEnergyUsed:" + afterEnergyUsed); + logger.info("afterNetUsed:" + afterNetUsed); + logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + + Assert.assertTrue(infoById.get().getResultValue() == 1); + Assert.assertEquals(contractResult.TRANSFER_FAILED, infoById.get().getReceipt().getResult()); + Assert.assertEquals( + "transfer trx failed: Validate InternalTransfer error, no ToAccount." + + " And not allowed to create account in smart contract.", + ByteArray.toStr(infoById.get().getResMessage().toByteArray())); + + Assert.assertTrue(afterBalance + fee == beforeBalance); + Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); + Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); + Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); + Assert.assertNotEquals(10000000, energyUsageTotal); + + + } + + + @Test(enabled = true, description = "ContractResult is STACK_TOO_SMALL") + public void test9Grammar009() { + ecKey1 = new ECKey(Utils.getRandom()); + grammarAddress = ecKey1.getAddress(); + testKeyForGrammarAddress = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + Assert.assertTrue(PublicMethed + .sendcoin(grammarAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + String contractName = "TestThrowsContract"; + String abi = "[{\"constant\":false,\"inputs\":[],\"name\":\"testStackTooSmall\",\"outputs\":[],\"payable\":false,\"type\":\"function\",\"stateMutability\":\"nonpayable\"}]"; + String code = "60606040523415600b57fe5b5b60608060196000396000f300606060405263ffffffff60e060020a6000350416632f3a24cc81146020575bfe5b3415602757fe5b602d602f565b005b50505b5600a165627a7a723058208184f2ff2627a8a490bfd1233a891f2f4605375d0fec375e237ffc188cdd7ec70029"; + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, testKeyForGrammarAddress, + grammarAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + final String txid = PublicMethed.triggerContract(contractAddress, + "testStackTooSmall()", "#", false, + 0, maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + logger.info("infoById:" + infoById); + Optional ById = PublicMethed.getTransactionById(txid, blockingStubFull); + logger.info("getRet:" + ById.get().getRet(0)); + logger.info("getNumber:" + ById.get().getRet(0).getContractRet().getNumber()); + logger.info("getContractRetValue:" + ById.get().getRet(0).getContractRetValue()); + logger.info("getContractRet:" + ById.get().getRet(0).getContractRet()); + + Assert.assertEquals(ById.get().getRet(0).getContractRet().getNumber(), + STACK_TOO_SMALL_VALUE); + Assert.assertEquals(ById.get().getRet(0).getContractRetValue(), STACK_TOO_SMALL_VALUE); + Assert.assertEquals(ById.get().getRet(0).getContractRet(), contractResult.STACK_TOO_SMALL); + + Assert + .assertEquals(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()), ""); + Assert.assertEquals(contractResult.STACK_TOO_SMALL, infoById.get().getReceipt().getResult()); + + } + + @Test(enabled = true, description = "ContractResult is STACK_TOO_LARGE") + public void test9Grammar010() { + ecKey1 = new ECKey(Utils.getRandom()); + grammarAddress = ecKey1.getAddress(); + testKeyForGrammarAddress = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + Assert.assertTrue(PublicMethed + .sendcoin(grammarAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + String contractName = "TestThrowsContract"; + String abi = "[{\"constant\":false,\"inputs\":[],\"name\":\"testStackTooLarge\",\"outputs\":[],\"payable\":false,\"type\":\"function\",\"stateMutability\":\"nonpayable\"}]"; + String code = "6060604052341561000c57fe5b5b610b658061001c6000396000f300606060405263ffffffff60e060020a600035041663f7d9c5c68114610021575bfe5b341561002957fe5b610031610033565b005b6000600160026003600460056006600760086009600a600b600c600d600e600f6010601160126013601460156016601760186019601a601b601c601d601e601f6020602160226023602460256026602760286029602a602b602c602d602e602f6030603160326033603460356036603760386039603a603b603c603d603e603f6040604160426043604460456046604760486049604a604b604c604d604e604f6050605160526053605460556056605760586059605a605b605c605d605e605f6060606160626063606460656066606760686069606a606b606c606d606e606f6070607160726073607460756076607760786079607a607b607c607d607e607f6080608160826083608460856086608760886089608a608b608c608d608e608f6090609160926093609460956096609760986099609a609b609c609d609e609f60a060a160a260a360a460a560a660a760a860a960aa60ab60ac60ad60ae60af60b060b160b260b360b460b560b660b760b860b960ba60bb60bc60bd60be60bf60c060c160c260c360c460c560c660c760c860c960ca60cb60cc60cd60ce60cf60d060d160d260d360d460d560d660d760d860d960da60db60dc60dd60de60df60e060e160e260e360e460e560e660e760e860e960ea60eb60ec60ed60ee60ef60f060f160f260f360f460f560f660f760f860f960fa60fb60fc60fd60fe60ff61010061010161010261010361010461010561010661010761010861010961010a61010b61010c61010d61010e61010f61011061011161011261011361011461011561011661011761011861011961011a61011b61011c61011d61011e61011f61012061012161012261012361012461012561012661012761012861012961012a61012b61012c61012d61012e61012f61013061013161013261013361013461013561013661013761013861013961013a61013b61013c61013d61013e61013f61014061014161014261014361014461014561014661014761014861014961014a61014b61014c61014d61014e61014f61015061015161015261015361015461015561015661015761015861015961015a61015b61015c61015d61015e61015f61016061016161016261016361016461016561016661016761016861016961016a61016b61016c61016d61016e61016f61017061017161017261017361017461017561017661017761017861017961017a61017b61017c61017d61017e61017f61018061018161018261018361018461018561018661018761018861018961018a61018b61018c61018d61018e61018f61019061019161019261019361019461019561019661019761019861019961019a61019b61019c61019d61019e61019f6101a06101a16101a26101a36101a46101a56101a66101a76101a86101a96101aa6101ab6101ac6101ad6101ae6101af6101b06101b16101b26101b36101b46101b56101b66101b76101b86101b96101ba6101bb6101bc6101bd6101be6101bf6101c06101c16101c26101c36101c46101c56101c66101c76101c86101c96101ca6101cb6101cc6101cd6101ce6101cf6101d06101d16101d26101d36101d46101d56101d66101d76101d86101d96101da6101db6101dc6101dd6101de6101df6101e06101e16101e26101e36101e46101e56101e66101e76101e86101e96101ea6101eb6101ec6101ed6101ee6101ef6101f06101f16101f26101f36101f46101f56101f66101f76101f86101f96101fa6101fb6101fc6101fd6101fe6101ff61020061020161020261020361020461020561020661020761020861020961020a61020b61020c61020d61020e61020f61021061021161021261021361021461021561021661021761021861021961021a61021b61021c61021d61021e61021f61022061022161022261022361022461022561022661022761022861022961022a61022b61022c61022d61022e61022f61023061023161023261023361023461023561023661023761023861023961023a61023b61023c61023d61023e61023f61024061024161024261024361024461024561024661024761024861024961024a61024b61024c61024d61024e61024f61025061025161025261025361025461025561025661025761025861025961025a61025b61025c61025d61025e61025f61026061026161026261026361026461026561026661026761026861026961026a61026b61026c61026d61026e61026f61027061027161027261027361027461027561027661027761027861027961027a61027b61027c61027d61027e61027f61028061028161028261028361028461028561028661028761028861028961028a61028b61028c61028d61028e61028f61029061029161029261029361029461029561029661029761029861029961029a61029b61029c61029d61029e61029f6102a06102a16102a26102a36102a46102a56102a66102a76102a86102a96102aa6102ab6102ac6102ad6102ae6102af6102b06102b16102b26102b36102b46102b56102b66102b76102b86102b96102ba6102bb6102bc6102bd6102be6102bf6102c06102c16102c26102c36102c46102c56102c66102c76102c86102c96102ca6102cb6102cc6102cd6102ce6102cf6102d06102d16102d26102d36102d46102d56102d66102d76102d86102d96102da6102db6102dc6102dd6102de6102df6102e06102e16102e26102e36102e46102e56102e66102e76102e86102e96102ea6102eb6102ec6102ed6102ee6102ef6102f06102f16102f26102f36102f46102f56102f66102f76102f86102f96102fa6102fb6102fc6102fd6102fe6102ff61030061030161030261030361030461030561030661030761030861030961030a61030b61030c61030d61030e61030f61031061031161031261031361031461031561031661031761031861031961031a61031b61031c61031d61031e61031f61032061032161032261032361032461032561032661032761032861032961032a61032b61032c61032d61032e61032f61033061033161033261033361033461033561033661033761033861033961033a61033b61033c61033d61033e61033f61034061034161034261034361034461034561034661034761034861034961034a61034b61034c61034d61034e61034f61035061035161035261035361035461035561035661035761035861035961035a61035b61035c61035d61035e61035f61036061036161036261036361036461036561036661036761036861036961036a61036b61036c61036d61036e61036f61037061037161037261037361037461037561037661037761037861037961037a61037b61037c61037d61037e61037f61038061038161038261038361038461038561038661038761038861038961038a61038b61038c61038d61038e61038f61039061039161039261039361039461039561039661039761039861039961039a61039b61039c61039d61039e61039f6103a06103a16103a26103a36103a46103a56103a66103a76103a86103a96103aa6103ab6103ac6103ad6103ae6103af6103b06103b16103b26103b36103b46103b56103b66103b76103b86103b96103ba6103bb6103bc6103bd6103be6103bf6103c06103c16103c26103c36103c46103c56103c66103c76103c86103c96103ca6103cb6103cc6103cd6103ce6103cf6103d06103d16103d26103d36103d46103d56103d66103d76103d86103d96103da6103db6103dc6103dd6103de6103df6103e06103e16103e26103e36103e46103e56103e66103e76103e86103e96103ea6103eb6103ec6103ed6103ee6103ef6103f06103f16103f26103f36103f46103f56103f66103f76103f86103f96103fa6103fb6103fc6103fd6103fe6103ff6104005b5600a165627a7a72305820998f09cc267db91352a3d0a4ab60ea08fc306fa8bc6dd78dc324a06109dcf0420029"; + contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, + 0L, 100, null, testKeyForGrammarAddress, + grammarAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + + final String txid = PublicMethed.triggerContract(contractAddress, + "testStackTooLarge()", "#", false, + 0, maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + Optional infoById = null; + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + logger.info("infoById:" + infoById); + Optional ById = PublicMethed.getTransactionById(txid, blockingStubFull); + logger.info("getRet:" + ById.get().getRet(0)); + logger.info("getNumber:" + ById.get().getRet(0).getContractRet().getNumber()); + logger.info("getContractRetValue:" + ById.get().getRet(0).getContractRetValue()); + logger.info("getContractRet:" + ById.get().getRet(0).getContractRet()); + + Assert.assertEquals(ById.get().getRet(0).getContractRet().getNumber(), + STACK_TOO_LARGE_VALUE); + Assert.assertEquals(ById.get().getRet(0).getContractRetValue(), STACK_TOO_LARGE_VALUE); + Assert.assertEquals(ById.get().getRet(0).getContractRet(), contractResult.STACK_TOO_LARGE); + + Assert + .assertEquals(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()), ""); + Assert.assertEquals(contractResult.STACK_TOO_LARGE, infoById.get().getReceipt().getResult()); + + } + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + +} diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test019.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test019.java index 5201788b6df..cce3d710083 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test019.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/create2/Create2Test019.java @@ -1,6 +1,7 @@ package stest.tron.wallet.dailybuild.tvmnewcommand.create2; import static org.hamcrest.core.StringContains.containsString; +import static org.tron.protos.Protocol.Transaction.Result.contractResult.SUCCESS_VALUE; import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; @@ -22,6 +23,8 @@ import org.tron.common.utils.Utils; import org.tron.core.Wallet; import org.tron.protos.Protocol.Account; +import org.tron.protos.Protocol.Transaction; +import org.tron.protos.Protocol.Transaction.Result.contractResult; import org.tron.protos.Protocol.TransactionInfo; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.Parameter.CommonConstant; @@ -106,9 +109,13 @@ public void testTriggerContract() { infoById0 = PublicMethed.getTransactionInfoById(sendcoin, blockingStubFull); logger.info("infoById0 " + infoById0.get()); Assert.assertEquals(ByteArray.toHexString(infoById0.get().getContractResult(0).toByteArray()), - "SUCCESS"); + ""); Assert.assertEquals(infoById0.get().getResult().getNumber(), 0); - + Optional ById = PublicMethed.getTransactionById(sendcoin, blockingStubFull); + Assert.assertEquals(ById.get().getRet(0).getContractRet().getNumber(), + SUCCESS_VALUE); + Assert.assertEquals(ById.get().getRet(0).getContractRetValue(), SUCCESS_VALUE); + Assert.assertEquals(ById.get().getRet(0).getContractRet(), contractResult.SUCCESS); String filePath = "src/test/resources/soliditycode/create2contractn2.sol"; String contractName = "Factory"; HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); diff --git a/src/test/resources/soliditycode/testOutOfMem.sol b/src/test/resources/soliditycode/testOutOfMem.sol new file mode 100644 index 00000000000..8d285b28b7d --- /dev/null +++ b/src/test/resources/soliditycode/testOutOfMem.sol @@ -0,0 +1,7 @@ +contract Test { + function testOutOfMem(uint256 x) public returns(bytes32 r) { + uint[] memory memVar; + memVar = new uint[](x); + } + +} \ No newline at end of file From 1a757395029c4a08697416eb26cbce0d59ea370f Mon Sep 17 00:00:00 2001 From: wangming Date: Tue, 18 Jun 2019 18:27:27 +0800 Subject: [PATCH 75/90] modify test case --- .../scenario/ContractScenario014.java | 12 +- .../scenario/ContractScenario015.java | 2 +- .../exceptionfee/AssertException002.java | 155 ----------- .../grammar/ContractGrammar004.java | 249 +++++++++--------- .../dailybuild/http/HttpTestSendCoin001.java | 12 +- 5 files changed, 149 insertions(+), 281 deletions(-) delete mode 100644 src/test/java/stest/tron/wallet/dailybuild/exceptionfee/AssertException002.java diff --git a/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario014.java b/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario014.java index e6dd2fbc25f..fc586aab93b 100644 --- a/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario014.java +++ b/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario014.java @@ -1,5 +1,6 @@ package stest.tron.wallet.contract.scenario; +import static org.tron.protos.Protocol.Transaction.Result.contractResult.SUCCESS_VALUE; import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; @@ -21,6 +22,8 @@ import org.tron.core.Wallet; import org.tron.protos.Protocol.Account; import org.tron.protos.Protocol.SmartContract; +import org.tron.protos.Protocol.Transaction; +import org.tron.protos.Protocol.Transaction.Result.contractResult; import org.tron.protos.Protocol.TransactionInfo; import stest.tron.wallet.common.client.Configuration; import stest.tron.wallet.common.client.Parameter.CommonConstant; @@ -130,7 +133,14 @@ public void testClearAbi() { Optional infoById = null; infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); Assert.assertEquals(0,infoById.get().getResultValue()); - Assert.assertEquals("SUCCESS",(infoById.get().getResMessage()).toString()); + Assert.assertEquals("", + ByteArray.toHexString(infoById.get().getResMessage().toByteArray())); + + Optional byId = PublicMethed.getTransactionById(txid, blockingStubFull); + Assert.assertEquals(byId.get().getRet(0).getContractRet().getNumber(), + SUCCESS_VALUE); + Assert.assertEquals(byId.get().getRet(0).getContractRetValue(), SUCCESS_VALUE); + Assert.assertEquals(byId.get().getRet(0).getContractRet(), contractResult.SUCCESS); smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); Assert.assertTrue(smartContract.getAbi().toString().isEmpty()); diff --git a/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario015.java b/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario015.java index 3f1c170091a..6c3f66de9a1 100644 --- a/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario015.java +++ b/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario015.java @@ -127,7 +127,7 @@ public void testTriggerConstantContract() { logger.info(":" + ByteArray .toStr(transactionExtention.getResult().getMessage().toByteArray())); logger.info("Result:" + Hex.toHexString(result)); - logger.info("getCode"+transactionExtention.getResult().getCode().getNumber()); + logger.info("getCode" + transactionExtention.getResult().getCode().getNumber()); Assert.assertEquals("SUCESS",transaction.getRet(0).getRet().toString()); Assert.assertEquals(1, ByteArray.toLong(ByteArray .fromHexString(Hex diff --git a/src/test/java/stest/tron/wallet/dailybuild/exceptionfee/AssertException002.java b/src/test/java/stest/tron/wallet/dailybuild/exceptionfee/AssertException002.java deleted file mode 100644 index 1dfbd7bfc01..00000000000 --- a/src/test/java/stest/tron/wallet/dailybuild/exceptionfee/AssertException002.java +++ /dev/null @@ -1,155 +0,0 @@ -package stest.tron.wallet.dailybuild.exceptionfee; - -import io.grpc.ManagedChannel; -import io.grpc.ManagedChannelBuilder; -import java.util.HashMap; -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.WalletGrpc; -import org.tron.api.WalletSolidityGrpc; -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.Transaction; -import org.tron.protos.Protocol.Transaction.Result.contractResult; -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 AssertException002 { - - - private final String testNetAccountKey = Configuration.getByPath("testng.conf") - .getString("foundationAccount.key2"); - private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); - private Long maxFeeLimit = Configuration.getByPath("testng.conf") - .getLong("defaultParameter.maxFeeLimit"); - private ManagedChannel channelSolidity = null; - - private ManagedChannel channelFull = null; - private WalletGrpc.WalletBlockingStub blockingStubFull = null; - - private ManagedChannel channelFull1 = null; - private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; - - - private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; - - private String fullnode = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(1); - private String fullnode1 = Configuration.getByPath("testng.conf") - .getStringList("fullnode.ip.list").get(0); - private String compilerVersion = Configuration.getByPath("testng.conf") - .getString("defaultParameter.solidityCompilerVersion"); - - - byte[] contractAddress = null; - - ECKey ecKey1 = new ECKey(Utils.getRandom()); - byte[] grammarAddress = ecKey1.getAddress(); - String testKeyForGrammarAddress = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - - - @BeforeSuite - public void beforeSuite() { - Wallet wallet = new Wallet(); - Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); - } - - /** - * constructor. - */ - - @BeforeClass(enabled = true) - public void beforeClass() { - PublicMethed.printAddress(testKeyForGrammarAddress); - channelFull = ManagedChannelBuilder.forTarget(fullnode) - .usePlaintext(true) - .build(); - blockingStubFull = WalletGrpc.newBlockingStub(channelFull); - channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) - .usePlaintext(true) - .build(); - blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); - } - - @Test(enabled = true, description = "Support function type") - public void test1AssertException001() { - ecKey1 = new ECKey(Utils.getRandom()); - grammarAddress = ecKey1.getAddress(); - testKeyForGrammarAddress = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - PublicMethed.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethed - .sendcoin(grammarAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); - String filePath = "src/test/resources/soliditycode/AssertException002.sol"; - String contractName = "AssertException"; - HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); - - String code = retMap.get("byteCode").toString(); - String abi = retMap.get("abI").toString(); - contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, - 0L, 100, null, testKeyForGrammarAddress, - grammarAddress, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); - - String txid = ""; - String num = "10" + "," + "0"; - txid = PublicMethed.triggerContract(contractAddress, - "divideIHaveArgsReturn(int,int)", num, false, - 0, maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull); - - - Optional infoById = null; - infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); - logger.info("infoById:" + infoById); - Optional ById = PublicMethed.getTransactionById(txid, blockingStubFull); - logger.info("getRet:" + ById.get().getRet(0)); - logger.info("getNumber:" + ById.get().getRet(0).getContractRet().getNumber()); - logger.info("getContractRetValue:" + ById.get().getRet(0).getContractRetValue()); - logger.info("getContractRet:" + ById.get().getRet(0).getContractRet()); - - Assert.assertEquals(ById.get().getRet(0).getContractRet().getNumber(), - contractResult.ILLEGAL_OPERATION_VALUE); - Assert.assertEquals(ById.get().getRet(0).getContractRetValue(), 8); - Assert.assertEquals(ById.get().getRet(0).getContractRet(), contractResult.ILLEGAL_OPERATION); - - Assert - .assertEquals(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()), ""); - Assert.assertEquals(contractResult.ILLEGAL_OPERATION, infoById.get().getReceipt().getResult()); - - logger.info("ById:" + ById); - Assert.assertEquals(ById.get().getRet(0).getRet().getNumber(), 0); - Assert.assertEquals(ById.get().getRet(0).getRetValue(), 0); - - Long returnnumber2 = ByteArray.toLong(ByteArray.fromHexString( - ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); - - Assert.assertTrue(returnnumber2 == 100); - } - - /** - * constructor. - */ - @AfterClass - public void shutdown() throws InterruptedException { - if (channelFull != null) { - channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } - if (channelFull1 != null) { - channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } - } - -} diff --git a/src/test/java/stest/tron/wallet/dailybuild/grammar/ContractGrammar004.java b/src/test/java/stest/tron/wallet/dailybuild/grammar/ContractGrammar004.java index d7e6de26d26..461163b0afe 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/grammar/ContractGrammar004.java +++ b/src/test/java/stest/tron/wallet/dailybuild/grammar/ContractGrammar004.java @@ -97,10 +97,6 @@ public void beforeClass() { @Test(enabled = true, description = "ContractResult is OUT_OF_TIME") public void test1Grammar001() { - ecKey1 = new ECKey(Utils.getRandom()); - grammarAddress = ecKey1.getAddress(); - testKeyForGrammarAddress = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - PublicMethed.waitProduceNextBlock(blockingStubFull); Assert.assertTrue(PublicMethed .sendcoin(grammarAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); @@ -152,13 +148,6 @@ public void test1Grammar001() { @Test(enabled = true, description = "ContractResult is OUT_OF_MEMORY") public void test2Grammar002() { - ecKey1 = new ECKey(Utils.getRandom()); - grammarAddress = ecKey1.getAddress(); - testKeyForGrammarAddress = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - PublicMethed.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethed - .sendcoin(grammarAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); String filePath = "./src/test/resources/soliditycode/testOutOfMem.sol"; String contractName = "Test"; HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); @@ -209,17 +198,22 @@ public void test2Grammar002() { @Test(enabled = true, description = "ContractResult is BAD_JUMP_DESTINATION") public void test3Grammar003() { - ecKey1 = new ECKey(Utils.getRandom()); - grammarAddress = ecKey1.getAddress(); - testKeyForGrammarAddress = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - PublicMethed.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethed - .sendcoin(grammarAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); String contractName = "Test"; - String code = "608060405234801561001057600080fd5b50d3801561001d57600080fd5b50d2801561002a57600080fd5b5061011f8061003a6000396000f30060806040526004361060485763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416634ef5a0088114604d5780639093b95b14608c575b600080fd5b348015605857600080fd5b50d38015606457600080fd5b50d28015607057600080fd5b50607a60043560b8565b60408051918252519081900360200190f35b348015609757600080fd5b50d3801560a357600080fd5b50d2801560af57600080fd5b5060b660ee565b005b600060608260405190808252806020026020018201604052801560e5578160200160208202803883390190505b50905050919050565b6001805600a165627a7a7230582092ba162087e13f41c6d6c00ba493edc5a5a6250a3840ece5f99aa38b66366a700029"; - String abi = "[{\"constant\":false,\"inputs\":[{\"name\":\"x\",\"type\":\"uint256\"}],\"name\":\"testOutOfMem\",\"outputs\":[{\"name\":\"r\",\"type\":\"bytes32\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"testBadJumpDestination\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]"; + String code = "608060405234801561001057600080fd5b50d3801561001d57600080fd5b50d2801561002a57600" + + "080fd5b5061011f8061003a6000396000f30060806040526004361060485763ffffffff7c01000000000000" + + "000000000000000000000000000000000000000000006000350416634ef5a0088114604d5780639093b95b1" + + "4608c575b600080fd5b348015605857600080fd5b50d38015606457600080fd5b50d28015607057600080fd" + + "5b50607a60043560b8565b60408051918252519081900360200190f35b348015609757600080fd5b50d3801" + + "560a357600080fd5b50d2801560af57600080fd5b5060b660ee565b005b6000606082604051908082528060" + + "20026020018201604052801560e5578160200160208202803883390190505b50905050919050565b6001805" + + "600a165627a7a7230582092ba162087e13f41c6d6c00ba493edc5a5a6250a3840ece5f99aa38b66366a7000" + + "29"; + String abi = "[{\"constant\":false,\"inputs\":[{\"name\":\"x\",\"type\":\"uint256\"}],\"name\"" + + ":\"testOutOfMem\",\"outputs\":[{\"name\":\"r\",\"type\":\"bytes32\"}],\"payable\":false" + + ",\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs" + + "\":[],\"name\":\"testBadJumpDestination\",\"outputs\":[],\"payable\":false,\"stateMutab" + + "ility\":\"nonpayable\",\"type\":\"function\"}]"; byte[] contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, @@ -264,14 +258,6 @@ public void test3Grammar003() { @Test(enabled = true, description = "ContractResult is OUT_OF_ENERGY") public void test4Grammar004() { - ecKey1 = new ECKey(Utils.getRandom()); - grammarAddress = ecKey1.getAddress(); - testKeyForGrammarAddress = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - PublicMethed.waitProduceNextBlock(blockingStubFull); - Assert.assertTrue(PublicMethed - .sendcoin(grammarAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); String filePath = "src/test/resources/soliditycode/contractUnknownException.sol"; String contractName = "testC"; @@ -313,13 +299,7 @@ public void test4Grammar004() { @Test(enabled = true, description = "ContractResult is ILLEGAL_OPERATION") public void test5Grammar005() { - ecKey1 = new ECKey(Utils.getRandom()); - grammarAddress = ecKey1.getAddress(); - testKeyForGrammarAddress = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - Assert.assertTrue(PublicMethed - .sendcoin(grammarAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/assertExceptiontest1DivideInt.sol"; String contractName = "divideIHaveArgsReturnStorage"; @@ -331,7 +311,6 @@ public void test5Grammar005() { contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, testKeyForGrammarAddress, grammarAddress, blockingStubFull); - Account info; PublicMethed.waitProduceNextBlock(blockingStubFull); String txid = ""; @@ -341,20 +320,19 @@ public void test5Grammar005() { "divideIHaveArgsReturn(int256,int256)", num, false, 0, maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull1); Optional infoById = null; infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); logger.info("infoById:" + infoById); - Optional ById = PublicMethed.getTransactionById(txid, blockingStubFull); - logger.info("getRet:" + ById.get().getRet(0)); - logger.info("getNumber:" + ById.get().getRet(0).getContractRet().getNumber()); - logger.info("getContractRetValue:" + ById.get().getRet(0).getContractRetValue()); - logger.info("getContractRet:" + ById.get().getRet(0).getContractRet()); + Optional byId = PublicMethed.getTransactionById(txid, blockingStubFull); + logger.info("getRet:" + byId.get().getRet(0)); + logger.info("getNumber:" + byId.get().getRet(0).getContractRet().getNumber()); + logger.info("getContractRetValue:" + byId.get().getRet(0).getContractRetValue()); + logger.info("getContractRet:" + byId.get().getRet(0).getContractRet()); - Assert.assertEquals(ById.get().getRet(0).getContractRet().getNumber(), + Assert.assertEquals(byId.get().getRet(0).getContractRet().getNumber(), ILLEGAL_OPERATION_VALUE); - Assert.assertEquals(ById.get().getRet(0).getContractRetValue(), ILLEGAL_OPERATION_VALUE); - Assert.assertEquals(ById.get().getRet(0).getContractRet(), contractResult.ILLEGAL_OPERATION); + Assert.assertEquals(byId.get().getRet(0).getContractRetValue(), ILLEGAL_OPERATION_VALUE); + Assert.assertEquals(byId.get().getRet(0).getContractRet(), contractResult.ILLEGAL_OPERATION); Assert .assertEquals(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()), ""); @@ -365,13 +343,7 @@ public void test5Grammar005() { @Test(enabled = true, description = "ContractResult is REVERT") public void test6Grammar006() { - ecKey1 = new ECKey(Utils.getRandom()); - grammarAddress = ecKey1.getAddress(); - testKeyForGrammarAddress = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - Assert.assertTrue(PublicMethed - .sendcoin(grammarAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); + String filePath = "src/test/resources/soliditycode/requireExceptiontest1TestRequireContract.sol"; String contractName = "TestThrowsContract"; @@ -390,16 +362,16 @@ public void test6Grammar006() { Optional infoById = null; infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); logger.info("infoById:" + infoById); - Optional ById = PublicMethed.getTransactionById(txid, blockingStubFull); - logger.info("getRet:" + ById.get().getRet(0)); - logger.info("getNumber:" + ById.get().getRet(0).getContractRet().getNumber()); - logger.info("getContractRetValue:" + ById.get().getRet(0).getContractRetValue()); - logger.info("getContractRet:" + ById.get().getRet(0).getContractRet()); + Optional byId = PublicMethed.getTransactionById(txid, blockingStubFull); + logger.info("getRet:" + byId.get().getRet(0)); + logger.info("getNumber:" + byId.get().getRet(0).getContractRet().getNumber()); + logger.info("getContractRetValue:" + byId.get().getRet(0).getContractRetValue()); + logger.info("getContractRet:" + byId.get().getRet(0).getContractRet()); - Assert.assertEquals(ById.get().getRet(0).getContractRet().getNumber(), + Assert.assertEquals(byId.get().getRet(0).getContractRet().getNumber(), REVERT_VALUE); - Assert.assertEquals(ById.get().getRet(0).getContractRetValue(), REVERT_VALUE); - Assert.assertEquals(ById.get().getRet(0).getContractRet(), contractResult.REVERT); + Assert.assertEquals(byId.get().getRet(0).getContractRetValue(), REVERT_VALUE); + Assert.assertEquals(byId.get().getRet(0).getContractRet(), contractResult.REVERT); Assert .assertEquals(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()), ""); @@ -409,13 +381,6 @@ public void test6Grammar006() { @Test(enabled = true, description = "ContractResult is SUCCESS") public void test7Grammar007() { - ecKey1 = new ECKey(Utils.getRandom()); - grammarAddress = ecKey1.getAddress(); - testKeyForGrammarAddress = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - Assert.assertTrue(PublicMethed - .sendcoin(grammarAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); String filePath = "src/test/resources/soliditycode/assertExceptiontest1DivideInt.sol"; String contractName = "divideIHaveArgsReturnStorage"; @@ -427,7 +392,6 @@ public void test7Grammar007() { contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, testKeyForGrammarAddress, grammarAddress, blockingStubFull); - Account info; PublicMethed.waitProduceNextBlock(blockingStubFull); String txid = ""; @@ -437,20 +401,19 @@ public void test7Grammar007() { "divideIHaveArgsReturn(int256,int256)", num, false, 0, maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull1); Optional infoById = null; infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); logger.info("infoById:" + infoById); - Optional ById = PublicMethed.getTransactionById(txid, blockingStubFull); - logger.info("getRet:" + ById.get().getRet(0)); - logger.info("getNumber:" + ById.get().getRet(0).getContractRet().getNumber()); - logger.info("getContractRetValue:" + ById.get().getRet(0).getContractRetValue()); - logger.info("getContractRet:" + ById.get().getRet(0).getContractRet()); + Optional byId = PublicMethed.getTransactionById(txid, blockingStubFull); + logger.info("getRet:" + byId.get().getRet(0)); + logger.info("getNumber:" + byId.get().getRet(0).getContractRet().getNumber()); + logger.info("getContractRetValue:" + byId.get().getRet(0).getContractRetValue()); + logger.info("getContractRet:" + byId.get().getRet(0).getContractRet()); - Assert.assertEquals(ById.get().getRet(0).getContractRet().getNumber(), + Assert.assertEquals(byId.get().getRet(0).getContractRet().getNumber(), contractResult.SUCCESS_VALUE); - Assert.assertEquals(ById.get().getRet(0).getContractRetValue(), contractResult.SUCCESS_VALUE); - Assert.assertEquals(ById.get().getRet(0).getContractRet(), contractResult.SUCCESS); + Assert.assertEquals(byId.get().getRet(0).getContractRetValue(), contractResult.SUCCESS_VALUE); + Assert.assertEquals(byId.get().getRet(0).getContractRet(), contractResult.SUCCESS); Assert.assertEquals(contractResult.SUCCESS, infoById.get().getReceipt().getResult()); @@ -463,12 +426,6 @@ public void test7Grammar007() { @Test(enabled = true, description = "ContractResult is TRANSFER_FAILED") public void test8Grammar008() { - ecKey1 = new ECKey(Utils.getRandom()); - grammarAddress = ecKey1.getAddress(); - testKeyForGrammarAddress = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - Assert.assertTrue(PublicMethed - .sendcoin(grammarAddress, 10000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); String filePath = "src/test/resources/soliditycode/TransferFailed001.sol"; String contractName = "EnergyOfTransferFailedTest"; HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); @@ -506,7 +463,6 @@ public void test8Grammar008() { 0, maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull); Optional infoById = null; PublicMethed.waitProduceNextBlock(blockingStubFull); - PublicMethed.waitProduceNextBlock(blockingStubFull1); infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); logger.info("infobyid : --- " + infoById); @@ -552,17 +508,13 @@ public void test8Grammar008() { @Test(enabled = true, description = "ContractResult is STACK_TOO_SMALL") public void test9Grammar009() { - ecKey1 = new ECKey(Utils.getRandom()); - grammarAddress = ecKey1.getAddress(); - testKeyForGrammarAddress = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - Assert.assertTrue(PublicMethed - .sendcoin(grammarAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); String contractName = "TestThrowsContract"; - String abi = "[{\"constant\":false,\"inputs\":[],\"name\":\"testStackTooSmall\",\"outputs\":[],\"payable\":false,\"type\":\"function\",\"stateMutability\":\"nonpayable\"}]"; - String code = "60606040523415600b57fe5b5b60608060196000396000f300606060405263ffffffff60e060020a6000350416632f3a24cc81146020575bfe5b3415602757fe5b602d602f565b005b50505b5600a165627a7a723058208184f2ff2627a8a490bfd1233a891f2f4605375d0fec375e237ffc188cdd7ec70029"; + String abi = "[{\"constant\":false,\"inputs\":[],\"name\":\"testStackTooSmall\",\"outputs\":[]" + + ",\"payable\":false,\"type\":\"function\",\"stateMutability\":\"nonpayable\"}]"; + String code = "60606040523415600b57fe5b5b60608060196000396000f300606060405263ffffffff60e060020" + + "a6000350416632f3a24cc81146020575bfe5b3415602757fe5b602d602f565b005b50505b5600a165627a7a" + + "723058208184f2ff2627a8a490bfd1233a891f2f4605375d0fec375e237ffc188cdd7ec70029"; contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, testKeyForGrammarAddress, grammarAddress, blockingStubFull); @@ -575,16 +527,16 @@ public void test9Grammar009() { Optional infoById = null; infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); logger.info("infoById:" + infoById); - Optional ById = PublicMethed.getTransactionById(txid, blockingStubFull); - logger.info("getRet:" + ById.get().getRet(0)); - logger.info("getNumber:" + ById.get().getRet(0).getContractRet().getNumber()); - logger.info("getContractRetValue:" + ById.get().getRet(0).getContractRetValue()); - logger.info("getContractRet:" + ById.get().getRet(0).getContractRet()); + Optional byId = PublicMethed.getTransactionById(txid, blockingStubFull); + logger.info("getRet:" + byId.get().getRet(0)); + logger.info("getNumber:" + byId.get().getRet(0).getContractRet().getNumber()); + logger.info("getContractRetValue:" + byId.get().getRet(0).getContractRetValue()); + logger.info("getContractRet:" + byId.get().getRet(0).getContractRet()); - Assert.assertEquals(ById.get().getRet(0).getContractRet().getNumber(), + Assert.assertEquals(byId.get().getRet(0).getContractRet().getNumber(), STACK_TOO_SMALL_VALUE); - Assert.assertEquals(ById.get().getRet(0).getContractRetValue(), STACK_TOO_SMALL_VALUE); - Assert.assertEquals(ById.get().getRet(0).getContractRet(), contractResult.STACK_TOO_SMALL); + Assert.assertEquals(byId.get().getRet(0).getContractRetValue(), STACK_TOO_SMALL_VALUE); + Assert.assertEquals(byId.get().getRet(0).getContractRet(), contractResult.STACK_TOO_SMALL); Assert .assertEquals(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()), ""); @@ -594,17 +546,78 @@ public void test9Grammar009() { @Test(enabled = true, description = "ContractResult is STACK_TOO_LARGE") public void test9Grammar010() { - ecKey1 = new ECKey(Utils.getRandom()); - grammarAddress = ecKey1.getAddress(); - testKeyForGrammarAddress = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); - Assert.assertTrue(PublicMethed - .sendcoin(grammarAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, - blockingStubFull)); - PublicMethed.waitProduceNextBlock(blockingStubFull); String contractName = "TestThrowsContract"; - String abi = "[{\"constant\":false,\"inputs\":[],\"name\":\"testStackTooLarge\",\"outputs\":[],\"payable\":false,\"type\":\"function\",\"stateMutability\":\"nonpayable\"}]"; - String code = "6060604052341561000c57fe5b5b610b658061001c6000396000f300606060405263ffffffff60e060020a600035041663f7d9c5c68114610021575bfe5b341561002957fe5b610031610033565b005b6000600160026003600460056006600760086009600a600b600c600d600e600f6010601160126013601460156016601760186019601a601b601c601d601e601f6020602160226023602460256026602760286029602a602b602c602d602e602f6030603160326033603460356036603760386039603a603b603c603d603e603f6040604160426043604460456046604760486049604a604b604c604d604e604f6050605160526053605460556056605760586059605a605b605c605d605e605f6060606160626063606460656066606760686069606a606b606c606d606e606f6070607160726073607460756076607760786079607a607b607c607d607e607f6080608160826083608460856086608760886089608a608b608c608d608e608f6090609160926093609460956096609760986099609a609b609c609d609e609f60a060a160a260a360a460a560a660a760a860a960aa60ab60ac60ad60ae60af60b060b160b260b360b460b560b660b760b860b960ba60bb60bc60bd60be60bf60c060c160c260c360c460c560c660c760c860c960ca60cb60cc60cd60ce60cf60d060d160d260d360d460d560d660d760d860d960da60db60dc60dd60de60df60e060e160e260e360e460e560e660e760e860e960ea60eb60ec60ed60ee60ef60f060f160f260f360f460f560f660f760f860f960fa60fb60fc60fd60fe60ff61010061010161010261010361010461010561010661010761010861010961010a61010b61010c61010d61010e61010f61011061011161011261011361011461011561011661011761011861011961011a61011b61011c61011d61011e61011f61012061012161012261012361012461012561012661012761012861012961012a61012b61012c61012d61012e61012f61013061013161013261013361013461013561013661013761013861013961013a61013b61013c61013d61013e61013f61014061014161014261014361014461014561014661014761014861014961014a61014b61014c61014d61014e61014f61015061015161015261015361015461015561015661015761015861015961015a61015b61015c61015d61015e61015f61016061016161016261016361016461016561016661016761016861016961016a61016b61016c61016d61016e61016f61017061017161017261017361017461017561017661017761017861017961017a61017b61017c61017d61017e61017f61018061018161018261018361018461018561018661018761018861018961018a61018b61018c61018d61018e61018f61019061019161019261019361019461019561019661019761019861019961019a61019b61019c61019d61019e61019f6101a06101a16101a26101a36101a46101a56101a66101a76101a86101a96101aa6101ab6101ac6101ad6101ae6101af6101b06101b16101b26101b36101b46101b56101b66101b76101b86101b96101ba6101bb6101bc6101bd6101be6101bf6101c06101c16101c26101c36101c46101c56101c66101c76101c86101c96101ca6101cb6101cc6101cd6101ce6101cf6101d06101d16101d26101d36101d46101d56101d66101d76101d86101d96101da6101db6101dc6101dd6101de6101df6101e06101e16101e26101e36101e46101e56101e66101e76101e86101e96101ea6101eb6101ec6101ed6101ee6101ef6101f06101f16101f26101f36101f46101f56101f66101f76101f86101f96101fa6101fb6101fc6101fd6101fe6101ff61020061020161020261020361020461020561020661020761020861020961020a61020b61020c61020d61020e61020f61021061021161021261021361021461021561021661021761021861021961021a61021b61021c61021d61021e61021f61022061022161022261022361022461022561022661022761022861022961022a61022b61022c61022d61022e61022f61023061023161023261023361023461023561023661023761023861023961023a61023b61023c61023d61023e61023f61024061024161024261024361024461024561024661024761024861024961024a61024b61024c61024d61024e61024f61025061025161025261025361025461025561025661025761025861025961025a61025b61025c61025d61025e61025f61026061026161026261026361026461026561026661026761026861026961026a61026b61026c61026d61026e61026f61027061027161027261027361027461027561027661027761027861027961027a61027b61027c61027d61027e61027f61028061028161028261028361028461028561028661028761028861028961028a61028b61028c61028d61028e61028f61029061029161029261029361029461029561029661029761029861029961029a61029b61029c61029d61029e61029f6102a06102a16102a26102a36102a46102a56102a66102a76102a86102a96102aa6102ab6102ac6102ad6102ae6102af6102b06102b16102b26102b36102b46102b56102b66102b76102b86102b96102ba6102bb6102bc6102bd6102be6102bf6102c06102c16102c26102c36102c46102c56102c66102c76102c86102c96102ca6102cb6102cc6102cd6102ce6102cf6102d06102d16102d26102d36102d46102d56102d66102d76102d86102d96102da6102db6102dc6102dd6102de6102df6102e06102e16102e26102e36102e46102e56102e66102e76102e86102e96102ea6102eb6102ec6102ed6102ee6102ef6102f06102f16102f26102f36102f46102f56102f66102f76102f86102f96102fa6102fb6102fc6102fd6102fe6102ff61030061030161030261030361030461030561030661030761030861030961030a61030b61030c61030d61030e61030f61031061031161031261031361031461031561031661031761031861031961031a61031b61031c61031d61031e61031f61032061032161032261032361032461032561032661032761032861032961032a61032b61032c61032d61032e61032f61033061033161033261033361033461033561033661033761033861033961033a61033b61033c61033d61033e61033f61034061034161034261034361034461034561034661034761034861034961034a61034b61034c61034d61034e61034f61035061035161035261035361035461035561035661035761035861035961035a61035b61035c61035d61035e61035f61036061036161036261036361036461036561036661036761036861036961036a61036b61036c61036d61036e61036f61037061037161037261037361037461037561037661037761037861037961037a61037b61037c61037d61037e61037f61038061038161038261038361038461038561038661038761038861038961038a61038b61038c61038d61038e61038f61039061039161039261039361039461039561039661039761039861039961039a61039b61039c61039d61039e61039f6103a06103a16103a26103a36103a46103a56103a66103a76103a86103a96103aa6103ab6103ac6103ad6103ae6103af6103b06103b16103b26103b36103b46103b56103b66103b76103b86103b96103ba6103bb6103bc6103bd6103be6103bf6103c06103c16103c26103c36103c46103c56103c66103c76103c86103c96103ca6103cb6103cc6103cd6103ce6103cf6103d06103d16103d26103d36103d46103d56103d66103d76103d86103d96103da6103db6103dc6103dd6103de6103df6103e06103e16103e26103e36103e46103e56103e66103e76103e86103e96103ea6103eb6103ec6103ed6103ee6103ef6103f06103f16103f26103f36103f46103f56103f66103f76103f86103f96103fa6103fb6103fc6103fd6103fe6103ff6104005b5600a165627a7a72305820998f09cc267db91352a3d0a4ab60ea08fc306fa8bc6dd78dc324a06109dcf0420029"; + String abi = "[{\"constant\":false,\"inputs\":[],\"name\":\"testStackTooLarge\",\"outputs\":[]" + + ",\"payable\":false,\"type\":\"function\",\"stateMutability\":\"nonpayable\"}]"; + String code = "6060604052341561000c57fe5b5b610b658061001c6000396000f300606060405263ffffffff60e" + + "060020a600035041663f7d9c5c68114610021575bfe5b341561002957fe5b610031610033565b005b600060" + + "0160026003600460056006600760086009600a600b600c600d600e600f60106011601260136014601560166" + + "01760186019601a601b601c601d601e601f6020602160226023602460256026602760286029602a602b602c" + + "602d602e602f6030603160326033603460356036603760386039603a603b603c603d603e603f60406041604" + + "26043604460456046604760486049604a604b604c604d604e604f6050605160526053605460556056605760" + + "586059605a605b605c605d605e605f6060606160626063606460656066606760686069606a606b606c606d6" + + "06e606f6070607160726073607460756076607760786079607a607b607c607d607e607f6080608160826083" + + "608460856086608760886089608a608b608c608d608e608f609060916092609360946095609660976098609" + + "9609a609b609c609d609e609f60a060a160a260a360a460a560a660a760a860a960aa60ab60ac60ad60ae60" + + "af60b060b160b260b360b460b560b660b760b860b960ba60bb60bc60bd60be60bf60c060c160c260c360c46" + + "0c560c660c760c860c960ca60cb60cc60cd60ce60cf60d060d160d260d360d460d560d660d760d860d960da" + + "60db60dc60dd60de60df60e060e160e260e360e460e560e660e760e860e960ea60eb60ec60ed60ee60ef60f" + + "060f160f260f360f460f560f660f760f860f960fa60fb60fc60fd60fe60ff61010061010161010261010361" + + "010461010561010661010761010861010961010a61010b61010c61010d61010e61010f61011061011161011" + + "261011361011461011561011661011761011861011961011a61011b61011c61011d61011e61011f61012061" + + "012161012261012361012461012561012661012761012861012961012a61012b61012c61012d61012e61012" + + "f61013061013161013261013361013461013561013661013761013861013961013a61013b61013c61013d61" + + "013e61013f61014061014161014261014361014461014561014661014761014861014961014a61014b61014" + + "c61014d61014e61014f61015061015161015261015361015461015561015661015761015861015961015a61" + + "015b61015c61015d61015e61015f61016061016161016261016361016461016561016661016761016861016" + + "961016a61016b61016c61016d61016e61016f61017061017161017261017361017461017561017661017761" + + "017861017961017a61017b61017c61017d61017e61017f61018061018161018261018361018461018561018" + + "661018761018861018961018a61018b61018c61018d61018e61018f61019061019161019261019361019461" + + "019561019661019761019861019961019a61019b61019c61019d61019e61019f6101a06101a16101a26101a" + + "36101a46101a56101a66101a76101a86101a96101aa6101ab6101ac6101ad6101ae6101af6101b06101b161" + + "01b26101b36101b46101b56101b66101b76101b86101b96101ba6101bb6101bc6101bd6101be6101bf6101c" + + "06101c16101c26101c36101c46101c56101c66101c76101c86101c96101ca6101cb6101cc6101cd6101ce61" + + "01cf6101d06101d16101d26101d36101d46101d56101d66101d76101d86101d96101da6101db6101dc6101d" + + "d6101de6101df6101e06101e16101e26101e36101e46101e56101e66101e76101e86101e96101ea6101eb61" + + "01ec6101ed6101ee6101ef6101f06101f16101f26101f36101f46101f56101f66101f76101f86101f96101f" + + "a6101fb6101fc6101fd6101fe6101ff61020061020161020261020361020461020561020661020761020861" + + "020961020a61020b61020c61020d61020e61020f61021061021161021261021361021461021561021661021" + + "761021861021961021a61021b61021c61021d61021e61021f61022061022161022261022361022461022561" + + "022661022761022861022961022a61022b61022c61022d61022e61022f61023061023161023261023361023" + + "461023561023661023761023861023961023a61023b61023c61023d61023e61023f61024061024161024261" + + "024361024461024561024661024761024861024961024a61024b61024c61024d61024e61024f61025061025" + + "161025261025361025461025561025661025761025861025961025a61025b61025c61025d61025e61025f61" + + "026061026161026261026361026461026561026661026761026861026961026a61026b61026c61026d61026" + + "e61026f61027061027161027261027361027461027561027661027761027861027961027a61027b61027c61" + + "027d61027e61027f61028061028161028261028361028461028561028661028761028861028961028a61028" + + "b61028c61028d61028e61028f61029061029161029261029361029461029561029661029761029861029961" + + "029a61029b61029c61029d61029e61029f6102a06102a16102a26102a36102a46102a56102a66102a76102a" + + "86102a96102aa6102ab6102ac6102ad6102ae6102af6102b06102b16102b26102b36102b46102b56102b661" + + "02b76102b86102b96102ba6102bb6102bc6102bd6102be6102bf6102c06102c16102c26102c36102c46102c" + + "56102c66102c76102c86102c96102ca6102cb6102cc6102cd6102ce6102cf6102d06102d16102d26102d361" + + "02d46102d56102d66102d76102d86102d96102da6102db6102dc6102dd6102de6102df6102e06102e16102e" + + "26102e36102e46102e56102e66102e76102e86102e96102ea6102eb6102ec6102ed6102ee6102ef6102f061" + + "02f16102f26102f36102f46102f56102f66102f76102f86102f96102fa6102fb6102fc6102fd6102fe6102f" + + "f61030061030161030261030361030461030561030661030761030861030961030a61030b61030c61030d61" + + "030e61030f61031061031161031261031361031461031561031661031761031861031961031a61031b61031" + + "c61031d61031e61031f61032061032161032261032361032461032561032661032761032861032961032a61" + + "032b61032c61032d61032e61032f61033061033161033261033361033461033561033661033761033861033" + + "961033a61033b61033c61033d61033e61033f61034061034161034261034361034461034561034661034761" + + "034861034961034a61034b61034c61034d61034e61034f61035061035161035261035361035461035561035" + + "661035761035861035961035a61035b61035c61035d61035e61035f61036061036161036261036361036461" + + "036561036661036761036861036961036a61036b61036c61036d61036e61036f61037061037161037261037" + + "361037461037561037661037761037861037961037a61037b61037c61037d61037e61037f61038061038161" + + "038261038361038461038561038661038761038861038961038a61038b61038c61038d61038e61038f61039" + + "061039161039261039361039461039561039661039761039861039961039a61039b61039c61039d61039e61" + + "039f6103a06103a16103a26103a36103a46103a56103a66103a76103a86103a96103aa6103ab6103ac6103a" + + "d6103ae6103af6103b06103b16103b26103b36103b46103b56103b66103b76103b86103b96103ba6103bb61" + + "03bc6103bd6103be6103bf6103c06103c16103c26103c36103c46103c56103c66103c76103c86103c96103c" + + "a6103cb6103cc6103cd6103ce6103cf6103d06103d16103d26103d36103d46103d56103d66103d76103d861" + + "03d96103da6103db6103dc6103dd6103de6103df6103e06103e16103e26103e36103e46103e56103e66103e" + + "76103e86103e96103ea6103eb6103ec6103ed6103ee6103ef6103f06103f16103f26103f36103f46103f561" + + "03f66103f76103f86103f96103fa6103fb6103fc6103fd6103fe6103ff6104005b5600a165627a7a7230582" + + "0998f09cc267db91352a3d0a4ab60ea08fc306fa8bc6dd78dc324a06109dcf0420029"; contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, testKeyForGrammarAddress, grammarAddress, blockingStubFull); @@ -617,16 +630,16 @@ public void test9Grammar010() { Optional infoById = null; infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); logger.info("infoById:" + infoById); - Optional ById = PublicMethed.getTransactionById(txid, blockingStubFull); - logger.info("getRet:" + ById.get().getRet(0)); - logger.info("getNumber:" + ById.get().getRet(0).getContractRet().getNumber()); - logger.info("getContractRetValue:" + ById.get().getRet(0).getContractRetValue()); - logger.info("getContractRet:" + ById.get().getRet(0).getContractRet()); + Optional byId = PublicMethed.getTransactionById(txid, blockingStubFull); + logger.info("getRet:" + byId.get().getRet(0)); + logger.info("getNumber:" + byId.get().getRet(0).getContractRet().getNumber()); + logger.info("getContractRetValue:" + byId.get().getRet(0).getContractRetValue()); + logger.info("getContractRet:" + byId.get().getRet(0).getContractRet()); - Assert.assertEquals(ById.get().getRet(0).getContractRet().getNumber(), + Assert.assertEquals(byId.get().getRet(0).getContractRet().getNumber(), STACK_TOO_LARGE_VALUE); - Assert.assertEquals(ById.get().getRet(0).getContractRetValue(), STACK_TOO_LARGE_VALUE); - Assert.assertEquals(ById.get().getRet(0).getContractRet(), contractResult.STACK_TOO_LARGE); + Assert.assertEquals(byId.get().getRet(0).getContractRetValue(), STACK_TOO_LARGE_VALUE); + Assert.assertEquals(byId.get().getRet(0).getContractRet(), contractResult.STACK_TOO_LARGE); Assert .assertEquals(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()), ""); diff --git a/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestSendCoin001.java b/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestSendCoin001.java index 970f60301bc..d5831d2aef4 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestSendCoin001.java +++ b/src/test/java/stest/tron/wallet/dailybuild/http/HttpTestSendCoin001.java @@ -56,8 +56,8 @@ public void test2GetTransactionByIdFromSolidity() { HttpMethed.printJsonContent(responseContent); String retString = responseContent.getString("ret"); JSONArray array = JSONArray.parseArray(retString); - Assert.assertTrue(HttpMethed.parseStringContent(array.get(0).toString()).getString( - "contractRet") == "SUCCESS"); + Assert.assertEquals(HttpMethed.parseStringContent(array.get(0).toString()).getString( + "contractRet"), "SUCCESS"); Assert.assertTrue(responseContent.size() > 4); } @@ -90,8 +90,8 @@ public void test4GetTransactionsFromThisFromSolidity() { responseContent.getString("transaction")).get(0).toString()); String retString = transactionObject.getString("ret"); JSONArray array = JSONArray.parseArray(retString); - Assert.assertTrue(HttpMethed.parseStringContent(array.get(0).toString()) - .getString("contractRet") == "SUCCESS"); + Assert.assertEquals(HttpMethed.parseStringContent(array.get(0).toString()) + .getString("contractRet"), "SUCCESS"); Assert.assertTrue(responseContent.size() == 1); } @@ -109,8 +109,8 @@ public void test5GetTransactionsToThisFromSolidity() { JSONArray.parseArray(responseContent.getString("transaction")).get(0).toString()); String retString = transactionObject.getString("ret"); JSONArray array = JSONArray.parseArray(retString); - Assert.assertTrue(HttpMethed.parseStringContent(array.get(0).toString()).getString( - "contractRet") == "SUCCESS"); + Assert.assertEquals(HttpMethed.parseStringContent(array.get(0).toString()).getString( + "contractRet"), "SUCCESS"); Assert.assertTrue(responseContent.size() == 1); } From 9c2acc42f2d8b3727824d3b0ba9cbaf3d39ad704 Mon Sep 17 00:00:00 2001 From: wangming Date: Tue, 18 Jun 2019 18:31:47 +0800 Subject: [PATCH 76/90] add ContractScenario016 --- .../scenario/ContractScenario016.java | 206 ++++++++++++++++++ 1 file changed, 206 insertions(+) create mode 100644 src/test/java/stest/tron/wallet/contract/scenario/ContractScenario016.java diff --git a/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario016.java b/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario016.java new file mode 100644 index 00000000000..914a6230915 --- /dev/null +++ b/src/test/java/stest/tron/wallet/contract/scenario/ContractScenario016.java @@ -0,0 +1,206 @@ +package stest.tron.wallet.contract.scenario; + +import static org.tron.protos.Protocol.Transaction.Result.contractResult.BAD_JUMP_DESTINATION_VALUE; +import static org.tron.protos.Protocol.Transaction.Result.contractResult.OUT_OF_ENERGY_VALUE; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.util.HashMap; +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.WalletGrpc; +import org.tron.api.WalletSolidityGrpc; +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.Transaction; +import org.tron.protos.Protocol.Transaction.Result.contractResult; +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 ContractScenario016 { + private final String testNetAccountKey = Configuration.getByPath("testng.conf") + .getString("foundationAccount.key2"); + private final byte[] testNetAccountAddress = PublicMethed.getFinalAddress(testNetAccountKey); + private Long maxFeeLimit = Configuration.getByPath("testng.conf") + .getLong("defaultParameter.maxFeeLimit"); + private ManagedChannel channelSolidity = null; + + private ManagedChannel channelFull = null; + private WalletGrpc.WalletBlockingStub blockingStubFull = null; + + private ManagedChannel channelFull1 = null; + private WalletGrpc.WalletBlockingStub blockingStubFull1 = null; + + + private WalletSolidityGrpc.WalletSolidityBlockingStub blockingStubSolidity = null; + + private String fullnode = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(1); + private String fullnode1 = Configuration.getByPath("testng.conf") + .getStringList("fullnode.ip.list").get(0); + private String compilerVersion = Configuration.getByPath("testng.conf") + .getString("defaultParameter.solidityCompilerVersion"); + + + byte[] contractAddress = null; + + ECKey ecKey1 = new ECKey(Utils.getRandom()); + byte[] grammarAddress = ecKey1.getAddress(); + String testKeyForGrammarAddress = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); + + + @BeforeSuite + public void beforeSuite() { + Wallet wallet = new Wallet(); + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); + } + + /** + * constructor. + */ + + @BeforeClass(enabled = true) + public void beforeClass() { + PublicMethed.printAddress(testKeyForGrammarAddress); + channelFull = ManagedChannelBuilder.forTarget(fullnode) + .usePlaintext(true) + .build(); + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); + channelFull1 = ManagedChannelBuilder.forTarget(fullnode1) + .usePlaintext(true) + .build(); + blockingStubFull1 = WalletGrpc.newBlockingStub(channelFull1); + } + + @Test(enabled = true, description = "ContractResult is BAD_JUMP_DESTINATION") + public void test1Grammar001() { + Assert.assertTrue(PublicMethed + .sendcoin(grammarAddress, 100000000000L, testNetAccountAddress, testNetAccountKey, + blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); + String contractName = "Test"; + + String code = "608060405234801561001057600080fd5b50d3801561001d57600080fd5b50d2801561002a57600" + + "080fd5b5061011f8061003a6000396000f30060806040526004361060485763ffffffff7c01000000000000" + + "000000000000000000000000000000000000000000006000350416634ef5a0088114604d5780639093b95b1" + + "4608c575b600080fd5b348015605857600080fd5b50d38015606457600080fd5b50d28015607057600080fd" + + "5b50607a60043560b8565b60408051918252519081900360200190f35b348015609757600080fd5b50d3801" + + "560a357600080fd5b50d2801560af57600080fd5b5060b660ee565b005b6000606082604051908082528060" + + "20026020018201604052801560e5578160200160208202803883390190505b50905050919050565b6001805" + + "600a165627a7a7230582092ba162087e13f41c6d6c00ba493edc5a5a6250a3840ece5f99aa38b66366a7000" + + "29"; + String abi = "[{\"constant\":false,\"inputs\":[{\"name\":\"x\",\"type\":\"uint256\"}],\"name\"" + + ":\"testOutOfMem\",\"outputs\":[{\"name\":\"r\",\"type\":\"bytes32\"}],\"payable\":false" + + ",\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs" + + "\":[],\"name\":\"testBadJumpDestination\",\"outputs\":[],\"payable\":false,\"stateMutab" + + "ility\":\"nonpayable\",\"type\":\"function\"}]"; + + byte[] contractAddress = PublicMethed.deployContract(contractName, abi, code, + "", maxFeeLimit, + 0L, 100, null, testKeyForGrammarAddress, grammarAddress, blockingStubFull); + + PublicMethed.waitProduceNextBlock(blockingStubFull); + SmartContract smartContract = PublicMethed.getContract(contractAddress, blockingStubFull); + org.testng.Assert.assertTrue(smartContract.getAbi().toString() != null); + String txid = null; + Optional infoById = null; + txid = PublicMethed.triggerContract(contractAddress, + "testBadJumpDestination()", "#", false, + 0, maxFeeLimit, grammarAddress, testKeyForGrammarAddress, blockingStubFull); + PublicMethed.waitProduceNextBlock(blockingStubFull); + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + logger.info("Txid is " + txid); + logger.info("Trigger energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); + + Optional byId = PublicMethed.getTransactionById(txid, blockingStubFull); + logger.info("getRet:" + byId.get().getRet(0)); + logger.info("getNumber:" + byId.get().getRet(0).getContractRet().getNumber()); + logger.info("getContractRetValue:" + byId.get().getRet(0).getContractRetValue()); + logger.info("getContractRet:" + byId.get().getRet(0).getContractRet()); + logger.info("ById:" + byId); + + logger.info("infoById:" + infoById); + + Assert.assertEquals(byId.get().getRet(0).getContractRetValue(), BAD_JUMP_DESTINATION_VALUE); + Assert.assertEquals(byId.get().getRet(0).getContractRet(), contractResult.BAD_JUMP_DESTINATION); + + Assert + .assertEquals(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()), ""); + Assert + .assertEquals(contractResult.BAD_JUMP_DESTINATION, infoById.get().getReceipt().getResult()); + + Assert.assertEquals(byId.get().getRet(0).getRet().getNumber(), 0); + Assert.assertEquals(byId.get().getRet(0).getRetValue(), 0); + + + } + + + @Test(enabled = true, description = "ContractResult is OUT_OF_ENERGY") + public void test2Grammar002() { + + String filePath = "src/test/resources/soliditycode/contractUnknownException.sol"; + String contractName = "testC"; + HashMap retMap = PublicMethed.getBycodeAbi(filePath, contractName); + String code = retMap.get("byteCode").toString(); + String abi = retMap.get("abI").toString(); + String txid = PublicMethed + .deployContractAndGetTransactionInfoById(contractName, abi, code, "", maxFeeLimit, + 20L, 100, null, testKeyForGrammarAddress, + grammarAddress, blockingStubFull); + Optional infoById = null; + PublicMethed.waitProduceNextBlock(blockingStubFull); + infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); + logger.info("Txid is " + txid); + logger.info("Trigger energytotal is " + infoById.get().getReceipt().getEnergyUsageTotal()); + + Optional byId = PublicMethed.getTransactionById(txid, blockingStubFull); + logger.info("getRet:" + byId.get().getRet(0)); + logger.info("getNumber:" + byId.get().getRet(0).getContractRet().getNumber()); + logger.info("getContractRetValue:" + byId.get().getRet(0).getContractRetValue()); + logger.info("getContractRet:" + byId.get().getRet(0).getContractRet()); + logger.info("ById:" + byId); + + logger.info("infoById:" + infoById); + + Assert.assertEquals(byId.get().getRet(0).getContractRetValue(), OUT_OF_ENERGY_VALUE); + Assert.assertEquals(byId.get().getRet(0).getContractRet(), contractResult.OUT_OF_ENERGY); + + Assert + .assertEquals(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()), ""); + Assert + .assertEquals(contractResult.OUT_OF_ENERGY, infoById.get().getReceipt().getResult()); + + Assert.assertEquals(byId.get().getRet(0).getRet().getNumber(), 0); + Assert.assertEquals(byId.get().getRet(0).getRetValue(), 0); + + } + + + + /** + * constructor. + */ + @AfterClass + public void shutdown() throws InterruptedException { + if (channelFull != null) { + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + if (channelFull1 != null) { + channelFull1.shutdown().awaitTermination(5, TimeUnit.SECONDS); + } + } + +} From cbcfe89777c7123236c9a96d76898e1e87e83a2f Mon Sep 17 00:00:00 2001 From: wangming Date: Tue, 18 Jun 2019 20:02:38 +0800 Subject: [PATCH 77/90] modify TransferFailed001 --- .../tvmnewcommand/transferfailed/TransferFailed001.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed001.java b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed001.java index 1a2efb62a48..90883fcf4c2 100644 --- a/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed001.java +++ b/src/test/java/stest/tron/wallet/dailybuild/tvmnewcommand/transferfailed/TransferFailed001.java @@ -173,6 +173,7 @@ public void test2TransferEnough() { Assert.assertTrue(PublicMethed .sendcoin(contractAddress, 3000000L, testNetAccountAddress, testNetAccountKey, blockingStubFull)); + PublicMethed.waitProduceNextBlock(blockingStubFull); Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, @@ -218,6 +219,7 @@ public void test2TransferEnough() { logger.info("afterNetUsed:" + afterNetUsed); logger.info("afterFreeNetUsed:" + afterFreeNetUsed); + logger.info("infoById" + infoById); Assert.assertTrue(infoById.get().getResultValue() == 0); Assert.assertTrue(afterBalance + fee - 1 == beforeBalance); Assert.assertTrue(beforeEnergyUsed + energyUsed >= afterEnergyUsed); From ee29c729053f7f61c6f563706d3e94f7f2db5864 Mon Sep 17 00:00:00 2001 From: wubin1 Date: Wed, 19 Jun 2019 16:25:21 +0800 Subject: [PATCH 78/90] add history switch --- src/main/java/org/tron/core/db/TransactionRetStore.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/org/tron/core/db/TransactionRetStore.java b/src/main/java/org/tron/core/db/TransactionRetStore.java index 36f3a0dd383..f97c7e030f5 100644 --- a/src/main/java/org/tron/core/db/TransactionRetStore.java +++ b/src/main/java/org/tron/core/db/TransactionRetStore.java @@ -3,12 +3,14 @@ import com.google.protobuf.ByteString; import java.util.Objects; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.BooleanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import org.tron.common.utils.ByteArray; import org.tron.core.capsule.TransactionInfoCapsule; import org.tron.core.capsule.TransactionRetCapsule; +import org.tron.core.config.args.Args; import org.tron.core.exception.BadItemException; import org.tron.protos.Protocol.TransactionInfo; @@ -24,6 +26,13 @@ public TransactionRetStore(@Value("transactionRetStore") String dbName) { super(dbName); } + @Override + public void put(byte[] key, TransactionRetCapsule item) { + if (BooleanUtils.toBoolean(Args.getInstance().getStorage().getTransactionHistoreSwitch())) { + super.put(key, item); + } + } + public TransactionInfoCapsule getTransactionInfo(byte[] key) throws BadItemException { long blockNumber = transactionStore.getBlockNumber(key); if (blockNumber == -1) { From c184c4af92ec4227a9830f127edab5b6a9e67e4f Mon Sep 17 00:00:00 2001 From: wubin1 Date: Thu, 20 Jun 2019 14:15:26 +0800 Subject: [PATCH 79/90] add more unit test for transactionRet --- .../tron/core/capsule/TransactionRetCapsule.java | 3 +++ src/main/java/org/tron/core/db/Manager.java | 5 ++++- .../org/tron/core/db/TransactionRetStoreTest.java | 15 +++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/tron/core/capsule/TransactionRetCapsule.java b/src/main/java/org/tron/core/capsule/TransactionRetCapsule.java index 8fd483df5fa..f2b41533384 100644 --- a/src/main/java/org/tron/core/capsule/TransactionRetCapsule.java +++ b/src/main/java/org/tron/core/capsule/TransactionRetCapsule.java @@ -40,6 +40,9 @@ public void addTransactionInfo(TransactionInfo result) { @Override public byte[] getData() { + if (Objects.isNull(transactionRet)) { + return null; + } return transactionRet.toByteArray(); } diff --git a/src/main/java/org/tron/core/db/Manager.java b/src/main/java/org/tron/core/db/Manager.java index b6e24dfea63..643a5febbae 100644 --- a/src/main/java/org/tron/core/db/Manager.java +++ b/src/main/java/org/tron/core/db/Manager.java @@ -1389,7 +1389,10 @@ public synchronized BlockCapsule generateBlock( tmpSeesion.merge(); // push into block blockCapsule.addTransaction(trx); - transationRetCapsule.addTransactionInfo(result); + + if (Objects.nonNull(result)) { + transationRetCapsule.addTransactionInfo(result); + } if (fromPending) { iterator.remove(); } diff --git a/src/test/java/org/tron/core/db/TransactionRetStoreTest.java b/src/test/java/org/tron/core/db/TransactionRetStoreTest.java index 8fdd6d76b59..baf36ddb5b9 100644 --- a/src/test/java/org/tron/core/db/TransactionRetStoreTest.java +++ b/src/test/java/org/tron/core/db/TransactionRetStoreTest.java @@ -73,4 +73,19 @@ public void get() throws BadItemException { TransactionInfoCapsule resultCapsule = transactionRetStore.getTransactionInfo(transactionId); Assert.assertNotNull("get transaction ret store", resultCapsule); } + + @Test + public void put() { + TransactionInfoCapsule transactionInfoCapsule = new TransactionInfoCapsule(); + transactionInfoCapsule.setId(transactionId); + transactionInfoCapsule.setFee(1000L); + transactionInfoCapsule.setBlockNumber(100L); + transactionInfoCapsule.setBlockTimeStamp(200L); + + TransactionRetCapsule transactionRetCapsule = new TransactionRetCapsule(); + transactionRetCapsule.addTransactionInfo(transactionInfoCapsule.getInstance()); + Assert.assertNull("put transaction info error", transactionRetStore.getUnchecked(transactionInfoCapsule.getId())); + transactionRetStore.put(transactionInfoCapsule.getId(), transactionRetCapsule); + Assert.assertNotNull("get transaction info error", transactionRetStore.getUnchecked(transactionInfoCapsule.getId())); + } } \ No newline at end of file From 76d11c05440e055cdc135fcbeb11b7dda3ed576f Mon Sep 17 00:00:00 2001 From: wubin1 Date: Thu, 20 Jun 2019 14:27:55 +0800 Subject: [PATCH 80/90] fix type error --- src/main/java/org/tron/core/capsule/TransactionCapsule.java | 1 - src/main/java/org/tron/core/config/args/Args.java | 4 ++-- src/main/java/org/tron/core/db/TransactionRetStore.java | 5 +++++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/tron/core/capsule/TransactionCapsule.java b/src/main/java/org/tron/core/capsule/TransactionCapsule.java index dd61bcbe877..6bb32fb8bff 100755 --- a/src/main/java/org/tron/core/capsule/TransactionCapsule.java +++ b/src/main/java/org/tron/core/capsule/TransactionCapsule.java @@ -925,7 +925,6 @@ public void setResult(Runtime runtime) { return; } this.setResultCode(contractResult.UNKNOWN); - return; } public void setResultCode(contractResult code) { diff --git a/src/main/java/org/tron/core/config/args/Args.java b/src/main/java/org/tron/core/config/args/Args.java index 25c87796bfc..4593036afbc 100644 --- a/src/main/java/org/tron/core/config/args/Args.java +++ b/src/main/java/org/tron/core/config/args/Args.java @@ -135,11 +135,11 @@ public class Args { private String storageDbEngine = ""; @Parameter(names = { - "--storage-db-synchronous"}, description = "Storage db is synchronous or not.(true or flase)") + "--storage-db-synchronous"}, description = "Storage db is synchronous or not.(true or false)") private String storageDbSynchronous = ""; @Parameter(names = { - "--contract-parse-enable"}, description = "enable contract parses in java-tron or not.(true or flase)") + "--contract-parse-enable"}, description = "enable contract parses in java-tron or not.(true or false)") private String contractParseEnable = ""; @Parameter(names = {"--storage-index-directory"}, description = "Storage index directory") diff --git a/src/main/java/org/tron/core/db/TransactionRetStore.java b/src/main/java/org/tron/core/db/TransactionRetStore.java index f97c7e030f5..a4230e7a36c 100644 --- a/src/main/java/org/tron/core/db/TransactionRetStore.java +++ b/src/main/java/org/tron/core/db/TransactionRetStore.java @@ -39,10 +39,15 @@ public TransactionInfoCapsule getTransactionInfo(byte[] key) throws BadItemExcep return null; } byte[] value = revokingDB.getUnchecked(ByteArray.fromLong(blockNumber)); + if (Objects.isNull(value)) { + return null; + } + TransactionRetCapsule result = new TransactionRetCapsule(value); if (Objects.isNull(result) || Objects.isNull(result.getInstance())) { return null; } + for (TransactionInfo transactionResultInfo : result.getInstance().getTransactioninfoList()) { if (transactionResultInfo.getId().equals(ByteString.copyFrom(key))) { return new TransactionInfoCapsule(transactionResultInfo); From 94094d1b7252305d93d489d1ea3ef9a2db2152cd Mon Sep 17 00:00:00 2001 From: wubin01 Date: Thu, 20 Jun 2019 16:07:14 +0800 Subject: [PATCH 81/90] modify block msg process msg --- .../net/messagehandler/BlockMsgHandler.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java b/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java index dbb1005c171..398d6224047 100644 --- a/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java +++ b/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java @@ -60,13 +60,20 @@ public void processMessage(PeerConnection peer, TronMessage msg) throws P2pExcep syncService.processBlock(peer, blockMessage); } else { Long time = peer.getAdvInvRequest().remove(new Item(blockId, InventoryType.BLOCK)); - long cost = time == null ? 0 : System.currentTimeMillis() - time; - logger.info("Receive block {}, witness: {} from {}, fetch cost {}ms", - blockId.getString(), - Hex.toHexString(blockMessage.getBlockCapsule().getWitnessAddress().toByteArray()), - peer.getInetAddress(), - cost); + long now = System.currentTimeMillis(); + long delay = now - tronNetDelegate.getHeadBlockTimeStamp() - BLOCK_PRODUCED_INTERVAL; + long interval = blockId.getNum() - tronNetDelegate.getHeadBlockId().getNum(); processBlock(peer, blockMessage.getBlockCapsule()); + logger.info( + "Receive block/interval {}/{} from {} fetch/delay {}/{}ms, txs/process {}/{}ms, witness: {}", + blockId.getNum(), + interval, + peer.getInetAddress(), + time == null ? 0 : now - time, + delay, + ((BlockMessage) msg).getBlockCapsule().getTransactions().size(), + System.currentTimeMillis() - now, + Hex.toHexString(blockMessage.getBlockCapsule().getWitnessAddress().toByteArray())); } } From 138c88487c6a38e037d194fd44339e210f060a09 Mon Sep 17 00:00:00 2001 From: wubin01 Date: Mon, 24 Jun 2019 15:02:45 +0800 Subject: [PATCH 82/90] modify nodes cfg --- .../java/org/tron/core/config/args/Args.java | 20 ++++++++++++------- src/main/java/org/tron/program/FullNode.java | 2 -- src/main/resources/config.conf | 3 ++- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/tron/core/config/args/Args.java b/src/main/java/org/tron/core/config/args/Args.java index 4593036afbc..c54a2f61746 100644 --- a/src/main/java/org/tron/core/config/args/Args.java +++ b/src/main/java/org/tron/core/config/args/Args.java @@ -741,12 +741,6 @@ public static void setParam(final String[] args, final String confFileName) { config.hasPath("node.connection.timeout") ? config.getInt("node.connection.timeout") * 1000 : 0; - INSTANCE.activeNodes = getNodes(config, "node.active"); - - INSTANCE.passiveNodes = getNodes(config, "node.passive"); - - INSTANCE.fastForwardNodes = getNodes(config, "node.fastForward"); - INSTANCE.nodeChannelReadTimeout = config.hasPath("node.channel.read.timeout") ? config.getInt("node.channel.read.timeout") : 0; @@ -951,6 +945,12 @@ public static void setParam(final String[] args, final String confFileName) { .getInt("node.validContractProto.threads") : Runtime.getRuntime().availableProcessors(); + INSTANCE.activeNodes = getNodes(config, "node.active"); + + INSTANCE.passiveNodes = getNodes(config, "node.passive"); + + INSTANCE.fastForwardNodes = getNodes(config, "node.fastForward"); + initBackupProperty(config); if ("ROCKSDB".equals(Args.getInstance().getStorage().getDbEngine().toUpperCase())) { initRocksDbBackupProperty(config); @@ -1026,7 +1026,12 @@ private static List getNodes(final com.typesafe.config.Config config, Stri List list = config.getStringList(path); for (String configString : list) { Node n = Node.instanceOf(configString); - ret.add(n); + if (!(INSTANCE.nodeDiscoveryBindIp.equals(n.getHost()) || + INSTANCE.nodeExternalIp.equals(n.getHost()) || + "127.0.0.1".equals(n.getHost())) || + INSTANCE.nodeListenPort != n.getPort()) { + ret.add(n); + } } return ret; } @@ -1321,6 +1326,7 @@ private static void logConfig() { logger.info("Discover enable: {}", args.isNodeDiscoveryEnable()); logger.info("Active node size: {}", args.getActiveNodes().size()); logger.info("Passive node size: {}", args.getPassiveNodes().size()); + logger.info("FastForward node size: {}", args.getFastForwardNodes().size()); logger.info("Seed node size: {}", args.getSeedNode().getIpList().size()); logger.info("Max connection: {}", args.getNodeMaxActiveNodes()); logger.info("Max connection with same IP: {}", args.getNodeMaxActiveNodesWithSameIp()); diff --git a/src/main/java/org/tron/program/FullNode.java b/src/main/java/org/tron/program/FullNode.java index 25619c36980..81debdcac52 100644 --- a/src/main/java/org/tron/program/FullNode.java +++ b/src/main/java/org/tron/program/FullNode.java @@ -1,11 +1,9 @@ package org.tron.program; -import ch.qos.logback.classic.Level; import ch.qos.logback.classic.LoggerContext; import ch.qos.logback.classic.joran.JoranConfigurator; import java.io.File; import lombok.extern.slf4j.Slf4j; -import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.tron.common.application.Application; diff --git a/src/main/resources/config.conf b/src/main/resources/config.conf index ba3cfffe83b..2787c3e6238 100644 --- a/src/main/resources/config.conf +++ b/src/main/resources/config.conf @@ -149,7 +149,8 @@ node { ] fastForward = [ - "47.90.208.194:18888" + "47.90.208.194:18888", + "47.75.212.39:18888" ] http { From 25bc40f5a78a3dad3bd81c96e56ebf4045c8452c Mon Sep 17 00:00:00 2001 From: wubinTron <44354524+wubinTron@users.noreply.github.com> Date: Mon, 24 Jun 2019 15:40:55 +0800 Subject: [PATCH 83/90] update start up bash --- start.sh | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/start.sh b/start.sh index 657b88ed320..849d18450fc 100644 --- a/start.sh +++ b/start.sh @@ -1,3 +1,46 @@ #!/bin/bash -kill -9 `cat /home/tron/pid.txt` -nohup java -jar /home/tron/java-tron/java-tron.jar -p $LOCAL_WITNESS_PRIVATE_KEY --witness -c /home/tron/config.conf > /home/tron/tron-shell.log 2>&1 & echo $! >/home/tron/pid.txt \ No newline at end of file +APP=$1 +APP=${APP:-"FullNode"} +START_OPT=`echo ${@:2}` +JAR_NAME="$APP.jar" +MAX_STOP_TIME=60 + +checkpid() { + pid=`ps -ef | grep $JAR_NAME |grep -v grep | awk '{print $2}'` + return $pid +} + +stopService() { + count=1 + while [ $count -le $MAX_STOP_TIME ]; do + checkpid + if [ $pid ]; then + kill -15 $pid + sleep 1 + else + echo "java-tron stop" + return + fi + count=$[$count+1] + if [ $count -eq $MAX_STOP_TIME ]; then + kill -9 $pid + sleep 1 + fi + done +} + +startService() { + echo `date` >> start.log + total=`cat /proc/meminfo |grep MemTotal |awk -F ' ' '{print $2}'` + xmx=`echo "$total/1024/1024*0.8" | bc |awk -F. '{print $1"g"}'` + logtime=`date +%Y-%m-%d_%H-%M-%S` + nohup java -Xmx$xmx -XX:+UseConcMarkSweepGC -XX:+PrintGCDetails -Xloggc:./gc.log\ + -XX:+PrintGCDateStamps -XX:+CMSParallelRemarkEnabled -XX:ReservedCodeCacheSize=256m\ + -XX:+CMSScavengeBeforeRemark -jar $JAR_NAME $START_OPT -c config.conf >> start.log 2>&1 & + + pid=`ps -ef |grep $JAR_NAME |grep -v grep |awk '{print $2}'` + echo "start java-tron with pid $pid on $HOSTNAME" +} + +stopService +startService From 78059cde289a138e8b0af7739c4f64700ba16fef Mon Sep 17 00:00:00 2001 From: wubin01 Date: Mon, 24 Jun 2019 16:10:09 +0800 Subject: [PATCH 84/90] modify version to 3.6.1 --- src/main/java/org/tron/program/Version.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/tron/program/Version.java b/src/main/java/org/tron/program/Version.java index 4430436db63..97c5c2ba245 100644 --- a/src/main/java/org/tron/program/Version.java +++ b/src/main/java/org/tron/program/Version.java @@ -1,7 +1,7 @@ package org.tron.program; public class Version { - private static final String version = "3.6.0"; + private static final String version = "3.6.1"; public static final String versionName = "Odyssey-v3.5.1-890-gd39973cbb"; public static final String versionCode = "10803"; From 630fcdfa3d79f2d0ec8b69643d3fcd651acf9292 Mon Sep 17 00:00:00 2001 From: wubin01 Date: Mon, 24 Jun 2019 18:32:58 +0800 Subject: [PATCH 85/90] modify syncpool test --- src/main/java/org/tron/common/overlay/server/SyncPool.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/java/org/tron/common/overlay/server/SyncPool.java b/src/main/java/org/tron/common/overlay/server/SyncPool.java index d8a7c131933..afce5d008e0 100644 --- a/src/main/java/org/tron/common/overlay/server/SyncPool.java +++ b/src/main/java/org/tron/common/overlay/server/SyncPool.java @@ -221,10 +221,6 @@ public boolean test(NodeHandler handler) { return false; } - if (handler.getNodeStatistics().getReputation() >= NodeStatistics.REPUTATION_PREDEFINED) { - return true; - } - InetAddress inetAddress = handler.getInetSocketAddress().getAddress(); if (channelManager.getRecentlyDisconnected().getIfPresent(inetAddress) != null) { return false; From dcbe05031dbf97ae5f5954e404279140a1eae06e Mon Sep 17 00:00:00 2001 From: wubin01 Date: Tue, 25 Jun 2019 15:50:03 +0800 Subject: [PATCH 86/90] optimizing the logic of fast forward node --- .../org/tron/core/net/messagehandler/BlockMsgHandler.java | 6 ++---- src/main/java/org/tron/core/net/service/AdvService.java | 6 ++++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java b/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java index 398d6224047..7949f128afb 100644 --- a/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java +++ b/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java @@ -41,8 +41,6 @@ public class BlockMsgHandler implements TronMsgHandler { private int maxBlockSize = BLOCK_SIZE + 1000; - private int threshold = 3; - private boolean fastForward = Args.getInstance().isFastForward(); @Override @@ -103,12 +101,12 @@ private void processBlock(PeerConnection peer, BlockCapsule block) throws P2pExc } Item item = new Item(blockId, InventoryType.BLOCK); - if (peer.isFastForwardPeer()) { + if (fastForward || peer.isFastForwardPeer()) { advService.addInvToCache(item); } if (fastForward) { - if (tronNetDelegate.getHeadBlockId().getNum() - block.getNum() > threshold) { + if (block.getNum() < tronNetDelegate.getHeadBlockId().getNum()) { logger.warn("Receive a low block {}, head {}", blockId.getString(), tronNetDelegate.getHeadBlockId().getString()); return; diff --git a/src/main/java/org/tron/core/net/service/AdvService.java b/src/main/java/org/tron/core/net/service/AdvService.java index 1664033ba44..3684946a833 100644 --- a/src/main/java/org/tron/core/net/service/AdvService.java +++ b/src/main/java/org/tron/core/net/service/AdvService.java @@ -102,7 +102,7 @@ synchronized public void addInvToCache(Item item) { synchronized public boolean addInv(Item item) { - if (fastForward) { + if (fastForward && item.getType().equals(InventoryType.TRX)) { return false; } @@ -252,7 +252,6 @@ synchronized private void consumerInvToSpread() { List peers = tronNetDelegate.getActivePeer().stream() .filter(peer -> !peer.isNeedSyncFromPeer() && !peer.isNeedSyncFromUs()) - .filter(peer -> !peer.isFastForwardPeer()) .collect(Collectors.toList()); if (invToSpread.isEmpty() || peers.isEmpty()) { @@ -310,6 +309,9 @@ public int getSize(PeerConnection peer) { public void sendInv() { send.forEach((peer, ids) -> ids.forEach((key, value) -> { + if (peer.isFastForwardPeer() && key.equals(InventoryType.TRX)) { + return; + } if (key.equals(InventoryType.BLOCK)) { value.sort(Comparator.comparingLong(value1 -> new BlockId(value1).getNum())); } From 24d10ecd416df4f74a63a4341ce0e6c5a856ad5f Mon Sep 17 00:00:00 2001 From: wubinTron <44354524+wubinTron@users.noreply.github.com> Date: Tue, 25 Jun 2019 16:15:14 +0800 Subject: [PATCH 87/90] Enable shadowJar for jitpack dependency --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 4947903401a..98581105a01 100755 --- a/build.gradle +++ b/build.gradle @@ -24,7 +24,7 @@ apply plugin: "jacoco" apply plugin: 'maven-publish' jar.enabled = false -shadowJar.enabled = false +shadowJar.enabled = true sourceCompatibility = 1.8 [compileJava, compileTestJava]*.options*.encoding = 'UTF-8' From 4e85f59a9c403babb7ed2e6d250c3ed4dc07e80d Mon Sep 17 00:00:00 2001 From: wubin01 Date: Tue, 25 Jun 2019 17:30:09 +0800 Subject: [PATCH 88/90] modify fastnode process block --- .../java/org/tron/core/net/messagehandler/BlockMsgHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java b/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java index 7949f128afb..f09ffd3f1aa 100644 --- a/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java +++ b/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java @@ -102,6 +102,7 @@ private void processBlock(PeerConnection peer, BlockCapsule block) throws P2pExc Item item = new Item(blockId, InventoryType.BLOCK); if (fastForward || peer.isFastForwardPeer()) { + peer.getAdvInvReceive().put(item, System.currentTimeMillis()); advService.addInvToCache(item); } @@ -112,7 +113,6 @@ private void processBlock(PeerConnection peer, BlockCapsule block) throws P2pExc return; } if (tronNetDelegate.validBlock(block)) { - peer.getAdvInvReceive().put(item, System.currentTimeMillis()); advService.fastForward(new BlockMessage(block)); tronNetDelegate.trustNode(peer); } From f133aa1df77e11156415c457767c994499acff49 Mon Sep 17 00:00:00 2001 From: wubin01 Date: Fri, 5 Jul 2019 16:51:39 +0800 Subject: [PATCH 89/90] merge from master --- src/main/java/org/tron/program/Version.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/tron/program/Version.java b/src/main/java/org/tron/program/Version.java index 97c5c2ba245..e80165ce9dd 100644 --- a/src/main/java/org/tron/program/Version.java +++ b/src/main/java/org/tron/program/Version.java @@ -1,6 +1,7 @@ package org.tron.program; public class Version { + private static final String version = "3.6.1"; public static final String versionName = "Odyssey-v3.5.1-890-gd39973cbb"; public static final String versionCode = "10803"; From 2b7b9a2e5054df5de17cfde0f4550b78fb130abd Mon Sep 17 00:00:00 2001 From: wubin01 Date: Tue, 9 Jul 2019 17:30:23 +0800 Subject: [PATCH 90/90] modify block handle msg --- .../java/org/tron/core/net/messagehandler/BlockMsgHandler.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java b/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java index f09ffd3f1aa..cd9712a61ff 100644 --- a/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java +++ b/src/main/java/org/tron/core/net/messagehandler/BlockMsgHandler.java @@ -59,7 +59,6 @@ public void processMessage(PeerConnection peer, TronMessage msg) throws P2pExcep } else { Long time = peer.getAdvInvRequest().remove(new Item(blockId, InventoryType.BLOCK)); long now = System.currentTimeMillis(); - long delay = now - tronNetDelegate.getHeadBlockTimeStamp() - BLOCK_PRODUCED_INTERVAL; long interval = blockId.getNum() - tronNetDelegate.getHeadBlockId().getNum(); processBlock(peer, blockMessage.getBlockCapsule()); logger.info( @@ -68,7 +67,7 @@ public void processMessage(PeerConnection peer, TronMessage msg) throws P2pExcep interval, peer.getInetAddress(), time == null ? 0 : now - time, - delay, + now - blockMessage.getBlockCapsule().getTimeStamp(), ((BlockMessage) msg).getBlockCapsule().getTransactions().size(), System.currentTimeMillis() - now, Hex.toHexString(blockMessage.getBlockCapsule().getWitnessAddress().toByteArray()));