diff --git a/ethereumj-core/src/main/java/org/ethereum/core/Transaction.java b/ethereumj-core/src/main/java/org/ethereum/core/Transaction.java index 3184686a..0201a34d 100644 --- a/ethereumj-core/src/main/java/org/ethereum/core/Transaction.java +++ b/ethereumj-core/src/main/java/org/ethereum/core/Transaction.java @@ -12,7 +12,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.spongycastle.util.BigIntegers; -import java.math.BigInteger; import java.security.SignatureException; /** diff --git a/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/AccountState.java b/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/AccountState.java index 9afdcf7f..d43f8bb1 100644 --- a/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/AccountState.java +++ b/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/AccountState.java @@ -41,7 +41,7 @@ public class AccountState { if (code != null && code.length() > 2) this.code = Hex.decode(code.substring(2)); else - this.code = new byte[0]; + this.code = ByteUtil.EMPTY_BYTE_ARRAY; this.nonce = new BigInteger(nonce).toByteArray(); @@ -61,7 +61,7 @@ public class AccountState { if (keyS != null && keyS.length() > 2) data = Hex.decode(keyS); else - data = new byte[0]; + data = ByteUtil.EMPTY_BYTE_ARRAY; key = new ByteArrayWrapper(data); } diff --git a/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/CallCreate.java b/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/CallCreate.java index 2089d39d..f8cc3d79 100644 --- a/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/CallCreate.java +++ b/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/CallCreate.java @@ -38,15 +38,13 @@ public class CallCreate { if (data != null && data.length() > 2) this.data = Hex.decode(data.substring(2)); else - this.data = new byte[0]; - + this.data = ByteUtil.EMPTY_BYTE_ARRAY; this.destination = Hex.decode(destination); this.gasLimit = ByteUtil.bigIntegerToBytes(new BigInteger(gasLimit)); this.value = ByteUtil.bigIntegerToBytes(new BigInteger(value)); } - public byte[] getData() { return data; } diff --git a/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/Exec.java b/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/Exec.java index 2b80688e..9a459b9c 100644 --- a/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/Exec.java +++ b/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/Exec.java @@ -60,12 +60,12 @@ public class Exec { if (code != null && code.length() > 2) this.code = Hex.decode(code.substring(2)); else - this.code = new byte[0]; + this.code = ByteUtil.EMPTY_BYTE_ARRAY; if (data != null && data.length() > 2) this.data = Hex.decode(data.substring(2)); else - this.data = new byte[0]; + this.data = ByteUtil.EMPTY_BYTE_ARRAY; this.gas = ByteUtil.bigIntegerToBytes(new BigInteger(gas)); this.gasPrice = ByteUtil.bigIntegerToBytes(new BigInteger(gasPrice)); diff --git a/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/TestCase.java b/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/TestCase.java index 548a3f59..4523d248 100644 --- a/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/TestCase.java +++ b/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/TestCase.java @@ -65,7 +65,7 @@ public class TestCase { if (outString != null && outString.length() > 2) this.out = Hex.decode(outString.substring(2)); else - this.out = new byte[0]; + this.out = ByteUtil.EMPTY_BYTE_ARRAY; for (Object key : preJSON.keySet()){ diff --git a/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/TestRunner.java b/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/TestRunner.java index 68b94bd2..ac538d96 100644 --- a/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/TestRunner.java +++ b/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/TestRunner.java @@ -49,6 +49,7 @@ public class TestRunner { Repository repository = new RepositoryImpl(); + System.out.println("--------- PRE ---------"); /* 1. Store pre-exist accounts - Pre */ for (ByteArrayWrapper key : testCase.getPre().keySet()) { @@ -69,7 +70,7 @@ public class TestRunner { byte[] address = exec.getAddress(); byte[] origin = exec.getOrigin(); byte[] caller = exec.getCaller(); - byte[] balance = ByteUtil.bigIntegerToBytes(repository.getBalance(exec.getAddress())); + byte[] balance = ByteUtil.bigIntegerToBytes(repository.getBalance(exec.getAddress())); byte[] gasPrice = exec.getGasPrice(); byte[] gas = exec.getGas(); byte[] callValue = exec.getValue(); @@ -91,14 +92,14 @@ public class TestRunner { Program program = new Program(exec.getCode(), programInvoke); try { + System.out.println("-------- EXEC --------"); while(!program.isStopped()) vm.step(program); - - System.out.println(); } catch (RuntimeException e) { program.setRuntimeFailure(e); } + System.out.println("--------- POST --------"); /* 5. Assert Post values */ for (ByteArrayWrapper key : testCase.getPost().keySet()) { @@ -275,7 +276,7 @@ public class TestRunner { // assert out byte[] expectedHReturn = testCase.getOut(); - byte[] actualHReturn = new byte[0]; + byte[] actualHReturn = ByteUtil.EMPTY_BYTE_ARRAY; if (program.getResult().getHReturn() != null) { actualHReturn = program.getResult().getHReturn().array(); } diff --git a/ethereumj-core/src/main/java/org/ethereum/net/message/HelloMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/message/HelloMessage.java index c0919d52..7ba4f1c3 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/message/HelloMessage.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/message/HelloMessage.java @@ -80,7 +80,7 @@ public class HelloMessage extends P2pMessage { byte[] clientId = RLP.encodeString(this.clientId); byte[][] capabilities = new byte[this.capabilities.size()][]; for (int i = 0; i < this.capabilities.size(); i++) { - capabilities[i] = RLP.encode(this.capabilities.get(i).getBytes()); + capabilities[i] = RLP.encodeElement(this.capabilities.get(i).getBytes()); } byte[] capabilityList = RLP.encodeList(capabilities); byte[] peerPort = RLP.encodeInt(this.listenPort); diff --git a/ethereumj-core/src/main/java/org/ethereum/util/RLP.java b/ethereumj-core/src/main/java/org/ethereum/util/RLP.java index 35ce44e8..6f1bf244 100644 --- a/ethereumj-core/src/main/java/org/ethereum/util/RLP.java +++ b/ethereumj-core/src/main/java/org/ethereum/util/RLP.java @@ -649,7 +649,7 @@ public class RLP { } // null item if ((msgData[pos] & 0xFF) == OFFSET_SHORT_ITEM) { - byte[] item = new byte[0]; + byte[] item = ByteUtil.EMPTY_BYTE_ARRAY; RLPItem rlpItem = new RLPItem(item); rlpList.add(rlpItem); pos += 1; @@ -741,7 +741,7 @@ public class RLP { if (inputArray.size() == 0) { return encodeLength(inputArray.size(), OFFSET_SHORT_LIST); } - byte[] output = new byte[0]; + byte[] output = ByteUtil.EMPTY_BYTE_ARRAY; for (Object object : inputArray) { output = concatenate(output, encode(object)); } @@ -916,13 +916,13 @@ public class RLP { return inputString.getBytes(); } else if(input instanceof Long) { Long inputLong = (Long) input; - return (inputLong == 0) ? new byte[0] : asUnsignedByteArray(BigInteger.valueOf(inputLong)); + return (inputLong == 0) ? ByteUtil.EMPTY_BYTE_ARRAY : asUnsignedByteArray(BigInteger.valueOf(inputLong)); } else if(input instanceof Integer) { Integer inputInt = (Integer) input; - return (inputInt == 0) ? new byte[0] : asUnsignedByteArray(BigInteger.valueOf(inputInt.intValue())); + return (inputInt == 0) ? ByteUtil.EMPTY_BYTE_ARRAY : asUnsignedByteArray(BigInteger.valueOf(inputInt.intValue())); } else if(input instanceof BigInteger) { BigInteger inputBigInt = (BigInteger) input; - return (inputBigInt == BigInteger.ZERO) ? new byte[0] : asUnsignedByteArray(inputBigInt); + return (inputBigInt == BigInteger.ZERO) ? ByteUtil.EMPTY_BYTE_ARRAY : asUnsignedByteArray(inputBigInt); } else if (input instanceof Value) { Value val = (Value) input; return toBytes(val.asObj()); diff --git a/ethereumj-core/src/main/java/org/ethereum/util/Value.java b/ethereumj-core/src/main/java/org/ethereum/util/Value.java index ce01af15..797a552a 100644 --- a/ethereumj-core/src/main/java/org/ethereum/util/Value.java +++ b/ethereumj-core/src/main/java/org/ethereum/util/Value.java @@ -81,7 +81,7 @@ public class Value { } else if(isString()) { return asString().getBytes(); } - return new byte[0]; + return ByteUtil.EMPTY_BYTE_ARRAY; } public int[] asSlice() {