log tests
This commit is contained in:
parent
a2b00ff8dd
commit
a88ec65459
|
@ -7,6 +7,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.ethereum.vm.DataWord;
|
||||
import org.ethereum.vm.LogInfo;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
@ -26,12 +27,12 @@ public class Logs {
|
|||
|
||||
byte[] address = Hex.decode((String)values.get("address"));
|
||||
byte[] data = Hex.decode(((String)values.get("data")).substring(2));
|
||||
List<byte[]> topics = new ArrayList<byte[]>();
|
||||
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(topic);
|
||||
topics.add(new DataWord(topic));
|
||||
}
|
||||
|
||||
LogInfo li = new LogInfo(address, topics, data);
|
||||
|
|
|
@ -232,13 +232,15 @@ public class TestRunner {
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -248,6 +250,43 @@ public class TestRunner {
|
|||
logger.info(output);
|
||||
results.add(output);
|
||||
}
|
||||
else {
|
||||
if(!Arrays.equals(expectedLogInfo.getAddress(), foundLogInfo.getAddress())) {
|
||||
String output =
|
||||
String.format("Expected address [ %s ], found [ %s ]", Hex.toHexString(expectedLogInfo.getAddress()), Hex.toHexString(foundLogInfo.getAddress()));
|
||||
logger.info(output);
|
||||
results.add(output);
|
||||
}
|
||||
|
||||
if(!Arrays.equals(expectedLogInfo.getData(), foundLogInfo.getData())) {
|
||||
String output =
|
||||
String.format("Expected data [ %s ], found [ %s ]", Hex.toHexString(expectedLogInfo.getData()), Hex.toHexString(foundLogInfo.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());
|
||||
logger.info(output);
|
||||
results.add(output);
|
||||
}
|
||||
else {
|
||||
int i=0;
|
||||
for(DataWord topic: expectedLogInfo.getTopics()) {
|
||||
byte[] foundTopic = foundLogInfo.getTopics().get(i).getData();
|
||||
|
||||
if(!Arrays.equals(topic.getData(), foundTopic)) {
|
||||
String output =
|
||||
String.format("Expected topic [ %s ], found [ %s ]", Hex.toHexString(topic.getData()), Hex.toHexString(foundTopic));
|
||||
logger.info(output);
|
||||
results.add(output);
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,15 +21,15 @@ import java.util.List;
|
|||
public class LogInfo {
|
||||
|
||||
byte[] address;
|
||||
List<byte[]> topics = new ArrayList<>();
|
||||
List<DataWord> topics = new ArrayList<DataWord>();
|
||||
byte[] data;
|
||||
|
||||
/* Log info in encoded form */
|
||||
private byte[] rlpEncoded;
|
||||
|
||||
public LogInfo(byte[] address, List<byte[]> topics, byte[] data) {
|
||||
public LogInfo(byte[] address, List<DataWord> topics, byte[] data) {
|
||||
this.address = address;
|
||||
this.topics = (topics == null) ? new ArrayList<byte[]>() : topics;
|
||||
this.topics = (topics == null) ? new ArrayList<DataWord>() : topics;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ public class LogInfo {
|
|||
return address;
|
||||
}
|
||||
|
||||
public List<byte[]> getTopics() {
|
||||
public List<DataWord> getTopics() {
|
||||
return topics;
|
||||
}
|
||||
|
||||
|
@ -55,8 +55,9 @@ public class LogInfo {
|
|||
if (topics != null){
|
||||
topicsEncoded = new byte[topics.size()][];
|
||||
int i = 0;
|
||||
for( byte[] topic : topics ){
|
||||
topicsEncoded[i] = topic;
|
||||
for( DataWord topic : topics ){
|
||||
byte[] topicData = topic.getData();
|
||||
topicsEncoded[i] = topicData;
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
@ -67,8 +68,9 @@ public class LogInfo {
|
|||
|
||||
public Bloom getBloom() {
|
||||
Bloom ret = Bloom.create(HashUtil.sha3(address));
|
||||
for(byte[] topic:topics) {
|
||||
ret.or(Bloom.create(HashUtil.sha3(topic)));
|
||||
for(DataWord topic:topics) {
|
||||
byte[] topicData = topic.getData();
|
||||
ret.or(Bloom.create(HashUtil.sha3(topicData)));
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -80,8 +82,8 @@ public class LogInfo {
|
|||
StringBuffer topicsStr = new StringBuffer();
|
||||
topicsStr.append("[");
|
||||
|
||||
for (byte[] topic: topics){
|
||||
String topicStr = Hex.toHexString(topic);
|
||||
for (DataWord topic: topics){
|
||||
String topicStr = Hex.toHexString(topic.getData());
|
||||
topicsStr.append(topicStr).append(" ");
|
||||
}
|
||||
topicsStr.append("]");
|
||||
|
|
|
@ -751,10 +751,11 @@ public class VM {
|
|||
|
||||
int nTopics = op.val() - OpCode.LOG0.val();
|
||||
|
||||
List<byte[]> topics = new ArrayList<>();
|
||||
List<DataWord> topics = new ArrayList<DataWord>();
|
||||
for (int i = 0; i < nTopics; ++i){
|
||||
DataWord topic = stack.pop();
|
||||
topics.add(topic.getData());
|
||||
if(!topics.contains(topic))
|
||||
topics.add(topic);
|
||||
}
|
||||
|
||||
ByteBuffer data = program.memoryChunk(memStart, memOffset);
|
||||
|
|
Loading…
Reference in New Issue