Skip to content

Commit

Permalink
Merge pull request tronprotocol#2534 from tronprotocol/tron-DK
Browse files Browse the repository at this point in the history
modify variables spelling errors and improve error message
  • Loading branch information
zk19862018 authored Oct 11, 2019
2 parents ac6f671 + 5ab5dd3 commit 0598e4f
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 58 deletions.
24 changes: 12 additions & 12 deletions src/main/java/org/tron/core/actuator/TransferAssetActuator.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public boolean validate() throws ContractValidateException {
}
if (!this.contract.is(TransferAssetContract.class)) {
throw new ContractValidateException(
"contract type error,expected type [TransferAssetContract],real type[" + contract
"contract type error, expected type [TransferAssetContract], real type[" + contract
.getClass() + "]");
}
final TransferAssetContract transferAssetContract;
Expand All @@ -130,7 +130,7 @@ public boolean validate() throws ContractValidateException {
// throw new ContractValidateException("Invalid assetName");
// }
if (amount <= 0) {
throw new ContractValidateException("Amount must greater than 0.");
throw new ContractValidateException("Amount must be greater than 0.");
}

if (Arrays.equals(ownerAddress, toAddress)) {
Expand All @@ -143,7 +143,7 @@ public boolean validate() throws ContractValidateException {
}

if (!this.dbManager.getAssetIssueStoreFinal().has(assetName)) {
throw new ContractValidateException("No asset !");
throw new ContractValidateException("No asset!");
}

Map<String, Long> asset;
Expand All @@ -153,12 +153,12 @@ public boolean validate() throws ContractValidateException {
asset = ownerAccount.getAssetMapV2();
}
if (asset.isEmpty()) {
throw new ContractValidateException("Owner no asset!");
throw new ContractValidateException("Owner account has no asset!");
}

Long assetBalance = asset.get(ByteArray.toStr(assetName));
if (null == assetBalance || assetBalance <= 0) {
throw new ContractValidateException("assetBalance must greater than 0.");
throw new ContractValidateException("assetBalance must be greater than 0.");
}
if (amount > assetBalance) {
throw new ContractValidateException("assetBalance is not sufficient.");
Expand All @@ -169,7 +169,7 @@ public boolean validate() throws ContractValidateException {
//after TvmSolidity059 proposal, send trx to smartContract by actuator is not allowed.
if (dbManager.getDynamicPropertiesStore().getAllowTvmSolidity059() == 1
&& toAccount.getType() == AccountType.Contract) {
throw new ContractValidateException("Cannot transfer asset to smartContract.");
throw new ContractValidateException("Cannot transfer asset to a smartContract.");
}

if (dbManager.getDynamicPropertiesStore().getAllowSameTokenName() == 0) {
Expand Down Expand Up @@ -214,7 +214,7 @@ public static boolean validateForSmartContract(Deposit deposit, byte[] ownerAddr
// throw new ContractValidateException("Invalid assetName");
// }
if (amount <= 0) {
throw new ContractValidateException("Amount must greater than 0.");
throw new ContractValidateException("Amount must be greater than 0.");
}

if (Arrays.equals(ownerAddress, toAddress)) {
Expand All @@ -227,10 +227,10 @@ public static boolean validateForSmartContract(Deposit deposit, byte[] ownerAddr
}

if (deposit.getAssetIssue(tokenIdWithoutLeadingZero) == null) {
throw new ContractValidateException("No asset !");
throw new ContractValidateException("No asset!");
}
if (!deposit.getDbManager().getAssetIssueStoreFinal().has(tokenIdWithoutLeadingZero)) {
throw new ContractValidateException("No asset !");
throw new ContractValidateException("No asset!");
}

Map<String, Long> asset;
Expand All @@ -240,12 +240,12 @@ public static boolean validateForSmartContract(Deposit deposit, byte[] ownerAddr
asset = ownerAccount.getAssetMapV2();
}
if (asset.isEmpty()) {
throw new ContractValidateException("Owner no asset!");
throw new ContractValidateException("Owner account has no asset!");
}

Long assetBalance = asset.get(ByteArray.toStr(tokenIdWithoutLeadingZero));
if (null == assetBalance || assetBalance <= 0) {
throw new ContractValidateException("assetBalance must greater than 0.");
throw new ContractValidateException("assetBalance must be greater than 0.");
}
if (amount > assetBalance) {
throw new ContractValidateException("assetBalance is not sufficient.");
Expand All @@ -268,7 +268,7 @@ public static boolean validateForSmartContract(Deposit deposit, byte[] ownerAddr
}
} else {
throw new ContractValidateException(
"Validate InternalTransfer error, no ToAccount. And not allowed to create account in smart contract.");
"Validate InternalTransfer error, no ToAccount. And not allowed to create account in smartContract.");
}

return true;
Expand Down
14 changes: 6 additions & 8 deletions src/test/java/org/tron/core/actuator/TransferActuatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ public void createCapsule() {
}

private Any getContract(long count) {
long nowTime = new Date().getTime();
return Any.pack(Contract.TransferContract.newBuilder()
.setOwnerAddress(ByteString.copyFrom(ByteArray.fromHexString(OWNER_ADDRESS)))
.setToAddress(ByteString.copyFrom(ByteArray.fromHexString(TO_ADDRESS))).setAmount(count)
Expand All @@ -115,17 +114,16 @@ private Any getContract(long count) {


private Any getContract(long count, byte[] address) {
long nowTime = new Date().getTime();
return Any.pack(Contract.TransferContract.newBuilder()
.setOwnerAddress(ByteString.copyFrom(ByteArray.fromHexString(OWNER_ADDRESS)))
.setToAddress(ByteString.copyFrom(address)).setAmount(count).build());
}


private Any getContract(long count, String owneraddress, String toaddress) {
private Any getContract(long count, String ownerAddress, String toAddress) {
return Any.pack(Contract.TransferContract.newBuilder()
.setOwnerAddress(ByteString.copyFrom(ByteArray.fromHexString(owneraddress)))
.setToAddress(ByteString.copyFrom(ByteArray.fromHexString(toaddress))).setAmount(count)
.setOwnerAddress(ByteString.copyFrom(ByteArray.fromHexString(ownerAddress)))
.setToAddress(ByteString.copyFrom(ByteArray.fromHexString(toAddress))).setAmount(count)
.build());
}

Expand Down Expand Up @@ -202,7 +200,7 @@ public void moreTransfer() {


@Test
public void iniviateOwnerAddress() {
public void initiateOwnerAddress() {
TransferActuator actuator = new TransferActuator(
getContract(10000L, OWNER_ADDRESS_INVALID, TO_ADDRESS), dbManager);
TransactionResultCapsule ret = new TransactionResultCapsule();
Expand All @@ -228,7 +226,7 @@ public void iniviateOwnerAddress() {
}

@Test
public void iniviateToAddress() {
public void initiateToAddress() {
TransferActuator actuator = new TransferActuator(
getContract(10000L, OWNER_ADDRESS, TO_ADDRESS_INVALID), dbManager);
TransactionResultCapsule ret = new TransactionResultCapsule();
Expand All @@ -253,7 +251,7 @@ public void iniviateToAddress() {
}

@Test
public void iniviateTrx() {
public void initiateTrx() {
TransferActuator actuator = new TransferActuator(
getContract(100L, OWNER_ADDRESS, OWNER_ADDRESS), dbManager);
TransactionResultCapsule ret = new TransactionResultCapsule();
Expand Down
Loading

0 comments on commit 0598e4f

Please sign in to comment.