JSON test suite :

+ adjusted format for the latest changes
+ option to run from a file
This commit is contained in:
romanman 2014-07-07 13:46:28 +01:00
parent bdeb898dd0
commit cf49683489
7 changed files with 122 additions and 12 deletions

View File

@ -32,13 +32,18 @@ public class AccountState {
this.address = address;
String balance = accountState.get("balance").toString();
JSONArray code = (JSONArray)accountState.get("code");
String code = (String)accountState.get("code");
String nonce = accountState.get("nonce").toString();
JSONObject store = (JSONObject)accountState.get("storage");
this.balance = new BigInteger(balance).toByteArray();
this.code = Helper.parseDataArray(code);
if (code != null && code.length() > 2)
this.code = Hex.decode(code.substring(2));
else
this.code = new byte[0];
this.nonce = new BigInteger(nonce).toByteArray();
int size = store.keySet().size();

View File

@ -36,12 +36,17 @@ public class CallCreate {
public CallCreate(JSONObject callCreateJSON) {
JSONArray data = (JSONArray)callCreateJSON.get("data");
String data = (String)callCreateJSON.get("data");
String destination = (String)callCreateJSON.get("destination");
Long gasLimit = (Long)callCreateJSON.get("gasLimit");
Long value = (Long)callCreateJSON.get("value");
this.data = Helper.parseDataArray(data);
if (data != null && data.length() > 2)
this.data = Hex.decode(data.substring(2));
else
this.data = new byte[0];
this.destination = Hex.decode(destination);
this.gasLimit = ByteUtil.bigIntegerToBytes( BigInteger.valueOf(gasLimit) );
this.value = ByteUtil.bigIntegerToBytes( BigInteger.valueOf(value) );

View File

@ -47,6 +47,9 @@ public class Exec {
String address = exec.get("address").toString();
String caller = exec.get("caller").toString();
String code = exec.get("code").toString();
String data = exec.get("data").toString();
String gas = exec.get("gas").toString();
String gasPrice = exec.get("gasPrice").toString();
String origin = exec.get("origin").toString();
@ -55,8 +58,16 @@ public class Exec {
this.address = Hex.decode(address);
this.caller = Hex.decode(caller);
this.data = Helper.parseDataArray((JSONArray) exec.get("data"));
this.code = Helper.parseDataArray((JSONArray) exec.get("code"));
if (code != null && code.length() > 2)
this.code = Hex.decode(code.substring(2));
else
this.code = new byte[0];
if (data != null && data.length() > 2)
this.data = Hex.decode(data.substring(2));
else
this.data = new byte[0];
this.gas = ByteUtil.bigIntegerToBytes( new BigInteger(gas) );
this.gasPrice = ByteUtil.bigIntegerToBytes( new BigInteger(gasPrice) );

View File

@ -324,9 +324,6 @@ public class Program {
return;
}
// actual gas subtract
this.spendGas(gas.intValue(), "internal call");
BigInteger endowment = endowmentValue.value();
BigInteger senderBalance = result.getRepository().getBalance(senderAddress);
if (senderBalance.compareTo(endowment) < 0){
@ -335,7 +332,6 @@ public class Program {
}
result.getRepository().addBalance(senderAddress, endowment.negate());
if (invokeData.byTestingSuite()) {
logger.info("[testing suite] - omit real call");
@ -348,6 +344,9 @@ public class Program {
return;
}
// actual gas subtract
this.spendGas(gas.intValue(), "internal call");
Repository trackRepository = result.getRepository().getTrack();
trackRepository.startTracking();

View File

@ -1,6 +1,7 @@
package org.ethereum.jsontestsuite;
import org.ethereum.db.ByteArrayWrapper;
import org.ethereum.util.Utils;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
@ -8,7 +9,12 @@ import org.junit.Assert;
import org.junit.Test;
import org.spongycastle.util.encoders.Hex;
import java.io.File;
import java.io.IOException;
import java.math.BigInteger;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.util.List;
/**
@ -157,7 +163,7 @@ public class JSONTestSuiteTest {
public void test5() throws ParseException {
JSONParser parser = new JSONParser();
// String testCaseString = "{'callcreates':[{'data':[],'destination':'cd1722f3947def4cf144679da39c4c32bdc35681','gasLimit':9792,'value':74}],'env':{'currentCoinbase':'2adc25665018aa1fe0e6bc666dac8fc2697ff9ba','currentDifficulty':'256','currentGasLimit':'1000000','currentNumber':'0','currentTimestamp':1,'previousHash':'5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6'},'exec':{'address':'0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6','caller':'cd1722f3947def4cf144679da39c4c32bdc35681','code':[96,0,96,0,96,0,96,0,96,74,51,96,200,92,3,241],'data':[],'gas':10000,'gasPrice':100000000000000,'origin':'cd1722f3947def4cf144679da39c4c32bdc35681','value':1000000000000000000},'gas':9971,'out':[],'post':{'0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6':{'balance':999999999999999926,'code':[96,0,96,0,96,0,96,0,96,74,51,96,200,92,3,241],'nonce':0,'storage':{}}},'pre':{'0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6':{'balance':1000000000000000000,'code':[96,0,96,0,96,0,96,0,96,74,51,96,200,92,3,241],'nonce':0,'storage':{}}}}";
// String testCaseString = "{'callcreates':[{'data':[],'destination':'cd1722f3947def4cf144679da39c4c32bdc35681','gasLimit':9786,'value':2},{'data':[],'destination':'cd1722f3947def4cf144679da39c4c32bdc35681','gasLimit':9732,'value':12},{'data':[],'destination':'cd1722f3947def4cf144679da39c4c32bdc35681','gasLimit':9696,'value':13},{'data':[],'destination':'cd1722f3947def4cf144679da39c4c32bdc35681','gasLimit':9660,'value':14}],'env':{'currentCoinbase':'2adc25665018aa1fe0e6bc666dac8fc2697ff9ba','currentDifficulty':'256','currentGasLimit':'1000000','currentNumber':'0','currentTimestamp':1,'previousHash':'5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6'},'exec':{'address':'0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6','caller':'cd1722f3947def4cf144679da39c4c32bdc35681','code':['0x60006001100f603459600060006000600060033360c85c03f150', '0x60016000100f604e59600060006000600060043360c85c03f150','0x60006000100f606859600060006000600060053360c85c03f150', '0x60016001110f6082596000600060006000600c3360c85c03f150','0x60006001110f609c596000600060006000600d3360c85c03f150','0x60016000110f60b6596000600060006000600e3360c85c03f150','0x60006000110f60d0596000600060006000600f3360c85c03f150'],'data':[],'gas':10000,'gasPrice':100000000000000,'origin':'cd1722f3947def4cf144679da39c4c32bdc35681','value':1000000000000000000},'gas':9832,'out':[]}";
String testCaseString = "{'callcreates':[{'data':[],'destination':'cd1722f3947def4cf144679da39c4c32bdc35681','gasLimit':200,'value':74}],'env':{'currentCoinbase':'2adc25665018aa1fe0e6bc666dac8fc2697ff9ba','currentDifficulty':'256','currentGasLimit':'1000000','currentNumber':'0','currentTimestamp':1,'previousHash':'5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6'},'exec':{'address':'0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6','caller':'cd1722f3947def4cf144679da39c4c32bdc35681','code':['0x6000600060006000604a3360c8f1'],'data':[],'gas':10000,'gasPrice':100000000000000,'origin':'cd1722f3947def4cf144679da39c4c32bdc35681','value':1000000000000000000},'gas':9773,'out':[],'post':{'0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6':{'balance':999999999999999926,'code':[],'nonce':0,'storage':{}}},'pre':{'0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6':{'balance':1000000000000000000,'code':[],'nonce':0,'storage':{}}}}";
testCaseString = testCaseString.replace("'", "\"");
@ -175,5 +181,40 @@ public class JSONTestSuiteTest {
}
@Test // TestCase parsing //
public void test7() throws ParseException, IOException, URISyntaxException {
URL vmtest = ClassLoader
.getSystemResource("jsontestsuite/vmtest-1.json");
File vmTestFile = new File(vmtest.toURI());
byte[] testData = Files.readAllBytes(vmTestFile.toPath());
String testSrc = new String(testData);
JSONParser parser = new JSONParser();
JSONObject testCaseJSONObj = (JSONObject)parser.parse(testSrc);
TestCase testCase = new TestCase(testCaseJSONObj);
int ccList = testCase.getCallCreateList().size();
Assert.assertEquals(1, ccList);
TestRunner runner = new TestRunner();
List<String> result = runner.runTestCase(testCase);
Assert.assertTrue(result.size() == 0);
}
@Test // testing full suite
public void testDirectFromGitHub(){
String json = Utils.getHTML("https://raw.githubusercontent.com/ethereum/tests/develop/vmtests.json");
}
}

View File

@ -0,0 +1,49 @@
{
"callcreates": [
{
"data": "0x",
"destination": "cd1722f3947def4cf144679da39c4c32bdc35681",
"gasLimit": 9770,
"value": 74
}
],
"env": {
"currentCoinbase": "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
"currentDifficulty": "256",
"currentGasLimit": "1000000",
"currentNumber": "0",
"currentTimestamp": 1,
"previousHash": "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6"
},
"exec": {
"address": "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
"caller": "cd1722f3947def4cf144679da39c4c32bdc35681",
"code": "0x600060006000600060026002600803036002600306600260020460046004600402026002600201010101013360c85c03f1",
"data": "0x",
"gas": 10000,
"gasPrice": 100000000000000,
"origin": "cd1722f3947def4cf144679da39c4c32bdc35681",
"value": 1000000000000000000
},
"gas": 9949,
"out": [
],
"post": {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6": {
"balance": 999999999999999926,
"code": "0x600060006000600060026002600803036002600306600260020460046004600402026002600201010101013360c85c03f1",
"nonce": 0,
"storage": {
}
}
},
"pre": {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6": {
"balance": 1000000000000000000,
"code": "0x600060006000600060026002600803036002600306600260020460046004600402026002600201010101013360c85c03f1",
"nonce": 0,
"storage": {
}
}
}
}

File diff suppressed because one or more lines are too long