From bb847a78a56abce8d1947efbd5dbbf6aca5287a5 Mon Sep 17 00:00:00 2001 From: Yulong Wu Date: Thu, 22 Nov 2018 12:41:41 +0800 Subject: [PATCH 1/2] Clean up transaction error code --- aion_fastvm | 2 +- .../contracts/AionAuctionContract.java | 24 ++-- .../contracts/AionNameServiceContract.java | 18 +-- .../contracts/EDVerifyContract.java | 2 +- .../precompiled/contracts/KeccakHash.java | 2 +- .../contracts/MultiSignatureContract.java | 26 ++-- .../contracts/TRS/TRSqueryContract.java | 28 ++-- .../contracts/TRS/TRSstateContract.java | 48 +++---- .../contracts/TRS/TRSuseContract.java | 76 +++++----- .../contracts/TotalCurrencyContract.java | 12 +- .../precompiled/TRS/TRSqueryContractTest.java | 42 +++--- .../precompiled/TRS/TRSstateContractTest.java | 116 +++++++-------- .../precompiled/TRS/TRSuseContractTest.java | 132 +++++++++--------- .../contracts/AionAuctionContractTest.java | 28 ++-- .../AionNameServiceContractTest.java | 16 +-- .../contracts/Blake2bHashTest.java | 2 +- .../precompiled/contracts/KeccakHashTest.java | 2 +- .../contracts/MultiSignatureContractTest.java | 98 ++++++------- .../contracts/TotalCurrencyContractTest.java | 12 +- .../org/aion/vm/AbstractExecutionResult.java | 27 +++- .../src/org/aion/vm/TransactionExecutor.java | 7 +- 21 files changed, 369 insertions(+), 351 deletions(-) diff --git a/aion_fastvm b/aion_fastvm index 33c554e37c..25dd3c2c61 160000 --- a/aion_fastvm +++ b/aion_fastvm @@ -1 +1 @@ -Subproject commit 33c554e37cd267e85eb376e908e8f3b1511e89a7 +Subproject commit 25dd3c2c61ef01fc62250c6a054a1c816ead53e4 diff --git a/modPrecompiled/src/org/aion/precompiled/contracts/AionAuctionContract.java b/modPrecompiled/src/org/aion/precompiled/contracts/AionAuctionContract.java index cb42013ca1..902637f229 100644 --- a/modPrecompiled/src/org/aion/precompiled/contracts/AionAuctionContract.java +++ b/modPrecompiled/src/org/aion/precompiled/contracts/AionAuctionContract.java @@ -163,24 +163,24 @@ public ExecutionResult execute(byte[] input, long nrg) { // check length for both operations if (input.length < 131) { return new ExecutionResult( - ResultCode.INTERNAL_ERROR, nrg - COST, "incorrect input length".getBytes()); + ResultCode.FAILURE, nrg - COST, "incorrect input length".getBytes()); } int domainNameLength = input[0]; if (domainNameLength < 0) return new ExecutionResult( - ResultCode.INTERNAL_ERROR, nrg - COST, "incorrect input length".getBytes()); + ResultCode.FAILURE, nrg - COST, "incorrect input length".getBytes()); // check if input is too short for extension function if (input.length < 130 + domainNameLength) return new ExecutionResult( - ResultCode.INTERNAL_ERROR, nrg - COST, "incorrect input length".getBytes()); + ResultCode.FAILURE, nrg - COST, "incorrect input length".getBytes()); int balanceLength = input[129 + domainNameLength]; if (balanceLength > 0) { if (input.length < 130 + domainNameLength + balanceLength) { return new ExecutionResult( - ResultCode.INTERNAL_ERROR, nrg - COST, "incorrect input length".getBytes()); + ResultCode.FAILURE, nrg - COST, "incorrect input length".getBytes()); } } @@ -206,14 +206,14 @@ public ExecutionResult execute(byte[] input, long nrg) { // check if the domain name already has active parent domain if (hasActiveParentDomain(domainNameRaw)) return new ExecutionResult( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, nrg - COST, "the given domain name has a parent that is already active".getBytes()); // check if the domain name is valid to register if (!isValidDomainName(domainNameRaw)) return new ExecutionResult( - ResultCode.INTERNAL_ERROR, nrg - COST, "domain name is invalid".getBytes()); + ResultCode.FAILURE, nrg - COST, "domain name is invalid".getBytes()); // add zeros for storing byte[] domainNameInBytesWithZeros = addLeadingZeros(domainNameInBytes); @@ -232,12 +232,12 @@ public ExecutionResult execute(byte[] input, long nrg) { // verify public key matches owner if (!b) { return new ExecutionResult( - ResultCode.INTERNAL_ERROR, nrg - COST, "incorrect signature".getBytes()); + ResultCode.FAILURE, nrg - COST, "incorrect signature".getBytes()); } if (!bidderAddress.equals(Address.wrap(sig.getAddress()))) { return new ExecutionResult( - ResultCode.INTERNAL_ERROR, nrg - COST, "incorrect key".getBytes()); + ResultCode.FAILURE, nrg - COST, "incorrect key".getBytes()); } // if this domain name does not have an callerAddress @@ -263,17 +263,17 @@ public ExecutionResult execute(byte[] input, long nrg) { // check if bidValue is valid (greater than 0) if (bidValue.compareTo(new BigInteger("0")) < 0) return new ExecutionResult( - ResultCode.INTERNAL_ERROR, nrg - COST, "negative bid value".getBytes()); + ResultCode.FAILURE, nrg - COST, "negative bid value".getBytes()); // check bidder addr and its balance if (this.track.hasAccountState(bidderAddress)) { if (this.track.getAccountState(bidderAddress).getBalance().compareTo(bidValue) < 0) { return new ExecutionResult( - ResultCode.INTERNAL_ERROR, nrg - COST, "insufficient balance".getBytes()); + ResultCode.FAILURE, nrg - COST, "insufficient balance".getBytes()); } } else return new ExecutionResult( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, nrg - COST, "bidder account does not exist".getBytes()); @@ -341,7 +341,7 @@ private ExecutionResult extensionRequest(Address domainAddress, long nrg) { if (expireDateFromStorage.getTime() < currentDate.getTime() || difference > ACTIVE_TIME.intValue()) { return new ExecutionResult( - ResultCode.INTERNAL_ERROR, COST - nrg, "already been extended".getBytes()); + ResultCode.FAILURE, COST - nrg, "already been extended".getBytes()); } // add the new expire date diff --git a/modPrecompiled/src/org/aion/precompiled/contracts/AionNameServiceContract.java b/modPrecompiled/src/org/aion/precompiled/contracts/AionNameServiceContract.java index 263ac7f3ba..5982940857 100644 --- a/modPrecompiled/src/org/aion/precompiled/contracts/AionNameServiceContract.java +++ b/modPrecompiled/src/org/aion/precompiled/contracts/AionNameServiceContract.java @@ -146,7 +146,7 @@ public AionNameServiceContract( public ExecutionResult execute(byte[] input, long nrg) { // check for correct input length if (input.length != 130 && input.length != 226) - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); // declare variables for parsing the byte[] input and storing each value byte[] addressFirstPart = new byte[16]; @@ -185,12 +185,12 @@ public ExecutionResult execute(byte[] input, long nrg) { subdomainName = new String(trimmedSubdomainNameInBytes, "UTF-8"); if (!isValidDomainName(this.domainName)) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } domains.put(this.domainName, this.address); } catch (UnsupportedEncodingException a) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } } @@ -201,12 +201,12 @@ public ExecutionResult execute(byte[] input, long nrg) { boolean b = ECKeyEd25519.verify(data, sig.getSignature(), sig.getPubkey(null)); if (!b) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } // verify public key matches owner if (!this.ownerAddress.equals(Address.wrap(sig.getAddress()))) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } // operation: {1-setResolver, 2-setTTL, 3-transferOwnership, 4-transferSubdomainOwnership} @@ -237,7 +237,7 @@ public ExecutionResult execute(byte[] input, long nrg) { addressSecondPart, subdomainName); default: - return new ExecutionResult(ResultCode.INTERNAL_ERROR, nrg); // unsupported operation + return new ExecutionResult(ResultCode.FAILURE, nrg); // unsupported operation } } @@ -275,7 +275,7 @@ private ExecutionResult transferOwnership( if (nrg < TRANSFER_COST) return new ExecutionResult(ResultCode.OUT_OF_NRG, 0); if (!isValidOwnerAddress(Address.wrap(combineTwoBytes(addr1, addr2)))) - return new ExecutionResult(ResultCode.INTERNAL_ERROR, nrg); + return new ExecutionResult(ResultCode.FAILURE, nrg); Address.wrap(combineTwoBytes(addr1, addr2)); storeResult(hash1, hash2, addr1, addr2); @@ -299,7 +299,7 @@ private ExecutionResult transferSubdomainOwnership( if (nrg < TRANSFER_COST) return new ExecutionResult(ResultCode.OUT_OF_NRG, 0); if (!isValidOwnerAddress(Address.wrap(combineTwoBytes(addr1, addr2)))) - return new ExecutionResult(ResultCode.INTERNAL_ERROR, nrg); + return new ExecutionResult(ResultCode.FAILURE, nrg); Address sdAddress = Address.wrap(subdomainAddress); @@ -308,7 +308,7 @@ private ExecutionResult transferSubdomainOwnership( this.track.addStorageRow(sdAddress, new DataWord(hash2), new DataWord(addr2)); return new ExecutionResult(ResultCode.SUCCESS, nrg - TRANSFER_COST); } - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } /** diff --git a/modPrecompiled/src/org/aion/precompiled/contracts/EDVerifyContract.java b/modPrecompiled/src/org/aion/precompiled/contracts/EDVerifyContract.java index 1e19dadaf8..5a4d3986d7 100644 --- a/modPrecompiled/src/org/aion/precompiled/contracts/EDVerifyContract.java +++ b/modPrecompiled/src/org/aion/precompiled/contracts/EDVerifyContract.java @@ -67,7 +67,7 @@ public IExecutionResult execute(byte[] input, long nrgLimit) { result[0] = verify ? (byte) 1 : (byte) 0; return new ExecutionResult(ExecutionResult.ResultCode.SUCCESS, nrgLimit - COST, result); } catch (Exception e) { - return new ExecutionResult(ExecutionResult.ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ExecutionResult.ResultCode.FAILURE, 0); } } } diff --git a/modPrecompiled/src/org/aion/precompiled/contracts/KeccakHash.java b/modPrecompiled/src/org/aion/precompiled/contracts/KeccakHash.java index bf4ff331cf..5f4ee05d31 100644 --- a/modPrecompiled/src/org/aion/precompiled/contracts/KeccakHash.java +++ b/modPrecompiled/src/org/aion/precompiled/contracts/KeccakHash.java @@ -49,7 +49,7 @@ public ExecutionResult execute(byte[] input, long nrg) { // check length if (input.length < 1) return new ExecutionResult( - ResultCode.INTERNAL_ERROR, nrg - DEFAULT_COST, "input too short".getBytes()); + ResultCode.FAILURE, nrg - DEFAULT_COST, "input too short".getBytes()); byte[] hash = keccak256(input); return new ExecutionResult(ResultCode.SUCCESS, nrg - DEFAULT_COST - additionalNRG, hash); diff --git a/modPrecompiled/src/org/aion/precompiled/contracts/MultiSignatureContract.java b/modPrecompiled/src/org/aion/precompiled/contracts/MultiSignatureContract.java index c3a38e799e..caf51dcccf 100644 --- a/modPrecompiled/src/org/aion/precompiled/contracts/MultiSignatureContract.java +++ b/modPrecompiled/src/org/aion/precompiled/contracts/MultiSignatureContract.java @@ -258,10 +258,10 @@ public ExecutionResult execute(byte[] input, long nrg) { return new ExecutionResult(ResultCode.OUT_OF_NRG, 0); } if (input == null) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } if (input.length < 1) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } int operation = input[0]; @@ -272,7 +272,7 @@ public ExecutionResult execute(byte[] input, long nrg) { case 1: return sendTransaction(input, nrg); default: - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } } @@ -285,7 +285,7 @@ public ExecutionResult execute(byte[] input, long nrg) { */ private ExecutionResult createWallet(byte[] input, long nrg) { if (input.length < 1 + Long.BYTES) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } ByteBuffer thresh = ByteBuffer.allocate(Long.BYTES); @@ -299,14 +299,14 @@ private ExecutionResult createWallet(byte[] input, long nrg) { return new ExecutionResult(ResultCode.INVALID_NRG_LIMIT, nrg); } if (owners == null) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } if ((owners.size() < MIN_OWNERS) || (owners.size() > MAX_OWNERS)) { // sanity check... owners should be null in both these cases really - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } if ((threshold < MIN_THRESH) || (threshold > owners.size())) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } Address wallet = initNewWallet(owners, threshold); @@ -324,7 +324,7 @@ private ExecutionResult createWallet(byte[] input, long nrg) { private ExecutionResult sendTransaction(byte[] input, long nrg) { int length = input.length; if (length > 1 + ADDR_LEN + (SIG_LEN * MAX_OWNERS) + AMOUNT_LEN + Long.BYTES + ADDR_LEN) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } int walletStart = 1; @@ -335,7 +335,7 @@ private ExecutionResult sendTransaction(byte[] input, long nrg) { // Ensures input is min expected size except possibly signatures, which is checked below. if (sigsStart > amountStart) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } Address wallet = new Address(Arrays.copyOfRange(input, walletStart, sigsStart)); @@ -353,19 +353,19 @@ private ExecutionResult sendTransaction(byte[] input, long nrg) { } if (track.getStorageValue(wallet, new DataWord(getMetaDataKey())) == null) { // Then wallet is not the address of a multi-sig wallet. - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } if (sigs == null) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } byte[] msg = constructMsg(wallet, track.getNonce(wallet), recipient, amount, nrgPrice); if (amount.compareTo(BigInteger.ZERO) < 0) { // Attempt to transfer negative amount. - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } if (!areValidSignatures(wallet, sigs, msg)) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } if (track.getBalance(wallet).compareTo(amount) < 0) { // Attempt to transfer more than available balance. diff --git a/modPrecompiled/src/org/aion/precompiled/contracts/TRS/TRSqueryContract.java b/modPrecompiled/src/org/aion/precompiled/contracts/TRS/TRSqueryContract.java index d020c214f0..914a0d9bb7 100644 --- a/modPrecompiled/src/org/aion/precompiled/contracts/TRS/TRSqueryContract.java +++ b/modPrecompiled/src/org/aion/precompiled/contracts/TRS/TRSqueryContract.java @@ -180,10 +180,10 @@ public TRSqueryContract( @Override public ExecutionResult execute(byte[] input, long nrgLimit) { if (input == null) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } if (input.length == 0) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } if (nrgLimit < COST) { return new ExecutionResult(ResultCode.OUT_OF_NRG, 0); @@ -207,7 +207,7 @@ public ExecutionResult execute(byte[] input, long nrgLimit) { case 5: return availableForWithdrawalAt(input, nrgLimit); default: - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } } @@ -232,7 +232,7 @@ private ExecutionResult isStarted(byte[] input, long nrgLimit) { final int len = 33; if (input.length != len) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } byte[] result = new byte[1]; @@ -264,7 +264,7 @@ private ExecutionResult isLocked(byte[] input, long nrgLimit) { final int len = 33; if (input.length != len) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } byte[] result = new byte[1]; @@ -297,7 +297,7 @@ private ExecutionResult isDirectDepositEnabled(byte[] input, long nrgLimit) { final int len = 33; if (input.length != len) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } byte[] result = new byte[1]; @@ -337,7 +337,7 @@ private ExecutionResult period(byte[] input, long nrgLimit) { final int len = 33; if (input.length != len) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } // Grab the contract address and block number and determine the period. @@ -375,7 +375,7 @@ private ExecutionResult periodAt(byte[] input, long nrgLimit) { final int len = 41; if (input.length != len) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } // Grab the contract address and block number and determine the period. @@ -387,7 +387,7 @@ private ExecutionResult periodAt(byte[] input, long nrgLimit) { long blockNum = blockBuf.getLong(); if (blockNum <= 0) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } return determinePeriod(contract, blockchain.getBlockByNumber(blockNum), nrgLimit); @@ -420,13 +420,13 @@ private ExecutionResult availableForWithdrawalAt(byte[] input, long nrgLimit) { final int len = 41; if (input.length != len) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } Address contract = Address.wrap(Arrays.copyOfRange(input, indexContract, indexTimestamp)); byte[] specs = getContractSpecs(contract); if (specs == null) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } // If a contract has its funds open then the fraction is always 1. @@ -440,7 +440,7 @@ private ExecutionResult availableForWithdrawalAt(byte[] input, long nrgLimit) { // This operation is only well-defined when the contract has a start time. Thus the contract // must be in the following state: live. if (!isContractLive(contract)) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES); @@ -500,7 +500,7 @@ private ExecutionResult determinePeriod(Address contract, IBlock block, long nrg byte[] specs = getContractSpecs(contract); if (specs == null) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } // If contract is not yet live we are in period 0. @@ -511,7 +511,7 @@ private ExecutionResult determinePeriod(Address contract, IBlock block, long nrg // Grab the timestamp of block number blockNum and calculate the period the contract is in. if (block == null) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } long blockTime = block.getTimestamp(); diff --git a/modPrecompiled/src/org/aion/precompiled/contracts/TRS/TRSstateContract.java b/modPrecompiled/src/org/aion/precompiled/contracts/TRS/TRSstateContract.java index a865863dd9..f760529ea5 100644 --- a/modPrecompiled/src/org/aion/precompiled/contracts/TRS/TRSstateContract.java +++ b/modPrecompiled/src/org/aion/precompiled/contracts/TRS/TRSstateContract.java @@ -147,10 +147,10 @@ public TRSstateContract( @Override public ExecutionResult execute(byte[] input, long nrgLimit) { if (input == null) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } if (input.length == 0) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } if (nrgLimit < COST) { return new ExecutionResult(ResultCode.OUT_OF_NRG, 0); @@ -170,7 +170,7 @@ public ExecutionResult execute(byte[] input, long nrgLimit) { case 3: return openFunds(input, nrgLimit); default: - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } } @@ -210,18 +210,18 @@ private ExecutionResult create(byte[] input, long nrgLimit) { final int len = 14; if (input.length != len) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } int deposit = input[indexDepo]; if (deposit < 0 || deposit > 3) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } // If request for a test contract, verify caller is Aion. boolean isTestContract = (deposit == 2 || deposit == 3); if (isTestContract && !caller.equals(AION)) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } boolean isDirectDeposit = (deposit == 1 || deposit == 3); @@ -232,14 +232,14 @@ private ExecutionResult create(byte[] input, long nrgLimit) { periods <<= Byte.SIZE; periods |= (input[indexPeriod + 1] & 0xFF); if (periods < 1 || periods > 1200) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } // Grab the precision and percentage and perform the shiftings and verify the range. // 2 byte representation cast to 4-byte int, result is interpreted as unsigned & positive. int precision = input[indexPrecision]; if (precision < 0 || precision > 18) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } // Keep first byte of percentBytes unused (as zero) so result is always unsigned. @@ -249,9 +249,9 @@ private ExecutionResult create(byte[] input, long nrgLimit) { BigInteger percent = new BigInteger(percentBytes); BigDecimal realPercent = new BigDecimal(percent).movePointLeft(precision); if (realPercent.compareTo(BigDecimal.ZERO) < 0) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } else if (realPercent.compareTo(new BigDecimal("100")) > 0) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } // All checks OK. Generate contract address, save the new contract & return to caller. @@ -290,32 +290,32 @@ private ExecutionResult lock(byte[] input, long nrgLimit) { final int len = 33; if (input.length != len) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } // The caller must also be the owner of this contract. Address contract = new Address(Arrays.copyOfRange(input, indexAddr, indexAddr + Address.ADDRESS_LEN)); if (!caller.equals(getContractOwner(contract))) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } // A lock call can only execute if the current state of the TRS contract is as follows: // contract is unlocked & contract is not live. byte[] specs = getContractSpecs(contract); if (specs == null) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } // A contract must have a strictly positive balance before it can be locked. if (getTotalBalance(contract).compareTo(BigInteger.ZERO) <= 0) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } // A lock call can only execute if the contract is in the following state: // contract is not locked and not live and its funds are not open. if (isContractLocked(contract) || isContractLive(contract) || isOpenFunds(contract)) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } // All checks OK. Change contract state to locked. @@ -345,27 +345,27 @@ private ExecutionResult start(byte[] input, long nrgLimit) { final int len = 33; if (input.length != len) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } // The caller must also be the owner of this contract. Address contract = new Address(Arrays.copyOfRange(input, indexAddr, indexAddr + Address.ADDRESS_LEN)); if (!caller.equals(getContractOwner(contract))) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } // A start call can only execute if the current state of the TRS contract is as follows: // contract is locked & contract is not live. byte[] specs = getContractSpecs(contract); if (specs == null) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } // A contract can only be started if it is in the following state: // the contract is locked and not live and its funds are not open. if (!isContractLocked(contract) || isContractLive(contract) || isOpenFunds(contract)) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } // All checks OK. Change contract state to live and save set bonus balance for the contract. @@ -397,30 +397,30 @@ private ExecutionResult openFunds(byte[] input, long nrgLimit) { final int len = 33; if (input.length != len) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } Address contract = Address.wrap(Arrays.copyOfRange(input, indexContract, len)); byte[] specs = getContractSpecs(contract); if (specs == null) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } // An openFunds operation can only execute if the caller is the owner of the contract. if (!getContractOwner(contract).equals(caller)) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } // An openFunds operation can only execute if the current state of the TRS contract is: // contract is not live. if (isContractLive(contract)) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } // An openFunds operation can only execute if the contract does not already have its funds // open - this is to protect against re-setting the bonus balance (not necessarily bad?). if (isOpenFunds(contract)) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } setIsOpenFunds(contract); diff --git a/modPrecompiled/src/org/aion/precompiled/contracts/TRS/TRSuseContract.java b/modPrecompiled/src/org/aion/precompiled/contracts/TRS/TRSuseContract.java index 0261c315da..5face0ea38 100644 --- a/modPrecompiled/src/org/aion/precompiled/contracts/TRS/TRSuseContract.java +++ b/modPrecompiled/src/org/aion/precompiled/contracts/TRS/TRSuseContract.java @@ -212,10 +212,10 @@ public TRSuseContract( @Override public ExecutionResult execute(byte[] input, long nrgLimit) { if (input == null) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } if (input.length == 0) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } if (nrgLimit < COST) { return new ExecutionResult(ResultCode.OUT_OF_NRG, 0); @@ -241,7 +241,7 @@ public ExecutionResult execute(byte[] input, long nrgLimit) { case 6: return addExtraFunds(input, nrgLimit); default: - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } } @@ -272,26 +272,26 @@ private ExecutionResult deposit(byte[] input, long nrgLimit) { final int len = 161; if (input.length != len) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } Address contract = Address.wrap(Arrays.copyOfRange(input, indexAddress, indexAmount)); byte[] specs = getContractSpecs(contract); if (specs == null) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } // A deposit operation can only execute if direct depositing is enabled or caller is owner. Address owner = getContractOwner(contract); if (!caller.equals(owner) && !isDirDepositsEnabled(contract)) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } // A deposit operation can only execute if the current state of the TRS contract is: // contract is unlocked (and obviously not live -- check this for sanity) and funds are not // open. if (isContractLocked(contract) || isContractLive(contract) || isOpenFunds(contract)) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } // Put amount in a byte array one byte larger with an empty initial byte so it is unsigned. @@ -333,24 +333,24 @@ private ExecutionResult withdraw(byte[] input, long nrgLimit) { final int len = 33; if (input.length != len) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } Address contract = Address.wrap(Arrays.copyOfRange(input, indexAddress, len)); byte[] specs = getContractSpecs(contract); if (specs == null) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } // A withdraw operation can only execute if the current state of the TRS contract is: // contract is live (and obviously locked -- check this for sanity) or contract funds are // open. if (!isOpenFunds(contract) && (!isContractLocked(contract) || !isContractLive(contract))) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } if (!makeWithdrawal(contract, caller)) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } track.flush(); @@ -391,27 +391,27 @@ private ExecutionResult bulkDepositFor(byte[] input, long nrgLimit) { // that the entries portion has a length that is a multiple of an entry length. int len = input.length; if ((len < indexEntries + entryLen) || (len > indexEntries + (entryLen * maxEntries))) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } else if ((len - indexEntries) % entryLen != 0) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } Address contract = Address.wrap(Arrays.copyOfRange(input, indexContract, indexEntries)); byte[] specs = getContractSpecs(contract); if (specs == null) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } // A bulk-deposit-for operation can only execute if the caller is the owner of the contract. if (!getContractOwner(contract).equals(caller)) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } // A bulkDepositFor operation can only execute if the current state of the TRS contract is: // contract is unlocked (and obviously not live -- check this for sanity) and funds are not // open. if (isContractLocked(contract) || isContractLive(contract) || isOpenFunds(contract)) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } // Iterate over every entry in the entries list and attempt to deposit for them. @@ -430,7 +430,7 @@ private ExecutionResult bulkDepositFor(byte[] input, long nrgLimit) { // Verify the account is an Aion address. if (input[index] != AION_PREFIX) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } beneficiaries[i] = Address.wrap(Arrays.copyOfRange(input, index, index + entryAddrLen)); @@ -476,24 +476,24 @@ private ExecutionResult bulkWithdraw(byte[] input, long nrgLimit) { final int len = 33; if (input.length != len) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } Address contract = Address.wrap(Arrays.copyOfRange(input, indexAddress, len)); byte[] specs = getContractSpecs(contract); if (specs == null) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } // A bulk-withdraw operation can only execute if the caller is the owner of the contract. if (!getContractOwner(contract).equals(caller)) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } // A bulk-withdraw operation can only execute if the current state of the TRS contract is: // contract is live (and obviously locked -- check this for sanity) or the funds are open. if (!isOpenFunds(contract) && (!isContractLocked(contract) || !isContractLive(contract))) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } // Iterate over all depositors and withdraw on their behalf. Once here this is a success. @@ -542,33 +542,33 @@ private ExecutionResult refund(byte[] input, long nrgLimit) { final int len = 193; if (input.length != len) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } Address contract = Address.wrap(Arrays.copyOfRange(input, indexContract, indexAccount)); byte[] specs = getContractSpecs(contract); if (specs == null) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } // A refund operation can only execute if the caller is the contract owner. Address owner = getContractOwner(contract); if (!caller.equals(owner)) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } // A refund operation can only execute if the current state of the TRS contract is: // contract is unlocked (and obviously not live -- check this for sanity) and funds are not // open. if (isContractLocked(contract) || isContractLive(contract) || isOpenFunds(contract)) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } // Ensure the account exists (ie. has a positive deposit balance for the contract). Address account = Address.wrap(Arrays.copyOfRange(input, indexAccount, indexAmount)); BigInteger accountBalance = getDepositBalance(contract, account); if (accountBalance.equals(BigInteger.ZERO)) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } // Put amount in a byte array one byte larger with an empty initial byte so it is unsigned. @@ -586,7 +586,7 @@ private ExecutionResult refund(byte[] input, long nrgLimit) { // then update the deposit meta-data (linked list, count, etc.) and refund the account. if (amount.compareTo(BigInteger.ZERO) > 0) { if (!setDepositBalance(contract, account, newBalance)) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } setTotalBalance(contract, getTotalBalance(contract).subtract(amount)); @@ -629,25 +629,25 @@ private ExecutionResult depositFor(byte[] input, long nrgLimit) { final int len = 193; if (input.length != len) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } Address contract = Address.wrap(Arrays.copyOfRange(input, indexContract, indexAccount)); byte[] specs = getContractSpecs(contract); if (specs == null) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } // A depositFor operation can only execute if caller is owner. if (!caller.equals(getContractOwner(contract))) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } // A depositFor operation can only execute if the current state of the TRS contract is: // contract is unlocked (and obviously not live -- check this for sanity) and funds are not // open. if (isContractLocked(contract) || isContractLive(contract) || isOpenFunds(contract)) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } // Put amount in a byte array one byte larger with an empty initial byte so it is unsigned. @@ -663,7 +663,7 @@ private ExecutionResult depositFor(byte[] input, long nrgLimit) { // Verify the account is an Aion address. if (input[indexAccount] != AION_PREFIX) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } Address account = Address.wrap(Arrays.copyOfRange(input, indexAccount, indexAmount)); @@ -697,23 +697,23 @@ private ExecutionResult addExtraFunds(byte[] input, long nrgLimit) { final int len = 161; if (input.length != len) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } Address contract = Address.wrap(Arrays.copyOfRange(input, indexContract, indexAmount)); byte[] specs = getContractSpecs(contract); if (specs == null) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } // A depositFor operation can only execute if caller is owner. if (!caller.equals(getContractOwner(contract))) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } // If contract has its funds open then this operation fails. if (isOpenFunds(contract)) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } // Put amount in a byte array one byte larger with an empty initial byte so it is unsigned. @@ -732,7 +732,7 @@ private ExecutionResult addExtraFunds(byte[] input, long nrgLimit) { track.addBalance(caller, amount.negate()); return new ExecutionResult(ResultCode.SUCCESS, COST - nrgLimit); } - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } // <-------------------------------------HELPER METHODS----------------------------------------> @@ -762,7 +762,7 @@ private ExecutionResult makeDeposit( if (amount.compareTo(BigInteger.ZERO) > 0) { BigInteger currAmount = getDepositBalance(contract, account); if (!setDepositBalance(contract, account, currAmount.add(amount))) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } listAddToHead(contract, account); setTotalBalance(contract, getTotalBalance(contract).add(amount)); diff --git a/modPrecompiled/src/org/aion/precompiled/contracts/TotalCurrencyContract.java b/modPrecompiled/src/org/aion/precompiled/contracts/TotalCurrencyContract.java index d56023623f..107ac84ee0 100644 --- a/modPrecompiled/src/org/aion/precompiled/contracts/TotalCurrencyContract.java +++ b/modPrecompiled/src/org/aion/precompiled/contracts/TotalCurrencyContract.java @@ -128,7 +128,7 @@ private ExecutionResult executeUpdateTotalBalance(byte[] input, long nrg) { } if (input.length < 114) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } // process input data @@ -149,7 +149,7 @@ private ExecutionResult executeUpdateTotalBalance(byte[] input, long nrg) { // verify signature is correct Ed25519Signature sig = Ed25519Signature.fromBytes(sign); if (sig == null) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } byte[] payload = new byte[18]; @@ -157,12 +157,12 @@ private ExecutionResult executeUpdateTotalBalance(byte[] input, long nrg) { boolean b = ECKeyEd25519.verify(payload, sig.getSignature(), sig.getPubkey(null)); if (!b) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } // verify public key matches owner if (!this.ownerAddress.equals(Address.wrap(sig.getAddress()))) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } // payload processing @@ -172,7 +172,7 @@ private ExecutionResult executeUpdateTotalBalance(byte[] input, long nrg) { BigInteger value = BIUtil.toBI(amount); if (signum != 0x0 && signum != 0x1) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } BigInteger finalValue; @@ -182,7 +182,7 @@ private ExecutionResult executeUpdateTotalBalance(byte[] input, long nrg) { } else { // subtraction if (value.compareTo(totalCurrBI) > 0) { - return new ExecutionResult(ResultCode.INTERNAL_ERROR, 0); + return new ExecutionResult(ResultCode.FAILURE, 0); } finalValue = totalCurrBI.subtract(value); diff --git a/modPrecompiled/test/org/aion/precompiled/TRS/TRSqueryContractTest.java b/modPrecompiled/test/org/aion/precompiled/TRS/TRSqueryContractTest.java index ab77cb6a72..5994f00d96 100644 --- a/modPrecompiled/test/org/aion/precompiled/TRS/TRSqueryContractTest.java +++ b/modPrecompiled/test/org/aion/precompiled/TRS/TRSqueryContractTest.java @@ -79,7 +79,7 @@ public void testCreateNullCaller() { public void testCreateNullInput() { TRSqueryContract trs = newTRSqueryContract(getNewExistentAccount(BigInteger.ZERO)); ExecutionResult res = trs.execute(null, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -87,7 +87,7 @@ public void testCreateNullInput() { public void testCreateEmptyInput() { TRSqueryContract trs = newTRSqueryContract(getNewExistentAccount(BigInteger.ZERO)); ExecutionResult res = trs.execute(ByteUtil.EMPTY_BYTE_ARRAY, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -125,7 +125,7 @@ public void testInvalidOperation() { for (int i = Byte.MIN_VALUE; i <= Byte.MAX_VALUE; i++) { if ((i < 0) || (i > MAX_OP)) { input[0] = (byte) i; - assertEquals(ResultCode.INTERNAL_ERROR, trs.execute(input, COST).getResultCode()); + assertEquals(ResultCode.FAILURE, trs.execute(input, COST).getResultCode()); } } } @@ -137,7 +137,7 @@ public void testIsLiveInputTooShort() { Address acct = getNewExistentAccount(DEFAULT_BALANCE); byte[] input = new byte[32]; ExecutionResult res = newTRSqueryContract(acct).execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -146,7 +146,7 @@ public void testIsLiveInputTooLong() { Address acct = getNewExistentAccount(DEFAULT_BALANCE); byte[] input = new byte[34]; ExecutionResult res = newTRSqueryContract(acct).execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -211,7 +211,7 @@ public void testIsLockedInputTooShort() { byte[] input = new byte[32]; input[0] = 0x1; ExecutionResult res = newTRSqueryContract(acct).execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -221,7 +221,7 @@ public void testIsLockedInputTooLong() { byte[] input = new byte[34]; input[0] = 0x1; ExecutionResult res = newTRSqueryContract(acct).execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -286,7 +286,7 @@ public void testIsDepoEnabledInputTooShort() { byte[] input = new byte[32]; input[0] = 0x2; ExecutionResult res = newTRSqueryContract(acct).execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -296,7 +296,7 @@ public void testIsDepoEnabledInputTooLong() { byte[] input = new byte[34]; input[0] = 0x2; ExecutionResult res = newTRSqueryContract(acct).execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -350,7 +350,7 @@ public void testPeriodInputTooShort() { byte[] input = new byte[32]; input[0] = 0x3; ExecutionResult res = newTRSqueryContract(acct).execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -360,7 +360,7 @@ public void testPeriodInputTooLong() { byte[] input = new byte[34]; input[0] = 0x3; ExecutionResult res = newTRSqueryContract(acct).execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -369,7 +369,7 @@ public void testPeriodOfNonExistentContract() { Address acct = getNewExistentAccount(DEFAULT_BALANCE); byte[] input = getPeriodInput(acct); ExecutionResult res = newTRSqueryContract(acct).execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -477,7 +477,7 @@ public void testPeriodAtInputTooShort() { byte[] input = new byte[32]; input[0] = 0x4; ExecutionResult res = newTRSqueryContract(acct).execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -487,7 +487,7 @@ public void testPeriodAtInputTooLong() { byte[] input = new byte[34]; input[0] = 0x4; ExecutionResult res = newTRSqueryContract(acct).execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -496,7 +496,7 @@ public void testPeriodAtNonExistentContract() { Address acct = getNewExistentAccount(DEFAULT_BALANCE); byte[] input = getPeriodAtInput(acct, 0); ExecutionResult res = newTRSqueryContract(acct).execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -506,7 +506,7 @@ public void testPeriodAtNegativeBlockNumber() { Address contract = createLockedAndLiveTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); byte[] input = getPeriodAtInput(contract, -1); ExecutionResult res = newTRSqueryContract(acct).execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -520,7 +520,7 @@ public void testPeriodAtBlockTooLargeAndDoesNotExist() { byte[] input = getPeriodAtInput(contract, numBlocks + 1); ExecutionResult res = newTRSqueryContract(acct).execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -632,7 +632,7 @@ public void testAvailableForInputTooShort() { byte[] input = getAvailableForWithdrawalAtInput(contract, 0); byte[] shortInput = Arrays.copyOf(input, input.length - 1); assertEquals( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, newTRSqueryContract(acct).execute(shortInput, COST).getResultCode()); } @@ -644,7 +644,7 @@ public void testAvailableForInputTooLong() { byte[] longInput = new byte[input.length + 1]; System.arraycopy(input, 0, longInput, 0, input.length); assertEquals( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, newTRSqueryContract(acct).execute(longInput, COST).getResultCode()); } @@ -653,7 +653,7 @@ public void testAvailableForContractNonExistent() { Address acct = getNewExistentAccount(DEFAULT_BALANCE); byte[] input = getAvailableForWithdrawalAtInput(acct, 0); assertEquals( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, newTRSqueryContract(acct).execute(input, COST).getResultCode()); } @@ -663,7 +663,7 @@ public void testAvailableForContractNotYetLive() { Address contract = createTRScontract(acct, false, true, 7, BigInteger.ZERO, 0); byte[] input = getAvailableForWithdrawalAtInput(contract, 0); assertEquals( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, newTRSqueryContract(acct).execute(input, COST).getResultCode()); } diff --git a/modPrecompiled/test/org/aion/precompiled/TRS/TRSstateContractTest.java b/modPrecompiled/test/org/aion/precompiled/TRS/TRSstateContractTest.java index da9779775a..c448784427 100644 --- a/modPrecompiled/test/org/aion/precompiled/TRS/TRSstateContractTest.java +++ b/modPrecompiled/test/org/aion/precompiled/TRS/TRSstateContractTest.java @@ -81,7 +81,7 @@ public void testCreateNullCaller() { public void testCreateNullInput() { TRSstateContract trs = newTRSstateContract(getNewExistentAccount(BigInteger.ZERO)); ExecutionResult res = trs.execute(null, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -89,7 +89,7 @@ public void testCreateNullInput() { public void testCreateEmptyInput() { TRSstateContract trs = newTRSstateContract(getNewExistentAccount(BigInteger.ZERO)); ExecutionResult res = trs.execute(ByteUtil.EMPTY_BYTE_ARRAY, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -119,7 +119,7 @@ public void testInvalidOperation() { for (int i = Byte.MIN_VALUE; i <= Byte.MAX_VALUE; i++) { if ((i < 0) || (i > MAX_OP)) { input[0] = (byte) i; - assertEquals(ResultCode.INTERNAL_ERROR, trs.execute(input, COST).getResultCode()); + assertEquals(ResultCode.FAILURE, trs.execute(input, COST).getResultCode()); } } } @@ -132,13 +132,13 @@ public void testCreateTestModeNotAion() { byte[] input = getCreateInput(true, false, 1, BigInteger.ZERO, 0); TRSstateContract trs = newTRSstateContract(getNewExistentAccount(BigInteger.ZERO)); ExecutionResult res = trs.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); // Test isDirectDeposit true input = getCreateInput(true, true, 1, BigInteger.ZERO, 0); res = trs.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -147,7 +147,7 @@ public void testCreateZeroPeriods() { byte[] input = getCreateInput(false, false, 0, BigInteger.ZERO, 0); TRSstateContract trs = newTRSstateContract(getNewExistentAccount(BigInteger.ZERO)); ExecutionResult res = trs.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -157,13 +157,13 @@ public void testCreatePeriodsTooLarge() { byte[] input = getCreateInput(false, false, 1201, BigInteger.ZERO, 0); TRSstateContract trs = newTRSstateContract(getNewExistentAccount(BigInteger.ZERO)); ExecutionResult res = trs.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); // Largest too-large period: 65,535 input = getCreateInput(false, false, 65_535, BigInteger.ZERO, 0); res = trs.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -173,13 +173,13 @@ public void testCreatePrecisionTooHigh() { byte[] input = getCreateInput(false, false, 1, BigInteger.ZERO, 19); TRSstateContract trs = newTRSstateContract(getNewExistentAccount(BigInteger.ZERO)); ExecutionResult res = trs.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); // Largest too-large precision: 255 input = getCreateInput(false, false, 1, BigInteger.ZERO, 255); res = trs.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -452,14 +452,14 @@ public void testCreateAboveOneHundredPercentage() { byte[] input = getCreateInput(false, false, 1, raw, 0); TRSstateContract trs = newTRSstateContract(caller); ExecutionResult res = trs.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); // Test 18 shifts. raw = new BigInteger("100000000000000000001"); input = getCreateInput(false, false, 1, raw, 18); res = trs.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); // Test all 9 bytes of percent as 1's using zero shifts. @@ -479,13 +479,13 @@ public void testCreateAboveOneHundredPercentage() { raw = new BigInteger(rawBytes); input = getCreateInput(false, false, 1, raw, 0); res = trs.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); // Test all 9 bytes of percent as 1's using 18 shifts -> 4722.36% still no good. input = getCreateInput(false, false, 1, raw, 18); res = trs.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -547,7 +547,7 @@ public void testCreateValidAndInvalidPercentagesByShifting() { byte[] input = getCreateInput(false, false, 1, raw, shifts); TRSstateContract trs = newTRSstateContract(caller); ExecutionResult res = trs.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); // With 12 shifts we have: 872.743562198734% -> no good @@ -555,7 +555,7 @@ public void testCreateValidAndInvalidPercentagesByShifting() { input = getCreateInput(false, false, 1, raw, shifts); trs = newTRSstateContract(caller); res = trs.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); // With 13 shifts we have: 87.2743562198734% -> good @@ -703,7 +703,7 @@ public void testLockAddressTooSmall() { input[0] = (byte) 0x1; TRSstateContract trs = newTRSstateContract(acct); ExecutionResult res = trs.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); // Test on address size 31. @@ -711,7 +711,7 @@ public void testLockAddressTooSmall() { input[0] = (byte) 0x1; trs = newTRSstateContract(acct); res = trs.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -724,7 +724,7 @@ public void testLockAddressTooLarge() { System.arraycopy(contract.toBytes(), 0, input, 1, Address.ADDRESS_LEN); TRSstateContract trs = newTRSstateContract(acct); ExecutionResult res = trs.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -736,7 +736,7 @@ public void testLockNotTRScontractAddress() { byte[] input = getLockInput(acct); TRSstateContract trs = newTRSstateContract(acct); ExecutionResult res = trs.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); // Test attempt to lock what looks like a TRS address (proper prefix). @@ -744,7 +744,7 @@ public void testLockNotTRScontractAddress() { input[input.length - 1] = (byte) ~input[input.length - 1]; trs = newTRSstateContract(acct); res = trs.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -756,7 +756,7 @@ public void testLockNotContractOwner() { byte[] input = getLockInput(contract); TRSstateContract trs = newTRSstateContract(AION); ExecutionResult res = trs.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); // Test in test mode: owner is AION, caller is acct. @@ -764,7 +764,7 @@ public void testLockNotContractOwner() { input = getLockInput(contract); trs = newTRSstateContract(acct); res = trs.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -794,7 +794,7 @@ public void testLockButContractAlreadyLocked() { // attempt to lock the contract again... res = trs.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); // Test in test mode. @@ -819,7 +819,7 @@ public void testLockButContractAlreadyLocked() { // attempt to lock the contract again... res = trs.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -886,7 +886,7 @@ public void testLockButContractIsLive() { input = getLockInput(contract); trs = newTRSstateContract(acct); res = trs.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); // Test in test mode. @@ -904,7 +904,7 @@ public void testLockButContractIsLive() { input = getLockInput(contract); trs = newTRSstateContract(AION); res = trs.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -915,7 +915,7 @@ public void testLockWithContractBalanceZero() { byte[] input = getLockInput(contract); ExecutionResult res = newTRSstateContract(owner).execute(input, COST); AbstractTRS trs = newTRSstateContract(owner); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); assertFalse(isContractLocked(trs, contract)); @@ -929,7 +929,7 @@ public void testLockWithContractBalanceZero() { input = getLockInput(contract); res = newTRSstateContract(owner).execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); assertFalse(isContractLocked(trs, contract)); } @@ -945,7 +945,7 @@ public void testStartAddressTooSmall() { input[0] = (byte) 0x1; TRSstateContract trs = newTRSstateContract(acct); ExecutionResult res = trs.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); // Test on address size 31. @@ -953,7 +953,7 @@ public void testStartAddressTooSmall() { input[0] = (byte) 0x1; trs = newTRSstateContract(acct); res = trs.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -966,7 +966,7 @@ public void testStartAddressTooLarge() { System.arraycopy(contract.toBytes(), 0, input, 1, Address.ADDRESS_LEN); TRSstateContract trs = newTRSstateContract(acct); ExecutionResult res = trs.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -980,7 +980,7 @@ public void testStartNotTRScontractAddress() { System.arraycopy(contract.toBytes(), 0, input, 1, Address.ADDRESS_LEN); TRSstateContract trs = newTRSstateContract(acct); ExecutionResult res = trs.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); repo.incrementNonce(acct); @@ -990,7 +990,7 @@ public void testStartNotTRScontractAddress() { input[input.length - 1] = (byte) ~input[input.length - 1]; // flip a bit trs = newTRSstateContract(acct); res = trs.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -1002,7 +1002,7 @@ public void testStartNotContractOwner() { byte[] input = getLockInput(contract); TRSstateContract trs = newTRSstateContract(AION); ExecutionResult res = trs.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); // Test in test mode: owner is AION, caller is acct. @@ -1010,7 +1010,7 @@ public void testStartNotContractOwner() { input = getLockInput(contract); trs = newTRSstateContract(acct); res = trs.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -1031,7 +1031,7 @@ public void testStartButContractAlreadyLive() { // Try to start contract again. res = trs.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); // Test in test mode. @@ -1048,7 +1048,7 @@ public void testStartButContractAlreadyLive() { // Try to start contract again. res = trs.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -1063,7 +1063,7 @@ public void testStartButContractNotLocked() { byte[] input = getStartInput(contract); ExecutionResult res = trs.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); // Test in test mode. @@ -1074,7 +1074,7 @@ public void testStartButContractNotLocked() { input = getStartInput(contract); trs = newTRSstateContract(acct); res = trs.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -1276,7 +1276,7 @@ public void testOpenFundsInputTooShort() { byte[] input = getOpenFundsInput(contract); byte[] shortInput = Arrays.copyOf(input, input.length - 1); assertEquals( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, newTRSstateContract(acct).execute(shortInput, COST).getResultCode()); } @@ -1289,7 +1289,7 @@ public void testOpenFundsInputTooLong() { byte[] longInput = new byte[input.length + 1]; System.arraycopy(input, 0, longInput, 0, input.length); assertEquals( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, newTRSstateContract(acct).execute(longInput, COST).getResultCode()); } @@ -1301,7 +1301,7 @@ public void testOpenFundsCallerIsNotOwner() { byte[] input = getOpenFundsInput(contract); assertEquals( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, newTRSstateContract(other).execute(input, COST).getResultCode()); } @@ -1312,7 +1312,7 @@ public void testOpenFundsContractIsLive() { byte[] input = getOpenFundsInput(contract); assertEquals( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, newTRSstateContract(acct).execute(input, COST).getResultCode()); } @@ -1321,7 +1321,7 @@ public void testOpenFundsContractNonExistent() { Address acct = getNewExistentAccount(BigInteger.TEN); byte[] input = getOpenFundsInput(acct); assertEquals( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, newTRSstateContract(acct).execute(input, COST).getResultCode()); } @@ -1362,10 +1362,10 @@ public void testOpenFundsMultipleTimes() { assertEquals( ResultCode.SUCCESS, newTRSstateContract(acct).execute(input, COST).getResultCode()); assertEquals( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, newTRSstateContract(acct).execute(input, COST).getResultCode()); assertEquals( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, newTRSstateContract(acct).execute(input, COST).getResultCode()); } @@ -1419,13 +1419,13 @@ public void testOpenFundsWithdrawIsNowWithdrawAll() { // A subsequent withdraw operation should not withdraw anything now. assertEquals( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, newTRSuseContract(acct1).execute(input, COST).getResultCode()); assertEquals( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, newTRSuseContract(acct2).execute(input, COST).getResultCode()); assertEquals( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, newTRSuseContract(acct3).execute(input, COST).getResultCode()); assertEquals(owings1, repo.getBalance(acct1)); assertEquals(owings2, repo.getBalance(acct2)); @@ -1496,7 +1496,7 @@ public void testOpenFundsLockContractNowDisabled() { input = getLockInput(contract); assertEquals( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, newTRSstateContract(acct).execute(input, COST).getResultCode()); } @@ -1512,7 +1512,7 @@ public void testOpenFundsStartContractNowDisabled() { input = getStartInput(contract); assertEquals( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, newTRSstateContract(acct).execute(input, COST).getResultCode()); } @@ -1550,7 +1550,7 @@ public void testOpenFundsNoFundsWithdraw() { // Now try to withdraw. input = getWithdrawInput(contract); assertEquals( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, newTRSuseContract(acct).execute(input, COST).getResultCode()); assertEquals(BigInteger.TEN, repo.getBalance(acct)); } @@ -1568,7 +1568,7 @@ public void testOpenFundsDepositNowDisabled() { // Now try to deposit. input = getDepositInput(contract, BigInteger.ONE); assertEquals( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, newTRSuseContract(acct).execute(input, COST).getResultCode()); assertEquals(BigInteger.TEN, repo.getBalance(acct)); assertEquals(BigInteger.ZERO, getDepositBalance(trs, contract, acct)); @@ -1588,7 +1588,7 @@ public void testOpenFundsDepositForNowDisabled() { // Now try to deposit. input = getDepositForInput(contract, other, BigInteger.ONE); assertEquals( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, newTRSuseContract(acct).execute(input, COST).getResultCode()); assertEquals(BigInteger.TEN, repo.getBalance(acct)); assertEquals(BigInteger.ZERO, getDepositBalance(trs, contract, other)); @@ -1619,7 +1619,7 @@ public void testOpenFundsBulkDepositForNowDisabled() { BigInteger total = deposit.multiply(BigInteger.valueOf(numBeneficiaries)); repo.addBalance(owner, total); input = getBulkDepositForInput(contract, beneficiaries, amounts); - assertEquals(ResultCode.INTERNAL_ERROR, trs.execute(input, COST).getResultCode()); + assertEquals(ResultCode.FAILURE, trs.execute(input, COST).getResultCode()); for (Address acc : beneficiaries) { assertEquals(BigInteger.ZERO, getDepositBalance(trs, contract, acc)); } @@ -1645,7 +1645,7 @@ public void testOpenFundsRefundNowDisabled() { // Now try to refund. input = getRefundInput(contract, other, BigInteger.ONE); assertEquals( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, newTRSuseContract(acct).execute(input, COST).getResultCode()); assertEquals(BigInteger.ONE, getDepositBalance(trs, contract, other)); assertEquals(BigInteger.ZERO, repo.getBalance(other)); @@ -1666,7 +1666,7 @@ public void testOpenFundsAddExtraNowDisabled() { repo.addBalance(acct, extra); input = getAddExtraInput(contract, extra); assertEquals( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, newTRSuseContract(acct).execute(input, COST).getResultCode()); assertEquals(BigInteger.ZERO, getExtraFunds(trs, contract)); } diff --git a/modPrecompiled/test/org/aion/precompiled/TRS/TRSuseContractTest.java b/modPrecompiled/test/org/aion/precompiled/TRS/TRSuseContractTest.java index 06965376aa..602b6313d8 100644 --- a/modPrecompiled/test/org/aion/precompiled/TRS/TRSuseContractTest.java +++ b/modPrecompiled/test/org/aion/precompiled/TRS/TRSuseContractTest.java @@ -80,7 +80,7 @@ public void testCreateNullCaller() { public void testCreateNullInput() { TRSuseContract trs = newTRSuseContract(getNewExistentAccount(BigInteger.ZERO)); ExecutionResult res = trs.execute(null, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -88,7 +88,7 @@ public void testCreateNullInput() { public void testCreateEmptyInput() { TRSuseContract trs = newTRSuseContract(getNewExistentAccount(BigInteger.ZERO)); ExecutionResult res = trs.execute(ByteUtil.EMPTY_BYTE_ARRAY, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -126,7 +126,7 @@ public void testInvalidOperation() { for (int i = Byte.MIN_VALUE; i <= Byte.MAX_VALUE; i++) { if ((i < 0) || (i > MAX_OP)) { input[0] = (byte) i; - assertEquals(ResultCode.INTERNAL_ERROR, trs.execute(input, COST).getResultCode()); + assertEquals(ResultCode.FAILURE, trs.execute(input, COST).getResultCode()); } } } @@ -139,13 +139,13 @@ public void testDepositInputTooShort() { TRSuseContract trs = newTRSuseContract(getNewExistentAccount(BigInteger.ZERO)); byte[] input = new byte[1]; ExecutionResult res = trs.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); // Test on maximum too-small amount. input = new byte[160]; res = trs.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -154,7 +154,7 @@ public void testDepositInputTooLong() { TRSuseContract trs = newTRSuseContract(getNewExistentAccount(BigInteger.ZERO)); byte[] input = new byte[162]; ExecutionResult res = trs.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -165,7 +165,7 @@ public void testDepositToNonExistentContract() { TRSuseContract trs = newTRSuseContract(acct); byte[] input = getDepositInput(acct, BigInteger.TWO); ExecutionResult res = trs.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); // Test on contract address looks like a legit TRS address (proper prefix). @@ -175,7 +175,7 @@ public void testDepositToNonExistentContract() { input = getDepositInput(Address.wrap(addr), BigInteger.TWO); res = trs.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -235,7 +235,7 @@ public void testDepositDirectDepositsDisabledCallerNotOwner() { TRSuseContract trs = newTRSuseContract(acct); byte[] input = getDepositInput(contract, BigInteger.TWO); ExecutionResult res = trs.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -247,7 +247,7 @@ public void testDepositCallerIsContract() { TRSuseContract trs = newTRSuseContract(contract); byte[] input = getDepositInput(contract, BigInteger.TWO); ExecutionResult res = trs.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -523,7 +523,7 @@ public void testDepositWhileTRSisLocked() { TRSuseContract trs = newTRSuseContract(acct); byte[] input = getDepositInput(contract, BigInteger.ONE); ExecutionResult res = trs.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -534,7 +534,7 @@ public void testDepositWhileTRSisLive() { TRSuseContract trs = newTRSuseContract(acct); byte[] input = getDepositInput(contract, BigInteger.ONE); ExecutionResult res = trs.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -744,7 +744,7 @@ public void testWithdrawInputTooShort() { input[0] = 0x1; System.arraycopy(contract.toBytes(), 0, input, 1, Address.ADDRESS_LEN - 1); ExecutionResult res = newTRSuseContract(acct).execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -756,7 +756,7 @@ public void testWithdrawInputTooLong() { input[0] = 0x1; System.arraycopy(contract.toBytes(), 0, input, 1, Address.ADDRESS_LEN); ExecutionResult res = newTRSuseContract(acct).execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -770,7 +770,7 @@ public void testWithdrawContractNotLockedOrLive() { input = getWithdrawInput(contract); ExecutionResult res = newTRSuseContract(acct).execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); assertEquals(DEFAULT_BALANCE, getDepositBalance(newTRSuseContract(acct), contract, acct)); } @@ -790,7 +790,7 @@ public void testWithdrawContractLockedNotLive() { input = getWithdrawInput(contract); ExecutionResult res = newTRSuseContract(acct).execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); assertEquals(DEFAULT_BALANCE, getDepositBalance(newTRSuseContract(acct), contract, acct)); } @@ -909,7 +909,7 @@ public void testWithdrawMultipleTimesSamePeriod() { // Try to keep withdrawing... for (int i = 0; i < 5; i++) { - assertEquals(ResultCode.INTERNAL_ERROR, trs.execute(input, COST).getResultCode()); + assertEquals(ResultCode.FAILURE, trs.execute(input, COST).getResultCode()); assertEquals(expectedBal, repo.getBalance(AION)); } } @@ -1012,7 +1012,7 @@ public void testWithdrawSpecialEventBeforePeriodOne() { // Let's try and withdraw again, now we should not be able to. for (Address acc : contributors) { assertEquals( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, newTRSuseContract(acc).execute(input, COST).getResultCode()); assertEquals(expectedAmt, repo.getBalance(acc)); } @@ -1073,7 +1073,7 @@ public void testWithdrawMultipleTimesInFinalPeriod() { // Try to withdraw again from the final period. for (Address acc : contributors) { assertEquals( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, newTRSuseContract(acc).execute(input, COST).getResultCode()); assertEquals(owings, repo.getBalance(acc)); } @@ -1381,7 +1381,7 @@ public void testWithdrawSpecialEventIsAllFunds() { mockBlockchain(timestamp + 1); for (Address acc : contributors) { assertEquals( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, newTRSuseContract(acc).execute(input, COST).getResultCode()); assertEquals(owings, repo.getBalance(acc)); } @@ -1391,7 +1391,7 @@ public void testWithdrawSpecialEventIsAllFunds() { assertEquals(BigInteger.valueOf(periods), getCurrentPeriod(trs, contract)); for (Address acc : contributors) { assertEquals( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, newTRSuseContract(acc).execute(input, COST).getResultCode()); assertEquals(owings, repo.getBalance(acc)); } @@ -1434,7 +1434,7 @@ public void testWithdrawSpecialEventVeryLarge() { mockBlockchain(timestamp + 1); for (Address acc : contributors) { assertEquals( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, newTRSuseContract(acc).execute(input, COST).getResultCode()); assertEquals(amt, repo.getBalance(acc)); } @@ -1575,13 +1575,13 @@ public void testBulkWithdrawInputTooShort() { input[0] = 0x3; System.arraycopy(contract.toBytes(), 0, input, 1, Address.ADDRESS_LEN - 1); ExecutionResult res = newTRSuseContract(acct).execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); // Test minimum too-short size. input = new byte[1]; res = newTRSuseContract(acct).execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -1593,7 +1593,7 @@ public void testBulkWithdrawInputTooLong() { input[0] = 0x3; System.arraycopy(contract.toBytes(), 0, input, 1, Address.ADDRESS_LEN); ExecutionResult res = newTRSuseContract(acct).execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -1612,7 +1612,7 @@ public void testBulkWithdrawCallerNotOwner() { Set
contributors = getAllDepositors(trs, contract); for (Address acc : contributors) { assertEquals( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, newTRSuseContract(acc).execute(input, COST).getResultCode()); } @@ -1630,7 +1630,7 @@ public void testBulkWithdrawContractNotLockedNotLive() { // Try first with no one in the contract. Caller is owner. byte[] input = getBulkWithdrawInput(contract); assertEquals( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, newTRSuseContract(acct).execute(input, COST).getResultCode()); // Now deposit some and try again. @@ -1639,7 +1639,7 @@ public void testBulkWithdrawContractNotLockedNotLive() { ResultCode.SUCCESS, newTRSuseContract(acct).execute(input, COST).getResultCode()); input = getBulkWithdrawInput(contract); assertEquals( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, newTRSuseContract(acct).execute(input, COST).getResultCode()); } @@ -1659,7 +1659,7 @@ public void testBulkWithdrawContractLockedNotLive() { // Try to withdraw. input = getBulkWithdrawInput(contract); assertEquals( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, newTRSuseContract(acct).execute(input, COST).getResultCode()); assertEquals(BigInteger.ZERO, repo.getBalance(acct)); } @@ -1946,13 +1946,13 @@ public void testRefundInputTooShort() { Address acct = getNewExistentAccount(DEFAULT_BALANCE); byte[] input = new byte[192]; ExecutionResult res = newTRSuseContract(acct).execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); // Test minimum too-short size. input = new byte[1]; res = newTRSuseContract(acct).execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -1961,7 +1961,7 @@ public void testRefundInputTooLarge() { Address acct = getNewExistentAccount(DEFAULT_BALANCE); byte[] input = new byte[194]; ExecutionResult res = newTRSuseContract(acct).execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -1972,7 +1972,7 @@ public void testRefundBadTRScontract() { Address contract = getNewExistentAccount(DEFAULT_BALANCE); byte[] input = getRefundInput(contract, acct, BigInteger.ZERO); ExecutionResult res = newTRSuseContract(acct).execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); // Test TRS address with TRS prefix, so it looks legit. @@ -1982,7 +1982,7 @@ public void testRefundBadTRScontract() { tempAddrs.add(contract); input = getRefundInput(contract, acct, BigInteger.ZERO); res = newTRSuseContract(acct).execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -2001,7 +2001,7 @@ public void testRefundCallerIsNotOwner() { // acct2 calls refund but owner is acct input = getRefundInput(contract, acct2, BigInteger.ONE); res = trs.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -2015,7 +2015,7 @@ public void testRefundAccountNotInContract() { byte[] input = getRefundInput(contract, acct2, BigInteger.ONE); TRSuseContract trs = newTRSuseContract(acct2); ExecutionResult res = trs.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); // Have others deposit but not acct2 and try again ... should be same result. @@ -2030,7 +2030,7 @@ public void testRefundAccountNotInContract() { input = getRefundInput(contract, acct2, BigInteger.ONE); res = newTRSuseContract(acct2).execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -2053,7 +2053,7 @@ public void testRefundContractIsLocked() { // Now have contract owner try to refund acct2. input = getRefundInput(contract, acct2, BigInteger.ONE); ExecutionResult res = newTRSuseContract(acct).execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -2079,7 +2079,7 @@ public void testRefundContractIsLive() { // Now have contract owner try to refund acct2. input = getRefundInput(contract, acct2, BigInteger.ONE); ExecutionResult res = newTRSuseContract(acct).execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -2272,7 +2272,7 @@ public void testRefundInvalidAccount() { // Now try to refund acct2 again... input = getRefundInput(contract, acct2, BigInteger.ONE); res = newTRSuseContract(acct).execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -2284,7 +2284,7 @@ public void testRefundZeroForNonExistentAccount() { byte[] input = getRefundInput(contract, acct2, BigInteger.ZERO); TRSuseContract trs = newTRSuseContract(acct); ExecutionResult res = trs.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -2304,7 +2304,7 @@ public void testRefundZeroForInvalidAccount() { // Acct2 is now marked invalid. input = getRefundInput(contract, acct2, BigInteger.ZERO); assertEquals( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, newTRSuseContract(acct).execute(input, COST).getResultCode()); } @@ -2361,7 +2361,7 @@ public void testDepositForInputTooLong() { System.arraycopy(input, 0, longInput, 0, input.length); assertEquals( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, newTRSuseContract(acct).execute(longInput, COST).getResultCode()); } @@ -2375,7 +2375,7 @@ public void testDepositForInputTooShort() { System.arraycopy(input, 0, shortInput, 0, input.length - 1); assertEquals( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, newTRSuseContract(acct).execute(shortInput, COST).getResultCode()); } @@ -2386,7 +2386,7 @@ public void testDepositForContractIsLocked() { byte[] input = getDepositForInput(contract, acct, BigInteger.ONE); ExecutionResult res = newTRSuseContract(acct).execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -2398,7 +2398,7 @@ public void testDepositForContractIsLive() { byte[] input = getDepositForInput(contract, acct, BigInteger.ONE); ExecutionResult res = newTRSuseContract(acct).execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -2410,7 +2410,7 @@ public void testDepositForCallerIsNotOwner() { byte[] input = getDepositForInput(contract, whoami, DEFAULT_BALANCE); ExecutionResult res = newTRSuseContract(whoami).execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -2436,7 +2436,7 @@ public void testDepositForNonAionAddressAsDepositor() { byte[] input = getDepositForInput(contract, other, BigInteger.ONE); ExecutionResult res = newTRSuseContract(owner).execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -2450,7 +2450,7 @@ public void testDepositForContractAddressIsInvalid() { byte[] input = getDepositForInput(contract, other, BigInteger.ONE); ExecutionResult res = newTRSuseContract(owner).execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getNrgLeft()); } @@ -2569,7 +2569,7 @@ public void testAddExtraInputTooShort() { byte[] input = getAddExtraInput(contract, DEFAULT_BALANCE); byte[] shortInput = Arrays.copyOf(input, input.length - 1); assertEquals( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, newTRSuseContract(acct).execute(shortInput, COST).getResultCode()); } @@ -2581,7 +2581,7 @@ public void testAddExtraInputTooLong() { byte[] longInput = new byte[input.length + 1]; System.arraycopy(input, 0, longInput, 0, input.length); assertEquals( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, newTRSuseContract(acct).execute(longInput, COST).getResultCode()); } @@ -2590,7 +2590,7 @@ public void testAddExtraContractNonExistent() { Address acct = getNewExistentAccount(DEFAULT_BALANCE); byte[] input = getAddExtraInput(acct, DEFAULT_BALANCE); assertEquals( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, newTRSuseContract(acct).execute(input, COST).getResultCode()); } @@ -2600,7 +2600,7 @@ public void testAddExtraCallerIsNotOwner() { Address contract = createTRScontract(AION, false, true, 1, BigInteger.ZERO, 0); byte[] input = getAddExtraInput(contract, DEFAULT_BALANCE); assertEquals( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, newTRSuseContract(acct).execute(input, COST).getResultCode()); } @@ -2625,7 +2625,7 @@ public void testAddExtraFundsOpen() { input = getAddExtraInput(contract, DEFAULT_BALANCE); assertEquals( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, newTRSuseContract(acct).execute(input, COST).getResultCode()); } @@ -2645,7 +2645,7 @@ public void testAddZeroExtraFunds() { AbstractTRS trs = newTRSuseContract(acct); byte[] input = getAddExtraInput(contract, BigInteger.ZERO); - assertEquals(ResultCode.INTERNAL_ERROR, trs.execute(input, COST).getResultCode()); + assertEquals(ResultCode.FAILURE, trs.execute(input, COST).getResultCode()); assertEquals(BigInteger.ZERO, getExtraFunds(trs, contract)); assertEquals(DEFAULT_BALANCE, repo.getBalance(acct)); } @@ -2831,7 +2831,7 @@ public void testAddExtraWithdrawMultipleTimesSpecialPeriod() { if (withdraw) { // These accounts have already withdrawn this period. assertEquals( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, newTRSuseContract(acc).execute(input, COST).getResultCode()); } else { assertEquals( @@ -2982,7 +2982,7 @@ public void testAddExtraWithdrawMultipleTimesFinalPeriod() { BigInteger share = getExtraShare(trs, contract, acc, fraction, currPeriod); input = getWithdrawInput(contract); assertEquals( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, newTRSuseContract(acc).execute(input, COST).getResultCode()); } } @@ -3055,7 +3055,7 @@ public void testBulkDepositForInputTooShort() { byte[] input = makeBulkDepositForInput(contract, numBeneficiaries, BigInteger.TEN); byte[] shortInput = Arrays.copyOf(input, input.length - 1); assertEquals( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, newTRSuseContract(acct).execute(shortInput, COST).getResultCode()); } @@ -3069,7 +3069,7 @@ public void testBulkDepositForInputTooLong() { byte[] longInput = new byte[input.length + 1]; System.arraycopy(input, 0, longInput, 0, input.length); assertEquals( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, newTRSuseContract(acct).execute(longInput, COST).getResultCode()); } @@ -3079,7 +3079,7 @@ public void testBulkDepositForContractNonExistent() { Address acct = getNewExistentAccount(BigInteger.ONE); byte[] input = makeBulkDepositForInput(acct, numBeneficiaries, BigInteger.TEN); assertEquals( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, newTRSuseContract(acct).execute(input, COST).getResultCode()); } @@ -3093,7 +3093,7 @@ public void testBulkDepositForCallerIsNotOwner() { BigInteger.TEN.multiply(BigInteger.valueOf(numBeneficiaries))); byte[] input = makeBulkDepositForInput(contract, numBeneficiaries, BigInteger.TEN); assertEquals( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, newTRSuseContract(whoami).execute(input, COST).getResultCode()); } @@ -3104,7 +3104,7 @@ public void testBulkDepositForContractLocked() { Address contract = createAndLockTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); byte[] input = makeBulkDepositForInput(contract, numBeneficiaries, BigInteger.TEN); assertEquals( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, newTRSuseContract(acct).execute(input, COST).getResultCode()); } @@ -3116,7 +3116,7 @@ public void testBulkDepositForContractLive() { createLockedAndLiveTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); byte[] input = makeBulkDepositForInput(contract, numBeneficiaries, BigInteger.TEN); assertEquals( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, newTRSuseContract(acct).execute(input, COST).getResultCode()); } @@ -3131,7 +3131,7 @@ public void testBulkDepositForZeroBeneficiaries() { byte[] noBeneficiaries = new byte[33]; System.arraycopy(input, 0, noBeneficiaries, 0, Address.ADDRESS_LEN + 1); assertEquals( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, newTRSuseContract(acct).execute(noBeneficiaries, COST).getResultCode()); } @@ -3146,14 +3146,14 @@ public void testBulkDepositForBeneficiaryLengthOff() { byte[] inputOff = new byte[input.length - 1]; System.arraycopy(input, 0, inputOff, 0, input.length - 1); assertEquals( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, newTRSuseContract(acct).execute(inputOff, COST).getResultCode()); // Add a byte to the array. inputOff = new byte[input.length + 1]; System.arraycopy(input, 0, inputOff, 0, input.length); assertEquals( - ResultCode.INTERNAL_ERROR, + ResultCode.FAILURE, newTRSuseContract(acct).execute(inputOff, COST).getResultCode()); } diff --git a/modPrecompiled/test/org/aion/precompiled/contracts/AionAuctionContractTest.java b/modPrecompiled/test/org/aion/precompiled/contracts/AionAuctionContractTest.java index 854b8e3482..af42c0f264 100644 --- a/modPrecompiled/test/org/aion/precompiled/contracts/AionAuctionContractTest.java +++ b/modPrecompiled/test/org/aion/precompiled/contracts/AionAuctionContractTest.java @@ -401,7 +401,7 @@ public void testActiveDomainTimeExtensionRequestPass() { assertEquals(ResultCode.SUCCESS, res.getResultCode()); - assertEquals(ResultCode.INTERNAL_ERROR, res2.getResultCode()); + assertEquals(ResultCode.FAILURE, res2.getResultCode()); Assert.assertArrayEquals("already been extended".getBytes(), res2.getOutput()); // uncomment to see extension output @@ -432,7 +432,7 @@ public void testActiveDomainTimeExtensionRequestFailure() { byte[] combined2 = setupForExtension(domainName1, Address.wrap(k2.getAddress())); ExecutionResult res = aac.execute(combined2, inputEnergy); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); } @Test @@ -458,7 +458,7 @@ public void testHasActiveParentDomain() { AionAuctionContract aac2 = new AionAuctionContract(repo, AION, blockchain); ExecutionResult result2 = aac2.execute(combined2, inputEnergy); - assertEquals(ResultCode.INTERNAL_ERROR, result2.getResultCode()); + assertEquals(ResultCode.FAILURE, result2.getResultCode()); } @Test(expected = IllegalArgumentException.class) @@ -478,7 +478,7 @@ public void testInvalidDomainNames() { defaultKey); AionAuctionContract aac = new AionAuctionContract(repo, AION, blockchain); ExecutionResult result = aac.execute(combined, DEFAULT_INPUT_NRG); - assertEquals(ResultCode.INTERNAL_ERROR, result.getResultCode()); + assertEquals(ResultCode.FAILURE, result.getResultCode()); byte[] combined2 = setupInputs( @@ -488,7 +488,7 @@ public void testInvalidDomainNames() { defaultKey); AionAuctionContract aac2 = new AionAuctionContract(repo, AION, blockchain); ExecutionResult result2 = aac2.execute(combined2, DEFAULT_INPUT_NRG); - assertEquals(ResultCode.INTERNAL_ERROR, result2.getResultCode()); + assertEquals(ResultCode.FAILURE, result2.getResultCode()); byte[] combined3 = setupInputs( @@ -498,7 +498,7 @@ public void testInvalidDomainNames() { defaultKey); AionAuctionContract aac3 = new AionAuctionContract(repo, AION, blockchain); ExecutionResult result3 = aac3.execute(combined3, DEFAULT_INPUT_NRG); - assertEquals(ResultCode.INTERNAL_ERROR, result3.getResultCode()); + assertEquals(ResultCode.FAILURE, result3.getResultCode()); byte[] combined4 = setupInputs( @@ -508,7 +508,7 @@ public void testInvalidDomainNames() { defaultKey); AionAuctionContract aac4 = new AionAuctionContract(repo, AION, blockchain); ExecutionResult result4 = aac4.execute(combined4, DEFAULT_INPUT_NRG); - assertEquals(ResultCode.INTERNAL_ERROR, result4.getResultCode()); + assertEquals(ResultCode.FAILURE, result4.getResultCode()); byte[] combined5 = setupInputs( @@ -518,7 +518,7 @@ public void testInvalidDomainNames() { defaultKey); AionAuctionContract aac5 = new AionAuctionContract(repo, AION, blockchain); ExecutionResult result5 = aac5.execute(combined5, DEFAULT_INPUT_NRG); - assertEquals(ResultCode.INTERNAL_ERROR, result5.getResultCode()); + assertEquals(ResultCode.FAILURE, result5.getResultCode()); } @Test @@ -532,7 +532,7 @@ public void testBidderAddressDoesNotExist() { notExistKey); AionAuctionContract aac = new AionAuctionContract(repo, AION, blockchain); ExecutionResult result = aac.execute(combined, DEFAULT_INPUT_NRG); - assertEquals(ResultCode.INTERNAL_ERROR, result.getResultCode()); + assertEquals(ResultCode.FAILURE, result.getResultCode()); Assert.assertArrayEquals("bidder account does not exist".getBytes(), result.getOutput()); } @@ -549,7 +549,7 @@ public void testInsufficientBalance() { defaultBidAmount.toByteArray(), poorKey); ExecutionResult result = testAAC.execute(combined3, DEFAULT_INPUT_NRG); - assertEquals(ResultCode.INTERNAL_ERROR, result.getResultCode()); + assertEquals(ResultCode.FAILURE, result.getResultCode()); Assert.assertArrayEquals("insufficient balance".getBytes(), result.getOutput()); } @@ -572,7 +572,7 @@ public void testIncorrectInputLength() { System.arraycopy(input, 0, wrongInput2, 0, 131); ExecutionResult result2 = testAAC.execute(wrongInput2, DEFAULT_INPUT_NRG); - assertEquals(ResultCode.INTERNAL_ERROR, result.getResultCode()); + assertEquals(ResultCode.FAILURE, result.getResultCode()); assertEquals(result.getNrgLeft(), 4000); Assert.assertArrayEquals("incorrect input length".getBytes(), result.getOutput()); @@ -594,7 +594,7 @@ public void testIncorrectSignature() { input[110] = (byte) ~input[65]; ExecutionResult result = testAAC.execute(input, DEFAULT_INPUT_NRG); - assertEquals(ResultCode.INTERNAL_ERROR, result.getResultCode()); + assertEquals(ResultCode.FAILURE, result.getResultCode()); assertEquals(result.getNrgLeft(), 4000); Assert.assertArrayEquals("incorrect signature".getBytes(), result.getOutput()); } @@ -611,7 +611,7 @@ public void testIncorrectPublicKey() { anotherKey); ExecutionResult result = testAAC.execute(input, DEFAULT_INPUT_NRG); - assertEquals(ResultCode.INTERNAL_ERROR, result.getResultCode()); + assertEquals(ResultCode.FAILURE, result.getResultCode()); assertEquals(result.getNrgLeft(), 4000); Assert.assertArrayEquals("incorrect key".getBytes(), result.getOutput()); } @@ -642,7 +642,7 @@ public void testNegativeBidValue() { defaultKey); ExecutionResult result = testAAC.execute(input, DEFAULT_INPUT_NRG); - assertEquals(ResultCode.INTERNAL_ERROR, result.getResultCode()); + assertEquals(ResultCode.FAILURE, result.getResultCode()); assertEquals(result.getNrgLeft(), 4000); Assert.assertArrayEquals("negative bid value".getBytes(), result.getOutput()); } diff --git a/modPrecompiled/test/org/aion/precompiled/contracts/AionNameServiceContractTest.java b/modPrecompiled/test/org/aion/precompiled/contracts/AionNameServiceContractTest.java index 4fc1b7f4a3..8d6bc687dc 100644 --- a/modPrecompiled/test/org/aion/precompiled/contracts/AionNameServiceContractTest.java +++ b/modPrecompiled/test/org/aion/precompiled/contracts/AionNameServiceContractTest.java @@ -234,7 +234,7 @@ public void testInvalidValues() { assertEquals(ResultCode.SUCCESS, res.getResultCode()); assertEquals(3000L, res.getNrgLeft()); - assertEquals(ResultCode.INTERNAL_ERROR, res2.getResultCode()); + assertEquals(ResultCode.FAILURE, res2.getResultCode()); assertEquals(0, res2.getNrgLeft()); } @@ -417,7 +417,7 @@ public void testNotASubdomain() { ExecutionResult res = ansc.execute(combined, inputEnergy); // check for success and failure - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(expectedEnergyLeft, res.getNrgLeft()); } @@ -447,7 +447,7 @@ public void incorrectInputLength() { Address actualReturnedAddress = ansc.getResolverAddress(); // check for success and failure - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(expectedEnergyLeft, res.getNrgLeft()); assertEquals(emptyAddress, actualReturnedAddress); } @@ -483,7 +483,7 @@ public void testIncorrectSignature() { Address actualReturnedAddress = ansc.getResolverAddress(); // check for success and failure - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(expectedEnergyLeft, res.getNrgLeft()); // since the signature is incorrect, contract is not modified assertEquals(emptyAddress, actualReturnedAddress); @@ -513,7 +513,7 @@ public void testUnsupportedOperation() { Address actualReturnedAddress = ansc.getResolverAddress(); // check for success and failure - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(expectedEnergyLeft, res.getNrgLeft()); assertEquals(emptyAddress, actualReturnedAddress); } @@ -548,7 +548,7 @@ public void testIncorrectPublicKey() { Address actualReturnedAddress = ansc.getResolverAddress(); // check for success and failure - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(expectedEnergyLeft, res.getNrgLeft()); // since the signature is incorrect, contract is not modified assertEquals(emptyAddress, actualReturnedAddress); @@ -594,7 +594,7 @@ public void testTransferOwnership() { assertEquals(newAddress1, actualReturnedAddress); // check for success and failure for execute with invalid new address - assertEquals(ResultCode.INTERNAL_ERROR, res2.getResultCode()); + assertEquals(ResultCode.FAILURE, res2.getResultCode()); assertEquals(inputEnergy, res2.getNrgLeft()); assertEquals(newAddress1, actualReturnedAddress2); } @@ -725,7 +725,7 @@ public void testSubdomainDoesNotExist() { // check for success and failure assertEquals(ResultCode.SUCCESS, res.getResultCode()); assertEquals(expectedEnergyLeft, res.getNrgLeft()); - assertEquals(ResultCode.INTERNAL_ERROR, res2.getResultCode()); + assertEquals(ResultCode.FAILURE, res2.getResultCode()); assertEquals(expectedEnergyLeft2, res2.getNrgLeft()); } diff --git a/modPrecompiled/test/org/aion/precompiled/contracts/Blake2bHashTest.java b/modPrecompiled/test/org/aion/precompiled/contracts/Blake2bHashTest.java index 041f5fbbe7..ee867cf89a 100644 --- a/modPrecompiled/test/org/aion/precompiled/contracts/Blake2bHashTest.java +++ b/modPrecompiled/test/org/aion/precompiled/contracts/Blake2bHashTest.java @@ -162,6 +162,6 @@ public void consistencyTest(){ public void testInvalidOperation() { byte[] input = Blake2bHashContract.setupInput(3, byteArray1); ExecutionResult res = blake2bHasher.execute(input, INPUT_NRG); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); } } diff --git a/modPrecompiled/test/org/aion/precompiled/contracts/KeccakHashTest.java b/modPrecompiled/test/org/aion/precompiled/contracts/KeccakHashTest.java index 5f02738b0e..6361d19c45 100644 --- a/modPrecompiled/test/org/aion/precompiled/contracts/KeccakHashTest.java +++ b/modPrecompiled/test/org/aion/precompiled/contracts/KeccakHashTest.java @@ -65,7 +65,7 @@ public void testKeccak256() { @Test public void invalidInputLength() { ExecutionResult res2 = keccakHasher.execute(shortByteArray, INPUT_NRG); - assertEquals(ResultCode.INTERNAL_ERROR, res2.getResultCode()); + assertEquals(ResultCode.FAILURE, res2.getResultCode()); } @Test diff --git a/modPrecompiled/test/org/aion/precompiled/contracts/MultiSignatureContractTest.java b/modPrecompiled/test/org/aion/precompiled/contracts/MultiSignatureContractTest.java index 56eebd82bc..ffa025a76b 100644 --- a/modPrecompiled/test/org/aion/precompiled/contracts/MultiSignatureContractTest.java +++ b/modPrecompiled/test/org/aion/precompiled/contracts/MultiSignatureContractTest.java @@ -453,20 +453,20 @@ public void testNrgAboveThanCost() { @Test public void testNullInput() { Address caller = getExistentAddress(BigInteger.ZERO); - execute(caller, null, COST, ResultCode.INTERNAL_ERROR, 0); + execute(caller, null, COST, ResultCode.FAILURE, 0); } @Test public void testEmptyInput() { Address caller = getExistentAddress(BigInteger.ZERO); - execute(caller, ByteUtil.EMPTY_BYTE_ARRAY, COST, ResultCode.INTERNAL_ERROR, 0); + execute(caller, ByteUtil.EMPTY_BYTE_ARRAY, COST, ResultCode.FAILURE, 0); } @Test public void testInputWithOperationOnly() { Address caller = getExistentAddress(BigInteger.ZERO); - execute(caller, new byte[] {(byte) 0x0}, COST, ResultCode.INTERNAL_ERROR, 0); - execute(caller, new byte[] {(byte) 0x1}, COST, ResultCode.INTERNAL_ERROR, 0); + execute(caller, new byte[] {(byte) 0x0}, COST, ResultCode.FAILURE, 0); + execute(caller, new byte[] {(byte) 0x1}, COST, ResultCode.FAILURE, 0); } @Test @@ -481,7 +481,7 @@ public void testInputWithUnsupportedOperation() { for (int i = Byte.MIN_VALUE; i <= Byte.MAX_VALUE; i++) { if ((i != 0) && (i != 1)) { input[0] = (byte) i; - execute(caller, input, COST, ResultCode.INTERNAL_ERROR, 0); + execute(caller, input, COST, ResultCode.FAILURE, 0); } } } @@ -495,13 +495,13 @@ public void testCreateWalletThresholdBelowLegalLimit() { Address caller = owners.get(0); byte[] input = MultiSignatureContract.constructCreateWalletInput(Long.MIN_VALUE, owners); - execute(caller, input, COST, ResultCode.INTERNAL_ERROR, 0); + execute(caller, input, COST, ResultCode.FAILURE, 0); // Test with max illegal value. input = MultiSignatureContract.constructCreateWalletInput( MultiSignatureContract.MIN_THRESH - 1, owners); - execute(caller, input, COST, ResultCode.INTERNAL_ERROR, 0); + execute(caller, input, COST, ResultCode.FAILURE, 0); } @Test @@ -511,11 +511,11 @@ public void testCreateWalletWithThresholdLargerThanNumOwners() { Address caller = owners.get(0); byte[] input = MultiSignatureContract.constructCreateWalletInput(Long.MAX_VALUE, owners); - execute(caller, input, COST, ResultCode.INTERNAL_ERROR, 0); + execute(caller, input, COST, ResultCode.FAILURE, 0); // Test with smallest illegal value. input = MultiSignatureContract.constructCreateWalletInput(owners.size() + 1, owners); - execute(caller, input, COST, ResultCode.INTERNAL_ERROR, 0); + execute(caller, input, COST, ResultCode.FAILURE, 0); } @Test @@ -526,7 +526,7 @@ public void testCreateWalletZeroOwners() { MultiSignatureContract.constructCreateWalletInput( MultiSignatureContract.MIN_THRESH, owners); - execute(caller, input, COST, ResultCode.INTERNAL_ERROR, 0); + execute(caller, input, COST, ResultCode.FAILURE, 0); } @Test @@ -535,7 +535,7 @@ public void testCreateWalletOneOwner() { List
owners = getExistentAddresses(1, BigInteger.ZERO); byte[] input = MultiSignatureContract.constructCreateWalletInput(Long.MAX_VALUE, owners); - execute(caller, input, COST, ResultCode.INTERNAL_ERROR, 0); + execute(caller, input, COST, ResultCode.FAILURE, 0); } @Test @@ -545,7 +545,7 @@ public void testCreateWalletWithMoreOwnersThanLegalLimit() { Address caller = owners.get(0); byte[] input = MultiSignatureContract.constructCreateWalletInput(Long.MAX_VALUE, owners); - execute(caller, input, COST, ResultCode.INTERNAL_ERROR, 0); + execute(caller, input, COST, ResultCode.FAILURE, 0); } @Test @@ -559,7 +559,7 @@ public void testCreateWalletWithTwoDuplicateOwners() { MultiSignatureContract.constructCreateWalletInput( MultiSignatureContract.MIN_THRESH, owners); - execute(caller, input, COST, ResultCode.INTERNAL_ERROR, 0); + execute(caller, input, COST, ResultCode.FAILURE, 0); // Test with min amount of owners owners = getExistentAddresses(MultiSignatureContract.MIN_OWNERS - 1, BigInteger.ZERO); @@ -568,7 +568,7 @@ public void testCreateWalletWithTwoDuplicateOwners() { MultiSignatureContract.constructCreateWalletInput( MultiSignatureContract.MIN_THRESH, owners); - execute(caller, input, COST, ResultCode.INTERNAL_ERROR, 0); + execute(caller, input, COST, ResultCode.FAILURE, 0); // Test all owners same owners.clear(); @@ -579,7 +579,7 @@ public void testCreateWalletWithTwoDuplicateOwners() { MultiSignatureContract.constructCreateWalletInput( MultiSignatureContract.MIN_THRESH, owners); - execute(caller, input, COST, ResultCode.INTERNAL_ERROR, 0); + execute(caller, input, COST, ResultCode.FAILURE, 0); } @Test @@ -591,7 +591,7 @@ public void testCreateWalletButCallerIsNotAnOwner() { MultiSignatureContract.constructCreateWalletInput( MultiSignatureContract.MIN_THRESH, owners); - execute(caller, input, COST, ResultCode.INTERNAL_ERROR, 0); + execute(caller, input, COST, ResultCode.FAILURE, 0); } @Test @@ -612,7 +612,7 @@ public void testCreateWalletWithPartiallyCompleteAddress() { System.arraycopy(in, 0, input, 0, in.length); System.arraycopy(partialAddr, 0, input, in.length, partialAddr.length); - execute(caller, input, COST, ResultCode.INTERNAL_ERROR, 0); + execute(caller, input, COST, ResultCode.FAILURE, 0); // Test on max legal number of owners. owners = getExistentAddresses(MultiSignatureContract.MAX_OWNERS - 2, BigInteger.ZERO); @@ -624,7 +624,7 @@ public void testCreateWalletWithPartiallyCompleteAddress() { System.arraycopy(in, 0, input, 0, in.length); System.arraycopy(partialAddr, 0, input, in.length, partialAddr.length); - execute(caller, input, COST, ResultCode.INTERNAL_ERROR, 0); + execute(caller, input, COST, ResultCode.FAILURE, 0); } @Test @@ -652,7 +652,7 @@ public void testCreateWalletWithMultiSigWalletCaller() { MultiSignatureContract.constructCreateWalletInput( MultiSignatureContract.MIN_THRESH, owners); - execute(walletCaller, input, NRG_LIMIT, ResultCode.INTERNAL_ERROR, 0); + execute(walletCaller, input, NRG_LIMIT, ResultCode.FAILURE, 0); } @Test @@ -682,7 +682,7 @@ public void testCreateWalletWithOwnerAsAMultiSigWallet() { MultiSignatureContract.constructCreateWalletInput( MultiSignatureContract.MIN_THRESH, owners); - execute(caller, input, NRG_LIMIT, ResultCode.INTERNAL_ERROR, 0); + execute(caller, input, NRG_LIMIT, ResultCode.FAILURE, 0); } @Test @@ -791,7 +791,7 @@ public void testSendTxWithZeroSignatures() { checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); - execute(caller, input, NRG_LIMIT, ResultCode.INTERNAL_ERROR, 0); + execute(caller, input, NRG_LIMIT, ResultCode.FAILURE, 0); checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); } @@ -817,7 +817,7 @@ public void testSendTxWithMoreThanMaxOwnersSignatures() { checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); - execute(caller, input, NRG_LIMIT, ResultCode.INTERNAL_ERROR, 0); + execute(caller, input, NRG_LIMIT, ResultCode.FAILURE, 0); checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); } @@ -843,7 +843,7 @@ public void testSendTxValidSignaturesMeetsThresholdPlusPhonySig() { checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); - execute(caller, input, NRG_LIMIT, ResultCode.INTERNAL_ERROR, 0); + execute(caller, input, NRG_LIMIT, ResultCode.FAILURE, 0); checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); } @@ -866,7 +866,7 @@ public void testSendTxNegativeAmountWithZeroBalance() { checkAccountState(wallet, BigInteger.ZERO, BigInteger.ZERO); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); - execute(caller, input, NRG_LIMIT, ResultCode.INTERNAL_ERROR, 0); + execute(caller, input, NRG_LIMIT, ResultCode.FAILURE, 0); checkAccountState(wallet, BigInteger.ZERO, BigInteger.ZERO); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); } @@ -889,7 +889,7 @@ public void testSendTxNegativeAmountWithActualBalance() { checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); - execute(caller, input, NRG_LIMIT, ResultCode.INTERNAL_ERROR, 0); + execute(caller, input, NRG_LIMIT, ResultCode.FAILURE, 0); checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); } @@ -913,7 +913,7 @@ public void testSendTxFromRegularAddress() { checkAccountState(phonyWallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); - execute(phonyWallet, input, NRG_LIMIT, ResultCode.INTERNAL_ERROR, 0); + execute(phonyWallet, input, NRG_LIMIT, ResultCode.FAILURE, 0); checkAccountState(phonyWallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); } @@ -935,7 +935,7 @@ public void testSendTxNoSenderInInput() { checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); - execute(caller, input, NRG_LIMIT, ResultCode.INTERNAL_ERROR, 0); + execute(caller, input, NRG_LIMIT, ResultCode.FAILURE, 0); checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); } @@ -957,7 +957,7 @@ public void testSendTxNoRecipient() { checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); - execute(caller, input, NRG_LIMIT, ResultCode.INTERNAL_ERROR, 0); + execute(caller, input, NRG_LIMIT, ResultCode.FAILURE, 0); checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); } @@ -979,7 +979,7 @@ public void testSendTxNoAmount() { checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); - execute(caller, input, NRG_LIMIT, ResultCode.INTERNAL_ERROR, 0); + execute(caller, input, NRG_LIMIT, ResultCode.FAILURE, 0); checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); } @@ -1012,7 +1012,7 @@ public void testSendTxNoNrgPrice() { checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); - execute(caller, noNrgInput, NRG_LIMIT, ResultCode.INTERNAL_ERROR, 0); + execute(caller, noNrgInput, NRG_LIMIT, ResultCode.FAILURE, 0); checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); } @@ -1043,7 +1043,7 @@ public void testSendTxWithSignatureUsingPreviousNonce() { checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); - execute(caller, input, NRG_LIMIT, ResultCode.INTERNAL_ERROR, 0); + execute(caller, input, NRG_LIMIT, ResultCode.FAILURE, 0); checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); } @@ -1078,7 +1078,7 @@ public void testSendTxWhereSignedMessagesDifferInNonce() { checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); - execute(caller, input, NRG_LIMIT, ResultCode.INTERNAL_ERROR, 0); + execute(caller, input, NRG_LIMIT, ResultCode.FAILURE, 0); checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); } @@ -1108,7 +1108,7 @@ public void testSendTxWhereSignedMessagesDifferInRecipient() { checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); - execute(caller, input, NRG_LIMIT, ResultCode.INTERNAL_ERROR, 0); + execute(caller, input, NRG_LIMIT, ResultCode.FAILURE, 0); checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); } @@ -1141,7 +1141,7 @@ public void testSendTxWhereSignedMessagesDifferInAmount() { checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); - execute(caller, input, NRG_LIMIT, ResultCode.INTERNAL_ERROR, 0); + execute(caller, input, NRG_LIMIT, ResultCode.FAILURE, 0); checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); } @@ -1171,7 +1171,7 @@ public void testSendTxWhereSignedMessagesDifferInNrgPrice() { checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); - execute(caller, input, NRG_LIMIT, ResultCode.INTERNAL_ERROR, 0); + execute(caller, input, NRG_LIMIT, ResultCode.FAILURE, 0); checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); } @@ -1198,7 +1198,7 @@ public void testSendTxAllSignWrongRecipient() { checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); - execute(caller, input, NRG_LIMIT, ResultCode.INTERNAL_ERROR, 0); + execute(caller, input, NRG_LIMIT, ResultCode.FAILURE, 0); checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); } @@ -1224,7 +1224,7 @@ public void testSendTxAllSignWrongAmount() { checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); - execute(caller, input, NRG_LIMIT, ResultCode.INTERNAL_ERROR, 0); + execute(caller, input, NRG_LIMIT, ResultCode.FAILURE, 0); checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); } @@ -1251,7 +1251,7 @@ public void testSendTxAllSignWrongNonce() { checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); - execute(caller, input, NRG_LIMIT, ResultCode.INTERNAL_ERROR, 0); + execute(caller, input, NRG_LIMIT, ResultCode.FAILURE, 0); checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); } @@ -1277,7 +1277,7 @@ public void testSendTxAllSignWrongNrgPrice() { checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); - execute(caller, input, NRG_LIMIT, ResultCode.INTERNAL_ERROR, 0); + execute(caller, input, NRG_LIMIT, ResultCode.FAILURE, 0); checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); } @@ -1354,7 +1354,7 @@ public void testSendTxLessSignaturesThanThresholdMinOwners() { checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); - execute(caller, input, NRG_LIMIT, ResultCode.INTERNAL_ERROR, 0); + execute(caller, input, NRG_LIMIT, ResultCode.FAILURE, 0); checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); } @@ -1379,7 +1379,7 @@ public void testSendTxLessSignaturesThanThresholdMaxOwners() { checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); - execute(caller, input, NRG_LIMIT, ResultCode.INTERNAL_ERROR, 0); + execute(caller, input, NRG_LIMIT, ResultCode.FAILURE, 0); checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); } @@ -1502,7 +1502,7 @@ public void testSendTxDuplicateSignee() { checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); - execute(caller, input, NRG_LIMIT, ResultCode.INTERNAL_ERROR, 0); + execute(caller, input, NRG_LIMIT, ResultCode.FAILURE, 0); checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); } @@ -1529,7 +1529,7 @@ public void testSendTxSignatureOneSigneeIsNonOwner() { checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); - execute(caller, input, NRG_LIMIT, ResultCode.INTERNAL_ERROR, 0); + execute(caller, input, NRG_LIMIT, ResultCode.FAILURE, 0); checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); } @@ -1583,7 +1583,7 @@ public void testSendTxSignedProperlyButCallerIsNotOwner() { checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); - execute(new Address(phony.getAddress()), input, NRG_LIMIT, ResultCode.INTERNAL_ERROR, 0); + execute(new Address(phony.getAddress()), input, NRG_LIMIT, ResultCode.FAILURE, 0); checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); } @@ -1611,7 +1611,7 @@ public void testPartialSignature() { checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); - execute(caller, shiftedInput, NRG_LIMIT, ResultCode.INTERNAL_ERROR, 0); + execute(caller, shiftedInput, NRG_LIMIT, ResultCode.FAILURE, 0); checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); } @@ -1639,7 +1639,7 @@ public void testPartialWalletAddress() { checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); - execute(caller, shiftedInput, NRG_LIMIT, ResultCode.INTERNAL_ERROR, 0); + execute(caller, shiftedInput, NRG_LIMIT, ResultCode.FAILURE, 0); checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); } @@ -1667,7 +1667,7 @@ public void testPartialRecipientAddress() { checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); - execute(caller, shiftedInput, NRG_LIMIT, ResultCode.INTERNAL_ERROR, 0); + execute(caller, shiftedInput, NRG_LIMIT, ResultCode.FAILURE, 0); checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); } @@ -1695,7 +1695,7 @@ public void testPartialAmount() { checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); - execute(caller, shiftedInput, NRG_LIMIT, ResultCode.INTERNAL_ERROR, 0); + execute(caller, shiftedInput, NRG_LIMIT, ResultCode.FAILURE, 0); checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); } @@ -1723,7 +1723,7 @@ public void testPartialNrgPrice() { checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); - execute(caller, shiftedInput, NRG_LIMIT, ResultCode.INTERNAL_ERROR, 0); + execute(caller, shiftedInput, NRG_LIMIT, ResultCode.FAILURE, 0); checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); } diff --git a/modPrecompiled/test/org/aion/precompiled/contracts/TotalCurrencyContractTest.java b/modPrecompiled/test/org/aion/precompiled/contracts/TotalCurrencyContractTest.java index 8259d97aaa..4139ae9f56 100644 --- a/modPrecompiled/test/org/aion/precompiled/contracts/TotalCurrencyContractTest.java +++ b/modPrecompiled/test/org/aion/precompiled/contracts/TotalCurrencyContractTest.java @@ -104,7 +104,7 @@ public void TestGetTotalAmountEmptyPayload() { ExecutionResult res = tcc.execute(payload, COST); System.out.println("Contract result: " + res.toString()); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); } @Test @@ -197,7 +197,7 @@ public void TestUpdateTotalIncorrectSigSize() { constructUpdateInput((byte) 0x0, (byte) 0x0), 0, 100); // cut sig short. ExecutionResult res = tcc.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0L, res.getNrgLeft()); } @@ -213,7 +213,7 @@ public void TestUpdateTotalNotOwner() { byte[] input = constructUpdateInput((byte) 0x0, (byte) 0x0); ExecutionResult res = contract.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0L, res.getNrgLeft()); } @@ -225,7 +225,7 @@ public void TestUpdateTotalIncorrectSig() { input[30] = (byte) ~input[30]; // flip a bit ExecutionResult res = tcc.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0L, res.getNrgLeft()); } @@ -262,7 +262,7 @@ public void TestSubtractTotalAmountBelowZero() { byte[] input = constructUpdateInput((byte) 0x0, (byte) 0x1); // 0x1 == subtract ExecutionResult res = tcc.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0L, res.getNrgLeft()); // Verify total amount is non-negative. @@ -277,7 +277,7 @@ public void TestBadSignum() { byte[] input = constructUpdateInput((byte) 0x0, (byte) 0x2); // only 0, 1 are valid. ExecutionResult res = tcc.execute(input, COST); - assertEquals(ResultCode.INTERNAL_ERROR, res.getResultCode()); + assertEquals(ResultCode.FAILURE, res.getResultCode()); assertEquals(0L, res.getNrgLeft()); } diff --git a/modVM/src/org/aion/vm/AbstractExecutionResult.java b/modVM/src/org/aion/vm/AbstractExecutionResult.java index 93aa577deb..339b4dba39 100644 --- a/modVM/src/org/aion/vm/AbstractExecutionResult.java +++ b/modVM/src/org/aion/vm/AbstractExecutionResult.java @@ -38,7 +38,14 @@ public abstract class AbstractExecutionResult implements IExecutionResult { byte[] output; public enum ResultCode { + /* + * Indicates a successful transaction. + */ SUCCESS(0), + + /* + * Indicates a runtime failure when executing the smart contract code. + */ FAILURE(1), OUT_OF_NRG(2), BAD_INSTRUCTION(3), @@ -46,11 +53,21 @@ public enum ResultCode { STACK_OVERFLOW(5), STACK_UNDERFLOW(6), REVERT(7), - INVALID_NONCE(8), - INVALID_NRG_LIMIT(9), - INSUFFICIENT_BALANCE(10), - CONTRACT_ALREADY_EXISTS(11), - INTERNAL_ERROR(-1); + STATIC_MODE_ERROR(8), + + /* + * Indicates a transaction rejection. This usually happens before any code execution. + */ + INVALID_NONCE(101), + INVALID_NRG_LIMIT(102), + INSUFFICIENT_BALANCE(103), + + /* + * Indicates an internal error, because of either bug or out-of-resource. + * The node shall shut itself down when this occurs. + */ + VM_REJECTED(-1), // VM is not willing to execute the code + VM_INTERNAL_ERROR(-2); // VM internal implementation error private static Map intMap = new HashMap<>(); diff --git a/modVM/src/org/aion/vm/TransactionExecutor.java b/modVM/src/org/aion/vm/TransactionExecutor.java index a5fd3f0666..db246a1aa8 100644 --- a/modVM/src/org/aion/vm/TransactionExecutor.java +++ b/modVM/src/org/aion/vm/TransactionExecutor.java @@ -200,7 +200,7 @@ protected void create() { Address contractAddress = tx.getContractAddress(); if (repoTrack.hasAccountState(contractAddress)) { - exeResult.setCodeAndNrgLeft(ResultCode.CONTRACT_ALREADY_EXISTS.toInt(), 0); + exeResult.setCodeAndNrgLeft(ResultCode.FAILURE.toInt(), 0); return; } @@ -245,7 +245,6 @@ protected AionTxExecSummary finish() { case INSUFFICIENT_BALANCE: builder.markAsRejected(); break; - case CONTRACT_ALREADY_EXISTS: case FAILURE: case OUT_OF_NRG: case BAD_INSTRUCTION: @@ -253,9 +252,11 @@ protected AionTxExecSummary finish() { case STACK_OVERFLOW: case STACK_UNDERFLOW: case REVERT: - case INTERNAL_ERROR: + case STATIC_MODE_ERROR: builder.markAsFailed(); break; + case VM_REJECTED: + case VM_INTERNAL_ERROR: default: throw new RuntimeException("invalid code path, should not ever default"); } From 0e6c2553595eae8598e0c3ea2cca79e2e7295c10 Mon Sep 17 00:00:00 2001 From: Yulong Wu Date: Fri, 23 Nov 2018 08:19:44 +0800 Subject: [PATCH 2/2] Add comments for the error codes --- .../org/aion/vm/AbstractExecutionResult.java | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/modVM/src/org/aion/vm/AbstractExecutionResult.java b/modVM/src/org/aion/vm/AbstractExecutionResult.java index 339b4dba39..85f16a75b5 100644 --- a/modVM/src/org/aion/vm/AbstractExecutionResult.java +++ b/modVM/src/org/aion/vm/AbstractExecutionResult.java @@ -23,13 +23,14 @@ package org.aion.vm; +import org.aion.base.type.IExecutionResult; +import org.aion.base.util.ByteUtil; +import org.aion.base.util.Hex; + import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.HashMap; import java.util.Map; -import org.aion.base.type.IExecutionResult; -import org.aion.base.util.ByteUtil; -import org.aion.base.util.Hex; /** An abstract class representing the result of either a transaction or contract execution. */ public abstract class AbstractExecutionResult implements IExecutionResult { @@ -46,21 +47,21 @@ public enum ResultCode { /* * Indicates a runtime failure when executing the smart contract code. */ - FAILURE(1), - OUT_OF_NRG(2), - BAD_INSTRUCTION(3), - BAD_JUMP_DESTINATION(4), - STACK_OVERFLOW(5), - STACK_UNDERFLOW(6), - REVERT(7), - STATIC_MODE_ERROR(8), + FAILURE(1), // generic failure + OUT_OF_NRG(2), // run out of energy + BAD_INSTRUCTION(3), // bad FAStVM instruction + BAD_JUMP_DESTINATION(4), // bad JUMP destination + STACK_OVERFLOW(5), // stack overflow + STACK_UNDERFLOW(6), // stack underflow + REVERT(7), // the REVERT opcode triggered + STATIC_MODE_ERROR(8), // trying to modify the state in a STATICCALL. /* * Indicates a transaction rejection. This usually happens before any code execution. */ - INVALID_NONCE(101), - INVALID_NRG_LIMIT(102), - INSUFFICIENT_BALANCE(103), + INVALID_NONCE(101), // invalid nonce + INVALID_NRG_LIMIT(102), // invalid energy limit + INSUFFICIENT_BALANCE(103), // balance is insufficient to cover the cost /* * Indicates an internal error, because of either bug or out-of-resource.