diff --git a/ethereumj-core/src/main/java/org/ethereum/core/Bloom.java b/ethereumj-core/src/main/java/org/ethereum/core/Bloom.java index e1f3dd37..81258688 100644 --- a/ethereumj-core/src/main/java/org/ethereum/core/Bloom.java +++ b/ethereumj-core/src/main/java/org/ethereum/core/Bloom.java @@ -4,6 +4,7 @@ import org.ethereum.util.ByteUtil; import org.spongycastle.util.encoders.Hex; import java.nio.ByteBuffer; +import java.util.Arrays; /** * www.etherj.com @@ -54,4 +55,21 @@ public class Bloom { public String toString() { return Hex.toHexString(data); } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Bloom bloom = (Bloom) o; + + if (!Arrays.equals(data, bloom.data)) return false; + + return true; + } + + @Override + public int hashCode() { + return data != null ? Arrays.hashCode(data) : 0; + } } diff --git a/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/Logs.java b/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/Logs.java index 5964d774..436d6318 100644 --- a/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/Logs.java +++ b/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/Logs.java @@ -14,43 +14,31 @@ import org.json.simple.JSONObject; import org.spongycastle.util.encoders.Hex; public class Logs { - Map logs; + List logs = new ArrayList<>(); - public Logs(JSONObject jLogs) { - logs = new HashMap(); - - Set keys = jLogs.keySet(); - for(Object k: keys.toArray()) { - byte[] key = Hex.decode((String)k); - - JSONObject values = (JSONObject)jLogs.get(k); - - byte[] address = Hex.decode((String)values.get("address")); - byte[] data = Hex.decode(((String)values.get("data")).substring(2)); - List topics = new ArrayList(); - - JSONArray jTopics = (JSONArray)values.get("topics"); - for(Object t: jTopics.toArray()) { - byte[] topic = Hex.decode(((String)t)); - topics.add(new DataWord(topic)); - } - - LogInfo li = new LogInfo(address, topics, data); - logs.put(key, li); - } - } - - /** - * returns null if {@link org.ethereum.vm.LogInfo LogInfo} object was not found for the given key - * @param k - * @return - */ - public LogInfo getLogBloom(byte[] k) { - if(logs.containsKey(k)) - return logs.get(k); - return null; - } - public Iterator getLogsBloomKeyIterator() { - return logs.keySet().iterator(); + public Logs(JSONArray jLogs) { + + for (int i = 0; i < jLogs.size(); ++i){ + + JSONObject jLog = (JSONObject)jLogs.get(i); + byte[] address = Hex.decode((String)jLog.get("address")); + byte[] data = Hex.decode(((String)jLog.get("data")).substring(2)); + + List topics = new ArrayList<>(); + + JSONArray jTopics = (JSONArray)jLog.get("topics"); + for(Object t: jTopics.toArray()) { + byte[] topic = Hex.decode(((String)t)); + topics.add(new DataWord(topic)); + } + + LogInfo li = new LogInfo(address, topics, data); + logs.add(li); + } } + + + public Iterator getIterator(){ + return logs.iterator(); + } } 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 cb620a83..030548e5 100644 --- a/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/TestCase.java +++ b/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/TestCase.java @@ -65,9 +65,9 @@ public class TestCase { if(testCaseJSONObj.containsKey("callcreates")) callCreates = (JSONArray)testCaseJSONObj.get("callcreates"); - JSONObject logsJSON = new JSONObject(); + JSONArray logsJSON = new JSONArray(); if(testCaseJSONObj.containsKey("logs")) - logsJSON = (JSONObject)testCaseJSONObj.get("logs"); + logsJSON = (JSONArray)testCaseJSONObj.get("logs"); logs = new Logs(logsJSON); String gasString = "0"; 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 16cdfe35..c2e92127 100644 --- a/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/TestRunner.java +++ b/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/TestRunner.java @@ -229,24 +229,18 @@ public class TestRunner { /* asset logs */ List logResult = program.getResult().getLogInfoList(); - Iterator itr = logs.getLogsBloomKeyIterator(); - while(itr.hasNext()) { - byte[] expectedLogKey = itr.next(); - System.out.println("Expected key " + Hex.toHexString(expectedLogKey)); - LogInfo expectedLogInfo = logs.getLogBloom(expectedLogKey); - LogInfo foundLogInfo = null; - boolean found = false; - for(LogInfo resultLogInfo:logResult) { - byte[] resultKey = resultLogInfo.getBloom().getData(); - System.out.println("returned key " + Hex.toHexString(resultKey)); - if(Arrays.equals(expectedLogKey, resultKey)) { - found = true; - foundLogInfo = resultLogInfo; - break; - } - } - - if(!found) { + + Iterator postLogs = logs.getIterator(); + int i = 0; + while(postLogs.hasNext()) { + + LogInfo expectedLogInfo = postLogs.next(); + + LogInfo foundLogInfo = null; + if (logResult.size() > i) + foundLogInfo = logResult.get(i); + + if(foundLogInfo == null) { String output = String.format("Expected log [ %s ]", expectedLogInfo.toString()); logger.info(output); @@ -267,6 +261,15 @@ public class TestRunner { results.add(output); } + if(!expectedLogInfo.getBloom().equals(foundLogInfo.getBloom())) { + String output = + String.format("Expected bloom [ %s ], found [ %s ]", + Hex.toHexString(expectedLogInfo.getBloom().getData()), + Hex.toHexString(foundLogInfo.getBloom().getData())); + logger.info(output); + results.add(output); + } + if(expectedLogInfo.getTopics().size() != foundLogInfo.getTopics().size()) { String output = String.format("Expected number of topics [ %d ], found [ %d ]", expectedLogInfo.getTopics().size(), foundLogInfo.getTopics().size()); @@ -274,9 +277,9 @@ public class TestRunner { results.add(output); } else { - int i=0; + int j=0; for(DataWord topic: expectedLogInfo.getTopics()) { - byte[] foundTopic = foundLogInfo.getTopics().get(i).getData(); + byte[] foundTopic = foundLogInfo.getTopics().get(j).getData(); if(!Arrays.equals(topic.getData(), foundTopic)) { String output = @@ -285,10 +288,12 @@ public class TestRunner { results.add(output); } - i++; + ++j; } } } + + ++i; } } diff --git a/ethereumj-core/src/main/resources/log4j.properties b/ethereumj-core/src/main/resources/log4j.properties index ce4edf2a..ea4b9c8c 100644 --- a/ethereumj-core/src/main/resources/log4j.properties +++ b/ethereumj-core/src/main/resources/log4j.properties @@ -36,7 +36,7 @@ log4j.logger.VM = ERROR log4j.logger.main = ERROR log4j.logger.trie = ERROR log4j.logger.state = INFO -log4j.logger.repository = ERROR +log4j.logger.repository = DEBUG log4j.logger.blockchain = DEBUG log4j.logger.txs = ERROR log4j.logger.ui = ERROR