fixing GitHub test suite structure

This commit is contained in:
romanman 2014-12-09 11:19:49 +01:00
parent d804cbb722
commit a8d407ab28
5 changed files with 72 additions and 61 deletions

View File

@ -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;
}
}

View File

@ -14,43 +14,31 @@ import org.json.simple.JSONObject;
import org.spongycastle.util.encoders.Hex;
public class Logs {
Map<byte[], LogInfo> logs;
List<LogInfo> logs = new ArrayList<>();
public Logs(JSONObject jLogs) {
logs = new HashMap<byte[], LogInfo>();
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<DataWord> topics = new ArrayList<DataWord>();
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<byte[]> 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<DataWord> 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<LogInfo> getIterator(){
return logs.iterator();
}
}

View File

@ -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";

View File

@ -229,24 +229,18 @@ public class TestRunner {
/* asset logs */
List<LogInfo> logResult = program.getResult().getLogInfoList();
Iterator<byte[]> 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<LogInfo> 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;
}
}

View File

@ -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