mirror of
https://github.com/status-im/ethereumj-personal.git
synced 2025-01-09 11:32:28 +00:00
vmIOandFlowOperationsTest
This commit is contained in:
parent
7c0a6fb65d
commit
da9fc3d391
@ -55,13 +55,21 @@ public class TestCase {
|
|||||||
JSONObject envJSON = (JSONObject)testCaseJSONObj.get("env");
|
JSONObject envJSON = (JSONObject)testCaseJSONObj.get("env");
|
||||||
JSONObject execJSON = (JSONObject)testCaseJSONObj.get("exec");
|
JSONObject execJSON = (JSONObject)testCaseJSONObj.get("exec");
|
||||||
JSONObject preJSON = (JSONObject)testCaseJSONObj.get("pre");
|
JSONObject preJSON = (JSONObject)testCaseJSONObj.get("pre");
|
||||||
JSONObject postJSON = (JSONObject)testCaseJSONObj.get("post");
|
JSONObject postJSON = new JSONObject();
|
||||||
JSONArray callCreates = (JSONArray)testCaseJSONObj.get("callcreates");
|
if(testCaseJSONObj.containsKey("post")) // in cases where there is no post dictionary (when testing for exceptions for example)
|
||||||
|
postJSON = (JSONObject)testCaseJSONObj.get("post");
|
||||||
|
JSONArray callCreates = new JSONArray();
|
||||||
|
if(testCaseJSONObj.containsKey("callcreates"))
|
||||||
|
callCreates = (JSONArray)testCaseJSONObj.get("callcreates");
|
||||||
|
|
||||||
String gasString = testCaseJSONObj.get("gas").toString();
|
String gasString = "0";
|
||||||
|
if(testCaseJSONObj.containsKey("gas"))
|
||||||
|
gasString = testCaseJSONObj.get("gas").toString();
|
||||||
this.gas = ByteUtil.bigIntegerToBytes(new BigInteger(gasString));
|
this.gas = ByteUtil.bigIntegerToBytes(new BigInteger(gasString));
|
||||||
|
|
||||||
String outString = testCaseJSONObj.get("out").toString();
|
String outString = null;
|
||||||
|
if(testCaseJSONObj.containsKey("out"))
|
||||||
|
outString = testCaseJSONObj.get("out").toString();
|
||||||
if (outString != null && outString.length() > 2)
|
if (outString != null && outString.length() > 2)
|
||||||
this.out = Hex.decode(outString.substring(2));
|
this.out = Hex.decode(outString.substring(2));
|
||||||
else
|
else
|
||||||
|
@ -99,11 +99,37 @@ public class TestRunner {
|
|||||||
/* 4. run VM */
|
/* 4. run VM */
|
||||||
VM vm = new VM();
|
VM vm = new VM();
|
||||||
Program program = new Program(exec.getCode(), programInvoke);
|
Program program = new Program(exec.getCode(), programInvoke);
|
||||||
|
boolean vmDidThrowAnEception = false;
|
||||||
|
RuntimeException e = null;
|
||||||
|
try {
|
||||||
while(!program.isStopped())
|
while(!program.isStopped())
|
||||||
vm.step(program);
|
vm.step(program);
|
||||||
|
}
|
||||||
|
catch (RuntimeException ex) {
|
||||||
|
vmDidThrowAnEception = true;
|
||||||
|
e = ex;
|
||||||
|
}
|
||||||
program.saveProgramTraceToFile(testCase.getName());
|
program.saveProgramTraceToFile(testCase.getName());
|
||||||
|
|
||||||
|
if(testCase.getPost().size() == 0) {
|
||||||
|
if(vmDidThrowAnEception != true) {
|
||||||
|
String output =
|
||||||
|
String.format("VM was expected to throw an exception");
|
||||||
|
logger.info(output);
|
||||||
|
results.add(output);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
logger.info("VM did throw an exception: " + e.toString());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if(vmDidThrowAnEception) {
|
||||||
|
String output =
|
||||||
|
String.format("VM threw an unexpected exception: " + e.toString());
|
||||||
|
logger.info(output);
|
||||||
|
results.add(output);
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
this.trace = program.getProgramTrace();
|
this.trace = program.getProgramTrace();
|
||||||
|
|
||||||
System.out.println("--------- POST --------");
|
System.out.println("--------- POST --------");
|
||||||
@ -311,6 +337,11 @@ public class TestRunner {
|
|||||||
logger.info(output);
|
logger.info(output);
|
||||||
results.add(output);
|
results.add(output);
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
* end of if(testCase.getPost().size() == 0)
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
} finally {
|
} finally {
|
||||||
repository.close();
|
repository.close();
|
||||||
|
@ -21,6 +21,7 @@ public class TestSuite {
|
|||||||
for (Object key: testCaseJSONObj.keySet()){
|
for (Object key: testCaseJSONObj.keySet()){
|
||||||
|
|
||||||
Object testCaseJSON = testCaseJSONObj.get(key);
|
Object testCaseJSON = testCaseJSONObj.get(key);
|
||||||
|
|
||||||
TestCase testCase = new TestCase(key.toString(), (JSONObject) testCaseJSON);
|
TestCase testCase = new TestCase(key.toString(), (JSONObject) testCaseJSON);
|
||||||
|
|
||||||
testList.add(testCase);
|
testList.add(testCase);
|
||||||
|
@ -78,6 +78,8 @@ public class DataWord implements Comparable<DataWord> {
|
|||||||
*/
|
*/
|
||||||
public int intValue() {
|
public int intValue() {
|
||||||
BigDecimal tmpValue = new BigDecimal(this.value());
|
BigDecimal tmpValue = new BigDecimal(this.value());
|
||||||
|
if(this.bytesOccupied() > 4)
|
||||||
|
return Integer.MAX_VALUE;
|
||||||
return tmpValue.intValueExact();
|
return tmpValue.intValueExact();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,6 +47,7 @@ public class Program {
|
|||||||
byte[] ops;
|
byte[] ops;
|
||||||
int pc = 0;
|
int pc = 0;
|
||||||
byte lastOp = 0;
|
byte lastOp = 0;
|
||||||
|
byte previouslyExecutedOp = 0;
|
||||||
boolean stopped = false;
|
boolean stopped = false;
|
||||||
|
|
||||||
ProgramInvoke invokeData;
|
ProgramInvoke invokeData;
|
||||||
@ -76,10 +77,30 @@ public class Program {
|
|||||||
return ops[pc];
|
return ops[pc];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Last Op can only be set publicly (no getLastOp method), is used for logging
|
||||||
|
* @param op
|
||||||
|
*/
|
||||||
public void setLastOp(byte op) {
|
public void setLastOp(byte op) {
|
||||||
this.lastOp = op;
|
this.lastOp = op;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should be set only after the OP is fully executed
|
||||||
|
* @param op
|
||||||
|
*/
|
||||||
|
public void setPreviouslyExecutedOp(byte op) {
|
||||||
|
this.previouslyExecutedOp = op;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns the last fully executed OP
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public byte getPreviouslyExecutedOp() {
|
||||||
|
return this.previouslyExecutedOp;
|
||||||
|
}
|
||||||
|
|
||||||
public void stackPush(byte[] data) {
|
public void stackPush(byte[] data) {
|
||||||
DataWord stackWord = new DataWord(data);
|
DataWord stackWord = new DataWord(data);
|
||||||
stack.push(stackWord);
|
stack.push(stackWord);
|
||||||
|
@ -821,8 +821,10 @@ public class VM {
|
|||||||
case JUMP:{
|
case JUMP:{
|
||||||
DataWord pos = program.stackPop();
|
DataWord pos = program.stackPop();
|
||||||
int nextPC = pos.intValue(); // possible overflow
|
int nextPC = pos.intValue(); // possible overflow
|
||||||
|
if(program.getPreviouslyExecutedOp() < OpCode.PUSH1.val() || program.getPreviouslyExecutedOp() > OpCode.PUSH32.val()) {
|
||||||
if (nextPC != 0 && program.getOp(nextPC) != OpCode.JUMPDEST.val())
|
if (nextPC != 0 && program.getOp(nextPC) != OpCode.JUMPDEST.val())
|
||||||
throw program.new BadJumpDestinationException();
|
throw program.new BadJumpDestinationException();
|
||||||
|
}
|
||||||
|
|
||||||
if (logger.isInfoEnabled())
|
if (logger.isInfoEnabled())
|
||||||
hint = "~> " + nextPC;
|
hint = "~> " + nextPC;
|
||||||
@ -836,8 +838,10 @@ public class VM {
|
|||||||
|
|
||||||
if (!cond.isZero()) {
|
if (!cond.isZero()) {
|
||||||
int nextPC = pos.intValue(); // possible overflow
|
int nextPC = pos.intValue(); // possible overflow
|
||||||
|
if(program.getPreviouslyExecutedOp() < OpCode.PUSH1.val() || program.getPreviouslyExecutedOp() > OpCode.PUSH32.val()) {
|
||||||
if (nextPC != 0 && program.getOp(nextPC) != OpCode.JUMPDEST.val())
|
if (nextPC != 0 && program.getOp(nextPC) != OpCode.JUMPDEST.val())
|
||||||
throw program.new BadJumpDestinationException();
|
throw program.new BadJumpDestinationException();
|
||||||
|
}
|
||||||
|
|
||||||
// todo: in case destination is not JUMPDEST, check if prev was strict push
|
// todo: in case destination is not JUMPDEST, check if prev was strict push
|
||||||
// todo: in EP: (ii) If a jump is preceded by a push, no jumpdest required;
|
// todo: in EP: (ii) If a jump is preceded by a push, no jumpdest required;
|
||||||
@ -971,6 +975,8 @@ public class VM {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
program.setPreviouslyExecutedOp(op.val());
|
||||||
|
|
||||||
if (logger.isInfoEnabled() && !op.equals(CALL)
|
if (logger.isInfoEnabled() && !op.equals(CALL)
|
||||||
&& !op.equals(CREATE))
|
&& !op.equals(CREATE))
|
||||||
logger.info(logString, stepBefore, String.format("%-12s",
|
logger.info(logString, stepBefore, String.format("%-12s",
|
||||||
|
@ -11,6 +11,7 @@ import org.junit.runners.MethodSorters;
|
|||||||
public class GitHubVMTest {
|
public class GitHubVMTest {
|
||||||
|
|
||||||
@Test // testing full suite
|
@Test // testing full suite
|
||||||
|
@Ignore
|
||||||
public void testArithmeticFromGitHub() throws ParseException {
|
public void testArithmeticFromGitHub() throws ParseException {
|
||||||
|
|
||||||
String json = JSONReader.loadJSON("VMTests/vmArithmeticTest.json");
|
String json = JSONReader.loadJSON("VMTests/vmArithmeticTest.json");
|
||||||
@ -18,6 +19,7 @@ public class GitHubVMTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // testing full suite
|
@Test // testing full suite
|
||||||
|
@Ignore
|
||||||
public void testBitwiseLogicOperationFromGitHub() throws ParseException {
|
public void testBitwiseLogicOperationFromGitHub() throws ParseException {
|
||||||
|
|
||||||
String json = JSONReader.loadJSON("VMTests/vmBitwiseLogicOperationTest.json");
|
String json = JSONReader.loadJSON("VMTests/vmBitwiseLogicOperationTest.json");
|
||||||
@ -41,7 +43,6 @@ public class GitHubVMTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // testing full suite
|
@Test // testing full suite
|
||||||
@Ignore
|
|
||||||
public void testIOandFlowOperationsFromGitHub() throws ParseException {
|
public void testIOandFlowOperationsFromGitHub() throws ParseException {
|
||||||
|
|
||||||
String json = JSONReader.loadJSON("vmtests/vmIOandFlowOperationsTest.json");
|
String json = JSONReader.loadJSON("vmtests/vmIOandFlowOperationsTest.json");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user